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