@itwin/editor-frontend 3.4.0-dev.44 → 3.4.0-dev.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/lib/cjs/CreateElementTool.d.ts +100 -100
  2. package/lib/cjs/CreateElementTool.js +327 -327
  3. package/lib/cjs/CreateElementTool.js.map +1 -1
  4. package/lib/cjs/DeleteElementsTool.d.ts +15 -15
  5. package/lib/cjs/DeleteElementsTool.js +40 -40
  6. package/lib/cjs/DeleteElementsTool.js.map +1 -1
  7. package/lib/cjs/EditTool.d.ts +37 -37
  8. package/lib/cjs/EditTool.js +135 -135
  9. package/lib/cjs/EditTool.js.map +1 -1
  10. package/lib/cjs/ElementGeometryTool.d.ts +148 -148
  11. package/lib/cjs/ElementGeometryTool.js +708 -708
  12. package/lib/cjs/ElementGeometryTool.js.map +1 -1
  13. package/lib/cjs/ModifyCurveTools.d.ts +118 -118
  14. package/lib/cjs/ModifyCurveTools.js +668 -668
  15. package/lib/cjs/ModifyCurveTools.js.map +1 -1
  16. package/lib/cjs/ProjectLocation/ProjectExtentsDecoration.d.ts +137 -137
  17. package/lib/cjs/ProjectLocation/ProjectExtentsDecoration.js +821 -821
  18. package/lib/cjs/ProjectLocation/ProjectExtentsDecoration.js.map +1 -1
  19. package/lib/cjs/ProjectLocation/ProjectGeolocation.d.ts +135 -135
  20. package/lib/cjs/ProjectLocation/ProjectGeolocation.js +507 -507
  21. package/lib/cjs/ProjectLocation/ProjectGeolocation.js.map +1 -1
  22. package/lib/cjs/SketchTools.d.ts +306 -306
  23. package/lib/cjs/SketchTools.js +1707 -1707
  24. package/lib/cjs/SketchTools.js.map +1 -1
  25. package/lib/cjs/SolidModelingTools.d.ts +380 -380
  26. package/lib/cjs/SolidModelingTools.js +1459 -1459
  27. package/lib/cjs/SolidModelingTools.js.map +1 -1
  28. package/lib/cjs/SolidPrimitiveTools.d.ts +254 -254
  29. package/lib/cjs/SolidPrimitiveTools.js +1095 -1095
  30. package/lib/cjs/SolidPrimitiveTools.js.map +1 -1
  31. package/lib/cjs/TransformElementsTool.d.ts +166 -166
  32. package/lib/cjs/TransformElementsTool.js +654 -654
  33. package/lib/cjs/TransformElementsTool.js.map +1 -1
  34. package/lib/cjs/UndoRedoTool.d.ts +16 -16
  35. package/lib/cjs/UndoRedoTool.js +42 -42
  36. package/lib/cjs/UndoRedoTool.js.map +1 -1
  37. package/lib/cjs/editor-frontend.d.ts +15 -15
  38. package/lib/cjs/editor-frontend.js +31 -31
  39. package/lib/cjs/editor-frontend.js.map +1 -1
  40. package/lib/esm/CreateElementTool.d.ts +100 -100
  41. package/lib/esm/CreateElementTool.js +319 -319
  42. package/lib/esm/CreateElementTool.js.map +1 -1
  43. package/lib/esm/DeleteElementsTool.d.ts +15 -15
  44. package/lib/esm/DeleteElementsTool.js +36 -36
  45. package/lib/esm/DeleteElementsTool.js.map +1 -1
  46. package/lib/esm/EditTool.d.ts +37 -37
  47. package/lib/esm/EditTool.js +131 -131
  48. package/lib/esm/EditTool.js.map +1 -1
  49. package/lib/esm/ElementGeometryTool.d.ts +148 -148
  50. package/lib/esm/ElementGeometryTool.js +700 -700
  51. package/lib/esm/ElementGeometryTool.js.map +1 -1
  52. package/lib/esm/ModifyCurveTools.d.ts +118 -118
  53. package/lib/esm/ModifyCurveTools.js +660 -660
  54. package/lib/esm/ModifyCurveTools.js.map +1 -1
  55. package/lib/esm/ProjectLocation/ProjectExtentsDecoration.d.ts +137 -137
  56. package/lib/esm/ProjectLocation/ProjectExtentsDecoration.js +813 -813
  57. package/lib/esm/ProjectLocation/ProjectExtentsDecoration.js.map +1 -1
  58. package/lib/esm/ProjectLocation/ProjectGeolocation.d.ts +135 -135
  59. package/lib/esm/ProjectLocation/ProjectGeolocation.js +501 -501
  60. package/lib/esm/ProjectLocation/ProjectGeolocation.js.map +1 -1
  61. package/lib/esm/SketchTools.d.ts +306 -306
  62. package/lib/esm/SketchTools.js +1697 -1697
  63. package/lib/esm/SketchTools.js.map +1 -1
  64. package/lib/esm/SolidModelingTools.d.ts +380 -380
  65. package/lib/esm/SolidModelingTools.js +1434 -1434
  66. package/lib/esm/SolidModelingTools.js.map +1 -1
  67. package/lib/esm/SolidPrimitiveTools.d.ts +254 -254
  68. package/lib/esm/SolidPrimitiveTools.js +1086 -1086
  69. package/lib/esm/SolidPrimitiveTools.js.map +1 -1
  70. package/lib/esm/TransformElementsTool.d.ts +166 -166
  71. package/lib/esm/TransformElementsTool.js +646 -646
  72. package/lib/esm/TransformElementsTool.js.map +1 -1
  73. package/lib/esm/UndoRedoTool.d.ts +16 -16
  74. package/lib/esm/UndoRedoTool.js +36 -36
  75. package/lib/esm/UndoRedoTool.js.map +1 -1
  76. package/lib/esm/editor-frontend.d.ts +15 -15
  77. package/lib/esm/editor-frontend.js +19 -19
  78. package/lib/esm/editor-frontend.js.map +1 -1
  79. package/lib/public/locales/en/Editor.json +448 -448
  80. package/package.json +15 -15
