개정판 a0e3dca4
dev issue #706 : Line modeling 수정 / ValidationCheck 추가 / 우선순위 Modeling 적용 / 에러 메시지 추가
Change-Id: I382716081a63a8fa2ac2b983ac7194c0c4b57ce7
DTI_PID/SPPIDConverter/AutoModeling.cs | ||
---|---|---|
38 | 38 |
public string DocumentLabelText { get; set; } |
39 | 39 |
|
40 | 40 |
int CurrentCount; |
41 |
List<Line> NewBranchLines = new List<Line>(); |
|
41 | 42 |
List<Tuple<string, Line, Line>> BranchLines = new List<Tuple<string, Line, Line>>(); |
42 | 43 |
List<string> ZeroLengthModelItemID = new List<string>(); |
43 | 44 |
List<Symbol> prioritySymbols; |
... | ... | |
117 | 118 |
|
118 | 119 |
if (DocumentCoordinateCorrection()) |
119 | 120 |
{ |
121 |
SetSystemEditingCommand(false); |
|
122 |
|
|
120 | 123 |
int AllCount = CalcProgressCount(); |
121 | 124 |
Log.Write("Start Modeling"); |
122 | 125 |
SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true); |
... | ... | |
159 | 162 |
} |
160 | 163 |
|
161 | 164 |
SetPriorityLine(); |
162 |
// LineRun Symbol Modeling |
|
163 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbols Modeling"); |
|
164 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
|
165 |
try |
|
166 |
{ |
|
167 |
foreach (LineRun run in lineNumber.RUNS) |
|
168 |
SymbolModelingByRun(run); |
|
169 |
} |
|
170 |
catch (Exception ex) |
|
171 |
{ |
|
172 |
Log.Write("Error in SymbolModelingByRun"); |
|
173 |
Log.Write("UID : " + lineNumber.UID); |
|
174 |
Log.Write(ex.Message); |
|
175 |
Log.Write(ex.StackTrace); |
|
176 |
} |
|
177 |
// TrimLineRun Symbol Modeling |
|
178 |
foreach (TrimLine trimLine in document.TRIMLINES) |
|
179 |
try |
|
180 |
{ |
|
181 |
foreach (LineRun run in trimLine.RUNS) |
|
182 |
SymbolModelingByRun(run); |
|
183 |
} |
|
184 |
catch (Exception ex) |
|
185 |
{ |
|
186 |
Log.Write("Error in SymbolModelingByRun"); |
|
187 |
Log.Write("UID : " + trimLine.UID); |
|
188 |
Log.Write(ex.Message); |
|
189 |
Log.Write(ex.StackTrace); |
|
190 |
} |
|
191 |
|
|
192 |
|
|
193 | 165 |
// LineRun Line Modeling |
194 | 166 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Lines Modeling"); |
195 |
|
|
196 | 167 |
foreach (var item in document.LINES) |
197 | 168 |
{ |
198 |
|
|
169 |
NewLineModeling(item); |
|
199 | 170 |
} |
200 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
|
201 |
try |
|
202 |
{ |
|
203 |
foreach (LineRun run in lineNumber.RUNS) |
|
204 |
LineModelingByRun(run); |
|
205 |
} |
|
206 |
catch (Exception ex) |
|
207 |
{ |
|
208 |
Log.Write("Error in LineModelingByRun"); |
|
209 |
Log.Write("UID : " + lineNumber.UID); |
|
210 |
Log.Write(ex.Message); |
|
211 |
Log.Write(ex.StackTrace); |
|
212 |
} |
|
213 |
// TrimLineRun Line Modeling |
|
214 |
foreach (TrimLine trimLine in document.TRIMLINES) |
|
215 |
try |
|
216 |
{ |
|
217 |
foreach (LineRun run in trimLine.RUNS) |
|
218 |
LineModelingByRun(run); |
|
219 |
} |
|
220 |
catch (Exception ex) |
|
221 |
{ |
|
222 |
Log.Write("Error in LineModelingByRun"); |
|
223 |
Log.Write("UID : " + trimLine.UID); |
|
224 |
Log.Write(ex.Message); |
|
225 |
Log.Write(ex.StackTrace); |
|
226 |
} |
|
227 |
|
|
228 | 171 |
|
229 |
// Branch Line Modeling |
|
230 | 172 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Branch Lines Modeling"); |
231 |
foreach (var item in BranchLines) |
|
232 |
try |
|
233 |
{ |
|
234 |
BranchLineModeling(item); |
|
235 |
} |
|
236 |
catch (Exception ex) |
|
237 |
{ |
|
238 |
Log.Write("Error in BranchLineModeling"); |
|
239 |
if (item.Item2 != null) |
|
240 |
Log.Write("UID : " + item.Item2.UID); |
|
241 |
if (item.Item3 != null) |
|
242 |
Log.Write("UID : " + item.Item3.UID); |
|
243 |
Log.Write(ex.Message); |
|
244 |
Log.Write(ex.StackTrace); |
|
245 |
} |
|
173 |
while (NewBranchLines.Count > 0) |
|
174 |
{ |
|
175 |
SortBranchLines(); |
|
176 |
NewLineModeling(NewBranchLines[0], true); |
|
177 |
} |
|
246 | 178 |
|
247 | 179 |
// EndBreak Modeling |
248 | 180 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling"); |
... | ... | |
569 | 501 |
} |
570 | 502 |
|
571 | 503 |
/// <summary> |
572 |
/// 라인을 Run 단위로 모델링하는 진입 메서드 |
|
573 |
/// </summary> |
|
574 |
/// <param name="run"></param> |
|
575 |
private void LineModelingByRun(LineRun run) |
|
576 |
{ |
|
577 |
Line prevLine = null; |
|
578 |
List<Line> lines = new List<Line>(); |
|
579 |
foreach (var item in run.RUNITEMS) |
|
580 |
{ |
|
581 |
// Line일 경우 |
|
582 |
if (item.GetType() == typeof(Line)) |
|
583 |
{ |
|
584 |
Line line = item as Line; |
|
585 |
if (prevLine == null) |
|
586 |
lines.Add(line); |
|
587 |
else if (prevLine != null) |
|
588 |
{ |
|
589 |
if (prevLine.SPPID.MAPPINGNAME == line.SPPID.MAPPINGNAME) |
|
590 |
lines.Add(line); |
|
591 |
else |
|
592 |
{ |
|
593 |
if (lines.Count > 0) |
|
594 |
{ |
|
595 |
LineModeling(lines); |
|
596 |
lines.Clear(); |
|
597 |
} |
|
598 |
lines.Add(line); |
|
599 |
} |
|
600 |
} |
|
601 |
|
|
602 |
prevLine = line; |
|
603 |
|
|
604 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
|
605 |
} |
|
606 |
// Symbol 일 경우 |
|
607 |
else if (item.GetType() == typeof(Symbol)) |
|
608 |
{ |
|
609 |
if (lines.Count > 0) |
|
610 |
{ |
|
611 |
LineModeling(lines); |
|
612 |
lines.Clear(); |
|
613 |
} |
|
614 |
} |
|
615 |
} |
|
616 |
|
|
617 |
if (lines.Count > 0) |
|
618 |
LineModeling(lines); |
|
619 |
} |
|
620 |
|
|
621 |
/// <summary> |
|
622 |
/// 심볼을 Run 단위로 모델링하는 진입 메서드 |
|
623 |
/// </summary> |
|
624 |
/// <param name="run"></param> |
|
625 |
private void SymbolModelingByRun(LineRun run) |
|
626 |
{ |
|
627 |
// 양끝 Symbol 검사 후 Line이 나올때까지만 Symbol Modeling |
|
628 |
if (run.RUNITEMS.Count > 0) |
|
629 |
{ |
|
630 |
if (run.RUNITEMS[0].GetType() == typeof(Symbol)) |
|
631 |
SymbolModelingByRunStart(run.RUNITEMS[0] as Symbol, run); |
|
632 |
|
|
633 |
if (run.RUNITEMS[run.RUNITEMS.Count - 1].GetType() == typeof(Symbol)) |
|
634 |
SymbolModelingByRunEnd(run.RUNITEMS[run.RUNITEMS.Count - 1] as Symbol, run); |
|
635 |
} |
|
636 |
|
|
637 |
Symbol targetSymbol = null; |
|
638 |
foreach (var item in run.RUNITEMS) |
|
639 |
{ |
|
640 |
if (item.GetType() == typeof(Symbol)) |
|
641 |
{ |
|
642 |
Symbol symbol = item as Symbol; |
|
643 |
SymbolModeling(symbol, targetSymbol); |
|
644 |
targetSymbol = symbol; |
|
645 |
} |
|
646 |
else |
|
647 |
{ |
|
648 |
targetSymbol = null; |
|
649 |
} |
|
650 |
} |
|
651 |
} |
|
652 |
|
|
653 |
/// <summary> |
|
654 |
/// Run에 있는 심볼을 모델링하는데 기준이 Run의 시작점 |
|
655 |
/// </summary> |
|
656 |
/// <param name="symbol"></param> |
|
657 |
/// <param name="run"></param> |
|
658 |
private void SymbolModelingByRunStart(Symbol symbol, LineRun run) |
|
659 |
{ |
|
660 |
foreach (var connector in symbol.CONNECTORS) |
|
661 |
{ |
|
662 |
object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
|
663 |
if (targetItem != null && |
|
664 |
(targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) && |
|
665 |
!IsSameLineRun(symbol, targetItem)) |
|
666 |
{ |
|
667 |
SymbolModeling(symbol, targetItem as Symbol); |
|
668 |
for (int i = 1; i < run.RUNITEMS.Count; i++) |
|
669 |
{ |
|
670 |
object item = run.RUNITEMS[i]; |
|
671 |
if (item.GetType() == typeof(Symbol)) |
|
672 |
SymbolModeling(item as Symbol, run.RUNITEMS[i - 1] as Symbol); |
|
673 |
else |
|
674 |
break; |
|
675 |
} |
|
676 |
break; |
|
677 |
} |
|
678 |
} |
|
679 |
|
|
680 |
|
|
681 |
} |
|
682 |
|
|
683 |
/// <summary> |
|
684 |
/// Run에 있는 심볼을 모델링하는데 기준이 Run의 끝점 |
|
685 |
/// </summary> |
|
686 |
/// <param name="symbol"></param> |
|
687 |
/// <param name="run"></param> |
|
688 |
private void SymbolModelingByRunEnd(Symbol symbol, LineRun run) |
|
689 |
{ |
|
690 |
foreach (var connector in symbol.CONNECTORS) |
|
691 |
{ |
|
692 |
object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
|
693 |
if (targetItem != null && |
|
694 |
(targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) && |
|
695 |
!IsSameLineRun(symbol, targetItem)) |
|
696 |
{ |
|
697 |
SymbolModeling(symbol, targetItem as Symbol); |
|
698 |
for (int i = run.RUNITEMS.Count - 2; i >= 0; i--) |
|
699 |
{ |
|
700 |
object item = run.RUNITEMS[i]; |
|
701 |
if (item.GetType() == typeof(Symbol)) |
|
702 |
SymbolModeling(item as Symbol, run.RUNITEMS[i + 1] as Symbol); |
|
703 |
else |
|
704 |
break; |
|
705 |
} |
|
706 |
break; |
|
707 |
} |
|
708 |
} |
|
709 |
} |
|
710 |
|
|
711 |
/// <summary> |
|
712 | 504 |
/// 심볼을 실제로 Modeling 메서드 |
713 | 505 |
/// </summary> |
714 | 506 |
/// <param name="symbol"></param> |
... | ... | |
874 | 666 |
double gapY = originY - sceneY; |
875 | 667 |
|
876 | 668 |
// SPPID Symbol과 ID2 심볼의 크기 차이 |
877 |
double sizeWidth = 0; |
|
878 |
double sizeHeight = 0; |
|
879 |
SPPIDUtil.ConvertPointBystring(targetSymbol.SIZE, ref sizeWidth, ref sizeHeight); |
|
669 |
DataRow row = document.SymbolTable.Select(string.Format("UID = '{0}'",targetSymbol.DBUID))[0]; |
|
670 |
double sizeWidth = Convert.ToDouble(row["Width"]); |
|
671 |
double sizeHeight = Convert.ToDouble(row["Height"]); |
|
672 |
//SPPIDUtil.ConvertPointBystring(targetSymbol.SIZE, ref sizeWidth, ref sizeHeight); |
|
880 | 673 |
double percentX = (x2 - x1) / sizeWidth; |
881 | 674 |
double percentY = (y2 - y1) / sizeHeight; |
882 | 675 |
|
... | ... | |
901 | 694 |
ReleaseCOMObjects(_TargetItem); |
902 | 695 |
} |
903 | 696 |
|
697 |
private void GetTargetLineConnectorPoint(Connector targetConnector, Line targetLine, ref double x, ref double y) |
|
698 |
{ |
|
699 |
int index = targetLine.CONNECTORS.IndexOf(targetConnector); |
|
700 |
if (index == 0) |
|
701 |
{ |
|
702 |
x = targetLine.SPPID.START_X; |
|
703 |
y = targetLine.SPPID.START_Y; |
|
704 |
} |
|
705 |
else |
|
706 |
{ |
|
707 |
x = targetLine.SPPID.END_X; |
|
708 |
y = targetLine.SPPID.END_Y; |
|
709 |
} |
|
710 |
} |
|
711 |
|
|
904 | 712 |
/// <summary> |
905 | 713 |
/// SPPID Symbol의 Range를 구한다. |
906 | 714 |
/// </summary> |
... | ... | |
1421 | 1229 |
ReleaseCOMObjects(_LMSymbol); |
1422 | 1230 |
} |
1423 | 1231 |
|
1424 |
/// <summary> |
|
1425 |
/// item이 TargetItem과 같은 LineRun에 있는지 검사 |
|
1426 |
/// </summary> |
|
1427 |
/// <param name="item"></param> |
|
1428 |
/// <param name="targetItem"></param> |
|
1429 |
/// <returns></returns> |
|
1430 |
private bool IsSameLineRun(object item, object targetItem) |
|
1232 |
private void NewLineModeling(Line line, bool isBranchModeling = false) |
|
1431 | 1233 |
{ |
1432 |
foreach (var lineNumber in document.LINENUMBERS) |
|
1234 |
if (!string.IsNullOrEmpty(line.SPPID.ModelItemId) || (NewBranchLines.Contains(line) && !isBranchModeling)) |
|
1235 |
return; |
|
1236 |
|
|
1237 |
List<Line> group = new List<Line>(); |
|
1238 |
GetConnectedLineGroup(line, group); |
|
1239 |
LineCoordinateCorrection(group); |
|
1240 |
|
|
1241 |
foreach (var groupLine in group) |
|
1433 | 1242 |
{ |
1434 |
foreach (var run in lineNumber.RUNS)
|
|
1243 |
try
|
|
1435 | 1244 |
{ |
1436 |
foreach (var runItem in run.RUNITEMS)
|
|
1245 |
if (!isBranchModeling && SPPIDUtil.IsBranchLine(groupLine))
|
|
1437 | 1246 |
{ |
1438 |
if (runItem == item) |
|
1247 |
NewBranchLines.Add(groupLine); |
|
1248 |
continue; |
|
1249 |
} |
|
1250 |
|
|
1251 |
_LMAItem _LMAItem = _placement.PIDCreateItem(groupLine.SPPID.MAPPINGNAME); |
|
1252 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
|
1253 |
foreach (var connector in groupLine.CONNECTORS) |
|
1254 |
{ |
|
1255 |
double x = 0; |
|
1256 |
double y = 0; |
|
1257 |
GetTargetLineConnectorPoint(connector, groupLine, ref x, ref y); |
|
1258 |
if (connector.ConnectedObject == null) |
|
1259 |
{ |
|
1260 |
placeRunInputs.AddPoint(x, y); |
|
1261 |
} |
|
1262 |
else if (connector.ConnectedObject.GetType() == typeof(Symbol)) |
|
1263 |
{ |
|
1264 |
Symbol targetSymbol = connector.ConnectedObject as Symbol; |
|
1265 |
LMSymbol _LMSymbol = GetTargetSymbol(targetSymbol, groupLine); |
|
1266 |
placeRunInputs.AddSymbolTarget(_LMSymbol, x, y); |
|
1267 |
} |
|
1268 |
else if (connector.ConnectedObject.GetType() == typeof(Line)) |
|
1439 | 1269 |
{ |
1440 |
foreach (var findItem in run.RUNITEMS) |
|
1270 |
Line targetLine = connector.ConnectedObject as Line; |
|
1271 |
if (!string.IsNullOrEmpty(targetLine.SPPID.ModelItemId)) |
|
1272 |
{ |
|
1273 |
LMConnector targetConnector = FindTargetLMConnectorForBranch(line, targetLine, ref x, ref y); |
|
1274 |
placeRunInputs.AddConnectorTarget(targetConnector, x, y); |
|
1275 |
ChangeLineSPPIDCoordinateByConnector(groupLine, targetLine, x, y, false); |
|
1276 |
} |
|
1277 |
else |
|
1441 | 1278 |
{ |
1442 |
if (findItem == targetItem)
|
|
1279 |
if (groupLine.CONNECTORS.IndexOf(connector) == 0)
|
|
1443 | 1280 |
{ |
1444 |
return true; |
|
1281 |
if (groupLine.SlopeType == SlopeType.HORIZONTAL) |
|
1282 |
placeRunInputs.AddPoint(x, -0.1); |
|
1283 |
else if (groupLine.SlopeType == SlopeType.VERTICAL) |
|
1284 |
placeRunInputs.AddPoint(-0.1, y); |
|
1285 |
else |
|
1286 |
placeRunInputs.AddPoint(x, -0.1); |
|
1445 | 1287 |
} |
1446 |
} |
|
1447 | 1288 |
|
1448 |
return false;
|
|
1289 |
placeRunInputs.AddPoint(x, y);
|
|
1449 | 1290 |
|
1291 |
if (groupLine.CONNECTORS.IndexOf(connector) == 1) |
|
1292 |
{ |
|
1293 |
if (groupLine.SlopeType == SlopeType.HORIZONTAL) |
|
1294 |
placeRunInputs.AddPoint(x, -0.1); |
|
1295 |
else if (groupLine.SlopeType == SlopeType.VERTICAL) |
|
1296 |
placeRunInputs.AddPoint(-0.1, y); |
|
1297 |
else |
|
1298 |
placeRunInputs.AddPoint(x, -0.1); |
|
1299 |
} |
|
1300 |
} |
|
1450 | 1301 |
} |
1451 | 1302 |
} |
1452 |
} |
|
1453 |
} |
|
1454 | 1303 |
|
1455 |
return false; |
|
1456 |
} |
|
1304 |
LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
|
1305 |
if (_lMConnector != null) |
|
1306 |
{ |
|
1307 |
groupLine.SPPID.ModelItemId = _lMConnector.ModelItemID; |
|
1308 |
ReleaseCOMObjects(_lMConnector); |
|
1309 |
} |
|
1457 | 1310 |
|
1458 |
/// <summary> |
|
1459 |
/// Line을 실제로 모델링하는 메서드 |
|
1460 |
/// </summary> |
|
1461 |
/// <param name="lines"></param> |
|
1462 |
private void LineModeling(List<Line> lines) |
|
1463 |
{ |
|
1464 |
_LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
|
1465 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
|
1466 |
LMSymbol _LMSymbol1 = null; |
|
1467 |
LMSymbol _LMSymbol2 = null; |
|
1468 |
Dictionary<LMConnector, List<double[]>> connectorVertices1 = new Dictionary<LMConnector, List<double[]>>(); |
|
1469 |
LMConnector targetConnector1 = null; |
|
1470 |
Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>(); |
|
1471 |
LMConnector targetConnector2 = null; |
|
1472 |
|
|
1473 |
Line startBranchLine = null; |
|
1474 |
Line endBranchLine = null; |
|
1475 |
|
|
1476 |
// Type, Line, TargetObjet, x, y |
|
1477 |
List<Tuple<string, Line, object, double, double>> linePointInfo = new List<Tuple<string, Line, object, double, double>>(); |
|
1478 |
// Point 정리 |
|
1479 |
for (int i = 0; i < lines.Count; i++) |
|
1480 |
{ |
|
1481 |
Line line = lines[i]; |
|
1482 |
if (i == 0 || i + 1 != lines.Count) |
|
1483 |
{ |
|
1484 |
// 시작점에 연결된 Symbol 찾기 |
|
1485 |
object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM); |
|
1486 |
if (connItem != null && connItem.GetType() == typeof(Symbol)) |
|
1487 |
{ |
|
1488 |
Symbol symbol1 = connItem as Symbol; |
|
1489 |
_LMSymbol1 = GetTargetSymbol(symbol1, line); |
|
1490 |
if (_LMSymbol1 != null) |
|
1491 |
{ |
|
1492 |
double x = line.SPPID.START_X; |
|
1493 |
double y = line.SPPID.START_Y; |
|
1494 |
Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, line.UID, symbol1); |
|
1495 |
if (connector != null) |
|
1496 |
{ |
|
1497 |
GetTargetSymbolConnectorPoint(connector, symbol1, ref x, ref y); |
|
1498 |
line.SPPID.START_X = x; |
|
1499 |
line.SPPID.START_Y = y; |
|
1500 |
} |
|
1311 |
List<object> removeLines = groupLine.CONNECTORS.FindAll(x => |
|
1312 |
x.ConnectedObject != null && |
|
1313 |
x.ConnectedObject.GetType() == typeof(Line) && |
|
1314 |
!string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)) |
|
1315 |
.Select(x => x.ConnectedObject) |
|
1316 |
.ToList(); |
|
1501 | 1317 |
|
1502 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>("SYMBOL", line, _LMSymbol1, x, y)); |
|
1503 |
} |
|
1504 |
else |
|
1505 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y)); |
|
1506 |
} |
|
1507 |
else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem)) |
|
1508 |
{ |
|
1509 |
connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId); |
|
1510 |
targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y); |
|
1318 |
foreach (var item in removeLines) |
|
1319 |
RemoveLineForModeling(item as Line); |
|
1511 | 1320 |
|
1512 |
if (targetConnector1 != null) |
|
1513 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>("LINE", line, targetConnector1, line.SPPID.START_X, line.SPPID.START_Y)); |
|
1514 |
else |
|
1515 |
{ |
|
1516 |
startBranchLine = connItem as Line; |
|
1517 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y)); |
|
1518 |
} |
|
1519 |
} |
|
1520 |
else |
|
1521 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y)); |
|
1321 |
if (_LMAItem != null) |
|
1322 |
ReleaseCOMObjects(_LMAItem); |
|
1323 |
if (placeRunInputs != null) |
|
1324 |
ReleaseCOMObjects(placeRunInputs); |
|
1522 | 1325 |
|
1326 |
if (isBranchModeling && NewBranchLines.Contains(groupLine)) |
|
1327 |
NewBranchLines.Remove(groupLine); |
|
1523 | 1328 |
} |
1524 |
if (i + 1 == lines.Count)
|
|
1329 |
catch (Exception ex)
|
|
1525 | 1330 |
{ |
1526 |
// 끝점에 연결된 Symbol 찾기 |
|
1527 |
object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM); |
|
1528 |
|
|
1529 |
if (i != 0) |
|
1530 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y)); |
|
1331 |
throw new Exception(groupLine.UID); |
|
1332 |
} |
|
1333 |
} |
|
1334 |
} |
|
1531 | 1335 |
|
1532 |
if (connItem != null && connItem.GetType() == typeof(Symbol)) |
|
1336 |
private void RemoveLineForModeling(Line line) |
|
1337 |
{ |
|
1338 |
LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
|
1339 |
if (modelItem != null) |
|
1340 |
{ |
|
1341 |
foreach (LMRepresentation rep in modelItem.Representations) |
|
1342 |
{ |
|
1343 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
|
1533 | 1344 |
{ |
1534 |
Symbol symbol2 = connItem as Symbol; |
|
1535 |
_LMSymbol2 = GetTargetSymbol(connItem as Symbol, line); |
|
1536 |
if (_LMSymbol2 != null) |
|
1345 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
|
1346 |
dynamic OID = rep.get_GraphicOID(); |
|
1347 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
|
1348 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
|
1349 |
int verticesCount = lineStringGeometry.VertexCount; |
|
1350 |
double[] vertices = null; |
|
1351 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
|
1352 |
for (int i = 0; i < verticesCount; i++) |
|
1537 | 1353 |
{ |
1538 |
double x = line.SPPID.END_X; |
|
1539 |
double y = line.SPPID.END_Y; |
|
1540 |
Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, line.UID, symbol2); |
|
1541 |
if (connector != null) |
|
1542 |
{ |
|
1543 |
GetTargetSymbolConnectorPoint(connector, symbol2, ref x, ref y); |
|
1544 |
line.SPPID.END_X = x; |
|
1545 |
line.SPPID.END_Y = y; |
|
1546 |
} |
|
1547 |
|
|
1548 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>("SYMBOL", line, _LMSymbol2, x, y)); |
|
1354 |
double x = 0; |
|
1355 |
double y = 0; |
|
1356 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
|
1357 |
if (verticesCount == 2 && x < 0 || y < 0) |
|
1358 |
_placement.PIDRemovePlacement(rep); |
|
1549 | 1359 |
} |
1550 |
else |
|
1551 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.END_X, line.SPPID.END_Y)); |
|
1360 |
ReleaseCOMObjects(_LMConnector); |
|
1552 | 1361 |
} |
1553 |
else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem)) |
|
1554 |
{ |
|
1555 |
connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId); |
|
1556 |
targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y); |
|
1362 |
} |
|
1557 | 1363 |
|
1558 |
if (targetConnector2 != null) |
|
1559 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>("LINE", line, targetConnector2, line.SPPID.END_X, line.SPPID.END_Y)); |
|
1560 |
else |
|
1561 |
{ |
|
1562 |
endBranchLine = connItem as Line; |
|
1563 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.END_X, line.SPPID.END_Y)); |
|
1564 |
} |
|
1565 |
} |
|
1566 |
else |
|
1567 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.END_X, line.SPPID.END_Y)); |
|
1364 |
ReleaseCOMObjects(modelItem); |
|
1365 |
} |
|
1366 |
} |
|
1367 |
|
|
1368 |
private void GetConnectedLineGroup(Line line, List<Line> group) |
|
1369 |
{ |
|
1370 |
if (!group.Contains(line)) |
|
1371 |
group.Add(line); |
|
1372 |
foreach (var connector in line.CONNECTORS) |
|
1373 |
{ |
|
1374 |
if (connector.ConnectedObject != null && |
|
1375 |
connector.ConnectedObject.GetType() == typeof(Line) && |
|
1376 |
!group.Contains(connector.ConnectedObject) && |
|
1377 |
string.IsNullOrEmpty(((Line)connector.ConnectedObject).SPPID.ModelItemId)) |
|
1378 |
{ |
|
1379 |
Line connLine = connector.ConnectedObject as Line; |
|
1380 |
if (!SPPIDUtil.IsBranchLine(connLine, line)) |
|
1381 |
GetConnectedLineGroup(connLine, group); |
|
1568 | 1382 |
} |
1569 | 1383 |
} |
1384 |
} |
|
1570 | 1385 |
|
1571 |
double prevX = double.NaN; |
|
1572 |
double prevY = double.NaN; |
|
1573 |
SlopeType prevSlopeType = SlopeType.None; |
|
1574 |
for (int i = 0; i < linePointInfo.Count; i++) |
|
1386 |
private void LineCoordinateCorrection(List<Line> group) |
|
1387 |
{ |
|
1388 |
// 순서대로 전 Item 기준 정렬 |
|
1389 |
LineCoordinateCorrectionByStart(group); |
|
1390 |
|
|
1391 |
// 역으로 심볼이 있을 경우 좌표 보정 |
|
1392 |
LineCoordinateCorrectionForLastLine(group); |
|
1393 |
} |
|
1394 |
|
|
1395 |
private void LineCoordinateCorrectionByStart(List<Line> group) |
|
1396 |
{ |
|
1397 |
for (int i = 0; i < group.Count; i++) |
|
1575 | 1398 |
{ |
1576 |
Tuple<string, Line, object, double, double> item = linePointInfo[i]; |
|
1577 |
Line line = item.Item2; |
|
1578 |
double x = item.Item4; |
|
1579 |
double y = item.Item5; |
|
1580 |
SlopeType slopeType = SPPIDUtil.CalcSlope(line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y); |
|
1581 |
// Symbol일 경우 바로 Input Point |
|
1582 |
if (item.Item1 == "SYMBOL") |
|
1399 |
Line line = group[i]; |
|
1400 |
if (i == 0) |
|
1583 | 1401 |
{ |
1584 |
LMSymbol targetSymbol = item.Item3 as LMSymbol; |
|
1585 |
placeRunInputs.AddSymbolTarget(targetSymbol, x, y); |
|
1402 |
Connector symbolConnector = line.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol)); |
|
1403 |
if (symbolConnector != null) |
|
1404 |
LineCoordinateCorrectionByConnItem(line, symbolConnector.ConnectedObject); |
|
1586 | 1405 |
} |
1587 |
else |
|
1406 |
else if (i != 0)
|
|
1588 | 1407 |
{ |
1589 |
SPPIDUtil.ConvertGridPoint(ref x, ref y); |
|
1590 |
// i == 0은 그대로 사용 |
|
1591 |
if (i != 0) |
|
1592 |
{ |
|
1593 |
Tuple<string, Line, object, double, double> prevItem = linePointInfo[i - 1]; |
|
1594 |
// y 좌표가 같아야함 및 Symbol 좌표가 정확하지 않으므로 한번더 보정 |
|
1595 |
if (prevSlopeType == SlopeType.HORIZONTAL) |
|
1596 |
{ |
|
1597 |
y = prevY; |
|
1598 |
SPPIDUtil.ConvertGridPointOnlyOnePoint(ref y); |
|
1599 |
} |
|
1600 |
else if (prevSlopeType == SlopeType.VERTICAL) |
|
1601 |
{ |
|
1602 |
x = prevX; |
|
1603 |
SPPIDUtil.ConvertGridPointOnlyOnePoint(ref x); |
|
1604 |
} |
|
1408 |
LineCoordinateCorrectionByConnItem(line, group[i - 1]); |
|
1409 |
} |
|
1410 |
} |
|
1411 |
} |
|
1605 | 1412 |
|
1606 |
// 마지막이 Symbol일 경우는 Symbol의 좌표를 따라감
|
|
1607 |
if (i + 1 == linePointInfo.Count - 1 && linePointInfo[i + 1].Item1 == "SYMBOL")
|
|
1608 |
{
|
|
1609 |
Line nextLine = linePointInfo[i + 1].Item2;
|
|
1610 |
SlopeType nextSlopeType = SPPIDUtil.CalcSlope(nextLine.SPPID.START_X, nextLine.SPPID.START_Y, nextLine.SPPID.END_X, nextLine.SPPID.END_Y);
|
|
1611 |
if (slopeType == SlopeType.HORIZONTAL)
|
|
1612 |
y = linePointInfo[i + 1].Item5;
|
|
1613 |
else if (slopeType == SlopeType.VERTICAL)
|
|
1614 |
x = linePointInfo[i + 1].Item4;
|
|
1615 |
}
|
|
1616 |
}
|
|
1413 |
private void LineCoordinateCorrectionForLastLine(List<Line> group)
|
|
1414 |
{
|
|
1415 |
Line checkLine = group[group.Count - 1];
|
|
1416 |
Connector lastSymbolConnector = checkLine.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol));
|
|
1417 |
if (lastSymbolConnector != null)
|
|
1418 |
{
|
|
1419 |
LineCoordinateCorrectionByConnItem(checkLine, lastSymbolConnector.ConnectedObject);
|
|
1420 |
for (int i = group.Count - 2; i >= 0; i--)
|
|
1421 |
{
|
|
1422 |
Line line = group[i + 1];
|
|
1423 |
Line prevLine = group[i];
|
|
1617 | 1424 |
|
1618 |
if (item.Item1 == "LINE") |
|
1425 |
// 같으면 보정 |
|
1426 |
if (line.SlopeType == prevLine.SlopeType) |
|
1427 |
LineCoordinateCorrectionByConnItem(prevLine, line); |
|
1428 |
else |
|
1619 | 1429 |
{ |
1620 |
LMConnector targetConnector = item.Item3 as LMConnector; |
|
1621 |
if (connectorVertices1.ContainsKey(targetConnector)) |
|
1430 |
if (line.SlopeType == SlopeType.HORIZONTAL) |
|
1622 | 1431 |
{ |
1623 |
List<double[]> vertices = connectorVertices1[targetConnector]; |
|
1432 |
double prevX = 0; |
|
1433 |
double prevY = 0; |
|
1434 |
GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY); |
|
1435 |
ChangeLineSPPIDCoordinateByConnectorOnlyX(line, prevLine, prevX); |
|
1624 | 1436 |
|
1437 |
double x = 0; |
|
1438 |
double y = 0; |
|
1439 |
GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y); |
|
1440 |
ChangeLineSPPIDCoordinateByConnectorOnlyY(prevLine, line, y); |
|
1625 | 1441 |
} |
1626 |
else if (connectorVertices2.ContainsKey(targetConnector))
|
|
1442 |
else if (line.SlopeType == SlopeType.VERTICAL)
|
|
1627 | 1443 |
{ |
1628 |
List<double[]> vertices = connectorVertices2[targetConnector]; |
|
1444 |
double prevX = 0; |
|
1445 |
double prevY = 0; |
|
1446 |
GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY); |
|
1447 |
ChangeLineSPPIDCoordinateByConnectorOnlyY(line, prevLine, prevY); |
|
1629 | 1448 |
|
1449 |
double x = 0; |
|
1450 |
double y = 0; |
|
1451 |
GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y); |
|
1452 |
ChangeLineSPPIDCoordinateByConnectorOnlyX(prevLine, line, x); |
|
1630 | 1453 |
} |
1631 |
placeRunInputs.AddConnectorTarget(targetConnector, x, y);
|
|
1454 |
break;
|
|
1632 | 1455 |
} |
1633 |
|
|
1634 |
else |
|
1635 |
placeRunInputs.AddPoint(x, y); |
|
1636 | 1456 |
} |
1637 |
|
|
1638 |
prevX = x; |
|
1639 |
prevY = y; |
|
1640 |
prevSlopeType = slopeType; |
|
1641 | 1457 |
} |
1458 |
} |
|
1642 | 1459 |
|
1643 |
LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
|
1644 |
|
|
1645 |
if (_lMConnector != null) |
|
1460 |
private void LineCoordinateCorrectionByConnItem(Line line, object connItem) |
|
1461 |
{ |
|
1462 |
double x = 0; |
|
1463 |
double y = 0; |
|
1464 |
if (connItem.GetType() == typeof(Symbol)) |
|
1465 |
{ |
|
1466 |
Symbol targetSymbol = connItem as Symbol; |
|
1467 |
Connector targetConnector = targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == line); |
|
1468 |
if (targetConnector != null) |
|
1469 |
GetTargetSymbolConnectorPoint(targetConnector, targetSymbol, ref x, ref y); |
|
1470 |
else |
|
1471 |
throw new Exception("Target symbol UID : " + targetSymbol.UID + "\r\nLine UID : " + line.UID); |
|
1472 |
} |
|
1473 |
else if (connItem.GetType() == typeof(Line)) |
|
1646 | 1474 |
{ |
1647 |
bool bStart = false; |
|
1648 |
bool bEnd = false; |
|
1649 |
|
|
1650 |
NeedReModeling(lines[0], _LMSymbol1, ref bStart); |
|
1651 |
NeedReModeling(lines[lines.Count - 1], _LMSymbol2, ref bEnd); |
|
1475 |
Line targetLine = connItem as Line; |
|
1476 |
GetTargetLineConnectorPoint(targetLine.CONNECTORS.Find(z => z.ConnectedObject == line), targetLine, ref x, ref y); |
|
1477 |
} |
|
1652 | 1478 |
|
1653 |
if (bStart || bEnd) |
|
1654 |
ReModelingLine(lines, _lMConnector, _LMSymbol1, _LMSymbol2, bStart, bEnd); |
|
1655 |
else |
|
1656 |
{ |
|
1657 |
foreach (var line in lines) |
|
1658 |
line.SPPID.ModelItemId = _lMConnector.ModelItemID; |
|
1659 |
_lMConnector.Commit(); |
|
1660 |
} |
|
1479 |
ChangeLineSPPIDCoordinateByConnector(line, connItem, x, y); |
|
1480 |
} |
|
1661 | 1481 |
|
1662 |
if (startBranchLine != null || endBranchLine != null) |
|
1663 |
BranchLines.Add(new Tuple<string, Line, Line>(lines[0].SPPID.ModelItemId, startBranchLine, endBranchLine)); |
|
1482 |
private void ChangeLineSPPIDCoordinateByConnector(Line line, object connItem, double x, double y, bool changeOtherCoordinate = true) |
|
1483 |
{ |
|
1484 |
Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem); |
|
1485 |
int index = line.CONNECTORS.IndexOf(connector); |
|
1486 |
if (index == 0) |
|
1487 |
{ |
|
1488 |
line.SPPID.START_X = x; |
|
1489 |
line.SPPID.START_Y = y; |
|
1490 |
if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate) |
|
1491 |
line.SPPID.END_Y = y; |
|
1492 |
else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate) |
|
1493 |
line.SPPID.END_X = x; |
|
1494 |
} |
|
1495 |
else |
|
1496 |
{ |
|
1497 |
line.SPPID.END_X = x; |
|
1498 |
line.SPPID.END_Y = y; |
|
1499 |
if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate) |
|
1500 |
line.SPPID.START_Y = y; |
|
1501 |
else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate) |
|
1502 |
line.SPPID.START_X = x; |
|
1664 | 1503 |
} |
1504 |
} |
|
1665 | 1505 |
|
1666 |
if (_LMSymbol1 != null) |
|
1667 |
ReleaseCOMObjects(_LMSymbol1); |
|
1668 |
if (_LMSymbol2 != null) |
|
1669 |
ReleaseCOMObjects(_LMSymbol2); |
|
1670 |
if (targetConnector1 != null) |
|
1671 |
ReleaseCOMObjects(targetConnector1); |
|
1672 |
if (targetConnector2 != null) |
|
1673 |
ReleaseCOMObjects(targetConnector2); |
|
1674 |
foreach (var item in connectorVertices1) |
|
1675 |
ReleaseCOMObjects(item.Key); |
|
1676 |
foreach (var item in connectorVertices2) |
|
1677 |
ReleaseCOMObjects(item.Key); |
|
1506 |
private void ChangeLineSPPIDCoordinateByConnectorOnlyX(Line line, object connItem, double x) |
|
1507 |
{ |
|
1508 |
Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem); |
|
1509 |
int index = line.CONNECTORS.IndexOf(connector); |
|
1510 |
if (index == 0) |
|
1511 |
{ |
|
1512 |
line.SPPID.START_X = x; |
|
1513 |
if (line.SlopeType == SlopeType.VERTICAL) |
|
1514 |
line.SPPID.END_X = x; |
|
1515 |
} |
|
1516 |
else |
|
1517 |
{ |
|
1518 |
line.SPPID.END_X = x; |
|
1519 |
if (line.SlopeType == SlopeType.VERTICAL) |
|
1520 |
line.SPPID.START_X = x; |
|
1521 |
} |
|
1522 |
} |
|
1678 | 1523 |
|
1679 |
ReleaseCOMObjects(_lMConnector); |
|
1680 |
ReleaseCOMObjects(placeRunInputs); |
|
1681 |
ReleaseCOMObjects(_LMAItem); |
|
1524 |
private void ChangeLineSPPIDCoordinateByConnectorOnlyY(Line line, object connItem, double y) |
|
1525 |
{ |
|
1526 |
Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem); |
|
1527 |
int index = line.CONNECTORS.IndexOf(connector); |
|
1528 |
if (index == 0) |
|
1529 |
{ |
|
1530 |
line.SPPID.START_Y = y; |
|
1531 |
if (line.SlopeType == SlopeType.HORIZONTAL) |
|
1532 |
line.SPPID.END_Y = y; |
|
1533 |
} |
|
1534 |
else |
|
1535 |
{ |
|
1536 |
line.SPPID.END_Y = y; |
|
1537 |
if (line.SlopeType == SlopeType.HORIZONTAL) |
|
1538 |
line.SPPID.START_Y = y; |
|
1539 |
} |
|
1682 | 1540 |
} |
1683 | 1541 |
|
1684 | 1542 |
private void NeedReModeling(Line line, LMSymbol symbol, ref bool result) |
... | ... | |
1888 | 1746 |
LMSymbol _LMSymbol = null; |
1889 | 1747 |
foreach (var connector in symbol.CONNECTORS) |
1890 | 1748 |
{ |
1891 |
if (connector.CONNECTEDITEM == line.UID) |
|
1892 |
{ |
|
1893 |
if (connector.Index == 0) |
|
1894 |
_LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
|
1895 |
else |
|
1896 |
{ |
|
1897 |
ChildSymbol child = null; |
|
1898 |
foreach (var childSymbol in symbol.ChildSymbols) |
|
1899 |
{ |
|
1900 |
if (childSymbol.Connectors.Contains(connector)) |
|
1901 |
child = childSymbol; |
|
1902 |
else |
|
1903 |
child = GetChildSymbolByConnector(childSymbol, connector); |
|
1904 |
|
|
1905 |
if (child != null) |
|
1906 |
break; |
|
1907 |
} |
|
1908 |
|
|
1909 |
if (child != null) |
|
1910 |
_LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId); |
|
1911 |
} |
|
1912 |
|
|
1913 |
break; |
|
1914 |
} |
|
1915 |
} |
|
1916 |
|
|
1917 |
return _LMSymbol; |
|
1918 |
} |
|
1919 |
|
|
1920 |
/// <summary> |
|
1921 |
/// Connector를 가지고 있는 ChildSymbol Object 반환 |
|
1922 |
/// </summary> |
|
1923 |
/// <param name="item"></param> |
|
1924 |
/// <param name="connector"></param> |
|
1925 |
/// <returns></returns> |
|
1926 |
private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector) |
|
1927 |
{ |
|
1928 |
foreach (var childSymbol in item.ChildSymbols) |
|
1929 |
{ |
|
1930 |
if (childSymbol.Connectors.Contains(connector)) |
|
1931 |
return childSymbol; |
|
1932 |
else |
|
1933 |
return GetChildSymbolByConnector(childSymbol, connector); |
|
1934 |
} |
|
1935 |
|
|
1936 |
return null; |
|
1937 |
} |
|
1938 |
|
|
1939 |
/// <summary> |
|
1940 |
/// Branch 라인을 다시 모델링하는 진입 메서드 |
|
1941 |
/// </summary> |
|
1942 |
/// <param name="branch"></param> |
|
1943 |
private void BranchLineModeling(Tuple<string, Line, Line> branch) |
|
1944 |
{ |
|
1945 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1); |
|
1946 |
|
|
1947 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1); |
|
1948 |
LMConnector _StartConnector = null; |
|
1949 |
LMConnector _EndConnector = null; |
|
1950 |
double lengthStart = double.MaxValue; |
|
1951 |
double lengthEnd = double.MaxValue; |
|
1952 |
List<double[]> startPoints = new List<double[]>(); |
|
1953 |
List<double[]> endPoints = new List<double[]>(); |
|
1954 |
|
|
1955 |
foreach (var item in connectorVertices) |
|
1956 |
{ |
|
1957 |
foreach (var point in item.Value) |
|
1958 |
{ |
|
1959 |
// Start Point가 Branch |
|
1960 |
if (branch.Item2 != null) |
|
1961 |
{ |
|
1962 |
Line targetLine = branch.Item2; |
|
1963 |
double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]); |
|
1964 |
if (lengthStart > distance) |
|
1965 |
{ |
|
1966 |
_StartConnector = item.Key; |
|
1967 |
lengthStart = distance; |
|
1968 |
startPoints = item.Value; |
|
1969 |
} |
|
1970 |
} |
|
1971 |
// End Point가 Branch |
|
1972 |
if (branch.Item3 != null) |
|
1973 |
{ |
|
1974 |
Line targetLine = branch.Item3; |
|
1975 |
double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]); |
|
1976 |
if (lengthEnd > distance) |
|
1977 |
{ |
|
1978 |
_EndConnector = item.Key; |
|
1979 |
lengthEnd = distance; |
|
1980 |
endPoints = item.Value; |
|
1981 |
} |
|
1982 |
} |
|
1983 |
} |
|
1984 |
} |
|
1985 |
#region Branch가 양쪽 전부일 때 |
|
1986 |
if (_StartConnector != null && _StartConnector == _EndConnector) |
|
1987 |
{ |
|
1988 |
_placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation()); |
|
1989 |
|
|
1990 |
_LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
|
1991 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
|
1992 |
|
|
1993 |
Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId); |
|
1994 |
LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]); |
|
1995 |
Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId); |
|
1996 |
LMConnector _EndTargetConnector = FindTargetLMConnector(endConnectorVertices, |
|
1997 |
startPoints[startPoints.Count - 1][0], |
|
1998 |
startPoints[startPoints.Count - 1][1], |
|
1999 |
startPoints[startPoints.Count - 2][0], |
|
2000 |
startPoints[startPoints.Count - 2][1]); |
|
2001 |
|
|
2002 |
for (int i = 0; i < startPoints.Count; i++) |
|
2003 |
{ |
|
2004 |
double[] point = startPoints[i]; |
|
2005 |
if (i == 0) |
|
2006 |
placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]); |
|
2007 |
else if (i == startPoints.Count - 1) |
|
2008 |
placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]); |
|
2009 |
else |
|
2010 |
placeRunInputs.AddPoint(point[0], point[1]); |
|
2011 |
} |
|
2012 |
|
|
2013 |
LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
|
2014 |
if (_LMConnector != null) |
|
2015 |
{ |
|
2016 |
_LMConnector.Commit(); |
|
2017 |
foreach (var item in lines) |
|
2018 |
item.SPPID.ModelItemId = _LMConnector.ModelItemID; |
|
2019 |
} |
|
2020 |
|
|
2021 |
foreach (var item in startConnectorVertices) |
|
2022 |
ReleaseCOMObjects(item.Key); |
|
2023 |
foreach (var item in endConnectorVertices) |
|
2024 |
ReleaseCOMObjects(item.Key); |
|
2025 |
ReleaseCOMObjects(placeRunInputs); |
|
2026 |
ReleaseCOMObjects(_LMAItem); |
|
2027 |
ReleaseCOMObjects(_LMConnector); |
|
2028 |
} |
|
2029 |
#endregion |
|
2030 |
#region 양쪽이 다른 Branch |
|
2031 |
else |
|
2032 |
{ |
|
2033 |
// Branch 시작 Connector |
|
2034 |
if (_StartConnector != null) |
|
2035 |
BranchLineModelingByConnector(branch, _StartConnector, startPoints, true); |
|
2036 |
// Branch 끝 Connector |
|
2037 |
else if (_EndConnector != null) |
|
2038 |
BranchLineModelingByConnector(branch, _EndConnector, endPoints, false); |
|
2039 |
} |
|
2040 |
#endregion |
|
2041 |
|
|
2042 |
if (_StartConnector != null) |
|
2043 |
ReleaseCOMObjects(_StartConnector); |
|
2044 |
if (_EndConnector != null) |
|
2045 |
ReleaseCOMObjects(_EndConnector); |
|
2046 |
foreach (var item in connectorVertices) |
|
2047 |
ReleaseCOMObjects(item.Key); |
|
2048 |
} |
|
2049 |
|
|
2050 |
/// <summary> |
|
2051 |
/// Branch 라인을 다시 실제로 모델링하는 메서드 |
|
2052 |
/// </summary> |
|
2053 |
/// <param name="branch"></param> |
|
2054 |
/// <param name="_Connector"></param> |
|
2055 |
/// <param name="points"></param> |
|
2056 |
/// <param name="IsStart"></param> |
|
2057 |
private void BranchLineModelingByConnector(Tuple<string, Line, Line> branch, LMConnector _Connector, List<double[]> points, bool IsStart) |
|
2058 |
{ |
|
2059 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1); |
|
2060 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1); |
|
2061 |
LMConnector _SameRunTargetConnector = null; |
|
2062 |
LMSymbol _SameRunTargetLMSymbol = null; |
|
2063 |
Symbol _SameRunTargetSymbol = null; |
|
2064 |
Dictionary<LMConnector, List<double[]>> branchConnectorVertices = null; |
|
2065 |
LMConnector _BranchTargetConnector = null; |
|
2066 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
|
2067 |
|
|
2068 |
// 같은 Line Run의 Connector 찾기 |
|
2069 |
foreach (var item in connectorVertices) |
|
2070 |
{ |
|
2071 |
if (item.Key == _Connector) |
|
2072 |
continue; |
|
2073 |
|
|
2074 |
if (IsStart && |
|
2075 |
!DBNull.Value.Equals(item.Key.ConnectItem1SymbolID) && |
|
2076 |
!DBNull.Value.Equals(_Connector.ConnectItem2SymbolID) && |
|
2077 |
item.Key.ConnectItem1SymbolID == _Connector.ConnectItem2SymbolID) |
|
2078 |
{ |
|
2079 |
_SameRunTargetConnector = item.Key; |
|
2080 |
break; |
|
2081 |
} |
|
2082 |
else if (!IsStart && |
|
2083 |
!DBNull.Value.Equals(item.Key.ConnectItem2SymbolID) && |
|
2084 |
!DBNull.Value.Equals(_Connector.ConnectItem1SymbolID) && |
|
2085 |
item.Key.ConnectItem2SymbolID == _Connector.ConnectItem1SymbolID) |
|
2086 |
{ |
|
2087 |
_SameRunTargetConnector = item.Key; |
|
2088 |
break; |
|
2089 |
} |
|
2090 |
} |
|
2091 |
|
|
2092 |
// Branch 반대편이 Symbol |
|
2093 |
if (_SameRunTargetConnector == null) |
|
2094 |
{ |
|
2095 |
foreach (var line in lines) |
|
2096 |
{ |
|
2097 |
foreach (var connector in line.CONNECTORS) |
|
2098 |
{ |
|
2099 |
Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol; |
|
2100 |
if (symbol != null) |
|
2101 |
{ |
|
2102 |
_SameRunTargetSymbol = symbol; |
|
2103 |
_SameRunTargetLMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
|
2104 |
break; |
|
2105 |
} |
|
2106 |
} |
|
2107 |
} |
|
2108 |
} |
|
2109 |
|
|
2110 |
// 기존 Connector 제거 |
|
2111 |
_placement.PIDRemovePlacement(_Connector.AsLMRepresentation()); |
|
2112 |
|
|
2113 |
// 시작 Connector일 경우 첫 Point가 TargetConnector를 찾아야함 |
|
2114 |
if (IsStart) |
|
2115 |
{ |
|
2116 |
branchConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId); |
|
2117 |
_BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, points[0][0], points[0][1], points[1][0], points[1][1]); |
|
2118 |
} |
|
2119 |
// 끝 Conenctor일 경우 마지막 Point가 TargetConnector를 찾아야함 |
|
2120 |
else |
|
2121 |
{ |
|
2122 |
branchConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId); |
|
2123 |
_BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, |
|
2124 |
points[points.Count - 1][0], |
|
2125 |
points[points.Count - 1][1], |
|
2126 |
points[points.Count - 2][0], |
|
2127 |
points[points.Count - 2][1]); |
|
2128 |
} |
|
2129 |
|
|
2130 |
|
|
2131 |
bool bNeedRemodeling = false; |
|
2132 |
if (_SameRunTargetLMSymbol != null) |
|
2133 |
{ |
|
2134 |
Line line = lines.Find(x => x.CONNECTORS.Find(y => y.CONNECTEDITEM == _SameRunTargetSymbol.UID) != null); |
|
2135 |
NeedReModeling(line, _SameRunTargetLMSymbol, ref bNeedRemodeling); |
|
2136 |
} |
|
2137 |
|
|
2138 |
|
|
2139 |
|
|
2140 |
for (int i = 0; i < points.Count; i++) |
|
2141 |
{ |
|
2142 |
double[] point = points[i]; |
|
2143 |
if (i == 0) |
|
2144 |
{ |
|
2145 |
if (IsStart) |
|
2146 |
{ |
|
2147 |
if (_BranchTargetConnector != null) |
|
2148 |
{ |
|
2149 |
placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]); |
|
2150 |
} |
|
2151 |
else |
|
2152 |
{ |
|
2153 |
placeRunInputs.AddPoint(point[0], point[1]); |
|
2154 |
} |
|
2155 |
} |
|
2156 |
else |
|
2157 |
{ |
|
2158 |
if (_SameRunTargetConnector != null) |
|
2159 |
placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]); |
|
2160 |
else if (_SameRunTargetLMSymbol != null && bNeedRemodeling) |
|
2161 |
{ |
|
2162 |
SlopeType slopeType = SPPIDUtil.CalcSlope(point[0], point[1], points[i + 1][0], points[i + 1][1]); |
|
2163 |
if (slopeType == SlopeType.HORIZONTAL) |
|
2164 |
placeRunInputs.AddPoint(point[0], -0.1); |
|
2165 |
else if (slopeType == SlopeType.VERTICAL) |
|
2166 |
placeRunInputs.AddPoint(-0.1, point[1]); |
|
2167 |
else |
|
2168 |
placeRunInputs.AddPoint(point[0], -0.1); |
|
2169 |
|
|
2170 |
placeRunInputs.AddPoint(point[0], point[1]); |
|
2171 |
} |
|
2172 |
else if (_SameRunTargetLMSymbol != null) |
|
2173 |
placeRunInputs.AddSymbolTarget(_SameRunTargetLMSymbol, point[0], point[1]); |
|
2174 |
else |
|
2175 |
placeRunInputs.AddPoint(point[0], point[1]); |
|
2176 |
} |
|
2177 |
} |
|
2178 |
else if (i == points.Count - 1) |
|
2179 |
{ |
|
2180 |
if (IsStart) |
|
2181 |
{ |
|
2182 |
if (_SameRunTargetConnector != null) |
|
2183 |
placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]); |
|
2184 |
else if (_SameRunTargetLMSymbol != null && bNeedRemodeling) |
|
2185 |
{ |
|
2186 |
placeRunInputs.AddPoint(point[0], point[1]); |
|
2187 |
|
|
2188 |
SlopeType slopeType = SPPIDUtil.CalcSlope(point[0], point[1], points[i - 1][0], points[i - 1][1]); |
|
2189 |
if (slopeType == SlopeType.HORIZONTAL) |
|
2190 |
placeRunInputs.AddPoint(point[0], -0.1); |
|
2191 |
else if (slopeType == SlopeType.VERTICAL) |
|
2192 |
placeRunInputs.AddPoint(-0.1, point[1]); |
|
2193 |
else |
|
2194 |
placeRunInputs.AddPoint(point[0], -0.1); |
|
2195 |
} |
|
2196 |
else if (_SameRunTargetLMSymbol != null) |
|
2197 |
placeRunInputs.AddSymbolTarget(_SameRunTargetLMSymbol, point[0], point[1]); |
|
2198 |
else |
|
2199 |
placeRunInputs.AddPoint(point[0], point[1]); |
|
2200 |
} |
|
2201 |
else |
|
2202 |
{ |
|
2203 |
if (_BranchTargetConnector != null) |
|
2204 |
{ |
|
2205 |
placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]); |
|
2206 |
} |
|
2207 |
else |
|
2208 |
{ |
|
2209 |
placeRunInputs.AddPoint(point[0], point[1]); |
|
2210 |
} |
|
2211 |
} |
|
2212 |
} |
|
2213 |
else |
|
2214 |
placeRunInputs.AddPoint(point[0], point[1]); |
|
2215 |
} |
|
2216 |
_LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
|
2217 |
LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
|
2218 |
|
|
2219 |
if (_LMConnector != null) |
|
2220 |
{ |
|
2221 |
if (_SameRunTargetConnector != null) |
|
2222 |
{ |
|
2223 |
JoinPipeRun(_LMConnector.ModelItemID, _SameRunTargetConnector.ModelItemID); |
|
2224 |
} |
|
2225 |
else |
|
1749 |
if (connector.CONNECTEDITEM == line.UID) |
|
2226 | 1750 |
{ |
2227 |
if (_SameRunTargetLMSymbol != null && bNeedRemodeling) |
|
1751 |
if (connector.Index == 0) |
|
1752 |
_LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
|
1753 |
else |
|
2228 | 1754 |
{ |
2229 |
string symbolPath = string.Empty; |
|
2230 |
#region get symbol path |
|
2231 |
LMModelItem modelItem = dataSource.GetModelItem(_LMConnector.ModelItemID); |
|
2232 |
foreach (LMRepresentation rep in modelItem.Representations) |
|
1755 |
ChildSymbol child = null; |
|
1756 |
foreach (var childSymbol in symbol.ChildSymbols) |
|
2233 | 1757 |
{ |
2234 |
if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName())) |
|
2235 |
{ |
|
2236 |
symbolPath = rep.get_FileName(); |
|
1758 |
if (childSymbol.Connectors.Contains(connector)) |
|
1759 |
child = childSymbol; |
|
1760 |
else |
|
1761 |
child = GetChildSymbolByConnector(childSymbol, connector); |
|
1762 |
|
|
1763 |
if (child != null) |
|
2237 | 1764 |
break; |
2238 |
} |
|
2239 | 1765 |
} |
2240 |
ReleaseCOMObjects(modelItem); |
|
2241 |
#endregion |
|
2242 |
|
|
2243 |
double[] point = null; |
|
2244 |
if (IsStart) |
|
2245 |
point = points[points.Count - 1]; |
|
2246 |
else |
|
2247 |
point = points[0]; |
|
2248 | 1766 |
|
2249 |
_LMAItem = _placement.PIDCreateItem(symbolPath); |
|
2250 |
placeRunInputs = new PlaceRunInputs(); |
|
2251 |
placeRunInputs.AddSymbolTarget(_SameRunTargetLMSymbol, point[0], point[1]); |
|
2252 |
placeRunInputs.AddConnectorTarget(_LMConnector, point[0], point[1]); |
|
2253 |
LMConnector _ZeroLengthLMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
|
2254 |
if (_ZeroLengthLMConnector != null) |
|
2255 |
{ |
|
2256 |
RemoveConnectorForReModelingLine(_LMConnector); |
|
2257 |
ZeroLengthModelItemID.Add(_ZeroLengthLMConnector.ModelItemID); |
|
2258 |
ReleaseCOMObjects(_ZeroLengthLMConnector); |
|
2259 |
} |
|
2260 |
ReleaseCOMObjects(placeRunInputs); |
|
2261 |
ReleaseCOMObjects(_LMAItem); |
|
1767 |
if (child != null) |
|
1768 |
_LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId); |
|
2262 | 1769 |
} |
2263 | 1770 |
|
2264 |
foreach (var item in lines) |
|
2265 |
item.SPPID.ModelItemId = _LMConnector.ModelItemID; |
|
1771 |
break; |
|
2266 | 1772 |
} |
1773 |
} |
|
2267 | 1774 |
|
2268 |
_LMConnector.Commit(); |
|
2269 |
ReleaseCOMObjects(_LMConnector); |
|
1775 |
return _LMSymbol; |
|
1776 |
} |
|
1777 |
|
|
1778 |
/// <summary> |
|
1779 |
/// Connector를 가지고 있는 ChildSymbol Object 반환 |
|
1780 |
/// </summary> |
|
1781 |
/// <param name="item"></param> |
|
1782 |
/// <param name="connector"></param> |
|
1783 |
/// <returns></returns> |
|
1784 |
private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector) |
|
1785 |
{ |
|
1786 |
foreach (var childSymbol in item.ChildSymbols) |
|
1787 |
{ |
|
1788 |
if (childSymbol.Connectors.Contains(connector)) |
|
1789 |
return childSymbol; |
|
1790 |
else |
|
1791 |
return GetChildSymbolByConnector(childSymbol, connector); |
|
2270 | 1792 |
} |
2271 | 1793 |
|
2272 |
ReleaseCOMObjects(placeRunInputs); |
|
2273 |
ReleaseCOMObjects(_LMAItem); |
|
2274 |
if (_BranchTargetConnector != null) |
|
2275 |
ReleaseCOMObjects(_BranchTargetConnector); |
|
2276 |
if (_SameRunTargetConnector != null) |
|
2277 |
ReleaseCOMObjects(_SameRunTargetConnector); |
|
2278 |
if (_SameRunTargetLMSymbol != null) |
|
2279 |
ReleaseCOMObjects(_SameRunTargetLMSymbol); |
|
2280 |
foreach (var item in connectorVertices) |
|
2281 |
ReleaseCOMObjects(item.Key); |
|
2282 |
foreach (var item in branchConnectorVertices) |
|
2283 |
ReleaseCOMObjects(item.Key); |
|
1794 |
return null; |
|
2284 | 1795 |
} |
2285 | 1796 |
|
2286 | 1797 |
/// <summary> |
... | ... | |
2719 | 2230 |
} |
2720 | 2231 |
|
2721 | 2232 |
/// <summary> |
2722 |
/// LMConnector들을 가져온다. |
|
2723 |
/// </summary> |
|
2724 |
/// <param name="modelId"></param> |
|
2725 |
/// <returns></returns> |
|
2726 |
private List<LMConnector> GetConnectors(string modelId) |
|
2727 |
{ |
|
2728 |
List<LMConnector> connectors = new List<LMConnector>(); |
|
2729 |
LMModelItem modelItem = dataSource.GetModelItem(modelId); |
|
2730 |
|
|
2731 |
if (modelItem != null) |
|
2732 |
{ |
|
2733 |
foreach (LMRepresentation rep in modelItem.Representations) |
|
2734 |
{ |
|
2735 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
|
2736 |
{ |
|
2737 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
|
2738 |
connectors.Add(_LMConnector); |
|
2739 |
} |
|
2740 |
} |
|
2741 |
|
|
2742 |
ReleaseCOMObjects(modelItem); |
|
2743 |
} |
|
2744 |
|
|
2745 |
return connectors; |
|
2746 |
} |
|
2747 |
|
|
2748 |
/// <summary> |
|
2749 |
/// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 두점으로 라인의 교차점을 기준으로 구함 |
|
2233 |
/// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식 |
|
2750 | 2234 |
/// </summary> |
2751 | 2235 |
/// <param name="connectorVertices"></param> |
2752 | 2236 |
/// <param name="connX"></param> |
2753 | 2237 |
/// <param name="connY"></param> |
2754 |
/// <param name="x2"></param> |
|
2755 |
/// <param name="y2"></param> |
|
2756 | 2238 |
/// <returns></returns> |
2757 |
private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2)
|
|
2239 |
private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
|
|
2758 | 2240 |
{ |
2759 | 2241 |
double length = double.MaxValue; |
2760 | 2242 |
LMConnector targetConnector = null; |
... | ... | |
2765 | 2247 |
{ |
2766 | 2248 |
double[] point1 = points[i]; |
2767 | 2249 |
double[] point2 = points[i + 1]; |
2250 |
double x1 = Math.Min(point1[0], point2[0]); |
|
2251 |
double y1 = Math.Min(point1[1], point2[1]); |
|
2252 |
double x2 = Math.Max(point1[0], point2[0]); |
|
2253 |
double y2 = Math.Max(point1[1], point2[1]); |
|
2768 | 2254 |
|
2769 |
double maxLineX = Math.Max(point1[0], point2[0]); |
|
2770 |
double minLineX = Math.Min(point1[0], point2[0]); |
|
2771 |
double maxLineY = Math.Max(point1[1], point2[1]); |
|
2772 |
double minLineY = Math.Min(point1[1], point2[1]); |
|
2773 |
|
|
2774 |
SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY); |
|
2775 |
|
|
2776 |
// 두직선의 교차점 |
|
2777 |
double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]); |
|
2778 |
if (crossingPoint != null) |
|
2255 |
if ((x1 <= connX && x2 >= connX) || |
|
2256 |
(y1 <= connY && y2 >= connY)) |
|
2779 | 2257 |
{ |
2780 |
double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]);
|
|
2258 |
double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY);
|
|
2781 | 2259 |
if (length >= distance) |
2782 | 2260 |
{ |
2783 |
if (slope == SlopeType.Slope && |
|
2784 |
minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] && |
|
2785 |
minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
|
2786 |
{ |
|
2787 |
targetConnector = item.Key; |
|
2788 |
length = distance; |
|
2789 |
} |
|
2790 |
else if (slope == SlopeType.HORIZONTAL && |
|
2791 |
minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0]) |
|
2792 |
{ |
|
2793 |
targetConnector = item.Key; |
|
2794 |
length = distance; |
|
2795 |
} |
|
2796 |
else if (slope == SlopeType.VERTICAL && |
|
2797 |
minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
|
2798 |
{ |
|
2799 |
targetConnector = item.Key; |
|
2800 |
length = distance; |
|
2801 |
} |
|
2261 |
targetConnector = item.Key; |
|
2262 |
length = distance; |
|
2263 |
} |
|
2264 |
|
|
2265 |
distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY); |
|
2266 |
if (length >= distance) |
|
2267 |
{ |
|
2268 |
targetConnector = item.Key; |
|
2269 |
length = distance; |
|
2802 | 2270 |
} |
2803 | 2271 |
} |
2804 | 2272 |
} |
2805 |
|
|
2806 |
|
|
2807 | 2273 |
} |
2808 | 2274 |
|
2275 |
// 못찾았을때. |
|
2276 |
length = double.MaxValue; |
|
2809 | 2277 |
if (targetConnector == null) |
2810 | 2278 |
{ |
2811 | 2279 |
foreach (var item in connectorVertices) |
2812 | 2280 |
{ |
2813 | 2281 |
List<double[]> points = item.Value; |
2814 |
foreach (var point in points) |
|
2282 |
|
|
2283 |
foreach (double[] point in points) |
|
2815 | 2284 |
{ |
2816 |
double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, point[0], point[1]);
|
|
2285 |
double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
|
|
2817 | 2286 |
if (length >= distance) |
2818 | 2287 |
{ |
2819 | 2288 |
targetConnector = item.Key; |
... | ... | |
2821 | 2290 |
} |
2822 | 2291 |
} |
2823 | 2292 |
} |
2824 |
|
|
2825 | 2293 |
} |
2826 | 2294 |
|
2827 | 2295 |
return targetConnector; |
2828 | 2296 |
} |
2829 | 2297 |
|
2830 |
/// <summary> |
|
2831 |
/// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 한점으로 제일 가까운 기준으로 구함(단순) |
|
2832 |
/// </summary> |
|
2833 |
/// <param name="connectorVertices"></param> |
|
2834 |
/// <param name="connX"></param> |
|
2835 |
/// <param name="connY"></param> |
|
2836 |
/// <returns></returns> |
|
2837 |
private LMConnector FindTargetLMConnectorByPoint(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY) |
|
2298 |
private LMConnector FindTargetLMConnectorForBranch(Line line, Line targetLine, ref double x, ref double y) |
|
2838 | 2299 |
{ |
2300 |
Dictionary<LMConnector, List<double[]>> vertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId); |
|
2301 |
|
|
2839 | 2302 |
double length = double.MaxValue; |
2840 | 2303 |
LMConnector targetConnector = null; |
2841 |
foreach (var item in connectorVertices) |
|
2304 |
double[] resultPoint = null; |
|
2305 |
List<double[]> targetVertices = null; |
|
2306 |
|
|
2307 |
// Vertices 포인트에 제일 가까운곳 |
|
2308 |
foreach (var item in vertices) |
|
2842 | 2309 |
{ |
2843 | 2310 |
List<double[]> points = item.Value; |
2844 |
|
|
2845 |
foreach (double[] point in points) |
|
2311 |
for (int i = 0; i < points.Count; i++) |
|
2846 | 2312 |
{ |
2847 |
double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY); |
|
2313 |
double[] point = points[i]; |
|
2314 |
double tempX = point[0]; |
|
2315 |
double tempY = point[1]; |
|
2316 |
|
|
2317 |
double distance = SPPIDUtil.CalcPointToPointdDistance(tempX, tempY, x, y); |
|
2848 | 2318 |
if (length >= distance) |
2849 | 2319 |
{ |
2850 | 2320 |
targetConnector = item.Key; |
2851 | 2321 |
length = distance; |
2322 |
resultPoint = point; |
|
2323 |
targetVertices = item.Value; |
|
2852 | 2324 |
} |
2853 | 2325 |
} |
2854 | 2326 |
} |
2855 | 2327 |
|
2856 |
return targetConnector; |
|
2857 |
} |
|
2858 |
|
|
2859 |
/// <summary> |
|
2860 |
/// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식 |
|
2861 |
/// </summary> |
|
2862 |
/// <param name="connectorVertices"></param> |
|
2863 |
/// <param name="connX"></param> |
|
2864 |
/// <param name="connY"></param> |
|
2865 |
/// <returns></returns> |
|
2866 |
private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY) |
|
2867 |
{ |
|
2868 |
double length = double.MaxValue; |
|
2869 |
LMConnector targetConnector = null; |
|
2870 |
foreach (var item in connectorVertices) |
|
2328 |
// Vertices Cross에 제일 가까운곳 |
|
2329 |
foreach (var item in vertices) |
|
2871 | 2330 |
{ |
2872 | 2331 |
List<double[]> points = item.Value; |
2873 | 2332 |
for (int i = 0; i < points.Count - 1; i++) |
2874 | 2333 |
{ |
2875 | 2334 |
double[] point1 = points[i]; |
2876 | 2335 |
double[] point2 = points[i + 1]; |
2877 |
double x1 = Math.Min(point1[0], point2[0]); |
|
2878 |
double y1 = Math.Min(point1[1], point2[1]); |
|
2879 |
double x2 = Math.Max(point1[0], point2[0]); |
|
2880 |
double y2 = Math.Max(point1[1], point2[1]); |
|
2881 | 2336 |
|
2882 |
if ((x1 <= connX && x2 >= connX) || |
|
2883 |
(y1 <= connY && y2 >= connY)) |
|
2884 |
{ |
|
2885 |
double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY); |
|
2886 |
if (length >= distance) |
|
2887 |
{ |
|
2888 |
targetConnector = item.Key; |
|
2889 |
length = distance; |
|
2890 |
} |
|
2337 |
double maxLineX = Math.Max(point1[0], point2[0]); |
|
2338 |
double minLineX = Math.Min(point1[0], point2[0]); |
|
2339 |
double maxLineY = Math.Max(point1[1], point2[1]); |
|
2340 |
double minLineY = Math.Min(point1[1], point2[1]); |
|
2891 | 2341 |
|
2892 |
distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY); |
|
2342 |
SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY); |
|
2343 |
|
|
2344 |
double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y, point1[0], point1[1], point2[0], point2[1]); |
|
2345 |
if (crossingPoint != null) |
|
2346 |
{ |
|
2347 |
double distance = SPPIDUtil.CalcPointToPointdDistance(crossingPoint[0], crossingPoint[1], x, y); |
|
2893 | 2348 |
if (length >= distance) |
2894 | 2349 |
{ |
2895 |
targetConnector = item.Key; |
|
2896 |
length = distance; |
|
2350 |
if (slope == SlopeType.Slope && |
|
2351 |
minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] && |
|
2352 |
minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
|
2353 |
{ |
|
2354 |
targetConnector = item.Key; |
|
2355 |
length = distance; |
|
2356 |
resultPoint = crossingPoint; |
|
2357 |
targetVertices = item.Value; |
|
2358 |
} |
내보내기 Unified diff