Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Apr 15, 2024
1 parent b60aed1 commit 43575bb
Show file tree
Hide file tree
Showing 14 changed files with 619 additions and 347 deletions.
18 changes: 17 additions & 1 deletion frontend/src/framework/GlobalAtoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@ import { EnsembleSet } from "@framework/EnsembleSet";
import { atom } from "jotai";
import { isEqual } from "lodash";

import { EnsembleIdent } from "./EnsembleIdent";
import { RealizationFilterSet } from "./RealizationFilterSet";
import { UserCreatedItems } from "./UserCreatedItems";
import { EnsembleRealizationFilterFunction } from "./WorkbenchSession";
import { atomWithCompare } from "./utils/atomUtils";

export const EnsembleSetAtom = atomWithCompare<EnsembleSet>(new EnsembleSet([]), isEqual);

export const EnsembleRealizationFilterFunctionAtom = atom<EnsembleRealizationFilterFunction | null>(null);
export const EnsembleRealizationFilterFunctionAtom = atom<EnsembleRealizationFilterFunction | null>((get) => {
const realizationFilterSet = get(RealizationFilterSetAtom);

if (!realizationFilterSet) {
return null;
}

return (ensembleIdent: EnsembleIdent) =>
realizationFilterSet.getRealizationFilterForEnsembleIdent(ensembleIdent).getFilteredRealizations();
});

export const UserCreatedItemsAtom = atomWithCompare<UserCreatedItems>(new UserCreatedItems(), (a, b) => a.isEqual(b));

export const RealizationFilterSetAtom = atomWithCompare<RealizationFilterSet | null>(null, isEqual);
23 changes: 23 additions & 0 deletions frontend/src/framework/UserCreatedItems.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { AtomStoreMaster } from "./AtomStoreMaster";

Check failure on line 1 in frontend/src/framework/UserCreatedItems.ts

View workflow job for this annotation

GitHub Actions / frontend

'AtomStoreMaster' is defined but never used
import { IntersectionPolylines } from "./userCreatedItems/IntersectionPolylines";

export interface UserCreatedItemSet {
serialize(): string;
populateFromData(data: string): void;
}

export class UserCreatedItems {
private _intersectionPolylines: IntersectionPolylines;

constructor() {
this._intersectionPolylines = new IntersectionPolylines();
}

getIntersectionPolylines(): IntersectionPolylines {
return this._intersectionPolylines;
}

isEqual(other: UserCreatedItems): boolean {
return this._intersectionPolylines.serialize() === other._intersectionPolylines.serialize();
}
}
6 changes: 6 additions & 0 deletions frontend/src/framework/WorkbenchSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Ensemble } from "./Ensemble";
import { EnsembleIdent } from "./EnsembleIdent";
import { EnsembleSet } from "./EnsembleSet";
import { RealizationFilterSet } from "./RealizationFilterSet";
import { UserCreatedItems } from "./UserCreatedItems";

export type EnsembleRealizationFilterFunction = (ensembleIdent: EnsembleIdent) => readonly number[];

