hytos / DTI_PID / BaseModel / Model / Document.cs @ 30d2cfcc
이력 | 보기 | 이력해설 | 다운로드 (12.9 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Threading.Tasks; |
6 |
using System.IO; |
7 |
using System.Xml.Linq; |
8 |
using System.Windows.Forms; |
9 |
|
10 |
namespace Converter.BaseModel |
11 |
{ |
12 |
public class Document |
13 |
{ |
14 |
private string _DWGNAME; |
15 |
private string _SIZE; |
16 |
private List<Symbol> _SYMBOLS = new List<Symbol>(); |
17 |
private List<Text> _TEXTINFOS = new List<Text>(); |
18 |
private List<Note> _NOTES = new List<Note>(); |
19 |
private List<Line> _LINES = new List<Line>(); |
20 |
private List<LineNumber> _LINENUMBERS = new List<LineNumber>(); |
21 |
private bool _Enable; |
22 |
|
23 |
public bool Enable { get { return _Enable; } } |
24 |
|
25 |
public List<Symbol> SYMBOLS { get => _SYMBOLS; set => _SYMBOLS = value; } |
26 |
public List<Text> TEXTINFOS { get => _TEXTINFOS; set => _TEXTINFOS = value; } |
27 |
public List<Note> NOTES { get => _NOTES; set => _NOTES = value; } |
28 |
public List<Line> LINES { get => _LINES; set => _LINES = value; } |
29 |
public List<LineNumber> LINENUMBERS { get => _LINENUMBERS; set => _LINENUMBERS = value; } |
30 |
public string DWGNAME { get => _DWGNAME; set => _DWGNAME = value; } |
31 |
public string SIZE { get => _SIZE; set => _SIZE = value; } |
32 |
|
33 |
public Document(string xmlPath) |
34 |
{ |
35 |
try |
36 |
{ |
37 |
XElement xml = XElement.Load(xmlPath); |
38 |
DWGNAME = xml.Element("DWGNAME").Value; |
39 |
SIZE = xml.Element("SIZE").Value; |
40 |
|
41 |
SetSymbol(xml.Element("SYMBOLS")); |
42 |
SetLine(xml.Element("LINEINFOS")); |
43 |
SetLineNumber(xml.Element("LINENOS")); |
44 |
SetText(xml.Element("TEXTINFOS")); |
45 |
SetNote(xml.Element("NOTES")); |
46 |
|
47 |
_Enable = true; |
48 |
} |
49 |
catch (Exception ex) |
50 |
{ |
51 |
_Enable = false; |
52 |
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
53 |
} |
54 |
} |
55 |
|
56 |
#region READ XML |
57 |
private void SetSymbol(XElement node) |
58 |
{ |
59 |
foreach (XElement item in node.Elements("SYMBOL")) |
60 |
{ |
61 |
Symbol symbol = new Symbol() |
62 |
{ |
63 |
UID = item.Element("UID").Value, |
64 |
DBUID = item.Element("DBUID").Value, |
65 |
NAME = item.Element("NAME").Value, |
66 |
TYPE = item.Element("TYPE").Value, |
67 |
OWNER = item.Element("OWNER").Value, |
68 |
ORIGINALPOINT = item.Element("ORIGINALPOINT").Value, |
69 |
CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value, |
70 |
LOCATION = item.Element("LOCATION").Value, |
71 |
SIZE = item.Element("SIZE").Value, |
72 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
73 |
PARENT = item.Element("PARENT").Value, |
74 |
CHILD = item.Element("CHILD").Value, |
75 |
HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value, |
76 |
AREA = item.Element("AREA").Value, |
77 |
FLIP = Convert.ToInt32(item.Element("FLIP").Value), |
78 |
CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value) |
79 |
}; |
80 |
SetAssociations(item.Element("ASSOCIATIONS"), symbol.ASSOCIATIONS); |
81 |
SetSymbolConnectors(item.Element("CONNECTORS"), symbol.CONNECTORS, symbol.CONNECTIONPOINT); |
82 |
SetProperties(item.Element("PROPERTIES"), symbol.PROPERTIES); |
83 |
SetAttributes(item.Element("SYMBOLATTRIBUTES"), symbol.ATTRIBUTES); |
84 |
SetChildSymbol(symbol); |
85 |
|
86 |
SYMBOLS.Add(symbol); |
87 |
} |
88 |
} |
89 |
|
90 |
private void SetLine(XElement node) |
91 |
{ |
92 |
foreach (XElement item in node.Elements("LINE")) |
93 |
{ |
94 |
Line line = new Line() |
95 |
{ |
96 |
OWNER = item.Attribute("OWNER").Value, |
97 |
UID = item.Element("UID").Value, |
98 |
STARTPOINT = item.Element("STARTPOINT").Value, |
99 |
ENDPOINT = item.Element("ENDPOINT").Value, |
100 |
TYPE = item.Element("TYPE").Value, |
101 |
TYPEUID = item.Element("TYPE").Attribute("TYPEUID").Value, |
102 |
AREA = item.Element("AREA").Value, |
103 |
THICKNESS = item.Element("THICKNESS").Value, |
104 |
}; |
105 |
SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS); |
106 |
LINES.Add(line); |
107 |
} |
108 |
} |
109 |
|
110 |
private void SetLineNumber(XElement node) |
111 |
{ |
112 |
foreach (XElement item in node.Elements("LINE_NO")) |
113 |
{ |
114 |
LineNumber lineNumber = new LineNumber() |
115 |
{ |
116 |
UID = item.Element("UID").Value, |
117 |
TEXT = item.Element("TEXT").Value, |
118 |
LOCATION = item.Element("LOCATION").Value, |
119 |
WIDTH = item.Element("WIDTH").Value, |
120 |
HEIGHT = item.Element("HEIGHT").Value, |
121 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
122 |
AREA = item.Element("AREA").Value |
123 |
}; |
124 |
SetLineNumberRuns(item, lineNumber.RUNS); |
125 |
SetProperties(item.Element("PROPERTIES"), lineNumber.PROPERTIES); |
126 |
SetAttributes(item, lineNumber.ATTRIBUTES); |
127 |
LINENUMBERS.Add(lineNumber); |
128 |
} |
129 |
} |
130 |
|
131 |
private void SetText(XElement node) |
132 |
{ |
133 |
foreach (XElement item in node.Elements("ATTRIBUTE")) |
134 |
{ |
135 |
Text text = new Text() |
136 |
{ |
137 |
UID = item.Element("UID").Value, |
138 |
ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value, |
139 |
NAME = item.Element("NAME").Value, |
140 |
LOCATION = item.Element("LOCATION").Value, |
141 |
VALUE = item.Element("VALUE").Value, |
142 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
143 |
WIDTH = item.Element("WIDTH").Value, |
144 |
HEIGHT = item.Element("HEIGHT").Value, |
145 |
AREA = item.Element("AREA").Value |
146 |
}; |
147 |
|
148 |
TEXTINFOS.Add(text); |
149 |
} |
150 |
} |
151 |
|
152 |
private void SetNote(XElement node) |
153 |
{ |
154 |
foreach (XElement item in node.Elements("ATTRIBUTE")) |
155 |
{ |
156 |
Note note = new Note() |
157 |
{ |
158 |
UID = item.Element("UID").Value, |
159 |
ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value, |
160 |
NAME = item.Element("NAME").Value, |
161 |
LOCATION = item.Element("LOCATION").Value, |
162 |
VALUE = item.Element("VALUE").Value, |
163 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
164 |
WIDTH = item.Element("WIDTH").Value, |
165 |
HEIGHT = item.Element("HEIGHT").Value, |
166 |
AREA = item.Element("AREA").Value |
167 |
}; |
168 |
|
169 |
NOTES.Add(note); |
170 |
} |
171 |
} |
172 |
|
173 |
private void SetAssociations(XElement node, List<Association> associations) |
174 |
{ |
175 |
foreach (XElement item in node.Elements("ASSOCIATION")) |
176 |
{ |
177 |
associations.Add(new Association() |
178 |
{ |
179 |
TYPE = item.Attribute("TYPE").Value, |
180 |
VALUE = item.Value |
181 |
}); |
182 |
} |
183 |
} |
184 |
|
185 |
private void SetConnectors(XElement node, List<Connector> connectors) |
186 |
{ |
187 |
foreach (XElement item in node.Elements("CONNECTOR")) |
188 |
{ |
189 |
connectors.Add(new Connector() |
190 |
{ |
191 |
UID = item.Attribute("UID").Value, |
192 |
CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value), |
193 |
CONNECTEDITEM = item.Element("CONNECTEDITEM").Value, |
194 |
CONNECTPOINT = item.Element("CONNECTPOINT").Value, |
195 |
SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value, |
196 |
}); |
197 |
} |
198 |
} |
199 |
|
200 |
private void SetSymbolConnectors(XElement node, List<Connector> connectors, string CONNECTIONPOINT) |
201 |
{ |
202 |
foreach (XElement item in node.Elements("CONNECTOR")) |
203 |
{ |
204 |
connectors.Add(new Connector() |
205 |
{ |
206 |
UID = item.Attribute("UID").Value, |
207 |
CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value), |
208 |
CONNECTEDITEM = item.Element("CONNECTEDITEM").Value, |
209 |
CONNECTPOINT = item.Element("CONNECTPOINT").Value, |
210 |
SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value, |
211 |
}); |
212 |
} |
213 |
} |
214 |
|
215 |
private void SetProperties(XElement node, List<Property> properties) |
216 |
{ |
217 |
foreach (XElement item in node.Elements("PROPERTY")) |
218 |
{ |
219 |
properties.Add(new Property() |
220 |
{ |
221 |
UID = item.Attribute("UID").Value, |
222 |
LENGTH = item.Attribute("Length").Value, |
223 |
EXPRESSION = item.Attribute("Expression").Value, |
224 |
DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value, |
225 |
ATTRIBUTETYPE = item.Attribute("AttributeType").Value, |
226 |
ATTRIBUTE = item.Attribute("Attribute").Value, |
227 |
VALUE = item.Value |
228 |
}); |
229 |
} |
230 |
} |
231 |
|
232 |
private void SetAttributes(XElement node, List<Attribute> attributes) |
233 |
{ |
234 |
foreach (XElement item in node.Elements("ATTRIBUTE")) |
235 |
{ |
236 |
attributes.Add(new Attribute() |
237 |
{ |
238 |
UID = item.Attribute("UID").Value, |
239 |
LENGTH = item.Attribute("Length").Value, |
240 |
EXPRESSION = item.Attribute("Expression").Value, |
241 |
DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value, |
242 |
ATTRIBUTETYPE = item.Attribute("AttributeType").Value, |
243 |
ATTRIBUTE = item.Attribute("Attribute").Value, |
244 |
ATTRAT = item.Attribute("AttrAt").Value, |
245 |
VALUE = item.Value |
246 |
}); |
247 |
} |
248 |
} |
249 |
|
250 |
private void SetLineNumberRuns(XElement node, List<LineNumberRun> lineNumberRuns) |
251 |
{ |
252 |
foreach (XElement item in node.Elements("RUN")) |
253 |
{ |
254 |
LineNumberRun run = new LineNumberRun() |
255 |
{ |
256 |
TYPE = item.Attribute("TYPE").Value |
257 |
}; |
258 |
|
259 |
foreach (XElement element in item.Elements()) |
260 |
{ |
261 |
if (element.Name == "SYMBOL") |
262 |
{ |
263 |
run.RUNITEMS.Add(GetSymbolByUID(element.Element("UID").Value)); |
264 |
} |
265 |
else if (element.Name == "LINE") |
266 |
{ |
267 |
run.RUNITEMS.Add(GetLineByUID(element.Element("UID").Value)); |
268 |
} |
269 |
} |
270 |
lineNumberRuns.Add(run); |
271 |
} |
272 |
} |
273 |
|
274 |
private void SetChildSymbol(Symbol symbol) |
275 |
{ |
276 |
List<ChildSymbol> childList = new List<ChildSymbol>(); |
277 |
if (!string.IsNullOrEmpty(symbol.CHILD) && symbol.CHILD != "None") |
278 |
{ |
279 |
string[] childArray = symbol.CHILD.Split(new char[] { '/' }); |
280 |
foreach (string sChild in childArray) |
281 |
{ |
282 |
string[] sChildInfo = sChild.Split(new char[] { ',' }); |
283 |
childList.Add(new ChildSymbol() |
284 |
{ |
285 |
ParentAt = Convert.ToInt32(sChildInfo[0]), |
286 |
Direction = sChildInfo[1], |
287 |
NAME = sChildInfo[2] |
288 |
}); |
289 |
} |
290 |
|
291 |
foreach (ChildSymbol child in childList) |
292 |
{ |
293 |
if (child.ParentAt == 0) |
294 |
symbol.ChildSymbols.Add(child); |
295 |
else |
296 |
childList[child.ParentAt - 1].ChildSymbols.Add(child); |
297 |
} |
298 |
} |
299 |
if (!string.IsNullOrEmpty(symbol.CONNECTIONPOINT) && symbol.CONNECTIONPOINT != "None") |
300 |
{ |
301 |
string[] connectionArray = symbol.CONNECTIONPOINT.Split(new char[] { '/' }); |
302 |
string[] array = symbol.CONNECTIONPOINT.Split(new char[] { '/' }); |
303 |
for (int i = 0; i < array.Length; i++) |
304 |
{ |
305 |
string[] arrConn = array[i].Split(new char[] { ',' }); |
306 |
int connIndex = Convert.ToInt32(arrConn[3]); |
307 |
if (connIndex != 0) |
308 |
childList[connIndex - 1].Connectors.Add(symbol.CONNECTORS[i]); |
309 |
} |
310 |
} |
311 |
} |
312 |
#endregion |
313 |
|
314 |
public Symbol GetSymbolByUID(string uid) |
315 |
{ |
316 |
return SYMBOLS.Find(x => x.UID == uid); |
317 |
} |
318 |
|
319 |
public Line GetLineByUID(string uid) |
320 |
{ |
321 |
return LINES.Find(x => x.UID == uid); |
322 |
} |
323 |
} |
324 |
} |