Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nilscognite committed Jun 18, 2024
1 parent 14f2d90 commit 56b2f60
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export class ApplyClipCommand extends RenderTargetCommand {
return 'Crop';
}

public override get buttonType(): string {
return 'primary';
}

public override get isEnabled(): boolean {
if (this.getSelectedCropBoxDomainObject() !== undefined) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { PrimitiveType } from '../primitives/PrimitiveType';
import { BoxCreator } from '../primitives/box/BoxCreator';
import { LineCreator } from '../primitives/line/LineCreator';
import { type VisualDomainObject } from '../../base/domainObjects/VisualDomainObject';
import { CDF_TO_VIEWER_TRANSFORMATION } from '@cognite/reveal';

export class MeasurementTool extends PrimitiveEditTool {
// ==================================================
Expand Down Expand Up @@ -57,7 +58,28 @@ export class MeasurementTool extends PrimitiveEditTool {

public override onActivate(): void {
super.onActivate();
this.setAllVisible(true);

if (!this.renderTarget.isGlobalClippingActive) {
this.setAllVisible(true);
return;
}
const sceneBoundingBox = this.renderTarget.clippedSceneBoundingBox;
for (const domainObject of this.getSelectable()) {
if (domainObject instanceof MeasureBoxDomainObject) {
const boundingBox = domainObject.getBoundingBox();
boundingBox.applyMatrix4(CDF_TO_VIEWER_TRANSFORMATION);
if (!sceneBoundingBox.intersectsBox(boundingBox)) {
continue;
}
} else if (domainObject instanceof MeasureLineDomainObject) {
const boundingBox = domainObject.getBoundingBox();
boundingBox.applyMatrix4(CDF_TO_VIEWER_TRANSFORMATION);
if (!sceneBoundingBox.intersectsBox(boundingBox)) {
continue;
}
}
domainObject.setVisibleInteractive(true, this.renderTarget);
}
}

public override onDeactivate(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { type RenderStyle } from '../../../base/renderStyles/RenderStyle';
import { type ThreeView } from '../../../base/views/ThreeView';
import { LineView } from './LineView';
import { Vector3 } from 'three';
import { Box3, Vector3 } from 'three';
import { PrimitiveType } from '../PrimitiveType';
import { LineRenderStyle } from './LineRenderStyle';
import {
Expand Down Expand Up @@ -197,6 +197,14 @@ export abstract class LineDomainObject extends VisualDomainObject {
return Math.abs(sum) / 2;
}

public getBoundingBox(): Box3 {
const boundingBox = new Box3().makeEmpty();
for (const point of this.points) {
boundingBox.expandByPoint(point);
}
return boundingBox;
}

public setFocusInteractive(focusType: FocusType): boolean {
if (this.focusType === focusType) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const CommandButton = ({
const { key, fallback } = newCommand.tooltip;
// This was the only way it went through compiler: (more button types will be added in the future)
const type = newCommand.buttonType;
if (type !== 'ghost' && type !== 'ghost-destructive') {
if (type !== 'ghost' && type !== 'ghost-destructive' && type !== 'primary') {
return <></>;
}
const text = key === undefined ? fallback : t(key, fallback);
Expand Down

0 comments on commit 56b2f60

Please sign in to comment.