@itwin/editor-frontend 3.4.0-dev.9 → 3.4.1

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