@itwin/core-frontend 4.8.0-dev.16 → 4.8.0-dev.17

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.
@@ -1 +1 @@
1
- {"version":3,"file":"SubCategoriesCache.js","sourceRoot":"","sources":["../../src/SubCategoriesCache.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAgC,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACzH,OAAO,EAAE,qBAAqB,EAAwB,MAAM,oBAAoB,CAAC;AAkBjF,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAU,CAAC;AAEjD;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAM7B,YAAmB,MAAwB;QAL1B,kBAAa,GAAG,IAAI,GAAG,EAAmB,CAAC;QAC3C,iBAAY,GAAG,IAAI,GAAG,EAAiC,CAAC;QAI1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAAC,CAAC;IAEvE,wIAAwI;IACjI,gBAAgB,CAAC,UAAkB,IAAyB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAE/G,wHAAwH;IACjH,wBAAwB,CAAC,aAAyB,IAAuC,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;IAEzJ;;;;OAIG;IACI,IAAI,CAAC,WAAoB;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC7C,IAAI,SAAS,KAAK,OAAO;YACvB,OAAO,SAAS,CAAC;QAEnB,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACtE,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,I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AK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;YACrE,CAAC;iBAAM,CAAC;gBACN,mGAAmG;gBACnG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC5B,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;oBACjD,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC;KACF;IAvGY,wBAAK,QAuGjB,CAAA;AACH,CAAC,EAjLgB,kBAAkB,KAAlB,kBAAkB,QAiLlC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { assert, CompressedId64Set, Id64, Id64Arg, Id64Set, Id64String, OrderedId64Iterable } from \"@itwin/core-bentley\";\r\nimport { SubCategoryAppearance, SubCategoryResultRow } from \"@itwin/core-common\";\r\nimport { IModelConnection } from \"./IModelConnection\";\r\n\r\n/** A cancelable paginated request for subcategory information.\r\n * @see SubCategoriesCache\r\n * @internal\r\n */\r\nexport interface SubCategoriesRequest {\r\n /** The Ids of any categories which were requested but were not yet loaded. */\r\n readonly missingCategoryIds: Id64Set;\r\n /** A promise which resolves to true when all of the requested categories have been loaded, or to false if not all categories were loaded.\r\n * Categories may fail to load if the request is explicitly canceled or if the IModelConnection is closed before all categories are loaded.\r\n */\r\n readonly promise: Promise<boolean>;\r\n /** Cancels the request. */\r\n cancel(): void;\r\n}\r\n\r\nconst invalidCategoryIdEntry = new Set<string>();\r\n\r\n/** A cache of information about the subcategories contained within an [[IModelConnection]]. It is populated on demand.\r\n * @internal\r\n */\r\nexport class SubCategoriesCache {\r\n private readonly _byCategoryId = new Map<string, Id64Set>();\r\n private readonly _appearances = new Map<string, SubCategoryAppearance>();\r\n private readonly _imodel: IModelConnection;\r\n private _missingAtTimeOfPreload: Id64Set | undefined;\r\n\r\n public constructor(imodel: IModelConnection) { this._imodel = imodel; }\r\n\r\n /** Get the Ids of all subcategories belonging to the category with the specified Id, or undefined if no such information is present. */\r\n public getSubCategories(categoryId: string): Id64Set | undefined { return this._byCategoryId.get(categoryId); }\r\n\r\n /** Get the base appearance of the subcategory with the specified Id, or undefined if no such information is present. */\r\n public getSubCategoryAppearance(subCategoryId: Id64String): SubCategoryAppearance | undefined { return this._appearances.get(subCategoryId.toString()); }\r\n\r\n /** Request that the subcategory information for all of the specified categories is loaded.\r\n * If all such information has already been loaded, returns undefined.\r\n * Otherwise, dispatches an asynchronous request to load those categories which are not already loaded and returns a cancellable request object\r\n * containing the corresponding promise and the set of categories still to be loaded.\r\n */\r\n public load(categoryIds: Id64Arg): SubCategoriesRequest | undefined {\r\n const missing = this.getMissing(categoryIds);\r\n if (undefined === missing)\r\n return undefined;\r\n\r\n const request = new SubCategoriesCache.Request(missing, this._imodel);\r\n const promise = request.dispatch().then((result?: SubCategoriesCache.Result) => {\r\n if (undefined !== result)\r\n this.processResults(result, missing);\r\n\r\n return !request.wasCanceled;\r\n });\r\n\r\n return {\r\n missingCategoryIds: missing,\r\n promise,\r\n cancel: () => request.cancel(),\r\n };\r\n }\r\n\r\n /** Given categoryIds, return which of these are not cached. */\r\n private getMissing(categoryIds: Id64Arg): Id64Set | undefined {\r\n let missing: Id64Set | undefined;\r\n for (const catId of Id64.iterable(categoryIds)) {\r\n if (undefined === this._byCategoryId.get(catId)) {\r\n if (undefined === missing)\r\n missing = new Set<string>();\r\n\r\n missing.add(catId);\r\n }\r\n }\r\n\r\n return missing;\r\n }\r\n\r\n public clear(): void {\r\n this._byCategoryId.clear();\r\n this._appearances.clear();\r\n }\r\n\r\n public onIModelConnectionClose(): void {\r\n this.clear();\r\n }\r\n\r\n private static createSubCategoryAppearance(json?: any) {\r\n let props: SubCategoryAppearance.Props | undefined;\r\n if (\"string\" === typeof json && 0 < json.length)\r\n props = JSON.parse(json);\r\n\r\n return new SubCategoryAppearance(props);\r\n }\r\n\r\n private processResults(result: SubCategoriesCache.Result, missing: Id64Set): void {\r\n for (const row of result)\r\n this.add(row.parentId, row.id, SubCategoriesCache.createSubCategoryAppearance(row.appearance));\r\n\r\n // Ensure that any category Ids which returned no results (e.g., non-existent category, invalid Id, etc) are still recorded so they are not repeatedly re-requested\r\n for (const id of missing)\r\n if (undefined === this._byCategoryId.get(id))\r\n this._byCategoryId.set(id, invalidCategoryIdEntry);\r\n }\r\n\r\n /** Exposed strictly for tests.\r\n * @internal\r\n */\r\n public add(categoryId: string, subCategoryId: string, appearance: SubCategoryAppearance) {\r\n let set = this._byCategoryId.get(categoryId);\r\n if (undefined === set)\r\n this._byCategoryId.set(categoryId, set = new Set<string>());\r\n\r\n set.add(subCategoryId);\r\n this._appearances.set(subCategoryId, appearance);\r\n }\r\n\r\n public async getCategoryInfo(inputCategoryIds: Id64String | Iterable<Id64String>): Promise<Map<Id64String, IModelConnection.Categories.CategoryInfo>> {\r\n // Eliminate duplicates...\r\n const categoryIds = new Set<string>(typeof inputCategoryIds === \"string\" ? [inputCategoryIds] : inputCategoryIds);\r\n const req = this.load(categoryIds);\r\n if (req)\r\n await req.promise;\r\n\r\n const map = new Map<Id64String, IModelConnection.Categories.CategoryInfo>();\r\n for (const categoryId of categoryIds) {\r\n const subCategoryIds = this._byCategoryId.get(categoryId);\r\n if (!subCategoryIds)\r\n continue;\r\n\r\n const subCategories = this.mapSubCategoryInfos(categoryId, subCategoryIds);\r\n map.set(categoryId, { id: categoryId, subCategories });\r\n }\r\n\r\n return map;\r\n }\r\n\r\n public async getSubCategoryInfo(categoryId: Id64String, inputSubCategoryIds: Id64String | Iterable<Id64String>): Promise<Map<Id64String, IModelConnection.Categories.SubCategoryInfo>> {\r\n // Eliminate duplicates...\r\n const subCategoryIds = new Set<string>(typeof inputSubCategoryIds === \"string\" ? [inputSubCategoryIds] : inputSubCategoryIds);\r\n const req = this.load(categoryId);\r\n if (req)\r\n await req.promise;\r\n\r\n return this.mapSubCategoryInfos(categoryId, subCategoryIds);\r\n }\r\n\r\n private mapSubCategoryInfos(categoryId: Id64String, subCategoryIds: Set<Id64String>): Map<Id64String, IModelConnection.Categories.SubCategoryInfo> {\r\n const map = new Map<Id64String, IModelConnection.Categories.SubCategoryInfo>();\r\n for (const id of subCategoryIds) {\r\n const appearance = this._appearances.get(id);\r\n if (appearance)\r\n map.set(id, { id, categoryId, appearance });\r\n }\r\n\r\n return map;\r\n }\r\n}\r\n\r\n/** This namespace and the types within it are exported strictly for use in tests.\r\n * @internal\r\n */\r\nexport namespace SubCategoriesCache { // eslint-disable-line no-redeclare\r\n export type Result = SubCategoryResultRow[];\r\n\r\n export class Request {\r\n private readonly _imodel: IModelConnection;\r\n private readonly _categoryIds: CompressedId64Set[] = [];\r\n private readonly _result: Result = [];\r\n private _canceled = false;\r\n private _curCategoryIdsIndex = 0;\r\n\r\n public get wasCanceled() { return this._canceled || this._imodel.isClosed; }\r\n\r\n public constructor(categoryIds: Set<string>, imodel: IModelConnection, maxCategoriesPerQuery = 2500) {\r\n this._imodel = imodel;\r\n\r\n const catIds = [...categoryIds];\r\n OrderedId64Iterable.sortArray(catIds); // sort categories, so that given the same set of categoryIds we will always create the same batches.\r\n while (catIds.length !== 0) {\r\n const end = (catIds.length > maxCategoriesPerQuery) ? maxCategoriesPerQuery : catIds.length;\r\n const compressedIds = CompressedId64Set.compressArray(catIds.splice(0, end));\r\n this._categoryIds.push(compressedIds);\r\n }\r\n }\r\n\r\n public cancel() { this._canceled = true; }\r\n\r\n public async dispatch(): Promise<Result | undefined> {\r\n if (this.wasCanceled || this._curCategoryIdsIndex >= this._categoryIds.length) // handle case of empty category Id set...\r\n return undefined;\r\n\r\n try {\r\n const catIds = this._categoryIds[this._curCategoryIdsIndex];\r\n const result = await this._imodel.querySubCategories(catIds);\r\n this._result.push(...result);\r\n if (this.wasCanceled)\r\n return undefined;\r\n } catch {\r\n // ###TODO: detect cases in which retry is warranted\r\n // Note that currently, if we succeed in obtaining some pages of results and fail to retrieve another page, we will end up processing the\r\n // incomplete results. Since we're not retrying, that's the best we can do.\r\n }\r\n\r\n // Finished with current batch of categoryIds. Dispatch the next batch if one exists.\r\n if (++this._curCategoryIdsIndex < this._categoryIds.length) {\r\n if (this.wasCanceled)\r\n return undefined;\r\n else\r\n return this.dispatch();\r\n }\r\n\r\n // Even if we were canceled, we've retrieved all the rows. Might as well process them to prevent another request for some of the same rows from being enqueued.\r\n return this._result;\r\n }\r\n }\r\n\r\n export type QueueFunc = () => void;\r\n\r\n export class QueueEntry {\r\n public readonly categoryIds: Id64Set;\r\n public readonly funcs: QueueFunc[];\r\n\r\n public constructor(categoryIds: Id64Set, func: QueueFunc) {\r\n this.categoryIds = categoryIds;\r\n this.funcs = [func];\r\n }\r\n }\r\n\r\n /** A \"queue\" of SubCategoriesRequests, which consists of between 0 and 2 entries. Each entry specifies the set of category IDs to be loaded and a list of functions to be executed\r\n * when loading is completed. This is used to enforce ordering of operations upon subcategories despite the need to asynchronously load them. It incidentally also provides an\r\n * opportunity to reduce the number of backend requests by batching consecutive requests.\r\n * Chiefly used by [[Viewport]].\r\n * @internal\r\n */\r\n export class Queue {\r\n /* NB: Members marked protected for use in tests only. */\r\n protected _current?: QueueEntry;\r\n protected _next?: QueueEntry;\r\n protected _request?: SubCategoriesRequest;\r\n protected _disposed = false;\r\n\r\n /** Push a request onto the queue. The requested categories will be loaded if necessary, and then\r\n * the supplied function will be invoked. Any previously-pushed requests are guaranteed to be processed before this one.\r\n */\r\n public push(cache: SubCategoriesCache, categoryIds: Id64Arg, func: QueueFunc): void {\r\n if (this._disposed)\r\n return;\r\n else if (undefined === this._current)\r\n this.pushCurrent(cache, categoryIds, func);\r\n else\r\n this.pushNext(categoryIds, func);\r\n }\r\n\r\n /** Cancel all requests and empty the queue. */\r\n public dispose(): void {\r\n if (undefined !== this._request) {\r\n assert(undefined !== this._current);\r\n this._request.cancel();\r\n this._request = undefined;\r\n }\r\n\r\n this._current = this._next = undefined;\r\n this._disposed = true;\r\n }\r\n\r\n public get isEmpty(): boolean {\r\n return undefined === this._current && undefined === this._next;\r\n }\r\n\r\n private pushCurrent(cache: SubCategoriesCache, categoryIds: Id64Arg, func: QueueFunc): void {\r\n assert(undefined === this._next);\r\n assert(undefined === this._current);\r\n assert(undefined === this._request);\r\n\r\n this._request = cache.load(categoryIds);\r\n if (undefined === this._request) {\r\n // All requested categories are already loaded.\r\n func();\r\n return;\r\n } else {\r\n // We need to load the requested categories before invoking the function.\r\n this.processCurrent(cache, new QueueEntry(Id64.toIdSet(categoryIds, true), func));\r\n }\r\n }\r\n\r\n private processCurrent(cache: SubCategoriesCache, entry: QueueEntry): void {\r\n assert(undefined !== this._request);\r\n assert(undefined === this._current);\r\n assert(undefined === this._next);\r\n\r\n this._current = entry;\r\n this._request.promise.then((completed: boolean) => { // eslint-disable-line @typescript-eslint/no-floating-promises\r\n if (this._disposed)\r\n return;\r\n\r\n // Invoke all the functions which were awaiting this set of IModelConnection.Categories.\r\n assert(undefined !== this._current);\r\n if (completed)\r\n for (const func of this._current.funcs)\r\n func();\r\n\r\n this._request = undefined;\r\n this._current = undefined;\r\n\r\n // If we have more requests, process them.\r\n const next = this._next;\r\n this._next = undefined;\r\n if (undefined !== next) {\r\n this._request = cache.load(next.categoryIds);\r\n if (undefined === this._request) {\r\n // All categories loaded.\r\n for (const func of next.funcs)\r\n func();\r\n } else {\r\n // We need to load the requested categories before invoking the pending functions.\r\n this.processCurrent(cache, next);\r\n }\r\n }\r\n });\r\n }\r\n\r\n private pushNext(categoryIds: Id64Arg, func: QueueFunc): void {\r\n assert(undefined !== this._current);\r\n assert(undefined !== this._request);\r\n\r\n if (undefined === this._next) {\r\n // We have a request currently in process and none pending.\r\n // We could potentially determine that this request doesn't require any categories that are not already loaded or being loaded by the current request.\r\n // But we will find that out (synchronously) when current request completes, unless more requests come in. Probably not worth it.\r\n this._next = new QueueEntry(Id64.toIdSet(categoryIds, true), func);\r\n } else {\r\n // We have a request currently in process, and one or more pending. Append this one to the pending.\r\n this._next.funcs.push(func);\r\n for (const categoryId of Id64.iterable(categoryIds))\r\n this._next.categoryIds.add(categoryId);\r\n }\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"SubCategoriesCache.js","sourceRoot":"","sources":["../../src/SubCategoriesCache.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAgC,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AACzH,OAAO,EAAE,qBAAqB,EAAwB,MAAM,oBAAoB,CAAC;AAkBjF,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAU,CAAC;AAEjD;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAM7B,YAAmB,MAAwB;QAL1B,kBAAa,GAAG,IAAI,GAAG,EAAmB,CAAC;QAC3C,iBAAY,GAAG,IAAI,GAAG,EAAiC,CAAC;QAI1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAAC,CAAC;IAEvE,wIAAwI;IACjI,gBAAgB,CAAC,UAAkB,IAAyB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAE/G,wHAAwH;IACjH,wBAAwB,CAAC,aAAyB,IAAuC,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;IAEzJ;;;;OAIG;IACI,IAAI,CAAC,WAAoB;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC7C,IAAI,SAAS,KAAK,OAAO;YACvB,OAAO,SAAS,CAAC;QAEnB,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,OAAO,CAAC,OAAO,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AyB;wBACzB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK;4BAC3B,IAAI,EAAE,CAAC;oBACX,CAAC;yBAAM,CAAC;wBACN,kFAAkF;wBAClF,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;oBACnC,CAAC;gBACH,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAEO,QAAQ,CAAC,WAAoB,EAAE,IAAe;YACpD,MAAM,CAAC,SAAS,KAAK,IAAI,CAAC,QAAQ,CAAC,CAAC;YACpC,MAAM,CAAC,SAAS,KAAK,IAAI,CAAC,QAAQ,CAAC,CAAC;YAEpC,IAAI,SAAS,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;gBAC7B,2DAA2D;gBAC3D,sJAAsJ;gBACtJ,iIAAiI;gBACjI,IAAI,CAAC,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;YACrE,CAAC;iBAAM,CAAC;gBACN,mGAAmG;gBACnG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC5B,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;oBACjD,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC;KACF;IAvGY,wBAAK,QAuGjB,CAAA;AACH,CAAC,EAjLgB,kBAAkB,KAAlB,kBAAkB,QAiLlC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { assert, CompressedId64Set, Id64, Id64Arg, Id64Set, Id64String, OrderedId64Iterable } from \"@itwin/core-bentley\";\r\nimport { SubCategoryAppearance, SubCategoryResultRow } from \"@itwin/core-common\";\r\nimport { IModelConnection } from \"./IModelConnection\";\r\n\r\n/** A cancelable paginated request for subcategory information.\r\n * @see SubCategoriesCache\r\n * @internal\r\n */\r\nexport interface SubCategoriesRequest {\r\n /** The Ids of any categories which were requested but were not yet loaded. */\r\n readonly missingCategoryIds: Id64Set;\r\n /** A promise which resolves to true when all of the requested categories have been loaded, or to false if not all categories were loaded.\r\n * Categories may fail to load if the request is explicitly canceled or if the IModelConnection is closed before all categories are loaded.\r\n */\r\n readonly promise: Promise<boolean>;\r\n /** Cancels the request. */\r\n cancel(): void;\r\n}\r\n\r\nconst invalidCategoryIdEntry = new Set<string>();\r\n\r\n/** A cache of information about the subcategories contained within an [[IModelConnection]]. It is populated on demand.\r\n * @internal\r\n */\r\nexport class SubCategoriesCache {\r\n private readonly _byCategoryId = new Map<string, Id64Set>();\r\n private readonly _appearances = new Map<string, SubCategoryAppearance>();\r\n private readonly _imodel: IModelConnection;\r\n private _missingAtTimeOfPreload: Id64Set | undefined;\r\n\r\n public constructor(imodel: IModelConnection) { this._imodel = imodel; }\r\n\r\n /** Get the Ids of all subcategories belonging to the category with the specified Id, or undefined if no such information is present. */\r\n public getSubCategories(categoryId: string): Id64Set | undefined { return this._byCategoryId.get(categoryId); }\r\n\r\n /** Get the base appearance of the subcategory with the specified Id, or undefined if no such information is present. */\r\n public getSubCategoryAppearance(subCategoryId: Id64String): SubCategoryAppearance | undefined { return this._appearances.get(subCategoryId.toString()); }\r\n\r\n /** Request that the subcategory information for all of the specified categories is loaded.\r\n * If all such information has already been loaded, returns undefined.\r\n * Otherwise, dispatches an asynchronous request to load those categories which are not already loaded and returns a cancellable request object\r\n * containing the corresponding promise and the set of categories still to be loaded.\r\n */\r\n public load(categoryIds: Id64Arg): SubCategoriesRequest | undefined {\r\n const missing = this.getMissing(categoryIds);\r\n if (undefined === missing)\r\n return undefined;\r\n\r\n const request = new SubCategoriesCache.Request(missing, this._imodel);\r\n const promise = request.dispatch().then((result?: SubCategoriesCache.Result) => {\r\n if (undefined !== result)\r\n this.processResults(result, missing);\r\n\r\n return !request.wasCanceled;\r\n });\r\n return {\r\n missingCategoryIds: missing,\r\n promise,\r\n cancel: () => request.cancel(),\r\n };\r\n }\r\n\r\n /** Load all subcategories that come from used spatial categories of the iModel into the cache. */\r\n public async loadAllUsedSpatialSubCategories(): Promise<void> {\r\n try {\r\n const results = await this._imodel.queryAllUsedSpatialSubCategories();\r\n if (undefined !== results){\r\n this.processResults(results, new Set<string>(), false);\r\n }\r\n } catch (e) {\r\n // In case of a truncated response, gracefully handle the error and exit.\r\n }\r\n\r\n }\r\n /** Given categoryIds, return which of these are not cached. */\r\n private getMissing(categoryIds: Id64Arg): Id64Set | undefined {\r\n let missing: Id64Set | undefined;\r\n for (const catId of Id64.iterable(categoryIds)) {\r\n if (undefined === this._byCategoryId.get(catId)) {\r\n if (undefined === missing)\r\n missing = new Set<string>();\r\n\r\n missing.add(catId);\r\n }\r\n }\r\n\r\n return missing;\r\n }\r\n\r\n public clear(): void {\r\n this._byCategoryId.clear();\r\n this._appearances.clear();\r\n }\r\n\r\n public onIModelConnectionClose(): void {\r\n this.clear();\r\n }\r\n\r\n private static createSubCategoryAppearance(json?: any) {\r\n let props: SubCategoryAppearance.Props | undefined;\r\n if (\"string\" === typeof json && 0 < json.length)\r\n props = JSON.parse(json);\r\n\r\n return new SubCategoryAppearance(props);\r\n }\r\n\r\n private processResults(result: SubCategoriesCache.Result, missing: Id64Set, override: boolean = true): void {\r\n for (const row of result){\r\n this.add(row.parentId, row.id, SubCategoriesCache.createSubCategoryAppearance(row.appearance), override);\r\n }\r\n\r\n // Ensure that any category Ids which returned no results (e.g., non-existent category, invalid Id, etc) are still recorded so they are not repeatedly re-requested\r\n for (const id of missing)\r\n if (undefined === this._byCategoryId.get(id))\r\n this._byCategoryId.set(id, invalidCategoryIdEntry);\r\n }\r\n\r\n /** Exposed strictly for tests.\r\n * @internal\r\n */\r\n public add(categoryId: string, subCategoryId: string, appearance: SubCategoryAppearance, override: boolean) {\r\n let set = this._byCategoryId.get(categoryId);\r\n if (undefined === set)\r\n this._byCategoryId.set(categoryId, set = new Set<string>());\r\n\r\n set.add(subCategoryId);\r\n if (override)\r\n this._appearances.set(subCategoryId, appearance);\r\n }\r\n\r\n public async getCategoryInfo(inputCategoryIds: Id64String | Iterable<Id64String>): Promise<Map<Id64String, IModelConnection.Categories.CategoryInfo>> {\r\n // Eliminate duplicates...\r\n const categoryIds = new Set<string>(typeof inputCategoryIds === \"string\" ? [inputCategoryIds] : inputCategoryIds);\r\n const req = this.load(categoryIds);\r\n if (req)\r\n await req.promise;\r\n\r\n const map = new Map<Id64String, IModelConnection.Categories.CategoryInfo>();\r\n for (const categoryId of categoryIds) {\r\n const subCategoryIds = this._byCategoryId.get(categoryId);\r\n if (!subCategoryIds)\r\n continue;\r\n\r\n const subCategories = this.mapSubCategoryInfos(categoryId, subCategoryIds);\r\n map.set(categoryId, { id: categoryId, subCategories });\r\n }\r\n\r\n return map;\r\n }\r\n\r\n public async getSubCategoryInfo(categoryId: Id64String, inputSubCategoryIds: Id64String | Iterable<Id64String>): Promise<Map<Id64String, IModelConnection.Categories.SubCategoryInfo>> {\r\n // Eliminate duplicates...\r\n const subCategoryIds = new Set<string>(typeof inputSubCategoryIds === \"string\" ? [inputSubCategoryIds] : inputSubCategoryIds);\r\n const req = this.load(categoryId);\r\n if (req)\r\n await req.promise;\r\n\r\n return this.mapSubCategoryInfos(categoryId, subCategoryIds);\r\n }\r\n\r\n private mapSubCategoryInfos(categoryId: Id64String, subCategoryIds: Set<Id64String>): Map<Id64String, IModelConnection.Categories.SubCategoryInfo> {\r\n const map = new Map<Id64String, IModelConnection.Categories.SubCategoryInfo>();\r\n for (const id of subCategoryIds) {\r\n const appearance = this._appearances.get(id);\r\n if (appearance)\r\n map.set(id, { id, categoryId, appearance });\r\n }\r\n\r\n return map;\r\n }\r\n}\r\n\r\n/** This namespace and the types within it are exported strictly for use in tests.\r\n * @internal\r\n */\r\nexport namespace SubCategoriesCache { // eslint-disable-line no-redeclare\r\n export type Result = SubCategoryResultRow[];\r\n\r\n export class Request {\r\n private readonly _imodel: IModelConnection;\r\n private readonly _categoryIds: CompressedId64Set[] = [];\r\n private readonly _result: Result = [];\r\n private _canceled = false;\r\n private _curCategoryIdsIndex = 0;\r\n\r\n public get wasCanceled() { return this._canceled || this._imodel.isClosed; }\r\n\r\n public constructor(categoryIds: Set<string>, imodel: IModelConnection, maxCategoriesPerQuery = 2500) {\r\n this._imodel = imodel;\r\n\r\n const catIds = [...categoryIds];\r\n OrderedId64Iterable.sortArray(catIds); // sort categories, so that given the same set of categoryIds we will always create the same batches.\r\n while (catIds.length !== 0) {\r\n const end = (catIds.length > maxCategoriesPerQuery) ? maxCategoriesPerQuery : catIds.length;\r\n const compressedIds = CompressedId64Set.compressArray(catIds.splice(0, end));\r\n this._categoryIds.push(compressedIds);\r\n }\r\n }\r\n\r\n public cancel() { this._canceled = true; }\r\n\r\n public async dispatch(): Promise<Result | undefined> {\r\n if (this.wasCanceled || this._curCategoryIdsIndex >= this._categoryIds.length) // handle case of empty category Id set...\r\n return undefined;\r\n\r\n try {\r\n const catIds = this._categoryIds[this._curCategoryIdsIndex];\r\n const result = await this._imodel.querySubCategories(catIds);\r\n this._result.push(...result);\r\n if (this.wasCanceled)\r\n return undefined;\r\n } catch {\r\n // ###TODO: detect cases in which retry is warranted\r\n // Note that currently, if we succeed in obtaining some pages of results and fail to retrieve another page, we will end up processing the\r\n // incomplete results. Since we're not retrying, that's the best we can do.\r\n }\r\n\r\n // Finished with current batch of categoryIds. Dispatch the next batch if one exists.\r\n if (++this._curCategoryIdsIndex < this._categoryIds.length) {\r\n if (this.wasCanceled)\r\n return undefined;\r\n else\r\n return this.dispatch();\r\n }\r\n\r\n // Even if we were canceled, we've retrieved all the rows. Might as well process them to prevent another request for some of the same rows from being enqueued.\r\n return this._result;\r\n }\r\n }\r\n\r\n export type QueueFunc = () => void;\r\n\r\n export class QueueEntry {\r\n public readonly categoryIds: Id64Set;\r\n public readonly funcs: QueueFunc[];\r\n\r\n public constructor(categoryIds: Id64Set, func: QueueFunc) {\r\n this.categoryIds = categoryIds;\r\n this.funcs = [func];\r\n }\r\n }\r\n\r\n /** A \"queue\" of SubCategoriesRequests, which consists of between 0 and 2 entries. Each entry specifies the set of category IDs to be loaded and a list of functions to be executed\r\n * when loading is completed. This is used to enforce ordering of operations upon subcategories despite the need to asynchronously load them. It incidentally also provides an\r\n * opportunity to reduce the number of backend requests by batching consecutive requests.\r\n * Chiefly used by [[Viewport]].\r\n * @internal\r\n */\r\n export class Queue {\r\n /* NB: Members marked protected for use in tests only. */\r\n protected _current?: QueueEntry;\r\n protected _next?: QueueEntry;\r\n protected _request?: SubCategoriesRequest;\r\n protected _disposed = false;\r\n\r\n /** Push a request onto the queue. The requested categories will be loaded if necessary, and then\r\n * the supplied function will be invoked. Any previously-pushed requests are guaranteed to be processed before this one.\r\n */\r\n public push(cache: SubCategoriesCache, categoryIds: Id64Arg, func: QueueFunc): void {\r\n if (this._disposed)\r\n return;\r\n else if (undefined === this._current)\r\n this.pushCurrent(cache, categoryIds, func);\r\n else\r\n this.pushNext(categoryIds, func);\r\n }\r\n\r\n /** Cancel all requests and empty the queue. */\r\n public dispose(): void {\r\n if (undefined !== this._request) {\r\n assert(undefined !== this._current);\r\n this._request.cancel();\r\n this._request = undefined;\r\n }\r\n\r\n this._current = this._next = undefined;\r\n this._disposed = true;\r\n }\r\n\r\n public get isEmpty(): boolean {\r\n return undefined === this._current && undefined === this._next;\r\n }\r\n\r\n private pushCurrent(cache: SubCategoriesCache, categoryIds: Id64Arg, func: QueueFunc): void {\r\n assert(undefined === this._next);\r\n assert(undefined === this._current);\r\n assert(undefined === this._request);\r\n\r\n this._request = cache.load(categoryIds);\r\n if (undefined === this._request) {\r\n // All requested categories are already loaded.\r\n func();\r\n return;\r\n } else {\r\n // We need to load the requested categories before invoking the function.\r\n this.processCurrent(cache, new QueueEntry(Id64.toIdSet(categoryIds, true), func));\r\n }\r\n }\r\n\r\n private processCurrent(cache: SubCategoriesCache, entry: QueueEntry): void {\r\n assert(undefined !== this._request);\r\n assert(undefined === this._current);\r\n assert(undefined === this._next);\r\n\r\n this._current = entry;\r\n this._request.promise.then((completed: boolean) => { // eslint-disable-line @typescript-eslint/no-floating-promises\r\n if (this._disposed)\r\n return;\r\n\r\n // Invoke all the functions which were awaiting this set of IModelConnection.Categories.\r\n assert(undefined !== this._current);\r\n if (completed)\r\n for (const func of this._current.funcs)\r\n func();\r\n\r\n this._request = undefined;\r\n this._current = undefined;\r\n\r\n // If we have more requests, process them.\r\n const next = this._next;\r\n this._next = undefined;\r\n if (undefined !== next) {\r\n this._request = cache.load(next.categoryIds);\r\n if (undefined === this._request) {\r\n // All categories loaded.\r\n for (const func of next.funcs)\r\n func();\r\n } else {\r\n // We need to load the requested categories before invoking the pending functions.\r\n this.processCurrent(cache, next);\r\n }\r\n }\r\n });\r\n }\r\n\r\n private pushNext(categoryIds: Id64Arg, func: QueueFunc): void {\r\n assert(undefined !== this._current);\r\n assert(undefined !== this._request);\r\n\r\n if (undefined === this._next) {\r\n // We have a request currently in process and none pending.\r\n // We could potentially determine that this request doesn't require any categories that are not already loaded or being loaded by the current request.\r\n // But we will find that out (synchronously) when current request completes, unless more requests come in. Probably not worth it.\r\n this._next = new QueueEntry(Id64.toIdSet(categoryIds, true), func);\r\n } else {\r\n // We have a request currently in process, and one or more pending. Append this one to the pending.\r\n this._next.funcs.push(func);\r\n for (const categoryId of Id64.iterable(categoryIds))\r\n this._next.categoryIds.add(categoryId);\r\n }\r\n }\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ViewCreator3d.d.ts","sourceRoot":"","sources":["../../src/ViewCreator3d.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,OAAO,EAAsC,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAMrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,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D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,8DAA8D;IAC9D,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;;OAOG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAED;;;;;;;;;GASG;AACH,qBAAa,aAAa;IAKZ,OAAO,CAAC,OAAO;IAJ3B;;;OAGG;gBACiB,OAAO,EAAE,gBAAgB;IAE7C;;;;;OAKG;IACU,iBAAiB,CAAC,OAAO,CAAC,EAAE,oBAAoB,EAAE,QAAQ,CAAC,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC;IAgC3G;;;;OAIG;YACW,qBAAqB;IAkGnC;;;OAGG;YACW,cAAc;IAwB5B;;OAEG;YACW,iBAAiB;CAUhC"}
@@ -41,6 +41,7 @@ export class ViewCreator3d {
41
41
  const props = await this._createViewStateProps(CompressedId64Set.decompressArray(serializedProps.modelIds), CompressedId64Set.decompressArray(serializedProps.categoryIds), baseExtents, options);
42
42
  const viewState = SpatialViewState.createFromProps(props, this._imodel);
43
43
  try {
44
+ await viewState.iModel.subcategories.loadAllUsedSpatialSubCategories();
44
45
  await viewState.load();
45
46
  }
46
47
  catch {
@@ -1 +1 @@
1
- {"version":3,"file":"ViewCreator3d.js","sourceRoot":"","sources":["../../src/ViewCreator3d.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAyB,MAAM,qBAAqB,CAAC;AACrF,OAAO,EACL,MAAM,EAAyB,IAAI,EAAwD,WAAW,EAAE,MAAM,EAAE,sBAAsB,EAClH,UAAU,GAC/B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,gBAAgB,EAAE,M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Aa,CAAC,MAAM,EAAE;YACxD,mBAAmB,EAAE,aAAa,CAAC,MAAM,EAAE;YAC3C,iBAAiB,EAAE,aAAa,CAAC,YAAY,CAAC,MAAM,EAAE;SACvD,CAAC;QACF,MAAM,kBAAkB,GAAG,kBAAkB,CAAC,iBAAiB,CAAC;QAChE,IAAI,kBAAkB,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;YACpD,kBAAkB,CAAC,cAAc,CAAC,MAAM,GAAG;gBACzC,GAAG,kBAAkB,CAAC,cAAc,CAAC,MAAM;gBAC3C,GAAG,cAAc,CAAC,iBAAiB,CAAC,cAAe,CAAC,MAAM;aAC3D,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,GAAG,kBAAkB,EAAE,GAAG,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,CAAC;IAC7F,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,iBAAiB;QAC7B,mDAAmD;QACnD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,CAAC;QAC7D,IAAI,MAAM,KAAK,IAAI,CAAC,OAAO;YACzB,OAAO,MAAM,CAAC;QAEhB,gCAAgC;QAChC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,aAAa,EAAE,CAAC,CAAC;QAC9H,OAAO,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5D,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\r\n/** @packageDocumentation\r\n * @module Views\r\n */\r\n\r\nimport { CompressedId64Set, Id64, Id64Array, Id64String } from \"@itwin/core-bentley\";\r\nimport {\r\n Camera, CategorySelectorProps, Code, CustomViewState3dCreatorOptions, DisplayStyle3dProps, Environment, IModel, IModelReadRpcInterface,\r\n ModelSelectorProps, RenderMode, ViewDefinition3dProps, ViewStateProps,\r\n} from \"@itwin/core-common\";\r\nimport { Range3d } from \"@itwin/core-geometry\";\r\nimport { IModelConnection } from \"./IModelConnection\";\r\nimport { SpatialViewState } from \"./SpatialViewState\";\r\nimport { StandardViewId } from \"./StandardView\";\r\nimport { ViewState } from \"./ViewState\";\r\n\r\n/** Api for creating a 3d default view for an iModel. Either takes in a list of modelIds, or displays all 3d models by default. */\r\n\r\n/** Options for creating a [[ViewState3d]] via [[ViewCreator3d]].\r\n * @public\r\n * @extensions\r\n*/\r\nexport interface ViewCreator3dOptions {\r\n /** Turn the [[Camera]] on to produce a perspective view.\r\n * Default: true\r\n */\r\n cameraOn?: boolean;\r\n /** Enables display of a [[SkyBox]] in the view. */\r\n skyboxOn?: boolean;\r\n /** Orients the view to one of the standard view rotations. */\r\n standardViewId?: StandardViewId;\r\n /** Merge in props from a persistent \"seed\" view obtained from the iModel.\r\n * @note The selection of the seed view is somewhat arbitrary, and the contents and styling of that view are unpredictable, so this option is not recommended.\r\n */\r\n useSeedView?: boolean;\r\n /** The desired aspect ratio of the [[Viewport]] in which the view is to be displayed.\r\n * This is used to adjust the view's frustum so that the viewed models are better centered within the viewport.\r\n */\r\n vpAspect?: number;\r\n /** Indicates that geometry belonging to every [SubCategory]($backend) should be visible within the view.\r\n * Each subcategory has a [SubCategoryAppearance]($common) that specifies how its geometry is displayed. This includes a [SubCategoryAppearance.invisible]($common) property that,\r\n * when set to `true`, indicates the geometry should not be displayed at all. A view can override the appearances of any subcategories using a [SubCategoryOverride]($common).\r\n * If `allSubCategoriesVisible` is `true`, [[ViewCreator3d]] will apply such an override to every viewed subcategory to change [SubCategoryOverride.invisible]($common) to `false`, making\r\n * every subcategory visible.\r\n * @note Subcategories are typically set to invisible by default for a reason.\r\n * Forcing them all to be visible may produce undesirable results, such as z-fighting between geometry on different subcategories that are not intended to be viewed together.\r\n */\r\n allSubCategoriesVisible?: boolean;\r\n}\r\n\r\n/**\r\n * API for creating a 3D default [[ViewState3d]] for an iModel. @see [[ViewCreator2d]] to create a view for a 2d model.\r\n * Example usage:\r\n * ```ts\r\n * const viewCreator = new ViewCreator3d(imodel);\r\n * const defaultView = await viewCreator.createDefaultView({skyboxOn: true});\r\n * ```\r\n * @public\r\n * @extensions\r\n */\r\nexport class ViewCreator3d {\r\n /**\r\n * Constructs a ViewCreator3d using an [[IModelConnection]].\r\n * @param _imodel [[IModelConnection]] to query for categories and/or models.\r\n */\r\n constructor(private _imodel: IModelConnection) { }\r\n\r\n /**\r\n * Creates a default [[ViewState3d]] based on the model ids passed in. If no model ids are passed in, all 3D models in the iModel are used.\r\n * @param [options] Options for creating the view.\r\n * @param [modelIds] Ids of models to display in the view.\r\n * @throws [IModelError]($common) If no 3d models are found in the iModel.\r\n */\r\n public async createDefaultView(options?: ViewCreator3dOptions, modelIds?: Id64String[]): Promise<ViewState> {\r\n const rpcOptions: CustomViewState3dCreatorOptions = modelIds ? { modelIds: CompressedId64Set.sortAndCompress(modelIds) } : {};\r\n const rpc = IModelReadRpcInterface.getClientForRouting(this._imodel.routingContext.token);\r\n const serializedProps = await rpc.getCustomViewState3dData(this._imodel.getRpcProps(), rpcOptions);\r\n\r\n const baseExtents = Range3d.fromJSON(serializedProps.modelExtents);\r\n const props = await this._createViewStateProps(\r\n CompressedId64Set.decompressArray(serializedProps.modelIds),\r\n CompressedId64Set.decompressArray(serializedProps.categoryIds),\r\n baseExtents,\r\n options,\r\n );\r\n\r\n const viewState = SpatialViewState.createFromProps(props, this._imodel);\r\n try {\r\n await viewState.load();\r\n } catch {\r\n }\r\n\r\n if (options?.standardViewId)\r\n viewState.setStandardRotation(options.standardViewId);\r\n\r\n if (options?.allSubCategoriesVisible)\r\n viewState.displayStyle.enableAllLoadedSubCategories(viewState.categorySelector.categories);\r\n\r\n const range = viewState.computeFitRange({ baseExtents });\r\n viewState.lookAtVolume(range, options?.vpAspect);\r\n\r\n return viewState;\r\n }\r\n\r\n /**\r\n * Generates a view state props object for creating a view. Merges display styles with a seed view if the options.useSeedView is true\r\n * @param models Models to put in view props\r\n * @param options view creation options like camera On and skybox On\r\n */\r\n private async _createViewStateProps(models: Id64Array, categories: Id64Array, modelExtents: Range3d, options?: ViewCreator3dOptions): Promise<ViewStateProps> {\r\n // Use dictionary model in all props\r\n const dictionaryId = IModel.dictionaryId;\r\n\r\n if (modelExtents.isNull)\r\n modelExtents.setFrom(this._imodel.projectExtents);\r\n\r\n let originX = modelExtents.low.x;\r\n let originY = modelExtents.low.y;\r\n const originZ = modelExtents.low.z;\r\n let deltaX = modelExtents.xLength();\r\n let deltaY = modelExtents.yLength();\r\n const deltaZ = modelExtents.zLength();\r\n\r\n // if vp aspect given, update model extents to fit view\r\n if (options?.vpAspect) {\r\n const modelAspect = deltaY / deltaX;\r\n\r\n if (modelAspect > options.vpAspect) {\r\n const xFix = deltaY / options.vpAspect;\r\n originX = originX - xFix / 2;\r\n deltaX = deltaX + xFix;\r\n } else if (modelAspect < options.vpAspect) {\r\n const yFix = deltaX * options.vpAspect;\r\n originY = originY - yFix / 2;\r\n deltaY = deltaY + yFix;\r\n }\r\n }\r\n\r\n const categorySelectorProps: CategorySelectorProps = {\r\n categories,\r\n code: Code.createEmpty(),\r\n model: dictionaryId,\r\n classFullName: \"BisCore:CategorySelector\",\r\n };\r\n\r\n const modelSelectorProps: ModelSelectorProps = {\r\n models,\r\n code: Code.createEmpty(),\r\n model: dictionaryId,\r\n classFullName: \"BisCore:ModelSelector\",\r\n };\r\n\r\n const cameraData = new Camera();\r\n const cameraOn = options?.cameraOn !== false;\r\n const viewDefinitionProps: ViewDefinition3dProps = {\r\n categorySelectorId: \"\",\r\n displayStyleId: \"\",\r\n code: Code.createEmpty(),\r\n model: dictionaryId,\r\n origin: { x: originX, y: originY, z: originZ },\r\n extents: { x: deltaX, y: deltaY, z: deltaZ },\r\n classFullName: \"BisCore:SpatialViewDefinition\",\r\n cameraOn,\r\n camera: {\r\n lens: cameraData.lens.toJSON(),\r\n focusDist: cameraData.focusDist,\r\n eye: cameraData.eye.toJSON(),\r\n },\r\n };\r\n\r\n const displayStyleProps: DisplayStyle3dProps = {\r\n code: Code.createEmpty(),\r\n model: dictionaryId,\r\n classFullName: \"BisCore:DisplayStyle3d\",\r\n jsonProperties: {\r\n styles: {\r\n viewflags: {\r\n renderMode: RenderMode.SmoothShade,\r\n noSourceLights: false,\r\n noCameraLights: false,\r\n noSolarLight: false,\r\n noConstruct: true,\r\n noTransp: false,\r\n visEdges: false,\r\n backgroundMap: this._imodel.isGeoLocated,\r\n },\r\n environment:\r\n options !== undefined &&\r\n options.skyboxOn !== undefined &&\r\n options.skyboxOn\r\n ? Environment.defaults.withDisplay({ sky: true }).toJSON()\r\n : undefined,\r\n },\r\n },\r\n };\r\n\r\n const viewStateProps: ViewStateProps = {\r\n displayStyleProps,\r\n categorySelectorProps,\r\n modelSelectorProps,\r\n viewDefinitionProps,\r\n };\r\n\r\n // merge seed view props if needed\r\n return options?.useSeedView ? this._mergeSeedView(viewStateProps) : viewStateProps;\r\n }\r\n\r\n /**\r\n * Merges a seed view in the iModel with the passed view state props. It will be a no-op if there are no default 3D views in the iModel\r\n * @param viewStateProps Input view props to be merged\r\n */\r\n private async _mergeSeedView(viewStateProps: ViewStateProps): Promise<ViewStateProps> {\r\n const viewId = await this._getDefaultViewId();\r\n // Handle iModels without any default view id\r\n if (viewId === undefined)\r\n return viewStateProps;\r\n\r\n const seedViewState = (await this._imodel.views.load(viewId) as SpatialViewState);\r\n const seedViewStateProps = {\r\n categorySelectorProps: seedViewState.categorySelector.toJSON(),\r\n modelSelectorProps: seedViewState.modelSelector.toJSON(),\r\n viewDefinitionProps: seedViewState.toJSON(),\r\n displayStyleProps: seedViewState.displayStyle.toJSON(),\r\n };\r\n const mergedDisplayProps = seedViewStateProps.displayStyleProps;\r\n if (mergedDisplayProps.jsonProperties !== undefined) {\r\n mergedDisplayProps.jsonProperties.styles = {\r\n ...mergedDisplayProps.jsonProperties.styles,\r\n ...viewStateProps.displayStyleProps.jsonProperties!.styles,\r\n };\r\n }\r\n\r\n return { ...seedViewStateProps, ...viewStateProps, displayStyleProps: mergedDisplayProps };\r\n }\r\n\r\n /**\r\n * Get the Id of the default view.\r\n */\r\n private async _getDefaultViewId(): Promise<Id64String | undefined> {\r\n // eslint-disable-next-line deprecation/deprecation\r\n const viewId = await this._imodel.views.queryDefaultViewId();\r\n if (viewId !== Id64.invalid)\r\n return viewId;\r\n\r\n // Return the first spatial view\r\n const viewList = await this._imodel.views.getViewList({ wantPrivate: false, limit: 1, from: SpatialViewState.classFullName });\r\n return viewList.length === 0 ? undefined : viewList[0].id;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"ViewCreator3d.js","sourceRoot":"","sources":["../../src/ViewCreator3d.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAyB,MAAM,qBAAqB,CAAC;AACrF,OAAO,EACL,MAAM,EAAyB,IAAI,EAAwD,WAAW,EAAE,MAAM,EAAE,sBAAsB,EAClH,UAAU,GAC/B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAsCtD;;;;;;;;;GASG;AACH,MAAM,OAAO,aAAa;IACxB;;;OAGG;IACH,YAAoB,OAAyB;QAAzB,YAAO,GAAP,OAAO,CAAkB;IAAI,CAAC;IAElD;;;;;OAKG;IACI,KAAK,CAAC,iBAAiB,CAAC,OAA8B,EAAE,QAAuB;QACpF,MAAM,UAAU,GAAoC,QAAQ,CAAC,CAAC,CAAC,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E,IAAI,kBAAkB,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;YACpD,kBAAkB,CAAC,cAAc,CAAC,MAAM,GAAG;gBACzC,GAAG,kBAAkB,CAAC,cAAc,CAAC,MAAM;gBAC3C,GAAG,cAAc,CAAC,iBAAiB,CAAC,cAAe,CAAC,MAAM;aAC3D,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,GAAG,kBAAkB,EAAE,GAAG,cAAc,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,CAAC;IAC7F,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,iBAAiB;QAC7B,mDAAmD;QACnD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,CAAC;QAC7D,IAAI,MAAM,KAAK,IAAI,CAAC,OAAO;YACzB,OAAO,MAAM,CAAC;QAEhB,gCAAgC;QAChC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,aAAa,EAAE,CAAC,CAAC;QAC9H,OAAO,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5D,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\r\n/** @packageDocumentation\r\n * @module Views\r\n */\r\n\r\nimport { CompressedId64Set, Id64, Id64Array, Id64String } from \"@itwin/core-bentley\";\r\nimport {\r\n Camera, CategorySelectorProps, Code, CustomViewState3dCreatorOptions, DisplayStyle3dProps, Environment, IModel, IModelReadRpcInterface,\r\n ModelSelectorProps, RenderMode, ViewDefinition3dProps, ViewStateProps,\r\n} from \"@itwin/core-common\";\r\nimport { Range3d } from \"@itwin/core-geometry\";\r\nimport { IModelConnection } from \"./IModelConnection\";\r\nimport { SpatialViewState } from \"./SpatialViewState\";\r\nimport { StandardViewId } from \"./StandardView\";\r\nimport { ViewState } from \"./ViewState\";\r\n\r\n/** Api for creating a 3d default view for an iModel. Either takes in a list of modelIds, or displays all 3d models by default. */\r\n\r\n/** Options for creating a [[ViewState3d]] via [[ViewCreator3d]].\r\n * @public\r\n * @extensions\r\n*/\r\nexport interface ViewCreator3dOptions {\r\n /** Turn the [[Camera]] on to produce a perspective view.\r\n * Default: true\r\n */\r\n cameraOn?: boolean;\r\n /** Enables display of a [[SkyBox]] in the view. */\r\n skyboxOn?: boolean;\r\n /** Orients the view to one of the standard view rotations. */\r\n standardViewId?: StandardViewId;\r\n /** Merge in props from a persistent \"seed\" view obtained from the iModel.\r\n * @note The selection of the seed view is somewhat arbitrary, and the contents and styling of that view are unpredictable, so this option is not recommended.\r\n */\r\n useSeedView?: boolean;\r\n /** The desired aspect ratio of the [[Viewport]] in which the view is to be displayed.\r\n * This is used to adjust the view's frustum so that the viewed models are better centered within the viewport.\r\n */\r\n vpAspect?: number;\r\n /** Indicates that geometry belonging to every [SubCategory]($backend) should be visible within the view.\r\n * Each subcategory has a [SubCategoryAppearance]($common) that specifies how its geometry is displayed. This includes a [SubCategoryAppearance.invisible]($common) property that,\r\n * when set to `true`, indicates the geometry should not be displayed at all. A view can override the appearances of any subcategories using a [SubCategoryOverride]($common).\r\n * If `allSubCategoriesVisible` is `true`, [[ViewCreator3d]] will apply such an override to every viewed subcategory to change [SubCategoryOverride.invisible]($common) to `false`, making\r\n * every subcategory visible.\r\n * @note Subcategories are typically set to invisible by default for a reason.\r\n * Forcing them all to be visible may produce undesirable results, such as z-fighting between geometry on different subcategories that are not intended to be viewed together.\r\n */\r\n allSubCategoriesVisible?: boolean;\r\n}\r\n\r\n/**\r\n * API for creating a 3D default [[ViewState3d]] for an iModel. @see [[ViewCreator2d]] to create a view for a 2d model.\r\n * Example usage:\r\n * ```ts\r\n * const viewCreator = new ViewCreator3d(imodel);\r\n * const defaultView = await viewCreator.createDefaultView({skyboxOn: true});\r\n * ```\r\n * @public\r\n * @extensions\r\n */\r\nexport class ViewCreator3d {\r\n /**\r\n * Constructs a ViewCreator3d using an [[IModelConnection]].\r\n * @param _imodel [[IModelConnection]] to query for categories and/or models.\r\n */\r\n constructor(private _imodel: IModelConnection) { }\r\n\r\n /**\r\n * Creates a default [[ViewState3d]] based on the model ids passed in. If no model ids are passed in, all 3D models in the iModel are used.\r\n * @param [options] Options for creating the view.\r\n * @param [modelIds] Ids of models to display in the view.\r\n * @throws [IModelError]($common) If no 3d models are found in the iModel.\r\n */\r\n public async createDefaultView(options?: ViewCreator3dOptions, modelIds?: Id64String[]): Promise<ViewState> {\r\n const rpcOptions: CustomViewState3dCreatorOptions = modelIds ? { modelIds: CompressedId64Set.sortAndCompress(modelIds) } : {};\r\n const rpc = IModelReadRpcInterface.getClientForRouting(this._imodel.routingContext.token);\r\n const serializedProps = await rpc.getCustomViewState3dData(this._imodel.getRpcProps(), rpcOptions);\r\n\r\n const baseExtents = Range3d.fromJSON(serializedProps.modelExtents);\r\n const props = await this._createViewStateProps(\r\n CompressedId64Set.decompressArray(serializedProps.modelIds),\r\n CompressedId64Set.decompressArray(serializedProps.categoryIds),\r\n baseExtents,\r\n options,\r\n );\r\n\r\n const viewState = SpatialViewState.createFromProps(props, this._imodel);\r\n try {\r\n await viewState.iModel.subcategories.loadAllUsedSpatialSubCategories();\r\n await viewState.load();\r\n } catch {\r\n }\r\n\r\n if (options?.standardViewId)\r\n viewState.setStandardRotation(options.standardViewId);\r\n\r\n if (options?.allSubCategoriesVisible)\r\n viewState.displayStyle.enableAllLoadedSubCategories(viewState.categorySelector.categories);\r\n\r\n const range = viewState.computeFitRange({ baseExtents });\r\n viewState.lookAtVolume(range, options?.vpAspect);\r\n\r\n return viewState;\r\n }\r\n\r\n /**\r\n * Generates a view state props object for creating a view. Merges display styles with a seed view if the options.useSeedView is true\r\n * @param models Models to put in view props\r\n * @param options view creation options like camera On and skybox On\r\n */\r\n private async _createViewStateProps(models: Id64Array, categories: Id64Array, modelExtents: Range3d, options?: ViewCreator3dOptions): Promise<ViewStateProps> {\r\n // Use dictionary model in all props\r\n const dictionaryId = IModel.dictionaryId;\r\n\r\n if (modelExtents.isNull)\r\n modelExtents.setFrom(this._imodel.projectExtents);\r\n\r\n let originX = modelExtents.low.x;\r\n let originY = modelExtents.low.y;\r\n const originZ = modelExtents.low.z;\r\n let deltaX = modelExtents.xLength();\r\n let deltaY = modelExtents.yLength();\r\n const deltaZ = modelExtents.zLength();\r\n\r\n // if vp aspect given, update model extents to fit view\r\n if (options?.vpAspect) {\r\n const modelAspect = deltaY / deltaX;\r\n\r\n if (modelAspect > options.vpAspect) {\r\n const xFix = deltaY / options.vpAspect;\r\n originX = originX - xFix / 2;\r\n deltaX = deltaX + xFix;\r\n } else if (modelAspect < options.vpAspect) {\r\n const yFix = deltaX * options.vpAspect;\r\n originY = originY - yFix / 2;\r\n deltaY = deltaY + yFix;\r\n }\r\n }\r\n\r\n const categorySelectorProps: CategorySelectorProps = {\r\n categories,\r\n code: Code.createEmpty(),\r\n model: dictionaryId,\r\n classFullName: \"BisCore:CategorySelector\",\r\n };\r\n\r\n const modelSelectorProps: ModelSelectorProps = {\r\n models,\r\n code: Code.createEmpty(),\r\n model: dictionaryId,\r\n classFullName: \"BisCore:ModelSelector\",\r\n };\r\n\r\n const cameraData = new Camera();\r\n const cameraOn = options?.cameraOn !== false;\r\n const viewDefinitionProps: ViewDefinition3dProps = {\r\n categorySelectorId: \"\",\r\n displayStyleId: \"\",\r\n code: Code.createEmpty(),\r\n model: dictionaryId,\r\n origin: { x: originX, y: originY, z: originZ },\r\n extents: { x: deltaX, y: deltaY, z: deltaZ },\r\n classFullName: \"BisCore:SpatialViewDefinition\",\r\n cameraOn,\r\n camera: {\r\n lens: cameraData.lens.toJSON(),\r\n focusDist: cameraData.focusDist,\r\n eye: cameraData.eye.toJSON(),\r\n },\r\n };\r\n\r\n const displayStyleProps: DisplayStyle3dProps = {\r\n code: Code.createEmpty(),\r\n model: dictionaryId,\r\n classFullName: \"BisCore:DisplayStyle3d\",\r\n jsonProperties: {\r\n styles: {\r\n viewflags: {\r\n renderMode: RenderMode.SmoothShade,\r\n noSourceLights: false,\r\n noCameraLights: false,\r\n noSolarLight: false,\r\n noConstruct: true,\r\n noTransp: false,\r\n visEdges: false,\r\n backgroundMap: this._imodel.isGeoLocated,\r\n },\r\n environment:\r\n options !== undefined &&\r\n options.skyboxOn !== undefined &&\r\n options.skyboxOn\r\n ? Environment.defaults.withDisplay({ sky: true }).toJSON()\r\n : undefined,\r\n },\r\n },\r\n };\r\n\r\n const viewStateProps: ViewStateProps = {\r\n displayStyleProps,\r\n categorySelectorProps,\r\n modelSelectorProps,\r\n viewDefinitionProps,\r\n };\r\n\r\n // merge seed view props if needed\r\n return options?.useSeedView ? this._mergeSeedView(viewStateProps) : viewStateProps;\r\n }\r\n\r\n /**\r\n * Merges a seed view in the iModel with the passed view state props. It will be a no-op if there are no default 3D views in the iModel\r\n * @param viewStateProps Input view props to be merged\r\n */\r\n private async _mergeSeedView(viewStateProps: ViewStateProps): Promise<ViewStateProps> {\r\n const viewId = await this._getDefaultViewId();\r\n // Handle iModels without any default view id\r\n if (viewId === undefined)\r\n return viewStateProps;\r\n\r\n const seedViewState = (await this._imodel.views.load(viewId) as SpatialViewState);\r\n const seedViewStateProps = {\r\n categorySelectorProps: seedViewState.categorySelector.toJSON(),\r\n modelSelectorProps: seedViewState.modelSelector.toJSON(),\r\n viewDefinitionProps: seedViewState.toJSON(),\r\n displayStyleProps: seedViewState.displayStyle.toJSON(),\r\n };\r\n const mergedDisplayProps = seedViewStateProps.displayStyleProps;\r\n if (mergedDisplayProps.jsonProperties !== undefined) {\r\n mergedDisplayProps.jsonProperties.styles = {\r\n ...mergedDisplayProps.jsonProperties.styles,\r\n ...viewStateProps.displayStyleProps.jsonProperties!.styles,\r\n };\r\n }\r\n\r\n return { ...seedViewStateProps, ...viewStateProps, displayStyleProps: mergedDisplayProps };\r\n }\r\n\r\n /**\r\n * Get the Id of the default view.\r\n */\r\n private async _getDefaultViewId(): Promise<Id64String | undefined> {\r\n // eslint-disable-next-line deprecation/deprecation\r\n const viewId = await this._imodel.views.queryDefaultViewId();\r\n if (viewId !== Id64.invalid)\r\n return viewId;\r\n\r\n // Return the first spatial view\r\n const viewList = await this._imodel.views.getViewList({ wantPrivate: false, limit: 1, from: SpatialViewState.classFullName });\r\n return viewList.length === 0 ? undefined : viewList[0].id;\r\n }\r\n}\r\n"]}