hytos / DTI_PID / ID2PSN / Object / Item.cs @ 6b9e7a56
이력 | 보기 | 이력해설 | 다운로드 (5.24 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Threading.Tasks; |
6 |
|
7 |
namespace ID2PSN |
8 |
{ |
9 |
public enum ItemType |
10 |
{ |
11 |
None, |
12 |
Symbol, |
13 |
Line |
14 |
} |
15 |
public enum SubItemType |
16 |
{ |
17 |
None, |
18 |
OPC, |
19 |
Header, |
20 |
Nozzle, |
21 |
} |
22 |
|
23 |
public class Item |
24 |
{ |
25 |
public Item() |
26 |
{ |
27 |
BranchItems = new List<Item>(); |
28 |
} |
29 |
|
30 |
public string UID { get; set; } |
31 |
public string Type { get; set; } |
32 |
public string Name { get; set; } |
33 |
public string Owner { get; set; } |
34 |
public string Parent { get; set; } |
35 |
public string ANGLE { get; set; } |
36 |
public double[] POINT { get; set; } |
37 |
public List<Relation> Relations { get; set; } |
38 |
public List<Attribute> Attributes { get; set; } |
39 |
public ItemType ItemType { get; set; } |
40 |
public SubItemType SubItemType { get; set; } |
41 |
public List<Item> BranchItems { get; set; } |
42 |
public string TopologyData { get; set; } |
43 |
public Topology Topology { get; set; } |
44 |
public LineNumber LineNumber { get; set; } |
45 |
} |
46 |
|
47 |
public class Relation |
48 |
{ |
49 |
public string UID { get; set; } |
50 |
public Item Item { get; set; } |
51 |
public double[] Point { get; set; } |
52 |
} |
53 |
public class Attribute |
54 |
{ |
55 |
public string UID { get; set; } |
56 |
public string Name { get; set; } |
57 |
public string DisplayName { get; set; } |
58 |
public string Value { get; set; } |
59 |
} |
60 |
public class Equipment |
61 |
{ |
62 |
public Equipment() |
63 |
{ |
64 |
POINT = new List<double[]>(); |
65 |
Nozzles = new List<Item>(); |
66 |
} |
67 |
public string UID { get; set; } |
68 |
public List<double[]> POINT { get; set; } |
69 |
public List<Item> Nozzles { get; set; } |
70 |
} |
71 |
public class LineNumber |
72 |
{ |
73 |
public string UID { get; set; } |
74 |
public string Name { get; set; } |
75 |
public List<Attribute> Attributes { get; set; } |
76 |
} |
77 |
|
78 |
public class RunInfo |
79 |
{ |
80 |
public RunInfo() |
81 |
{ |
82 |
Items = new List<Item>(); |
83 |
} |
84 |
public string UID { get; set; } |
85 |
public int Index { get; set; } |
86 |
public List<Item> Items { get; set; } |
87 |
} |
88 |
|
89 |
public class Group |
90 |
{ |
91 |
public Group(Document document) |
92 |
{ |
93 |
_Document = document; |
94 |
} |
95 |
public Group StartGroup { get; set; } |
96 |
public Group EndGroup { get; set; } |
97 |
public string UID { get; set; } |
98 |
public List<Item> Items { get; set; } |
99 |
private Document _Document; |
100 |
public Document Document { get { return _Document; } } |
101 |
public void SortItems() |
102 |
{ |
103 |
List<Item> sorted = new List<Item>(); |
104 |
Item line = Items.Find(x => x.ItemType == ItemType.Line); |
105 |
if (line != null) |
106 |
{ |
107 |
sorted.Add(line); |
108 |
Item startItem = line.Relations[0].Item; |
109 |
if (startItem != null) |
110 |
{ |
111 |
Stack<Item> stacks = new Stack<Item>(); |
112 |
stacks.Push(startItem); |
113 |
while (stacks.Count > 0) |
114 |
{ |
115 |
Item stack = stacks.Pop(); |
116 |
if (sorted.Contains(stack)) |
117 |
continue; |
118 |
|
119 |
if (Items.Contains(stack)) |
120 |
{ |
121 |
sorted.Insert(0, stack); |
122 |
foreach (var relation in stack.Relations) |
123 |
{ |
124 |
if (relation.Item == null || !Items.Contains(relation.Item)) |
125 |
continue; |
126 |
stacks.Push(relation.Item); |
127 |
} |
128 |
} |
129 |
} |
130 |
} |
131 |
Item endItem = line.Relations[1].Item; |
132 |
if (endItem != null) |
133 |
{ |
134 |
Stack<Item> stacks = new Stack<Item>(); |
135 |
stacks.Push(endItem); |
136 |
while (stacks.Count > 0) |
137 |
{ |
138 |
Item stack = stacks.Pop(); |
139 |
if (sorted.Contains(stack)) |
140 |
continue; |
141 |
|
142 |
if (Items.Contains(stack)) |
143 |
{ |
144 |
sorted.Add(stack); |
145 |
foreach (var relation in stack.Relations) |
146 |
{ |
147 |
if (relation.Item == null || !Items.Contains(relation.Item)) |
148 |
continue; |
149 |
stacks.Push(relation.Item); |
150 |
} |
151 |
} |
152 |
} |
153 |
} |
154 |
|
155 |
if (!sorted.Count.Equals(Items.Count)) |
156 |
throw new Exception("logic error"); |
157 |
|
158 |
Items = sorted; |
159 |
} |
160 |
else |
161 |
{ |
162 |
|
163 |
} |
164 |
} |
165 |
} |
166 |
|
167 |
public class Topology |
168 |
{ |
169 |
public Topology() |
170 |
{ |
171 |
Items = new List<Item>(); |
172 |
} |
173 |
public string ID { get; set; } |
174 |
public string Type { get; set; } |
175 |
public string Index { get; set; } |
176 |
public string FullName { get { return ID + "-" + Type + Index; } } |
177 |
public List<Item> Items { get; set; } |
178 |
} |
179 |
} |