From 8e397569067b9ad972b027a7ed226309ac2aad6f Mon Sep 17 00:00:00 2001 From: Nils Petter Fremming Date: Fri, 16 Aug 2024 10:38:41 +0200 Subject: [PATCH 1/7] Initial commit --- .../base/commands/mocks/MockFilterCommand.ts | 2 +- .../PointCloudFilterCommand.ts | 73 +++++++++++++++---- .../components/Architecture/FilterButton.tsx | 3 +- 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/react-components/src/architecture/base/commands/mocks/MockFilterCommand.ts b/react-components/src/architecture/base/commands/mocks/MockFilterCommand.ts index 44f0aa1f27a..92c249fd6fd 100644 --- a/react-components/src/architecture/base/commands/mocks/MockFilterCommand.ts +++ b/react-components/src/architecture/base/commands/mocks/MockFilterCommand.ts @@ -98,7 +98,7 @@ class FilterItemCommand extends BaseFilterItemCommand { return this._color; } - public setChecked(value: boolean): void { + public override setChecked(value: boolean): void { if (this._use === value) { return; } diff --git a/react-components/src/architecture/base/concreteCommands/PointCloudFilterCommand.ts b/react-components/src/architecture/base/concreteCommands/PointCloudFilterCommand.ts index 81b09377873..6700d7b485e 100644 --- a/react-components/src/architecture/base/concreteCommands/PointCloudFilterCommand.ts +++ b/react-components/src/architecture/base/concreteCommands/PointCloudFilterCommand.ts @@ -10,6 +10,11 @@ import { CommandsUpdater } from '../reactUpdaters/CommandsUpdater'; import { type RevealRenderTarget } from '../renderTarget/RevealRenderTarget'; export class PointCloudFilterCommand extends BaseFilterCommand { + // ================================================== + // INSTANCE FIELDS + // ================================================== + + private _modelId: number | undefined = undefined; private _revisionId: number | undefined = undefined; // ================================================== @@ -21,30 +26,28 @@ export class PointCloudFilterCommand extends BaseFilterCommand { } public override get isEnabled(): boolean { - const pointCloud = getFirstPointCloudWithClasses(this.renderTarget); - if (pointCloud === undefined) { - return false; - } - return true; + return this.getPointCloud() !== undefined; } public override initializeChildrenIfNeeded(): void { const pointCloud = getFirstPointCloudWithClasses(this.renderTarget); if (pointCloud === undefined) { this._children = undefined; + this._modelId = undefined; this._revisionId = undefined; return; } - if (this._revisionId === pointCloud.revisionId) { - return; + if (this._modelId === pointCloud.modelId && this._revisionId === pointCloud.revisionId) { + return; // Nothing changed } + this._modelId = pointCloud.modelId; this._revisionId = pointCloud.revisionId; this._children = undefined; super.initializeChildrenIfNeeded(); } protected createChildren(): FilterItemCommand[] { - const pointCloud = getFirstPointCloudWithClasses(this.renderTarget); + const pointCloud = this.getPointCloud(); if (pointCloud === undefined) { return []; } @@ -55,13 +58,13 @@ export class PointCloudFilterCommand extends BaseFilterCommand { const children = []; for (const c of classes) { const pointClass = new PointClass(c.name, c.code, c.color); - children.push(new FilterItemCommand(pointClass)); + children.push(new FilterItemCommand(pointClass, pointCloud.modelId, pointCloud.revisionId)); } return children; } public override get isAllChecked(): boolean { - const pointCloud = getFirstPointCloudWithClasses(this.renderTarget); + const pointCloud = this.getPointCloud(); if (pointCloud === undefined) { return false; } @@ -69,7 +72,7 @@ export class PointCloudFilterCommand extends BaseFilterCommand { } public override toggleAllChecked(): void { - const pointCloud = getFirstPointCloudWithClasses(this.renderTarget); + const pointCloud = this.getPointCloud(); if (pointCloud === undefined) { return; } @@ -82,19 +85,39 @@ export class PointCloudFilterCommand extends BaseFilterCommand { pointCloud.setClassVisible(c.code, !isAllChecked); } } + + // ================================================== + // INSTANCE METHODS + // ================================================== + + private getPointCloud(): CognitePointCloudModel | undefined { + if (this._modelId === undefined || this._revisionId === undefined) { + return undefined; + } + for (const pointCloud of this.renderTarget.getPointClouds()) { + if (this._modelId === pointCloud.modelId && this._revisionId === pointCloud.revisionId) { + return pointCloud; + } + } + return undefined; + } } // Note: This is not exported, as it is only used internally class FilterItemCommand extends BaseFilterItemCommand { + private readonly _modelId: number; + private readonly _revisionId: number; private readonly _pointClass: PointClass; // ================================================== // CONSTRUCTOR // ================================================== - public constructor(pointClass: PointClass) { + public constructor(pointClass: PointClass, modelId: number, revisionId: number) { super(); + this._modelId = modelId; + this._revisionId = revisionId; this._pointClass = pointClass; } @@ -107,7 +130,7 @@ class FilterItemCommand extends BaseFilterItemCommand { } public override get isChecked(): boolean { - const pointCloud = getFirstPointCloudWithClasses(this.renderTarget); + const pointCloud = this.getPointCloud(); if (pointCloud === undefined) { return false; } @@ -115,7 +138,7 @@ class FilterItemCommand extends BaseFilterItemCommand { } public override invokeCore(): boolean { - const pointCloud = getFirstPointCloudWithClasses(this.renderTarget); + const pointCloud = this.getPointCloud(); if (pointCloud === undefined) { return false; } @@ -128,14 +151,27 @@ class FilterItemCommand extends BaseFilterItemCommand { return this._pointClass.color; } - public setChecked(value: boolean): void { - const pointCloud = getFirstPointCloudWithClasses(this.renderTarget); + public override setChecked(value: boolean): void { + const pointCloud = this.getPointCloud(); if (pointCloud === undefined) { return; } pointCloud.setClassVisible(this._pointClass.code, value); CommandsUpdater.update(this._renderTarget); } + + // ================================================== + // INSTANCE METHODS + // ================================================== + + private getPointCloud(): CognitePointCloudModel | undefined { + for (const pointCloud of this.renderTarget.getPointClouds()) { + if (this._modelId === pointCloud.modelId && this._revisionId === pointCloud.revisionId) { + return pointCloud; + } + } + return undefined; + } } class PointClass { @@ -161,6 +197,10 @@ class PointClass { } } +// ================================================== +// PRIVATE FUNCTIONS +// ================================================== + function getFirstPointCloudWithClasses( renderTarget: RevealRenderTarget ): CognitePointCloudModel | undefined { @@ -169,6 +209,7 @@ function getFirstPointCloudWithClasses( if (classes === undefined || classes.length === 0) { continue; } + return pointCloud; } return undefined; } diff --git a/react-components/src/components/Architecture/FilterButton.tsx b/react-components/src/components/Architecture/FilterButton.tsx index d879d1e32b8..56c87d5e9a7 100644 --- a/react-components/src/components/Architecture/FilterButton.tsx +++ b/react-components/src/components/Architecture/FilterButton.tsx @@ -44,6 +44,8 @@ export const FilterButton = ({ [] ); + command.initializeChildrenIfNeeded(); + const [isEnabled, setEnabled] = useState(true); const [isVisible, setVisible] = useState(true); const [uniqueId, setUniqueId] = useState(0); @@ -94,7 +96,6 @@ export const FilterButton = ({ const shortcut = command.getShortCutKeys(); const flexDirection = getFlexDirection(isHorizontal); - command.initializeChildrenIfNeeded(); const children = command.children; if (children === undefined || !command.hasChildren) { return <>; From 63706623325ce09ec00a6ed943b0fe4dac3716f5 Mon Sep 17 00:00:00 2001 From: Nils Petter Fremming Date: Fri, 16 Aug 2024 14:47:27 +0200 Subject: [PATCH 2/7] Fix styling --- react-components/src/components/Architecture/FilterItem.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/react-components/src/components/Architecture/FilterItem.tsx b/react-components/src/components/Architecture/FilterItem.tsx index 194b2aeea3d..b1ce4bb4e9f 100644 --- a/react-components/src/components/Architecture/FilterItem.tsx +++ b/react-components/src/components/Architecture/FilterItem.tsx @@ -61,8 +61,9 @@ const ColorBox = styled.div<{ backgroundColor: Color }>` `; const CenteredContainer = styled.div` + padding: 0px 1px; display: flex; row-gap: 3px; - gap: 3px; + gap: 4px; align-items: center; `; From 954fa0bb5f8d7c6ae700248677df84879ddedc56 Mon Sep 17 00:00:00 2001 From: Nils Petter Fremming Date: Fri, 16 Aug 2024 21:50:25 +0200 Subject: [PATCH 3/7] Fixed minor things --- .../concrete/clipping/commands/ApplyClipCommand.ts | 11 +++++++---- .../src/components/Architecture/utilities.ts | 6 +----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/react-components/src/architecture/concrete/clipping/commands/ApplyClipCommand.ts b/react-components/src/architecture/concrete/clipping/commands/ApplyClipCommand.ts index 24dec061358..9f5f4bcf7e4 100644 --- a/react-components/src/architecture/concrete/clipping/commands/ApplyClipCommand.ts +++ b/react-components/src/architecture/concrete/clipping/commands/ApplyClipCommand.ts @@ -31,8 +31,9 @@ export class ApplyClipCommand extends RenderTargetCommand { } public override get isEnabled(): boolean { - if (this.getSelectedCropBoxDomainObject() !== undefined) { - return true; + const cropBox = this.getSelectedCropBoxDomainObject(); + if (cropBox !== undefined) { + return cropBox.focusType !== FocusType.Pending; } if (this.rootDomainObject.getDescendantByType(SliceDomainObject) !== undefined) { return true; @@ -56,8 +57,10 @@ export class ApplyClipCommand extends RenderTargetCommand { } const cropBox = this.getSelectedCropBoxDomainObject(); if (cropBox !== undefined) { - cropBox.setThisAsGlobalCropBox(); - renderTarget.fitView(); + if (cropBox.focusType !== FocusType.Pending) { + cropBox.setThisAsGlobalCropBox(); + renderTarget.fitView(); + } } else { ApplyClipCommand.setClippingPlanes(this.rootDomainObject); } diff --git a/react-components/src/components/Architecture/utilities.ts b/react-components/src/components/Architecture/utilities.ts index 71dc19f0d2e..a339f5b1c02 100644 --- a/react-components/src/components/Architecture/utilities.ts +++ b/react-components/src/components/Architecture/utilities.ts @@ -25,11 +25,7 @@ export function getTooltipPlacement(isHorizontal: boolean): PlacementType { export function getButtonType(command: BaseCommand): ButtonType { // This was the only way it went through compiler: (more button types will be added in the future) - const type = command.buttonType; - if (type === 'ghost' || type === 'ghost-destructive' || type === 'primary') { - return type; - } - return 'ghost'; + return command.buttonType as ButtonType; } export function getDefaultCommand( From aa0a10bd8e066e332babd8764e5ae8582e331e89 Mon Sep 17 00:00:00 2001 From: Nils Petter Fremming Date: Sat, 17 Aug 2024 10:43:47 +0200 Subject: [PATCH 4/7] Update BaseFilterCommand.ts --- .../base/commands/BaseFilterCommand.ts | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/react-components/src/architecture/base/commands/BaseFilterCommand.ts b/react-components/src/architecture/base/commands/BaseFilterCommand.ts index cc4c48ea61f..2079acb1a16 100644 --- a/react-components/src/architecture/base/commands/BaseFilterCommand.ts +++ b/react-components/src/architecture/base/commands/BaseFilterCommand.ts @@ -91,32 +91,20 @@ export abstract class BaseFilterCommand extends RenderTargetCommand { public getSelectedLabel(translate: TranslateDelegate): string { if (this._children === undefined) { - return this.getNoneLabel(translate); + return getNoneLabel(translate); } const selected = this._children.filter((child) => child.isChecked); const counter = selected.length; if (counter === 0) { - return this.getNoneLabel(translate); + return getNoneLabel(translate); } if (counter === this._children.length) { - return this.getAllLabel(translate); + return getAllLabel(translate); } if (counter === 1) { return selected[0].getLabel(translate); } - return counter.toString() + ' ' + this.getSelected(translate); - } - - public getAllLabel(translate: TranslateDelegate): string { - return translate('ALL', 'All'); - } - - public getNoneLabel(translate: TranslateDelegate): string { - return translate('NONE', 'None'); - } - - public getSelected(translate: TranslateDelegate): string { - return translate('SELECTED', 'Selected'); + return counter.toString() + ' ' + getSelectedLabel(translate); } } @@ -124,3 +112,19 @@ export abstract class BaseFilterItemCommand extends RenderTargetCommand { public abstract get color(): Color | undefined; public abstract setChecked(value: boolean): void; } + +// ================================================== +// PRIVATE FUNCTIONS +// ================================================== + +function getAllLabel(translate: TranslateDelegate): string { + return translate('ALL', 'All'); +} + +function getNoneLabel(translate: TranslateDelegate): string { + return translate('NONE', 'None'); +} + +function getSelectedLabel(translate: TranslateDelegate): string { + return translate('SELECTED', 'Selected'); +} From d4a122e2fb60a52871bd22d0787d8a8c26b79cd0 Mon Sep 17 00:00:00 2001 From: Nils Petter Fremming Date: Sat, 17 Aug 2024 10:44:40 +0200 Subject: [PATCH 5/7] Update Transaction.ts --- react-components/src/architecture/base/undo/Transaction.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/react-components/src/architecture/base/undo/Transaction.ts b/react-components/src/architecture/base/undo/Transaction.ts index 0caafb4687e..517d97a0457 100644 --- a/react-components/src/architecture/base/undo/Transaction.ts +++ b/react-components/src/architecture/base/undo/Transaction.ts @@ -29,7 +29,6 @@ export abstract class Transaction { throw new Error('Parent is undefined'); } this.parentUniqueId = parent.uniqueId; - // console.log('Add transaction:', this.changed); } // ================================================== @@ -52,7 +51,6 @@ export abstract class Transaction { if (domainObject === undefined) { return false; } - // console.log('Undo transaction:', this.changed); this.undoCore(domainObject, root.renderTarget); return true; } From 3f66667a81564a2fae48ccd5cf04306ea43febcc Mon Sep 17 00:00:00 2001 From: Nils Petter Fremming Date: Sat, 17 Aug 2024 10:53:02 +0200 Subject: [PATCH 6/7] Make static --- .../base/commands/BaseFilterCommand.ts | 38 +++++++++---------- .../components/Architecture/FilterButton.tsx | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/react-components/src/architecture/base/commands/BaseFilterCommand.ts b/react-components/src/architecture/base/commands/BaseFilterCommand.ts index 2079acb1a16..97fa3f8553c 100644 --- a/react-components/src/architecture/base/commands/BaseFilterCommand.ts +++ b/react-components/src/architecture/base/commands/BaseFilterCommand.ts @@ -91,40 +91,40 @@ export abstract class BaseFilterCommand extends RenderTargetCommand { public getSelectedLabel(translate: TranslateDelegate): string { if (this._children === undefined) { - return getNoneLabel(translate); + return BaseFilterCommand.getNoneString(translate); } const selected = this._children.filter((child) => child.isChecked); const counter = selected.length; if (counter === 0) { - return getNoneLabel(translate); + return BaseFilterCommand.getNoneString(translate); } if (counter === this._children.length) { - return getAllLabel(translate); + return BaseFilterCommand.getAllString(translate); } if (counter === 1) { return selected[0].getLabel(translate); } - return counter.toString() + ' ' + getSelectedLabel(translate); + return counter.toString() + ' ' + BaseFilterCommand.getSelectedString(translate); } -} -export abstract class BaseFilterItemCommand extends RenderTargetCommand { - public abstract get color(): Color | undefined; - public abstract setChecked(value: boolean): void; -} + // ================================================== + // STATIC METHODS + // ================================================== -// ================================================== -// PRIVATE FUNCTIONS -// ================================================== + public static getAllString(translate: TranslateDelegate): string { + return translate('ALL', 'All'); + } -function getAllLabel(translate: TranslateDelegate): string { - return translate('ALL', 'All'); -} + private static getNoneString(translate: TranslateDelegate): string { + return translate('NONE', 'None'); + } -function getNoneLabel(translate: TranslateDelegate): string { - return translate('NONE', 'None'); + private static getSelectedString(translate: TranslateDelegate): string { + return translate('SELECTED', 'Selected'); + } } -function getSelectedLabel(translate: TranslateDelegate): string { - return translate('SELECTED', 'Selected'); +export abstract class BaseFilterItemCommand extends RenderTargetCommand { + public abstract get color(): Color | undefined; + public abstract setChecked(value: boolean): void; } diff --git a/react-components/src/components/Architecture/FilterButton.tsx b/react-components/src/components/Architecture/FilterButton.tsx index 56c87d5e9a7..d46cec944d0 100644 --- a/react-components/src/components/Architecture/FilterButton.tsx +++ b/react-components/src/components/Architecture/FilterButton.tsx @@ -125,7 +125,7 @@ export const FilterButton = ({ onClick={() => { command.toggleAllChecked(); }}> - {command.getAllLabel(t)} + {BaseFilterCommand.getAllString(t)} {children.map((child, _index): ReactElement => { From b96066dd6440637627cb092653028b4e55978902 Mon Sep 17 00:00:00 2001 From: Nils Petter Fremming Date: Mon, 19 Aug 2024 09:49:03 +0200 Subject: [PATCH 7/7] Smaller fixes --- .../architecture/base/commands/mocks/MockFilterCommand.ts | 2 +- .../base/concreteCommands/PointCloudFilterCommand.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/react-components/src/architecture/base/commands/mocks/MockFilterCommand.ts b/react-components/src/architecture/base/commands/mocks/MockFilterCommand.ts index 92c249fd6fd..856cbd54138 100644 --- a/react-components/src/architecture/base/commands/mocks/MockFilterCommand.ts +++ b/react-components/src/architecture/base/commands/mocks/MockFilterCommand.ts @@ -14,7 +14,7 @@ export class MockFilterCommand extends BaseFilterCommand { private _timeStamp: number | undefined = undefined; private _useAllColor: boolean = true; - private readonly _testDynamic: boolean = false; + private readonly _testDynamic: boolean = false; // True to test dynamic updates (for testing purposes) // ================================================== // OVERRIDES diff --git a/react-components/src/architecture/base/concreteCommands/PointCloudFilterCommand.ts b/react-components/src/architecture/base/concreteCommands/PointCloudFilterCommand.ts index 6700d7b485e..267ead40d55 100644 --- a/react-components/src/architecture/base/concreteCommands/PointCloudFilterCommand.ts +++ b/react-components/src/architecture/base/concreteCommands/PointCloudFilterCommand.ts @@ -46,7 +46,7 @@ export class PointCloudFilterCommand extends BaseFilterCommand { super.initializeChildrenIfNeeded(); } - protected createChildren(): FilterItemCommand[] { + protected override createChildren(): FilterItemCommand[] { const pointCloud = this.getPointCloud(); if (pointCloud === undefined) { return []; @@ -68,7 +68,7 @@ export class PointCloudFilterCommand extends BaseFilterCommand { if (pointCloud === undefined) { return false; } - return isClassesVisible(pointCloud); + return isAllClassesVisible(pointCloud); } public override toggleAllChecked(): void { @@ -76,7 +76,7 @@ export class PointCloudFilterCommand extends BaseFilterCommand { if (pointCloud === undefined) { return; } - const isAllChecked = isClassesVisible(pointCloud); + const isAllChecked = isAllClassesVisible(pointCloud); const classes = pointCloud.getClasses(); if (classes === undefined || classes.length === 0) { return; @@ -214,7 +214,7 @@ function getFirstPointCloudWithClasses( return undefined; } -function isClassesVisible(pointCloud: CognitePointCloudModel): boolean { +function isAllClassesVisible(pointCloud: CognitePointCloudModel): boolean { const classes = pointCloud.getClasses(); if (classes === undefined || classes.length === 0) { return false;