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