Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nilscognite committed Aug 20, 2024
1 parent ca195d4 commit 93bac8d
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export abstract class BaseCommand {
return false;
}

public get shortCutKeyOnAlt(): boolean {
return false;
}

public get shortCutKeyOnShift(): boolean {
return false;
}
Expand Down Expand Up @@ -172,6 +176,9 @@ export abstract class BaseCommand {
if (this.shortCutKeyOnCtrl) {
keys.push('Ctrl');
}
if (this.shortCutKeyOnAlt) {
keys.push('Alt');
}
if (this.shortCutKeyOnShift) {
keys.push('Shift');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* Copyright 2024 Cognite AS
*/

import { type TranslateKey } from '../utilities/TranslateKey';
import { clear } from '../utilities/extensions/arrayExtensions';
import { type BaseCommand } from './BaseCommand';
import { RenderTargetCommand } from './RenderTargetCommand';

export class SettingsCommand extends RenderTargetCommand {
export abstract class BaseSettingsCommand extends RenderTargetCommand {
// ==================================================
// INSTANCE FIELDS/PROPERTIES
// ==================================================
Expand All @@ -25,14 +25,6 @@ export class SettingsCommand extends RenderTargetCommand {
// OVERRIDES
// ==================================================

public override get tooltip(): TranslateKey {
return { key: 'SETTINGS_TOOLTIP', fallback: 'Settings' };
}

public override get icon(): string | undefined {
return 'Settings';
}

protected override *getChildren(): Generator<BaseCommand> {
if (this._children === undefined) {
return;
Expand All @@ -53,4 +45,8 @@ export class SettingsCommand extends RenderTargetCommand {
}
this._children.push(command);
}

public clear(): void {
clear(this._children);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
* Copyright 2024 Cognite AS
*/

import { BaseSettingsCommand } from '../BaseSettingsCommand';
import { MockActionCommand } from './MockActionCommand';
import { MockToggleCommand } from './MockToggleCommand';
import { MockCheckableCommand } from './MockCheckableCommand';
import { MockEnumOptionCommand } from './MockEnumOptionCommand';
import { MockSliderCommand } from './MockSliderCommand';
import { SettingsCommand } from '../SettingsCommand';
import { MockFilterCommand } from './MockFilterCommand';
import { type TranslateKey } from '../../utilities/TranslateKey';
import { MockNumberOptionCommand } from './MockNumberOptionCommand';
import { type TranslateKey } from '../../utilities/TranslateKey';

export class MockSettingsCommand extends SettingsCommand {
export class MockSettingsCommand extends BaseSettingsCommand {
// ==================================================
// INSTANCE FIELDS
// ==================================================
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*!
* Copyright 2024 Cognite AS
*/

import { BaseSettingsCommand } from '../commands/BaseSettingsCommand';
import { SetQualityCommand } from './SetQualityCommand';
import { SetPointSizeCommand } from './SetPointSizeCommand';
import { SetPointColorTypeCommand } from './SetPointColorTypeCommand';
import { SetPointShapeCommand } from './SetPointShapeCommand';
import { PointCloudFilterCommand } from './PointCloudFilterCommand';
import { type TranslateKey } from '../utilities/TranslateKey';

export class SettingsCommand extends BaseSettingsCommand {
// ==================================================
// CONSTRUCTOR
// ==================================================

public constructor() {
super();

this.add(new SetQualityCommand());
this.add(new SetPointSizeCommand());
this.add(new SetPointColorTypeCommand());
this.add(new SetPointShapeCommand());
this.add(new PointCloudFilterCommand());
}

// ==================================================
// OVERRIDES
// ==================================================

public override get tooltip(): TranslateKey {
return { key: 'SETTINGS_TOOLTIP', fallback: 'Settings' };
}

public override get icon(): string | undefined {
return 'Settings';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ import { MeasurementTool } from '../measurements/MeasurementTool';
import { ClipTool } from '../clipping/ClipTool';
import { KeyboardSpeedCommand } from '../../base/concreteCommands/KeyboardSpeedCommand';
import { ObservationsTool } from '../observations/ObservationsTool';
import { SettingsCommand } from '../../base/commands/SettingsCommand';
import { SetQualityCommand } from '../../base/concreteCommands/SetQualityCommand';
import { SetPointSizeCommand } from '../../base/concreteCommands/SetPointSizeCommand';
import { SetPointColorTypeCommand } from '../../base/concreteCommands/SetPointColorTypeCommand';
import { SetPointShapeCommand } from '../../base/concreteCommands/SetPointShapeCommand';
import { SettingsCommand } from '../../base/concreteCommands/SettingsCommand';
import { MockSettingsCommand } from '../../base/commands/mocks/MockSettingsCommand';
import { PointCloudFilterCommand } from '../../base/concreteCommands/PointCloudFilterCommand';
import { MockFilterCommand } from '../../base/commands/mocks/MockFilterCommand';

export class StoryBookConfig extends BaseRevealConfig {
Expand All @@ -40,13 +35,6 @@ export class StoryBookConfig extends BaseRevealConfig {
}

public override createMainToolbar(): Array<BaseCommand | undefined> {
const settings = new SettingsCommand();
settings.add(new SetQualityCommand());
settings.add(new SetPointSizeCommand());
settings.add(new SetPointColorTypeCommand());
settings.add(new SetPointShapeCommand());
settings.add(new PointCloudFilterCommand());

return [
new SetFlexibleControlsTypeCommand(FlexibleControlsType.Orbit),
new SetFlexibleControlsTypeCommand(FlexibleControlsType.FirstPerson),
Expand All @@ -55,7 +43,7 @@ export class StoryBookConfig extends BaseRevealConfig {
new SetAxisVisibleCommand(),
new ToggleMetricUnitsCommand(),
new KeyboardSpeedCommand(),
settings,
new SettingsCommand(),
new MockSettingsCommand(),
new MockFilterCommand(),
undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { OptionButton } from './OptionButton';
import { BaseOptionCommand } from '../../architecture/base/commands/BaseOptionCommand';
import { CommandButton } from './CommandButton';
import { SettingsButton } from './SettingsButton';
import { SettingsCommand } from '../../architecture/base/commands/SettingsCommand';
import { BaseSettingsCommand } from '../../architecture/base/commands/BaseSettingsCommand';
import { BaseFilterCommand } from '../../architecture/base/commands/BaseFilterCommand';
import { FilterButton } from './FilterButton';

export function createButton(command: BaseCommand, isHorizontal = false): ReactElement {
if (command instanceof BaseFilterCommand) {
return <FilterButton inputCommand={command} isHorizontal={isHorizontal} />;
}
if (command instanceof SettingsCommand) {
if (command instanceof BaseSettingsCommand) {
return <SettingsButton inputCommand={command} isHorizontal={isHorizontal} />;
}
if (command instanceof BaseOptionCommand) {
Expand Down
20 changes: 3 additions & 17 deletions react-components/src/components/Architecture/RevealButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@ import { MeasurementTool } from '../../architecture/concrete/measurements/Measur
import { KeyboardSpeedCommand } from '../../architecture/base/concreteCommands/KeyboardSpeedCommand';
import { ObservationsTool } from '../../architecture/concrete/observations/ObservationsTool';
import { createButtonFromCommandConstructor } from './CommandButtons';
import { SettingsCommand } from '../../architecture/base/commands/SettingsCommand';
import { SetPointColorTypeCommand } from '../../architecture/base/concreteCommands/SetPointColorTypeCommand';
import { SetPointShapeCommand } from '../../architecture/base/concreteCommands/SetPointShapeCommand';
import { SetPointSizeCommand } from '../../architecture/base/concreteCommands/SetPointSizeCommand';
import { SetQualityCommand } from '../../architecture/base/concreteCommands/SetQualityCommand';
import { PointCloudFilterCommand } from '../../architecture/base/concreteCommands/PointCloudFilterCommand';
import { SettingsCommand } from '../../architecture/base/concreteCommands/SettingsCommand';

export class RevealButtons {
static Settings = (): ReactElement => createButtonFromCommandConstructor(() => createSettings());
static Settings = (): ReactElement =>
createButtonFromCommandConstructor(() => new SettingsCommand());

static FitView = (): ReactElement =>
createButtonFromCommandConstructor(() => new FitViewCommand());
Expand Down Expand Up @@ -54,13 +50,3 @@ export class RevealButtons {
static KeyboardSpeed = (): ReactElement =>
createButtonFromCommandConstructor(() => new KeyboardSpeedCommand());
}

function createSettings(): SettingsCommand {
const settings = new SettingsCommand();
settings.add(new SetQualityCommand());
settings.add(new SetPointSizeCommand());
settings.add(new SetPointColorTypeCommand());
settings.add(new SetPointShapeCommand());
settings.add(new PointCloudFilterCommand());
return settings;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import { LabelWithShortcut } from './LabelWithShortcut';
import { type TranslateDelegate } from '../../architecture/base/utilities/TranslateKey';
import styled from 'styled-components';
import { type SettingsCommand } from '../../architecture/base/commands/SettingsCommand';
import { type BaseSettingsCommand } from '../../architecture/base/commands/BaseSettingsCommand';
import { BaseOptionCommand } from '../../architecture/base/commands/BaseOptionCommand';
import { OptionButton } from './OptionButton';
import { BaseSliderCommand } from '../../architecture/base/commands/BaseSliderCommand';
Expand All @@ -35,13 +35,13 @@ export const SettingsButton = ({
inputCommand,
isHorizontal = false
}: {
inputCommand: SettingsCommand;
inputCommand: BaseSettingsCommand;
isHorizontal: boolean;
}): ReactElement => {
const renderTarget = useRenderTarget();
const { t } = useTranslation();
const command = useMemo<SettingsCommand>(
() => getDefaultCommand<SettingsCommand>(inputCommand, renderTarget),
const command = useMemo<BaseSettingsCommand>(
() => getDefaultCommand<BaseSettingsCommand>(inputCommand, renderTarget),
[]
);

Expand Down

0 comments on commit 93bac8d

Please sign in to comment.