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

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,502 +1,502 @@
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 { AccuDrawHintBuilder, AccuDrawShortcuts, AngleDescription, CoreTools, EventHandled, GraphicType, IModelApp, LengthDescription, PrimitiveTool, ToolAssistance, ToolAssistanceImage, ToolAssistanceInputMethod } from "@itwin/core-frontend";
9
- import { Angle, Matrix3d, Point3d, Ray3d, Vector3d } from "@itwin/core-geometry";
10
- import { Cartographic, ColorDef, LinePixels } from "@itwin/core-common";
11
- import { ProjectExtentsClipDecoration } from "./ProjectExtentsDecoration";
12
- import { DialogProperty } from "@itwin/appui-abstract";
13
- import { EditTools } from "../EditTool";
14
- function translatePrompt(key) { return EditTools.translate(`ProjectLocation:Prompts.${key}`); }
15
- function translateMessage(key) { return EditTools.translate(`ProjectLocation:Message.${key}`); }
16
- /** @internal */
17
- class LabelDecoration {
18
- constructor(worldLocation, label) {
19
- this.worldLocation = new Point3d();
20
- this.position = new Point3d();
21
- this.worldLocation.setFrom(worldLocation);
22
- this.label = label;
23
- }
24
- drawDecoration(ctx) {
25
- ctx.font = "16px san-serif";
26
- const labelHeight = ctx.measureText("M").width; // Close enough for border padding...
27
- const labelWidth = ctx.measureText(this.label).width + labelHeight;
28
- ctx.lineWidth = 1;
29
- ctx.strokeStyle = "white";
30
- ctx.fillStyle = "rgba(0,0,0,.4)";
31
- ctx.shadowColor = "black";
32
- ctx.shadowBlur = 10;
33
- ctx.fillRect(-(labelWidth / 2), -labelHeight, labelWidth, labelHeight * 2);
34
- ctx.strokeRect(-(labelWidth / 2), -labelHeight, labelWidth, labelHeight * 2);
35
- ctx.fillStyle = "white";
36
- ctx.shadowBlur = 0;
37
- ctx.textAlign = "center";
38
- ctx.textBaseline = "middle";
39
- ctx.fillText(this.label, 0, 0);
40
- }
41
- setPosition(vp) {
42
- vp.worldToView(this.worldLocation, this.position);
43
- this.position.y -= Math.floor(vp.pixelsFromInches(0.45)) + 0.5; // Offset from world location...
44
- return vp.viewRect.containsPoint(this.position);
45
- }
46
- addDecoration(context) {
47
- if (this.setPosition(context.viewport))
48
- context.addCanvasDecoration(this);
49
- }
50
- }
51
- /** Change or update geolocation for project.
52
- * To show tool settings for specifying lat/long, make sure formatting and parsing data are cached before the tool starts
53
- * by calling QuantityFormatter.onInitialized at app startup.
54
- * @beta
55
- */
56
- export class ProjectGeolocationPointTool extends PrimitiveTool {
57
- constructor() {
58
- super(...arguments);
59
- this._haveToolSettings = false;
60
- this._cartographicFromArgs = false;
61
- this._accept = false;
62
- this._scale = 1.0;
63
- }
64
- static get minArgs() { return 0; }
65
- static get maxArgs() { return 4; } // latitude, longitude, altitude, north direction...
66
- isCompatibleViewport(vp, isSelectedViewChange) { return (super.isCompatibleViewport(vp, isSelectedViewChange) && undefined !== vp && vp.view.isSpatialView()); }
67
- isValidLocation(_ev, _isButtonEvent) { return true; } // Allow snapping to terrain, etc. outside project extents...
68
- requireWriteableTarget() { return false; } // Tool doesn't modify the imodel...
69
- async onPostInstall() { await super.onPostInstall(); this.setupAndPromptForNextAction(); }
70
- async onCleanup() { await super.onCleanup(); this.unsuspendDecorations(); }
71
- async onRestartTool() { return this.exitTool(); }
72
- async onUnsuspend() { this.provideToolAssistance(); }
73
- get latitudeProperty() {
74
- if (!this._latitudeProperty)
75
- this._latitudeProperty = new DialogProperty(new AngleDescription("latitude", translateMessage("Latitude")), 0.0);
76
- return this._latitudeProperty;
77
- }
78
- get latitude() { return this.latitudeProperty.value; }
79
- set latitude(value) { this.latitudeProperty.value = value; }
80
- get longitudeProperty() {
81
- if (!this._longitudeProperty)
82
- this._longitudeProperty = new DialogProperty(new AngleDescription("longitude", translateMessage("Longitude")), 0.0);
83
- return this._longitudeProperty;
84
- }
85
- get longitude() { return this.longitudeProperty.value; }
86
- set longitude(value) { this.longitudeProperty.value = value; }
87
- get altitudeProperty() {
88
- if (!this._altitudeProperty)
89
- this._altitudeProperty = new DialogProperty(new LengthDescription("altitude", CoreTools.translate("Measure.Labels.Altitude")), 0.0);
90
- return this._altitudeProperty;
91
- }
92
- get altitude() { return this.altitudeProperty.value; }
93
- set altitude(value) { this.altitudeProperty.value = value; }
94
- get northProperty() {
95
- if (!this._northProperty)
96
- this._northProperty = new DialogProperty(new AngleDescription("north", translateMessage("North")), 0.0);
97
- return this._northProperty;
98
- }
99
- get north() { return this.northProperty.value; }
100
- set north(value) { this.northProperty.value = value; }
101
- syncToolSettingsCoordinates() {
102
- this.syncToolSettingsProperties([this.latitudeProperty.syncItem, this.longitudeProperty.syncItem, this.altitudeProperty.syncItem, this.northProperty.syncItem]);
103
- }
104
- async applyToolSettingPropertyChange(updatedValue) {
105
- return this.changeToolSettingPropertyValue(updatedValue);
106
- }
107
- supplyToolSettingsProperties() {
108
- this._haveToolSettings = true;
109
- const toolSettings = new Array();
110
- toolSettings.push(this.latitudeProperty.toDialogItem({ rowPriority: 1, columnIndex: 2 }));
111
- toolSettings.push(this.longitudeProperty.toDialogItem({ rowPriority: 2, columnIndex: 2 }));
112
- toolSettings.push(this.altitudeProperty.toDialogItem({ rowPriority: 3, columnIndex: 2 }));
113
- toolSettings.push(this.northProperty.toDialogItem({ rowPriority: 4, columnIndex: 2 }));
114
- return toolSettings;
115
- }
116
- provideToolAssistance() {
117
- const acceptMsg = CoreTools.translate(undefined === this._origin ? "ElementSet.Inputs.AcceptPoint" : "ElementSet.Inputs.Accept");
118
- const rejectMsg = CoreTools.translate("ElementSet.Inputs.Cancel");
119
- const mainInstruction = ToolAssistance.createInstruction(this.iconSpec, translatePrompt(undefined === this._origin ? "IdentifyKnownLocation" : "ConfirmCoordinates"));
120
- const sections = [];
121
- const mouseInstructions = [];
122
- mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.LeftClick, acceptMsg, false, ToolAssistanceInputMethod.Mouse));
123
- mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.RightClick, rejectMsg, false, ToolAssistanceInputMethod.Mouse));
124
- sections.push(ToolAssistance.createSection(mouseInstructions, ToolAssistance.inputsLabel));
125
- const touchInstructions = [];
126
- if (!ToolAssistance.createTouchCursorInstructions(touchInstructions))
127
- touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.OneTouchTap, acceptMsg, false, ToolAssistanceInputMethod.Touch));
128
- touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.TwoTouchTap, rejectMsg, false, ToolAssistanceInputMethod.Touch));
129
- sections.push(ToolAssistance.createSection(touchInstructions, ToolAssistance.inputsLabel));
130
- const instructions = ToolAssistance.createInstructions(mainInstruction, sections);
131
- IModelApp.notifications.setToolAssistance(instructions);
132
- }
133
- setupAndPromptForNextAction() {
134
- IModelApp.accuSnap.enableSnap(undefined === this._origin);
135
- this.provideToolAssistance();
136
- }
137
- pulseDecoration() {
138
- if (!this._accept)
139
- return;
140
- const deco = ProjectExtentsClipDecoration.get();
141
- if (undefined === deco)
142
- return;
143
- this._scale += 0.1;
144
- if (this._scale > 1.6)
145
- this._scale = 1.0;
146
- deco.viewport.invalidateDecorations();
147
- setTimeout(() => { this.pulseDecoration(); }, 100);
148
- }
149
- unsuspendDecorations() {
150
- const deco = ProjectExtentsClipDecoration.get();
151
- if (undefined !== deco)
152
- deco.suspendGeolocationDecorations = false;
153
- }
154
- decorate(context) {
155
- if (undefined === this._origin || !context.viewport.view.isSpatialView())
156
- return;
157
- const deco = ProjectExtentsClipDecoration.get();
158
- if (undefined === deco)
159
- return;
160
- deco.suspendGeolocationDecorations = true;
161
- deco.drawMonumentPoint(context, this._origin, this._scale);
162
- if (undefined !== this._labelDeco)
163
- this._labelDeco.addDecoration(context);
164
- }
165
- async onMouseMotion(ev) {
166
- if (undefined === ev.viewport || this._accept)
167
- return;
168
- this._origin = ev.point.clone();
169
- ev.viewport.invalidateDecorations();
170
- }
171
- async onResetButtonUp(_ev) {
172
- await this.onReinitialize(); // Calls onRestartTool to exit...
173
- return EventHandled.No;
174
- }
175
- acceptDefaultLocation() {
176
- // Greenwich is better default when testing control handle w/o tool settings support...
177
- this.latitude = Angle.createDegrees(51.4934).radians;
178
- this.longitude = Angle.createDegrees(0.0098).radians;
179
- this.altitude = 50.0;
180
- this.north = 0.0;
181
- }
182
- acceptKnownLocation(ev) {
183
- const deco = ProjectExtentsClipDecoration.get();
184
- if (undefined === deco)
185
- return;
186
- this._accept = true; // Require explicit accept to give user a chance to change values...
187
- this._origin = ev.point.clone();
188
- this._labelDeco = new LabelDecoration(this._origin, translatePrompt("SpecifyCoordinates"));
189
- if (!this._cartographicFromArgs) {
190
- if (this.iModel.isGeoLocated) {
191
- const cartographic = this.iModel.spatialToCartographicFromEcef(this._origin);
192
- this.latitude = cartographic.latitude;
193
- this.longitude = cartographic.longitude;
194
- this.altitude = cartographic.height;
195
- this.north = deco.getClockwiseAngleToNorth().radians;
196
- }
197
- else if (!this._haveToolSettings) {
198
- this.acceptDefaultLocation();
199
- }
200
- }
201
- this.syncToolSettingsCoordinates();
202
- this.pulseDecoration(); // Pulse to indicate that we are waiting for user input...
203
- this.setupAndPromptForNextAction();
204
- }
205
- async acceptCoordinates() {
206
- const deco = ProjectExtentsClipDecoration.get();
207
- if (undefined === deco)
208
- return;
209
- const origin = Cartographic.fromRadians({ longitude: this.longitude, latitude: this.latitude, height: this.altitude });
210
- if (!deco.updateEcefLocation(origin, this._origin, Angle.createRadians(this.north)))
211
- return;
212
- return this.onReinitialize(); // Calls onRestartTool to exit...
213
- }
214
- async onDataButtonDown(ev) {
215
- if (undefined === ev.viewport)
216
- return EventHandled.No; // Shouldn't really happen...
217
- const haveKnownLocation = this._accept;
218
- if (!haveKnownLocation)
219
- this.acceptKnownLocation(ev);
220
- const needAcceptPoint = !haveKnownLocation && this._haveToolSettings;
221
- if (!needAcceptPoint)
222
- await this.acceptCoordinates();
223
- return EventHandled.No;
224
- }
225
- async onInstall() {
226
- if (!ProjectExtentsClipDecoration.allowEcefLocationChange(false))
227
- return false;
228
- // Setup initial values here instead of supplyToolSettingsProperties to support keyin args w/o appui-react...
229
- this.initializeToolSettingPropertyValues([this.latitudeProperty, this.longitudeProperty, this.altitudeProperty, this.northProperty]);
230
- return true;
231
- }
232
- /** The keyin takes the following arguments, all of which are optional:
233
- * - `latitude=number` Latitude of accept point in degrees.
234
- * - `longitude=number` Longitude of accept point in degrees.
235
- * - `altitude=number` Height above ellipsoid of accept point.
236
- * - `north=number` North direction in degrees of accept point.
237
- */
238
- async parseAndRun(...inputArgs) {
239
- for (const arg of inputArgs) {
240
- const parts = arg.split("=");
241
- if (2 !== parts.length)
242
- continue;
243
- if (parts[0].toLowerCase().startsWith("la")) {
244
- const latitude = Number.parseFloat(parts[1]);
245
- if (!Number.isNaN(latitude)) {
246
- this.saveToolSettingPropertyValue(this.latitudeProperty, { value: Angle.createDegrees(latitude).radians });
247
- this._cartographicFromArgs = true;
248
- }
249
- }
250
- else if (parts[0].toLowerCase().startsWith("lo")) {
251
- const longitude = Number.parseFloat(parts[1]);
252
- if (!Number.isNaN(longitude)) {
253
- this.saveToolSettingPropertyValue(this.longitudeProperty, { value: Angle.createDegrees(longitude).radians });
254
- this._cartographicFromArgs = true;
255
- }
256
- }
257
- else if (parts[0].toLowerCase().startsWith("al")) {
258
- const altitude = Number.parseFloat(parts[1]);
259
- if (!Number.isNaN(altitude)) {
260
- this.saveToolSettingPropertyValue(this.altitudeProperty, { value: altitude });
261
- this._cartographicFromArgs = true;
262
- }
263
- }
264
- else if (parts[0].toLowerCase().startsWith("no")) {
265
- const north = Number.parseFloat(parts[1]);
266
- if (!Number.isNaN(north)) {
267
- this.saveToolSettingPropertyValue(this.northProperty, { value: Angle.createDegrees(north).radians });
268
- this._cartographicFromArgs = true;
269
- }
270
- }
271
- }
272
- return this.run();
273
- }
274
- static async startTool() { return new ProjectGeolocationPointTool().run(); }
275
- }
276
- ProjectGeolocationPointTool.toolId = "ProjectLocation.Geolocation.Point";
277
- ProjectGeolocationPointTool.iconSpec = "icon-globe"; // <== Tool button should use whatever icon you have here...
278
- /** Change or update geolocation direction to true north.
279
- * @beta
280
- */
281
- export class ProjectGeolocationNorthTool extends PrimitiveTool {
282
- isCompatibleViewport(vp, isSelectedViewChange) { return (super.isCompatibleViewport(vp, isSelectedViewChange) && undefined !== vp && vp.view.isSpatialView()); }
283
- isValidLocation(_ev, _isButtonEvent) { return true; } // Allow snapping to terrain, etc. outside project extents...
284
- requireWriteableTarget() { return false; } // Tool doesn't modify the imodel...
285
- async onPostInstall() { await super.onPostInstall(); this.setupAndPromptForNextAction(); }
286
- async onCleanup() { await super.onCleanup(); this.unsuspendDecorations(); }
287
- async onRestartTool() { return this.exitTool(); }
288
- async onUnsuspend() { this.provideToolAssistance(); }
289
- provideToolAssistance() {
290
- const acceptMsg = CoreTools.translate("ElementSet.Inputs.AcceptPoint");
291
- const rejectMsg = CoreTools.translate("ElementSet.Inputs.Cancel");
292
- const mainInstruction = ToolAssistance.createInstruction(this.iconSpec, translatePrompt(undefined === this._origin ? "IdentifyRefPoint" : "DefineAngle"));
293
- const sections = [];
294
- const mouseInstructions = [];
295
- mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.LeftClick, acceptMsg, false, ToolAssistanceInputMethod.Mouse));
296
- mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.RightClick, rejectMsg, false, ToolAssistanceInputMethod.Mouse));
297
- sections.push(ToolAssistance.createSection(mouseInstructions, ToolAssistance.inputsLabel));
298
- const touchInstructions = [];
299
- if (!ToolAssistance.createTouchCursorInstructions(touchInstructions))
300
- touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.OneTouchTap, acceptMsg, false, ToolAssistanceInputMethod.Touch));
301
- touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.TwoTouchTap, rejectMsg, false, ToolAssistanceInputMethod.Touch));
302
- sections.push(ToolAssistance.createSection(touchInstructions, ToolAssistance.inputsLabel));
303
- const instructions = ToolAssistance.createInstructions(mainInstruction, sections);
304
- IModelApp.notifications.setToolAssistance(instructions);
305
- }
306
- setupAndPromptForNextAction() {
307
- IModelApp.accuSnap.enableSnap(true);
308
- this.provideToolAssistance();
309
- if (undefined === this._origin)
310
- return;
311
- const hints = new AccuDrawHintBuilder();
312
- hints.setRotation(Matrix3d.createIdentity());
313
- hints.setOrigin(this._origin);
314
- hints.setModePolar();
315
- hints.setOriginFixed = true;
316
- hints.setLockZ = true;
317
- hints.sendHints();
318
- }
319
- getAdjustedPoint(ev) {
320
- if (undefined === this._origin)
321
- return undefined;
322
- return AccuDrawHintBuilder.projectPointToPlaneInView(ev.point, this._origin, Vector3d.unitZ(), ev.viewport, true);
323
- }
324
- unsuspendDecorations() {
325
- const deco = ProjectExtentsClipDecoration.get();
326
- if (undefined !== deco)
327
- deco.suspendGeolocationDecorations = false;
328
- }
329
- updateNorthVector(ev) {
330
- if (undefined === ev.viewport)
331
- return;
332
- if (undefined === this._northDir)
333
- this._northDir = Ray3d.create(ev.point, Vector3d.unitY());
334
- else
335
- this._northDir.origin.setFrom(undefined !== this._origin ? this._origin : ev.point);
336
- const dirPt = this.getAdjustedPoint(ev);
337
- if (undefined === dirPt)
338
- return;
339
- this._northDir.direction.setStartEnd(this._northDir.origin, dirPt);
340
- if (this._northDir.direction.magnitude() < 1.0e-6)
341
- this._northDir.direction.setFrom(Vector3d.unitY());
342
- this._northDir.direction.z = 0.0;
343
- this._northDir.direction.normalizeInPlace();
344
- }
345
- decorate(context) {
346
- if (undefined === this._northDir || !context.viewport.view.isSpatialView())
347
- return;
348
- const deco = ProjectExtentsClipDecoration.get();
349
- if (undefined === deco)
350
- return;
351
- deco.suspendGeolocationDecorations = true;
352
- deco.drawNorthArrow(context, this._northDir);
353
- }
354
- async onKeyTransition(wentDown, keyEvent) {
355
- if (EventHandled.Yes === await super.onKeyTransition(wentDown, keyEvent))
356
- return EventHandled.Yes;
357
- return (wentDown && await AccuDrawShortcuts.processShortcutKey(keyEvent)) ? EventHandled.Yes : EventHandled.No;
358
- }
359
- async onMouseMotion(ev) {
360
- if (undefined === ev.viewport)
361
- return;
362
- this.updateNorthVector(ev);
363
- ev.viewport.invalidateDecorations();
364
- }
365
- async onResetButtonUp(_ev) {
366
- await this.onReinitialize(); // Calls onRestartTool to exit...
367
- return EventHandled.No;
368
- }
369
- async onDataButtonDown(ev) {
370
- if (undefined === ev.viewport)
371
- return EventHandled.No; // Shouldn't really happen...
372
- if (undefined === this._origin) {
373
- this._origin = ev.point.clone();
374
- this.setupAndPromptForNextAction();
375
- return EventHandled.No;
376
- }
377
- this.updateNorthVector(ev);
378
- if (undefined !== this._northDir) {
379
- const deco = ProjectExtentsClipDecoration.get();
380
- if (undefined !== deco)
381
- deco.updateNorthDirection(this._northDir);
382
- }
383
- await this.onReinitialize(); // Calls onRestartTool to exit...
384
- return EventHandled.No;
385
- }
386
- async onInstall() { return ProjectExtentsClipDecoration.allowEcefLocationChange(true); }
387
- static async startTool() { return new ProjectGeolocationNorthTool().run(); }
388
- }
389
- ProjectGeolocationNorthTool.toolId = "ProjectLocation.Geolocation.North";
390
- ProjectGeolocationNorthTool.iconSpec = "icon-sort-up"; // <== Tool button should use whatever icon you have here...
391
- /** Move a geolocated model by specifying two points to define the offset.
392
- * @beta
393
- */
394
- export class ProjectGeolocationMoveTool extends PrimitiveTool {
395
- isCompatibleViewport(vp, isSelectedViewChange) { return (super.isCompatibleViewport(vp, isSelectedViewChange) && undefined !== vp && vp.view.isSpatialView()); }
396
- isValidLocation(_ev, _isButtonEvent) { return true; } // Allow snapping to terrain, etc. outside project extents...
397
- requireWriteableTarget() { return false; } // Tool doesn't modify the imodel...
398
- async onPostInstall() { await super.onPostInstall(); this.setupAndPromptForNextAction(); }
399
- async onCleanup() { await super.onCleanup(); this.unsuspendDecorations(); }
400
- async onRestartTool() { const tool = new ProjectGeolocationMoveTool(); if (!await tool.run())
401
- return this.exitTool(); }
402
- async onUnsuspend() { this.provideToolAssistance(); }
403
- provideToolAssistance() {
404
- const acceptMsg = CoreTools.translate("ElementSet.Inputs.AcceptPoint");
405
- const rejectMsg = CoreTools.translate("ElementSet.Inputs.Cancel");
406
- const mainInstruction = ToolAssistance.createInstruction(this.iconSpec, translatePrompt(undefined === this._origin ? "IdentifyRefPoint" : "DefineOffset"));
407
- const sections = [];
408
- const mouseInstructions = [];
409
- mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.LeftClick, acceptMsg, false, ToolAssistanceInputMethod.Mouse));
410
- mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.RightClick, rejectMsg, false, ToolAssistanceInputMethod.Mouse));
411
- sections.push(ToolAssistance.createSection(mouseInstructions, ToolAssistance.inputsLabel));
412
- const touchInstructions = [];
413
- if (!ToolAssistance.createTouchCursorInstructions(touchInstructions))
414
- touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.OneTouchTap, acceptMsg, false, ToolAssistanceInputMethod.Touch));
415
- touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.TwoTouchTap, rejectMsg, false, ToolAssistanceInputMethod.Touch));
416
- sections.push(ToolAssistance.createSection(touchInstructions, ToolAssistance.inputsLabel));
417
- const instructions = ToolAssistance.createInstructions(mainInstruction, sections);
418
- IModelApp.notifications.setToolAssistance(instructions);
419
- }
420
- setupAndPromptForNextAction() {
421
- IModelApp.accuSnap.enableSnap(true);
422
- this.provideToolAssistance();
423
- if (undefined === this._origin)
424
- return;
425
- const hints = new AccuDrawHintBuilder();
426
- hints.setRotation(Matrix3d.createIdentity());
427
- hints.setOrigin(this._origin);
428
- hints.setModePolar();
429
- hints.setOriginFixed = true;
430
- hints.sendHints();
431
- }
432
- unsuspendDecorations() {
433
- const deco = ProjectExtentsClipDecoration.get();
434
- if (undefined !== deco)
435
- deco.suspendGeolocationDecorations = false;
436
- }
437
- async acceptOffset(ev) {
438
- if (undefined === ev.viewport || undefined === this._origin)
439
- return;
440
- const deco = ProjectExtentsClipDecoration.get();
441
- if (undefined === deco)
442
- return;
443
- const origin = this.iModel.spatialToCartographicFromEcef(ev.point);
444
- if (!deco.updateEcefLocation(origin, this._origin))
445
- return;
446
- return this.onReinitialize(); // Calls onRestartTool to exit...
447
- }
448
- decorate(context) {
449
- if (undefined === this._origin || undefined === this._current || !context.viewport.view.isSpatialView())
450
- return;
451
- const deco = ProjectExtentsClipDecoration.get();
452
- if (undefined === deco)
453
- return;
454
- const builderAccVis = context.createGraphicBuilder(GraphicType.WorldDecoration);
455
- const builderAccHid = context.createGraphicBuilder(GraphicType.WorldOverlay);
456
- const colorAccVis = ColorDef.white.adjustedForContrast(context.viewport.view.backgroundColor);
457
- const colorAccHid = colorAccVis.withAlpha(100);
458
- builderAccVis.setSymbology(colorAccVis, ColorDef.black, 3);
459
- builderAccHid.setSymbology(colorAccHid, ColorDef.black, 1, LinePixels.Code2);
460
- const extents = this.iModel.projectExtents.cloneTranslated(Vector3d.createStartEnd(this._origin, this._current));
461
- builderAccVis.addRangeBox(extents);
462
- builderAccHid.addRangeBox(extents);
463
- builderAccHid.addLineString([this._origin, this._current]);
464
- context.addDecorationFromBuilder(builderAccVis);
465
- context.addDecorationFromBuilder(builderAccHid);
466
- deco.suspendGeolocationDecorations = true;
467
- }
468
- async onKeyTransition(wentDown, keyEvent) {
469
- if (EventHandled.Yes === await super.onKeyTransition(wentDown, keyEvent))
470
- return EventHandled.Yes;
471
- return (wentDown && await AccuDrawShortcuts.processShortcutKey(keyEvent)) ? EventHandled.Yes : EventHandled.No;
472
- }
473
- async onMouseMotion(ev) {
474
- if (undefined === ev.viewport)
475
- return;
476
- this._current = ev.point;
477
- ev.viewport.invalidateDecorations();
478
- }
479
- async onResetButtonUp(_ev) {
480
- if (undefined === this._origin)
481
- await this.exitTool(); // exit to select tool if we haven't gotten first point...
482
- else
483
- await this.onReinitialize(); // Calls onRestartTool...
484
- return EventHandled.No;
485
- }
486
- async onDataButtonDown(ev) {
487
- if (undefined === ev.viewport)
488
- return EventHandled.No; // Shouldn't really happen...
489
- if (undefined === this._origin) {
490
- this._origin = ev.point.clone();
491
- this.setupAndPromptForNextAction();
492
- return EventHandled.No;
493
- }
494
- await this.acceptOffset(ev);
495
- return EventHandled.No;
496
- }
497
- async onInstall() { return ProjectExtentsClipDecoration.allowEcefLocationChange(true); }
498
- static async startTool() { return new ProjectGeolocationMoveTool().run(); }
499
- }
500
- ProjectGeolocationMoveTool.toolId = "ProjectLocation.Geolocation.Move";
501
- ProjectGeolocationMoveTool.iconSpec = "icon-move"; // <== Tool button should use whatever icon you have here...
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 { AccuDrawHintBuilder, AccuDrawShortcuts, AngleDescription, CoreTools, EventHandled, GraphicType, IModelApp, LengthDescription, PrimitiveTool, ToolAssistance, ToolAssistanceImage, ToolAssistanceInputMethod } from "@itwin/core-frontend";
9
+ import { Angle, Matrix3d, Point3d, Ray3d, Vector3d } from "@itwin/core-geometry";
10
+ import { Cartographic, ColorDef, LinePixels } from "@itwin/core-common";
11
+ import { ProjectExtentsClipDecoration } from "./ProjectExtentsDecoration";
12
+ import { DialogProperty } from "@itwin/appui-abstract";
13
+ import { EditTools } from "../EditTool";
14
+ function translatePrompt(key) { return EditTools.translate(`ProjectLocation:Prompts.${key}`); }
15
+ function translateMessage(key) { return EditTools.translate(`ProjectLocation:Message.${key}`); }
16
+ /** @internal */
17
+ class LabelDecoration {
18
+ constructor(worldLocation, label) {
19
+ this.worldLocation = new Point3d();
20
+ this.position = new Point3d();
21
+ this.worldLocation.setFrom(worldLocation);
22
+ this.label = label;
23
+ }
24
+ drawDecoration(ctx) {
25
+ ctx.font = "16px san-serif";
26
+ const labelHeight = ctx.measureText("M").width; // Close enough for border padding...
27
+ const labelWidth = ctx.measureText(this.label).width + labelHeight;
28
+ ctx.lineWidth = 1;
29
+ ctx.strokeStyle = "white";
30
+ ctx.fillStyle = "rgba(0,0,0,.4)";
31
+ ctx.shadowColor = "black";
32
+ ctx.shadowBlur = 10;
33
+ ctx.fillRect(-(labelWidth / 2), -labelHeight, labelWidth, labelHeight * 2);
34
+ ctx.strokeRect(-(labelWidth / 2), -labelHeight, labelWidth, labelHeight * 2);
35
+ ctx.fillStyle = "white";
36
+ ctx.shadowBlur = 0;
37
+ ctx.textAlign = "center";
38
+ ctx.textBaseline = "middle";
39
+ ctx.fillText(this.label, 0, 0);
40
+ }
41
+ setPosition(vp) {
42
+ vp.worldToView(this.worldLocation, this.position);
43
+ this.position.y -= Math.floor(vp.pixelsFromInches(0.45)) + 0.5; // Offset from world location...
44
+ return vp.viewRect.containsPoint(this.position);
45
+ }
46
+ addDecoration(context) {
47
+ if (this.setPosition(context.viewport))
48
+ context.addCanvasDecoration(this);
49
+ }
50
+ }
51
+ /** Change or update geolocation for project.
52
+ * To show tool settings for specifying lat/long, make sure formatting and parsing data are cached before the tool starts
53
+ * by calling QuantityFormatter.onInitialized at app startup.
54
+ * @beta
55
+ */
56
+ export class ProjectGeolocationPointTool extends PrimitiveTool {
57
+ constructor() {
58
+ super(...arguments);
59
+ this._haveToolSettings = false;
60
+ this._cartographicFromArgs = false;
61
+ this._accept = false;
62
+ this._scale = 1.0;
63
+ }
64
+ static get minArgs() { return 0; }
65
+ static get maxArgs() { return 4; } // latitude, longitude, altitude, north direction...
66
+ isCompatibleViewport(vp, isSelectedViewChange) { return (super.isCompatibleViewport(vp, isSelectedViewChange) && undefined !== vp && vp.view.isSpatialView()); }
67
+ isValidLocation(_ev, _isButtonEvent) { return true; } // Allow snapping to terrain, etc. outside project extents...
68
+ requireWriteableTarget() { return false; } // Tool doesn't modify the imodel...
69
+ async onPostInstall() { await super.onPostInstall(); this.setupAndPromptForNextAction(); }
70
+ async onCleanup() { await super.onCleanup(); this.unsuspendDecorations(); }
71
+ async onRestartTool() { return this.exitTool(); }
72
+ async onUnsuspend() { this.provideToolAssistance(); }
73
+ get latitudeProperty() {
74
+ if (!this._latitudeProperty)
75
+ this._latitudeProperty = new DialogProperty(new AngleDescription("latitude", translateMessage("Latitude")), 0.0);
76
+ return this._latitudeProperty;
77
+ }
78
+ get latitude() { return this.latitudeProperty.value; }
79
+ set latitude(value) { this.latitudeProperty.value = value; }
80
+ get longitudeProperty() {
81
+ if (!this._longitudeProperty)
82
+ this._longitudeProperty = new DialogProperty(new AngleDescription("longitude", translateMessage("Longitude")), 0.0);
83
+ return this._longitudeProperty;
84
+ }
85
+ get longitude() { return this.longitudeProperty.value; }
86
+ set longitude(value) { this.longitudeProperty.value = value; }
87
+ get altitudeProperty() {
88
+ if (!this._altitudeProperty)
89
+ this._altitudeProperty = new DialogProperty(new LengthDescription("altitude", CoreTools.translate("Measure.Labels.Altitude")), 0.0);
90
+ return this._altitudeProperty;
91
+ }
92
+ get altitude() { return this.altitudeProperty.value; }
93
+ set altitude(value) { this.altitudeProperty.value = value; }
94
+ get northProperty() {
95
+ if (!this._northProperty)
96
+ this._northProperty = new DialogProperty(new AngleDescription("north", translateMessage("North")), 0.0);
97
+ return this._northProperty;
98
+ }
99
+ get north() { return this.northProperty.value; }
100
+ set north(value) { this.northProperty.value = value; }
101
+ syncToolSettingsCoordinates() {
102
+ this.syncToolSettingsProperties([this.latitudeProperty.syncItem, this.longitudeProperty.syncItem, this.altitudeProperty.syncItem, this.northProperty.syncItem]);
103
+ }
104
+ async applyToolSettingPropertyChange(updatedValue) {
105
+ return this.changeToolSettingPropertyValue(updatedValue);
106
+ }
107
+ supplyToolSettingsProperties() {
108
+ this._haveToolSettings = true;
109
+ const toolSettings = new Array();
110
+ toolSettings.push(this.latitudeProperty.toDialogItem({ rowPriority: 1, columnIndex: 2 }));
111
+ toolSettings.push(this.longitudeProperty.toDialogItem({ rowPriority: 2, columnIndex: 2 }));
112
+ toolSettings.push(this.altitudeProperty.toDialogItem({ rowPriority: 3, columnIndex: 2 }));
113
+ toolSettings.push(this.northProperty.toDialogItem({ rowPriority: 4, columnIndex: 2 }));
114
+ return toolSettings;
115
+ }
116
+ provideToolAssistance() {
117
+ const acceptMsg = CoreTools.translate(undefined === this._origin ? "ElementSet.Inputs.AcceptPoint" : "ElementSet.Inputs.Accept");
118
+ const rejectMsg = CoreTools.translate("ElementSet.Inputs.Cancel");
119
+ const mainInstruction = ToolAssistance.createInstruction(this.iconSpec, translatePrompt(undefined === this._origin ? "IdentifyKnownLocation" : "ConfirmCoordinates"));
120
+ const sections = [];
121
+ const mouseInstructions = [];
122
+ mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.LeftClick, acceptMsg, false, ToolAssistanceInputMethod.Mouse));
123
+ mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.RightClick, rejectMsg, false, ToolAssistanceInputMethod.Mouse));
124
+ sections.push(ToolAssistance.createSection(mouseInstructions, ToolAssistance.inputsLabel));
125
+ const touchInstructions = [];
126
+ if (!ToolAssistance.createTouchCursorInstructions(touchInstructions))
127
+ touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.OneTouchTap, acceptMsg, false, ToolAssistanceInputMethod.Touch));
128
+ touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.TwoTouchTap, rejectMsg, false, ToolAssistanceInputMethod.Touch));
129
+ sections.push(ToolAssistance.createSection(touchInstructions, ToolAssistance.inputsLabel));
130
+ const instructions = ToolAssistance.createInstructions(mainInstruction, sections);
131
+ IModelApp.notifications.setToolAssistance(instructions);
132
+ }
133
+ setupAndPromptForNextAction() {
134
+ IModelApp.accuSnap.enableSnap(undefined === this._origin);
135
+ this.provideToolAssistance();
136
+ }
137
+ pulseDecoration() {
138
+ if (!this._accept)
139
+ return;
140
+ const deco = ProjectExtentsClipDecoration.get();
141
+ if (undefined === deco)
142
+ return;
143
+ this._scale += 0.1;
144
+ if (this._scale > 1.6)
145
+ this._scale = 1.0;
146
+ deco.viewport.invalidateDecorations();
147
+ setTimeout(() => { this.pulseDecoration(); }, 100);
148
+ }
149
+ unsuspendDecorations() {
150
+ const deco = ProjectExtentsClipDecoration.get();
151
+ if (undefined !== deco)
152
+ deco.suspendGeolocationDecorations = false;
153
+ }
154
+ decorate(context) {
155
+ if (undefined === this._origin || !context.viewport.view.isSpatialView())
156
+ return;
157
+ const deco = ProjectExtentsClipDecoration.get();
158
+ if (undefined === deco)
159
+ return;
160
+ deco.suspendGeolocationDecorations = true;
161
+ deco.drawMonumentPoint(context, this._origin, this._scale);
162
+ if (undefined !== this._labelDeco)
163
+ this._labelDeco.addDecoration(context);
164
+ }
165
+ async onMouseMotion(ev) {
166
+ if (undefined === ev.viewport || this._accept)
167
+ return;
168
+ this._origin = ev.point.clone();
169
+ ev.viewport.invalidateDecorations();
170
+ }
171
+ async onResetButtonUp(_ev) {
172
+ await this.onReinitialize(); // Calls onRestartTool to exit...
173
+ return EventHandled.No;
174
+ }
175
+ acceptDefaultLocation() {
176
+ // Greenwich is better default when testing control handle w/o tool settings support...
177
+ this.latitude = Angle.createDegrees(51.4934).radians;
178
+ this.longitude = Angle.createDegrees(0.0098).radians;
179
+ this.altitude = 50.0;
180
+ this.north = 0.0;
181
+ }
182
+ acceptKnownLocation(ev) {
183
+ const deco = ProjectExtentsClipDecoration.get();
184
+ if (undefined === deco)
185
+ return;
186
+ this._accept = true; // Require explicit accept to give user a chance to change values...
187
+ this._origin = ev.point.clone();
188
+ this._labelDeco = new LabelDecoration(this._origin, translatePrompt("SpecifyCoordinates"));
189
+ if (!this._cartographicFromArgs) {
190
+ if (this.iModel.isGeoLocated) {
191
+ const cartographic = this.iModel.spatialToCartographicFromEcef(this._origin);
192
+ this.latitude = cartographic.latitude;
193
+ this.longitude = cartographic.longitude;
194
+ this.altitude = cartographic.height;
195
+ this.north = deco.getClockwiseAngleToNorth().radians;
196
+ }
197
+ else if (!this._haveToolSettings) {
198
+ this.acceptDefaultLocation();
199
+ }
200
+ }
201
+ this.syncToolSettingsCoordinates();
202
+ this.pulseDecoration(); // Pulse to indicate that we are waiting for user input...
203
+ this.setupAndPromptForNextAction();
204
+ }
205
+ async acceptCoordinates() {
206
+ const deco = ProjectExtentsClipDecoration.get();
207
+ if (undefined === deco)
208
+ return;
209
+ const origin = Cartographic.fromRadians({ longitude: this.longitude, latitude: this.latitude, height: this.altitude });
210
+ if (!deco.updateEcefLocation(origin, this._origin, Angle.createRadians(this.north)))
211
+ return;
212
+ return this.onReinitialize(); // Calls onRestartTool to exit...
213
+ }
214
+ async onDataButtonDown(ev) {
215
+ if (undefined === ev.viewport)
216
+ return EventHandled.No; // Shouldn't really happen...
217
+ const haveKnownLocation = this._accept;
218
+ if (!haveKnownLocation)
219
+ this.acceptKnownLocation(ev);
220
+ const needAcceptPoint = !haveKnownLocation && this._haveToolSettings;
221
+ if (!needAcceptPoint)
222
+ await this.acceptCoordinates();
223
+ return EventHandled.No;
224
+ }
225
+ async onInstall() {
226
+ if (!ProjectExtentsClipDecoration.allowEcefLocationChange(false))
227
+ return false;
228
+ // Setup initial values here instead of supplyToolSettingsProperties to support keyin args w/o appui-react...
229
+ this.initializeToolSettingPropertyValues([this.latitudeProperty, this.longitudeProperty, this.altitudeProperty, this.northProperty]);
230
+ return true;
231
+ }
232
+ /** The keyin takes the following arguments, all of which are optional:
233
+ * - `latitude=number` Latitude of accept point in degrees.
234
+ * - `longitude=number` Longitude of accept point in degrees.
235
+ * - `altitude=number` Height above ellipsoid of accept point.
236
+ * - `north=number` North direction in degrees of accept point.
237
+ */
238
+ async parseAndRun(...inputArgs) {
239
+ for (const arg of inputArgs) {
240
+ const parts = arg.split("=");
241
+ if (2 !== parts.length)
242
+ continue;
243
+ if (parts[0].toLowerCase().startsWith("la")) {
244
+ const latitude = Number.parseFloat(parts[1]);
245
+ if (!Number.isNaN(latitude)) {
246
+ this.saveToolSettingPropertyValue(this.latitudeProperty, { value: Angle.createDegrees(latitude).radians });
247
+ this._cartographicFromArgs = true;
248
+ }
249
+ }
250
+ else if (parts[0].toLowerCase().startsWith("lo")) {
251
+ const longitude = Number.parseFloat(parts[1]);
252
+ if (!Number.isNaN(longitude)) {
253
+ this.saveToolSettingPropertyValue(this.longitudeProperty, { value: Angle.createDegrees(longitude).radians });
254
+ this._cartographicFromArgs = true;
255
+ }
256
+ }
257
+ else if (parts[0].toLowerCase().startsWith("al")) {
258
+ const altitude = Number.parseFloat(parts[1]);
259
+ if (!Number.isNaN(altitude)) {
260
+ this.saveToolSettingPropertyValue(this.altitudeProperty, { value: altitude });
261
+ this._cartographicFromArgs = true;
262
+ }
263
+ }
264
+ else if (parts[0].toLowerCase().startsWith("no")) {
265
+ const north = Number.parseFloat(parts[1]);
266
+ if (!Number.isNaN(north)) {
267
+ this.saveToolSettingPropertyValue(this.northProperty, { value: Angle.createDegrees(north).radians });
268
+ this._cartographicFromArgs = true;
269
+ }
270
+ }
271
+ }
272
+ return this.run();
273
+ }
274
+ static async startTool() { return new ProjectGeolocationPointTool().run(); }
275
+ }
276
+ ProjectGeolocationPointTool.toolId = "ProjectLocation.Geolocation.Point";
277
+ ProjectGeolocationPointTool.iconSpec = "icon-globe"; // <== Tool button should use whatever icon you have here...
278
+ /** Change or update geolocation direction to true north.
279
+ * @beta
280
+ */
281
+ export class ProjectGeolocationNorthTool extends PrimitiveTool {
282
+ isCompatibleViewport(vp, isSelectedViewChange) { return (super.isCompatibleViewport(vp, isSelectedViewChange) && undefined !== vp && vp.view.isSpatialView()); }
283
+ isValidLocation(_ev, _isButtonEvent) { return true; } // Allow snapping to terrain, etc. outside project extents...
284
+ requireWriteableTarget() { return false; } // Tool doesn't modify the imodel...
285
+ async onPostInstall() { await super.onPostInstall(); this.setupAndPromptForNextAction(); }
286
+ async onCleanup() { await super.onCleanup(); this.unsuspendDecorations(); }
287
+ async onRestartTool() { return this.exitTool(); }
288
+ async onUnsuspend() { this.provideToolAssistance(); }
289
+ provideToolAssistance() {
290
+ const acceptMsg = CoreTools.translate("ElementSet.Inputs.AcceptPoint");
291
+ const rejectMsg = CoreTools.translate("ElementSet.Inputs.Cancel");
292
+ const mainInstruction = ToolAssistance.createInstruction(this.iconSpec, translatePrompt(undefined === this._origin ? "IdentifyRefPoint" : "DefineAngle"));
293
+ const sections = [];
294
+ const mouseInstructions = [];
295
+ mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.LeftClick, acceptMsg, false, ToolAssistanceInputMethod.Mouse));
296
+ mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.RightClick, rejectMsg, false, ToolAssistanceInputMethod.Mouse));
297
+ sections.push(ToolAssistance.createSection(mouseInstructions, ToolAssistance.inputsLabel));
298
+ const touchInstructions = [];
299
+ if (!ToolAssistance.createTouchCursorInstructions(touchInstructions))
300
+ touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.OneTouchTap, acceptMsg, false, ToolAssistanceInputMethod.Touch));
301
+ touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.TwoTouchTap, rejectMsg, false, ToolAssistanceInputMethod.Touch));
302
+ sections.push(ToolAssistance.createSection(touchInstructions, ToolAssistance.inputsLabel));
303
+ const instructions = ToolAssistance.createInstructions(mainInstruction, sections);
304
+ IModelApp.notifications.setToolAssistance(instructions);
305
+ }
306
+ setupAndPromptForNextAction() {
307
+ IModelApp.accuSnap.enableSnap(true);
308
+ this.provideToolAssistance();
309
+ if (undefined === this._origin)
310
+ return;
311
+ const hints = new AccuDrawHintBuilder();
312
+ hints.setRotation(Matrix3d.createIdentity());
313
+ hints.setOrigin(this._origin);
314
+ hints.setModePolar();
315
+ hints.setOriginFixed = true;
316
+ hints.setLockZ = true;
317
+ hints.sendHints();
318
+ }
319
+ getAdjustedPoint(ev) {
320
+ if (undefined === this._origin)
321
+ return undefined;
322
+ return AccuDrawHintBuilder.projectPointToPlaneInView(ev.point, this._origin, Vector3d.unitZ(), ev.viewport, true);
323
+ }
324
+ unsuspendDecorations() {
325
+ const deco = ProjectExtentsClipDecoration.get();
326
+ if (undefined !== deco)
327
+ deco.suspendGeolocationDecorations = false;
328
+ }
329
+ updateNorthVector(ev) {
330
+ if (undefined === ev.viewport)
331
+ return;
332
+ if (undefined === this._northDir)
333
+ this._northDir = Ray3d.create(ev.point, Vector3d.unitY());
334
+ else
335
+ this._northDir.origin.setFrom(undefined !== this._origin ? this._origin : ev.point);
336
+ const dirPt = this.getAdjustedPoint(ev);
337
+ if (undefined === dirPt)
338
+ return;
339
+ this._northDir.direction.setStartEnd(this._northDir.origin, dirPt);
340
+ if (this._northDir.direction.magnitude() < 1.0e-6)
341
+ this._northDir.direction.setFrom(Vector3d.unitY());
342
+ this._northDir.direction.z = 0.0;
343
+ this._northDir.direction.normalizeInPlace();
344
+ }
345
+ decorate(context) {
346
+ if (undefined === this._northDir || !context.viewport.view.isSpatialView())
347
+ return;
348
+ const deco = ProjectExtentsClipDecoration.get();
349
+ if (undefined === deco)
350
+ return;
351
+ deco.suspendGeolocationDecorations = true;
352
+ deco.drawNorthArrow(context, this._northDir);
353
+ }
354
+ async onKeyTransition(wentDown, keyEvent) {
355
+ if (EventHandled.Yes === await super.onKeyTransition(wentDown, keyEvent))
356
+ return EventHandled.Yes;
357
+ return (wentDown && await AccuDrawShortcuts.processShortcutKey(keyEvent)) ? EventHandled.Yes : EventHandled.No;
358
+ }
359
+ async onMouseMotion(ev) {
360
+ if (undefined === ev.viewport)
361
+ return;
362
+ this.updateNorthVector(ev);
363
+ ev.viewport.invalidateDecorations();
364
+ }
365
+ async onResetButtonUp(_ev) {
366
+ await this.onReinitialize(); // Calls onRestartTool to exit...
367
+ return EventHandled.No;
368
+ }
369
+ async onDataButtonDown(ev) {
370
+ if (undefined === ev.viewport)
371
+ return EventHandled.No; // Shouldn't really happen...
372
+ if (undefined === this._origin) {
373
+ this._origin = ev.point.clone();
374
+ this.setupAndPromptForNextAction();
375
+ return EventHandled.No;
376
+ }
377
+ this.updateNorthVector(ev);
378
+ if (undefined !== this._northDir) {
379
+ const deco = ProjectExtentsClipDecoration.get();
380
+ if (undefined !== deco)
381
+ deco.updateNorthDirection(this._northDir);
382
+ }
383
+ await this.onReinitialize(); // Calls onRestartTool to exit...
384
+ return EventHandled.No;
385
+ }
386
+ async onInstall() { return ProjectExtentsClipDecoration.allowEcefLocationChange(true); }
387
+ static async startTool() { return new ProjectGeolocationNorthTool().run(); }
388
+ }
389
+ ProjectGeolocationNorthTool.toolId = "ProjectLocation.Geolocation.North";
390
+ ProjectGeolocationNorthTool.iconSpec = "icon-sort-up"; // <== Tool button should use whatever icon you have here...
391
+ /** Move a geolocated model by specifying two points to define the offset.
392
+ * @beta
393
+ */
394
+ export class ProjectGeolocationMoveTool extends PrimitiveTool {
395
+ isCompatibleViewport(vp, isSelectedViewChange) { return (super.isCompatibleViewport(vp, isSelectedViewChange) && undefined !== vp && vp.view.isSpatialView()); }
396
+ isValidLocation(_ev, _isButtonEvent) { return true; } // Allow snapping to terrain, etc. outside project extents...
397
+ requireWriteableTarget() { return false; } // Tool doesn't modify the imodel...
398
+ async onPostInstall() { await super.onPostInstall(); this.setupAndPromptForNextAction(); }
399
+ async onCleanup() { await super.onCleanup(); this.unsuspendDecorations(); }
400
+ async onRestartTool() { const tool = new ProjectGeolocationMoveTool(); if (!await tool.run())
401
+ return this.exitTool(); }
402
+ async onUnsuspend() { this.provideToolAssistance(); }
403
+ provideToolAssistance() {
404
+ const acceptMsg = CoreTools.translate("ElementSet.Inputs.AcceptPoint");
405
+ const rejectMsg = CoreTools.translate("ElementSet.Inputs.Cancel");
406
+ const mainInstruction = ToolAssistance.createInstruction(this.iconSpec, translatePrompt(undefined === this._origin ? "IdentifyRefPoint" : "DefineOffset"));
407
+ const sections = [];
408
+ const mouseInstructions = [];
409
+ mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.LeftClick, acceptMsg, false, ToolAssistanceInputMethod.Mouse));
410
+ mouseInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.RightClick, rejectMsg, false, ToolAssistanceInputMethod.Mouse));
411
+ sections.push(ToolAssistance.createSection(mouseInstructions, ToolAssistance.inputsLabel));
412
+ const touchInstructions = [];
413
+ if (!ToolAssistance.createTouchCursorInstructions(touchInstructions))
414
+ touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.OneTouchTap, acceptMsg, false, ToolAssistanceInputMethod.Touch));
415
+ touchInstructions.push(ToolAssistance.createInstruction(ToolAssistanceImage.TwoTouchTap, rejectMsg, false, ToolAssistanceInputMethod.Touch));
416
+ sections.push(ToolAssistance.createSection(touchInstructions, ToolAssistance.inputsLabel));
417
+ const instructions = ToolAssistance.createInstructions(mainInstruction, sections);
418
+ IModelApp.notifications.setToolAssistance(instructions);
419
+ }
420
+ setupAndPromptForNextAction() {
421
+ IModelApp.accuSnap.enableSnap(true);
422
+ this.provideToolAssistance();
423
+ if (undefined === this._origin)
424
+ return;
425
+ const hints = new AccuDrawHintBuilder();
426
+ hints.setRotation(Matrix3d.createIdentity());
427
+ hints.setOrigin(this._origin);
428
+ hints.setModePolar();
429
+ hints.setOriginFixed = true;
430
+ hints.sendHints();
431
+ }
432
+ unsuspendDecorations() {
433
+ const deco = ProjectExtentsClipDecoration.get();
434
+ if (undefined !== deco)
435
+ deco.suspendGeolocationDecorations = false;
436
+ }
437
+ async acceptOffset(ev) {
438
+ if (undefined === ev.viewport || undefined === this._origin)
439
+ return;
440
+ const deco = ProjectExtentsClipDecoration.get();
441
+ if (undefined === deco)
442
+ return;
443
+ const origin = this.iModel.spatialToCartographicFromEcef(ev.point);
444
+ if (!deco.updateEcefLocation(origin, this._origin))
445
+ return;
446
+ return this.onReinitialize(); // Calls onRestartTool to exit...
447
+ }
448
+ decorate(context) {
449
+ if (undefined === this._origin || undefined === this._current || !context.viewport.view.isSpatialView())
450
+ return;
451
+ const deco = ProjectExtentsClipDecoration.get();
452
+ if (undefined === deco)
453
+ return;
454
+ const builderAccVis = context.createGraphicBuilder(GraphicType.WorldDecoration);
455
+ const builderAccHid = context.createGraphicBuilder(GraphicType.WorldOverlay);
456
+ const colorAccVis = ColorDef.white.adjustedForContrast(context.viewport.view.backgroundColor);
457
+ const colorAccHid = colorAccVis.withAlpha(100);
458
+ builderAccVis.setSymbology(colorAccVis, ColorDef.black, 3);
459
+ builderAccHid.setSymbology(colorAccHid, ColorDef.black, 1, LinePixels.Code2);
460
+ const extents = this.iModel.projectExtents.cloneTranslated(Vector3d.createStartEnd(this._origin, this._current));
461
+ builderAccVis.addRangeBox(extents);
462
+ builderAccHid.addRangeBox(extents);
463
+ builderAccHid.addLineString([this._origin, this._current]);
464
+ context.addDecorationFromBuilder(builderAccVis);
465
+ context.addDecorationFromBuilder(builderAccHid);
466
+ deco.suspendGeolocationDecorations = true;
467
+ }
468
+ async onKeyTransition(wentDown, keyEvent) {
469
+ if (EventHandled.Yes === await super.onKeyTransition(wentDown, keyEvent))
470
+ return EventHandled.Yes;
471
+ return (wentDown && await AccuDrawShortcuts.processShortcutKey(keyEvent)) ? EventHandled.Yes : EventHandled.No;
472
+ }
473
+ async onMouseMotion(ev) {
474
+ if (undefined === ev.viewport)
475
+ return;
476
+ this._current = ev.point;
477
+ ev.viewport.invalidateDecorations();
478
+ }
479
+ async onResetButtonUp(_ev) {
480
+ if (undefined === this._origin)
481
+ await this.exitTool(); // exit to select tool if we haven't gotten first point...
482
+ else
483
+ await this.onReinitialize(); // Calls onRestartTool...
484
+ return EventHandled.No;
485
+ }
486
+ async onDataButtonDown(ev) {
487
+ if (undefined === ev.viewport)
488
+ return EventHandled.No; // Shouldn't really happen...
489
+ if (undefined === this._origin) {
490
+ this._origin = ev.point.clone();
491
+ this.setupAndPromptForNextAction();
492
+ return EventHandled.No;
493
+ }
494
+ await this.acceptOffset(ev);
495
+ return EventHandled.No;
496
+ }
497
+ async onInstall() { return ProjectExtentsClipDecoration.allowEcefLocationChange(true); }
498
+ static async startTool() { return new ProjectGeolocationMoveTool().run(); }
499
+ }
500
+ ProjectGeolocationMoveTool.toolId = "ProjectLocation.Geolocation.Move";
501
+ ProjectGeolocationMoveTool.iconSpec = "icon-move"; // <== Tool button should use whatever icon you have here...
502
502
  //# sourceMappingURL=ProjectGeolocation.js.map