Skip to content

Commit

Permalink
Multiple bug fixes and features
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Nov 12, 2024
1 parent 6e2dcff commit 1ca3234
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 30 deletions.
6 changes: 6 additions & 0 deletions frontend/src/modules/2DViewer/layers/LayerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export enum LayerManagerTopic {
AVAILABLE_SETTINGS_CHANGED = "AVAILABLE_SETTINGS_CHANGED",
LAYER_DATA_REVISION = "LAYER_DATA_REVISION",
GLOBAL_SETTINGS_CHANGED = "GLOBAL_SETTINGS_CHANGED",
SHARED_SETTINGS_CHANGED = "SHARED_SETTINGS_CHANGED",
}

export type LayerManagerTopicPayload = {
Expand All @@ -30,6 +31,7 @@ export type LayerManagerTopicPayload = {
[LayerManagerTopic.AVAILABLE_SETTINGS_CHANGED]: void;
[LayerManagerTopic.LAYER_DATA_REVISION]: number;
[LayerManagerTopic.GLOBAL_SETTINGS_CHANGED]: void;
[LayerManagerTopic.SHARED_SETTINGS_CHANGED]: void;
};

export type GlobalSettings = {
Expand Down Expand Up @@ -137,6 +139,7 @@ export class LayerManager implements Group, PublishSubscribe<LayerManagerTopic,
if (topic === LayerManagerTopic.LAYER_DATA_REVISION) {
this._layerDataRevision++;
}

this._publishSubscribeDelegate.notifySubscribers(topic);
}

Expand Down Expand Up @@ -169,6 +172,9 @@ export class LayerManager implements Group, PublishSubscribe<LayerManagerTopic,
if (topic === LayerManagerTopic.GLOBAL_SETTINGS_CHANGED) {
return this._globalSettings;
}
if (topic === LayerManagerTopic.SHARED_SETTINGS_CHANGED) {
return;
}
};

