hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 53c81765
이력 | 보기 | 이력해설 | 다운로드 (120 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Threading.Tasks; |
6 |
using System.Data; |
7 |
using Llama; |
8 |
using Plaice; |
9 |
using Ingr.RAD2D.Interop.RAD2D; |
10 |
using Ingr.RAD2D.Internal; |
11 |
using Ingr.RAD2D.Helper; |
12 |
using Converter.BaseModel; |
13 |
using Converter.SPPID.Model; |
14 |
using Converter.SPPID.Properties; |
15 |
using Converter.SPPID.Util; |
16 |
using Converter.SPPID.DB; |
17 |
using Ingr.RAD2D.MacroControls.CmdCtrl; |
18 |
using Ingr.RAD2D; |
19 |
using System.Windows; |
20 |
using System.Threading; |
21 |
using System.Drawing; |
22 |
using Microsoft.VisualBasic; |
23 |
using Newtonsoft.Json; |
24 |
|
25 |
using DevExpress.XtraSplashScreen; |
26 |
namespace Converter.SPPID |
27 |
{ |
28 |
public class AutoModeling |
29 |
{ |
30 |
Placement _placement; |
31 |
LMADataSource dataSource; |
32 |
dynamic newDrawing; |
33 |
dynamic application; |
34 |
Ingr.RAD2D.Application radApp; |
35 |
SPPID_Document document; |
36 |
ETCSetting _ETCSetting; |
37 |
|
38 |
public string DocumentLabelText { get; set; } |
39 |
|
40 |
int CurrentCount; |
41 |
List <Tuple<string, Line, Line>> BranchLines = new List<Tuple<string, Line, Line>>(); |
42 |
|
43 |
public AutoModeling(SPPID_Document document, dynamic application, Ingr.RAD2D.Application radApp) |
44 |
{ |
45 |
this.document = document; |
46 |
this.application = application; |
47 |
this.radApp = radApp; |
48 |
this._ETCSetting = ETCSetting.GetInstance(); |
49 |
} |
50 |
|
51 |
private int ClacProgressCount() |
52 |
{ |
53 |
int EquipCount = 0; |
54 |
int SymbolCount = 0; |
55 |
int LineCount = 0; |
56 |
int NoteCount = 0; |
57 |
int TextCount = 0; |
58 |
int EndBreakCount = 0; |
59 |
int LineNumberCount = 0; |
60 |
|
61 |
EquipCount = document.Equipments.Count; |
62 |
SymbolCount = document.SYMBOLS.Count; |
63 |
SymbolCount = SymbolCount * 3; |
64 |
|
65 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
66 |
foreach (LineRun run in lineNumber.RUNS) |
67 |
foreach (var item in run.RUNITEMS) |
68 |
if (item.GetType() == typeof(Line)) |
69 |
LineCount++; |
70 |
foreach (TrimLine trimLine in document.TRIMLINES) |
71 |
foreach (LineRun run in trimLine.RUNS) |
72 |
foreach (var item in run.RUNITEMS) |
73 |
if (item.GetType() == typeof(Line)) |
74 |
LineCount++; |
75 |
|
76 |
LineCount = LineCount * 2; |
77 |
NoteCount = document.NOTES.Count; |
78 |
TextCount = document.TEXTINFOS.Count; |
79 |
EndBreakCount = document.EndBreaks.Count; |
80 |
LineNumberCount = document.LINENUMBERS.Count; |
81 |
LineNumberCount = LineNumberCount * 2; |
82 |
|
83 |
return EquipCount + SymbolCount + LineCount + NoteCount + TextCount + EndBreakCount; |
84 |
} |
85 |
|
86 |
/// <summary> |
87 |
/// 도면 단위당 실행되는 메서드 |
88 |
/// </summary> |
89 |
public void Run() |
90 |
{ |
91 |
try |
92 |
{ |
93 |
_placement = new Placement(); |
94 |
dataSource = _placement.PIDDataSource; |
95 |
|
96 |
CreateDocument(); |
97 |
|
98 |
if (DocumentCoordinateCorrection()) |
99 |
{ |
100 |
int AllCount = ClacProgressCount(); |
101 |
|
102 |
SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true); |
103 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllStep, AllCount); |
104 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText); |
105 |
|
106 |
//SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Group Symbol Modeling"); |
107 |
//List<List<Symbol>> symbolGroups = SPPIDUtil.GetThreeConnectedSymbolGroup(document); |
108 |
//foreach (List<Symbol> symbolGroup in symbolGroups) |
109 |
// SymbolModelingByThreeSymbolGroup(symbolGroup); |
110 |
|
111 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Priority Symbol Modeling"); |
112 |
List<Symbol> prioritySymbols = GetPrioritySymbol(); |
113 |
foreach (var item in prioritySymbols) |
114 |
SymbolModelingByPriority(item); |
115 |
|
116 |
// Equipment Modeling |
117 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Equipments Modeling"); |
118 |
foreach (Equipment equipment in document.Equipments) |
119 |
EquipmentModeling(equipment); |
120 |
|
121 |
// LineRun Symbol Modeling |
122 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbols Modeling"); |
123 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
124 |
foreach (LineRun run in lineNumber.RUNS) |
125 |
SymbolModelingByRun(run); |
126 |
// TrimLineRun Symbol Modeling |
127 |
foreach (TrimLine trimLine in document.TRIMLINES) |
128 |
foreach (LineRun run in trimLine.RUNS) |
129 |
SymbolModelingByRun(run); |
130 |
|
131 |
// LineRun Line Modeling |
132 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Lines Modeling"); |
133 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
134 |
foreach (LineRun run in lineNumber.RUNS) |
135 |
LineModelingByRun(run); |
136 |
// TrimLineRun Line Modeling |
137 |
foreach (TrimLine trimLine in document.TRIMLINES) |
138 |
foreach (LineRun run in trimLine.RUNS) |
139 |
LineModelingByRun(run); |
140 |
|
141 |
// Branch Line Modeling |
142 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Branch Lines Modeling"); |
143 |
foreach (var item in BranchLines) |
144 |
BranchLineModeling(item); |
145 |
|
146 |
// EndBreak Modeling |
147 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling"); |
148 |
foreach (var item in document.EndBreaks) |
149 |
EndBreakModeling(item); |
150 |
|
151 |
// SpecBreak Modeling |
152 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "SpecBreaks Modeling"); |
153 |
foreach (var item in document.SpecBreaks) |
154 |
SpecBreakModeling(item); |
155 |
|
156 |
// LineNumber Modeling |
157 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "LineNumbers Modeling"); |
158 |
foreach (var item in document.LINENUMBERS) |
159 |
LineNumberModeling(item); |
160 |
|
161 |
// LineNumber Modeling |
162 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Flow Mark Modeling"); |
163 |
foreach (var item in document.LINES) |
164 |
FlowMarkModeling(item); |
165 |
|
166 |
// Note Modeling |
167 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling"); |
168 |
foreach (var item in document.NOTES) |
169 |
NoteModeling(item); |
170 |
|
171 |
// Text Modeling |
172 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling"); |
173 |
foreach (var item in document.TEXTINFOS) |
174 |
TextModeling(item); |
175 |
|
176 |
// LineRun Line Join |
177 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Join LineRuns"); |
178 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
179 |
foreach (LineRun run in lineNumber.RUNS) |
180 |
JoinRunLine(run); |
181 |
// TrimLineRun Line Join |
182 |
foreach (TrimLine trimLine in document.TRIMLINES) |
183 |
foreach (LineRun run in trimLine.RUNS) |
184 |
JoinRunLine(run); |
185 |
|
186 |
// Input LineNumber Attribute |
187 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Lines Attribute"); |
188 |
foreach (var item in document.LINENUMBERS) |
189 |
InputLineNumberAttribute(item); |
190 |
|
191 |
// Input Symbol Attribute |
192 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute"); |
193 |
foreach (var item in document.SYMBOLS) |
194 |
InputSymbolAttribute(item, item.ATTRIBUTES); |
195 |
|
196 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Labels Modeling"); |
197 |
foreach (var item in document.SYMBOLS) |
198 |
LabelSymbolModeling(item); |
199 |
|
200 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, AllCount); |
201 |
} |
202 |
} |
203 |
catch (Exception ex) |
204 |
{ |
205 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
206 |
} |
207 |
finally |
208 |
{ |
209 |
application.ActiveWindow.Fit(); |
210 |
|
211 |
if (radApp.ActiveDocument != null) |
212 |
{ |
213 |
//radApp.ActiveDocument.Save(); |
214 |
//radApp.ActiveDocument.SaveOnClose = false; |
215 |
//radApp.ActiveDocument.Close(false); |
216 |
|
217 |
ReleaseCOMObjects(newDrawing); |
218 |
} |
219 |
|
220 |
ReleaseCOMObjects(dataSource); |
221 |
ReleaseCOMObjects(_placement); |
222 |
|
223 |
//SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null); |
224 |
SplashScreenManager.CloseForm(false); |
225 |
} |
226 |
} |
227 |
|
228 |
/// <summary> |
229 |
/// 도면 생성 메서드 |
230 |
/// </summary> |
231 |
private void CreateDocument() |
232 |
{ |
233 |
string drawingName = document.DrawingName; |
234 |
string drawingNumber = document.DrawingNumber; |
235 |
|
236 |
GetDrawingNameAndNumber(ref drawingName, ref drawingNumber); |
237 |
|
238 |
newDrawing = application.Drawings.Add(document.Unit, document.Template, drawingNumber, drawingName); |
239 |
application.ActiveWindow.Fit(); |
240 |
Thread.Sleep(1000); |
241 |
application.ActiveWindow.Zoom = 2000; |
242 |
Thread.Sleep(2000); |
243 |
|
244 |
|
245 |
} |
246 |
|
247 |
private void GetDrawingNameAndNumber(ref string drawingName, ref string drawingNumber) |
248 |
{ |
249 |
LMDrawings drawings = new LMDrawings(); |
250 |
drawings.Collect(dataSource); |
251 |
|
252 |
List<string> drawingNameList = new List<string>(); |
253 |
List<string> drawingNumberList = new List<string>(); |
254 |
|
255 |
foreach (LMDrawing item in drawings) |
256 |
{ |
257 |
drawingNameList.Add(item.Attributes["Name"].get_Value().ToString()); |
258 |
drawingNumberList.Add(item.Attributes["DrawingNumber"].get_Value().ToString()); |
259 |
} |
260 |
|
261 |
int nameLength = drawingName.Length; |
262 |
while (drawingNameList.Contains(drawingName)) |
263 |
{ |
264 |
if (nameLength == drawingName.Length) |
265 |
drawingName += "-1"; |
266 |
else |
267 |
{ |
268 |
int index = Convert.ToInt32(drawingName.Remove(0, nameLength + 1)); |
269 |
drawingName = drawingName.Substring(0, nameLength + 1); |
270 |
drawingName += ++index; |
271 |
} |
272 |
} |
273 |
|
274 |
int numberLength = drawingNumber.Length; |
275 |
while (drawingNameList.Contains(drawingNumber)) |
276 |
{ |
277 |
if (numberLength == drawingNumber.Length) |
278 |
drawingNumber += "-1"; |
279 |
else |
280 |
{ |
281 |
int index = Convert.ToInt32(drawingNumber.Remove(0, numberLength + 1)); |
282 |
drawingNumber = drawingNumber.Substring(0, numberLength + 1); |
283 |
drawingNumber += ++index; |
284 |
} |
285 |
} |
286 |
|
287 |
ReleaseCOMObjects(drawings); |
288 |
} |
289 |
|
290 |
/// <summary> |
291 |
/// 도면 크기 구하는 메서드 |
292 |
/// </summary> |
293 |
/// <returns></returns> |
294 |
private bool DocumentCoordinateCorrection() |
295 |
{ |
296 |
if (Settings.Default.DrawingX != 0 && Settings.Default.DrawingY != 0) |
297 |
{ |
298 |
document.SetSPPIDLocation(Settings.Default.DrawingX, Settings.Default.DrawingY); |
299 |
document.CoordinateCorrection(); |
300 |
return true; |
301 |
} |
302 |
else |
303 |
return false; |
304 |
} |
305 |
|
306 |
/// <summary> |
307 |
/// 라인을 Run 단위로 모델링하는 진입 메서드 |
308 |
/// </summary> |
309 |
/// <param name="run"></param> |
310 |
private void LineModelingByRun(LineRun run) |
311 |
{ |
312 |
Line prevLine = null; |
313 |
List<Line> lines = new List<Line>(); |
314 |
foreach (var item in run.RUNITEMS) |
315 |
{ |
316 |
// Line일 경우 |
317 |
if (item.GetType() == typeof(Line)) |
318 |
{ |
319 |
Line line = item as Line; |
320 |
if (prevLine == null) |
321 |
lines.Add(line); |
322 |
else if (prevLine != null) |
323 |
{ |
324 |
if (prevLine.SPPID.MAPPINGNAME == line.SPPID.MAPPINGNAME) |
325 |
lines.Add(line); |
326 |
else |
327 |
{ |
328 |
if (lines.Count > 0) |
329 |
{ |
330 |
LineModeling(lines); |
331 |
lines.Clear(); |
332 |
} |
333 |
lines.Add(line); |
334 |
} |
335 |
} |
336 |
|
337 |
prevLine = line; |
338 |
|
339 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
340 |
} |
341 |
// Symbol 일 경우 |
342 |
else if (item.GetType() == typeof(Symbol)) |
343 |
{ |
344 |
if (lines.Count > 0) |
345 |
{ |
346 |
LineModeling(lines); |
347 |
lines.Clear(); |
348 |
} |
349 |
} |
350 |
} |
351 |
|
352 |
if (lines.Count > 0) |
353 |
LineModeling(lines); |
354 |
} |
355 |
|
356 |
/// <summary> |
357 |
/// 심볼을 Run 단위로 모델링하는 진입 메서드 |
358 |
/// </summary> |
359 |
/// <param name="run"></param> |
360 |
private void SymbolModelingByRun(LineRun run) |
361 |
{ |
362 |
// 양끝 Symbol 검사 후 Line이 나올때까지만 Symbol Modeling |
363 |
if (run.RUNITEMS.Count > 0) |
364 |
{ |
365 |
if (run.RUNITEMS[0].GetType() == typeof(Symbol)) |
366 |
SymbolModelingByRunStart(run.RUNITEMS[0] as Symbol, run); |
367 |
|
368 |
if (run.RUNITEMS[run.RUNITEMS.Count - 1].GetType() == typeof(Symbol)) |
369 |
SymbolModelingByRunEnd(run.RUNITEMS[run.RUNITEMS.Count - 1] as Symbol, run); |
370 |
} |
371 |
|
372 |
Symbol targetSymbol = null; |
373 |
foreach (var item in run.RUNITEMS) |
374 |
{ |
375 |
if (item.GetType() == typeof(Symbol)) |
376 |
{ |
377 |
Symbol symbol = item as Symbol; |
378 |
SymbolModeling(symbol, targetSymbol); |
379 |
targetSymbol = symbol; |
380 |
} |
381 |
else |
382 |
{ |
383 |
targetSymbol = null; |
384 |
} |
385 |
} |
386 |
} |
387 |
|
388 |
/// <summary> |
389 |
/// Run에 있는 심볼을 모델링하는데 기준이 Run의 시작점 |
390 |
/// </summary> |
391 |
/// <param name="symbol"></param> |
392 |
/// <param name="run"></param> |
393 |
private void SymbolModelingByRunStart(Symbol symbol, LineRun run) |
394 |
{ |
395 |
foreach (var connector in symbol.CONNECTORS) |
396 |
{ |
397 |
object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
398 |
if (targetItem != null && |
399 |
(targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) && |
400 |
!IsSameLineRun(symbol, targetItem)) |
401 |
{ |
402 |
SymbolModeling(symbol, targetItem as Symbol); |
403 |
for (int i = 1; i < run.RUNITEMS.Count; i++) |
404 |
{ |
405 |
object item = run.RUNITEMS[i]; |
406 |
if (item.GetType() == typeof(Symbol)) |
407 |
SymbolModeling(item as Symbol, run.RUNITEMS[i - 1] as Symbol); |
408 |
else |
409 |
break; |
410 |
} |
411 |
break; |
412 |
} |
413 |
} |
414 |
|
415 |
|
416 |
} |
417 |
|
418 |
/// <summary> |
419 |
/// Run에 있는 심볼을 모델링하는데 기준이 Run의 끝점 |
420 |
/// </summary> |
421 |
/// <param name="symbol"></param> |
422 |
/// <param name="run"></param> |
423 |
private void SymbolModelingByRunEnd(Symbol symbol, LineRun run) |
424 |
{ |
425 |
foreach (var connector in symbol.CONNECTORS) |
426 |
{ |
427 |
object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
428 |
if (targetItem != null && |
429 |
(targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) && |
430 |
!IsSameLineRun(symbol, targetItem)) |
431 |
{ |
432 |
SymbolModeling(symbol, targetItem as Symbol); |
433 |
for (int i = run.RUNITEMS.Count - 2; i >= 0; i--) |
434 |
{ |
435 |
object item = run.RUNITEMS[i]; |
436 |
if (item.GetType() == typeof(Symbol)) |
437 |
SymbolModeling(item as Symbol, run.RUNITEMS[i + 1] as Symbol); |
438 |
else |
439 |
break; |
440 |
} |
441 |
break; |
442 |
} |
443 |
} |
444 |
} |
445 |
|
446 |
/// <summary> |
447 |
/// 심볼을 실제로 Modeling 메서드 |
448 |
/// </summary> |
449 |
/// <param name="symbol"></param> |
450 |
/// <param name="targetSymbol"></param> |
451 |
/// <param name="prevSymbol"></param> |
452 |
private void SymbolModeling(Symbol symbol, Symbol targetSymbol) |
453 |
{ |
454 |
#if DEBUG |
455 |
try |
456 |
{ |
457 |
#endif |
458 |
// OWNERSYMBOL Attribute, 값을 가지고 있을 경우 |
459 |
BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(attr => attr.ATTRIBUTE == "OWNERSYMBOL"); |
460 |
if (itemAttribute != null && string.IsNullOrEmpty(itemAttribute.VALUE) && itemAttribute.VALUE != "None") |
461 |
return; |
462 |
// 이미 모델링 됐을 경우 |
463 |
else if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
464 |
return; |
465 |
|
466 |
LMSymbol _LMSymbol = null; |
467 |
|
468 |
string mappingPath = symbol.SPPID.MAPPINGNAME; |
469 |
double x = symbol.SPPID.ORIGINAL_X; |
470 |
double y = symbol.SPPID.ORIGINAL_Y; |
471 |
int mirror = 0; |
472 |
double angle = symbol.ANGLE; |
473 |
|
474 |
SPPIDUtil.ConvertGridPoint(ref x, ref y); |
475 |
|
476 |
// OPC 일경우 180도 일때 Mirror |
477 |
if (mappingPath.Contains("Piping OPC's") && angle == Math.PI) |
478 |
mirror = 1; |
479 |
|
480 |
// Mirror 계산 |
481 |
if (symbol.FLIP == 1) |
482 |
{ |
483 |
mirror = 1; |
484 |
angle += Math.PI; |
485 |
} |
486 |
|
487 |
if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId)) |
488 |
{ |
489 |
LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); |
490 |
Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, symbol.UID, targetSymbol); |
491 |
if (connector != null) |
492 |
GetTargetSymbolConnectorPoint(connector, targetSymbol, ref x, ref y); |
493 |
|
494 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem); |
495 |
ReleaseCOMObjects(_TargetItem); |
496 |
} |
497 |
else |
498 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
499 |
|
500 |
|
501 |
if (_LMSymbol != null) |
502 |
{ |
503 |
_LMSymbol.Commit(); |
504 |
symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
505 |
symbol.SPPID.GraphicOID = _LMSymbol.get_GraphicOID(); |
506 |
|
507 |
foreach (var item in symbol.ChildSymbols) |
508 |
CreateChildSymbol(item, _LMSymbol); |
509 |
} |
510 |
|
511 |
ReleaseCOMObjects(_LMSymbol); |
512 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
513 |
#if DEBUG |
514 |
|
515 |
} |
516 |
catch (Exception ex) |
517 |
{ |
518 |
System.Windows.Forms.MessageBox.Show(ex.StackTrace); |
519 |
} |
520 |
#endif |
521 |
} |
522 |
|
523 |
/// <summary> |
524 |
/// ID2의 Symbol Width와 Height를 비교해서 상대적인 SPPID Connector좌표를 가져온다. |
525 |
/// </summary> |
526 |
/// <param name="targetConnector"></param> |
527 |
/// <param name="targetSymbol"></param> |
528 |
/// <param name="x"></param> |
529 |
/// <param name="y"></param> |
530 |
private void GetTargetSymbolConnectorPoint(Connector targetConnector, Symbol targetSymbol, ref double x, ref double y) |
531 |
{ |
532 |
LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); |
533 |
|
534 |
double[] range = null; |
535 |
List<double[]> points = new List<double[]>(); |
536 |
GetSPPIDSymbolRangeAndConnectionPoints(targetSymbol, ref range, points); |
537 |
double x1 = range[0]; |
538 |
double y1 = range[1]; |
539 |
double x2 = range[2]; |
540 |
double y2 = range[3]; |
541 |
|
542 |
// Origin 기준 Connector의 위치차이 |
543 |
double sceneX = 0; |
544 |
double sceneY = 0; |
545 |
SPPIDUtil.ConvertPointBystring(targetConnector.SCENECONNECTPOINT, ref sceneX, ref sceneY); |
546 |
double originX = 0; |
547 |
double originY = 0; |
548 |
SPPIDUtil.ConvertPointBystring(targetSymbol.ORIGINALPOINT, ref originX, ref originY); |
549 |
double gapX = originX - sceneX; |
550 |
double gapY = originY - sceneY; |
551 |
|
552 |
// SPPID Symbol과 ID2 심볼의 크기 차이 |
553 |
double sizeWidth = 0; |
554 |
double sizeHeight = 0; |
555 |
SPPIDUtil.ConvertPointBystring(targetSymbol.SIZE, ref sizeWidth, ref sizeHeight); |
556 |
double percentX = (x2 - x1) / sizeWidth; |
557 |
double percentY = (y2 - y1) / sizeHeight; |
558 |
|
559 |
double SPPIDgapX = gapX * percentX; |
560 |
double SPPIDgapY = gapY * percentY; |
561 |
|
562 |
double[] SPPIDOriginPoint = new double[] { _TargetItem.get_XCoordinate() - SPPIDgapX, _TargetItem.get_YCoordinate() + SPPIDgapY }; |
563 |
double distance = double.MaxValue; |
564 |
double[] resultPoint; |
565 |
foreach (var point in points) |
566 |
{ |
567 |
double result = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], SPPIDOriginPoint[0], SPPIDOriginPoint[1]); |
568 |
if (distance > result) |
569 |
{ |
570 |
distance = result; |
571 |
resultPoint = point; |
572 |
x = point[0]; |
573 |
y = point[1]; |
574 |
} |
575 |
} |
576 |
|
577 |
ReleaseCOMObjects(_TargetItem); |
578 |
} |
579 |
|
580 |
/// <summary> |
581 |
/// SPPID Symbol의 Range를 구한다. |
582 |
/// </summary> |
583 |
/// <param name="symbol"></param> |
584 |
/// <param name="range"></param> |
585 |
private void GetSPPIDSymbolRangeAndConnectionPoints(Symbol symbol, ref double[] range, List<double[]> points) |
586 |
{ |
587 |
LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
588 |
Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()]; |
589 |
double x1 = 0; |
590 |
double y1 = 0; |
591 |
double x2 = 0; |
592 |
double y2 = 0; |
593 |
symbol2d.Range(out x1, out y1, out x2, out y2); |
594 |
range = new double[] { x1, y1, x2, y2 }; |
595 |
|
596 |
for (int i = 1; i < int.MaxValue; i++) |
597 |
{ |
598 |
double connX = 0; |
599 |
double connY = 0; |
600 |
if (_placement.PIDConnectPointLocation(_TargetItem, i, ref connX, ref connY)) |
601 |
points.Add(new double[] { connX, connY }); |
602 |
else |
603 |
break; |
604 |
} |
605 |
|
606 |
foreach (var childSymbol in symbol.ChildSymbols) |
607 |
GetSPPIDChildSymbolRange(childSymbol, ref range, points); |
608 |
|
609 |
ReleaseCOMObjects(_TargetItem); |
610 |
} |
611 |
|
612 |
/// <summary> |
613 |
/// Child Modeling 된 Symbol의 Range를 구한다. |
614 |
/// </summary> |
615 |
/// <param name="childSymbol"></param> |
616 |
/// <param name="range"></param> |
617 |
private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range, List<double[]> points) |
618 |
{ |
619 |
LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId); |
620 |
Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()]; |
621 |
double x1 = 0; |
622 |
double y1 = 0; |
623 |
double x2 = 0; |
624 |
double y2 = 0; |
625 |
symbol2d.Range(out x1, out y1, out x2, out y2); |
626 |
range[0] = Math.Min(range[0], x1); |
627 |
range[1] = Math.Min(range[1], y1); |
628 |
range[2] = Math.Max(range[2], x2); |
629 |
range[3] = Math.Max(range[3], y2); |
630 |
|
631 |
for (int i = 1; i < int.MaxValue; i++) |
632 |
{ |
633 |
double connX = 0; |
634 |
double connY = 0; |
635 |
if (_placement.PIDConnectPointLocation(_ChildSymbol, i, ref connX, ref connY)) |
636 |
points.Add(new double[] { connX, connY }); |
637 |
else |
638 |
break; |
639 |
} |
640 |
|
641 |
foreach (var loopChildSymbol in childSymbol.ChildSymbols) |
642 |
GetSPPIDChildSymbolRange(loopChildSymbol, ref range, points); |
643 |
|
644 |
ReleaseCOMObjects(_ChildSymbol); |
645 |
} |
646 |
|
647 |
/// <summary> |
648 |
/// Label Symbol Modeling |
649 |
/// </summary> |
650 |
/// <param name="symbol"></param> |
651 |
private void LabelSymbolModeling(Symbol symbol) |
652 |
{ |
653 |
BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL"); |
654 |
if (itemAttribute == null || string.IsNullOrEmpty(itemAttribute.VALUE)) |
655 |
return; |
656 |
|
657 |
Array points = new double[] { 0, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y }; |
658 |
|
659 |
string symbolUID = itemAttribute.VALUE; |
660 |
object targetItem = SPPIDUtil.FindObjectByUID(document, symbolUID); |
661 |
if (targetItem != null) |
662 |
{ |
663 |
// Object 아이템이 Symbol일 경우 Equipment일 경우 |
664 |
string sRep = null; |
665 |
if (targetItem.GetType() == typeof(Symbol)) |
666 |
sRep = ((Symbol)targetItem).SPPID.RepresentationId; |
667 |
else if (targetItem.GetType() == typeof(Equipment)) |
668 |
sRep = ((Equipment)targetItem).SPPID.RepresentationId; |
669 |
|
670 |
if (!string.IsNullOrEmpty(sRep)) |
671 |
{ |
672 |
// LEADER Line 검사 |
673 |
bool leaderLine = false; |
674 |
SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID); |
675 |
if (symbolMapping != null) |
676 |
leaderLine = symbolMapping.LEADERLINE; |
677 |
|
678 |
// Target Symbol Item 가져오고 Label Modeling |
679 |
LMSymbol _TargetItem = dataSource.GetSymbol(sRep); |
680 |
LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: _TargetItem.AsLMRepresentation(), IsLeaderVisible: leaderLine); |
681 |
|
682 |
//Leader 선 센터로 |
683 |
if (_LMLabelPresist != null) |
684 |
{ |
685 |
// Target Item에 Label의 Attribute Input |
686 |
InputSymbolAttribute(targetItem, symbol.ATTRIBUTES); |
687 |
|
688 |
string OID = _LMLabelPresist.get_GraphicOID(); |
689 |
DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID] as DependencyObject; |
690 |
if (dependency != null) |
691 |
{ |
692 |
bool result = false; |
693 |
foreach (var attributes in dependency.AttributeSets) |
694 |
{ |
695 |
foreach (var attribute in attributes) |
696 |
{ |
697 |
string name = attribute.Name; |
698 |
string value = attribute.GetValue().ToString(); |
699 |
if (name == "DrawingItemType" && value == "LabelPersist") |
700 |
{ |
701 |
foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects) |
702 |
{ |
703 |
if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLineString2d) |
704 |
{ |
705 |
Ingr.RAD2D.LineString2d lineString2D = drawingObject as Ingr.RAD2D.LineString2d; |
706 |
double prevX = _TargetItem.get_XCoordinate(); |
707 |
double prevY = _TargetItem.get_YCoordinate(); |
708 |
lineString2D.InsertVertex(lineString2D.VertexCount, prevX, prevY); |
709 |
lineString2D.RemoveVertex(lineString2D.VertexCount); |
710 |
result = true; |
711 |
break; |
712 |
} |
713 |
} |
714 |
} |
715 |
|
716 |
if (result) |
717 |
break; |
718 |
} |
719 |
|
720 |
if (result) |
721 |
break; |
722 |
} |
723 |
} |
724 |
|
725 |
_LMLabelPresist.Commit(); |
726 |
} |
727 |
|
728 |
ReleaseCOMObjects(_TargetItem); |
729 |
ReleaseCOMObjects(_LMLabelPresist); |
730 |
} |
731 |
} |
732 |
|
733 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
734 |
} |
735 |
|
736 |
/// <summary> |
737 |
/// Equipment를 실제로 Modeling 메서드 |
738 |
/// </summary> |
739 |
/// <param name="equipment"></param> |
740 |
private void EquipmentModeling(Equipment equipment) |
741 |
{ |
742 |
if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId)) |
743 |
return; |
744 |
|
745 |
LMSymbol _LMSymbol = null; |
746 |
LMSymbol targetItem = null; |
747 |
string mappingPath = equipment.SPPID.MAPPINGNAME; |
748 |
double x = equipment.SPPID.ORIGINAL_X; |
749 |
double y = equipment.SPPID.ORIGINAL_Y; |
750 |
int mirror = 0; |
751 |
double angle = equipment.ANGLE; |
752 |
|
753 |
SPPIDUtil.ConvertGridPoint(ref x, ref y); |
754 |
|
755 |
Connector connector = equipment.CONNECTORS.Find(conn => !string.IsNullOrEmpty(conn.CONNECTEDITEM) && conn.CONNECTEDITEM != "None"); |
756 |
if (connector != null) |
757 |
{ |
758 |
Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment; |
759 |
if (connEquipment != null) |
760 |
{ |
761 |
if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId)) |
762 |
EquipmentModeling(connEquipment); |
763 |
|
764 |
if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId)) |
765 |
{ |
766 |
targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId); |
767 |
if (targetItem != null) |
768 |
{ |
769 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem); |
770 |
} |
771 |
else |
772 |
{ |
773 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
774 |
} |
775 |
} |
776 |
else |
777 |
{ |
778 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
779 |
} |
780 |
} |
781 |
else |
782 |
{ |
783 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
784 |
} |
785 |
} |
786 |
else |
787 |
{ |
788 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
789 |
} |
790 |
|
791 |
if (_LMSymbol != null) |
792 |
{ |
793 |
_LMSymbol.Commit(); |
794 |
equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
795 |
equipment.SPPID.GraphicOID = _LMSymbol.get_GraphicOID(); |
796 |
ReleaseCOMObjects(_LMSymbol); |
797 |
} |
798 |
|
799 |
if (targetItem != null) |
800 |
{ |
801 |
ReleaseCOMObjects(targetItem); |
802 |
} |
803 |
|
804 |
ReleaseCOMObjects(_LMSymbol); |
805 |
|
806 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
807 |
} |
808 |
|
809 |
private void SymbolModelingByPriority(Symbol symbol) |
810 |
{ |
811 |
// Angle, Center, 우선순위 모델링 |
812 |
SymbolModeling(symbol, null); |
813 |
List<Symbol> group = new List<Symbol>() { symbol }; |
814 |
SPPIDUtil.FindConnectedSymbolGroup(document, symbol, group); |
815 |
|
816 |
List<Symbol> endModeling = new List<Symbol>() { symbol }; |
817 |
while (endModeling.Count != group.Count) |
818 |
{ |
819 |
foreach (var item in group) |
820 |
{ |
821 |
if (!endModeling.Contains(item)) |
822 |
{ |
823 |
bool result = false; |
824 |
foreach (var connector in item.CONNECTORS) |
825 |
{ |
826 |
Symbol connSymbol = group.Find(x => x.UID == connector.CONNECTEDITEM); |
827 |
if (connSymbol == item) |
828 |
throw new Exception(connSymbol.UID); |
829 |
|
830 |
if (connSymbol != null && endModeling.Contains(connSymbol)) |
831 |
{ |
832 |
SymbolModeling(item, connSymbol); |
833 |
endModeling.Add(item); |
834 |
result = true; |
835 |
break; |
836 |
} |
837 |
} |
838 |
|
839 |
if (result) |
840 |
break; |
841 |
} |
842 |
} |
843 |
} |
844 |
} |
845 |
|
846 |
/// <summary> |
847 |
/// 심볼을 실제로 Modeling할때 ChildSymbol이 있다면 Modeling하는 메서드 |
848 |
/// </summary> |
849 |
/// <param name="childSymbol"></param> |
850 |
/// <param name="parentSymbol"></param> |
851 |
private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol) |
852 |
{ |
853 |
Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()]; |
854 |
double x1 = 0; |
855 |
double x2 = 0; |
856 |
double y1 = 0; |
857 |
double y2 = 0; |
858 |
symbol2d.Range(out x1, out y1, out x2, out y2); |
859 |
|
860 |
LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol); |
861 |
if (_LMSymbol != null) |
862 |
{ |
863 |
childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
864 |
foreach (var item in childSymbol.ChildSymbols) |
865 |
CreateChildSymbol(item, _LMSymbol); |
866 |
} |
867 |
|
868 |
|
869 |
ReleaseCOMObjects(_LMSymbol); |
870 |
} |
871 |
|
872 |
/// <summary> |
873 |
/// item이 TargetItem과 같은 LineRun에 있는지 검사 |
874 |
/// </summary> |
875 |
/// <param name="item"></param> |
876 |
/// <param name="targetItem"></param> |
877 |
/// <returns></returns> |
878 |
private bool IsSameLineRun(object item, object targetItem) |
879 |
{ |
880 |
foreach (var lineNumber in document.LINENUMBERS) |
881 |
{ |
882 |
foreach (var run in lineNumber.RUNS) |
883 |
{ |
884 |
foreach (var runItem in run.RUNITEMS) |
885 |
{ |
886 |
if (runItem == item) |
887 |
{ |
888 |
foreach (var findItem in run.RUNITEMS) |
889 |
{ |
890 |
if (findItem == targetItem) |
891 |
{ |
892 |
return true; |
893 |
} |
894 |
} |
895 |
|
896 |
return false; |
897 |
|
898 |
} |
899 |
} |
900 |
} |
901 |
} |
902 |
|
903 |
return false; |
904 |
} |
905 |
|
906 |
/// <summary> |
907 |
/// Line을 실제로 모델링하는 메서드 |
908 |
/// </summary> |
909 |
/// <param name="lines"></param> |
910 |
private void LineModeling(List<Line> lines) |
911 |
{ |
912 |
_LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
913 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
914 |
LMSymbol _LMSymbol1 = null; |
915 |
LMSymbol _LMSymbol2 = null; |
916 |
Dictionary<LMConnector, List<double[]>> connectorVertices1 = new Dictionary<LMConnector, List<double[]>>(); |
917 |
LMConnector targetConnector1 = null; |
918 |
Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>(); |
919 |
LMConnector targetConnector2 = null; |
920 |
|
921 |
Line startBranchLine = null; |
922 |
Line endBranchLine = null; |
923 |
|
924 |
// Type, Line, TargetObjet, x, y |
925 |
List<Tuple<string, Line, object, double, double>> linePointInfo = new List<Tuple<string, Line, object, double, double>>(); |
926 |
// Point 정리 |
927 |
for (int i = 0; i < lines.Count; i++) |
928 |
{ |
929 |
Line line = lines[i]; |
930 |
if (i == 0 || i + 1 != lines.Count) |
931 |
{ |
932 |
// 시작점에 연결된 Symbol 찾기 |
933 |
object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM); |
934 |
if (connItem != null && connItem.GetType() == typeof(Symbol)) |
935 |
{ |
936 |
Symbol symbol1 = connItem as Symbol; |
937 |
_LMSymbol1 = GetTargetSymbol(symbol1, line); |
938 |
if (_LMSymbol1 != null) |
939 |
{ |
940 |
double x = line.SPPID.START_X; |
941 |
double y = line.SPPID.START_Y; |
942 |
Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, line.UID, symbol1); |
943 |
if (connector != null) |
944 |
{ |
945 |
GetTargetSymbolConnectorPoint(connector, symbol1, ref x, ref y); |
946 |
line.SPPID.START_X = x; |
947 |
line.SPPID.START_Y = y; |
948 |
} |
949 |
|
950 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>("SYMBOL", line, _LMSymbol1, x, y)); |
951 |
} |
952 |
else |
953 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y)); |
954 |
} |
955 |
else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem)) |
956 |
{ |
957 |
connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId); |
958 |
targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y); |
959 |
|
960 |
if (targetConnector1 != null) |
961 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>("LINE", line, targetConnector1, line.SPPID.START_X, line.SPPID.START_Y)); |
962 |
else |
963 |
{ |
964 |
startBranchLine = connItem as Line; |
965 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y)); |
966 |
} |
967 |
} |
968 |
else |
969 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y)); |
970 |
|
971 |
} |
972 |
if (i + 1 == lines.Count) |
973 |
{ |
974 |
// 끝점에 연결된 Symbol 찾기 |
975 |
object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM); |
976 |
|
977 |
if (i != 0) |
978 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.START_X, line.SPPID.START_Y)); |
979 |
|
980 |
if (connItem != null && connItem.GetType() == typeof(Symbol)) |
981 |
{ |
982 |
Symbol symbol2 = connItem as Symbol; |
983 |
_LMSymbol2 = GetTargetSymbol(connItem as Symbol, line); |
984 |
if (_LMSymbol2 != null) |
985 |
{ |
986 |
double x = line.SPPID.END_X; |
987 |
double y = line.SPPID.END_Y; |
988 |
Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, line.UID, symbol2); |
989 |
if (connector != null) |
990 |
{ |
991 |
GetTargetSymbolConnectorPoint(connector, symbol2, ref x, ref y); |
992 |
line.SPPID.END_X = x; |
993 |
line.SPPID.END_Y = y; |
994 |
} |
995 |
|
996 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>("SYMBOL", line, _LMSymbol2, x, y)); |
997 |
} |
998 |
else |
999 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.END_X, line.SPPID.END_Y)); |
1000 |
} |
1001 |
else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem)) |
1002 |
{ |
1003 |
connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId); |
1004 |
targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y); |
1005 |
|
1006 |
if (targetConnector2 != null) |
1007 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>("LINE", line, targetConnector2, line.SPPID.END_X, line.SPPID.END_Y)); |
1008 |
else |
1009 |
{ |
1010 |
endBranchLine = connItem as Line; |
1011 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.END_X, line.SPPID.END_Y)); |
1012 |
} |
1013 |
} |
1014 |
else |
1015 |
linePointInfo.Add(new Tuple<string, Line, object, double, double>(null, line, null, line.SPPID.END_X, line.SPPID.END_Y)); |
1016 |
} |
1017 |
} |
1018 |
|
1019 |
double prevX = double.NaN; |
1020 |
double prevY = double.NaN; |
1021 |
SlopeType prevSlopeType = SlopeType.None; |
1022 |
for (int i = 0; i < linePointInfo.Count; i++) |
1023 |
{ |
1024 |
Tuple<string, Line, object, double, double> item = linePointInfo[i]; |
1025 |
Line line = item.Item2; |
1026 |
double x = item.Item4; |
1027 |
double y = item.Item5; |
1028 |
SlopeType slopeType = SPPIDUtil.CalcSlope(line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y); |
1029 |
// Symbol일 경우 바로 Input Point |
1030 |
if (item.Item1 == "SYMBOL") |
1031 |
placeRunInputs.AddSymbolTarget(item.Item3 as LMSymbol, x, y); |
1032 |
else |
1033 |
{ |
1034 |
SPPIDUtil.ConvertGridPoint(ref x, ref y); |
1035 |
// i == 0은 그대로 사용 |
1036 |
if (i != 0) |
1037 |
{ |
1038 |
Tuple<string, Line, object, double, double> prevItem = linePointInfo[i - 1]; |
1039 |
// y 좌표가 같아야함 및 Symbol 좌표가 정확하지 않으므로 한번더 보정 |
1040 |
if (prevSlopeType == SlopeType.HORIZONTAL) |
1041 |
{ |
1042 |
y = prevY; |
1043 |
SPPIDUtil.ConvertGridPointOnlyOnePoint(ref y); |
1044 |
} |
1045 |
else if (prevSlopeType == SlopeType.VERTICAL) |
1046 |
{ |
1047 |
x = prevX; |
1048 |
SPPIDUtil.ConvertGridPointOnlyOnePoint(ref x); |
1049 |
} |
1050 |
|
1051 |
// 마지막이 Symbol일 경우는 Symbol의 좌표를 따라감 |
1052 |
if (i + 1 == linePointInfo.Count - 1 && linePointInfo[i + 1].Item1 == "SYMBOL") |
1053 |
{ |
1054 |
Line nextLine = linePointInfo[i + 1].Item2; |
1055 |
SlopeType nextSlopeType = SPPIDUtil.CalcSlope(nextLine.SPPID.START_X, nextLine.SPPID.START_Y, nextLine.SPPID.END_X, nextLine.SPPID.END_Y); |
1056 |
if (slopeType == SlopeType.HORIZONTAL) |
1057 |
y = linePointInfo[i + 1].Item5; |
1058 |
else if (slopeType == SlopeType.VERTICAL) |
1059 |
x = linePointInfo[i + 1].Item4; |
1060 |
} |
1061 |
} |
1062 |
|
1063 |
if (item.Item1 == "LINE") |
1064 |
placeRunInputs.AddConnectorTarget(item.Item3 as LMConnector, x, y); |
1065 |
else |
1066 |
placeRunInputs.AddPoint(x, y); |
1067 |
} |
1068 |
|
1069 |
prevX = x; |
1070 |
prevY = y; |
1071 |
prevSlopeType = slopeType; |
1072 |
} |
1073 |
|
1074 |
LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
1075 |
|
1076 |
if (_lMConnector != null) |
1077 |
{ |
1078 |
foreach (var line in lines) |
1079 |
line.SPPID.ModelItemId = _lMConnector.ModelItemID; |
1080 |
_lMConnector.Commit(); |
1081 |
if (startBranchLine != null || endBranchLine != null) |
1082 |
BranchLines.Add(new Tuple<string, Line, Line>(_lMConnector.ModelItemID, startBranchLine, endBranchLine)); |
1083 |
} |
1084 |
|
1085 |
if (_LMSymbol1 != null) |
1086 |
ReleaseCOMObjects(_LMSymbol1); |
1087 |
if (_LMSymbol2 != null) |
1088 |
ReleaseCOMObjects(_LMSymbol2); |
1089 |
if (targetConnector1 != null) |
1090 |
ReleaseCOMObjects(targetConnector1); |
1091 |
if (targetConnector2 != null) |
1092 |
ReleaseCOMObjects(targetConnector2); |
1093 |
foreach (var item in connectorVertices1) |
1094 |
ReleaseCOMObjects(item.Key); |
1095 |
foreach (var item in connectorVertices2) |
1096 |
ReleaseCOMObjects(item.Key); |
1097 |
|
1098 |
ReleaseCOMObjects(_lMConnector); |
1099 |
ReleaseCOMObjects(placeRunInputs); |
1100 |
ReleaseCOMObjects(_LMAItem); |
1101 |
} |
1102 |
|
1103 |
/// <summary> |
1104 |
/// Symbol이 모델링된 SPPPID Symbol Object를 반환 - 연결된 Symbol이 ChildSymbol일 수도 있기때문에 메서드 개발 |
1105 |
/// </summary> |
1106 |
/// <param name="symbol"></param> |
1107 |
/// <param name="line"></param> |
1108 |
/// <returns></returns> |
1109 |
private LMSymbol GetTargetSymbol(Symbol symbol, Line line) |
1110 |
{ |
1111 |
LMSymbol _LMSymbol = null; |
1112 |
foreach (var connector in symbol.CONNECTORS) |
1113 |
{ |
1114 |
if (connector.CONNECTEDITEM == line.UID) |
1115 |
{ |
1116 |
if (connector.Index == 0) |
1117 |
_LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
1118 |
else |
1119 |
{ |
1120 |
ChildSymbol child = null; |
1121 |
foreach (var childSymbol in symbol.ChildSymbols) |
1122 |
{ |
1123 |
if (childSymbol.Connectors.Contains(connector)) |
1124 |
child = childSymbol; |
1125 |
else |
1126 |
child = GetChildSymbolByConnector(childSymbol, connector); |
1127 |
|
1128 |
if (child != null) |
1129 |
break; |
1130 |
} |
1131 |
|
1132 |
if (child != null) |
1133 |
_LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId); |
1134 |
} |
1135 |
|
1136 |
break; |
1137 |
} |
1138 |
} |
1139 |
|
1140 |
return _LMSymbol; |
1141 |
} |
1142 |
|
1143 |
/// <summary> |
1144 |
/// Connector를 가지고 있는 ChildSymbol Object 반환 |
1145 |
/// </summary> |
1146 |
/// <param name="item"></param> |
1147 |
/// <param name="connector"></param> |
1148 |
/// <returns></returns> |
1149 |
private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector) |
1150 |
{ |
1151 |
foreach (var childSymbol in item.ChildSymbols) |
1152 |
{ |
1153 |
if (childSymbol.Connectors.Contains(connector)) |
1154 |
return childSymbol; |
1155 |
else |
1156 |
return GetChildSymbolByConnector(childSymbol, connector); |
1157 |
} |
1158 |
|
1159 |
return null; |
1160 |
} |
1161 |
|
1162 |
/// <summary> |
1163 |
/// Branch 라인을 다시 모델링하는 진입 메서드 |
1164 |
/// </summary> |
1165 |
/// <param name="branch"></param> |
1166 |
private void BranchLineModeling(Tuple<string, Line, Line> branch) |
1167 |
{ |
1168 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1); |
1169 |
|
1170 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1); |
1171 |
|
1172 |
LMConnector _StartConnector = null; |
1173 |
LMConnector _EndConnector = null; |
1174 |
double lengthStart = double.MaxValue; |
1175 |
double lengthEnd = double.MaxValue; |
1176 |
List<double[]> startPoints = new List<double[]>(); |
1177 |
List<double[]> endPoints = new List<double[]>(); |
1178 |
|
1179 |
foreach (var item in connectorVertices) |
1180 |
{ |
1181 |
foreach (var point in item.Value) |
1182 |
{ |
1183 |
// Start Point가 Branch |
1184 |
if (branch.Item2 != null) |
1185 |
{ |
1186 |
Line targetLine = branch.Item2; |
1187 |
double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]); |
1188 |
if (lengthStart > distance) |
1189 |
{ |
1190 |
_StartConnector = item.Key; |
1191 |
lengthStart = distance; |
1192 |
startPoints = item.Value; |
1193 |
} |
1194 |
} |
1195 |
// End Point가 Branch |
1196 |
if (branch.Item3 != null) |
1197 |
{ |
1198 |
Line targetLine = branch.Item3; |
1199 |
double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]); |
1200 |
if (lengthEnd > distance) |
1201 |
{ |
1202 |
_EndConnector = item.Key; |
1203 |
lengthEnd = distance; |
1204 |
endPoints = item.Value; |
1205 |
} |
1206 |
} |
1207 |
} |
1208 |
} |
1209 |
#region Branch가 양쪽 전부일 때 |
1210 |
if (_StartConnector != null && _StartConnector == _EndConnector) |
1211 |
{ |
1212 |
_placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation()); |
1213 |
|
1214 |
_LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
1215 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
1216 |
|
1217 |
Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId); |
1218 |
LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]); |
1219 |
Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId); |
1220 |
LMConnector _EndTargetConnector = FindTargetLMConnector(endConnectorVertices, |
1221 |
startPoints[startPoints.Count - 1][0], |
1222 |
startPoints[startPoints.Count - 1][1], |
1223 |
startPoints[startPoints.Count - 2][0], |
1224 |
startPoints[startPoints.Count - 2][1]); |
1225 |
|
1226 |
for (int i = 0; i < startPoints.Count; i++) |
1227 |
{ |
1228 |
double[] point = startPoints[i]; |
1229 |
if (i == 0) |
1230 |
placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]); |
1231 |
else if (i == startPoints.Count - 1) |
1232 |
placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]); |
1233 |
else |
1234 |
placeRunInputs.AddPoint(point[0], point[1]); |
1235 |
} |
1236 |
|
1237 |
LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
1238 |
if (_LMConnector != null) |
1239 |
{ |
1240 |
_LMConnector.Commit(); |
1241 |
foreach (var item in lines) |
1242 |
item.SPPID.ModelItemId = _LMConnector.ModelItemID; |
1243 |
} |
1244 |
|
1245 |
foreach (var item in startConnectorVertices) |
1246 |
ReleaseCOMObjects(item.Key); |
1247 |
foreach (var item in endConnectorVertices) |
1248 |
ReleaseCOMObjects(item.Key); |
1249 |
ReleaseCOMObjects(placeRunInputs); |
1250 |
ReleaseCOMObjects(_LMAItem); |
1251 |
ReleaseCOMObjects(_LMConnector); |
1252 |
} |
1253 |
#endregion |
1254 |
#region 양쪽이 다른 Branch |
1255 |
else |
1256 |
{ |
1257 |
// Branch 시작 Connector |
1258 |
if (_StartConnector != null) |
1259 |
BranchLineModelingByConnector(branch, _StartConnector, startPoints, true); |
1260 |
|
1261 |
// Branch 끝 Connector |
1262 |
if (_EndConnector != null) |
1263 |
BranchLineModelingByConnector(branch, _EndConnector, endPoints, false); |
1264 |
} |
1265 |
#endregion |
1266 |
|
1267 |
if (_StartConnector != null) |
1268 |
ReleaseCOMObjects(_StartConnector); |
1269 |
if (_EndConnector != null) |
1270 |
ReleaseCOMObjects(_EndConnector); |
1271 |
foreach (var item in connectorVertices) |
1272 |
ReleaseCOMObjects(item.Key); |
1273 |
} |
1274 |
|
1275 |
/// <summary> |
1276 |
/// Branch 라인을 다시 실제로 모델링하는 메서드 |
1277 |
/// </summary> |
1278 |
/// <param name="branch"></param> |
1279 |
/// <param name="_Connector"></param> |
1280 |
/// <param name="points"></param> |
1281 |
/// <param name="IsStart"></param> |
1282 |
private void BranchLineModelingByConnector(Tuple<string, Line, Line> branch, LMConnector _Connector, List<double[]> points, bool IsStart) |
1283 |
{ |
1284 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1); |
1285 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1); |
1286 |
LMConnector _SameRunTargetConnector = null; |
1287 |
LMSymbol _SameRunTargetSymbol = null; |
1288 |
Dictionary<LMConnector, List<double[]>> branchConnectorVertices = null; |
1289 |
LMConnector _BranchTargetConnector = null; |
1290 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
1291 |
|
1292 |
// 같은 Line Run의 Connector 찾기 |
1293 |
foreach (var item in connectorVertices) |
1294 |
{ |
1295 |
if (item.Key == _Connector) |
1296 |
continue; |
1297 |
|
1298 |
if (IsStart && |
1299 |
!DBNull.Value.Equals(item.Key.ConnectItem1SymbolID) && |
1300 |
!DBNull.Value.Equals(_Connector.ConnectItem2SymbolID)&& |
1301 |
item.Key.ConnectItem1SymbolID == _Connector.ConnectItem2SymbolID) |
1302 |
{ |
1303 |
_SameRunTargetConnector = item.Key; |
1304 |
break; |
1305 |
} |
1306 |
else if (!IsStart && |
1307 |
!DBNull.Value.Equals(item.Key.ConnectItem2SymbolID) && |
1308 |
!DBNull.Value.Equals(_Connector.ConnectItem1SymbolID) && |
1309 |
item.Key.ConnectItem2SymbolID == _Connector.ConnectItem1SymbolID) |
1310 |
{ |
1311 |
_SameRunTargetConnector = item.Key; |
1312 |
break; |
1313 |
} |
1314 |
} |
1315 |
|
1316 |
// Branch 반대편이 Symbol |
1317 |
if (_SameRunTargetConnector == null) |
1318 |
{ |
1319 |
foreach (var line in lines) |
1320 |
{ |
1321 |
foreach (var connector in line.CONNECTORS) |
1322 |
{ |
1323 |
Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol; |
1324 |
if (symbol != null) |
1325 |
{ |
1326 |
_SameRunTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
1327 |
break; |
1328 |
} |
1329 |
} |
1330 |
} |
1331 |
} |
1332 |
|
1333 |
// 기존 Connector 제거 |
1334 |
_placement.PIDRemovePlacement(_Connector.AsLMRepresentation()); |
1335 |
|
1336 |
// 시작 Connector일 경우 첫 Point가 TargetConnector를 찾아야함 |
1337 |
if (IsStart) |
1338 |
{ |
1339 |
branchConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId); |
1340 |
_BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, points[0][0], points[0][1], points[1][0], points[1][1]); |
1341 |
} |
1342 |
// 끝 Conenctor일 경우 마지막 Point가 TargetConnector를 찾아야함 |
1343 |
else |
1344 |
{ |
1345 |
branchConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId); |
1346 |
_BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, |
1347 |
points[points.Count - 1][0], |
1348 |
points[points.Count - 1][1], |
1349 |
points[points.Count - 2][0], |
1350 |
points[points.Count - 2][1]); |
1351 |
} |
1352 |
|
1353 |
for (int i = 0; i < points.Count; i++) |
1354 |
{ |
1355 |
double[] point = points[i]; |
1356 |
if (i == 0) |
1357 |
{ |
1358 |
if (IsStart) |
1359 |
{ |
1360 |
if (_BranchTargetConnector != null) |
1361 |
{ |
1362 |
placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]); |
1363 |
} |
1364 |
else |
1365 |
{ |
1366 |
placeRunInputs.AddPoint(point[0], point[1]); |
1367 |
} |
1368 |
|
1369 |
} |
1370 |
else |
1371 |
{ |
1372 |
if (_SameRunTargetConnector != null) |
1373 |
placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]); |
1374 |
else if (_SameRunTargetSymbol != null) |
1375 |
placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]); |
1376 |
else |
1377 |
placeRunInputs.AddPoint(point[0], point[1]); |
1378 |
} |
1379 |
} |
1380 |
else if (i == points.Count - 1) |
1381 |
{ |
1382 |
if (IsStart) |
1383 |
{ |
1384 |
if (_SameRunTargetConnector != null) |
1385 |
placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]); |
1386 |
else if (_SameRunTargetSymbol != null) |
1387 |
placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]); |
1388 |
else |
1389 |
placeRunInputs.AddPoint(point[0], point[1]); |
1390 |
} |
1391 |
else |
1392 |
{ |
1393 |
if (_BranchTargetConnector != null) |
1394 |
{ |
1395 |
placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]); |
1396 |
} |
1397 |
else |
1398 |
{ |
1399 |
placeRunInputs.AddPoint(point[0], point[1]); |
1400 |
} |
1401 |
} |
1402 |
} |
1403 |
else |
1404 |
placeRunInputs.AddPoint(point[0], point[1]); |
1405 |
} |
1406 |
_LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
1407 |
LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
1408 |
|
1409 |
if (_LMConnector != null) |
1410 |
{ |
1411 |
if (_SameRunTargetConnector != null) |
1412 |
{ |
1413 |
JoinPipeRun(_LMConnector.ModelItemID, _SameRunTargetConnector.ModelItemID); |
1414 |
} |
1415 |
else |
1416 |
{ |
1417 |
foreach (var item in lines) |
1418 |
item.SPPID.ModelItemId = _LMConnector.ModelItemID; |
1419 |
} |
1420 |
|
1421 |
_LMConnector.Commit(); |
1422 |
ReleaseCOMObjects(_LMConnector); |
1423 |
} |
1424 |
|
1425 |
ReleaseCOMObjects(placeRunInputs); |
1426 |
ReleaseCOMObjects(_LMAItem); |
1427 |
if (_BranchTargetConnector != null) |
1428 |
ReleaseCOMObjects(_BranchTargetConnector); |
1429 |
if (_SameRunTargetConnector != null) |
1430 |
ReleaseCOMObjects(_SameRunTargetConnector); |
1431 |
if (_SameRunTargetSymbol != null) |
1432 |
ReleaseCOMObjects(_SameRunTargetSymbol); |
1433 |
foreach (var item in connectorVertices) |
1434 |
ReleaseCOMObjects(item.Key); |
1435 |
foreach (var item in branchConnectorVertices) |
1436 |
ReleaseCOMObjects(item.Key); |
1437 |
} |
1438 |
|
1439 |
/// <summary> |
1440 |
/// EndBreak 모델링 메서드 |
1441 |
/// </summary> |
1442 |
/// <param name="endBreak"></param> |
1443 |
private void EndBreakModeling(EndBreak endBreak) |
1444 |
{ |
1445 |
object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER); |
1446 |
LMConnector targetLMConnector = null; |
1447 |
if (ownerObj !=null && ownerObj.GetType() == typeof(Line)) |
1448 |
{ |
1449 |
Line ownerLine = ownerObj as Line; |
1450 |
LMLabelPersist _LmLabelPersist = null; |
1451 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(ownerLine.SPPID.ModelItemId); |
1452 |
|
1453 |
targetLMConnector = FindTargetLMConnectorByPoint(connectorVertices, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y); |
1454 |
|
1455 |
if (targetLMConnector != null) |
1456 |
{ |
1457 |
Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y }; |
1458 |
_LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
1459 |
} |
1460 |
|
1461 |
if (_LmLabelPersist != null) |
1462 |
{ |
1463 |
_LmLabelPersist.Commit(); |
1464 |
ReleaseCOMObjects(_LmLabelPersist); |
1465 |
} |
1466 |
else |
1467 |
RetryEndBreakModeling(endBreak, targetLMConnector); |
1468 |
|
1469 |
foreach (var item in connectorVertices) |
1470 |
ReleaseCOMObjects(item.Key); |
1471 |
|
1472 |
} |
1473 |
else if (ownerObj != null && ownerObj.GetType() == typeof(Symbol)) |
1474 |
{ |
1475 |
Symbol ownerSymbol = ownerObj as Symbol; |
1476 |
LMSymbol _LMSymbol = dataSource.GetSymbol(ownerSymbol.SPPID.RepresentationId); |
1477 |
|
1478 |
targetLMConnector = null; |
1479 |
double distance = double.MaxValue; |
1480 |
|
1481 |
foreach (LMConnector connector in _LMSymbol.Avoid1Connectors) |
1482 |
{ |
1483 |
if (connector.get_ItemStatus() == "Active") |
1484 |
{ |
1485 |
dynamic OID = connector.get_GraphicOID(); |
1486 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
1487 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
1488 |
int verticesCount = lineStringGeometry.VertexCount; |
1489 |
double[] vertices = null; |
1490 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
1491 |
for (int i = 0; i < verticesCount; i++) |
1492 |
{ |
1493 |
double x = 0; |
1494 |
double y = 0; |
1495 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
1496 |
|
1497 |
double result = SPPIDUtil.CalcPointToPointdDistance(x, y, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y); |
1498 |
if (result < distance) |
1499 |
{ |
1500 |
targetLMConnector = connector; |
1501 |
distance = result; |
1502 |
} |
1503 |
} |
1504 |
} |
1505 |
} |
1506 |
|
1507 |
foreach (LMConnector connector in _LMSymbol.Avoid2Connectors) |
1508 |
{ |
1509 |
if (connector.get_ItemStatus() == "Active") |
1510 |
{ |
1511 |
dynamic OID = connector.get_GraphicOID(); |
1512 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
1513 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
1514 |
int verticesCount = lineStringGeometry.VertexCount; |
1515 |
double[] vertices = null; |
1516 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
1517 |
for (int i = 0; i < verticesCount; i++) |
1518 |
{ |
1519 |
double x = 0; |
1520 |
double y = 0; |
1521 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
1522 |
|
1523 |
double result = SPPIDUtil.CalcPointToPointdDistance(x, y, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y); |
1524 |
if (result < distance) |
1525 |
{ |
1526 |
targetLMConnector = connector; |
1527 |
distance = result; |
1528 |
} |
1529 |
} |
1530 |
} |
1531 |
} |
1532 |
|
1533 |
if (targetLMConnector != null) |
1534 |
{ |
1535 |
LMLabelPersist _LmLabelPersist = null; |
1536 |
Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y }; |
1537 |
_LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
1538 |
if (_LmLabelPersist != null) |
1539 |
{ |
1540 |
_LmLabelPersist.Commit(); |
1541 |
ReleaseCOMObjects(_LmLabelPersist); |
1542 |
} |
1543 |
else |
1544 |
RetryEndBreakModeling(endBreak, targetLMConnector); |
1545 |
} |
1546 |
|
1547 |
ReleaseCOMObjects(_LMSymbol); |
1548 |
} |
1549 |
|
1550 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
1551 |
} |
1552 |
|
1553 |
/// <summary> |
1554 |
/// EndBreak 모델링이 실패시 다시 시도하는 메서드 |
1555 |
/// </summary> |
1556 |
/// <param name="endBreak"></param> |
1557 |
/// <param name="targetLMConnector"></param> |
1558 |
private void RetryEndBreakModeling(EndBreak endBreak, LMConnector targetLMConnector) |
1559 |
{ |
1560 |
bool isZeroLength = Convert.ToBoolean(targetLMConnector.get_IsZeroLength()); |
1561 |
Array array = null; |
1562 |
LMLabelPersist _LMLabelPersist = null; |
1563 |
LMConnector _LMConnector = null; |
1564 |
dynamic OID = targetLMConnector.get_GraphicOID(); |
1565 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
1566 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
1567 |
int verticesCount = lineStringGeometry.VertexCount; |
1568 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
1569 |
_LMAItem _LMAItem = _placement.PIDCreateItem(@"\Piping\Routing\Process Lines\Primary Piping.sym"); |
1570 |
|
1571 |
if (isZeroLength) |
1572 |
{ |
1573 |
double[] vertices = null; |
1574 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
1575 |
double x = 0; |
1576 |
double y = 0; |
1577 |
lineStringGeometry.GetVertex(1, ref x, ref y); |
1578 |
|
1579 |
placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem1SymbolObject, x, y); |
1580 |
placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem2SymbolObject, x, y); |
1581 |
|
1582 |
_placement.PIDRemovePlacement(targetLMConnector.AsLMRepresentation()); |
1583 |
_LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
1584 |
|
1585 |
array = new double[] { 0, x, y }; |
1586 |
_LMLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: _LMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
1587 |
|
1588 |
AutoJoinPipeRun(_LMConnector.ModelItemID); |
1589 |
} |
1590 |
else |
1591 |
{ |
1592 |
List<double[]> vertices = new List<double[]>(); |
1593 |
for (int i = 1; i <= verticesCount; i++) |
1594 |
{ |
1595 |
double x = 0; |
1596 |
double y = 0; |
1597 |
lineStringGeometry.GetVertex(i, ref x, ref y); |
1598 |
vertices.Add(new double[] { x, y }); |
1599 |
} |
1600 |
|
1601 |
for (int i = 0; i < vertices.Count; i++) |
1602 |
{ |
1603 |
double[] points = vertices[i]; |
1604 |
if (i == 0) |
1605 |
{ |
1606 |
if (targetLMConnector.ConnectItem1SymbolObject != null) |
1607 |
placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem1SymbolObject, points[0], points[1]); |
1608 |
else |
1609 |
placeRunInputs.AddPoint(points[0], points[1]); |
1610 |
} |
1611 |
else if (i == vertices.Count - 1) |
1612 |
{ |
1613 |
if (targetLMConnector.ConnectItem2SymbolObject != null) |
1614 |
placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem2SymbolObject, points[0], points[1]); |
1615 |
else |
1616 |
placeRunInputs.AddPoint(points[0], points[1]); |
1617 |
} |
1618 |
else |
1619 |
placeRunInputs.AddPoint(points[0], points[1]); |
1620 |
} |
1621 |
|
1622 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, targetLMConnector.ModelItemID); |
1623 |
|
1624 |
_placement.PIDRemovePlacement(targetLMConnector.AsLMRepresentation()); |
1625 |
_LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
1626 |
|
1627 |
array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y }; |
1628 |
_LMLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: _LMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
1629 |
|
1630 |
AutoJoinPipeRun(_LMConnector.ModelItemID); |
1631 |
foreach (var line in lines) |
1632 |
line.SPPID.ModelItemId = _LMConnector.ModelItemID; |
1633 |
} |
1634 |
|
1635 |
|
1636 |
if (_LMLabelPersist != null) |
1637 |
{ |
1638 |
_LMLabelPersist.Commit(); |
1639 |
ReleaseCOMObjects(_LMLabelPersist); |
1640 |
} |
1641 |
else |
1642 |
{ |
1643 |
|
1644 |
} |
1645 |
|
1646 |
ReleaseCOMObjects(_LMConnector); |
1647 |
ReleaseCOMObjects(placeRunInputs); |
1648 |
ReleaseCOMObjects(_LMAItem); |
1649 |
} |
1650 |
|
1651 |
/// <summary> |
1652 |
/// SpecBreak Modeling 메서드 |
1653 |
/// </summary> |
1654 |
/// <param name="specBreak"></param> |
1655 |
private void SpecBreakModeling(SpecBreak specBreak) |
1656 |
{ |
1657 |
object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID); |
1658 |
object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID); |
1659 |
|
1660 |
if (upStreamObj != null && |
1661 |
downStreamObj != null) |
1662 |
{ |
1663 |
LMConnector targetLMConnector = null; |
1664 |
LMSymbol upStreamLMSymbol = null; |
1665 |
LMSymbol downStreamLMSymbol = null; |
1666 |
List<LMConnector> upStreamLMConnectors = null; |
1667 |
List<LMConnector> downStreamLMConnectors = null; |
1668 |
|
1669 |
// UpStream = Symbol, DownStream = Symbol 경우 |
1670 |
if (upStreamObj.GetType() == typeof(Symbol) && downStreamObj.GetType() == typeof(Symbol)) |
1671 |
{ |
1672 |
Symbol upStreamSymbol = upStreamObj as Symbol; |
1673 |
Symbol downStreamSymbol = downStreamObj as Symbol; |
1674 |
if (!string.IsNullOrEmpty(upStreamSymbol.SPPID.RepresentationId) && !string.IsNullOrEmpty(downStreamSymbol.SPPID.RepresentationId)) |
1675 |
{ |
1676 |
upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId); |
1677 |
downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId); |
1678 |
|
1679 |
foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors) |
1680 |
{ |
1681 |
if (connector.get_ItemStatus() == "Active") |
1682 |
{ |
1683 |
if (connector.AvoidItem1SymbolObject.AsLMRepresentation().Id == downStreamLMSymbol.AsLMRepresentation().Id || |
1684 |
connector.AvoidItem2SymbolObject.AsLMRepresentation().Id == downStreamLMSymbol.AsLMRepresentation().Id) |
1685 |
targetLMConnector = connector; |
1686 |
} |
1687 |
} |
1688 |
|
1689 |
foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors) |
1690 |
{ |
1691 |
if (connector.get_ItemStatus() == "Active") |
1692 |
{ |
1693 |
if (connector.AvoidItem1SymbolObject.AsLMRepresentation().Id == downStreamLMSymbol.AsLMRepresentation().Id || |
1694 |
connector.AvoidItem2SymbolObject.AsLMRepresentation().Id == downStreamLMSymbol.AsLMRepresentation().Id) |
1695 |
targetLMConnector = connector; |
1696 |
} |
1697 |
} |
1698 |
} |
1699 |
} |
1700 |
// UpStream = Symbol, DownStream = Line 경우 |
1701 |
else if (upStreamObj.GetType() == typeof(Symbol) && downStreamObj.GetType() == typeof(Line)) |
1702 |
{ |
1703 |
Symbol upStreamSymbol = upStreamObj as Symbol; |
1704 |
Line downStreamLine = downStreamObj as Line; |
1705 |
if (!string.IsNullOrEmpty(upStreamSymbol.SPPID.RepresentationId) && !string.IsNullOrEmpty(downStreamLine.SPPID.ModelItemId)) |
1706 |
{ |
1707 |
upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId); |
1708 |
downStreamLMConnectors = GetConnectors(downStreamLine.SPPID.ModelItemId); |
1709 |
|
1710 |
foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors) |
1711 |
{ |
1712 |
if (connector.get_ItemStatus() == "Active") |
1713 |
if (downStreamLMConnectors.Find(x => x.AsLMRepresentation().Id == connector.AsLMRepresentation().Id) != null) |
1714 |
targetLMConnector = connector; |
1715 |
} |
1716 |
foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors) |
1717 |
{ |
1718 |
if (connector.get_ItemStatus() == "Active") |
1719 |
if (downStreamLMConnectors.Find(x => x.AsLMRepresentation().Id == connector.AsLMRepresentation().Id) != null) |
1720 |
targetLMConnector = connector; |
1721 |
} |
1722 |
} |
1723 |
} |
1724 |
// UpStream = Line, DownStream = Symbol 경우 |
1725 |
else if (upStreamObj.GetType() == typeof(Line) && downStreamObj.GetType() == typeof(Symbol)) |
1726 |
{ |
1727 |
Line upStreamLine = upStreamObj as Line; |
1728 |
Symbol downStreamSymbol = downStreamObj as Symbol; |
1729 |
if (!string.IsNullOrEmpty(upStreamLine.SPPID.ModelItemId) && !string.IsNullOrEmpty(downStreamSymbol.SPPID.RepresentationId)) |
1730 |
{ |
1731 |
downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId); |
1732 |
upStreamLMConnectors = GetConnectors(upStreamLine.SPPID.ModelItemId); |
1733 |
|
1734 |
foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors) |
1735 |
{ |
1736 |
if (connector.get_ItemStatus() == "Active") |
1737 |
if (upStreamLMConnectors.Find(x => x.AsLMRepresentation().Id == connector.AsLMRepresentation().Id) != null) |
1738 |
targetLMConnector = connector; |
1739 |
} |
1740 |
foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors) |
1741 |
{ |
1742 |
if (connector.get_ItemStatus() == "Active") |
1743 |
if (upStreamLMConnectors.Find(x => x.AsLMRepresentation().Id == connector.AsLMRepresentation().Id) != null) |
1744 |
targetLMConnector = connector; |
1745 |
} |
1746 |
} |
1747 |
} |
1748 |
// UpStream = Line, DownStream = Line 경우 |
1749 |
else if (upStreamObj.GetType() == typeof(Line) && downStreamObj.GetType() == typeof(Line)) |
1750 |
{ |
1751 |
Line upStreamLine = upStreamObj as Line; |
1752 |
Line downStreamLine = downStreamObj as Line; |
1753 |
|
1754 |
if (!string.IsNullOrEmpty(upStreamLine.SPPID.ModelItemId) && !string.IsNullOrEmpty(downStreamLine.SPPID.ModelItemId)) |
1755 |
{ |
1756 |
upStreamLMConnectors = GetConnectors(upStreamLine.SPPID.ModelItemId); |
1757 |
downStreamLMConnectors = GetConnectors(downStreamLine.SPPID.ModelItemId); |
1758 |
List<LMConnector> findUpStreamConnector = new List<LMConnector>(); |
1759 |
List<LMConnector> findDownStreamConnector = new List<LMConnector>(); |
1760 |
foreach (LMConnector upStreamConnector in upStreamLMConnectors) |
1761 |
{ |
1762 |
foreach (LMConnector downStreamConnector in downStreamLMConnectors) |
1763 |
{ |
1764 |
if (upStreamConnector.ConnectItem1SymbolObject != null && |
1765 |
downStreamConnector.ConnectItem1SymbolObject != null && |
1766 |
upStreamConnector.ConnectItem1SymbolObject.AsLMRepresentation().Id == downStreamConnector.ConnectItem1SymbolObject.AsLMRepresentation().Id) |
1767 |
{ |
1768 |
findUpStreamConnector.Add(upStreamConnector); |
1769 |
findDownStreamConnector.Add(downStreamConnector); |
1770 |
} |
1771 |
if (upStreamConnector.ConnectItem1SymbolObject != null && |
1772 |
downStreamConnector.ConnectItem2SymbolObject != null && |
1773 |
upStreamConnector.ConnectItem1SymbolObject.AsLMRepresentation().Id == downStreamConnector.ConnectItem2SymbolObject.AsLMRepresentation().Id) |
1774 |
{ |
1775 |
findUpStreamConnector.Add(upStreamConnector); |
1776 |
findDownStreamConnector.Add(downStreamConnector); |
1777 |
} |
1778 |
if (upStreamConnector.ConnectItem2SymbolObject != null && |
1779 |
downStreamConnector.ConnectItem1SymbolObject != null && |
1780 |
upStreamConnector.ConnectItem2SymbolObject.AsLMRepresentation().Id == downStreamConnector.ConnectItem1SymbolObject.AsLMRepresentation().Id) |
1781 |
{ |
1782 |
findUpStreamConnector.Add(upStreamConnector); |
1783 |
findDownStreamConnector.Add(downStreamConnector); |
1784 |
} |
1785 |
if (upStreamConnector.ConnectItem2SymbolObject != null && |
1786 |
downStreamConnector.ConnectItem2SymbolObject != null && |
1787 |
upStreamConnector.ConnectItem2SymbolObject.AsLMRepresentation().Id == downStreamConnector.ConnectItem2SymbolObject.AsLMRepresentation().Id) |
1788 |
{ |
1789 |
findUpStreamConnector.Add(upStreamConnector); |
1790 |
findDownStreamConnector.Add(downStreamConnector); |
1791 |
} |
1792 |
} |
1793 |
} |
1794 |
|
1795 |
findUpStreamConnector = findUpStreamConnector.Distinct().ToList(); |
1796 |
findDownStreamConnector = findDownStreamConnector.Distinct().ToList(); |
1797 |
|
1798 |
if (findUpStreamConnector.Count == 1) |
1799 |
targetLMConnector = findUpStreamConnector[0]; |
1800 |
else if (findDownStreamConnector.Count == 1) |
1801 |
targetLMConnector = findDownStreamConnector[0]; |
1802 |
} |
1803 |
} |
1804 |
|
1805 |
if (targetLMConnector != null) |
1806 |
{ |
1807 |
string MappingPath = specBreak.SPPID.MAPPINGNAME; |
1808 |
Array array = new double[] { 0, specBreak.SPPID.ORIGINAL_X, specBreak.SPPID.ORIGINAL_Y }; |
1809 |
LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(MappingPath, ref array, Rotation: specBreak.ANGLE, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
1810 |
|
1811 |
if (_LmLabelPersist != null) |
1812 |
{ |
1813 |
ReleaseCOMObjects(_LmLabelPersist); |
1814 |
} |
1815 |
} |
1816 |
|
1817 |
if (upStreamLMSymbol != null) |
1818 |
ReleaseCOMObjects(upStreamLMSymbol); |
1819 |
if (downStreamLMSymbol != null) |
1820 |
ReleaseCOMObjects(downStreamLMSymbol); |
1821 |
if (upStreamLMConnectors != null) |
1822 |
foreach (var item in upStreamLMConnectors) |
1823 |
ReleaseCOMObjects(item); |
1824 |
if (downStreamLMConnectors != null) |
1825 |
foreach (var item in downStreamLMConnectors) |
1826 |
ReleaseCOMObjects(item); |
1827 |
} |
1828 |
} |
1829 |
|
1830 |
/// <summary> |
1831 |
/// FromModelItem을 ToModelItem으로 PipeRunJoin하는 메서드 |
1832 |
/// </summary> |
1833 |
/// <param name="fromModelItemId"></param> |
1834 |
/// <param name="toModelItemId"></param> |
1835 |
private void JoinPipeRun(string fromModelItemId, string toModelItemId) |
1836 |
{ |
1837 |
LMModelItem modelItem1 = dataSource.GetModelItem(toModelItemId); |
1838 |
_LMAItem item1 = modelItem1.AsLMAItem(); |
1839 |
LMModelItem modelItem2 = dataSource.GetModelItem(fromModelItemId); |
1840 |
_LMAItem item2 = modelItem2.AsLMAItem(); |
1841 |
|
1842 |
// item2가 item1으로 조인 |
1843 |
try |
1844 |
{ |
1845 |
_placement.PIDJoinRuns(ref item1, ref item2); |
1846 |
item1.Commit(); |
1847 |
item2.Commit(); |
1848 |
|
1849 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, fromModelItemId); |
1850 |
foreach (var line in lines) |
1851 |
line.SPPID.ModelItemId = toModelItemId; |
1852 |
} |
1853 |
catch (Exception ex) |
1854 |
{ |
1855 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
1856 |
} |
1857 |
finally |
1858 |
{ |
1859 |
ReleaseCOMObjects(modelItem1); |
1860 |
ReleaseCOMObjects(item1); |
1861 |
ReleaseCOMObjects(modelItem2); |
1862 |
ReleaseCOMObjects(item2); |
1863 |
} |
1864 |
} |
1865 |
|
1866 |
/// <summary> |
1867 |
/// PipeRun을 자동으로 Join하는 메서드 |
1868 |
/// </summary> |
1869 |
/// <param name="modelItemId"></param> |
1870 |
private void AutoJoinPipeRun(string modelItemId) |
1871 |
{ |
1872 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemId); |
1873 |
_LMAItem item = modelItem.AsLMAItem(); |
1874 |
try |
1875 |
{ |
1876 |
string modelitemID = item.Id; |
1877 |
_placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item); |
1878 |
string afterModelItemID = item.Id; |
1879 |
|
1880 |
if (modelitemID != afterModelItemID) |
1881 |
{ |
1882 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID); |
1883 |
foreach (var line in lines) |
1884 |
line.SPPID.ModelItemId = afterModelItemID; |
1885 |
} |
1886 |
item.Commit(); |
1887 |
} |
1888 |
catch (Exception ex) |
1889 |
{ |
1890 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
1891 |
} |
1892 |
finally |
1893 |
{ |
1894 |
ReleaseCOMObjects(modelItem); |
1895 |
ReleaseCOMObjects(item); |
1896 |
} |
1897 |
} |
1898 |
|
1899 |
/// <summary> |
1900 |
/// LineRun에 있는 Line들을 Join하는 진입 메서드 |
1901 |
/// </summary> |
1902 |
/// <param name="run"></param> |
1903 |
private void JoinRunLine(LineRun run) |
1904 |
{ |
1905 |
string modelItemId = string.Empty; |
1906 |
foreach (var item in run.RUNITEMS) |
1907 |
{ |
1908 |
if (item.GetType() == typeof(Line)) |
1909 |
{ |
1910 |
Line line = item as Line; |
1911 |
AutoJoinPipeRun(line.SPPID.ModelItemId); |
1912 |
modelItemId = line.SPPID.ModelItemId; |
1913 |
|
1914 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
1915 |
} |
1916 |
} |
1917 |
} |
1918 |
|
1919 |
/// <summary> |
1920 |
/// PipeRun의 좌표를 가져오는 메서드 |
1921 |
/// </summary> |
1922 |
/// <param name="modelId"></param> |
1923 |
/// <returns></returns> |
1924 |
private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId) |
1925 |
{ |
1926 |
Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>(); |
1927 |
LMModelItem modelItem = dataSource.GetModelItem(modelId); |
1928 |
|
1929 |
if (modelItem != null) |
1930 |
{ |
1931 |
foreach (LMRepresentation rep in modelItem.Representations) |
1932 |
{ |
1933 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
1934 |
{ |
1935 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
1936 |
connectorVertices.Add(_LMConnector, new List<double[]>()); |
1937 |
dynamic OID = rep.get_GraphicOID(); |
1938 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
1939 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
1940 |
int verticesCount = lineStringGeometry.VertexCount; |
1941 |
double[] vertices = null; |
1942 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
1943 |
for (int i = 0; i < verticesCount; i++) |
1944 |
{ |
1945 |
double x = 0; |
1946 |
double y = 0; |
1947 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
1948 |
connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) }); |
1949 |
} |
1950 |
} |
1951 |
} |
1952 |
|
1953 |
ReleaseCOMObjects(modelItem); |
1954 |
} |
1955 |
|
1956 |
return connectorVertices; |
1957 |
} |
1958 |
|
1959 |
private List<LMConnector> GetConnectors(string modelId) |
1960 |
{ |
1961 |
List<LMConnector> connectors = new List<LMConnector>(); |
1962 |
LMModelItem modelItem = dataSource.GetModelItem(modelId); |
1963 |
|
1964 |
if (modelItem != null) |
1965 |
{ |
1966 |
foreach (LMRepresentation rep in modelItem.Representations) |
1967 |
{ |
1968 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
1969 |
{ |
1970 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
1971 |
connectors.Add(_LMConnector); |
1972 |
} |
1973 |
} |
1974 |
|
1975 |
ReleaseCOMObjects(modelItem); |
1976 |
} |
1977 |
|
1978 |
return connectors; |
1979 |
} |
1980 |
|
1981 |
/// <summary> |
1982 |
/// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 두점으로 라인의 교차점을 기준으로 구함 |
1983 |
/// </summary> |
1984 |
/// <param name="connectorVertices"></param> |
1985 |
/// <param name="connX"></param> |
1986 |
/// <param name="connY"></param> |
1987 |
/// <param name="x2"></param> |
1988 |
/// <param name="y2"></param> |
1989 |
/// <returns></returns> |
1990 |
private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2) |
1991 |
{ |
1992 |
double length = double.MaxValue; |
1993 |
LMConnector targetConnector = null; |
1994 |
foreach (var item in connectorVertices) |
1995 |
{ |
1996 |
List<double[]> points = item.Value; |
1997 |
for (int i = 0; i < points.Count - 1; i++) |
1998 |
{ |
1999 |
double[] point1 = points[i]; |
2000 |
double[] point2 = points[i + 1]; |
2001 |
|
2002 |
double maxLineX = Math.Max(point1[0], point2[0]); |
2003 |
double minLineX = Math.Min(point1[0], point2[0]); |
2004 |
double maxLineY = Math.Max(point1[1], point2[1]); |
2005 |
double minLineY = Math.Min(point1[1], point2[1]); |
2006 |
|
2007 |
SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY); |
2008 |
|
2009 |
// 두직선의 교차점 |
2010 |
double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]); |
2011 |
if (crossingPoint != null) |
2012 |
{ |
2013 |
double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]); |
2014 |
if (length >= distance) |
2015 |
{ |
2016 |
if (slope == SlopeType.Slope && |
2017 |
minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] && |
2018 |
minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
2019 |
{ |
2020 |
targetConnector = item.Key; |
2021 |
length = distance; |
2022 |
} |
2023 |
else if (slope == SlopeType.HORIZONTAL && |
2024 |
minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0]) |
2025 |
{ |
2026 |
targetConnector = item.Key; |
2027 |
length = distance; |
2028 |
} |
2029 |
else if (slope == SlopeType.VERTICAL && |
2030 |
minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
2031 |
{ |
2032 |
targetConnector = item.Key; |
2033 |
length = distance; |
2034 |
} |
2035 |
} |
2036 |
} |
2037 |
} |
2038 |
|
2039 |
|
2040 |
} |
2041 |
|
2042 |
if (targetConnector == null) |
2043 |
{ |
2044 |
foreach (var item in connectorVertices) |
2045 |
{ |
2046 |
List<double[]> points = item.Value; |
2047 |
foreach (var point in points) |
2048 |
{ |
2049 |
double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, point[0], point[1]); |
2050 |
if (length >= distance) |
2051 |
{ |
2052 |
targetConnector = item.Key; |
2053 |
length = distance; |
2054 |
} |
2055 |
} |
2056 |
} |
2057 |
|
2058 |
} |
2059 |
|
2060 |
return targetConnector; |
2061 |
} |
2062 |
|
2063 |
/// <summary> |
2064 |
/// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 한점으로 제일 가까운 기준으로 구함(단순) |
2065 |
/// </summary> |
2066 |
/// <param name="connectorVertices"></param> |
2067 |
/// <param name="connX"></param> |
2068 |
/// <param name="connY"></param> |
2069 |
/// <returns></returns> |
2070 |
private LMConnector FindTargetLMConnectorByPoint(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY) |
2071 |
{ |
2072 |
double length = double.MaxValue; |
2073 |
LMConnector targetConnector = null; |
2074 |
foreach (var item in connectorVertices) |
2075 |
{ |
2076 |
List<double[]> points = item.Value; |
2077 |
|
2078 |
foreach (double[] point in points) |
2079 |
{ |
2080 |
double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY); |
2081 |
if (length >= distance) |
2082 |
{ |
2083 |
targetConnector = item.Key; |
2084 |
length = distance; |
2085 |
} |
2086 |
} |
2087 |
} |
2088 |
|
2089 |
return targetConnector; |
2090 |
} |
2091 |
|
2092 |
/// <summary> |
2093 |
/// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식 |
2094 |
/// </summary> |
2095 |
/// <param name="connectorVertices"></param> |
2096 |
/// <param name="connX"></param> |
2097 |
/// <param name="connY"></param> |
2098 |
/// <returns></returns> |
2099 |
private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY) |
2100 |
{ |
2101 |
double length = double.MaxValue; |
2102 |
LMConnector targetConnector = null; |
2103 |
foreach (var item in connectorVertices) |
2104 |
{ |
2105 |
List<double[]> points = item.Value; |
2106 |
for (int i = 0; i < points.Count - 1; i++) |
2107 |
{ |
2108 |
double[] point1 = points[i]; |
2109 |
double[] point2 = points[i + 1]; |
2110 |
double x1 = Math.Min(point1[0], point2[0]); |
2111 |
double y1 = Math.Min(point1[1], point2[1]); |
2112 |
double x2 = Math.Max(point1[0], point2[0]); |
2113 |
double y2 = Math.Max(point1[1], point2[1]); |
2114 |
|
2115 |
if ((x1 <= connX && x2 >= connX) || |
2116 |
(y1 <= connY && y2 >= connY)) |
2117 |
{ |
2118 |
double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY); |
2119 |
if (length >= distance) |
2120 |
{ |
2121 |
targetConnector = item.Key; |
2122 |
length = distance; |
2123 |
} |
2124 |
|
2125 |
distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY); |
2126 |
if (length >= distance) |
2127 |
{ |
2128 |
targetConnector = item.Key; |
2129 |
length = distance; |
2130 |
} |
2131 |
} |
2132 |
} |
2133 |
} |
2134 |
|
2135 |
// 못찾았을때. |
2136 |
length = double.MaxValue; |
2137 |
if (targetConnector == null) |
2138 |
{ |
2139 |
foreach (var item in connectorVertices) |
2140 |
{ |
2141 |
List<double[]> points = item.Value; |
2142 |
|
2143 |
foreach (double[] point in points) |
2144 |
{ |
2145 |
double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY); |
2146 |
if (length >= distance) |
2147 |
{ |
2148 |
targetConnector = item.Key; |
2149 |
length = distance; |
2150 |
} |
2151 |
} |
2152 |
} |
2153 |
} |
2154 |
|
2155 |
return targetConnector; |
2156 |
} |
2157 |
|
2158 |
/// <summary> |
2159 |
/// Line Number Symbol을 실제로 Modeling하는 메서드 |
2160 |
/// </summary> |
2161 |
/// <param name="lineNumber"></param> |
2162 |
private void LineNumberModeling(LineNumber lineNumber) |
2163 |
{ |
2164 |
Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line; |
2165 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId); |
2166 |
LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y); |
2167 |
if (connectedLMConnector != null) |
2168 |
{ |
2169 |
double x = 0; |
2170 |
double y = 0; |
2171 |
CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation); |
2172 |
|
2173 |
Array points = new double[] { 0, x, y }; |
2174 |
LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false); |
2175 |
|
2176 |
foreach (var item in connectorVertices) |
2177 |
ReleaseCOMObjects(item.Key); |
2178 |
if (_LmLabelPresist != null) |
2179 |
{ |
2180 |
_LmLabelPresist.Commit(); |
2181 |
lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id; |
2182 |
ReleaseCOMObjects(_LmLabelPresist); |
2183 |
} |
2184 |
else |
2185 |
{ |
2186 |
|
2187 |
} |
2188 |
} |
2189 |
|
2190 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
2191 |
} |
2192 |
|
2193 |
/// <summary> |
2194 |
/// Flow Mark Modeling |
2195 |
/// </summary> |
2196 |
/// <param name="line"></param> |
2197 |
private void FlowMarkModeling(Line line) |
2198 |
{ |
2199 |
if (line.FLOWMARK && !string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(_ETCSetting.FlowMarkSymbolPath)) |
2200 |
{ |
2201 |
SlopeType targetSlopeType = SPPIDUtil.CalcSlope(line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y); |
2202 |
string mappingPath = _ETCSetting.FlowMarkSymbolPath; |
2203 |
double percent = line.FLOWMARK_PERCENT; |
2204 |
double tempX = 0; |
2205 |
double tempY = 0; |
2206 |
|
2207 |
double gapX; |
2208 |
double gapY; |
2209 |
// ID2 기준의 Gap을 구함 |
2210 |
if (percent == 0) |
2211 |
{ |
2212 |
gapX = 0; |
2213 |
gapY = 0; |
2214 |
} |
2215 |
else |
2216 |
{ |
2217 |
gapX = Math.Abs(line.SPPID.START_X - line.SPPID.END_X) / 100 * percent; |
2218 |
gapY = Math.Abs(line.SPPID.START_Y - line.SPPID.END_Y) / 100 * percent; |
2219 |
} |
2220 |
|
2221 |
if (line.SPPID.START_X < line.SPPID.END_X) |
2222 |
tempX = line.SPPID.START_X + gapX; |
2223 |
else |
2224 |
tempX = line.SPPID.START_X - gapX; |
2225 |
|
2226 |
if (line.SPPID.START_Y < line.SPPID.END_Y) |
2227 |
tempY = line.SPPID.START_Y + gapY; |
2228 |
else |
2229 |
tempY = line.SPPID.START_Y - gapY; |
2230 |
|
2231 |
|
2232 |
|
2233 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId); |
2234 |
LMConnector _TargetItem = null; |
2235 |
double distance = double.MaxValue; |
2236 |
double[] startPoint = null; |
2237 |
double[] endPoint = null; |
2238 |
// ID2의 기준 Gap으로 제일 가까운 Line 찾음(Slope도 같은조건) |
2239 |
foreach (var item in connectorVertices) |
2240 |
{ |
2241 |
for (int i = 0; i < item.Value.Count - 1; i++) |
2242 |
{ |
2243 |
List<double[]> points = item.Value; |
2244 |
double[] point1 = points[i]; |
2245 |
double[] point2 = points[i + 1]; |
2246 |
|
2247 |
SlopeType slopeType = SPPIDUtil.CalcSlope(point1[0], point1[1], point2[0], point2[1]); |
2248 |
if (slopeType == targetSlopeType) |
2249 |
{ |
2250 |
double result = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], tempX, tempY); |
2251 |
if (result < distance) |
2252 |
{ |
2253 |
distance = result; |
2254 |
_TargetItem = item.Key; |
2255 |
|
2256 |
startPoint = point1; |
2257 |
endPoint = point2; |
2258 |
} |
2259 |
|
2260 |
result = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], tempX, tempY); |
2261 |
if (result < distance) |
2262 |
{ |
2263 |
distance = result; |
2264 |
_TargetItem = item.Key; |
2265 |
|
2266 |
startPoint = point1; |
2267 |
endPoint = point2; |
2268 |
} |
2269 |
} |
2270 |
} |
2271 |
} |
2272 |
|
2273 |
if (_TargetItem != null) |
2274 |
{ |
2275 |
double x = 0; |
2276 |
double y = 0; |
2277 |
double angle = 0; |
2278 |
// SPPID 기준의 Gap으로 실 좌표를 구함 |
2279 |
if (percent == 0) |
2280 |
{ |
2281 |
gapX = 0; |
2282 |
gapY = 0; |
2283 |
} |
2284 |
else |
2285 |
{ |
2286 |
gapX = Math.Abs(startPoint[0] - endPoint[0]) / 100 * percent; |
2287 |
gapY = Math.Abs(startPoint[1] - endPoint[1]) / 100 * percent; |
2288 |
} |
2289 |
|
2290 |
if (startPoint[0] < endPoint[0]) |
2291 |
x = startPoint[0] + gapX; |
2292 |
else |
2293 |
x = startPoint[0] - gapX; |
2294 |
|
2295 |
if (startPoint[1] < endPoint[1]) |
2296 |
y = startPoint[1] + gapY; |
2297 |
else |
2298 |
y = startPoint[1] - gapY; |
2299 |
|
2300 |
if (targetSlopeType == SlopeType.HORIZONTAL) |
2301 |
{ |
2302 |
if (startPoint[0] < endPoint[0]) |
2303 |
angle = 0; |
2304 |
else |
2305 |
angle = Math.PI; |
2306 |
} |
2307 |
// 90 270 |
2308 |
else if (targetSlopeType == SlopeType.VERTICAL) |
2309 |
{ |
2310 |
if (startPoint[1] < endPoint[1]) |
2311 |
angle = 90 * Math.PI / 180; |
2312 |
else |
2313 |
angle = 270 * Math.PI / 180; |
2314 |
} |
2315 |
|
2316 |
LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: 0, Rotation: angle, TargetItem: _TargetItem); |
2317 |
|
2318 |
if (_LMSymbol != null) |
2319 |
{ |
2320 |
ReleaseCOMObjects(_LMSymbol); |
2321 |
} |
2322 |
|
2323 |
} |
2324 |
|
2325 |
foreach (var item in connectorVertices) |
2326 |
ReleaseCOMObjects(item.Key); |
2327 |
} |
2328 |
} |
2329 |
|
2330 |
/// <summary> |
2331 |
/// Line Number 기준으로 모든 Item에 Line Number의 Attribute Input |
2332 |
/// </summary> |
2333 |
/// <param name="lineNumber"></param> |
2334 |
private void InputLineNumberAttribute(LineNumber lineNumber) |
2335 |
{ |
2336 |
foreach (LineRun run in lineNumber.RUNS) |
2337 |
{ |
2338 |
foreach (var item in run.RUNITEMS) |
2339 |
{ |
2340 |
if (item.GetType() == typeof(Symbol)) |
2341 |
{ |
2342 |
Symbol symbol = item as Symbol; |
2343 |
LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
2344 |
LMModelItem _LMModelItem = _LMSymbol.ModelItemObject; |
2345 |
|
2346 |
if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
2347 |
{ |
2348 |
foreach (var attribute in lineNumber.ATTRIBUTES) |
2349 |
{ |
2350 |
LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID); |
2351 |
if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
2352 |
{ |
2353 |
LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME]; |
2354 |
if (_LMAAttribute != null) |
2355 |
{ |
2356 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
2357 |
_LMAAttribute.set_Value(attribute.VALUE); |
2358 |
else if (_LMAAttribute.get_Value() != attribute.VALUE) |
2359 |
_LMAAttribute.set_Value(attribute.VALUE); |
2360 |
} |
2361 |
} |
2362 |
} |
2363 |
_LMModelItem.Commit(); |
2364 |
} |
2365 |
if (_LMModelItem != null) |
2366 |
ReleaseCOMObjects(_LMModelItem); |
2367 |
if (_LMSymbol != null) |
2368 |
ReleaseCOMObjects(_LMSymbol); |
2369 |
} |
2370 |
else if (item.GetType() == typeof(Line)) |
2371 |
{ |
2372 |
Line line = item as Line; |
2373 |
if (line != null) |
2374 |
{ |
2375 |
LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
2376 |
if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
2377 |
{ |
2378 |
foreach (var attribute in lineNumber.ATTRIBUTES) |
2379 |
{ |
2380 |
LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID); |
2381 |
if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
2382 |
{ |
2383 |
LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME]; |
2384 |
if (_LMAAttribute != null) |
2385 |
{ |
2386 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
2387 |
_LMAAttribute.set_Value(attribute.VALUE); |
2388 |
else if (_LMAAttribute.get_Value() != attribute.VALUE) |
2389 |
_LMAAttribute.set_Value(attribute.VALUE); |
2390 |
|
2391 |
} |
2392 |
} |
2393 |
} |
2394 |
_LMModelItem.Commit(); |
2395 |
} |
2396 |
if (_LMModelItem != null) |
2397 |
ReleaseCOMObjects(_LMModelItem); |
2398 |
} |
2399 |
} |
2400 |
} |
2401 |
} |
2402 |
|
2403 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
2404 |
} |
2405 |
|
2406 |
/// <summary> |
2407 |
/// Symbol Attribute 입력 메서드 |
2408 |
/// </summary> |
2409 |
/// <param name="item"></param> |
2410 |
private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes) |
2411 |
{ |
2412 |
try |
2413 |
{ |
2414 |
// Object 아이템이 Symbol일 경우 Equipment일 경우 |
2415 |
string sRep = null; |
2416 |
if (targetItem.GetType() == typeof(Symbol)) |
2417 |
sRep = ((Symbol)targetItem).SPPID.RepresentationId; |
2418 |
else if (targetItem.GetType() == typeof(Equipment)) |
2419 |
sRep = ((Equipment)targetItem).SPPID.RepresentationId; |
2420 |
|
2421 |
if (!string.IsNullOrEmpty(sRep)) |
2422 |
{ |
2423 |
LMSymbol _LMSymbol = dataSource.GetSymbol(sRep); |
2424 |
LMModelItem _LMModelItem = _LMSymbol.ModelItemObject; |
2425 |
LMAAttributes _Attributes = _LMModelItem.Attributes; |
2426 |
|
2427 |
foreach (var item in targetAttributes) |
2428 |
{ |
2429 |
AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID); |
2430 |
if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None") |
2431 |
{ |
2432 |
LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME]; |
2433 |
if (_Attribute != null) |
2434 |
_Attribute.set_Value(item.VALUE); |
2435 |
} |
2436 |
} |
2437 |
_LMModelItem.Commit(); |
2438 |
|
2439 |
ReleaseCOMObjects(_Attributes); |
2440 |
ReleaseCOMObjects(_LMModelItem); |
2441 |
ReleaseCOMObjects(_LMSymbol); |
2442 |
} |
2443 |
} |
2444 |
catch (Exception ex) |
2445 |
{ |
2446 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
2447 |
} |
2448 |
|
2449 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
2450 |
} |
2451 |
|
2452 |
/// <summary> |
2453 |
/// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링 |
2454 |
/// </summary> |
2455 |
/// <param name="text"></param> |
2456 |
private void TextModeling(Text text) |
2457 |
{ |
2458 |
LMSymbol _LMSymbol = null; |
2459 |
try |
2460 |
{ |
2461 |
//if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None") |
2462 |
if (text.ASSOCIATION) |
2463 |
{ |
2464 |
object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER); |
2465 |
if (owner.GetType() == typeof(Symbol)) |
2466 |
{ |
2467 |
Symbol symbol = owner as Symbol; |
2468 |
_LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
2469 |
if (_LMSymbol != null) |
2470 |
{ |
2471 |
Association association = symbol.ASSOCIATIONS.Find(x => x.VALUE == text.UID); |
2472 |
List<BaseModel.Attribute> attributes = symbol.ATTRIBUTES.FindAll(x => x.ATTRIBUTETYPE == association.TYPE); |
2473 |
AttributeMapping mapping = null; |
2474 |
foreach (var attribute in attributes) |
2475 |
{ |
2476 |
if (string.IsNullOrEmpty(attribute.VALUE) || attribute.VALUE == "None") |
2477 |
continue; |
2478 |
|
2479 |
mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME)); |
2480 |
if (mapping != null) |
2481 |
break; |
2482 |
} |
2483 |
|
2484 |
if (mapping != null) |
2485 |
{ |
2486 |
double x = 0; |
2487 |
double y = 0; |
2488 |
|
2489 |
CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location); |
2490 |
Array array = new double[] { 0, x, y }; |
2491 |
|
2492 |
LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine); |
2493 |
if (_LMLabelPersist!=null) |
2494 |
{ |
2495 |
_LMLabelPersist.Commit(); |
2496 |
ReleaseCOMObjects(_LMLabelPersist); |
2497 |
} |
2498 |
} |
2499 |
} |
2500 |
} |
2501 |
else if (owner.GetType() == typeof(Line)) |
2502 |
{ |
2503 |
|
2504 |
} |
2505 |
} |
2506 |
else |
2507 |
{ |
2508 |
LMItemNote _LMItemNote = null; |
2509 |
LMAAttribute _LMAAttribute = null; |
2510 |
|
2511 |
double x = 0; |
2512 |
double y = 0; |
2513 |
|
2514 |
CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation); |
2515 |
|
2516 |
_LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y); |
2517 |
_LMSymbol.Commit(); |
2518 |
_LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
2519 |
_LMItemNote.Commit(); |
2520 |
_LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
2521 |
_LMAAttribute.set_Value(text.VALUE); |
2522 |
_LMItemNote.Commit(); |
2523 |
|
2524 |
if (_LMAAttribute != null) |
2525 |
ReleaseCOMObjects(_LMAAttribute); |
2526 |
if (_LMItemNote != null) |
2527 |
ReleaseCOMObjects(_LMItemNote); |
2528 |
} |
2529 |
} |
2530 |
catch (Exception ex) |
2531 |
{ |
2532 |
|
2533 |
} |
2534 |
finally |
2535 |
{ |
2536 |
if (_LMSymbol != null) |
2537 |
ReleaseCOMObjects(_LMSymbol); |
2538 |
} |
2539 |
|
2540 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
2541 |
} |
2542 |
|
2543 |
/// <summary> |
2544 |
/// Note Modeling |
2545 |
/// </summary> |
2546 |
/// <param name="note"></param> |
2547 |
private void NoteModeling(Note note) |
2548 |
{ |
2549 |
LMSymbol _LMSymbol = null; |
2550 |
LMItemNote _LMItemNote = null; |
2551 |
LMAAttribute _LMAAttribute = null; |
2552 |
|
2553 |
try |
2554 |
{ |
2555 |
double x = 0; |
2556 |
double y = 0; |
2557 |
|
2558 |
CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation); |
2559 |
|
2560 |
_LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y); |
2561 |
_LMSymbol.Commit(); |
2562 |
_LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
2563 |
_LMItemNote.Commit(); |
2564 |
_LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
2565 |
_LMAAttribute.set_Value(note.VALUE); |
2566 |
_LMItemNote.Commit(); |
2567 |
} |
2568 |
catch (Exception ex) |
2569 |
{ |
2570 |
|
2571 |
} |
2572 |
finally |
2573 |
{ |
2574 |
if (_LMAAttribute != null) |
2575 |
ReleaseCOMObjects(_LMAAttribute); |
2576 |
if (_LMItemNote != null) |
2577 |
ReleaseCOMObjects(_LMItemNote); |
2578 |
if (_LMSymbol != null) |
2579 |
ReleaseCOMObjects(_LMSymbol); |
2580 |
} |
2581 |
|
2582 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
2583 |
} |
2584 |
|
2585 |
/// <summary> |
2586 |
/// Label의 좌표를 구하는 메서드(ID2 기준의 좌표 -> SPPID 좌표) |
2587 |
/// </summary> |
2588 |
/// <param name="x"></param> |
2589 |
/// <param name="y"></param> |
2590 |
/// <param name="originX"></param> |
2591 |
/// <param name="originY"></param> |
2592 |
/// <param name="SPPIDLabelLocation"></param> |
2593 |
/// <param name="location"></param> |
2594 |
private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location) |
2595 |
{ |
2596 |
if (location == Location.None) |
2597 |
{ |
2598 |
x = originX; |
2599 |
y = originY; |
2600 |
} |
2601 |
else |
2602 |
{ |
2603 |
if (location.HasFlag(Location.Center)) |
2604 |
{ |
2605 |
x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2; |
2606 |
y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2; |
2607 |
} |
2608 |
|
2609 |
if (location.HasFlag(Location.Left)) |
2610 |
x = SPPIDLabelLocation.X1; |
2611 |
else if (location.HasFlag(Location.Right)) |
2612 |
x = SPPIDLabelLocation.X2; |
2613 |
|
2614 |
if (location.HasFlag(Location.Down)) |
2615 |
y = SPPIDLabelLocation.Y1; |
2616 |
else if (location.HasFlag(Location.Up)) |
2617 |
y = SPPIDLabelLocation.Y2; |
2618 |
} |
2619 |
} |
2620 |
|
2621 |
/// <summary> |
2622 |
/// Symbol의 우선순위 Modeling 목록을 가져온다. |
2623 |
/// 1. Angle Valve |
2624 |
/// 2. 3개로 이루어진 Symbol Group |
2625 |
/// </summary> |
2626 |
/// <returns></returns> |
2627 |
private List<Symbol> GetPrioritySymbol() |
2628 |
{ |
2629 |
DataTable symbolTable = document.SymbolTable; |
2630 |
|
2631 |
// List에 순서대로 쌓는다. |
2632 |
List<Symbol> symbols = new List<Symbol>(); |
2633 |
// Angle Valve 부터 |
2634 |
foreach (var symbol in document.SYMBOLS.FindAll(x => x.CONNECTORS.Count == 2)) |
2635 |
{ |
2636 |
if (!symbols.Contains(symbol)) |
2637 |
{ |
2638 |
double originX = 0; |
2639 |
double originY = 0; |
2640 |
|
2641 |
// ID2 Table에서 Original Point 가져옴. |
2642 |
string OriginalPoint = symbolTable.Select(string.Format("UID = {0}",symbol.DBUID))[0]["OriginalPoint"].ToString(); |
2643 |
SPPIDUtil.ConvertPointBystring(OriginalPoint, ref originX, ref originY); |
2644 |
|
2645 |
SlopeType slopeType1 = SlopeType.None; |
2646 |
SlopeType slopeType2 = SlopeType.None; |
2647 |
foreach (Connector connector in symbol.CONNECTORS) |
2648 |
{ |
2649 |
double connectorX = 0; |
2650 |
double connectorY = 0; |
2651 |
SPPIDUtil.ConvertPointBystring(connector.CONNECTPOINT, ref connectorX, ref connectorY); |
2652 |
if (slopeType1 == SlopeType.None) |
2653 |
slopeType1 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY); |
2654 |
else |
2655 |
slopeType2 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY); |
2656 |
} |
2657 |
|
2658 |
if ((slopeType1 == SlopeType.VERTICAL && slopeType2 == SlopeType.HORIZONTAL) || |
2659 |
(slopeType2 == SlopeType.VERTICAL && slopeType1 == SlopeType.HORIZONTAL)) |
2660 |
symbols.Add(symbol); |
2661 |
} |
2662 |
} |
2663 |
|
2664 |
// 3개의 Symbol이 뭉쳐 있을 때 |
2665 |
foreach (var item in document.SYMBOLS) |
2666 |
{ |
2667 |
List<Symbol> group = new List<Symbol>(); |
2668 |
SPPIDUtil.FindConnectedSymbolGroup(document, item, group); |
2669 |
if (group.Count == 3) |
2670 |
{ |
2671 |
Symbol symbol = SPPIDUtil.FindCenterAtThreeSymbols(document, group); |
2672 |
if (!symbols.Contains(symbol)) |
2673 |
symbols.Add(symbol); |
2674 |
} |
2675 |
} |
2676 |
|
2677 |
// Connection Point가 3개 이상 |
2678 |
foreach (var symbol in document.SYMBOLS) |
2679 |
if (symbol.CONNECTORS.Count > 2 && !symbols.Contains(symbol)) |
2680 |
symbols.Add(symbol); |
2681 |
|
2682 |
return symbols; |
2683 |
} |
2684 |
|
2685 |
/// <summary> |
2686 |
/// Graphic OID로 해당 Symbol의 크기를 구하여 Zoom |
2687 |
/// </summary> |
2688 |
/// <param name="graphicOID"></param> |
2689 |
/// <param name="milliseconds"></param> |
2690 |
private void ZoomObjectByGraphicOID(string graphicOID, int milliseconds = 150) |
2691 |
{ |
2692 |
if (radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] != null) |
2693 |
{ |
2694 |
double minX = 0; |
2695 |
double minY = 0; |
2696 |
double maxX = 0; |
2697 |
double maxY = 0; |
2698 |
radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID].Range(out minX, out minY, out maxX, out maxY); |
2699 |
radApp.ActiveWindow.ZoomArea2(minX - 0.007, minY - 0.007, maxX + 0.007, maxY + 0.007, null); |
2700 |
|
2701 |
Thread.Sleep(milliseconds); |
2702 |
} |
2703 |
} |
2704 |
|
2705 |
/// <summary> |
2706 |
/// ComObject를 Release |
2707 |
/// </summary> |
2708 |
/// <param name="objVars"></param> |
2709 |
public void ReleaseCOMObjects(params object[] objVars) |
2710 |
{ |
2711 |
int intNewRefCount = 0; |
2712 |
foreach (object obj in objVars) |
2713 |
{ |
2714 |
if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
2715 |
intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
2716 |
} |
2717 |
} |
2718 |
} |
2719 |
} |