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