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 (react-components): Use primary button for cropping and do not show measurements completely outside the bounding box #4611

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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
Loading