개정판 5e6ecf05
dev issue #000 : branch target 구하는 로직 추가(보안 필요)
Change-Id: Iac4e63f4c2cdbee58c5b7489b7d46e91c5cae942
DTI_PID/SPPIDConverter/AutoModeling.cs | ||
---|---|---|
13 | 13 |
using Converter.SPPID.Properties; |
14 | 14 |
using Converter.SPPID.Util; |
15 | 15 |
using Converter.SPPID.DB; |
16 |
|
|
16 |
using Ingr.RAD2D.MacroControls.CmdCtrl; |
|
17 |
using Ingr.RAD2D; |
|
17 | 18 |
using System.Windows; |
18 | 19 |
using System.Threading; |
19 | 20 |
using System.Drawing; |
... | ... | |
26 | 27 |
{ |
27 | 28 |
Placement _placement; |
28 | 29 |
LMADataSource dataSource; |
29 |
|
|
30 |
Ingr.RAD2D.Application radApp; |
|
30 | 31 |
SPPID_Document document; |
31 | 32 |
|
32 |
public AutoModeling(SPPID_Document document) |
|
33 |
public AutoModeling(SPPID_Document document, Ingr.RAD2D.Application radApp)
|
|
33 | 34 |
{ |
34 | 35 |
this.document = document; |
36 |
this.radApp = radApp; |
|
35 | 37 |
} |
36 | 38 |
|
37 | 39 |
public void Run() |
... | ... | |
44 | 46 |
//Thread.Sleep(100); |
45 | 47 |
//application.ActiveWindow.Zoom = 60; |
46 | 48 |
//Thread.Sleep(100); |
47 |
|
|
48 |
foreach (Equipment equipment in document.Equipments) |
|
49 |
{ |
|
50 |
SymbolModeling(equipment as Symbol, null, null); |
|
51 |
} |
|
52 |
|
|
53 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
|
49 |
try |
|
54 | 50 |
{ |
55 |
foreach (LineRun run in lineNumber.RUNS)
|
|
51 |
foreach (Equipment equipment in document.Equipments)
|
|
56 | 52 |
{ |
57 |
SymbolModelingByRun(run);
|
|
53 |
SymbolModeling(equipment as Symbol, null, null);
|
|
58 | 54 |
} |
59 |
} |
|
60 | 55 |
|
56 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
|
57 |
{ |
|
58 |
foreach (LineRun run in lineNumber.RUNS) |
|
59 |
{ |
|
60 |
SymbolModelingByRun(run); |
|
61 |
} |
|
62 |
} |
|
61 | 63 |
|
62 |
foreach (TrimLine trimLine in document.TRIMLINES) |
|
63 |
{ |
|
64 |
foreach (LineRun run in trimLine.RUNS) |
|
64 |
foreach (TrimLine trimLine in document.TRIMLINES) |
|
65 | 65 |
{ |
66 |
SymbolModelingByRun(run); |
|
66 |
foreach (LineRun run in trimLine.RUNS) |
|
67 |
{ |
|
68 |
SymbolModelingByRun(run); |
|
69 |
} |
|
67 | 70 |
} |
68 |
} |
|
69 | 71 |
|
70 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
|
71 |
{ |
|
72 |
foreach (LineRun run in lineNumber.RUNS) |
|
72 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
|
73 | 73 |
{ |
74 |
LineModelingByRun(run); |
|
74 |
foreach (LineRun run in lineNumber.RUNS) |
|
75 |
{ |
|
76 |
LineModelingByRun(run); |
|
77 |
} |
|
75 | 78 |
} |
76 |
} |
|
77 | 79 |
|
78 |
foreach (TrimLine trimLine in document.TRIMLINES) |
|
79 |
{ |
|
80 |
foreach (LineRun run in trimLine.RUNS) |
|
80 |
foreach (TrimLine trimLine in document.TRIMLINES) |
|
81 | 81 |
{ |
82 |
LineModelingByRun(run); |
|
82 |
foreach (LineRun run in trimLine.RUNS) |
|
83 |
{ |
|
84 |
LineModelingByRun(run); |
|
85 |
} |
|
83 | 86 |
} |
84 | 87 |
} |
85 |
|
|
86 |
|
|
87 |
ReleaseCOMObjects(dataSource); |
|
88 |
ReleaseCOMObjects(_placement); |
|
88 |
catch (Exception ex) |
|
89 |
{ |
|
90 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
|
91 |
} |
|
92 |
finally |
|
93 |
{ |
|
94 |
ReleaseCOMObjects(dataSource); |
|
95 |
ReleaseCOMObjects(_placement); |
|
96 |
} |
|
97 |
|
|
89 | 98 |
System.Windows.Forms.MessageBox.Show("end"); |
90 | 99 |
} |
91 | 100 |
|
... | ... | |
365 | 374 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
366 | 375 |
LMSymbol _LMSymbol1 = null; |
367 | 376 |
LMSymbol _LMSymbol2 = null; |
377 |
Dictionary<LMConnector, List<double[]>> connectorVertices1 = new Dictionary<LMConnector, List<double[]>>(); |
|
378 |
LMConnector targetConnector1 = null; |
|
379 |
Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>(); |
|
380 |
LMConnector targetConnector2 = null; |
|
368 | 381 |
for (int i = 0; i < lines.Count; i++) |
369 | 382 |
{ |
370 | 383 |
Line line = lines[i]; |
... | ... | |
380 | 393 |
else |
381 | 394 |
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
382 | 395 |
} |
396 |
else if (connItem != null && connItem.GetType() == typeof(Line)) |
|
397 |
{ |
|
398 |
connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId); |
|
399 |
targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y); |
|
400 |
|
|
401 |
if (targetConnector1 != null) |
|
402 |
placeRunInputs.AddConnectorTarget(targetConnector1, line.SPPID.START_X, line.SPPID.START_Y); |
|
403 |
else |
|
404 |
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
|
405 |
} |
|
383 | 406 |
else |
384 | 407 |
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
385 | 408 |
} |
... | ... | |
388 | 411 |
{ |
389 | 412 |
// 끝점에 연결된 Symbol 찾기 |
390 | 413 |
object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM); |
414 |
|
|
415 |
if (i != 0) |
|
416 |
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
|
417 |
|
|
391 | 418 |
if (connItem != null && connItem.GetType() == typeof(Symbol)) |
392 | 419 |
{ |
393 | 420 |
_LMSymbol2 = dataSource.GetSymbol(((Symbol)connItem).SPPID.RepresentationId); |
394 | 421 |
if (_LMSymbol2 != null) |
395 |
{ |
|
396 |
if (i != 0) |
|
397 |
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
|
398 |
|
|
399 | 422 |
placeRunInputs.AddSymbolTarget(_LMSymbol2, line.SPPID.END_X, line.SPPID.END_Y); |
400 |
} |
|
401 | 423 |
else |
402 |
{ |
|
403 |
if (i != 0) |
|
404 |
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
|
405 | 424 |
placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
406 |
} |
|
407 | 425 |
|
408 | 426 |
} |
427 |
else if (connItem != null && connItem.GetType() == typeof(Line)) |
|
428 |
{ |
|
429 |
connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId); |
|
430 |
targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y); |
|
431 |
|
|
432 |
if (targetConnector2 != null) |
|
433 |
placeRunInputs.AddConnectorTarget(targetConnector2, line.SPPID.END_X, line.SPPID.END_Y); |
|
434 |
else |
|
435 |
placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
|
436 |
} |
|
409 | 437 |
else |
410 | 438 |
{ |
411 |
if (i != 0) |
|
412 |
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
|
413 | 439 |
placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
414 | 440 |
} |
415 | 441 |
} |
... | ... | |
419 | 445 |
if (_lMConnector != null) |
420 | 446 |
{ |
421 | 447 |
foreach (var line in lines) |
422 |
line.SPPID.RepresentationId = _lMConnector.AsLMRepresentation().Id;
|
|
448 |
line.SPPID.ModelItemId = _lMConnector.ModelItemID;
|
|
423 | 449 |
_lMConnector.Commit(); |
424 | 450 |
} |
425 |
|
|
451 |
|
|
426 | 452 |
|
427 | 453 |
if (_LMSymbol1 != null) |
428 | 454 |
ReleaseCOMObjects(_LMSymbol1); |
429 | 455 |
if (_LMSymbol2 != null) |
430 | 456 |
ReleaseCOMObjects(_LMSymbol2); |
457 |
if (targetConnector1 != null) |
|
458 |
ReleaseCOMObjects(targetConnector1); |
|
459 |
if (targetConnector2 != null) |
|
460 |
ReleaseCOMObjects(targetConnector2); |
|
461 |
foreach (var item in connectorVertices1) |
|
462 |
ReleaseCOMObjects(item.Key); |
|
463 |
foreach (var item in connectorVertices2) |
|
464 |
ReleaseCOMObjects(item.Key); |
|
431 | 465 |
|
432 | 466 |
ReleaseCOMObjects(_lMConnector); |
433 | 467 |
ReleaseCOMObjects(placeRunInputs); |
434 | 468 |
ReleaseCOMObjects(_LMAItem); |
435 | 469 |
} |
436 | 470 |
|
471 |
private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId) |
|
472 |
{ |
|
473 |
Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>(); |
|
474 |
LMPipeRun _LMPipeRun = dataSource.GetPipeRun(modelId); |
|
475 |
if (_LMPipeRun != null) |
|
476 |
{ |
|
477 |
foreach (LMRepresentation rep in _LMPipeRun.Representations) |
|
478 |
{ |
|
479 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
|
480 |
{ |
|
481 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
|
482 |
connectorVertices.Add(_LMConnector, new List<double[]>()); |
|
483 |
dynamic OID = rep.get_GraphicOID(); |
|
484 |
Ingr.RAD2D.DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
|
485 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
|
486 |
int verticesCount = lineStringGeometry.VertexCount; |
|
487 |
double[] vertices = null; |
|
488 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
|
489 |
for (int i = 0; i < verticesCount; i++) |
|
490 |
{ |
|
491 |
double x = 0; |
|
492 |
double y = 0; |
|
493 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
|
494 |
connectorVertices[_LMConnector].Add(new double[] { x, y }); |
|
495 |
} |
|
496 |
} |
|
497 |
} |
|
498 |
|
|
499 |
ReleaseCOMObjects(_LMPipeRun); |
|
500 |
} |
|
501 |
|
|
502 |
return connectorVertices; |
|
503 |
} |
|
504 |
|
|
505 |
private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double x, double y) |
|
506 |
{ |
|
507 |
double length = double.MaxValue; |
|
508 |
LMConnector targetConnector = null; |
|
509 |
foreach (var item in connectorVertices) |
|
510 |
{ |
|
511 |
List<double[]> points = item.Value; |
|
512 |
for (int i = 0; i < points.Count - 1; i++) |
|
513 |
{ |
|
514 |
double[] point1 = points[i]; |
|
515 |
double[] point2 = points[i + 1]; |
|
516 |
|
|
517 |
double maxLineX = Math.Max(point1[0], point2[0]); |
|
518 |
double minLineX = Math.Min(point1[0], point2[0]); |
|
519 |
double maxLineY = Math.Max(point1[1], point2[1]); |
|
520 |
double minLineY = Math.Min(point1[1], point2[1]); |
|
521 |
|
|
522 |
// 두직선의 교차점으로 구하면 될듯 그리고 교차점이 x y랑 제일 가까운것 |
|
523 |
|
|
524 |
if ((minLineX <= x && maxLineX >= x) || |
|
525 |
(minLineY <= y && maxLineY >= y)) |
|
526 |
{ |
|
527 |
double result = SPPIDUtil.CalcLineToPointDistance(point1[0], point1[1], point2[0], point2[1], x, y); |
|
528 |
if (length > result) |
|
529 |
{ |
|
530 |
targetConnector = item.Key; |
|
531 |
length = result; |
|
532 |
} |
|
533 |
} |
|
534 |
} |
|
535 |
} |
|
536 |
|
|
537 |
return targetConnector; |
|
538 |
} |
|
539 |
|
|
437 | 540 |
private void LineNumberModeling(LineNumber lineNumber) |
438 | 541 |
{ |
439 | 542 |
|
내보내기 Unified diff