hytos / DTI_PID / SPPIDConverter / SPPIDModel / SPPID_Document.cs @ 4d2571ab
이력 | 보기 | 이력해설 | 다운로드 (17.5 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.Data; |
7 |
using Converter.BaseModel; |
8 |
using Converter.SPPID.Util; |
9 |
|
10 |
namespace Converter.SPPID.Model |
11 |
{ |
12 |
public class SPPID_Document : Document |
13 |
{ |
14 |
public SPPID_Document(string xmlPath) : base(xmlPath) |
15 |
{ |
16 |
|
17 |
} |
18 |
|
19 |
public List<SymbolMapping> SymbolMappings; |
20 |
public List<ChildSymbolMapping> ChildSymbolMappings; |
21 |
public List<LineMapping> LineMappings; |
22 |
public List<LineNumberMapping> LineNumberMappings; |
23 |
public List<AttributeMapping> AttributeMappings; |
24 |
public ETCSetting ETCSetting; |
25 |
public DataTable SymbolTable { get; set; } |
26 |
|
27 |
public List<Group> GROUPS = new List<Group>(); |
28 |
|
29 |
public string DrawingName { get; set; } |
30 |
public string DrawingNumber { get; set; } |
31 |
public string Unit { get; set; } |
32 |
public string Template { get; set; } |
33 |
|
34 |
public void SetSPPIDInfo() |
35 |
{ |
36 |
foreach (var item in SYMBOLS) |
37 |
{ |
38 |
if (item.SPPID == null) |
39 |
item.SPPID = new SPPIDSymbolInfo(); |
40 |
|
41 |
foreach (var childSymbol in item.ChildSymbols) |
42 |
{ |
43 |
if (childSymbol.SPPID == null) |
44 |
childSymbol.SPPID = new SPPIDSymbolInfo(); |
45 |
SetChildSymbolSPPIDInfo(childSymbol); |
46 |
} |
47 |
} |
48 |
|
49 |
foreach (var item in LINES) |
50 |
{ |
51 |
if (item.SPPID == null) |
52 |
item.SPPID = new SPPIDLineInfo(); |
53 |
} |
54 |
|
55 |
foreach (var item in Equipments) |
56 |
{ |
57 |
if (item.SPPID == null) |
58 |
item.SPPID = new SPPIDSymbolInfo(); |
59 |
} |
60 |
|
61 |
foreach (var item in EndBreaks) |
62 |
{ |
63 |
if (item.SPPID == null) |
64 |
item.SPPID = new SPPIDSymbolInfo(); |
65 |
} |
66 |
|
67 |
foreach (var item in LINENUMBERS) |
68 |
{ |
69 |
if (item.SPPID == null) |
70 |
item.SPPID = new SPPIDSymbolInfo(); |
71 |
} |
72 |
|
73 |
foreach (var item in TEXTINFOS) |
74 |
{ |
75 |
if (item.SPPID == null) |
76 |
item.SPPID = new SPPIDSymbolInfo(); |
77 |
} |
78 |
|
79 |
foreach (var item in NOTES) |
80 |
{ |
81 |
if (item.SPPID == null) |
82 |
item.SPPID = new SPPIDSymbolInfo(); |
83 |
} |
84 |
} |
85 |
|
86 |
public void SetSPPIDLocation(double SPPIDDocumentX, double SPPIDDocumentY) |
87 |
{ |
88 |
foreach (var item in SYMBOLS) |
89 |
{ |
90 |
double x = double.NaN; |
91 |
double y = double.NaN; |
92 |
SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y); |
93 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
94 |
|
95 |
item.SPPID.ORIGINAL_X = x; |
96 |
item.SPPID.ORIGINAL_Y = y; |
97 |
} |
98 |
|
99 |
foreach (var item in LINES) |
100 |
{ |
101 |
double x = double.NaN; |
102 |
double y = double.NaN; |
103 |
|
104 |
SPPIDUtil.ConvertPointBystring(item.STARTPOINT, ref x, ref y); |
105 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
106 |
item.SPPID.START_X = x; |
107 |
item.SPPID.START_Y = y; |
108 |
|
109 |
SPPIDUtil.ConvertPointBystring(item.ENDPOINT, ref x, ref y); |
110 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
111 |
item.SPPID.END_X = x; |
112 |
item.SPPID.END_Y = y; |
113 |
} |
114 |
|
115 |
foreach (var item in Equipments) |
116 |
{ |
117 |
double x = double.NaN; |
118 |
double y = double.NaN; |
119 |
SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y); |
120 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
121 |
|
122 |
item.SPPID.ORIGINAL_X = x; |
123 |
item.SPPID.ORIGINAL_Y = y; |
124 |
} |
125 |
|
126 |
foreach (var item in EndBreaks) |
127 |
{ |
128 |
double x = double.NaN; |
129 |
double y = double.NaN; |
130 |
SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y); |
131 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
132 |
item.SPPID.ORIGINAL_X = x; |
133 |
item.SPPID.ORIGINAL_Y = y; |
134 |
} |
135 |
|
136 |
foreach (var item in LINENUMBERS) |
137 |
{ |
138 |
double x = double.NaN; |
139 |
double y = double.NaN; |
140 |
SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y); |
141 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
142 |
item.SPPID.ORIGINAL_X = x; |
143 |
item.SPPID.ORIGINAL_Y = y; |
144 |
|
145 |
item.SPPIDLabelLocation = new SPPIDLabelLocationInfo(); |
146 |
double x1 = item.X1; |
147 |
double y1 = item.Y1; |
148 |
double x2 = item.X2; |
149 |
double y2 = item.Y2; |
150 |
SPPIDUtil.ConvertSPPIDPoint(ref x1, ref y1, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
151 |
SPPIDUtil.ConvertSPPIDPoint(ref x2, ref y2, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
152 |
item.SPPIDLabelLocation.X1 = Math.Min(x1, x2); |
153 |
item.SPPIDLabelLocation.Y1 = Math.Min(y1, y2); |
154 |
item.SPPIDLabelLocation.X2 = Math.Max(x1, x2); |
155 |
item.SPPIDLabelLocation.Y2 = Math.Max(y1, y2); |
156 |
} |
157 |
|
158 |
foreach (var item in TEXTINFOS) |
159 |
{ |
160 |
double x = double.NaN; |
161 |
double y = double.NaN; |
162 |
SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y); |
163 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
164 |
item.SPPID.ORIGINAL_X = x; |
165 |
item.SPPID.ORIGINAL_Y = y; |
166 |
|
167 |
item.SPPIDLabelLocation = new SPPIDLabelLocationInfo(); |
168 |
double x1 = item.X1; |
169 |
double y1 = item.Y1; |
170 |
double x2 = item.X2; |
171 |
double y2 = item.Y2; |
172 |
SPPIDUtil.ConvertSPPIDPoint(ref x1, ref y1, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
173 |
SPPIDUtil.ConvertSPPIDPoint(ref x2, ref y2, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
174 |
item.SPPIDLabelLocation.X1 = Math.Min(x1, x2); |
175 |
item.SPPIDLabelLocation.Y1 = Math.Min(y1, y2); |
176 |
item.SPPIDLabelLocation.X2 = Math.Max(x1, x2); |
177 |
item.SPPIDLabelLocation.Y2 = Math.Max(y1, y2); |
178 |
} |
179 |
|
180 |
foreach (var item in NOTES) |
181 |
{ |
182 |
double x = double.NaN; |
183 |
double y = double.NaN; |
184 |
SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y); |
185 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
186 |
item.SPPID.ORIGINAL_X = x; |
187 |
item.SPPID.ORIGINAL_Y = y; |
188 |
|
189 |
item.SPPIDLabelLocation = new SPPIDLabelLocationInfo(); |
190 |
double x1 = item.X1; |
191 |
double y1 = item.Y1; |
192 |
double x2 = item.X2; |
193 |
double y2 = item.Y2; |
194 |
SPPIDUtil.ConvertSPPIDPoint(ref x1, ref y1, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
195 |
SPPIDUtil.ConvertSPPIDPoint(ref x2, ref y2, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
196 |
item.SPPIDLabelLocation.X1 = Math.Min(x1, x2); |
197 |
item.SPPIDLabelLocation.Y1 = Math.Min(y1, y2); |
198 |
item.SPPIDLabelLocation.X2 = Math.Max(x1, x2); |
199 |
item.SPPIDLabelLocation.Y2 = Math.Max(y1, y2); |
200 |
} |
201 |
} |
202 |
|
203 |
/// <summary> |
204 |
/// 좌표 보정 |
205 |
/// </summary> |
206 |
public void CoordinateCorrection() |
207 |
{ |
208 |
foreach (Symbol symbol in SYMBOLS) |
209 |
{ |
210 |
if (!symbol.SPPID.IsCorrectionX) |
211 |
{ |
212 |
List<object> group = new List<object>(); |
213 |
group.Add(symbol); |
214 |
FindGroupBySymbolAndSlopeType(symbol, group, SlopeType.VERTICAL); |
215 |
|
216 |
List<Symbol> groupSymbols = (from sym in @group |
217 |
where sym.GetType() == typeof(Symbol) |
218 |
select sym as Symbol).ToList(); |
219 |
|
220 |
// X 좌표만 보정 |
221 |
Symbol correctionSymbol = groupSymbols.Find(x => x.SPPID.IsCorrectionX); |
222 |
double value = symbol.SPPID.ORIGINAL_X; |
223 |
if (correctionSymbol == null) |
224 |
SPPIDUtil.ConvertGridPointOnlyOnePoint(ref value); |
225 |
else |
226 |
value = correctionSymbol.SPPID.ORIGINAL_X; |
227 |
|
228 |
foreach (var item in groupSymbols) |
229 |
{ |
230 |
item.SPPID.IsCorrectionX = true; |
231 |
item.SPPID.ORIGINAL_X = value; |
232 |
} |
233 |
} |
234 |
|
235 |
if (!symbol.SPPID.IsCorrectionY) |
236 |
{ |
237 |
List<object> group = new List<object>(); |
238 |
group.Add(symbol); |
239 |
FindGroupBySymbolAndSlopeType(symbol, group, SlopeType.HORIZONTAL); |
240 |
|
241 |
List<Symbol> groupSymbols = (from sym in @group |
242 |
where sym.GetType() == typeof(Symbol) |
243 |
select sym as Symbol).ToList(); |
244 |
|
245 |
// Y 좌표만 보정 |
246 |
Symbol correctionSymbol = groupSymbols.Find(x => x.SPPID.IsCorrectionY); |
247 |
double value = symbol.SPPID.ORIGINAL_Y; |
248 |
if (correctionSymbol == null) |
249 |
SPPIDUtil.ConvertGridPointOnlyOnePoint(ref value); |
250 |
else |
251 |
value = correctionSymbol.SPPID.ORIGINAL_Y; |
252 |
|
253 |
foreach (var item in groupSymbols) |
254 |
{ |
255 |
item.SPPID.IsCorrectionY = true; |
256 |
item.SPPID.ORIGINAL_Y = value; |
257 |
} |
258 |
} |
259 |
} |
260 |
} |
261 |
|
262 |
private void FindGroupBySymbolAndSlopeType(Symbol symbol, List<object> group, SlopeType searchType) |
263 |
{ |
264 |
foreach (var connector in symbol.CONNECTORS) |
265 |
{ |
266 |
object connectedItem = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM); |
267 |
if (connectedItem != null && connectedItem.GetType() == typeof(Symbol)) |
268 |
{ |
269 |
Symbol connSymbol = connectedItem as Symbol; |
270 |
SlopeType slopeType = SPPIDUtil.CalcSlope(symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y); |
271 |
if (slopeType == searchType) |
272 |
{ |
273 |
if (!group.Contains(connSymbol)) |
274 |
{ |
275 |
group.Add(connSymbol); |
276 |
FindGroupBySymbolAndSlopeType(connSymbol, group, searchType); |
277 |
} |
278 |
} |
279 |
} |
280 |
else if (connectedItem != null && connectedItem.GetType() == typeof(Line)) |
281 |
{ |
282 |
Line connLine = connectedItem as Line; |
283 |
SlopeType slopeType = SPPIDUtil.CalcSlope(connLine.SPPID.START_X, connLine.SPPID.START_Y, connLine.SPPID.END_X, connLine.SPPID.END_Y); |
284 |
if (slopeType == searchType) |
285 |
{ |
286 |
if (!group.Contains(connLine)) |
287 |
{ |
288 |
group.Add(connLine); |
289 |
FindGroupByLineAndSlopeType(connLine, group, searchType); |
290 |
} |
291 |
} |
292 |
} |
293 |
} |
294 |
} |
295 |
|
296 |
private void FindGroupByLineAndSlopeType(Line Line, List<object> group, SlopeType searchType) |
297 |
{ |
298 |
foreach (var connector in Line.CONNECTORS) |
299 |
{ |
300 |
object connectedItem = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM); |
301 |
if (connectedItem != null && connectedItem.GetType() == typeof(Symbol)) |
302 |
{ |
303 |
Symbol connSymbol = connectedItem as Symbol; |
304 |
double lineX = double.NaN; |
305 |
double lineY = double.NaN; |
306 |
SPPIDUtil.ConvertPointBystring(connector.SCENECONNECTPOINT, ref lineX, ref lineY); |
307 |
double symbolX = double.NaN; |
308 |
double symbolY = double.NaN; |
309 |
SPPIDUtil.ConvertPointBystring(connSymbol.ORIGINALPOINT, ref symbolX, ref symbolY); |
310 |
|
311 |
SlopeType slopeType = SPPIDUtil.CalcSlope(lineX, lineY, symbolX, symbolY); |
312 |
if (slopeType == searchType) |
313 |
{ |
314 |
if (!group.Contains(connSymbol)) |
315 |
{ |
316 |
group.Add(connSymbol); |
317 |
FindGroupBySymbolAndSlopeType(connSymbol, group, searchType); |
318 |
} |
319 |
} |
320 |
} |
321 |
else if (connectedItem != null && connectedItem.GetType() == typeof(Line)) |
322 |
{ |
323 |
Line connLine = connectedItem as Line; |
324 |
SlopeType slopeType = SPPIDUtil.CalcSlope(connLine.SPPID.START_X, connLine.SPPID.START_Y, connLine.SPPID.END_X, connLine.SPPID.END_Y); |
325 |
if (slopeType == searchType) |
326 |
{ |
327 |
if (!group.Contains(connLine)) |
328 |
{ |
329 |
group.Add(connLine); |
330 |
FindGroupByLineAndSlopeType(connLine, group, searchType); |
331 |
} |
332 |
} |
333 |
} |
334 |
} |
335 |
} |
336 |
|
337 |
private void SetChildSymbolSPPIDInfo(ChildSymbol item) |
338 |
{ |
339 |
foreach (var childSymbol in item.ChildSymbols) |
340 |
{ |
341 |
if (childSymbol.SPPID == null) |
342 |
childSymbol.SPPID = new SPPIDSymbolInfo(); |
343 |
SetChildSymbolSPPIDInfo(childSymbol); |
344 |
} |
345 |
} |
346 |
|
347 |
public bool SetSPPIDMapping() |
348 |
{ |
349 |
foreach (var item in SYMBOLS) |
350 |
{ |
351 |
SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID); |
352 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
353 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
354 |
return false; |
355 |
|
356 |
foreach (var childSymbol in item.ChildSymbols) |
357 |
{ |
358 |
ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME); |
359 |
childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null; |
360 |
if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME) || !SetChildSymbolMapping(childSymbol)) |
361 |
return false; |
362 |
} |
363 |
} |
364 |
|
365 |
foreach (var item in LINES) |
366 |
{ |
367 |
LineMapping mapping = LineMappings.Find(x => x.UID == item.TYPEUID); |
368 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
369 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
370 |
return false; |
371 |
} |
372 |
|
373 |
foreach (var item in Equipments) |
374 |
{ |
375 |
SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID); |
376 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
377 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
378 |
return false; |
379 |
} |
380 |
|
381 |
foreach (var item in EndBreaks) |
382 |
{ |
383 |
SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID); |
384 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
385 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
386 |
return false; |
387 |
} |
388 |
|
389 |
foreach (var item in LINENUMBERS) |
390 |
{ |
391 |
if (LineNumberMappings.Count > 0) |
392 |
item.SPPID.MAPPINGNAME = LineNumberMappings[0].SPPIDSYMBOLNAME; |
393 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
394 |
return false; |
395 |
} |
396 |
|
397 |
ETCSetting etc = ETCSetting.GetInstance(); |
398 |
foreach (var item in NOTES) |
399 |
{ |
400 |
item.SPPID.MAPPINGNAME = etc.NoteSymbolPath; |
401 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
402 |
return false; |
403 |
} |
404 |
|
405 |
foreach (var item in TEXTINFOS) |
406 |
{ |
407 |
item.SPPID.MAPPINGNAME = etc.TextSymbolPath; |
408 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
409 |
return false; |
410 |
} |
411 |
|
412 |
return true; |
413 |
} |
414 |
|
415 |
private bool SetChildSymbolMapping(ChildSymbol item) |
416 |
{ |
417 |
foreach (var childSymbol in item.ChildSymbols) |
418 |
{ |
419 |
ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME); |
420 |
childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null; |
421 |
if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME)) |
422 |
return false; |
423 |
else |
424 |
return SetChildSymbolMapping(childSymbol); |
425 |
} |
426 |
|
427 |
return true; |
428 |
} |
429 |
} |
430 |
} |