hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ e8536f2b
이력 | 보기 | 이력해설 | 다운로드 (133 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 LineNumbers 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 |
Project_DB.InsertDrawingInfo(document.PATH, drawingNumber, drawingName); |
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 |
private LMConnector ReModelingLMConnector(LMConnector connector) |
1657 |
{ |
1658 |
string symbolPath = string.Empty; |
1659 |
#region get symbol path |
1660 |
LMModelItem modelItem = dataSource.GetModelItem(connector.ModelItemID); |
1661 |
foreach (LMRepresentation rep in modelItem.Representations) |
1662 |
{ |
1663 |
if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName())) |
1664 |
{ |
1665 |
symbolPath = rep.get_FileName(); |
1666 |
break; |
1667 |
} |
1668 |
} |
1669 |
#endregion |
1670 |
|
1671 |
LMConnector newConnector = null; |
1672 |
dynamic OID = connector.get_GraphicOID(); |
1673 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
1674 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
1675 |
int verticesCount = lineStringGeometry.VertexCount; |
1676 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
1677 |
_LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath); |
1678 |
|
1679 |
if (Convert.ToBoolean(connector.get_IsZeroLength())) |
1680 |
{ |
1681 |
double[] vertices = null; |
1682 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
1683 |
double x = 0; |
1684 |
double y = 0; |
1685 |
lineStringGeometry.GetVertex(1, ref x, ref y); |
1686 |
|
1687 |
placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y); |
1688 |
placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y); |
1689 |
|
1690 |
_placement.PIDRemovePlacement(connector.AsLMRepresentation()); |
1691 |
newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
1692 |
} |
1693 |
else |
1694 |
{ |
1695 |
List<double[]> vertices = new List<double[]>(); |
1696 |
for (int i = 1; i <= verticesCount; i++) |
1697 |
{ |
1698 |
double x = 0; |
1699 |
double y = 0; |
1700 |
lineStringGeometry.GetVertex(i, ref x, ref y); |
1701 |
vertices.Add(new double[] { x, y }); |
1702 |
} |
1703 |
|
1704 |
for (int i = 0; i < vertices.Count; i++) |
1705 |
{ |
1706 |
double[] points = vertices[i]; |
1707 |
if (i == 0) |
1708 |
{ |
1709 |
if (connector.ConnectItem1SymbolObject != null) |
1710 |
placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, points[0], points[1]); |
1711 |
else |
1712 |
placeRunInputs.AddPoint(points[0], points[1]); |
1713 |
} |
1714 |
else if (i == vertices.Count - 1) |
1715 |
{ |
1716 |
if (connector.ConnectItem2SymbolObject != null) |
1717 |
placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, points[0], points[1]); |
1718 |
else |
1719 |
placeRunInputs.AddPoint(points[0], points[1]); |
1720 |
} |
1721 |
else |
1722 |
placeRunInputs.AddPoint(points[0], points[1]); |
1723 |
} |
1724 |
|
1725 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, connector.ModelItemID); |
1726 |
|
1727 |
_placement.PIDRemovePlacement(connector.AsLMRepresentation()); |
1728 |
newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
1729 |
|
1730 |
foreach (var line in lines) |
1731 |
line.SPPID.ModelItemId = newConnector.ModelItemID; |
1732 |
} |
1733 |
|
1734 |
|
1735 |
return newConnector; |
1736 |
} |
1737 |
|
1738 |
/// <summary> |
1739 |
/// SpecBreak Modeling 메서드 |
1740 |
/// </summary> |
1741 |
/// <param name="specBreak"></param> |
1742 |
private void SpecBreakModeling(SpecBreak specBreak) |
1743 |
{ |
1744 |
object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID); |
1745 |
object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID); |
1746 |
|
1747 |
if (upStreamObj != null && |
1748 |
downStreamObj != null) |
1749 |
{ |
1750 |
LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj); |
1751 |
|
1752 |
if (targetLMConnector != null) |
1753 |
{ |
1754 |
foreach (var attribute in specBreak.ATTRIBUTES) |
1755 |
{ |
1756 |
AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID); |
1757 |
if (mapping != null && !string.IsNullOrEmpty(mapping.SPPIDSYMBOLNAME) && mapping.SPPIDSYMBOLNAME != "None") |
1758 |
{ |
1759 |
string MappingPath = mapping.SPPIDSYMBOLNAME; |
1760 |
Array array = new double[] { 0, specBreak.SPPID.ORIGINAL_X, specBreak.SPPID.ORIGINAL_Y }; |
1761 |
LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(MappingPath, ref array, Rotation: specBreak.ANGLE, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine); |
1762 |
|
1763 |
if (_LmLabelPersist != null) |
1764 |
{ |
1765 |
ReleaseCOMObjects(_LmLabelPersist); |
1766 |
} |
1767 |
} |
1768 |
} |
1769 |
ReleaseCOMObjects(targetLMConnector); |
1770 |
} |
1771 |
} |
1772 |
} |
1773 |
|
1774 |
private LMConnector FindBreakLineTarget(object targetObj, object connectedObj) |
1775 |
{ |
1776 |
LMConnector targetConnector = null; |
1777 |
Symbol targetSymbol = targetObj as Symbol; |
1778 |
Symbol connectedSymbol = connectedObj as Symbol; |
1779 |
Line targetLine = targetObj as Line; |
1780 |
Line connectedLine = connectedObj as Line; |
1781 |
if (targetSymbol != null && connectedSymbol != null) |
1782 |
{ |
1783 |
LMSymbol targetLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); |
1784 |
LMSymbol connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId); |
1785 |
|
1786 |
foreach (LMConnector connector in targetLMSymbol.Avoid1Connectors) |
1787 |
{ |
1788 |
if (connector.get_ItemStatus() != "Active") |
1789 |
continue; |
1790 |
|
1791 |
if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id) |
1792 |
{ |
1793 |
targetConnector = connector; |
1794 |
break; |
1795 |
} |
1796 |
else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id) |
1797 |
{ |
1798 |
targetConnector = connector; |
1799 |
break; |
1800 |
} |
1801 |
} |
1802 |
|
1803 |
foreach (LMConnector connector in targetLMSymbol.Avoid2Connectors) |
1804 |
{ |
1805 |
if (connector.get_ItemStatus() != "Active") |
1806 |
continue; |
1807 |
|
1808 |
if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id) |
1809 |
{ |
1810 |
targetConnector = connector; |
1811 |
break; |
1812 |
} |
1813 |
else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id) |
1814 |
{ |
1815 |
targetConnector = connector; |
1816 |
break; |
1817 |
} |
1818 |
} |
1819 |
|
1820 |
ReleaseCOMObjects(targetLMSymbol); |
1821 |
ReleaseCOMObjects(connectedLMSymbol); |
1822 |
} |
1823 |
else if (targetLine != null && connectedLine != null) |
1824 |
{ |
1825 |
LMModelItem targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId); |
1826 |
LMModelItem connectedModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId); |
1827 |
|
1828 |
if (targetModelItem != null && connectedModelItem != null) |
1829 |
{ |
1830 |
foreach (LMRepresentation rep in targetModelItem.Representations) |
1831 |
{ |
1832 |
if (targetConnector != null) |
1833 |
break; |
1834 |
|
1835 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
1836 |
{ |
1837 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
1838 |
|
1839 |
if (IsConnected(_LMConnector, connectedModelItem)) |
1840 |
targetConnector = _LMConnector; |
1841 |
else |
1842 |
ReleaseCOMObjects(_LMConnector); |
1843 |
} |
1844 |
} |
1845 |
|
1846 |
ReleaseCOMObjects(targetModelItem); |
1847 |
} |
1848 |
} |
1849 |
else |
1850 |
{ |
1851 |
LMSymbol connectedLMSymbol = connectedSymbol != null ? |
1852 |
dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId) : dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); |
1853 |
LMModelItem targetModelItem = targetLine != null ? |
1854 |
dataSource.GetModelItem(targetLine.SPPID.ModelItemId) : dataSource.GetModelItem(connectedLine.SPPID.ModelItemId); |
1855 |
if (connectedLMSymbol != null && targetModelItem != null) |
1856 |
{ |
1857 |
foreach (LMConnector connector in connectedLMSymbol.Avoid1Connectors) |
1858 |
{ |
1859 |
if (IsConnected(connector, targetModelItem)) |
1860 |
{ |
1861 |
targetConnector = connector; |
1862 |
break; |
1863 |
} |
1864 |
} |
1865 |
|
1866 |
if (targetConnector == null) |
1867 |
{ |
1868 |
foreach (LMConnector connector in connectedLMSymbol.Avoid2Connectors) |
1869 |
{ |
1870 |
if (IsConnected(connector, targetModelItem)) |
1871 |
{ |
1872 |
targetConnector = connector; |
1873 |
break; |
1874 |
} |
1875 |
} |
1876 |
} |
1877 |
} |
1878 |
|
1879 |
} |
1880 |
|
1881 |
return targetConnector; |
1882 |
} |
1883 |
|
1884 |
private bool IsConnected(LMConnector connector, LMModelItem modelItem) |
1885 |
{ |
1886 |
bool result = false; |
1887 |
|
1888 |
foreach (LMRepresentation rep in modelItem.Representations) |
1889 |
{ |
1890 |
if (result) |
1891 |
break; |
1892 |
|
1893 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
1894 |
{ |
1895 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
1896 |
|
1897 |
if (_LMConnector.ConnectItem1SymbolObject != null && |
1898 |
connector.ConnectItem1SymbolObject != null && |
1899 |
_LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id) |
1900 |
{ |
1901 |
result = true; |
1902 |
ReleaseCOMObjects(_LMConnector); |
1903 |
break; |
1904 |
} |
1905 |
else if (_LMConnector.ConnectItem1SymbolObject != null && |
1906 |
connector.ConnectItem2SymbolObject != null && |
1907 |
_LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id) |
1908 |
{ |
1909 |
result = true; |
1910 |
ReleaseCOMObjects(_LMConnector); |
1911 |
break; |
1912 |
} |
1913 |
else if (_LMConnector.ConnectItem2SymbolObject != null && |
1914 |
connector.ConnectItem1SymbolObject != null && |
1915 |
_LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id) |
1916 |
{ |
1917 |
result = true; |
1918 |
ReleaseCOMObjects(_LMConnector); |
1919 |
break; |
1920 |
} |
1921 |
else if (_LMConnector.ConnectItem2SymbolObject != null && |
1922 |
connector.ConnectItem2SymbolObject != null && |
1923 |
_LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id) |
1924 |
{ |
1925 |
result = true; |
1926 |
ReleaseCOMObjects(_LMConnector); |
1927 |
break; |
1928 |
} |
1929 |
|
1930 |
ReleaseCOMObjects(_LMConnector); |
1931 |
} |
1932 |
} |
1933 |
|
1934 |
|
1935 |
return result; |
1936 |
} |
1937 |
|
1938 |
/// <summary> |
1939 |
/// FromModelItem을 ToModelItem으로 PipeRunJoin하는 메서드 |
1940 |
/// </summary> |
1941 |
/// <param name="fromModelItemId"></param> |
1942 |
/// <param name="toModelItemId"></param> |
1943 |
private void JoinPipeRun(string fromModelItemId, string toModelItemId) |
1944 |
{ |
1945 |
LMModelItem modelItem1 = dataSource.GetModelItem(toModelItemId); |
1946 |
_LMAItem item1 = modelItem1.AsLMAItem(); |
1947 |
LMModelItem modelItem2 = dataSource.GetModelItem(fromModelItemId); |
1948 |
_LMAItem item2 = modelItem2.AsLMAItem(); |
1949 |
|
1950 |
// item2가 item1으로 조인 |
1951 |
try |
1952 |
{ |
1953 |
_placement.PIDJoinRuns(ref item1, ref item2); |
1954 |
item1.Commit(); |
1955 |
item2.Commit(); |
1956 |
|
1957 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, fromModelItemId); |
1958 |
foreach (var line in lines) |
1959 |
line.SPPID.ModelItemId = toModelItemId; |
1960 |
} |
1961 |
catch (Exception ex) |
1962 |
{ |
1963 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
1964 |
} |
1965 |
finally |
1966 |
{ |
1967 |
ReleaseCOMObjects(modelItem1); |
1968 |
ReleaseCOMObjects(item1); |
1969 |
ReleaseCOMObjects(modelItem2); |
1970 |
ReleaseCOMObjects(item2); |
1971 |
} |
1972 |
} |
1973 |
|
1974 |
/// <summary> |
1975 |
/// PipeRun을 자동으로 Join하는 메서드 |
1976 |
/// </summary> |
1977 |
/// <param name="modelItemId"></param> |
1978 |
private void AutoJoinPipeRun(string modelItemId) |
1979 |
{ |
1980 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemId); |
1981 |
_LMAItem item = modelItem.AsLMAItem(); |
1982 |
try |
1983 |
{ |
1984 |
string modelitemID = item.Id; |
1985 |
_placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item); |
1986 |
string afterModelItemID = item.Id; |
1987 |
|
1988 |
if (modelitemID != afterModelItemID) |
1989 |
{ |
1990 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID); |
1991 |
foreach (var line in lines) |
1992 |
line.SPPID.ModelItemId = afterModelItemID; |
1993 |
} |
1994 |
item.Commit(); |
1995 |
} |
1996 |
catch (Exception ex) |
1997 |
{ |
1998 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
1999 |
} |
2000 |
finally |
2001 |
{ |
2002 |
ReleaseCOMObjects(modelItem); |
2003 |
ReleaseCOMObjects(item); |
2004 |
} |
2005 |
} |
2006 |
|
2007 |
/// <summary> |
2008 |
/// LineRun에 있는 Line들을 Join하는 진입 메서드 |
2009 |
/// </summary> |
2010 |
/// <param name="run"></param> |
2011 |
private void JoinRunLine(LineRun run) |
2012 |
{ |
2013 |
string modelItemId = string.Empty; |
2014 |
foreach (var item in run.RUNITEMS) |
2015 |
{ |
2016 |
if (item.GetType() == typeof(Line)) |
2017 |
{ |
2018 |
Line line = item as Line; |
2019 |
AutoJoinPipeRun(line.SPPID.ModelItemId); |
2020 |
modelItemId = line.SPPID.ModelItemId; |
2021 |
|
2022 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
2023 |
} |
2024 |
} |
2025 |
} |
2026 |
|
2027 |
/// <summary> |
2028 |
/// PipeRun의 좌표를 가져오는 메서드 |
2029 |
/// </summary> |
2030 |
/// <param name="modelId"></param> |
2031 |
/// <returns></returns> |
2032 |
private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId) |
2033 |
{ |
2034 |
Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>(); |
2035 |
LMModelItem modelItem = dataSource.GetModelItem(modelId); |
2036 |
|
2037 |
if (modelItem != null) |
2038 |
{ |
2039 |
foreach (LMRepresentation rep in modelItem.Representations) |
2040 |
{ |
2041 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
2042 |
{ |
2043 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
2044 |
connectorVertices.Add(_LMConnector, new List<double[]>()); |
2045 |
dynamic OID = rep.get_GraphicOID(); |
2046 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
2047 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
2048 |
int verticesCount = lineStringGeometry.VertexCount; |
2049 |
double[] vertices = null; |
2050 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
2051 |
for (int i = 0; i < verticesCount; i++) |
2052 |
{ |
2053 |
double x = 0; |
2054 |
double y = 0; |
2055 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
2056 |
connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) }); |
2057 |
} |
2058 |
} |
2059 |
} |
2060 |
|
2061 |
ReleaseCOMObjects(modelItem); |
2062 |
} |
2063 |
|
2064 |
return connectorVertices; |
2065 |
} |
2066 |
|
2067 |
/// <summary> |
2068 |
/// LMConnector들을 가져온다. |
2069 |
/// </summary> |
2070 |
/// <param name="modelId"></param> |
2071 |
/// <returns></returns> |
2072 |
private List<LMConnector> GetConnectors(string modelId) |
2073 |
{ |
2074 |
List<LMConnector> connectors = new List<LMConnector>(); |
2075 |
LMModelItem modelItem = dataSource.GetModelItem(modelId); |
2076 |
|
2077 |
if (modelItem != null) |
2078 |
{ |
2079 |
foreach (LMRepresentation rep in modelItem.Representations) |
2080 |
{ |
2081 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
2082 |
{ |
2083 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
2084 |
connectors.Add(_LMConnector); |
2085 |
} |
2086 |
} |
2087 |
|
2088 |
ReleaseCOMObjects(modelItem); |
2089 |
} |
2090 |
|
2091 |
return connectors; |
2092 |
} |
2093 |
|
2094 |
/// <summary> |
2095 |
/// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 두점으로 라인의 교차점을 기준으로 구함 |
2096 |
/// </summary> |
2097 |
/// <param name="connectorVertices"></param> |
2098 |
/// <param name="connX"></param> |
2099 |
/// <param name="connY"></param> |
2100 |
/// <param name="x2"></param> |
2101 |
/// <param name="y2"></param> |
2102 |
/// <returns></returns> |
2103 |
private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2) |
2104 |
{ |
2105 |
double length = double.MaxValue; |
2106 |
LMConnector targetConnector = null; |
2107 |
foreach (var item in connectorVertices) |
2108 |
{ |
2109 |
List<double[]> points = item.Value; |
2110 |
for (int i = 0; i < points.Count - 1; i++) |
2111 |
{ |
2112 |
double[] point1 = points[i]; |
2113 |
double[] point2 = points[i + 1]; |
2114 |
|
2115 |
double maxLineX = Math.Max(point1[0], point2[0]); |
2116 |
double minLineX = Math.Min(point1[0], point2[0]); |
2117 |
double maxLineY = Math.Max(point1[1], point2[1]); |
2118 |
double minLineY = Math.Min(point1[1], point2[1]); |
2119 |
|
2120 |
SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY); |
2121 |
|
2122 |
// 두직선의 교차점 |
2123 |
double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]); |
2124 |
if (crossingPoint != null) |
2125 |
{ |
2126 |
double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]); |
2127 |
if (length >= distance) |
2128 |
{ |
2129 |
if (slope == SlopeType.Slope && |
2130 |
minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] && |
2131 |
minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
2132 |
{ |
2133 |
targetConnector = item.Key; |
2134 |
length = distance; |
2135 |
} |
2136 |
else if (slope == SlopeType.HORIZONTAL && |
2137 |
minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0]) |
2138 |
{ |
2139 |
targetConnector = item.Key; |
2140 |
length = distance; |
2141 |
} |
2142 |
else if (slope == SlopeType.VERTICAL && |
2143 |
minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
2144 |
{ |
2145 |
targetConnector = item.Key; |
2146 |
length = distance; |
2147 |
} |
2148 |
} |
2149 |
} |
2150 |
} |
2151 |
|
2152 |
|
2153 |
} |
2154 |
|
2155 |
if (targetConnector == null) |
2156 |
{ |
2157 |
foreach (var item in connectorVertices) |
2158 |
{ |
2159 |
List<double[]> points = item.Value; |
2160 |
foreach (var point in points) |
2161 |
{ |
2162 |
double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, point[0], point[1]); |
2163 |
if (length >= distance) |
2164 |
{ |
2165 |
targetConnector = item.Key; |
2166 |
length = distance; |
2167 |
} |
2168 |
} |
2169 |
} |
2170 |
|
2171 |
} |
2172 |
|
2173 |
return targetConnector; |
2174 |
} |
2175 |
|
2176 |
/// <summary> |
2177 |
/// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 한점으로 제일 가까운 기준으로 구함(단순) |
2178 |
/// </summary> |
2179 |
/// <param name="connectorVertices"></param> |
2180 |
/// <param name="connX"></param> |
2181 |
/// <param name="connY"></param> |
2182 |
/// <returns></returns> |
2183 |
private LMConnector FindTargetLMConnectorByPoint(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY) |
2184 |
{ |
2185 |
double length = double.MaxValue; |
2186 |
LMConnector targetConnector = null; |
2187 |
foreach (var item in connectorVertices) |
2188 |
{ |
2189 |
List<double[]> points = item.Value; |
2190 |
|
2191 |
foreach (double[] point in points) |
2192 |
{ |
2193 |
double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY); |
2194 |
if (length >= distance) |
2195 |
{ |
2196 |
targetConnector = item.Key; |
2197 |
length = distance; |
2198 |
} |
2199 |
} |
2200 |
} |
2201 |
|
2202 |
return targetConnector; |
2203 |
} |
2204 |
|
2205 |
/// <summary> |
2206 |
/// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식 |
2207 |
/// </summary> |
2208 |
/// <param name="connectorVertices"></param> |
2209 |
/// <param name="connX"></param> |
2210 |
/// <param name="connY"></param> |
2211 |
/// <returns></returns> |
2212 |
private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY) |
2213 |
{ |
2214 |
double length = double.MaxValue; |
2215 |
LMConnector targetConnector = null; |
2216 |
foreach (var item in connectorVertices) |
2217 |
{ |
2218 |
List<double[]> points = item.Value; |
2219 |
for (int i = 0; i < points.Count - 1; i++) |
2220 |
{ |
2221 |
double[] point1 = points[i]; |
2222 |
double[] point2 = points[i + 1]; |
2223 |
double x1 = Math.Min(point1[0], point2[0]); |
2224 |
double y1 = Math.Min(point1[1], point2[1]); |
2225 |
double x2 = Math.Max(point1[0], point2[0]); |
2226 |
double y2 = Math.Max(point1[1], point2[1]); |
2227 |
|
2228 |
if ((x1 <= connX && x2 >= connX) || |
2229 |
(y1 <= connY && y2 >= connY)) |
2230 |
{ |
2231 |
double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY); |
2232 |
if (length >= distance) |
2233 |
{ |
2234 |
targetConnector = item.Key; |
2235 |
length = distance; |
2236 |
} |
2237 |
|
2238 |
distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY); |
2239 |
if (length >= distance) |
2240 |
{ |
2241 |
targetConnector = item.Key; |
2242 |
length = distance; |
2243 |
} |
2244 |
} |
2245 |
} |
2246 |
} |
2247 |
|
2248 |
// 못찾았을때. |
2249 |
length = double.MaxValue; |
2250 |
if (targetConnector == null) |
2251 |
{ |
2252 |
foreach (var item in connectorVertices) |
2253 |
{ |
2254 |
List<double[]> points = item.Value; |
2255 |
|
2256 |
foreach (double[] point in points) |
2257 |
{ |
2258 |
double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY); |
2259 |
if (length >= distance) |
2260 |
{ |
2261 |
targetConnector = item.Key; |
2262 |
length = distance; |
2263 |
} |
2264 |
} |
2265 |
} |
2266 |
} |
2267 |
|
2268 |
return targetConnector; |
2269 |
} |
2270 |
|
2271 |
/// <summary> |
2272 |
/// Line Number Symbol을 실제로 Modeling하는 메서드 |
2273 |
/// </summary> |
2274 |
/// <param name="lineNumber"></param> |
2275 |
private void LineNumberModeling(LineNumber lineNumber) |
2276 |
{ |
2277 |
Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line; |
2278 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId); |
2279 |
LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y); |
2280 |
if (connectedLMConnector != null) |
2281 |
{ |
2282 |
double x = 0; |
2283 |
double y = 0; |
2284 |
CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation); |
2285 |
|
2286 |
Array points = new double[] { 0, x, y }; |
2287 |
LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false); |
2288 |
|
2289 |
foreach (var item in connectorVertices) |
2290 |
ReleaseCOMObjects(item.Key); |
2291 |
if (_LmLabelPresist != null) |
2292 |
{ |
2293 |
_LmLabelPresist.Commit(); |
2294 |
lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id; |
2295 |
ReleaseCOMObjects(_LmLabelPresist); |
2296 |
} |
2297 |
else |
2298 |
{ |
2299 |
|
2300 |
} |
2301 |
} |
2302 |
|
2303 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
2304 |
} |
2305 |
|
2306 |
/// <summary> |
2307 |
/// Flow Mark Modeling |
2308 |
/// </summary> |
2309 |
/// <param name="line"></param> |
2310 |
private void FlowMarkModeling(Line line) |
2311 |
{ |
2312 |
if (line.FLOWMARK && !string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(_ETCSetting.FlowMarkSymbolPath)) |
2313 |
{ |
2314 |
SlopeType targetSlopeType = SPPIDUtil.CalcSlope(line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y); |
2315 |
string mappingPath = _ETCSetting.FlowMarkSymbolPath; |
2316 |
double percent = line.FLOWMARK_PERCENT; |
2317 |
double tempX = 0; |
2318 |
double tempY = 0; |
2319 |
|
2320 |
double gapX; |
2321 |
double gapY; |
2322 |
// ID2 기준의 Gap을 구함 |
2323 |
if (percent == 0) |
2324 |
{ |
2325 |
gapX = 0; |
2326 |
gapY = 0; |
2327 |
} |
2328 |
else |
2329 |
{ |
2330 |
gapX = Math.Abs(line.SPPID.START_X - line.SPPID.END_X) / 100 * percent; |
2331 |
gapY = Math.Abs(line.SPPID.START_Y - line.SPPID.END_Y) / 100 * percent; |
2332 |
} |
2333 |
|
2334 |
if (line.SPPID.START_X < line.SPPID.END_X) |
2335 |
tempX = line.SPPID.START_X + gapX; |
2336 |
else |
2337 |
tempX = line.SPPID.START_X - gapX; |
2338 |
|
2339 |
if (line.SPPID.START_Y < line.SPPID.END_Y) |
2340 |
tempY = line.SPPID.START_Y + gapY; |
2341 |
else |
2342 |
tempY = line.SPPID.START_Y - gapY; |
2343 |
|
2344 |
|
2345 |
|
2346 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId); |
2347 |
LMConnector _TargetItem = null; |
2348 |
double distance = double.MaxValue; |
2349 |
double[] startPoint = null; |
2350 |
double[] endPoint = null; |
2351 |
// ID2의 기준 Gap으로 제일 가까운 Line 찾음(Slope도 같은조건) |
2352 |
foreach (var item in connectorVertices) |
2353 |
{ |
2354 |
for (int i = 0; i < item.Value.Count - 1; i++) |
2355 |
{ |
2356 |
List<double[]> points = item.Value; |
2357 |
double[] point1 = points[i]; |
2358 |
double[] point2 = points[i + 1]; |
2359 |
|
2360 |
SlopeType slopeType = SPPIDUtil.CalcSlope(point1[0], point1[1], point2[0], point2[1]); |
2361 |
if (slopeType == targetSlopeType) |
2362 |
{ |
2363 |
double result = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], tempX, tempY); |
2364 |
if (result < distance) |
2365 |
{ |
2366 |
distance = result; |
2367 |
_TargetItem = item.Key; |
2368 |
|
2369 |
startPoint = point1; |
2370 |
endPoint = point2; |
2371 |
} |
2372 |
|
2373 |
result = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], tempX, tempY); |
2374 |
if (result < distance) |
2375 |
{ |
2376 |
distance = result; |
2377 |
_TargetItem = item.Key; |
2378 |
|
2379 |
startPoint = point1; |
2380 |
endPoint = point2; |
2381 |
} |
2382 |
} |
2383 |
} |
2384 |
} |
2385 |
|
2386 |
if (_TargetItem != null) |
2387 |
{ |
2388 |
double x = 0; |
2389 |
double y = 0; |
2390 |
double angle = 0; |
2391 |
// SPPID 기준의 Gap으로 실 좌표를 구함 |
2392 |
if (percent == 0) |
2393 |
{ |
2394 |
gapX = 0; |
2395 |
gapY = 0; |
2396 |
} |
2397 |
else |
2398 |
{ |
2399 |
gapX = Math.Abs(startPoint[0] - endPoint[0]) / 100 * percent; |
2400 |
gapY = Math.Abs(startPoint[1] - endPoint[1]) / 100 * percent; |
2401 |
} |
2402 |
|
2403 |
if (startPoint[0] < endPoint[0]) |
2404 |
x = startPoint[0] + gapX; |
2405 |
else |
2406 |
x = startPoint[0] - gapX; |
2407 |
|
2408 |
if (startPoint[1] < endPoint[1]) |
2409 |
y = startPoint[1] + gapY; |
2410 |
else |
2411 |
y = startPoint[1] - gapY; |
2412 |
|
2413 |
if (targetSlopeType == SlopeType.HORIZONTAL) |
2414 |
{ |
2415 |
if (startPoint[0] < endPoint[0]) |
2416 |
angle = 0; |
2417 |
else |
2418 |
angle = Math.PI; |
2419 |
} |
2420 |
// 90 270 |
2421 |
else if (targetSlopeType == SlopeType.VERTICAL) |
2422 |
{ |
2423 |
if (startPoint[1] < endPoint[1]) |
2424 |
angle = 90 * Math.PI / 180; |
2425 |
else |
2426 |
angle = 270 * Math.PI / 180; |
2427 |
} |
2428 |
|
2429 |
LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: 0, Rotation: angle, TargetItem: _TargetItem); |
2430 |
|
2431 |
if (_LMSymbol != null) |
2432 |
{ |
2433 |
ReleaseCOMObjects(_LMSymbol); |
2434 |
} |
2435 |
|
2436 |
} |
2437 |
|
2438 |
foreach (var item in connectorVertices) |
2439 |
ReleaseCOMObjects(item.Key); |
2440 |
} |
2441 |
} |
2442 |
|
2443 |
/// <summary> |
2444 |
/// Line Number 기준으로 모든 Item에 Line Number의 Attribute Input |
2445 |
/// </summary> |
2446 |
/// <param name="lineNumber"></param> |
2447 |
private void InputLineNumberAttribute(LineNumber lineNumber) |
2448 |
{ |
2449 |
foreach (LineRun run in lineNumber.RUNS) |
2450 |
{ |
2451 |
foreach (var item in run.RUNITEMS) |
2452 |
{ |
2453 |
if (item.GetType() == typeof(Symbol)) |
2454 |
{ |
2455 |
Symbol symbol = item as Symbol; |
2456 |
LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
2457 |
LMModelItem _LMModelItem = _LMSymbol.ModelItemObject; |
2458 |
|
2459 |
if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
2460 |
{ |
2461 |
foreach (var attribute in lineNumber.ATTRIBUTES) |
2462 |
{ |
2463 |
LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID); |
2464 |
if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
2465 |
{ |
2466 |
LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME]; |
2467 |
if (_LMAAttribute != null) |
2468 |
{ |
2469 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
2470 |
_LMAAttribute.set_Value(attribute.VALUE); |
2471 |
else if (_LMAAttribute.get_Value() != attribute.VALUE) |
2472 |
_LMAAttribute.set_Value(attribute.VALUE); |
2473 |
} |
2474 |
} |
2475 |
} |
2476 |
_LMModelItem.Commit(); |
2477 |
} |
2478 |
if (_LMModelItem != null) |
2479 |
ReleaseCOMObjects(_LMModelItem); |
2480 |
if (_LMSymbol != null) |
2481 |
ReleaseCOMObjects(_LMSymbol); |
2482 |
} |
2483 |
else if (item.GetType() == typeof(Line)) |
2484 |
{ |
2485 |
Line line = item as Line; |
2486 |
if (line != null) |
2487 |
{ |
2488 |
LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
2489 |
if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
2490 |
{ |
2491 |
foreach (var attribute in lineNumber.ATTRIBUTES) |
2492 |
{ |
2493 |
LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID); |
2494 |
if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
2495 |
{ |
2496 |
LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME]; |
2497 |
if (_LMAAttribute != null) |
2498 |
{ |
2499 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
2500 |
_LMAAttribute.set_Value(attribute.VALUE); |
2501 |
else if (_LMAAttribute.get_Value() != attribute.VALUE) |
2502 |
_LMAAttribute.set_Value(attribute.VALUE); |
2503 |
|
2504 |
} |
2505 |
} |
2506 |
} |
2507 |
_LMModelItem.Commit(); |
2508 |
} |
2509 |
if (_LMModelItem != null) |
2510 |
ReleaseCOMObjects(_LMModelItem); |
2511 |
} |
2512 |
} |
2513 |
} |
2514 |
} |
2515 |
|
2516 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
2517 |
} |
2518 |
|
2519 |
/// <summary> |
2520 |
/// Symbol Attribute 입력 메서드 |
2521 |
/// </summary> |
2522 |
/// <param name="item"></param> |
2523 |
private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes) |
2524 |
{ |
2525 |
try |
2526 |
{ |
2527 |
// Object 아이템이 Symbol일 경우 Equipment일 경우 |
2528 |
string sRep = null; |
2529 |
if (targetItem.GetType() == typeof(Symbol)) |
2530 |
sRep = ((Symbol)targetItem).SPPID.RepresentationId; |
2531 |
else if (targetItem.GetType() == typeof(Equipment)) |
2532 |
sRep = ((Equipment)targetItem).SPPID.RepresentationId; |
2533 |
|
2534 |
if (!string.IsNullOrEmpty(sRep)) |
2535 |
{ |
2536 |
LMSymbol _LMSymbol = dataSource.GetSymbol(sRep); |
2537 |
LMModelItem _LMModelItem = _LMSymbol.ModelItemObject; |
2538 |
LMAAttributes _Attributes = _LMModelItem.Attributes; |
2539 |
|
2540 |
foreach (var item in targetAttributes) |
2541 |
{ |
2542 |
AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID); |
2543 |
if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None") |
2544 |
{ |
2545 |
LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME]; |
2546 |
if (_Attribute != null) |
2547 |
_Attribute.set_Value(item.VALUE); |
2548 |
} |
2549 |
} |
2550 |
_LMModelItem.Commit(); |
2551 |
|
2552 |
ReleaseCOMObjects(_Attributes); |
2553 |
ReleaseCOMObjects(_LMModelItem); |
2554 |
ReleaseCOMObjects(_LMSymbol); |
2555 |
} |
2556 |
} |
2557 |
catch (Exception ex) |
2558 |
{ |
2559 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
2560 |
} |
2561 |
|
2562 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
2563 |
} |
2564 |
|
2565 |
/// <summary> |
2566 |
/// Input SpecBreak Attribute |
2567 |
/// </summary> |
2568 |
/// <param name="specBreak"></param> |
2569 |
private void InputSpecBreakAttribute(SpecBreak specBreak) |
2570 |
{ |
2571 |
try |
2572 |
{ |
2573 |
object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID); |
2574 |
object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID); |
2575 |
|
2576 |
if (upStreamObj != null && |
2577 |
downStreamObj != null) |
2578 |
{ |
2579 |
LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj); |
2580 |
|
2581 |
if (targetLMConnector != null) |
2582 |
{ |
2583 |
foreach (LMLabelPersist _LMLabelPersist in targetLMConnector.LabelPersists) |
2584 |
{ |
2585 |
string symbolPath = _LMLabelPersist.get_FileName(); |
2586 |
AttributeMapping mapping = document.AttributeMappings.Find(x => x.SPPIDSYMBOLNAME == symbolPath); |
2587 |
if (mapping != null) |
2588 |
{ |
2589 |
BaseModel.Attribute attribute = specBreak.ATTRIBUTES.Find(y => y.UID == mapping.UID); |
2590 |
if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
2591 |
{ |
2592 |
string[] values = attribute.VALUE.Split(new char[] { ',' }); |
2593 |
if (values.Length == 2) |
2594 |
{ |
2595 |
string upStreamValue = values[0]; |
2596 |
string downStreamValue = values[1]; |
2597 |
|
2598 |
InputAttributeForSpecBreak(upStreamObj, downStreamObj, upStreamValue, downStreamValue, mapping.SPPIDATTRIBUTENAME); |
2599 |
} |
2600 |
} |
2601 |
} |
2602 |
} |
2603 |
|
2604 |
ReleaseCOMObjects(targetLMConnector); |
2605 |
} |
2606 |
} |
2607 |
} |
2608 |
catch (Exception ex) |
2609 |
{ |
2610 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
2611 |
} |
2612 |
|
2613 |
#region 내부에서만 쓰는 메서드 |
2614 |
void InputAttributeForSpecBreak(object upStreamObj, object downStreamObj, string upStreamValue, string downStreamValue, string sppidAttributeName) |
2615 |
{ |
2616 |
try |
2617 |
{ |
2618 |
Symbol upStreamSymbol = upStreamObj as Symbol; |
2619 |
Line upStreamLine = upStreamObj as Line; |
2620 |
Symbol downStreamSymbol = downStreamObj as Symbol; |
2621 |
Line downStreamLine = downStreamObj as Line; |
2622 |
// 둘다 Line일 경우 |
2623 |
if (upStreamLine != null && downStreamLine != null) |
2624 |
{ |
2625 |
InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue); |
2626 |
InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue); |
2627 |
} |
2628 |
// 둘다 Symbol일 경우 |
2629 |
else if (upStreamSymbol != null && downStreamSymbol != null) |
2630 |
{ |
2631 |
LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamSymbol); |
2632 |
LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId); |
2633 |
LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId); |
2634 |
|
2635 |
foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors) |
2636 |
{ |
2637 |
if (connector.get_ItemStatus() != "Active") |
2638 |
continue; |
2639 |
|
2640 |
if (connector.Id != zeroLenthConnector.Id) |
2641 |
InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue); |
2642 |
} |
2643 |
|
2644 |
foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors) |
2645 |
{ |
2646 |
if (connector.get_ItemStatus() != "Active") |
2647 |
continue; |
2648 |
|
2649 |
if (connector.Id != zeroLenthConnector.Id) |
2650 |
InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue); |
2651 |
} |
2652 |
|
2653 |
foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors) |
2654 |
{ |
2655 |
if (connector.get_ItemStatus() != "Active") |
2656 |
continue; |
2657 |
|
2658 |
if (connector.Id != zeroLenthConnector.Id) |
2659 |
InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue); |
2660 |
} |
2661 |
|
2662 |
foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors) |
2663 |
{ |
2664 |
if (connector.get_ItemStatus() != "Active") |
2665 |
continue; |
2666 |
|
2667 |
if (connector.Id != zeroLenthConnector.Id) |
2668 |
InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue); |
2669 |
} |
2670 |
|
2671 |
ReleaseCOMObjects(zeroLenthConnector); |
2672 |
ReleaseCOMObjects(upStreamLMSymbol); |
2673 |
ReleaseCOMObjects(downStreamLMSymbol); |
2674 |
} |
2675 |
else if (upStreamSymbol != null && downStreamLine != null) |
2676 |
{ |
2677 |
LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamLine); |
2678 |
InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue); |
2679 |
LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId); |
2680 |
|
2681 |
foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors) |
2682 |
{ |
2683 |
if (connector.get_ItemStatus() != "Active") |
2684 |
continue; |
2685 |
|
2686 |
if (connector.Id != zeroLenthConnector.Id) |
2687 |
InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue); |
2688 |
} |
2689 |
|
2690 |
foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors) |
2691 |
{ |
2692 |
if (connector.get_ItemStatus() != "Active") |
2693 |
continue; |
2694 |
|
2695 |
if (connector.Id != zeroLenthConnector.Id) |
2696 |
InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue); |
2697 |
} |
2698 |
|
2699 |
ReleaseCOMObjects(zeroLenthConnector); |
2700 |
ReleaseCOMObjects(upStreamLMSymbol); |
2701 |
} |
2702 |
else if (upStreamLine != null && downStreamSymbol != null) |
2703 |
{ |
2704 |
LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamLine, downStreamSymbol); |
2705 |
InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue); |
2706 |
LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId); |
2707 |
|
2708 |
foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors) |
2709 |
{ |
2710 |
if (connector.get_ItemStatus() != "Active") |
2711 |
continue; |
2712 |
|
2713 |
if (connector.Id != zeroLenthConnector.Id) |
2714 |
InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue); |
2715 |
} |
2716 |
|
2717 |
foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors) |
2718 |
{ |
2719 |
if (connector.get_ItemStatus() != "Active") |
2720 |
continue; |
2721 |
|
2722 |
if (connector.Id != zeroLenthConnector.Id) |
2723 |
InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue); |
2724 |
} |
2725 |
|
2726 |
ReleaseCOMObjects(zeroLenthConnector); |
2727 |
ReleaseCOMObjects(downStreamLMSymbol); |
2728 |
} |
2729 |
} |
2730 |
catch (Exception ex) |
2731 |
{ |
2732 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
2733 |
} |
2734 |
} |
2735 |
|
2736 |
void InputLineAttributeForSpecBreakLine(Line line, string attrName, string value) |
2737 |
{ |
2738 |
try |
2739 |
{ |
2740 |
LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
2741 |
if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
2742 |
{ |
2743 |
LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName]; |
2744 |
if (_LMAAttribute != null) |
2745 |
{ |
2746 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
2747 |
_LMAAttribute.set_Value(value); |
2748 |
else if (_LMAAttribute.get_Value() != value) |
2749 |
_LMAAttribute.set_Value(value); |
2750 |
} |
2751 |
|
2752 |
_LMModelItem.Commit(); |
2753 |
} |
2754 |
if (_LMModelItem != null) |
2755 |
ReleaseCOMObjects(_LMModelItem); |
2756 |
} |
2757 |
catch (Exception ex) |
2758 |
{ |
2759 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
2760 |
} |
2761 |
} |
2762 |
|
2763 |
void InputLineAttributeForSpecBreakLMConnector(LMConnector connector, string attrName, string value) |
2764 |
{ |
2765 |
try |
2766 |
{ |
2767 |
LMModelItem _LMModelItem = dataSource.GetModelItem(connector.ModelItemID); |
2768 |
if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
2769 |
{ |
2770 |
LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName]; |
2771 |
if (_LMAAttribute != null) |
2772 |
{ |
2773 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
2774 |
_LMAAttribute.set_Value(value); |
2775 |
else if (_LMAAttribute.get_Value() != value) |
2776 |
_LMAAttribute.set_Value(value); |
2777 |
} |
2778 |
|
2779 |
_LMModelItem.Commit(); |
2780 |
} |
2781 |
if (_LMModelItem != null) |
2782 |
ReleaseCOMObjects(_LMModelItem); |
2783 |
} |
2784 |
catch (Exception ex) |
2785 |
{ |
2786 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
2787 |
} |
2788 |
} |
2789 |
#endregion |
2790 |
} |
2791 |
|
2792 |
/// <summary> |
2793 |
/// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링 |
2794 |
/// </summary> |
2795 |
/// <param name="text"></param> |
2796 |
private void TextModeling(Text text) |
2797 |
{ |
2798 |
LMSymbol _LMSymbol = null; |
2799 |
try |
2800 |
{ |
2801 |
//if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None") |
2802 |
if (text.ASSOCIATION) |
2803 |
{ |
2804 |
object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER); |
2805 |
if (owner.GetType() == typeof(Symbol)) |
2806 |
{ |
2807 |
Symbol symbol = owner as Symbol; |
2808 |
_LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
2809 |
if (_LMSymbol != null) |
2810 |
{ |
2811 |
Association association = symbol.ASSOCIATIONS.Find(x => x.VALUE == text.UID); |
2812 |
List<BaseModel.Attribute> attributes = symbol.ATTRIBUTES.FindAll(x => x.ATTRIBUTETYPE == association.TYPE); |
2813 |
AttributeMapping mapping = null; |
2814 |
foreach (var attribute in attributes) |
2815 |
{ |
2816 |
if (string.IsNullOrEmpty(attribute.VALUE) || attribute.VALUE == "None") |
2817 |
continue; |
2818 |
|
2819 |
mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME)); |
2820 |
if (mapping != null) |
2821 |
break; |
2822 |
} |
2823 |
|
2824 |
if (mapping != null) |
2825 |
{ |
2826 |
double x = 0; |
2827 |
double y = 0; |
2828 |
|
2829 |
CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location); |
2830 |
Array array = new double[] { 0, x, y }; |
2831 |
|
2832 |
LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine); |
2833 |
if (_LMLabelPersist!=null) |
2834 |
{ |
2835 |
_LMLabelPersist.Commit(); |
2836 |
ReleaseCOMObjects(_LMLabelPersist); |
2837 |
} |
2838 |
} |
2839 |
} |
2840 |
} |
2841 |
else if (owner.GetType() == typeof(Line)) |
2842 |
{ |
2843 |
|
2844 |
} |
2845 |
} |
2846 |
else |
2847 |
{ |
2848 |
LMItemNote _LMItemNote = null; |
2849 |
LMAAttribute _LMAAttribute = null; |
2850 |
|
2851 |
double x = 0; |
2852 |
double y = 0; |
2853 |
|
2854 |
CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation); |
2855 |
|
2856 |
_LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y); |
2857 |
_LMSymbol.Commit(); |
2858 |
_LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
2859 |
_LMItemNote.Commit(); |
2860 |
_LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
2861 |
_LMAAttribute.set_Value(text.VALUE); |
2862 |
_LMItemNote.Commit(); |
2863 |
|
2864 |
if (_LMAAttribute != null) |
2865 |
ReleaseCOMObjects(_LMAAttribute); |
2866 |
if (_LMItemNote != null) |
2867 |
ReleaseCOMObjects(_LMItemNote); |
2868 |
} |
2869 |
} |
2870 |
catch (Exception ex) |
2871 |
{ |
2872 |
|
2873 |
} |
2874 |
finally |
2875 |
{ |
2876 |
if (_LMSymbol != null) |
2877 |
ReleaseCOMObjects(_LMSymbol); |
2878 |
} |
2879 |
|
2880 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
2881 |
} |
2882 |
|
2883 |
/// <summary> |
2884 |
/// Note Modeling |
2885 |
/// </summary> |
2886 |
/// <param name="note"></param> |
2887 |
private void NoteModeling(Note note) |
2888 |
{ |
2889 |
LMSymbol _LMSymbol = null; |
2890 |
LMItemNote _LMItemNote = null; |
2891 |
LMAAttribute _LMAAttribute = null; |
2892 |
|
2893 |
try |
2894 |
{ |
2895 |
double x = 0; |
2896 |
double y = 0; |
2897 |
|
2898 |
CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation); |
2899 |
|
2900 |
_LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y); |
2901 |
_LMSymbol.Commit(); |
2902 |
_LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
2903 |
_LMItemNote.Commit(); |
2904 |
_LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
2905 |
_LMAAttribute.set_Value(note.VALUE); |
2906 |
_LMItemNote.Commit(); |
2907 |
} |
2908 |
catch (Exception ex) |
2909 |
{ |
2910 |
|
2911 |
} |
2912 |
finally |
2913 |
{ |
2914 |
if (_LMAAttribute != null) |
2915 |
ReleaseCOMObjects(_LMAAttribute); |
2916 |
if (_LMItemNote != null) |
2917 |
ReleaseCOMObjects(_LMItemNote); |
2918 |
if (_LMSymbol != null) |
2919 |
ReleaseCOMObjects(_LMSymbol); |
2920 |
} |
2921 |
|
2922 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
2923 |
} |
2924 |
|
2925 |
/// <summary> |
2926 |
/// Label의 좌표를 구하는 메서드(ID2 기준의 좌표 -> SPPID 좌표) |
2927 |
/// </summary> |
2928 |
/// <param name="x"></param> |
2929 |
/// <param name="y"></param> |
2930 |
/// <param name="originX"></param> |
2931 |
/// <param name="originY"></param> |
2932 |
/// <param name="SPPIDLabelLocation"></param> |
2933 |
/// <param name="location"></param> |
2934 |
private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location) |
2935 |
{ |
2936 |
if (location == Location.None) |
2937 |
{ |
2938 |
x = originX; |
2939 |
y = originY; |
2940 |
} |
2941 |
else |
2942 |
{ |
2943 |
if (location.HasFlag(Location.Center)) |
2944 |
{ |
2945 |
x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2; |
2946 |
y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2; |
2947 |
} |
2948 |
|
2949 |
if (location.HasFlag(Location.Left)) |
2950 |
x = SPPIDLabelLocation.X1; |
2951 |
else if (location.HasFlag(Location.Right)) |
2952 |
x = SPPIDLabelLocation.X2; |
2953 |
|
2954 |
if (location.HasFlag(Location.Down)) |
2955 |
y = SPPIDLabelLocation.Y1; |
2956 |
else if (location.HasFlag(Location.Up)) |
2957 |
y = SPPIDLabelLocation.Y2; |
2958 |
} |
2959 |
} |
2960 |
|
2961 |
/// <summary> |
2962 |
/// Symbol의 우선순위 Modeling 목록을 가져온다. |
2963 |
/// 1. Angle Valve |
2964 |
/// 2. 3개로 이루어진 Symbol Group |
2965 |
/// </summary> |
2966 |
/// <returns></returns> |
2967 |
private List<Symbol> GetPrioritySymbol() |
2968 |
{ |
2969 |
DataTable symbolTable = document.SymbolTable; |
2970 |
|
2971 |
// List에 순서대로 쌓는다. |
2972 |
List<Symbol> symbols = new List<Symbol>(); |
2973 |
// Angle Valve 부터 |
2974 |
foreach (var symbol in document.SYMBOLS.FindAll(x => x.CONNECTORS.Count == 2)) |
2975 |
{ |
2976 |
if (!symbols.Contains(symbol)) |
2977 |
{ |
2978 |
double originX = 0; |
2979 |
double originY = 0; |
2980 |
|
2981 |
// ID2 Table에서 Original Point 가져옴. |
2982 |
string OriginalPoint = symbolTable.Select(string.Format("UID = {0}",symbol.DBUID))[0]["OriginalPoint"].ToString(); |
2983 |
SPPIDUtil.ConvertPointBystring(OriginalPoint, ref originX, ref originY); |
2984 |
|
2985 |
SlopeType slopeType1 = SlopeType.None; |
2986 |
SlopeType slopeType2 = SlopeType.None; |
2987 |
foreach (Connector connector in symbol.CONNECTORS) |
2988 |
{ |
2989 |
double connectorX = 0; |
2990 |
double connectorY = 0; |
2991 |
SPPIDUtil.ConvertPointBystring(connector.CONNECTPOINT, ref connectorX, ref connectorY); |
2992 |
if (slopeType1 == SlopeType.None) |
2993 |
slopeType1 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY); |
2994 |
else |
2995 |
slopeType2 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY); |
2996 |
} |
2997 |
|
2998 |
if ((slopeType1 == SlopeType.VERTICAL && slopeType2 == SlopeType.HORIZONTAL) || |
2999 |
(slopeType2 == SlopeType.VERTICAL && slopeType1 == SlopeType.HORIZONTAL)) |
3000 |
symbols.Add(symbol); |
3001 |
} |
3002 |
} |
3003 |
|
3004 |
// 3개의 Symbol이 뭉쳐 있을 때 |
3005 |
foreach (var item in document.SYMBOLS) |
3006 |
{ |
3007 |
List<Symbol> group = new List<Symbol>(); |
3008 |
SPPIDUtil.FindConnectedSymbolGroup(document, item, group); |
3009 |
if (group.Count == 3) |
3010 |
{ |
3011 |
Symbol symbol = SPPIDUtil.FindCenterAtThreeSymbols(document, group); |
3012 |
if (!symbols.Contains(symbol)) |
3013 |
symbols.Add(symbol); |
3014 |
} |
3015 |
} |
3016 |
|
3017 |
// Connection Point가 3개 이상 |
3018 |
foreach (var symbol in document.SYMBOLS) |
3019 |
if (symbol.CONNECTORS.Count > 2 && !symbols.Contains(symbol)) |
3020 |
symbols.Add(symbol); |
3021 |
|
3022 |
return symbols; |
3023 |
} |
3024 |
|
3025 |
/// <summary> |
3026 |
/// Graphic OID로 해당 Symbol의 크기를 구하여 Zoom |
3027 |
/// </summary> |
3028 |
/// <param name="graphicOID"></param> |
3029 |
/// <param name="milliseconds"></param> |
3030 |
private void ZoomObjectByGraphicOID(string graphicOID, int milliseconds = 150) |
3031 |
{ |
3032 |
if (radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] != null) |
3033 |
{ |
3034 |
double minX = 0; |
3035 |
double minY = 0; |
3036 |
double maxX = 0; |
3037 |
double maxY = 0; |
3038 |
radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID].Range(out minX, out minY, out maxX, out maxY); |
3039 |
radApp.ActiveWindow.ZoomArea2(minX - 0.007, minY - 0.007, maxX + 0.007, maxY + 0.007, null); |
3040 |
|
3041 |
Thread.Sleep(milliseconds); |
3042 |
} |
3043 |
} |
3044 |
|
3045 |
/// <summary> |
3046 |
/// ComObject를 Release |
3047 |
/// </summary> |
3048 |
/// <param name="objVars"></param> |
3049 |
public void ReleaseCOMObjects(params object[] objVars) |
3050 |
{ |
3051 |
int intNewRefCount = 0; |
3052 |
foreach (object obj in objVars) |
3053 |
{ |
3054 |
if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
3055 |
intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
3056 |
} |
3057 |
} |
3058 |
} |
3059 |
} |