Expand All @@ -23,6 +24,7 @@ export class WorkbenchSession {
private _subscribersMap: Map<keyof WorkbenchSessionEvent, Set<(payload: any) => void>> = new Map();
protected _ensembleSet: EnsembleSet = new EnsembleSet([]);
protected _realizationFilterSet = new RealizationFilterSet();
protected _userCreatedItems: UserCreatedItems = new UserCreatedItems();

getEnsembleSet(): EnsembleSet {
return this._ensembleSet;
Expand All @@ -32,6 +34,10 @@ export class WorkbenchSession {
return this._realizationFilterSet;
}

getUserCreatedItems(): UserCreatedItems {
return this._userCreatedItems;
}

subscribe<T extends Exclude<WorkbenchSessionEvent, keyof WorkbenchSessionPayloads>>(
event: T,
cb: () => void
Expand Down
10 changes: 4 additions & 6 deletions frontend/src/framework/internal/WorkbenchSessionPrivate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { AtomStoreMaster } from "@framework/AtomStoreMaster";
import { EnsembleIdent } from "@framework/EnsembleIdent";

Check failure on line 2 in frontend/src/framework/internal/WorkbenchSessionPrivate.ts

View workflow job for this annotation

GitHub Actions / frontend

'EnsembleIdent' is defined but never used
import { UserCreatedItems } from "@framework/UserCreatedItems";

Check failure on line 3 in frontend/src/framework/internal/WorkbenchSessionPrivate.ts

View workflow job for this annotation

GitHub Actions / frontend

'UserCreatedItems' is defined but never used

import { EnsembleSet } from "../EnsembleSet";
import { EnsembleRealizationFilterFunctionAtom, EnsembleSetAtom } from "../GlobalAtoms";
import { EnsembleSetAtom, RealizationFilterSetAtom, UserCreatedItemsAtom } from "../GlobalAtoms";
import { WorkbenchSession, WorkbenchSessionEvent } from "../WorkbenchSession";

export class WorkbenchSessionPrivate extends WorkbenchSession {
Expand All @@ -11,6 +12,8 @@ export class WorkbenchSessionPrivate extends WorkbenchSession {
constructor(atomStoreMaster: AtomStoreMaster) {
super();
this._atomStoreMaster = atomStoreMaster;
this._atomStoreMaster.setAtomValue(UserCreatedItemsAtom, this._userCreatedItems);
this._atomStoreMaster.setAtomValue(RealizationFilterSetAtom, this._realizationFilterSet);
}

setEnsembleSetLoadingState(isLoading: boolean): void {
Expand All @@ -21,11 +24,6 @@ export class WorkbenchSessionPrivate extends WorkbenchSession {
this._ensembleSet = newEnsembleSet;
this._realizationFilterSet.synchronizeWithEnsembleSet(this._ensembleSet);
this._atomStoreMaster.setAtomValue(EnsembleSetAtom, newEnsembleSet);
this._atomStoreMaster.setAtomValue(
EnsembleRealizationFilterFunctionAtom,
() => (ensembleIdent: EnsembleIdent) =>
this._realizationFilterSet.getRealizationFilterForEnsembleIdent(ensembleIdent).getFilteredRealizations()
);
this.notifySubscribers(WorkbenchSessionEvent.EnsembleSetChanged);
this.notifySubscribers(WorkbenchSessionEvent.RealizationFilterSetChanged);
}
Expand Down
51 changes: 51 additions & 0 deletions frontend/src/framework/userCreatedItems/IntersectionPolylines.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { UserCreatedItemSet } from "@framework/UserCreatedItems";

import { v4 } from "uuid";

export type IntersectionPolyline = {
id: string;
name: string;
points: number[][];
};

export type IntersectionPolylineWithoutId = Omit<IntersectionPolyline, "id">;

export class IntersectionPolylines implements UserCreatedItemSet {
private _polylines: IntersectionPolyline[] = [];

serialize(): string {
return JSON.stringify(this._polylines);
}

populateFromData(data: string): void {
this._polylines = JSON.parse(data);
}

add(polyline: IntersectionPolylineWithoutId): void {
const id = v4();
this._polylines.push({
id,
...polyline,
});
}

remove(id: string): void {
this._polylines = this._polylines.filter((polyline) => polyline.id !== id);
}

getPolylines(): IntersectionPolyline[] {
return this._polylines;
}

getPolyline(id: string): IntersectionPolyline | undefined {
return this._polylines.find((polyline) => polyline.id === id);
}

updatePolyline(id: string, polyline: IntersectionPolylineWithoutId): void {
const index = this._polylines.findIndex((polyline) => polyline.id === id);
this._polylines[index] = {
id,
...polyline,
};
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EnsembleIdent } from "@framework/EnsembleIdent";
import { EnsembleRealizationFilterFunctionAtom, EnsembleSetAtom } from "@framework/GlobalAtoms";
import { EnsembleRealizationFilterFunctionAtom, EnsembleSetAtom, UserCreatedItemsAtom } from "@framework/GlobalAtoms";
import { selectedEnsembleIdentAtom } from "@modules/Grid3DIntersection/sharedAtoms/sharedAtoms";

import { atom } from "jotai";
Expand Down Expand Up @@ -158,3 +158,8 @@ export const selectedGridModelParameterDateOrIntervalAtom = atom((get) => {

return userSelectedGridModelParameterDateOrInterval;
});

export const availableUserCreatedIntersectionPolylinesAtom = atom((get) => {
const userCreatedItems = get(UserCreatedItemsAtom);
return userCreatedItems.getIntersectionPolylines().getPolylines();
});
36 changes: 17 additions & 19 deletions frontend/src/modules/Grid3DIntersection/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import React from "react";

import { Grid3dInfo_api, Grid3dPropertyInfo_api, WellboreHeader_api } from "@api";
import { EnsembleIdent } from "@framework/EnsembleIdent";
import { UserCreatedItemsAtom } from "@framework/GlobalAtoms";

Check failure on line 5 in frontend/src/modules/Grid3DIntersection/settings/settings.tsx

View workflow job for this annotation

GitHub Actions / frontend

'UserCreatedItemsAtom' is defined but never used
import { ModuleSettingsProps } from "@framework/Module";
import { useSettingsStatusWriter } from "@framework/StatusWriter";
import { EnsembleDropdown } from "@framework/components/EnsembleDropdown";
import { IntersectionPolyline } from "@framework/userCreatedItems/IntersectionPolylines";
import { Button } from "@lib/components/Button";
import { CollapsibleGroup } from "@lib/components/CollapsibleGroup";
import { Dialog } from "@lib/components/Dialog";
Expand Down Expand Up @@ -33,6 +35,7 @@ import {
} from "./atoms/baseAtoms";
import {
availableRealizationsAtom,
availableUserCreatedIntersectionPolylinesAtom,
gridModelDimensionsAtom,
selectedGridModelNameAtom,
selectedGridModelParameterDateOrIntervalAtom,
Expand All @@ -45,7 +48,6 @@ import { SettingsToViewInterface } from "../settingsToViewInterface";
import {
addCustomIntersectionPolylineEditModeActiveAtom,
currentCustomIntersectionPolylineAtom,
customIntersectionPolylinesAtom,
editCustomIntersectionPolylineEditModeActiveAtom,
intersectionTypeAtom,
selectedCustomIntersectionPolylineIdAtom,
Expand Down Expand Up @@ -96,9 +98,7 @@ export function Settings(props: ModuleSettingsProps<State, SettingsToViewInterfa
const selectedWellboreHeader = useAtomValue(selectedWellboreUuidAtom);
const setSelectedWellboreHeader = useSetAtom(userSelectedWellboreUuidAtom);

const [availableCustomIntersectionPolylines, setAvailableCustomIntersectionPolylines] = useAtom(
customIntersectionPolylinesAtom
);
const availableUserCreatedIntersectionPolylines = useAtomValue(availableUserCreatedIntersectionPolylinesAtom);
const selectedCustomIntersectionPolylineId = useAtomValue(selectedCustomIntersectionPolylineIdAtom);
const setSelectedCustomIntersectionPolylineId = useSetAtom(userSelectedCustomIntersectionPolylineIdAtom);

Expand Down Expand Up @@ -181,6 +181,7 @@ export function Settings(props: ModuleSettingsProps<State, SettingsToViewInterfa
polylineNameInputRef.current?.focus();
}

/*
function handleEditPolylineModeChange() {
if (!polylineEditModeActive) {
setPolylineEditModeActive(true);
Expand All @@ -202,6 +203,7 @@ export function Settings(props: ModuleSettingsProps<State, SettingsToViewInterfa
setPolylineEditModeActive(false);
setCurrentCustomIntersectionPolyline([]);
}
*/

function handleCustomPolylineSelectionChange(customPolylineId: string[]) {
setSelectedCustomIntersectionPolylineId(customPolylineId.at(0) ?? null);
Expand All @@ -213,7 +215,7 @@ export function Settings(props: ModuleSettingsProps<State, SettingsToViewInterfa
return;
}

if (availableCustomIntersectionPolylines.some((el) => el.name === currentCustomPolylineName)) {
if (availableUserCreatedIntersectionPolylines.some((el) => el.name === currentCustomPolylineName)) {
setCurrentCustomPolylineNameMessage("A polyline with this name already exists");
return;
}
Expand All @@ -225,10 +227,12 @@ export function Settings(props: ModuleSettingsProps<State, SettingsToViewInterfa
polyline: currentCustomIntersectionPolyline,
};
setSelectedCustomIntersectionPolylineId(uuid);
/*
setAvailableCustomIntersectionPolylines([
...availableCustomIntersectionPolylines,
newCustomIntersectionPolyline,
]);
*/
setPolylineAddModeActive(false);
setPolylineEditModeActive(false);
setCurrentCustomPolylineName("");
Expand Down Expand Up @@ -256,16 +260,7 @@ export function Settings(props: ModuleSettingsProps<State, SettingsToViewInterfa
setCurrentCustomPolylineName(event.target.value);
}

function handleRemoveCustomPolyline() {
setAvailableCustomIntersectionPolylines((prev) =>
prev.filter((el) => el.id !== selectedCustomIntersectionPolylineId)
);
setSelectedCustomIntersectionPolylineId(null);
setPolylineAddModeActive(false);
setPolylineEditModeActive(false);
setCurrentCustomIntersectionPolyline([]);
}

/*
React.useEffect(() => {
function handleKeyboardEvent(event: KeyboardEvent) {
if (!polylineAddModeActive && !polylineEditModeActive) {
Expand All @@ -292,6 +287,7 @@ export function Settings(props: ModuleSettingsProps<State, SettingsToViewInterfa
document.removeEventListener("keydown", handleKeyboardEvent);
};
}, [polylineAddModeActive, polylineEditModeActive]);
*/

React.useEffect(
function handleShowDialog() {
Expand Down Expand Up @@ -405,9 +401,10 @@ export function Settings(props: ModuleSettingsProps<State, SettingsToViewInterfa
/>
<TableSelect
options={makeCustomIntersectionPolylineOptions(
availableCustomIntersectionPolylines,
availableUserCreatedIntersectionPolylines,
selectedCustomIntersectionPolylineId,
<div className="flex items-center">
<></>
/*<div className="flex items-center">
<div
onClick={handleEditPolylineModeChange}
className={resolveClassNames("p-1 hover:underline cursor-pointer", {
Expand All @@ -429,7 +426,8 @@ export function Settings(props: ModuleSettingsProps<State, SettingsToViewInterfa
>
<Delete fontSize="small" />
</div>
</div>
</div>
*/
)}
value={selectedCustomIntersectionPolylineId ? [selectedCustomIntersectionPolylineId] : []}
headerLabels={["Polyline name", "Actions"]}
Expand Down Expand Up @@ -548,7 +546,7 @@ function makeWellHeaderOptions(wellHeaders: WellboreHeader_api[]): SelectOption[
}

function makeCustomIntersectionPolylineOptions(
polylines: CustomIntersectionPolyline[],
polylines: IntersectionPolyline[],
selectedId: string | null,
actions: React.ReactNode
): TableSelectOption[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EnsembleIdent } from "@framework/EnsembleIdent";
import { EnsembleSetAtom } from "@framework/GlobalAtoms";
import { EnsembleSetAtom, UserCreatedItemsAtom } from "@framework/GlobalAtoms";

import { atom } from "jotai";

Expand Down Expand Up @@ -46,10 +46,9 @@ export const editCustomIntersectionPolylineEditModeActiveAtom = atom<boolean>(fa

export const currentCustomIntersectionPolylineAtom = atom<number[][]>([]);

export const customIntersectionPolylinesAtom = atom<CustomIntersectionPolyline[]>([]);
export const selectedCustomIntersectionPolylineIdAtom = atom((get) => {
const userSelectedCustomIntersectionPolylineId = get(userSelectedCustomIntersectionPolylineIdAtom);
const customIntersectionPolylines = get(customIntersectionPolylinesAtom);
const customIntersectionPolylines = get(UserCreatedItemsAtom).getIntersectionPolylines().getPolylines();

if (!customIntersectionPolylines.length) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { PolylineIntersection_trans } from "../view/queries/queryDataTransforms";

export function backsampleIntersectionPolyline(
completeWellborePath: number[][],
polylineIntersection: PolylineIntersection_trans
) {
/*
const backsampledIntersectionPolyline: number[][] = [];
for (const point of polylineIntersection) {
const closestPoint = findClosestPoint(completeWellborePath, point);
backsampledIntersectionPolyline.push(closestPoint);
}
return backsampledIntersectionPolyline;
*/
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IntersectionReferenceSystem } from "@equinor/esv-intersection";
import { UserCreatedItemsAtom } from "@framework/GlobalAtoms";
import {
currentCustomIntersectionPolylineAtom,
customIntersectionPolylinesAtom,
intersectionTypeAtom,
selectedCustomIntersectionPolylineIdAtom,
selectedWellboreUuidAtom,
Expand All @@ -14,7 +13,7 @@ import { fieldWellboreTrajectoriesQueryAtom } from "./queryAtoms";

export const selectedCustomIntersectionPolylineAtom = atom((get) => {
const customIntersectionPolylineId = get(selectedCustomIntersectionPolylineIdAtom);
const customIntersectionPolylines = get(customIntersectionPolylinesAtom);
const customIntersectionPolylines = get(UserCreatedItemsAtom).getIntersectionPolylines().getPolylines();

return customIntersectionPolylines.find((el) => el.id === customIntersectionPolylineId);
});
Expand Down Expand Up @@ -51,11 +50,11 @@ export const intersectionReferenceSystemAtom = atom((get) => {
return referenceSystem;
}
} else if (intersectionType === IntersectionType.CUSTOM_POLYLINE && customIntersectionPolyline) {
if (customIntersectionPolyline.polyline.length < 2) {
if (customIntersectionPolyline.points.length < 2) {
return null;
}
const referenceSystem = new IntersectionReferenceSystem(
customIntersectionPolyline.polyline.map((point) => [point[0], point[1], 0])
customIntersectionPolyline.points.map((point) => [point[0], point[1], 0])
);
referenceSystem.offset = 0;

Expand Down
Loading

0 comments on commit 43575bb

Please sign in to comment.