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) Some renaming, and smaller fixes #4548

Merged
merged 55 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
d21937d
Initial commit
nilscognite May 25, 2024
9ac6395
Some movements
nilscognite May 25, 2024
0c69ba7
Fix linter problems
nilscognite May 25, 2024
53499d6
Make the axis a tiny better
nilscognite May 25, 2024
648d916
Comments only
nilscognite May 25, 2024
c23aa7d
Some rafactoring
nilscognite May 25, 2024
e0bed21
Make it better
nilscognite May 26, 2024
39f5ae6
Update MeasurementTool.ts
nilscognite May 26, 2024
89243a8
Fix lint
nilscognite May 26, 2024
1f05ec0
Make better axis tick labels, but still not perfect
nilscognite May 26, 2024
3f8ed41
handleEscape better
nilscognite May 26, 2024
bc61459
Changes in RevealRenderTarget
nilscognite May 26, 2024
7d0b716
Update RootDomainObject.ts
nilscognite May 26, 2024
96f9bd1
Fix smal bug
nilscognite May 27, 2024
2a4de0a
Moving code
nilscognite May 27, 2024
7826f7c
Merge branch 'master' into np/architecture-continued
nilscognite May 27, 2024
a580f55
Fix typo
nilscognite May 27, 2024
7570059
Set new default value
nilscognite May 27, 2024
0f91bd0
Fix typo
nilscognite May 27, 2024
ad31e2d
Merge branch 'master' into np/example-code
nilscognite May 27, 2024
7f4ee11
Merge branch 'master' into np/example-code
nilscognite May 28, 2024
ad63029
Initial commit
nilscognite May 28, 2024
f2748f2
Update Architecture.stories.tsx
nilscognite May 28, 2024
98d8406
Update yarn.lock
nilscognite May 28, 2024
316fd10
Fix MeasureLineView so lines are visible from long distance
nilscognite May 28, 2024
d42f04c
Make a DefaultRevealConfig
nilscognite May 28, 2024
d4804cc
Add override keyword
nilscognite May 28, 2024
b5bcab4
Remove some unneccesary code
nilscognite May 28, 2024
0b55801
Merge branch 'master' into np/architecture-continued
nilscognite May 28, 2024
92fa70e
Merge branch 'master' into np/example-code
nilscognite May 28, 2024
4bddd3f
Merge branch 'np/architecture-continued' of https://github.com/cognit…
nilscognite May 28, 2024
f6bc2c0
Update ExampleTool.ts
nilscognite May 28, 2024
6aad7d6
Merge branch 'master' into np/crop-box
nilscognite May 28, 2024
ecac8e3
Fixing updating
nilscognite May 28, 2024
c035a1e
CommandsUpdater and some renaming
nilscognite May 28, 2024
de172cf
Update Toolbar.tsx
nilscognite May 28, 2024
812f95b
Add accept in tools
nilscognite May 29, 2024
c45f05b
Move some panel code + tiny other things
nilscognite May 29, 2024
24b69e5
Fixed updating issues in toolbars
nilscognite May 29, 2024
de0e593
Fix divider
nilscognite May 29, 2024
ffd38f2
Some refacoring
nilscognite May 29, 2024
aa26934
Smaller fixes
nilscognite May 29, 2024
f33d795
Merge branch 'master' into np/crop-box
nilscognite May 29, 2024
d9da15d
Some renaming
nilscognite May 29, 2024
45e22ac
Merge branch 'np/crop-box' of https://github.com/cognitedata/reveal i…
nilscognite May 29, 2024
bbaf596
Remove code
nilscognite May 29, 2024
5b7f6bf
Renaming file + placement of a button
nilscognite May 30, 2024
43c36f6
Merge branch 'master' into np/crop-box
nilscognite May 30, 2024
be7f33a
Update ExampleTool.ts
nilscognite May 30, 2024
09af68a
Merge branch 'np/crop-box' of https://github.com/cognitedata/reveal i…
nilscognite May 30, 2024
2a1b692
Tuning on the visualization
nilscognite May 30, 2024
f7be729
Updates according to code review
nilscognite May 30, 2024
1f3b0f1
Fixed the sprite so they are more like the old measurments
nilscognite May 30, 2024
062f6f7
Update selection color
nilscognite May 30, 2024
8f3d75a
Merge branch 'master' into np/crop-box
nilscognite May 30, 2024
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
41 changes: 37 additions & 4 deletions react-components/src/architecture/base/commands/BaseEditTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ 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';
import { VisualDomainObject } from '../domainObjects/VisualDomainObject';
import { type AnyIntersection, CDF_TO_VIEWER_TRANSFORMATION } from '@cognite/reveal';

