Skip to content

Commit

Permalink
react-components (feat) Attemt on making a configurative startUp func…
Browse files Browse the repository at this point in the history
…tion (#4571)

* Initial commit

* Update BaseTool.ts
  • Loading branch information
nilscognite authored Jun 5, 2024
1 parent 36188d0 commit aed9b28
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export abstract class BaseTool extends RenderTargetCommand {
): Promise<AnyIntersection | undefined> {
const { renderTarget } = this;
const { viewer } = renderTarget;

const point = viewer.getPixelCoordinatesFromEvent(event);
const intersection = await viewer.getAnyIntersectionFromPixel(point);
if (intersection === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { type BaseCommand } from '../commands/BaseCommand';
import { PopupStyle } from '../domainObjectsHelpers/PopupStyle';
import { NavigationTool } from '../commands/NavigationTool';
import { type BaseTool } from '../commands/BaseTool';
import { type RevealRenderTarget } from './RevealRenderTarget';

export abstract class BaseRevealConfig {
// ==================================================
Expand All @@ -28,4 +29,6 @@ export abstract class BaseRevealConfig {
public createDefaultTool(): BaseTool {
return new NavigationTool();
}

public onStartup(_renderTarget: RevealRenderTarget): void {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ export class RevealRenderTarget {
}
}

public onStartup(): void {
this._config?.onStartup(this);
}

public dispose(): void {
this._viewer.dispose();
if (this._ambientLight !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ExampleTool } from '../exampleDomainObject/ExampleTool';
import { MeasurementTool } from '../boxDomainObject/MeasurementTool';
import { AxisGizmoTool } from '@cognite/reveal/tools';
import { BaseRevealConfig } from '../../base/renderTarget/BaseRevealConfig';
import { type RevealRenderTarget } from '../../base/renderTarget/RevealRenderTarget';

export class StoryBookConfig extends BaseRevealConfig {
// ==================================================
Expand Down Expand Up @@ -43,4 +44,8 @@ export class StoryBookConfig extends BaseRevealConfig {
public override createAxisGizmoTool(): AxisGizmoTool | undefined {
return new AxisGizmoTool();
}

public override onStartup(renderTarget: RevealRenderTarget): void {
renderTarget.fitView();
}
}
18 changes: 17 additions & 1 deletion react-components/stories/Architecture.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { RevealStoryContainer } from './utilities/RevealStoryContainer';
import { getAddModelOptionsFromUrl } from './utilities/getAddModelOptionsFromUrl';
import { DomainObjectPanel } from '../src/components/Architecture/DomainObjectPanel';
import { ActiveToolToolbar, MainToolbar } from '../src/components/Architecture/Toolbar';
import { useRenderTarget } from '../src/components/RevealCanvas/ViewerContext';
import { type AddModelOptions, type CogniteCadModel } from '@cognite/reveal';

const meta = {
title: 'Example/Architecture',
Expand Down Expand Up @@ -82,7 +84,7 @@ export const Main: Story = {
return (
<RevealStoryContainer color={new Color(0x4a4a4a)} viewerOptions={{}}>
<FitToUrlCameraState />
<CadModelContainer addModelOptions={addModelOptions} />
<StoryContent addModelOptions={addModelOptions} />
<RevealToolbar
customSettingsContent={exampleCustomSettingElements()}
lowFidelitySettings={exampleLowQualitySettings}
Expand All @@ -96,6 +98,20 @@ export const Main: Story = {
}
};

function StoryContent({ addModelOptions }: { addModelOptions: AddModelOptions }): ReactElement {
const renderTarget = useRenderTarget();
return (
<>
<CadModelContainer
addModelOptions={addModelOptions}
onLoad={(_model: CogniteCadModel) => {
renderTarget.onStartup();
}}
/>
</>
);
}

function FitToUrlCameraState(): ReactElement {
const getCameraState = useGetCameraStateFromUrlParam();
const cameraNavigation = useCameraNavigation();
Expand Down

0 comments on commit aed9b28

Please sign in to comment.