Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Nov 12, 2024
1 parent 264524a commit 6e2dcff
Show file tree
Hide file tree
Showing 22 changed files with 119 additions and 99 deletions.
6 changes: 2 additions & 4 deletions frontend/src/modules/2DViewer/layers/ColorScale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,15 @@ export class ColorScale implements Item {

serializeState(): SerializedColorScale {
return {
...this._itemDelegate.serializeState(),
type: "color-scale",
name: this._itemDelegate.getName(),
id: this._itemDelegate.getId(),
colorScale: this._colorScale.serialize(),
userDefinedBoundaries: this._areBoundariesUserDefined,
};
}

deserializeState(serialized: SerializedColorScale): void {
this._itemDelegate.setName(serialized.name);
this._itemDelegate.setId(serialized.id);
this._itemDelegate.deserializeState(serialized);
this._colorScale = ColorScaleImpl.fromSerialized(serialized.colorScale);
this._areBoundariesUserDefined = serialized.userDefinedBoundaries;
}
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/modules/2DViewer/layers/DeltaSurface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ export class DeltaSurface implements Group {
return this._groupDelegate;
}

deserializeState(serialized: SerializedDeltaSurface): void {
this._itemDelegate.deserializeState(serialized);
this._groupDelegate.deserializeChildren(serialized.children);
}

serializeState(): SerializedDeltaSurface {
return {
id: this._itemDelegate.getId(),
...this._itemDelegate.serializeState(),
type: "delta-surface",
name: this._itemDelegate.getName(),
children: this.getGroupDelegate().serializeChildren(),
};
}
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/modules/2DViewer/layers/LayerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,17 @@ export class LayerManager implements Group, PublishSubscribe<LayerManagerTopic,
}

serializeState(): SerializedLayerManager {
const itemState = this._itemDelegate.serializeState();
return {
id: this._itemDelegate.getId(),
name: this._itemDelegate.getName(),
...itemState,
type: "layer-manager",
children: this._groupDelegate.serializeChildren(),
};
}

