diff --git a/react-components/src/architecture/base/commands/BaseCommand.ts b/react-components/src/architecture/base/commands/BaseCommand.ts index 8b73bb262af..e3a2050450f 100644 --- a/react-components/src/architecture/base/commands/BaseCommand.ts +++ b/react-components/src/architecture/base/commands/BaseCommand.ts @@ -5,7 +5,14 @@ import { type TranslateDelegate, type TranslateKey } from '../utilities/TranslateKey'; import { clear, remove } from '../utilities/extensions/arrayExtensions'; -type UpdateDelegate = (command: BaseCommand) => void; +/** + * Represents a delegate function for updating a command. + * + * @param command - The command to be updated. + * @param change - An optional symbol representing the change made to the command. + * if not set, anything can be changed. See changes is CommandChanges for common legal changes. + */ +export type CommandUpdateDelegate = (command: BaseCommand, change?: symbol) => void; /** * Base class for all command and tools. These are object that can do a @@ -20,7 +27,7 @@ export abstract class BaseCommand { // INSTANCE FIELDS // ================================================== - private readonly _listeners: UpdateDelegate[] = []; + private readonly _listeners: CommandUpdateDelegate[] = []; // Unique id for the command, used by in React to force rerender // when the command changes for a button. @@ -130,11 +137,11 @@ export abstract class BaseCommand { // INSTANCE METHODS: Event listeners // ================================================== - public addEventListener(listener: UpdateDelegate): void { + public addEventListener(listener: CommandUpdateDelegate): void { this._listeners.push(listener); } - public removeEventListener(listener: UpdateDelegate): void { + public removeEventListener(listener: CommandUpdateDelegate): void { remove(this._listeners, listener); } @@ -142,12 +149,12 @@ export abstract class BaseCommand { clear(this._listeners); } - public update(): void { + public update(change?: symbol): void { for (const listener of this._listeners) { - listener(this); + listener(this, change); } for (const child of this.getChildren()) { - child.update(); + child.update(change); } } diff --git a/react-components/src/architecture/base/commands/BaseTool.ts b/react-components/src/architecture/base/commands/BaseTool.ts index 38828620367..fb73daef083 100644 --- a/react-components/src/architecture/base/commands/BaseTool.ts +++ b/react-components/src/architecture/base/commands/BaseTool.ts @@ -22,6 +22,7 @@ import { ActiveToolUpdater } from '../reactUpdaters/ActiveToolUpdater'; import { PopupStyle } from '../domainObjectsHelpers/PopupStyle'; import { ThreeView } from '../views/ThreeView'; import { UndoManager } from '../undo/UndoManager'; +import { CommandChanges } from '../domainObjectsHelpers/CommandChanges'; /** * Base class for interactions in the 3D viewer @@ -70,14 +71,14 @@ export abstract class BaseTool extends RenderTargetCommand { } public onActivate(): void { - this.update(); + this.update(CommandChanges.active); this.setDefaultCursor(); this.clearDragging(); ActiveToolUpdater.update(); } public onDeactivate(): void { - this.update(); + this.update(CommandChanges.deactive); this.clearDragging(); ActiveToolUpdater.update(); } diff --git a/react-components/src/architecture/base/domainObjectsHelpers/CommandChanges.ts b/react-components/src/architecture/base/domainObjectsHelpers/CommandChanges.ts new file mode 100644 index 00000000000..a594fa719db --- /dev/null +++ b/react-components/src/architecture/base/domainObjectsHelpers/CommandChanges.ts @@ -0,0 +1,8 @@ +/*! + * Copyright 2024 Cognite AS + */ + +export class CommandChanges { + public static readonly active: symbol = Symbol('active'); + public static readonly deactive: symbol = Symbol('deactive'); +} diff --git a/react-components/src/architecture/concrete/observations/ObservationsTool.ts b/react-components/src/architecture/concrete/observations/ObservationsTool.ts index e3c63ef7ec1..93a262736f3 100644 --- a/react-components/src/architecture/concrete/observations/ObservationsTool.ts +++ b/react-components/src/architecture/concrete/observations/ObservationsTool.ts @@ -36,6 +36,7 @@ export class ObservationsTool extends BaseEditTool { } public override onActivate(): void { + super.onActivate(); let domainObject = this.getObservationsDomainObject(); if (domainObject === undefined) { domainObject = new ObservationsDomainObject(this.renderTarget.fdmSdk); @@ -45,6 +46,7 @@ export class ObservationsTool extends BaseEditTool { } public override onDeactivate(): void { + super.onDeactivate(); const domainObject = this.getObservationsDomainObject(); domainObject?.setSelectedObservation(undefined); } diff --git a/react-components/src/architecture/index.ts b/react-components/src/architecture/index.ts new file mode 100644 index 00000000000..9d9813a0397 --- /dev/null +++ b/react-components/src/architecture/index.ts @@ -0,0 +1,86 @@ +/*! + * Copyright 2023 Cognite AS + */ +// New architecture: commands +export { BaseCommand } from './base/commands/BaseCommand'; +export type { CommandUpdateDelegate } from './base/commands/BaseCommand'; +export { BaseFilterCommand } from './base/commands/BaseFilterCommand'; +export { BaseOptionCommand } from './base/commands/BaseOptionCommand'; +export { BaseSliderCommand } from './base/commands/BaseSliderCommand'; +export { BaseTool } from './base/commands/BaseTool'; +export { DomainObjectCommand } from './base/commands/DomainObjectCommand'; +export { InstanceCommand } from './base/commands/InstanceCommand'; +export { RenderTargetCommand } from './base/commands/RenderTargetCommand'; +export { BaseEditTool } from './base/commands/BaseEditTool'; +export { SettingsCommand } from './base/commands/SettingsCommand'; +export { ShowAllDomainObjectsCommand } from './base/commands/ShowAllDomainObjectsCommand'; +export { ShowDomainObjectsOnTopCommand } from './base/commands/ShowDomainObjectsOnTopCommand'; + +// New architecture: concreteCommands +export { CopyToClipboardCommand } from './base/concreteCommands/CopyToClipboardCommand'; +export { DeleteDomainObjectCommand } from './base/concreteCommands/DeleteDomainObjectCommand'; +export { FitViewCommand } from './base/concreteCommands/FitViewCommand'; +export { KeyboardSpeedCommand } from './base/concreteCommands/KeyboardSpeedCommand'; +export { NavigationTool } from './base/concreteCommands/NavigationTool'; +export { PointCloudFilterCommand } from './base/concreteCommands/PointCloudFilterCommand'; +export { SetPointColorTypeCommand } from './base/concreteCommands/SetPointColorTypeCommand'; +export { SetPointShapeCommand } from './base/concreteCommands/SetPointShapeCommand'; +export { SetPointSizeCommand } from './base/concreteCommands/SetPointSizeCommand'; +export { SetQualityCommand } from './base/concreteCommands/SetQualityCommand'; +export { ToggleMetricUnitsCommand } from './base/concreteCommands/ToggleMetricUnitsCommand'; +export { UndoCommand } from './base/concreteCommands/UndoCommand'; + +// New architecture: domainObjects +export { DomainObject } from './base/domainObjects/DomainObject'; +export { FolderDomainObject } from './base/domainObjects/FolderDomainObject'; +export { RootDomainObject } from './base/domainObjects/RootDomainObject'; +export { VisualDomainObject } from './base/domainObjects/VisualDomainObject'; + +export { BaseRevealConfig } from './base/renderTarget/BaseRevealConfig'; +export { CommandsController } from './base/renderTarget/CommandsController'; +export { DefaultRevealConfig } from './base/renderTarget/DefaultRevealConfig'; +export { RevealRenderTarget } from './base/renderTarget/RevealRenderTarget'; +export { UnitSystem } from './base/renderTarget/UnitSystem'; + +// New architecture: renderStyles +export { RenderStyle } from './base/renderStyles/RenderStyle'; +export { CommonRenderStyle } from './base/renderStyles/CommonRenderStyle'; + +// New architecture: domainObjectsHelpers +export { BaseCreator } from './base/domainObjectsHelpers/BaseCreator'; +export { BaseDragger } from './base/domainObjectsHelpers/BaseDragger'; +export { Changes } from './base/domainObjectsHelpers/Changes'; +export { CommandChanges } from './base/domainObjectsHelpers/CommandChanges'; +export { ColorType } from './base/domainObjectsHelpers/ColorType'; +export { DomainObjectChange } from './base/domainObjectsHelpers/DomainObjectChange'; +export { FocusType } from './base/domainObjectsHelpers/FocusType'; +export { PanelInfo } from './base/domainObjectsHelpers/PanelInfo'; +export { PopupStyle } from './base/domainObjectsHelpers/PopupStyle'; +export { Quantity } from './base/domainObjectsHelpers/Quantity'; +export { Views } from './base/domainObjectsHelpers/Views'; +export { VisibleState } from './base/domainObjectsHelpers/VisibleState'; +export type { DomainObjectIntersection } from './base/domainObjectsHelpers/DomainObjectIntersection'; +export { isDomainObjectIntersection } from './base/domainObjectsHelpers/DomainObjectIntersection'; +export { isCustomObjectIntersection } from './base/domainObjectsHelpers/DomainObjectIntersection'; + +// New architecture: undo +export { DomainObjectTransaction } from './base/undo/DomainObjectTransaction'; +export { Transaction } from './base/undo/Transaction'; +export { UndoManager } from './base/undo/UndoManager'; + +// New architecture: utilities +export { ClosestGeometryFinder } from './base/utilities/geometry/ClosestGeometryFinder'; +export { Index2 } from './base/utilities/geometry/Index2'; +export { Range1 } from './base/utilities/geometry/Range1'; +export { Range3 } from './base/utilities/geometry/Range3'; +export { TrianglesBuffers } from './base/utilities/geometry/TrianglesBuffers'; +export { getNextColor } from './base/utilities/colors/getNextColor'; +export { getNextColorByIndex } from './base/utilities/colors/getNextColor'; +export { getResizeCursor } from './base/utilities/geometry/getResizeCursor'; +export type { TranslateDelegate } from './base/utilities/TranslateKey'; +export type { TranslateKey } from './base/utilities/TranslateKey'; + +// New architecture: views +export { BaseView } from './base/views/BaseView'; +export { GroupThreeView } from './base/views/GroupThreeView'; +export { ThreeView } from './base/views/ThreeView'; diff --git a/react-components/src/index.ts b/react-components/src/index.ts index bbc7b8b38e0..986ad954ca5 100644 --- a/react-components/src/index.ts +++ b/react-components/src/index.ts @@ -161,13 +161,21 @@ export type { CriteriaTypes } from './components/RuleBasedOutputs/types'; -export { ActiveToolToolbar } from './components/Architecture/Toolbar'; -export { DomainObjectPanel } from './components/Architecture/DomainObjectPanel'; -export { RevealButtons } from './components/Architecture/RevealButtons'; - export { RuleBasedOutputsPanel } from './components/RuleBasedOutputs/RuleBasedOutputsPanel'; // Functions export { getRuleTriggerTypes } from './components/RuleBasedOutputs/utils'; export type { InstanceReference, AssetInstanceReference } from './data-providers/types'; + +export { ActiveToolToolbar } from './components/Architecture/Toolbar'; +export { DomainObjectPanel } from './components/Architecture/DomainObjectPanel'; +export { RevealButtons } from './components/Architecture/RevealButtons'; +export { useRenderTarget } from './components/RevealCanvas/ViewerContext'; + +/** + * Export classes and types from architecture + * Note: This is not stable code yet and is subject to change. + * @beta + */ +export * as Architecture from './architecture/index';