Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/*---------------------------------------------------------------------------------------------
* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license terms.
*--------------------------------------------------------------------------------------------*/
import { Logger } from "@bentley/bentleyjs-core";
import { AngleSweep, Arc3d, Point2d, Point3d, XAndY, XYAndZ } from "@bentley/geometry-core";
import { AxisAlignedBox3d, ColorByName, ColorDef } from "@bentley/imodeljs-common";
import {
BeButton, BeButtonEvent, Cluster, DecorateContext, GraphicType, imageElementFromUrl,
IModelApp, Marker, MarkerImage, MarkerSet, MessageBoxIconType, MessageBoxType, Tool,
} from "@bentley/imodeljs-frontend";
/** Example Marker to show an *incident*. Each incident has an *id*, a *severity*, and an *icon*. */
class IncidentMarker extends Marker {
private static _size = Point2d.create(30, 30);
private static _imageSize = Point2d.create(40, 40);
private static _imageOffset = Point2d.create(0, 30);
private static _amber = new ColorDef(ColorByName.amber);
private static _sweep360 = AngleSweep.create360();
private _color: ColorDef;
/** uncomment the next line to make the icon only show when the cursor is over an incident marker. */
// public get wantImage() { return this._isHilited; }
/** Get a color based on severity by interpolating Green(0) -> Amber(15) -> Red(30) */
public static makeColor(severity: number): ColorDef {
return (severity <= 16 ? ColorDef.green.lerp(this._amber, (severity - 1) / 15.) :
this._amber.lerp(ColorDef.red, (severity - 16) / 14.));
}
// when someone clicks on our marker, open a message box with the severity of the incident.
public setupAndPromptForNextAction(): void {
IModelApp.accuSnap.enableSnap(true);
if (0 === this.points.length) {
IModelApp.notifications.outputPromptByKey("SampleApp:tools.Measure.ByPoints.Prompts.FirstPoint");
return;
}
IModelApp.notifications.outputPromptByKey("SampleApp:tools.Measure.ByPoints.Prompts.NextPoint");
const hints = new AccuDrawHintBuilder();
hints.enableSmartRotation = true;
if (this.points.length > 1 && !(this.points[this.points.length - 1].isAlmostEqual(this.points[this.points.length - 2])))
hints.setXAxis(Vector3d.createStartEnd(this.points[this.points.length - 2], this.points[this.points.length - 1])); // Rotate AccuDraw to last segment...
hints.setOrigin(this.points[this.points.length - 1]);
hints.sendHints();
}
radialHeightData.push(height);
radialSlopeData.push(slope);
radialDisplacementData.push(0.0);
radialDisplacementData.push(0.0);
radialDisplacementData.push(height);
}
// Static Channels.
auxChannels.push(new AuxChannel([new AuxChannelData(0.0, radialDisplacementData)], AuxChannelDataType.Vector, "Static Radial Displacement", "Radial: Static"));
auxChannels.push(new AuxChannel([new AuxChannelData(1.0, radialHeightData)], AuxChannelDataType.Distance, "Static Radial Height", "Radial: Static"));
auxChannels.push(new AuxChannel([new AuxChannelData(1.0, radialSlopeData)], AuxChannelDataType.Scalar, "Static Radial Slope", "Radial: Static"));
// Animated Channels.
const radialDisplacementDataVector = [new AuxChannelData(0.0, zeroDisplacementData), new AuxChannelData(1.0, radialDisplacementData), new AuxChannelData(2.0, zeroDisplacementData)];
const radialHeightDataVector = [new AuxChannelData(0.0, zeroScalarData), new AuxChannelData(1.0, radialHeightData), new AuxChannelData(2.0, zeroScalarData)];
const radialSlopeDataVector = [new AuxChannelData(0.0, zeroScalarData), new AuxChannelData(1.0, radialSlopeData), new AuxChannelData(2.0, zeroScalarData)];
auxChannels.push(new AuxChannel(radialDisplacementDataVector, AuxChannelDataType.Vector, "Animated Radial Displacement", "Radial: Time"));
auxChannels.push(new AuxChannel(radialHeightDataVector, AuxChannelDataType.Distance, "Animated Radial Height", "Radial: Time"));
auxChannels.push(new AuxChannel(radialSlopeDataVector, AuxChannelDataType.Scalar, "Animated Radial Slope", "Radial: Time"));
/** Create linear waves -- 10 separate frames. */
const waveHeight = radius / 20.0;
const waveLength = radius / 2.0;
const frameCount = 10;
const linearDisplacementDataVector = [], linearHeightDataVector = [], linearSlopeDataVector = [];
for (let i = 0; i < frameCount; i++) {
const fraction = i / (frameCount - 1);
const waveCenter = waveLength * fraction;
const linearHeightData = [], linearSlopeData = [], linearDisplacementData = [];
zeroScalarData.push(0.0);
zeroDisplacementData.push(0.0);
zeroDisplacementData.push(0.0);
zeroDisplacementData.push(0.0);
radialHeightData.push(height);
radialSlopeData.push(slope);
radialDisplacementData.push(0.0);
radialDisplacementData.push(0.0);
radialDisplacementData.push(height);
}
// Static Channels.
auxChannels.push(new AuxChannel([new AuxChannelData(0.0, radialDisplacementData)], AuxChannelDataType.Vector, "Static Radial Displacement", "Radial: Static"));
auxChannels.push(new AuxChannel([new AuxChannelData(1.0, radialHeightData)], AuxChannelDataType.Distance, "Static Radial Height", "Radial: Static"));
auxChannels.push(new AuxChannel([new AuxChannelData(1.0, radialSlopeData)], AuxChannelDataType.Scalar, "Static Radial Slope", "Radial: Static"));
// Animated Channels.
const radialDisplacementDataVector = [new AuxChannelData(0.0, zeroDisplacementData), new AuxChannelData(1.0, radialDisplacementData), new AuxChannelData(2.0, zeroDisplacementData)];
const radialHeightDataVector = [new AuxChannelData(0.0, zeroScalarData), new AuxChannelData(1.0, radialHeightData), new AuxChannelData(2.0, zeroScalarData)];
const radialSlopeDataVector = [new AuxChannelData(0.0, zeroScalarData), new AuxChannelData(1.0, radialSlopeData), new AuxChannelData(2.0, zeroScalarData)];
auxChannels.push(new AuxChannel(radialDisplacementDataVector, AuxChannelDataType.Vector, "Animated Radial Displacement", "Radial: Time"));
auxChannels.push(new AuxChannel(radialHeightDataVector, AuxChannelDataType.Distance, "Animated Radial Height", "Radial: Time"));
auxChannels.push(new AuxChannel(radialSlopeDataVector, AuxChannelDataType.Scalar, "Animated Radial Slope", "Radial: Time"));
/** Create linear waves -- 10 separate frames. */
const waveHeight = radius / 20.0;
const waveLength = radius / 2.0;
const frameCount = 10;
const linearDisplacementDataVector = [], linearHeightDataVector = [], linearSlopeDataVector = [];
const slope = Math.abs(Math.cos(angle));
zeroScalarData.push(0.0);
zeroDisplacementData.push(0.0);
zeroDisplacementData.push(0.0);
zeroDisplacementData.push(0.0);
radialHeightData.push(height);
radialSlopeData.push(slope);
radialDisplacementData.push(0.0);
radialDisplacementData.push(0.0);
radialDisplacementData.push(height);
}
// Static Channels.
auxChannels.push(new AuxChannel([new AuxChannelData(0.0, radialDisplacementData)], AuxChannelDataType.Vector, "Static Radial Displacement", "Radial: Static"));
auxChannels.push(new AuxChannel([new AuxChannelData(1.0, radialHeightData)], AuxChannelDataType.Distance, "Static Radial Height", "Radial: Static"));
auxChannels.push(new AuxChannel([new AuxChannelData(1.0, radialSlopeData)], AuxChannelDataType.Scalar, "Static Radial Slope", "Radial: Static"));
// Animated Channels.
const radialDisplacementDataVector = [new AuxChannelData(0.0, zeroDisplacementData), new AuxChannelData(1.0, radialDisplacementData), new AuxChannelData(2.0, zeroDisplacementData)];
const radialHeightDataVector = [new AuxChannelData(0.0, zeroScalarData), new AuxChannelData(1.0, radialHeightData), new AuxChannelData(2.0, zeroScalarData)];
const radialSlopeDataVector = [new AuxChannelData(0.0, zeroScalarData), new AuxChannelData(1.0, radialSlopeData), new AuxChannelData(2.0, zeroScalarData)];
auxChannels.push(new AuxChannel(radialDisplacementDataVector, AuxChannelDataType.Vector, "Animated Radial Displacement", "Radial: Time"));
auxChannels.push(new AuxChannel(radialHeightDataVector, AuxChannelDataType.Distance, "Animated Radial Height", "Radial: Time"));
auxChannels.push(new AuxChannel(radialSlopeDataVector, AuxChannelDataType.Scalar, "Animated Radial Slope", "Radial: Time"));
/** Create linear waves -- 10 separate frames. */
const waveHeight = radius / 20.0;
const waveLength = radius / 2.0;
const frameCount = 10;
zeroDisplacementData.push(0.0);
radialHeightData.push(height);
radialSlopeData.push(slope);
radialDisplacementData.push(0.0);
radialDisplacementData.push(0.0);
radialDisplacementData.push(height);
}
// Static Channels.
auxChannels.push(new AuxChannel([new AuxChannelData(0.0, radialDisplacementData)], AuxChannelDataType.Vector, "Static Radial Displacement", "Radial: Static"));
auxChannels.push(new AuxChannel([new AuxChannelData(1.0, radialHeightData)], AuxChannelDataType.Distance, "Static Radial Height", "Radial: Static"));
auxChannels.push(new AuxChannel([new AuxChannelData(1.0, radialSlopeData)], AuxChannelDataType.Scalar, "Static Radial Slope", "Radial: Static"));
// Animated Channels.
const radialDisplacementDataVector = [new AuxChannelData(0.0, zeroDisplacementData), new AuxChannelData(1.0, radialDisplacementData), new AuxChannelData(2.0, zeroDisplacementData)];
const radialHeightDataVector = [new AuxChannelData(0.0, zeroScalarData), new AuxChannelData(1.0, radialHeightData), new AuxChannelData(2.0, zeroScalarData)];
const radialSlopeDataVector = [new AuxChannelData(0.0, zeroScalarData), new AuxChannelData(1.0, radialSlopeData), new AuxChannelData(2.0, zeroScalarData)];
auxChannels.push(new AuxChannel(radialDisplacementDataVector, AuxChannelDataType.Vector, "Animated Radial Displacement", "Radial: Time"));
auxChannels.push(new AuxChannel(radialHeightDataVector, AuxChannelDataType.Distance, "Animated Radial Height", "Radial: Time"));
auxChannels.push(new AuxChannel(radialSlopeDataVector, AuxChannelDataType.Scalar, "Animated Radial Slope", "Radial: Time"));
/** Create linear waves -- 10 separate frames. */
const waveHeight = radius / 20.0;
const waveLength = radius / 2.0;
const frameCount = 10;
const linearDisplacementDataVector = [], linearHeightDataVector = [], linearSlopeDataVector = [];
for (let i = 0; i < frameCount; i++) {
const fraction = i / (frameCount - 1);
const waveCenter = waveLength * fraction;
if (fs.existsSync(pathname))
fs.unlinkSync(pathname);
this._iModelDb = IModelDb.createStandalone(pathname, { rootSubject: { name: this._iModelName } });
const definitionModelId: Id64String = IModel.dictionaryId;
this._physicalModelId = PhysicalModel.insert(this._iModelDb, IModel.rootSubjectId, "TestModel");
this._codeSpecId = this._iModelDb.codeSpecs.insert("TestCodeSpec", CodeScopeSpec.Type.Model);
this._categoryId = SpatialCategory.insert(this._iModelDb, definitionModelId, "TestCategory", { color: new ColorDef("blanchedAlmond") });
// Insert a ViewDefinition for the PhysicalModel
const viewName = "Physical View";
const modelSelectorId: Id64String = ModelSelector.insert(this._iModelDb, definitionModelId, viewName, [this._physicalModelId]);
const categorySelectorId: Id64String = CategorySelector.insert(this._iModelDb, definitionModelId, viewName, [this._categoryId]);
const displayStyleId: Id64String = DisplayStyle3d.insert(this._iModelDb, definitionModelId, viewName);
const viewRange = new Range3d(0, 0, 0, 50, 50, 50);
OrthographicViewDefinition.insert(this._iModelDb, definitionModelId, viewName, modelSelectorId, categorySelectorId, displayStyleId, viewRange);
this._iModelDb.updateProjectExtents(new Range3d(-1000, -1000, -1000, 1000, 1000, 1000));
this._iModelDb.saveChanges("Setup new iModel");
this._iModelDb.closeStandalone();
this._iModelDb = undefined;
return pathname;
}
private _initializeLogger(): void {
this._iModelDb = IModelDb.createStandalone(pathname, { rootSubject: { name: this._iModelName } });
const definitionModelId: Id64String = IModel.dictionaryId;
this._physicalModelId = PhysicalModel.insert(this._iModelDb, IModel.rootSubjectId, "TestModel");
this._codeSpecId = this._iModelDb.codeSpecs.insert("TestCodeSpec", CodeScopeSpec.Type.Model);
this._categoryId = SpatialCategory.insert(this._iModelDb, definitionModelId, "TestCategory", { color: new ColorDef("blanchedAlmond") });
// Insert a ViewDefinition for the PhysicalModel
const viewName = "Physical View";
const modelSelectorId: Id64String = ModelSelector.insert(this._iModelDb, definitionModelId, viewName, [this._physicalModelId]);
const categorySelectorId: Id64String = CategorySelector.insert(this._iModelDb, definitionModelId, viewName, [this._categoryId]);
const displayStyleId: Id64String = DisplayStyle3d.insert(this._iModelDb, definitionModelId, viewName);
const viewRange = new Range3d(0, 0, 0, 50, 50, 50);
OrthographicViewDefinition.insert(this._iModelDb, definitionModelId, viewName, modelSelectorId, categorySelectorId, displayStyleId, viewRange);
this._iModelDb.updateProjectExtents(new Range3d(-1000, -1000, -1000, 1000, 1000, 1000));
this._iModelDb.saveChanges("Setup new iModel");
this._iModelDb.closeStandalone();
this._iModelDb = undefined;
return pathname;
}
private _initializeLogger(): void {
radialDisplacementData.push(height);
}
// Static Channels.
auxChannels.push(new AuxChannel([new AuxChannelData(0.0, radialDisplacementData)], AuxChannelDataType.Vector, "Static Radial Displacement", "Radial: Static"));
auxChannels.push(new AuxChannel([new AuxChannelData(1.0, radialHeightData)], AuxChannelDataType.Distance, "Static Radial Height", "Radial: Static"));
auxChannels.push(new AuxChannel([new AuxChannelData(1.0, radialSlopeData)], AuxChannelDataType.Scalar, "Static Radial Slope", "Radial: Static"));
// Animated Channels.
const radialDisplacementDataVector = [new AuxChannelData(0.0, zeroDisplacementData), new AuxChannelData(1.0, radialDisplacementData), new AuxChannelData(2.0, zeroDisplacementData)];
const radialHeightDataVector = [new AuxChannelData(0.0, zeroScalarData), new AuxChannelData(1.0, radialHeightData), new AuxChannelData(2.0, zeroScalarData)];
const radialSlopeDataVector = [new AuxChannelData(0.0, zeroScalarData), new AuxChannelData(1.0, radialSlopeData), new AuxChannelData(2.0, zeroScalarData)];
auxChannels.push(new AuxChannel(radialDisplacementDataVector, AuxChannelDataType.Vector, "Animated Radial Displacement", "Radial: Time"));
auxChannels.push(new AuxChannel(radialHeightDataVector, AuxChannelDataType.Distance, "Animated Radial Height", "Radial: Time"));
auxChannels.push(new AuxChannel(radialSlopeDataVector, AuxChannelDataType.Scalar, "Animated Radial Slope", "Radial: Time"));
/** Create linear waves -- 10 separate frames. */
const waveHeight = radius / 20.0;
const waveLength = radius / 2.0;
const frameCount = 10;
const linearDisplacementDataVector = [], linearHeightDataVector = [], linearSlopeDataVector = [];
for (let i = 0; i < frameCount; i++) {
const fraction = i / (frameCount - 1);
const waveCenter = waveLength * fraction;
const linearHeightData = [], linearSlopeData = [], linearDisplacementData = [];
for (let j = 0; j < polyface.data.point.length; j++) {
const point = polyface.data.point.getPoint3dAtUncheckedPointIndex(j);
const theta = Angle.pi2Radians * (point.x - waveCenter) / waveLength;
const height = waveHeight * Math.sin(theta);
radialDisplacementData.push(0.0);
radialDisplacementData.push(0.0);
radialDisplacementData.push(height);
}
// Static Channels.
auxChannels.push(new AuxChannel([new AuxChannelData(0.0, radialDisplacementData)], AuxChannelDataType.Vector, "Static Radial Displacement", "Radial: Static"));
auxChannels.push(new AuxChannel([new AuxChannelData(1.0, radialHeightData)], AuxChannelDataType.Distance, "Static Radial Height", "Radial: Static"));
auxChannels.push(new AuxChannel([new AuxChannelData(1.0, radialSlopeData)], AuxChannelDataType.Scalar, "Static Radial Slope", "Radial: Static"));
// Animated Channels.
const radialDisplacementDataVector = [new AuxChannelData(0.0, zeroDisplacementData), new AuxChannelData(1.0, radialDisplacementData), new AuxChannelData(2.0, zeroDisplacementData)];
const radialHeightDataVector = [new AuxChannelData(0.0, zeroScalarData), new AuxChannelData(1.0, radialHeightData), new AuxChannelData(2.0, zeroScalarData)];
const radialSlopeDataVector = [new AuxChannelData(0.0, zeroScalarData), new AuxChannelData(1.0, radialSlopeData), new AuxChannelData(2.0, zeroScalarData)];
auxChannels.push(new AuxChannel(radialDisplacementDataVector, AuxChannelDataType.Vector, "Animated Radial Displacement", "Radial: Time"));
auxChannels.push(new AuxChannel(radialHeightDataVector, AuxChannelDataType.Distance, "Animated Radial Height", "Radial: Time"));
auxChannels.push(new AuxChannel(radialSlopeDataVector, AuxChannelDataType.Scalar, "Animated Radial Slope", "Radial: Time"));
/** Create linear waves -- 10 separate frames. */
const waveHeight = radius / 20.0;
const waveLength = radius / 2.0;
const frameCount = 10;
const linearDisplacementDataVector = [], linearHeightDataVector = [], linearSlopeDataVector = [];
for (let i = 0; i < frameCount; i++) {
const fraction = i / (frameCount - 1);
const waveCenter = waveLength * fraction;
const linearHeightData = [], linearSlopeData = [], linearDisplacementData = [];
for (let j = 0; j < polyface.data.point.length; j++) {
const point = polyface.data.point.getPoint3dAtUncheckedPointIndex(j);