hytos / DTI_PID / BaseModel / Model / Document.cs @ 30d2cfcc
이력 | 보기 | 이력해설 | 다운로드 (12.9 KB)
1 | 96a2080c | gaqhf | 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 | 60244a8b | gaqhf | 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 | 96a2080c | gaqhf | |
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 | 60244a8b | gaqhf | |
47 | _Enable = true; |
||
48 | 96a2080c | gaqhf | } |
49 | catch (Exception ex) |
||
50 | { |
||
51 | 60244a8b | gaqhf | _Enable = false; |
52 | 96a2080c | gaqhf | MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
53 | } |
||
54 | } |
||
55 | |||
56 | 60244a8b | gaqhf | #region READ XML |
57 | 96a2080c | gaqhf | private void SetSymbol(XElement node) |
58 | { |
||
59 | foreach (XElement item in node.Elements("SYMBOL")) |
||
60 | { |
||
61 | 60244a8b | gaqhf | Symbol symbol = new Symbol() |
62 | 96a2080c | gaqhf | { |
63 | 60244a8b | gaqhf | UID = item.Element("UID").Value, |
64 | 30d2cfcc | gaqhf | DBUID = item.Element("DBUID").Value, |
65 | 60244a8b | gaqhf | 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 | bca81f4c | gaqhf | SetSymbolConnectors(item.Element("CONNECTORS"), symbol.CONNECTORS, symbol.CONNECTIONPOINT); |
82 | 60244a8b | gaqhf | SetProperties(item.Element("PROPERTIES"), symbol.PROPERTIES); |
83 | SetAttributes(item.Element("SYMBOLATTRIBUTES"), symbol.ATTRIBUTES); |
||
84 | 30d2cfcc | gaqhf | SetChildSymbol(symbol); |
85 | bca81f4c | gaqhf | |
86 | 60244a8b | gaqhf | SYMBOLS.Add(symbol); |
87 | 96a2080c | gaqhf | } |
88 | } |
||
89 | |||
90 | private void SetLine(XElement node) |
||
91 | { |
||
92 | foreach (XElement item in node.Elements("LINE")) |
||
93 | { |
||
94 | 60244a8b | gaqhf | Line line = new Line() |
95 | 96a2080c | gaqhf | { |
96 | 60244a8b | gaqhf | 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 | 30d2cfcc | gaqhf | TYPEUID = item.Element("TYPE").Attribute("TYPEUID").Value, |
102 | 60244a8b | gaqhf | AREA = item.Element("AREA").Value, |
103 | THICKNESS = item.Element("THICKNESS").Value, |
||
104 | }; |
||
105 | cfda1fed | gaqhf | SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS); |
106 | 60244a8b | gaqhf | LINES.Add(line); |
107 | 96a2080c | gaqhf | } |
108 | } |
||
109 | |||
110 | private void SetLineNumber(XElement node) |
||
111 | { |
||
112 | foreach (XElement item in node.Elements("LINE_NO")) |
||
113 | { |
||
114 | 60244a8b | gaqhf | LineNumber lineNumber = new LineNumber() |
115 | 96a2080c | gaqhf | { |
116 | 60244a8b | gaqhf | 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 | 96a2080c | gaqhf | } |
129 | } |
||
130 | |||
131 | private void SetText(XElement node) |
||
132 | { |
||
133 | foreach (XElement item in node.Elements("ATTRIBUTE")) |
||
134 | { |
||
135 | 60244a8b | gaqhf | Text text = new Text() |
136 | 96a2080c | gaqhf | { |
137 | 60244a8b | gaqhf | 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 | 96a2080c | gaqhf | |
148 | 60244a8b | gaqhf | TEXTINFOS.Add(text); |
149 | 96a2080c | gaqhf | } |
150 | } |
||
151 | |||
152 | private void SetNote(XElement node) |
||
153 | { |
||
154 | foreach (XElement item in node.Elements("ATTRIBUTE")) |
||
155 | { |
||
156 | 60244a8b | gaqhf | Note note = new Note() |
157 | 96a2080c | gaqhf | { |
158 | 60244a8b | gaqhf | 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 | 96a2080c | gaqhf | |
169 | 60244a8b | gaqhf | 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 | 96a2080c | gaqhf | }); |
182 | } |
||
183 | } |
||
184 | 60244a8b | gaqhf | |
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 | bca81f4c | gaqhf | 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 | 60244a8b | gaqhf | 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 | 30d2cfcc | gaqhf | properties.Add(new Property() |
220 | 60244a8b | gaqhf | { |
221 | 30d2cfcc | gaqhf | 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 | 60244a8b | gaqhf | } |
230 | } |
||
231 | |||
232 | private void SetAttributes(XElement node, List<Attribute> attributes) |
||
233 | { |
||
234 | 30d2cfcc | gaqhf | foreach (XElement item in node.Elements("ATTRIBUTE")) |
235 | 60244a8b | gaqhf | { |
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 | 30d2cfcc | gaqhf | ATTRAT = item.Attribute("AttrAt").Value, |
245 | 60244a8b | gaqhf | 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 | 30d2cfcc | gaqhf | |
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 | 60244a8b | gaqhf | #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 | 96a2080c | gaqhf | } |
324 | } |