hytos / DTI_PID / ID2PSN / Object / Item.cs @ b2e32d43
이력 | 보기 | 이력해설 | 다운로드 (8.88 KB)
1 |
using DevExpress.XtraGrid.Views.Layout; |
---|---|
2 |
using System; |
3 |
using System.Collections.Generic; |
4 |
using System.Linq; |
5 |
using System.Text; |
6 |
using System.Threading.Tasks; |
7 |
|
8 |
namespace ID2PSN |
9 |
{ |
10 |
public enum ItemType |
11 |
{ |
12 |
None, |
13 |
Symbol, |
14 |
Line |
15 |
} |
16 |
public enum SubItemType |
17 |
{ |
18 |
None, |
19 |
OPC, |
20 |
Header, |
21 |
Nozzle, |
22 |
Keyword |
23 |
} |
24 |
|
25 |
public class Item |
26 |
{ |
27 |
public Item() |
28 |
{ |
29 |
BranchItems = new List<Item>(); |
30 |
Attributes = new List<Attribute>(); |
31 |
} |
32 |
|
33 |
public string UID { get; set; } |
34 |
public string ID2DBCategory { get; set; } |
35 |
public string ID2DBType { get; set; } |
36 |
public string Name { get; set; } |
37 |
public string Owner { get; set; } |
38 |
public string ID2DBName { get; set; } |
39 |
public string ANGLE { get; set; } |
40 |
public double[] POINT { get; set; } |
41 |
public List<Relation> Relations { get; set; } |
42 |
public List<Attribute> Attributes { get; set; } |
43 |
public ItemType ItemType { get; set; } |
44 |
public SubItemType SubItemType { get; set; } |
45 |
public List<Item> BranchItems { get; set; } |
46 |
public string TopologyData { get; set; } |
47 |
public string PSNPipeLineID { get; set; } |
48 |
public string PSNPipeSystemID { get; set; } |
49 |
public Topology Topology { get; set; } |
50 |
public Group Group { get; set; } |
51 |
public PSNItem PSNItem { get; set; } |
52 |
public LineNumber LineNumber { get; set; } |
53 |
|
54 |
public Equipment Equipment { get; set; } |
55 |
public Document Document { get; set; } |
56 |
public string Keyword { get; set; } |
57 |
|
58 |
public Item pairItem { get; set; } |
59 |
public Item LineItemCopy() |
60 |
{ |
61 |
Item newItem = new Item(); |
62 |
|
63 |
newItem.UID = Guid.NewGuid().ToString(); |
64 |
|
65 |
newItem.Name = this.Name; |
66 |
newItem.ID2DBType = this.ID2DBType; |
67 |
newItem.Owner = this.Owner; |
68 |
newItem.ItemType = ItemType.Line; |
69 |
|
70 |
List<Attribute> attributes = new List<Attribute>(); |
71 |
foreach (var attr in this.Attributes) |
72 |
{ |
73 |
attributes.Add(new Attribute() |
74 |
{ |
75 |
UID = attr.UID, |
76 |
Name = attr.Name, |
77 |
DisplayName = attr.DisplayName, |
78 |
Value = attr.Value |
79 |
}); |
80 |
} |
81 |
newItem.Attributes = attributes; |
82 |
|
83 |
List<Relation> relations = new List<Relation>(); |
84 |
foreach (var _relation in this.Relations) |
85 |
{ |
86 |
relations.Add(new Relation() |
87 |
{ |
88 |
UID = "None", |
89 |
Point = (double[])_relation.Point.Clone() |
90 |
}); |
91 |
} |
92 |
newItem.Relations = relations; |
93 |
|
94 |
return newItem; |
95 |
} |
96 |
|
97 |
public string GetAttributeByName(string name) |
98 |
{ |
99 |
Attribute attribute = this.Attributes.Find(x => x.Name.ToUpper() == name.ToUpper()); |
100 |
if (attribute != null && !string.IsNullOrEmpty(attribute.Value) && attribute.Value != "None") |
101 |
{ |
102 |
return attribute.Value; |
103 |
} |
104 |
|
105 |
if (this.LineNumber != null) |
106 |
{ |
107 |
attribute = this.LineNumber.Attributes.Find(x => x.Name.ToUpper() == name.ToUpper()); |
108 |
if (attribute != null) |
109 |
{ |
110 |
return attribute.Value; |
111 |
} |
112 |
} |
113 |
|
114 |
return null; |
115 |
} |
116 |
|
117 |
} |
118 |
|
119 |
public class Relation |
120 |
{ |
121 |
public string UID { get; set; } |
122 |
public Item Item { get; set; } |
123 |
public double[] Point { get; set; } |
124 |
} |
125 |
|
126 |
public class Attribute |
127 |
{ |
128 |
public string UID { get; set; } |
129 |
public string Name { get; set; } |
130 |
public string DisplayName { get; set; } |
131 |
public string Value { get; set; } |
132 |
} |
133 |
|
134 |
public class Equipment |
135 |
{ |
136 |
public Equipment() |
137 |
{ |
138 |
POINT = new List<double[]>(); |
139 |
Nozzles = new List<Item>(); |
140 |
Attributes = new List<Attribute>(); |
141 |
} |
142 |
public string Name { get; set; } |
143 |
public string UID { get; set; } |
144 |
public List<double[]> POINT { get; set; } |
145 |
public List<Item> Nozzles { get; set; } |
146 |
public List<Attribute> Attributes { get; set; } |
147 |
public string ItemTag { get; set; } |
148 |
} |
149 |
|
150 |
public class LineNumber |
151 |
{ |
152 |
public LineNumber() |
153 |
{ |
154 |
Attributes = new List<Attribute>(); |
155 |
} |
156 |
public string UID { get; set; } |
157 |
public string Name { get; set; } |
158 |
public List<Attribute> Attributes { get; set; } |
159 |
public bool IsCopy { get; set; } |
160 |
public bool MissingLineNumber1 { get; set; } |
161 |
public bool MissingLineNumber2 { get; set; } |
162 |
|
163 |
public LineNumber Copy() |
164 |
{ |
165 |
LineNumber copy = new LineNumber(); |
166 |
copy.IsCopy = true; |
167 |
copy.UID = Guid.NewGuid().ToString(); |
168 |
copy.Name = Name; |
169 |
foreach (Attribute attribute in Attributes) |
170 |
{ |
171 |
copy.Attributes.Add(new Attribute() |
172 |
{ |
173 |
UID = attribute.UID, |
174 |
Name = attribute.Name, |
175 |
DisplayName = attribute.DisplayName, |
176 |
Value = attribute.Value, |
177 |
}); |
178 |
} |
179 |
Attribute seqAttr = copy.Attributes.Find(x => x.Name == "Tag Seq No"); |
180 |
if (seqAttr != null) |
181 |
{ |
182 |
copy.Name = copy.Name.Replace(seqAttr.Value, seqAttr.Value + "V"); |
183 |
seqAttr.Value += "V"; |
184 |
} |
185 |
else |
186 |
copy.Name += "V"; |
187 |
|
188 |
|
189 |
|
190 |
return copy; |
191 |
} |
192 |
} |
193 |
|
194 |
public class RunInfo |
195 |
{ |
196 |
public RunInfo() |
197 |
{ |
198 |
Items = new List<Item>(); |
199 |
} |
200 |
public string UID { get; set; } |
201 |
public int Index { get; set; } |
202 |
public List<Item> Items { get; set; } |
203 |
} |
204 |
|
205 |
public class Group |
206 |
{ |
207 |
public Group(Document document) |
208 |
{ |
209 |
_Document = document; |
210 |
} |
211 |
public Group StartGroup { get; set; } |
212 |
public Group EndGroup { get; set; } |
213 |
public string UID { get; set; } |
214 |
public List<Item> Items { get; set; } |
215 |
private Document _Document; |
216 |
public Document Document { get { return _Document; } } |
217 |
public void SortItems() |
218 |
{ |
219 |
List<Item> sorted = new List<Item>(); |
220 |
Item line = Items.Find(x => x.ItemType == ItemType.Line); |
221 |
if (line != null) |
222 |
{ |
223 |
sorted.Add(line); |
224 |
Item startItem = line.Relations[0].Item; |
225 |
if (startItem != null) |
226 |
{ |
227 |
Stack<Item> stacks = new Stack<Item>(); |
228 |
stacks.Push(startItem); |
229 |
while (stacks.Count > 0) |
230 |
{ |
231 |
Item stack = stacks.Pop(); |
232 |
if (sorted.Contains(stack)) |
233 |
continue; |
234 |
|
235 |
if (Items.Contains(stack)) |
236 |
{ |
237 |
sorted.Insert(0, stack); |
238 |
foreach (var relation in stack.Relations) |
239 |
{ |
240 |
if (relation.Item == null || !Items.Contains(relation.Item)) |
241 |
continue; |
242 |
stacks.Push(relation.Item); |
243 |
} |
244 |
} |
245 |
} |
246 |
} |
247 |
Item endItem = line.Relations[1].Item; |
248 |
if (endItem != null) |
249 |
{ |
250 |
Stack<Item> stacks = new Stack<Item>(); |
251 |
stacks.Push(endItem); |
252 |
while (stacks.Count > 0) |
253 |
{ |
254 |
Item stack = stacks.Pop(); |
255 |
if (sorted.Contains(stack)) |
256 |
continue; |
257 |
|
258 |
if (Items.Contains(stack)) |
259 |
{ |
260 |
sorted.Add(stack); |
261 |
foreach (var relation in stack.Relations) |
262 |
{ |
263 |
if (relation.Item == null || !Items.Contains(relation.Item)) |
264 |
continue; |
265 |
stacks.Push(relation.Item); |
266 |
} |
267 |
} |
268 |
} |
269 |
} |
270 |
|
271 |
if (!sorted.Count.Equals(Items.Count)) |
272 |
throw new Exception("logic error"); |
273 |
|
274 |
Items = sorted; |
275 |
} |
276 |
else |
277 |
{ |
278 |
|
279 |
} |
280 |
} |
281 |
} |
282 |
|
283 |
public class Topology |
284 |
{ |
285 |
public Topology() |
286 |
{ |
287 |
Items = new List<Item>(); |
288 |
} |
289 |
public string ID { get; set; } |
290 |
public string Type { get; set; } |
291 |
public string Index { get; set; } |
292 |
public string FullName { get { return ID + "-" + Type + Index; } } |
293 |
public List<Item> Items { get; set; } |
294 |
} |
295 |
} |