/
ExternalSource.ts
158 lines (141 loc) · 7.39 KB
/
ExternalSource.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Elements
*/
import { Id64String } from "@itwin/core-bentley";
import { Point3d } from "@itwin/core-geometry";
import {
BisCodeSpec, Code, CodeScopeSpec, EntityReferenceSet, ExternalSourceAttachmentProps, ExternalSourceAttachmentRole, ExternalSourceProps, IModel, RelatedElement,
SynchronizationConfigLinkProps,
} from "@itwin/core-common";
import { InformationReferenceElement, UrlLink } from "./Element";
import { IModelDb } from "./IModelDb";
import { ExternalSourceAttachmentAttachesSource, ExternalSourceIsInRepository } from "./NavigationRelationship";
/** An ExternalSource refers to an 'information container' found in a repository. In some cases, the container is the entire repository.
* @note The associated ECClass was added to the BisCore schema in version 1.0.13
* @beta
*/
export class ExternalSource extends InformationReferenceElement {
/** The repository that contains this ExternalSource. */
public repository?: ExternalSourceIsInRepository;
/** The name of the iModel Connecter that processed this ExternalSource. */
public connectorName?: string;
/** The version of the iModel Connecter that processed this ExternalSource. */
public connectorVersion?: string;
/** @internal */
public static override get className(): string { return "ExternalSource"; }
protected constructor(props: ExternalSourceProps, iModel: IModelDb) {
super(props, iModel);
if (props.repository)
this.repository = new ExternalSourceIsInRepository(RelatedElement.idFromJson(props.repository));
}
public override toJSON(): ExternalSourceProps { // This override only specializes the return type
return super.toJSON() as ExternalSourceProps; // Entity.toJSON takes care of auto-handled properties
}
/** The [[CodeSpec]] for ExternalSource elements is not automatically created, so this method ensures that it exists. */
public static ensureCodeSpec(iModelDb: IModelDb): Id64String {
try {
const codeSpec = iModelDb.codeSpecs.getByName(BisCodeSpec.externalSource);
return codeSpec.id;
} catch (e) {
return iModelDb.codeSpecs.insert(BisCodeSpec.externalSource, CodeScopeSpec.Type.Repository);
}
}
/** Create a Code for an ExternalSource element given a name that is meant to be unique within the scope of the iModel.
* @param iModelDb The IModelDb
* @param codeValue The ExternalSource name
* @see [[ensureCodeSpec]]
*/
public static createCode(iModelDb: IModelDb, codeValue: string): Code {
const codeSpec = iModelDb.codeSpecs.getByName(BisCodeSpec.externalSource);
return new Code({ spec: codeSpec.id, scope: IModel.rootSubjectId, value: codeValue });
}
protected override collectReferenceIds(referenceIds: EntityReferenceSet): void {
super.collectReferenceIds(referenceIds);
if (this.repository)
referenceIds.addElement(this.repository.id);
}
}
/** Attachment of an ExternalSource
* @note The associated ECClass was added to the BisCore schema in version 1.0.13
* @beta
*/
export class ExternalSourceAttachment extends InformationReferenceElement {
/** The [[ExternalSource]] that is attached by this ExternalSourceAttachment. */
public attaches?: ExternalSourceAttachmentAttachesSource;
/** Specifies whether the attached [[ExternalSource]] provides context or models a part of the whole. */
public role?: ExternalSourceAttachmentRole;
/** The translation or offset in global coordinates of the attached [[ExternalSource]] relative to the ExternalSource that attaches it. */
public translation?: Point3d;
/** The Yaw angle (in degrees) of the attached [[ExternalSource]] relative to the ExternalSource that attaches it. */
public yaw?: number;
/** The Pitch angle (in degrees) of the attached [[ExternalSource]] relative to the ExternalSource that attaches it. */
public pitch?: number;
/** The Roll angle (in degrees) of the attached [[ExternalSource]] relative to the ExternalSource that attaches it. */
public roll?: number;
/** The scale of the attached [[ExternalSource]] relative to the ExternalSource that attaches it. */
public scale?: Point3d;
/** @internal */
public static override get className(): string { return "ExternalSourceAttachment"; }
protected constructor(props: ExternalSourceAttachmentProps, iModel: IModelDb) {
super(props, iModel);
if (props.attaches)
this.attaches = new ExternalSourceAttachmentAttachesSource(RelatedElement.idFromJson(props.attaches));
if (props.translation)
this.translation = Point3d.fromJSON(props.translation);
if (props.scale)
this.scale = Point3d.fromJSON(props.scale);
}
public override toJSON(): ExternalSourceAttachmentProps { // This override only specializes the return type
return super.toJSON() as ExternalSourceAttachmentProps; // Entity.toJSON takes care of auto-handled properties
}
/** The [[CodeSpec]] for ExternalSourceAttachment elements is not automatically created, so this method ensures that it exists. */
public static ensureCodeSpec(iModelDb: IModelDb): Id64String {
try {
const codeSpec = iModelDb.codeSpecs.getByName(BisCodeSpec.externalSourceAttachment);
return codeSpec.id;
} catch (e) {
return iModelDb.codeSpecs.insert(BisCodeSpec.externalSourceAttachment, CodeScopeSpec.Type.ParentElement);
}
}
/** Create a Code for an ExternalSourceAttachment element given a name that is meant to be unique within the scope of its parent [[ExternalSource]].
* @param iModelDb The IModelDb
* @param scopeElementId The parent ExternalSource
* @param codeValue The ExternalSourceAttachment name
* @see [[ensureCodeSpec]]
*/
public static createCode(iModelDb: IModelDb, scopeElementId: Id64String, codeValue: string): Code {
const codeSpec = iModelDb.codeSpecs.getByName(BisCodeSpec.externalSourceAttachment);
return new Code({ spec: codeSpec.id, scope: scopeElementId, value: codeValue });
}
}
/** A group of ExternalSources that are collectively a source of information for one or more elements.
* @note The associated ECClass was added to the BisCore schema in version 1.0.13
* @beta
*/
export class ExternalSourceGroup extends ExternalSource {
/** @internal */
public static override get className(): string { return "ExternalSourceGroup"; }
protected constructor(props: ExternalSourceProps, iModel: IModelDb) {
super(props, iModel);
}
}
/** Link to the Configuration for an iModel Synchronization Job
* @note The associated ECClass was added to the BisCore schema in version 1.0.13
* @beta
*/
export class SynchronizationConfigLink extends UrlLink {
/** Date/Time of last successful run of this synchronization configuration */
public lastSuccessfulRun?: string;
/** @internal */
public static override get className(): string { return "SynchronizationConfigLink"; }
protected constructor(props: SynchronizationConfigLinkProps, iModel: IModelDb) {
super(props, iModel);
}
public override toJSON(): SynchronizationConfigLinkProps { // This override only specializes the return type
return super.toJSON() as SynchronizationConfigLinkProps; // Entity.toJSON takes care of auto-handled properties
}
}