deserializeState(serializedState: SerializedLayerManager): void {
this._deserializing = true;
this._itemDelegate.setId(serializedState.id);
this._itemDelegate.setName(serializedState.name);
this._itemDelegate.deserializeState(serializedState);
this._groupDelegate.deserializeChildren(serializedState.children);
this._deserializing = false;

Expand Down
6 changes: 2 additions & 4 deletions frontend/src/modules/2DViewer/layers/SettingsGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ export class SettingsGroup implements Group {

serializeState(): SerializedSettingsGroup {
return {
...this._itemDelegate.serializeState(),
type: "settings-group",
name: this._itemDelegate.getName(),
id: this._itemDelegate.getId(),
children: this._groupDelegate.serializeChildren(),
};
}

deserializeState(serialized: SerializedSettingsGroup) {
this._itemDelegate.setName(serialized.name);
this._itemDelegate.setId(serialized.id);
this._itemDelegate.deserializeState(serialized);
this._groupDelegate.deserializeChildren(serialized.children);
}
}
6 changes: 2 additions & 4 deletions frontend/src/modules/2DViewer/layers/SharedSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ export class SharedSetting implements Item {

serializeState(): SerializedSharedSetting {
return {
id: this._itemDelegate.getId(),
name: this._itemDelegate.getName(),
...this._itemDelegate.serializeState(),
type: "shared-setting",
wrappedSettingClass: this._wrappedSetting.constructor.name,
settingType: this._wrappedSetting.getType(),
Expand All @@ -116,8 +115,7 @@ export class SharedSetting implements Item {
}

deserializeState(serialized: SerializedSharedSetting): void {
this._itemDelegate.setId(serialized.id);
this._itemDelegate.setName(serialized.name);
this._itemDelegate.deserializeState(serialized);
this._wrappedSetting.getDelegate().deserializeValue(serialized.value);
}

Expand Down
6 changes: 2 additions & 4 deletions frontend/src/modules/2DViewer/layers/View.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ export class View implements Group {

serializeState(): SerializedView {
return {
id: this._itemDelegate.getId(),
...this._itemDelegate.serializeState(),
type: "view",
color: this._groupDelegate.getColor() ?? "",
name: this._itemDelegate.getName(),
children: this._groupDelegate.serializeChildren(),
};
}

deserializeState(serialized: SerializedView) {
this._itemDelegate.setName(serialized.name);
this._itemDelegate.setId(serialized.id);
this._itemDelegate.deserializeState(serialized);
this._groupDelegate.setColor(serialized.color);
this._groupDelegate.deserializeChildren(serialized.children);
}
Expand Down
32 changes: 17 additions & 15 deletions frontend/src/modules/2DViewer/layers/delegates/GroupDelegate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ItemDelegateTopic } from "./ItemDelegate";
import { PublishSubscribe, PublishSubscribeDelegate } from "./PublishSubscribeDelegate";
import { UnsubscribeHandlerDelegate } from "./UnsubscribeHandlerDelegate";

import { DeserializationFactory } from "../DeserializationFactory";
import { LayerManagerTopic } from "../LayerManager";
Expand All @@ -23,7 +24,7 @@ export class GroupDelegate implements PublishSubscribe<GroupDelegateTopic, Group
private _color: string | null = null;
private _children: Item[] = [];
private _publishSubscribeDelegate = new PublishSubscribeDelegate<GroupDelegateTopic>();
private _subscriptions: Map<string, Set<() => void>> = new Map();
private _unsubscribeHandlerDelegate = new UnsubscribeHandlerDelegate();
private _treeRevisionNumber: number = 0;
private _deserializing = false;

Expand All @@ -47,10 +48,11 @@ export class GroupDelegate implements PublishSubscribe<GroupDelegateTopic, Group
protected takeOwnershipOfChild(child: Item) {
child.getItemDelegate().setParentGroup(this);

const subscriptionSet = new Set<() => void>();
this._unsubscribeHandlerDelegate.unsubscribe(child.getItemDelegate().getId());

if (instanceofLayer(child)) {
subscriptionSet.add(
this._unsubscribeHandlerDelegate.registerUnsubscribeFunction(
child.getItemDelegate().getId(),
child
.getItemDelegate()
.getPublishSubscribeDelegate()
Expand All @@ -61,18 +63,26 @@ export class GroupDelegate implements PublishSubscribe<GroupDelegateTopic, Group
}

if (instanceofGroup(child)) {
subscriptionSet.add(
this._unsubscribeHandlerDelegate.registerUnsubscribeFunction(
child.getItemDelegate().getId(),
child
.getGroupDelegate()
.getPublishSubscribeDelegate()
.makeSubscriberFunction(GroupDelegateTopic.TREE_REVISION_NUMBER)(() => {
this.incrementTreeRevisionNumber();
})
);
this._unsubscribeHandlerDelegate.registerUnsubscribeFunction(
child.getItemDelegate().getId(),
child
.getGroupDelegate()
.getPublishSubscribeDelegate()
.makeSubscriberFunction(GroupDelegateTopic.CHILDREN_EXPANSION_STATES)(() => {
this.publishTopic(GroupDelegateTopic.CHILDREN_EXPANSION_STATES);
})
);
}

this._subscriptions.set(child.getItemDelegate().getId(), subscriptionSet);

this.publishTopic(GroupDelegateTopic.CHILDREN);
this.incrementTreeRevisionNumber();
}
Expand All @@ -85,15 +95,7 @@ export class GroupDelegate implements PublishSubscribe<GroupDelegateTopic, Group
}

private disposeOwnershipOfChild(child: Item) {
if (instanceofGroup(child)) {
const unsubscribeFuncs = this._subscriptions.get(child.getItemDelegate().getId());
if (unsubscribeFuncs) {
for (const unsubscribeFunc of unsubscribeFuncs) {
unsubscribeFunc();
}
}
}

this._unsubscribeHandlerDelegate.unsubscribe(child.getItemDelegate().getId());
child.getItemDelegate().setParentGroup(null);

if (child instanceof SharedSetting) {
Expand Down
36 changes: 35 additions & 1 deletion frontend/src/modules/2DViewer/layers/delegates/ItemDelegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { GroupDelegate } from "./GroupDelegate";
import { PublishSubscribe, PublishSubscribeDelegate } from "./PublishSubscribeDelegate";

import { LayerManager, LayerManagerTopic } from "../LayerManager";
import { SerializedItem } from "../interfaces";

export enum ItemDelegateTopic {
NAME = "NAME",
Expand All @@ -29,8 +30,25 @@ export class ItemDelegate implements PublishSubscribe<ItemDelegateTopic, ItemDel

constructor(name: string, layerManager: LayerManager) {
this._id = v4();
this._name = name;
this._layerManager = layerManager;
this._name = this.makeUniqueName(name);
}

private makeUniqueName(candidate: string): string {
const groupDelegate = this._layerManager?.getGroupDelegate();
if (!groupDelegate) {
return candidate;
}
const existingNames = groupDelegate
.getDescendantItems(() => true)
.map((item) => item.getItemDelegate().getName());
let uniqueName = candidate;
let counter = 1;
while (existingNames.includes(uniqueName)) {
uniqueName = `${candidate} (${counter})`;
counter++;
}
return uniqueName;
}

setId(id: string): void {
Expand Down Expand Up @@ -116,4 +134,20 @@ export class ItemDelegate implements PublishSubscribe<ItemDelegateTopic, ItemDel
getPublishSubscribeDelegate(): PublishSubscribeDelegate<ItemDelegateTopic> {
return this._publishSubscribeDelegate;
}

serializeState(): Omit<SerializedItem, "type"> {
return {
id: this._id,
name: this._name,
visible: this._visible,
expanded: this._expanded,
};
}

deserializeState(state: Omit<SerializedItem, "type">): void {
this._id = state.id;
this._name = state.name;
this._visible = state.visible;
this._expanded = state.expanded;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,18 @@ export class LayerDelegate<TSettings extends Settings, TData>
}
}

serializeState(id: string, name: string): SerializedLayer<TSettings> {
serializeState(): SerializedLayer<TSettings> {
const itemState = this._owner.getItemDelegate().serializeState();
return {
id,
name,
...itemState,
type: "layer",
layerClass: this._owner.constructor.name,
settings: this._settingsContext.getDelegate().serializeSettings(),
};
}

deserializeState(serializedLayer: SerializedLayer<TSettings>): void {
this._owner.getItemDelegate().deserializeState(serializedLayer);
this._settingsContext.getDelegate().deserializeSettings(serializedLayer.settings);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class DrilledWellTrajectoriesLayer implements Layer<DrilledWellTrajectori
const selectedWellboreHeaders = settings[SettingType.SMDA_WELLBORE_HEADERS].getDelegate().getValue();
let selectedWellboreUuids: string[] = [];
if (selectedWellboreHeaders) {
selectedWellboreHeaders.map((header) => header.wellboreUuid);
selectedWellboreUuids = selectedWellboreHeaders.map((header) => header.wellboreUuid);
}

let fieldIdentifier: string | null = null;
Expand Down Expand Up @@ -114,14 +114,10 @@ export class DrilledWellTrajectoriesLayer implements Layer<DrilledWellTrajectori
}

serializeState(): SerializedLayer<DrilledWellTrajectoriesSettings> {
const id = this._itemDelegate.getId();
const name = this._itemDelegate.getName();
return this._layerDelegate.serializeState(id, name);
return this._layerDelegate.serializeState();
}

deserializeState(serializedState: SerializedLayer<DrilledWellTrajectoriesSettings>): void {
this._itemDelegate.setId(serializedState.id);
this._itemDelegate.setName(serializedState.name);
this._layerDelegate.deserializeState(serializedState);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,11 @@ export class DrilledWellborePicksLayer implements Layer<DrilledWellborePicksSett
}

serializeState(): SerializedLayer<DrilledWellborePicksSettings> {
const id = this._itemDelegate.getId();
const name = this._itemDelegate.getName();
return this._layerDelegate.serializeState(id, name);
return this._layerDelegate.serializeState();
}

deserializeState(serializedState: SerializedLayer<DrilledWellborePicksSettings>): void {
this._itemDelegate.setId(serializedState.id);
this._itemDelegate.setName(serializedState.name);
this._layerDelegate.deserializeState(serializedState);
deserializeState(state: SerializedLayer<DrilledWellborePicksSettings>): void {
this._layerDelegate.deserializeState(state);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,10 @@ export class ObservedSurfaceLayer
}

serializeState(): SerializedLayer<ObservedSurfaceSettings> {
const id = this._itemDelegate.getId();
const name = this._itemDelegate.getName();
return this._layerDelegate.serializeState(id, name);
return this._layerDelegate.serializeState();
}

deserializeState(serializedState: SerializedLayer<ObservedSurfaceSettings>): void {
this._itemDelegate.setId(serializedState.id);
this._itemDelegate.setName(serializedState.name);
this._layerDelegate.deserializeState(serializedState);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,10 @@ export class RealizationGridLayer
}

serializeState(): SerializedLayer<RealizationGridSettings> {
const id = this._itemDelegate.getId();
const name = this._itemDelegate.getName();
return this._layerDelegate.serializeState(id, name);
return this._layerDelegate.serializeState();
}

deserializeState(serializedState: SerializedLayer<RealizationGridSettings>): void {
this._itemDelegate.setId(serializedState.id);
this._itemDelegate.setName(serializedState.name);
this._layerDelegate.deserializeState(serializedState);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,10 @@ export class RealizationPolygonsLayer implements Layer<RealizationPolygonsSettin
}

serializeState(): SerializedLayer<RealizationPolygonsSettings> {
const id = this._itemDelegate.getId();
const name = this._itemDelegate.getName();
return this._layerDelegate.serializeState(id, name);
return this._layerDelegate.serializeState();
}

deserializeState(serializedState: SerializedLayer<RealizationPolygonsSettings>): void {
this._itemDelegate.setId(serializedState.id);
this._itemDelegate.setName(serializedState.name);
this._layerDelegate.deserializeState(serializedState);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,10 @@ export class RealizationSurfaceLayer
}

serializeState(): SerializedLayer<RealizationSurfaceSettings> {
const id = this._itemDelegate.getId();
const name = this._itemDelegate.getName();
return this._layerDelegate.serializeState(id, name);
return this._layerDelegate.serializeState();
}

deserializeState(serializedState: SerializedLayer<RealizationSurfaceSettings>): void {
this._itemDelegate.setId(serializedState.id);
this._itemDelegate.setName(serializedState.name);
this._layerDelegate.deserializeState(serializedState);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,10 @@ export class StatisticalSurfaceLayer
}

serializeState(): SerializedLayer<StatisticalSurfaceSettings> {
const id = this._itemDelegate.getId();
const name = this._itemDelegate.getName();
return this._layerDelegate.serializeState(id, name);
return this._layerDelegate.serializeState();
}

deserializeState(serializedState: SerializedLayer<StatisticalSurfaceSettings>): void {
this._itemDelegate.setId(serializedState.id);
this._itemDelegate.setName(serializedState.name);
this._layerDelegate.deserializeState(serializedState);
}
}
Expand Down
Loading

0 comments on commit 6e2dcff

Please sign in to comment.