@itwin/core-frontend 5.12.0-dev.13 → 5.12.0-dev.15

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.
Files changed (39) hide show
  1. package/lib/cjs/AccuDraw.d.ts.map +1 -1
  2. package/lib/cjs/AccuDraw.js +7 -2
  3. package/lib/cjs/AccuDraw.js.map +1 -1
  4. package/lib/cjs/AuxCoordSys.d.ts +11 -4
  5. package/lib/cjs/AuxCoordSys.d.ts.map +1 -1
  6. package/lib/cjs/AuxCoordSys.js +12 -6
  7. package/lib/cjs/AuxCoordSys.js.map +1 -1
  8. package/lib/cjs/EntityState.js +1 -1
  9. package/lib/cjs/EntityState.js.map +1 -1
  10. package/lib/cjs/IpcApp.d.ts +37 -0
  11. package/lib/cjs/IpcApp.d.ts.map +1 -1
  12. package/lib/cjs/IpcApp.js +56 -26
  13. package/lib/cjs/IpcApp.js.map +1 -1
  14. package/lib/cjs/tile/TileRequestChannel.js.map +1 -1
  15. package/lib/cjs/tools/AccuDrawTool.d.ts +20 -3
  16. package/lib/cjs/tools/AccuDrawTool.d.ts.map +1 -1
  17. package/lib/cjs/tools/AccuDrawTool.js +108 -58
  18. package/lib/cjs/tools/AccuDrawTool.js.map +1 -1
  19. package/lib/esm/AccuDraw.d.ts.map +1 -1
  20. package/lib/esm/AccuDraw.js +8 -3
  21. package/lib/esm/AccuDraw.js.map +1 -1
  22. package/lib/esm/AuxCoordSys.d.ts +11 -4
  23. package/lib/esm/AuxCoordSys.d.ts.map +1 -1
  24. package/lib/esm/AuxCoordSys.js +13 -7
  25. package/lib/esm/AuxCoordSys.js.map +1 -1
  26. package/lib/esm/EntityState.js +1 -1
  27. package/lib/esm/EntityState.js.map +1 -1
  28. package/lib/esm/IpcApp.d.ts +37 -0
  29. package/lib/esm/IpcApp.d.ts.map +1 -1
  30. package/lib/esm/IpcApp.js +56 -27
  31. package/lib/esm/IpcApp.js.map +1 -1
  32. package/lib/esm/tile/TileRequestChannel.js.map +1 -1
  33. package/lib/esm/tools/AccuDrawTool.d.ts +20 -3
  34. package/lib/esm/tools/AccuDrawTool.d.ts.map +1 -1
  35. package/lib/esm/tools/AccuDrawTool.js +109 -59
  36. package/lib/esm/tools/AccuDrawTool.js.map +1 -1
  37. package/lib/public/scripts/parse-imdl-worker.js +1 -1
  38. package/lib/workers/webpack/parse-imdl-worker.js +1 -1
  39. package/package.json +23 -23