@@ -1,814 +1,814 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
- /** @packageDocumentation
6
- * @module Editing
7
- */
8
- import { BeDuration, BeEvent, BentleyError } from "@itwin/core-bentley";
9
- import { ColorDef, EcefLocation } from "@itwin/core-common";
10
- import { BeButton, CoreTools, EditManipulator, EventHandled, GraphicType, IModelApp, MessageBoxIconType, MessageBoxType, MessageBoxValue, NotifyMessageDetails, OutputMessagePriority, QuantityType, Tool, ViewClipControlArrow, ViewClipDecorationProvider, ViewClipShapeModifyTool, ViewClipTool, } from "@itwin/core-frontend";
11
- import { Angle, Arc3d, AxisIndex, AxisOrder, Constant, Matrix3d, Point3d, PolygonOps, Range1d, Range3d, Ray3d, Transform, Vector3d, } from "@itwin/core-geometry";
12
- import { editorBuiltInCmdIds } from "@itwin/editor-common";
13
- import { EditTools } from "../EditTool";
14
- import { ProjectGeolocationNorthTool, ProjectGeolocationPointTool } from "./ProjectGeolocation";
15
- function translateMessage(key) { return EditTools.translate(`ProjectLocation:Message.${key}`); }
16
- function translateMessageBold(key) { return `<b>${translateMessage(key)}:</b> `; }
17
- function translateCoreMeasureBold(key) { return `<b>${CoreTools.translate(`Measure.Labels.${key}`)}:</b> `; }
18
- function clearViewClip(vp) {
19
- if (!ViewClipTool.doClipClear(vp))
20
- return false;
21
- ViewClipDecorationProvider.create().onClearClip(vp); // Send clear event...
22
- ViewClipDecorationProvider.clear();
23
- return true;
24
- }
25
- function clipToProjectExtents(vp) {
26
- clearViewClip(vp); // Clear any existing view clip and send clear event...
27
- ViewClipTool.enableClipVolume(vp);
28
- return ViewClipTool.doClipToRange(vp, vp.iModel.projectExtents, Transform.createIdentity());
29
- }
30
- function enableBackgroundMap(viewport, onOff) {
31
- if (onOff === viewport.viewFlags.backgroundMap)
32
- return false;
33
- viewport.viewFlags = viewport.viewFlags.with("backgroundMap", onOff);
34
- return true;
35
- }
36
- function updateMapDisplay(vp, turnOnMap) {
37
- if (!turnOnMap || !enableBackgroundMap(vp, true))
38
- vp.invalidateRenderPlan();
39
- }
40
- class ProjectExtentsControlArrow extends ViewClipControlArrow {
41
- constructor() {
42
- super(...arguments);
43
- this.extentValid = true;
44
- }
45
- }
46
- /** Values for [[ProjectExtentsClipDecoration.onChanged] event.
47
- * @beta
48
- */
49
- export var ProjectLocationChanged;
50
- (function (ProjectLocationChanged) {
51
- /** Extents has been modified (unsaved changes) */
52
- ProjectLocationChanged[ProjectLocationChanged["Extents"] = 0] = "Extents";
53
- /** Geolocation has been modified (unsaved changes) */
54
- ProjectLocationChanged[ProjectLocationChanged["Geolocation"] = 1] = "Geolocation";
55
- /** Abandon unsaved changes to extents */
56
- ProjectLocationChanged[ProjectLocationChanged["ResetExtents"] = 2] = "ResetExtents";
57
- /** Abandon unsaved changes to geolocation */
58
- ProjectLocationChanged[ProjectLocationChanged["ResetGeolocation"] = 3] = "ResetGeolocation";
59
- /** Decoration hidden (unsaved changes preserved) */
60
- ProjectLocationChanged[ProjectLocationChanged["Hide"] = 4] = "Hide";
61
- /** Decoration shown (unsaved changes restored) */
62
- ProjectLocationChanged[ProjectLocationChanged["Show"] = 5] = "Show";
63
- /** Save changes to extents and geolocation */
64
- ProjectLocationChanged[ProjectLocationChanged["Save"] = 6] = "Save";
65
- })(ProjectLocationChanged || (ProjectLocationChanged = {}));
66
- /** Controls to modify project extents shown using view clip
67
- * @beta
68
- */
69
- export class ProjectExtentsClipDecoration extends EditManipulator.HandleProvider {
70
- constructor(viewport) {
71
- super(viewport.iModel);
72
- this.viewport = viewport;
73
- this._extentsLengthValid = true;
74
- this._extentsWidthValid = true;
75
- this._extentsHeightValid = true;
76
- this._allowEcefLocationChange = false;
77
- this._controlIds = [];
78
- this._controls = [];
79
- this._suspendDecorator = false;
80
- this.suspendGeolocationDecorations = false;
81
- /** Called when project extents or geolocation is modified */
82
- this.onChanged = new BeEvent();
83
- if (!this.init())
84
- return;
85
- this._monumentId = this.iModel.transientIds.next;
86
- this._northId = this.iModel.transientIds.next;
87
- this._clipId = this.iModel.transientIds.next;
88
- this.start();
89
- }
90
- start() {
91
- this.updateDecorationListener(true);
92
- this._removeViewCloseListener = IModelApp.viewManager.onViewClose.addListener((vp) => this.onViewClose(vp));
93
- this.iModel.selectionSet.replace(this._clipId); // Always select decoration on create...
94
- }
95
- stop() {
96
- const selectedId = (undefined !== this._clipId && this.iModel.selectionSet.has(this._clipId)) ? this._clipId : undefined;
97
- this._clipId = undefined; // Invalidate id so that decorator will be dropped...
98
- super.stop();
99
- if (undefined !== selectedId)
100
- this.iModel.selectionSet.remove(selectedId); // Don't leave decorator id in selection set...
101
- if (undefined !== this._removeViewCloseListener) {
102
- this._removeViewCloseListener();
103
- this._removeViewCloseListener = undefined;
104
- }
105
- }
106
- init() {
107
- if (!this.getClipData())
108
- return false;
109
- this._ecefLocation = this.iModel.ecefLocation;
110
- this._monumentPoint = this.getMonumentPoint();
111
- this._northDirection = this.getNorthDirection();
112
- return true;
113
- }
114
- onViewClose(vp) {
115
- if (this.viewport === vp)
116
- ProjectExtentsClipDecoration.clear();
117
- }
118
- getClipData() {
119
- this._clip = this._clipShape = this._clipShapeExtents = this._clipRange = undefined;
120
- const clip = this.viewport.view.getViewClip();
121
- if (undefined === clip)
122
- return false;
123
- const clipShape = ViewClipTool.isSingleClipShape(clip);
124
- if (undefined === clipShape)
125
- return false;
126
- if (5 !== clipShape.polygon.length || undefined === clipShape.zLow || undefined === clipShape.zHigh)
127
- return false; // Not a box, can't be project extents clip...
128
- if (undefined !== clipShape.transformFromClip && !clipShape.transformFromClip.isIdentity)
129
- return false; // Not axis aligned, can't be project extents clip...
130
- this._clipShapeExtents = Range1d.createXX(clipShape.zLow, clipShape.zHigh);
131
- this._clipShape = clipShape;
132
- this._clip = clip;
133
- this._clipRange = Range3d.create();
134
- const shapePtsLo = ViewClipTool.getClipShapePoints(this._clipShape, this._clipShapeExtents.low);
135
- const shapePtsHi = ViewClipTool.getClipShapePoints(this._clipShape, this._clipShapeExtents.high);
136
- this._clipRange.extendArray(shapePtsLo);
137
- this._clipRange.extendArray(shapePtsHi);
138
- return true;
139
- }
140
- ensureNumControls(numReqControls) {
141
- const numCurrent = this._controlIds.length;
142
- if (numCurrent < numReqControls) {
143
- const transientIds = this.iModel.transientIds;
144
- for (let i = numCurrent; i < numReqControls; i++)
145
- this._controlIds[i] = transientIds.next;
146
- }
147
- else if (numCurrent > numReqControls) {
148
- this._controlIds.length = numReqControls;
149
- }
150
- }
151
- createClipShapeControls() {
152
- if (undefined === this._clipShape)
153
- return false;
154
- const shapePtsLo = ViewClipTool.getClipShapePoints(this._clipShape, this._clipShapeExtents.low);
155
- const shapePtsHi = ViewClipTool.getClipShapePoints(this._clipShape, this._clipShapeExtents.high);
156
- const shapeArea = PolygonOps.centroidAreaNormal(shapePtsLo);
157
- if (undefined === shapeArea)
158
- return false;
159
- const numControls = shapePtsLo.length + 1; // Number of edge midpoints plus zLow and zHigh...
160
- this.ensureNumControls(numControls);
161
- for (let i = 0; i < numControls - 2; i++) {
162
- const midPtLo = shapePtsLo[i].interpolate(0.5, shapePtsLo[i + 1]);
163
- const midPtHi = shapePtsHi[i].interpolate(0.5, shapePtsHi[i + 1]);
164
- const faceCenter = midPtLo.interpolate(0.5, midPtHi);
165
- const edgeTangent = Vector3d.createStartEnd(shapePtsLo[i], shapePtsLo[i + 1]);
166
- const faceNormal = edgeTangent.crossProduct(shapeArea.direction);
167
- faceNormal.normalizeInPlace();
168
- this._controls[i] = new ProjectExtentsControlArrow(faceCenter, faceNormal, 0.75);
169
- this._controls[i].extentValid = (faceNormal.isParallelTo(Vector3d.unitX(), true) ? this._extentsLengthValid : this._extentsWidthValid);
170
- }
171
- const zFillColor = ColorDef.from(150, 150, 250);
172
- this._controls[numControls - 2] = new ProjectExtentsControlArrow(shapeArea.origin, Vector3d.unitZ(-1.0), 0.75, zFillColor, undefined, "zLow");
173
- this._controls[numControls - 1] = new ProjectExtentsControlArrow(shapeArea.origin.plusScaled(Vector3d.unitZ(), shapePtsLo[0].distance(shapePtsHi[0])), Vector3d.unitZ(), 0.75, zFillColor, undefined, "zHigh");
174
- this._controls[numControls - 2].extentValid = this._extentsHeightValid;
175
- this._controls[numControls - 1].extentValid = this._extentsHeightValid;
176
- return true;
177
- }
178
- /** Allow project extents for map projections to be larger since curvature of the earth is accounted for. */
179
- get maxExtentLength() { return ((this._allowEcefLocationChange ? 20 : 350) * Constant.oneKilometer); }
180
- /** Impose some reasonable height limit for project extents. */
181
- get maxExtentHeight() { return (2 * Constant.oneKilometer); }
182
- hasValidGCS() {
183
- if (!this.iModel.isGeoLocated || this.iModel.noGcsDefined)
184
- return false;
185
- const gcs = this.iModel.geographicCoordinateSystem;
186
- if (undefined === gcs || undefined === gcs.horizontalCRS)
187
- return false; // A valid GCS ought to have horizontalCR defined...
188
- // Check for approximate GCS (such as from MicroStation's "From Placemark" tool) and allow it to be replaced...
189
- const hasValidId = (undefined !== gcs.horizontalCRS.id && 0 !== gcs.horizontalCRS.id.length);
190
- const hasValidDescr = (undefined !== gcs.horizontalCRS.description && 0 !== gcs.horizontalCRS.description.length);
191
- const hasValidProjection = (undefined !== gcs.horizontalCRS.projection && "AzimuthalEqualArea" !== gcs.horizontalCRS.projection.method);
192
- return hasValidId || hasValidDescr || hasValidProjection;
193
- }
194
- async createControls() {
195
- // Always update to current view clip to handle post-modify, etc.
196
- if (undefined === this._clipId || !this.getClipData())
197
- return false;
198
- this._allowEcefLocationChange = !this.hasValidGCS();
199
- if (undefined !== this._clipRange) {
200
- this._extentsLengthValid = (this._clipRange.xLength() < this.maxExtentLength);
201
- this._extentsWidthValid = (this._clipRange.yLength() < this.maxExtentLength);
202
- this._extentsHeightValid = (this._clipRange.zLength() < this.maxExtentHeight);
203
- }
204
- // Show controls if only range box and it's controls are selected, selection set doesn't include any other elements...
205
- let showControls = false;
206
- if (this.iModel.selectionSet.size <= this._controlIds.length + 1 && this.iModel.selectionSet.has(this._clipId)) {
207
- showControls = true;
208
- if (this.iModel.selectionSet.size > 1) {
209
- this.iModel.selectionSet.elements.forEach((val) => {
210
- if (this._clipId !== val && !this._controlIds.includes(val))
211
- showControls = false;
212
- });
213
- }
214
- }
215
- if (!showControls)
216
- return false; // Don't clear decoration on de-select...
217
- return this.createClipShapeControls();
218
- }
219
- clearControls() {
220
- this.iModel.selectionSet.remove(this._controlIds); // Remove any selected controls as they won't continue to be displayed...
221
- super.clearControls();
222
- }
223
- async modifyControls(hit, _ev) {
224
- if (undefined === this._clip || hit.sourceId === this._clipId)
225
- return false;
226
- const saveQualifiers = IModelApp.toolAdmin.currentInputState.qualifiers;
227
- if (undefined !== this._clipShape) {
228
- const clipShapeModifyTool = new ViewClipShapeModifyTool(this, this._clip, this.viewport, hit.sourceId, this._controlIds, this._controls);
229
- this._suspendDecorator = await clipShapeModifyTool.run();
230
- }
231
- if (this._suspendDecorator)
232
- IModelApp.toolAdmin.currentInputState.qualifiers = saveQualifiers; // onInstallTool cleared qualifiers, preserve for "modify all" behavior when shift was held and drag started...
233
- return this._suspendDecorator;
234
- }
235
- async onRightClick(_hit, _ev) { return EventHandled.No; }
236
- async onTouchTap(hit, ev) { return (hit.sourceId === this._clipId ? EventHandled.No : super.onTouchTap(hit, ev)); }
237
- async onDecorationButtonEvent(hit, ev) {
238
- if (hit.sourceId === this._monumentId) {
239
- if (BeButton.Data === ev.button && !ev.isDown && !ev.isDragging)
240
- await ProjectGeolocationPointTool.startTool();
241
- return EventHandled.Yes; // Only pickable for tooltip, don't allow selection...
242
- }
243
- if (hit.sourceId === this._northId) {
244
- if (BeButton.Data === ev.button && !ev.isDown && !ev.isDragging)
245
- await ProjectGeolocationNorthTool.startTool();
246
- return EventHandled.Yes; // Only pickable for tooltip, don't allow selection...
247
- }
248
- return super.onDecorationButtonEvent(hit, ev);
249
- }
250
- onManipulatorEvent(eventType) {
251
- if (EditManipulator.EventType.Accept === eventType)
252
- this.onChanged.raiseEvent(this.iModel, ProjectLocationChanged.Extents);
253
- this._suspendDecorator = false;
254
- super.onManipulatorEvent(eventType);
255
- }
256
- async getDecorationToolTip(hit) {
257
- const quantityFormatter = IModelApp.quantityFormatter;
258
- const toolTip = document.createElement("div");
259
- let toolTipHtml = "";
260
- if (hit.sourceId === this._monumentId) {
261
- toolTipHtml += `${translateMessage("ModifyGeolocation")}<br>`;
262
- const coordFormatterSpec = quantityFormatter.findFormatterSpecByQuantityType(QuantityType.Coordinate);
263
- if (undefined !== coordFormatterSpec) {
264
- const pointAdjusted = this._monumentPoint.minus(this.iModel.globalOrigin);
265
- const formattedPointX = quantityFormatter.formatQuantity(pointAdjusted.x, coordFormatterSpec);
266
- const formattedPointY = quantityFormatter.formatQuantity(pointAdjusted.y, coordFormatterSpec);
267
- const formattedPointZ = quantityFormatter.formatQuantity(pointAdjusted.z, coordFormatterSpec);
268
- toolTipHtml += `${translateCoreMeasureBold("Coordinate") + formattedPointX}, ${formattedPointY}, ${formattedPointZ}<br>`;
269
- }
270
- const latLongFormatterSpec = quantityFormatter.findFormatterSpecByQuantityType(QuantityType.LatLong);
271
- if (undefined !== latLongFormatterSpec && undefined !== coordFormatterSpec && this.iModel.isGeoLocated) {
272
- const cartographic = this.iModel.spatialToCartographicFromEcef(this._monumentPoint);
273
- const formattedLat = quantityFormatter.formatQuantity(Math.abs(cartographic.latitude), latLongFormatterSpec);
274
- const formattedLong = quantityFormatter.formatQuantity(Math.abs(cartographic.longitude), latLongFormatterSpec);
275
- const formattedHeight = quantityFormatter.formatQuantity(cartographic.height, coordFormatterSpec);
276
- const latDir = CoreTools.translate(cartographic.latitude < 0 ? "Measure.Labels.S" : "Measure.Labels.N");
277
- const longDir = CoreTools.translate(cartographic.longitude < 0 ? "Measure.Labels.W" : "Measure.Labels.E");
278
- toolTipHtml += `${translateCoreMeasureBold("LatLong") + formattedLat + latDir}, ${formattedLong}${longDir}<br>`;
279
- toolTipHtml += `${translateCoreMeasureBold("Altitude") + formattedHeight}<br>`;
280
- }
281
- }
282
- else if (hit.sourceId === this._northId) {
283
- toolTipHtml += `${translateMessage("ModifyNorthDirection")}<br>`;
284
- const angleFormatterSpec = quantityFormatter.findFormatterSpecByQuantityType(QuantityType.Angle);
285
- if (undefined !== angleFormatterSpec) {
286
- const formattedAngle = quantityFormatter.formatQuantity(this.getClockwiseAngleToNorth().radians, angleFormatterSpec);
287
- toolTipHtml += `${translateMessageBold("Angle") + formattedAngle}<br>`;
288
- }
289
- }
290
- else if (hit.sourceId === this._clipId) {
291
- const extentsValid = (this._extentsLengthValid && this._extentsWidthValid && this._extentsHeightValid);
292
- toolTipHtml += `${translateMessage(extentsValid ? "ProjectExtents" : "LargeProjectExtents")}<br>`;
293
- const distanceFormatterSpec = quantityFormatter.findFormatterSpecByQuantityType(QuantityType.Length);
294
- if (undefined !== distanceFormatterSpec && undefined !== this._clipRange) {
295
- const formattedLength = quantityFormatter.formatQuantity(this._clipRange.xLength(), distanceFormatterSpec);
296
- const formattedWidth = quantityFormatter.formatQuantity(this._clipRange.yLength(), distanceFormatterSpec);
297
- const formattedHeight = quantityFormatter.formatQuantity(this._clipRange.zLength(), distanceFormatterSpec);
298
- toolTipHtml += `${translateMessageBold("Length") + formattedLength}<br>`;
299
- toolTipHtml += `${translateMessageBold("Width") + formattedWidth}<br>`;
300
- toolTipHtml += `${translateMessageBold("Height") + formattedHeight}<br>`;
301
- }
302
- }
303
- else {
304
- const arrowIndex = this._controlIds.indexOf(hit.sourceId);
305
- if (-1 !== arrowIndex) {
306
- toolTipHtml += `${translateMessage("ModifyProjectExtents")}<br>`;
307
- const distanceFormatterSpec = quantityFormatter.findFormatterSpecByQuantityType(QuantityType.Length);
308
- if (undefined !== distanceFormatterSpec && undefined !== this._clipRange) {
309
- const arrowControl = this._controls[arrowIndex];
310
- let arrowLabel = "";
311
- let arrowLength = 0.0;
312
- let arrowLengthMax = 0.0;
313
- if (arrowControl.direction.isParallelTo(Vector3d.unitX(), true)) {
314
- arrowLabel = "Length";
315
- arrowLength = this._clipRange.xLength();
316
- if (!this._extentsLengthValid)
317
- arrowLengthMax = this.maxExtentLength;
318
- }
319
- else if (arrowControl.direction.isParallelTo(Vector3d.unitY(), true)) {
320
- arrowLabel = "Width";
321
- arrowLength = this._clipRange.yLength();
322
- if (!this._extentsWidthValid)
323
- arrowLengthMax = this.maxExtentLength;
324
- }
325
- else {
326
- arrowLabel = "Height";
327
- arrowLength = this._clipRange.zLength();
328
- if (!this._extentsHeightValid)
329
- arrowLengthMax = this.maxExtentHeight;
330
- const coordFormatterSpec = (this.iModel.isGeoLocated ? quantityFormatter.findFormatterSpecByQuantityType(QuantityType.Coordinate) : undefined);
331
- if (undefined !== coordFormatterSpec) {
332
- const heightPt = ("zLow" === arrowControl.name ? this._clipRange.low : this._clipRange.high);
333
- const cartographic = this.iModel.spatialToCartographicFromEcef(heightPt);
334
- const formattedAltitude = quantityFormatter.formatQuantity(cartographic.height, coordFormatterSpec);
335
- toolTipHtml += `${translateCoreMeasureBold("Altitude") + formattedAltitude}<br>`;
336
- }
337
- }
338
- const formattedLength = quantityFormatter.formatQuantity(arrowLength, distanceFormatterSpec);
339
- toolTipHtml += `${translateMessageBold(arrowLabel) + formattedLength}<br>`;
340
- if (0.0 !== arrowLengthMax) {
341
- const formattedMaxLength = quantityFormatter.formatQuantity(arrowLengthMax, distanceFormatterSpec);
342
- toolTipHtml += `${translateMessageBold("MaxExtent") + formattedMaxLength}<br>`;
343
- }
344
- }
345
- }
346
- }
347
- toolTip.innerHTML = toolTipHtml;
348
- return toolTip;
349
- }
350
- testDecorationHit(id) { return (id === this._monumentId || id === this._northId || id === this._clipId || this._controlIds.includes(id)); }
351
- updateDecorationListener(_add) { super.updateDecorationListener(undefined !== this._clipId); } // Decorator isn't just for resize controls...
352
- getMonumentPoint() {
353
- const origin = Point3d.createZero();
354
- if (this.iModel.ecefLocation && this.iModel.ecefLocation.cartographicOrigin)
355
- return this.iModel.cartographicToSpatialFromEcef(this.iModel.ecefLocation.cartographicOrigin, origin);
356
- origin.setFrom(this.iModel.projectExtents.low);
357
- if (0.0 > this.iModel.projectExtents.low.z && 0.0 < this.iModel.projectExtents.high.z)
358
- origin.z = 0.0;
359
- return origin;
360
- }
361
- getClockwiseAngleToNorth() {
362
- const angle = this.getNorthAngle();
363
- angle.setRadians(Angle.adjustRadians0To2Pi(angle.radians));
364
- return angle;
365
- }
366
- getNorthAngle() {
367
- const northDirection = (undefined !== this._northDirection ? this._northDirection : this.getNorthDirection());
368
- return northDirection.direction.angleToXY(Vector3d.unitY());
369
- }
370
- getNorthDirection(refOrigin) {
371
- const origin = (undefined !== refOrigin ? refOrigin : this.iModel.projectExtents.center);
372
- if (!this.iModel.isGeoLocated)
373
- return Ray3d.create(origin, Vector3d.unitY());
374
- const cartographic = this.iModel.spatialToCartographicFromEcef(origin);
375
- cartographic.latitude += Angle.createDegrees(0.01).radians;
376
- const pt2 = this.iModel.cartographicToSpatialFromEcef(cartographic);
377
- const northVec = Vector3d.createStartEnd(origin, pt2);
378
- northVec.z = 0.0;
379
- northVec.normalizeInPlace();
380
- return Ray3d.create(origin, northVec);
381
- }
382
- drawNorthArrow(context, northDir, id) {
383
- const vp = context.viewport;
384
- const pixelSize = vp.pixelsFromInches(0.55);
385
- const scale = vp.viewingSpace.getPixelSizeAtPoint(northDir.origin) * pixelSize;
386
- const matrix = Matrix3d.createRigidFromColumns(northDir.direction, Vector3d.unitZ(), AxisOrder.YZX);
387
- if (undefined === matrix)
388
- return;
389
- matrix.scaleColumnsInPlace(scale, scale, scale);
390
- const arrowTrans = Transform.createRefs(northDir.origin, matrix);
391
- const northArrowBuilder = context.createGraphicBuilder(GraphicType.WorldOverlay, arrowTrans, id);
392
- const color = ColorDef.white;
393
- const arrowOutline = [];
394
- arrowOutline[0] = Point3d.create(0.0, 0.65);
395
- arrowOutline[1] = Point3d.create(-0.45, -0.5);
396
- arrowOutline[2] = Point3d.create(0.0, -0.2);
397
- arrowOutline[3] = Point3d.create(0.45, -0.5);
398
- arrowOutline[4] = arrowOutline[0].clone();
399
- const arrowLeftFill = [];
400
- arrowLeftFill[0] = arrowOutline[0].clone();
401
- arrowLeftFill[1] = arrowOutline[1].clone();
402
- arrowLeftFill[2] = arrowOutline[2].clone();
403
- arrowLeftFill[3] = arrowLeftFill[0].clone();
404
- const arrowRightFill = [];
405
- arrowRightFill[0] = arrowOutline[0].clone();
406
- arrowRightFill[1] = arrowOutline[3].clone();
407
- arrowRightFill[2] = arrowOutline[2].clone();
408
- arrowRightFill[3] = arrowRightFill[0].clone();
409
- northArrowBuilder.setSymbology(color, ColorDef.from(0, 0, 0, 200), 1);
410
- northArrowBuilder.addArc(Arc3d.createXY(Point3d.createZero(), 0.6), true, true);
411
- northArrowBuilder.addArc(Arc3d.createXY(Point3d.create(0.0, 0.85), 0.2), true, true);
412
- northArrowBuilder.setSymbology(color, color, 2);
413
- northArrowBuilder.addArc(Arc3d.createXY(Point3d.createZero(), 0.5), false, false);
414
- northArrowBuilder.addLineString([Point3d.create(0.6, 0.0), Point3d.create(-0.6, 0.0)]);
415
- northArrowBuilder.addLineString([Point3d.create(0.0, 0.6), Point3d.create(0.0, -0.6)]);
416
- northArrowBuilder.setSymbology(color, ColorDef.from(150, 150, 150), 1);
417
- northArrowBuilder.addShape(arrowLeftFill);
418
- northArrowBuilder.setSymbology(color, ColorDef.black, 1);
419
- northArrowBuilder.addShape(arrowRightFill);
420
- northArrowBuilder.setSymbology(color, color, 1);
421
- northArrowBuilder.addLineString(arrowOutline);
422
- northArrowBuilder.setSymbology(color, color, 3);
423
- northArrowBuilder.addLineString([Point3d.create(-0.1, 0.75), Point3d.create(-0.1, 0.95), Point3d.create(0.1, 0.75), Point3d.create(0.1, 0.95)]);
424
- context.addDecorationFromBuilder(northArrowBuilder);
425
- }
426
- drawMonumentPoint(context, point, scaleFactor, id) {
427
- const vp = context.viewport;
428
- const pixelSize = vp.pixelsFromInches(0.25) * scaleFactor;
429
- const scale = vp.viewingSpace.getPixelSizeAtPoint(point) * pixelSize;
430
- const matrix = Matrix3d.createRotationAroundAxisIndex(AxisIndex.Z, Angle.createDegrees(45.0));
431
- matrix.scaleColumnsInPlace(scale, scale, scale);
432
- const monumentTrans = Transform.createRefs(point, matrix);
433
- const monumentPointBuilder = context.createGraphicBuilder(GraphicType.WorldOverlay, monumentTrans, id);
434
- const color = ColorDef.white;
435
- monumentPointBuilder.setSymbology(color, ColorDef.from(0, 0, 0, 150), 1);
436
- monumentPointBuilder.addArc(Arc3d.createXY(Point3d.createZero(), 0.7), true, true);
437
- monumentPointBuilder.setSymbology(color, color, 2);
438
- monumentPointBuilder.addArc(Arc3d.createXY(Point3d.createZero(), 0.5), false, false);
439
- monumentPointBuilder.addLineString([Point3d.create(0.5, 0.0), Point3d.create(-0.5, 0.0)]);
440
- monumentPointBuilder.addLineString([Point3d.create(0.0, 0.5), Point3d.create(0.0, -0.5)]);
441
- context.addDecorationFromBuilder(monumentPointBuilder);
442
- }
443
- drawAreaTooLargeIndicator(context) {
444
- if ((this._extentsLengthValid && this._extentsWidthValid) || undefined === this._clipRange)
445
- return;
446
- const corners = this._clipRange.corners();
447
- const indices = Range3d.faceCornerIndices(5);
448
- const points = [];
449
- for (const index of indices)
450
- points.push(corners[index]);
451
- const areaWarnColor = ColorDef.red.withAlpha(50);
452
- const areaWarnBuilder = context.createGraphicBuilder(GraphicType.WorldDecoration);
453
- areaWarnBuilder.setSymbology(areaWarnColor, areaWarnColor, 1);
454
- areaWarnBuilder.addShape(points);
455
- context.addDecorationFromBuilder(areaWarnBuilder);
456
- }
457
- drawExtentTooLargeIndicator(context, worldPoint, sizePixels) {
458
- const position = context.viewport.worldToView(worldPoint);
459
- position.x = Math.floor(position.x) + 0.5;
460
- position.y = Math.floor(position.y) + 0.5;
461
- const drawDecoration = (ctx) => {
462
- ctx.lineWidth = 4;
463
- ctx.lineCap = "round";
464
- ctx.strokeStyle = "rgba(255,0,0,.75)";
465
- ctx.fillStyle = "rgba(255,255,255,.75)";
466
- ctx.shadowColor = "black";
467
- ctx.shadowBlur = 5;
468
- ctx.beginPath();
469
- ctx.moveTo(0, -sizePixels);
470
- ctx.lineTo(-sizePixels, sizePixels);
471
- ctx.lineTo(sizePixels, sizePixels);
472
- ctx.lineTo(0, -sizePixels);
473
- ctx.fill();
474
- ctx.shadowBlur = 0;
475
- ctx.beginPath();
476
- ctx.moveTo(0, -sizePixels);
477
- ctx.lineTo(-sizePixels, sizePixels);
478
- ctx.lineTo(sizePixels, sizePixels);
479
- ctx.lineTo(0, -sizePixels);
480
- ctx.stroke();
481
- ctx.strokeStyle = "black";
482
- ctx.lineWidth = 3;
483
- ctx.beginPath();
484
- ctx.moveTo(0, -sizePixels * 0.2);
485
- ctx.lineTo(0, sizePixels * 0.3);
486
- ctx.moveTo(0, (sizePixels * 0.3) + 4);
487
- ctx.lineTo(0, (sizePixels * 0.3) + 4.5);
488
- ctx.stroke();
489
- };
490
- context.addCanvasDecoration({ position, drawDecoration });
491
- }
492
- decorate(context) {
493
- if (this._suspendDecorator)
494
- return;
495
- if (undefined === this._clipId || undefined === this._clipShape || undefined === this._clipRange)
496
- return;
497
- const vp = context.viewport;
498
- if (this.viewport !== vp)
499
- return;
500
- if (!this.suspendGeolocationDecorations && undefined !== this._northDirection && this.iModel.isGeoLocated)
501
- this.drawNorthArrow(context, this._northDirection, this._allowEcefLocationChange ? this._northId : undefined); // Show north, but don't make pickable if it shouldn't be modified...
502
- const maxSizeInches = ((this._clipRange.maxLength() / vp.viewingSpace.getPixelSizeAtPoint(this._clipRange.center)) / vp.pixelsPerInch) * 0.5; // Display size limit when zooming out...
503
- if (maxSizeInches < 0.5)
504
- return;
505
- if (!this.suspendGeolocationDecorations && undefined !== this._monumentPoint && this._allowEcefLocationChange)
506
- this.drawMonumentPoint(context, this._monumentPoint, 1.0, this._monumentId);
507
- ViewClipTool.drawClipShape(context, this._clipShape, this._clipShapeExtents, ColorDef.white.adjustedForContrast(context.viewport.view.backgroundColor), 3, this._clipId);
508
- this.drawAreaTooLargeIndicator(context);
509
- if (!this._isActive)
510
- return;
511
- const outlineColor = ColorDef.from(0, 0, 0, 50).adjustedForContrast(vp.view.backgroundColor);
512
- const fillVisColor = ColorDef.from(150, 250, 200, 225).adjustedForContrast(vp.view.backgroundColor);
513
- const fillHidColor = fillVisColor.withAlpha(200);
514
- const fillSelColor = fillVisColor.inverse().withAlpha(75);
515
- const shapePts = EditManipulator.HandleUtils.getArrowShape(0.0, 0.15, 0.55, 1.0, 0.3, 0.5, 0.1);
516
- for (let iFace = 0; iFace < this._controlIds.length; iFace++) {
517
- const sizeInches = Math.min(this._controls[iFace].sizeInches, maxSizeInches);
518
- if (0.0 === sizeInches)
519
- continue;
520
- const anchorRay = ViewClipTool.getClipRayTransformed(this._controls[iFace].origin, this._controls[iFace].direction, undefined !== this._clipShape ? this._clipShape.transformFromClip : undefined);
521
- const transform = EditManipulator.HandleUtils.getArrowTransform(vp, anchorRay.origin, anchorRay.direction, sizeInches);
522
- if (undefined === transform)
523
- continue;
524
- const visPts = [];
525
- for (const pt of shapePts)
526
- visPts.push(pt.clone()); // deep copy because we're using a builder transform w/addLineString...
527
- const hidPts = [];
528
- for (const pt of shapePts)
529
- hidPts.push(pt.clone());
530
- const arrowVisBuilder = context.createGraphicBuilder(GraphicType.WorldOverlay, transform, this._controlIds[iFace]);
531
- const arrowHidBuilder = context.createGraphicBuilder(GraphicType.WorldDecoration, transform);
532
- const isSelected = this.iModel.selectionSet.has(this._controlIds[iFace]);
533
- let outlineColorOvr = this._controls[iFace].outline;
534
- if (undefined !== outlineColorOvr) {
535
- outlineColorOvr = outlineColorOvr.adjustedForContrast(vp.view.backgroundColor);
536
- outlineColorOvr = outlineColorOvr.withAlpha(outlineColor.getAlpha());
537
- }
538
- else {
539
- outlineColorOvr = outlineColor;
540
- }
541
- let fillVisColorOvr = this._controls[iFace].fill;
542
- let fillHidColorOvr = fillHidColor;
543
- let fillSelColorOvr = fillSelColor;
544
- if (undefined !== fillVisColorOvr) {
545
- fillVisColorOvr = fillVisColorOvr.adjustedForContrast(vp.view.backgroundColor);
546
- fillVisColorOvr = fillVisColorOvr.withAlpha(fillVisColor.getAlpha());
547
- fillHidColorOvr = fillVisColorOvr.withAlpha(fillHidColor.getAlpha());
548
- fillSelColorOvr = fillVisColorOvr.inverse().withAlpha(fillSelColor.getAlpha());
549
- }
550
- else {
551
- fillVisColorOvr = fillVisColor;
552
- }
553
- arrowVisBuilder.setSymbology(outlineColorOvr, outlineColorOvr, isSelected ? 4 : 2);
554
- arrowVisBuilder.addLineString(visPts);
555
- arrowVisBuilder.setBlankingFill(isSelected ? fillSelColorOvr : fillVisColorOvr);
556
- arrowVisBuilder.addShape(visPts);
557
- context.addDecorationFromBuilder(arrowVisBuilder);
558
- arrowHidBuilder.setSymbology(fillHidColorOvr, fillHidColorOvr, 1);
559
- arrowHidBuilder.addShape(hidPts);
560
- context.addDecorationFromBuilder(arrowHidBuilder);
561
- if (this._controls[iFace].extentValid)
562
- continue;
563
- const warnPixels = 15.0;
564
- const warnOffset = vp.viewingSpace.getPixelSizeAtPoint(anchorRay.origin) * warnPixels * 1.5;
565
- const warnOrigin = anchorRay.origin.plusScaled(anchorRay.direction, -warnOffset);
566
- this.drawExtentTooLargeIndicator(context, warnOrigin, warnPixels);
567
- }
568
- }
569
- resetViewClip() {
570
- if (!clearViewClip(this.viewport))
571
- return false;
572
- if (undefined !== this.getModifiedExtents())
573
- this.onChanged.raiseEvent(this.iModel, ProjectLocationChanged.ResetExtents);
574
- return true;
575
- }
576
- resetGeolocation() {
577
- if (!this._allowEcefLocationChange)
578
- return false;
579
- if (undefined === this.getModifiedEcefLocation())
580
- return false; // Wasn't changed...
581
- this.iModel.disableGCS(false);
582
- this.iModel.ecefLocation = this._ecefLocation;
583
- this._monumentPoint = this.getMonumentPoint();
584
- this._northDirection = this.getNorthDirection();
585
- updateMapDisplay(this.viewport, false);
586
- this.onChanged.raiseEvent(this.iModel, ProjectLocationChanged.ResetGeolocation);
587
- return true;
588
- }
589
- updateEcefLocation(origin, point, angle) {
590
- if (!this._allowEcefLocationChange)
591
- return false;
592
- const newEcefLocation = EcefLocation.createFromCartographicOrigin(origin, point, (undefined !== angle ? angle : this.getNorthAngle())); // Preserve modified north direction...
593
- const ecefLocation = this.iModel.ecefLocation;
594
- if (undefined !== ecefLocation && ecefLocation.isAlmostEqual(newEcefLocation))
595
- return false;
596
- this.iModel.disableGCS(true); // Map display will ignore change to ecef location when GCS is present...
597
- this.iModel.setEcefLocation(newEcefLocation);
598
- this._monumentPoint = this.getMonumentPoint();
599
- this._northDirection = this.getNorthDirection(undefined !== this._northDirection ? this._northDirection.origin : undefined); // Preserve modified north reference point...
600
- updateMapDisplay(this.viewport, true);
601
- this.onChanged.raiseEvent(this.iModel, ProjectLocationChanged.Geolocation);
602
- return true;
603
- }
604
- updateNorthDirection(northDir) {
605
- if (!this._allowEcefLocationChange || !this.iModel.isGeoLocated)
606
- return false;
607
- const point = (undefined !== this._monumentPoint ? this._monumentPoint : this.getMonumentPoint()); // Preserve modified monument point...
608
- const origin = this.iModel.spatialToCartographicFromEcef(point);
609
- const saveDirection = this._northDirection;
610
- this._northDirection = northDir; // Change reference point to input location...
611
- const angle = this.getNorthAngle();
612
- if (!this.updateEcefLocation(origin, point, angle)) {
613
- this._northDirection = saveDirection;
614
- return false;
615
- }
616
- return true;
617
- }
618
- getModifiedEcefLocation() {
619
- const ecefLocation = this.iModel.ecefLocation;
620
- if (undefined === ecefLocation)
621
- return undefined; // geolocation wasn't added...
622
- if (undefined === this._ecefLocation)
623
- return ecefLocation; // geolocation didn't exist previously...
624
- if (this._ecefLocation.isAlmostEqual(ecefLocation))
625
- return undefined;
626
- return ecefLocation;
627
- }
628
- getModifiedExtents() {
629
- if (undefined === this._clipRange)
630
- return undefined;
631
- return this._clipRange.isAlmostEqual(this.iModel.projectExtents) ? undefined : this._clipRange;
632
- }
633
- static allowEcefLocationChange(requireExisting, outputError = true) {
634
- if (undefined === ProjectExtentsClipDecoration._decorator) {
635
- if (outputError)
636
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, translateMessage("NotActive")));
637
- return false;
638
- }
639
- else if (!ProjectExtentsClipDecoration._decorator._allowEcefLocationChange) {
640
- if (outputError)
641
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, translateMessage("NotAllowed")));
642
- return false;
643
- }
644
- else if (requireExisting && !ProjectExtentsClipDecoration._decorator.iModel.isGeoLocated) {
645
- if (outputError)
646
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, translateMessage("NotGeolocated")));
647
- return false;
648
- }
649
- return true;
650
- }
651
- fitExtents() {
652
- if (undefined === this._clipRange)
653
- return undefined;
654
- const options = { animateFrustumChange: true, animationTime: BeDuration.fromSeconds(2).milliseconds };
655
- const aspect = this.viewport.viewRect.aspect;
656
- this.viewport.view.lookAtVolume(this._clipRange, aspect);
657
- this.viewport.synchWithView(options);
658
- this.viewport.viewCmdTargetCenter = undefined;
659
- }
660
- static get() {
661
- if (undefined === ProjectExtentsClipDecoration._decorator)
662
- return undefined;
663
- return ProjectExtentsClipDecoration._decorator;
664
- }
665
- static show(vp, fitExtents = true) {
666
- if (!vp.view.isSpatialView())
667
- return false;
668
- if (undefined !== ProjectExtentsClipDecoration._decorator) {
669
- const deco = ProjectExtentsClipDecoration._decorator;
670
- if (vp === deco.viewport && undefined !== deco._clipId && undefined !== deco._clip) {
671
- if (deco._clip !== vp.view.getViewClip()) {
672
- clearViewClip(vp);
673
- ViewClipTool.enableClipVolume(vp);
674
- ViewClipTool.setViewClip(vp, deco._clip);
675
- }
676
- if (undefined === deco._removeManipulatorToolListener) {
677
- deco._removeManipulatorToolListener = IModelApp.toolAdmin.manipulatorToolEvent.addListener((tool, event) => deco.onManipulatorToolEvent(tool, event));
678
- deco.start();
679
- deco.onChanged.raiseEvent(deco.iModel, ProjectLocationChanged.Show);
680
- }
681
- return true;
682
- }
683
- ProjectExtentsClipDecoration.clear();
684
- }
685
- if (!clipToProjectExtents(vp))
686
- return false;
687
- ProjectExtentsClipDecoration._decorator = new ProjectExtentsClipDecoration(vp);
688
- if (fitExtents)
689
- ProjectExtentsClipDecoration._decorator.fitExtents();
690
- vp.onChangeView.addOnce(() => this.clear(false, true));
691
- return (undefined !== ProjectExtentsClipDecoration._decorator._clipId);
692
- }
693
- static hide() {
694
- if (undefined === ProjectExtentsClipDecoration._decorator)
695
- return;
696
- const saveClipId = ProjectExtentsClipDecoration._decorator._clipId; // cleared by stop to trigger decorator removal...
697
- ProjectExtentsClipDecoration._decorator.stop();
698
- ProjectExtentsClipDecoration._decorator._clipId = saveClipId;
699
- ProjectExtentsClipDecoration._decorator.onChanged.raiseEvent(ProjectExtentsClipDecoration._decorator.iModel, ProjectLocationChanged.Hide);
700
- }
701
- static clear(clearClip = true, resetGeolocation = true) {
702
- if (undefined === ProjectExtentsClipDecoration._decorator)
703
- return;
704
- if (clearClip)
705
- ProjectExtentsClipDecoration._decorator.resetViewClip(); // Clear project extents view clip...
706
- if (resetGeolocation)
707
- ProjectExtentsClipDecoration._decorator.resetGeolocation(); // Restore modified geolocation back to create state...
708
- ProjectExtentsClipDecoration._decorator.stop();
709
- ProjectExtentsClipDecoration._decorator = undefined;
710
- }
711
- static async update() {
712
- const deco = ProjectExtentsClipDecoration._decorator;
713
- if (undefined === deco)
714
- return;
715
- clipToProjectExtents(deco.viewport);
716
- deco.init();
717
- return deco.updateControls();
718
- }
719
- }
720
- /** Show project location decoration. Project extents represented by view clip.
721
- * @beta
722
- */
723
- export class ProjectLocationShowTool extends Tool {
724
- async run() {
725
- const vp = IModelApp.viewManager.selectedView;
726
- if (undefined === vp || !ProjectExtentsClipDecoration.show(vp))
727
- return false;
728
- await IModelApp.toolAdmin.startDefaultTool();
729
- return true;
730
- }
731
- }
732
- ProjectLocationShowTool.toolId = "ProjectLocation.Show";
733
- /** Hide project location decoration. Preserves changes to project extents view clip and geolocation.
734
- * @beta
735
- */
736
- export class ProjectLocationHideTool extends Tool {
737
- async run() {
738
- ProjectExtentsClipDecoration.hide();
739
- await IModelApp.toolAdmin.startDefaultTool();
740
- return true;
741
- }
742
- }
743
- ProjectLocationHideTool.toolId = "ProjectLocation.Hide";
744
- /** Clear project location decoration. Restore modified geolocation and remove view clip.
745
- * @beta
746
- */
747
- export class ProjectLocationCancelTool extends Tool {
748
- async run() {
749
- ProjectExtentsClipDecoration.clear();
750
- await IModelApp.toolAdmin.startDefaultTool();
751
- return true;
752
- }
753
- }
754
- ProjectLocationCancelTool.toolId = "ProjectLocation.Cancel";
755
- /** Save modified project extents and geolocation. Updates decoration to reflect saved state.
756
- * @note Allowing this change to be undone is both problematic and undesirable.
757
- * Warns the user if called with previous changes to cancel restarting the TxnManager session.
758
- * @beta
759
- */
760
- export class ProjectLocationSaveTool extends Tool {
761
- static callCommand(method, ...args) {
762
- return EditTools.callCommand(method, ...args);
763
- }
764
- async allowRestartTxnSession(iModel) {
765
- if (!await iModel.txns.isUndoPossible())
766
- return true;
767
- // NOTE: Default if openMessageBox isn't implemented is MessageBoxValue.Ok, so we'll check No instead of Yes...
768
- if (MessageBoxValue.No === await IModelApp.notifications.openMessageBox(MessageBoxType.YesNo, translateMessage("RestartTxn"), MessageBoxIconType.Question))
769
- return false;
770
- return true;
771
- }
772
- async saveChanges(deco, extents, ecefLocation) {
773
- if (!deco.iModel.isBriefcaseConnection())
774
- return;
775
- if (!await this.allowRestartTxnSession(deco.iModel))
776
- return;
777
- try {
778
- await EditTools.startCommand(editorBuiltInCmdIds.cmdBasicManipulation, deco.iModel.key);
779
- if (undefined !== extents)
780
- await ProjectLocationSaveTool.callCommand("updateProjectExtents", extents);
781
- if (undefined !== ecefLocation)
782
- await ProjectLocationSaveTool.callCommand("updateEcefLocation", ecefLocation);
783
- await deco.iModel.saveChanges(this.toolId);
784
- await deco.iModel.txns.restartTxnSession();
785
- }
786
- catch (err) {
787
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, BentleyError.getErrorMessage(err) || "An unknown error occurred."));
788
- }
789
- deco.onChanged.raiseEvent(deco.iModel, ProjectLocationChanged.Save);
790
- await ProjectExtentsClipDecoration.update();
791
- return IModelApp.toolAdmin.startDefaultTool();
792
- }
793
- async run() {
794
- const deco = ProjectExtentsClipDecoration.get();
795
- if (undefined === deco) {
796
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, translateMessage("NotActive")));
797
- return false;
798
- }
799
- if (deco.iModel.isReadonly) {
800
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, translateMessage("Readonly")));
801
- return true;
802
- }
803
- const extents = deco.getModifiedExtents();
804
- const ecefLocation = deco.getModifiedEcefLocation();
805
- if (undefined === extents && undefined === ecefLocation) {
806
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, translateMessage("NoChanges")));
807
- return true;
808
- }
809
- await this.saveChanges(deco, extents, ecefLocation);
810
- return true;
811
- }
812
- }
813
- ProjectLocationSaveTool.toolId = "ProjectLocation.Save";
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /** @packageDocumentation
6
+ * @module Editing
7
+ */
8
+ import { BeDuration, BeEvent, BentleyError } from "@itwin/core-bentley";
9
+ import { ColorDef, EcefLocation } from "@itwin/core-common";
10
+ import { BeButton, CoreTools, EditManipulator, EventHandled, GraphicType, IModelApp, MessageBoxIconType, MessageBoxType, MessageBoxValue, NotifyMessageDetails, OutputMessagePriority, QuantityType, Tool, ViewClipControlArrow, ViewClipDecorationProvider, ViewClipShapeModifyTool, ViewClipTool, } from "@itwin/core-frontend";
11
+ import { Angle, Arc3d, AxisIndex, AxisOrder, Constant, Matrix3d, Point3d, PolygonOps, Range1d, Range3d, Ray3d, Transform, Vector3d, } from "@itwin/core-geometry";
12
+ import { editorBuiltInCmdIds } from "@itwin/editor-common";
13
+ import { EditTools } from "../EditTool";
14
+ import { ProjectGeolocationNorthTool, ProjectGeolocationPointTool } from "./ProjectGeolocation";
15
+ function translateMessage(key) { return EditTools.translate(`ProjectLocation:Message.${key}`); }
16
+ function translateMessageBold(key) { return `<b>${translateMessage(key)}:</b> `; }
17
+ function translateCoreMeasureBold(key) { return `<b>${CoreTools.translate(`Measure.Labels.${key}`)}:</b> `; }
18
+ function clearViewClip(vp) {
19
+ if (!ViewClipTool.doClipClear(vp))
20
+ return false;
21
+ ViewClipDecorationProvider.create().onClearClip(vp); // Send clear event...
22
+ ViewClipDecorationProvider.clear();
23
+ return true;
24
+ }
25
+ function clipToProjectExtents(vp) {
26
+ clearViewClip(vp); // Clear any existing view clip and send clear event...
27
+ ViewClipTool.enableClipVolume(vp);
28
+ return ViewClipTool.doClipToRange(vp, vp.iModel.projectExtents, Transform.createIdentity());
29
+ }
30
+ function enableBackgroundMap(viewport, onOff) {
31
+ if (onOff === viewport.viewFlags.backgroundMap)
32
+ return false;
33
+ viewport.viewFlags = viewport.viewFlags.with("backgroundMap", onOff);
34
+ return true;
35
+ }
36
+ function updateMapDisplay(vp, turnOnMap) {
37
+ if (!turnOnMap || !enableBackgroundMap(vp, true))
38
+ vp.invalidateRenderPlan();
39
+ }
40
+ class ProjectExtentsControlArrow extends ViewClipControlArrow {
41
+ constructor() {
42
+ super(...arguments);
43
+ this.extentValid = true;
44
+ }
45
+ }
46
+ /** Values for [[ProjectExtentsClipDecoration.onChanged] event.
47
+ * @beta
48
+ */
49
+ export var ProjectLocationChanged;
50
+ (function (ProjectLocationChanged) {
51
+ /** Extents has been modified (unsaved changes) */
52
+ ProjectLocationChanged[ProjectLocationChanged["Extents"] = 0] = "Extents";
53
+ /** Geolocation has been modified (unsaved changes) */
54
+ ProjectLocationChanged[ProjectLocationChanged["Geolocation"] = 1] = "Geolocation";
55
+ /** Abandon unsaved changes to extents */
56
+ ProjectLocationChanged[ProjectLocationChanged["ResetExtents"] = 2] = "ResetExtents";
57
+ /** Abandon unsaved changes to geolocation */
58
+ ProjectLocationChanged[ProjectLocationChanged["ResetGeolocation"] = 3] = "ResetGeolocation";
59
+ /** Decoration hidden (unsaved changes preserved) */
60
+ ProjectLocationChanged[ProjectLocationChanged["Hide"] = 4] = "Hide";
61
+ /** Decoration shown (unsaved changes restored) */
62
+ ProjectLocationChanged[ProjectLocationChanged["Show"] = 5] = "Show";
63
+ /** Save changes to extents and geolocation */
64
+ ProjectLocationChanged[ProjectLocationChanged["Save"] = 6] = "Save";
65
+ })(ProjectLocationChanged || (ProjectLocationChanged = {}));
66
+ /** Controls to modify project extents shown using view clip
67
+ * @beta
68
+ */
69
+ export class ProjectExtentsClipDecoration extends EditManipulator.HandleProvider {
70
+ constructor(viewport) {
71
+ super(viewport.iModel);
72
+ this.viewport = viewport;
73
+ this._extentsLengthValid = true;
74
+ this._extentsWidthValid = true;
75
+ this._extentsHeightValid = true;
76
+ this._allowEcefLocationChange = false;
77
+ this._controlIds = [];
78
+ this._controls = [];
79
+ this._suspendDecorator = false;
80
+ this.suspendGeolocationDecorations = false;
81
+ /** Called when project extents or geolocation is modified */
82
+ this.onChanged = new BeEvent();
83
+ if (!this.init())
84
+ return;
85
+ this._monumentId = this.iModel.transientIds.next;
86
+ this._northId = this.iModel.transientIds.next;
87
+ this._clipId = this.iModel.transientIds.next;
88
+ this.start();
89
+ }
90
+ start() {
91
+ this.updateDecorationListener(true);
92
+ this._removeViewCloseListener = IModelApp.viewManager.onViewClose.addListener((vp) => this.onViewClose(vp));
93
+ this.iModel.selectionSet.replace(this._clipId); // Always select decoration on create...
94
+ }
95
+ stop() {
96
+ const selectedId = (undefined !== this._clipId && this.iModel.selectionSet.has(this._clipId)) ? this._clipId : undefined;
97
+ this._clipId = undefined; // Invalidate id so that decorator will be dropped...
98
+ super.stop();
99
+ if (undefined !== selectedId)
100
+ this.iModel.selectionSet.remove(selectedId); // Don't leave decorator id in selection set...
101
+ if (undefined !== this._removeViewCloseListener) {
102
+ this._removeViewCloseListener();
103
+ this._removeViewCloseListener = undefined;
104
+ }
105
+ }
106
+ init() {
107
+ if (!this.getClipData())
108
+ return false;
109
+ this._ecefLocation = this.iModel.ecefLocation;
110
+ this._monumentPoint = this.getMonumentPoint();
111
+ this._northDirection = this.getNorthDirection();
112
+ return true;
113
+ }
114
+ onViewClose(vp) {
115
+ if (this.viewport === vp)
116
+ ProjectExtentsClipDecoration.clear();
117
+ }
118
+ getClipData() {
119
+ this._clip = this._clipShape = this._clipShapeExtents = this._clipRange = undefined;
120
+ const clip = this.viewport.view.getViewClip();
121
+ if (undefined === clip)
122
+ return false;
123
+ const clipShape = ViewClipTool.isSingleClipShape(clip);
124
+ if (undefined === clipShape)
125
+ return false;
126
+ if (5 !== clipShape.polygon.length || undefined === clipShape.zLow || undefined === clipShape.zHigh)
127
+ return false; // Not a box, can't be project extents clip...
128
+ if (undefined !== clipShape.transformFromClip && !clipShape.transformFromClip.isIdentity)
129
+ return false; // Not axis aligned, can't be project extents clip...
130
+ this._clipShapeExtents = Range1d.createXX(clipShape.zLow, clipShape.zHigh);
131
+ this._clipShape = clipShape;
132
+ this._clip = clip;
133
+ this._clipRange = Range3d.create();
134
+ const shapePtsLo = ViewClipTool.getClipShapePoints(this._clipShape, this._clipShapeExtents.low);
135
+ const shapePtsHi = ViewClipTool.getClipShapePoints(this._clipShape, this._clipShapeExtents.high);
136
+ this._clipRange.extendArray(shapePtsLo);
137
+ this._clipRange.extendArray(shapePtsHi);
138
+ return true;
139
+ }
140
+ ensureNumControls(numReqControls) {
141
+ const numCurrent = this._controlIds.length;
142
+ if (numCurrent < numReqControls) {
143
+ const transientIds = this.iModel.transientIds;
144
+ for (let i = numCurrent; i < numReqControls; i++)
145
+ this._controlIds[i] = transientIds.next;
146
+ }
147
+ else if (numCurrent > numReqControls) {
148
+ this._controlIds.length = numReqControls;
149
+ }
150
+ }
151
+ createClipShapeControls() {
152
+ if (undefined === this._clipShape)
153
+ return false;
154
+ const shapePtsLo = ViewClipTool.getClipShapePoints(this._clipShape, this._clipShapeExtents.low);
155
+ const shapePtsHi = ViewClipTool.getClipShapePoints(this._clipShape, this._clipShapeExtents.high);
156
+ const shapeArea = PolygonOps.centroidAreaNormal(shapePtsLo);
157
+ if (undefined === shapeArea)
158
+ return false;
159
+ const numControls = shapePtsLo.length + 1; // Number of edge midpoints plus zLow and zHigh...
160
+ this.ensureNumControls(numControls);
161
+ for (let i = 0; i < numControls - 2; i++) {
162
+ const midPtLo = shapePtsLo[i].interpolate(0.5, shapePtsLo[i + 1]);
163
+ const midPtHi = shapePtsHi[i].interpolate(0.5, shapePtsHi[i + 1]);
164
+ const faceCenter = midPtLo.interpolate(0.5, midPtHi);
165
+ const edgeTangent = Vector3d.createStartEnd(shapePtsLo[i], shapePtsLo[i + 1]);
166
+ const faceNormal = edgeTangent.crossProduct(shapeArea.direction);
167
+ faceNormal.normalizeInPlace();
168
+ this._controls[i] = new ProjectExtentsControlArrow(faceCenter, faceNormal, 0.75);
169
+ this._controls[i].extentValid = (faceNormal.isParallelTo(Vector3d.unitX(), true) ? this._extentsLengthValid : this._extentsWidthValid);
170
+ }
171
+ const zFillColor = ColorDef.from(150, 150, 250);
172
+ this._controls[numControls - 2] = new ProjectExtentsControlArrow(shapeArea.origin, Vector3d.unitZ(-1.0), 0.75, zFillColor, undefined, "zLow");
173
+ this._controls[numControls - 1] = new ProjectExtentsControlArrow(shapeArea.origin.plusScaled(Vector3d.unitZ(), shapePtsLo[0].distance(shapePtsHi[0])), Vector3d.unitZ(), 0.75, zFillColor, undefined, "zHigh");
174
+ this._controls[numControls - 2].extentValid = this._extentsHeightValid;
175
+ this._controls[numControls - 1].extentValid = this._extentsHeightValid;
176
+ return true;
177
+ }
178
+ /** Allow project extents for map projections to be larger since curvature of the earth is accounted for. */
179
+ get maxExtentLength() { return ((this._allowEcefLocationChange ? 20 : 350) * Constant.oneKilometer); }
180
+ /** Impose some reasonable height limit for project extents. */
181
+ get maxExtentHeight() { return (2 * Constant.oneKilometer); }
182
+ hasValidGCS() {
183
+ if (!this.iModel.isGeoLocated || this.iModel.noGcsDefined)
184
+ return false;
185
+ const gcs = this.iModel.geographicCoordinateSystem;
186
+ if (undefined === gcs || undefined === gcs.horizontalCRS)
187
+ return false; // A valid GCS ought to have horizontalCR defined...
188
+ // Check for approximate GCS (such as from MicroStation's "From Placemark" tool) and allow it to be replaced...
189
+ const hasValidId = (undefined !== gcs.horizontalCRS.id && 0 !== gcs.horizontalCRS.id.length);
190
+ const hasValidDescr = (undefined !== gcs.horizontalCRS.description && 0 !== gcs.horizontalCRS.description.length);
191
+ const hasValidProjection = (undefined !== gcs.horizontalCRS.projection && "AzimuthalEqualArea" !== gcs.horizontalCRS.projection.method);
192
+ return hasValidId || hasValidDescr || hasValidProjection;
193
+ }
194
+ async createControls() {
195
+ // Always update to current view clip to handle post-modify, etc.
196
+ if (undefined === this._clipId || !this.getClipData())
197
+ return false;
198
+ this._allowEcefLocationChange = !this.hasValidGCS();
199
+ if (undefined !== this._clipRange) {
200
+ this._extentsLengthValid = (this._clipRange.xLength() < this.maxExtentLength);
201
+ this._extentsWidthValid = (this._clipRange.yLength() < this.maxExtentLength);
202
+ this._extentsHeightValid = (this._clipRange.zLength() < this.maxExtentHeight);
203
+ }
204
+ // Show controls if only range box and it's controls are selected, selection set doesn't include any other elements...
205
+ let showControls = false;
206
+ if (this.iModel.selectionSet.size <= this._controlIds.length + 1 && this.iModel.selectionSet.has(this._clipId)) {
207
+ showControls = true;
208
+ if (this.iModel.selectionSet.size > 1) {
209
+ this.iModel.selectionSet.elements.forEach((val) => {
210
+ if (this._clipId !== val && !this._controlIds.includes(val))
211
+ showControls = false;
212
+ });
213
+ }
214
+ }
215
+ if (!showControls)
216
+ return false; // Don't clear decoration on de-select...
217
+ return this.createClipShapeControls();
218
+ }
219
+ clearControls() {
220
+ this.iModel.selectionSet.remove(this._controlIds); // Remove any selected controls as they won't continue to be displayed...
221
+ super.clearControls();
222
+ }
223
+ async modifyControls(hit, _ev) {
224
+ if (undefined === this._clip || hit.sourceId === this._clipId)
225
+ return false;
226
+ const saveQualifiers = IModelApp.toolAdmin.currentInputState.qualifiers;
227
+ if (undefined !== this._clipShape) {
228
+ const clipShapeModifyTool = new ViewClipShapeModifyTool(this, this._clip, this.viewport, hit.sourceId, this._controlIds, this._controls);
229
+ this._suspendDecorator = await clipShapeModifyTool.run();
230
+ }
231
+ if (this._suspendDecorator)
232
+ IModelApp.toolAdmin.currentInputState.qualifiers = saveQualifiers; // onInstallTool cleared qualifiers, preserve for "modify all" behavior when shift was held and drag started...
233
+ return this._suspendDecorator;
234
+ }
235
+ async onRightClick(_hit, _ev) { return EventHandled.No; }
236
+ async onTouchTap(hit, ev) { return (hit.sourceId === this._clipId ? EventHandled.No : super.onTouchTap(hit, ev)); }
237
+ async onDecorationButtonEvent(hit, ev) {
238
+ if (hit.sourceId === this._monumentId) {
239
+ if (BeButton.Data === ev.button && !ev.isDown && !ev.isDragging)
240
+ await ProjectGeolocationPointTool.startTool();
241
+ return EventHandled.Yes; // Only pickable for tooltip, don't allow selection...
242
+ }
243
+ if (hit.sourceId === this._northId) {
244
+ if (BeButton.Data === ev.button && !ev.isDown && !ev.isDragging)
245
+ await ProjectGeolocationNorthTool.startTool();
246
+ return EventHandled.Yes; // Only pickable for tooltip, don't allow selection...
247
+ }
248
+ return super.onDecorationButtonEvent(hit, ev);
249
+ }
250
+ onManipulatorEvent(eventType) {
251
+ if (EditManipulator.EventType.Accept === eventType)
252
+ this.onChanged.raiseEvent(this.iModel, ProjectLocationChanged.Extents);
253
+ this._suspendDecorator = false;
254
+ super.onManipulatorEvent(eventType);
255
+ }
256
+ async getDecorationToolTip(hit) {
257
+ const quantityFormatter = IModelApp.quantityFormatter;
258
+ const toolTip = document.createElement("div");
259
+ let toolTipHtml = "";
260
+ if (hit.sourceId === this._monumentId) {
261
+ toolTipHtml += `${translateMessage("ModifyGeolocation")}<br>`;
262
+ const coordFormatterSpec = quantityFormatter.findFormatterSpecByQuantityType(QuantityType.Coordinate);
263
+ if (undefined !== coordFormatterSpec) {
264
+ const pointAdjusted = this._monumentPoint.minus(this.iModel.globalOrigin);
265
+ const formattedPointX = quantityFormatter.formatQuantity(pointAdjusted.x, coordFormatterSpec);
266
+ const formattedPointY = quantityFormatter.formatQuantity(pointAdjusted.y, coordFormatterSpec);
267
+ const formattedPointZ = quantityFormatter.formatQuantity(pointAdjusted.z, coordFormatterSpec);
268
+ toolTipHtml += `${translateCoreMeasureBold("Coordinate") + formattedPointX}, ${formattedPointY}, ${formattedPointZ}<br>`;
269
+ }
270
+ const latLongFormatterSpec = quantityFormatter.findFormatterSpecByQuantityType(QuantityType.LatLong);
271
+ if (undefined !== latLongFormatterSpec && undefined !== coordFormatterSpec && this.iModel.isGeoLocated) {
272
+ const cartographic = this.iModel.spatialToCartographicFromEcef(this._monumentPoint);
273
+ const formattedLat = quantityFormatter.formatQuantity(Math.abs(cartographic.latitude), latLongFormatterSpec);
274
+ const formattedLong = quantityFormatter.formatQuantity(Math.abs(cartographic.longitude), latLongFormatterSpec);
275
+ const formattedHeight = quantityFormatter.formatQuantity(cartographic.height, coordFormatterSpec);
276
+ const latDir = CoreTools.translate(cartographic.latitude < 0 ? "Measure.Labels.S" : "Measure.Labels.N");
277
+ const longDir = CoreTools.translate(cartographic.longitude < 0 ? "Measure.Labels.W" : "Measure.Labels.E");
278
+ toolTipHtml += `${translateCoreMeasureBold("LatLong") + formattedLat + latDir}, ${formattedLong}${longDir}<br>`;
279
+ toolTipHtml += `${translateCoreMeasureBold("Altitude") + formattedHeight}<br>`;
280
+ }
281
+ }
282
+ else if (hit.sourceId === this._northId) {
283
+ toolTipHtml += `${translateMessage("ModifyNorthDirection")}<br>`;
284
+ const angleFormatterSpec = quantityFormatter.findFormatterSpecByQuantityType(QuantityType.Angle);
285
+ if (undefined !== angleFormatterSpec) {
286
+ const formattedAngle = quantityFormatter.formatQuantity(this.getClockwiseAngleToNorth().radians, angleFormatterSpec);
287
+ toolTipHtml += `${translateMessageBold("Angle") + formattedAngle}<br>`;
288
+ }
289
+ }
290
+ else if (hit.sourceId === this._clipId) {
291
+ const extentsValid = (this._extentsLengthValid && this._extentsWidthValid && this._extentsHeightValid);
292
+ toolTipHtml += `${translateMessage(extentsValid ? "ProjectExtents" : "LargeProjectExtents")}<br>`;
293
+ const distanceFormatterSpec = quantityFormatter.findFormatterSpecByQuantityType(QuantityType.Length);
294
+ if (undefined !== distanceFormatterSpec && undefined !== this._clipRange) {
295
+ const formattedLength = quantityFormatter.formatQuantity(this._clipRange.xLength(), distanceFormatterSpec);
296
+ const formattedWidth = quantityFormatter.formatQuantity(this._clipRange.yLength(), distanceFormatterSpec);
297
+ const formattedHeight = quantityFormatter.formatQuantity(this._clipRange.zLength(), distanceFormatterSpec);
298
+ toolTipHtml += `${translateMessageBold("Length") + formattedLength}<br>`;
299
+ toolTipHtml += `${translateMessageBold("Width") + formattedWidth}<br>`;
300
+ toolTipHtml += `${translateMessageBold("Height") + formattedHeight}<br>`;
301
+ }
302
+ }
303
+ else {
304
+ const arrowIndex = this._controlIds.indexOf(hit.sourceId);
305
+ if (-1 !== arrowIndex) {
306
+ toolTipHtml += `${translateMessage("ModifyProjectExtents")}<br>`;
307
+ const distanceFormatterSpec = quantityFormatter.findFormatterSpecByQuantityType(QuantityType.Length);
308
+ if (undefined !== distanceFormatterSpec && undefined !== this._clipRange) {
309
+ const arrowControl = this._controls[arrowIndex];
310
+ let arrowLabel = "";
311
+ let arrowLength = 0.0;
312
+ let arrowLengthMax = 0.0;
313
+ if (arrowControl.direction.isParallelTo(Vector3d.unitX(), true)) {
314
+ arrowLabel = "Length";
315
+ arrowLength = this._clipRange.xLength();
316
+ if (!this._extentsLengthValid)
317
+ arrowLengthMax = this.maxExtentLength;
318
+ }
319
+ else if (arrowControl.direction.isParallelTo(Vector3d.unitY(), true)) {
320
+ arrowLabel = "Width";
321
+ arrowLength = this._clipRange.yLength();
322
+ if (!this._extentsWidthValid)
323
+ arrowLengthMax = this.maxExtentLength;
324
+ }
325
+ else {
326
+ arrowLabel = "Height";
327
+ arrowLength = this._clipRange.zLength();
328
+ if (!this._extentsHeightValid)
329
+ arrowLengthMax = this.maxExtentHeight;
330
+ const coordFormatterSpec = (this.iModel.isGeoLocated ? quantityFormatter.findFormatterSpecByQuantityType(QuantityType.Coordinate) : undefined);
331
+ if (undefined !== coordFormatterSpec) {
332
+ const heightPt = ("zLow" === arrowControl.name ? this._clipRange.low : this._clipRange.high);
333
+ const cartographic = this.iModel.spatialToCartographicFromEcef(heightPt);
334
+ const formattedAltitude = quantityFormatter.formatQuantity(cartographic.height, coordFormatterSpec);
335
+ toolTipHtml += `${translateCoreMeasureBold("Altitude") + formattedAltitude}<br>`;
336
+ }
337
+ }
338
+ const formattedLength = quantityFormatter.formatQuantity(arrowLength, distanceFormatterSpec);
339
+ toolTipHtml += `${translateMessageBold(arrowLabel) + formattedLength}<br>`;
340
+ if (0.0 !== arrowLengthMax) {
341
+ const formattedMaxLength = quantityFormatter.formatQuantity(arrowLengthMax, distanceFormatterSpec);
342
+ toolTipHtml += `${translateMessageBold("MaxExtent") + formattedMaxLength}<br>`;
343
+ }
344
+ }
345
+ }
346
+ }
347
+ toolTip.innerHTML = toolTipHtml;
348
+ return toolTip;
349
+ }
350
+ testDecorationHit(id) { return (id === this._monumentId || id === this._northId || id === this._clipId || this._controlIds.includes(id)); }
351
+ updateDecorationListener(_add) { super.updateDecorationListener(undefined !== this._clipId); } // Decorator isn't just for resize controls...
352
+ getMonumentPoint() {
353
+ const origin = Point3d.createZero();
354
+ if (this.iModel.ecefLocation && this.iModel.ecefLocation.cartographicOrigin)
355
+ return this.iModel.cartographicToSpatialFromEcef(this.iModel.ecefLocation.cartographicOrigin, origin);
356
+ origin.setFrom(this.iModel.projectExtents.low);
357
+ if (0.0 > this.iModel.projectExtents.low.z && 0.0 < this.iModel.projectExtents.high.z)
358
+ origin.z = 0.0;
359
+ return origin;
360
+ }
361
+ getClockwiseAngleToNorth() {
362
+ const angle = this.getNorthAngle();
363
+ angle.setRadians(Angle.adjustRadians0To2Pi(angle.radians));
364
+ return angle;
365
+ }
366
+ getNorthAngle() {
367
+ const northDirection = (undefined !== this._northDirection ? this._northDirection : this.getNorthDirection());
368
+ return northDirection.direction.angleToXY(Vector3d.unitY());
369
+ }
370
+ getNorthDirection(refOrigin) {
371
+ const origin = (undefined !== refOrigin ? refOrigin : this.iModel.projectExtents.center);
372
+ if (!this.iModel.isGeoLocated)
373
+ return Ray3d.create(origin, Vector3d.unitY());
374
+ const cartographic = this.iModel.spatialToCartographicFromEcef(origin);
375
+ cartographic.latitude += Angle.createDegrees(0.01).radians;
376
+ const pt2 = this.iModel.cartographicToSpatialFromEcef(cartographic);
377
+ const northVec = Vector3d.createStartEnd(origin, pt2);
378
+ northVec.z = 0.0;
379
+ northVec.normalizeInPlace();
380
+ return Ray3d.create(origin, northVec);
381
+ }
382
+ drawNorthArrow(context, northDir, id) {
383
+ const vp = context.viewport;
384
+ const pixelSize = vp.pixelsFromInches(0.55);
385
+ const scale = vp.viewingSpace.getPixelSizeAtPoint(northDir.origin) * pixelSize;
386
+ const matrix = Matrix3d.createRigidFromColumns(northDir.direction, Vector3d.unitZ(), AxisOrder.YZX);
387
+ if (undefined === matrix)
388
+ return;
389
+ matrix.scaleColumnsInPlace(scale, scale, scale);
390
+ const arrowTrans = Transform.createRefs(northDir.origin, matrix);
391
+ const northArrowBuilder = context.createGraphicBuilder(GraphicType.WorldOverlay, arrowTrans, id);
392
+ const color = ColorDef.white;
393
+ const arrowOutline = [];
394
+ arrowOutline[0] = Point3d.create(0.0, 0.65);
395
+ arrowOutline[1] = Point3d.create(-0.45, -0.5);
396
+ arrowOutline[2] = Point3d.create(0.0, -0.2);
397
+ arrowOutline[3] = Point3d.create(0.45, -0.5);
398
+ arrowOutline[4] = arrowOutline[0].clone();
399
+ const arrowLeftFill = [];
400
+ arrowLeftFill[0] = arrowOutline[0].clone();
401
+ arrowLeftFill[1] = arrowOutline[1].clone();
402
+ arrowLeftFill[2] = arrowOutline[2].clone();
403
+ arrowLeftFill[3] = arrowLeftFill[0].clone();
404
+ const arrowRightFill = [];
405
+ arrowRightFill[0] = arrowOutline[0].clone();
406
+ arrowRightFill[1] = arrowOutline[3].clone();
407
+ arrowRightFill[2] = arrowOutline[2].clone();
408
+ arrowRightFill[3] = arrowRightFill[0].clone();
409
+ northArrowBuilder.setSymbology(color, ColorDef.from(0, 0, 0, 200), 1);
410
+ northArrowBuilder.addArc(Arc3d.createXY(Point3d.createZero(), 0.6), true, true);
411
+ northArrowBuilder.addArc(Arc3d.createXY(Point3d.create(0.0, 0.85), 0.2), true, true);
412
+ northArrowBuilder.setSymbology(color, color, 2);
413
+ northArrowBuilder.addArc(Arc3d.createXY(Point3d.createZero(), 0.5), false, false);
414
+ northArrowBuilder.addLineString([Point3d.create(0.6, 0.0), Point3d.create(-0.6, 0.0)]);
415
+ northArrowBuilder.addLineString([Point3d.create(0.0, 0.6), Point3d.create(0.0, -0.6)]);
416
+ northArrowBuilder.setSymbology(color, ColorDef.from(150, 150, 150), 1);
417
+ northArrowBuilder.addShape(arrowLeftFill);
418
+ northArrowBuilder.setSymbology(color, ColorDef.black, 1);
419
+ northArrowBuilder.addShape(arrowRightFill);
420
+ northArrowBuilder.setSymbology(color, color, 1);
421
+ northArrowBuilder.addLineString(arrowOutline);
422
+ northArrowBuilder.setSymbology(color, color, 3);
423
+ northArrowBuilder.addLineString([Point3d.create(-0.1, 0.75), Point3d.create(-0.1, 0.95), Point3d.create(0.1, 0.75), Point3d.create(0.1, 0.95)]);
424
+ context.addDecorationFromBuilder(northArrowBuilder);
425
+ }
426
+ drawMonumentPoint(context, point, scaleFactor, id) {
427
+ const vp = context.viewport;
428
+ const pixelSize = vp.pixelsFromInches(0.25) * scaleFactor;
429
+ const scale = vp.viewingSpace.getPixelSizeAtPoint(point) * pixelSize;
430
+ const matrix = Matrix3d.createRotationAroundAxisIndex(AxisIndex.Z, Angle.createDegrees(45.0));
431
+ matrix.scaleColumnsInPlace(scale, scale, scale);
432
+ const monumentTrans = Transform.createRefs(point, matrix);
433
+ const monumentPointBuilder = context.createGraphicBuilder(GraphicType.WorldOverlay, monumentTrans, id);
434
+ const color = ColorDef.white;
435
+ monumentPointBuilder.setSymbology(color, ColorDef.from(0, 0, 0, 150), 1);
436
+ monumentPointBuilder.addArc(Arc3d.createXY(Point3d.createZero(), 0.7), true, true);
437
+ monumentPointBuilder.setSymbology(color, color, 2);
438
+ monumentPointBuilder.addArc(Arc3d.createXY(Point3d.createZero(), 0.5), false, false);
439
+ monumentPointBuilder.addLineString([Point3d.create(0.5, 0.0), Point3d.create(-0.5, 0.0)]);
440
+ monumentPointBuilder.addLineString([Point3d.create(0.0, 0.5), Point3d.create(0.0, -0.5)]);
441
+ context.addDecorationFromBuilder(monumentPointBuilder);
442
+ }
443
+ drawAreaTooLargeIndicator(context) {
444
+ if ((this._extentsLengthValid && this._extentsWidthValid) || undefined === this._clipRange)
445
+ return;
446
+ const corners = this._clipRange.corners();
447
+ const indices = Range3d.faceCornerIndices(5);
448
+ const points = [];
449
+ for (const index of indices)
450
+ points.push(corners[index]);
451
+ const areaWarnColor = ColorDef.red.withAlpha(50);
452
+ const areaWarnBuilder = context.createGraphicBuilder(GraphicType.WorldDecoration);
453
+ areaWarnBuilder.setSymbology(areaWarnColor, areaWarnColor, 1);
454
+ areaWarnBuilder.addShape(points);
455
+ context.addDecorationFromBuilder(areaWarnBuilder);
456
+ }
457
+ drawExtentTooLargeIndicator(context, worldPoint, sizePixels) {
458
+ const position = context.viewport.worldToView(worldPoint);
459
+ position.x = Math.floor(position.x) + 0.5;
460
+ position.y = Math.floor(position.y) + 0.5;
461
+ const drawDecoration = (ctx) => {
462
+ ctx.lineWidth = 4;
463
+ ctx.lineCap = "round";
464
+ ctx.strokeStyle = "rgba(255,0,0,.75)";
465
+ ctx.fillStyle = "rgba(255,255,255,.75)";
466
+ ctx.shadowColor = "black";
467
+ ctx.shadowBlur = 5;
468
+ ctx.beginPath();
469
+ ctx.moveTo(0, -sizePixels);
470
+ ctx.lineTo(-sizePixels, sizePixels);
471
+ ctx.lineTo(sizePixels, sizePixels);
472
+ ctx.lineTo(0, -sizePixels);
473
+ ctx.fill();
474
+ ctx.shadowBlur = 0;
475
+ ctx.beginPath();
476
+ ctx.moveTo(0, -sizePixels);
477
+ ctx.lineTo(-sizePixels, sizePixels);
478
+ ctx.lineTo(sizePixels, sizePixels);
479
+ ctx.lineTo(0, -sizePixels);
480
+ ctx.stroke();
481
+ ctx.strokeStyle = "black";
482
+ ctx.lineWidth = 3;
483
+ ctx.beginPath();
484
+ ctx.moveTo(0, -sizePixels * 0.2);
485
+ ctx.lineTo(0, sizePixels * 0.3);
486
+ ctx.moveTo(0, (sizePixels * 0.3) + 4);
487
+ ctx.lineTo(0, (sizePixels * 0.3) + 4.5);
488
+ ctx.stroke();
489
+ };
490
+ context.addCanvasDecoration({ position, drawDecoration });
491
+ }
492
+ decorate(context) {
493
+ if (this._suspendDecorator)
494
+ return;
495
+ if (undefined === this._clipId || undefined === this._clipShape || undefined === this._clipRange)
496
+ return;
497
+ const vp = context.viewport;
498
+ if (this.viewport !== vp)
499
+ return;
500
+ if (!this.suspendGeolocationDecorations && undefined !== this._northDirection && this.iModel.isGeoLocated)
501
+ this.drawNorthArrow(context, this._northDirection, this._allowEcefLocationChange ? this._northId : undefined); // Show north, but don't make pickable if it shouldn't be modified...
502
+ const maxSizeInches = ((this._clipRange.maxLength() / vp.viewingSpace.getPixelSizeAtPoint(this._clipRange.center)) / vp.pixelsPerInch) * 0.5; // Display size limit when zooming out...
503
+ if (maxSizeInches < 0.5)
504
+ return;
505
+ if (!this.suspendGeolocationDecorations && undefined !== this._monumentPoint && this._allowEcefLocationChange)
506
+ this.drawMonumentPoint(context, this._monumentPoint, 1.0, this._monumentId);
507
+ ViewClipTool.drawClipShape(context, this._clipShape, this._clipShapeExtents, ColorDef.white.adjustedForContrast(context.viewport.view.backgroundColor), 3, this._clipId);
508
+ this.drawAreaTooLargeIndicator(context);
509
+ if (!this._isActive)
510
+ return;
511
+ const outlineColor = ColorDef.from(0, 0, 0, 50).adjustedForContrast(vp.view.backgroundColor);
512
+ const fillVisColor = ColorDef.from(150, 250, 200, 225).adjustedForContrast(vp.view.backgroundColor);
513
+ const fillHidColor = fillVisColor.withAlpha(200);
514
+ const fillSelColor = fillVisColor.inverse().withAlpha(75);
515
+ const shapePts = EditManipulator.HandleUtils.getArrowShape(0.0, 0.15, 0.55, 1.0, 0.3, 0.5, 0.1);
516
+ for (let iFace = 0; iFace < this._controlIds.length; iFace++) {
517
+ const sizeInches = Math.min(this._controls[iFace].sizeInches, maxSizeInches);
518
+ if (0.0 === sizeInches)
519
+ continue;
520
+ const anchorRay = ViewClipTool.getClipRayTransformed(this._controls[iFace].origin, this._controls[iFace].direction, undefined !== this._clipShape ? this._clipShape.transformFromClip : undefined);
521
+ const transform = EditManipulator.HandleUtils.getArrowTransform(vp, anchorRay.origin, anchorRay.direction, sizeInches);
522
+ if (undefined === transform)
523
+ continue;
524
+ const visPts = [];
525
+ for (const pt of shapePts)
526
+ visPts.push(pt.clone()); // deep copy because we're using a builder transform w/addLineString...
527
+ const hidPts = [];
528
+ for (const pt of shapePts)
529
+ hidPts.push(pt.clone());
530
+ const arrowVisBuilder = context.createGraphicBuilder(GraphicType.WorldOverlay, transform, this._controlIds[iFace]);
531
+ const arrowHidBuilder = context.createGraphicBuilder(GraphicType.WorldDecoration, transform);
532
+ const isSelected = this.iModel.selectionSet.has(this._controlIds[iFace]);
533
+ let outlineColorOvr = this._controls[iFace].outline;
534
+ if (undefined !== outlineColorOvr) {
535
+ outlineColorOvr = outlineColorOvr.adjustedForContrast(vp.view.backgroundColor);
536
+ outlineColorOvr = outlineColorOvr.withAlpha(outlineColor.getAlpha());
537
+ }
538
+ else {
539
+ outlineColorOvr = outlineColor;
540
+ }
541
+ let fillVisColorOvr = this._controls[iFace].fill;
542
+ let fillHidColorOvr = fillHidColor;
543
+ let fillSelColorOvr = fillSelColor;
544
+ if (undefined !== fillVisColorOvr) {
545
+ fillVisColorOvr = fillVisColorOvr.adjustedForContrast(vp.view.backgroundColor);
546
+ fillVisColorOvr = fillVisColorOvr.withAlpha(fillVisColor.getAlpha());
547
+ fillHidColorOvr = fillVisColorOvr.withAlpha(fillHidColor.getAlpha());
548
+ fillSelColorOvr = fillVisColorOvr.inverse().withAlpha(fillSelColor.getAlpha());
549
+ }
550
+ else {
551
+ fillVisColorOvr = fillVisColor;
552
+ }
553
+ arrowVisBuilder.setSymbology(outlineColorOvr, outlineColorOvr, isSelected ? 4 : 2);
554
+ arrowVisBuilder.addLineString(visPts);
555
+ arrowVisBuilder.setBlankingFill(isSelected ? fillSelColorOvr : fillVisColorOvr);
556
+ arrowVisBuilder.addShape(visPts);
557
+ context.addDecorationFromBuilder(arrowVisBuilder);
558
+ arrowHidBuilder.setSymbology(fillHidColorOvr, fillHidColorOvr, 1);
559
+ arrowHidBuilder.addShape(hidPts);
560
+ context.addDecorationFromBuilder(arrowHidBuilder);
561
+ if (this._controls[iFace].extentValid)
562
+ continue;
563
+ const warnPixels = 15.0;
564
+ const warnOffset = vp.viewingSpace.getPixelSizeAtPoint(anchorRay.origin) * warnPixels * 1.5;
565
+ const warnOrigin = anchorRay.origin.plusScaled(anchorRay.direction, -warnOffset);
566
+ this.drawExtentTooLargeIndicator(context, warnOrigin, warnPixels);
567
+ }
568
+ }
569
+ resetViewClip() {
570
+ if (!clearViewClip(this.viewport))
571
+ return false;
572
+ if (undefined !== this.getModifiedExtents())
573
+ this.onChanged.raiseEvent(this.iModel, ProjectLocationChanged.ResetExtents);
574
+ return true;
575
+ }
576
+ resetGeolocation() {
577
+ if (!this._allowEcefLocationChange)
578
+ return false;
579
+ if (undefined === this.getModifiedEcefLocation())
580
+ return false; // Wasn't changed...
581
+ this.iModel.disableGCS(false);
582
+ this.iModel.ecefLocation = this._ecefLocation;
583
+ this._monumentPoint = this.getMonumentPoint();
584
+ this._northDirection = this.getNorthDirection();
585
+ updateMapDisplay(this.viewport, false);
586
+ this.onChanged.raiseEvent(this.iModel, ProjectLocationChanged.ResetGeolocation);
587
+ return true;
588
+ }
589
+ updateEcefLocation(origin, point, angle) {
590
+ if (!this._allowEcefLocationChange)
591
+ return false;
592
+ const newEcefLocation = EcefLocation.createFromCartographicOrigin(origin, point, (undefined !== angle ? angle : this.getNorthAngle())); // Preserve modified north direction...
593
+ const ecefLocation = this.iModel.ecefLocation;
594
+ if (undefined !== ecefLocation && ecefLocation.isAlmostEqual(newEcefLocation))
595
+ return false;
596
+ this.iModel.disableGCS(true); // Map display will ignore change to ecef location when GCS is present...
597
+ this.iModel.setEcefLocation(newEcefLocation);
598
+ this._monumentPoint = this.getMonumentPoint();
599
+ this._northDirection = this.getNorthDirection(undefined !== this._northDirection ? this._northDirection.origin : undefined); // Preserve modified north reference point...
600
+ updateMapDisplay(this.viewport, true);
601
+ this.onChanged.raiseEvent(this.iModel, ProjectLocationChanged.Geolocation);
602
+ return true;
603
+ }
604
+ updateNorthDirection(northDir) {
605
+ if (!this._allowEcefLocationChange || !this.iModel.isGeoLocated)
606
+ return false;
607
+ const point = (undefined !== this._monumentPoint ? this._monumentPoint : this.getMonumentPoint()); // Preserve modified monument point...
608
+ const origin = this.iModel.spatialToCartographicFromEcef(point);
609
+ const saveDirection = this._northDirection;
610
+ this._northDirection = northDir; // Change reference point to input location...
611
+ const angle = this.getNorthAngle();
612
+ if (!this.updateEcefLocation(origin, point, angle)) {
613
+ this._northDirection = saveDirection;
614
+ return false;
615
+ }
616
+ return true;
617
+ }
618
+ getModifiedEcefLocation() {
619
+ const ecefLocation = this.iModel.ecefLocation;
620
+ if (undefined === ecefLocation)
621
+ return undefined; // geolocation wasn't added...
622
+ if (undefined === this._ecefLocation)
623
+ return ecefLocation; // geolocation didn't exist previously...
624
+ if (this._ecefLocation.isAlmostEqual(ecefLocation))
625
+ return undefined;
626
+ return ecefLocation;
627
+ }
628
+ getModifiedExtents() {
629
+ if (undefined === this._clipRange)
630
+ return undefined;
631
+ return this._clipRange.isAlmostEqual(this.iModel.projectExtents) ? undefined : this._clipRange;
632
+ }
633
+ static allowEcefLocationChange(requireExisting, outputError = true) {
634
+ if (undefined === ProjectExtentsClipDecoration._decorator) {
635
+ if (outputError)
636
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, translateMessage("NotActive")));
637
+ return false;
638
+ }
639
+ else if (!ProjectExtentsClipDecoration._decorator._allowEcefLocationChange) {
640
+ if (outputError)
641
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, translateMessage("NotAllowed")));
642
+ return false;
643
+ }
644
+ else if (requireExisting && !ProjectExtentsClipDecoration._decorator.iModel.isGeoLocated) {
645
+ if (outputError)
646
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, translateMessage("NotGeolocated")));
647
+ return false;
648
+ }
649
+ return true;
650
+ }
651
+ fitExtents() {
652
+ if (undefined === this._clipRange)
653
+ return undefined;
654
+ const options = { animateFrustumChange: true, animationTime: BeDuration.fromSeconds(2).milliseconds };
655
+ const aspect = this.viewport.viewRect.aspect;
656
+ this.viewport.view.lookAtVolume(this._clipRange, aspect);
657
+ this.viewport.synchWithView(options);
658
+ this.viewport.viewCmdTargetCenter = undefined;
659
+ }
660
+ static get() {
661
+ if (undefined === ProjectExtentsClipDecoration._decorator)
662
+ return undefined;
663
+ return ProjectExtentsClipDecoration._decorator;
664
+ }
665
+ static show(vp, fitExtents = true) {
666
+ if (!vp.view.isSpatialView())
667
+ return false;
668
+ if (undefined !== ProjectExtentsClipDecoration._decorator) {
669
+ const deco = ProjectExtentsClipDecoration._decorator;
670
+ if (vp === deco.viewport && undefined !== deco._clipId && undefined !== deco._clip) {
671
+ if (deco._clip !== vp.view.getViewClip()) {
672
+ clearViewClip(vp);
673
+ ViewClipTool.enableClipVolume(vp);
674
+ ViewClipTool.setViewClip(vp, deco._clip);
675
+ }
676
+ if (undefined === deco._removeManipulatorToolListener) {
677
+ deco._removeManipulatorToolListener = IModelApp.toolAdmin.manipulatorToolEvent.addListener((tool, event) => deco.onManipulatorToolEvent(tool, event));
678
+ deco.start();
679
+ deco.onChanged.raiseEvent(deco.iModel, ProjectLocationChanged.Show);
680
+ }
681
+ return true;
682
+ }
683
+ ProjectExtentsClipDecoration.clear();
684
+ }
685
+ if (!clipToProjectExtents(vp))
686
+ return false;
687
+ ProjectExtentsClipDecoration._decorator = new ProjectExtentsClipDecoration(vp);
688
+ if (fitExtents)
689
+ ProjectExtentsClipDecoration._decorator.fitExtents();
690
+ vp.onChangeView.addOnce(() => this.clear(false, true));
691
+ return (undefined !== ProjectExtentsClipDecoration._decorator._clipId);
692
+ }
693
+ static hide() {
694
+ if (undefined === ProjectExtentsClipDecoration._decorator)
695
+ return;
696
+ const saveClipId = ProjectExtentsClipDecoration._decorator._clipId; // cleared by stop to trigger decorator removal...
697
+ ProjectExtentsClipDecoration._decorator.stop();
698
+ ProjectExtentsClipDecoration._decorator._clipId = saveClipId;
699
+ ProjectExtentsClipDecoration._decorator.onChanged.raiseEvent(ProjectExtentsClipDecoration._decorator.iModel, ProjectLocationChanged.Hide);
700
+ }
701
+ static clear(clearClip = true, resetGeolocation = true) {
702
+ if (undefined === ProjectExtentsClipDecoration._decorator)
703
+ return;
704
+ if (clearClip)
705
+ ProjectExtentsClipDecoration._decorator.resetViewClip(); // Clear project extents view clip...
706
+ if (resetGeolocation)
707
+ ProjectExtentsClipDecoration._decorator.resetGeolocation(); // Restore modified geolocation back to create state...
708
+ ProjectExtentsClipDecoration._decorator.stop();
709
+ ProjectExtentsClipDecoration._decorator = undefined;
710
+ }
711
+ static async update() {
712
+ const deco = ProjectExtentsClipDecoration._decorator;
713
+ if (undefined === deco)
714
+ return;
715
+ clipToProjectExtents(deco.viewport);
716
+ deco.init();
717
+ return deco.updateControls();
718
+ }
719
+ }
720
+ /** Show project location decoration. Project extents represented by view clip.
721
+ * @beta
722
+ */
723
+ export class ProjectLocationShowTool extends Tool {
724
+ async run() {
725
+ const vp = IModelApp.viewManager.selectedView;
726
+ if (undefined === vp || !ProjectExtentsClipDecoration.show(vp))
727
+ return false;
728
+ await IModelApp.toolAdmin.startDefaultTool();
729
+ return true;
730
+ }
731
+ }
732
+ ProjectLocationShowTool.toolId = "ProjectLocation.Show";
733
+ /** Hide project location decoration. Preserves changes to project extents view clip and geolocation.
734
+ * @beta
735
+ */
736
+ export class ProjectLocationHideTool extends Tool {
737
+ async run() {
738
+ ProjectExtentsClipDecoration.hide();
739
+ await IModelApp.toolAdmin.startDefaultTool();
740
+ return true;
741
+ }
742
+ }
743
+ ProjectLocationHideTool.toolId = "ProjectLocation.Hide";
744
+ /** Clear project location decoration. Restore modified geolocation and remove view clip.
745
+ * @beta
746
+ */
747
+ export class ProjectLocationCancelTool extends Tool {
748
+ async run() {
749
+ ProjectExtentsClipDecoration.clear();
750
+ await IModelApp.toolAdmin.startDefaultTool();
751
+ return true;
752
+ }
753
+ }
754
+ ProjectLocationCancelTool.toolId = "ProjectLocation.Cancel";
755
+ /** Save modified project extents and geolocation. Updates decoration to reflect saved state.
756
+ * @note Allowing this change to be undone is both problematic and undesirable.
757
+ * Warns the user if called with previous changes to cancel restarting the TxnManager session.
758
+ * @beta
759
+ */
760
+ export class ProjectLocationSaveTool extends Tool {
761
+ static callCommand(method, ...args) {
762
+ return EditTools.callCommand(method, ...args);
763
+ }
764
+ async allowRestartTxnSession(iModel) {
765
+ if (!await iModel.txns.isUndoPossible())
766
+ return true;
767
+ // NOTE: Default if openMessageBox isn't implemented is MessageBoxValue.Ok, so we'll check No instead of Yes...
768
+ if (MessageBoxValue.No === await IModelApp.notifications.openMessageBox(MessageBoxType.YesNo, translateMessage("RestartTxn"), MessageBoxIconType.Question))
769
+ return false;
770
+ return true;
771
+ }
772
+ async saveChanges(deco, extents, ecefLocation) {
773
+ if (!deco.iModel.isBriefcaseConnection())
774
+ return;
775
+ if (!await this.allowRestartTxnSession(deco.iModel))
776
+ return;
777
+ try {
778
+ await EditTools.startCommand(editorBuiltInCmdIds.cmdBasicManipulation, deco.iModel.key);
779
+ if (undefined !== extents)
780
+ await ProjectLocationSaveTool.callCommand("updateProjectExtents", extents);
781
+ if (undefined !== ecefLocation)
782
+ await ProjectLocationSaveTool.callCommand("updateEcefLocation", ecefLocation);
783
+ await deco.iModel.saveChanges(this.toolId);
784
+ await deco.iModel.txns.restartTxnSession();
785
+ }
786
+ catch (err) {
787
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, BentleyError.getErrorMessage(err) || "An unknown error occurred."));
788
+ }
789
+ deco.onChanged.raiseEvent(deco.iModel, ProjectLocationChanged.Save);
790
+ await ProjectExtentsClipDecoration.update();
791
+ return IModelApp.toolAdmin.startDefaultTool();
792
+ }
793
+ async run() {
794
+ const deco = ProjectExtentsClipDecoration.get();
795
+ if (undefined === deco) {
796
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, translateMessage("NotActive")));
797
+ return false;
798
+ }
799
+ if (deco.iModel.isReadonly) {
800
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, translateMessage("Readonly")));
801
+ return true;
802
+ }
803
+ const extents = deco.getModifiedExtents();
804
+ const ecefLocation = deco.getModifiedEcefLocation();
805
+ if (undefined === extents && undefined === ecefLocation) {
806
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, translateMessage("NoChanges")));
807
+ return true;
808
+ }
809
+ await this.saveChanges(deco, extents, ecefLocation);
810
+ return true;
811
+ }
812
+ }
813
+ ProjectLocationSaveTool.toolId = "ProjectLocation.Save";
814
814
  //# sourceMappingURL=ProjectExtentsDecoration.js.map