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