@@ -1 +1 @@
1
- {"version":3,"file":"TileRequestChannel.js","sourceRoot":"","sources":["../../../src/tile/TileRequestChannel.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAI5D,MAAM,gBAAiB,SAAQ,aAA0B;IACvD;QACE,KAAK,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACjB,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC;YACrE,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;QACzD,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAmBD;;;;;;GAMG;AACH,MAAM,OAAO,4BAA4B;IACvC,uEAAuE;IAChE,kBAAkB,GAAG,CAAC,CAAC;IAC9B,8EAA8E;IACvE,iBAAiB,GAAG,CAAC,CAAC;IAC7B,qEAAqE;IAC9D,WAAW,GAAG,CAAC,CAAC;IACvB,kEAAkE;IAC3D,sBAAsB,GAAG,CAAC,CAAC;IAClC,+DAA+D;IACxD,mBAAmB,GAAG,CAAC,CAAC;IAC/B,kEAAkE;IAC3D,qBAAqB,GAAG,CAAC,CAAC;IACjC;;OAEG;IACI,eAAe,GAAG,CAAC,CAAC;IAC3B;;OAEG;IACI,uBAAuB,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ACO,iBAAiB,CAAC,OAAoB;QAC9C,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;QACxD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tiles\n */\n\nimport { assert, PriorityQueue } from \"@itwin/core-bentley\";\nimport { IModelConnection } from \"../IModelConnection\";\nimport { Tile, TileContent, TileRequest } from \"./internal\";\n\nclass TileRequestQueue extends PriorityQueue<TileRequest> {\n public constructor() {\n super((lhs, rhs) => {\n const diff = lhs.tile.tree.loadPriority - rhs.tile.tree.loadPriority;\n return 0 !== diff ? diff : lhs.priority - rhs.priority;\n });\n }\n}\n\n/** As part of a [[TileRequestChannelStatistics]], summarizes cumulative time spent decoding tile content.\n * For each Tile, the time elapsed between receiving the raw tile content (e.g., over the network) and converting it to a [[TileContent]] via [[Tile.readContent]]\n * is recorded.\n * All times are reported in milliseconds.\n * @beta\n */\nexport interface TileContentDecodingStatistics {\n /** The total number of milliseconds spent decoding content. */\n total: number;\n /** The mean (average) number of milliseconds spent decoding content. */\n mean: number;\n /** The longest amount of time, in milliseconds, spent decoding any single tile's content. */\n max: number;\n /** The shortest amount of time, in milliseconds, spent decoding any single tile's content. */\n min: number;\n}\n\n/** Statistics regarding the current and cumulative state of one or more [[TileRequestChannel]]s. Useful for monitoring performance and diagnosing problems.\n * @see [[TileRequestChannel.statistics]] for a specific channel's statistics.\n * @see [[TileRequestChannels.statistics]] for statistics from all channels.\n * @see [[TileAdmin.statistics]] for additional statistics.\n * @public\n * @extensions\n */\nexport class TileRequestChannelStatistics {\n /** The number of queued requests that have not yet been dispatched. */\n public numPendingRequests = 0;\n /** The number of requests that have been dispatched but not yet completed. */\n public numActiveRequests = 0;\n /** The number of requests canceled during the most recent update. */\n public numCanceled = 0;\n /** The total number of completed requests during this session. */\n public totalCompletedRequests = 0;\n /** The total number of failed requests during this session. */\n public totalFailedRequests = 0;\n /** The total number of timed-out requests during this session. */\n public totalTimedOutRequests = 0;\n /** The total number of completed requests during this session which produced an empty tile.\n * These tiles also contribute to [[totalCompletedRequests]], but not to [[totalUndisplayableTiles]].\n */\n public totalEmptyTiles = 0;\n /** The total number of completed requests during this session that produced an undisplayable tile.\n * These tiles also contribute to [[totalCompletedRequests]], but not to [[totalEmptyTiles]].\n */\n public totalUndisplayableTiles = 0;\n /** The total number of tiles whose contents were not found in cloud storage cache and therefore resulted in a backend request to generate the tile content. */\n public totalCacheMisses = 0;\n /** The total number of tiles for which content requests were dispatched. */\n public totalDispatchedRequests = 0;\n /** The total number of tiles for which content requests were dispatched and then canceled on the backend before completion. */\n public totalAbortedRequests = 0;\n /** Statistics summarizing time spent decoding tile content.\n * @beta\n */\n public decoding: TileContentDecodingStatistics = {\n total: 0,\n mean: 0,\n max: Number.MIN_SAFE_INTEGER,\n min: Number.MAX_SAFE_INTEGER,\n };\n\n /** @internal */\n public addTo(stats: TileRequestChannelStatistics): void {\n for (const propName in this) { // eslint-disable-line guard-for-in\n const key = propName as keyof TileRequestChannelStatistics;\n const val = this[key];\n if (typeof val === \"number\") {\n assert(typeof stats[key] === \"number\");\n (stats[key] as number) += val; // eslint-disable-line @typescript-eslint/no-unnecessary-type-assertion\n }\n }\n\n stats.decoding.total += this.decoding.total;\n stats.decoding.max = Math.max(this.decoding.max, stats.decoding.max);\n stats.decoding.min = Math.min(this.decoding.min, stats.decoding.min);\n\n if (stats.totalCompletedRequests > 0)\n stats.decoding.mean = (stats.decoding.total) / stats.totalCompletedRequests;\n }\n\n /** @internal */\n public recordCompletion(tile: Tile, elapsedMilliseconds: number): void {\n ++this.totalCompletedRequests;\n if (tile.isEmpty)\n ++this.totalEmptyTiles;\n else if (!tile.isDisplayable)\n ++this.totalUndisplayableTiles;\n\n this.decoding.total += elapsedMilliseconds;\n this.decoding.mean = this.decoding.total / this.totalCompletedRequests;\n this.decoding.max = Math.max(this.decoding.max, elapsedMilliseconds);\n this.decoding.min = Math.min(this.decoding.min, elapsedMilliseconds);\n }\n}\n\n/** A channel over which requests for tile content can be made. The channel may request content over HTTP, calls to the backend via IPC or RPC, or any other method like generating the content\n * on the frontend. The channel consists of a queue of pending requests and a set of \"active\" requests (dispatched and awaiting a response). Incoming requests are placed onto the queue. Requests are popped of the queue in order of priority and dispatched, until the maximum number of simultaneously-active requests is reached.\n * The maximum number of active requests depends on the transport mechanism. For HTTP 1.1, browsers impose a limit of 6 simultaneous connections to a given domain, so ideally each unique domain will use its own unique channel with a limit of 6 active requests. Even for requests satisfied entirely by the frontend, imposing a limit is important for throttling the amount of work done at one time, especially because as the user navigates the view, tiles that were previously requested may no longer be of interest and we shouldn't waste resources producing their content.\n * A channel must be registered with [[TileRequestChannels]] and must have a unique name among all registered channels.\n * @see [[TileRequestChannels.getForHttp]] to obtain (and register if not already registered) an HTTP-based channel.\n * @see [[TileAdmin.channels]] for the channels configured for use with the iTwin.js display system.\n * @see [[Tile.channel]] to specify the channel to be used to request a given tile's content.\n * @public\n * @extensions\n */\nexport class TileRequestChannel {\n /** The channel's name. It must be unique among all registered [[TileRequestChannels]]. */\n public readonly name: string;\n private _concurrency: number;\n /** Protected strictly for tests. @internal */\n protected readonly _active = new Set<TileRequest>();\n private _pending = new TileRequestQueue();\n private _previouslyPending = new TileRequestQueue();\n protected _statistics = new TileRequestChannelStatistics();\n /** Callback invoked by recordCompletion. See IModelTileMetadataCacheChannel.\n * @internal\n */\n public contentCallback?: (tile: Tile, content: TileContent) => void;\n\n /** Create a new channel.\n * @param name The unique name of the channel.\n * @param concurrency The maximum number of requests that can be dispatched and awaiting a response at any given time. Requests beyond this maximum are enqueued for deferred dispatch.\n * @see [[TileRequestChannels.getForHttp]] to create an HTTP-based channel.\n */\n public constructor(name: string, concurrency: number) {\n this.name = name;\n this._concurrency = concurrency;\n }\n\n /** The maximum number of active requests. This is generally only modified for debugging purposes.\n * @note When reducing `concurrency`, the number of active requests ([[numActive]]) will only decrease to the new value after a sufficient number of dispatched requests are resolved.\n */\n public get concurrency(): number {\n return this._concurrency;\n }\n public set concurrency(max: number) {\n this._concurrency = max;\n }\n\n /** The number of requests that have been dispatched and are awaiting a response. */\n public get numActive(): number {\n return this._active.size;\n }\n\n /** The number of requests that have been enqueued for later dispatch. */\n public get numPending(): number {\n return this._pending.length;\n }\n\n /** The total number of requests in this channel, whether dispatched or enqueued. */\n public get size(): number {\n return this.numActive + this.numPending;\n }\n\n /** Statistics intended primarily for debugging. */\n public get statistics(): Readonly<TileRequestChannelStatistics> {\n this._statistics.numPendingRequests = this.numPending;\n this._statistics.numActiveRequests = this.numActive;\n return this._statistics;\n }\n\n /** Reset all of this channel's [[statistics]] to zero. */\n public resetStatistics(): void {\n this._statistics = new TileRequestChannelStatistics();\n }\n\n /** Invoked by [[TileRequest]] when a request times out.\n * @internal\n */\n public recordTimeout(): void {\n ++this._statistics.totalTimedOutRequests;\n }\n\n /** Invoked by [[TileRequest]] when a request fails to produce a response.\n * @internal\n */\n public recordFailure(): void {\n ++this._statistics.totalFailedRequests;\n }\n\n /** Invoked by [[TileRequest]] after a request completes.\n * @internal\n */\n public recordCompletion(tile: Tile, content: TileContent, elapsedMilliseconds: number): void {\n this._statistics.recordCompletion(tile, elapsedMilliseconds);\n\n if (this.contentCallback)\n this.contentCallback(tile, content);\n }\n\n /** Invoked by [[TileRequestChannels.swapPending]] when [[TileAdmin]] is about to start enqueuing new requests.\n * @internal\n */\n public swapPending(): void {\n const previouslyPending = this._pending;\n this._pending = this._previouslyPending;\n this._previouslyPending = previouslyPending;\n }\n\n /** Invoked by [[TileAdmin.processRequests]] to enqueue a request. Ordering is ignored - the queue will be re-sorted later.\n * @internal\n */\n public append(request: TileRequest): void {\n assert(request.channel === this);\n this._pending.append(request);\n }\n\n /** Invoked by [[TileRequestChannels.process]] to process the active and pending requests.\n * @internal\n */\n public process(): void {\n this._statistics.numCanceled = 0;\n\n // Recompute priority of each request.\n for (const pending of this._pending)\n pending.priority = pending.tile.computeLoadPriority(pending.viewports, pending.users);\n\n // Sort pending requests by priority.\n this._pending.sort();\n\n // Cancel any previously pending requests that are no longer needed.\n for (const queued of this._previouslyPending)\n if (queued.users.isEmpty)\n this.cancel(queued);\n\n this._previouslyPending.clear();\n\n // Cancel any active requests that are no longer needed.\n // NB: Do NOT remove them from the active set until their http activity has completed.\n for (const active of this._active)\n if (active.users.isEmpty)\n this.cancel(active);\n\n // Batch-cancel running requests.\n this.processCancellations();\n\n // Dispatch requests from the queue up to our maximum.\n while (this._active.size < this._concurrency) {\n const request = this._pending.pop();\n if (!request)\n break;\n\n this.dispatch(request);\n }\n }\n\n /** Cancel all active and queued requests and clear the active set and queue.\n * @internal\n */\n public cancelAndClearAll(): void {\n for (const active of this._active)\n active.cancel();\n\n for (const queued of this._pending)\n queued.cancel();\n\n this._active.clear();\n this._pending.clear();\n }\n\n /** Invoked when [[Tile.requestContent]] returns `undefined`. Return true if the request can be retried, e.g., via different channel.\n * If so, the tile will remain marked as \"not loaded\" and, if re-selected for display, a new [[TileRequest]] will be enqueued for it.\n * Otherwise, the tile will be marked as \"failed to load\" and no further requests will be made for its content.\n * The default implementation always returns `false`.\n */\n public onNoContent(_request: TileRequest): boolean {\n return false;\n }\n\n /** Invoked when a request that was previously dispatched is canceled before a response is received.\n * Some channels accumulate such requests for later cancellation in [[processCancellations]].\n */\n public onActiveRequestCanceled(_request: TileRequest): void { }\n\n /** Invoked to do any additional work to cancel tiles accumulated by [[onActiveRequestCanceled]]. For example, a channel that requests tile content\n * over IPC may signal to the tile generation process that it should cease generating content for those tiles.\n */\n public processCancellations(): void { }\n\n /** Invoked when an iModel is closed, to clean up any state associated with that iModel. */\n public onIModelClosed(_iModel: IModelConnection): void { }\n\n /** Request content for the specified tile. The default implementation simply forwards to [[Tile.requestContent]]. */\n public async requestContent(tile: Tile, isCanceled: () => boolean): Promise<TileRequest.Response> {\n return tile.requestContent(isCanceled);\n }\n\n /** Protected only for tests - do not override.\n * @internal\n */\n protected dispatch(request: TileRequest): void {\n ++this._statistics.totalDispatchedRequests;\n this._active.add(request);\n request.dispatch(() => {\n this.dropActiveRequest(request);\n }).catch((_) => {\n //\n });\n }\n\n /** Protected only for tests - do not override.\n * @internal\n */\n protected cancel(request: TileRequest): void {\n request.cancel();\n ++this._statistics.numCanceled;\n }\n\n /** Protected only for tests - do not override.\n * @internal\n */\n protected dropActiveRequest(request: TileRequest): void {\n assert(this._active.has(request) || request.isCanceled);\n this._active.delete(request);\n }\n}\n"]}
1
+ {"version":3,"file":"TileRequestChannel.js","sourceRoot":"","sources":["../../../src/tile/TileRequestChannel.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAA2B,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIrF,MAAM,gBAAiB,SAAQ,aAA0B;IACvD;QACE,KAAK,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACjB,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC;YACrE,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;QACzD,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAmBD;;;;;;GAMG;AACH,MAAM,OAAO,4BAA4B;IACvC,uEAAuE;IAChE,kBAAkB,GAAG,CAAC,CAAC;IAC9B,8EAA8E;IACvE,iBAAiB,GAAG,CAAC,CAAC;IAC7B,qEAAqE;IAC9D,WAAW,GAAG,CAAC,CAAC;IACvB,kEAAkE;IAC3D,sBAAsB,GAA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ACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACO,MAAM,CAAC,OAAoB;QACnC,OAAO,CAAC,MAAM,EAAE,CAAC;QACjB,EAAE,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC;IACjC,CAAC;IAED;;OAEG;IACO,iBAAiB,CAAC,OAAoB;QAC9C,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;QACxD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Tiles\n */\n\nimport { assert, NonFunctionPropertiesOf, PriorityQueue } from \"@itwin/core-bentley\";\nimport { IModelConnection } from \"../IModelConnection\";\nimport { Tile, TileContent, TileRequest } from \"./internal\";\n\nclass TileRequestQueue extends PriorityQueue<TileRequest> {\n public constructor() {\n super((lhs, rhs) => {\n const diff = lhs.tile.tree.loadPriority - rhs.tile.tree.loadPriority;\n return 0 !== diff ? diff : lhs.priority - rhs.priority;\n });\n }\n}\n\n/** As part of a [[TileRequestChannelStatistics]], summarizes cumulative time spent decoding tile content.\n * For each Tile, the time elapsed between receiving the raw tile content (e.g., over the network) and converting it to a [[TileContent]] via [[Tile.readContent]]\n * is recorded.\n * All times are reported in milliseconds.\n * @beta\n */\nexport interface TileContentDecodingStatistics {\n /** The total number of milliseconds spent decoding content. */\n total: number;\n /** The mean (average) number of milliseconds spent decoding content. */\n mean: number;\n /** The longest amount of time, in milliseconds, spent decoding any single tile's content. */\n max: number;\n /** The shortest amount of time, in milliseconds, spent decoding any single tile's content. */\n min: number;\n}\n\n/** Statistics regarding the current and cumulative state of one or more [[TileRequestChannel]]s. Useful for monitoring performance and diagnosing problems.\n * @see [[TileRequestChannel.statistics]] for a specific channel's statistics.\n * @see [[TileRequestChannels.statistics]] for statistics from all channels.\n * @see [[TileAdmin.statistics]] for additional statistics.\n * @public\n * @extensions\n */\nexport class TileRequestChannelStatistics {\n /** The number of queued requests that have not yet been dispatched. */\n public numPendingRequests = 0;\n /** The number of requests that have been dispatched but not yet completed. */\n public numActiveRequests = 0;\n /** The number of requests canceled during the most recent update. */\n public numCanceled = 0;\n /** The total number of completed requests during this session. */\n public totalCompletedRequests = 0;\n /** The total number of failed requests during this session. */\n public totalFailedRequests = 0;\n /** The total number of timed-out requests during this session. */\n public totalTimedOutRequests = 0;\n /** The total number of completed requests during this session which produced an empty tile.\n * These tiles also contribute to [[totalCompletedRequests]], but not to [[totalUndisplayableTiles]].\n */\n public totalEmptyTiles = 0;\n /** The total number of completed requests during this session that produced an undisplayable tile.\n * These tiles also contribute to [[totalCompletedRequests]], but not to [[totalEmptyTiles]].\n */\n public totalUndisplayableTiles = 0;\n /** The total number of tiles whose contents were not found in cloud storage cache and therefore resulted in a backend request to generate the tile content. */\n public totalCacheMisses = 0;\n /** The total number of tiles for which content requests were dispatched. */\n public totalDispatchedRequests = 0;\n /** The total number of tiles for which content requests were dispatched and then canceled on the backend before completion. */\n public totalAbortedRequests = 0;\n /** Statistics summarizing time spent decoding tile content.\n * @beta\n */\n public decoding: TileContentDecodingStatistics = {\n total: 0,\n mean: 0,\n max: Number.MIN_SAFE_INTEGER,\n min: Number.MAX_SAFE_INTEGER,\n };\n\n /** @internal */\n public addTo(stats: TileRequestChannelStatistics): void {\n for (const propName in this) { // eslint-disable-line guard-for-in\n const key = propName as keyof NonFunctionPropertiesOf<TileRequestChannelStatistics>;\n const val = this[key];\n if (typeof val === \"number\") {\n assert(typeof stats[key] === \"number\");\n (stats[key] as number) += val; // eslint-disable-line @typescript-eslint/no-unnecessary-type-assertion\n }\n }\n\n stats.decoding.total += this.decoding.total;\n stats.decoding.max = Math.max(this.decoding.max, stats.decoding.max);\n stats.decoding.min = Math.min(this.decoding.min, stats.decoding.min);\n\n if (stats.totalCompletedRequests > 0)\n stats.decoding.mean = (stats.decoding.total) / stats.totalCompletedRequests;\n }\n\n /** @internal */\n public recordCompletion(tile: Tile, elapsedMilliseconds: number): void {\n ++this.totalCompletedRequests;\n if (tile.isEmpty)\n ++this.totalEmptyTiles;\n else if (!tile.isDisplayable)\n ++this.totalUndisplayableTiles;\n\n this.decoding.total += elapsedMilliseconds;\n this.decoding.mean = this.decoding.total / this.totalCompletedRequests;\n this.decoding.max = Math.max(this.decoding.max, elapsedMilliseconds);\n this.decoding.min = Math.min(this.decoding.min, elapsedMilliseconds);\n }\n}\n\n/** A channel over which requests for tile content can be made. The channel may request content over HTTP, calls to the backend via IPC or RPC, or any other method like generating the content\n * on the frontend. The channel consists of a queue of pending requests and a set of \"active\" requests (dispatched and awaiting a response). Incoming requests are placed onto the queue. Requests are popped of the queue in order of priority and dispatched, until the maximum number of simultaneously-active requests is reached.\n * The maximum number of active requests depends on the transport mechanism. For HTTP 1.1, browsers impose a limit of 6 simultaneous connections to a given domain, so ideally each unique domain will use its own unique channel with a limit of 6 active requests. Even for requests satisfied entirely by the frontend, imposing a limit is important for throttling the amount of work done at one time, especially because as the user navigates the view, tiles that were previously requested may no longer be of interest and we shouldn't waste resources producing their content.\n * A channel must be registered with [[TileRequestChannels]] and must have a unique name among all registered channels.\n * @see [[TileRequestChannels.getForHttp]] to obtain (and register if not already registered) an HTTP-based channel.\n * @see [[TileAdmin.channels]] for the channels configured for use with the iTwin.js display system.\n * @see [[Tile.channel]] to specify the channel to be used to request a given tile's content.\n * @public\n * @extensions\n */\nexport class TileRequestChannel {\n /** The channel's name. It must be unique among all registered [[TileRequestChannels]]. */\n public readonly name: string;\n private _concurrency: number;\n /** Protected strictly for tests. @internal */\n protected readonly _active = new Set<TileRequest>();\n private _pending = new TileRequestQueue();\n private _previouslyPending = new TileRequestQueue();\n protected _statistics = new TileRequestChannelStatistics();\n /** Callback invoked by recordCompletion. See IModelTileMetadataCacheChannel.\n * @internal\n */\n public contentCallback?: (tile: Tile, content: TileContent) => void;\n\n /** Create a new channel.\n * @param name The unique name of the channel.\n * @param concurrency The maximum number of requests that can be dispatched and awaiting a response at any given time. Requests beyond this maximum are enqueued for deferred dispatch.\n * @see [[TileRequestChannels.getForHttp]] to create an HTTP-based channel.\n */\n public constructor(name: string, concurrency: number) {\n this.name = name;\n this._concurrency = concurrency;\n }\n\n /** The maximum number of active requests. This is generally only modified for debugging purposes.\n * @note When reducing `concurrency`, the number of active requests ([[numActive]]) will only decrease to the new value after a sufficient number of dispatched requests are resolved.\n */\n public get concurrency(): number {\n return this._concurrency;\n }\n public set concurrency(max: number) {\n this._concurrency = max;\n }\n\n /** The number of requests that have been dispatched and are awaiting a response. */\n public get numActive(): number {\n return this._active.size;\n }\n\n /** The number of requests that have been enqueued for later dispatch. */\n public get numPending(): number {\n return this._pending.length;\n }\n\n /** The total number of requests in this channel, whether dispatched or enqueued. */\n public get size(): number {\n return this.numActive + this.numPending;\n }\n\n /** Statistics intended primarily for debugging. */\n public get statistics(): Readonly<TileRequestChannelStatistics> {\n this._statistics.numPendingRequests = this.numPending;\n this._statistics.numActiveRequests = this.numActive;\n return this._statistics;\n }\n\n /** Reset all of this channel's [[statistics]] to zero. */\n public resetStatistics(): void {\n this._statistics = new TileRequestChannelStatistics();\n }\n\n /** Invoked by [[TileRequest]] when a request times out.\n * @internal\n */\n public recordTimeout(): void {\n ++this._statistics.totalTimedOutRequests;\n }\n\n /** Invoked by [[TileRequest]] when a request fails to produce a response.\n * @internal\n */\n public recordFailure(): void {\n ++this._statistics.totalFailedRequests;\n }\n\n /** Invoked by [[TileRequest]] after a request completes.\n * @internal\n */\n public recordCompletion(tile: Tile, content: TileContent, elapsedMilliseconds: number): void {\n this._statistics.recordCompletion(tile, elapsedMilliseconds);\n\n if (this.contentCallback)\n this.contentCallback(tile, content);\n }\n\n /** Invoked by [[TileRequestChannels.swapPending]] when [[TileAdmin]] is about to start enqueuing new requests.\n * @internal\n */\n public swapPending(): void {\n const previouslyPending = this._pending;\n this._pending = this._previouslyPending;\n this._previouslyPending = previouslyPending;\n }\n\n /** Invoked by [[TileAdmin.processRequests]] to enqueue a request. Ordering is ignored - the queue will be re-sorted later.\n * @internal\n */\n public append(request: TileRequest): void {\n assert(request.channel === this);\n this._pending.append(request);\n }\n\n /** Invoked by [[TileRequestChannels.process]] to process the active and pending requests.\n * @internal\n */\n public process(): void {\n this._statistics.numCanceled = 0;\n\n // Recompute priority of each request.\n for (const pending of this._pending)\n pending.priority = pending.tile.computeLoadPriority(pending.viewports, pending.users);\n\n // Sort pending requests by priority.\n this._pending.sort();\n\n // Cancel any previously pending requests that are no longer needed.\n for (const queued of this._previouslyPending)\n if (queued.users.isEmpty)\n this.cancel(queued);\n\n this._previouslyPending.clear();\n\n // Cancel any active requests that are no longer needed.\n // NB: Do NOT remove them from the active set until their http activity has completed.\n for (const active of this._active)\n if (active.users.isEmpty)\n this.cancel(active);\n\n // Batch-cancel running requests.\n this.processCancellations();\n\n // Dispatch requests from the queue up to our maximum.\n while (this._active.size < this._concurrency) {\n const request = this._pending.pop();\n if (!request)\n break;\n\n this.dispatch(request);\n }\n }\n\n /** Cancel all active and queued requests and clear the active set and queue.\n * @internal\n */\n public cancelAndClearAll(): void {\n for (const active of this._active)\n active.cancel();\n\n for (const queued of this._pending)\n queued.cancel();\n\n this._active.clear();\n this._pending.clear();\n }\n\n /** Invoked when [[Tile.requestContent]] returns `undefined`. Return true if the request can be retried, e.g., via different channel.\n * If so, the tile will remain marked as \"not loaded\" and, if re-selected for display, a new [[TileRequest]] will be enqueued for it.\n * Otherwise, the tile will be marked as \"failed to load\" and no further requests will be made for its content.\n * The default implementation always returns `false`.\n */\n public onNoContent(_request: TileRequest): boolean {\n return false;\n }\n\n /** Invoked when a request that was previously dispatched is canceled before a response is received.\n * Some channels accumulate such requests for later cancellation in [[processCancellations]].\n */\n public onActiveRequestCanceled(_request: TileRequest): void { }\n\n /** Invoked to do any additional work to cancel tiles accumulated by [[onActiveRequestCanceled]]. For example, a channel that requests tile content\n * over IPC may signal to the tile generation process that it should cease generating content for those tiles.\n */\n public processCancellations(): void { }\n\n /** Invoked when an iModel is closed, to clean up any state associated with that iModel. */\n public onIModelClosed(_iModel: IModelConnection): void { }\n\n /** Request content for the specified tile. The default implementation simply forwards to [[Tile.requestContent]]. */\n public async requestContent(tile: Tile, isCanceled: () => boolean): Promise<TileRequest.Response> {\n return tile.requestContent(isCanceled);\n }\n\n /** Protected only for tests - do not override.\n * @internal\n */\n protected dispatch(request: TileRequest): void {\n ++this._statistics.totalDispatchedRequests;\n this._active.add(request);\n request.dispatch(() => {\n this.dropActiveRequest(request);\n }).catch((_) => {\n //\n });\n }\n\n /** Protected only for tests - do not override.\n * @internal\n */\n protected cancel(request: TileRequest): void {\n request.cancel();\n ++this._statistics.numCanceled;\n }\n\n /** Protected only for tests - do not override.\n * @internal\n */\n protected dropActiveRequest(request: TileRequest): void {\n assert(this._active.has(request) || request.isCanceled);\n this._active.delete(request);\n }\n}\n"]}
@@ -1,7 +1,6 @@
1
1
  /** @packageDocumentation
2
2
  * @module Tools
3
3
  */