return snapshotGetter;
Expand Down
21 changes: 18 additions & 3 deletions frontend/src/modules/2DViewer/layers/SharedSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class SharedSetting implements Item {
publishValueChange(): void {
const layerManager = this._itemDelegate.getLayerManager();
if (layerManager) {
layerManager.publishTopic(LayerManagerTopic.LAYER_DATA_REVISION);
layerManager.publishTopic(LayerManagerTopic.SHARED_SETTINGS_CHANGED);
}
}

Expand All @@ -71,17 +71,24 @@ export class SharedSetting implements Item {
const layersAndSharedSettings = parentGroup.getDescendantItems(
(item) => instanceofLayer(item) || item instanceof SharedSetting
) as Layer<any, any>[];
let noSettingLoadingOrUninitialized = true;
let index = 0;
const availableValues = layersAndSharedSettings.reduce((acc, item) => {
if (instanceofLayer(item)) {
const setting = item.getLayerDelegate().getSettingsContext().getDelegate().getSettings()[
this._wrappedSetting.getType()
];
if (setting) {
if (acc.length === 0) {
noSettingLoadingOrUninitialized =
noSettingLoadingOrUninitialized &&
!setting.getDelegate().getIsLoading() &&
setting.getDelegate().getIsInitialized();
if (index === 0) {
acc.push(...setting.getDelegate().getAvailableValues());
} else {
acc = acc.filter((value) => setting.getDelegate().getAvailableValues().includes(value));
}
index++;
}
}
if (
Expand All @@ -91,16 +98,24 @@ export class SharedSetting implements Item {
) {
const setting = item.getWrappedSetting();
if (setting) {
if (acc.length === 0) {
if (index === 0) {
acc.push(...setting.getDelegate().getAvailableValues());
} else {
acc = acc.filter((value) => setting.getDelegate().getAvailableValues().includes(value));
}
index++;
}
}
return acc;
}, [] as any[]);

if (!noSettingLoadingOrUninitialized) {
this._wrappedSetting.getDelegate().setIsLoading(true);
return;
}

this._wrappedSetting.getDelegate().setIsLoading(false);

this._wrappedSetting.getDelegate().setAvailableValues(availableValues);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ export function LayerComponent(props: LayerComponentProps): React.ReactNode {
if (!manager) {
return null;
}
return <SettingComponent key={setting.getDelegate().getId()} setting={setting} manager={manager} />;
return (
<SettingComponent
key={setting.getDelegate().getId()}
setting={setting}
manager={manager}
sharedSetting={false}
/>
);
}

function makeSettings(settings: Record<string, Setting<any>>): React.ReactNode[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Setting, SettingComponentProps as SettingComponentPropsInterface } from
export type SettingComponentProps<TValue> = {
setting: Setting<TValue>;
manager: LayerManager;
sharedSetting: boolean;
};

export function SettingComponent<TValue>(props: SettingComponentProps<TValue>): React.ReactNode {
Expand Down Expand Up @@ -42,6 +43,15 @@ export function SettingComponent<TValue>(props: SettingComponentProps<TValue>):
props.setting.getDelegate().setValue(newValue);
}

if (props.sharedSetting && availableValues.length === 0 && isInitialized) {
return (
<React.Fragment key={props.setting.getDelegate().getId()}>
<div className="p-0.5 px-2 w-32">{props.setting.getLabel()}</div>
<div className="p-0.5 px-2 w-full italic h-8 flex items-center text-orange-600">Empty intersection</div>
</React.Fragment>
);
}

if (overriddenValue !== undefined) {
const valueAsString = props.setting
.getDelegate()
Expand All @@ -54,7 +64,9 @@ export function SettingComponent<TValue>(props: SettingComponentProps<TValue>):
<Link fontSize="inherit" titleAccess="This settings is controlled by a shared setting" />
</span>
</div>
<div className="p-0.5 px-2 w-full flex items-center h-8">{isValid ? valueAsString : "-"}</div>
<div className="p-0.5 px-2 w-full flex items-center h-8">
{isValid ? valueAsString : <i className="text-orange-600">No valid shared setting value</i>}
</div>
</React.Fragment>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function SharedSettingComponent(props: SharedSettingComponentProps): Reac
hidden: !isExpanded,
})}
>
<SettingComponent setting={props.sharedSetting.getWrappedSetting()} manager={manager} />
<SettingComponent setting={props.sharedSetting.getWrappedSetting()} manager={manager} sharedSetting />
</div>
</SortableListItem>
);
Expand Down
36 changes: 26 additions & 10 deletions frontend/src/modules/2DViewer/layers/delegates/LayerDelegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,18 @@ export class LayerDelegate<TSettings extends Settings, TData>

this._unsubscribeHandler.registerUnsubscribeFunction(
"layer-manager",
layerManager.getPublishSubscribeDelegate().makeSubscriberFunction(LayerManagerTopic.LAYER_DATA_REVISION)(
() => {
this.handleSharedSettingsChanged();
}
)
layerManager
.getPublishSubscribeDelegate()
.makeSubscriberFunction(LayerManagerTopic.SHARED_SETTINGS_CHANGED)(() => {
this.handleSharedSettingsChanged();
})
);

this._unsubscribeHandler.registerUnsubscribeFunction(
"layer-manager",
layerManager.getPublishSubscribeDelegate().makeSubscriberFunction(LayerManagerTopic.ITEMS_CHANGED)(() => {
this.handleSharedSettingsChanged();
})
);
}

Expand Down Expand Up @@ -148,10 +155,18 @@ export class LayerDelegate<TSettings extends Settings, TData>
const overriddenSettings: { [K in keyof TSettings]: TSettings[K] } = {} as {
[K in keyof TSettings]: TSettings[K];
};
for (const setting of sharedSettings) {
const type = setting.getWrappedSetting().getType();
if (this._settingsContext.getDelegate().getSettings()[type] && overriddenSettings[type] === undefined) {
overriddenSettings[type] = setting.getWrappedSetting().getDelegate().getValue();
for (const sharedSetting of sharedSettings) {
const type = sharedSetting.getWrappedSetting().getType();
const setting = this._settingsContext.getDelegate().getSettings()[type];
if (setting && overriddenSettings[type] === undefined) {
if (
sharedSetting.getWrappedSetting().getDelegate().getIsInitialized() &&
sharedSetting.getWrappedSetting().getDelegate().isValueValid()
) {
overriddenSettings[type] = sharedSetting.getWrappedSetting().getDelegate().getValue();
} else {
overriddenSettings[type] = null;
}
}
}
this._settingsContext.getDelegate().setOverriddenSettings(overriddenSettings);
Expand Down Expand Up @@ -205,7 +220,7 @@ export class LayerDelegate<TSettings extends Settings, TData>
}

this._status = status;
this._layerManager?.publishTopic(LayerManagerTopic.LAYER_DATA_REVISION);
this._layerManager.publishTopic(LayerManagerTopic.LAYER_DATA_REVISION);
this._publishSubscribeDelegate.notifySubscribers(LayerDelegateTopic.STATUS);
}

Expand Down Expand Up @@ -277,6 +292,7 @@ export class LayerDelegate<TSettings extends Settings, TData>
}
this._queryKeys = [];
this._publishSubscribeDelegate.notifySubscribers(LayerDelegateTopic.DATA);
this._layerManager.publishTopic(LayerManagerTopic.LAYER_DATA_REVISION);
this.setStatus(LayerStatus.SUCCESS);
} catch (error: any) {
if (isCancelledError(error)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export class PublishSubscribeDelegate<TTopic extends string> {

notifySubscribers(topic: TTopic): void {
const subscribers = this._subscribers.get(topic);
console.debug(topic);
if (subscribers) {
subscribers.forEach((subscriber) => subscriber());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export class DrilledWellTrajectoriesLayer implements Layer<DrilledWellTrajectori
}

const bbox: BoundingBox = {
x: [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY],
y: [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY],
z: [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY],
x: [Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER],
y: [Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER],
z: [Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER],
};

for (const trajectory of data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ export class DrilledWellborePicksLayer implements Layer<DrilledWellborePicksSett
}

const bbox: BoundingBox = {
x: [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY],
y: [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY],
z: [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY],
x: [Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER],
y: [Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER],
z: [Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER],
};

for (const trajectory of data) {
Expand Down
10 changes: 3 additions & 7 deletions frontend/src/modules/2DViewer/view/components/LayersWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ViewContext } from "@framework/ModuleContext";
import { useViewStatusWriter } from "@framework/StatusWriter";
import { PendingWrapper } from "@lib/components/PendingWrapper";
import { useElementSize } from "@lib/hooks/useElementSize";
import { Rect2D, rectContainsPoint } from "@lib/utils/geometry";
import { Rect2D, outerRectContainsInnerRect } from "@lib/utils/geometry";
import { Interfaces } from "@modules/2DViewer/interfaces";
import { LayerManager, LayerManagerTopic } from "@modules/2DViewer/layers/LayerManager";
import { usePublishSubscribeTopicValue } from "@modules/2DViewer/layers/delegates/PublishSubscribeDelegate";
Expand Down Expand Up @@ -34,6 +34,7 @@ export function LayersWrapper(props: LayersWrapperProps): React.ReactNode {
const statusWriter = useViewStatusWriter(props.viewContext);

usePublishSubscribeTopicValue(props.layerManager, LayerManagerTopic.LAYER_DATA_REVISION);
console.debug("rerendered");

const viewports: ViewportType[] = [];
const viewerLayers: DeckGlLayerWithPosition[] = [];
Expand Down Expand Up @@ -113,12 +114,7 @@ export function LayersWrapper(props: LayersWrapperProps): React.ReactNode {
height: viewsAndLayers.boundingBox.y[1] - viewsAndLayers.boundingBox.y[0],
};

if (
!(
rectContainsPoint(oldBoundingRect, newBoundingRect) ||
rectContainsPoint(newBoundingRect, oldBoundingRect)
)
) {
if (!outerRectContainsInnerRect(oldBoundingRect, newBoundingRect)) {
setPrevBoundingBox(viewsAndLayers.boundingBox);
}
} else {
Expand Down

0 comments on commit 1ca3234

Please sign in to comment.