UNPKG

@itwin/measure-tools-react

Version:
101 lines 4.01 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import { AreaMeasurement } from "../measurements/AreaMeasurement.js"; import { MeasurementToolModel } from "../api/MeasurementToolModel.js"; var State; (function (State) { State[State["SetMeasurementViewport"] = 0] = "SetMeasurementViewport"; State[State["AddPoint"] = 1] = "AddPoint"; })(State || (State = {})); export class MeasureAreaToolModel extends MeasurementToolModel { constructor() { super(); this._currentState = State.SetMeasurementViewport; } get drawingMetadata() { return this._currentMeasurement?.drawingMetadata; } set drawingMetadata(data) { if (this._currentMeasurement) this._currentMeasurement.drawingMetadata = data; } set sheetViewId(id) { if (this._currentMeasurement) this._currentMeasurement.sheetViewId = id; } get sheetViewId() { return this._currentMeasurement?.sheetViewId; } get currentState() { return this._currentState; } get hasEnoughPoints() { if (!this._currentMeasurement) return false; return this._currentMeasurement.isValidPolygon; } get dynamicMeasurement() { return this._currentMeasurement; } setMeasurementViewport(viewType) { if (State.SetMeasurementViewport !== this._currentState) return false; this._currentViewportType = viewType; this._currentState = State.AddPoint; return true; } addPoint(viewType, point, isDynamic) { if (State.AddPoint !== this._currentState) return false; if (viewType !== this._currentViewportType) return false; if (undefined === this._currentMeasurement) { if (isDynamic) return false; this._currentMeasurement = AreaMeasurement.create([point], viewType); this._currentMeasurement.isDynamic = true; this.notifyNewMeasurement(); return true; } if (isDynamic) { this._currentMeasurement.updateDynamicPolygon(point); this.notifyDynamicMeasurementChanged(); return true; } // &&AG some refactor needed. addPointToDynamicPolygon returns false even when it added a point successfully // returns only true if the polygon has been closed... if (this._currentMeasurement.addPointToDynamicPolygon(point)) { this.notifyDynamicMeasurementChanged(); this.addMeasurementAndReset(this._currentMeasurement); } return true; } /** Attemps to remove the last point of the current measurement. * * Fails if there is only one point left to prevent an invalid state. */ popMeasurementPoint() { if (undefined === this._currentMeasurement) return false; const polygon = this._currentMeasurement.polygon; if (1 >= polygon.points.length) return false; polygon.points.pop(); polygon.recomputeFromPoints(); this.notifyDynamicMeasurementChanged(); return true; } tryCommitMeasurement() { if (!this._currentMeasurement) return false; if (!this._currentMeasurement.closeDynamicPolygon()) return false; this.notifyDynamicMeasurementChanged(); this.addMeasurementAndReset(this._currentMeasurement); return true; } reset(clearMeasurements) { super.reset(clearMeasurements); this._currentMeasurement = undefined; this._currentState = State.SetMeasurementViewport; } } MeasureAreaToolModel.State = State; //# sourceMappingURL=MeasureAreaToolModel.js.map