diff --git a/frontend/src/modules/LayerSpike/layers/implementations/layers/RealizationFaultPolygonsLayer/RealizationFaultPolygonsContext.ts b/frontend/src/modules/LayerSpike/layers/implementations/layers/RealizationFaultPolygonsLayer/RealizationFaultPolygonsContext.ts index a9cca3a0a..a7e40bf1e 100644 --- a/frontend/src/modules/LayerSpike/layers/implementations/layers/RealizationFaultPolygonsLayer/RealizationFaultPolygonsContext.ts +++ b/frontend/src/modules/LayerSpike/layers/implementations/layers/RealizationFaultPolygonsLayer/RealizationFaultPolygonsContext.ts @@ -12,7 +12,9 @@ import { SettingsContext } from "../../../interfaces"; import { Ensemble } from "../../settings/Ensemble"; import { Realization } from "../../settings/Realization"; import { SurfaceAttribute } from "../../settings/SurfaceAttribute"; +import { SurfaceLayer } from "../../settings/SurfaceLayer"; import { SurfaceName } from "../../settings/SurfaceName"; +import { extractSurfaceNamesAndLayers } from "../../utils/surfaceNamesAndLayers"; export class RealizationFaultPolygonsContext implements SettingsContext { private _contextDelegate: SettingsContextDelegate; @@ -27,6 +29,7 @@ export class RealizationFaultPolygonsContext implements SettingsContext el.surfaceName); let currentSurfaceName = settings[SettingType.SURFACE_NAME].getDelegate().getValue(); - if (!currentSurfaceName || !availableSurfaceNames.includes(currentSurfaceName)) { - if (availableSurfaceNames.length > 0) { - currentSurfaceName = availableSurfaceNames[0]; + if (!currentSurfaceName || !surfaceNames.includes(currentSurfaceName)) { + if (surfaceNames.length > 0) { + currentSurfaceName = surfaceNames[0]; settings[SettingType.SURFACE_NAME].getDelegate().setValue(currentSurfaceName); } } + this._contextDelegate.setAvailableValues(SettingType.SURFACE_NAME, surfaceNames); + + const surfaceLayers = + surfaceNamesAndLayers.find((el) => el.surfaceName === currentSurfaceName)?.surfaceLayers ?? []; + let currentSurfaceLayer = settings[SettingType.SURFACE_LAYER].getDelegate().getValue(); + if (!currentSurfaceLayer || !surfaceLayers.includes(currentSurfaceLayer)) { + if (surfaceLayers.length > 0) { + currentSurfaceLayer = surfaceLayers[0]; + settings[SettingType.SURFACE_LAYER].getDelegate().setValue(currentSurfaceLayer); + } + } + if (surfaceLayers.length === 0) { + surfaceLayers.push("DEFAULT"); + settings[SettingType.SURFACE_LAYER].getDelegate().setValue("DEFAULT"); + } + this._contextDelegate.setAvailableValues(SettingType.SURFACE_LAYER, surfaceLayers); } fetchData(oldValues: RealizationFaultPolygonsSettings, newValues: RealizationFaultPolygonsSettings): void { @@ -136,6 +158,7 @@ export class RealizationFaultPolygonsContext implements SettingsContext { private _layerDelegate: LayerDelegate; @@ -46,6 +47,8 @@ export class RealizationFaultPolygonsLayer implements Layer { private _contextDelegate: SettingsContextDelegate; @@ -29,6 +31,7 @@ export class RealizationSurfaceContext implements SettingsContext el.surfaceName); let currentSurfaceName = settings[SettingType.SURFACE_NAME].getDelegate().getValue(); - if (!currentSurfaceName || !availableSurfaceNames.includes(currentSurfaceName)) { - if (availableSurfaceNames.length > 0) { - currentSurfaceName = availableSurfaceNames[0]; + if (!currentSurfaceName || !surfaceNames.includes(currentSurfaceName)) { + if (surfaceNames.length > 0) { + currentSurfaceName = surfaceNames[0]; settings[SettingType.SURFACE_NAME].getDelegate().setValue(currentSurfaceName); } } + this._contextDelegate.setAvailableValues(SettingType.SURFACE_NAME, surfaceNames); + + const surfaceLayers = + surfaceNamesAndLayers.find((el) => el.surfaceName === currentSurfaceName)?.surfaceLayers ?? []; + let currentSurfaceLayer = settings[SettingType.SURFACE_LAYER].getDelegate().getValue(); + if (!currentSurfaceLayer || !surfaceLayers.includes(currentSurfaceLayer)) { + if (surfaceLayers.length > 0) { + currentSurfaceLayer = surfaceLayers[0]; + settings[SettingType.SURFACE_LAYER].getDelegate().setValue(currentSurfaceLayer); + } + } + if (surfaceLayers.length === 0) { + surfaceLayers.push("DEFAULT"); + settings[SettingType.SURFACE_LAYER].getDelegate().setValue("DEFAULT"); + } + this._contextDelegate.setAvailableValues(SettingType.SURFACE_LAYER, surfaceLayers); const availableTimeOrIntervals: string[] = []; if (currentAttribute && currentSurfaceName) { + const combinedSurfaceName = combineSurfaceNameAndLayer(currentSurfaceName, currentSurfaceLayer); const availableTimeTypes: SurfaceTimeType_api[] = []; availableTimeTypes.push( ...Array.from( @@ -97,7 +120,7 @@ export class RealizationSurfaceContext implements SettingsContext - surface.attribute_name === currentAttribute && surface.name === currentSurfaceName + surface.attribute_name === currentAttribute && surface.name === combinedSurfaceName ) .map((el) => el.time_type) ) @@ -168,7 +191,9 @@ export class RealizationSurfaceContext implements SettingsContext @@ -54,12 +55,14 @@ export class RealizationSurfaceLayer const ensembleIdent = settings[SettingType.ENSEMBLE].getDelegate().getValue(); const realizationNum = settings[SettingType.REALIZATION].getDelegate().getValue(); const surfaceName = settings[SettingType.SURFACE_NAME].getDelegate().getValue(); + const surfaceLayer = settings[SettingType.SURFACE_LAYER].getDelegate().getValue(); + const combinedSurfaceName = combineSurfaceNameAndLayer(surfaceName, surfaceLayer); const attribute = settings[SettingType.SURFACE_ATTRIBUTE].getDelegate().getValue(); const timeOrInterval = settings[SettingType.TIME_OR_INTERVAL].getDelegate().getValue(); - if (ensembleIdent && surfaceName && attribute && realizationNum !== null) { + if (ensembleIdent && combinedSurfaceName && attribute && realizationNum !== null) { addrBuilder.withEnsembleIdent(ensembleIdent); - addrBuilder.withName(surfaceName); + addrBuilder.withName(combinedSurfaceName); addrBuilder.withAttribute(attribute); addrBuilder.withRealization(realizationNum); diff --git a/frontend/src/modules/LayerSpike/layers/implementations/layers/RealizationSurfaceLayer/types.ts b/frontend/src/modules/LayerSpike/layers/implementations/layers/RealizationSurfaceLayer/types.ts index ed394d6c0..3fe1c8c8d 100644 --- a/frontend/src/modules/LayerSpike/layers/implementations/layers/RealizationSurfaceLayer/types.ts +++ b/frontend/src/modules/LayerSpike/layers/implementations/layers/RealizationSurfaceLayer/types.ts @@ -7,5 +7,6 @@ export type RealizationSurfaceSettings = { [SettingType.REALIZATION]: number | null; [SettingType.SURFACE_ATTRIBUTE]: string | null; [SettingType.SURFACE_NAME]: string | null; + [SettingType.SURFACE_LAYER]: string | null; [SettingType.TIME_OR_INTERVAL]: string | null; }; diff --git a/frontend/src/modules/LayerSpike/layers/implementations/settings/SurfaceLayer.tsx b/frontend/src/modules/LayerSpike/layers/implementations/settings/SurfaceLayer.tsx new file mode 100644 index 000000000..d52f367e1 --- /dev/null +++ b/frontend/src/modules/LayerSpike/layers/implementations/settings/SurfaceLayer.tsx @@ -0,0 +1,46 @@ +import React from "react"; + +import { Dropdown, DropdownOption } from "@lib/components/Dropdown"; + +import { SettingDelegate } from "../../delegates/SettingDelegate"; +import { Setting, SettingComponentProps } from "../../interfaces"; +import { SettingType } from "../../settingsTypes"; + +type ValueType = string | null; + +export class SurfaceLayer implements Setting { + private _delegate: SettingDelegate = new SettingDelegate(null); + + getType(): SettingType { + return SettingType.SURFACE_LAYER; + } + + getLabel(): string { + return "Surface layer"; + } + + getDelegate(): SettingDelegate { + return this._delegate; + } + + makeComponent(): (props: SettingComponentProps) => React.ReactNode { + return function SurfaceLayer(props: SettingComponentProps) { + const options: DropdownOption[] = props.availableValues.map((value) => { + return { + value: value.toString(), + label: value === null ? "None" : value.toString(), + }; + }); + + return ( + + ); + }; + } +} diff --git a/frontend/src/modules/LayerSpike/layers/implementations/utils/surfaceNamesAndLayers.ts b/frontend/src/modules/LayerSpike/layers/implementations/utils/surfaceNamesAndLayers.ts new file mode 100644 index 000000000..d828b6ae5 --- /dev/null +++ b/frontend/src/modules/LayerSpike/layers/implementations/utils/surfaceNamesAndLayers.ts @@ -0,0 +1,32 @@ +export function extractSurfaceNamesAndLayers(surfaceNamesAndLayers: string[]): { + surfaceName: string; + surfaceLayers: string[]; +}[] { + const surfaceNamesAndLayersMap: Map> = new Map(); + + const regex = /^([\w .]+?)( (top|bottom))?$/i; + + for (const surfaceNameOrLayer of surfaceNamesAndLayers) { + const match = regex.exec(surfaceNameOrLayer); + if (match) { + const [, surfaceName, , surfaceLayer] = match; + const surfaceLayers = surfaceNamesAndLayersMap.get(surfaceName) || new Set(); + if (surfaceLayer) { + surfaceLayers.add(surfaceLayer); + } + surfaceNamesAndLayersMap.set(surfaceName, surfaceLayers); + } + } + + return Array.from(surfaceNamesAndLayersMap.entries()).map(([surfaceName, surfaceLayers]) => ({ + surfaceName, + surfaceLayers: Array.from(surfaceLayers), + })); +} + +export function combineSurfaceNameAndLayer(surfaceName: string | null, surfaceLayer: string | null): string | null { + if (!surfaceName || !surfaceLayer) { + return null; + } + return surfaceLayer !== "DEFAULT" ? `${surfaceName} ${surfaceLayer}` : surfaceName; +} diff --git a/frontend/src/modules/LayerSpike/layers/settingsTypes.ts b/frontend/src/modules/LayerSpike/layers/settingsTypes.ts index bea89b38e..936a97191 100644 --- a/frontend/src/modules/LayerSpike/layers/settingsTypes.ts +++ b/frontend/src/modules/LayerSpike/layers/settingsTypes.ts @@ -5,6 +5,7 @@ export enum SettingType { SENSITIVITY = "sensitivity", SURFACE_NAME = "surfaceName", SURFACE_ATTRIBUTE = "surfaceAttribute", + SURFACE_LAYER = "surfaceLayer", TIME_OR_INTERVAL = "timeOrInterval", FAULT_POLYGONS_ATTRIBUTE = "faultPolygonsAttribute", SMDA_WELLBORE_HEADERS = "smdaWellboreHeaders",