@itwin/core-frontend 3.6.0 → 3.6.2

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":"ElementLocateManager.d.ts","sourceRoot":"","sources":["../../src/ElementLocateManager.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAW,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAe,SAAS,EAAE,MAAM,aAAa,CAAC;AAGzE,OAAO,EAAE,WAAW,EAAmB,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtD;;;GAGG;AACH,oBAAY,YAAY;IACtB,QAAQ,IAAI;IACZ,UAAU,IAAI;CACf;AAED;;;;GAIG;AACH,oBAAY,kBAAkB;IAC5B,MAAM,IAAI;IACV,MAAM,IAAI;CACX;AAED;;;GAGG;AACH,oBAAY,UAAU;IACpB,OAAO,IAAI;IACX,OAAO,IAAI;IACX,UAAU,IAAI;IACd,QAAQ,MAAM;IACd,cAAc,MAAM;IACpB,YAAY,MAAM;IAClB,aAAa,MAAM;IACnB,oBAAoB,MAAM;CAC3B;AAED;;;GAGG;AACH,qBAAa,aAAa;IACxB,yDAAyD;IAClD,gBAAgB,UAAS;IAChC,+DAA+D;IACxD,iBAAiB,UAAS;IACjC,wCAAwC;IACjC,OAAO,SAAM;IACpB,gDAAgD;IACzC,SAAS,YAAuB;IACvC;;;;OAIG;IACI,oBAAoB,UAAS;IACpC;;;OAGG;IACI,8BAA8B,UAAS;IAE9C,yCAAyC;IAClC,KAAK,IAAI,aAAa;IAStB,OAAO,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;IAOnC,IAAI;CAKZ;AAED;;;GAGG;AACH,qBAAa,cAAc;IAClB,UAAU,aAAsB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAA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x + 0.5), Math.floor(pickPointView.y + 0.5));
196
196
  let pixelRadius = Math.floor(pickRadiusView + 0.5);
197
197
  const rect = new ViewRect(testPointView.x - pixelRadius, testPointView.y - pixelRadius, testPointView.x + pixelRadius, testPointView.y + pixelRadius);
198
+ if (rect.isNull)
199
+ return 0;
198
200
  let result = 0;
