@itwin/core-frontend 3.6.0-dev.1 → 3.6.0-dev.5
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/lib/cjs/EnvironmentDecorations.d.ts +4 -4
- package/lib/cjs/EnvironmentDecorations.d.ts.map +1 -1
- package/lib/cjs/EnvironmentDecorations.js +69 -52
- package/lib/cjs/EnvironmentDecorations.js.map +1 -1
- package/lib/cjs/GraphicalEditingScope.d.ts.map +1 -1
- package/lib/cjs/GraphicalEditingScope.js +8 -2
- package/lib/cjs/GraphicalEditingScope.js.map +1 -1
- package/lib/cjs/SelectionSet.d.ts.map +1 -1
- package/lib/cjs/SelectionSet.js +3 -1
- package/lib/cjs/SelectionSet.js.map +1 -1
- package/lib/cjs/Viewport.d.ts.map +1 -1
- package/lib/cjs/Viewport.js +14 -11
- package/lib/cjs/Viewport.js.map +1 -1
- package/lib/esm/EnvironmentDecorations.d.ts +4 -4
- package/lib/esm/EnvironmentDecorations.d.ts.map +1 -1
- package/lib/esm/EnvironmentDecorations.js +69 -52
- package/lib/esm/EnvironmentDecorations.js.map +1 -1
- package/lib/esm/GraphicalEditingScope.d.ts.map +1 -1
- package/lib/esm/GraphicalEditingScope.js +8 -2
- package/lib/esm/GraphicalEditingScope.js.map +1 -1
- package/lib/esm/SelectionSet.d.ts.map +1 -1
- package/lib/esm/SelectionSet.js +3 -1
- package/lib/esm/SelectionSet.js.map +1 -1
- package/lib/esm/Viewport.d.ts.map +1 -1
- package/lib/esm/Viewport.js +14 -11
- package/lib/esm/Viewport.js.map +1 -1
- package/package.json +20 -20
|
@@ -12,8 +12,8 @@ export interface GroundPlaneDecorations {
|
|
|
12
12
|
}
|
|
13
13
|
/** @internal */
|
|
14
14
|
export interface SkyBoxDecorations {
|
|
15
|
-
params?: RenderSkyBoxParams
|
|
16
|
-
promise?: Promise<
|
|
15
|
+
params?: RenderSkyBoxParams;
|
|
16
|
+
promise?: Promise<boolean>;
|
|
17
17
|
}
|
|
18
18
|
/** @internal */
|
|
19
19
|
export declare class EnvironmentDecorations {
|
|
@@ -29,9 +29,9 @@ export declare class EnvironmentDecorations {
|
|
|
29
29
|
decorate(context: DecorateContext): void;
|
|
30
30
|
private loadGround;
|
|
31
31
|
private createGroundParams;
|
|
32
|
-
private
|
|
32
|
+
private loadSkyBox;
|
|
33
33
|
private setSky;
|
|
34
|
-
private
|
|
34
|
+
private loadSkyBoxParams;
|
|
35
35
|
private createCubeImageKey;
|
|
36
36
|
private createSkyGradientParams;
|
|
37
37
|
private imageFromSpec;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvironmentDecorations.d.ts","sourceRoot":"","sources":["../../src/EnvironmentDecorations.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EACK,WAAW,EAAY,aAAa,EAC/C,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,gBAAgB;AAChB,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC;IACpC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC;CACrC;
|
|
1
|
+
{"version":3,"file":"EnvironmentDecorations.d.ts","sourceRoot":"","sources":["../../src/EnvironmentDecorations.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EACK,WAAW,EAAY,aAAa,EAC/C,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,gBAAgB;AAChB,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC;IACpC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC;CACrC;AASD,gBAAgB;AAChB,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;CAC5B;AAED,gBAAgB;AAChB,qBAAa,sBAAsB;IACjC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IACtC,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,IAAI,CAAC;IACzC,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,IAAI,CAAC;IAC1C,SAAS,CAAC,YAAY,EAAE,WAAW,CAAC;IACpC,SAAS,CAAC,OAAO,CAAC,EAAE,sBAAsB,CAAC;IAC3C,SAAS,CAAC,IAAI,EAAE,iBAAiB,CAAC;gBAEf,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,EAAE,SAAS,EAAE,MAAM,IAAI;IAY1E,OAAO,IAAI,IAAI;IAOf,cAAc,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI;IAmBtC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAoC/C,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,kBAAkB;IAqC1B,OAAO,CAAC,UAAU;IAkBlB,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,gBAAgB;IAqExB,OAAO,CAAC,kBAAkB;IAK1B,OAAO,CAAC,uBAAuB;YAQjB,aAAa;CAM5B"}
|
|
@@ -19,13 +19,13 @@ export class EnvironmentDecorations {
|
|
|
19
19
|
this._onLoaded = onLoaded;
|
|
20
20
|
this._onDispose = onDispose;
|
|
21
21
|
this._sky = {};
|
|
22
|
-
this.
|
|
22
|
+
this.loadSkyBox();
|
|
23
23
|
if (this._environment.displayGround)
|
|
24
24
|
this.loadGround();
|
|
25
25
|
}
|
|
26
26
|
dispose() {
|
|
27
27
|
this._ground = undefined;
|
|
28
|
-
this._sky.
|
|
28
|
+
this._sky.params = this._sky.promise = undefined;
|
|
29
29
|
this._onDispose();
|
|
30
30
|
}
|
|
31
31
|
setEnvironment(env) {
|
|
@@ -40,7 +40,7 @@ export class EnvironmentDecorations {
|
|
|
40
40
|
this.loadGround();
|
|
41
41
|
// Update sky box
|
|
42
42
|
if (env.sky !== prev.sky)
|
|
43
|
-
this.
|
|
43
|
+
this.loadSkyBox();
|
|
44
44
|
}
|
|
45
45
|
decorate(context) {
|
|
46
46
|
const env = this._environment;
|
|
@@ -109,82 +109,99 @@ export class EnvironmentDecorations {
|
|
|
109
109
|
params.material = material;
|
|
110
110
|
return params;
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
const
|
|
112
|
+
loadSkyBox() {
|
|
113
|
+
const loader = this.loadSkyBoxParams();
|
|
114
|
+
if (undefined === loader.preload) {
|
|
115
|
+
this.setSky(loader.load());
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const promise = loader.preload;
|
|
114
119
|
this._sky.promise = promise;
|
|
115
|
-
|
|
116
|
-
promise.then((params) => {
|
|
120
|
+
loader.preload.then((loaded) => {
|
|
117
121
|
if (promise === this._sky.promise)
|
|
118
|
-
this.setSky(
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
this.setSky(this.createSkyGradientParams());
|
|
122
|
+
this.setSky(loaded ? loader.load() : undefined);
|
|
123
|
+
}).catch(() => {
|
|
124
|
+
if (promise === this._sky.promise)
|
|
125
|
+
this.setSky(undefined);
|
|
123
126
|
});
|
|
124
127
|
}
|
|
125
128
|
setSky(params) {
|
|
126
129
|
this._sky.promise = undefined;
|
|
127
|
-
this._sky.params = params;
|
|
130
|
+
this._sky.params = params !== null && params !== void 0 ? params : this.createSkyGradientParams();
|
|
128
131
|
this._onLoaded();
|
|
129
132
|
}
|
|
130
|
-
|
|
133
|
+
loadSkyBoxParams() {
|
|
134
|
+
let load;
|
|
135
|
+
let preload;
|
|
131
136
|
const sky = this._environment.sky;
|
|
132
137
|
if (sky instanceof SkyCube) {
|
|
133
138
|
const key = this.createCubeImageKey(sky);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return { type: "cube", texture: existingTexture };
|
|
137
|
-
// Some faces may use the same image. Only request each image once.
|
|
138
|
-
const specs = new Set([sky.images.front, sky.images.back, sky.images.left, sky.images.right, sky.images.top, sky.images.bottom]);
|
|
139
|
-
const promises = [];
|
|
140
|
-
for (const spec of specs)
|
|
141
|
-
promises.push(this.imageFromSpec(spec));
|
|
142
|
-
return Promise.all(promises).then((images) => {
|
|
143
|
-
const idToImage = new Map();
|
|
144
|
-
let index = 0;
|
|
145
|
-
for (const spec of specs) {
|
|
146
|
-
const image = images[index++];
|
|
147
|
-
if (!image)
|
|
148
|
-
return undefined;
|
|
149
|
-
else
|
|
150
|
-
idToImage.set(spec, image);
|
|
151
|
-
}
|
|
152
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
153
|
-
const params = new RenderTexture.Params(key, RenderTexture.Type.SkyBox);
|
|
154
|
-
const txImgs = [
|
|
155
|
-
idToImage.get(sky.images.front), idToImage.get(sky.images.back), idToImage.get(sky.images.top),
|
|
156
|
-
idToImage.get(sky.images.bottom), idToImage.get(sky.images.right), idToImage.get(sky.images.left),
|
|
157
|
-
];
|
|
158
|
-
const texture = IModelApp.renderSystem.createTextureFromCubeImages(txImgs[0], txImgs[1], txImgs[2], txImgs[3], txImgs[4], txImgs[5], this._view.iModel, params);
|
|
139
|
+
load = () => {
|
|
140
|
+
const texture = IModelApp.renderSystem.findTexture(key, this._view.iModel);
|
|
159
141
|
return texture ? { type: "cube", texture } : undefined;
|
|
160
|
-
}
|
|
142
|
+
};
|
|
143
|
+
if (!IModelApp.renderSystem.findTexture(key, this._view.iModel)) {
|
|
144
|
+
// Some faces may use the same image. Only request each image once.
|
|
145
|
+
const promises = [];
|
|
146
|
+
const specs = new Set([sky.images.front, sky.images.back, sky.images.left, sky.images.right, sky.images.top, sky.images.bottom]);
|
|
147
|
+
for (const spec of specs)
|
|
148
|
+
promises.push(this.imageFromSpec(spec));
|
|
149
|
+
preload = Promise.all(promises).then((images) => {
|
|
150
|
+
const idToImage = new Map();
|
|
151
|
+
let index = 0;
|
|
152
|
+
for (const spec of specs) {
|
|
153
|
+
const image = images[index++];
|
|
154
|
+
if (!image)
|
|
155
|
+
return false;
|
|
156
|
+
else
|
|
157
|
+
idToImage.set(spec, image);
|
|
158
|
+
}
|
|
159
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
160
|
+
const params = new RenderTexture.Params(key, RenderTexture.Type.SkyBox);
|
|
161
|
+
const txImgs = [
|
|
162
|
+
idToImage.get(sky.images.front), idToImage.get(sky.images.back), idToImage.get(sky.images.top),
|
|
163
|
+
idToImage.get(sky.images.bottom), idToImage.get(sky.images.right), idToImage.get(sky.images.left),
|
|
164
|
+
];
|
|
165
|
+
return undefined !== IModelApp.renderSystem.createTextureFromCubeImages(txImgs[0], txImgs[1], txImgs[2], txImgs[3], txImgs[4], txImgs[5], this._view.iModel, params);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
161
168
|
}
|
|
162
169
|
else if (sky instanceof SkySphere) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
170
|
+
load = () => {
|
|
171
|
+
const texture = IModelApp.renderSystem.findTexture(sky.image, this._view.iModel);
|
|
172
|
+
return texture ? {
|
|
173
|
+
type: "sphere",
|
|
174
|
+
texture,
|
|
175
|
+
rotation: 0,
|
|
176
|
+
zOffset: this._view.iModel.globalOrigin.z,
|
|
177
|
+
} : undefined;
|
|
178
|
+
};
|
|
179
|
+
if (!IModelApp.renderSystem.findTexture(sky.image, this._view.iModel)) {
|
|
180
|
+
preload = this.imageFromSpec(sky.image).then((image) => {
|
|
181
|
+
if (!image)
|
|
182
|
+
return false;
|
|
183
|
+
return undefined !== IModelApp.renderSystem.createTexture({
|
|
169
184
|
image: { source: image },
|
|
170
185
|
ownership: { iModel: this._view.iModel, key: sky.image },
|
|
171
186
|
});
|
|
172
|
-
}
|
|
187
|
+
});
|
|
173
188
|
}
|
|
174
|
-
if (!texture)
|
|
175
|
-
return undefined;
|
|
176
|
-
return { type: "sphere", texture, rotation, zOffset: this._view.iModel.globalOrigin.z };
|
|
177
189
|
}
|
|
178
190
|
else {
|
|
179
|
-
|
|
191
|
+
load = () => this.createSkyGradientParams();
|
|
180
192
|
}
|
|
193
|
+
return { load, preload };
|
|
181
194
|
}
|
|
182
195
|
createCubeImageKey(sky) {
|
|
183
196
|
const i = sky.images;
|
|
184
197
|
return `skycube:${i.front}:${i.back}:${i.left}:${i.right}:${i.top}:${i.bottom}`;
|
|
185
198
|
}
|
|
186
199
|
createSkyGradientParams() {
|
|
187
|
-
return {
|
|
200
|
+
return {
|
|
201
|
+
type: "gradient",
|
|
202
|
+
gradient: this._environment.sky.gradient,
|
|
203
|
+
zOffset: this._view.iModel.globalOrigin.z,
|
|
204
|
+
};
|
|
188
205
|
}
|
|
189
206
|
async imageFromSpec(spec) {
|
|
190
207
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvironmentDecorations.js","sourceRoot":"","sources":["../../src/EnvironmentDecorations.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAC,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAW,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EACL,QAAQ,EAAe,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAoB,cAAc,GACpH,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE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AM,SAAS,CAAC,YAAY,CAAC,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,0CAAE,KAAK,CAAC;QAEzF,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;CACF","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 Views\r\n */\r\n\r\nimport { assert, Id64} from \"@itwin/core-bentley\";\r\nimport { Point2d, Point3d, PolyfaceBuilder, StrokeOptions } from \"@itwin/core-geometry\";\r\nimport {\r\n ColorDef, Environment, Gradient, GraphicParams, RenderTexture, SkyCube, SkySphere, TextureImageSpec, TextureMapping,\r\n} from \"@itwin/core-common\";\r\nimport { IModelApp } from \"./IModelApp\";\r\nimport { ViewState3d } from \"./ViewState\";\r\nimport { DecorateContext } from \"./ViewContext\";\r\nimport { tryImageElementFromUrl } from \"./ImageUtil\";\r\nimport { GraphicType } from \"./render/GraphicBuilder\";\r\nimport { RenderSkyBoxParams } from \"./render/RenderSystem\";\r\n\r\n/** @internal */\r\nexport interface GroundPlaneDecorations {\r\n readonly aboveParams: GraphicParams;\r\n readonly belowParams: GraphicParams;\r\n}\r\n\r\n/** @internal */\r\nexport interface SkyBoxDecorations {\r\n params?: RenderSkyBoxParams | undefined;\r\n promise?: Promise<RenderSkyBoxParams | undefined>;\r\n}\r\n\r\n/** @internal */\r\nexport class EnvironmentDecorations {\r\n protected readonly _view: ViewState3d;\r\n protected readonly _onLoaded: () => void;\r\n protected readonly _onDispose: () => void;\r\n protected _environment: Environment;\r\n protected _ground?: GroundPlaneDecorations;\r\n protected _sky: SkyBoxDecorations;\r\n\r\n public constructor(view: ViewState3d, onLoaded: () => void, onDispose: () => void) {\r\n this._environment = view.displayStyle.environment;\r\n this._view = view;\r\n this._onLoaded = onLoaded;\r\n this._onDispose = onDispose;\r\n\r\n this._sky = { };\r\n this.loadSky();\r\n if (this._environment.displayGround)\r\n this.loadGround();\r\n }\r\n\r\n public dispose(): void {\r\n this._ground = undefined;\r\n\r\n this._sky.promise = this._sky.params = undefined;\r\n\r\n this._onDispose();\r\n }\r\n\r\n public setEnvironment(env: Environment): void {\r\n const prev = this._environment;\r\n if (prev === env)\r\n return;\r\n\r\n this._environment = env;\r\n\r\n // Update ground plane\r\n if (!env.displayGround || env.ground !== prev.ground)\r\n this._ground = undefined;\r\n\r\n if (env.displayGround && !this._ground)\r\n this.loadGround();\r\n\r\n // Update sky box\r\n if (env.sky !== prev.sky)\r\n this.loadSky();\r\n }\r\n\r\n public decorate(context: DecorateContext): void {\r\n const env = this._environment;\r\n if (env.displaySky && this._sky.params) {\r\n const sky = IModelApp.renderSystem.createSkyBox(this._sky.params);\r\n if (sky)\r\n context.setSkyBox(sky);\r\n }\r\n\r\n if (!env.displayGround || !this._ground)\r\n return;\r\n\r\n const extents = this._view.getGroundExtents(context.viewport);\r\n if (extents.isNull)\r\n return;\r\n\r\n const points: Point3d[] = [extents.low.clone(), extents.low.clone(), extents.high.clone(), extents.high.clone()];\r\n points[1].x = extents.high.x;\r\n points[3].x = extents.low.x;\r\n\r\n const aboveGround = this._view.isEyePointAbove(extents.low.z);\r\n const params = aboveGround ? this._ground.aboveParams : this._ground.belowParams;\r\n const builder = context.createGraphicBuilder(GraphicType.WorldDecoration);\r\n builder.activateGraphicParams(params);\r\n\r\n const strokeOptions = new StrokeOptions();\r\n strokeOptions.needParams = true;\r\n const polyfaceBuilder = PolyfaceBuilder.create(strokeOptions);\r\n polyfaceBuilder.toggleReversedFacetFlag();\r\n const uvParams: Point2d[] = [Point2d.create(0, 0), Point2d.create(1, 0), Point2d.create(1, 1), Point2d.create(0, 1)];\r\n polyfaceBuilder.addQuadFacet(points, uvParams);\r\n const polyface = polyfaceBuilder.claimPolyface(false);\r\n\r\n builder.addPolyface(polyface, true);\r\n context.addDecorationFromBuilder(builder);\r\n }\r\n\r\n private loadGround(): void {\r\n assert(undefined === this._ground);\r\n const aboveParams = this.createGroundParams(true);\r\n const belowParams = this.createGroundParams(false);\r\n if (aboveParams && belowParams)\r\n this._ground = { aboveParams, belowParams };\r\n }\r\n\r\n private createGroundParams(above: boolean): GraphicParams | undefined {\r\n // Create a gradient texture.\r\n const ground = this._environment.ground;\r\n const values = [0, 0.25, 0.5 ];\r\n const color = above ? ground.aboveColor : ground.belowColor;\r\n const alpha = above ? 0x80 : 0x85;\r\n const groundColors = [color.withTransparency(0xff), color, color];\r\n groundColors[1] = groundColors[2] = color.withTransparency(alpha);\r\n\r\n const gradient = new Gradient.Symb();\r\n gradient.mode = Gradient.Mode.Spherical;\r\n gradient.keys = [{ color: groundColors[0], value: values[0] }, { color: groundColors[1], value: values[1] }, { color: groundColors[2], value: values[2] }];\r\n const texture = IModelApp.renderSystem.getGradientTexture(gradient, this._view.iModel);\r\n if (!texture)\r\n return undefined;\r\n\r\n // Create a material using the gradient texture\r\n const material = IModelApp.renderSystem.createRenderMaterial({\r\n diffuse: { color: ColorDef.white, weight: 0 },\r\n textureMapping: {\r\n texture,\r\n transform: new TextureMapping.Trans2x3(0, 1, 0, 1, 0, 0),\r\n },\r\n });\r\n\r\n if (!material)\r\n return undefined;\r\n\r\n // Create GraphicParams using the material.\r\n const params = new GraphicParams();\r\n params.lineColor = gradient.keys[0].color;\r\n params.fillColor = ColorDef.white; // Fill should be set to opaque white for gradient texture...\r\n params.material = material;\r\n\r\n return params;\r\n }\r\n\r\n private loadSky(): void {\r\n const promise = this.loadSkyParams();\r\n this._sky.promise = promise;\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n promise.then((params) => {\r\n if (promise === this._sky.promise)\r\n this.setSky(params ?? this.createSkyGradientParams());\r\n });\r\n\r\n promise.catch(() => {\r\n if (this._sky.promise === promise)\r\n this.setSky(this.createSkyGradientParams());\r\n });\r\n }\r\n\r\n private setSky(params: RenderSkyBoxParams): void {\r\n this._sky.promise = undefined;\r\n this._sky.params = params;\r\n this._onLoaded();\r\n }\r\n\r\n private async loadSkyParams(): Promise<RenderSkyBoxParams | undefined> {\r\n const sky = this._environment.sky;\r\n if (sky instanceof SkyCube) {\r\n const key = this.createCubeImageKey(sky);\r\n const existingTexture = IModelApp.renderSystem.findTexture(key, this._view.iModel);\r\n if (existingTexture)\r\n return { type: \"cube\", texture: existingTexture };\r\n\r\n // Some faces may use the same image. Only request each image once.\r\n const specs = new Set<string>([sky.images.front, sky.images.back, sky.images.left, sky.images.right, sky.images.top, sky.images.bottom]);\r\n const promises = [];\r\n for (const spec of specs)\r\n promises.push(this.imageFromSpec(spec));\r\n\r\n return Promise.all(promises).then((images) => {\r\n const idToImage = new Map<TextureImageSpec, HTMLImageElement>();\r\n let index = 0;\r\n for (const spec of specs) {\r\n const image = images[index++];\r\n if (!image)\r\n return undefined;\r\n else\r\n idToImage.set(spec, image);\r\n }\r\n\r\n // eslint-disable-next-line deprecation/deprecation\r\n const params = new RenderTexture.Params(key, RenderTexture.Type.SkyBox);\r\n const txImgs = [\r\n idToImage.get(sky.images.front)!, idToImage.get(sky.images.back)!, idToImage.get(sky.images.top)!,\r\n idToImage.get(sky.images.bottom)!, idToImage.get(sky.images.right)!, idToImage.get(sky.images.left)!,\r\n ];\r\n\r\n const texture = IModelApp.renderSystem.createTextureFromCubeImages(txImgs[0], txImgs[1], txImgs[2], txImgs[3], txImgs[4], txImgs[5], this._view.iModel, params);\r\n return texture ? { type: \"cube\", texture } : undefined;\r\n });\r\n } else if (sky instanceof SkySphere) {\r\n const rotation = 0; // ###TODO where is this supposed to come from?\r\n let texture = IModelApp.renderSystem.findTexture(sky.image, this._view.iModel);\r\n if (!texture) {\r\n const image = await this.imageFromSpec(sky.image);\r\n if (image) {\r\n texture = IModelApp.renderSystem.createTexture({\r\n image: { source: image },\r\n ownership: { iModel: this._view.iModel, key: sky.image },\r\n });\r\n }\r\n }\r\n\r\n if (!texture)\r\n return undefined;\r\n\r\n return { type: \"sphere\", texture, rotation, zOffset: this._view.iModel.globalOrigin.z };\r\n } else {\r\n return this.createSkyGradientParams();\r\n }\r\n }\r\n\r\n private createCubeImageKey(sky: SkyCube): string {\r\n const i = sky.images;\r\n return `skycube:${i.front}:${i.back}:${i.left}:${i.right}:${i.top}:${i.bottom}`;\r\n }\r\n\r\n private createSkyGradientParams(): RenderSkyBoxParams {\r\n return { type: \"gradient\", gradient: this._environment.sky.gradient, zOffset: this._view.iModel.globalOrigin.z };\r\n }\r\n\r\n private async imageFromSpec(spec: TextureImageSpec): Promise<HTMLImageElement | undefined> {\r\n if (Id64.isValidId64(spec))\r\n return (await IModelApp.renderSystem.loadTextureImage(spec, this._view.iModel))?.image;\r\n\r\n return tryImageElementFromUrl(spec);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"EnvironmentDecorations.js","sourceRoot":"","sources":["../../src/EnvironmentDecorations.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAC,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAW,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EACL,QAAQ,EAAe,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAoB,cAAc,GACpH,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAsBtD,gBAAgB;AAChB,MAAM,OAAO,sBAAsB;IAQjC,YAAmB,IAAiB,EAAE,QAAoB,EAAE,SAAqB;QAC/E,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC;QAClD,IAAI,CAAC,KAA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AAC,GAAG,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;IAClF,CAAC;IAEO,uBAAuB;QAC7B,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ;YACxC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;SAC1C,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,aAAa,CAAC,IAAsB;;QAChD,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;YACxB,OAAO,MAAA,CAAC,MAAM,SAAS,CAAC,YAAY,CAAC,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,0CAAE,KAAK,CAAC;QAEzF,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;CACF","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 Views\r\n */\r\n\r\nimport { assert, Id64} from \"@itwin/core-bentley\";\r\nimport { Point2d, Point3d, PolyfaceBuilder, StrokeOptions } from \"@itwin/core-geometry\";\r\nimport {\r\n ColorDef, Environment, Gradient, GraphicParams, RenderTexture, SkyCube, SkySphere, TextureImageSpec, TextureMapping,\r\n} from \"@itwin/core-common\";\r\nimport { IModelApp } from \"./IModelApp\";\r\nimport { ViewState3d } from \"./ViewState\";\r\nimport { DecorateContext } from \"./ViewContext\";\r\nimport { tryImageElementFromUrl } from \"./ImageUtil\";\r\nimport { GraphicType } from \"./render/GraphicBuilder\";\r\nimport { RenderSkyBoxParams } from \"./render/RenderSystem\";\r\n\r\n/** @internal */\r\nexport interface GroundPlaneDecorations {\r\n readonly aboveParams: GraphicParams;\r\n readonly belowParams: GraphicParams;\r\n}\r\n\r\ninterface SkyBoxParamsLoader {\r\n // Invoke to obtain sky box params.\r\n load(): RenderSkyBoxParams | undefined;\r\n // If defined, await before invoking load().\r\n preload?: Promise<boolean>;\r\n}\r\n\r\n/** @internal */\r\nexport interface SkyBoxDecorations {\r\n params?: RenderSkyBoxParams;\r\n promise?: Promise<boolean>;\r\n}\r\n\r\n/** @internal */\r\nexport class EnvironmentDecorations {\r\n protected readonly _view: ViewState3d;\r\n protected readonly _onLoaded: () => void;\r\n protected readonly _onDispose: () => void;\r\n protected _environment: Environment;\r\n protected _ground?: GroundPlaneDecorations;\r\n protected _sky: SkyBoxDecorations;\r\n\r\n public constructor(view: ViewState3d, onLoaded: () => void, onDispose: () => void) {\r\n this._environment = view.displayStyle.environment;\r\n this._view = view;\r\n this._onLoaded = onLoaded;\r\n this._onDispose = onDispose;\r\n\r\n this._sky = { };\r\n this.loadSkyBox();\r\n if (this._environment.displayGround)\r\n this.loadGround();\r\n }\r\n\r\n public dispose(): void {\r\n this._ground = undefined;\r\n this._sky.params = this._sky.promise = undefined;\r\n\r\n this._onDispose();\r\n }\r\n\r\n public setEnvironment(env: Environment): void {\r\n const prev = this._environment;\r\n if (prev === env)\r\n return;\r\n\r\n this._environment = env;\r\n\r\n // Update ground plane\r\n if (!env.displayGround || env.ground !== prev.ground)\r\n this._ground = undefined;\r\n\r\n if (env.displayGround && !this._ground)\r\n this.loadGround();\r\n\r\n // Update sky box\r\n if (env.sky !== prev.sky)\r\n this.loadSkyBox();\r\n }\r\n\r\n public decorate(context: DecorateContext): void {\r\n const env = this._environment;\r\n if (env.displaySky && this._sky.params) {\r\n const sky = IModelApp.renderSystem.createSkyBox(this._sky.params);\r\n if (sky)\r\n context.setSkyBox(sky);\r\n }\r\n\r\n if (!env.displayGround || !this._ground)\r\n return;\r\n\r\n const extents = this._view.getGroundExtents(context.viewport);\r\n if (extents.isNull)\r\n return;\r\n\r\n const points: Point3d[] = [extents.low.clone(), extents.low.clone(), extents.high.clone(), extents.high.clone()];\r\n points[1].x = extents.high.x;\r\n points[3].x = extents.low.x;\r\n\r\n const aboveGround = this._view.isEyePointAbove(extents.low.z);\r\n const params = aboveGround ? this._ground.aboveParams : this._ground.belowParams;\r\n const builder = context.createGraphicBuilder(GraphicType.WorldDecoration);\r\n builder.activateGraphicParams(params);\r\n\r\n const strokeOptions = new StrokeOptions();\r\n strokeOptions.needParams = true;\r\n const polyfaceBuilder = PolyfaceBuilder.create(strokeOptions);\r\n polyfaceBuilder.toggleReversedFacetFlag();\r\n const uvParams: Point2d[] = [Point2d.create(0, 0), Point2d.create(1, 0), Point2d.create(1, 1), Point2d.create(0, 1)];\r\n polyfaceBuilder.addQuadFacet(points, uvParams);\r\n const polyface = polyfaceBuilder.claimPolyface(false);\r\n\r\n builder.addPolyface(polyface, true);\r\n context.addDecorationFromBuilder(builder);\r\n }\r\n\r\n private loadGround(): void {\r\n assert(undefined === this._ground);\r\n const aboveParams = this.createGroundParams(true);\r\n const belowParams = this.createGroundParams(false);\r\n if (aboveParams && belowParams)\r\n this._ground = { aboveParams, belowParams };\r\n }\r\n\r\n private createGroundParams(above: boolean): GraphicParams | undefined {\r\n // Create a gradient texture.\r\n const ground = this._environment.ground;\r\n const values = [0, 0.25, 0.5 ];\r\n const color = above ? ground.aboveColor : ground.belowColor;\r\n const alpha = above ? 0x80 : 0x85;\r\n const groundColors = [color.withTransparency(0xff), color, color];\r\n groundColors[1] = groundColors[2] = color.withTransparency(alpha);\r\n\r\n const gradient = new Gradient.Symb();\r\n gradient.mode = Gradient.Mode.Spherical;\r\n gradient.keys = [{ color: groundColors[0], value: values[0] }, { color: groundColors[1], value: values[1] }, { color: groundColors[2], value: values[2] }];\r\n const texture = IModelApp.renderSystem.getGradientTexture(gradient, this._view.iModel);\r\n if (!texture)\r\n return undefined;\r\n\r\n // Create a material using the gradient texture\r\n const material = IModelApp.renderSystem.createRenderMaterial({\r\n diffuse: { color: ColorDef.white, weight: 0 },\r\n textureMapping: {\r\n texture,\r\n transform: new TextureMapping.Trans2x3(0, 1, 0, 1, 0, 0),\r\n },\r\n });\r\n\r\n if (!material)\r\n return undefined;\r\n\r\n // Create GraphicParams using the material.\r\n const params = new GraphicParams();\r\n params.lineColor = gradient.keys[0].color;\r\n params.fillColor = ColorDef.white; // Fill should be set to opaque white for gradient texture...\r\n params.material = material;\r\n\r\n return params;\r\n }\r\n\r\n private loadSkyBox(): void {\r\n const loader = this.loadSkyBoxParams();\r\n if (undefined === loader.preload) {\r\n this.setSky(loader.load());\r\n return;\r\n }\r\n\r\n const promise = loader.preload;\r\n this._sky.promise = promise;\r\n loader.preload.then((loaded) => {\r\n if (promise === this._sky.promise)\r\n this.setSky(loaded ? loader.load() : undefined);\r\n }).catch(() => {\r\n if (promise === this._sky.promise)\r\n this.setSky(undefined);\r\n });\r\n }\r\n\r\n private setSky(params: RenderSkyBoxParams | undefined): void {\r\n this._sky.promise = undefined;\r\n this._sky.params = params ?? this.createSkyGradientParams();\r\n this._onLoaded();\r\n }\r\n\r\n private loadSkyBoxParams(): SkyBoxParamsLoader {\r\n let load: (() => RenderSkyBoxParams | undefined);\r\n let preload: Promise<boolean> | undefined;\r\n\r\n const sky = this._environment.sky;\r\n if (sky instanceof SkyCube) {\r\n const key = this.createCubeImageKey(sky);\r\n load = () => {\r\n const texture = IModelApp.renderSystem.findTexture(key, this._view.iModel);\r\n return texture ? { type: \"cube\", texture } : undefined;\r\n };\r\n\r\n if (!IModelApp.renderSystem.findTexture(key, this._view.iModel)) {\r\n // Some faces may use the same image. Only request each image once.\r\n const promises = [];\r\n const specs = new Set<string>([sky.images.front, sky.images.back, sky.images.left, sky.images.right, sky.images.top, sky.images.bottom]);\r\n for (const spec of specs)\r\n promises.push(this.imageFromSpec(spec));\r\n\r\n preload = Promise.all(promises).then((images) => {\r\n const idToImage = new Map<TextureImageSpec, HTMLImageElement>();\r\n let index = 0;\r\n for (const spec of specs) {\r\n const image = images[index++];\r\n if (!image)\r\n return false;\r\n else\r\n idToImage.set(spec, image);\r\n }\r\n\r\n // eslint-disable-next-line deprecation/deprecation\r\n const params = new RenderTexture.Params(key, RenderTexture.Type.SkyBox);\r\n const txImgs = [\r\n idToImage.get(sky.images.front)!, idToImage.get(sky.images.back)!, idToImage.get(sky.images.top)!,\r\n idToImage.get(sky.images.bottom)!, idToImage.get(sky.images.right)!, idToImage.get(sky.images.left)!,\r\n ];\r\n\r\n return undefined !== IModelApp.renderSystem.createTextureFromCubeImages(txImgs[0], txImgs[1], txImgs[2], txImgs[3], txImgs[4], txImgs[5], this._view.iModel, params);\r\n });\r\n }\r\n } else if (sky instanceof SkySphere) {\r\n load = () => {\r\n const texture = IModelApp.renderSystem.findTexture(sky.image, this._view.iModel);\r\n return texture ? {\r\n type: \"sphere\",\r\n texture,\r\n rotation: 0,\r\n zOffset: this._view.iModel.globalOrigin.z,\r\n } : undefined;\r\n };\r\n\r\n if (!IModelApp.renderSystem.findTexture(sky.image, this._view.iModel)) {\r\n preload = this.imageFromSpec(sky.image).then((image) => {\r\n if (!image)\r\n return false;\r\n\r\n return undefined !== IModelApp.renderSystem.createTexture({\r\n image: { source: image },\r\n ownership: { iModel: this._view.iModel, key: sky.image },\r\n });\r\n });\r\n }\r\n } else {\r\n load = () => this.createSkyGradientParams();\r\n }\r\n\r\n return { load, preload };\r\n }\r\n\r\n private createCubeImageKey(sky: SkyCube): string {\r\n const i = sky.images;\r\n return `skycube:${i.front}:${i.back}:${i.left}:${i.right}:${i.top}:${i.bottom}`;\r\n }\r\n\r\n private createSkyGradientParams(): RenderSkyBoxParams {\r\n return {\r\n type: \"gradient\",\r\n gradient: this._environment.sky.gradient,\r\n zOffset: this._view.iModel.globalOrigin.z,\r\n };\r\n }\r\n\r\n private async imageFromSpec(spec: TextureImageSpec): Promise<HTMLImageElement | undefined> {\r\n if (Id64.isValidId64(spec))\r\n return (await IModelApp.renderSystem.loadTextureImage(spec, this._view.iModel))?.image;\r\n\r\n return tryImageElementFromUrl(spec);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphicalEditingScope.d.ts","sourceRoot":"","sources":["../../src/GraphicalEditingScope.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAU,OAAO,
|
|
1
|
+
{"version":3,"file":"GraphicalEditingScope.d.ts","sourceRoot":"","sources":["../../src/GraphicalEditingScope.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAU,OAAO,EAAkE,UAAU,EAAe,MAAM,qBAAqB,CAAC;AAE/I,OAAO,EACL,yBAAyB,EAAE,qBAAqB,EAAE,aAAa,EAAE,oBAAoB,EAAE,yBAAyB,EACjH,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAc5D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,qBAAsB,SAAQ,4BAA6B,YAAW,yBAAyB;IAC1G,IAAW,oBAAoB,kBAAyC;IAExE,8FAA8F;IAC9F,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAuC;IACxE,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,CAAiB;IAElC,iDAAiD;IACjD,SAAgB,MAAM,EAAE,mBAAmB,CAAC;IAE5C;;OAEG;IACH,gBAAuB,OAAO,kBAAuB,qBAAqB,KAAK,IAAI,EAAI;IAEvF;;;OAGG;IACH,SAAgB,SAAS,kBAAuB,qBAAqB,KAAK,IAAI,EAAI;IAElF;;;OAGG;IACH,SAAgB,QAAQ,kBAAuB,qBAAqB,KAAK,IAAI,EAAI;IAEjF,sEAAsE;IACtE,SAAgB,iBAAiB,oBAAyB,SAAS,oBAAoB,CAAC,SAAS,qBAAqB,KAAK,IAAI,EAAI;IAEnI;;OAEG;WACiB,KAAK,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAmBtF;;;OAGG;IACU,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBlC,yGAAyG;IAClG,0BAA0B,CAAC,OAAO,EAAE,UAAU,GAAG,QAAQ,CAAC,qBAAqB,CAAC,GAAG,SAAS;IAInG,4EAA4E;IACrE,kBAAkB,IAAI,QAAQ,CAAC,oBAAoB,CAAC;IAI3D,gBAAgB;IAChB,IAAW,UAAU,YAEpB;IAED,OAAO,CAAG,sBAAsB;IAWhC,OAAO;IAMP,OAAO,CAAC,OAAO;IAef,gBAAgB;IACT,qBAAqB,CAAC,KAAK,EAAE,yBAAyB,EAAE;CAiChE"}
|
|
@@ -142,6 +142,7 @@ export class GraphicalEditingScope extends BriefcaseNotificationHandler {
|
|
|
142
142
|
notifyGeometryChanged(props) {
|
|
143
143
|
const changes = ModelGeometryChanges.iterable(props);
|
|
144
144
|
const modelIds = [];
|
|
145
|
+
let deletedIds;
|
|
145
146
|
for (const modelChanges of changes) {
|
|
146
147
|
// ###TODO do we care about the model range?
|
|
147
148
|
let list = this._geometryChanges.get(modelChanges.id);
|
|
@@ -156,11 +157,16 @@ export class GraphicalEditingScope extends BriefcaseNotificationHandler {
|
|
|
156
157
|
}
|
|
157
158
|
list.insert(elementChange);
|
|
158
159
|
if (DbOpcode.Delete === elementChange.type) {
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
if (undefined === deletedIds)
|
|
161
|
+
deletedIds = new Set();
|
|
162
|
+
deletedIds.add(elementChange.id);
|
|
161
163
|
}
|
|
162
164
|
}
|
|
163
165
|
}
|
|
166
|
+
if (deletedIds) {
|
|
167
|
+
this.iModel.selectionSet.remove(deletedIds);
|
|
168
|
+
this.iModel.hilited.setHilite(deletedIds, false);
|
|
169
|
+
}
|
|
164
170
|
this.onGeometryChanges.raiseEvent(changes, this);
|
|
165
171
|
}
|
|
166
172
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphicalEditingScope.js","sourceRoot":"","sources":["../../src/Graphical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I,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;YACtD,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;YAC/B,KAAK,MAAM,aAAa,IAAI,YAAY,CAAC,QAAQ,EAAE;gBACjD,IAAI,CAAC,IAAI,EAAE;oBACT,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,EAAE,IAAI,GAAG,IAAI,YAAY,CAAC,YAAY,CAAC,YAAY,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;iBACpH;qBAAM;oBACL,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC,YAAY,CAAC;oBAC9C,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBACtC;gBAED,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;gBAC3B,IAAI,QAAQ,CAAC,MAAM,KAAK,aAAa,CAAC,IAAI,EAAE;oBAC1C,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;oBAClD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;iBACxD;aACF;SACF;QAED,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;;AAxID;;GAEG;AACoB,6BAAO,GAAG,IAAI,OAAO,EAA0C,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 IModelConnection\r\n */\r\n\r\nimport { assert, BeEvent, compareStrings, DbOpcode, DuplicatePolicy, GuidString, Id64String, SortedArray } from \"@itwin/core-bentley\";\r\nimport { Range3d } from \"@itwin/core-geometry\";\r\nimport {\r\n EditingScopeNotifications, ElementGeometryChange, IpcAppChannel, ModelGeometryChanges, ModelGeometryChangesProps, RemoveFunction,\r\n} from \"@itwin/core-common\";\r\nimport { BriefcaseNotificationHandler } from \"./BriefcaseTxns\";\r\nimport { BriefcaseConnection } from \"./BriefcaseConnection\";\r\nimport { IpcApp } from \"./IpcApp\";\r\n\r\nclass ModelChanges extends SortedArray<ElementGeometryChange> {\r\n public geometryGuid: GuidString;\r\n public readonly range: Range3d;\r\n\r\n public constructor(geometryGuid: GuidString, range: Range3d) {\r\n super((lhs, rhs) => compareStrings(lhs.id, rhs.id), DuplicatePolicy.Replace);\r\n this.geometryGuid = geometryGuid;\r\n this.range = range;\r\n }\r\n}\r\n\r\n/** Represents a period of time within an [interactive editing]($docs/learning/InteractiveEditing.md) session during which the\r\n * geometry of elements being displayed in one or more [[Viewport]]s is being modified. Outside of such a scope, whenever the\r\n * geometry within a [GeometricModel]($backend) changes new [[Tile]]s must be generated to reflect those changes in a viewport.\r\n * Regenerating entire tiles each time individual elements change can be time-consuming, which may introduce an unacceptable delay\r\n * between making a modification and seeing its result on the screen.\r\n *\r\n * Within the context of a graphical editing scope, no new tiles are generated. Instead, the geometry for any deleted or modified elements\r\n * is hidden in the tile graphics, and additional temporary graphics are displayed for any newly-inserted or modified elements. Only when the\r\n * scope exits are new tiles produced.\r\n *\r\n * The application decides when to enter and exit a graphical editing scope. A single interactive editing session may involve any number of\r\n * editing scopes. Typically, applications will enter a new editing scope (after first exiting a previous scope, if one exists):\r\n * - When switching from a non-graphical workflow to one that involves editing geometry; or\r\n * - When changing which geometric model is being edited; or\r\n * - After performing an operation that creates or modifies a \"large\" number (perhaps hundreds?) of elements.\r\n *\r\n * An application should typically exit any graphical editing scope before:\r\n * - Pulling changesets; or\r\n * - Switching from a graphical editing workflow to some non-graphical workflow.\r\n *\r\n * Graphical editing scopes are only supported for [[BriefcaseConnection]]s opened in read-write mode that contain version 1.0.11 or newer of the BisCore schema.\r\n * @see [[BriefcaseConnection.enterEditingScope]] to create a scope for a briefcase.\r\n * @see [[BriefcaseConnection.editingScope]] to obtain a briefcase's current scope.\r\n * @see [[exit]] to terminate a scope.\r\n * @public\r\n */\r\nexport class GraphicalEditingScope extends BriefcaseNotificationHandler implements EditingScopeNotifications {\r\n public get briefcaseChannelName() { return IpcAppChannel.EditingScope; }\r\n\r\n /** Maps model Id to accumulated changes to geometric elements within the associated model. */\r\n private readonly _geometryChanges = new Map<Id64String, ModelChanges>();\r\n private _disposed = false;\r\n private _cleanup?: RemoveFunction;\r\n\r\n /** The connection to the iModel being edited. */\r\n public readonly iModel: BriefcaseConnection;\r\n\r\n /** Event raised when a new scope is created for any [[BriefcaseConnection]].\r\n * @see [[onExiting]] and [[onExited]] for complementary events.\r\n */\r\n public static readonly onEnter = new BeEvent<(scope: GraphicalEditingScope) => void>();\r\n\r\n /** Event raised when this scope is about to exit.\r\n * @see [[onEnter]] for the complementary event.\r\n * @see [[onExited]] for an event raised after the scope exits.\r\n */\r\n public readonly onExiting = new BeEvent<(scope: GraphicalEditingScope) => void>();\r\n\r\n /** Event raised when this scope has exited.\r\n * @see [[onEnter]] for the complementary event.\r\n * @see [[onExiting]] for an event raised just before the scope is exited.\r\n */\r\n public readonly onExited = new BeEvent<(scope: GraphicalEditingScope) => void>();\r\n\r\n /** Event raised after geometric changes are written to the iModel. */\r\n public readonly onGeometryChanges = new BeEvent<(changes: Iterable<ModelGeometryChanges>, scope: GraphicalEditingScope) => void>();\r\n\r\n /** Don't call this directly - use BriefcaseConnection.enterEditingScope.\r\n * @internal\r\n */\r\n public static async enter(imodel: BriefcaseConnection): Promise<GraphicalEditingScope> {\r\n if (imodel.editingScope)\r\n throw new Error(\"Cannot create an editing scope for an iModel that already has one\");\r\n\r\n // Register the scope synchronously, in case enter() is called again for same iModel while awaiting asynchronous initialization.\r\n const scope = new GraphicalEditingScope(imodel);\r\n try {\r\n const scopeStarted = await IpcApp.appFunctionIpc.toggleGraphicalEditingScope(imodel.key, true);\r\n assert(scopeStarted); // If it didn't, the backend threw an error.\r\n } catch (e) {\r\n scope.dispose();\r\n throw e;\r\n }\r\n\r\n this.onEnter.raiseEvent(scope);\r\n\r\n return scope;\r\n }\r\n\r\n /** Exits this editing scope. The associated [[BriefcaseConnection]]'s `editingScope` will be reset to `undefined`.\r\n * @throws Error if the scope could not be exited, e.g., if it has already been exited.\r\n * @see [[BriefcaseConnection.enterEditingScope]] to enter an editing scope.\r\n */\r\n public async exit(): Promise<void> {\r\n if (this._disposed || this.iModel.editingScope !== this)\r\n throw new Error(\"Cannot exit editing scope after it is disconnected from the iModel\");\r\n\r\n this._disposed = true;\r\n try {\r\n this.onExiting.raiseEvent(this);\r\n } finally {\r\n const scopeExited = await IpcApp.appFunctionIpc.toggleGraphicalEditingScope(this.iModel.key, false);\r\n assert(!scopeExited);\r\n try {\r\n this.onExited.raiseEvent(this);\r\n } finally {\r\n this.dispose();\r\n }\r\n }\r\n }\r\n\r\n /** Obtain all geometric changes to elements within the specified model accumulated within this scope. */\r\n public getGeometryChangesForModel(modelId: Id64String): Iterable<ElementGeometryChange> | undefined {\r\n return this._geometryChanges.get(modelId);\r\n }\r\n\r\n /** Obtain all geometric changes to models accumulated within this scope. */\r\n public getGeometryChanges(): Iterable<ModelGeometryChanges> {\r\n return { [Symbol.iterator]: () => this.geometryChangeIterator() };\r\n }\r\n\r\n /** @internal */\r\n public get isDisposed() {\r\n return this._disposed;\r\n }\r\n\r\n private * geometryChangeIterator(): Iterator<ModelGeometryChanges> {\r\n for (const [key, value] of this._geometryChanges) {\r\n yield {\r\n id: key,\r\n geometryGuid: value.geometryGuid,\r\n range: value.range,\r\n elements: value,\r\n };\r\n }\r\n }\r\n\r\n private constructor(iModel: BriefcaseConnection) {\r\n super(iModel.key);\r\n this.iModel = iModel;\r\n this._cleanup = this.registerImpl();\r\n }\r\n\r\n private dispose(): void {\r\n this._disposed = true;\r\n\r\n this.onExiting.clear();\r\n this.onGeometryChanges.clear();\r\n this.onExited.clear();\r\n\r\n this._geometryChanges.clear();\r\n\r\n if (this._cleanup) {\r\n this._cleanup();\r\n this._cleanup = undefined;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public notifyGeometryChanged(props: ModelGeometryChangesProps[]) {\r\n const changes = ModelGeometryChanges.iterable(props);\r\n const modelIds: Id64String[] = [];\r\n for (const modelChanges of changes) {\r\n // ###TODO do we care about the model range?\r\n let list = this._geometryChanges.get(modelChanges.id);\r\n modelIds.push(modelChanges.id);\r\n for (const elementChange of modelChanges.elements) {\r\n if (!list) {\r\n this._geometryChanges.set(modelChanges.id, list = new ModelChanges(modelChanges.geometryGuid, modelChanges.range));\r\n } else {\r\n list.geometryGuid = modelChanges.geometryGuid;\r\n modelChanges.range.clone(list.range);\r\n }\r\n\r\n list.insert(elementChange);\r\n if (DbOpcode.Delete === elementChange.type) {\r\n this.iModel.selectionSet.remove(elementChange.id);\r\n this.iModel.hilited.setHilite(elementChange.id, false);\r\n }\r\n }\r\n }\r\n\r\n this.onGeometryChanges.raiseEvent(changes, this);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"GraphicalEditingScope.js","sourceRoot":"","sources":["../../src/GraphicalEditingScope.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,eAAe,EAAmC,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE/I,OAAO,EAC6C,aAAa,EAAE,oBAAoB,GACtF,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,MAAM,YAAa,SAAQ,WAAkC;IAI3D,YAAmB,YAAwB,EAAE,KAAc;QACzD,KAAK,CAAC,CAAC,GAAG,EAAE,GAAG,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,GAAG,YAAY,CAAC,YAAY,CAAC;oBAC9C,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBACtC;gBAED,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;gBAC3B,IAAI,QAAQ,CAAC,MAAM,KAAK,aAAa,CAAC,IAAI,EAAE;oBAC1C,IAAI,SAAS,KAAK,UAAU;wBAC1B,UAAU,GAAG,IAAI,GAAG,EAAc,CAAC;oBACrC,UAAU,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;iBAClC;aACF;SACF;QAED,IAAI,UAAU,EAAE;YACd,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAC5C,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;SAClD;QAED,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;;AAhJD;;GAEG;AACoB,6BAAO,GAAG,IAAI,OAAO,EAA0C,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 IModelConnection\r\n */\r\n\r\nimport { assert, BeEvent, compareStrings, DbOpcode, DuplicatePolicy, GuidString, Id64Set, Id64String, SortedArray } from \"@itwin/core-bentley\";\r\nimport { Range3d } from \"@itwin/core-geometry\";\r\nimport {\r\n EditingScopeNotifications, ElementGeometryChange, IpcAppChannel, ModelGeometryChanges, ModelGeometryChangesProps, RemoveFunction,\r\n} from \"@itwin/core-common\";\r\nimport { BriefcaseNotificationHandler } from \"./BriefcaseTxns\";\r\nimport { BriefcaseConnection } from \"./BriefcaseConnection\";\r\nimport { IpcApp } from \"./IpcApp\";\r\n\r\nclass ModelChanges extends SortedArray<ElementGeometryChange> {\r\n public geometryGuid: GuidString;\r\n public readonly range: Range3d;\r\n\r\n public constructor(geometryGuid: GuidString, range: Range3d) {\r\n super((lhs, rhs) => compareStrings(lhs.id, rhs.id), DuplicatePolicy.Replace);\r\n this.geometryGuid = geometryGuid;\r\n this.range = range;\r\n }\r\n}\r\n\r\n/** Represents a period of time within an [interactive editing]($docs/learning/InteractiveEditing.md) session during which the\r\n * geometry of elements being displayed in one or more [[Viewport]]s is being modified. Outside of such a scope, whenever the\r\n * geometry within a [GeometricModel]($backend) changes new [[Tile]]s must be generated to reflect those changes in a viewport.\r\n * Regenerating entire tiles each time individual elements change can be time-consuming, which may introduce an unacceptable delay\r\n * between making a modification and seeing its result on the screen.\r\n *\r\n * Within the context of a graphical editing scope, no new tiles are generated. Instead, the geometry for any deleted or modified elements\r\n * is hidden in the tile graphics, and additional temporary graphics are displayed for any newly-inserted or modified elements. Only when the\r\n * scope exits are new tiles produced.\r\n *\r\n * The application decides when to enter and exit a graphical editing scope. A single interactive editing session may involve any number of\r\n * editing scopes. Typically, applications will enter a new editing scope (after first exiting a previous scope, if one exists):\r\n * - When switching from a non-graphical workflow to one that involves editing geometry; or\r\n * - When changing which geometric model is being edited; or\r\n * - After performing an operation that creates or modifies a \"large\" number (perhaps hundreds?) of elements.\r\n *\r\n * An application should typically exit any graphical editing scope before:\r\n * - Pulling changesets; or\r\n * - Switching from a graphical editing workflow to some non-graphical workflow.\r\n *\r\n * Graphical editing scopes are only supported for [[BriefcaseConnection]]s opened in read-write mode that contain version 1.0.11 or newer of the BisCore schema.\r\n * @see [[BriefcaseConnection.enterEditingScope]] to create a scope for a briefcase.\r\n * @see [[BriefcaseConnection.editingScope]] to obtain a briefcase's current scope.\r\n * @see [[exit]] to terminate a scope.\r\n * @public\r\n */\r\nexport class GraphicalEditingScope extends BriefcaseNotificationHandler implements EditingScopeNotifications {\r\n public get briefcaseChannelName() { return IpcAppChannel.EditingScope; }\r\n\r\n /** Maps model Id to accumulated changes to geometric elements within the associated model. */\r\n private readonly _geometryChanges = new Map<Id64String, ModelChanges>();\r\n private _disposed = false;\r\n private _cleanup?: RemoveFunction;\r\n\r\n /** The connection to the iModel being edited. */\r\n public readonly iModel: BriefcaseConnection;\r\n\r\n /** Event raised when a new scope is created for any [[BriefcaseConnection]].\r\n * @see [[onExiting]] and [[onExited]] for complementary events.\r\n */\r\n public static readonly onEnter = new BeEvent<(scope: GraphicalEditingScope) => void>();\r\n\r\n /** Event raised when this scope is about to exit.\r\n * @see [[onEnter]] for the complementary event.\r\n * @see [[onExited]] for an event raised after the scope exits.\r\n */\r\n public readonly onExiting = new BeEvent<(scope: GraphicalEditingScope) => void>();\r\n\r\n /** Event raised when this scope has exited.\r\n * @see [[onEnter]] for the complementary event.\r\n * @see [[onExiting]] for an event raised just before the scope is exited.\r\n */\r\n public readonly onExited = new BeEvent<(scope: GraphicalEditingScope) => void>();\r\n\r\n /** Event raised after geometric changes are written to the iModel. */\r\n public readonly onGeometryChanges = new BeEvent<(changes: Iterable<ModelGeometryChanges>, scope: GraphicalEditingScope) => void>();\r\n\r\n /** Don't call this directly - use BriefcaseConnection.enterEditingScope.\r\n * @internal\r\n */\r\n public static async enter(imodel: BriefcaseConnection): Promise<GraphicalEditingScope> {\r\n if (imodel.editingScope)\r\n throw new Error(\"Cannot create an editing scope for an iModel that already has one\");\r\n\r\n // Register the scope synchronously, in case enter() is called again for same iModel while awaiting asynchronous initialization.\r\n const scope = new GraphicalEditingScope(imodel);\r\n try {\r\n const scopeStarted = await IpcApp.appFunctionIpc.toggleGraphicalEditingScope(imodel.key, true);\r\n assert(scopeStarted); // If it didn't, the backend threw an error.\r\n } catch (e) {\r\n scope.dispose();\r\n throw e;\r\n }\r\n\r\n this.onEnter.raiseEvent(scope);\r\n\r\n return scope;\r\n }\r\n\r\n /** Exits this editing scope. The associated [[BriefcaseConnection]]'s `editingScope` will be reset to `undefined`.\r\n * @throws Error if the scope could not be exited, e.g., if it has already been exited.\r\n * @see [[BriefcaseConnection.enterEditingScope]] to enter an editing scope.\r\n */\r\n public async exit(): Promise<void> {\r\n if (this._disposed || this.iModel.editingScope !== this)\r\n throw new Error(\"Cannot exit editing scope after it is disconnected from the iModel\");\r\n\r\n this._disposed = true;\r\n try {\r\n this.onExiting.raiseEvent(this);\r\n } finally {\r\n const scopeExited = await IpcApp.appFunctionIpc.toggleGraphicalEditingScope(this.iModel.key, false);\r\n assert(!scopeExited);\r\n try {\r\n this.onExited.raiseEvent(this);\r\n } finally {\r\n this.dispose();\r\n }\r\n }\r\n }\r\n\r\n /** Obtain all geometric changes to elements within the specified model accumulated within this scope. */\r\n public getGeometryChangesForModel(modelId: Id64String): Iterable<ElementGeometryChange> | undefined {\r\n return this._geometryChanges.get(modelId);\r\n }\r\n\r\n /** Obtain all geometric changes to models accumulated within this scope. */\r\n public getGeometryChanges(): Iterable<ModelGeometryChanges> {\r\n return { [Symbol.iterator]: () => this.geometryChangeIterator() };\r\n }\r\n\r\n /** @internal */\r\n public get isDisposed() {\r\n return this._disposed;\r\n }\r\n\r\n private * geometryChangeIterator(): Iterator<ModelGeometryChanges> {\r\n for (const [key, value] of this._geometryChanges) {\r\n yield {\r\n id: key,\r\n geometryGuid: value.geometryGuid,\r\n range: value.range,\r\n elements: value,\r\n };\r\n }\r\n }\r\n\r\n private constructor(iModel: BriefcaseConnection) {\r\n super(iModel.key);\r\n this.iModel = iModel;\r\n this._cleanup = this.registerImpl();\r\n }\r\n\r\n private dispose(): void {\r\n this._disposed = true;\r\n\r\n this.onExiting.clear();\r\n this.onGeometryChanges.clear();\r\n this.onExited.clear();\r\n\r\n this._geometryChanges.clear();\r\n\r\n if (this._cleanup) {\r\n this._cleanup();\r\n this._cleanup = undefined;\r\n }\r\n }\r\n\r\n /** @internal */\r\n public notifyGeometryChanged(props: ModelGeometryChangesProps[]) {\r\n const changes = ModelGeometryChanges.iterable(props);\r\n const modelIds: Id64String[] = [];\r\n let deletedIds: Id64Set | undefined;\r\n\r\n for (const modelChanges of changes) {\r\n // ###TODO do we care about the model range?\r\n let list = this._geometryChanges.get(modelChanges.id);\r\n modelIds.push(modelChanges.id);\r\n for (const elementChange of modelChanges.elements) {\r\n if (!list) {\r\n this._geometryChanges.set(modelChanges.id, list = new ModelChanges(modelChanges.geometryGuid, modelChanges.range));\r\n } else {\r\n list.geometryGuid = modelChanges.geometryGuid;\r\n modelChanges.range.clone(list.range);\r\n }\r\n\r\n list.insert(elementChange);\r\n if (DbOpcode.Delete === elementChange.type) {\r\n if (undefined === deletedIds)\r\n deletedIds = new Set<Id64String>();\r\n deletedIds.add(elementChange.id);\r\n }\r\n }\r\n }\r\n\r\n if (deletedIds) {\r\n this.iModel.selectionSet.remove(deletedIds);\r\n this.iModel.hilited.setHilite(deletedIds, false);\r\n }\r\n\r\n this.onGeometryChanges.raiseEvent(changes, this);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionSet.d.ts","sourceRoot":"","sources":["../../src/SelectionSet.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;;GAGG;AACH,oBAAY,qBAAqB;IAC/B,2CAA2C;IAC3C,GAAG,IAAA;IACH,+CAA+C;IAC/C,MAAM,IAAA;IACN,6EAA6E;IAC7E,OAAO,IAAA;IACP,yDAAyD;IACzD,KAAK,IAAA;CACN;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,qBAAqB,CAAC,GAAG,CAAC;IAChC,gDAAgD;IAChD,KAAK,EAAE,OAAO,CAAC;IACf,iCAAiC;IACjC,GAAG,EAAE,YAAY,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,sDAAsD;IACtD,IA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,iBAAiB,KAAK,IAAI,EAAI;gBAEjD,MAAM,EAAE,gBAAgB;IAElD,OAAO,CAAC,gBAAgB;IAKxB,uDAAuD;IACvD,IAAW,IAAI,WAAiC;IAEhD,qDAAqD;IACrD,IAAW,QAAQ,YAA8B;IAEjD;;OAEG;IACI,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM;IAE1B;;OAEG;IACI,UAAU,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO;IAE/C;;OAEG;IACI,QAAQ,IAAI,IAAI;IASvB;;;;OAIG;IACI,GAAG,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO;IAIlC,OAAO,CAAC,IAAI;IAYZ;;;;OAIG;IACI,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO;IAIrC,OAAO,CAAC,OAAO;IAYf;;;OAGG;IACI,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO;IAc7D,2DAA2D;IACpD,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO;IAarC,0DAA0D;IACnD,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;CAiBpC"}
|
package/lib/esm/SelectionSet.js
CHANGED
|
@@ -164,13 +164,15 @@ export class HiliteSet {
|
|
|
164
164
|
* @param onOff True to add the elements to the hilited set, false to remove them.
|
|
165
165
|
*/
|
|
166
166
|
setHilite(arg, onOff) {
|
|
167
|
+
const oldSize = this.elements.size;
|
|
167
168
|
for (const id of Id64.iterable(arg)) {
|
|
168
169
|
if (onOff)
|
|
169
170
|
this.elements.addId(id);
|
|
170
171
|
else
|
|
171
172
|
this.elements.deleteId(id);
|
|
172
173
|
}
|
|
173
|
-
|
|
174
|
+
if (oldSize !== this.elements.size)
|
|
175
|
+
IModelApp.viewManager.onSelectionSetChanged(this.iModel);
|
|
174
176
|
}
|
|
175
177
|
}
|
|
176
178
|
/** A set of *currently selected* elements for an IModelConnection.
|
|
@@ -1 +1 @@
|
|
|
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,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAEvB,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE;YACpB,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;gBACpC,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;oBACjB,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;aACtB;SACF;QAED,IAAI,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,qBAAqB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAClG,CAAC;CACF;AAED,SAAS,QAAQ,CAAC,GAAgB,EAAE,GAAY;IAC9C,wDAAwD;IACxD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QACpB,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAE1B,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QAC/B,OAAO,KAAK,CAAC;IAEf,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QACjC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACd,OAAO,KAAK,CAAC;IAEjB,OAAO,IAAI,CAAC;AACd,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 SelectionSet\r\n */\r\nimport { BeEvent, Id64, Id64Arg, Id64String } from \"@itwin/core-bentley\";\r\nimport { IModelApp } from \"./IModelApp\";\r\nimport { IModelConnection } from \"./IModelConnection\";\r\n\r\n/** Identifies the type of changes made to the [[SelectionSet]] to produce a [[SelectionSetEvent]].\r\n * @public\r\n * @extensions\r\n */\r\nexport enum SelectionSetEventType {\r\n /** Elements have been added to the set. */\r\n Add,\r\n /** Elements have been removed from the set. */\r\n Remove,\r\n /** Some elements have been added to the set and others have been removed. */\r\n Replace,\r\n /** All elements are about to be removed from the set. */\r\n Clear,\r\n}\r\n\r\n/** Passed to [[SelectionSet.onChanged]] event listeners when elements are added to the selection set.\r\n * @public\r\n * @extensions\r\n */\r\nexport interface SelectAddEvent {\r\n type: SelectionSetEventType.Add;\r\n /** The Ids of the elements added to the set. */\r\n added: Id64Arg;\r\n /** The affected SelectionSet. */\r\n set: SelectionSet;\r\n}\r\n\r\n/** Passed to [[SelectionSet.onChanged]] event listeners when elements are removed from the selection set.\r\n * @public\r\n * @extensions\r\n */\r\nexport interface SelectRemoveEvent {\r\n /** The type of operation that produced this event. */\r\n type: SelectionSetEventType.Remove | SelectionSetEventType.Clear;\r\n /** The element Ids removed from the set. */\r\n removed: Id64Arg;\r\n /** The affected SelectionSet. */\r\n set: SelectionSet;\r\n}\r\n\r\n/** Passed to [[SelectionSet.onChanged]] event listeners when elements are simultaneously added to and removed from the selection set.\r\n * @public\r\n * @extensions\r\n */\r\nexport interface SelectReplaceEvent {\r\n type: SelectionSetEventType.Replace;\r\n /** The element Ids added to the set. */\r\n added: Id64Arg;\r\n /** The element Ids removed from the set. */\r\n removed: Id64Arg;\r\n /** The affected SelectionSet. */\r\n set: SelectionSet;\r\n}\r\n\r\n/** Payload sent to [[SelectionSet.onChanged]] event listeners to describe how the contents of the set have changed.\r\n * The `type` property of the event serves as a type assertion. For example, the following code will output the added and/or removed Ids:\r\n * ```ts\r\n * processSelectionSetEvent(ev: SelectionSetEvent): void {\r\n * if (SelectionSetEventType.Add === ev.type || SelectionSetEventType.Replace === ev.type)\r\n * console.log(\"Added \" + ev.added.size + \" elements\");\r\n *\r\n * if (SelectionSetEventType.Add !== ev.type)\r\n * console.log(\"Removed \" + ev.removed.size + \" elements\");\r\n * }\r\n * ```\r\n * @public\r\n * @extensions\r\n */\r\nexport type SelectionSetEvent = SelectAddEvent | SelectRemoveEvent | SelectReplaceEvent;\r\n\r\n/** Tracks a set of hilited entities. When the set changes, notifies ViewManager so that symbology overrides can be updated in active Viewports.\r\n * @internal\r\n */\r\nclass HilitedIds extends Id64.Uint32Set {\r\n protected _iModel: IModelConnection;\r\n protected _changing = false;\r\n\r\n public constructor(iModel: IModelConnection) {\r\n super();\r\n this._iModel = iModel;\r\n }\r\n\r\n public override add(low: number, high: number) {\r\n super.add(low, high);\r\n this.onChanged();\r\n }\r\n\r\n public override delete(low: number, high: number) {\r\n super.delete(low, high);\r\n this.onChanged();\r\n }\r\n\r\n public override clear() {\r\n super.clear();\r\n this.onChanged();\r\n }\r\n\r\n public override addIds(ids: Id64Arg) {\r\n this.change(() => super.addIds(ids));\r\n }\r\n\r\n public override deleteIds(ids: Id64Arg) {\r\n this.change(() => super.deleteIds(ids));\r\n }\r\n\r\n protected onChanged() {\r\n if (!this._changing)\r\n IModelApp.viewManager.onSelectionSetChanged(this._iModel);\r\n }\r\n\r\n protected change(func: () => void) {\r\n const changing = this._changing;\r\n this._changing = false;\r\n func();\r\n this._changing = changing;\r\n this.onChanged();\r\n }\r\n}\r\n\r\n/** Keeps the set of hilited elements in sync with the selection set.\r\n * @internal\r\n */\r\nclass HilitedElementIds extends HilitedIds {\r\n private _removeListener?: () => void;\r\n\r\n public constructor(iModel: IModelConnection, syncWithSelectionSet = true) {\r\n super(iModel);\r\n this.wantSyncWithSelectionSet = syncWithSelectionSet;\r\n }\r\n\r\n public get wantSyncWithSelectionSet(): boolean { return undefined !== this._removeListener; }\r\n public set wantSyncWithSelectionSet(want: boolean) {\r\n if (want === this.wantSyncWithSelectionSet)\r\n return;\r\n\r\n if (want) {\r\n const set = this._iModel.selectionSet;\r\n this._removeListener = set.onChanged.addListener((ev) => this.change(() => this.processSelectionSetEvent(ev)));\r\n this.processSelectionSetEvent({\r\n set,\r\n type: SelectionSetEventType.Add,\r\n added: set.elements,\r\n });\r\n } else {\r\n this._removeListener!();\r\n this._removeListener = undefined;\r\n }\r\n }\r\n\r\n private processSelectionSetEvent(ev: SelectionSetEvent): void {\r\n if (SelectionSetEventType.Add !== ev.type)\r\n this.deleteIds(ev.removed);\r\n\r\n if (ev.type === SelectionSetEventType.Add || ev.type === SelectionSetEventType.Replace)\r\n this.addIds(ev.added);\r\n }\r\n}\r\n\r\n/** Describes how the sets of hilited models and subcategories in a [[HiliteSet]] interact.\r\n * - \"union\" indicates a [Feature]($common) will be hilited if either its model **or** its subcategory is present in the HiliteSet.\r\n * - \"intersection\" indicates a [Feature]($common) will be hilited only if both its model **and** its subcategory are present in the HiliteSet.\r\n *\r\n * @see [[HiliteSet.modelSubCategoryMode]] to change the mode for a HiliteSet.\r\n * @public\r\n */\r\nexport type ModelSubCategoryHiliteMode = \"union\" | \"intersection\";\r\n\r\n/** A set of *hilited* elements for an [[IModelConnection]], by element id.\r\n * Hilited elements are displayed with a customizable hilite effect within a [[Viewport]].\r\n * The set exposes 3 types of elements in 3 separate collections: [GeometricElement]($backend), [GeometricModel]($backend), and [SubCategory]($backend).\r\n * The [[models]] and [[subcategories]] can be hilited independently or as an intersection of the two sets, as specified by [[modelSubCategoryMode]].\r\n *\r\n * Technically, the hilite effect is applied to [Feature]($common)s, not [Element]($backend)s. An element's geometry stream can contain multiple\r\n * features belonging to different subcategories.\r\n *\r\n * Because Javascript lacks efficient support for 64-bit integers, the Ids are stored as pairs of 32-bit integers via [Id64.Uint32Set]($bentley).\r\n *\r\n * @note Typically, elements are hilited by virtue of their presence in the IModelConnection's [[SelectionSet]]. The HiliteSet allows additional\r\n * elements to be displayed with the hilite effect without adding them to the [[SelectionSet]]. If you add elements to the HiliteSet directly, you\r\n * are also responsible for removing them as appropriate.\r\n * @see [[IModelConnection.hilited]] for the HiliteSet associated with an iModel.\r\n * @see [Hilite.Settings]($common) for customization of the hilite effect.\r\n * @public\r\n * @extensions\r\n */\r\nexport class HiliteSet {\r\n private readonly _elements: HilitedElementIds;\r\n private _mode: ModelSubCategoryHiliteMode = \"union\";\r\n\r\n /** The set of hilited subcategories.\r\n * @see [[modelSubCategoryMode]] to control how this set interacts with the set of hilited [[models]].\r\n * @see [[IModelConnection.Categories]] to obtain the set of subcategories associated with one or more [Category]($backend)'s.\r\n */\r\n public readonly subcategories: Id64.Uint32Set;\r\n\r\n /** The set of hilited [[GeometricModelState]]s.\r\n * @see [[modelSubCategoryMode]] to control how this set interacts with the set of hilited [[subcategories]].\r\n */\r\n public readonly models: Id64.Uint32Set;\r\n\r\n /** The set of hilited elements. */\r\n public get elements(): Id64.Uint32Set { return this._elements; }\r\n\r\n /** Controls how the sets of hilited [[models]] and [[subcategories]] interact with one another.\r\n * By default they are treated as a union: a [Feature]($common) is hilited if either its model **or** its subcategory is hilited.\r\n * This can be changed to an intersection such that a [Feature]($common) is hilited only if both its model **and** subcategory are hilited.\r\n * @note The sets of hilited models and subcategories are independent of the set of hilited [[elements]] - an element whose Id is present in\r\n * [[elements]] is always hilited regardless of its model or subcategories.\r\n */\r\n public get modelSubCategoryMode(): ModelSubCategoryHiliteMode {\r\n return this._mode;\r\n }\r\n public set modelSubCategoryMode(mode: ModelSubCategoryHiliteMode) {\r\n if (mode === this._mode)\r\n return;\r\n\r\n this.onModelSubCategoryModeChanged.raiseEvent(mode);\r\n this._mode = mode;\r\n }\r\n\r\n /** Event raised just before changing the value of [[modelSubCategoryMode]]. */\r\n public readonly onModelSubCategoryModeChanged = new BeEvent<(newMode: ModelSubCategoryHiliteMode) => void>();\r\n\r\n /** Construct a HiliteSet\r\n * @param iModel The iModel containing the entities to be hilited.\r\n * @param syncWithSelectionSet If true, the contents of the `elements` set will be synchronized with those in the `iModel`'s [[SelectionSet]].\r\n * @internal\r\n */\r\n public constructor(public iModel: IModelConnection, syncWithSelectionSet = true) {\r\n this._elements = new HilitedElementIds(iModel, syncWithSelectionSet);\r\n this.subcategories = new HilitedIds(iModel);\r\n this.models = new HilitedIds(iModel);\r\n }\r\n\r\n /** Control whether the hilited elements will be synchronized with the contents of the [[SelectionSet]].\r\n * By default they are synchronized. Applications that override this take responsibility for managing the set of hilited entities.\r\n * When turning synchronization off, the contents of the HiliteSet will remain unchanged.\r\n * When turning synchronization on, the current contents of the HiliteSet will be preserved, and the contents of the selection set will be added to them.\r\n */\r\n public get wantSyncWithSelectionSet(): boolean { return this._elements.wantSyncWithSelectionSet; }\r\n public set wantSyncWithSelectionSet(want: boolean) { this._elements.wantSyncWithSelectionSet = want; }\r\n\r\n /** Remove all elements from the hilited set. */\r\n public clear() {\r\n this.elements.clear();\r\n this.subcategories.clear();\r\n this.models.clear();\r\n }\r\n\r\n /** Returns true if nothing is hilited. */\r\n public get isEmpty(): boolean { return this.elements.isEmpty && this.subcategories.isEmpty && this.models.isEmpty; }\r\n\r\n /** Toggle the hilited state of one or more elements.\r\n * @param arg the ID(s) of the elements whose state is to be toggled.\r\n * @param onOff True to add the elements to the hilited set, false to remove them.\r\n */\r\n public setHilite(arg: Id64Arg, onOff: boolean): void {\r\n for (const id of Id64.iterable(arg)) {\r\n if (onOff)\r\n this.elements.addId(id);\r\n else\r\n this.elements.deleteId(id);\r\n }\r\n\r\n IModelApp.viewManager.onSelectionSetChanged(this.iModel);\r\n }\r\n}\r\n\r\n/** A set of *currently selected* elements for an IModelConnection.\r\n * Selected elements are displayed with a customizable hilite effect within a [[Viewport]].\r\n * @see [Hilite.Settings]($common) for customization of the hilite effect.\r\n * @public\r\n * @extensions\r\n */\r\nexport class SelectionSet {\r\n private _elements = new Set<string>();\r\n\r\n /** The IDs of the selected elements.\r\n * @note Do not modify this set directly. Instead, use methods like [[SelectionSet.add]].\r\n */\r\n public get elements(): Set<string> { return this._elements; }\r\n\r\n /** Called whenever elements are added or removed from this SelectionSet */\r\n public readonly onChanged = new BeEvent<(ev: SelectionSetEvent) => void>();\r\n\r\n public constructor(public iModel: IModelConnection) { }\r\n\r\n private sendChangedEvent(ev: SelectionSetEvent) {\r\n IModelApp.viewManager.onSelectionSetChanged(this.iModel);\r\n this.onChanged.raiseEvent(ev);\r\n }\r\n\r\n /** Get the number of entries in this selection set. */\r\n public get size() { return this.elements.size; }\r\n\r\n /** Check whether there are any selected elements. */\r\n public get isActive() { return this.size !== 0; }\r\n\r\n /** Return true if elemId is in this SelectionSet.\r\n * @see [[isSelected]]\r\n */\r\n public has(elemId?: string) { return !!elemId && this.elements.has(elemId); }\r\n\r\n /** Query whether an Id is in the selection set.\r\n * @see [[has]]\r\n */\r\n public isSelected(elemId?: Id64String): boolean { return !!elemId && this.elements.has(elemId); }\r\n\r\n /** Clear current selection set.\r\n * @note raises the [[onChanged]] event with [[SelectionSetEventType.Clear]].\r\n */\r\n public emptyAll(): void {\r\n if (!this.isActive)\r\n return;\r\n\r\n const removed = this._elements;\r\n this._elements = new Set<string>();\r\n this.sendChangedEvent({ set: this, type: SelectionSetEventType.Clear, removed });\r\n }\r\n\r\n /**\r\n * Add one or more Ids to the current selection set.\r\n * @param elem The set of Ids to add.\r\n * @returns true if any elements were added.\r\n */\r\n public add(elem: Id64Arg): boolean {\r\n return this._add(elem);\r\n }\r\n\r\n private _add(elem: Id64Arg, sendEvent = true): boolean {\r\n const oldSize = this.elements.size;\r\n for (const id of Id64.iterable(elem))\r\n this.elements.add(id);\r\n\r\n const changed = oldSize !== this.elements.size;\r\n if (sendEvent && changed)\r\n this.sendChangedEvent({ type: SelectionSetEventType.Add, set: this, added: elem });\r\n\r\n return changed;\r\n }\r\n\r\n /**\r\n * Remove one or more Ids from the current selection set.\r\n * @param elem The set of Ids to remove.\r\n * @returns true if any elements were removed.\r\n */\r\n public remove(elem: Id64Arg): boolean {\r\n return this._remove(elem);\r\n }\r\n\r\n private _remove(elem: Id64Arg, sendEvent = true): boolean {\r\n const oldSize = this.elements.size;\r\n for (const id of Id64.iterable(elem))\r\n this.elements.delete(id);\r\n\r\n const changed = oldSize !== this.elements.size;\r\n if (sendEvent && changed)\r\n this.sendChangedEvent({ type: SelectionSetEventType.Remove, set: this, removed: elem });\r\n\r\n return changed;\r\n }\r\n\r\n /**\r\n * Add one set of Ids, and remove another set of Ids. Any Ids that are in both sets are removed.\r\n * @returns True if any Ids were either added or removed.\r\n */\r\n public addAndRemove(adds: Id64Arg, removes: Id64Arg): boolean {\r\n const added = this._add(adds, false);\r\n const removed = this._remove(removes, false);\r\n\r\n if (added && removed)\r\n this.sendChangedEvent({ type: SelectionSetEventType.Replace, set: this, added: adds, removed: removes });\r\n else if (added)\r\n this.sendChangedEvent({ type: SelectionSetEventType.Add, set: this, added: adds });\r\n else if (removed)\r\n this.sendChangedEvent({ type: SelectionSetEventType.Remove, set: this, removed: removes });\r\n\r\n return (added || removed);\r\n }\r\n\r\n /** Invert the state of a set of Ids in the SelectionSet */\r\n public invert(elem: Id64Arg): boolean {\r\n const elementsToAdd = new Set<string>();\r\n const elementsToRemove = new Set<string>();\r\n for (const id of Id64.iterable(elem)) {\r\n if (this.elements.has(id))\r\n elementsToRemove.add(id);\r\n else\r\n elementsToAdd.add(id);\r\n }\r\n\r\n return this.addAndRemove(elementsToAdd, elementsToRemove);\r\n }\r\n\r\n /** Change selection set to be the supplied set of Ids. */\r\n public replace(elem: Id64Arg): void {\r\n if (areEqual(this.elements, elem))\r\n return;\r\n\r\n const removed = this._elements;\r\n this._elements = new Set<string>();\r\n this._add(elem, false);\r\n\r\n if (0 < removed.size) {\r\n for (const id of Id64.iterable(elem)) {\r\n if (removed.has(id))\r\n removed.delete(id);\r\n }\r\n }\r\n\r\n this.sendChangedEvent({ type: SelectionSetEventType.Replace, set: this, added: elem, removed });\r\n }\r\n}\r\n\r\nfunction areEqual(lhs: Set<string>, rhs: Id64Arg): boolean {\r\n // Size is unreliable if input can contain duplicates...\r\n if (Array.isArray(rhs))\r\n rhs = Id64.toIdSet(rhs);\r\n\r\n if (lhs.size !== Id64.sizeOf(rhs))\r\n return false;\r\n\r\n for (const id of Id64.iterable(rhs))\r\n if (!lhs.has(id))\r\n return false;\r\n\r\n return true;\r\n}\r\n"]}
|
|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QAET,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAU,CAAC;QACnC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAEvB,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE;YACpB,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;gBACpC,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;oBACjB,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;aACtB;SACF;QAED,IAAI,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,qBAAqB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAClG,CAAC;CACF;AAED,SAAS,QAAQ,CAAC,GAAgB,EAAE,GAAY;IAC9C,wDAAwD;IACxD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QACpB,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAE1B,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QAC/B,OAAO,KAAK,CAAC;IAEf,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QACjC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACd,OAAO,KAAK,CAAC;IAEjB,OAAO,IAAI,CAAC;AACd,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 SelectionSet\r\n */\r\nimport { BeEvent, Id64, Id64Arg, Id64String } from \"@itwin/core-bentley\";\r\nimport { IModelApp } from \"./IModelApp\";\r\nimport { IModelConnection } from \"./IModelConnection\";\r\n\r\n/** Identifies the type of changes made to the [[SelectionSet]] to produce a [[SelectionSetEvent]].\r\n * @public\r\n * @extensions\r\n */\r\nexport enum SelectionSetEventType {\r\n /** Elements have been added to the set. */\r\n Add,\r\n /** Elements have been removed from the set. */\r\n Remove,\r\n /** Some elements have been added to the set and others have been removed. */\r\n Replace,\r\n /** All elements are about to be removed from the set. */\r\n Clear,\r\n}\r\n\r\n/** Passed to [[SelectionSet.onChanged]] event listeners when elements are added to the selection set.\r\n * @public\r\n * @extensions\r\n */\r\nexport interface SelectAddEvent {\r\n type: SelectionSetEventType.Add;\r\n /** The Ids of the elements added to the set. */\r\n added: Id64Arg;\r\n /** The affected SelectionSet. */\r\n set: SelectionSet;\r\n}\r\n\r\n/** Passed to [[SelectionSet.onChanged]] event listeners when elements are removed from the selection set.\r\n * @public\r\n * @extensions\r\n */\r\nexport interface SelectRemoveEvent {\r\n /** The type of operation that produced this event. */\r\n type: SelectionSetEventType.Remove | SelectionSetEventType.Clear;\r\n /** The element Ids removed from the set. */\r\n removed: Id64Arg;\r\n /** The affected SelectionSet. */\r\n set: SelectionSet;\r\n}\r\n\r\n/** Passed to [[SelectionSet.onChanged]] event listeners when elements are simultaneously added to and removed from the selection set.\r\n * @public\r\n * @extensions\r\n */\r\nexport interface SelectReplaceEvent {\r\n type: SelectionSetEventType.Replace;\r\n /** The element Ids added to the set. */\r\n added: Id64Arg;\r\n /** The element Ids removed from the set. */\r\n removed: Id64Arg;\r\n /** The affected SelectionSet. */\r\n set: SelectionSet;\r\n}\r\n\r\n/** Payload sent to [[SelectionSet.onChanged]] event listeners to describe how the contents of the set have changed.\r\n * The `type` property of the event serves as a type assertion. For example, the following code will output the added and/or removed Ids:\r\n * ```ts\r\n * processSelectionSetEvent(ev: SelectionSetEvent): void {\r\n * if (SelectionSetEventType.Add === ev.type || SelectionSetEventType.Replace === ev.type)\r\n * console.log(\"Added \" + ev.added.size + \" elements\");\r\n *\r\n * if (SelectionSetEventType.Add !== ev.type)\r\n * console.log(\"Removed \" + ev.removed.size + \" elements\");\r\n * }\r\n * ```\r\n * @public\r\n * @extensions\r\n */\r\nexport type SelectionSetEvent = SelectAddEvent | SelectRemoveEvent | SelectReplaceEvent;\r\n\r\n/** Tracks a set of hilited entities. When the set changes, notifies ViewManager so that symbology overrides can be updated in active Viewports.\r\n * @internal\r\n */\r\nclass HilitedIds extends Id64.Uint32Set {\r\n protected _iModel: IModelConnection;\r\n protected _changing = false;\r\n\r\n public constructor(iModel: IModelConnection) {\r\n super();\r\n this._iModel = iModel;\r\n }\r\n\r\n public override add(low: number, high: number) {\r\n super.add(low, high);\r\n this.onChanged();\r\n }\r\n\r\n public override delete(low: number, high: number) {\r\n super.delete(low, high);\r\n this.onChanged();\r\n }\r\n\r\n public override clear() {\r\n super.clear();\r\n this.onChanged();\r\n }\r\n\r\n public override addIds(ids: Id64Arg) {\r\n this.change(() => super.addIds(ids));\r\n }\r\n\r\n public override deleteIds(ids: Id64Arg) {\r\n this.change(() => super.deleteIds(ids));\r\n }\r\n\r\n protected onChanged() {\r\n if (!this._changing)\r\n IModelApp.viewManager.onSelectionSetChanged(this._iModel);\r\n }\r\n\r\n protected change(func: () => void) {\r\n const changing = this._changing;\r\n this._changing = false;\r\n func();\r\n this._changing = changing;\r\n this.onChanged();\r\n }\r\n}\r\n\r\n/** Keeps the set of hilited elements in sync with the selection set.\r\n * @internal\r\n */\r\nclass HilitedElementIds extends HilitedIds {\r\n private _removeListener?: () => void;\r\n\r\n public constructor(iModel: IModelConnection, syncWithSelectionSet = true) {\r\n super(iModel);\r\n this.wantSyncWithSelectionSet = syncWithSelectionSet;\r\n }\r\n\r\n public get wantSyncWithSelectionSet(): boolean { return undefined !== this._removeListener; }\r\n public set wantSyncWithSelectionSet(want: boolean) {\r\n if (want === this.wantSyncWithSelectionSet)\r\n return;\r\n\r\n if (want) {\r\n const set = this._iModel.selectionSet;\r\n this._removeListener = set.onChanged.addListener((ev) => this.change(() => this.processSelectionSetEvent(ev)));\r\n this.processSelectionSetEvent({\r\n set,\r\n type: SelectionSetEventType.Add,\r\n added: set.elements,\r\n });\r\n } else {\r\n this._removeListener!();\r\n this._removeListener = undefined;\r\n }\r\n }\r\n\r\n private processSelectionSetEvent(ev: SelectionSetEvent): void {\r\n if (SelectionSetEventType.Add !== ev.type)\r\n this.deleteIds(ev.removed);\r\n\r\n if (ev.type === SelectionSetEventType.Add || ev.type === SelectionSetEventType.Replace)\r\n this.addIds(ev.added);\r\n }\r\n}\r\n\r\n/** Describes how the sets of hilited models and subcategories in a [[HiliteSet]] interact.\r\n * - \"union\" indicates a [Feature]($common) will be hilited if either its model **or** its subcategory is present in the HiliteSet.\r\n * - \"intersection\" indicates a [Feature]($common) will be hilited only if both its model **and** its subcategory are present in the HiliteSet.\r\n *\r\n * @see [[HiliteSet.modelSubCategoryMode]] to change the mode for a HiliteSet.\r\n * @public\r\n */\r\nexport type ModelSubCategoryHiliteMode = \"union\" | \"intersection\";\r\n\r\n/** A set of *hilited* elements for an [[IModelConnection]], by element id.\r\n * Hilited elements are displayed with a customizable hilite effect within a [[Viewport]].\r\n * The set exposes 3 types of elements in 3 separate collections: [GeometricElement]($backend), [GeometricModel]($backend), and [SubCategory]($backend).\r\n * The [[models]] and [[subcategories]] can be hilited independently or as an intersection of the two sets, as specified by [[modelSubCategoryMode]].\r\n *\r\n * Technically, the hilite effect is applied to [Feature]($common)s, not [Element]($backend)s. An element's geometry stream can contain multiple\r\n * features belonging to different subcategories.\r\n *\r\n * Because Javascript lacks efficient support for 64-bit integers, the Ids are stored as pairs of 32-bit integers via [Id64.Uint32Set]($bentley).\r\n *\r\n * @note Typically, elements are hilited by virtue of their presence in the IModelConnection's [[SelectionSet]]. The HiliteSet allows additional\r\n * elements to be displayed with the hilite effect without adding them to the [[SelectionSet]]. If you add elements to the HiliteSet directly, you\r\n * are also responsible for removing them as appropriate.\r\n * @see [[IModelConnection.hilited]] for the HiliteSet associated with an iModel.\r\n * @see [Hilite.Settings]($common) for customization of the hilite effect.\r\n * @public\r\n * @extensions\r\n */\r\nexport class HiliteSet {\r\n private readonly _elements: HilitedElementIds;\r\n private _mode: ModelSubCategoryHiliteMode = \"union\";\r\n\r\n /** The set of hilited subcategories.\r\n * @see [[modelSubCategoryMode]] to control how this set interacts with the set of hilited [[models]].\r\n * @see [[IModelConnection.Categories]] to obtain the set of subcategories associated with one or more [Category]($backend)'s.\r\n */\r\n public readonly subcategories: Id64.Uint32Set;\r\n\r\n /** The set of hilited [[GeometricModelState]]s.\r\n * @see [[modelSubCategoryMode]] to control how this set interacts with the set of hilited [[subcategories]].\r\n */\r\n public readonly models: Id64.Uint32Set;\r\n\r\n /** The set of hilited elements. */\r\n public get elements(): Id64.Uint32Set { return this._elements; }\r\n\r\n /** Controls how the sets of hilited [[models]] and [[subcategories]] interact with one another.\r\n * By default they are treated as a union: a [Feature]($common) is hilited if either its model **or** its subcategory is hilited.\r\n * This can be changed to an intersection such that a [Feature]($common) is hilited only if both its model **and** subcategory are hilited.\r\n * @note The sets of hilited models and subcategories are independent of the set of hilited [[elements]] - an element whose Id is present in\r\n * [[elements]] is always hilited regardless of its model or subcategories.\r\n */\r\n public get modelSubCategoryMode(): ModelSubCategoryHiliteMode {\r\n return this._mode;\r\n }\r\n public set modelSubCategoryMode(mode: ModelSubCategoryHiliteMode) {\r\n if (mode === this._mode)\r\n return;\r\n\r\n this.onModelSubCategoryModeChanged.raiseEvent(mode);\r\n this._mode = mode;\r\n }\r\n\r\n /** Event raised just before changing the value of [[modelSubCategoryMode]]. */\r\n public readonly onModelSubCategoryModeChanged = new BeEvent<(newMode: ModelSubCategoryHiliteMode) => void>();\r\n\r\n /** Construct a HiliteSet\r\n * @param iModel The iModel containing the entities to be hilited.\r\n * @param syncWithSelectionSet If true, the contents of the `elements` set will be synchronized with those in the `iModel`'s [[SelectionSet]].\r\n * @internal\r\n */\r\n public constructor(public iModel: IModelConnection, syncWithSelectionSet = true) {\r\n this._elements = new HilitedElementIds(iModel, syncWithSelectionSet);\r\n this.subcategories = new HilitedIds(iModel);\r\n this.models = new HilitedIds(iModel);\r\n }\r\n\r\n /** Control whether the hilited elements will be synchronized with the contents of the [[SelectionSet]].\r\n * By default they are synchronized. Applications that override this take responsibility for managing the set of hilited entities.\r\n * When turning synchronization off, the contents of the HiliteSet will remain unchanged.\r\n * When turning synchronization on, the current contents of the HiliteSet will be preserved, and the contents of the selection set will be added to them.\r\n */\r\n public get wantSyncWithSelectionSet(): boolean { return this._elements.wantSyncWithSelectionSet; }\r\n public set wantSyncWithSelectionSet(want: boolean) { this._elements.wantSyncWithSelectionSet = want; }\r\n\r\n /** Remove all elements from the hilited set. */\r\n public clear() {\r\n this.elements.clear();\r\n this.subcategories.clear();\r\n this.models.clear();\r\n }\r\n\r\n /** Returns true if nothing is hilited. */\r\n public get isEmpty(): boolean { return this.elements.isEmpty && this.subcategories.isEmpty && this.models.isEmpty; }\r\n\r\n /** Toggle the hilited state of one or more elements.\r\n * @param arg the ID(s) of the elements whose state is to be toggled.\r\n * @param onOff True to add the elements to the hilited set, false to remove them.\r\n */\r\n public setHilite(arg: Id64Arg, onOff: boolean): void {\r\n const oldSize = this.elements.size;\r\n\r\n for (const id of Id64.iterable(arg)) {\r\n if (onOff)\r\n this.elements.addId(id);\r\n else\r\n this.elements.deleteId(id);\r\n }\r\n\r\n if (oldSize !== this.elements.size)\r\n IModelApp.viewManager.onSelectionSetChanged(this.iModel);\r\n }\r\n}\r\n\r\n/** A set of *currently selected* elements for an IModelConnection.\r\n * Selected elements are displayed with a customizable hilite effect within a [[Viewport]].\r\n * @see [Hilite.Settings]($common) for customization of the hilite effect.\r\n * @public\r\n * @extensions\r\n */\r\nexport class SelectionSet {\r\n private _elements = new Set<string>();\r\n\r\n /** The IDs of the selected elements.\r\n * @note Do not modify this set directly. Instead, use methods like [[SelectionSet.add]].\r\n */\r\n public get elements(): Set<string> { return this._elements; }\r\n\r\n /** Called whenever elements are added or removed from this SelectionSet */\r\n public readonly onChanged = new BeEvent<(ev: SelectionSetEvent) => void>();\r\n\r\n public constructor(public iModel: IModelConnection) { }\r\n\r\n private sendChangedEvent(ev: SelectionSetEvent) {\r\n IModelApp.viewManager.onSelectionSetChanged(this.iModel);\r\n this.onChanged.raiseEvent(ev);\r\n }\r\n\r\n /** Get the number of entries in this selection set. */\r\n public get size() { return this.elements.size; }\r\n\r\n /** Check whether there are any selected elements. */\r\n public get isActive() { return this.size !== 0; }\r\n\r\n /** Return true if elemId is in this SelectionSet.\r\n * @see [[isSelected]]\r\n */\r\n public has(elemId?: string) { return !!elemId && this.elements.has(elemId); }\r\n\r\n /** Query whether an Id is in the selection set.\r\n * @see [[has]]\r\n */\r\n public isSelected(elemId?: Id64String): boolean { return !!elemId && this.elements.has(elemId); }\r\n\r\n /** Clear current selection set.\r\n * @note raises the [[onChanged]] event with [[SelectionSetEventType.Clear]].\r\n */\r\n public emptyAll(): void {\r\n if (!this.isActive)\r\n return;\r\n\r\n const removed = this._elements;\r\n this._elements = new Set<string>();\r\n this.sendChangedEvent({ set: this, type: SelectionSetEventType.Clear, removed });\r\n }\r\n\r\n /**\r\n * Add one or more Ids to the current selection set.\r\n * @param elem The set of Ids to add.\r\n * @returns true if any elements were added.\r\n */\r\n public add(elem: Id64Arg): boolean {\r\n return this._add(elem);\r\n }\r\n\r\n private _add(elem: Id64Arg, sendEvent = true): boolean {\r\n const oldSize = this.elements.size;\r\n for (const id of Id64.iterable(elem))\r\n this.elements.add(id);\r\n\r\n const changed = oldSize !== this.elements.size;\r\n if (sendEvent && changed)\r\n this.sendChangedEvent({ type: SelectionSetEventType.Add, set: this, added: elem });\r\n\r\n return changed;\r\n }\r\n\r\n /**\r\n * Remove one or more Ids from the current selection set.\r\n * @param elem The set of Ids to remove.\r\n * @returns true if any elements were removed.\r\n */\r\n public remove(elem: Id64Arg): boolean {\r\n return this._remove(elem);\r\n }\r\n\r\n private _remove(elem: Id64Arg, sendEvent = true): boolean {\r\n const oldSize = this.elements.size;\r\n for (const id of Id64.iterable(elem))\r\n this.elements.delete(id);\r\n\r\n const changed = oldSize !== this.elements.size;\r\n if (sendEvent && changed)\r\n this.sendChangedEvent({ type: SelectionSetEventType.Remove, set: this, removed: elem });\r\n\r\n return changed;\r\n }\r\n\r\n /**\r\n * Add one set of Ids, and remove another set of Ids. Any Ids that are in both sets are removed.\r\n * @returns True if any Ids were either added or removed.\r\n */\r\n public addAndRemove(adds: Id64Arg, removes: Id64Arg): boolean {\r\n const added = this._add(adds, false);\r\n const removed = this._remove(removes, false);\r\n\r\n if (added && removed)\r\n this.sendChangedEvent({ type: SelectionSetEventType.Replace, set: this, added: adds, removed: removes });\r\n else if (added)\r\n this.sendChangedEvent({ type: SelectionSetEventType.Add, set: this, added: adds });\r\n else if (removed)\r\n this.sendChangedEvent({ type: SelectionSetEventType.Remove, set: this, removed: removes });\r\n\r\n return (added || removed);\r\n }\r\n\r\n /** Invert the state of a set of Ids in the SelectionSet */\r\n public invert(elem: Id64Arg): boolean {\r\n const elementsToAdd = new Set<string>();\r\n const elementsToRemove = new Set<string>();\r\n for (const id of Id64.iterable(elem)) {\r\n if (this.elements.has(id))\r\n elementsToRemove.add(id);\r\n else\r\n elementsToAdd.add(id);\r\n }\r\n\r\n return this.addAndRemove(elementsToAdd, elementsToRemove);\r\n }\r\n\r\n /** Change selection set to be the supplied set of Ids. */\r\n public replace(elem: Id64Arg): void {\r\n if (areEqual(this.elements, elem))\r\n return;\r\n\r\n const removed = this._elements;\r\n this._elements = new Set<string>();\r\n this._add(elem, false);\r\n\r\n if (0 < removed.size) {\r\n for (const id of Id64.iterable(elem)) {\r\n if (removed.has(id))\r\n removed.delete(id);\r\n }\r\n }\r\n\r\n this.sendChangedEvent({ type: SelectionSetEventType.Replace, set: this, added: elem, removed });\r\n }\r\n}\r\n\r\nfunction areEqual(lhs: Set<string>, rhs: Id64Arg): boolean {\r\n // Size is unreliable if input can contain duplicates...\r\n if (Array.isArray(rhs))\r\n rhs = Id64.toIdSet(rhs);\r\n\r\n if (lhs.size !== Id64.sizeOf(rhs))\r\n return false;\r\n\r\n for (const id of Id64.iterable(rhs))\r\n if (!lhs.has(id))\r\n return false;\r\n\r\n return true;\r\n}\r\n"]}
|