/**
* The `BaseEditTool` class is an abstract class that extends the `NavigationTool` class.
Expand Down Expand Up @@ -65,10 +65,25 @@ export abstract class BaseEditTool extends NavigationTool {
}
}

public override onDeactivate(): void {
super.onDeactivate();
this.deselectAll();
}

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

/**
* Determines whether the specified domain object can be selected or dragged by this edit tool.
*
* @param _domainObject - The domain object to be accepted.
* @returns `true` if the domain object can be accepted, `false` otherwise.
*/
protected canBeSelected(_domainObject: DomainObject): boolean {
return false;
}

/**
* Override this function to create custom dragger
* with other creation logic. Otherwise createDragger in
Expand All @@ -82,7 +97,7 @@ export abstract class BaseEditTool extends NavigationTool {
if (!isDomainObjectIntersection(intersection)) {
return undefined;
}
const domainObject = intersection.domainObject as VisualDomainObject;
const domainObject = this.getIntersectedDomainObject(intersection);
if (domainObject === undefined) {
return undefined;
}
Expand All @@ -98,13 +113,31 @@ export abstract class BaseEditTool extends NavigationTool {
// INSTANCE METHODS
// ==================================================

protected deselectAll(except?: DomainObject | undefined): void {
protected deselectAll(except?: VisualDomainObject | undefined): void {
const { rootDomainObject } = this;
for (const domainObject of rootDomainObject.getDescendants()) {
if (!this.canBeSelected(domainObject)) {
continue;
}
if (except !== undefined && domainObject === except) {
continue;
}
domainObject.setSelectedInteractive(false);
}
}

protected getIntersectedDomainObject(
intersection: AnyIntersection | undefined
): VisualDomainObject | undefined {
if (!isDomainObjectIntersection(intersection)) {
return undefined;
}
if (!this.canBeSelected(intersection.domainObject)) {
return undefined;
} else if (intersection.domainObject instanceof VisualDomainObject) {
return intersection.domainObject;
} else {
return undefined;
}
}
}
6 changes: 3 additions & 3 deletions react-components/src/architecture/base/commands/BaseTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export abstract class BaseTool extends RenderTargetCommand {
}

public override get isChecked(): boolean {
return this.renderTarget.toolController.activeTool === this;
return this.renderTarget.commandsController.activeTool === this;
}

protected override invokeCore(): boolean {
if (this.isChecked) {
this.renderTarget.toolController.activateDefaultTool();
this.renderTarget.commandsController.activateDefaultTool();
} else {
this.renderTarget.toolController.setActiveTool(this);
this.renderTarget.commandsController.setActiveTool(this);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { BaseCommand } from './BaseCommand';
import { type RevealRenderTarget } from '../renderTarget/RevealRenderTarget';
import { type RootDomainObject } from '../domainObjects/RootDomainObject';
import { CommandsUpdater } from '../reactUpdaters/CommandsUpdater';

/**
* Represents a base class where the render target is known.
Expand All @@ -27,7 +28,7 @@ export abstract class RenderTargetCommand extends BaseCommand {
public override invoke(): boolean {
const success = this.invokeCore();
if (success) {
this.renderTarget.toolController.update();
CommandsUpdater.update(this._renderTarget);
}
return success;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { Views } from '../domainObjectsHelpers/Views';
import { type PanelInfo } from '../domainObjectsHelpers/PanelInfo';
import { PopupStyle } from '../domainObjectsHelpers/PopupStyle';
import { RootDomainObject } from './RootDomainObject';
import { CommandsUpdater } from '../reactUpdaters/CommandsUpdater';
import { DomainObjectPanelUpdater } from '../reactUpdaters/DomainObjectPanelUpdater';

/**
* Represents an abstract base class for domain objects.
Expand Down Expand Up @@ -226,7 +228,7 @@ export abstract class DomainObject {
return true; // to be overridden
}

public canBeChecked(_target: RevealRenderTarget): boolean {
public canBeSetVisibleNow(_target: RevealRenderTarget): boolean {
return true; // to be overridden
}

Expand All @@ -244,27 +246,32 @@ export abstract class DomainObject {
protected notifyCore(change: DomainObjectChange): void {
this.views.notify(this, change);

// This is a little bit dirty, but will be refacored by using onIdle()
if (
change.isChanged(
Changes.visibleState,
Changes.active,
Changes.active,
Changes.selected,
Changes.childAdded,
Changes.childDeleted
)
) {
if (this.root instanceof RootDomainObject) {
this.root.renderTarget.toolController.update();
CommandsUpdater.update(this.root.renderTarget);
}
}
if (this.hasPanelInfo) {
DomainObjectPanelUpdater.notify(this, change);
}
}

// ==================================================
// VIRTUAL METHODS: For updating the panel
// ==================================================

public get hasPanelInfo(): boolean {
return false; // to be overridden
}

public getPanelInfo(): PanelInfo | undefined {
return undefined; // to be overridden
}
Expand Down Expand Up @@ -341,7 +348,10 @@ export abstract class DomainObject {
numCandidates++;
if (childState === VisibleState.All) {
numAll++;
} else if (childState === VisibleState.None || childState === VisibleState.CanNotBeChecked) {
} else if (
childState === VisibleState.None ||
childState === VisibleState.CanNotBeVisibleNow
) {
numNone++;
}
if (numNone < numCandidates && numCandidates < numAll) {
Expand All @@ -355,7 +365,9 @@ export abstract class DomainObject {
return VisibleState.All;
}
if (numCandidates === numNone) {
return this.canBeChecked(renderTarget) ? VisibleState.None : VisibleState.CanNotBeChecked;
return this.canBeSetVisibleNow(renderTarget)
? VisibleState.None
: VisibleState.CanNotBeVisibleNow;
}
return VisibleState.Some;
}
Expand All @@ -369,7 +381,7 @@ export abstract class DomainObject {
if (visibleState === VisibleState.Disabled) {
return false;
}
if (visibleState === VisibleState.None && !this.canBeChecked(renderTarget)) {
if (visibleState === VisibleState.None && !this.canBeSetVisibleNow(renderTarget)) {
return false;
}
let hasChanged = false;
Expand Down Expand Up @@ -753,7 +765,7 @@ export abstract class DomainObject {

// ==================================================
// INSTANCE METHODS: Color type
// Used in the renderstyle to determin which of the color a doamin object should have.
// Used in the renderstyle to determin which of the color a domain object should have.
// ==================================================

public supportsColorType(colorType: ColorType, solid: boolean): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export abstract class VisualDomainObject extends DomainObject {
return VisibleState.All;
}
if (this.canCreateThreeView()) {
if (this.canBeChecked(renderTarget)) {
if (this.canBeSetVisibleNow(renderTarget)) {
return VisibleState.None;
}
return VisibleState.CanNotBeChecked;
return VisibleState.CanNotBeVisibleNow;
}
return VisibleState.Disabled;
}
Expand All @@ -38,7 +38,7 @@ export abstract class VisualDomainObject extends DomainObject {
renderTarget: RevealRenderTarget,
topLevel = true
): boolean {
if (visible && !this.canBeChecked(renderTarget)) {
if (visible && !this.canBeSetVisibleNow(renderTarget)) {
return false;
}
if (!this.setVisible(visible, renderTarget)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,31 @@
*/

