Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat (react-components): Export the base classes and some utility from the new architecture #4714

Merged
merged 5 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions react-components/src/architecture/base/commands/BaseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -130,24 +137,24 @@ 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);
}

public removeEventListeners(): void {
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);
}
}

Expand Down
5 changes: 3 additions & 2 deletions react-components/src/architecture/base/commands/BaseTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -45,6 +46,7 @@ export class ObservationsTool extends BaseEditTool {
}

public override onDeactivate(): void {
super.onDeactivate();
const domainObject = this.getObservationsDomainObject();
domainObject?.setSelectedObservation(undefined);
}
Expand Down
86 changes: 86 additions & 0 deletions react-components/src/architecture/index.ts
Original file line number Diff line number Diff line change
@@ -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';
16 changes: 12 additions & 4 deletions react-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Loading