hytos / DTI_PID / SPPIDConverter_AutoModeling / Modeling / AutoModeling.cs @ 7a01d2c1
이력 | 보기 | 이력해설 | 다운로드 (35.3 KB)
1 |
using System; |
---|---|
2 |
using System.Windows.Forms; |
3 |
using System.Collections.Generic; |
4 |
using System.Drawing; |
5 |
using System.Linq; |
6 |
using System.Text; |
7 |
using System.Threading.Tasks; |
8 |
using System.Xml.Linq; |
9 |
using Llama; |
10 |
using Plaice; |
11 |
using SPPID.Model; |
12 |
using SPPID.Utill; |
13 |
using System.Diagnostics; |
14 |
using SPPIDConverter_AutoModeling; |
15 |
|
16 |
|
17 |
namespace SPPID.Modeling |
18 |
{ |
19 |
public class AutoModeling |
20 |
{ |
21 |
private Document document; |
22 |
|
23 |
|
24 |
public AutoModeling(Document doc) |
25 |
{ |
26 |
document = doc; |
27 |
} |
28 |
|
29 |
public void Run() |
30 |
{ |
31 |
CloseOPCForm.Run(); |
32 |
|
33 |
ProgressForm.SetProgressAllValue(0); |
34 |
|
35 |
// Group Symbol 실패시 Group Remove |
36 |
ProgressForm.UpdateStatus("Symbol Modeling"); |
37 |
ProgressForm.SetProgressStatusValue(0); |
38 |
ProgressForm.SetProgressStatusMax(document.SYMBOLS.Count); |
39 |
foreach (Group group in document.GROUPS) |
40 |
{ |
41 |
if (!GroupSymbolModeling(group)) |
42 |
{ |
43 |
group.Enable = false; |
44 |
} |
45 |
} |
46 |
ProgressForm.SetProgressStatusMax(); |
47 |
ProgressForm.IncreaseProgressAll(); |
48 |
System.Threading.Thread.Sleep(100); |
49 |
|
50 |
// Line Group은 Group 없을 때까지 Loop |
51 |
ProgressForm.UpdateStatus("Line Modeling"); |
52 |
ProgressForm.SetProgressStatusValue(0); |
53 |
ProgressForm.SetProgressStatusMax(document.LINES.Count); |
54 |
while (document.GROUPS.Count > 0) |
55 |
{ |
56 |
bool loopAction = false; |
57 |
foreach (Group group in document.GROUPS) |
58 |
{ |
59 |
if (!group.Enable) |
60 |
continue; |
61 |
|
62 |
if (IsPossibleDrawGroupLine(group)) |
63 |
{ |
64 |
loopAction = true; |
65 |
GroupLineModeling(group); |
66 |
document.GROUPS.Remove(group); |
67 |
break; |
68 |
} |
69 |
} |
70 |
if (!loopAction) |
71 |
break; |
72 |
} |
73 |
// Line Group Modeling 실패한 로그 |
74 |
foreach (Group group in document.GROUPS) |
75 |
{ |
76 |
foreach (SPPID_ITEM item in group.Items) |
77 |
{ |
78 |
Line line = item as Line; |
79 |
if (line != null && line.SPPID_ITEM_OBJECT == null) |
80 |
{ |
81 |
ProgressForm.IncreaseProgressStatus(); |
82 |
} |
83 |
} |
84 |
} |
85 |
ProgressForm.SetProgressStatusMax(); |
86 |
ProgressForm.IncreaseProgressAll(); |
87 |
System.Threading.Thread.Sleep(100); |
88 |
// End |
89 |
|
90 |
// SprecBreak Modeling |
91 |
ProgressForm.UpdateStatus("Spec Break Modeling"); |
92 |
ProgressForm.SetProgressStatusValue(0); |
93 |
ProgressForm.SetProgressStatusMax(document.SPECBREAK.Count); |
94 |
foreach (SpecBreak item in document.SPECBREAK) |
95 |
{ |
96 |
item.Modeling(document); |
97 |
item.SetAttribute(document); |
98 |
foreach (var result in item.SPPID_ITEM_OBJECT_LIST) |
99 |
{ |
100 |
LMLabelPersist label = result.Value; |
101 |
if (label != null) |
102 |
{ |
103 |
|
104 |
} |
105 |
else |
106 |
{ |
107 |
|
108 |
} |
109 |
} |
110 |
|
111 |
ProgressForm.IncreaseProgressStatus(); |
112 |
} |
113 |
ProgressForm.SetProgressStatusMax(); |
114 |
ProgressForm.IncreaseProgressAll(); |
115 |
System.Threading.Thread.Sleep(100); |
116 |
// End |
117 |
|
118 |
// Text Modeling |
119 |
ProgressForm.UpdateStatus("Text Modeling"); |
120 |
ProgressForm.SetProgressStatusValue(0); |
121 |
ProgressForm.SetProgressStatusMax(document.TEXTS.Count); |
122 |
foreach (Text text in document.TEXTS) |
123 |
{ |
124 |
text.Modeling(document); |
125 |
if (text.SPPID_ITEM_OBJECT != null || text.IsAssociation) |
126 |
{ |
127 |
|
128 |
} |
129 |
else |
130 |
{ |
131 |
|
132 |
} |
133 |
ProgressForm.IncreaseProgressStatus(); |
134 |
} |
135 |
ProgressForm.SetProgressStatusMax(); |
136 |
ProgressForm.IncreaseProgressAll(); |
137 |
System.Threading.Thread.Sleep(100); |
138 |
// End |
139 |
|
140 |
//// Line Number Attribute Modeling |
141 |
//ProgressForm.UpdateStatus("Input Line Number Attribute"); |
142 |
//ProgressForm.SetProgressStatusValue(0); |
143 |
//ProgressForm.SetProgressStatusMax(document.LINENUMBERS.Count); |
144 |
//foreach (LineNumber lineNumber in document.LINENUMBERS) |
145 |
//{ |
146 |
// lineNumber.SetAttribute(document); |
147 |
|
148 |
// ProgressForm.IncreaseProgressStatus(); |
149 |
//} |
150 |
//ProgressForm.SetProgressStatusMax(); |
151 |
//ProgressForm.IncreaseProgressAll(); |
152 |
//System.Threading.Thread.Sleep(100); |
153 |
//// End |
154 |
|
155 |
// Line Number Attribute Modeling |
156 |
ProgressForm.UpdateStatus("Input Line Number Attribute"); |
157 |
ProgressForm.SetProgressStatusValue(0); |
158 |
ProgressForm.SetProgressStatusMax(document.LINES.Count); |
159 |
foreach (Line line in document.LINES) |
160 |
{ |
161 |
line.SetAttribute(document); |
162 |
|
163 |
ProgressForm.IncreaseProgressStatus(); |
164 |
} |
165 |
ProgressForm.SetProgressStatusMax(); |
166 |
ProgressForm.IncreaseProgressAll(); |
167 |
System.Threading.Thread.Sleep(100); |
168 |
// End |
169 |
|
170 |
// attribute |
171 |
ProgressForm.UpdateStatus("Input Symbol Attribute"); |
172 |
ProgressForm.SetProgressStatusValue(0); |
173 |
ProgressForm.SetProgressStatusMax(document.SYMBOLS.Count); |
174 |
foreach (Symbol item in document.SYMBOLS) |
175 |
{ |
176 |
if (item.SPPID_ITEM_OBJECT != null) |
177 |
{ |
178 |
item.SetAttribute(document); |
179 |
} |
180 |
|
181 |
ProgressForm.IncreaseProgressStatus(); |
182 |
} |
183 |
ProgressForm.SetProgressStatusMax(); |
184 |
ProgressForm.IncreaseProgressAll(); |
185 |
System.Threading.Thread.Sleep(100); |
186 |
// End |
187 |
|
188 |
CloseOPCForm.Stop(); |
189 |
// |
190 |
//Log.WriteLine(new ListBoxItem(string.Format("Time : {0}", ts), Color.Black), logListBox); |
191 |
} |
192 |
|
193 |
private bool IsPossibleDrawGroupLine(Group group) |
194 |
{ |
195 |
foreach (SPPID_ITEM item in group.Items) |
196 |
{ |
197 |
if (item.GetType() == typeof(Symbol)) |
198 |
{ |
199 |
Symbol symbol = item as Symbol; |
200 |
foreach (Connector connector in symbol.CONNECTORS) |
201 |
{ |
202 |
SPPID_ITEM objItem = SPPIDUtill.FindObjectByUID(document, connector.CONNECTEDITEM) as SPPID_ITEM; |
203 |
if (objItem != null && !group.Items.Contains(objItem) && objItem.SPPID_ITEM_OBJECT == null) |
204 |
return false; |
205 |
} |
206 |
} |
207 |
else if (item.GetType() == typeof(Line)) |
208 |
{ |
209 |
Line line = item as Line; |
210 |
foreach (Connector connector in line.CONNECTORS) |
211 |
{ |
212 |
SPPID_ITEM objItem = SPPIDUtill.FindObjectByUID(document, connector.CONNECTEDITEM) as SPPID_ITEM; |
213 |
if (objItem != null && !group.Items.Contains(objItem) && objItem.SPPID_ITEM_OBJECT == null) |
214 |
return false; |
215 |
} |
216 |
} |
217 |
} |
218 |
|
219 |
return true; |
220 |
} |
221 |
|
222 |
#region Modeling |
223 |
|
224 |
private bool GroupSymbolModeling(Group group) |
225 |
{ |
226 |
List<object> Items = group.Items; |
227 |
Symbol prevSymbol = null; |
228 |
int prevIndex = 0; |
229 |
bool result = true; |
230 |
|
231 |
for (int itemIndex = 0; itemIndex < Items.Count(); itemIndex++) |
232 |
{ |
233 |
Line.SlopeType prevSlope = Line.SlopeType.NONE; |
234 |
Symbol symbol = Items[itemIndex] as Symbol; |
235 |
try |
236 |
{ |
237 |
if (symbol != null) |
238 |
{ |
239 |
ProgressForm.IncreaseProgressStatus(); |
240 |
// Group중에 최근에 Modeling된 Symbol |
241 |
if (prevSymbol != null) |
242 |
{ |
243 |
LMSymbol prevLMSymbol = prevSymbol.SPPID_ITEM_OBJECT as LMSymbol; |
244 |
for (int prevLineIndex = prevIndex + 1; prevLineIndex < itemIndex; prevLineIndex++) |
245 |
{ |
246 |
Line prevLine = Items[prevLineIndex] as Line; |
247 |
if (prevLine != null) |
248 |
{ |
249 |
if (prevSlope == Line.SlopeType.NONE) |
250 |
{ |
251 |
prevSlope = prevLine.SLOPTYPE; |
252 |
} |
253 |
else if (prevSlope != prevLine.SLOPTYPE) |
254 |
{ |
255 |
prevSlope = Line.SlopeType.NONE; |
256 |
break; |
257 |
} |
258 |
} |
259 |
} |
260 |
|
261 |
if (prevSlope == Line.SlopeType.HORIZONTAL) |
262 |
symbol.LOCATION_Y = prevLMSymbol.get_YCoordinate(); |
263 |
else if (prevSlope == Line.SlopeType.VERTICAL) |
264 |
symbol.LOCATION_X = prevLMSymbol.get_XCoordinate(); |
265 |
} |
266 |
|
267 |
symbol.Modeling(document); |
268 |
if (symbol.SPPID_ITEM_OBJECT != null) |
269 |
{ |
270 |
prevSymbol = symbol; |
271 |
prevIndex = itemIndex; |
272 |
} |
273 |
else |
274 |
{ |
275 |
result = false; |
276 |
} |
277 |
} |
278 |
} |
279 |
catch (Exception ex) |
280 |
{ |
281 |
result = false; |
282 |
return result; |
283 |
} |
284 |
finally |
285 |
{ |
286 |
|
287 |
} |
288 |
} |
289 |
|
290 |
return result; |
291 |
} |
292 |
|
293 |
private bool GroupLineModeling(Group group) |
294 |
{ |
295 |
try |
296 |
{ |
297 |
List<object> Items = group.Items; |
298 |
List<Line> lineList = new List<Line>(); |
299 |
foreach (SPPID_ITEM item in Items) |
300 |
{ |
301 |
Line line = item as Line; |
302 |
if (line != null) |
303 |
lineList.Add(line); |
304 |
else if (lineList.Count > 0) |
305 |
{ |
306 |
GroupLineModelingByList(lineList, group); |
307 |
} |
308 |
} |
309 |
|
310 |
if (lineList.Count > 0) |
311 |
GroupLineModelingByList(lineList, group); |
312 |
} |
313 |
catch (Exception ex) |
314 |
{ |
315 |
Log.WriteLine(ex); |
316 |
return false; |
317 |
} |
318 |
|
319 |
return true; |
320 |
} |
321 |
|
322 |
private void GroupLineModelingByList(List<Line> lines, Group group) |
323 |
{ |
324 |
List<PointInfo> pointInfos = GetLinePointInfos(lines, group); |
325 |
LMConnector lMConnector = DrawLines(pointInfos, lines[0].SPPIDMAPPINGNAME, lines); |
326 |
|
327 |
if (lMConnector != null) |
328 |
{ |
329 |
string modelId = lMConnector.ModelItemID; |
330 |
document.PipeRunPoint.Add(lMConnector.ModelItemID, pointInfos); |
331 |
foreach (Line line in lines) |
332 |
{ |
333 |
line.SPPID_ITEM_OBJECT = modelId; |
334 |
IfContainLineNumber(line.UID); |
335 |
} |
336 |
} |
337 |
else |
338 |
{ |
339 |
foreach (Line line in lines) |
340 |
{ |
341 |
//Log.WriteLine(new ListBoxItem(string.Format("Fail Line UID : {0}", line.UID), Color.Red), logListBox); |
342 |
//Log.ProgressBarIncrement(progressBar); |
343 |
} |
344 |
} |
345 |
|
346 |
for (int i = 0; i < lines.Count; i++) |
347 |
ProgressForm.IncreaseProgressStatus(); |
348 |
|
349 |
lines.Clear(); |
350 |
} |
351 |
|
352 |
private void IfContainLineNumber(string lineUID) |
353 |
{ |
354 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
355 |
{ |
356 |
if (lineNumber.CONNECTLINE == lineUID) |
357 |
{ |
358 |
lineNumber.Modeling(document); |
359 |
|
360 |
if (lineNumber.SPPID_ITEM_OBJECT != null) |
361 |
{ |
362 |
|
363 |
} |
364 |
else |
365 |
{ |
366 |
|
367 |
} |
368 |
break; |
369 |
} |
370 |
} |
371 |
} |
372 |
|
373 |
private LMConnector DrawLines(List<PointInfo> pointInfos, string SPPID_MAPPINGNAME, List<Line> lines) |
374 |
{ |
375 |
LMConnector lMConnector = null; |
376 |
try |
377 |
{ |
378 |
Placement _placement = new Placement(); |
379 |
_LMAItem _LMAItem = _placement.PIDCreateItem(SPPID_MAPPINGNAME); |
380 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
381 |
|
382 |
PointInfo branchPoint1 = null; |
383 |
PointInfo branchPoint1_1 = null; |
384 |
int branchIndex1 = 0; |
385 |
List<string> branch_SP_ID_List1 = null; |
386 |
PointInfo branchPoint2 = null; |
387 |
PointInfo branchPoint2_1 = null; |
388 |
int branchIndex2 = 0; |
389 |
List<string> branch_SP_ID_List2 = null; |
390 |
|
391 |
|
392 |
for (int pointIndex = 0; pointIndex < pointInfos.Count; pointIndex++) |
393 |
{ |
394 |
PointInfo pointInfo = pointInfos[pointIndex]; |
395 |
if (pointIndex == 0 || pointIndex == pointInfos.Count - 1) |
396 |
{ |
397 |
if (pointInfo.ConnectedItemObject == null) |
398 |
{ |
399 |
placeRunInputs.AddPoint(pointInfo.X, pointInfo.Y); |
400 |
} |
401 |
else |
402 |
{ |
403 |
if (typeof(Symbol) == pointInfo.ConnectedItemObject.GetType()) |
404 |
{ |
405 |
Symbol symbol = pointInfo.ConnectedItemObject as Symbol; |
406 |
//check child |
407 |
List<string> linesUID = new List<string>(); |
408 |
foreach (Line line in lines) |
409 |
linesUID.Add(line.UID); |
410 |
|
411 |
int symbolIndex = 0; |
412 |
foreach (Connector connector in symbol.CONNECTORS) |
413 |
{ |
414 |
if (linesUID.Contains(connector.CONNECTEDITEM)) |
415 |
{ |
416 |
symbolIndex = connector.INDEX; |
417 |
break; |
418 |
} |
419 |
} |
420 |
LMSymbol tartgetLMSymbol = null; |
421 |
if (symbolIndex == 0) |
422 |
tartgetLMSymbol = symbol.SPPID_ITEM_OBJECT as LMSymbol; |
423 |
else |
424 |
{ |
425 |
foreach (SymbolChild child in symbol.CHILD_LIST) |
426 |
{ |
427 |
if (child.Index == symbolIndex) |
428 |
{ |
429 |
tartgetLMSymbol = child.SPPID_ITEM_OBJECT as LMSymbol; |
430 |
break; |
431 |
} |
432 |
} |
433 |
} |
434 |
|
435 |
placeRunInputs.AddSymbolTarget(tartgetLMSymbol, pointInfo.X, pointInfo.Y); |
436 |
pointInfo.Type = PointInfo.PointType.Branch; |
437 |
} |
438 |
else if (typeof(Line) == pointInfo.ConnectedItemObject.GetType()) |
439 |
{ |
440 |
Line line = pointInfo.ConnectedItemObject as Line; |
441 |
Tuple<LMConnector, int> targetLMConnector = GetTargetLMConnector(pointInfo); |
442 |
if (targetLMConnector != null) |
443 |
{ |
444 |
if (targetLMConnector.Item1 != null) |
445 |
{ |
446 |
if (branchPoint1 == null) |
447 |
{ |
448 |
placeRunInputs.AddConnectorTarget(targetLMConnector.Item1, pointInfo.X, pointInfo.Y); |
449 |
pointInfo.Type = PointInfo.PointType.Branch; |
450 |
branchPoint1 = new PointInfo(pointInfo.X, pointInfo.Y); |
451 |
branchPoint1.Type = PointInfo.PointType.Branch; |
452 |
branchPoint1.ConnectedItem = pointInfo.ConnectedItem; |
453 |
branchPoint1.ConnectedItemObject = pointInfo.ConnectedItemObject; |
454 |
branchIndex1 = targetLMConnector.Item2; |
455 |
branchPoint1_1 = pointInfo; |
456 |
|
457 |
branch_SP_ID_List1 = new List<string>(); |
458 |
LMPipeRun lMPipeRun = _placement.PIDDataSource.GetPipeRun(line.SPPID_ITEM_OBJECT.ToString()); |
459 |
foreach (LMRepresentation rep in lMPipeRun.Representations) |
460 |
if (rep.Attributes["RepresentationType"].get_Value() == "Branch" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
461 |
branch_SP_ID_List1.Add(rep.Id); |
462 |
} |
463 |
else |
464 |
{ |
465 |
placeRunInputs.AddConnectorTarget(targetLMConnector.Item1, pointInfo.X, pointInfo.Y); |
466 |
pointInfo.Type = PointInfo.PointType.Branch; |
467 |
branchPoint2 = new PointInfo(pointInfo.X, pointInfo.Y); |
468 |
branchPoint2.Type = PointInfo.PointType.Branch; |
469 |
branchPoint2.ConnectedItem = pointInfo.ConnectedItem; |
470 |
branchPoint2.ConnectedItemObject = pointInfo.ConnectedItemObject; |
471 |
branchIndex2 = targetLMConnector.Item2; |
472 |
branchPoint2_1 = pointInfo; |
473 |
|
474 |
branch_SP_ID_List2 = new List<string>(); |
475 |
LMPipeRun lMPipeRun = _placement.PIDDataSource.GetPipeRun(line.SPPID_ITEM_OBJECT.ToString()); |
476 |
foreach (LMRepresentation rep in lMPipeRun.Representations) |
477 |
if (rep.Attributes["RepresentationType"].get_Value() == "Branch" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
478 |
branch_SP_ID_List2.Add(rep.Id); |
479 |
} |
480 |
} |
481 |
else |
482 |
{ |
483 |
placeRunInputs.AddPoint(pointInfo.X, pointInfo.Y); |
484 |
pointInfo.Type = PointInfo.PointType.Run; |
485 |
} |
486 |
} |
487 |
else |
488 |
{ |
489 |
placeRunInputs.AddPoint(pointInfo.X, pointInfo.Y); |
490 |
pointInfo.Type = PointInfo.PointType.Run; |
491 |
} |
492 |
} |
493 |
} |
494 |
} |
495 |
else |
496 |
{ |
497 |
placeRunInputs.AddPoint(pointInfo.X, pointInfo.Y); |
498 |
pointInfo.Type = PointInfo.PointType.Run; |
499 |
} |
500 |
} |
501 |
|
502 |
lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
503 |
lMConnector.Commit(); |
504 |
|
505 |
// Branch Point Setting |
506 |
if (branchPoint1 != null) |
507 |
{ |
508 |
Line branchedLine = branchPoint1.ConnectedItemObject as Line; |
509 |
LMPipeRun lMPipeRun = _placement.PIDDataSource.GetPipeRun(branchedLine.SPPID_ITEM_OBJECT.ToString()); |
510 |
foreach (LMRepresentation rep in lMPipeRun.Representations) |
511 |
if (rep.Attributes["RepresentationType"].get_Value() == "Branch" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
512 |
{ |
513 |
if (!branch_SP_ID_List1.Contains(rep.Id)) |
514 |
{ |
515 |
branchPoint1.SP_ID = rep.Id; |
516 |
branchPoint1_1.SP_ID = rep.Id; |
517 |
document.PipeRunPoint[branchedLine.SPPID_ITEM_OBJECT.ToString()].Insert(branchIndex1, branchPoint1); |
518 |
break; |
519 |
} |
520 |
} |
521 |
|
522 |
if (string.IsNullOrEmpty(branchPoint1.SP_ID)) |
523 |
{ |
524 |
document.PipeRunPoint[branchedLine.SPPID_ITEM_OBJECT.ToString()].RemoveAt(branchIndex1); |
525 |
branchPoint1_1.Type = PointInfo.PointType.Run; |
526 |
} |
527 |
} |
528 |
if (branchPoint2 != null) |
529 |
{ |
530 |
Line branchedLine = branchPoint2.ConnectedItemObject as Line; |
531 |
LMPipeRun lMPipeRun = _placement.PIDDataSource.GetPipeRun(branchedLine.SPPID_ITEM_OBJECT.ToString()); |
532 |
foreach (LMRepresentation rep in lMPipeRun.Representations) |
533 |
if (rep.Attributes["RepresentationType"].get_Value() == "Branch" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
534 |
{ |
535 |
if (!branch_SP_ID_List2.Contains(rep.Id)) |
536 |
{ |
537 |
branchPoint2.SP_ID = rep.Id; |
538 |
branchPoint2_1.SP_ID = rep.Id; |
539 |
document.PipeRunPoint[branchedLine.SPPID_ITEM_OBJECT.ToString()].Insert(branchIndex2, branchPoint2); |
540 |
break; |
541 |
} |
542 |
} |
543 |
|
544 |
if (string.IsNullOrEmpty(branchPoint2.SP_ID)) |
545 |
{ |
546 |
document.PipeRunPoint[branchedLine.SPPID_ITEM_OBJECT.ToString()].RemoveAt(branchIndex2); |
547 |
branchPoint2_1.Type = PointInfo.PointType.Run; |
548 |
} |
549 |
} |
550 |
// End |
551 |
} |
552 |
catch (Exception ex) |
553 |
{ |
554 |
Log.WriteLine(ex); |
555 |
} |
556 |
|
557 |
return lMConnector; |
558 |
} |
559 |
|
560 |
private List<PointInfo> GetLinePointInfos(List<Line> lineList, Group group) |
561 |
{ |
562 |
// Line들의 points를 구함 |
563 |
List<PointInfo> pointInfos = new List<PointInfo>(); |
564 |
if (lineList.Count == 1) |
565 |
{ |
566 |
pointInfos.Add(new PointInfo(lineList[0].START_X, lineList[0].START_Y) { ConnectedItem = lineList[0].CONNECTORS[0].CONNECTEDITEM }); |
567 |
pointInfos.Add(new PointInfo(lineList[0].END_X, lineList[0].END_Y) { ConnectedItem = lineList[0].CONNECTORS[1].CONNECTEDITEM }); |
568 |
} |
569 |
else |
570 |
{ |
571 |
for (int i = 0; i < lineList.Count; i++) |
572 |
if (lineList.Count > i + 1) |
573 |
GetLinePoints(lineList[i], lineList[i + 1], pointInfos); |
574 |
} |
575 |
|
576 |
// 맨앞 뒤의 ConnectedItem 구함 |
577 |
for (int i = 0; i < pointInfos.Count; i++) |
578 |
{ |
579 |
PointInfo info = pointInfos[i]; |
580 |
if (i == 0 || pointInfos.Count - 1 == i) |
581 |
{ |
582 |
info.ConnectedItemObject = SPPIDUtill.FindObjectByUID(document, info.ConnectedItem) as SPPID_ITEM; |
583 |
|
584 |
if (info.ConnectedItemObject == null) |
585 |
{ |
586 |
info.Type = PointInfo.PointType.Run; |
587 |
} |
588 |
else |
589 |
{ |
590 |
if (info.ConnectedItemObject.GetType() == typeof(Symbol)) |
591 |
{ |
592 |
Symbol symbol = info.ConnectedItemObject as Symbol; |
593 |
LMSymbol _lmSymbol = symbol.SPPID_ITEM_OBJECT as LMSymbol; |
594 |
info.SP_ID = _lmSymbol.AsLMRepresentation().Id; |
595 |
} |
596 |
info.Type = PointInfo.PointType.Branch; |
597 |
} |
598 |
} |
599 |
else |
600 |
{ |
601 |
info.ConnectedItem = string.Empty; |
602 |
info.Type = PointInfo.PointType.Run; |
603 |
} |
604 |
|
605 |
} |
606 |
|
607 |
// 라인 보정 |
608 |
CalibratePointInfos(pointInfos, lineList); |
609 |
|
610 |
return pointInfos; |
611 |
} |
612 |
|
613 |
private void GetLinePoints(Line line, Line nextLine, List<PointInfo> pointInfos) |
614 |
{ |
615 |
if (nextLine != null) |
616 |
{ |
617 |
if (pointInfos.Count > 0) |
618 |
pointInfos.RemoveRange(pointInfos.Count - 2, 2); |
619 |
|
620 |
if (line.CONNECTORS[0].CONNECTEDITEM == nextLine.UID) |
621 |
{ |
622 |
pointInfos.Add(new PointInfo(line.END_X, line.END_Y) { ConnectedItem = line.CONNECTORS[1].CONNECTEDITEM }); |
623 |
pointInfos.Add(new PointInfo(line.START_X, line.START_Y) { ConnectedItem = line.CONNECTORS[0].CONNECTEDITEM }); |
624 |
|
625 |
if (nextLine.CONNECTORS[0].CONNECTEDITEM == line.UID) |
626 |
pointInfos.Add(new PointInfo(nextLine.END_X, nextLine.END_Y) { ConnectedItem = nextLine.CONNECTORS[1].CONNECTEDITEM }); |
627 |
else if (nextLine.CONNECTORS[1].CONNECTEDITEM == line.UID) |
628 |
pointInfos.Add(new PointInfo(nextLine.START_X, nextLine.START_Y) { ConnectedItem = nextLine.CONNECTORS[0].CONNECTEDITEM }); |
629 |
|
630 |
} |
631 |
else if (line.CONNECTORS[1].CONNECTEDITEM == nextLine.UID) |
632 |
{ |
633 |
pointInfos.Add(new PointInfo(line.START_X, line.START_Y) { ConnectedItem = line.CONNECTORS[0].CONNECTEDITEM }); |
634 |
pointInfos.Add(new PointInfo(line.END_X, line.END_Y) { ConnectedItem = line.CONNECTORS[1].CONNECTEDITEM }); |
635 |
|
636 |
if (nextLine.CONNECTORS[0].CONNECTEDITEM == line.UID) |
637 |
pointInfos.Add(new PointInfo(nextLine.END_X, nextLine.END_Y) { ConnectedItem = nextLine.CONNECTORS[1].CONNECTEDITEM }); |
638 |
else if (nextLine.CONNECTORS[1].CONNECTEDITEM == line.UID) |
639 |
pointInfos.Add(new PointInfo(nextLine.START_X, nextLine.START_Y) { ConnectedItem = nextLine.CONNECTORS[0].CONNECTEDITEM }); |
640 |
} |
641 |
} |
642 |
} |
643 |
|
644 |
private void CalibratePointInfos(List<PointInfo> pointInfos, List<Line> lines) |
645 |
{ |
646 |
// 맨 앞이 Symbol일 경우 |
647 |
if (pointInfos[0].ConnectedItemObject != null && typeof(Symbol) == pointInfos[0].ConnectedItemObject.GetType()) |
648 |
{ |
649 |
PointInfo startPoint = pointInfos[0]; |
650 |
PointInfo nextPoint = pointInfos[1]; |
651 |
|
652 |
Symbol symbol = startPoint.ConnectedItemObject as Symbol; |
653 |
LMSymbol _LMSymbol = symbol.SPPID_ITEM_OBJECT as LMSymbol; |
654 |
double symbolX = _LMSymbol.get_XCoordinate(); |
655 |
double symbolY = _LMSymbol.get_YCoordinate(); |
656 |
|
657 |
if (lines[0].SLOPTYPE == Line.SlopeType.HORIZONTAL) |
658 |
{ |
659 |
startPoint.Y = symbolY; |
660 |
nextPoint.Y = symbolY; |
661 |
} |
662 |
else if (lines[0].SLOPTYPE == Line.SlopeType.VERTICAL) |
663 |
{ |
664 |
startPoint.X = symbolX; |
665 |
nextPoint.X = symbolX; |
666 |
} |
667 |
} |
668 |
// 맨 뒤가 Symbol일 경우 |
669 |
else if (pointInfos[pointInfos.Count - 1].ConnectedItemObject != null && typeof(Symbol) == pointInfos[pointInfos.Count - 1].ConnectedItemObject.GetType()) |
670 |
{ |
671 |
PointInfo startPoint = pointInfos[pointInfos.Count - 1]; |
672 |
PointInfo nextPoint = pointInfos[pointInfos.Count - 2]; |
673 |
|
674 |
Symbol symbol = startPoint.ConnectedItemObject as Symbol; |
675 |
LMSymbol _LMSymbol = symbol.SPPID_ITEM_OBJECT as LMSymbol; |
676 |
double symbolX = _LMSymbol.get_XCoordinate(); |
677 |
double symbolY = _LMSymbol.get_YCoordinate(); |
678 |
|
679 |
if (lines[lines.Count - 1].SLOPTYPE == Line.SlopeType.HORIZONTAL) |
680 |
{ |
681 |
startPoint.Y = symbolY; |
682 |
nextPoint.Y = symbolY; |
683 |
} |
684 |
else if (lines[lines.Count - 1].SLOPTYPE == Line.SlopeType.VERTICAL) |
685 |
{ |
686 |
startPoint.X = symbolX; |
687 |
nextPoint.X = symbolX; |
688 |
} |
689 |
} |
690 |
} |
691 |
|
692 |
private Tuple<LMConnector, int> GetTargetLMConnector(PointInfo pointInfo) |
693 |
{ |
694 |
LMConnector lMConnector = null; |
695 |
int insertIndex = 0; |
696 |
try |
697 |
{ |
698 |
Line line = pointInfo.ConnectedItemObject as Line; |
699 |
if (line.SPPID_ITEM_OBJECT == null) |
700 |
return null; |
701 |
|
702 |
string modelId = line.SPPID_ITEM_OBJECT.ToString(); |
703 |
List<PointInfo> pointInfos = document.PipeRunPoint[modelId]; |
704 |
double distance = double.MaxValue; |
705 |
|
706 |
PointInfo point1 = new PointInfo(0, 0); |
707 |
PointInfo point2 = new PointInfo(0, 0); |
708 |
|
709 |
for (int i = 0; i < pointInfos.Count - 1; i++) |
710 |
{ |
711 |
PointInfo tempPoint1 = pointInfos[i]; |
712 |
PointInfo tempPoint2 = pointInfos[i + 1]; |
713 |
|
714 |
double tempDistance = double.MaxValue; |
715 |
|
716 |
Line.SlopeType slopeType = SPPIDUtill.CalcSlop(tempPoint1, tempPoint2); |
717 |
if (slopeType == Line.SlopeType.HORIZONTAL) |
718 |
{ |
719 |
double min = Math.Min(tempPoint1.X, tempPoint2.X); |
720 |
double max = Math.Max(tempPoint1.X, tempPoint2.X); |
721 |
|
722 |
if (min <= pointInfo.X && max >= pointInfo.X) |
723 |
tempDistance = SPPIDUtill.CalcLineToPointDistance(tempPoint1, tempPoint2, pointInfo); |
724 |
} |
725 |
else if (slopeType == Line.SlopeType.VERTICAL) |
726 |
{ |
727 |
double min = Math.Min(tempPoint1.Y, tempPoint2.Y); |
728 |
double max = Math.Max(tempPoint1.Y, tempPoint2.Y); |
729 |
|
730 |
if (min <= pointInfo.Y && max >= pointInfo.Y) |
731 |
tempDistance = SPPIDUtill.CalcLineToPointDistance(tempPoint1, tempPoint2, pointInfo); |
732 |
} |
733 |
else |
734 |
{ |
735 |
tempDistance = SPPIDUtill.CalcLineToPointDistance(tempPoint1, tempPoint2, pointInfo); |
736 |
} |
737 |
|
738 |
if (tempDistance < distance) |
739 |
{ |
740 |
insertIndex = i + 1; |
741 |
distance = tempDistance; |
742 |
point1 = tempPoint1; |
743 |
point2 = tempPoint2; |
744 |
} |
745 |
} |
746 |
|
747 |
if (point1.Type == PointInfo.PointType.Run) |
748 |
lMConnector = GetLMConnectorByPoint(modelId, point1); |
749 |
else if (point2.Type == PointInfo.PointType.Run) |
750 |
lMConnector = GetLMConnectorByPoint(modelId, point2); |
751 |
else |
752 |
lMConnector = GetLMConnectorBySP_ID(modelId, point1.SP_ID, point2.SP_ID); |
753 |
} |
754 |
catch (Exception ex) |
755 |
{ |
756 |
Log.WriteLine(ex); |
757 |
return null; |
758 |
} |
759 |
|
760 |
if (lMConnector == null) |
761 |
return null; |
762 |
else |
763 |
return new Tuple<LMConnector, int>(lMConnector, insertIndex); |
764 |
} |
765 |
|
766 |
private LMConnector GetLMConnectorByPoint(string modelId, PointInfo pointInfo) |
767 |
{ |
768 |
LMConnector lMConnector = null; |
769 |
|
770 |
try |
771 |
{ |
772 |
Placement _placement = new Placement(); |
773 |
double distance = double.MaxValue; |
774 |
LMPipeRun lMPipeRun = _placement.PIDDataSource.GetPipeRun(modelId); |
775 |
if (lMPipeRun != null) |
776 |
{ |
777 |
foreach (LMRepresentation rep in lMPipeRun.Representations) |
778 |
{ |
779 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
780 |
{ |
781 |
LMConnector _tempLMConnector = _placement.PIDDataSource.GetConnector(rep.Id); |
782 |
foreach (LMConnectorVertex vertex in _tempLMConnector.ConnectorVertices) |
783 |
{ |
784 |
double tempDistance = SPPIDUtill.CalcPointToPointdDistance(pointInfo, new PointInfo(vertex.get_XCoordinate(), vertex.get_YCoordinate())); |
785 |
|
786 |
if (tempDistance < distance) |
787 |
{ |
788 |
distance = tempDistance; |
789 |
lMConnector = _tempLMConnector; |
790 |
} |
791 |
} |
792 |
|
793 |
} |
794 |
} |
795 |
} |
796 |
} |
797 |
catch (Exception ex) |
798 |
{ |
799 |
Log.WriteLine(ex); |
800 |
} |
801 |
|
802 |
|
803 |
return lMConnector; |
804 |
} |
805 |
|
806 |
private LMConnector GetLMConnectorBySP_ID(string modelId, string SP_ID1, string SP_ID2) |
807 |
{ |
808 |
Placement _placement = new Placement(); |
809 |
|
810 |
LMPipeRun lMPipeRun = _placement.PIDDataSource.GetPipeRun(modelId); |
811 |
foreach (LMRepresentation rep in lMPipeRun.Representations) |
812 |
{ |
813 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
814 |
{ |
815 |
LMConnector _tempLMConnector = _placement.PIDDataSource.GetConnector(rep.Id); |
816 |
|
817 |
bool find1 = false; |
818 |
bool find2 = false; |
819 |
|
820 |
if (_tempLMConnector.ConnectItem1SymbolID != null && !DBNull.Value.Equals(_tempLMConnector.ConnectItem1SymbolID)) |
821 |
{ |
822 |
string connId = _tempLMConnector.ConnectItem1SymbolID; |
823 |
if (connId == SP_ID1 || connId == SP_ID2) |
824 |
find1 = true; |
825 |
} |
826 |
|
827 |
if (_tempLMConnector.ConnectItem2SymbolID != null && !DBNull.Value.Equals(_tempLMConnector.ConnectItem2SymbolID)) |
828 |
{ |
829 |
string connId = _tempLMConnector.ConnectItem2SymbolID; |
830 |
if (connId == SP_ID1 || connId == SP_ID2) |
831 |
find2 = true; |
832 |
} |
833 |
|
834 |
|
835 |
if (find1 && find2) |
836 |
{ |
837 |
return _tempLMConnector; |
838 |
} |
839 |
} |
840 |
} |
841 |
return null; |
842 |
} |
843 |
|
844 |
#endregion |
845 |
|
846 |
} |
847 |
} |