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