This repository has been archived by the owner on Aug 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iTwinLink.ts
60 lines (45 loc) · 2.45 KB
/
iTwinLink.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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { Id64String } from "@itwin/core-bentley";
import { IModelConnection } from "@itwin/core-frontend";
export interface Pipeline {
id: Id64String;
pipes: Id64String[];
}
export class ITwinLink {
private static pipelines: Pipeline[];
public static getPipelines = async (iModel: IModelConnection): Promise<Pipeline[]> => {
let pipelines = ITwinLink.pipelines;
if (!pipelines) {
pipelines = [];
/* In the Open_Plant_3d schema - The actual pipe geometry of a Pipeline (Piping_Network_System)
is stored as Piping_Components. Piping_Components are children of Pipe_Network_Segments,
which are children of the Pipeline component.
(Piping_Network_System (Pipeline) --> Piping_Network_Segments --> Piping_Components)
So the way to get the geometry of a Pipeline is to traverse down these relationships
and get all the related Piping_Components. That's what we are doing in the query below.*/
const query = `SELECT pipeline.SourceECInstanceId, pipeGeometry.TargetECInstanceId
FROM Bis.ElementOwnsChildElements pipeGeometry
JOIN Bis.ElementOwnsChildElements pipe
ON pipe.TargetECInstanceId = pipeGeometry.SourceECinstanceId
JOIN OpenPlant_3D.SEGMENT_HAS_PIPING_COMPONENT segment
ON segment.TargetECInstanceId = pipe.SourceECInstanceId
JOIN OpenPlant_3D.PIPELINE_HAS_SEGMENT pipeline
ON pipeline.TargetECInstanceId = segment.SourceECInstanceId`
try {
for await (const row of iModel.query(query)) {
if (!pipelines.some((pipeline) => pipeline.id === row[0]))
pipelines.push({id: row[0], pipes:[]})
pipelines.find((pipeline) => pipeline.id === row[0])?.pipes.push(row[1]);
}
} catch (e: any) {
console.log(e.message);
alert(e.message);
}
}
ITwinLink.pipelines = pipelines;
return pipelines;
}
}