4
- import { BentleyStatus } from "@itwin/core-bentley";
5
4
  import { Point3d } from "@itwin/core-geometry";
6
5
  import { ItemField, RotationMode } from "../AccuDraw";
7
6
  import { AuxCoordSystemState } from "../AuxCoordSys";
@@ -14,6 +13,7 @@ import { AccuDrawShortcutImplementation, AccuDrawShortcutTool } from "./AccuDraw
14
13
  * @beta
15
14
  */
16
15
  export declare class AccuDrawShortcuts {
16
+ private static _acsRequestGeneration;
17
17
  /** Disable/Enable AccuDraw for the session */
18
18
  static sessionToggle(): void;
19
19
  /** Suspend/Unsuspend AccuDraw for the active tool */
@@ -51,8 +51,25 @@ export declare class AccuDrawShortcuts {
51
51
  static rotateToElement(): Promise<boolean>;
52
52
  static defineACSByElement(): Promise<boolean>;
53
53
  static defineACSByPoints(): Promise<boolean>;
54
- static getACS(acsName: string | undefined, useOrigin: boolean, useRotation: boolean): BentleyStatus;
55
- static writeACS(_acsName: string): BentleyStatus;
54
+ private static getACSCode;
55
+ private static getNamedACS;
56
+ private static createNewACS;
57
+ /**
58
+ * Set the AuxiliaryCoordinateSystem for the current AccuDraw viewport by name.
59
+ * Optionally updates the AccuDraw origin and rotation to match the ACS.
60
+ * @note When no name is specified, AccuDraw is updated using the view's current ACS.
61
+ * @returns AuxCoordSystemState or undefined if name does not exist or is invalid for the view.
62
+ * @throws Error if resolving the ACS CodeSpec or loading ACS element properties fails.
63
+ */
64
+ static getACS(acsName: string | undefined, useOrigin: boolean, useRotation: boolean): Promise<AuxCoordSystemState | undefined>;
65
+ /**
66
+ * Create a new AuxiliaryCoordinateSystem for the current AccuDraw viewport using the compass origin, orientation, and mode.
67
+ * @note When no name is specified, the view's current ACS is updated from AccuDraw. Caller can choose to create
68
+ * an EditCommand to insert/update as a named ACS element using the returned AuxCoordSystemState.
69
+ * @returns AuxCoordSystemState or undefined if ACS could not be created.
70
+ * @throws Error if resolving the ACS CodeSpec or loading ACS element properties fails.
71
+ */
72
+ static writeACS(acsName: string | undefined): Promise<AuxCoordSystemState | undefined>;
56
73
  static itemFieldUnlockAll(): void;
57
74
  }
58
75
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"AccuDrawTool.d.ts","sourceRoot":"","sources":["../../../src/tools/AccuDrawTool.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAA+D,OAAO,EAAuB,MAAM,sBAAsB,CAAC;AACjI,OAAO,EAAqD,SAAS,EAA6B,YAAY,EAAa,MAAM,aAAa,CAAC;AAE/I,OAAO,EAAqB,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAIxE,OAAO,EAAkB,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAA4B,IAAI,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAE,8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a,sBAAuB,SAAQ,oBAAoB;IAC9D,OAAuB,MAAM,SAAiC;IAE9D,gBAAgB;cACG,oBAAoB,IAAI,8BAA8B;CAG1E;AAiFD;;;GAGG;AACH,qBAAa,qBAAsB,SAAQ,oBAAoB;IAC7D,OAAuB,MAAM,SAAgC;IAE7D,gBAAgB;cACG,oBAAoB,IAAI,8BAA8B;CAG1E"}
@@ -5,11 +5,11 @@
5
5
  /** @packageDocumentation
6
6
  * @module Tools
7
7
  */
8
- import { BentleyStatus } from "@itwin/core-bentley";
8
+ import { BisCodeSpec, Code } from "@itwin/core-common";
9
9
  import { AxisOrder, Geometry, Matrix3d, Plane3dByOriginAndUnitNormal, Point3d, Transform, Vector3d } from "@itwin/core-geometry";
10
10
  import { AccuDraw, AccuDrawFlags, CompassMode, ContextMode, ItemField, KeyinStatus, LockedStates, RotationMode, ThreeAxes } from "../AccuDraw";
11
11
  import { TentativeOrAccuSnap } from "../AccuSnap";
12
- import { ACSDisplayOptions } from "../AuxCoordSys";
12
+ import { ACSDisplayOptions, ACSType, AuxCoordSystemState } from "../AuxCoordSys";
13
13
  import { IModelApp } from "../IModelApp";
14
14
  import { BeButtonEvent, CoreTools, Tool } from "./Tool";
15
15
  import { AccuDrawShortcutImplementation, AccuDrawShortcutTool } from "./AccuDrawShortcutTool";
@@ -27,6 +27,8 @@ function normalizedCrossProduct(vec1, vec2, out) {
27
27
  * @beta
28
28
  */
29
29
  export class AccuDrawShortcuts {
30
+ // Monotonic token used to ignore stale async ACS operations.
31
+ static _acsRequestGeneration = 0;
30
32
  /** Disable/Enable AccuDraw for the session */
31
33
  static sessionToggle() {
32
34
  const accudraw = IModelApp.accuDraw;
@@ -733,41 +735,71 @@ export class AccuDrawShortcuts {
733
735
  static async defineACSByPoints() {
734
736
  return IModelApp.tools.run("AccuDraw.DefineACSByPoints");
735
737
  }
736
- static getACS(acsName, useOrigin, useRotation) {
738
+ static async getACSCode(view, acsName) {
739
+ const codeSpecName = view.isSpatialView() ? BisCodeSpec.auxCoordSystemSpatial : (view.is3d() ? BisCodeSpec.auxCoordSystem3d : BisCodeSpec.auxCoordSystem2d);
740
+ const codeSpec = await view.iModel.codeSpecs.getByName(codeSpecName);
741
+ return new Code({ spec: codeSpec.id, scope: view.model, value: acsName });
742
+ }
743
+ static async getNamedACS(view, acsName) {
744
+ const acsCode = await this.getACSCode(view, acsName);
745
+ const acsProps = await view.iModel.elements.loadProps(acsCode.toJSON());
746
+ if (!acsProps)
747
+ return { validForView: false };
748
+ const namedAcs = AuxCoordSystemState.fromProps(acsProps, view.iModel);
749
+ const validForView = namedAcs.isValidForView(view);
750
+ return { validForView, acs: namedAcs };
751
+ }
752
+ static async createNewACS(view, acsName) {
753
+ // Want a CodeProps to support insert so ViewState.createAuxCoordSystem(acsName) is not called.
754
+ const acsCode = await this.getACSCode(view, acsName);
755
+ // Determine the class name based on view type
756
+ let classFullName;
757
+ if (view.isSpatialView())
758
+ classFullName = "BisCore:AuxCoordSystemSpatial";
759
+ else if (view.is3d())
760
+ classFullName = "BisCore:AuxCoordSystem3d";
761
+ else
762
+ classFullName = "BisCore:AuxCoordSystem2d";
763
+ const acsProps = { model: acsCode.scope, code: acsCode.toJSON(), classFullName, type: ACSType.None };
764
+ const acs = AuxCoordSystemState.fromProps(acsProps, view.iModel);
765
+ return acs;
766
+ }
767
+ /**
768
+ * Set the AuxiliaryCoordinateSystem for the current AccuDraw viewport by name.
769
+ * Optionally updates the AccuDraw origin and rotation to match the ACS.
770
+ * @note When no name is specified, AccuDraw is updated using the view's current ACS.
771
+ * @returns AuxCoordSystemState or undefined if name does not exist or is invalid for the view.
772
+ * @throws Error if resolving the ACS CodeSpec or loading ACS element properties fails.
773
+ */
774
+ static async getACS(acsName, useOrigin, useRotation) {
737
775
  const accudraw = IModelApp.accuDraw;
738
776
  if (!accudraw.isEnabled)
739
- return BentleyStatus.ERROR;
777
+ return undefined;
740
778
  const vp = accudraw.currentView;
741
779
  if (!vp)
742
- return BentleyStatus.ERROR;
743
- let currRotation = 0, currBaseRotation = 0;
744
- const axes = new ThreeAxes();
745
- if (!useRotation) {
746
- // Save current rotation, event listener on ACS change will orient AccuDraw to ACS...
747
- currRotation = accudraw.rotationMode;
748
- currBaseRotation = accudraw.flags.baseRotation;
749
- axes.setFrom(accudraw.axes);
750
- }
780
+ return undefined;
781
+ const view = vp.view;
782
+ const requestGeneration = ++this._acsRequestGeneration;
783
+ const isRequestCurrent = () => accudraw.isEnabled && accudraw.currentView === vp && vp.view === view && requestGeneration === this._acsRequestGeneration;
784
+ let currentACS = view.auxiliaryCoordinateSystem;
751
785
  if (acsName && "" !== acsName) {
752
- // // See if this ACS already exists...
753
- // DgnCode acsCode = AuxCoordSystem:: CreateCode(vp -> GetViewControllerR().GetViewDefinition(), acsName);
754
- // DgnElementId acsId = vp -> GetViewController().GetDgnDb().Elements().QueryElementIdByCode(acsCode);
755
- // if (!acsId.IsValid())
756
- // return ERROR;
757
- // AuxCoordSystemCPtr auxElm = vp -> GetViewController().GetDgnDb().Elements().Get<AuxCoordSystem>(acsId);
758
- // if (!auxElm.IsValid())
759
- // return ERROR;
760
- // AuxCoordSystemPtr acsPtr = auxElm -> MakeCopy<AuxCoordSystem>();
761
- // if (!acsPtr.IsValid())
762
- // return ERROR;
763
- // AuxCoordSystemCR oldACS = vp -> GetViewController().GetAuxCoordinateSystem();
764
- // if (!useOrigin)
765
- // acsPtr -> SetOrigin(oldACS.GetOrigin());
766
- // if (!useRotation)
767
- // acsPtr -> SetRotation(oldACS.GetRotation());
768
- // AccuDraw:: UpdateAuxCoordinateSystem(* acsPtr, * vp);
786
+ const namedAcsResult = await this.getNamedACS(view, acsName);
787
+ if (!isRequestCurrent())
788
+ return undefined;
789
+ if (!namedAcsResult.validForView)
790
+ return undefined;
791
+ const namedAcs = namedAcsResult.acs;
792
+ if (!namedAcs)
793
+ return undefined;
794
+ if (!useOrigin)
795
+ namedAcs.setOrigin(currentACS.getOrigin());
796
+ if (!useRotation)
797
+ namedAcs.setRotation(currentACS.getRotation());
798
+ AccuDraw.updateAuxCoordinateSystem(namedAcs, vp); // Sets AccuDrawFlags.OrientACS hint to orient AccuDraw to ACS...
799
+ currentACS = namedAcs;
769
800
  }
770
- const currentACS = vp.view.auxiliaryCoordinateSystem;
801
+ if (!isRequestCurrent())
802
+ return undefined;
771
803
  if (useOrigin) {
772
804
  accudraw.origin.setFrom(currentACS.getOrigin());
773
805
  accudraw.point.setFrom(accudraw.origin);
@@ -779,44 +811,62 @@ export class AccuDrawShortcuts {
779
811
  }
780
812
  else {
781
813
  this.itemFieldUnlockAll();
782
- accudraw.setRotationMode(currRotation);
783
- accudraw.flags.baseRotation = currBaseRotation;
784
- accudraw.axes.setFrom(axes);
785
814
  if (RotationMode.ACS === accudraw.flags.baseRotation) {
786
815
  const acs = currentACS.clone();
787
- const rMatrix = accudraw.getRotation();
788
- acs.setRotation(rMatrix);
816
+ acs.setRotation(accudraw.getRotation());
789
817
  AccuDraw.updateAuxCoordinateSystem(acs, vp);
790
818
  }
791
819
  accudraw.published.flags &= ~AccuDrawFlags.OrientACS;
792
820
  }
793
- return BentleyStatus.SUCCESS;
794
- }
795
- static writeACS(_acsName) {
821
+ return currentACS;
822
+ }
823
+ /**
824
+ * Create a new AuxiliaryCoordinateSystem for the current AccuDraw viewport using the compass origin, orientation, and mode.
825
+ * @note When no name is specified, the view's current ACS is updated from AccuDraw. Caller can choose to create
826
+ * an EditCommand to insert/update as a named ACS element using the returned AuxCoordSystemState.
827
+ * @returns AuxCoordSystemState or undefined if ACS could not be created.
828
+ * @throws Error if resolving the ACS CodeSpec or loading ACS element properties fails.
829
+ */
830
+ static async writeACS(acsName) {
796
831
  const accudraw = IModelApp.accuDraw;
797
832
  if (!accudraw.isEnabled)
798
- return BentleyStatus.ERROR;
833
+ return undefined;
799
834
  const vp = accudraw.currentView;
800
835
  if (!vp)
801
- return BentleyStatus.ERROR;
802
- // const origin = accudraw.origin;
803
- // const rMatrix = accudraw.getRotation();
804
- // AuxCoordSystemPtr acsPtr = AuxCoordSystem:: CreateFrom(vp -> GetViewController().GetAuxCoordinateSystem());
805
- // acsPtr -> SetOrigin(origin);
806
- // acsPtr -> SetRotation(rMatrix);
807
- // acsPtr -> SetType(CompassMode.Polar == accudraw.getCompassMode() ? ACSType :: Cylindrical : ACSType:: Rectangular);
808
- // acsPtr -> SetCode(AuxCoordSystem:: CreateCode(vp -> GetViewControllerR().GetViewDefinition(), nullptr != acsName ? acsName : ""));
809
- // acsPtr -> SetDescription("");
810
- // if (acsName && '\0' != acsName[0]) {
811
- // DgnDbStatus status;
812
- // acsPtr -> Insert(& status);
813
- // if (DgnDbStatus:: Success != status)
814
- // return BentleyStatus.ERROR;
815
- // }
816
- // AccuDraw:: UpdateAuxCoordinateSystem(* acsPtr, * vp);
817
- // accudraw.flags.baseRotation = RotationMode.ACS;
818
- // accudraw.SetRotationMode(RotationMode.ACS);
819
- return BentleyStatus.SUCCESS;
836
+ return undefined;
837
+ const view = vp.view;
838
+ const requestGeneration = ++this._acsRequestGeneration;
839
+ const isRequestCurrent = () => accudraw.isEnabled && accudraw.currentView === vp && vp.view === view && requestGeneration === this._acsRequestGeneration;
840
+ let acs;
841
+ if (acsName && "" !== acsName) {
842
+ const namedAcsResult = await this.getNamedACS(view, acsName);
843
+ if (!isRequestCurrent())
844
+ return undefined;
845
+ acs = namedAcsResult.acs;
846
+ if (!acs) {
847
+ acs = await this.createNewACS(view, acsName);
848
+ if (!isRequestCurrent())
849
+ return undefined;
850
+ }
851
+ else if (!namedAcsResult.validForView) {
852
+ return undefined;
853
+ }
854
+ }
855
+ else {
856
+ acs = view.auxiliaryCoordinateSystem.clone();
857
+ acs.description = "";
858
+ }
859
+ if (!isRequestCurrent())
860
+ return undefined;
861
+ if (!acs)
862
+ return undefined;
863
+ acs.setOrigin(accudraw.origin);
864
+ acs.setRotation(accudraw.getRotation());
865
+ acs.type = CompassMode.Polar === accudraw.compassMode ? ACSType.Cylindrical : ACSType.Rectangular;
866
+ AccuDraw.updateAuxCoordinateSystem(acs, vp);
867
+ accudraw.flags.baseRotation = RotationMode.ACS;
868
+ accudraw.setRotationMode(RotationMode.ACS);
869
+ return acs;
820
870
  }
821
871
  static itemFieldUnlockAll() {
822
872
  const accudraw = IModelApp.accuDraw;