import { Ray, type Vector3 } from 'three';
import { type DomainObject } from '../domainObjects/DomainObject';
import { type CreateDraggerProps } from '../domainObjects/VisualDomainObject';
import {
type VisualDomainObject,
type CreateDraggerProps
} from '../domainObjects/VisualDomainObject';

/**
* The `BaseDragger` class represents a utility for dragging and manipulating any object in 3D space.
* It provides methods for onPointerDown, onPointerDrag, and onPointerUp based on user interactions.
*/

export abstract class BaseDragger {
// ==================================================
// INSTANCE FIELDS
// ==================================================

protected readonly point: Vector3; // Intersection point at pointer down in CDF coordinates
protected readonly ray: Ray = new Ray(); // Intersection point at pointer down in CDF coordinates

// ==================================================
// CONTRUCTOR
// ==================================================

/**
* Represents a base dragger object.
* @param props - Contains the ray amd the clicked point in CDF coordinates
*/
protected constructor(props: CreateDraggerProps) {
// Note: that yje point and the ray comes in CDF coordinates
this.point = props.point;
this.ray = props.ray;
}
Expand All @@ -32,17 +36,28 @@ export abstract class BaseDragger {
// VIRTUAL METHODS
// ==================================================

public abstract get domainObject(): DomainObject;

public onPointerDown(_event: PointerEvent): void {
// Empty, probably not needed
}

// This must be overriden
// Note: that the ray comes in CDF coordinates
public abstract onPointerDrag(_event: PointerEvent, ray: Ray): boolean;

public onPointerUp(_event: PointerEvent): void {
// Empty, probably not needed
}
/**
* Returns the domain object to be manipulated
*/
public abstract get domainObject(): VisualDomainObject;

/**
* Called just after the dragger is created and the pointer is down.
* @param _event - The pointer event object.
*/
public onPointerDown(_event: PointerEvent): void {}

/**
* Called every times the mouse moves during dragging
* @param event - The pointer event.
* @param ray - The current ray in CDF cooordinates
* @returns True if the dragger has changed the domain object, false otherwise.
*/
public abstract onPointerDrag(event: PointerEvent, ray: Ray): boolean;

/**
* Called just before the dragger is deleted.
* @param _event - The pointer event.
*/
public onPointerUp(_event: PointerEvent): void {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@ type PopupProps = {
};

export class PopupStyle {
private readonly _horizontal: boolean = true;
private readonly _left?: number = undefined;
private readonly _right?: number = undefined;
private readonly _top?: number = undefined;
private readonly _bottom?: number = undefined;
private readonly _margin: number = 16; // margin ouside the popup
private readonly _padding: number = 16; // margin inside the popup
private readonly _margin: number = 16; // margin outside the popup
private readonly _padding: number = 8; // margin inside the popup
private readonly _horizontal: boolean = true; // Used for toolbars only

public constructor(props: PopupProps) {
if (props.horizontal !== undefined) {
this._horizontal = props.horizontal;
}
this._left = props.left;
this._right = props.right;
this._top = props.top;
Expand All @@ -36,14 +33,9 @@ export class PopupStyle {
if (props.padding !== undefined) {
this._padding = props.padding;
}
}

public get flexFlow(): string {
return this._horizontal ? 'row' : 'column';
}

public get isDividerHorizontal(): boolean {
return !this._horizontal;
if (props.horizontal !== undefined) {
this._horizontal = props.horizontal;
}
}

public get leftPx(): string {
Expand Down Expand Up @@ -73,4 +65,16 @@ export class PopupStyle {
public static getStringWithPx(value?: number): string {
return value === undefined ? 'undefined' : value.toString() + 'px';
}

public get flexFlow(): string {
return this._horizontal ? 'row' : 'column';
}

public get isHorizontal(): boolean {
return this._horizontal;
}

public get isHorizontalDivider(): boolean {
return !this._horizontal;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export enum VisibleState {
All, // Visible
Some, // Partly visible
None, // None visible
CanNotBeChecked, // Can not be checked on, but it can be visible
CanNotBeVisibleNow, // Can not be checked on, but it can be visible
Disabled // Visiable disabled
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class ActiveToolUpdater {
// Increment the counter, so the state change in React and force a redraw each time the active tool changes
// The reason for solution it that I only want to store the active tool at one single location, since this gives a more
// stabel code, and never goes out of sync.
// React get the active tool by: renderTarget.toolController.activeTool;
// React get the active tool by: renderTarget.commandsController.activeTool;
if (this._setCounter === undefined) {
return;
}
Expand Down
Loading
Loading