/
LinearReferencingElementAspects.ts
127 lines (108 loc) · 6.03 KB
/
LinearReferencingElementAspects.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module LinearReferencing
*/
import { Id64String, JsonUtils } from "@itwin/core-bentley";
import { ElementMultiAspect, IModelDb } from "@itwin/core-backend";
import { RelatedElement } from "@itwin/core-common";
import {
DistanceExpressionProps, LinearlyReferencedAtLocationAspectProps, LinearlyReferencedFromToLocationAspectProps,
} from "@itwin/linear-referencing-common";
import {
LinearlyReferencedAtPositionRefersToReferent, LinearlyReferencedFromPositionRefersToReferent, LinearlyReferencedToPositionRefersToReferent,
} from "./LinearReferencingRelationships";
/** Core structure carrying linearly-referenced information.
* @beta
*/
export class DistanceExpression implements DistanceExpressionProps {
public distanceAlongFromStart: number;
public lateralOffsetFromILinearElement?: number;
public verticalOffsetFromILinearElement?: number;
public distanceAlongFromReferent?: number;
constructor(props: DistanceExpressionProps) {
this.distanceAlongFromStart = JsonUtils.asDouble(props.distanceAlongFromStart);
this.lateralOffsetFromILinearElement = JsonUtils.asDouble(props.lateralOffsetFromILinearElement);
this.verticalOffsetFromILinearElement = JsonUtils.asDouble(props.verticalOffsetFromILinearElement);
this.distanceAlongFromReferent = JsonUtils.asDouble(props.distanceAlongFromReferent);
}
public static fromJSON(json: DistanceExpressionProps): DistanceExpression { return new DistanceExpression(json); }
}
/** Base class for multi-aspects carrying linearly-referenced locations.
* @beta
*/
export class LinearlyReferencedLocation extends ElementMultiAspect {
/** @internal */
public static override get className(): string { return "LinearlyReferencedLocation"; }
}
/** Concrete multi-aspect class carrying 'at' linearly-referenced positions along a Linear-Element.
* @beta
*/
export class LinearlyReferencedAtLocation extends LinearlyReferencedLocation {
/** @internal */
public static override get className(): string { return "LinearlyReferencedAtLocation"; }
public atPosition: DistanceExpression;
public fromReferent?: LinearlyReferencedAtPositionRefersToReferent;
constructor(props: LinearlyReferencedAtLocationAspectProps, iModel: IModelDb) {
super(props, iModel);
this.atPosition = DistanceExpression.fromJSON(props.atPosition);
this.fromReferent = RelatedElement.fromJSON(props.fromReferent);
}
private static toProps(locatedElementId: Id64String, at: DistanceExpression, fromReferentId?: Id64String): LinearlyReferencedAtLocationAspectProps {
const props: LinearlyReferencedAtLocationAspectProps = {
classFullName: LinearlyReferencedAtLocation.classFullName,
element: { id: locatedElementId },
atPosition: at,
fromReferent: (fromReferentId === undefined) ? undefined : new LinearlyReferencedAtPositionRefersToReferent(fromReferentId),
};
return props;
}
public static create(iModel: IModelDb, locatedElementId: Id64String,
at: DistanceExpression, fromReferentId?: Id64String): LinearlyReferencedAtLocation {
return new LinearlyReferencedAtLocation(this.toProps(locatedElementId, at, fromReferentId), iModel);
}
public static insert(iModel: IModelDb, locatedElementId: Id64String,
at: DistanceExpression, fromReferentId?: Id64String): void {
iModel.elements.insertAspect(this.toProps(locatedElementId, at, fromReferentId));
}
}
/** Concrete multi-aspect class carrying 'from-to' linearly-referenced positions along a Linear-Element.
* @beta
*/
export class LinearlyReferencedFromToLocation extends LinearlyReferencedLocation {
/** @internal */
public static override get className(): string { return "LinearlyReferencedFromToLocation"; }
public fromPosition: DistanceExpression;
public fromPositionFromReferent?: LinearlyReferencedFromPositionRefersToReferent;
public toPosition: DistanceExpression;
public toPositionFromReferent?: LinearlyReferencedToPositionRefersToReferent;
constructor(props: LinearlyReferencedFromToLocationAspectProps, iModel: IModelDb) {
super(props, iModel);
this.fromPosition = DistanceExpression.fromJSON(props.fromPosition);
this.toPosition = DistanceExpression.fromJSON(props.toPosition);
this.fromPositionFromReferent = RelatedElement.fromJSON(props.fromPositionFromReferent);
this.toPositionFromReferent = RelatedElement.fromJSON(props.toPositionFromReferent);
}
private static toProps(locatedElementId: Id64String,
from: DistanceExpression, to: DistanceExpression, fromReferentId?: Id64String, toReferentId?: Id64String): LinearlyReferencedFromToLocationAspectProps {
const props: LinearlyReferencedFromToLocationAspectProps = {
classFullName: LinearlyReferencedFromToLocation.classFullName,
element: { id: locatedElementId },
fromPosition: from,
fromPositionFromReferent: (fromReferentId === undefined) ? undefined : new LinearlyReferencedFromPositionRefersToReferent(fromReferentId),
toPosition: to,
toPositionFromReferent: (toReferentId === undefined) ? undefined : new LinearlyReferencedToPositionRefersToReferent(toReferentId),
};
return props;
}
public static create(iModel: IModelDb, locatedElementId: Id64String,
from: DistanceExpression, to: DistanceExpression, fromReferentId?: Id64String, toReferentId?: Id64String): LinearlyReferencedFromToLocation {
return new LinearlyReferencedFromToLocation(this.toProps(locatedElementId, from, to, fromReferentId, toReferentId), iModel);
}
public static insert(iModel: IModelDb, locatedElementId: Id64String,
from: DistanceExpression, to: DistanceExpression, fromReferentId?: Id64String, toReferentId?: Id64String): void {
iModel.elements.insertAspect(this.toProps(locatedElementId, from, to, fromReferentId, toReferentId));
}
}