hytos / DTI_PID / BaseModel / Model / Document.cs @ cfda1fed
이력 | 보기 | 이력해설 | 다운로드 (10.4 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 |
NAME = item.Element("NAME").Value, |
65 |
TYPE = item.Element("TYPE").Value, |
66 |
OWNER = item.Element("OWNER").Value, |
67 |
ORIGINALPOINT = item.Element("ORIGINALPOINT").Value, |
68 |
CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value, |
69 |
LOCATION = item.Element("LOCATION").Value, |
70 |
SIZE = item.Element("SIZE").Value, |
71 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
72 |
PARENT = item.Element("PARENT").Value, |
73 |
CHILD = item.Element("CHILD").Value, |
74 |
HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value, |
75 |
AREA = item.Element("AREA").Value, |
76 |
FLIP = Convert.ToInt32(item.Element("FLIP").Value), |
77 |
CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value) |
78 |
}; |
79 |
SetAssociations(item.Element("ASSOCIATIONS"), symbol.ASSOCIATIONS); |
80 |
SetConnectors(item.Element("CONNECTORS"), symbol.CONNECTORS); |
81 |
SetProperties(item.Element("PROPERTIES"), symbol.PROPERTIES); |
82 |
SetAttributes(item.Element("SYMBOLATTRIBUTES"), symbol.ATTRIBUTES); |
83 |
|
84 |
SYMBOLS.Add(symbol); |
85 |
} |
86 |
} |
87 |
|
88 |
private void SetLine(XElement node) |
89 |
{ |
90 |
foreach (XElement item in node.Elements("LINE")) |
91 |
{ |
92 |
Line line = new Line() |
93 |
{ |
94 |
OWNER = item.Attribute("OWNER").Value, |
95 |
UID = item.Element("UID").Value, |
96 |
STARTPOINT = item.Element("STARTPOINT").Value, |
97 |
ENDPOINT = item.Element("ENDPOINT").Value, |
98 |
TYPE = item.Element("TYPE").Value, |
99 |
AREA = item.Element("AREA").Value, |
100 |
THICKNESS = item.Element("THICKNESS").Value, |
101 |
}; |
102 |
SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS); |
103 |
LINES.Add(line); |
104 |
} |
105 |
} |
106 |
|
107 |
private void SetLineNumber(XElement node) |
108 |
{ |
109 |
foreach (XElement item in node.Elements("LINE_NO")) |
110 |
{ |
111 |
LineNumber lineNumber = new LineNumber() |
112 |
{ |
113 |
UID = item.Element("UID").Value, |
114 |
TEXT = item.Element("TEXT").Value, |
115 |
LOCATION = item.Element("LOCATION").Value, |
116 |
WIDTH = item.Element("WIDTH").Value, |
117 |
HEIGHT = item.Element("HEIGHT").Value, |
118 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
119 |
AREA = item.Element("AREA").Value |
120 |
}; |
121 |
SetLineNumberRuns(item, lineNumber.RUNS); |
122 |
SetProperties(item.Element("PROPERTIES"), lineNumber.PROPERTIES); |
123 |
SetAttributes(item, lineNumber.ATTRIBUTES); |
124 |
LINENUMBERS.Add(lineNumber); |
125 |
} |
126 |
} |
127 |
|
128 |
private void SetText(XElement node) |
129 |
{ |
130 |
foreach (XElement item in node.Elements("ATTRIBUTE")) |
131 |
{ |
132 |
Text text = new Text() |
133 |
{ |
134 |
UID = item.Element("UID").Value, |
135 |
ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value, |
136 |
NAME = item.Element("NAME").Value, |
137 |
LOCATION = item.Element("LOCATION").Value, |
138 |
VALUE = item.Element("VALUE").Value, |
139 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
140 |
WIDTH = item.Element("WIDTH").Value, |
141 |
HEIGHT = item.Element("HEIGHT").Value, |
142 |
AREA = item.Element("AREA").Value |
143 |
}; |
144 |
|
145 |
TEXTINFOS.Add(text); |
146 |
} |
147 |
} |
148 |
|
149 |
private void SetNote(XElement node) |
150 |
{ |
151 |
foreach (XElement item in node.Elements("ATTRIBUTE")) |
152 |
{ |
153 |
Note note = new Note() |
154 |
{ |
155 |
UID = item.Element("UID").Value, |
156 |
ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value, |
157 |
NAME = item.Element("NAME").Value, |
158 |
LOCATION = item.Element("LOCATION").Value, |
159 |
VALUE = item.Element("VALUE").Value, |
160 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
161 |
WIDTH = item.Element("WIDTH").Value, |
162 |
HEIGHT = item.Element("HEIGHT").Value, |
163 |
AREA = item.Element("AREA").Value |
164 |
}; |
165 |
|
166 |
NOTES.Add(note); |
167 |
} |
168 |
} |
169 |
|
170 |
private void SetAssociations(XElement node, List<Association> associations) |
171 |
{ |
172 |
foreach (XElement item in node.Elements("ASSOCIATION")) |
173 |
{ |
174 |
associations.Add(new Association() |
175 |
{ |
176 |
TYPE = item.Attribute("TYPE").Value, |
177 |
VALUE = item.Value |
178 |
}); |
179 |
} |
180 |
} |
181 |
|
182 |
private void SetConnectors(XElement node, List<Connector> connectors) |
183 |
{ |
184 |
foreach (XElement item in node.Elements("CONNECTOR")) |
185 |
{ |
186 |
connectors.Add(new Connector() |
187 |
{ |
188 |
UID = item.Attribute("UID").Value, |
189 |
CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value), |
190 |
CONNECTEDITEM = item.Element("CONNECTEDITEM").Value, |
191 |
CONNECTPOINT = item.Element("CONNECTPOINT").Value, |
192 |
SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value, |
193 |
}); |
194 |
} |
195 |
} |
196 |
|
197 |
private void SetProperties(XElement node, List<Property> properties) |
198 |
{ |
199 |
foreach (XElement item in node.Elements("PROPERTY")) |
200 |
{ |
201 |
try |
202 |
{ |
203 |
properties.Add(new Property() |
204 |
{ |
205 |
UID = item.Attribute("UID").Value, |
206 |
LENGTH = item.Attribute("Length").Value, |
207 |
EXPRESSION = item.Attribute("Expression").Value, |
208 |
DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value, |
209 |
ATTRIBUTETYPE = item.Attribute("AttributeType").Value, |
210 |
ATTRIBUTE = item.Attribute("Attribute").Value, |
211 |
VALUE = item.Value |
212 |
}); |
213 |
} |
214 |
catch (Exception ex) |
215 |
{ |
216 |
|
217 |
} |
218 |
} |
219 |
} |
220 |
|
221 |
private void SetAttributes(XElement node, List<Attribute> attributes) |
222 |
{ |
223 |
foreach (XElement item in node.Elements("PROPERTY")) |
224 |
{ |
225 |
attributes.Add(new Attribute() |
226 |
{ |
227 |
UID = item.Attribute("UID").Value, |
228 |
LENGTH = item.Attribute("Length").Value, |
229 |
EXPRESSION = item.Attribute("Expression").Value, |
230 |
DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value, |
231 |
ATTRIBUTETYPE = item.Attribute("AttributeType").Value, |
232 |
ATTRIBUTE = item.Attribute("Attribute").Value, |
233 |
VALUE = item.Value |
234 |
}); |
235 |
} |
236 |
} |
237 |
|
238 |
private void SetLineNumberRuns(XElement node, List<LineNumberRun> lineNumberRuns) |
239 |
{ |
240 |
foreach (XElement item in node.Elements("RUN")) |
241 |
{ |
242 |
LineNumberRun run = new LineNumberRun() |
243 |
{ |
244 |
TYPE = item.Attribute("TYPE").Value |
245 |
}; |
246 |
|
247 |
foreach (XElement element in item.Elements()) |
248 |
{ |
249 |
if (element.Name == "SYMBOL") |
250 |
{ |
251 |
run.RUNITEMS.Add(GetSymbolByUID(element.Element("UID").Value)); |
252 |
} |
253 |
else if (element.Name == "LINE") |
254 |
{ |
255 |
run.RUNITEMS.Add(GetLineByUID(element.Element("UID").Value)); |
256 |
} |
257 |
} |
258 |
lineNumberRuns.Add(run); |
259 |
} |
260 |
} |
261 |
#endregion |
262 |
|
263 |
public Symbol GetSymbolByUID(string uid) |
264 |
{ |
265 |
return SYMBOLS.Find(x => x.UID == uid); |
266 |
} |
267 |
|
268 |
public Line GetLineByUID(string uid) |
269 |
{ |
270 |
return LINES.Find(x => x.UID == uid); |
271 |
} |
272 |
} |
273 |
} |