@itwin/frontend-devtools 3.0.0-dev.82 → 3.0.0-dev.86
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 +723 -723
- package/LICENSE.md +9 -9
- package/lib/cjs/ClipboardUtilities.js.map +1 -1
- package/lib/cjs/effects/Convolution.js +17 -17
- package/lib/cjs/effects/Convolution.js.map +1 -1
- package/lib/cjs/effects/EffectTools.js.map +1 -1
- package/lib/cjs/effects/Explosion.js.map +1 -1
- package/lib/cjs/effects/FlipImage.js +20 -20
- package/lib/cjs/effects/FlipImage.js.map +1 -1
- package/lib/cjs/effects/LensDistortion.js +21 -21
- package/lib/cjs/effects/LensDistortion.js.map +1 -1
- package/lib/cjs/effects/Random.js.map +1 -1
- package/lib/cjs/effects/Saturation.js +26 -26
- package/lib/cjs/effects/Saturation.js.map +1 -1
- package/lib/cjs/effects/Snow.js.map +1 -1
- package/lib/cjs/effects/Vignette.js +29 -29
- package/lib/cjs/effects/Vignette.js.map +1 -1
- package/lib/cjs/tools/FrustumDecoration.js.map +1 -1
- package/lib/cjs/tools/InspectElementTool.js.map +1 -1
- package/lib/cjs/tools/MapLayerTool.js.map +1 -1
- package/lib/cjs/tools/SetGpuMemoryLimitTool.js.map +1 -1
- package/lib/cjs/ui/Button.js.map +1 -1
- package/lib/cjs/ui/CheckBox.js.map +1 -1
- package/lib/cjs/ui/ColorInput.js.map +1 -1
- package/lib/cjs/ui/ComboBox.js.map +1 -1
- package/lib/cjs/ui/NestedMenu.js.map +1 -1
- package/lib/cjs/ui/NumericInput.js.map +1 -1
- package/lib/cjs/ui/RadioBox.js.map +1 -1
- package/lib/cjs/ui/Slider.js.map +1 -1
- package/lib/cjs/ui/TextBox.js.map +1 -1
- package/lib/cjs/widgets/DiagnosticsPanel.js.map +1 -1
- package/lib/cjs/widgets/FpsTracker.js.map +1 -1
- package/lib/cjs/widgets/MemoryTracker.js.map +1 -1
- package/lib/cjs/widgets/TileMemoryBreakdown.js.map +1 -1
- package/lib/cjs/widgets/TileStatisticsTracker.js.map +1 -1
- package/lib/cjs/widgets/ToolSettingsTracker.js.map +1 -1
- package/lib/esm/ClipboardUtilities.js.map +1 -1
- package/lib/esm/effects/Convolution.js +17 -17
- package/lib/esm/effects/Convolution.js.map +1 -1
- package/lib/esm/effects/EffectTools.js.map +1 -1
- package/lib/esm/effects/Explosion.js.map +1 -1
- package/lib/esm/effects/FlipImage.js +20 -20
- package/lib/esm/effects/FlipImage.js.map +1 -1
- package/lib/esm/effects/LensDistortion.js +21 -21
- package/lib/esm/effects/LensDistortion.js.map +1 -1
- package/lib/esm/effects/Random.js.map +1 -1
- package/lib/esm/effects/Saturation.js +26 -26
- package/lib/esm/effects/Saturation.js.map +1 -1
- package/lib/esm/effects/Snow.js.map +1 -1
- package/lib/esm/effects/Vignette.js +29 -29
- package/lib/esm/effects/Vignette.js.map +1 -1
- package/lib/esm/tools/FrustumDecoration.js.map +1 -1
- package/lib/esm/tools/InspectElementTool.js.map +1 -1
- package/lib/esm/tools/MapLayerTool.js.map +1 -1
- package/lib/esm/tools/SetGpuMemoryLimitTool.js.map +1 -1
- package/lib/esm/ui/Button.js.map +1 -1
- package/lib/esm/ui/CheckBox.js.map +1 -1
- package/lib/esm/ui/ColorInput.js.map +1 -1
- package/lib/esm/ui/ComboBox.js.map +1 -1
- package/lib/esm/ui/NestedMenu.js.map +1 -1
- package/lib/esm/ui/NumericInput.js.map +1 -1
- package/lib/esm/ui/RadioBox.js.map +1 -1
- package/lib/esm/ui/Slider.js.map +1 -1
- package/lib/esm/ui/TextBox.js.map +1 -1
- package/lib/esm/widgets/DiagnosticsPanel.js.map +1 -1
- package/lib/esm/widgets/FpsTracker.js.map +1 -1
- package/lib/esm/widgets/MemoryTracker.js.map +1 -1
- package/lib/esm/widgets/TileMemoryBreakdown.js.map +1 -1
- package/lib/esm/widgets/TileStatisticsTracker.js.map +1 -1
- package/lib/esm/widgets/ToolSettingsTracker.js.map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AAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,mBAAmB,CAAC,KAAK,EAAE;aAClE,CAAC,CAAC;YAEH,IAAI,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;SACtC;IACH,CAAC;;AAxBuB,yBAAW,GAAG,IAAI,GAAG,EAA2B,CAAC;AA2B3E;;;GAGG;AACH,MAAM,OAAO,UAAW,SAAQ,IAAI;IAGlB,KAAK,CAAC,GAAG,CAAC,MAAgB;QACxC,MAAM,EAAE,GAAG,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC9C,IAAI,EAAE;YACJ,MAAM,aAAa,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAEzC,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,WAAW,CAAC,GAAG,IAAc;QACjD,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,IAAI,OAAO,MAAM,KAAK,QAAQ;YAC5B,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAEzB,OAAO,IAAI,CAAC;IACd,CAAC;;AAhBsB,iBAAM,GAAG,YAAY,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Effects\n */\n\nimport { dispose } from \"@itwin/core-bentley\";\nimport { Point2d, Range1d, Range2d, Vector2d } from \"@itwin/core-geometry\";\nimport { RenderTexture } from \"@itwin/core-common\";\nimport {\n DecorateContext, Decorator, GraphicType, imageElementFromUrl, IModelApp, ParticleCollectionBuilder, ParticleProps, TextureTransparency, Tool, Viewport,\n} from \"@itwin/core-frontend\";\nimport { parseToggle } from \"../tools/parseToggle\";\nimport { randomFloat, randomInteger } from \"./Random\";\n\n/** Represents one particle displayed by a [[SnowDecorator]].\n * Particle positions are in [CoordSystem.View]($frontend).\n * @beta\n */\nexport interface SnowParticle extends ParticleProps {\n /** Make x, y, and z from ParticleProps writable. */\n x: number;\n y: number;\n z: number;\n\n /** Current velocity, in pixels per second. */\n velocity: Vector2d;\n}\n\n/** Parameters controlling how a [[SnowDecorator]] works.\n * @beta\n */\nexport interface SnowParams {\n /** The number of snow particles to produce. This could alternatively be expressed as a density so that small viewports would not be more crowded than larger ones. */\n numParticles: number;\n /** Range from which to randomly select each particle's size, in pixels. */\n sizeRange: Range1d;\n /** Range from which to randomly select each particle's transparency. */\n transparencyRange: Range1d;\n /** Range from which to randomly select each particle's initial velocity, in pixels per second. */\n velocityRange: Range2d;\n /** Range from which to randomly select an acceleration to apply to each particle's velocity each frame, in pixels per second squared, to simulate wind. */\n accelerationRange: Range2d;\n /** Wind velocity in pixels per second in X. */\n windVelocity: number;\n}\n\n/** The default snow effect parameters used by newly-created SnowDecorators. */\nconst defaultSnowParams: SnowParams = {\n numParticles: 2000,\n sizeRange: Range1d.createXX(3, 22),\n transparencyRange: Range1d.createXX(0, 50),\n velocityRange: new Range2d(-30, 50, 30, 130),\n accelerationRange: new Range2d(-1, -0.25, 1, 0.25),\n windVelocity: 0,\n};\n\n/** Simulates snowfall in a [Viewport]($frontend) using particle effects.\n * @see [[SnowEffect]] for a [Tool]($frontend) that toggles this decorator.\n * @see [ParticleCollectionBuilder]($frontend) for defining custom particle effects.\n * @beta\n */\nexport class SnowDecorator implements Decorator {\n /** The viewport being decorated. */\n public readonly viewport: Viewport;\n /** Invoked when this decorator is to be destroyed. */\n public readonly dispose: VoidFunction;\n /** The initial width and height of the viewport, from which we randomly select each particle's initial position. */\n private readonly _dimensions: Point2d;\n /** The list of particles being drawn. */\n private readonly _particles: SnowParticle[] = [];\n /** The image to display for each particle. */\n private _texture?: RenderTexture;\n /** The last time `updateParticles()` was invoked, in milliseconds. */\n private _lastUpdateTime: number;\n private readonly _params: SnowParams;\n\n private constructor(viewport: Viewport, texture: RenderTexture | undefined) {\n this._params = { ...defaultSnowParams };\n this.viewport = viewport;\n this._dimensions = new Point2d(viewport.viewRect.width, viewport.viewRect.height);\n this._lastUpdateTime = Date.now();\n this._texture = texture;\n\n // Tell the viewport to re-render the decorations every frame so that the snow particles animate smoothly.\n const removeOnRender = viewport.onRender.addListener(() => viewport.invalidateDecorations());\n\n // When the viewport is resized, replace this decorator with a new one to match the new dimensions.\n const removeOnResized = viewport.onResized.addListener(() => {\n // Transfer ownership of the texture to the new decorator.\n const tex = this._texture;\n this._texture = undefined;\n this.dispose();\n new SnowDecorator(viewport, tex);\n });\n\n // When the viewport is destroyed, dispose of this decorator too.\n const removeOnDispose = viewport.onDisposed.addListener(() => this.dispose());\n const removeDecorator = IModelApp.viewManager.addDecorator(this);\n\n this.dispose = () => {\n removeDecorator();\n removeOnRender();\n removeOnDispose();\n removeOnResized();\n this._texture = dispose(this._texture);\n SnowDecorator._decorators.delete(viewport);\n };\n\n SnowDecorator._decorators.set(viewport, this);\n\n // Initialize the particles.\n for (let i = 0; i < this._params.numParticles; i++)\n this._particles.push(this.emit(true));\n }\n\n public decorate(context: DecorateContext): void {\n if (context.viewport !== this.viewport || !this._texture)\n return;\n\n // Update the particles.\n const now = Date.now();\n const deltaMillis = now - this._lastUpdateTime;\n this._lastUpdateTime = now;\n this.updateParticles(deltaMillis / 1000);\n\n // Create particle graphics.\n const builder = ParticleCollectionBuilder.create({\n viewport: this.viewport,\n isViewCoords: true,\n texture: this._texture,\n size: (this._params.sizeRange.high - this._params.sizeRange.low) / 2,\n });\n\n for (const particle of this._particles)\n builder.addParticle(particle);\n\n const graphic = builder.finish();\n if (graphic)\n context.addDecoration(GraphicType.ViewOverlay, graphic);\n }\n\n /** Change some of the parameters affecting this decorator. */\n public configure(params: Partial<SnowParams>): void {\n for (const key of Object.keys(params)) {\n const val = (params as any)[key];\n if (undefined !== val)\n (this._params as any)[key] = val;\n }\n }\n\n /** Emit a new particle with randomized properties. */\n private emit(randomizeHeight: boolean): SnowParticle {\n return {\n x: randomInteger(0, this._dimensions.x),\n y: randomizeHeight ? randomInteger(0, this._dimensions.y) : 0,\n z: 0,\n size: randomInteger(this._params.sizeRange.low, this._params.sizeRange.high),\n transparency: randomInteger(this._params.transparencyRange.low, this._params.transparencyRange.high),\n velocity: new Vector2d(randomFloat(this._params.velocityRange.low.x, this._params.velocityRange.high.x),\n randomFloat(this._params.velocityRange.low.y, this._params.velocityRange.high.y)),\n };\n }\n\n // Update the positions and velocities of all the particles based on the amount of time that has passed since the last update.\n private updateParticles(elapsedSeconds: number): void {\n // Determine if someone changed the desired number of particles.\n const particleDiscrepancy = this._params.numParticles - this._particles.length;\n if (particleDiscrepancy > 0) {\n // Birth new particles up to the new maximum.\n for (let i = 0; i < particleDiscrepancy; i++)\n this._particles.push(this.emit(true));\n } else {\n // Destroy extra particles.\n this._particles.length = this._params.numParticles;\n }\n\n const acceleration = new Vector2d();\n const velocity = new Vector2d();\n for (let i = 0; i < this._particles.length; i++) {\n // Apply some acceleration to produce random drift.\n const particle = this._particles[i];\n acceleration.set(randomFloat(this._params.accelerationRange.low.x, this._params.accelerationRange.high.x),\n randomFloat(this._params.accelerationRange.low.y, this._params.accelerationRange.high.y));\n\n acceleration.scale(elapsedSeconds, acceleration);\n particle.velocity.plus(acceleration, particle.velocity);\n\n // Apply velocity.\n particle.velocity.clone(velocity);\n velocity.scale(elapsedSeconds, velocity);\n particle.x += velocity.x;\n particle.y += velocity.y;\n\n // Apply wind\n particle.x += this._params.windVelocity * elapsedSeconds;\n\n // Particles that travel beyond the viewport's left or right edges wrap around to the other side.\n if (particle.x < 0)\n particle.x = this._dimensions.x - 1;\n else if (particle.x >= this._dimensions.x)\n particle.x = 0;\n\n // Particles that travel beyond the viewport's bottom or top edges are replaced by newborn particles.\n if (particle.y < 0 || particle.y >= this._dimensions.y)\n this._particles[i] = this.emit(false);\n }\n }\n\n private static readonly _decorators = new Map<Viewport, SnowDecorator>();\n\n /** Toggle this decorator for the specified viewport.\n * @param viewport The viewport to which the effect should be applied or removed.\n * @param enable `true` to enable the effect, `false` to disable it, or `undefined` to toggle the current state.\n */\n public static async toggle(viewport: Viewport, enable?: boolean): Promise<void> {\n const decorator = this._decorators.get(viewport);\n if (undefined === enable)\n enable = undefined === decorator;\n\n if (undefined !== decorator && !enable)\n decorator.dispose();\n else if (undefined === decorator && enable) {\n // Create a texture to use for the particles.\n // Note: the decorator takes ownership of the texture, and disposes of it when the decorator is disposed.\n const image = await imageElementFromUrl(\"./sprites/particle_snow.png\");\n const texture = IModelApp.renderSystem.createTexture({\n ownership: \"external\",\n image: { source: image, transparency: TextureTransparency.Mixed },\n });\n\n new SnowDecorator(viewport, texture);\n }\n }\n}\n\n/** Toggles a decorator that simulates snow using particle effects.\n * @see [[SnowDecorator]] for the implementation of the decorator.\n * @beta\n */\nexport class SnowEffect extends Tool {\n public static override toolId = \"SnowEffect\";\n\n public override async run(enable?: boolean): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (vp)\n await SnowDecorator.toggle(vp, enable);\n\n return true;\n }\n\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const enable = parseToggle(args[0]);\n if (typeof enable !== \"string\")\n await this.run(enable);\n\n return true;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Snow.js","sourceRoot":"","sources":["../../../src/effects/Snow.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAE3E,OAAO,EACuB,WAAW,EAAE,mBAAmB,EAAE,SAAS,EAAE,yBAAyB,EAAiB,mBAAmB,EAAE,IAAI,GAC7I,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,aAA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AAK,CAAC,WAAW,CAAC,GAAG,IAAc;QACjD,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,IAAI,OAAO,MAAM,KAAK,QAAQ;YAC5B,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAEzB,OAAO,IAAI,CAAC;IACd,CAAC;;AAhBsB,iBAAM,GAAG,YAAY,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Effects\r\n */\r\n\r\nimport { dispose } from \"@itwin/core-bentley\";\r\nimport { Point2d, Range1d, Range2d, Vector2d } from \"@itwin/core-geometry\";\r\nimport { RenderTexture } from \"@itwin/core-common\";\r\nimport {\r\n DecorateContext, Decorator, GraphicType, imageElementFromUrl, IModelApp, ParticleCollectionBuilder, ParticleProps, TextureTransparency, Tool, Viewport,\r\n} from \"@itwin/core-frontend\";\r\nimport { parseToggle } from \"../tools/parseToggle\";\r\nimport { randomFloat, randomInteger } from \"./Random\";\r\n\r\n/** Represents one particle displayed by a [[SnowDecorator]].\r\n * Particle positions are in [CoordSystem.View]($frontend).\r\n * @beta\r\n */\r\nexport interface SnowParticle extends ParticleProps {\r\n /** Make x, y, and z from ParticleProps writable. */\r\n x: number;\r\n y: number;\r\n z: number;\r\n\r\n /** Current velocity, in pixels per second. */\r\n velocity: Vector2d;\r\n}\r\n\r\n/** Parameters controlling how a [[SnowDecorator]] works.\r\n * @beta\r\n */\r\nexport interface SnowParams {\r\n /** The number of snow particles to produce. This could alternatively be expressed as a density so that small viewports would not be more crowded than larger ones. */\r\n numParticles: number;\r\n /** Range from which to randomly select each particle's size, in pixels. */\r\n sizeRange: Range1d;\r\n /** Range from which to randomly select each particle's transparency. */\r\n transparencyRange: Range1d;\r\n /** Range from which to randomly select each particle's initial velocity, in pixels per second. */\r\n velocityRange: Range2d;\r\n /** Range from which to randomly select an acceleration to apply to each particle's velocity each frame, in pixels per second squared, to simulate wind. */\r\n accelerationRange: Range2d;\r\n /** Wind velocity in pixels per second in X. */\r\n windVelocity: number;\r\n}\r\n\r\n/** The default snow effect parameters used by newly-created SnowDecorators. */\r\nconst defaultSnowParams: SnowParams = {\r\n numParticles: 2000,\r\n sizeRange: Range1d.createXX(3, 22),\r\n transparencyRange: Range1d.createXX(0, 50),\r\n velocityRange: new Range2d(-30, 50, 30, 130),\r\n accelerationRange: new Range2d(-1, -0.25, 1, 0.25),\r\n windVelocity: 0,\r\n};\r\n\r\n/** Simulates snowfall in a [Viewport]($frontend) using particle effects.\r\n * @see [[SnowEffect]] for a [Tool]($frontend) that toggles this decorator.\r\n * @see [ParticleCollectionBuilder]($frontend) for defining custom particle effects.\r\n * @beta\r\n */\r\nexport class SnowDecorator implements Decorator {\r\n /** The viewport being decorated. */\r\n public readonly viewport: Viewport;\r\n /** Invoked when this decorator is to be destroyed. */\r\n public readonly dispose: VoidFunction;\r\n /** The initial width and height of the viewport, from which we randomly select each particle's initial position. */\r\n private readonly _dimensions: Point2d;\r\n /** The list of particles being drawn. */\r\n private readonly _particles: SnowParticle[] = [];\r\n /** The image to display for each particle. */\r\n private _texture?: RenderTexture;\r\n /** The last time `updateParticles()` was invoked, in milliseconds. */\r\n private _lastUpdateTime: number;\r\n private readonly _params: SnowParams;\r\n\r\n private constructor(viewport: Viewport, texture: RenderTexture | undefined) {\r\n this._params = { ...defaultSnowParams };\r\n this.viewport = viewport;\r\n this._dimensions = new Point2d(viewport.viewRect.width, viewport.viewRect.height);\r\n this._lastUpdateTime = Date.now();\r\n this._texture = texture;\r\n\r\n // Tell the viewport to re-render the decorations every frame so that the snow particles animate smoothly.\r\n const removeOnRender = viewport.onRender.addListener(() => viewport.invalidateDecorations());\r\n\r\n // When the viewport is resized, replace this decorator with a new one to match the new dimensions.\r\n const removeOnResized = viewport.onResized.addListener(() => {\r\n // Transfer ownership of the texture to the new decorator.\r\n const tex = this._texture;\r\n this._texture = undefined;\r\n this.dispose();\r\n new SnowDecorator(viewport, tex);\r\n });\r\n\r\n // When the viewport is destroyed, dispose of this decorator too.\r\n const removeOnDispose = viewport.onDisposed.addListener(() => this.dispose());\r\n const removeDecorator = IModelApp.viewManager.addDecorator(this);\r\n\r\n this.dispose = () => {\r\n removeDecorator();\r\n removeOnRender();\r\n removeOnDispose();\r\n removeOnResized();\r\n this._texture = dispose(this._texture);\r\n SnowDecorator._decorators.delete(viewport);\r\n };\r\n\r\n SnowDecorator._decorators.set(viewport, this);\r\n\r\n // Initialize the particles.\r\n for (let i = 0; i < this._params.numParticles; i++)\r\n this._particles.push(this.emit(true));\r\n }\r\n\r\n public decorate(context: DecorateContext): void {\r\n if (context.viewport !== this.viewport || !this._texture)\r\n return;\r\n\r\n // Update the particles.\r\n const now = Date.now();\r\n const deltaMillis = now - this._lastUpdateTime;\r\n this._lastUpdateTime = now;\r\n this.updateParticles(deltaMillis / 1000);\r\n\r\n // Create particle graphics.\r\n const builder = ParticleCollectionBuilder.create({\r\n viewport: this.viewport,\r\n isViewCoords: true,\r\n texture: this._texture,\r\n size: (this._params.sizeRange.high - this._params.sizeRange.low) / 2,\r\n });\r\n\r\n for (const particle of this._particles)\r\n builder.addParticle(particle);\r\n\r\n const graphic = builder.finish();\r\n if (graphic)\r\n context.addDecoration(GraphicType.ViewOverlay, graphic);\r\n }\r\n\r\n /** Change some of the parameters affecting this decorator. */\r\n public configure(params: Partial<SnowParams>): void {\r\n for (const key of Object.keys(params)) {\r\n const val = (params as any)[key];\r\n if (undefined !== val)\r\n (this._params as any)[key] = val;\r\n }\r\n }\r\n\r\n /** Emit a new particle with randomized properties. */\r\n private emit(randomizeHeight: boolean): SnowParticle {\r\n return {\r\n x: randomInteger(0, this._dimensions.x),\r\n y: randomizeHeight ? randomInteger(0, this._dimensions.y) : 0,\r\n z: 0,\r\n size: randomInteger(this._params.sizeRange.low, this._params.sizeRange.high),\r\n transparency: randomInteger(this._params.transparencyRange.low, this._params.transparencyRange.high),\r\n velocity: new Vector2d(randomFloat(this._params.velocityRange.low.x, this._params.velocityRange.high.x),\r\n randomFloat(this._params.velocityRange.low.y, this._params.velocityRange.high.y)),\r\n };\r\n }\r\n\r\n // Update the positions and velocities of all the particles based on the amount of time that has passed since the last update.\r\n private updateParticles(elapsedSeconds: number): void {\r\n // Determine if someone changed the desired number of particles.\r\n const particleDiscrepancy = this._params.numParticles - this._particles.length;\r\n if (particleDiscrepancy > 0) {\r\n // Birth new particles up to the new maximum.\r\n for (let i = 0; i < particleDiscrepancy; i++)\r\n this._particles.push(this.emit(true));\r\n } else {\r\n // Destroy extra particles.\r\n this._particles.length = this._params.numParticles;\r\n }\r\n\r\n const acceleration = new Vector2d();\r\n const velocity = new Vector2d();\r\n for (let i = 0; i < this._particles.length; i++) {\r\n // Apply some acceleration to produce random drift.\r\n const particle = this._particles[i];\r\n acceleration.set(randomFloat(this._params.accelerationRange.low.x, this._params.accelerationRange.high.x),\r\n randomFloat(this._params.accelerationRange.low.y, this._params.accelerationRange.high.y));\r\n\r\n acceleration.scale(elapsedSeconds, acceleration);\r\n particle.velocity.plus(acceleration, particle.velocity);\r\n\r\n // Apply velocity.\r\n particle.velocity.clone(velocity);\r\n velocity.scale(elapsedSeconds, velocity);\r\n particle.x += velocity.x;\r\n particle.y += velocity.y;\r\n\r\n // Apply wind\r\n particle.x += this._params.windVelocity * elapsedSeconds;\r\n\r\n // Particles that travel beyond the viewport's left or right edges wrap around to the other side.\r\n if (particle.x < 0)\r\n particle.x = this._dimensions.x - 1;\r\n else if (particle.x >= this._dimensions.x)\r\n particle.x = 0;\r\n\r\n // Particles that travel beyond the viewport's bottom or top edges are replaced by newborn particles.\r\n if (particle.y < 0 || particle.y >= this._dimensions.y)\r\n this._particles[i] = this.emit(false);\r\n }\r\n }\r\n\r\n private static readonly _decorators = new Map<Viewport, SnowDecorator>();\r\n\r\n /** Toggle this decorator for the specified viewport.\r\n * @param viewport The viewport to which the effect should be applied or removed.\r\n * @param enable `true` to enable the effect, `false` to disable it, or `undefined` to toggle the current state.\r\n */\r\n public static async toggle(viewport: Viewport, enable?: boolean): Promise<void> {\r\n const decorator = this._decorators.get(viewport);\r\n if (undefined === enable)\r\n enable = undefined === decorator;\r\n\r\n if (undefined !== decorator && !enable)\r\n decorator.dispose();\r\n else if (undefined === decorator && enable) {\r\n // Create a texture to use for the particles.\r\n // Note: the decorator takes ownership of the texture, and disposes of it when the decorator is disposed.\r\n const image = await imageElementFromUrl(\"./sprites/particle_snow.png\");\r\n const texture = IModelApp.renderSystem.createTexture({\r\n ownership: \"external\",\r\n image: { source: image, transparency: TextureTransparency.Mixed },\r\n });\r\n\r\n new SnowDecorator(viewport, texture);\r\n }\r\n }\r\n}\r\n\r\n/** Toggles a decorator that simulates snow using particle effects.\r\n * @see [[SnowDecorator]] for the implementation of the decorator.\r\n * @beta\r\n */\r\nexport class SnowEffect extends Tool {\r\n public static override toolId = \"SnowEffect\";\r\n\r\n public override async run(enable?: boolean): Promise<boolean> {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (vp)\r\n await SnowDecorator.toggle(vp, enable);\r\n\r\n return true;\r\n }\r\n\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n const enable = parseToggle(args[0]);\r\n if (typeof enable !== \"string\")\r\n await this.run(enable);\r\n\r\n return true;\r\n }\r\n}\r\n"]}
|
|
@@ -17,36 +17,36 @@ export class VignetteEffect extends AddEffectTool {
|
|
|
17
17
|
get textureCoordFromPosition() { return true; }
|
|
18
18
|
get source() {
|
|
19
19
|
return {
|
|
20
|
-
vertex: `
|
|
21
|
-
void effectMain(vec4 pos) {
|
|
22
|
-
v_texCoord = textureCoordFromPosition(pos);
|
|
23
|
-
}
|
|
20
|
+
vertex: `
|
|
21
|
+
void effectMain(vec4 pos) {
|
|
22
|
+
v_texCoord = textureCoordFromPosition(pos);
|
|
23
|
+
}
|
|
24
24
|
`,
|
|
25
|
-
fragment: `
|
|
26
|
-
float sdSquare(vec2 point, float width) {
|
|
27
|
-
vec2 d = abs(point) - width;
|
|
28
|
-
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
float vignette(vec2 uv, vec2 size, float roundness, float smoothness) {
|
|
32
|
-
// Center UVs
|
|
33
|
-
uv -= 0.5;
|
|
34
|
-
|
|
35
|
-
// Shift UVs based on the larger of width or height
|
|
36
|
-
float minWidth = min(size.x, size.y);
|
|
37
|
-
uv.x = sign(uv.x) * clamp(abs(uv.x) - abs(minWidth - size.x), 0.0, 1.0);
|
|
38
|
-
uv.y = sign(uv.y) * clamp(abs(uv.y) - abs(minWidth - size.y), 0.0, 1.0);
|
|
39
|
-
|
|
40
|
-
// Signed distance calculation
|
|
41
|
-
float boxSize = minWidth * (1.0 - roundness);
|
|
42
|
-
float dist = sdSquare(uv, boxSize) - (minWidth * roundness);
|
|
43
|
-
|
|
44
|
-
return 1.0 - smoothstep(0.0, smoothness, dist);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
vec4 effectMain() {
|
|
48
|
-
return TEXTURE(u_diffuse, v_texCoord) * vignette(v_texCoord, u_size, u_roundness, u_smoothness);
|
|
49
|
-
}
|
|
25
|
+
fragment: `
|
|
26
|
+
float sdSquare(vec2 point, float width) {
|
|
27
|
+
vec2 d = abs(point) - width;
|
|
28
|
+
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
float vignette(vec2 uv, vec2 size, float roundness, float smoothness) {
|
|
32
|
+
// Center UVs
|
|
33
|
+
uv -= 0.5;
|
|
34
|
+
|
|
35
|
+
// Shift UVs based on the larger of width or height
|
|
36
|
+
float minWidth = min(size.x, size.y);
|
|
37
|
+
uv.x = sign(uv.x) * clamp(abs(uv.x) - abs(minWidth - size.x), 0.0, 1.0);
|
|
38
|
+
uv.y = sign(uv.y) * clamp(abs(uv.y) - abs(minWidth - size.y), 0.0, 1.0);
|
|
39
|
+
|
|
40
|
+
// Signed distance calculation
|
|
41
|
+
float boxSize = minWidth * (1.0 - roundness);
|
|
42
|
+
float dist = sdSquare(uv, boxSize) - (minWidth * roundness);
|
|
43
|
+
|
|
44
|
+
return 1.0 - smoothstep(0.0, smoothness, dist);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
vec4 effectMain() {
|
|
48
|
+
return TEXTURE(u_diffuse, v_texCoord) * vignette(v_texCoord, u_size, u_roundness, u_smoothness);
|
|
49
|
+
}
|
|
50
50
|
`,
|
|
51
51
|
};
|
|
52
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Vignette.js","sourceRoot":"","sources":["../../../src/effects/Vignette.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAA4B,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAEzE;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,aAAa;IAG/C,IAAc,UAAU,KAAK,OAAO,UAAU,CAAC,CAAC,CAAC;IACjD,IAAc,wBAAwB,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;IAEzD,IAAc,MAAM;QAClB,OAAO;YACL,MAAM,EAAE;;;;OAIP;YACD,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;OAyBT;SACF,CAAC;IACJ,CAAC;IAES,YAAY,CAAC,OAAiC;QACtD,OAAO,CAAC,UAAU,CAAC,YAAY,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;QACnD,OAAO,CAAC,UAAU,CAAC;YACjB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,IAAI,EAAE,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AAV,UAAU,GAAI,MAAM,CAAC,UAAU,CAAC;QAEpD,yBAAyB,CAAC,cAAc,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,WAAW,CAAC,GAAG,KAAe;QAClD,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAClG,CAAC;;AA/BsB,qBAAM,GAAG,gBAAgB,CAAC;AAIjD;;GAEG;AACoB,mBAAI,GAAG,IAAI,YAAY,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAE7D,iGAAiG;AACnF,wBAAS,GAAG,GAAG,CAAC;AAE9B;;GAEG;AACW,yBAAU,GAAG,GAAG,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Effects\n */\n\nimport { ScreenSpaceEffectBuilder, Tool, UniformType, VaryingType } from \"@itwin/core-frontend\";\nimport { parseArgs } from \"../tools/parseArgs\";\nimport { AddEffectTool, refreshViewportsForEffect } from \"./EffectTools\";\n\n/** Applies a [vignette](https://en.wikipedia.org/wiki/Vignetting) effect to the viewport.\n * From https://github.com/TyLindberg/glsl-vignette/blob/master/advanced.glsl.\n * @beta\n */\nexport class VignetteEffect extends AddEffectTool {\n public static override toolId = \"VignetteEffect\";\n\n protected get effectName() { return \"Vignette\"; }\n protected get textureCoordFromPosition() { return true; }\n\n protected get source() {\n return {\n vertex: `\n void effectMain(vec4 pos) {\n v_texCoord = textureCoordFromPosition(pos);\n }\n `,\n fragment: `\n float sdSquare(vec2 point, float width) {\n vec2 d = abs(point) - width;\n return min(max(d.x,d.y),0.0) + length(max(d,0.0));\n }\n\n float vignette(vec2 uv, vec2 size, float roundness, float smoothness) {\n // Center UVs\n uv -= 0.5;\n\n // Shift UVs based on the larger of width or height\n float minWidth = min(size.x, size.y);\n uv.x = sign(uv.x) * clamp(abs(uv.x) - abs(minWidth - size.x), 0.0, 1.0);\n uv.y = sign(uv.y) * clamp(abs(uv.y) - abs(minWidth - size.y), 0.0, 1.0);\n\n // Signed distance calculation\n float boxSize = minWidth * (1.0 - roundness);\n float dist = sdSquare(uv, boxSize) - (minWidth * roundness);\n\n return 1.0 - smoothstep(0.0, smoothness, dist);\n }\n\n vec4 effectMain() {\n return TEXTURE(u_diffuse, v_texCoord) * vignette(v_texCoord, u_size, u_roundness, u_smoothness);\n }\n `,\n };\n }\n\n protected defineEffect(builder: ScreenSpaceEffectBuilder): void {\n builder.addVarying(\"v_texCoord\", VaryingType.Vec2);\n builder.addUniform({\n name: \"u_size\",\n type: UniformType.Vec2,\n bind: (uniform) => uniform.setUniform2fv(VignetteConfig.size),\n });\n builder.addUniform({\n name: \"u_roundness\",\n type: UniformType.Float,\n bind: (uniform) => uniform.setUniform1f(VignetteConfig.roundness),\n });\n builder.addUniform({\n name: \"u_smoothness\",\n type: UniformType.Float,\n bind: (uniform) => uniform.setUniform1f(VignetteConfig.smoothness),\n });\n }\n}\n\n/** Configures the [[VignetteEffect]].\n * @beta\n */\nexport class VignetteConfig extends Tool {\n public static override toolId = \"VignetteConfig\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 4; }\n\n /** Size of the vignette in the form (width/2, height/2). e.g., to make the vignette start fading in halfway between the center and edges of\n * UV space, use (0.25, 0.25).\n */\n public static readonly size = new Float32Array([0.25, 0.25]);\n\n /** How round the vignette will be, from 0.0 (perfectly rectangular) to 1.0 (perfectly round). */\n public static roundness = 1.0;\n\n /** How quickly the vignette fades in. The vignette starts fading in at the edge of the values provided by `size` and will be\n * fully faded in at (size.x + smoothness, size.y * smoothness). A value of 0.0 produces a hard edge.\n */\n public static smoothness = 0.5;\n\n public override async run(width?: number, height?: number, roundness?: number, smoothness?: number): Promise<boolean> {\n const config = VignetteConfig;\n config.size[0] = width ?? config.size[0];\n config.size[1] = height ?? config.size[1];\n config.roundness = roundness ?? config.roundness;\n config.smoothness = smoothness ?? config.smoothness;\n\n refreshViewportsForEffect(\"fdt Vignette\");\n return true;\n }\n\n public override async parseAndRun(...input: string[]): Promise<boolean> {\n const args = parseArgs(input);\n return this.run(args.getFloat(\"w\"), args.getFloat(\"h\"), args.getFloat(\"r\"), args.getFloat(\"s\"));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Vignette.js","sourceRoot":"","sources":["../../../src/effects/Vignette.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAA4B,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAEzE;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,aAAa;IAG/C,IAAc,UAAU,KAAK,OAAO,UAAU,CAAC,CAAC,CAAC;IACjD,IAAc,wBAAwB,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;IAEzD,IAAc,MAAM;QAClB,OAAO;YACL,MAAM,EAAE;;;;OAIP;YACD,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;OAyBT;SACF,CAAC;IACJ,CAAC;IAES,YAAY,CAAC,OAAiC;QACtD,OAAO,CAAC,UAAU,CAAC,YAAY,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;QACnD,OAAO,CAAC,UAAU,CAAC;YACjB,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,WAAW,CAAC,IA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G,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,MAAM,CAAC,UAAU,CAAC;QAEpD,yBAAyB,CAAC,cAAc,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,WAAW,CAAC,GAAG,KAAe;QAClD,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAClG,CAAC;;AA/BsB,qBAAM,GAAG,gBAAgB,CAAC;AAIjD;;GAEG;AACoB,mBAAI,GAAG,IAAI,YAAY,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAE7D,iGAAiG;AACnF,wBAAS,GAAG,GAAG,CAAC;AAE9B;;GAEG;AACW,yBAAU,GAAG,GAAG,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Effects\r\n */\r\n\r\nimport { ScreenSpaceEffectBuilder, Tool, UniformType, VaryingType } from \"@itwin/core-frontend\";\r\nimport { parseArgs } from \"../tools/parseArgs\";\r\nimport { AddEffectTool, refreshViewportsForEffect } from \"./EffectTools\";\r\n\r\n/** Applies a [vignette](https://en.wikipedia.org/wiki/Vignetting) effect to the viewport.\r\n * From https://github.com/TyLindberg/glsl-vignette/blob/master/advanced.glsl.\r\n * @beta\r\n */\r\nexport class VignetteEffect extends AddEffectTool {\r\n public static override toolId = \"VignetteEffect\";\r\n\r\n protected get effectName() { return \"Vignette\"; }\r\n protected get textureCoordFromPosition() { return true; }\r\n\r\n protected get source() {\r\n return {\r\n vertex: `\r\n void effectMain(vec4 pos) {\r\n v_texCoord = textureCoordFromPosition(pos);\r\n }\r\n `,\r\n fragment: `\r\n float sdSquare(vec2 point, float width) {\r\n vec2 d = abs(point) - width;\r\n return min(max(d.x,d.y),0.0) + length(max(d,0.0));\r\n }\r\n\r\n float vignette(vec2 uv, vec2 size, float roundness, float smoothness) {\r\n // Center UVs\r\n uv -= 0.5;\r\n\r\n // Shift UVs based on the larger of width or height\r\n float minWidth = min(size.x, size.y);\r\n uv.x = sign(uv.x) * clamp(abs(uv.x) - abs(minWidth - size.x), 0.0, 1.0);\r\n uv.y = sign(uv.y) * clamp(abs(uv.y) - abs(minWidth - size.y), 0.0, 1.0);\r\n\r\n // Signed distance calculation\r\n float boxSize = minWidth * (1.0 - roundness);\r\n float dist = sdSquare(uv, boxSize) - (minWidth * roundness);\r\n\r\n return 1.0 - smoothstep(0.0, smoothness, dist);\r\n }\r\n\r\n vec4 effectMain() {\r\n return TEXTURE(u_diffuse, v_texCoord) * vignette(v_texCoord, u_size, u_roundness, u_smoothness);\r\n }\r\n `,\r\n };\r\n }\r\n\r\n protected defineEffect(builder: ScreenSpaceEffectBuilder): void {\r\n builder.addVarying(\"v_texCoord\", VaryingType.Vec2);\r\n builder.addUniform({\r\n name: \"u_size\",\r\n type: UniformType.Vec2,\r\n bind: (uniform) => uniform.setUniform2fv(VignetteConfig.size),\r\n });\r\n builder.addUniform({\r\n name: \"u_roundness\",\r\n type: UniformType.Float,\r\n bind: (uniform) => uniform.setUniform1f(VignetteConfig.roundness),\r\n });\r\n builder.addUniform({\r\n name: \"u_smoothness\",\r\n type: UniformType.Float,\r\n bind: (uniform) => uniform.setUniform1f(VignetteConfig.smoothness),\r\n });\r\n }\r\n}\r\n\r\n/** Configures the [[VignetteEffect]].\r\n * @beta\r\n */\r\nexport class VignetteConfig extends Tool {\r\n public static override toolId = \"VignetteConfig\";\r\n public static override get minArgs() { return 0; }\r\n public static override get maxArgs() { return 4; }\r\n\r\n /** Size of the vignette in the form (width/2, height/2). e.g., to make the vignette start fading in halfway between the center and edges of\r\n * UV space, use (0.25, 0.25).\r\n */\r\n public static readonly size = new Float32Array([0.25, 0.25]);\r\n\r\n /** How round the vignette will be, from 0.0 (perfectly rectangular) to 1.0 (perfectly round). */\r\n public static roundness = 1.0;\r\n\r\n /** How quickly the vignette fades in. The vignette starts fading in at the edge of the values provided by `size` and will be\r\n * fully faded in at (size.x + smoothness, size.y * smoothness). A value of 0.0 produces a hard edge.\r\n */\r\n public static smoothness = 0.5;\r\n\r\n public override async run(width?: number, height?: number, roundness?: number, smoothness?: number): Promise<boolean> {\r\n const config = VignetteConfig;\r\n config.size[0] = width ?? config.size[0];\r\n config.size[1] = height ?? config.size[1];\r\n config.roundness = roundness ?? config.roundness;\r\n config.smoothness = smoothness ?? config.smoothness;\r\n\r\n refreshViewportsForEffect(\"fdt Vignette\");\r\n return true;\r\n }\r\n\r\n public override async parseAndRun(...input: string[]): Promise<boolean> {\r\n const args = parseArgs(input);\r\n return this.run(args.getFloat(\"w\"), args.getFloat(\"h\"), args.getFloat(\"r\"), args.getFloat(\"s\"));\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FrustumDecoration.js","sourceRoot":"","sources":["../../../src/tools/FrustumDecoration.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAS,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAW,UAAU,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACrF,OAAO,EACL,WAAW,EAA8C,WAAW,EAAE,SAAS,EAAE,IAAI,GACtF,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAO5C;;;;;;GAMG;AACH,MAAM,iBAAiB;IAUrB,YAAoB,EAAY,EAAE,IA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AAO,CAAC,CAAC,CAAC,CAAC;IAC3C,MAAM,KAAc,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAElC,KAAK,CAAC,GAAG,CAAC,MAAgB;QACxC,MAAM,EAAE,GAAG,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC9C,IAAI,SAAS,KAAK,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,aAAa,EAAE;YAC7C,uBAAuB,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAE7C,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,WAAW,CAAC,GAAG,IAAc;QACjD,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,IAAI,OAAO,MAAM,KAAK,QAAQ;YAC5B,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAEzB,OAAO,IAAI,CAAC;IACd,CAAC;;AAlBsB,8BAAM,GAAG,qBAAqB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\n/** @packageDocumentation\n * @module Tools\n */\n\nimport { Map4d, Point3d } from \"@itwin/core-geometry\";\nimport { ColorByName, ColorDef, Frustum, LinePixels, Npc } from \"@itwin/core-common\";\nimport {\n CoordSystem, DecorateContext, Decorator, GraphicBuilder, GraphicType, IModelApp, Tool, Viewport, ViewState, ViewState3d,\n} from \"@itwin/core-frontend\";\nimport { parseToggle } from \"./parseToggle\";\n\ninterface FrustumDecorationOptions {\n showPreloadFrustum?: boolean;\n showBackgroundIntersections?: boolean;\n}\n\n/**\n * Decorates the viewport with a graphical depiction of a Frustum.\n * This is obviously only useful when drawn inside a viewport using a *different* Frustum.\n * Options for doing so include:\n * - Having more than one viewport, and drawing the frustum of one viewport inside the other viewports; and\n * - Allowing the user to take a snapshot of the current frustum, then navigate the view to inspect it within the same viewport.\n */\nclass FrustumDecoration {\n private readonly _worldFrustum: Frustum;\n private readonly _adjustedWorldFrustum: Frustum;\n private readonly _preloadFrustum: Frustum;\n private readonly _npcFrustum: Frustum;\n private readonly _worldToNpcMap: Map4d;\n private readonly _eyePoint: Point3d;\n private readonly _focalPlane: number;\n private readonly _isCameraOn: boolean;\n\n private constructor(vp: Viewport, view: ViewState3d, private readonly _options?: FrustumDecorationOptions) {\n this._worldFrustum = vp.getFrustum(CoordSystem.World, false);\n this._adjustedWorldFrustum = vp.getFrustum(CoordSystem.World, true);\n this._preloadFrustum = vp.viewingSpace.getPreloadFrustum();\n this._npcFrustum = vp.getFrustum(CoordSystem.Npc, true);\n this._worldToNpcMap = vp.viewingSpace.worldToNpcMap.clone();\n this._eyePoint = view.camera.getEyePoint().clone();\n this._focalPlane = vp.worldToNpc(view.getTargetPoint()).z;\n this._isCameraOn = vp.isCameraOn;\n }\n\n public static create(vp: Viewport, options?: FrustumDecorationOptions): FrustumDecoration | undefined {\n const view = vp.view.isSpatialView() ? vp.view : undefined;\n return undefined !== view ? new FrustumDecoration(vp, view, options) : undefined;\n }\n\n public decorate(context: DecorateContext): void {\n const builder = context.createGraphicBuilder(GraphicType.WorldDecoration);\n\n if (this._isCameraOn)\n FrustumDecoration.drawEyePositionAndFocalPlane(builder, this._npcFrustum, this._worldToNpcMap, this._eyePoint, this._focalPlane, context.viewport);\n\n FrustumDecoration.drawFrustumBox(builder, this._worldFrustum, false, context.viewport); // show original frustum...\n FrustumDecoration.drawFrustumBox(builder, this._adjustedWorldFrustum, true, context.viewport); // show adjusted frustum...\n const options = this._options;\n if (options !== undefined) {\n if (options.showPreloadFrustum)\n FrustumDecoration.drawPreloadFrustum(builder, this._preloadFrustum);\n\n if (options?.showBackgroundIntersections) {\n const backgroundMapGeometry = context.viewport.view.displayStyle.getBackgroundMapGeometry();\n if (backgroundMapGeometry)\n backgroundMapGeometry.addFrustumDecorations(builder, this._adjustedWorldFrustum);\n }\n }\n context.addDecorationFromBuilder(builder);\n }\n\n public static drawPreloadFrustum(builder: GraphicBuilder, frustum: Frustum) {\n const preloadColor = ColorDef.create(ColorByName.coral);\n builder.setSymbology(preloadColor, preloadColor, 1, 2);\n builder.addFrustum(frustum);\n }\n\n public static drawFrustumBox(builder: GraphicBuilder, frustum: Frustum, adjustedBox: boolean, vp: Viewport): void {\n const backPts = this.getPlanePts(frustum.points, false); // back plane\n const frontPts = this.getPlanePts(frustum.points, true); // front plane\n\n const bgColor = vp.view.backgroundColor;\n const backAndBottomColor = ColorDef.red.adjustedForContrast(bgColor);\n const frontAndTopLeftColor = ColorDef.blue.adjustedForContrast(bgColor);\n const frontAndTopRightColor = ColorDef.green.adjustedForContrast(bgColor);\n const edgeWeight = adjustedBox ? 2 : 1;\n const edgeStyle = adjustedBox ? LinePixels.Solid : LinePixels.Code2;\n\n // Back plane\n builder.setSymbology(backAndBottomColor, ColorDef.black, edgeWeight, edgeStyle);\n builder.addLineString(backPts);\n\n // Front plane\n builder.setSymbology(frontAndTopLeftColor, ColorDef.black, edgeWeight, edgeStyle);\n builder.addLineString(frontPts);\n\n // Bottom edge\n builder.setSymbology(backAndBottomColor, ColorDef.black, edgeWeight, edgeStyle);\n builder.addLineString(this.getEdgePts(backPts, frontPts, 0));\n builder.addLineString(this.getEdgePts(backPts, frontPts, 1));\n\n // Top edge\n builder.setSymbology(frontAndTopRightColor, ColorDef.black, edgeWeight, edgeStyle);\n builder.addLineString(this.getEdgePts(backPts, frontPts, 2));\n builder.setSymbology(frontAndTopLeftColor, ColorDef.black, edgeWeight, edgeStyle);\n builder.addLineString(this.getEdgePts(backPts, frontPts, 3));\n }\n\n private static getEdgePts(startPts: Point3d[], endPts: Point3d[], index: number): Point3d[] {\n return [\n startPts[index],\n endPts[index],\n ];\n }\n\n private static getPlanePts(frustPts: Point3d[], front: boolean): Point3d[] {\n const baseIndex = front ? Npc._001 : Npc._000;\n const planePts = [\n frustPts[baseIndex + Npc._000],\n frustPts[baseIndex + Npc._100],\n frustPts[baseIndex + Npc._110],\n frustPts[baseIndex + Npc._010],\n ];\n\n planePts.push(planePts[0]);\n return planePts;\n }\n\n public static drawEyePositionAndFocalPlane(builder: GraphicBuilder, npcFrustum: Frustum, worldToNpcMap: Map4d, eyePoint: Point3d, focusPlaneNpc: number, vp: Viewport): void {\n // Eye position...\n const contrastColor = vp.getContrastToBackgroundColor();\n builder.setSymbology(contrastColor, ColorDef.black, 8);\n builder.addPointString([eyePoint]);\n\n // Focal plane...\n const focalPtsNpc = FrustumDecoration.getPlanePts(npcFrustum.points, false);\n const focalPtsWorld: Point3d[] = [];\n for (const npcPt of focalPtsNpc)\n focalPtsWorld.push(Point3d.create(npcPt.x, npcPt.y, focusPlaneNpc));\n worldToNpcMap.transform1.multiplyPoint3dArrayQuietNormalize(focalPtsWorld);\n\n const bgColor = vp.view.backgroundColor;\n const focalPlaneColor = ColorDef.green.adjustedForContrast(bgColor);\n const focalTransColor = focalPlaneColor.withTransparency(100);\n builder.setSymbology(focalPlaneColor, focalTransColor, 2);\n builder.addLineString(focalPtsWorld);\n builder.addShape(focalPtsWorld);\n }\n}\n\n/**\n * Decorates the viewport with a graphical depiction of a Frustum.\n * This is obviously only useful when drawn inside a viewport using a *different* Frustum.\n * Options for doing so include:\n * - Having more than one viewport, and drawing the frustum of one viewport inside the other viewports; and\n * - Allowing the user to take a snapshot of the current frustum, then navigate the view to inspect it within the same viewport.\n * @beta\n */\nexport class FrustumDecorator implements Decorator {\n private readonly _decoration?: FrustumDecoration;\n\n private constructor(vp: Viewport, options?: FrustumDecorationOptions) {\n this._decoration = FrustumDecoration.create(vp, options);\n }\n\n /** This will allow the render system to cache and reuse the decorations created by this decorator's decorate() method. */\n public readonly useCachedDecorations = true;\n\n public decorate(context: DecorateContext): void {\n if (undefined !== this._decoration)\n this._decoration.decorate(context);\n }\n\n private static _instance?: FrustumDecorator;\n\n /** Add the decoration to the specified viewport. */\n public static enable(vp: Viewport, options?: FrustumDecorationOptions): void {\n FrustumDecorator.disable();\n FrustumDecorator._instance = new FrustumDecorator(vp, options);\n IModelApp.viewManager.addDecorator(FrustumDecorator._instance);\n }\n\n /** Remove the decoration from the specified viewport. */\n public static disable(): void {\n const instance = FrustumDecorator._instance;\n if (undefined !== instance) {\n IModelApp.viewManager.dropDecorator(instance);\n FrustumDecorator._instance = undefined;\n }\n }\n\n public static get isEnabled() { return undefined !== FrustumDecorator._instance; }\n}\n\n/** Enable (\"ON\"), disable (\"OFF\"), or toggle (\"TOGGLE\" or omitted) the [[FrustumDecorator]].\n * @beta\n */\nexport class ToggleFrustumSnapshotTool extends Tool {\n public static override toolId = \"ToggleFrustumSnapshot\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 2; }\n\n public override async run(enable?: boolean, showPreloadFrustum?: boolean, showBackgroundIntersections?: boolean): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined === vp)\n return true;\n\n if (undefined === enable)\n enable = !FrustumDecorator.isEnabled;\n\n if (enable !== FrustumDecorator.isEnabled) {\n if (enable) {\n FrustumDecorator.enable(vp, { showPreloadFrustum, showBackgroundIntersections });\n vp.onChangeView.addOnce(() => FrustumDecorator.disable());\n } else {\n FrustumDecorator.disable();\n }\n }\n\n return true;\n }\n\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n let showPreload, showBackgroundIntersections, enable;\n for (const arg of args) {\n if (arg === \"preload\")\n showPreload = true;\n else if (arg === \"background\")\n showBackgroundIntersections = true;\n else\n enable = parseToggle(arg);\n }\n\n if (typeof enable !== \"string\")\n await this.run(enable, showPreload, showBackgroundIntersections);\n\n return true;\n }\n}\n\n/**\n * Decorates the viewport with a graphical depiction of a Frustum from the currently selected viewport.\n * Only useful when more than one spatial viewport is open.\n */\nclass SelectedViewFrustumDecoration {\n private static _decorator?: SelectedViewFrustumDecoration;\n protected _targetVp: Viewport;\n protected _removeDecorationListener?: () => void;\n protected _removeViewChangedListener?: () => void;\n\n /** This will allow the render system to cache and reuse the decorations created by this decorator's decorate() method. */\n public readonly useCachedDecorations = true;\n\n public constructor(vp: Viewport, private _options?: FrustumDecorationOptions) {\n this._targetVp = vp;\n this._removeDecorationListener = IModelApp.viewManager.addDecorator(this);\n this._removeViewChangedListener = vp.onViewChanged.addListener(this.onViewChanged, this); // eslint-disable-line @typescript-eslint/unbound-method\n IModelApp.viewManager.invalidateCachedDecorationsAllViews(this);\n }\n\n protected stop(): void {\n if (this._removeDecorationListener) {\n this._removeDecorationListener();\n this._removeDecorationListener = undefined;\n }\n if (this._removeViewChangedListener) {\n this._removeViewChangedListener();\n this._removeViewChangedListener = undefined;\n }\n\n IModelApp.viewManager.invalidateCachedDecorationsAllViews(this);\n }\n\n public onViewChanged(targetVp: Viewport): void {\n if (targetVp !== this._targetVp)\n return;\n const decorator = SelectedViewFrustumDecoration._decorator;\n if (undefined !== decorator) {\n for (const vp of IModelApp.viewManager) {\n if (vp !== this._targetVp)\n vp.invalidateCachedDecorations(decorator);\n }\n }\n }\n\n public decorate(context: DecorateContext): void {\n const vp = context.viewport;\n if (!this._targetVp.view.isSpatialView() || vp === this._targetVp || !vp.view.isSpatialView())\n return;\n\n const builder = context.createGraphicBuilder(GraphicType.WorldDecoration);\n\n if (this._targetVp.isCameraOn) {\n const npcFrustum = this._targetVp.getFrustum(CoordSystem.Npc, true);\n const focalPlane = this._targetVp.worldToNpc(this._targetVp.view.getTargetPoint()).z;\n FrustumDecoration.drawEyePositionAndFocalPlane(builder, npcFrustum, this._targetVp.viewingSpace.worldToNpcMap, this._targetVp.view.camera.getEyePoint(), focalPlane, context.viewport);\n }\n\n const worldFrustum = this._targetVp.getFrustum(CoordSystem.World, false);\n const adjustedWorldFrustum = this._targetVp.getFrustum(CoordSystem.World, true);\n\n FrustumDecoration.drawFrustumBox(builder, worldFrustum, false, context.viewport); // show original frustum...\n FrustumDecoration.drawFrustumBox(builder, adjustedWorldFrustum, true, context.viewport); // show adjusted frustum...\n if (this._options && this._options.showPreloadFrustum)\n FrustumDecoration.drawPreloadFrustum(builder, context.viewport.viewingSpace.getPreloadFrustum());\n\n context.addDecorationFromBuilder(builder);\n }\n\n // Returns true if decoration becomes enabled.\n public static toggle(vp: Viewport, enabled?: boolean): boolean {\n if (undefined !== enabled) {\n const alreadyEnabled = undefined !== SelectedViewFrustumDecoration._decorator;\n if (enabled === alreadyEnabled)\n return alreadyEnabled;\n }\n\n if (undefined === SelectedViewFrustumDecoration._decorator) {\n SelectedViewFrustumDecoration._decorator = new SelectedViewFrustumDecoration(vp);\n return true;\n } else {\n SelectedViewFrustumDecoration._decorator.stop();\n SelectedViewFrustumDecoration._decorator = undefined;\n return false;\n }\n }\n}\n\n/** Enable (\"ON\"), disable (\"OFF\"), or toggle (\"TOGGLE\" or omitted) the selected view frustum decoration.\n * @beta\n */\nexport class ToggleSelectedViewFrustumTool extends Tool {\n public static override toolId = \"ToggleSelectedViewFrustum\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 1; }\n\n public override async run(enable?: boolean): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined === vp || !vp.view.isSpatialView())\n return false;\n if (SelectedViewFrustumDecoration.toggle(vp, enable)) {\n const remove = vp.onChangeView.addListener((_vp: Viewport, prev: ViewState) => {\n if (!prev.hasSameCoordinates(vp.view)) {\n SelectedViewFrustumDecoration.toggle(vp, false);\n remove();\n }\n });\n }\n\n return true;\n }\n\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const enable = parseToggle(args[0]);\n if (typeof enable !== \"string\")\n await this.run(enable);\n\n return true;\n }\n}\n\nclass ShadowFrustumDecoration {\n private static _instance?: ShadowFrustumDecoration;\n private _targetVp: Viewport;\n private _cleanup?: () => void;\n\n /** This will allow the render system to cache and reuse the decorations created by this decorator's decorate() method. */\n public readonly useCachedDecorations = true;\n\n public constructor(vp: Viewport) {\n this._targetVp = vp;\n const removeDecorator = IModelApp.viewManager.addDecorator(this);\n const removeOnRender = vp.onRender.addListener((_) => this.onRender());\n this._cleanup = () => { removeDecorator(); removeOnRender(); };\n IModelApp.viewManager.invalidateCachedDecorationsAllViews(this);\n }\n\n private stop(): void {\n if (undefined !== this._cleanup) {\n this._cleanup();\n this._cleanup = undefined;\n }\n\n IModelApp.viewManager.invalidateCachedDecorationsAllViews(this);\n }\n\n public onRender(): void {\n const decorator = ShadowFrustumDecoration._instance;\n if (undefined !== decorator) {\n for (const vp of IModelApp.viewManager) {\n if (vp !== this._targetVp)\n vp.invalidateCachedDecorations(decorator);\n }\n }\n }\n\n public decorate(context: DecorateContext): void {\n const frustum = this._targetVp.target.debugControl!.shadowFrustum;\n if (undefined === frustum)\n return;\n\n const thisVp = context.viewport;\n if (thisVp === this._targetVp || !thisVp.view.isSpatialView())\n return;\n\n const builder = context.createGraphicBuilder(GraphicType.WorldDecoration);\n FrustumDecoration.drawFrustumBox(builder, frustum, false, thisVp);\n context.addDecorationFromBuilder(builder);\n }\n\n public static toggle(vp: Viewport, enabled?: boolean): void {\n const instance = ShadowFrustumDecoration._instance;\n if (undefined !== enabled) {\n const alreadyEnabled = undefined !== instance;\n if (enabled === alreadyEnabled)\n return;\n }\n\n if (undefined === instance) {\n ShadowFrustumDecoration._instance = new ShadowFrustumDecoration(vp);\n } else {\n instance.stop();\n ShadowFrustumDecoration._instance = undefined;\n }\n }\n}\n\n/** Toggle visualization of the selected viewport's shadow frustum in all other viewports.\n * @beta\n */\nexport class ToggleShadowFrustumTool extends Tool {\n public static override toolId = \"ToggleShadowFrustum\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 1; }\n\n public override async run(enable?: boolean): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined !== vp && vp.view.isSpatialView())\n ShadowFrustumDecoration.toggle(vp, enable);\n\n return true;\n }\n\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const enable = parseToggle(args[0]);\n if (typeof enable !== \"string\")\n await this.run(enable);\n\n return true;\n }\n}\n"]}
|
|
1
|
+
{"version":3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AAC;QACnD,IAAI,SAAS,KAAK,OAAO,EAAE;YACzB,MAAM,cAAc,GAAG,SAAS,KAAK,QAAQ,CAAC;YAC9C,IAAI,OAAO,KAAK,cAAc;gBAC5B,OAAO;SACV;QAED,IAAI,SAAS,KAAK,QAAQ,EAAE;YAC1B,uBAAuB,CAAC,SAAS,GAAG,IAAI,uBAAuB,CAAC,EAAE,CAAC,CAAC;SACrE;aAAM;YACL,QAAQ,CAAC,IAAI,EAAE,CAAC;YAChB,uBAAuB,CAAC,SAAS,GAAG,SAAS,CAAC;SAC/C;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,IAAI;IAExC,MAAM,KAAc,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3C,MAAM,KAAc,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAElC,KAAK,CAAC,GAAG,CAAC,MAAgB;QACxC,MAAM,EAAE,GAAG,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC9C,IAAI,SAAS,KAAK,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,aAAa,EAAE;YAC7C,uBAAuB,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAE7C,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,WAAW,CAAC,GAAG,IAAc;QACjD,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,IAAI,OAAO,MAAM,KAAK,QAAQ;YAC5B,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAEzB,OAAO,IAAI,CAAC;IACd,CAAC;;AAlBsB,8BAAM,GAAG,qBAAqB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module Tools\r\n */\r\n\r\nimport { Map4d, Point3d } from \"@itwin/core-geometry\";\r\nimport { ColorByName, ColorDef, Frustum, LinePixels, Npc } from \"@itwin/core-common\";\r\nimport {\r\n CoordSystem, DecorateContext, Decorator, GraphicBuilder, GraphicType, IModelApp, Tool, Viewport, ViewState, ViewState3d,\r\n} from \"@itwin/core-frontend\";\r\nimport { parseToggle } from \"./parseToggle\";\r\n\r\ninterface FrustumDecorationOptions {\r\n showPreloadFrustum?: boolean;\r\n showBackgroundIntersections?: boolean;\r\n}\r\n\r\n/**\r\n * Decorates the viewport with a graphical depiction of a Frustum.\r\n * This is obviously only useful when drawn inside a viewport using a *different* Frustum.\r\n * Options for doing so include:\r\n * - Having more than one viewport, and drawing the frustum of one viewport inside the other viewports; and\r\n * - Allowing the user to take a snapshot of the current frustum, then navigate the view to inspect it within the same viewport.\r\n */\r\nclass FrustumDecoration {\r\n private readonly _worldFrustum: Frustum;\r\n private readonly _adjustedWorldFrustum: Frustum;\r\n private readonly _preloadFrustum: Frustum;\r\n private readonly _npcFrustum: Frustum;\r\n private readonly _worldToNpcMap: Map4d;\r\n private readonly _eyePoint: Point3d;\r\n private readonly _focalPlane: number;\r\n private readonly _isCameraOn: boolean;\r\n\r\n private constructor(vp: Viewport, view: ViewState3d, private readonly _options?: FrustumDecorationOptions) {\r\n this._worldFrustum = vp.getFrustum(CoordSystem.World, false);\r\n this._adjustedWorldFrustum = vp.getFrustum(CoordSystem.World, true);\r\n this._preloadFrustum = vp.viewingSpace.getPreloadFrustum();\r\n this._npcFrustum = vp.getFrustum(CoordSystem.Npc, true);\r\n this._worldToNpcMap = vp.viewingSpace.worldToNpcMap.clone();\r\n this._eyePoint = view.camera.getEyePoint().clone();\r\n this._focalPlane = vp.worldToNpc(view.getTargetPoint()).z;\r\n this._isCameraOn = vp.isCameraOn;\r\n }\r\n\r\n public static create(vp: Viewport, options?: FrustumDecorationOptions): FrustumDecoration | undefined {\r\n const view = vp.view.isSpatialView() ? vp.view : undefined;\r\n return undefined !== view ? new FrustumDecoration(vp, view, options) : undefined;\r\n }\r\n\r\n public decorate(context: DecorateContext): void {\r\n const builder = context.createGraphicBuilder(GraphicType.WorldDecoration);\r\n\r\n if (this._isCameraOn)\r\n FrustumDecoration.drawEyePositionAndFocalPlane(builder, this._npcFrustum, this._worldToNpcMap, this._eyePoint, this._focalPlane, context.viewport);\r\n\r\n FrustumDecoration.drawFrustumBox(builder, this._worldFrustum, false, context.viewport); // show original frustum...\r\n FrustumDecoration.drawFrustumBox(builder, this._adjustedWorldFrustum, true, context.viewport); // show adjusted frustum...\r\n const options = this._options;\r\n if (options !== undefined) {\r\n if (options.showPreloadFrustum)\r\n FrustumDecoration.drawPreloadFrustum(builder, this._preloadFrustum);\r\n\r\n if (options?.showBackgroundIntersections) {\r\n const backgroundMapGeometry = context.viewport.view.displayStyle.getBackgroundMapGeometry();\r\n if (backgroundMapGeometry)\r\n backgroundMapGeometry.addFrustumDecorations(builder, this._adjustedWorldFrustum);\r\n }\r\n }\r\n context.addDecorationFromBuilder(builder);\r\n }\r\n\r\n public static drawPreloadFrustum(builder: GraphicBuilder, frustum: Frustum) {\r\n const preloadColor = ColorDef.create(ColorByName.coral);\r\n builder.setSymbology(preloadColor, preloadColor, 1, 2);\r\n builder.addFrustum(frustum);\r\n }\r\n\r\n public static drawFrustumBox(builder: GraphicBuilder, frustum: Frustum, adjustedBox: boolean, vp: Viewport): void {\r\n const backPts = this.getPlanePts(frustum.points, false); // back plane\r\n const frontPts = this.getPlanePts(frustum.points, true); // front plane\r\n\r\n const bgColor = vp.view.backgroundColor;\r\n const backAndBottomColor = ColorDef.red.adjustedForContrast(bgColor);\r\n const frontAndTopLeftColor = ColorDef.blue.adjustedForContrast(bgColor);\r\n const frontAndTopRightColor = ColorDef.green.adjustedForContrast(bgColor);\r\n const edgeWeight = adjustedBox ? 2 : 1;\r\n const edgeStyle = adjustedBox ? LinePixels.Solid : LinePixels.Code2;\r\n\r\n // Back plane\r\n builder.setSymbology(backAndBottomColor, ColorDef.black, edgeWeight, edgeStyle);\r\n builder.addLineString(backPts);\r\n\r\n // Front plane\r\n builder.setSymbology(frontAndTopLeftColor, ColorDef.black, edgeWeight, edgeStyle);\r\n builder.addLineString(frontPts);\r\n\r\n // Bottom edge\r\n builder.setSymbology(backAndBottomColor, ColorDef.black, edgeWeight, edgeStyle);\r\n builder.addLineString(this.getEdgePts(backPts, frontPts, 0));\r\n builder.addLineString(this.getEdgePts(backPts, frontPts, 1));\r\n\r\n // Top edge\r\n builder.setSymbology(frontAndTopRightColor, ColorDef.black, edgeWeight, edgeStyle);\r\n builder.addLineString(this.getEdgePts(backPts, frontPts, 2));\r\n builder.setSymbology(frontAndTopLeftColor, ColorDef.black, edgeWeight, edgeStyle);\r\n builder.addLineString(this.getEdgePts(backPts, frontPts, 3));\r\n }\r\n\r\n private static getEdgePts(startPts: Point3d[], endPts: Point3d[], index: number): Point3d[] {\r\n return [\r\n startPts[index],\r\n endPts[index],\r\n ];\r\n }\r\n\r\n private static getPlanePts(frustPts: Point3d[], front: boolean): Point3d[] {\r\n const baseIndex = front ? Npc._001 : Npc._000;\r\n const planePts = [\r\n frustPts[baseIndex + Npc._000],\r\n frustPts[baseIndex + Npc._100],\r\n frustPts[baseIndex + Npc._110],\r\n frustPts[baseIndex + Npc._010],\r\n ];\r\n\r\n planePts.push(planePts[0]);\r\n return planePts;\r\n }\r\n\r\n public static drawEyePositionAndFocalPlane(builder: GraphicBuilder, npcFrustum: Frustum, worldToNpcMap: Map4d, eyePoint: Point3d, focusPlaneNpc: number, vp: Viewport): void {\r\n // Eye position...\r\n const contrastColor = vp.getContrastToBackgroundColor();\r\n builder.setSymbology(contrastColor, ColorDef.black, 8);\r\n builder.addPointString([eyePoint]);\r\n\r\n // Focal plane...\r\n const focalPtsNpc = FrustumDecoration.getPlanePts(npcFrustum.points, false);\r\n const focalPtsWorld: Point3d[] = [];\r\n for (const npcPt of focalPtsNpc)\r\n focalPtsWorld.push(Point3d.create(npcPt.x, npcPt.y, focusPlaneNpc));\r\n worldToNpcMap.transform1.multiplyPoint3dArrayQuietNormalize(focalPtsWorld);\r\n\r\n const bgColor = vp.view.backgroundColor;\r\n const focalPlaneColor = ColorDef.green.adjustedForContrast(bgColor);\r\n const focalTransColor = focalPlaneColor.withTransparency(100);\r\n builder.setSymbology(focalPlaneColor, focalTransColor, 2);\r\n builder.addLineString(focalPtsWorld);\r\n builder.addShape(focalPtsWorld);\r\n }\r\n}\r\n\r\n/**\r\n * Decorates the viewport with a graphical depiction of a Frustum.\r\n * This is obviously only useful when drawn inside a viewport using a *different* Frustum.\r\n * Options for doing so include:\r\n * - Having more than one viewport, and drawing the frustum of one viewport inside the other viewports; and\r\n * - Allowing the user to take a snapshot of the current frustum, then navigate the view to inspect it within the same viewport.\r\n * @beta\r\n */\r\nexport class FrustumDecorator implements Decorator {\r\n private readonly _decoration?: FrustumDecoration;\r\n\r\n private constructor(vp: Viewport, options?: FrustumDecorationOptions) {\r\n this._decoration = FrustumDecoration.create(vp, options);\r\n }\r\n\r\n /** This will allow the render system to cache and reuse the decorations created by this decorator's decorate() method. */\r\n public readonly useCachedDecorations = true;\r\n\r\n public decorate(context: DecorateContext): void {\r\n if (undefined !== this._decoration)\r\n this._decoration.decorate(context);\r\n }\r\n\r\n private static _instance?: FrustumDecorator;\r\n\r\n /** Add the decoration to the specified viewport. */\r\n public static enable(vp: Viewport, options?: FrustumDecorationOptions): void {\r\n FrustumDecorator.disable();\r\n FrustumDecorator._instance = new FrustumDecorator(vp, options);\r\n IModelApp.viewManager.addDecorator(FrustumDecorator._instance);\r\n }\r\n\r\n /** Remove the decoration from the specified viewport. */\r\n public static disable(): void {\r\n const instance = FrustumDecorator._instance;\r\n if (undefined !== instance) {\r\n IModelApp.viewManager.dropDecorator(instance);\r\n FrustumDecorator._instance = undefined;\r\n }\r\n }\r\n\r\n public static get isEnabled() { return undefined !== FrustumDecorator._instance; }\r\n}\r\n\r\n/** Enable (\"ON\"), disable (\"OFF\"), or toggle (\"TOGGLE\" or omitted) the [[FrustumDecorator]].\r\n * @beta\r\n */\r\nexport class ToggleFrustumSnapshotTool extends Tool {\r\n public static override toolId = \"ToggleFrustumSnapshot\";\r\n public static override get minArgs() { return 0; }\r\n public static override get maxArgs() { return 2; }\r\n\r\n public override async run(enable?: boolean, showPreloadFrustum?: boolean, showBackgroundIntersections?: boolean): Promise<boolean> {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (undefined === vp)\r\n return true;\r\n\r\n if (undefined === enable)\r\n enable = !FrustumDecorator.isEnabled;\r\n\r\n if (enable !== FrustumDecorator.isEnabled) {\r\n if (enable) {\r\n FrustumDecorator.enable(vp, { showPreloadFrustum, showBackgroundIntersections });\r\n vp.onChangeView.addOnce(() => FrustumDecorator.disable());\r\n } else {\r\n FrustumDecorator.disable();\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n let showPreload, showBackgroundIntersections, enable;\r\n for (const arg of args) {\r\n if (arg === \"preload\")\r\n showPreload = true;\r\n else if (arg === \"background\")\r\n showBackgroundIntersections = true;\r\n else\r\n enable = parseToggle(arg);\r\n }\r\n\r\n if (typeof enable !== \"string\")\r\n await this.run(enable, showPreload, showBackgroundIntersections);\r\n\r\n return true;\r\n }\r\n}\r\n\r\n/**\r\n * Decorates the viewport with a graphical depiction of a Frustum from the currently selected viewport.\r\n * Only useful when more than one spatial viewport is open.\r\n */\r\nclass SelectedViewFrustumDecoration {\r\n private static _decorator?: SelectedViewFrustumDecoration;\r\n protected _targetVp: Viewport;\r\n protected _removeDecorationListener?: () => void;\r\n protected _removeViewChangedListener?: () => void;\r\n\r\n /** This will allow the render system to cache and reuse the decorations created by this decorator's decorate() method. */\r\n public readonly useCachedDecorations = true;\r\n\r\n public constructor(vp: Viewport, private _options?: FrustumDecorationOptions) {\r\n this._targetVp = vp;\r\n this._removeDecorationListener = IModelApp.viewManager.addDecorator(this);\r\n this._removeViewChangedListener = vp.onViewChanged.addListener(this.onViewChanged, this); // eslint-disable-line @typescript-eslint/unbound-method\r\n IModelApp.viewManager.invalidateCachedDecorationsAllViews(this);\r\n }\r\n\r\n protected stop(): void {\r\n if (this._removeDecorationListener) {\r\n this._removeDecorationListener();\r\n this._removeDecorationListener = undefined;\r\n }\r\n if (this._removeViewChangedListener) {\r\n this._removeViewChangedListener();\r\n this._removeViewChangedListener = undefined;\r\n }\r\n\r\n IModelApp.viewManager.invalidateCachedDecorationsAllViews(this);\r\n }\r\n\r\n public onViewChanged(targetVp: Viewport): void {\r\n if (targetVp !== this._targetVp)\r\n return;\r\n const decorator = SelectedViewFrustumDecoration._decorator;\r\n if (undefined !== decorator) {\r\n for (const vp of IModelApp.viewManager) {\r\n if (vp !== this._targetVp)\r\n vp.invalidateCachedDecorations(decorator);\r\n }\r\n }\r\n }\r\n\r\n public decorate(context: DecorateContext): void {\r\n const vp = context.viewport;\r\n if (!this._targetVp.view.isSpatialView() || vp === this._targetVp || !vp.view.isSpatialView())\r\n return;\r\n\r\n const builder = context.createGraphicBuilder(GraphicType.WorldDecoration);\r\n\r\n if (this._targetVp.isCameraOn) {\r\n const npcFrustum = this._targetVp.getFrustum(CoordSystem.Npc, true);\r\n const focalPlane = this._targetVp.worldToNpc(this._targetVp.view.getTargetPoint()).z;\r\n FrustumDecoration.drawEyePositionAndFocalPlane(builder, npcFrustum, this._targetVp.viewingSpace.worldToNpcMap, this._targetVp.view.camera.getEyePoint(), focalPlane, context.viewport);\r\n }\r\n\r\n const worldFrustum = this._targetVp.getFrustum(CoordSystem.World, false);\r\n const adjustedWorldFrustum = this._targetVp.getFrustum(CoordSystem.World, true);\r\n\r\n FrustumDecoration.drawFrustumBox(builder, worldFrustum, false, context.viewport); // show original frustum...\r\n FrustumDecoration.drawFrustumBox(builder, adjustedWorldFrustum, true, context.viewport); // show adjusted frustum...\r\n if (this._options && this._options.showPreloadFrustum)\r\n FrustumDecoration.drawPreloadFrustum(builder, context.viewport.viewingSpace.getPreloadFrustum());\r\n\r\n context.addDecorationFromBuilder(builder);\r\n }\r\n\r\n // Returns true if decoration becomes enabled.\r\n public static toggle(vp: Viewport, enabled?: boolean): boolean {\r\n if (undefined !== enabled) {\r\n const alreadyEnabled = undefined !== SelectedViewFrustumDecoration._decorator;\r\n if (enabled === alreadyEnabled)\r\n return alreadyEnabled;\r\n }\r\n\r\n if (undefined === SelectedViewFrustumDecoration._decorator) {\r\n SelectedViewFrustumDecoration._decorator = new SelectedViewFrustumDecoration(vp);\r\n return true;\r\n } else {\r\n SelectedViewFrustumDecoration._decorator.stop();\r\n SelectedViewFrustumDecoration._decorator = undefined;\r\n return false;\r\n }\r\n }\r\n}\r\n\r\n/** Enable (\"ON\"), disable (\"OFF\"), or toggle (\"TOGGLE\" or omitted) the selected view frustum decoration.\r\n * @beta\r\n */\r\nexport class ToggleSelectedViewFrustumTool extends Tool {\r\n public static override toolId = \"ToggleSelectedViewFrustum\";\r\n public static override get minArgs() { return 0; }\r\n public static override get maxArgs() { return 1; }\r\n\r\n public override async run(enable?: boolean): Promise<boolean> {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (undefined === vp || !vp.view.isSpatialView())\r\n return false;\r\n if (SelectedViewFrustumDecoration.toggle(vp, enable)) {\r\n const remove = vp.onChangeView.addListener((_vp: Viewport, prev: ViewState) => {\r\n if (!prev.hasSameCoordinates(vp.view)) {\r\n SelectedViewFrustumDecoration.toggle(vp, false);\r\n remove();\r\n }\r\n });\r\n }\r\n\r\n return true;\r\n }\r\n\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n const enable = parseToggle(args[0]);\r\n if (typeof enable !== \"string\")\r\n await this.run(enable);\r\n\r\n return true;\r\n }\r\n}\r\n\r\nclass ShadowFrustumDecoration {\r\n private static _instance?: ShadowFrustumDecoration;\r\n private _targetVp: Viewport;\r\n private _cleanup?: () => void;\r\n\r\n /** This will allow the render system to cache and reuse the decorations created by this decorator's decorate() method. */\r\n public readonly useCachedDecorations = true;\r\n\r\n public constructor(vp: Viewport) {\r\n this._targetVp = vp;\r\n const removeDecorator = IModelApp.viewManager.addDecorator(this);\r\n const removeOnRender = vp.onRender.addListener((_) => this.onRender());\r\n this._cleanup = () => { removeDecorator(); removeOnRender(); };\r\n IModelApp.viewManager.invalidateCachedDecorationsAllViews(this);\r\n }\r\n\r\n private stop(): void {\r\n if (undefined !== this._cleanup) {\r\n this._cleanup();\r\n this._cleanup = undefined;\r\n }\r\n\r\n IModelApp.viewManager.invalidateCachedDecorationsAllViews(this);\r\n }\r\n\r\n public onRender(): void {\r\n const decorator = ShadowFrustumDecoration._instance;\r\n if (undefined !== decorator) {\r\n for (const vp of IModelApp.viewManager) {\r\n if (vp !== this._targetVp)\r\n vp.invalidateCachedDecorations(decorator);\r\n }\r\n }\r\n }\r\n\r\n public decorate(context: DecorateContext): void {\r\n const frustum = this._targetVp.target.debugControl!.shadowFrustum;\r\n if (undefined === frustum)\r\n return;\r\n\r\n const thisVp = context.viewport;\r\n if (thisVp === this._targetVp || !thisVp.view.isSpatialView())\r\n return;\r\n\r\n const builder = context.createGraphicBuilder(GraphicType.WorldDecoration);\r\n FrustumDecoration.drawFrustumBox(builder, frustum, false, thisVp);\r\n context.addDecorationFromBuilder(builder);\r\n }\r\n\r\n public static toggle(vp: Viewport, enabled?: boolean): void {\r\n const instance = ShadowFrustumDecoration._instance;\r\n if (undefined !== enabled) {\r\n const alreadyEnabled = undefined !== instance;\r\n if (enabled === alreadyEnabled)\r\n return;\r\n }\r\n\r\n if (undefined === instance) {\r\n ShadowFrustumDecoration._instance = new ShadowFrustumDecoration(vp);\r\n } else {\r\n instance.stop();\r\n ShadowFrustumDecoration._instance = undefined;\r\n }\r\n }\r\n}\r\n\r\n/** Toggle visualization of the selected viewport's shadow frustum in all other viewports.\r\n * @beta\r\n */\r\nexport class ToggleShadowFrustumTool extends Tool {\r\n public static override toolId = \"ToggleShadowFrustum\";\r\n public static override get minArgs() { return 0; }\r\n public static override get maxArgs() { return 1; }\r\n\r\n public override async run(enable?: boolean): Promise<boolean> {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (undefined !== vp && vp.view.isSpatialView())\r\n ShadowFrustumDecoration.toggle(vp, enable);\r\n\r\n return true;\r\n }\r\n\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n const enable = parseToggle(args[0]);\r\n if (typeof enable !== \"string\")\r\n await this.run(enable);\r\n\r\n return true;\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InspectElementTool.js","sourceRoot":"","sources":["../../../src/tools/InspectElementTool.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,IAAI,EAAyB,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAA0B,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC9G,OAAO,EACU,SAAS,EAAE,YAAY,EAAa,SAAS,EAAE,kBAAkB,EAAE,cAAc,EAAE,kBAAkB,EAAE,cAAc,EACpI,oBAAoB,EAAE,qBAAqB,EAAE,aAAa,GAC3D,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,kBAAmB,SAAQ,aAAa;IAWnD,YAAY,OAAgC,EAAE,UAAyB;QACrE,KAAK,EAAE,CAAC;QAPF,aAAQ,GAA2B,EAAE,CAAC;QAEtC,WAAM,GAAG,KAAK,CAAC;QACf,kBAAa,GAAG,KAAK,CAAC;QACtB,YAAO,GAAG,KAAK,CAAC;QAItB,IAAI,SAAS,KAAK,OAAO;YACvB,IAAI,CAAC,QAAQ,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;QAEjC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;I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M,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,SAAS,KAAK,KAAK;YACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QAEtB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,SAAS,KAAK,MAAM;YACtB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QAExB,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;IACpB,CAAC;;AA3LsB,yBAAM,GAAG,gBAAgB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\n/** @packageDocumentation\n * @module Tools\n */\n\nimport { BentleyError, Id64, Id64Array, Id64String } from \"@itwin/core-bentley\";\nimport { GeometrySummaryOptions, GeometrySummaryVerbosity, IModelReadRpcInterface } from \"@itwin/core-common\";\nimport {\n BeButtonEvent, CoreTools, EventHandled, HitDetail, IModelApp, LocateFilterStatus, LocateResponse, MessageBoxIconType, MessageBoxType,\n NotifyMessageDetails, OutputMessagePriority, PrimitiveTool,\n} from \"@itwin/core-frontend\";\nimport { copyStringToClipboard } from \"../ClipboardUtilities\";\nimport { parseArgs } from \"./parseArgs\";\n\n/** Creates a readable text summary of a geometric element or geometry part. The keyin takes the following arguments, all of which are optional:\n * - `id=elementId,elementId,elementId` comma-separated list of element Ids where each `elementId` is a hexadecimal element Id such as \"0x12cb\";\n * - `symbology=0|1` where 1 indicates detailed symbology information should be included in the output;\n * - `placement=0|1` where 1 indicates detailed geometric element placement should be included; and\n * - `verbosity=0|1|2` controlling the verbosity of the output for each geometric primitive in the geometry stream. Higher values = more detailed information. Note verbosity=2 can produce megabytes of data for certain types of geometric primitives like large meshes.\n * - `modal=0|1` where 1 indicates the output should appear in a modal dialog.\n * - `copy=0|1` where 1 indicates the output should be copied to the clipboard. Defaults to true.\n * - `refs=0|1` where 1 indicates that for geometry parts a list of all elements referencing that part should be included in the output. This is extremely computationally expensive.\n * If no id is specified, the tool runs in interactive mode: first operating upon the selection set (if any), then allowing the user to select additional elements.\n * @beta\n */\nexport class InspectElementTool extends PrimitiveTool {\n public static override toolId = \"InspectElement\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 6; }\n\n private _options: GeometrySummaryOptions = {};\n private _elementIds?: Id64String[];\n private _modal = false;\n private _useSelection = false;\n private _doCopy = false;\n\n constructor(options?: GeometrySummaryOptions, elementIds?: Id64String[]) {\n super();\n if (undefined !== options)\n this._options = { ...options };\n\n this._elementIds = elementIds;\n }\n\n private setupAndPromptForNextAction(): void {\n this._useSelection = (undefined !== this.targetView && this.targetView.iModel.selectionSet.isActive);\n if (!this._useSelection)\n IModelApp.accuSnap.enableLocate(true);\n\n this.showPrompt();\n }\n\n private showPrompt(): void {\n CoreTools.outputPromptByKey(this._useSelection ? \"ElementSet.Prompts.ConfirmSelection\" : \"ElementSet.Prompts.IdentifyElement\");\n }\n\n public override autoLockTarget(): void { }\n\n public override requireWriteableTarget(): boolean { return false; }\n\n public override async onUnsuspend() {\n this.showPrompt();\n }\n\n public override async onPostInstall() {\n await super.onPostInstall();\n\n if (undefined !== this._elementIds)\n this.process(this._elementIds).then(async () => {\n await this.onReinitialize();\n }).catch((err) => {\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, err.toString()));\n });\n else {\n this.setupAndPromptForNextAction();\n }\n }\n\n public override async onDataButtonDown(ev: BeButtonEvent): Promise<EventHandled> {\n if (this._useSelection) {\n if (undefined !== ev.viewport) {\n const ids: Id64Array = [];\n ev.viewport.iModel.selectionSet.elements.forEach((id) => {\n if (!Id64.isInvalid(id) && !Id64.isTransient(id))\n ids.push(id);\n });\n\n if (0 === ids.length)\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, CoreTools.translate(\"ElementSet.Error.NotSupportedElmType\")));\n else\n await this.process(ids);\n\n await this.onReinitialize();\n return EventHandled.Yes;\n }\n }\n\n const hit = await IModelApp.locateManager.doLocate(new LocateResponse(), true, ev.point, ev.viewport, ev.inputSource);\n if (undefined === hit || !hit.isElementHit)\n return EventHandled.No;\n\n await this.process([hit.sourceId]);\n this.setupAndPromptForNextAction();\n return EventHandled.No;\n }\n\n public override async onResetButtonUp(_ev: BeButtonEvent): Promise<EventHandled> {\n await this.onReinitialize();\n return EventHandled.No;\n }\n\n public override async onReinitialize() {\n if (this._useSelection || undefined !== this._elementIds) {\n await this.exitTool();\n } else {\n await this.onRestartTool();\n }\n }\n\n public async onRestartTool() {\n const tool = new InspectElementTool();\n if (!await tool.run())\n return this.exitTool();\n }\n\n public override async filterHit(hit: HitDetail, _out: LocateResponse): Promise<LocateFilterStatus> {\n return hit.isElementHit ? LocateFilterStatus.Accept : LocateFilterStatus.Reject;\n }\n\n private async process(elementIds: Id64String[]) {\n const request = {\n elementIds,\n options: this._options,\n };\n let messageDetails: NotifyMessageDetails;\n try {\n const str = await IModelReadRpcInterface.getClientForRouting(this.iModel.routingContext.token).getGeometrySummary(this.iModel.getRpcProps(), request);\n if (this._doCopy)\n copyStringToClipboard(str);\n\n const brief = `Summary ${this._doCopy ? \"copied to clipboard.\" : \"complete.\"}`;\n messageDetails = new NotifyMessageDetails(OutputMessagePriority.Info, brief, str);\n\n if (this._modal) {\n const div = document.createElement(\"div\");\n const appendText = (toAppend: string) => {\n const txt = document.createElement(\"div\");\n txt.innerText = toAppend;\n div.append(txt);\n };\n\n const lines = str.split(\"\\n\");\n const maxLines = 30;\n let curLine = 0;\n for (const line of lines) {\n appendText(line);\n if (++curLine > maxLines) {\n appendText(\"...\");\n break;\n }\n }\n\n await IModelApp.notifications.openMessageBox(MessageBoxType.Ok, div, MessageBoxIconType.Information);\n }\n } catch (err) {\n messageDetails = new NotifyMessageDetails(OutputMessagePriority.Error, \"Error occurred while generating summary\", BentleyError.getErrorMessage(err));\n }\n\n IModelApp.notifications.outputMessage(messageDetails);\n }\n\n public override async parseAndRun(...inputArgs: string[]): Promise<boolean> {\n const args = parseArgs(inputArgs);\n const ids = args.get(\"i\");\n if (undefined !== ids)\n this._elementIds = ids.split(\",\");\n\n const verbosity = args.getInteger(\"v\");\n if (undefined !== verbosity) {\n switch (verbosity) {\n case 0:\n this._options.geometryVerbosity = GeometrySummaryVerbosity.Basic;\n break;\n case 1:\n this._options.geometryVerbosity = GeometrySummaryVerbosity.Detailed;\n break;\n case 2:\n this._options.geometryVerbosity = GeometrySummaryVerbosity.Full;\n break;\n }\n }\n\n const symbology = args.getBoolean(\"s\");\n if (undefined !== symbology)\n this._options.verboseSymbology = symbology;\n\n const placement = args.getBoolean(\"p\");\n if (undefined !== placement)\n this._options.includePlacement = placement;\n\n const parts = args.getBoolean(\"r\");\n if (true === parts && undefined !== IModelApp.viewManager.selectedView)\n this._options.includePartReferences = IModelApp.viewManager.selectedView.view.is3d() ? \"3d\" : \"2d\";\n\n const modal = args.getBoolean(\"m\");\n if (undefined !== modal)\n this._modal = modal;\n\n const doCopy = args.getBoolean(\"c\");\n if (undefined !== doCopy)\n this._doCopy = doCopy;\n\n return this.run();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"InspectElementTool.js","sourceRoot":"","sources":["../../../src/tools/InspectElementTool.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,IAAI,EAAyB,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAA0B,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC9G,OAAO,EACU,SAAS,EAAE,YAAY,EAAa,SAAS,EAAE,kBAAkB,EAAE,cAAc,EAAE,kBAAkB,EAAE,cAAc,EACpI,oBAAoB,EAAE,qBAAqB,EAAE,aAAa,GAC3D,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC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AC,UAAU,CAAC,GAAG,CAAC,CAAC;QACvC,IAAI,SAAS,KAAK,SAAS;YACzB,IAAI,CAAC,QAAQ,CAAC,gBAAgB,GAAG,SAAS,CAAC;QAE7C,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,IAAI,KAAK,KAAK,IAAI,SAAS,KAAK,SAAS,CAAC,WAAW,CAAC,YAAY;YACpE,IAAI,CAAC,QAAQ,CAAC,qBAAqB,GAAG,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QAErG,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,SAAS,KAAK,KAAK;YACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QAEtB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,SAAS,KAAK,MAAM;YACtB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QAExB,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;IACpB,CAAC;;AA3LsB,yBAAM,GAAG,gBAAgB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module Tools\r\n */\r\n\r\nimport { BentleyError, Id64, Id64Array, Id64String } from \"@itwin/core-bentley\";\r\nimport { GeometrySummaryOptions, GeometrySummaryVerbosity, IModelReadRpcInterface } from \"@itwin/core-common\";\r\nimport {\r\n BeButtonEvent, CoreTools, EventHandled, HitDetail, IModelApp, LocateFilterStatus, LocateResponse, MessageBoxIconType, MessageBoxType,\r\n NotifyMessageDetails, OutputMessagePriority, PrimitiveTool,\r\n} from \"@itwin/core-frontend\";\r\nimport { copyStringToClipboard } from \"../ClipboardUtilities\";\r\nimport { parseArgs } from \"./parseArgs\";\r\n\r\n/** Creates a readable text summary of a geometric element or geometry part. The keyin takes the following arguments, all of which are optional:\r\n * - `id=elementId,elementId,elementId` comma-separated list of element Ids where each `elementId` is a hexadecimal element Id such as \"0x12cb\";\r\n * - `symbology=0|1` where 1 indicates detailed symbology information should be included in the output;\r\n * - `placement=0|1` where 1 indicates detailed geometric element placement should be included; and\r\n * - `verbosity=0|1|2` controlling the verbosity of the output for each geometric primitive in the geometry stream. Higher values = more detailed information. Note verbosity=2 can produce megabytes of data for certain types of geometric primitives like large meshes.\r\n * - `modal=0|1` where 1 indicates the output should appear in a modal dialog.\r\n * - `copy=0|1` where 1 indicates the output should be copied to the clipboard. Defaults to true.\r\n * - `refs=0|1` where 1 indicates that for geometry parts a list of all elements referencing that part should be included in the output. This is extremely computationally expensive.\r\n * If no id is specified, the tool runs in interactive mode: first operating upon the selection set (if any), then allowing the user to select additional elements.\r\n * @beta\r\n */\r\nexport class InspectElementTool extends PrimitiveTool {\r\n public static override toolId = \"InspectElement\";\r\n public static override get minArgs() { return 0; }\r\n public static override get maxArgs() { return 6; }\r\n\r\n private _options: GeometrySummaryOptions = {};\r\n private _elementIds?: Id64String[];\r\n private _modal = false;\r\n private _useSelection = false;\r\n private _doCopy = false;\r\n\r\n constructor(options?: GeometrySummaryOptions, elementIds?: Id64String[]) {\r\n super();\r\n if (undefined !== options)\r\n this._options = { ...options };\r\n\r\n this._elementIds = elementIds;\r\n }\r\n\r\n private setupAndPromptForNextAction(): void {\r\n this._useSelection = (undefined !== this.targetView && this.targetView.iModel.selectionSet.isActive);\r\n if (!this._useSelection)\r\n IModelApp.accuSnap.enableLocate(true);\r\n\r\n this.showPrompt();\r\n }\r\n\r\n private showPrompt(): void {\r\n CoreTools.outputPromptByKey(this._useSelection ? \"ElementSet.Prompts.ConfirmSelection\" : \"ElementSet.Prompts.IdentifyElement\");\r\n }\r\n\r\n public override autoLockTarget(): void { }\r\n\r\n public override requireWriteableTarget(): boolean { return false; }\r\n\r\n public override async onUnsuspend() {\r\n this.showPrompt();\r\n }\r\n\r\n public override async onPostInstall() {\r\n await super.onPostInstall();\r\n\r\n if (undefined !== this._elementIds)\r\n this.process(this._elementIds).then(async () => {\r\n await this.onReinitialize();\r\n }).catch((err) => {\r\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, err.toString()));\r\n });\r\n else {\r\n this.setupAndPromptForNextAction();\r\n }\r\n }\r\n\r\n public override async onDataButtonDown(ev: BeButtonEvent): Promise<EventHandled> {\r\n if (this._useSelection) {\r\n if (undefined !== ev.viewport) {\r\n const ids: Id64Array = [];\r\n ev.viewport.iModel.selectionSet.elements.forEach((id) => {\r\n if (!Id64.isInvalid(id) && !Id64.isTransient(id))\r\n ids.push(id);\r\n });\r\n\r\n if (0 === ids.length)\r\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, CoreTools.translate(\"ElementSet.Error.NotSupportedElmType\")));\r\n else\r\n await this.process(ids);\r\n\r\n await this.onReinitialize();\r\n return EventHandled.Yes;\r\n }\r\n }\r\n\r\n const hit = await IModelApp.locateManager.doLocate(new LocateResponse(), true, ev.point, ev.viewport, ev.inputSource);\r\n if (undefined === hit || !hit.isElementHit)\r\n return EventHandled.No;\r\n\r\n await this.process([hit.sourceId]);\r\n this.setupAndPromptForNextAction();\r\n return EventHandled.No;\r\n }\r\n\r\n public override async onResetButtonUp(_ev: BeButtonEvent): Promise<EventHandled> {\r\n await this.onReinitialize();\r\n return EventHandled.No;\r\n }\r\n\r\n public override async onReinitialize() {\r\n if (this._useSelection || undefined !== this._elementIds) {\r\n await this.exitTool();\r\n } else {\r\n await this.onRestartTool();\r\n }\r\n }\r\n\r\n public async onRestartTool() {\r\n const tool = new InspectElementTool();\r\n if (!await tool.run())\r\n return this.exitTool();\r\n }\r\n\r\n public override async filterHit(hit: HitDetail, _out: LocateResponse): Promise<LocateFilterStatus> {\r\n return hit.isElementHit ? LocateFilterStatus.Accept : LocateFilterStatus.Reject;\r\n }\r\n\r\n private async process(elementIds: Id64String[]) {\r\n const request = {\r\n elementIds,\r\n options: this._options,\r\n };\r\n let messageDetails: NotifyMessageDetails;\r\n try {\r\n const str = await IModelReadRpcInterface.getClientForRouting(this.iModel.routingContext.token).getGeometrySummary(this.iModel.getRpcProps(), request);\r\n if (this._doCopy)\r\n copyStringToClipboard(str);\r\n\r\n const brief = `Summary ${this._doCopy ? \"copied to clipboard.\" : \"complete.\"}`;\r\n messageDetails = new NotifyMessageDetails(OutputMessagePriority.Info, brief, str);\r\n\r\n if (this._modal) {\r\n const div = document.createElement(\"div\");\r\n const appendText = (toAppend: string) => {\r\n const txt = document.createElement(\"div\");\r\n txt.innerText = toAppend;\r\n div.append(txt);\r\n };\r\n\r\n const lines = str.split(\"\\n\");\r\n const maxLines = 30;\r\n let curLine = 0;\r\n for (const line of lines) {\r\n appendText(line);\r\n if (++curLine > maxLines) {\r\n appendText(\"...\");\r\n break;\r\n }\r\n }\r\n\r\n await IModelApp.notifications.openMessageBox(MessageBoxType.Ok, div, MessageBoxIconType.Information);\r\n }\r\n } catch (err) {\r\n messageDetails = new NotifyMessageDetails(OutputMessagePriority.Error, \"Error occurred while generating summary\", BentleyError.getErrorMessage(err));\r\n }\r\n\r\n IModelApp.notifications.outputMessage(messageDetails);\r\n }\r\n\r\n public override async parseAndRun(...inputArgs: string[]): Promise<boolean> {\r\n const args = parseArgs(inputArgs);\r\n const ids = args.get(\"i\");\r\n if (undefined !== ids)\r\n this._elementIds = ids.split(\",\");\r\n\r\n const verbosity = args.getInteger(\"v\");\r\n if (undefined !== verbosity) {\r\n switch (verbosity) {\r\n case 0:\r\n this._options.geometryVerbosity = GeometrySummaryVerbosity.Basic;\r\n break;\r\n case 1:\r\n this._options.geometryVerbosity = GeometrySummaryVerbosity.Detailed;\r\n break;\r\n case 2:\r\n this._options.geometryVerbosity = GeometrySummaryVerbosity.Full;\r\n break;\r\n }\r\n }\r\n\r\n const symbology = args.getBoolean(\"s\");\r\n if (undefined !== symbology)\r\n this._options.verboseSymbology = symbology;\r\n\r\n const placement = args.getBoolean(\"p\");\r\n if (undefined !== placement)\r\n this._options.includePlacement = placement;\r\n\r\n const parts = args.getBoolean(\"r\");\r\n if (true === parts && undefined !== IModelApp.viewManager.selectedView)\r\n this._options.includePartReferences = IModelApp.viewManager.selectedView.view.is3d() ? \"3d\" : \"2d\";\r\n\r\n const modal = args.getBoolean(\"m\");\r\n if (undefined !== modal)\r\n this._modal = modal;\r\n\r\n const doCopy = args.getBoolean(\"c\");\r\n if (undefined !== doCopy)\r\n this._doCopy = doCopy;\r\n\r\n return this.run();\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapLayerTool.js","sourceRoot":"","sources":["../../../src/tools/MapLayerTool.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,eAAe,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzK,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,+CAA+C;AAC/C,MAAM,sBAAuB,SAAQ,IAAI;IACvC,YAAsB,gBAAgB,IAAI,EAAY,UAAU,KAAK;QACnE,KAAK,EAAE,CAAC;QADY,kBAAa,GAAb,aAAa,CAAO;QAAY,YAAO,GAAP,OAAO,CAAQ;IAErE,CAAC;IAES,QAAQ,CAAC,MAAuB;QACxC,MAAM,EAAE,GAAG,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC9C,IAAI,EAAE,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Y,CAAC;QAC9C,IAAI,SAAS,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC,YAAY,CAAC,iBAAiB,YAAY,QAAQ;YACvG,OAAO,KAAK,CAAC;QAEf,EAAE,CAAC,YAAY,CAAC,iBAAiB,GAAG,EAAE,CAAC,YAAY,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QACzF,EAAE,CAAC,oBAAoB,EAAE,CAAC;QAE1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACa,KAAK,CAAC,WAAW,CAAC,GAAG,IAAc;QACjD,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAEtC,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC7D,CAAC;;AAzBsB,4BAAM,GAAG,0BAA0B,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\n/** @packageDocumentation\n * @module Tools\n */\n\nimport { BaseMapLayerSettings, ColorDef } from \"@itwin/core-common\";\nimport { IModelApp, MapLayerSource, MapLayerSources, MapLayerSourceStatus, NotifyMessageDetails, OutputMessagePriority, Tool, WmsUtilities } from \"@itwin/core-frontend\";\nimport { parseBoolean } from \"./parseBoolean\";\nimport { parseToggle } from \"./parseToggle\";\n\n/** Base class for attaching map layer tool. */\nclass AttachMapLayerBaseTool extends Tool {\n constructor(protected _isBackground = true, protected _isBase = false) {\n super();\n }\n\n protected doAttach(source?: MapLayerSource) {\n const vp = IModelApp.viewManager.selectedView;\n if (vp === undefined || source === undefined)\n return;\n\n source.validateSource().then((validation) => {\n if (validation.status === MapLayerSourceStatus.Valid || validation.status === MapLayerSourceStatus.RequireAuth) {\n if (this._isBase) {\n vp.displayStyle.backgroundMapBase = BaseMapLayerSettings.fromJSON({ ...source, subLayers: validation.subLayers });\n vp.invalidateRenderPlan();\n } else {\n const layerSettings = source.toLayerSettings(validation.subLayers);\n if (layerSettings) {\n vp.displayStyle.attachMapLayerSettings(layerSettings, !this._isBackground);\n }\n }\n\n if (validation.status === MapLayerSourceStatus.Valid) {\n vp.invalidateRenderPlan();\n const msg = IModelApp.localization.getLocalizedString(\"FrontendDevTools:tools.AttachMapLayerTool.Messages.MapLayerAttached\", { sourceName: source.name, sourceUrl: source.url });\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, msg));\n } else if (validation.status === MapLayerSourceStatus.RequireAuth) {\n const msg = IModelApp.localization.getLocalizedString(\"FrontendDevTools:tools.AttachMapLayerTool.Messages.MapLayerAttachedRequiresAuth\", { sourceName: source.name });\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Warning, msg));\n }\n\n } else {\n const msg = IModelApp.localization.getLocalizedString(\"FrontendDevTools:tools.AttachMapLayerTool.Messages.MapLayerValidationFailed\", { sourceUrl: source.url });\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));\n }\n }).catch((error) => {\n const msg = IModelApp.localization.getLocalizedString(\"FrontendDevTools:tools.AttachMapLayerTool.Messages.MapLayerAttachError\", { error, sourceUrl: source.url });\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));\n });\n }\n}\n/** Attach a map layer from URL base class. */\nclass AttachMapLayerByURLBaseTool extends AttachMapLayerBaseTool {\n public static override get minArgs() { return 1; }\n public static override get maxArgs() { return 4; }\n constructor(protected _formatId: string) { super(); }\n\n public override async run(url: string, name?: string, userName?: string, password?: string): Promise<boolean> {\n this.doAttach(MapLayerSource.fromJSON({ url, name: (name ? name : url), formatId: this._formatId, userName, password }));\n return true;\n }\n\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n return this.run(args[0], args[1], args[2], args[3]);\n }\n}\n\n/** This tool attaches a WMS map layer from a given URL.\n * @beta\n */\nexport class AttachWmsMapLayerByUrlTool extends AttachMapLayerByURLBaseTool {\n public static override toolId = \"AttachWmsMapLayerTool\";\n constructor() { super(\"WMS\"); }\n /** This method runs the tool, attaching a WMS map layer from a given URL.\n * @param args contains url, name, userName, password in array order\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n return this.run(WmsUtilities.getBaseUrl(args[0]), args[1], args[2], args[3]);\n }\n}\n\n/** This tool attaches a WMTS map layer from a given URL.\n * @beta\n */\nexport class AttachWmtsMapLayerByUrlTool extends AttachMapLayerByURLBaseTool {\n public static override toolId = \"AttachWmtsMapLayerTool\";\n constructor() { super(\"WMTS\"); }\n /** This method runs the tool, attaching a WMTS map layer from a given URL.\n * @param args contains url, name, userName, password in array order\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n return this.run(WmsUtilities.getBaseUrl(args[0]), args[1], args[2], args[3]);\n }\n}\n\n/** This tool attaches an ArcGIS map layer from a given URL.\n * @beta\n */\nexport class AttachArcGISMapLayerByUrlTool extends AttachMapLayerByURLBaseTool {\n public static override toolId = \"AttachArcGISMapLayerTool\";\n constructor() { super(\"ArcGIS\"); }\n}\n\n/** This tool attaches a map layer from a given tile URL.\n * @beta\n */\nexport class AttachTileURLMapLayerByUrlTool extends AttachMapLayerByURLBaseTool {\n public static override toolId = \"AttachTileURLMapLayerTool\";\n constructor() { super(\"TileURL\"); }\n}\n\n/** This tool add a Map Layer from a specified name (look up in MapLayerSources.json).\n * @beta\n */\nexport class AttachMapLayerTool extends AttachMapLayerBaseTool {\n public static override toolId = \"AttachMapLayerTool\";\n public static override get minArgs() { return 1; }\n public static override get maxArgs() { return 1; }\n\n /** This method runs the tool, adding a map layer from a specified name in MayLayerSources.json.\n * @param name the name of the map layer to add\n */\n public override async run(name: string): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (vp === undefined)\n return false;\n\n MapLayerSources.create().then((sources) => {\n if (sources !== undefined) {\n const source = sources.findByName(name, this._isBase);\n if (source !== undefined)\n this.doAttach(source);\n }\n }).catch((_err) => { });\n\n return true;\n }\n\n /** Executes this tool's run method with args[0] containing `name`.\n * @see [[run]]\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n return this.run(args[0]);\n }\n}\n/** This tool attaches a Overlay map layer.\n * @beta\n */\nexport class AttachMapOverlayTool extends AttachMapLayerTool {\n public static override toolId = \"AttachMapOverlayTool\";\n constructor() {\n super();\n this._isBackground = false;\n }\n}\n\n/** Sets map layer base tool.\n * @beta\n */\nexport class SetMapBaseTool extends AttachMapLayerTool {\n public static override toolId = \"SetMapBaseTool\";\n constructor() {\n super();\n this._isBase = true;\n }\n}\n\n/** Detach Map Layers Tool.\n * @beta\n */\nexport class DetachMapLayersTool extends Tool {\n public static override toolId = \"DetachMapLayersTool\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 0; }\n public override async parseAndRun(..._args: string[]): Promise<boolean> {\n return this.run();\n }\n\n public override async run(): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (vp === undefined)\n return false;\n vp.displayStyle.detachMapLayerByIndex(-1, true);\n vp.displayStyle.detachMapLayerByIndex(-1, false);\n vp.invalidateRenderPlan();\n return true;\n }\n}\n\nfunction parseLayerIndex(args: string[]) {\n const layerIndex = args.length > 1 ? parseInt(args[1], 10) : 0;\n return isNaN(layerIndex) ? 0 : layerIndex;\n}\n\n/** This tool sets the visibility of the map layer.\n * @beta\n */\nexport class MapLayerVisibilityTool extends Tool {\n public static override toolId = \"SetMapLayerVisibility\";\n public static override get minArgs() { return 1; }\n public static override get maxArgs() { return 2; }\n\n /** This method runs the tool, setting the visibility of a map layer.\n * @param layerIndex the index of the layer to change\n * @param visible a boolean that should be true if the layer should be visible\n */\n public override async run(layerIndex: number, enable?: boolean): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined === vp || !vp.view.isSpatialView())\n return false;\n\n const mapLayer = vp.displayStyle.mapLayerAtIndex(layerIndex, false);\n if (undefined === mapLayer)\n return false;\n\n const visible = (enable === undefined) ? !mapLayer.visible : enable;\n\n vp.displayStyle.changeMapLayerProps({ visible }, layerIndex, false);\n vp.invalidateRenderPlan();\n\n return true;\n }\n\n /** Executes this tool's run method with args[0] containing `enable` and args[1] containing `layerIndex`.\n * @see [[run]]\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const enable = parseToggle(args[0]);\n const layerIndex = parseLayerIndex(args);\n if (typeof enable !== \"string\")\n await this.run(layerIndex, enable);\n\n return true;\n }\n}\n/** This tool reorders map layers.\n * @beta\n */\nexport class ReorderMapLayers extends Tool {\n public static override toolId = \"ReorderMapLayers\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 2; }\n /** This method runs the tool, reordering the map layers.\n * @param from a numeric value specifying the layer index that is being moved\n * @param from a numeric value specifying the layer index to move that layer to\n */\n public override async run(from: number, to: number): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined === vp || !vp.view.isSpatialView())\n return false;\n\n vp.displayStyle.moveMapLayerToIndex(isNaN(from) ? 0 : from, isNaN(to) ? vp.displayStyle.backgroundMapLayers.length : to, false);\n vp.invalidateRenderPlan();\n return true;\n }\n /** Executes this tool's run method with args[0] containing `from` and args[1] containing `to`.\n * @see [[run]]\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const from = parseInt(args[0], 10);\n const to = parseInt(args[1], 10);\n await this.run(from, to);\n return true;\n }\n\n}\n\n/** This tool sets the transparency of a map layer.\n * @beta\n */\nexport class MapLayerTransparencyTool extends Tool {\n public static override toolId = \"SetMapLayerTransparency\";\n public static override get minArgs() { return 1; }\n public static override get maxArgs() { return 2; }\n /** This method runs the tool, setting the transparency of a map layer.\n * @param layerIndex the index of the layer to change\n * @param transparency a numeric value in the range 0.0 (fully opaque) to 1.0 (fully transparent)\n */\n public override async run(layerIndex: number, transparency: number): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined === vp || !vp.view.isSpatialView())\n return false;\n\n vp.displayStyle.changeMapLayerProps({ transparency }, layerIndex, false);\n vp.invalidateRenderPlan();\n\n return true;\n }\n /** Executes this tool's run method with args[0] containing `transparency` and args[1] containing `layerIndex`.\n * @see [[run]]\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const transparency = parseFloat(args[0]);\n const layerIndex = parseLayerIndex(args);\n if (transparency >= 0 && transparency <= 1)\n await this.run(layerIndex, transparency);\n\n return true;\n }\n}\n/** This tool sets the visibility of the map sublayer.\n * @beta\n */\nexport class MapLayerSubLayerVisibilityTool extends Tool {\n public static override toolId = \"SetMapSubLayerVisibility\";\n public static override get minArgs() { return 1; }\n public static override get maxArgs() { return 2; }\n\n /** This method runs the tool, setting the visibility of a map sublayer.\n * @param layerIndex the index of the layer to change\n * @param visible a boolean that should be true if the sublayer should be visible\n */\n public override async run(layerIndex: number, visible: boolean): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined === vp || !vp.view.isSpatialView())\n return false;\n\n vp.displayStyle.changeMapSubLayerProps({ visible }, -1, layerIndex, false);\n vp.invalidateRenderPlan();\n\n return true;\n }\n\n /** Executes this tool's run method with args[0] containing `transparency` and args[1] containing `layerIndex`.\n * @see [[run]]\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const on = args[0] !== \"off\";\n const layerIndex = parseLayerIndex(args);\n await this.run(layerIndex, on);\n\n return true;\n }\n}\n\n/** This tool changes the viewport so it is zoomed to the range of a map layer.\n * @beta\n */\nexport class MapLayerZoomTool extends Tool {\n public static override toolId = \"MapLayerZoom\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 1; }\n\n /** This method runs the tool, changing the viewport so it is zoomed to the range of a map layer.\n * @param layerIndex the index of the layer whose range to zoom to\n */\n public override async run(layerIndex: number): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined === vp || !vp.view.isSpatialView())\n return false;\n\n vp.displayStyle.viewMapLayerRange(layerIndex, false, vp).then(() => { }).catch(() => { });\n\n return true;\n }\n\n /** Executes this tool's run method with args[0] containing `layerIndex`.\n * @see [[run]]\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const layerIndex = parseLayerIndex(args);\n await this.run(layerIndex);\n\n return true;\n }\n}\n\n/** This tool toggles whether to apply terrain heights to the map.\n * @beta\n */\nexport class ToggleTerrainTool extends Tool {\n public static override toolId = \"ToggleTerrain\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 1; }\n\n /** This method runs the tool, changing whether to apply terrain heights to the map.\n * @param enable whether or not to enable terrain heights on the map\n */\n public override async run(enable?: boolean): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined === vp || !vp.view.isSpatialView())\n return false;\n\n const applyTerrain = (enable === undefined) ? !vp.displayStyle.backgroundMapSettings.applyTerrain : enable;\n vp.displayStyle.changeBackgroundMapProps({ applyTerrain });\n vp.invalidateRenderPlan();\n\n return true;\n }\n\n /** Executes this tool's run method with args[0] containing `enable`.\n * @see [[run]]\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const enable = parseToggle(args[0]);\n if (typeof enable !== \"string\")\n await this.run(enable);\n\n return true;\n }\n}\n\n/** This tool changes the color of the base map.\n * @beta\n */\nexport class MapBaseColorTool extends Tool {\n public static override toolId = \"SetMapBaseColorTool\";\n public static override get minArgs() { return 3; }\n public static override get maxArgs() { return 3; }\n\n /** This method runs the tool, changing the color of the base map.\n * @param color the color for the base map\n */\n public override async run(color: ColorDef) {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined === vp || !vp.view.isSpatialView())\n return false;\n\n const curTransparency = vp.displayStyle.backgroundMapBase instanceof ColorDef ? vp.displayStyle.backgroundMapBase.getTransparency() : 0;\n vp.displayStyle.backgroundMapBase = color.withTransparency(curTransparency);\n vp.invalidateRenderPlan();\n\n return true;\n }\n\n /** Executes this tool's run method with args[0] containing a 0 to 255 red component, args[1] containing a 0 to 255 green component, and args[2] containing a 0 to 255 blue component.\n * These rgb values will be used to construct the `color` parameter passed to this tool's run method.\n * @see [[run]]\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const red = parseFloat(args[0]), green = parseFloat(args[1]), blue = parseFloat(args[2]);\n\n return (isNaN(red) || red < 0 || red > 255 || isNaN(green) || green < 0 || green > 255 || isNaN(blue) || blue < 0 || blue > 255) ? false : this.run(ColorDef.from(red, green, blue));\n }\n}\n/** This tool changes the transparency of the base map.\n * @beta\n */\nexport class MapBaseTransparencyTool extends Tool {\n public static override toolId = \"SetMapBaseTransparencyTool\";\n public static override get minArgs() { return 1; }\n public static override get maxArgs() { return 1; }\n\n /** This method runs the tool, changing the transparency of the base map.\n * @param transparency a numeric value in range 0.0 to 1.0 whether 0.0 means fully opaque and 1.0 means fully transparent\n */\n public override async run(transparency: number) {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined === vp || !vp.view.isSpatialView())\n return false;\n\n vp.displayStyle.changeBaseMapTransparency(transparency);\n vp.invalidateRenderPlan();\n\n return true;\n }\n\n /** Executes this tool's run method with args[0] containing `transparency`.\n * @see [[run]]\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const transparency = parseFloat(args[0]);\n\n return (isNaN(transparency) || transparency < 0 || transparency > 1) ? false : this.run(transparency);\n }\n}\n\n/** This tool changes the visibility of the base map.\n * @beta\n */\nexport class MapBaseVisibilityTool extends Tool {\n public static override toolId = \"SetMapBaseVisibilityTool\";\n public static override get minArgs() { return 1; }\n public static override get maxArgs() { return 1; }\n\n /** This method runs the tool, changing the visibility of the base map.\n * @param visible a boolean which specifies whether or not to make the base map visible\n */\n public override async run(visible: boolean) {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined === vp || !vp.view.isSpatialView() || vp.displayStyle.backgroundMapBase instanceof ColorDef)\n return false;\n\n vp.displayStyle.backgroundMapBase = vp.displayStyle.backgroundMapBase.clone({ visible });\n vp.invalidateRenderPlan();\n\n return true;\n }\n\n /** Executes this tool's run method with args[0] containing `visible`.\n * @see [[run]]\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const visible = parseBoolean(args[0]);\n\n return (visible !== undefined ? this.run(visible) : false);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MapLayerTool.js","sourceRoot":"","sources":["../../../src/tools/MapLayerTool.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,eAAe,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzK,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,+CAA+C;AAC/C,MAAM,sBAAuB,SAAQ,IAAI;IACvC,YAAsB,gBAAgB,IAAI,EAAY,UAAU,KAAK;QACnE,KAAK,EAAE,CAAC;QADY,kBAAa,GAAb,aAAa,CAAO;QAAY,YAAO,GAAP,OAAO,CAAQ;IAErE,CAAC;IAES,QAAQ,CAAC,MAAuB;QACxC,MAAM,EAAE,GAAG,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC9C,IAAI,EAAE,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS;YAC1C,OAAO;QAET,MAAM,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;YAC1C,IAAI,UAAU,CAAC,MAAM,KAAK,oBAAoB,CAAC,KAAK,IAAI,UAAU,CAAC,MAAM,KAAK,oBAAoB,CAAC,WAAW,EAAE;gBAC9G,IAAI,IAAI,CAAC,OAAO,EAAE;oBAChB,EAAE,CAAC,YAAY,CAAC,iBA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BAAoB,EAAE,CAAC;QAE1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACa,KAAK,CAAC,WAAW,CAAC,GAAG,IAAc;QACjD,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAEtC,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC7D,CAAC;;AAzBsB,4BAAM,GAAG,0BAA0B,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module Tools\r\n */\r\n\r\nimport { BaseMapLayerSettings, ColorDef } from \"@itwin/core-common\";\r\nimport { IModelApp, MapLayerSource, MapLayerSources, MapLayerSourceStatus, NotifyMessageDetails, OutputMessagePriority, Tool, WmsUtilities } from \"@itwin/core-frontend\";\r\nimport { parseBoolean } from \"./parseBoolean\";\r\nimport { parseToggle } from \"./parseToggle\";\r\n\r\n/** Base class for attaching map layer tool. */\r\nclass AttachMapLayerBaseTool extends Tool {\r\n constructor(protected _isBackground = true, protected _isBase = false) {\r\n super();\r\n }\r\n\r\n protected doAttach(source?: MapLayerSource) {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (vp === undefined || source === undefined)\r\n return;\r\n\r\n source.validateSource().then((validation) => {\r\n if (validation.status === MapLayerSourceStatus.Valid || validation.status === MapLayerSourceStatus.RequireAuth) {\r\n if (this._isBase) {\r\n vp.displayStyle.backgroundMapBase = BaseMapLayerSettings.fromJSON({ ...source, subLayers: validation.subLayers });\r\n vp.invalidateRenderPlan();\r\n } else {\r\n const layerSettings = source.toLayerSettings(validation.subLayers);\r\n if (layerSettings) {\r\n vp.displayStyle.attachMapLayerSettings(layerSettings, !this._isBackground);\r\n }\r\n }\r\n\r\n if (validation.status === MapLayerSourceStatus.Valid) {\r\n vp.invalidateRenderPlan();\r\n const msg = IModelApp.localization.getLocalizedString(\"FrontendDevTools:tools.AttachMapLayerTool.Messages.MapLayerAttached\", { sourceName: source.name, sourceUrl: source.url });\r\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, msg));\r\n } else if (validation.status === MapLayerSourceStatus.RequireAuth) {\r\n const msg = IModelApp.localization.getLocalizedString(\"FrontendDevTools:tools.AttachMapLayerTool.Messages.MapLayerAttachedRequiresAuth\", { sourceName: source.name });\r\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Warning, msg));\r\n }\r\n\r\n } else {\r\n const msg = IModelApp.localization.getLocalizedString(\"FrontendDevTools:tools.AttachMapLayerTool.Messages.MapLayerValidationFailed\", { sourceUrl: source.url });\r\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));\r\n }\r\n }).catch((error) => {\r\n const msg = IModelApp.localization.getLocalizedString(\"FrontendDevTools:tools.AttachMapLayerTool.Messages.MapLayerAttachError\", { error, sourceUrl: source.url });\r\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));\r\n });\r\n }\r\n}\r\n/** Attach a map layer from URL base class. */\r\nclass AttachMapLayerByURLBaseTool extends AttachMapLayerBaseTool {\r\n public static override get minArgs() { return 1; }\r\n public static override get maxArgs() { return 4; }\r\n constructor(protected _formatId: string) { super(); }\r\n\r\n public override async run(url: string, name?: string, userName?: string, password?: string): Promise<boolean> {\r\n this.doAttach(MapLayerSource.fromJSON({ url, name: (name ? name : url), formatId: this._formatId, userName, password }));\r\n return true;\r\n }\r\n\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n return this.run(args[0], args[1], args[2], args[3]);\r\n }\r\n}\r\n\r\n/** This tool attaches a WMS map layer from a given URL.\r\n * @beta\r\n */\r\nexport class AttachWmsMapLayerByUrlTool extends AttachMapLayerByURLBaseTool {\r\n public static override toolId = \"AttachWmsMapLayerTool\";\r\n constructor() { super(\"WMS\"); }\r\n /** This method runs the tool, attaching a WMS map layer from a given URL.\r\n * @param args contains url, name, userName, password in array order\r\n */\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n return this.run(WmsUtilities.getBaseUrl(args[0]), args[1], args[2], args[3]);\r\n }\r\n}\r\n\r\n/** This tool attaches a WMTS map layer from a given URL.\r\n * @beta\r\n */\r\nexport class AttachWmtsMapLayerByUrlTool extends AttachMapLayerByURLBaseTool {\r\n public static override toolId = \"AttachWmtsMapLayerTool\";\r\n constructor() { super(\"WMTS\"); }\r\n /** This method runs the tool, attaching a WMTS map layer from a given URL.\r\n * @param args contains url, name, userName, password in array order\r\n */\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n return this.run(WmsUtilities.getBaseUrl(args[0]), args[1], args[2], args[3]);\r\n }\r\n}\r\n\r\n/** This tool attaches an ArcGIS map layer from a given URL.\r\n * @beta\r\n */\r\nexport class AttachArcGISMapLayerByUrlTool extends AttachMapLayerByURLBaseTool {\r\n public static override toolId = \"AttachArcGISMapLayerTool\";\r\n constructor() { super(\"ArcGIS\"); }\r\n}\r\n\r\n/** This tool attaches a map layer from a given tile URL.\r\n * @beta\r\n */\r\nexport class AttachTileURLMapLayerByUrlTool extends AttachMapLayerByURLBaseTool {\r\n public static override toolId = \"AttachTileURLMapLayerTool\";\r\n constructor() { super(\"TileURL\"); }\r\n}\r\n\r\n/** This tool add a Map Layer from a specified name (look up in MapLayerSources.json).\r\n * @beta\r\n */\r\nexport class AttachMapLayerTool extends AttachMapLayerBaseTool {\r\n public static override toolId = \"AttachMapLayerTool\";\r\n public static override get minArgs() { return 1; }\r\n public static override get maxArgs() { return 1; }\r\n\r\n /** This method runs the tool, adding a map layer from a specified name in MayLayerSources.json.\r\n * @param name the name of the map layer to add\r\n */\r\n public override async run(name: string): Promise<boolean> {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (vp === undefined)\r\n return false;\r\n\r\n MapLayerSources.create().then((sources) => {\r\n if (sources !== undefined) {\r\n const source = sources.findByName(name, this._isBase);\r\n if (source !== undefined)\r\n this.doAttach(source);\r\n }\r\n }).catch((_err) => { });\r\n\r\n return true;\r\n }\r\n\r\n /** Executes this tool's run method with args[0] containing `name`.\r\n * @see [[run]]\r\n */\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n return this.run(args[0]);\r\n }\r\n}\r\n/** This tool attaches a Overlay map layer.\r\n * @beta\r\n */\r\nexport class AttachMapOverlayTool extends AttachMapLayerTool {\r\n public static override toolId = \"AttachMapOverlayTool\";\r\n constructor() {\r\n super();\r\n this._isBackground = false;\r\n }\r\n}\r\n\r\n/** Sets map layer base tool.\r\n * @beta\r\n */\r\nexport class SetMapBaseTool extends AttachMapLayerTool {\r\n public static override toolId = \"SetMapBaseTool\";\r\n constructor() {\r\n super();\r\n this._isBase = true;\r\n }\r\n}\r\n\r\n/** Detach Map Layers Tool.\r\n * @beta\r\n */\r\nexport class DetachMapLayersTool extends Tool {\r\n public static override toolId = \"DetachMapLayersTool\";\r\n public static override get minArgs() { return 0; }\r\n public static override get maxArgs() { return 0; }\r\n public override async parseAndRun(..._args: string[]): Promise<boolean> {\r\n return this.run();\r\n }\r\n\r\n public override async run(): Promise<boolean> {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (vp === undefined)\r\n return false;\r\n vp.displayStyle.detachMapLayerByIndex(-1, true);\r\n vp.displayStyle.detachMapLayerByIndex(-1, false);\r\n vp.invalidateRenderPlan();\r\n return true;\r\n }\r\n}\r\n\r\nfunction parseLayerIndex(args: string[]) {\r\n const layerIndex = args.length > 1 ? parseInt(args[1], 10) : 0;\r\n return isNaN(layerIndex) ? 0 : layerIndex;\r\n}\r\n\r\n/** This tool sets the visibility of the map layer.\r\n * @beta\r\n */\r\nexport class MapLayerVisibilityTool extends Tool {\r\n public static override toolId = \"SetMapLayerVisibility\";\r\n public static override get minArgs() { return 1; }\r\n public static override get maxArgs() { return 2; }\r\n\r\n /** This method runs the tool, setting the visibility of a map layer.\r\n * @param layerIndex the index of the layer to change\r\n * @param visible a boolean that should be true if the layer should be visible\r\n */\r\n public override async run(layerIndex: number, enable?: boolean): Promise<boolean> {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (undefined === vp || !vp.view.isSpatialView())\r\n return false;\r\n\r\n const mapLayer = vp.displayStyle.mapLayerAtIndex(layerIndex, false);\r\n if (undefined === mapLayer)\r\n return false;\r\n\r\n const visible = (enable === undefined) ? !mapLayer.visible : enable;\r\n\r\n vp.displayStyle.changeMapLayerProps({ visible }, layerIndex, false);\r\n vp.invalidateRenderPlan();\r\n\r\n return true;\r\n }\r\n\r\n /** Executes this tool's run method with args[0] containing `enable` and args[1] containing `layerIndex`.\r\n * @see [[run]]\r\n */\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n const enable = parseToggle(args[0]);\r\n const layerIndex = parseLayerIndex(args);\r\n if (typeof enable !== \"string\")\r\n await this.run(layerIndex, enable);\r\n\r\n return true;\r\n }\r\n}\r\n/** This tool reorders map layers.\r\n * @beta\r\n */\r\nexport class ReorderMapLayers extends Tool {\r\n public static override toolId = \"ReorderMapLayers\";\r\n public static override get minArgs() { return 0; }\r\n public static override get maxArgs() { return 2; }\r\n /** This method runs the tool, reordering the map layers.\r\n * @param from a numeric value specifying the layer index that is being moved\r\n * @param from a numeric value specifying the layer index to move that layer to\r\n */\r\n public override async run(from: number, to: number): Promise<boolean> {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (undefined === vp || !vp.view.isSpatialView())\r\n return false;\r\n\r\n vp.displayStyle.moveMapLayerToIndex(isNaN(from) ? 0 : from, isNaN(to) ? vp.displayStyle.backgroundMapLayers.length : to, false);\r\n vp.invalidateRenderPlan();\r\n return true;\r\n }\r\n /** Executes this tool's run method with args[0] containing `from` and args[1] containing `to`.\r\n * @see [[run]]\r\n */\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n const from = parseInt(args[0], 10);\r\n const to = parseInt(args[1], 10);\r\n await this.run(from, to);\r\n return true;\r\n }\r\n\r\n}\r\n\r\n/** This tool sets the transparency of a map layer.\r\n * @beta\r\n */\r\nexport class MapLayerTransparencyTool extends Tool {\r\n public static override toolId = \"SetMapLayerTransparency\";\r\n public static override get minArgs() { return 1; }\r\n public static override get maxArgs() { return 2; }\r\n /** This method runs the tool, setting the transparency of a map layer.\r\n * @param layerIndex the index of the layer to change\r\n * @param transparency a numeric value in the range 0.0 (fully opaque) to 1.0 (fully transparent)\r\n */\r\n public override async run(layerIndex: number, transparency: number): Promise<boolean> {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (undefined === vp || !vp.view.isSpatialView())\r\n return false;\r\n\r\n vp.displayStyle.changeMapLayerProps({ transparency }, layerIndex, false);\r\n vp.invalidateRenderPlan();\r\n\r\n return true;\r\n }\r\n /** Executes this tool's run method with args[0] containing `transparency` and args[1] containing `layerIndex`.\r\n * @see [[run]]\r\n */\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n const transparency = parseFloat(args[0]);\r\n const layerIndex = parseLayerIndex(args);\r\n if (transparency >= 0 && transparency <= 1)\r\n await this.run(layerIndex, transparency);\r\n\r\n return true;\r\n }\r\n}\r\n/** This tool sets the visibility of the map sublayer.\r\n * @beta\r\n */\r\nexport class MapLayerSubLayerVisibilityTool extends Tool {\r\n public static override toolId = \"SetMapSubLayerVisibility\";\r\n public static override get minArgs() { return 1; }\r\n public static override get maxArgs() { return 2; }\r\n\r\n /** This method runs the tool, setting the visibility of a map sublayer.\r\n * @param layerIndex the index of the layer to change\r\n * @param visible a boolean that should be true if the sublayer should be visible\r\n */\r\n public override async run(layerIndex: number, visible: boolean): Promise<boolean> {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (undefined === vp || !vp.view.isSpatialView())\r\n return false;\r\n\r\n vp.displayStyle.changeMapSubLayerProps({ visible }, -1, layerIndex, false);\r\n vp.invalidateRenderPlan();\r\n\r\n return true;\r\n }\r\n\r\n /** Executes this tool's run method with args[0] containing `transparency` and args[1] containing `layerIndex`.\r\n * @see [[run]]\r\n */\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n const on = args[0] !== \"off\";\r\n const layerIndex = parseLayerIndex(args);\r\n await this.run(layerIndex, on);\r\n\r\n return true;\r\n }\r\n}\r\n\r\n/** This tool changes the viewport so it is zoomed to the range of a map layer.\r\n * @beta\r\n */\r\nexport class MapLayerZoomTool extends Tool {\r\n public static override toolId = \"MapLayerZoom\";\r\n public static override get minArgs() { return 0; }\r\n public static override get maxArgs() { return 1; }\r\n\r\n /** This method runs the tool, changing the viewport so it is zoomed to the range of a map layer.\r\n * @param layerIndex the index of the layer whose range to zoom to\r\n */\r\n public override async run(layerIndex: number): Promise<boolean> {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (undefined === vp || !vp.view.isSpatialView())\r\n return false;\r\n\r\n vp.displayStyle.viewMapLayerRange(layerIndex, false, vp).then(() => { }).catch(() => { });\r\n\r\n return true;\r\n }\r\n\r\n /** Executes this tool's run method with args[0] containing `layerIndex`.\r\n * @see [[run]]\r\n */\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n const layerIndex = parseLayerIndex(args);\r\n await this.run(layerIndex);\r\n\r\n return true;\r\n }\r\n}\r\n\r\n/** This tool toggles whether to apply terrain heights to the map.\r\n * @beta\r\n */\r\nexport class ToggleTerrainTool extends Tool {\r\n public static override toolId = \"ToggleTerrain\";\r\n public static override get minArgs() { return 0; }\r\n public static override get maxArgs() { return 1; }\r\n\r\n /** This method runs the tool, changing whether to apply terrain heights to the map.\r\n * @param enable whether or not to enable terrain heights on the map\r\n */\r\n public override async run(enable?: boolean): Promise<boolean> {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (undefined === vp || !vp.view.isSpatialView())\r\n return false;\r\n\r\n const applyTerrain = (enable === undefined) ? !vp.displayStyle.backgroundMapSettings.applyTerrain : enable;\r\n vp.displayStyle.changeBackgroundMapProps({ applyTerrain });\r\n vp.invalidateRenderPlan();\r\n\r\n return true;\r\n }\r\n\r\n /** Executes this tool's run method with args[0] containing `enable`.\r\n * @see [[run]]\r\n */\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n const enable = parseToggle(args[0]);\r\n if (typeof enable !== \"string\")\r\n await this.run(enable);\r\n\r\n return true;\r\n }\r\n}\r\n\r\n/** This tool changes the color of the base map.\r\n * @beta\r\n */\r\nexport class MapBaseColorTool extends Tool {\r\n public static override toolId = \"SetMapBaseColorTool\";\r\n public static override get minArgs() { return 3; }\r\n public static override get maxArgs() { return 3; }\r\n\r\n /** This method runs the tool, changing the color of the base map.\r\n * @param color the color for the base map\r\n */\r\n public override async run(color: ColorDef) {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (undefined === vp || !vp.view.isSpatialView())\r\n return false;\r\n\r\n const curTransparency = vp.displayStyle.backgroundMapBase instanceof ColorDef ? vp.displayStyle.backgroundMapBase.getTransparency() : 0;\r\n vp.displayStyle.backgroundMapBase = color.withTransparency(curTransparency);\r\n vp.invalidateRenderPlan();\r\n\r\n return true;\r\n }\r\n\r\n /** Executes this tool's run method with args[0] containing a 0 to 255 red component, args[1] containing a 0 to 255 green component, and args[2] containing a 0 to 255 blue component.\r\n * These rgb values will be used to construct the `color` parameter passed to this tool's run method.\r\n * @see [[run]]\r\n */\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n const red = parseFloat(args[0]), green = parseFloat(args[1]), blue = parseFloat(args[2]);\r\n\r\n return (isNaN(red) || red < 0 || red > 255 || isNaN(green) || green < 0 || green > 255 || isNaN(blue) || blue < 0 || blue > 255) ? false : this.run(ColorDef.from(red, green, blue));\r\n }\r\n}\r\n/** This tool changes the transparency of the base map.\r\n * @beta\r\n */\r\nexport class MapBaseTransparencyTool extends Tool {\r\n public static override toolId = \"SetMapBaseTransparencyTool\";\r\n public static override get minArgs() { return 1; }\r\n public static override get maxArgs() { return 1; }\r\n\r\n /** This method runs the tool, changing the transparency of the base map.\r\n * @param transparency a numeric value in range 0.0 to 1.0 whether 0.0 means fully opaque and 1.0 means fully transparent\r\n */\r\n public override async run(transparency: number) {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (undefined === vp || !vp.view.isSpatialView())\r\n return false;\r\n\r\n vp.displayStyle.changeBaseMapTransparency(transparency);\r\n vp.invalidateRenderPlan();\r\n\r\n return true;\r\n }\r\n\r\n /** Executes this tool's run method with args[0] containing `transparency`.\r\n * @see [[run]]\r\n */\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n const transparency = parseFloat(args[0]);\r\n\r\n return (isNaN(transparency) || transparency < 0 || transparency > 1) ? false : this.run(transparency);\r\n }\r\n}\r\n\r\n/** This tool changes the visibility of the base map.\r\n * @beta\r\n */\r\nexport class MapBaseVisibilityTool extends Tool {\r\n public static override toolId = \"SetMapBaseVisibilityTool\";\r\n public static override get minArgs() { return 1; }\r\n public static override get maxArgs() { return 1; }\r\n\r\n /** This method runs the tool, changing the visibility of the base map.\r\n * @param visible a boolean which specifies whether or not to make the base map visible\r\n */\r\n public override async run(visible: boolean) {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (undefined === vp || !vp.view.isSpatialView() || vp.displayStyle.backgroundMapBase instanceof ColorDef)\r\n return false;\r\n\r\n vp.displayStyle.backgroundMapBase = vp.displayStyle.backgroundMapBase.clone({ visible });\r\n vp.invalidateRenderPlan();\r\n\r\n return true;\r\n }\r\n\r\n /** Executes this tool's run method with args[0] containing `visible`.\r\n * @see [[run]]\r\n */\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n const visible = parseBoolean(args[0]);\r\n\r\n return (visible !== undefined ? this.run(visible) : false);\r\n }\r\n}\r\n"]}
|