@itwin/core-backend 5.15.0-dev.5 → 5.15.0-dev.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/Element.d.ts +29 -2
- package/lib/cjs/Element.d.ts.map +1 -1
- package/lib/cjs/Element.js +38 -2
- package/lib/cjs/Element.js.map +1 -1
- package/lib/cjs/GeographicCRSServices.d.ts +50 -2
- package/lib/cjs/GeographicCRSServices.d.ts.map +1 -1
- package/lib/cjs/GeographicCRSServices.js +11 -1
- package/lib/cjs/GeographicCRSServices.js.map +1 -1
- package/lib/esm/Element.d.ts +29 -2
- package/lib/esm/Element.d.ts.map +1 -1
- package/lib/esm/Element.js +41 -5
- package/lib/esm/Element.js.map +1 -1
- package/lib/esm/GeographicCRSServices.d.ts +50 -2
- package/lib/esm/GeographicCRSServices.d.ts.map +1 -1
- package/lib/esm/GeographicCRSServices.js +10 -1
- package/lib/esm/GeographicCRSServices.js.map +1 -1
- package/lib/esm/test/element/ElementSubModelInsert.test.d.ts +2 -0
- package/lib/esm/test/element/ElementSubModelInsert.test.d.ts.map +1 -0
- package/lib/esm/test/element/ElementSubModelInsert.test.js +183 -0
- package/lib/esm/test/element/ElementSubModelInsert.test.js.map +1 -0
- package/lib/esm/test/imodel/IModelGeolocation.test.js +3 -3
- package/lib/esm/test/imodel/IModelGeolocation.test.js.map +1 -1
- package/package.json +15 -15
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module iModels
|
|
3
3
|
*/
|
|
4
|
-
import { Range2dProps } from "@itwin/core-geometry";
|
|
4
|
+
import { Range2dProps, XAndY } from "@itwin/core-geometry";
|
|
5
5
|
/** Describes a coordinate reference system produced by [[getAvailableCoordinateReferenceSystems]].
|
|
6
6
|
* @beta
|
|
7
7
|
*/
|
|
@@ -45,13 +45,61 @@ export interface GetAvailableCoordinateReferenceSystemsArgs {
|
|
|
45
45
|
*/
|
|
46
46
|
unit?: string;
|
|
47
47
|
}
|
|
48
|
+
/** Describes a vertical coordinate reference system produced by [[getAvailableVerticalCoordinateReferenceSystems]].
|
|
49
|
+
* @beta
|
|
50
|
+
*/
|
|
51
|
+
export interface AvailableVerticalCoordinateReferenceSystemProps {
|
|
52
|
+
/** Name in the Bentley Vertical Datum dictionary. */
|
|
53
|
+
crsName: string;
|
|
54
|
+
/** Backward-compatible approximation used by older readers. */
|
|
55
|
+
id: "GEOID" | "ELLIPSOID" | "NGVD29" | "NAVD88" | "LOCAL_ELLIPSOID";
|
|
56
|
+
/** EPSG code identifying the vertical coordinate reference system, when one is defined. */
|
|
57
|
+
epsg?: number;
|
|
58
|
+
/** Description of the vertical coordinate reference system. */
|
|
59
|
+
description: string;
|
|
60
|
+
/** Whether the vertical coordinate reference system is deprecated. */
|
|
61
|
+
deprecated: boolean;
|
|
62
|
+
/** The vertical coordinate reference system type. */
|
|
63
|
+
type: string;
|
|
64
|
+
/** The name of the linear unit used by the vertical coordinate reference system.
|
|
65
|
+
* The value uses the canonical casing returned by [[getAvailableCRSUnits]].
|
|
66
|
+
*/
|
|
67
|
+
unit: string;
|
|
68
|
+
/** The geographic extent where the vertical coordinate reference system applies. */
|
|
69
|
+
extent: Range2dProps;
|
|
70
|
+
}
|
|
71
|
+
/** Arguments supplied to [[getAvailableVerticalCoordinateReferenceSystems]].
|
|
72
|
+
* @beta
|
|
73
|
+
*/
|
|
74
|
+
export interface GetAvailableVerticalCoordinateReferenceSystemsArgs {
|
|
75
|
+
/** If provided, only return vertical coordinate reference systems applicable at this geographic point in degrees.
|
|
76
|
+
* The x coordinate is longitude and the y coordinate is latitude.
|
|
77
|
+
*/
|
|
78
|
+
point?: XAndY;
|
|
79
|
+
/** If provided, only return vertical coordinate reference systems whose extent contains this extent. */
|
|
80
|
+
extent?: Range2dProps;
|
|
81
|
+
/** If true, include vertical coordinate reference systems whose extent intersects, but does not contain, [[extent]].
|
|
82
|
+
* @default false
|
|
83
|
+
*/
|
|
84
|
+
includeIntersecting?: boolean;
|
|
85
|
+
/** If provided, filter vertical coordinate reference systems by unit name.
|
|
86
|
+
* Matching is case-insensitive. Use [[getAvailableCRSUnits]] to get a list of canonical unit names.
|
|
87
|
+
*/
|
|
88
|
+
unit?: string;
|
|
89
|
+
}
|
|
48
90
|
/** Get a list of Geographic Coordinate Reference Systems.
|
|
49
91
|
* @param options Specifies the parameters to filter the returned list.
|
|
50
92
|
* @returns The list of Geographic Coordinate Reference Systems, according to the supplied parameters.
|
|
51
93
|
* @beta
|
|
52
94
|
*/
|
|
53
95
|
export declare function getAvailableCoordinateReferenceSystems(args: GetAvailableCoordinateReferenceSystemsArgs): Promise<AvailableCoordinateReferenceSystemProps[]>;
|
|
54
|
-
/** Get a list of
|
|
96
|
+
/** Get a list of Vertical Coordinate Reference Systems.
|
|
97
|
+
* @param args Specifies the parameters used to filter the returned list. Point and extent filters are mutually exclusive.
|
|
98
|
+
* @returns The list of Vertical Coordinate Reference Systems according to the supplied parameters.
|
|
99
|
+
* @beta
|
|
100
|
+
*/
|
|
101
|
+
export declare function getAvailableVerticalCoordinateReferenceSystems(args?: GetAvailableVerticalCoordinateReferenceSystemsArgs): AvailableVerticalCoordinateReferenceSystemProps[];
|
|
102
|
+
/** Get a list of units used by horizontal and vertical coordinate reference systems in iTwin.js.
|
|
55
103
|
* @returns An array of canonical unit names.
|
|
56
104
|
* @beta
|
|
57
105
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeographicCRSServices.d.ts","sourceRoot":"","sources":["../../src/GeographicCRSServices.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"GeographicCRSServices.d.ts","sourceRoot":"","sources":["../../src/GeographicCRSServices.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAI3D;;GA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AAuC,EAAE,CAAC,CAOpD;AAED;;;;GAIG;AACH,wBAAgB,8CAA8C,CAC5D,IAAI,GAAE,kDAAuD,GAC5D,+CAA+C,EAAE,CAGnD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAG/C"}
|
|
@@ -16,7 +16,16 @@ export async function getAvailableCoordinateReferenceSystems(args) {
|
|
|
16
16
|
GeoCoordConfig.loadDefaultDatabases();
|
|
17
17
|
return IModelNative.platform.GeoServices.getListOfCRS(args.extent, args.includeWorld, args.unit);
|
|
18
18
|
}
|
|
19
|
-
/** Get a list of
|
|
19
|
+
/** Get a list of Vertical Coordinate Reference Systems.
|
|
20
|
+
* @param args Specifies the parameters used to filter the returned list. Point and extent filters are mutually exclusive.
|
|
21
|
+
* @returns The list of Vertical Coordinate Reference Systems according to the supplied parameters.
|
|
22
|
+
* @beta
|
|
23
|
+
*/
|
|
24
|
+
export function getAvailableVerticalCoordinateReferenceSystems(args = {}) {
|
|
25
|
+
GeoCoordConfig.loadDefaultDatabases();
|
|
26
|
+
return IModelNative.platform.GeoServices.getListOfVerticalCRS(args);
|
|
27
|
+
}
|
|
28
|
+
/** Get a list of units used by horizontal and vertical coordinate reference systems in iTwin.js.
|
|
20
29
|
* @returns An array of canonical unit names.
|
|
21
30
|
* @beta
|
|
22
31
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeographicCRSServices.js","sourceRoot":"","sources":["../../src/GeographicCRSServices.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"GeographicCRSServices.js","sourceRoot":"","sources":["../../src/GeographicCRSServices.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AA2FlD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,sCAAsC,CAC1D,IAAgD;IAEhD,cAAc,CAAC,oBAAoB,EAAE,CAAC;IACtC,OAAO,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC,YAAY,CACnD,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,IAAI,CACV,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,8CAA8C,CAC5D,OAA2D,EAAE;IAE7D,cAAc,CAAC,oBAAoB,EAAE,CAAC;IACtC,OAAO,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;AACtE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB;IAClC,cAAc,CAAC,oBAAoB,EAAE,CAAC;IACtC,OAAO,YAAY,CAAC,QAAQ,CAAC,WAAW,CAAC,qBAAqB,EAAE,CAAC;AACnE,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n * See LICENSE.md in the project root for license terms and full copyright notice.\r\n *--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module iModels\r\n */\r\n\r\nimport { Range2dProps, XAndY } from \"@itwin/core-geometry\";\r\nimport { IModelNative } from \"./internal/NativePlatform\";\r\nimport { GeoCoordConfig } from \"./GeoCoordConfig\";\r\n\r\n/** Describes a coordinate reference system produced by [[getAvailableCoordinateReferenceSystems]].\r\n * @beta\r\n */\r\nexport interface AvailableCoordinateReferenceSystemProps {\r\n /** The name of the coordinate reference system. It can be presented to the user in the UI as an identifier for the coordinate reference system. */\r\n name: string;\r\n /** The description of the coordinate reference system. It can be presented to the user in the UI as extra information for the coordinate reference system. */\r\n description: string;\r\n /** Indicate if the coordinate reference system is deprecated. A coordinate reference system is deprecated if it is no longer recommended for use.\r\n * A deprecated coordinate reference system can usually be substituted by a more accurate one. It is possible that an existing project uses a deprecated coordinate reference system.\r\n * However, for new projects, it is recommended to use a non-deprecated coordinate reference system.\r\n */\r\n deprecated: boolean;\r\n /** Extent of the coordinate reference system. This is the area where the coordinate reference system can be used.\r\n * Outside of this area, the coordinate reference system may not be accurate. The extent is defined by a range of longitude and latitude values.\r\n * Minimum longitude and latitude correspond to crsExtent.low.x and crsExtent.low.y, respectively.\r\n * Maximum longitude and latitude correspond to crsExtent.high.x and crsExtent.high.y, respectively.\r\n */\r\n crsExtent: Range2dProps;\r\n /** The name of the linear unit used by the coordinate reference system.\r\n * When returned by [[getAvailableCoordinateReferenceSystems]], the value uses the canonical casing returned by [[getAvailableCRSUnits]].\r\n */\r\n unit?: string;\r\n}\r\n\r\n/** Arguments supplied to [[getAvailableCoordinateReferenceSystems]].\r\n * @beta\r\n */\r\nexport interface GetAvailableCoordinateReferenceSystemsArgs {\r\n /** If provided, only return coordinate reference systems that contain the given extent. Minimum longitude and latitude correspond to extent.low.x and extent.low.y, respectively.\r\n * Maximum longitude and latitude correspond to extent.high.x and extent.high.y, respectively.\r\n */\r\n extent?: Range2dProps;\r\n /** If true, returns additional coordinate reference systems with extents spanning the entire Earth's surface.\r\n * @default false\r\n */\r\n includeWorld?: boolean;\r\n /**\r\n * If provided, filter coordinate reference systems by unit name.\r\n * Matching is case-insensitive.\r\n * Use [[getAvailableCRSUnits]] to get a list of canonical unit names.\r\n */\r\n unit?: string;\r\n}\r\n\r\n/** Describes a vertical coordinate reference system produced by [[getAvailableVerticalCoordinateReferenceSystems]].\r\n * @beta\r\n */\r\nexport interface AvailableVerticalCoordinateReferenceSystemProps {\r\n /** Name in the Bentley Vertical Datum dictionary. */\r\n crsName: string;\r\n /** Backward-compatible approximation used by older readers. */\r\n id: \"GEOID\" | \"ELLIPSOID\" | \"NGVD29\" | \"NAVD88\" | \"LOCAL_ELLIPSOID\";\r\n /** EPSG code identifying the vertical coordinate reference system, when one is defined. */\r\n epsg?: number;\r\n /** Description of the vertical coordinate reference system. */\r\n description: string;\r\n /** Whether the vertical coordinate reference system is deprecated. */\r\n deprecated: boolean;\r\n /** The vertical coordinate reference system type. */\r\n type: string;\r\n /** The name of the linear unit used by the vertical coordinate reference system.\r\n * The value uses the canonical casing returned by [[getAvailableCRSUnits]].\r\n */\r\n unit: string;\r\n /** The geographic extent where the vertical coordinate reference system applies. */\r\n extent: Range2dProps;\r\n}\r\n\r\n/** Arguments supplied to [[getAvailableVerticalCoordinateReferenceSystems]].\r\n * @beta\r\n */\r\nexport interface GetAvailableVerticalCoordinateReferenceSystemsArgs {\r\n /** If provided, only return vertical coordinate reference systems applicable at this geographic point in degrees.\r\n * The x coordinate is longitude and the y coordinate is latitude.\r\n */\r\n point?: XAndY;\r\n /** If provided, only return vertical coordinate reference systems whose extent contains this extent. */\r\n extent?: Range2dProps;\r\n /** If true, include vertical coordinate reference systems whose extent intersects, but does not contain, [[extent]].\r\n * @default false\r\n */\r\n includeIntersecting?: boolean;\r\n /** If provided, filter vertical coordinate reference systems by unit name.\r\n * Matching is case-insensitive. Use [[getAvailableCRSUnits]] to get a list of canonical unit names.\r\n */\r\n unit?: string;\r\n}\r\n\r\n/** Get a list of Geographic Coordinate Reference Systems.\r\n * @param options Specifies the parameters to filter the returned list.\r\n * @returns The list of Geographic Coordinate Reference Systems, according to the supplied parameters.\r\n * @beta\r\n */\r\nexport async function getAvailableCoordinateReferenceSystems(\r\n args: GetAvailableCoordinateReferenceSystemsArgs\r\n): Promise<AvailableCoordinateReferenceSystemProps[]> {\r\n GeoCoordConfig.loadDefaultDatabases();\r\n return IModelNative.platform.GeoServices.getListOfCRS(\r\n args.extent,\r\n args.includeWorld,\r\n args.unit\r\n );\r\n}\r\n\r\n/** Get a list of Vertical Coordinate Reference Systems.\r\n * @param args Specifies the parameters used to filter the returned list. Point and extent filters are mutually exclusive.\r\n * @returns The list of Vertical Coordinate Reference Systems according to the supplied parameters.\r\n * @beta\r\n */\r\nexport function getAvailableVerticalCoordinateReferenceSystems(\r\n args: GetAvailableVerticalCoordinateReferenceSystemsArgs = {}\r\n): AvailableVerticalCoordinateReferenceSystemProps[] {\r\n GeoCoordConfig.loadDefaultDatabases();\r\n return IModelNative.platform.GeoServices.getListOfVerticalCRS(args);\r\n}\r\n\r\n/** Get a list of units used by horizontal and vertical coordinate reference systems in iTwin.js.\r\n * @returns An array of canonical unit names.\r\n * @beta\r\n */\r\nexport function getAvailableCRSUnits(): string[] {\r\n GeoCoordConfig.loadDefaultDatabases();\r\n return IModelNative.platform.GeoServices.getAvailableUnitNames();\r\n}\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElementSubModelInsert.test.d.ts","sourceRoot":"","sources":["../../../../src/test/element/ElementSubModelInsert.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the repository root for full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { expect } from "chai";
|
|
6
|
+
import { spy as sinonSpy } from "sinon";
|
|
7
|
+
import { Id64, IModelStatus } from "@itwin/core-bentley";
|
|
8
|
+
import { Code, IModel, IModelError } from "@itwin/core-common";
|
|
9
|
+
import { ClassRegistry } from "../../ClassRegistry";
|
|
10
|
+
import { withEditTxn } from "../../EditTxn";
|
|
11
|
+
import { Document, Drawing, SectionDrawing, Sheet, TemplateRecipe2d } from "../../Element";
|
|
12
|
+
import { GenericSchema } from "../../domains/GenericSchema";
|
|
13
|
+
import { SnapshotDb } from "../../IModelDb";
|
|
14
|
+
import { DefinitionModel, DocumentListModel, DrawingModel, SectionDrawingModel, SheetModel } from "../../Model";
|
|
15
|
+
import { Schema, Schemas } from "../../Schema";
|
|
16
|
+
import { IModelTestUtils } from "../IModelTestUtils";
|
|
17
|
+
class TestSubModelSchema extends Schema {
|
|
18
|
+
static get schemaName() { return "TestSubModel"; }
|
|
19
|
+
}
|
|
20
|
+
/** A Sheet subclass that overrides the hook and defers to the inherited validation via `super`. */
|
|
21
|
+
class TestSheetSpy extends Sheet {
|
|
22
|
+
static get className() { return "TestSheetSpy"; }
|
|
23
|
+
static onSubModelInsert(arg) {
|
|
24
|
+
super.onSubModelInsert(arg);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** A Sheet subclass that widens the inherited rule to also permit a DrawingModel. */
|
|
28
|
+
class TestSheetWidened extends Sheet {
|
|
29
|
+
static get className() { return "TestSheetWidened"; }
|
|
30
|
+
static get allowedSubModelClasses() { return [SheetModel, DrawingModel]; }
|
|
31
|
+
}
|
|
32
|
+
/** A Sheet subclass that replaces the hook without calling `super`, opting out of validation. */
|
|
33
|
+
class TestSheetUnvalidated extends Sheet {
|
|
34
|
+
static get className() { return "TestSheetUnvalidated"; }
|
|
35
|
+
static onSubModelInsert(_arg) { }
|
|
36
|
+
}
|
|
37
|
+
/** A domain ISubModeledElement unrelated to Sheet/Drawing that opts in by overriding only the getter. */
|
|
38
|
+
class TestRestrictedDocument extends Document {
|
|
39
|
+
static get className() { return "TestRestrictedDocument"; }
|
|
40
|
+
static get allowedSubModelClasses() { return [DrawingModel]; }
|
|
41
|
+
}
|
|
42
|
+
const testSchemaXml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
43
|
+
<ECSchema schemaName="TestSubModel" alias="tsm" version="01.00.00" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2">
|
|
44
|
+
<ECSchemaReference name="BisCore" version="01.00.04" alias="bis"/>
|
|
45
|
+
<ECCustomAttributes>
|
|
46
|
+
<SchemaHasBehavior xmlns="BisCore.01.00.00"/>
|
|
47
|
+
</ECCustomAttributes>
|
|
48
|
+
<ECEntityClass typeName="TestSheetModel">
|
|
49
|
+
<BaseClass>bis:SheetModel</BaseClass>
|
|
50
|
+
</ECEntityClass>
|
|
51
|
+
<ECEntityClass typeName="TestSheetGenerated">
|
|
52
|
+
<BaseClass>bis:Sheet</BaseClass>
|
|
53
|
+
</ECEntityClass>
|
|
54
|
+
<ECEntityClass typeName="TestSheetSpy">
|
|
55
|
+
<BaseClass>bis:Sheet</BaseClass>
|
|
56
|
+
</ECEntityClass>
|
|
57
|
+
<ECEntityClass typeName="TestSheetWidened">
|
|
58
|
+
<BaseClass>bis:Sheet</BaseClass>
|
|
59
|
+
</ECEntityClass>
|
|
60
|
+
<ECEntityClass typeName="TestSheetUnvalidated">
|
|
61
|
+
<BaseClass>bis:Sheet</BaseClass>
|
|
62
|
+
</ECEntityClass>
|
|
63
|
+
<ECEntityClass typeName="TestHostDocument">
|
|
64
|
+
<BaseClass>bis:Document</BaseClass>
|
|
65
|
+
<BaseClass>bis:ISubModeledElement</BaseClass>
|
|
66
|
+
</ECEntityClass>
|
|
67
|
+
<ECEntityClass typeName="TestRestrictedDocument">
|
|
68
|
+
<BaseClass>bis:Document</BaseClass>
|
|
69
|
+
<BaseClass>bis:ISubModeledElement</BaseClass>
|
|
70
|
+
</ECEntityClass>
|
|
71
|
+
</ECSchema>`;
|
|
72
|
+
describe("Sub-model insert validation", () => {
|
|
73
|
+
let imodel;
|
|
74
|
+
let documentListModelId;
|
|
75
|
+
before(async () => {
|
|
76
|
+
GenericSchema.registerSchema();
|
|
77
|
+
Schemas.registerSchema(TestSubModelSchema);
|
|
78
|
+
ClassRegistry.register(TestSheetSpy, TestSubModelSchema);
|
|
79
|
+
ClassRegistry.register(TestSheetWidened, TestSubModelSchema);
|
|
80
|
+
ClassRegistry.register(TestSheetUnvalidated, TestSubModelSchema);
|
|
81
|
+
ClassRegistry.register(TestRestrictedDocument, TestSubModelSchema);
|
|
82
|
+
const iModelPath = IModelTestUtils.prepareOutputFile("SubModelInsert", "SubModelInsert.bim");
|
|
83
|
+
imodel = SnapshotDb.createEmpty(iModelPath, { rootSubject: { name: "SubModelInsertTest" } });
|
|
84
|
+
await imodel.importSchemaStrings([testSchemaXml]);
|
|
85
|
+
documentListModelId = withEditTxn(imodel, (txn) => DocumentListModel.insert(txn, SnapshotDb.rootSubjectId, "DocumentList"));
|
|
86
|
+
});
|
|
87
|
+
after(() => {
|
|
88
|
+
imodel.close();
|
|
89
|
+
Schemas.unregisterSchema(TestSubModelSchema.schemaName);
|
|
90
|
+
});
|
|
91
|
+
function insertHost(classFullName, modelId = documentListModelId) {
|
|
92
|
+
const id = withEditTxn(imodel, (txn) => txn.insertElement({ classFullName, model: modelId, code: Code.createEmpty() }));
|
|
93
|
+
expect(Id64.isValidId64(id)).to.be.true;
|
|
94
|
+
return id;
|
|
95
|
+
}
|
|
96
|
+
function insertSubModel(modelClassFullName, modeledElementId) {
|
|
97
|
+
return withEditTxn(imodel, (txn) => txn.insertModel({ classFullName: modelClassFullName, modeledElement: { id: modeledElementId } }));
|
|
98
|
+
}
|
|
99
|
+
function expectAccepted(hostClassFullName, modelClassFullName, hostModelId) {
|
|
100
|
+
const hostId = insertHost(hostClassFullName, hostModelId);
|
|
101
|
+
const modelId = insertSubModel(modelClassFullName, hostId);
|
|
102
|
+
expect(modelId).to.equal(hostId);
|
|
103
|
+
expect(imodel.models.getModel(modelId).classFullName).to.equal(modelClassFullName);
|
|
104
|
+
}
|
|
105
|
+
function expectRejected(hostClassFullName, modelClassFullName, hostModelId) {
|
|
106
|
+
const hostId = insertHost(hostClassFullName, hostModelId);
|
|
107
|
+
let error;
|
|
108
|
+
try {
|
|
109
|
+
insertSubModel(modelClassFullName, hostId);
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
error = err;
|
|
113
|
+
}
|
|
114
|
+
expect(error).to.be.instanceOf(IModelError);
|
|
115
|
+
expect(error.errorNumber).to.equal(IModelStatus.WrongModel);
|
|
116
|
+
expect(error.message).to.contain("must be sub-modeled by");
|
|
117
|
+
expect(imodel.models.tryGetModel(hostId)).to.be.undefined;
|
|
118
|
+
}
|
|
119
|
+
describe("accepts", () => {
|
|
120
|
+
it("Sheet + SheetModel", () => expectAccepted(Sheet.classFullName, SheetModel.classFullName));
|
|
121
|
+
it("Drawing + DrawingModel", () => expectAccepted(Drawing.classFullName, DrawingModel.classFullName));
|
|
122
|
+
it("SectionDrawing + DrawingModel", () => expectAccepted(SectionDrawing.classFullName, DrawingModel.classFullName));
|
|
123
|
+
it("SectionDrawing + SectionDrawingModel", () => expectAccepted(SectionDrawing.classFullName, SectionDrawingModel.classFullName));
|
|
124
|
+
it("SectionDrawing + Generic:GraphicalModel3d", () => expectAccepted(SectionDrawing.classFullName, "Generic:GraphicalModel3d"));
|
|
125
|
+
it("TemplateRecipe2d + DrawingModel", () => expectAccepted(TemplateRecipe2d.classFullName, DrawingModel.classFullName, IModel.dictionaryId));
|
|
126
|
+
it("Sheet + SheetModel subclass without a JS class", () => expectAccepted(Sheet.classFullName, "TestSubModel:TestSheetModel"));
|
|
127
|
+
it("no allowedSubModelClasses → any model accepted", () => {
|
|
128
|
+
expectAccepted("TestSubModel:TestHostDocument", SheetModel.classFullName);
|
|
129
|
+
expectAccepted("TestSubModel:TestHostDocument", DrawingModel.classFullName);
|
|
130
|
+
});
|
|
131
|
+
it("Sheet subclass that widens allowedSubModelClasses + DrawingModel", () => expectAccepted(TestSheetWidened.classFullName, DrawingModel.classFullName));
|
|
132
|
+
it("Sheet subclass that overrides onSubModelInsert without super + DrawingModel", () => expectAccepted(TestSheetUnvalidated.classFullName, DrawingModel.classFullName));
|
|
133
|
+
it("Document subclass with allowedSubModelClasses + DrawingModel", () => expectAccepted(TestRestrictedDocument.classFullName, DrawingModel.classFullName));
|
|
134
|
+
});
|
|
135
|
+
describe("rejects with IModelStatus.WrongModel", () => {
|
|
136
|
+
it("Sheet + DrawingModel", () => expectRejected(Sheet.classFullName, DrawingModel.classFullName));
|
|
137
|
+
it("Drawing + SheetModel", () => expectRejected(Drawing.classFullName, SheetModel.classFullName));
|
|
138
|
+
it("SectionDrawing + SheetModel", () => expectRejected(SectionDrawing.classFullName, SheetModel.classFullName));
|
|
139
|
+
it("TemplateRecipe2d + SheetModel", () => expectRejected(TemplateRecipe2d.classFullName, SheetModel.classFullName, IModel.dictionaryId));
|
|
140
|
+
it("Sheet subclass without a JS class + DrawingModel", () => expectRejected("TestSubModel:TestSheetGenerated", DrawingModel.classFullName));
|
|
141
|
+
it("Document subclass with allowedSubModelClasses + SheetModel", () => expectRejected(TestRestrictedDocument.classFullName, SheetModel.classFullName));
|
|
142
|
+
});
|
|
143
|
+
it("invokes an overriding subclass hook that defers to the inherited validation", () => {
|
|
144
|
+
const spy = sinonSpy(TestSheetSpy, "onSubModelInsert");
|
|
145
|
+
try {
|
|
146
|
+
expectAccepted(TestSheetSpy.classFullName, SheetModel.classFullName);
|
|
147
|
+
expect(spy.calledOnce).to.be.true;
|
|
148
|
+
expect(spy.getCall(0).args[0].subModelProps.classFullName).to.equal(SheetModel.classFullName);
|
|
149
|
+
expectRejected(TestSheetSpy.classFullName, DrawingModel.classFullName);
|
|
150
|
+
expect(spy.calledTwice).to.be.true;
|
|
151
|
+
expect(spy.getCall(1).threw()).to.be.true;
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
spy.restore();
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
describe("missing required behavior", () => {
|
|
158
|
+
it("rejects sub-model insertion", () => {
|
|
159
|
+
const hostId = insertHost(TestRestrictedDocument.classFullName);
|
|
160
|
+
Schemas.unregisterSchema(TestSubModelSchema.schemaName);
|
|
161
|
+
try {
|
|
162
|
+
let error;
|
|
163
|
+
try {
|
|
164
|
+
insertSubModel(DefinitionModel.classFullName, hostId);
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
error = err;
|
|
168
|
+
}
|
|
169
|
+
expect(error).to.be.instanceOf(IModelError);
|
|
170
|
+
expect(error.errorNumber).to.equal(IModelStatus.WrongHandler);
|
|
171
|
+
expect(imodel.models.tryGetModel(hostId)).to.be.undefined;
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
Schemas.registerSchema(TestSubModelSchema);
|
|
175
|
+
ClassRegistry.register(TestSheetSpy, TestSubModelSchema);
|
|
176
|
+
ClassRegistry.register(TestSheetWidened, TestSubModelSchema);
|
|
177
|
+
ClassRegistry.register(TestSheetUnvalidated, TestSubModelSchema);
|
|
178
|
+
ClassRegistry.register(TestRestrictedDocument, TestSubModelSchema);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
//# sourceMappingURL=ElementSubModelInsert.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElementSubModelInsert.test.js","sourceRoot":"","sources":["../../../../src/test/element/ElementSubModelInsert.test.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,GAAG,IAAI,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,EAAE,IAAI,EAAc,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAsB,cAAc,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE/G,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,YAAY,EAAS,mBAAmB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACvH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAA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,MAAM,CAAC,CAAC;gBACxD,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,KAAK,GAAG,GAAG,CAAC;gBACd,CAAC;gBAED,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;gBAC5C,MAAM,CAAE,KAAqB,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;gBAC/E,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC;YAC5D,CAAC;oBAAS,CAAC;gBACT,OAAO,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;gBAC3C,aAAa,CAAC,QAAQ,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;gBACzD,aAAa,CAAC,QAAQ,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAAC;gBAC7D,aAAa,CAAC,QAAQ,CAAC,oBAAoB,EAAE,kBAAkB,CAAC,CAAC;gBACjE,aAAa,CAAC,QAAQ,CAAC,sBAAsB,EAAE,kBAAkB,CAAC,CAAC;YACrE,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the repository root for full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { expect } from \"chai\";\r\nimport { spy as sinonSpy } from \"sinon\";\r\nimport { Id64, Id64String, IModelStatus } from \"@itwin/core-bentley\";\r\nimport { Code, IModel, IModelError } from \"@itwin/core-common\";\r\nimport { ClassRegistry } from \"../../ClassRegistry\";\r\nimport { withEditTxn } from \"../../EditTxn\";\r\nimport { Document, Drawing, OnSubModelPropsArg, SectionDrawing, Sheet, TemplateRecipe2d } from \"../../Element\";\r\nimport { EntityClassType } from \"../../Entity\";\r\nimport { GenericSchema } from \"../../domains/GenericSchema\";\r\nimport { SnapshotDb } from \"../../IModelDb\";\r\nimport { DefinitionModel, DocumentListModel, DrawingModel, Model, SectionDrawingModel, SheetModel } from \"../../Model\";\r\nimport { Schema, Schemas } from \"../../Schema\";\r\nimport { IModelTestUtils } from \"../IModelTestUtils\";\r\n\r\nclass TestSubModelSchema extends Schema {\r\n public static override get schemaName(): string { return \"TestSubModel\"; }\r\n}\r\n\r\n/** A Sheet subclass that overrides the hook and defers to the inherited validation via `super`. */\r\nclass TestSheetSpy extends Sheet {\r\n public static override get className(): string { return \"TestSheetSpy\"; }\r\n public static override onSubModelInsert(arg: OnSubModelPropsArg): void {\r\n super.onSubModelInsert(arg);\r\n }\r\n}\r\n\r\n/** A Sheet subclass that widens the inherited rule to also permit a DrawingModel. */\r\nclass TestSheetWidened extends Sheet {\r\n public static override get className(): string { return \"TestSheetWidened\"; }\r\n protected static override get allowedSubModelClasses(): Array<EntityClassType<Model>> { return [SheetModel, DrawingModel]; }\r\n}\r\n\r\n/** A Sheet subclass that replaces the hook without calling `super`, opting out of validation. */\r\nclass TestSheetUnvalidated extends Sheet {\r\n public static override get className(): string { return \"TestSheetUnvalidated\"; }\r\n public static override onSubModelInsert(_arg: OnSubModelPropsArg): void { }\r\n}\r\n\r\n/** A domain ISubModeledElement unrelated to Sheet/Drawing that opts in by overriding only the getter. */\r\nclass TestRestrictedDocument extends Document {\r\n public static override get className(): string { return \"TestRestrictedDocument\"; }\r\n protected static override get allowedSubModelClasses(): Array<EntityClassType<Model>> { return [DrawingModel]; }\r\n}\r\n\r\nconst testSchemaXml = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<ECSchema schemaName=\"TestSubModel\" alias=\"tsm\" version=\"01.00.00\" xmlns=\"http://www.bentley.com/schemas/Bentley.ECXML.3.2\">\r\n <ECSchemaReference name=\"BisCore\" version=\"01.00.04\" alias=\"bis\"/>\r\n <ECCustomAttributes>\r\n <SchemaHasBehavior xmlns=\"BisCore.01.00.00\"/>\r\n </ECCustomAttributes>\r\n <ECEntityClass typeName=\"TestSheetModel\">\r\n <BaseClass>bis:SheetModel</BaseClass>\r\n </ECEntityClass>\r\n <ECEntityClass typeName=\"TestSheetGenerated\">\r\n <BaseClass>bis:Sheet</BaseClass>\r\n </ECEntityClass>\r\n <ECEntityClass typeName=\"TestSheetSpy\">\r\n <BaseClass>bis:Sheet</BaseClass>\r\n </ECEntityClass>\r\n <ECEntityClass typeName=\"TestSheetWidened\">\r\n <BaseClass>bis:Sheet</BaseClass>\r\n </ECEntityClass>\r\n <ECEntityClass typeName=\"TestSheetUnvalidated\">\r\n <BaseClass>bis:Sheet</BaseClass>\r\n </ECEntityClass>\r\n <ECEntityClass typeName=\"TestHostDocument\">\r\n <BaseClass>bis:Document</BaseClass>\r\n <BaseClass>bis:ISubModeledElement</BaseClass>\r\n </ECEntityClass>\r\n <ECEntityClass typeName=\"TestRestrictedDocument\">\r\n <BaseClass>bis:Document</BaseClass>\r\n <BaseClass>bis:ISubModeledElement</BaseClass>\r\n </ECEntityClass>\r\n</ECSchema>`;\r\n\r\ndescribe(\"Sub-model insert validation\", () => {\r\n let imodel: SnapshotDb;\r\n let documentListModelId: Id64String;\r\n\r\n before(async () => {\r\n GenericSchema.registerSchema();\r\n Schemas.registerSchema(TestSubModelSchema);\r\n ClassRegistry.register(TestSheetSpy, TestSubModelSchema);\r\n ClassRegistry.register(TestSheetWidened, TestSubModelSchema);\r\n ClassRegistry.register(TestSheetUnvalidated, TestSubModelSchema);\r\n ClassRegistry.register(TestRestrictedDocument, TestSubModelSchema);\r\n\r\n const iModelPath = IModelTestUtils.prepareOutputFile(\"SubModelInsert\", \"SubModelInsert.bim\");\r\n imodel = SnapshotDb.createEmpty(iModelPath, { rootSubject: { name: \"SubModelInsertTest\" } });\r\n await imodel.importSchemaStrings([testSchemaXml]);\r\n documentListModelId = withEditTxn(imodel, (txn) => DocumentListModel.insert(txn, SnapshotDb.rootSubjectId, \"DocumentList\"));\r\n });\r\n\r\n after(() => {\r\n imodel.close();\r\n Schemas.unregisterSchema(TestSubModelSchema.schemaName);\r\n });\r\n\r\n function insertHost(classFullName: string, modelId: Id64String = documentListModelId): Id64String {\r\n const id = withEditTxn(imodel, (txn) => txn.insertElement({ classFullName, model: modelId, code: Code.createEmpty() }));\r\n expect(Id64.isValidId64(id)).to.be.true;\r\n return id;\r\n }\r\n\r\n function insertSubModel(modelClassFullName: string, modeledElementId: Id64String): Id64String {\r\n return withEditTxn(imodel, (txn) => txn.insertModel({ classFullName: modelClassFullName, modeledElement: { id: modeledElementId } }));\r\n }\r\n\r\n function expectAccepted(hostClassFullName: string, modelClassFullName: string, hostModelId?: Id64String): void {\r\n const hostId = insertHost(hostClassFullName, hostModelId);\r\n const modelId = insertSubModel(modelClassFullName, hostId);\r\n expect(modelId).to.equal(hostId);\r\n expect(imodel.models.getModel(modelId).classFullName).to.equal(modelClassFullName);\r\n }\r\n\r\n function expectRejected(hostClassFullName: string, modelClassFullName: string, hostModelId?: Id64String): void {\r\n const hostId = insertHost(hostClassFullName, hostModelId);\r\n let error: unknown;\r\n try {\r\n insertSubModel(modelClassFullName, hostId);\r\n } catch (err) {\r\n error = err;\r\n }\r\n\r\n expect(error).to.be.instanceOf(IModelError);\r\n expect((error as IModelError).errorNumber).to.equal(IModelStatus.WrongModel);\r\n expect((error as IModelError).message).to.contain(\"must be sub-modeled by\");\r\n expect(imodel.models.tryGetModel(hostId)).to.be.undefined;\r\n }\r\n\r\n describe(\"accepts\", () => {\r\n it(\"Sheet + SheetModel\", () => expectAccepted(Sheet.classFullName, SheetModel.classFullName));\r\n it(\"Drawing + DrawingModel\", () => expectAccepted(Drawing.classFullName, DrawingModel.classFullName));\r\n it(\"SectionDrawing + DrawingModel\", () => expectAccepted(SectionDrawing.classFullName, DrawingModel.classFullName));\r\n it(\"SectionDrawing + SectionDrawingModel\", () => expectAccepted(SectionDrawing.classFullName, SectionDrawingModel.classFullName));\r\n it(\"SectionDrawing + Generic:GraphicalModel3d\", () => expectAccepted(SectionDrawing.classFullName, \"Generic:GraphicalModel3d\"));\r\n it(\"TemplateRecipe2d + DrawingModel\", () => expectAccepted(TemplateRecipe2d.classFullName, DrawingModel.classFullName, IModel.dictionaryId));\r\n it(\"Sheet + SheetModel subclass without a JS class\", () => expectAccepted(Sheet.classFullName, \"TestSubModel:TestSheetModel\"));\r\n it(\"no allowedSubModelClasses → any model accepted\", () => {\r\n expectAccepted(\"TestSubModel:TestHostDocument\", SheetModel.classFullName);\r\n expectAccepted(\"TestSubModel:TestHostDocument\", DrawingModel.classFullName);\r\n });\r\n it(\"Sheet subclass that widens allowedSubModelClasses + DrawingModel\", () => expectAccepted(TestSheetWidened.classFullName, DrawingModel.classFullName));\r\n it(\"Sheet subclass that overrides onSubModelInsert without super + DrawingModel\", () => expectAccepted(TestSheetUnvalidated.classFullName, DrawingModel.classFullName));\r\n it(\"Document subclass with allowedSubModelClasses + DrawingModel\", () => expectAccepted(TestRestrictedDocument.classFullName, DrawingModel.classFullName));\r\n });\r\n\r\n describe(\"rejects with IModelStatus.WrongModel\", () => {\r\n it(\"Sheet + DrawingModel\", () => expectRejected(Sheet.classFullName, DrawingModel.classFullName));\r\n it(\"Drawing + SheetModel\", () => expectRejected(Drawing.classFullName, SheetModel.classFullName));\r\n it(\"SectionDrawing + SheetModel\", () => expectRejected(SectionDrawing.classFullName, SheetModel.classFullName));\r\n it(\"TemplateRecipe2d + SheetModel\", () => expectRejected(TemplateRecipe2d.classFullName, SheetModel.classFullName, IModel.dictionaryId));\r\n it(\"Sheet subclass without a JS class + DrawingModel\", () => expectRejected(\"TestSubModel:TestSheetGenerated\", DrawingModel.classFullName));\r\n it(\"Document subclass with allowedSubModelClasses + SheetModel\", () => expectRejected(TestRestrictedDocument.classFullName, SheetModel.classFullName));\r\n });\r\n\r\n it(\"invokes an overriding subclass hook that defers to the inherited validation\", () => {\r\n const spy = sinonSpy(TestSheetSpy, \"onSubModelInsert\");\r\n try {\r\n expectAccepted(TestSheetSpy.classFullName, SheetModel.classFullName);\r\n expect(spy.calledOnce).to.be.true;\r\n expect(spy.getCall(0).args[0].subModelProps.classFullName).to.equal(SheetModel.classFullName);\r\n\r\n expectRejected(TestSheetSpy.classFullName, DrawingModel.classFullName);\r\n expect(spy.calledTwice).to.be.true;\r\n expect(spy.getCall(1).threw()).to.be.true;\r\n } finally {\r\n spy.restore();\r\n }\r\n });\r\n\r\n describe(\"missing required behavior\", () => {\r\n it(\"rejects sub-model insertion\", () => {\r\n const hostId = insertHost(TestRestrictedDocument.classFullName);\r\n Schemas.unregisterSchema(TestSubModelSchema.schemaName);\r\n\r\n try {\r\n let error: unknown;\r\n try {\r\n insertSubModel(DefinitionModel.classFullName, hostId);\r\n } catch (err) {\r\n error = err;\r\n }\r\n\r\n expect(error).to.be.instanceOf(IModelError);\r\n expect((error as IModelError).errorNumber).to.equal(IModelStatus.WrongHandler);\r\n expect(imodel.models.tryGetModel(hostId)).to.be.undefined;\r\n } finally {\r\n Schemas.registerSchema(TestSubModelSchema);\r\n ClassRegistry.register(TestSheetSpy, TestSubModelSchema);\r\n ClassRegistry.register(TestSheetWidened, TestSubModelSchema);\r\n ClassRegistry.register(TestSheetUnvalidated, TestSubModelSchema);\r\n ClassRegistry.register(TestRestrictedDocument, TestSubModelSchema);\r\n }\r\n });\r\n });\r\n});\r\n"]}
|
|
@@ -188,7 +188,7 @@ describe("iModel geolocation", () => {
|
|
|
188
188
|
const expectedPt1 = Point3d.fromJSON(outputCoord.p);
|
|
189
189
|
const outPt1 = Point3d.fromJSON(response1.geoCoords[0].p);
|
|
190
190
|
expect(Geometry.isSamePoint3dXY(expectedPt1, outPt1, 0.001)).to.be.true;
|
|
191
|
-
expect(Math.abs(expectedPt1.z - outPt1.z), fileName).to.be.lessThan(0.
|
|
191
|
+
expect(Math.abs(expectedPt1.z - outPt1.z), fileName).to.be.lessThan(0.001);
|
|
192
192
|
// No point testing reversal when Out of useful range since reversibility is doubtful
|
|
193
193
|
if (outputCoord.s !== GeoCoordStatus.OutOfUsefulRange) {
|
|
194
194
|
const testPoint2 = [];
|
|
@@ -197,8 +197,8 @@ describe("iModel geolocation", () => {
|
|
|
197
197
|
const response2 = await iModel.getIModelCoordinatesFromGeoCoordinates(requestProps2);
|
|
198
198
|
const expectedPt2 = Point3d.fromJSON(inputCoord);
|
|
199
199
|
const outPt2 = Point3d.fromJSON(response2.iModelCoords[0].p);
|
|
200
|
-
expect(expectedPt2.distanceXY(outPt2)
|
|
201
|
-
expect(Math.abs(expectedPt2.z - outPt2.z)
|
|
200
|
+
expect(expectedPt2.distanceXY(outPt2), fileName).to.be.lessThan(0.001);
|
|
201
|
+
expect(Math.abs(expectedPt2.z - outPt2.z), fileName).to.be.lessThan(0.001);
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
iModel.close();
|