199
201
  vp.readPixels(rect, Pixel.Selector.All, (pixels) => {
200
202
  if (undefined === pixels)
@@ -1 +1 @@
1
- {"version":3,"file":"ElementLocateManager.js","sourceRoot":"","sources":["../../src/ElementLocateManager.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE5D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;;GAGG;AACH,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,uDAAY,CAAA;IACZ,2DAAc,CAAA;AAChB,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB;AAED;;;;GAIG;AACH,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,+DAAU,CAAA;IACV,+DAAU,CAAA;AACZ,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B;AAED;;;GAGG;AACH,MAAM,CAAN,IAAY,UASX;AATD,WAAY,UAAU;IACpB,iDAAW,CAAA;IACX,iDAAW,CAAA;IACX,uDAAc,CAAA;IACd,qDAAc,CAAA;IACd,iE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kB,EAAE,IAAgC,EAAE,MAAmB,EAAE,UAAU,GAAG,IAAI;QAC9J,QAAQ,CAAC,MAAM,GAAG,oBAAoB,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC;QAC1E,QAAQ,CAAC,WAAW,GAAG,EAAE,CAAC;QAE1B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;QAC3F,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAErB,8FAA8F;QAC9F,IAAI,GAAG,IAAI,IAAI,CAAC,OAAO;YACrB,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC5C,OAAO,GAAG,CAAC;IACb,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 LocatingElements\n */\n\nimport { Id64 } from \"@itwin/core-bentley\";\nimport { Point2d, Point3d } from \"@itwin/core-geometry\";\nimport { HitDetail, HitList, HitPriority, HitSource } from \"./HitDetail\";\nimport { IModelApp } from \"./IModelApp\";\nimport { Pixel } from \"./render/Pixel\";\nimport { InputSource, InteractiveTool } from \"./tools/Tool\";\nimport { ScreenViewport, Viewport } from \"./Viewport\";\nimport { ViewRect } from \"./ViewRect\";\n\n/** The possible actions for which a locate filter can be called.\n * @public\n * @extensions\n */\nexport enum LocateAction {\n Identify = 0,\n AutoLocate = 1,\n}\n\n/** Values to return from a locate filter.\n * Return `Reject` to indicate the element is unacceptable.\n * @public\n * @extensions\n */\nexport enum LocateFilterStatus {\n Accept = 0,\n Reject = 1,\n}\n\n/**\n * @public\n * @extensions\n */\nexport enum SnapStatus {\n Success = 0,\n Aborted = 1,\n NoElements = 2,\n Disabled = 100,\n NoSnapPossible = 200,\n NotSnappable = 300,\n FilteredByApp = 600,\n FilteredByAppQuietly = 700,\n}\n\n/** Options that customize the way element location (i.e. *picking*) works.\n * @public\n * @extensions\n */\nexport class LocateOptions {\n /** If true, also test graphics from view decorations. */\n public allowDecorations = false;\n /** If true, also test graphics with non-locatable flag set. */\n public allowNonLocatable = false;\n /** Maximum number of hits to return. */\n public maxHits = 20;\n /** The [[HitSource]] identifying the caller. */\n public hitSource = HitSource.DataPoint;\n /** If true, also test graphics from an IModelConnection other than the one associated with the Viewport. This can occur if, e.g., a\n * [[TiledGraphicsProvider]] is used to display graphics from a different iModel into the [[Viewport]].\n * @note If you override this, you must be prepared to properly handle [[HitDetail]]s originating from other IModelConnections.\n * @see [[HitDetail.iModel]] and [[HitDetail.isExternalIModelHit]]\n */\n public allowExternalIModels = false;\n /** If true, then the world point of a hit on a model will preserve any transforms applied to the model at display time,\n * such as those supplied by a [[ModelDisplayTransformProvider]] or [PlanProjectionSettings.elevation]($common).\n * Otherwise, the world point will be multiplied by the inverse of any such transforms to correlate it with the model's true coordinate space.\n */\n public preserveModelDisplayTransforms = false;\n\n /** Make a copy of this LocateOptions. */\n public clone(): LocateOptions {\n const other = new LocateOptions();\n other.allowDecorations = this.allowDecorations;\n other.allowNonLocatable = this.allowNonLocatable;\n other.maxHits = this.maxHits;\n other.hitSource = this.hitSource;\n other.allowExternalIModels = this.allowExternalIModels;\n return other;\n }\n public setFrom(other: LocateOptions): void {\n this.allowDecorations = other.allowDecorations;\n this.allowNonLocatable = other.allowNonLocatable;\n this.maxHits = other.maxHits;\n this.hitSource = other.hitSource;\n this.allowExternalIModels = other.allowExternalIModels;\n }\n public init() {\n this.allowDecorations = this.allowNonLocatable = this.allowExternalIModels = false;\n this.maxHits = 20;\n this.hitSource = HitSource.DataPoint;\n }\n}\n\n/**\n * @public\n * @extensions\n */\nexport class LocateResponse {\n public snapStatus = SnapStatus.Success;\n public reason?: string;\n public explanation = \"\";\n\n /** @internal */\n public clone(): LocateResponse {\n const other = new LocateResponse();\n other.snapStatus = this.snapStatus;\n other.reason = this.reason;\n other.explanation = this.explanation;\n return other;\n }\n\n /** @internal */\n public setFrom(other: LocateResponse): void {\n this.snapStatus = other.snapStatus;\n this.reason = other.reason;\n this.explanation = other.explanation;\n }\n}\n\n/**\n * @public\n * @extensions\n */\nexport interface HitListHolder {\n setHitList(list: HitList<HitDetail> | undefined): void;\n}\n\n/**\n * @public\n * @extensions\n */\nexport class ElementPicker {\n public viewport?: Viewport;\n public readonly pickPointWorld = new Point3d();\n public hitList?: HitList<HitDetail>;\n\n public empty() {\n this.pickPointWorld.setZero();\n this.viewport = undefined;\n if (this.hitList)\n this.hitList.empty();\n else\n this.hitList = new HitList<HitDetail>();\n }\n\n /** return the HitList for the last Pick performed. Optionally allows the caller to take ownership of the list. */\n public getHitList(takeOwnership: boolean): HitList<HitDetail> {\n const list = this.hitList!;\n if (takeOwnership)\n this.hitList = undefined;\n return list;\n }\n\n public getNextHit(): HitDetail | undefined { return this.hitList ? this.hitList.getNextHit() : undefined; }\n\n /** Return a hit from the list of hits created the last time pickElements was called. */\n public getHit(i: number): HitDetail | undefined { return this.hitList ? this.hitList.getHit(i) : undefined; }\n\n public resetCurrentHit(): void {\n if (this.hitList)\n this.hitList.resetCurrentHit();\n }\n\n private getPixelPriority(pixel: Pixel.Data) {\n switch (pixel.type) {\n case Pixel.GeometryType.Surface:\n return Pixel.Planarity.Planar === pixel.planarity ? HitPriority.PlanarSurface : HitPriority.NonPlanarSurface;\n case Pixel.GeometryType.Linear:\n return HitPriority.WireEdge;\n case Pixel.GeometryType.Edge:\n return Pixel.Planarity.Planar === pixel.planarity ? HitPriority.PlanarEdge : HitPriority.NonPlanarEdge;\n case Pixel.GeometryType.Silhouette:\n return HitPriority.SilhouetteEdge;\n default:\n return HitPriority.Unknown;\n }\n }\n\n private comparePixel(pixel1: Pixel.Data, pixel2: Pixel.Data, distXY1: number, distXY2: number) {\n const priority1 = this.getPixelPriority(pixel1);\n const priority2 = this.getPixelPriority(pixel2);\n if (priority1 < priority2)\n return -1;\n if (priority1 > priority2)\n return 1;\n if (distXY1 < distXY2)\n return -1;\n if (distXY1 > distXY2)\n return 1;\n if (pixel1.distanceFraction > pixel2.distanceFraction)\n return -1;\n if (pixel1.distanceFraction < pixel2.distanceFraction)\n return 1;\n\n return 0;\n }\n\n /** Generate a list of elements that are close to a given point.\n * @returns The number of hits in the hitList of this object.\n */\n public doPick(vp: ScreenViewport, pickPointWorld: Point3d, pickRadiusView: number, options: LocateOptions): number {\n if (this.hitList && this.hitList.length > 0 && vp === this.viewport && pickPointWorld.isAlmostEqual(this.pickPointWorld)) {\n this.hitList.resetCurrentHit();\n return this.hitList.length;\n }\n\n this.empty(); // empty the hit list\n this.viewport = vp;\n this.pickPointWorld.setFrom(pickPointWorld);\n\n const pickPointView = vp.worldToView(pickPointWorld);\n const testPointView = new Point2d(Math.floor(pickPointView.x + 0.5), Math.floor(pickPointView.y + 0.5));\n let pixelRadius = Math.floor(pickRadiusView + 0.5);\n const rect = new ViewRect(testPointView.x - pixelRadius, testPointView.y - pixelRadius, testPointView.x + pixelRadius, testPointView.y + pixelRadius);\n let result: number = 0;\n vp.readPixels(rect, Pixel.Selector.All, (pixels) => {\n if (undefined === pixels)\n return;\n\n testPointView.x = vp.cssPixelsToDevicePixels(testPointView.x);\n testPointView.y = vp.cssPixelsToDevicePixels(testPointView.y);\n pixelRadius = vp.cssPixelsToDevicePixels(pixelRadius);\n\n const elmHits = new Map<string, Point2d>();\n const testPoint = Point2d.createZero();\n for (testPoint.x = testPointView.x - pixelRadius; testPoint.x <= testPointView.x + pixelRadius; ++testPoint.x) {\n for (testPoint.y = testPointView.y - pixelRadius; testPoint.y <= testPointView.y + pixelRadius; ++testPoint.y) {\n const pixel = pixels.getPixel(testPoint.x, testPoint.y);\n if (undefined === pixel || undefined === pixel.elementId || Id64.isInvalid(pixel.elementId))\n continue; // no geometry at this location...\n\n const distXY = testPointView.distance(testPoint);\n if (distXY > pixelRadius)\n continue; // ignore corners. it's a locate circle not square...\n\n const oldPoint = elmHits.get(pixel.elementId);\n if (undefined !== oldPoint) {\n if (this.comparePixel(pixel, pixels.getPixel(oldPoint.x, oldPoint.y), distXY, testPointView.distance(oldPoint)) < 0)\n oldPoint.setFrom(testPoint); // new hit is better, update location...\n } else {\n elmHits.set(pixel.elementId, testPoint.clone());\n }\n }\n }\n if (0 === elmHits.size)\n return;\n\n for (const elmPoint of elmHits.values()) {\n const pixel = pixels.getPixel(elmPoint.x, elmPoint.y);\n if (undefined === pixel || undefined === pixel.elementId)\n continue;\n\n const hitPointWorld = vp.getPixelDataWorldPoint({\n pixels,\n x: elmPoint.x,\n y: elmPoint.y,\n preserveModelDisplayTransforms: options.preserveModelDisplayTransforms,\n });\n\n if (!hitPointWorld)\n continue;\n\n const modelId = undefined !== pixel.featureTable ? pixel.featureTable.modelId : undefined;\n const hit = new HitDetail(pickPointWorld, vp, options.hitSource, hitPointWorld, pixel.elementId, this.getPixelPriority(pixel), testPointView.distance(elmPoint), pixel.distanceFraction, pixel.subCategoryId, pixel.geometryClass, modelId, pixel.iModel, pixel.tileId, pixel.isClassifier);\n this.hitList!.addHit(hit);\n\n if (this.hitList!.hits.length > options.maxHits)\n this.hitList!.hits.length = options.maxHits; // truncate array...\n }\n\n result = this.hitList!.length;\n }, !options.allowNonLocatable);\n\n return result;\n }\n\n public testHit(hit: HitDetail, vp: ScreenViewport, pickPointWorld: Point3d, pickRadiusView: number, options: LocateOptions): boolean {\n if (0 === this.doPick(vp, pickPointWorld, pickRadiusView, options))\n return false;\n\n return this.hitList!.hits.some((thisHit) => hit.isSameHit(thisHit));\n }\n}\n\n/**\n * @public\n * @extensions\n */\nexport class ElementLocateManager {\n public hitList?: HitList<HitDetail>;\n public currHit?: HitDetail;\n public readonly options = new LocateOptions();\n public readonly picker = new ElementPicker();\n\n /** get the full message key for a locate failure */\n public static getFailureMessageKey(key: string) { return `LocateFailure.${key}`; }\n public onInitialized() { }\n public get apertureInches() { return 0.11; }\n public get touchApertureInches() { return 0.22; }\n\n public clear(): void { this.setCurrHit(undefined); }\n public setHitList(list?: HitList<HitDetail>) { this.hitList = list; }\n public setCurrHit(hit?: HitDetail): void { this.currHit = hit; }\n public getNextHit(): HitDetail | undefined { return this.hitList ? this.hitList.getNextHit() : undefined; }\n\n /** return the current path from either the snapping logic or the pre-locating systems. */\n public getPreLocatedHit(): HitDetail | undefined {\n // NOTE: Check AccuSnap first as Tentative is used to build intersect snap. For normal snaps when a Tentative is active there should be no AccuSnap.\n let preLocated = IModelApp.accuSnap.getHitAndList(this);\n\n if (!preLocated && !!(preLocated = IModelApp.tentativePoint.getHitAndList(this))) {\n const vp = preLocated.viewport;\n this.picker.empty(); // Get new hit list at hit point; want reset to cycle hits using adjusted point location...\n this.picker.doPick(vp, preLocated.getPoint(), (vp.pixelsFromInches(this.apertureInches) / 2.0) + 1.5, this.options);\n this.setHitList(this.picker.getHitList(true));\n }\n\n if (this.hitList)\n this.hitList.resetCurrentHit();\n\n return preLocated;\n }\n\n public async filterHit(hit: HitDetail, _action: LocateAction, out: LocateResponse): Promise<LocateFilterStatus> {\n // Tools must opt-in to locate of transient geometry as it requires special treatment.\n if (!this.options.allowDecorations && !hit.isElementHit) {\n if (hit.isModelHit)\n out.reason = ElementLocateManager.getFailureMessageKey(\"RealityModel\");\n else if (hit.isMapHit)\n out.reason = ElementLocateManager.getFailureMessageKey(\"Map\");\n else\n out.reason = ElementLocateManager.getFailureMessageKey(\"Transient\");\n return LocateFilterStatus.Reject;\n }\n\n // Tools must opt-in to locate geometry from external iModels.\n if (!this.options.allowExternalIModels && hit.isExternalIModelHit) {\n out.reason = ElementLocateManager.getFailureMessageKey(\"ExternalIModel\");\n return LocateFilterStatus.Reject;\n }\n\n if (undefined !== hit.subCategoryId && !hit.isExternalIModelHit) {\n const appearance = hit.viewport.getSubCategoryAppearance(hit.subCategoryId);\n if (appearance.dontLocate) {\n out.reason = ElementLocateManager.getFailureMessageKey(\"NotLocatableSubCategory\");\n return LocateFilterStatus.Reject;\n }\n }\n\n const tool = IModelApp.toolAdmin.activeTool;\n if (!(tool && tool instanceof InteractiveTool))\n return LocateFilterStatus.Accept;\n\n const status = await tool.filterHit(hit, out);\n if (LocateFilterStatus.Reject === status)\n out.reason = ElementLocateManager.getFailureMessageKey(\"ByApp\");\n\n return status;\n }\n\n public initLocateOptions() { this.options.init(); }\n public initToolLocate() {\n this.initLocateOptions();\n this.clear();\n this.picker.empty();\n IModelApp.tentativePoint.clear(true);\n }\n\n private async _doLocate(response: LocateResponse, newSearch: boolean, testPoint: Point3d, vp: ScreenViewport | undefined, source: InputSource, filterHits: boolean): Promise<HitDetail | undefined> {\n if (!vp)\n return;\n\n // the \"newSearch\" flag indicates whether the caller wants us to conduct a new search at the testPoint, or just continue returning paths from the previous search.\n if (newSearch) {\n const hit = this.getPreLocatedHit();\n\n // if we're snapped to something, that path has the highest priority and becomes the active hit.\n if (hit) {\n if (!filterHits || LocateFilterStatus.Accept === await this.filterHit(hit, LocateAction.Identify, response))\n return hit;\n\n response = new LocateResponse(); // we have the reason and explanation we want.\n }\n\n this.picker.empty();\n this.picker.doPick(vp, testPoint, (vp.pixelsFromInches(InputSource.Touch === source ? this.touchApertureInches : this.apertureInches) / 2.0) + 1.5, this.options);\n\n const hitList = this.picker.getHitList(true);\n this.setHitList(hitList);\n }\n\n let newHit: HitDetail | undefined;\n while (undefined !== (newHit = this.getNextHit())) {\n if (!filterHits || LocateFilterStatus.Accept === await this.filterHit(newHit, LocateAction.Identify, response))\n return newHit;\n response = new LocateResponse(); // we have the reason and explanation we want.\n }\n\n return undefined;\n }\n\n public async doLocate(response: LocateResponse, newSearch: boolean, testPoint: Point3d, view: ScreenViewport | undefined, source: InputSource, filterHits = true): Promise<HitDetail | undefined> {\n response.reason = ElementLocateManager.getFailureMessageKey(\"NoElements\");\n response.explanation = \"\";\n\n const hit = await this._doLocate(response, newSearch, testPoint, view, source, filterHits);\n this.setCurrHit(hit);\n\n // if we found a hit, remove it from the list of remaining hits near the current search point.\n if (hit && this.hitList)\n this.hitList.removeHitsFrom(hit.sourceId);\n return hit;\n }\n}\n"]}
1
+ {"version":3,"file":"ElementLocateManager.js","sourceRoot":"","sources":["../../src/ElementLocateManager.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE5D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;;GAGG;AACH,MAAM,CAAN,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,uDAAY,CAAA;IACZ,2DAAc,CAAA;AAChB,CAAC,EAHW,YAAY,KAAZ,YAAY,QAGvB;AAED;;;;GAIG;AACH,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,+DAAU,CAAA;IACV,+DAAU,CAAA;AACZ,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B;AAED;;;GAGG;AACH,MAAM,CAAN,IAAY,UASX;AATD,WAAY,UAAU;IACpB,iDAAW,CAAA;IACX,iDAAW,CAAA;IACX,uDAAc,CAAA;IACd,qDAAc,CAAA;IACd,iEAAoB,CAAA;IACpB,6DAAkB,CAAA;IAClB,+DAAmB,CAAA;IACnB,6EAA0B,CAAA;AAC5B,CAAC,EATW,UAAU,KAAV,UAAU,QASrB;AAED;;;GAGG;AACH,MAAM,OAAO,aAAa;IAA1B;QACE,yDAA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AY,CAAC,CAAC;QAC1E,QAAQ,CAAC,WAAW,GAAG,EAAE,CAAC;QAE1B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;QAC3F,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAErB,8FAA8F;QAC9F,IAAI,GAAG,IAAI,IAAI,CAAC,OAAO;YACrB,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC5C,OAAO,GAAG,CAAC;IACb,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 LocatingElements\n */\n\nimport { Id64 } from \"@itwin/core-bentley\";\nimport { Point2d, Point3d } from \"@itwin/core-geometry\";\nimport { HitDetail, HitList, HitPriority, HitSource } from \"./HitDetail\";\nimport { IModelApp } from \"./IModelApp\";\nimport { Pixel } from \"./render/Pixel\";\nimport { InputSource, InteractiveTool } from \"./tools/Tool\";\nimport { ScreenViewport, Viewport } from \"./Viewport\";\nimport { ViewRect } from \"./ViewRect\";\n\n/** The possible actions for which a locate filter can be called.\n * @public\n * @extensions\n */\nexport enum LocateAction {\n Identify = 0,\n AutoLocate = 1,\n}\n\n/** Values to return from a locate filter.\n * Return `Reject` to indicate the element is unacceptable.\n * @public\n * @extensions\n */\nexport enum LocateFilterStatus {\n Accept = 0,\n Reject = 1,\n}\n\n/**\n * @public\n * @extensions\n */\nexport enum SnapStatus {\n Success = 0,\n Aborted = 1,\n NoElements = 2,\n Disabled = 100,\n NoSnapPossible = 200,\n NotSnappable = 300,\n FilteredByApp = 600,\n FilteredByAppQuietly = 700,\n}\n\n/** Options that customize the way element location (i.e. *picking*) works.\n * @public\n * @extensions\n */\nexport class LocateOptions {\n /** If true, also test graphics from view decorations. */\n public allowDecorations = false;\n /** If true, also test graphics with non-locatable flag set. */\n public allowNonLocatable = false;\n /** Maximum number of hits to return. */\n public maxHits = 20;\n /** The [[HitSource]] identifying the caller. */\n public hitSource = HitSource.DataPoint;\n /** If true, also test graphics from an IModelConnection other than the one associated with the Viewport. This can occur if, e.g., a\n * [[TiledGraphicsProvider]] is used to display graphics from a different iModel into the [[Viewport]].\n * @note If you override this, you must be prepared to properly handle [[HitDetail]]s originating from other IModelConnections.\n * @see [[HitDetail.iModel]] and [[HitDetail.isExternalIModelHit]]\n */\n public allowExternalIModels = false;\n /** If true, then the world point of a hit on a model will preserve any transforms applied to the model at display time,\n * such as those supplied by a [[ModelDisplayTransformProvider]] or [PlanProjectionSettings.elevation]($common).\n * Otherwise, the world point will be multiplied by the inverse of any such transforms to correlate it with the model's true coordinate space.\n */\n public preserveModelDisplayTransforms = false;\n\n /** Make a copy of this LocateOptions. */\n public clone(): LocateOptions {\n const other = new LocateOptions();\n other.allowDecorations = this.allowDecorations;\n other.allowNonLocatable = this.allowNonLocatable;\n other.maxHits = this.maxHits;\n other.hitSource = this.hitSource;\n other.allowExternalIModels = this.allowExternalIModels;\n return other;\n }\n public setFrom(other: LocateOptions): void {\n this.allowDecorations = other.allowDecorations;\n this.allowNonLocatable = other.allowNonLocatable;\n this.maxHits = other.maxHits;\n this.hitSource = other.hitSource;\n this.allowExternalIModels = other.allowExternalIModels;\n }\n public init() {\n this.allowDecorations = this.allowNonLocatable = this.allowExternalIModels = false;\n this.maxHits = 20;\n this.hitSource = HitSource.DataPoint;\n }\n}\n\n/**\n * @public\n * @extensions\n */\nexport class LocateResponse {\n public snapStatus = SnapStatus.Success;\n public reason?: string;\n public explanation = \"\";\n\n /** @internal */\n public clone(): LocateResponse {\n const other = new LocateResponse();\n other.snapStatus = this.snapStatus;\n other.reason = this.reason;\n other.explanation = this.explanation;\n return other;\n }\n\n /** @internal */\n public setFrom(other: LocateResponse): void {\n this.snapStatus = other.snapStatus;\n this.reason = other.reason;\n this.explanation = other.explanation;\n }\n}\n\n/**\n * @public\n * @extensions\n */\nexport interface HitListHolder {\n setHitList(list: HitList<HitDetail> | undefined): void;\n}\n\n/**\n * @public\n * @extensions\n */\nexport class ElementPicker {\n public viewport?: Viewport;\n public readonly pickPointWorld = new Point3d();\n public hitList?: HitList<HitDetail>;\n\n public empty() {\n this.pickPointWorld.setZero();\n this.viewport = undefined;\n if (this.hitList)\n this.hitList.empty();\n else\n this.hitList = new HitList<HitDetail>();\n }\n\n /** return the HitList for the last Pick performed. Optionally allows the caller to take ownership of the list. */\n public getHitList(takeOwnership: boolean): HitList<HitDetail> {\n const list = this.hitList!;\n if (takeOwnership)\n this.hitList = undefined;\n return list;\n }\n\n public getNextHit(): HitDetail | undefined { return this.hitList ? this.hitList.getNextHit() : undefined; }\n\n /** Return a hit from the list of hits created the last time pickElements was called. */\n public getHit(i: number): HitDetail | undefined { return this.hitList ? this.hitList.getHit(i) : undefined; }\n\n public resetCurrentHit(): void {\n if (this.hitList)\n this.hitList.resetCurrentHit();\n }\n\n private getPixelPriority(pixel: Pixel.Data) {\n switch (pixel.type) {\n case Pixel.GeometryType.Surface:\n return Pixel.Planarity.Planar === pixel.planarity ? HitPriority.PlanarSurface : HitPriority.NonPlanarSurface;\n case Pixel.GeometryType.Linear:\n return HitPriority.WireEdge;\n case Pixel.GeometryType.Edge:\n return Pixel.Planarity.Planar === pixel.planarity ? HitPriority.PlanarEdge : HitPriority.NonPlanarEdge;\n case Pixel.GeometryType.Silhouette:\n return HitPriority.SilhouetteEdge;\n default:\n return HitPriority.Unknown;\n }\n }\n\n private comparePixel(pixel1: Pixel.Data, pixel2: Pixel.Data, distXY1: number, distXY2: number) {\n const priority1 = this.getPixelPriority(pixel1);\n const priority2 = this.getPixelPriority(pixel2);\n if (priority1 < priority2)\n return -1;\n if (priority1 > priority2)\n return 1;\n if (distXY1 < distXY2)\n return -1;\n if (distXY1 > distXY2)\n return 1;\n if (pixel1.distanceFraction > pixel2.distanceFraction)\n return -1;\n if (pixel1.distanceFraction < pixel2.distanceFraction)\n return 1;\n\n return 0;\n }\n\n /** Generate a list of elements that are close to a given point.\n * @returns The number of hits in the hitList of this object.\n */\n public doPick(vp: ScreenViewport, pickPointWorld: Point3d, pickRadiusView: number, options: LocateOptions): number {\n if (this.hitList && this.hitList.length > 0 && vp === this.viewport && pickPointWorld.isAlmostEqual(this.pickPointWorld)) {\n this.hitList.resetCurrentHit();\n return this.hitList.length;\n }\n\n this.empty(); // empty the hit list\n this.viewport = vp;\n this.pickPointWorld.setFrom(pickPointWorld);\n\n const pickPointView = vp.worldToView(pickPointWorld);\n const testPointView = new Point2d(Math.floor(pickPointView.x + 0.5), Math.floor(pickPointView.y + 0.5));\n let pixelRadius = Math.floor(pickRadiusView + 0.5);\n const rect = new ViewRect(testPointView.x - pixelRadius, testPointView.y - pixelRadius, testPointView.x + pixelRadius, testPointView.y + pixelRadius);\n if (rect.isNull)\n return 0;\n let result: number = 0;\n vp.readPixels(rect, Pixel.Selector.All, (pixels) => {\n if (undefined === pixels)\n return;\n\n testPointView.x = vp.cssPixelsToDevicePixels(testPointView.x);\n testPointView.y = vp.cssPixelsToDevicePixels(testPointView.y);\n pixelRadius = vp.cssPixelsToDevicePixels(pixelRadius);\n\n const elmHits = new Map<string, Point2d>();\n const testPoint = Point2d.createZero();\n for (testPoint.x = testPointView.x - pixelRadius; testPoint.x <= testPointView.x + pixelRadius; ++testPoint.x) {\n for (testPoint.y = testPointView.y - pixelRadius; testPoint.y <= testPointView.y + pixelRadius; ++testPoint.y) {\n const pixel = pixels.getPixel(testPoint.x, testPoint.y);\n if (undefined === pixel || undefined === pixel.elementId || Id64.isInvalid(pixel.elementId))\n continue; // no geometry at this location...\n\n const distXY = testPointView.distance(testPoint);\n if (distXY > pixelRadius)\n continue; // ignore corners. it's a locate circle not square...\n\n const oldPoint = elmHits.get(pixel.elementId);\n if (undefined !== oldPoint) {\n if (this.comparePixel(pixel, pixels.getPixel(oldPoint.x, oldPoint.y), distXY, testPointView.distance(oldPoint)) < 0)\n oldPoint.setFrom(testPoint); // new hit is better, update location...\n } else {\n elmHits.set(pixel.elementId, testPoint.clone());\n }\n }\n }\n if (0 === elmHits.size)\n return;\n\n for (const elmPoint of elmHits.values()) {\n const pixel = pixels.getPixel(elmPoint.x, elmPoint.y);\n if (undefined === pixel || undefined === pixel.elementId)\n continue;\n\n const hitPointWorld = vp.getPixelDataWorldPoint({\n pixels,\n x: elmPoint.x,\n y: elmPoint.y,\n preserveModelDisplayTransforms: options.preserveModelDisplayTransforms,\n });\n\n if (!hitPointWorld)\n continue;\n\n const modelId = undefined !== pixel.featureTable ? pixel.featureTable.modelId : undefined;\n const hit = new HitDetail(pickPointWorld, vp, options.hitSource, hitPointWorld, pixel.elementId, this.getPixelPriority(pixel), testPointView.distance(elmPoint), pixel.distanceFraction, pixel.subCategoryId, pixel.geometryClass, modelId, pixel.iModel, pixel.tileId, pixel.isClassifier);\n this.hitList!.addHit(hit);\n\n if (this.hitList!.hits.length > options.maxHits)\n this.hitList!.hits.length = options.maxHits; // truncate array...\n }\n\n result = this.hitList!.length;\n }, !options.allowNonLocatable);\n\n return result;\n }\n\n public testHit(hit: HitDetail, vp: ScreenViewport, pickPointWorld: Point3d, pickRadiusView: number, options: LocateOptions): boolean {\n if (0 === this.doPick(vp, pickPointWorld, pickRadiusView, options))\n return false;\n\n return this.hitList!.hits.some((thisHit) => hit.isSameHit(thisHit));\n }\n}\n\n/**\n * @public\n * @extensions\n */\nexport class ElementLocateManager {\n public hitList?: HitList<HitDetail>;\n public currHit?: HitDetail;\n public readonly options = new LocateOptions();\n public readonly picker = new ElementPicker();\n\n /** get the full message key for a locate failure */\n public static getFailureMessageKey(key: string) { return `LocateFailure.${key}`; }\n public onInitialized() { }\n public get apertureInches() { return 0.11; }\n public get touchApertureInches() { return 0.22; }\n\n public clear(): void { this.setCurrHit(undefined); }\n public setHitList(list?: HitList<HitDetail>) { this.hitList = list; }\n public setCurrHit(hit?: HitDetail): void { this.currHit = hit; }\n public getNextHit(): HitDetail | undefined { return this.hitList ? this.hitList.getNextHit() : undefined; }\n\n /** return the current path from either the snapping logic or the pre-locating systems. */\n public getPreLocatedHit(): HitDetail | undefined {\n // NOTE: Check AccuSnap first as Tentative is used to build intersect snap. For normal snaps when a Tentative is active there should be no AccuSnap.\n let preLocated = IModelApp.accuSnap.getHitAndList(this);\n\n if (!preLocated && !!(preLocated = IModelApp.tentativePoint.getHitAndList(this))) {\n const vp = preLocated.viewport;\n this.picker.empty(); // Get new hit list at hit point; want reset to cycle hits using adjusted point location...\n this.picker.doPick(vp, preLocated.getPoint(), (vp.pixelsFromInches(this.apertureInches) / 2.0) + 1.5, this.options);\n this.setHitList(this.picker.getHitList(true));\n }\n\n if (this.hitList)\n this.hitList.resetCurrentHit();\n\n return preLocated;\n }\n\n public async filterHit(hit: HitDetail, _action: LocateAction, out: LocateResponse): Promise<LocateFilterStatus> {\n // Tools must opt-in to locate of transient geometry as it requires special treatment.\n if (!this.options.allowDecorations && !hit.isElementHit) {\n if (hit.isModelHit)\n out.reason = ElementLocateManager.getFailureMessageKey(\"RealityModel\");\n else if (hit.isMapHit)\n out.reason = ElementLocateManager.getFailureMessageKey(\"Map\");\n else\n out.reason = ElementLocateManager.getFailureMessageKey(\"Transient\");\n return LocateFilterStatus.Reject;\n }\n\n // Tools must opt-in to locate geometry from external iModels.\n if (!this.options.allowExternalIModels && hit.isExternalIModelHit) {\n out.reason = ElementLocateManager.getFailureMessageKey(\"ExternalIModel\");\n return LocateFilterStatus.Reject;\n }\n\n if (undefined !== hit.subCategoryId && !hit.isExternalIModelHit) {\n const appearance = hit.viewport.getSubCategoryAppearance(hit.subCategoryId);\n if (appearance.dontLocate) {\n out.reason = ElementLocateManager.getFailureMessageKey(\"NotLocatableSubCategory\");\n return LocateFilterStatus.Reject;\n }\n }\n\n const tool = IModelApp.toolAdmin.activeTool;\n if (!(tool && tool instanceof InteractiveTool))\n return LocateFilterStatus.Accept;\n\n const status = await tool.filterHit(hit, out);\n if (LocateFilterStatus.Reject === status)\n out.reason = ElementLocateManager.getFailureMessageKey(\"ByApp\");\n\n return status;\n }\n\n public initLocateOptions() { this.options.init(); }\n public initToolLocate() {\n this.initLocateOptions();\n this.clear();\n this.picker.empty();\n IModelApp.tentativePoint.clear(true);\n }\n\n private async _doLocate(response: LocateResponse, newSearch: boolean, testPoint: Point3d, vp: ScreenViewport | undefined, source: InputSource, filterHits: boolean): Promise<HitDetail | undefined> {\n if (!vp)\n return;\n\n // the \"newSearch\" flag indicates whether the caller wants us to conduct a new search at the testPoint, or just continue returning paths from the previous search.\n if (newSearch) {\n const hit = this.getPreLocatedHit();\n\n // if we're snapped to something, that path has the highest priority and becomes the active hit.\n if (hit) {\n if (!filterHits || LocateFilterStatus.Accept === await this.filterHit(hit, LocateAction.Identify, response))\n return hit;\n\n response = new LocateResponse(); // we have the reason and explanation we want.\n }\n\n this.picker.empty();\n this.picker.doPick(vp, testPoint, (vp.pixelsFromInches(InputSource.Touch === source ? this.touchApertureInches : this.apertureInches) / 2.0) + 1.5, this.options);\n\n const hitList = this.picker.getHitList(true);\n this.setHitList(hitList);\n }\n\n let newHit: HitDetail | undefined;\n while (undefined !== (newHit = this.getNextHit())) {\n if (!filterHits || LocateFilterStatus.Accept === await this.filterHit(newHit, LocateAction.Identify, response))\n return newHit;\n response = new LocateResponse(); // we have the reason and explanation we want.\n }\n\n return undefined;\n }\n\n public async doLocate(response: LocateResponse, newSearch: boolean, testPoint: Point3d, view: ScreenViewport | undefined, source: InputSource, filterHits = true): Promise<HitDetail | undefined> {\n response.reason = ElementLocateManager.getFailureMessageKey(\"NoElements\");\n response.explanation = \"\";\n\n const hit = await this._doLocate(response, newSearch, testPoint, view, source, filterHits);\n this.setCurrHit(hit);\n\n // if we found a hit, remove it from the list of remaining hits near the current search point.\n if (hit && this.hitList)\n this.hitList.removeHitsFrom(hit.sourceId);\n return hit;\n }\n}\n"]}
@@ -1,6 +1,58 @@
1
- import { XYZProps } from "@itwin/core-geometry";
1
+ import { BeEvent, Dictionary, SortedArray } from "@itwin/core-bentley";
2
+ import { WritableXYAndZ, XYAndZ, XYZProps } from "@itwin/core-geometry";
2
3
  import { GeoCoordinatesResponseProps, GeographicCRSProps, IModelCoordinatesResponseProps, PointWithStatus } from "@itwin/core-common";
3
4
  import { IModelConnection } from "./IModelConnection";
5
+ /** Options used to create a [[CoordinateConverter]].
6
+ * @internal exported strictly for tests.
7
+ */
8
+ export interface CoordinateConverterOptions {
9
+ /** The iModel for which to perform the conversions. */
10
+ iModel: IModelConnection;
11
+ /** Asynchronously convert each point. The resultant array should have the same number and order of points as the input. */
12
+ requestPoints: (points: XYAndZ[]) => Promise<PointWithStatus[]>;
13
+ /** Maximum number of points to include in each request. Default: 300. */
14
+ maxPointsPerRequest?: number;
15
+ }
16
+ declare type CoordinateConverterState = "idle" | "scheduled" | "in-flight";
17
+ /** Performs conversion of coordinates from one coordinate system to another.
18
+ * A [[GeoConverter]] has a pair of these for converting between iModel coordinates and geographic coordinates.
19
+ * Uses a cache to avoid repeatedly requesting the same points, and a batching strategy to avoid making frequent small requests.
20
+ * The cache stores every point that was ever converted by [[convert]]. It is currently permitted to grow to unbounded size.
21
+ * The batching works as follows:
22
+ * When a conversion is requested via [[convert]], if all the requested points are in the cache, they are returned immediately.
23
+ * Otherwise, any points not in the cache and not in the current in-flight request (if any) are placed onto the queue of pending requests.
24
+ * A pending request is scheduled if one hasn't already been scheduled, via requestAnimationFrame.
25
+ * In the animation frame callback, the pending requests are split into batches of no more than options.maxPointsPerRequest and dispatched to the backend.
26
+ * Once the response is received, the results are loaded into and returned from the cache.
27
+ * If more calls to convert occurred while the request was in flight, another request is dispatched.
28
+ * @internal exported strictly for tests.
29
+ */
30
+ export declare class CoordinateConverter {
31
+ protected readonly _cache: Dictionary<XYAndZ, PointWithStatus>;
32
+ protected _state: CoordinateConverterState;
33
+ protected _pending: SortedArray<XYAndZ>;
34
+ protected _inflight: SortedArray<XYAndZ>;
35
+ protected _onCompleted: BeEvent<() => void>;
36
+ protected readonly _scratchXYZ: {
37
+ x: number;
38
+ y: number;
39
+ z: number;
40
+ };
41
+ protected readonly _maxPointsPerRequest: number;
42
+ protected readonly _iModel: IModelConnection;
43
+ protected readonly _requestPoints: (points: XYAndZ[]) => Promise<PointWithStatus[]>;
44
+ protected toXYAndZ(input: XYZProps, output: WritableXYAndZ): XYAndZ;
45
+ constructor(opts: CoordinateConverterOptions);
46
+ protected dispatch(): Promise<void>;
47
+ protected enqueue(points: XYZProps[]): number;
48
+ protected getFromCache(inputs: XYZProps[]): PointWithStatus[];
49
+ protected scheduleDispatch(): Promise<void>;
50
+ convert(inputs: XYZProps[]): Promise<{
51
+ points: PointWithStatus[];
52
+ fromCache: number;
53
+ }>;
54
+ findCached(inputs: XYZProps[]): CachedIModelCoordinatesResponseProps;
55
+ }
4
56
  /** Response to a request to obtain imodel coordinates from cache.
5
57
  * @internal
6
58
  */
@@ -14,13 +66,12 @@ export interface CachedIModelCoordinatesResponseProps {
14
66
  * @internal
15
67
  */
16
68
  export declare class GeoConverter {
17
- private _datumOrGCRS;
18
- private _gCtoIMCResultCache;
19
- private _iMCtoGCResultCache;
69
+ private readonly _geoToIModel;
70
+ private readonly _iModelToGeo;
20
71
  constructor(iModel: IModelConnection, datumOrGCRS: string | GeographicCRSProps);
21
72
  getIModelCoordinatesFromGeoCoordinates(geoPoints: XYZProps[]): Promise<IModelCoordinatesResponseProps>;
22
- getCachedIModelCoordinatesFromGeoCoordinates(geoPoints: XYZProps[]): CachedIModelCoordinatesResponseProps;
23
73
  getGeoCoordinatesFromIModelCoordinates(iModelPoints: XYZProps[]): Promise<GeoCoordinatesResponseProps>;
74
+ getCachedIModelCoordinatesFromGeoCoordinates(geoPoints: XYZProps[]): CachedIModelCoordinatesResponseProps;
24
75
  }
25
76
  /** The Geographic Services available for an [[IModelConnection]].
26
77
  * @internal
@@ -30,4 +81,5 @@ export declare class GeoServices {
30
81
  constructor(iModel: IModelConnection);
31
82
  getConverter(datumOrGCRS?: string | GeographicCRSProps): GeoConverter | undefined;
32
83
  }
84
+ export {};
33
85
  //# sourceMappingURL=GeoServices.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GeoServices.d.ts","sourceRoot":"","sources":["../../src/GeoServices.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EACuB,2BAA2B,EAAkB,kBAAkB,EAAiC,8BAA8B,EAClI,eAAe,EACxC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,oCAAoC;IACnD,oIAAoI;IACpI,MAAM,EAAE,KAAK,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC;IAC3C,mIAAmI;IACnI,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC;CACtB;AA+LD;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,mBAAmB,CAAqB;IAChD,OAAO,CAAC,mBAAmB,CAAqB;gBACpC,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,GAAG,kBAAkB;IASjE,sCAAsC,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,8BAA8B,CAAC;IAK5G,4CAA4C,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,oCAAoC;IAInG,sCAAsC,CAAC,YAAY,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,2BAA2B,CAAC;CAIpH;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAmB;gBAEtB,MAAM,EAAE,gBAAgB;IAI7B,YAAY,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,kBAAkB,GAAG,YAAY,GAAG,SAAS;CAGzF"}
1
+ {"version":3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;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAmB;gBAEtB,MAAM,EAAE,gBAAgB;IAI7B,YAAY,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,kBAAkB,GAAG,YAAY,GAAG,SAAS;CAGzF"}
@@ -1,156 +1,163 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ // cspell:ignore GCRS
6
+ import { assert, BeEvent, Dictionary, Logger, SortedArray, } from "@itwin/core-bentley";
1
7
  import { GeoCoordStatus, IModelReadRpcInterface, } from "@itwin/core-common";
2
- // this class is used to cache results from conversion of geoCoordinates to IModelCoordinates.
3
- class GCtoIMCResultCache {
4
- constructor(iModel, source) {
5
- this._iModel = iModel;
6
- this._cache = {};
7
- this._source = source;
8
+ import { FrontendLoggerCategory } from "./FrontendLoggerCategory";
9
+ function compareXYAndZ(lhs, rhs) {
10
+ return lhs.x - rhs.x || lhs.y - rhs.y || lhs.z - rhs.z;
11
+ }
12
+ function cloneXYAndZ(xyz) {
13
+ return { x: xyz.x, y: xyz.y, z: xyz.z };
14
+ }
15
+ /** Performs conversion of coordinates from one coordinate system to another.
16
+ * A [[GeoConverter]] has a pair of these for converting between iModel coordinates and geographic coordinates.
17
+ * Uses a cache to avoid repeatedly requesting the same points, and a batching strategy to avoid making frequent small requests.
18
+ * The cache stores every point that was ever converted by [[convert]]. It is currently permitted to grow to unbounded size.
19
+ * The batching works as follows:
20
+ * When a conversion is requested via [[convert]], if all the requested points are in the cache, they are returned immediately.
21
+ * Otherwise, any points not in the cache and not in the current in-flight request (if any) are placed onto the queue of pending requests.
22
+ * A pending request is scheduled if one hasn't already been scheduled, via requestAnimationFrame.
23
+ * In the animation frame callback, the pending requests are split into batches of no more than options.maxPointsPerRequest and dispatched to the backend.
24
+ * Once the response is received, the results are loaded into and returned from the cache.
25
+ * If more calls to convert occurred while the request was in flight, another request is dispatched.
26
+ * @internal exported strictly for tests.
27
+ */
28
+ export class CoordinateConverter {
29
+ constructor(opts) {
30
+ var _a;
31
+ this._state = "idle";
32
+ // An event fired when the next request completes.
33
+ this._onCompleted = new BeEvent();
34
+ // Used for creating cache keys (XYAndZ) from XYZProps without having to allocate temporary objects.
35
+ this._scratchXYZ = { x: 0, y: 0, z: 0 };
36
+ this._maxPointsPerRequest = Math.max(1, (_a = opts.maxPointsPerRequest) !== null && _a !== void 0 ? _a : 300);
37
+ this._iModel = opts.iModel;
38
+ this._requestPoints = opts.requestPoints;
39
+ this._cache = new Dictionary(compareXYAndZ, cloneXYAndZ);
40
+ this._pending = new SortedArray(compareXYAndZ, false, cloneXYAndZ);
41
+ this._inflight = new SortedArray(compareXYAndZ, false, cloneXYAndZ);
8
42
  }
9
- /** @internal */
10
- findInCache(geoPoints) {
11
- const result = [];
12
- let missing;
13
- for (const geoPoint of geoPoints) {
14
- const key = JSON.stringify(geoPoint);
15
- const imodelCoord = this._cache[key];
16
- result.push(imodelCoord);
17
- if (undefined === imodelCoord) {
18
- if (undefined === missing)
19
- missing = [];
20
- missing.push(geoPoint);
21
- }
43
+ toXYAndZ(input, output) {
44
+ var _a, _b, _c, _d, _e, _f;
45
+ if (Array.isArray(input)) {
46
+ output.x = (_a = input[0]) !== null && _a !== void 0 ? _a : 0;
47
+ output.y = (_b = input[1]) !== null && _b !== void 0 ? _b : 0;
48
+ output.z = (_c = input[2]) !== null && _c !== void 0 ? _c : 0;
22
49
  }
23
- return { result, missing };
24
- }
25
- async findInCacheOrRequest(request) {
26
- const response = { iModelCoords: [], fromCache: 0 };
27
- let missing;
28
- // Index by cache key to obtain index in input array.
29
- const originalPositions = {};
30
- for (let iPoint = 0; iPoint < request.geoCoords.length; ++iPoint) {
31
- const thisGeoCoord = request.geoCoords[iPoint];
32
- // we use the JSON string as the key into our cache of previously returned results.
33
- const thisCacheKey = JSON.stringify(thisGeoCoord);
34
- // put something in each output that corresponds to the input.
35
- if (this._cache[thisCacheKey]) {
36
- response.iModelCoords.push(this._cache[thisCacheKey]);
37
- }
38
- else {
39
- if (undefined === missing)
40
- missing = [];
41
- // add this geoCoord to the request we are going to send.
42
- missing.push(thisGeoCoord);
43
- // keep track of the original position of this point.
44
- if (originalPositions.hasOwnProperty(thisCacheKey)) {
45
- // it is a duplicate of an earlier point (or points)
46
- if (Array.isArray(originalPositions[thisCacheKey])) {
47
- originalPositions[thisCacheKey].push(iPoint);
48
- }
49
- else {
50
- const list = [originalPositions[thisCacheKey], iPoint];
51
- originalPositions[thisCacheKey] = list;
52
- }
53
- }
54
- else {
55
- originalPositions[thisCacheKey] = iPoint;
56
- }
57
- // mark the response as pending.
58
- response.iModelCoords.push({ p: [0, 0, 0], s: GeoCoordStatus.Pending });
59
- }
50
+ else {
51
+ output.x = (_d = input.x) !== null && _d !== void 0 ? _d : 0;
52
+ output.y = (_e = input.y) !== null && _e !== void 0 ? _e : 0;
53
+ output.z = (_f = input.z) !== null && _f !== void 0 ? _f : 0;
60
54
  }
61
- // if none are missing from the cache, resolve the promise immediately
62
- if (undefined === missing) {
63
- response.fromCache = request.geoCoords.length;
55
+ return output;
56
+ }
57
+ async dispatch() {
58
+ assert(this._state === "scheduled");
59
+ if (this._iModel.isClosed || this._pending.isEmpty) {
60
+ this._state = "idle";
61
+ this._onCompleted.raiseEvent();
62
+ return;
64
63
  }
65
- else {
66
- // keep track of how many came from the cache (mostly for tests).
67
- response.fromCache = request.geoCoords.length - missing.length;
68
- // Avoiding requesting too many points at once, exceeding max request length (this definition of "too many" should be safely conservative) - but enough to load 4 levels of tile corners.
69
- const maxPointsPerRequest = 300;
70
- const promises = [];
71
- for (let i = 0; i < missing.length; i += maxPointsPerRequest) {
72
- const remainingRequest = { source: this._source, geoCoords: missing.slice(i, i + maxPointsPerRequest) };
73
- const promise = IModelReadRpcInterface.getClientForRouting(this._iModel.routingContext.token).getIModelCoordinatesFromGeoCoordinates(this._iModel.getRpcProps(), remainingRequest).then((remainingResponse) => {
74
- // put the responses into the cache, and fill in the output response for each
75
- for (let iResponse = 0; iResponse < remainingResponse.iModelCoords.length; ++iResponse) {
76
- const thisPoint = remainingResponse.iModelCoords[iResponse];
77
- // put the answer in the cache.
78
- const thisGeoCoord = remainingRequest.geoCoords[iResponse];
79
- const thisCacheKey = JSON.stringify(thisGeoCoord);
80
- this._cache[thisCacheKey] = thisPoint;
81
- // transfer the answer stored in remainingResponse to the correct position in the overall response.
82
- const responseIndex = originalPositions[thisCacheKey];
83
- if (Array.isArray(responseIndex)) {
84
- for (const thisIndex of responseIndex) {
85
- response.iModelCoords[thisIndex] = thisPoint;
86
- }
87
- }
88
- else {
89
- response.iModelCoords[responseIndex] = thisPoint;
90
- }
91
- }
92
- });
93
- promises.push(promise);
94
- }
95
- await Promise.all(promises);
64
+ this._state = "in-flight";
65
+ // Ensure subsequently-enqueued requests listen for the *next* response to be received.
66
+ const onCompleted = this._onCompleted;
67
+ this._onCompleted = new BeEvent();
68
+ // Pending requests are now in flight. Start a new list of pending requests. It's cheaper to swap than to allocate new objects.
69
+ const inflight = this._pending;
70
+ this._pending = this._inflight;
71
+ assert(this._pending.isEmpty);
72
+ this._inflight = inflight;
73
+ // Split requests if necessary to avoid requesting more than the maximum allowed number of points.
74
+ const promises = [];
75
+ for (let i = 0; i < inflight.length; i += this._maxPointsPerRequest) {
76
+ const requests = inflight.slice(i, i + this._maxPointsPerRequest).extractArray();
77
+ const promise = this._requestPoints(requests).then((results) => {
78
+ if (this._iModel.isClosed)
79
+ return;
80
+ if (results.length !== requests.length)
81
+ Logger.logError(`${FrontendLoggerCategory.Package}.geoservices`, `requested conversion of ${requests.length} points, but received ${results.length} points`);
82
+ for (let j = 0; j < results.length; j++) {
83
+ if (j < requests.length)
84
+ this._cache.set(requests[j], results[j]);
85
+ }
86
+ }).catch((err) => {
87
+ Logger.logException(`${FrontendLoggerCategory.Package}.geoservices`, err);
88
+ });
89
+ promises.push(promise);
96
90
  }
97
- return response;
91
+ await Promise.all(promises);
92
+ assert(this._state === "in-flight");
93
+ this._state = "idle";
94
+ this._inflight.clear();
95
+ // If any more pending conversions arrived while awaiting this request, schedule another request.
96
+ if (!this._pending.isEmpty)
97
+ this.scheduleDispatch(); // eslint-disable-line @typescript-eslint/no-floating-promises
98
+ // Resolve promises of all callers who were awaiting this request.
99
+ onCompleted.raiseEvent();
98
100
  }
99
- }
100
- // this class is used to cache results from conversion of IModelCoordinates to GeoCoordinates.
101
- class IMCtoGCResultCache {
102
- constructor(iModel, target) {
103
- this._iModel = iModel;
104
- this._cache = {};
105
- this._target = target;
101
+ // Add any points not present in cache to pending request list.
102
+ // Return the number of points present in cache.
103
+ enqueue(points) {
104
+ let numInCache = 0;
105
+ for (const point of points) {
106
+ const xyz = this.toXYAndZ(point, this._scratchXYZ);
107
+ if (this._cache.get(xyz))
108
+ ++numInCache;
109
+ else if (!this._inflight.contains(xyz))
110
+ this._pending.insert(xyz);
111
+ }
112
+ return numInCache;
106
113
  }
107
- async findInCacheOrRequest(request) {
108
- let missing = false;
109
- const response = { geoCoords: [], fromCache: 0 };
110
- let remainingRequest;
111
- const originalPositions = [];
112
- for (let iPoint = 0; iPoint < request.iModelCoords.length; ++iPoint) {
113
- const thisIModelCoord = request.iModelCoords[iPoint];
114
- // we use the JSON string as the key into our cache of previously returned results.
115
- const thisCacheKey = JSON.stringify(thisIModelCoord);
116
- // put something in each output that corresponds to the input.
117
- if (this._cache[thisCacheKey]) {
118
- response.geoCoords.push(this._cache[thisCacheKey]);
119
- }
120
- else {
121
- if (!remainingRequest)
122
- remainingRequest = { target: this._target, iModelCoords: [] };
123
- // add this geoCoord to the request we are going to send.
124
- remainingRequest.iModelCoords.push(thisIModelCoord);
125
- // keep track of the original position of this point.
126
- originalPositions.push(iPoint);
127
- // mark the response as pending.
128
- response.geoCoords.push({ p: [0, 0, 0], s: GeoCoordStatus.Pending });
129
- missing = true;
130
- }
114
+ // Obtain converted points from the cache. The assumption is that every point in `inputs` is already present in the cache.
115
+ // Any point not present will be returned unconverted with an error status.
116
+ getFromCache(inputs) {
117
+ const outputs = [];
118
+ for (const input of inputs) {
119
+ const xyz = this.toXYAndZ(input, this._scratchXYZ);
120
+ let output = this._cache.get(xyz);
121
+ if (!output)
122
+ output = { p: { ...xyz }, s: GeoCoordStatus.CSMapError };
123
+ outputs.push(output);
131
124
  }
132
- // if none are missing from the cache, resolve the promise immediately
133
- if (!missing) {
134
- response.fromCache = request.iModelCoords.length;
135
- return response;
125
+ return outputs;
126
+ }
127
+ async scheduleDispatch() {
128
+ if ("idle" === this._state) {
129
+ this._state = "scheduled";
130
+ requestAnimationFrame(() => {
131
+ this.dispatch(); // eslint-disable-line @typescript-eslint/no-floating-promises
132
+ });
136
133
  }
137
- else {
138
- // keep track of how many came from the cache (mostly for tests).
139
- response.fromCache = request.iModelCoords.length - originalPositions.length;
140
- const remainingResponse = await IModelReadRpcInterface.getClientForRouting(this._iModel.routingContext.token).getGeoCoordinatesFromIModelCoordinates(this._iModel.getRpcProps(), remainingRequest);
141
- // put the responses into the cache, and fill in the output response for each
142
- for (let iResponse = 0; iResponse < remainingResponse.geoCoords.length; ++iResponse) {
143
- const thisPoint = remainingResponse.geoCoords[iResponse];
144
- // transfer the answer stored in remainingResponse to the correct position in the overall response.
145
- const responseIndex = originalPositions[iResponse];
146
- response.geoCoords[responseIndex] = thisPoint;
147
- // put the answer in the cache.
148
- const thisIModelCoord = remainingRequest.iModelCoords[iResponse];
149
- const thisCacheKey = JSON.stringify(thisIModelCoord);
150
- this._cache[thisCacheKey] = thisPoint;
134
+ return new Promise((resolve) => {
135
+ this._onCompleted.addOnce(() => resolve());
136
+ });
137
+ }
138
+ async convert(inputs) {
139
+ const fromCache = this.enqueue(inputs);
140
+ assert(fromCache >= 0);
141
+ assert(fromCache <= inputs.length);
142
+ if (fromCache === inputs.length)
143
+ return { points: this.getFromCache(inputs), fromCache };
144
+ await this.scheduleDispatch();
145
+ return { points: this.getFromCache(inputs), fromCache };
146
+ }
147
+ findCached(inputs) {
148
+ const result = [];
149
+ let missing;
150
+ for (const input of inputs) {
151
+ const key = this.toXYAndZ(input, this._scratchXYZ);
152
+ const output = this._cache.get(key);
153
+ result.push(output);
154
+ if (!output) {
155
+ if (!missing)
156
+ missing = [];
157
+ missing.push(input);
151
158
  }
152
- return response;
153
159
  }
160
+ return { result, missing };
154
161
  }
155
162
  }
156
163
  /** The GeoConverter class communicates with the backend to convert longitude/latitude coordinates to iModel coordinates and vice-versa
@@ -158,23 +165,42 @@ class IMCtoGCResultCache {
158
165
  */
159
166
  export class GeoConverter {
160
167
  constructor(iModel, datumOrGCRS) {
161
- if (typeof (datumOrGCRS) === "object")
162
- this._datumOrGCRS = JSON.stringify(datumOrGCRS);
163
- else
164
- this._datumOrGCRS = datumOrGCRS;
165
- this._gCtoIMCResultCache = new GCtoIMCResultCache(iModel, this._datumOrGCRS);
166
- this._iMCtoGCResultCache = new IMCtoGCResultCache(iModel, this._datumOrGCRS);
168
+ const datum = typeof datumOrGCRS === "object" ? JSON.stringify(datumOrGCRS) : datumOrGCRS;
169
+ this._geoToIModel = new CoordinateConverter({
170
+ iModel,
171
+ requestPoints: async (geoCoords) => {
172
+ const request = { source: datum, geoCoords };
173
+ const rpc = IModelReadRpcInterface.getClientForRouting(iModel.routingContext.token);
174
+ const response = await rpc.getIModelCoordinatesFromGeoCoordinates(iModel.getRpcProps(), request);
175
+ return response.iModelCoords;
176
+ },
177
+ });
178
+ this._iModelToGeo = new CoordinateConverter({
179
+ iModel,
180
+ requestPoints: async (iModelCoords) => {
181
+ const request = { target: datum, iModelCoords };
182
+ const rpc = IModelReadRpcInterface.getClientForRouting(iModel.routingContext.token);
183
+ const response = await rpc.getGeoCoordinatesFromIModelCoordinates(iModel.getRpcProps(), request);
184
+ return response.geoCoords;
185
+ },
186
+ });
167
187
  }
168
188
  async getIModelCoordinatesFromGeoCoordinates(geoPoints) {
169
- const requestProps = { source: this._datumOrGCRS, geoCoords: geoPoints };
170
- return this._gCtoIMCResultCache.findInCacheOrRequest(requestProps);
171
- }
172
- getCachedIModelCoordinatesFromGeoCoordinates(geoPoints) {
173
- return this._gCtoIMCResultCache.findInCache(geoPoints);
189
+ const result = await this._geoToIModel.convert(geoPoints);
190
+ return {
191
+ iModelCoords: result.points,
192
+ fromCache: result.fromCache,
193
+ };
174
194
  }
175
195
  async getGeoCoordinatesFromIModelCoordinates(iModelPoints) {
176
- const requestProps = { target: this._datumOrGCRS, iModelCoords: iModelPoints };
177
- return this._iMCtoGCResultCache.findInCacheOrRequest(requestProps);
196
+ const result = await this._iModelToGeo.convert(iModelPoints);
197
+ return {
198
+ geoCoords: result.points,
199
+ fromCache: result.fromCache,
200
+ };
201
+ }
202
+ getCachedIModelCoordinatesFromGeoCoordinates(geoPoints) {
203
+ return this._geoToIModel.findCached(geoPoints);
178
204
  }
179
205
  }
180
206
  /** The Geographic Services available for an [[IModelConnection]].