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

(fix) Continue the architecture work #4531

Merged
merged 19 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export type Tooltip = {
fallback?: string;
};

/**
* Base class for all command and tools. Thses are object that can do a
* user interaction with the system. It also have enough information to
* generate the UI for the command.
*/
export abstract class BaseCommand {
// ==================================================
// INSTANCE FIELDS
Expand Down
23 changes: 18 additions & 5 deletions react-components/src/architecture/base/commands/BaseEditTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ import { NavigationTool } from './NavigationTool';
import { type DomainObject } from '../domainObjects/DomainObject';
import { isDomainObjectIntersection } from '../domainObjectsHelpers/DomainObjectIntersection';
import { type BaseDragger } from '../domainObjectsHelpers/BaseDragger';
import { type VisualDomainObject } from '../domainObjects/VisualDomainObject';
import { CDF_TO_VIEWER_TRANSFORMATION } from '@cognite/reveal';

/**
* The `BaseEditTool` class is an abstract class that extends the `NavigationTool` class.
* It provides a base implementation for editing tools in a specific architecture.
* Custom editing tools can be created by extending this class and overriding its methods.
* This class will also proivide the dragging functionality if the picked domain object has
* createDragger() overridden.
*/
export abstract class BaseEditTool extends NavigationTool {
// ==================================================
// INSTANCE FIELDS
Expand Down Expand Up @@ -57,7 +66,7 @@ export abstract class BaseEditTool extends NavigationTool {
}

// ==================================================
// VIRTUALS METHODS
// VIRTUAL METHODS
// ==================================================

/**
Expand All @@ -73,20 +82,24 @@ export abstract class BaseEditTool extends NavigationTool {
if (!isDomainObjectIntersection(intersection)) {
return undefined;
}
const domainObject = intersection.domainObject;
const domainObject = intersection.domainObject as VisualDomainObject;
if (domainObject === undefined) {
return undefined;
}
return domainObject.createDragger(intersection);
const ray = this.getRay(event);
const matrix = CDF_TO_VIEWER_TRANSFORMATION.clone().invert();
const point = intersection.point.clone();
point.applyMatrix4(matrix);
ray.applyMatrix4(matrix);
return domainObject.createDragger({ intersection, point, ray });
}

// ==================================================
// INSTANCE METHODS
// ==================================================

protected deselectAll(except?: DomainObject | undefined): void {
const { renderTarget } = this;
const { rootDomainObject } = renderTarget;
const { rootDomainObject } = this;
for (const domainObject of rootDomainObject.getDescendants()) {
if (except !== undefined && domainObject === except) {
continue;
Expand Down
11 changes: 8 additions & 3 deletions react-components/src/architecture/base/commands/BaseTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import { type BaseCommand } from './BaseCommand';
import { ActiveToolUpdater } from '../reactUpdaters/ActiveToolUpdater';
import { PopupStyle } from '../domainObjectsHelpers/PopupStyle';

/**
* Base class for intraction in the 3D viewer
* Provides common functionality and virtual methods to be overridden by derived classes.
*/
export abstract class BaseTool extends RenderTargetCommand {
// ==================================================
// OVERRIDES
Expand Down Expand Up @@ -116,7 +120,9 @@ export abstract class BaseTool extends RenderTargetCommand {
this.renderTarget.cursor = this.defaultCursor;
}

protected async getIntersection(event: PointerEvent): Promise<AnyIntersection | undefined> {
protected async getIntersection(
event: PointerEvent | WheelEvent
): Promise<AnyIntersection | undefined> {
const { renderTarget } = this;
const { viewer } = renderTarget;
const point = viewer.getPixelCoordinatesFromEvent(event);
Expand All @@ -132,8 +138,7 @@ export abstract class BaseTool extends RenderTargetCommand {
classType: Class<T>
): DomainObjectIntersection | undefined {
// This function is similar to getIntersection, but it only considers a specific DomainObject
const { renderTarget } = this;
const { rootDomainObject } = renderTarget;
const { renderTarget, rootDomainObject } = this;
const { viewer } = renderTarget;

const point = viewer.getPixelCoordinatesFromEvent(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { BaseTool } from './BaseTool';
import { type Tooltip } from './BaseCommand';
import { type IFlexibleCameraManager } from '@cognite/reveal';

/**
* Represents a tool navigation tool used for camera manipulation.
* Inherit from this class if you like to have some camera manipulation in your tool.
*/
export class NavigationTool extends BaseTool {
// ==================================================
// INSTANVE PROPERTIES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

import { BaseCommand } from './BaseCommand';
import { type RevealRenderTarget } from '../renderTarget/RevealRenderTarget';
import { type RootDomainObject } from '../domainObjects/RootDomainObject';

/**
* Represents a base class where the render target is known.
* Subclasses of this class is used to interact with the render target
*/
export abstract class RenderTargetCommand extends BaseCommand {
public _renderTarget: RevealRenderTarget | undefined = undefined;

Expand All @@ -15,6 +20,10 @@ export abstract class RenderTargetCommand extends BaseCommand {
return this._renderTarget;
}

public get rootDomainObject(): RootDomainObject {
return this.renderTarget.rootDomainObject;
}

public override invoke(): boolean {
const success = this.invokeCore();
if (success) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ export class FitViewCommand extends RenderTargetCommand {

protected override invokeCore(): boolean {
const { renderTarget } = this;
const { viewer } = renderTarget;

const boundingBox = viewer.getSceneBoundingBox();
if (boundingBox.isEmpty()) {
return false;
}
viewer.fitCameraToBoundingBox(boundingBox);
return true;
return renderTarget.fitView();
}
}
Loading
Loading