hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ baa87c88
이력 | 보기 | 이력해설 | 다운로드 (330 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 |
using DevExpress.XtraSplashScreen; |
25 |
using System.IO; |
26 |
|
27 |
namespace Converter.SPPID |
28 |
{ |
29 |
[Flags] |
30 |
public enum SegmentLocation |
31 |
{ |
32 |
None = 0, |
33 |
Right = 1, |
34 |
Left = 2, |
35 |
Down = 4, |
36 |
Up = 8 |
37 |
} |
38 |
public class AutoModeling : IDisposable |
39 |
{ |
40 |
Placement _placement; |
41 |
LMADataSource dataSource; |
42 |
string drawingID; |
43 |
dynamic newDrawing; |
44 |
dynamic application; |
45 |
bool closeDocument; |
46 |
Ingr.RAD2D.Application radApp; |
47 |
SPPID_Document document; |
48 |
ETCSetting _ETCSetting; |
49 |
DataTable nominalDiameterTable = null; |
50 |
public string DocumentLabelText { get; set; } |
51 |
|
52 |
List<double[]> itemRange = new List<double[]>(); |
53 |
|
54 |
List<Line> BranchLines = new List<Line>(); |
55 |
List<string> ZeroLengthSymbolToSymbolModelItemID = new List<string>(); |
56 |
List<string> ZeroLengthModelItemID = new List<string>(); |
57 |
List<string> ZeroLengthModelItemIDReverse = new List<string>(); |
58 |
List<Symbol> prioritySymbols; |
59 |
List<string> FlowMarkRepIds = new List<string>(); |
60 |
|
61 |
public AutoModeling(SPPID_Document document, bool closeDocument) |
62 |
{ |
63 |
application = Interaction.GetObject("", "PIDAutomation.Application"); |
64 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
65 |
radApp = wApp.RADApplication; |
66 |
|
67 |
this.closeDocument = closeDocument; |
68 |
this.document = document; |
69 |
this._ETCSetting = ETCSetting.GetInstance(); |
70 |
} |
71 |
|
72 |
private void SetSystemEditingCommand(bool value) |
73 |
{ |
74 |
foreach (var item in radApp.Commands) |
75 |
{ |
76 |
if (item.Argument == "SystemEditingCmd.SystemEditing") |
77 |
{ |
78 |
if (item.Checked != value) |
79 |
{ |
80 |
radApp.RunMacro("systemeditingcmd.dll"); |
81 |
break; |
82 |
} |
83 |
|
84 |
} |
85 |
} |
86 |
} |
87 |
|
88 |
/// <summary> |
89 |
/// 도면 단위당 실행되는 메서드 |
90 |
/// </summary> |
91 |
public void Run() |
92 |
{ |
93 |
string drawingNumber = document.DrawingNumber; |
94 |
string drawingName = document.DrawingName; |
95 |
try |
96 |
{ |
97 |
radApp.Interactive = false; |
98 |
|
99 |
nominalDiameterTable = Project_DB.SelectProjectNominalDiameter(); |
100 |
_placement = new Placement(); |
101 |
dataSource = _placement.PIDDataSource; |
102 |
|
103 |
if (CreateDocument(ref drawingNumber, ref drawingName) && DocumentCoordinateCorrection()) |
104 |
{ |
105 |
Log.Write("Start Modeling"); |
106 |
SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true); |
107 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetParent, (IntPtr)radApp.HWnd); |
108 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllStepCount, 26); |
109 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText); |
110 |
|
111 |
// VendorPackage Modeling |
112 |
// ID2에서 VendorPackage로 된 Symbol을 SPPID에서 그림 |
113 |
RunVendorPackageModeling(); |
114 |
// Equipment Modeling |
115 |
// Id2에서 인식한 Equipment일 경우 SPPID에 Draft |
116 |
RunEquipmentModeling(); |
117 |
// Symbol Modeling |
118 |
// ID2의 Symbol Draft |
119 |
// 단 Symbol draft할 때 붙어 있는 symbol도 draft함 |
120 |
RunSymbolModeling(); |
121 |
// LineRun Line Modeling |
122 |
// Line 그리는 우선 순위 |
123 |
// 1. Branch 없는 것 |
124 |
// 2. Symbol 연결 개수 |
125 |
// 3. Symbol 제외 Item 연결 개수 |
126 |
// 4. ConnectedItem이 없는것 |
127 |
RunLineModeling(); |
128 |
// Vent Drain Modeling |
129 |
// Vent/Drain으로 인식한 Item draft |
130 |
// 인식 조건 |
131 |
// 1. ID2에서 Line이 하나며 Branch된 Line이 있고 |
132 |
// 2. Valve가 line에 붙어있다. |
133 |
RunVentDrainModeling(); |
134 |
// Clear Attribute |
135 |
// SPPID에서 Line 생성 시 자동으로 Nominal Diameter가 입력되는 경우가 있음 |
136 |
// 모든 Item의 Nominal Diameter 속성값 초기화 |
137 |
RunClearNominalDiameter(); |
138 |
// Join SameConnector |
139 |
// 기존 Line을 그릴때 SPPID에서는 같은 Run으로 생성되지 않고 각각 PipeRun이 생성됨 |
140 |
// ID2의 EndBreak등 segmentbreak가 없으면 Line을 합침 |
141 |
RunJoinRunForSameConnector(); |
142 |
// Join Run |
143 |
// 같은 Type의 Line일 경우 Join함 |
144 |
RunJoinRun(); |
145 |
|
146 |
// avoid interference |
147 |
SetConnectorAndSymbolRange(); |
148 |
// EndBreak Modeling |
149 |
RunEndBreakModeling(); |
150 |
// avoid interference |
151 |
SetConnectorAndSymbolRange(); |
152 |
// SpecBreak Modeling |
153 |
RunSpecBreakModeling(); |
154 |
//Line Number Modeling |
155 |
// Label만 draft |
156 |
RunLineNumberModeling(); |
157 |
// Note Modeling |
158 |
RunNoteModeling(); |
159 |
// Text Modeling |
160 |
RunTextModeling(); |
161 |
// Input LineNumber Attribute |
162 |
RunInputLineNumberAttribute(); |
163 |
// Input Symbol Attribute |
164 |
RunInputSymbolAttribute(); |
165 |
// Input SpecBreak Attribute |
166 |
RunInputSpecBreakAttribute(); |
167 |
// Input EndBreak Attribute |
168 |
RunInputEndBreakAttribute(); |
169 |
// Label Symbol Modeling |
170 |
RunLabelSymbolModeling(); |
171 |
|
172 |
// Correct Text |
173 |
// LabelPersist 정렬 로직 |
174 |
// 예) Valve Size label 등 |
175 |
RunCorrectAssociationText(); |
176 |
// ETC |
177 |
// Label을 Front로 옮김 |
178 |
RunETC(); |
179 |
// input bulk attribute |
180 |
RunBulkAttribute(); |
181 |
// import Auxiliary Graphics |
182 |
RunGraphicModeling(); |
183 |
// Update PipeRun Properties |
184 |
RunUpdatePipeRunProperties(); |
185 |
// log file 생성 |
186 |
document.CheckModelingResult(); |
187 |
} |
188 |
} |
189 |
catch (Exception ex) |
190 |
{ |
191 |
if (SplashScreenManager.Default != null && SplashScreenManager.Default.IsSplashFormVisible) |
192 |
{ |
193 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null); |
194 |
SplashScreenManager.CloseForm(false); |
195 |
Log.Write("\r\n"); |
196 |
} |
197 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
198 |
} |
199 |
finally |
200 |
{ |
201 |
radApp.Interactive = true; |
202 |
|
203 |
Project_DB.InsertDrawingInfoAndOPCInfo(document.PATH, drawingNumber, drawingName, document); |
204 |
//Project_DB.InsertLineNumberInfo(document.PATH, drawingNumber, drawingName, document); |
205 |
|
206 |
if (SplashScreenManager.Default != null && SplashScreenManager.Default.IsSplashFormVisible) |
207 |
{ |
208 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null); |
209 |
SplashScreenManager.CloseForm(false); |
210 |
Log.Write("\r\n"); |
211 |
} |
212 |
Thread.Sleep(1000); |
213 |
|
214 |
Log.Write("End Modeling"); |
215 |
radApp.ActiveWindow.Fit(); |
216 |
|
217 |
ReleaseCOMObjects(application); |
218 |
application = null; |
219 |
if (radApp.ActiveDocument != null) |
220 |
{ |
221 |
if (newDrawing != null) |
222 |
{ |
223 |
newDrawing.Save(); |
224 |
if (closeDocument) |
225 |
newDrawing.CloseDrawing(true); |
226 |
ReleaseCOMObjects(newDrawing); |
227 |
newDrawing = null; |
228 |
} |
229 |
else if (newDrawing == null) |
230 |
{ |
231 |
Log.Write("error document"); |
232 |
} |
233 |
} |
234 |
|
235 |
ReleaseCOMObjects(dataSource); |
236 |
dataSource = null; |
237 |
ReleaseCOMObjects(_placement); |
238 |
_placement = null; |
239 |
|
240 |
Thread.Sleep(1000); |
241 |
} |
242 |
} |
243 |
|
244 |
private void RunVendorPackageModeling() |
245 |
{ |
246 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.VendorPackages.Count); |
247 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "VendorPackages Modeling"); |
248 |
foreach (VendorPackage item in document.VendorPackages) |
249 |
{ |
250 |
try |
251 |
{ |
252 |
VendorPackageModeling(item); |
253 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
254 |
} |
255 |
catch (Exception ex) |
256 |
{ |
257 |
Log.Write("Error in RunVendorPackageModeling"); |
258 |
Log.Write("UID : " + item.UID); |
259 |
Log.Write(ex.Message); |
260 |
Log.Write(ex.StackTrace); |
261 |
} |
262 |
} |
263 |
} |
264 |
private void RunEquipmentModeling() |
265 |
{ |
266 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.Equipments.Count); |
267 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Equipments Modeling"); |
268 |
for (int i = 0; i < document.Equipments.Count; i++) |
269 |
{ |
270 |
Equipment item = document.Equipments[i]; |
271 |
try |
272 |
{ |
273 |
if (!string.IsNullOrEmpty(item.SPPID.RepresentationId)) |
274 |
continue; |
275 |
EquipmentModeling(item); |
276 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.Equipments.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count); |
277 |
if (!string.IsNullOrEmpty(item.SPPID.RepresentationId)) |
278 |
i = -1; |
279 |
} |
280 |
catch (Exception ex) |
281 |
{ |
282 |
Log.Write("Error in EquipmentModeling"); |
283 |
Log.Write("UID : " + item.UID); |
284 |
Log.Write(ex.Message); |
285 |
Log.Write(ex.StackTrace); |
286 |
} |
287 |
} |
288 |
} |
289 |
private void RunSymbolModeling() |
290 |
{ |
291 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count); |
292 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbol Modeling"); |
293 |
prioritySymbols = GetPrioritySymbol(); |
294 |
foreach (var item in prioritySymbols) |
295 |
{ |
296 |
try |
297 |
{ |
298 |
if (document.VentDrainSymbol.Contains(item) || !string.IsNullOrWhiteSpace(item.SPPID.RepresentationId)) |
299 |
continue; |
300 |
SymbolModelingBySymbol(item); |
301 |
} |
302 |
catch (Exception ex) |
303 |
{ |
304 |
Log.Write("Error in SymbolModelingByPriority"); |
305 |
Log.Write("UID : " + item.UID); |
306 |
Log.Write(ex.Message); |
307 |
Log.Write(ex.StackTrace); |
308 |
} |
309 |
} |
310 |
} |
311 |
private void RunLineModeling() |
312 |
{ |
313 |
List<Line> AllLine = document.LINES.ToList(); |
314 |
List<Line> stepLast_Line = document.LINES.FindAll(x => x.CONNECTORS.FindAll(y => y.ConnectedObject != null |
315 |
&& y.ConnectedObject.GetType() == typeof(Symbol)).Count == 2 |
316 |
&& !SPPIDUtil.IsBranchedLine(document, x)); |
317 |
List<Line> step1_Line = AllLine.FindAll(x => !stepLast_Line.Contains(x)); |
318 |
|
319 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, step1_Line.Count); |
320 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling - 1"); |
321 |
|
322 |
SetPriorityLine(step1_Line); |
323 |
while (step1_Line.Count > 0) |
324 |
{ |
325 |
try |
326 |
{ |
327 |
Line item = step1_Line[0]; |
328 |
if (!string.IsNullOrEmpty(item.SPPID.ModelItemId) || BranchLines.Contains(item) || document.VentDrainLine.Contains(item)) |
329 |
{ |
330 |
step1_Line.Remove(item); |
331 |
} |
332 |
else |
333 |
{ |
334 |
NewLineModeling(item); |
335 |
step1_Line.Remove(item); |
336 |
if (string.IsNullOrEmpty(item.SPPID.ModelItemId)) |
337 |
{ |
338 |
step1_Line.Add(item); |
339 |
} |
340 |
} |
341 |
if (!step1_Line.Contains(item)) |
342 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
343 |
} |
344 |
catch (Exception ex) |
345 |
{ |
346 |
Log.Write("Error in NewLineModeling"); |
347 |
Log.Write("UID : " + step1_Line[0].UID); |
348 |
Log.Write(ex.Message); |
349 |
Log.Write(ex.StackTrace); |
350 |
step1_Line.Remove(step1_Line[0]); |
351 |
} |
352 |
} |
353 |
|
354 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, BranchLines.Count); |
355 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling - 2"); |
356 |
int branchCount = BranchLines.Count; |
357 |
SortBranchLines(); |
358 |
while (BranchLines.Count > 0) |
359 |
{ |
360 |
try |
361 |
{ |
362 |
Line item = BranchLines[0]; |
363 |
if (!string.IsNullOrEmpty(item.SPPID.ModelItemId) || document.VentDrainLine.Contains(item)) |
364 |
{ |
365 |
BranchLines.Remove(item); |
366 |
} |
367 |
else |
368 |
{ |
369 |
NewLineModeling(item, true); |
370 |
BranchLines.Remove(item); |
371 |
if (string.IsNullOrEmpty(item.SPPID.ModelItemId)) |
372 |
{ |
373 |
BranchLines.Add(item); |
374 |
} |
375 |
} |
376 |
if (!BranchLines.Contains(item)) |
377 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
378 |
} |
379 |
catch (Exception ex) |
380 |
{ |
381 |
Log.Write("Error in NewLineModeling"); |
382 |
Log.Write("UID : " + BranchLines[0].UID); |
383 |
Log.Write(ex.Message); |
384 |
Log.Write(ex.StackTrace); |
385 |
BranchLines.Remove(BranchLines[0]); |
386 |
} |
387 |
} |
388 |
|
389 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, stepLast_Line.Count); |
390 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling - 3"); |
391 |
while (stepLast_Line.Count > 0) |
392 |
{ |
393 |
try |
394 |
{ |
395 |
Line item = stepLast_Line[0]; |
396 |
if (!string.IsNullOrEmpty(item.SPPID.ModelItemId) || BranchLines.Contains(item) || document.VentDrainLine.Contains(item)) |
397 |
{ |
398 |
stepLast_Line.Remove(item); |
399 |
} |
400 |
else |
401 |
{ |
402 |
NewLineModeling(item); |
403 |
stepLast_Line.Remove(item); |
404 |
if (string.IsNullOrEmpty(item.SPPID.ModelItemId)) |
405 |
{ |
406 |
stepLast_Line.Add(item); |
407 |
} |
408 |
} |
409 |
if (!stepLast_Line.Contains(item)) |
410 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
411 |
} |
412 |
catch (Exception ex) |
413 |
{ |
414 |
Log.Write("Error in NewLineModeling"); |
415 |
Log.Write("UID : " + stepLast_Line[0].UID); |
416 |
Log.Write(ex.Message); |
417 |
Log.Write(ex.StackTrace); |
418 |
stepLast_Line.Remove(stepLast_Line[0]); |
419 |
} |
420 |
} |
421 |
} |
422 |
private void RunVentDrainModeling() |
423 |
{ |
424 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.VentDrainLine.Count); |
425 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Vent Drain Modeling"); |
426 |
foreach (var item in document.VentDrainLine) |
427 |
{ |
428 |
try |
429 |
{ |
430 |
Connector connector = item.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol)); |
431 |
if (connector != null) |
432 |
{ |
433 |
SetCoordinate(); |
434 |
Symbol connSymbol = connector.ConnectedObject as Symbol; |
435 |
SymbolModeling(connSymbol, null); |
436 |
NewLineModeling(item, true); |
437 |
|
438 |
GridSetting grid = GridSetting.GetInstance(); |
439 |
int count = grid.DrainValveCellCount; |
440 |
double length = grid.Length; |
441 |
|
442 |
// 길이 확인 |
443 |
if (!string.IsNullOrEmpty(item.SPPID.ModelItemId)) |
444 |
{ |
445 |
LMConnector _LMConnector = GetLMConnectorOnlyOne(item.SPPID.ModelItemId); |
446 |
if (_LMConnector != null) |
447 |
{ |
448 |
double[] connectorRange = GetConnectorRange(_LMConnector); |
449 |
double connectorLength = double.NaN; |
450 |
if (item.SlopeType == SlopeType.HORIZONTAL) |
451 |
connectorLength = connectorRange[2] - connectorRange[0]; |
452 |
else if (item.SlopeType == SlopeType.VERTICAL) |
453 |
connectorLength = connectorRange[3] - connectorRange[1]; |
454 |
|
455 |
if (!double.IsNaN(connectorLength) && connectorLength != count * length) |
456 |
{ |
457 |
double move = count * length - connectorLength; |
458 |
List<Symbol> group = new List<Symbol>(); |
459 |
SPPIDUtil.FindConnectedSymbolGroup(document, connSymbol, group); |
460 |
foreach (var symbol in group) |
461 |
{ |
462 |
int connSymbolIndex = item.CONNECTORS.IndexOf(item.CONNECTORS.Find(x => x.ConnectedObject == connSymbol)); |
463 |
if (item.SlopeType == SlopeType.HORIZONTAL) |
464 |
{ |
465 |
if (connSymbolIndex == 0) |
466 |
{ |
467 |
if (item.SPPID.START_X > item.SPPID.END_X) |
468 |
symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X + move; |
469 |
else |
470 |
symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X - move; |
471 |
} |
472 |
else |
473 |
{ |
474 |
if (item.SPPID.START_X < item.SPPID.END_X) |
475 |
symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X + move; |
476 |
else |
477 |
symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X - move; |
478 |
} |
479 |
} |
480 |
else if (item.SlopeType == SlopeType.VERTICAL) |
481 |
{ |
482 |
if (connSymbolIndex == 0) |
483 |
{ |
484 |
if (item.SPPID.START_Y > item.SPPID.END_Y) |
485 |
symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y + move; |
486 |
else |
487 |
symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y - move; |
488 |
} |
489 |
else |
490 |
{ |
491 |
if (item.SPPID.START_Y < item.SPPID.END_Y) |
492 |
symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y + move; |
493 |
else |
494 |
symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y - move; |
495 |
} |
496 |
} |
497 |
} |
498 |
|
499 |
// 제거 |
500 |
RemoveSymbol(connSymbol); |
501 |
RemoveLine(item); |
502 |
|
503 |
// 재생성 |
504 |
SymbolModelingBySymbol(connSymbol); |
505 |
NewLineModeling(item, true); |
506 |
} |
507 |
} |
508 |
|
509 |
ReleaseCOMObjects(_LMConnector); |
510 |
_LMConnector = null; |
511 |
} |
512 |
} |
513 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
514 |
} |
515 |
catch (Exception ex) |
516 |
{ |
517 |
Log.Write("Error in NewLineModeling"); |
518 |
Log.Write("UID : " + item.UID); |
519 |
Log.Write(ex.Message); |
520 |
Log.Write(ex.StackTrace); |
521 |
} |
522 |
|
523 |
void SetCoordinate() |
524 |
{ |
525 |
Connector branchConnector = item.CONNECTORS.Find(loop => loop.ConnectedObject != null && loop.ConnectedObject.GetType() == typeof(Line)); |
526 |
if (branchConnector != null) |
527 |
{ |
528 |
Line connLine = branchConnector.ConnectedObject as Line; |
529 |
double x = 0; |
530 |
double y = 0; |
531 |
GetTargetLineConnectorPoint(branchConnector, item, ref x, ref y); |
532 |
LMConnector targetConnector = FindTargetLMConnectorForBranch(item, connLine, ref x, ref y); |
533 |
if (targetConnector != null) |
534 |
{ |
535 |
List<Symbol> group = new List<Symbol>(); |
536 |
SPPIDUtil.FindConnectedSymbolGroup(document, item.CONNECTORS.Find(loop => loop != branchConnector).ConnectedObject as Symbol, group); |
537 |
if (item.SlopeType == SlopeType.HORIZONTAL) |
538 |
{ |
539 |
item.SPPID.START_Y = y; |
540 |
item.SPPID.END_Y = y; |
541 |
foreach (var symbol in group) |
542 |
{ |
543 |
symbol.SPPID.ORIGINAL_Y = y; |
544 |
symbol.SPPID.SPPID_Y = y; |
545 |
} |
546 |
} |
547 |
else if (item.SlopeType == SlopeType.VERTICAL) |
548 |
{ |
549 |
item.SPPID.START_X = x; |
550 |
item.SPPID.END_X = x; |
551 |
foreach (var symbol in group) |
552 |
{ |
553 |
symbol.SPPID.ORIGINAL_X = x; |
554 |
symbol.SPPID.SPPID_X = x; |
555 |
} |
556 |
} |
557 |
} |
558 |
ReleaseCOMObjects(targetConnector); |
559 |
targetConnector = null; |
560 |
} |
561 |
} |
562 |
} |
563 |
} |
564 |
private void RunClearNominalDiameter() |
565 |
{ |
566 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count + document.LINES.Count); |
567 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Clear Attribute"); |
568 |
return; |
569 |
|
570 |
List<string> endClearModelItemID = new List<string>(); |
571 |
for (int i = 0; i < document.LINES.Count; i++) |
572 |
{ |
573 |
Line item = document.LINES[i]; |
574 |
string modelItemID = item.SPPID.ModelItemId; |
575 |
if (!string.IsNullOrEmpty(modelItemID)) |
576 |
{ |
577 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemID); |
578 |
if (modelItem != null) |
579 |
{ |
580 |
LMAAttribute attribute = modelItem.Attributes["NominalDiameter"]; |
581 |
if (attribute != null) |
582 |
attribute.set_Value(DBNull.Value); |
583 |
|
584 |
modelItem.Commit(); |
585 |
ReleaseCOMObjects(modelItem); |
586 |
modelItem = null; |
587 |
} |
588 |
} |
589 |
if (!endClearModelItemID.Contains(modelItemID)) |
590 |
endClearModelItemID.Add(modelItemID); |
591 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
592 |
} |
593 |
for (int i = 0; i < document.SYMBOLS.Count; i++) |
594 |
{ |
595 |
Symbol item = document.SYMBOLS[i]; |
596 |
string repID = item.SPPID.RepresentationId; |
597 |
string modelItemID = item.SPPID.ModelItemID; |
598 |
if (!string.IsNullOrEmpty(modelItemID)) |
599 |
{ |
600 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemID); |
601 |
if (modelItem != null) |
602 |
{ |
603 |
LMAAttribute attribute = modelItem.Attributes["NominalDiameter"]; |
604 |
if (attribute != null) |
605 |
attribute.set_Value(DBNull.Value); |
606 |
int index = 1; |
607 |
while (true) |
608 |
{ |
609 |
attribute = modelItem.Attributes[string.Format("PipingPoint{0}.NominalDiameter", index)]; |
610 |
if (attribute != null) |
611 |
attribute.set_Value(DBNull.Value); |
612 |
else |
613 |
break; |
614 |
index++; |
615 |
} |
616 |
modelItem.Commit(); |
617 |
ReleaseCOMObjects(modelItem); |
618 |
modelItem = null; |
619 |
} |
620 |
} |
621 |
if (!string.IsNullOrEmpty(repID)) |
622 |
{ |
623 |
LMSymbol symbol = dataSource.GetSymbol(repID); |
624 |
if (symbol != null) |
625 |
{ |
626 |
foreach (LMConnector connector in symbol.Connect1Connectors) |
627 |
{ |
628 |
if (connector.get_ItemStatus() == "Active" && !endClearModelItemID.Contains(connector.ModelItemID)) |
629 |
{ |
630 |
endClearModelItemID.Add(connector.ModelItemID); |
631 |
LMModelItem modelItem = connector.ModelItemObject; |
632 |
if (modelItem != null) |
633 |
{ |
634 |
LMAAttribute attribute = modelItem.Attributes["NominalDiameter"]; |
635 |
if (attribute != null) |
636 |
attribute.set_Value(DBNull.Value); |
637 |
|
638 |
modelItem.Commit(); |
639 |
ReleaseCOMObjects(modelItem); |
640 |
modelItem = null; |
641 |
} |
642 |
} |
643 |
} |
644 |
foreach (LMConnector connector in symbol.Connect2Connectors) |
645 |
{ |
646 |
if (connector.get_ItemStatus() == "Active" && !endClearModelItemID.Contains(connector.ModelItemID)) |
647 |
{ |
648 |
endClearModelItemID.Add(connector.ModelItemID); |
649 |
LMModelItem modelItem = connector.ModelItemObject; |
650 |
if (modelItem != null) |
651 |
{ |
652 |
LMAAttribute attribute = modelItem.Attributes["NominalDiameter"]; |
653 |
if (attribute != null) |
654 |
attribute.set_Value(DBNull.Value); |
655 |
|
656 |
modelItem.Commit(); |
657 |
ReleaseCOMObjects(modelItem); |
658 |
modelItem = null; |
659 |
} |
660 |
} |
661 |
} |
662 |
} |
663 |
ReleaseCOMObjects(symbol); |
664 |
symbol = null; |
665 |
} |
666 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
667 |
} |
668 |
} |
669 |
private void RunClearValueInconsistancy() |
670 |
{ |
671 |
int count = 1; |
672 |
bool loop = true; |
673 |
while (loop) |
674 |
{ |
675 |
loop = false; |
676 |
LMAFilter filter = new LMAFilter(); |
677 |
LMACriterion criterion = new LMACriterion(); |
678 |
filter.ItemType = "Relationship"; |
679 |
criterion.SourceAttributeName = "SP_DRAWINGID"; |
680 |
criterion.Operator = "="; |
681 |
criterion.set_ValueAttribute(drawingID); |
682 |
filter.get_Criteria().Add(criterion); |
683 |
|
684 |
LMRelationships relationships = new LMRelationships(); |
685 |
relationships.Collect(dataSource, Filter: filter); |
686 |
|
687 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, relationships.Count); |
688 |
if (count > 1) |
689 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStepMinus, null); |
690 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Clear Inconsistent Property Value - " + count); |
691 |
foreach (LMRelationship relationship in relationships) |
692 |
{ |
693 |
foreach (LMInconsistency inconsistency in relationship.Inconsistencies) |
694 |
{ |
695 |
if (inconsistency.get_InconsistencyTypeIndex() == 1) |
696 |
{ |
697 |
LMModelItem modelItem1 = relationship.Item1RepresentationObject == null ? null : relationship.Item1RepresentationObject.ModelItemObject; |
698 |
LMModelItem modelItem2 = relationship.Item2RepresentationObject == null ? null : relationship.Item2RepresentationObject.ModelItemObject; |
699 |
string[] array = inconsistency.get_Name().ToString().Split(new char[] { '=' }); |
700 |
if (modelItem1 != null) |
701 |
{ |
702 |
string attrName = array[0]; |
703 |
if (attrName.Contains("PipingPoint")) |
704 |
{ |
705 |
string originalAttr = attrName.Split(new char[] { '.' })[1]; |
706 |
int index = Convert.ToInt32(relationship.get_Item1Location()); |
707 |
LMAAttribute attribute1 = modelItem1.Attributes["PipingPoint" + index + "." + originalAttr]; |
708 |
if (attribute1 != null && !DBNull.Value.Equals(attribute1.get_Value())) |
709 |
{ |
710 |
loop = true; |
711 |
attribute1.set_Value(DBNull.Value); |
712 |
} |
713 |
attribute1 = null; |
714 |
} |
715 |
else |
716 |
{ |
717 |
LMAAttribute attribute1 = modelItem1.Attributes[attrName]; |
718 |
if (attribute1 != null && !DBNull.Value.Equals(attribute1.get_Value())) |
719 |
{ |
720 |
loop = true; |
721 |
attribute1.set_Value(DBNull.Value); |
722 |
} |
723 |
attribute1 = null; |
724 |
} |
725 |
modelItem1.Commit(); |
726 |
} |
727 |
if (modelItem2 != null) |
728 |
{ |
729 |
string attrName = array[1]; |
730 |
if (attrName.Contains("PipingPoint")) |
731 |
{ |
732 |
string originalAttr = attrName.Split(new char[] { '.' })[1]; |
733 |
int index = Convert.ToInt32(relationship.get_Item2Location()); |
734 |
LMAAttribute attribute2 = modelItem2.Attributes["PipingPoint" + index + "." + originalAttr]; |
735 |
if (attribute2 != null && !DBNull.Value.Equals(attribute2.get_Value())) |
736 |
{ |
737 |
attribute2.set_Value(DBNull.Value); |
738 |
loop = true; |
739 |
} |
740 |
attribute2 = null; |
741 |
} |
742 |
else |
743 |
{ |
744 |
LMAAttribute attribute2 = modelItem2.Attributes[attrName]; |
745 |
if (attribute2 != null && !DBNull.Value.Equals(attribute2.get_Value())) |
746 |
{ |
747 |
attribute2.set_Value(DBNull.Value); |
748 |
loop = true; |
749 |
} |
750 |
attribute2 = null; |
751 |
} |
752 |
modelItem2.Commit(); |
753 |
} |
754 |
ReleaseCOMObjects(modelItem1); |
755 |
modelItem1 = null; |
756 |
ReleaseCOMObjects(modelItem2); |
757 |
modelItem2 = null; |
758 |
inconsistency.Commit(); |
759 |
} |
760 |
ReleaseCOMObjects(inconsistency); |
761 |
} |
762 |
relationship.Commit(); |
763 |
ReleaseCOMObjects(relationship); |
764 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
765 |
} |
766 |
ReleaseCOMObjects(filter); |
767 |
filter = null; |
768 |
ReleaseCOMObjects(criterion); |
769 |
criterion = null; |
770 |
ReleaseCOMObjects(relationships); |
771 |
relationships = null; |
772 |
count++; |
773 |
} |
774 |
} |
775 |
private void RunEndBreakModeling() |
776 |
{ |
777 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.EndBreaks.Count); |
778 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling"); |
779 |
foreach (var item in document.EndBreaks) |
780 |
try |
781 |
{ |
782 |
EndBreakModeling(item); |
783 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
784 |
} |
785 |
catch (Exception ex) |
786 |
{ |
787 |
Log.Write("Error in EndBreakModeling"); |
788 |
Log.Write("UID : " + item.UID); |
789 |
Log.Write(ex.Message); |
790 |
Log.Write(ex.StackTrace); |
791 |
} |
792 |
} |
793 |
private void RunSpecBreakModeling() |
794 |
{ |
795 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SpecBreaks.Count); |
796 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "SpecBreaks Modeling"); |
797 |
foreach (var item in document.SpecBreaks) |
798 |
try |
799 |
{ |
800 |
SpecBreakModeling(item); |
801 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
802 |
} |
803 |
catch (Exception ex) |
804 |
{ |
805 |
Log.Write("Error in SpecBreakModeling"); |
806 |
Log.Write("UID : " + item.UID); |
807 |
Log.Write(ex.Message); |
808 |
Log.Write(ex.StackTrace); |
809 |
} |
810 |
} |
811 |
private void RunJoinRunForSameConnector() |
812 |
{ |
813 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count); |
814 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "PipeRun Join - 1"); |
815 |
foreach (var line in document.LINES) |
816 |
{ |
817 |
Dictionary<LMConnector, List<double[]>> vertices = GetPipeRunVertices(line.SPPID.ModelItemId, false); |
818 |
List<List<double[]>> result = new List<List<double[]>>(); |
819 |
foreach (var item in vertices) |
820 |
{ |
821 |
ReleaseCOMObjects(item.Key); |
822 |
result.Add(item.Value); |
823 |
} |
824 |
line.SPPID.Vertices = result; |
825 |
vertices = null; |
826 |
} |
827 |
|
828 |
foreach (var line in document.LINES) |
829 |
{ |
830 |
foreach (var connector in line.CONNECTORS) |
831 |
{ |
832 |
if (connector.ConnectedObject != null && |
833 |
connector.ConnectedObject.GetType() == typeof(Line) && |
834 |
!SPPIDUtil.IsBranchLine(line, connector.ConnectedObject as Line)) |
835 |
{ |
836 |
Line connLine = connector.ConnectedObject as Line; |
837 |
if (line.SPPID.ModelItemId != connLine.SPPID.ModelItemId && |
838 |
!string.IsNullOrEmpty(line.SPPID.ModelItemId) && |
839 |
!string.IsNullOrEmpty(connLine.SPPID.ModelItemId) && |
840 |
!SPPIDUtil.IsSegment(document, line, connLine)) |
841 |
{ |
842 |
string survivorId = string.Empty; |
843 |
JoinRun(connLine.SPPID.ModelItemId, line.SPPID.ModelItemId, ref survivorId); |
844 |
} |
845 |
|
846 |
} |
847 |
} |
848 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
849 |
} |
850 |
|
851 |
foreach (var line in document.LINES) |
852 |
line.SPPID.Representations = GetRepresentations(line.SPPID.ModelItemId); |
853 |
} |
854 |
private void RunJoinRun() |
855 |
{ |
856 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count); |
857 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "PipeRun Join - 2"); |
858 |
List<string> endModelID = new List<string>(); |
859 |
foreach (var line in document.LINES) |
860 |
{ |
861 |
if (!endModelID.Contains(line.SPPID.ModelItemId)) |
862 |
{ |
863 |
while (!endModelID.Contains(line.SPPID.ModelItemId)) |
864 |
{ |
865 |
string survivorId = string.Empty; |
866 |
JoinRunBySameType(line.SPPID.ModelItemId, ref survivorId); |
867 |
if (string.IsNullOrEmpty(survivorId)) |
868 |
{ |
869 |
endModelID.Add(line.SPPID.ModelItemId); |
870 |
} |
871 |
} |
872 |
} |
873 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
874 |
} |
875 |
} |
876 |
private void RunLineNumberModeling() |
877 |
{ |
878 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINENUMBERS.Count); |
879 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Number Modeling"); |
880 |
foreach (var item in document.LINENUMBERS) |
881 |
{ |
882 |
LMLabelPersist label = dataSource.GetLabelPersist(item.SPPID.RepresentationId); |
883 |
if (label == null || (label != null && label.get_ItemStatus() != "Active")) |
884 |
{ |
885 |
ReleaseCOMObjects(label); |
886 |
item.SPPID.RepresentationId = null; |
887 |
LineNumberModeling(item); |
888 |
} |
889 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
890 |
} |
891 |
} |
892 |
private void RunNoteModeling() |
893 |
{ |
894 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count); |
895 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling"); |
896 |
List<Note> correctList = new List<Note>(); |
897 |
foreach (var item in document.NOTES) |
898 |
try |
899 |
{ |
900 |
NoteModeling(item, correctList); |
901 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
902 |
} |
903 |
catch (Exception ex) |
904 |
{ |
905 |
Log.Write("Error in NoteModeling"); |
906 |
Log.Write("UID : " + item.UID); |
907 |
Log.Write(ex.Message); |
908 |
Log.Write(ex.StackTrace); |
909 |
} |
910 |
|
911 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, correctList.Count); |
912 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Correct Note"); |
913 |
SortNote(correctList); |
914 |
List<Note> endList = new List<Note>(); |
915 |
if (correctList.Count > 0) |
916 |
endList.Add(correctList[0]); |
917 |
foreach (var item in correctList) |
918 |
try |
919 |
{ |
920 |
if (!endList.Contains(item)) |
921 |
NoteCorrectModeling(item, endList); |
922 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
923 |
} |
924 |
catch (Exception ex) |
925 |
{ |
926 |
Log.Write("Error in NoteModeling"); |
927 |
Log.Write("UID : " + item.UID); |
928 |
Log.Write(ex.Message); |
929 |
Log.Write(ex.StackTrace); |
930 |
} |
931 |
} |
932 |
private void RunTextModeling() |
933 |
{ |
934 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.TEXTINFOS.Count); |
935 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling"); |
936 |
SortText(document.TEXTINFOS); |
937 |
foreach (var item in document.TEXTINFOS) |
938 |
try |
939 |
{ |
940 |
if (item.ASSOCIATION) |
941 |
AssociationTextModeling(item); |
942 |
else |
943 |
NormalTextModeling(item); |
944 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
945 |
} |
946 |
catch (Exception ex) |
947 |
{ |
948 |
Log.Write("Error in TextModeling"); |
949 |
Log.Write("UID : " + item.UID); |
950 |
Log.Write(ex.Message); |
951 |
Log.Write(ex.StackTrace); |
952 |
} |
953 |
} |
954 |
private void RunInputLineNumberAttribute() |
955 |
{ |
956 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINENUMBERS.Count); |
957 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set LineNumbers Attribute"); |
958 |
List<string> endLine = new List<string>(); |
959 |
foreach (var item in document.LINENUMBERS) |
960 |
try |
961 |
{ |
962 |
InputLineNumberAttribute(item, endLine); |
963 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
964 |
} |
965 |
catch (Exception ex) |
966 |
{ |
967 |
Log.Write("Error in InputLineNumberAttribute"); |
968 |
Log.Write("UID : " + item.UID); |
969 |
Log.Write(ex.Message); |
970 |
Log.Write(ex.StackTrace); |
971 |
} |
972 |
} |
973 |
private void RunInputSymbolAttribute() |
974 |
{ |
975 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count + document.Equipments.Count + document.LINES.Count); |
976 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute"); |
977 |
foreach (var item in document.SYMBOLS) |
978 |
try |
979 |
{ |
980 |
InputSymbolAttribute(item, item.ATTRIBUTES); |
981 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
982 |
} |
983 |
catch (Exception ex) |
984 |
{ |
985 |
Log.Write("Error in InputSymbolAttribute"); |
986 |
Log.Write("UID : " + item.UID); |
987 |
Log.Write(ex.Message); |
988 |
Log.Write(ex.StackTrace); |
989 |
} |
990 |
|
991 |
foreach (var item in document.Equipments) |
992 |
try |
993 |
{ |
994 |
InputSymbolAttribute(item, item.ATTRIBUTES); |
995 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
996 |
} |
997 |
catch (Exception ex) |
998 |
{ |
999 |
Log.Write("Error in InputSymbolAttribute"); |
1000 |
Log.Write("UID : " + item.UID); |
1001 |
Log.Write(ex.Message); |
1002 |
Log.Write(ex.StackTrace); |
1003 |
} |
1004 |
foreach (var item in document.LINES) |
1005 |
try |
1006 |
{ |
1007 |
InputSymbolAttribute(item, item.ATTRIBUTES); |
1008 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
1009 |
} |
1010 |
catch (Exception ex) |
1011 |
{ |
1012 |
Log.Write("Error in InputSymbolAttribute"); |
1013 |
Log.Write("UID : " + item.UID); |
1014 |
Log.Write(ex.Message); |
1015 |
Log.Write(ex.StackTrace); |
1016 |
} |
1017 |
} |
1018 |
private void RunInputSpecBreakAttribute() |
1019 |
{ |
1020 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SpecBreaks.Count); |
1021 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set SpecBreak Attribute"); |
1022 |
foreach (var item in document.SpecBreaks) |
1023 |
try |
1024 |
{ |
1025 |
InputSpecBreakAttribute(item); |
1026 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
1027 |
} |
1028 |
catch (Exception ex) |
1029 |
{ |
1030 |
Log.Write("Error in InputSpecBreakAttribute"); |
1031 |
Log.Write("UID : " + item.UID); |
1032 |
Log.Write(ex.Message); |
1033 |
Log.Write(ex.StackTrace); |
1034 |
} |
1035 |
} |
1036 |
private void RunInputEndBreakAttribute() |
1037 |
{ |
1038 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.EndBreaks.Count); |
1039 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set EndBreak Attribute"); |
1040 |
foreach (var item in document.EndBreaks) |
1041 |
try |
1042 |
{ |
1043 |
InputEndBreakAttribute(item); |
1044 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
1045 |
} |
1046 |
catch (Exception ex) |
1047 |
{ |
1048 |
Log.Write("Error in RunInputEndBreakAttribute"); |
1049 |
Log.Write("UID : " + item.UID); |
1050 |
Log.Write(ex.Message); |
1051 |
Log.Write(ex.StackTrace); |
1052 |
} |
1053 |
} |
1054 |
private void RunLabelSymbolModeling() |
1055 |
{ |
1056 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count); |
1057 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Labels Modeling"); |
1058 |
foreach (var item in document.SYMBOLS) |
1059 |
try |
1060 |
{ |
1061 |
LabelSymbolModeling(item); |
1062 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
1063 |
} |
1064 |
catch (Exception ex) |
1065 |
{ |
1066 |
Log.Write("Error in LabelSymbolModeling"); |
1067 |
Log.Write("UID : " + item.UID); |
1068 |
Log.Write(ex.Message); |
1069 |
Log.Write(ex.StackTrace); |
1070 |
} |
1071 |
|
1072 |
} |
1073 |
private void RunCorrectAssociationText() |
1074 |
{ |
1075 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.TEXTINFOS.Count + document.LINENUMBERS.Count); |
1076 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Correct Labels"); |
1077 |
List<Text> endTexts = new List<Text>(); |
1078 |
foreach (var item in document.TEXTINFOS) |
1079 |
{ |
1080 |
try |
1081 |
{ |
1082 |
if (item.ASSOCIATION && !endTexts.Contains(item)) |
1083 |
AssociationTextCorrectModeling(item, endTexts); |
1084 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
1085 |
} |
1086 |
catch (Exception ex) |
1087 |
{ |
1088 |
Log.Write("Error in RunCorrectAssociationText"); |
1089 |
Log.Write("UID : " + item.UID); |
1090 |
Log.Write(ex.Message); |
1091 |
Log.Write(ex.StackTrace); |
1092 |
} |
1093 |
|
1094 |
} |
1095 |
|
1096 |
foreach (var item in document.LINENUMBERS) |
1097 |
{ |
1098 |
try |
1099 |
{ |
1100 |
LineNumberCorrectModeling(item); |
1101 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
1102 |
} |
1103 |
catch (Exception ex) |
1104 |
{ |
1105 |
Log.Write("Error in RunCorrectAssociationText"); |
1106 |
Log.Write("UID : " + item.UID); |
1107 |
Log.Write(ex.Message); |
1108 |
Log.Write(ex.StackTrace); |
1109 |
} |
1110 |
} |
1111 |
} |
1112 |
private void RunETC() |
1113 |
{ |
1114 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, FlowMarkRepIds.Count); |
1115 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "ETC"); |
1116 |
foreach (var item in FlowMarkRepIds) |
1117 |
{ |
1118 |
LMLabelPersist label = dataSource.GetLabelPersist(item); |
1119 |
if (label != null) |
1120 |
{ |
1121 |
label.get_GraphicOID(); |
1122 |
DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[label.get_GraphicOID().ToString()] as DependencyObject; |
1123 |
if (dependency != null) |
1124 |
dependency.BringToFront(); |
1125 |
} |
1126 |
ReleaseCOMObjects(label); |
1127 |
label = null; |
1128 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
1129 |
} |
1130 |
} |
1131 |
private void RunBulkAttribute() |
1132 |
{ |
1133 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, 2); |
1134 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Bulk Attribute"); |
1135 |
|
1136 |
List<SPPIDModel.BulkAttribute> select = _ETCSetting.BulkAttributes.FindAll(x => x.RuleName.Equals(document.BulkAttributeName)); |
1137 |
if (select.Count > 0) |
1138 |
SPPIDUtil.BulkAttribute(dataSource, select, BulkAttributeItemType.PipeRun); |
1139 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
1140 |
if (select.Count > 0) |
1141 |
SPPIDUtil.BulkAttribute(dataSource, select, BulkAttributeItemType.Symbol); |
1142 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
1143 |
} |
1144 |
private void RunGraphicModeling() |
1145 |
{ |
1146 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.Graphics.Count); |
1147 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Graphic Modeling"); |
1148 |
foreach (var item in document.Graphics) |
1149 |
{ |
1150 |
try |
1151 |
{ |
1152 |
GraphicModeling(item); |
1153 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
1154 |
} |
1155 |
catch (Exception ex) |
1156 |
{ |
1157 |
Log.Write("Error in GrahicModeling"); |
1158 |
Log.Write("UID : " + item.UID); |
1159 |
Log.Write(ex.Message); |
1160 |
Log.Write(ex.StackTrace); |
1161 |
} |
1162 |
} |
1163 |
} |
1164 |
private void RunUpdatePipeRunProperties() |
1165 |
{ |
1166 |
DataTable dt = Project_DB.SelectPipeRunPropSetting(); |
1167 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, dt == null ? 0 : dt.Rows.Count); |
1168 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Update PipeRun Properties"); |
1169 |
|
1170 |
if (dt == null) return; |
1171 |
foreach (DataRow dr in dt.Rows) |
1172 |
{ |
1173 |
Model.SPPID_PipeRunPropSetting setting = new SPPID_PipeRunPropSetting(dr); |
1174 |
if (setting.Cond1_DataType.StartsWith("C") || setting.Cond1_Value.Contains(",") && setting.Cond2_DataType.StartsWith("C") || setting.Cond2_Value.Contains(",")) |
1175 |
{ |
1176 |
string[] value1_Arr = setting.Cond1_Value.Split(','); |
1177 |
string[] value2_Arr = setting.Cond2_Value.Split(','); |
1178 |
|
1179 |
for (int i = 0; i < value1_Arr.Length; i++) |
1180 |
{ |
1181 |
for (int j = 0; j < value2_Arr.Length; j++) |
1182 |
{ |
1183 |
setting.Cond1_Value = value1_Arr[i].Trim(); |
1184 |
setting.Cond2_Value = value2_Arr[j].Trim(); |
1185 |
SPPIDUtil.UpdatePipeRunProperty(dataSource, setting); |
1186 |
} |
1187 |
} |
1188 |
} |
1189 |
else if (setting.Cond1_DataType.StartsWith("C") || setting.Cond1_Value.Contains(",")) |
1190 |
{ |
1191 |
string[] value1_Arr = setting.Cond1_Value.Split(','); |
1192 |
|
1193 |
for (int i = 0; i < value1_Arr.Length; i++) |
1194 |
{ |
1195 |
setting.Cond1_Value = value1_Arr[i].Trim(); |
1196 |
SPPIDUtil.UpdatePipeRunProperty(dataSource, setting); |
1197 |
} |
1198 |
} |
1199 |
else if (setting.Cond2_DataType.StartsWith("C") || setting.Cond2_Value.Contains(",")) |
1200 |
{ |
1201 |
string[] value2_Arr = setting.Cond2_Value.Split(','); |
1202 |
|
1203 |
for (int i = 0; i < value2_Arr.Length; i++) |
1204 |
{ |
1205 |
setting.Cond2_Value = value2_Arr[i].Trim(); |
1206 |
SPPIDUtil.UpdatePipeRunProperty(dataSource, setting); |
1207 |
} |
1208 |
} |
1209 |
else |
1210 |
{ |
1211 |
SPPIDUtil.UpdatePipeRunProperty(dataSource, setting); |
1212 |
} |
1213 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null); |
1214 |
} |
1215 |
} |
1216 |
/// <summary> |
1217 |
/// 도면 생성 메서드 |
1218 |
/// </summary> |
1219 |
private bool CreateDocument(ref string drawingNumber, ref string drawingName) |
1220 |
{ |
1221 |
Log.Write("------------------ Start create document ------------------"); |
1222 |
GetDrawingNameAndNumber(ref drawingName, ref drawingNumber); |
1223 |
Log.Write("Drawing name : " + drawingName); |
1224 |
Log.Write("Drawing number : " + drawingNumber); |
1225 |
Thread.Sleep(1000); |
1226 |
try |
1227 |
{ |
1228 |
newDrawing = application.Drawings.Add(document.Unit, document.Template, drawingNumber, drawingName); |
1229 |
} |
1230 |
catch (Exception ex) |
1231 |
{ |
1232 |
if (ex.Message == "Invalid procedure call or argument") |
1233 |
{ |
1234 |
Exception newEx = new Exception(string.Format("Invalid Unit [0]", document.Unit), ex.InnerException); |
1235 |
throw newEx; |
1236 |
} |
1237 |
else |
1238 |
{ |
1239 |
throw ex; |
1240 |
} |
1241 |
} |
1242 |
|
1243 |
if (newDrawing != null) |
1244 |
{ |
1245 |
document.SPPID_DrawingNumber = drawingNumber; |
1246 |
document.SPPID_DrawingName = drawingName; |
1247 |
Thread.Sleep(1000); |
1248 |
radApp.ActiveWindow.Fit(); |
1249 |
Thread.Sleep(1000); |
1250 |
radApp.ActiveWindow.Zoom = 2000; |
1251 |
Thread.Sleep(2000); |
1252 |
|
1253 |
//current LMDrawing 가져오기 |
1254 |
LMAFilter filter = new LMAFilter(); |
1255 |
LMACriterion criterion = new LMACriterion(); |
1256 |
filter.ItemType = "Drawing"; |
1257 |
criterion.SourceAttributeName = "Name"; |
1258 |
criterion.Operator = "="; |
1259 |
criterion.set_ValueAttribute(drawingName); |
1260 |
filter.get_Criteria().Add(criterion); |
1261 |
|
1262 |
LMDrawings drawings = new LMDrawings(); |
1263 |
drawings.Collect(dataSource, Filter: filter); |
1264 |
|
1265 |
// Input Drawing Attribute |
1266 |
LMDrawing drawing = ((dynamic)drawings).Nth(1); |
1267 |
if (drawing != null) |
1268 |
{ |
1269 |
using (DataTable drawingAttributeDT = Project_DB.SelectDrawingProjectAttribute()) |
1270 |
{ |
1271 |
foreach (DataRow row in drawingAttributeDT.Rows) |
1272 |
{ |
1273 |
string mappingName = DBNull.Value.Equals(row["SPPID_ATTRIBUTE"]) ? string.Empty : row["SPPID_ATTRIBUTE"].ToString(); |
1274 |
if (!string.IsNullOrEmpty(mappingName)) |
1275 |
{ |
1276 |
string uid = row["UID"].ToString(); |
1277 |
string name = row["NAME"].ToString(); |
1278 |
Text text = document.TEXTINFOS.Find(x => x.AREA == uid); |
1279 |
if (text != null) |
1280 |
{ |
1281 |
string value = text.VALUE; |
1282 |
LMAAttribute attribute = drawing.Attributes[mappingName]; |
1283 |
if (attribute != null) |
1284 |
attribute.set_Value(value); |
1285 |
ReleaseCOMObjects(attribute); |
1286 |
document.TEXTINFOS.Remove(text); |
1287 |
} |
1288 |
} |
1289 |
} |
1290 |
|
1291 |
drawingAttributeDT.Dispose(); |
1292 |
} |
1293 |
|
1294 |
ReleaseCOMObjects(drawing); |
1295 |
} |
1296 |
|
1297 |
drawingID = ((dynamic)drawings).Nth(1).Id; |
1298 |
ReleaseCOMObjects(filter); |
1299 |
ReleaseCOMObjects(criterion); |
1300 |
ReleaseCOMObjects(drawings); |
1301 |
filter = null; |
1302 |
criterion = null; |
1303 |
drawings = null; |
1304 |
} |
1305 |
else |
1306 |
Log.Write("Fail Create Drawing"); |
1307 |
|
1308 |
if (newDrawing != null) |
1309 |
{ |
1310 |
SetBorderFile(); |
1311 |
return true; |
1312 |
} |
1313 |
else |
1314 |
return false; |
1315 |
} |
1316 |
|
1317 |
private void SetBorderFile() |
1318 |
{ |
1319 |
ETCSetting setting = ETCSetting.GetInstance(); |
1320 |
|
1321 |
if (!string.IsNullOrEmpty(setting.BorderFilePath) && System.IO.File.Exists(setting.BorderFilePath)) |
1322 |
{ |
1323 |
foreach (Ingr.RAD2D.SmartFrame2d smartFrame in radApp.ActiveDocument.ActiveSheet.SmartFrames2d) |
1324 |
{ |
1325 |
if (!string.IsNullOrEmpty(smartFrame.LinkMoniker) && smartFrame.LinkMoniker != setting.BorderFilePath) |
1326 |
{ |
1327 |
smartFrame.ChangeSource(Ingr.RAD2D.OLEInsertionTypeConstant.igOLELinked, setting.BorderFilePath, true); |
1328 |
smartFrame.Update(); |
1329 |
} |
1330 |
|
1331 |
} |
1332 |
} |
1333 |
} |
1334 |
|
1335 |
/// <summary> |
1336 |
/// DrawingName, DrawingNumber를 확인하여 중복이 있으면 _1을 붙이고 +1씩 한다. |
1337 |
/// </summary> |
1338 |
/// <param name="drawingName"></param> |
1339 |
/// <param name="drawingNumber"></param> |
1340 |
private void GetDrawingNameAndNumber(ref string drawingName, ref string drawingNumber) |
1341 |
{ |
1342 |
LMDrawings drawings = new LMDrawings(); |
1343 |
drawings.Collect(dataSource); |
1344 |
|
1345 |
List<string> drawingNameList = new List<string>(); |
1346 |
List<string> drawingNumberList = new List<string>(); |
1347 |
|
1348 |
foreach (LMDrawing item in drawings) |
1349 |
{ |
1350 |
drawingNameList.Add(item.Attributes["Name"].get_Value().ToString()); |
1351 |
drawingNumberList.Add(item.Attributes["DrawingNumber"].get_Value().ToString()); |
1352 |
} |
1353 |
|
1354 |
int nameLength = drawingName.Length; |
1355 |
while (drawingNameList.Contains(drawingName)) |
1356 |
{ |
1357 |
if (nameLength == drawingName.Length) |
1358 |
drawingName += "-1"; |
1359 |
else |
1360 |
{ |
1361 |
int index = Convert.ToInt32(drawingName.Remove(0, nameLength + 1)); |
1362 |
drawingName = drawingName.Substring(0, nameLength + 1); |
1363 |
drawingName += ++index; |
1364 |
} |
1365 |
} |
1366 |
|
1367 |
int numberLength = drawingNumber.Length; |
1368 |
while (drawingNameList.Contains(drawingNumber)) |
1369 |
{ |
1370 |
if (numberLength == drawingNumber.Length) |
1371 |
drawingNumber += "-1"; |
1372 |
else |
1373 |
{ |
1374 |
int index = Convert.ToInt32(drawingNumber.Remove(0, numberLength + 1)); |
1375 |
drawingNumber = drawingNumber.Substring(0, numberLength + 1); |
1376 |
drawingNumber += ++index; |
1377 |
} |
1378 |
} |
1379 |
ReleaseCOMObjects(drawings); |
1380 |
drawings = null; |
1381 |
} |
1382 |
|
1383 |
/// <summary> |
1384 |
/// 도면 크기 구하는 메서드 |
1385 |
/// </summary> |
1386 |
/// <returns></returns> |
1387 |
private bool DocumentCoordinateCorrection() |
1388 |
{ |
1389 |
//if (radApp.ActiveDocument.ActiveSheet.SmartFrames2d.Count > 0) |
1390 |
//{ |
1391 |
// double x = 0; |
1392 |
// double y = 0; |
1393 |
// foreach (Ingr.RAD2D.SmartFrame2d smartFrame in radApp.ActiveDocument.ActiveSheet.SmartFrames2d) |
1394 |
// { |
1395 |
// x = Math.Max(smartFrame.CropRight, x); |
1396 |
// y = Math.Max(smartFrame.CropTop, y); |
1397 |
// } |
1398 |
// document.SetSPPIDLocation(x, y); |
1399 |
// document.CoordinateCorrection(); |
1400 |
// return true; |
1401 |
//} |
1402 |
//else |
1403 |
//{ |
1404 |
// Log.Write("Need Border!"); |
1405 |
// return false; |
1406 |
//} |
1407 |
|
1408 |
if (Settings.Default.DrawingX != 0 && Settings.Default.DrawingY != 0) |
1409 |
{ |
1410 |
Log.Write("Setting Drawing X, Drawing Y"); |
1411 |
document.SetSPPIDLocation(Settings.Default.DrawingX, Settings.Default.DrawingY); |
1412 |
Log.Write("Start coordinate correction"); |
1413 |
document.CoordinateCorrection(); |
1414 |
return true; |
1415 |
} |
1416 |
else |
1417 |
{ |
1418 |
Log.Write("Need Drawing X, Y"); |
1419 |
return false; |
1420 |
} |
1421 |
} |
1422 |
|
1423 |
/// <summary> |
1424 |
/// 심볼을 실제로 Modeling 메서드 |
1425 |
/// </summary> |
1426 |
/// <param name="symbol">생성할 심볼</param> |
1427 |
/// <param name="targetSymbol">연결되어 있는 심볼</param> |
1428 |
private void SymbolModeling(Symbol symbol, Symbol targetSymbol) |
1429 |
{ |
1430 |
// OWNERSYMBOL Attribute, 값을 가지고 있을 경우 |
1431 |
BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(attr => attr.ATTRIBUTE == "OWNERSYMBOL"); |
1432 |
if (itemAttribute != null && (string.IsNullOrEmpty(itemAttribute.VALUE) || itemAttribute.VALUE != "None")) |
1433 |
return; |
1434 |
// 이미 모델링 됐을 경우 |
1435 |
else if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
1436 |
return; |
1437 |
|
1438 |
LMSymbol _LMSymbol = null; |
1439 |
|
1440 |
string mappingPath = symbol.SPPID.MAPPINGNAME; |
1441 |
double x = symbol.SPPID.ORIGINAL_X; |
1442 |
double y = symbol.SPPID.ORIGINAL_Y; |
1443 |
int mirror = 0; |
1444 |
double angle = symbol.ANGLE; |
1445 |
|
1446 |
// OPC 일경우 180도 일때 Mirror |
1447 |
if (mappingPath.Contains("Piping OPC's") && angle == Math.PI) |
1448 |
mirror = 1; |
1449 |
|
1450 |
// Mirror 계산 |
1451 |
if (symbol.FLIP == 1) |
1452 |
{ |
1453 |
mirror = 1; |
1454 |
if (angle == Math.PI || angle == 0) |
1455 |
angle += Math.PI; |
1456 |
} |
1457 |
|
1458 |
if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId)) |
1459 |
{ |
1460 |
LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); /// RepresentationId로 SPPID 심볼을 찾음 |
1461 |
Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, symbol.UID, targetSymbol); |
1462 |
if (connector != null) |
1463 |
GetTargetSymbolConnectorPoint(connector, targetSymbol, ref x, ref y); |
1464 |
|
1465 |
LMConnector temp = LineModelingForSymbolZeroLength(symbol, _TargetItem, x, y); |
1466 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem); |
1467 |
if (temp != null) |
1468 |
_placement.PIDRemovePlacement(temp.AsLMRepresentation()); |
1469 |
ReleaseCOMObjects(temp); |
1470 |
temp = null; |
1471 |
|
1472 |
if (_LMSymbol != null && _TargetItem != null) |
1473 |
symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
1474 |
|
1475 |
ReleaseCOMObjects(_TargetItem); |
1476 |
} |
1477 |
else |
1478 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
1479 |
|
1480 |
if (_LMSymbol != null) |
1481 |
{ |
1482 |
_LMSymbol.Commit(); |
1483 |
|
1484 |
// ConnCheck |
1485 |
List<string> ids = new List<string>(); |
1486 |
foreach (LMConnector item in _LMSymbol.Connect1Connectors) |
1487 |
{ |
1488 |
if (item.get_ItemStatus() == "Active" && !ids.Contains(item.Id)) |
1489 |
ids.Add(item.Id); |
1490 |
ReleaseCOMObjects(item); |
1491 |
} |
1492 |
foreach (LMConnector item in _LMSymbol.Connect2Connectors) |
1493 |
{ |
1494 |
if (item.get_ItemStatus() == "Active" && !ids.Contains(item.Id)) |
1495 |
ids.Add(item.Id); |
1496 |
ReleaseCOMObjects(item); |
1497 |
} |
1498 |
|
1499 |
int createdSymbolCount = document.SYMBOLS.FindAll(i => i.CONNECTORS.Find(j => j.CONNECTEDITEM == symbol.UID) != null && !string.IsNullOrEmpty(i.SPPID.RepresentationId)).Count; |
1500 |
if (targetSymbol == null && ids.Count != createdSymbolCount) |
1501 |
{ |
1502 |
double currentX = _LMSymbol.get_XCoordinate(); |
1503 |
double currentY = _LMSymbol.get_YCoordinate(); |
1504 |
} |
1505 |
|
1506 |
symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
1507 |
symbol.SPPID.ModelItemID = _LMSymbol.ModelItemID; |
1508 |
symbol.SPPID.GraphicOID = _LMSymbol.get_GraphicOID().ToString(); |
1509 |
|
1510 |
foreach (var item in symbol.ChildSymbols) |
1511 |
CreateChildSymbol(item, _LMSymbol, symbol); |
1512 |
|
1513 |
symbol.SPPID.SPPID_X = _LMSymbol.get_XCoordinate(); |
1514 |
symbol.SPPID.SPPID_Y = _LMSymbol.get_YCoordinate(); |
1515 |
|
1516 |
double[] range = null; |
1517 |
GetSPPIDSymbolRange(symbol, ref range); |
1518 |
symbol.SPPID.SPPID_Min_X = range[0]; |
1519 |
symbol.SPPID.SPPID_Min_Y = range[1]; |
1520 |
symbol.SPPID.SPPID_Max_X = range[2]; |
1521 |
symbol.SPPID.SPPID_Max_Y = range[3]; |
1522 |
|
1523 |
double xGap = symbol.SPPID.SPPID_X - symbol.SPPID.ORIGINAL_X; |
1524 |
double yGap = symbol.SPPID.SPPID_Y - symbol.SPPID.ORIGINAL_Y; |
1525 |
|
1526 |
List<Symbol> xGroupSymbols = symbol.SPPID.CorrectionX_GroupSymbols; |
1527 |
List<Symbol> yGroupSymbols = symbol.SPPID.CorrectionY_GroupSymbols; |
1528 |
xGroupSymbols.Sort(SPPIDUtil.SortSymbolPriority); |
1529 |
yGroupSymbols.Sort(SPPIDUtil.SortSymbolPriority); |
1530 |
int xDrawnCount = xGroupSymbols.Count(c => c.SPPID.RepresentationId != null); |
1531 |
int yDrawnCount = yGroupSymbols.Count(c => c.SPPID.RepresentationId != null); |
1532 |
|
1533 |
if (xDrawnCount == 1 || xDrawnCount == 2) |
1534 |
{ |
1535 |
for (int i = 0; i < xGroupSymbols.Count; i++) |
1536 |
{ |
1537 |
var item = xGroupSymbols[i]; |
1538 |
if (!string.IsNullOrWhiteSpace(item.SPPID.RepresentationId)) continue; |
1539 |
|
1540 |
if (xDrawnCount == 1) |
1541 |
{ |
1542 |
item.SPPID.ORIGINAL_X = symbol.SPPID.SPPID_X; |
1543 |
item.SPPID.ORIGINAL_Y = item.SPPID.ORIGINAL_Y + yGap; |
1544 |
} |
1545 |
else if (xDrawnCount == 2) |
1546 |
{ |
1547 |
if (item.SPPID.IsEqualSpacingY) |
1548 |
{ |
1549 |
double ppValue = xGroupSymbols[i - 2].SPPID.SPPID_Y != 0 ? xGroupSymbols[i - 2].SPPID.SPPID_Y : xGroupSymbols[i - 2].SPPID.ORIGINAL_Y; |
1550 |
double pValue = xGroupSymbols[i - 1].SPPID.SPPID_Y != 0 ? xGroupSymbols[i - 1].SPPID.SPPID_Y : xGroupSymbols[i - 1].SPPID.ORIGINAL_Y; |
1551 |
double gap = pValue - ppValue; |
1552 |
double value = pValue + gap; |
1553 |
item.SPPID.ORIGINAL_Y = value; |
1554 |
} |
1555 |
} |
1556 |
} |
1557 |
} |
1558 |
|
1559 |
if (yDrawnCount == 1 || yDrawnCount == 2) |
1560 |
{ |
1561 |
for (int i = 0; i < yGroupSymbols.Count; i++) |
1562 |
{ |
1563 |
var item = yGroupSymbols[i]; |
1564 |
if (!string.IsNullOrWhiteSpace(item.SPPID.RepresentationId)) continue; |
1565 |
|
1566 |
if (yDrawnCount == 1) |
1567 |
{ |
1568 |
item.SPPID.ORIGINAL_Y = symbol.SPPID.SPPID_Y; |
1569 |
item.SPPID.ORIGINAL_X = item.SPPID.ORIGINAL_X + xGap; |
1570 |
} |
1571 |
else if (yDrawnCount == 2) |
1572 |
{ |
1573 |
if (item.SPPID.IsEqualSpacingX) |
1574 |
{ |
1575 |
double ppValue = yGroupSymbols[i - 2].SPPID.SPPID_X != 0 ? yGroupSymbols[i - 2].SPPID.SPPID_X : yGroupSymbols[i - 2].SPPID.ORIGINAL_X; |
1576 |
double pValue = yGroupSymbols[i - 1].SPPID.SPPID_X != 0 ? yGroupSymbols[i - 1].SPPID.SPPID_X : yGroupSymbols[i - 1].SPPID.ORIGINAL_X; |
1577 |
double gap = pValue - ppValue; |
1578 |
double value = pValue + gap; |
1579 |
item.SPPID.ORIGINAL_X = value; |
1580 |
} |
1581 |
} |
1582 |
} |
1583 |
} |
1584 |
|
1585 |
ReleaseCOMObjects(_LMSymbol); |
1586 |
} |
1587 |
} |
1588 |
/// <summary> |
1589 |
/// targetX와 targetY 기준 제일 먼 PipingPoint에 TempLine Modeling |
1590 |
/// Signal Point는 고려하지 않음 |
1591 |
/// </summary> |
1592 |
/// <param name="symbol"></param> |
1593 |
/// <param name="_TargetItem"></param> |
1594 |
/// <param name="targetX"></param> |
1595 |
/// <param name="targetY"></param> |
1596 |
/// <returns></returns> |
1597 |
private LMConnector LineModelingForSymbolZeroLength(Symbol symbol, LMSymbol _TargetItem, double targetX, double targetY) |
1598 |
{ |
1599 |
LMConnector tempConnector = null; |
1600 |
|
1601 |
List<Symbol> group = new List<Symbol>(); |
1602 |
SPPIDUtil.FindConnectedSymbolGroup(document, symbol, group); |
1603 |
if (group.FindAll(loopX => !string.IsNullOrEmpty(loopX.SPPID.RepresentationId)).Count == 1) |
1604 |
{ |
1605 |
List<Connector> connectors = new List<Connector>(); |
1606 |
foreach (var item in group) |
1607 |
connectors.AddRange(item.CONNECTORS.FindAll(loopX => loopX.ConnectedObject != null && loopX.ConnectedObject.GetType() == typeof(Line))); |
1608 |
/// Primary or Secondary Type Line만 고려 |
1609 |
Connector _connector = connectors.Find(loopX => loopX.ConnectedObject != null && loopX.ConnectedObject.GetType() == typeof(Line) && |
1610 |
(((Line)loopX.ConnectedObject).TYPE == "Primary" || ((Line)loopX.ConnectedObject).TYPE == "Secondary")); |
1611 |
if (_connector != null) |
1612 |
{ |
1613 |
string sppidLine = ((Line)_connector.ConnectedObject).SPPID.MAPPINGNAME; |
1614 |
List<double[]> pointInfos = getPipingPoints(_TargetItem); |
1615 |
/// PipingPoint가 2개 이상만 |
1616 |
if (pointInfos.Count >= 2) |
1617 |
{ |
1618 |
double lineX = 0; |
1619 |
double lineY = 0; |
1620 |
double length = 0; |
1621 |
foreach (var item in pointInfos) |
1622 |
{ |
1623 |
double tempX = item[1]; |
1624 |
double tempY = item[2]; |
1625 |
|
1626 |
double calcDistance = SPPIDUtil.CalcPointToPointdDistance(targetX, targetY, tempX, tempY); |
1627 |
if (calcDistance > length) |
1628 |
{ |
1629 |
lineX = tempX; |
1630 |
lineY = tempY; |
1631 |
} |
1632 |
} |
1633 |
|
1634 |
_LMAItem _LMAItem = _placement.PIDCreateItem(sppidLine); |
1635 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
1636 |
placeRunInputs.AddPoint(-1, -1); |
1637 |
placeRunInputs.AddSymbolTarget(_TargetItem, lineX, lineY); |
1638 |
tempConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
1639 |
if (tempConnector != null) |
1640 |
tempConnector.Commit(); |
1641 |
ReleaseCOMObjects(_LMAItem); |
1642 |
_LMAItem = null; |
1643 |
ReleaseCOMObjects(placeRunInputs); |
1644 |
placeRunInputs = null; |
1645 |
} |
1646 |
} |
1647 |
} |
1648 |
|
1649 |
return tempConnector; |
1650 |
} |
1651 |
/// <summary> |
1652 |
/// Symbol의 PipingPoints를 구함 |
1653 |
/// SignalPoint는 고려하지 않음 |
1654 |
/// </summary> |
1655 |
/// <param name="symbol"></param> |
1656 |
/// <returns></returns> |
1657 |
private List<double[]> getPipingPoints(LMSymbol symbol) |
1658 |
{ |
1659 |
LMModelItem modelItem = symbol.ModelItemObject; |
1660 |
LMPipingPoints pipingPoints = null; |
1661 |
if (modelItem.get_ItemTypeName() == "PipingComp") |
1662 |
{ |
1663 |
LMPipingComp pipingComp = dataSource.GetPipingComp(modelItem.Id); |
1664 |
pipingPoints = pipingComp.PipingPoints; |
1665 |
ReleaseCOMObjects(pipingComp); |
1666 |
pipingComp = null; |
1667 |
} |
1668 |
else if (modelItem.get_ItemTypeName() == "Instrument") |
1669 |
{ |
1670 |
LMInstrument instrument = dataSource.GetInstrument(modelItem.Id); |
1671 |
pipingPoints = instrument.PipingPoints; |
1672 |
ReleaseCOMObjects(instrument); |
1673 |
instrument = null; |
1674 |
} |
1675 |
else |
1676 |
Log.Write("다른 Type"); |
1677 |
|
1678 |
List<double[]> info = new List<double[]>(); |
1679 |
if (pipingPoints != null) |
1680 |
{ |
1681 |
foreach (LMPipingPoint pipingPoint in pipingPoints) |
1682 |
{ |
1683 |
foreach (LMAAttribute attribute in pipingPoint.Attributes) |
1684 |
{ |
1685 |
if (attribute.Name == "PipingPointNumber") |
1686 |
{ |
1687 |
int index = Convert.ToInt32(attribute.get_Value()); |
1688 |
if (info.Find(loopX => loopX[0] == index) == null) |
1689 |
{ |
1690 |
double x = 0; |
1691 |
double y = 0; |
1692 |
if (_placement.PIDConnectPointLocation(symbol, index, ref x, ref y)) |
1693 |
info.Add(new double[] { index, x, y }); |
1694 |
} |
1695 |
} |
1696 |
} |
1697 |
} |
1698 |
} |
1699 |
ReleaseCOMObjects(modelItem); |
1700 |
modelItem = null; |
1701 |
ReleaseCOMObjects(pipingPoints); |
1702 |
pipingPoints = null; |
1703 |
|
1704 |
return info; |
1705 |
} |
1706 |
|
1707 |
private void RemoveSymbol(Symbol symbol) |
1708 |
{ |
1709 |
if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
1710 |
{ |
1711 |
LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
1712 |
if (_LMSymbol != null) |
1713 |
{ |
1714 |
_placement.PIDRemovePlacement(_LMSymbol.AsLMRepresentation()); |
1715 |
ReleaseCOMObjects(_LMSymbol); |
1716 |
} |
1717 |
} |
1718 |
|
1719 |
symbol.SPPID.RepresentationId = string.Empty; |
1720 |
symbol.SPPID.ModelItemID = string.Empty; |
1721 |
symbol.SPPID.SPPID_X = double.NaN; |
1722 |
symbol.SPPID.SPPID_Y = double.NaN; |
1723 |
symbol.SPPID.SPPID_Min_X = double.NaN; |
1724 |
symbol.SPPID.SPPID_Min_Y = double.NaN; |
1725 |
symbol.SPPID.SPPID_Max_X = double.NaN; |
1726 |
symbol.SPPID.SPPID_Max_Y = double.NaN; |
1727 |
} |
1728 |
|
1729 |
private void RemoveSymbol(List<Symbol> symbols) |
1730 |
{ |
1731 |
foreach (var symbol in symbols) |
1732 |
{ |
1733 |
if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
1734 |
{ |
1735 |
LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
1736 |
if (_LMSymbol != null) |
1737 |
{ |
1738 |
_placement.PIDRemovePlacement(_LMSymbol.AsLMRepresentation()); |
1739 |
ReleaseCOMObjects(_LMSymbol); |
1740 |
} |
1741 |
} |
1742 |
|
1743 |
symbol.SPPID.RepresentationId = string.Empty; |
1744 |
symbol.SPPID.ModelItemID = string.Empty; |
1745 |
symbol.SPPID.SPPID_X = double.NaN; |
1746 |
symbol.SPPID.SPPID_Y = double.NaN; |
1747 |
symbol.SPPID.SPPID_Min_X = double.NaN; |
1748 |
symbol.SPPID.SPPID_Min_Y = double.NaN; |
1749 |
symbol.SPPID.SPPID_Max_X = double.NaN; |
1750 |
symbol.SPPID.SPPID_Max_Y = double.NaN; |
1751 |
} |
1752 |
} |
1753 |
|
1754 |
/// <summary> |
1755 |
/// ID2의 Symbol Width와 Height를 비교해서 상대적인 SPPID Connector좌표를 가져온다. |
1756 |
/// </summary> |
1757 |
/// <param name="targetConnector"></param> |
1758 |
/// <param name="targetSymbol"></param> |
1759 |
/// <param name="x"></param> |
1760 |
/// <param name="y"></param> |
1761 |
private void GetTargetSymbolConnectorPoint(Connector targetConnector, Symbol targetSymbol, ref double x, ref double y) |
1762 |
{ |
1763 |
LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); |
1764 |
|
1765 |
double[] range = null; |
1766 |
List<double[]> points = new List<double[]>(); |
1767 |
GetSPPIDSymbolRangeAndConnectionPoints(targetSymbol, ref range, points); |
1768 |
double x1 = range[0]; |
1769 |
double y1 = range[1]; |
1770 |
double x2 = range[2]; |
1771 |
double y2 = range[3]; |
1772 |
|
1773 |
// Origin 기준 Connector의 위치차이 |
1774 |
double sceneX = 0; |
1775 |
double sceneY = 0; |
1776 |
SPPIDUtil.ConvertPointBystring(targetConnector.SCENECONNECTPOINT, ref sceneX, ref sceneY); |
1777 |
double originX = 0; |
1778 |
double originY = 0; |
1779 |
SPPIDUtil.ConvertPointBystring(targetSymbol.ORIGINALPOINT, ref originX, ref originY); |
1780 |
double gapX = originX - sceneX; |
1781 |
double gapY = originY - sceneY; |
1782 |
|
1783 |
// SPPID Symbol과 ID2 심볼의 크기 차이 |
1784 |
double sizeWidth = 0; |
1785 |
double sizeHeight = 0; |
1786 |
SPPIDUtil.ConvertPointBystring(targetSymbol.SIZE, ref sizeWidth, ref sizeHeight); |
1787 |
if (sizeWidth == 0 || sizeHeight == 0) |
1788 |
throw new Exception("Check symbol size! \r\nUID : " + targetSymbol.UID); |
1789 |
|
1790 |
double percentX = (x2 - x1) / sizeWidth; |
1791 |
double percentY = (y2 - y1) / sizeHeight; |
1792 |
|
1793 |
double SPPIDgapX = gapX * percentX; |
1794 |
double SPPIDgapY = gapY * percentY; |
1795 |
|
1796 |
double[] SPPIDOriginPoint = new double[] { _TargetItem.get_XCoordinate() - SPPIDgapX, _TargetItem.get_YCoordinate() + SPPIDgapY }; |
1797 |
double distance = double.MaxValue; |
1798 |
double[] resultPoint; |
1799 |
foreach (var point in points) |
1800 |
{ |
1801 |
double result = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], SPPIDOriginPoint[0], SPPIDOriginPoint[1]); |
1802 |
if (distance > result) |
1803 |
{ |
1804 |
distance = result; |
1805 |
resultPoint = point; |
1806 |
x = point[0]; |
1807 |
y = point[1]; |
1808 |
} |
1809 |
} |
1810 |
|
1811 |
ReleaseCOMObjects(_TargetItem); |
1812 |
} |
1813 |
|
1814 |
private void GetTargetLineConnectorPoint(Connector targetConnector, Line targetLine, ref double x, ref double y) |
1815 |
{ |
1816 |
int index = targetLine.CONNECTORS.IndexOf(targetConnector); |
1817 |
if (index == 0) |
1818 |
{ |
1819 |
x = targetLine.SPPID.START_X; |
1820 |
y = targetLine.SPPID.START_Y; |
1821 |
} |
1822 |
else |
1823 |
{ |
1824 |
x = targetLine.SPPID.END_X; |
1825 |
y = targetLine.SPPID.END_Y; |
1826 |
} |
1827 |
} |
1828 |
|
1829 |
/// <summary> |
1830 |
/// SPPID Symbol의 Range를 구한다. |
1831 |
/// </summary> |
1832 |
/// <param name="symbol"></param> |
1833 |
/// <param name="range"></param> |
1834 |
private void GetSPPIDSymbolRangeAndConnectionPoints(Symbol symbol, ref double[] range, List<double[]> points) |
1835 |
{ |
1836 |
LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
1837 |
Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()]; |
1838 |
double x1 = 0; |
1839 |
double y1 = 0; |
1840 |
double x2 = 0; |
1841 |
double y2 = 0; |
1842 |
symbol2d.Range(out x1, out y1, out x2, out y2); |
1843 |
range = new double[] { x1, y1, x2, y2 }; |
1844 |
|
1845 |
for (int i = 1; i < 30; i++) |
1846 |
{ |
1847 |
double connX = 0; |
1848 |
double connY = 0; |
1849 |
if (_placement.PIDConnectPointLocation(_TargetItem, i, ref connX, ref connY)) |
1850 |
points.Add(new double[] { connX, connY }); |
1851 |
} |
1852 |
|
1853 |
foreach (var childSymbol in symbol.ChildSymbols) |
1854 |
GetSPPIDChildSymbolRange(childSymbol, ref range, points); |
1855 |
|
1856 |
ReleaseCOMObjects(_TargetItem); |
1857 |
} |
1858 |
|
1859 |
private void GetSPPIDSymbolRange(Symbol symbol, ref double[] range, bool bOnlySymbol = false, bool bForGraphic = false) |
1860 |
{ |
1861 |
LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
1862 |
if (_TargetItem != null) |
1863 |
{ |
1864 |
Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()]; |
1865 |
double x1 = 0; |
1866 |
double y1 = 0; |
1867 |
double x2 = 0; |
1868 |
double y2 = 0; |
1869 |
if (!bForGraphic) |
1870 |
{ |
1871 |
symbol2d.Range(out x1, out y1, out x2, out y2); |
1872 |
range = new double[] { x1, y1, x2, y2 }; |
1873 |
} |
1874 |
else |
1875 |
{ |
1876 |
x1 = double.MaxValue; |
1877 |
y1 = double.MaxValue; |
1878 |
x2 = double.MinValue; |
1879 |
y2 = double.MinValue; |
1880 |
range = new double[] { x1, y1, x2, y2 }; |
1881 |
|
1882 |
foreach (var item in symbol2d.DrawingObjects) |
1883 |
{ |
1884 |
if (item.GetType() == typeof(Ingr.RAD2D.Line2d)) |
1885 |
{ |
1886 |
Ingr.RAD2D.Line2d rangeObject = item as Ingr.RAD2D.Line2d; |
1887 |
if (rangeObject.Layer == "Default") |
1888 |
{ |
1889 |
rangeObject.Range(out x1, out y1, out x2, out y2); |
1890 |
range = new double[] { |
1891 |
Math.Min(x1, range[0]), |
1892 |
Math.Min(y1, range[1]), |
1893 |
Math.Max(x2, range[2]), |
1894 |
Math.Max(y2, range[3]) |
1895 |
}; |
1896 |
} |
1897 |
} |
1898 |
else if (item.GetType() == typeof(Ingr.RAD2D.Circle2d)) |
1899 |
{ |
1900 |
Ingr.RAD2D.Circle2d rangeObject = item as Ingr.RAD2D.Circle2d; |
1901 |
if (rangeObject.Layer == "Default") |
1902 |
{ |
1903 |
rangeObject.Range(out x1, out y1, out x2, out y2); |
1904 |
range = new double[] { |
1905 |
Math.Min(x1, range[0]), |
1906 |
Math.Min(y1, range[1]), |
1907 |
Math.Max(x2, range[2]), |
1908 |
Math.Max(y2, range[3]) |
1909 |
}; |
1910 |
} |
1911 |
} |
1912 |
else if (item.GetType() == typeof(Ingr.RAD2D.Rectangle2d)) |
1913 |
{ |
1914 |
Ingr.RAD2D.Rectangle2d rangeObject = item as Ingr.RAD2D.Rectangle2d; |
1915 |
if (rangeObject.Layer == "Default") |
1916 |
{ |
1917 |
rangeObject.Range(out x1, out y1, out x2, out y2); |
1918 |
range = new double[] { |
1919 |
Math.Min(x1, range[0]), |
1920 |
Math.Min(y1, range[1]), |
1921 |
Math.Max(x2, range[2]), |
1922 |
Math.Max(y2, range[3]) |
1923 |
}; |
1924 |
} |
1925 |
} |
1926 |
else if (item.GetType() == typeof(Ingr.RAD2D.Arc2d)) |
1927 |
{ |
1928 |
Ingr.RAD2D.Arc2d rangeObject = item as Ingr.RAD2D.Arc2d; |
1929 |
if (rangeObject.Layer == "Default") |
1930 |
{ |
1931 |
rangeObject.Range(out x1, out y1, out x2, out y2); |
1932 |
range = new double[] { |
1933 |
Math.Min(x1, range[0]), |
1934 |
Math.Min(y1, range[1]), |
1935 |
Math.Max(x2, range[2]), |
1936 |
Math.Max(y2, range[3]) |
1937 |
}; |
1938 |
} |
1939 |
} |
1940 |
} |
1941 |
} |
1942 |
|
1943 |
if (!bOnlySymbol) |
1944 |
{ |
1945 |
foreach (var childSymbol in symbol.ChildSymbols) |
1946 |
GetSPPIDChildSymbolRange(childSymbol, ref range); |
1947 |
} |
1948 |
ReleaseCOMObjects(_TargetItem); |
1949 |
} |
1950 |
} |
1951 |
|
1952 |
private void GetSPPIDSymbolRange(LMLabelPersist labelPersist, ref double[] range) |
1953 |
{ |
1954 |
if (labelPersist != null) |
1955 |
{ |
1956 |
double x1 = double.MaxValue; |
1957 |
double y1 = double.MaxValue; |
1958 |
double x2 = double.MinValue; |
1959 |
double y2 = double.MinValue; |
1960 |
range = new double[] { x1, y1, x2, y2 }; |
1961 |
|
1962 |
Ingr.RAD2D.DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[labelPersist.get_GraphicOID().ToString()] as DependencyObject; |
1963 |
foreach (var item in dependency.DrawingObjects) |
1964 |
{ |
1965 |
Ingr.RAD2D.TextBox textBox = item as Ingr.RAD2D.TextBox; |
1966 |
if (textBox != null) |
1967 |
{ |
1968 |
if (dependency != null) |
1969 |
{ |
1970 |
double tempX1; |
1971 |
double tempY1; |
1972 |
double tempX2; |
1973 |
double tempY2; |
1974 |
textBox.Range(out tempX1, out tempY1, out tempX2, out tempY2); |
1975 |
x1 = Math.Min(x1, tempX1); |
1976 |
y1 = Math.Min(y1, tempY1); |
1977 |
x2 = Math.Max(x2, tempX2); |
1978 |
y2 = Math.Max(y2, tempY2); |
1979 |
|
1980 |
range = new double[] { x1, y1, x2, y2 }; |
1981 |
} |
1982 |
} |
1983 |
} |
1984 |
|
1985 |
} |
1986 |
} |
1987 |
|
1988 |
private void GetSPPIDSymbolRange(List<Symbol> symbols, ref double[] range, bool bOnlySymbol = false, bool bForGraphic = false) |
1989 |
{ |
1990 |
double[] tempRange = new double[] { double.MaxValue, double.MaxValue, double.MinValue, double.MinValue }; |
1991 |
foreach (var symbol in symbols) |
1992 |
{ |
1993 |
double[] symbolRange = null; |
1994 |
GetSPPIDSymbolRange(symbol, ref symbolRange, bOnlySymbol, bForGraphic); |
1995 |
|
1996 |
tempRange[0] = Math.Min(tempRange[0], symbolRange[0]); |
1997 |
tempRange[1] = Math.Min(tempRange[1], symbolRange[1]); |
1998 |
tempRange[2] = Math.Max(tempRange[2], symbolRange[2]); |
1999 |
tempRange[3] = Math.Max(tempRange[3], symbolRange[3]); |
2000 |
|
2001 |
foreach (var childSymbol in symbol.ChildSymbols) |
2002 |
GetSPPIDChildSymbolRange(childSymbol, ref tempRange); |
2003 |
} |
2004 |
|
2005 |
range = tempRange; |
2006 |
} |
2007 |
|
2008 |
/// <summary> |
2009 |
/// Child Modeling 된 Symbol의 Range를 구한다. |
2010 |
/// </summary> |
2011 |
/// <param name="childSymbol"></param> |
2012 |
/// <param name="range"></param> |
2013 |
private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range, List<double[]> points) |
2014 |
{ |
2015 |
LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId); |
2016 |
if (_ChildSymbol != null) |
2017 |
{ |
2018 |
Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()]; |
2019 |
double x1 = 0; |
2020 |
double y1 = 0; |
2021 |
double x2 = 0; |
2022 |
double y2 = 0; |
2023 |
symbol2d.Range(out x1, out y1, out x2, out y2); |
2024 |
range[0] = Math.Min(range[0], x1); |
2025 |
range[1] = Math.Min(range[1], y1); |
2026 |
range[2] = Math.Max(range[2], x2); |
2027 |
range[3] = Math.Max(range[3], y2); |
2028 |
|
2029 |
for (int i = 1; i < int.MaxValue; i++) |
2030 |
{ |
2031 |
double connX = 0; |
2032 |
double connY = 0; |
2033 |
if (_placement.PIDConnectPointLocation(_ChildSymbol, i, ref connX, ref connY)) |
2034 |
points.Add(new double[] { connX, connY }); |
2035 |
else |
2036 |
break; |
2037 |
} |
2038 |
|
2039 |
foreach (var loopChildSymbol in childSymbol.ChildSymbols) |
2040 |
GetSPPIDChildSymbolRange(loopChildSymbol, ref range, points); |
2041 |
|
2042 |
ReleaseCOMObjects(_ChildSymbol); |
2043 |
} |
2044 |
} |
2045 |
|
2046 |
private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range) |
2047 |
{ |
2048 |
LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId); |
2049 |
if (_ChildSymbol != null) |
2050 |
{ |
2051 |
Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()]; |
2052 |
double x1 = 0; |
2053 |
double y1 = 0; |
2054 |
double x2 = 0; |
2055 |
double y2 = 0; |
2056 |
symbol2d.Range(out x1, out y1, out x2, out y2); |
2057 |
range[0] = Math.Min(range[0], x1); |
2058 |
range[1] = Math.Min(range[1], y1); |
2059 |
range[2] = Math.Max(range[2], x2); |
2060 |
range[3] = Math.Max(range[3], y2); |
2061 |
|
2062 |
foreach (var loopChildSymbol in childSymbol.ChildSymbols) |
2063 |
GetSPPIDChildSymbolRange(loopChildSymbol, ref range); |
2064 |
ReleaseCOMObjects(_ChildSymbol); |
2065 |
} |
2066 |
} |
2067 |
|
2068 |
/// <summary> |
2069 |
/// Label Symbol Modeling |
2070 |
/// </summary> |
2071 |
/// <param name="symbol"></param> |
2072 |
private void LabelSymbolModeling(Symbol symbol) |
2073 |
{ |
2074 |
if (string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
2075 |
{ |
2076 |
BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL"); |
2077 |
if (itemAttribute == null || string.IsNullOrEmpty(itemAttribute.VALUE) || itemAttribute.VALUE == "None") |
2078 |
return; |
2079 |
Array points = new double[] { 0, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y }; |
2080 |
|
2081 |
string symbolUID = itemAttribute.VALUE; |
2082 |
object targetItem = SPPIDUtil.FindObjectByUID(document, symbolUID); |
2083 |
if (targetItem != null && |
2084 |
(targetItem.GetType() == typeof(Symbol) || |
2085 |
targetItem.GetType() == typeof(Equipment))) |
2086 |
{ |
2087 |
// Object 아이템이 Symbol일 경우 Equipment일 경우 |
2088 |
string sRep = null; |
2089 |
if (targetItem.GetType() == typeof(Symbol)) |
2090 |
sRep = ((Symbol)targetItem).SPPID.RepresentationId; |
2091 |
else if (targetItem.GetType() == typeof(Equipment)) |
2092 |
sRep = ((Equipment)targetItem).SPPID.RepresentationId; |
2093 |
if (!string.IsNullOrEmpty(sRep)) |
2094 |
{ |
2095 |
// LEADER Line 검사 |
2096 |
bool leaderLine = false; |
2097 |
SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID); |
2098 |
if (symbolMapping != null) |
2099 |
leaderLine = symbolMapping.LEADERLINE; |
2100 |
|
2101 |
// Target Symbol Item 가져오고 Label Modeling |
2102 |
LMSymbol _TargetItem = dataSource.GetSymbol(sRep); |
2103 |
LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: symbol.ANGLE, LabeledItem: _TargetItem.AsLMRepresentation(), IsLeaderVisible: leaderLine); |
2104 |
|
2105 |
//Leader 선 센터로 |
2106 |
if (_LMLabelPresist != null) |
2107 |
{ |
2108 |
// Target Item에 Label의 Attribute Input |
2109 |
InputSymbolAttribute(targetItem, symbol.ATTRIBUTES); |
2110 |
|
2111 |
string OID = _LMLabelPresist.get_GraphicOID().ToString(); |
2112 |
DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID] as DependencyObject; |
2113 |
if (dependency != null) |
2114 |
{ |
2115 |
bool result = false; |
2116 |
foreach (var attributes in dependency.AttributeSets) |
2117 |
{ |
2118 |
foreach (var attribute in attributes) |
2119 |
{ |
2120 |
string name = attribute.Name; |
2121 |
string value = attribute.GetValue().ToString(); |
2122 |
if (name == "DrawingItemType" && value == "LabelPersist") |
2123 |
{ |
2124 |
foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects) |
2125 |
{ |
2126 |
if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLineString2d) |
2127 |
{ |
2128 |
Ingr.RAD2D.LineString2d lineString2D = drawingObject as Ingr.RAD2D.LineString2d; |
2129 |
double prevX = _TargetItem.get_XCoordinate(); |
2130 |
double prevY = _TargetItem.get_YCoordinate(); |
2131 |
lineString2D.InsertVertex(lineString2D.VertexCount, prevX, prevY); |
2132 |
lineString2D.RemoveVertex(lineString2D.VertexCount); |
2133 |
result = true; |
2134 |
break; |
2135 |
} |
2136 |
} |
2137 |
} |
2138 |
|
2139 |
if (result) |
2140 |
break; |
2141 |
} |
2142 |
|
2143 |
if (result) |
2144 |
break; |
2145 |
} |
2146 |
} |
2147 |
|
2148 |
symbol.SPPID.RepresentationId = _LMLabelPresist.AsLMRepresentation().Id; |
2149 |
_LMLabelPresist.Commit(); |
2150 |
ReleaseCOMObjects(_LMLabelPresist); |
2151 |
} |
2152 |
|
2153 |
ReleaseCOMObjects(_TargetItem); |
2154 |
} |
2155 |
} |
2156 |
else if (targetItem != null && targetItem.GetType() == typeof(Line)) |
2157 |
{ |
2158 |
Line targetLine = targetItem as Line; |
2159 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId); |
2160 |
LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y); |
2161 |
if (connectedLMConnector != null) |
2162 |
{ |
2163 |
// Target Item에 Label의 Attribute Input |
2164 |
InputSymbolAttribute(targetItem, symbol.ATTRIBUTES); |
2165 |
|
2166 |
// LEADER Line 검사 |
2167 |
bool leaderLine = false; |
2168 |
SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID); |
2169 |
if (symbolMapping != null) |
2170 |
leaderLine = symbolMapping.LEADERLINE; |
2171 |
|
2172 |
LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: symbol.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: leaderLine); |
2173 |
if (_LMLabelPresist != null) |
2174 |
{ |
2175 |
symbol.SPPID.RepresentationId = _LMLabelPresist.AsLMRepresentation().Id; |
2176 |
_LMLabelPresist.Commit(); |
2177 |
ReleaseCOMObjects(_LMLabelPresist); |
2178 |
} |
2179 |
ReleaseCOMObjects(connectedLMConnector); |
2180 |
} |
2181 |
|
2182 |
foreach (var item in connectorVertices) |
2183 |
if (item.Key != null) |
2184 |
ReleaseCOMObjects(item.Key); |
2185 |
} |
2186 |
} |
2187 |
} |
2188 |
|
2189 |
/// <summary> |
2190 |
/// Equipment를 실제로 Modeling 메서드 |
2191 |
/// </summary> |
2192 |
/// <param name="equipment"></param> |
2193 |
private void EquipmentModeling(Equipment equipment) |
2194 |
{ |
2195 |
if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId)) |
2196 |
return; |
2197 |
|
2198 |
LMSymbol _LMSymbol = null; |
2199 |
LMSymbol targetItem = null; |
2200 |
string mappingPath = equipment.SPPID.MAPPINGNAME; |
2201 |
double x = equipment.SPPID.ORIGINAL_X; |
2202 |
double y = equipment.SPPID.ORIGINAL_Y; |
2203 |
int mirror = 0; |
2204 |
double angle = equipment.ANGLE; |
2205 |
|
2206 |
// Mirror 계산 |
2207 |
if (equipment.FLIP == 1) |
2208 |
{ |
2209 |
mirror = 1; |
2210 |
if (angle == Math.PI || angle == 0) |
2211 |
angle += Math.PI; |
2212 |
} |
2213 |
|
2214 |
SPPIDUtil.ConvertGridPoint(ref x, ref y); |
2215 |
|
2216 |
Connector connector = equipment.CONNECTORS.Find(conn => |
2217 |
!string.IsNullOrEmpty(conn.CONNECTEDITEM) && |
2218 |
conn.CONNECTEDITEM != "None" && |
2219 |
conn.ConnectedObject.GetType() == typeof(Equipment)); |
2220 |
|
2221 |
if (connector != null) |
2222 |
{ |
2223 |
Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment; |
2224 |
VendorPackage connVendorPackage = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as VendorPackage; |
2225 |
if (connEquipment != null) |
2226 |
{ |
2227 |
//if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId)) |
2228 |
// EquipmentModeling(connEquipment); |
2229 |
|
2230 |
if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId)) |
2231 |
{ |
2232 |
targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId); |
2233 |
if (targetItem != null) |
2234 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem); |
2235 |
else |
2236 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
2237 |
} |
2238 |
else |
2239 |
{ |
2240 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
2241 |
} |
2242 |
} |
2243 |
else if (connVendorPackage != null) |
2244 |
{ |
2245 |
if (!string.IsNullOrEmpty(connVendorPackage.SPPID.RepresentationId)) |
2246 |
{ |
2247 |
targetItem = dataSource.GetSymbol(connVendorPackage.SPPID.RepresentationId); |
2248 |
if (targetItem != null) |
2249 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem); |
2250 |
else |
2251 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
2252 |
} |
2253 |
} |
2254 |
else |
2255 |
{ |
2256 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
2257 |
} |
2258 |
} |
2259 |
else |
2260 |
{ |
2261 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
2262 |
} |
2263 |
|
2264 |
if (_LMSymbol != null) |
2265 |
{ |
2266 |
_LMSymbol.Commit(); |
2267 |
equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
2268 |
equipment.SPPID.GraphicOID = _LMSymbol.get_GraphicOID().ToString(); |
2269 |
ReleaseCOMObjects(_LMSymbol); |
2270 |
} |
2271 |
|
2272 |
if (targetItem != null) |
2273 |
{ |
2274 |
ReleaseCOMObjects(targetItem); |
2275 |
} |
2276 |
|
2277 |
ReleaseCOMObjects(_LMSymbol); |
2278 |
} |
2279 |
|
2280 |
private void VendorPackageModeling(VendorPackage vendorPackage) |
2281 |
{ |
2282 |
ETCSetting setting = ETCSetting.GetInstance(); |
2283 |
if (!string.IsNullOrEmpty(setting.VendorPackageSymbolPath)) |
2284 |
{ |
2285 |
string symbolPath = setting.VendorPackageSymbolPath; |
2286 |
double x = vendorPackage.SPPID.ORIGINAL_X; |
2287 |
double y = vendorPackage.SPPID.ORIGINAL_Y; |
2288 |
|
2289 |
LMSymbol symbol = _placement.PIDPlaceSymbol(symbolPath, x, y); |
2290 |
if (symbol != null) |
2291 |
{ |
2292 |
symbol.Commit(); |
2293 |
vendorPackage.SPPID.RepresentationId = symbol.AsLMRepresentation().Id; |
2294 |
} |
2295 |
|
2296 |
ReleaseCOMObjects(symbol); |
2297 |
symbol = null; |
2298 |
} |
2299 |
} |
2300 |
|
2301 |
private void GraphicModeling(Graphic graphic) |
2302 |
{ |
2303 |
Ingr.RAD2D.SmartFrame2d borderFrame = radApp.ActiveDocument.ActiveSheet.SmartFrames2d[0]; |
2304 |
string styleName = "SFStyleConverter"; |
2305 |
string projectPah = Settings.Default.ProjectPath; |
2306 |
string graphicDirectory = Path.Combine(projectPah, "graphic"); |
2307 |
string filePath = Path.Combine(graphicDirectory, string.Format("{0}.igr", graphic.NAME)); |
2308 |
if (!File.Exists(filePath)) return; |
2309 |
|
2310 |
int styleCount = radApp.ActiveDocument.SmartFrame2dStyles.Count(c => c.Name.StartsWith(styleName)); |
2311 |
styleName = string.Format("{0}_{1}", styleName, styleCount); |
2312 |
Ingr.RAD2D.SmartFrame2dStyle StyleConverter = radApp.ActiveDocument.SmartFrame2dStyles.Add(styleName, ""); |
2313 |
|
2314 |
Ingr.RAD2D.SmartFrame2d smartFrame = radApp.ActiveDocument.ActiveSheet.SmartFrames2d.AddBy2Points(styleName, 0.01, 0.01, 0.1, 0.1, false, filePath); |
2315 |
smartFrame.BorderVisible = false; |
2316 |
smartFrame.SetLayerDisplay("default", true); |
2317 |
|
2318 |
double oMinx = 0, oMinY = 0, oMaxX = 0, oMaxY = 0; |
2319 |
smartFrame.Range(out oMinx, out oMinY, out oMaxX, out oMaxY); |
2320 |
double cWidth = oMaxX - oMinx; |
2321 |
double cHeight = oMaxY - oMinY; |
2322 |
double height = Math.Abs(graphic.SPPIDGraphicLocation.Y2 - graphic.SPPIDGraphicLocation.Y1); |
2323 |
double width = Math.Abs(graphic.SPPIDGraphicLocation.X2 - graphic.SPPIDGraphicLocation.X1); |
2324 |
double scaleFactor = width / cWidth; |
2325 |
smartFrame.ScaleFactor = scaleFactor; |
2326 |
smartFrame.SetOrigin(graphic.SPPIDGraphicLocation.X1, graphic.SPPIDGraphicLocation.Y1); |
2327 |
} |
2328 |
|
2329 |
/// <summary> |
2330 |
/// 첫 진입점 |
2331 |
/// </summary> |
2332 |
/// <param name="symbol"></param> |
2333 |
private void SymbolModelingBySymbol(Symbol symbol) |
2334 |
{ |
2335 |
SymbolModeling(symbol, null); /// 심볼을 생성한다 |
2336 |
List<object> endObjects = new List<object>(); |
2337 |
endObjects.Add(symbol); |
2338 |
|
2339 |
// 심볼에 연결되어 있는 항목들을 모델링한다 |
2340 |
foreach (var connector in symbol.CONNECTORS) |
2341 |
{ |
2342 |
object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
2343 |
if (connItem != null && connItem.GetType() != typeof(Equipment)) |
2344 |
{ |
2345 |
endObjects.Add(connItem); |
2346 |
if (connItem.GetType() == typeof(Symbol)) |
2347 |
{ |
2348 |
Symbol connSymbol = connItem as Symbol; |
2349 |
if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId)) |
2350 |
{ |
2351 |
SymbolModeling(connSymbol, symbol); |
2352 |
} |
2353 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count); |
2354 |
SymbolModelingByNeerSymbolLoop(connSymbol, endObjects); |
2355 |
} |
2356 |
else if (connItem.GetType() == typeof(Line)) |
2357 |
{ |
2358 |
Line connLine = connItem as Line; |
2359 |
SymbolModelingByNeerLineLoop(connLine, endObjects, symbol); |
2360 |
} |
2361 |
} |
2362 |
} |
2363 |
} |
2364 |
|
2365 |
private void SymbolModelingByNeerSymbolLoop(Symbol symbol, List<object> endObjects) |
2366 |
{ |
2367 |
foreach (var connector in symbol.CONNECTORS) |
2368 |
{ |
2369 |
object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
2370 |
if (connItem != null && connItem.GetType() != typeof(Equipment)) |
2371 |
{ |
2372 |
if (!endObjects.Contains(connItem)) |
2373 |
{ |
2374 |
endObjects.Add(connItem); |
2375 |
if (connItem.GetType() == typeof(Symbol)) |
2376 |
{ |
2377 |
Symbol connSymbol = connItem as Symbol; |
2378 |
if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId)) |
2379 |
{ |
2380 |
SymbolModeling(connSymbol, symbol); |
2381 |
} |
2382 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count); |
2383 |
SymbolModelingByNeerSymbolLoop(connSymbol, endObjects); |
2384 |
} |
2385 |
else if (connItem.GetType() == typeof(Line)) |
2386 |
{ |
2387 |
Line connLine = connItem as Line; |
2388 |
SymbolModelingByNeerLineLoop(connLine, endObjects, symbol); |
2389 |
} |
2390 |
} |
2391 |
} |
2392 |
} |
2393 |
} |
2394 |
|
2395 |
private void SymbolModelingByNeerLineLoop(Line line, List<object> endObjects, Symbol prevSymbol) |
2396 |
{ |
2397 |
foreach (var connector in line.CONNECTORS) |
2398 |
{ |
2399 |
object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
2400 |
if (connItem != null && connItem.GetType() != typeof(Equipment)) |
2401 |
{ |
2402 |
if (!endObjects.Contains(connItem)) |
2403 |
{ |
2404 |
endObjects.Add(connItem); |
2405 |
if (connItem.GetType() == typeof(Symbol)) |
2406 |
{ |
2407 |
Symbol connSymbol = connItem as Symbol; |
2408 |
if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId)) |
2409 |
{ |
2410 |
Line connLine = SPPIDUtil.GetConnectedLine(prevSymbol, connSymbol); |
2411 |
int branchCount = 0; |
2412 |
if (connLine != null) |
2413 |
branchCount = SPPIDUtil.GetBranchLineCount(document, connLine); |
2414 |
|
2415 |
List<Symbol> group = new List<Symbol>(); |
2416 |
SPPIDUtil.FindConnectedSymbolGroup(document, connSymbol, group); |
2417 |
Symbol priority = prioritySymbols.Find(x => group.Contains(x)); |
2418 |
List<Symbol> endModelingGroup = new List<Symbol>(); |
2419 |
if (priority != null) |
2420 |
{ |
2421 |
SymbolGroupModeling(priority, group); |
2422 |
|
2423 |
// Range 겹치는지 확인해야함 |
2424 |
double[] prevRange = null; |
2425 |
GetSPPIDSymbolRange(prevSymbol, ref prevRange, bForGraphic: true); |
2426 |
double[] groupRange = null; |
2427 |
GetSPPIDSymbolRange(group, ref groupRange, bForGraphic: true); |
2428 |
|
2429 |
double distanceX = 0; |
2430 |
double distanceY = 0; |
2431 |
bool overlapX = false; |
2432 |
bool overlapY = false; |
2433 |
SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y); |
2434 |
SPPIDUtil.CalcOverlap(prevRange, groupRange, ref distanceX, ref distanceY, ref overlapX, ref overlapY); |
2435 |
if ((slopeType == SlopeType.HORIZONTAL && overlapX) || |
2436 |
(slopeType == SlopeType.VERTICAL && overlapY)) |
2437 |
{ |
2438 |
RemoveSymbol(group); |
2439 |
foreach (var _temp in group) |
2440 |
SPPIDUtil.CalcNewCoordinateForSymbol(_temp, prevSymbol, distanceX, distanceY); |
2441 |
|
2442 |
SymbolGroupModeling(priority, group); |
2443 |
} |
2444 |
else if (branchCount > 0) |
2445 |
{ |
2446 |
LMConnector _connector = JustLineModeling(connLine); |
2447 |
if (_connector != null) |
2448 |
{ |
2449 |
double distance = GetConnectorDistance(_connector); |
2450 |
int cellCount = (int)Math.Truncate(distance / GridSetting.GetInstance().Length); |
2451 |
_placement.PIDRemovePlacement(_connector.AsLMRepresentation()); |
2452 |
_connector.Commit(); |
2453 |
ReleaseCOMObjects(_connector); |
2454 |
_connector = null; |
2455 |
if (cellCount < branchCount + 1) |
2456 |
{ |
2457 |
int moveCount = branchCount - cellCount; |
2458 |
RemoveSymbol(group); |
2459 |
foreach (var _temp in group) |
2460 |
SPPIDUtil.CalcNewCoordinateForSymbol(_temp, prevSymbol, moveCount * GridSetting.GetInstance().Length, moveCount * GridSetting.GetInstance().Length); |
2461 |
|
2462 |
SymbolGroupModeling(priority, group); |
2463 |
} |
2464 |
} |
2465 |
} |
2466 |
} |
2467 |
else |
2468 |
{ |
2469 |
SymbolModeling(connSymbol, null); |
2470 |
// Range 겹치는지 확인해야함 |
2471 |
double[] prevRange = null; |
2472 |
GetSPPIDSymbolRange(prevSymbol, ref prevRange, bForGraphic: true); |
2473 |
double[] connRange = null; |
2474 |
GetSPPIDSymbolRange(connSymbol, ref connRange, bForGraphic: true); |
2475 |
|
2476 |
double distanceX = 0; |
2477 |
double distanceY = 0; |
2478 |
bool overlapX = false; |
2479 |
bool overlapY = false; |
2480 |
SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y); |
2481 |
SPPIDUtil.CalcOverlap(prevRange, connRange, ref distanceX, ref distanceY, ref overlapX, ref overlapY); |
2482 |
if ((slopeType == SlopeType.HORIZONTAL && overlapX) || |
2483 |
(slopeType == SlopeType.VERTICAL && overlapY)) |
2484 |
{ |
2485 |
RemoveSymbol(connSymbol); |
2486 |
SPPIDUtil.CalcNewCoordinateForSymbol(connSymbol, prevSymbol, distanceX, distanceY); |
2487 |
|
2488 |
SymbolModeling(connSymbol, null); |
2489 |
} |
2490 |
else if (branchCount > 0) |
2491 |
{ |
2492 |
LMConnector _connector = JustLineModeling(connLine); |
2493 |
if (_connector != null) |
2494 |
{ |
2495 |
double distance = GetConnectorDistance(_connector); |
2496 |
int cellCount = (int)Math.Truncate(distance / GridSetting.GetInstance().Length); |
2497 |
_placement.PIDRemovePlacement(_connector.AsLMRepresentation()); |
2498 |
_connector.Commit(); |
2499 |
ReleaseCOMObjects(_connector); |
2500 |
_connector = null; |
2501 |
if (cellCount < branchCount + 1) |
2502 |
{ |
2503 |
int moveCount = branchCount - cellCount; |
2504 |
RemoveSymbol(group); |
2505 |
foreach (var _temp in group) |
2506 |
SPPIDUtil.CalcNewCoordinateForSymbol(_temp, prevSymbol, moveCount * GridSetting.GetInstance().Length, moveCount * GridSetting.GetInstance().Length); |
2507 |
|
2508 |
SymbolGroupModeling(priority, group); |
2509 |
} |
2510 |
} |
2511 |
} |
2512 |
} |
2513 |
} |
2514 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count); |
2515 |
SymbolModelingByNeerSymbolLoop(connSymbol, endObjects); |
2516 |
} |
2517 |
else if (connItem.GetType() == typeof(Line)) |
2518 |
{ |
2519 |
Line connLine = connItem as Line; |
2520 |
if (!SPPIDUtil.IsBranchLine(connLine, line)) |
2521 |
SymbolModelingByNeerLineLoop(connLine, endObjects, prevSymbol); |
2522 |
} |
2523 |
} |
2524 |
} |
2525 |
} |
2526 |
} |
2527 |
|
2528 |
private void SymbolGroupModeling(Symbol firstSymbol, List<Symbol> group) |
2529 |
{ |
2530 |
List<Symbol> endModelingGroup = new List<Symbol>(); |
2531 |
SymbolModeling(firstSymbol, null); |
2532 |
endModelingGroup.Add(firstSymbol); |
2533 |
while (endModelingGroup.Count != group.Count) |
2534 |
{ |
2535 |
foreach (var _symbol in group) |
2536 |
{ |
2537 |
if (!endModelingGroup.Contains(_symbol)) |
2538 |
{ |
2539 |
foreach (var _connector in _symbol.CONNECTORS) |
2540 |
{ |
2541 |
Symbol _connSymbol = SPPIDUtil.FindObjectByUID(document, _connector.CONNECTEDITEM) as Symbol; |
2542 |
if (_connSymbol != null && endModelingGroup.Contains(_connSymbol)) |
2543 |
{ |
2544 |
SymbolModeling(_symbol, _connSymbol); |
2545 |
endModelingGroup.Add(_symbol); |
2546 |
break; |
2547 |
} |
2548 |
} |
2549 |
} |
2550 |
} |
2551 |
} |
2552 |
} |
2553 |
|
2554 |
/// <summary> |
2555 |
/// 심볼을 실제로 Modeling할때 ChildSymbol이 있다면 Modeling하는 메서드 |
2556 |
/// </summary> |
2557 |
/// <param name="childSymbol"></param> |
2558 |
/// <param name="parentSymbol"></param> |
2559 |
private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol, Symbol parent) |
2560 |
{ |
2561 |
Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()]; |
2562 |
double x1 = 0; |
2563 |
double x2 = 0; |
2564 |
double y1 = 0; |
2565 |
double y2 = 0; |
2566 |
symbol2d.Range(out x1, out y1, out x2, out y2); |
2567 |
|
2568 |
LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol); |
2569 |
if (_LMSymbol != null) |
2570 |
{ |
2571 |
_LMSymbol.Commit(); |
2572 |
childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
2573 |
foreach (var item in childSymbol.ChildSymbols) |
2574 |
CreateChildSymbol(item, _LMSymbol, parent); |
2575 |
} |
2576 |
|
2577 |
|
2578 |
ReleaseCOMObjects(_LMSymbol); |
2579 |
} |
2580 |
double index = 0; |
2581 |
private void NewLineModeling(Line line, bool isBranchModeling = false) |
2582 |
{ |
2583 |
if (!string.IsNullOrEmpty(line.SPPID.ModelItemId) || (BranchLines.Contains(line) && !isBranchModeling)) |
2584 |
return; |
2585 |
|
2586 |
List<Line> group = new List<Line>(); |
2587 |
GetConnectedLineGroup(line, group); |
2588 |
if (!BranchLines.Contains(line)) |
2589 |
LineCoordinateCorrection(group); |
2590 |
|
2591 |
for (int i = 0; i < group.Count; i++) |
2592 |
{ |
2593 |
var currentLine = group[i]; |
2594 |
|
2595 |
if (currentLine.UID == "69f0b083-9aea-4c25-bb4f-193175b545f8" || currentLine.UID == "20a60787-b1df-4c6a-9007-f5a48269fd2e" || currentLine.UID == "8671539d-3dfa-422e-b322-3e6cfe49464a") |
2596 |
currentLine.UID = currentLine.UID; |
2597 |
|
2598 |
if (!isBranchModeling && SPPIDUtil.IsBranchLine(currentLine)) |
2599 |
{ |
2600 |
for (int j = i; j < group.Count; j++) |
2601 |
{ |
2602 |
var brachLine = group[j]; |
2603 |
if (!BranchLines.Contains(brachLine)) |
2604 |
BranchLines.Add(brachLine); |
2605 |
} |
2606 |
break; |
2607 |
} |
2608 |
if (currentLine.CONNECTORS[0].ConnectedObject != null |
2609 |
&& currentLine.CONNECTORS[0].ConnectedObject.GetType() == typeof(Line) |
2610 |
&& string.IsNullOrEmpty(((Line)currentLine.CONNECTORS[0].ConnectedObject).SPPID.ModelItemId)) |
2611 |
{ |
2612 |
break; |
2613 |
} |
2614 |
|
2615 |
bool diagonal = false; |
2616 |
if (currentLine.SlopeType != SlopeType.HORIZONTAL && currentLine.SlopeType != SlopeType.VERTICAL) |
2617 |
diagonal = true; |
2618 |
_LMAItem _LMAItem = _placement.PIDCreateItem(currentLine.SPPID.MAPPINGNAME); |
2619 |
LMSymbol _LMSymbolStart = null; |
2620 |
LMSymbol _LMSymbolEnd = null; |
2621 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
2622 |
foreach (var connector in currentLine.CONNECTORS) |
2623 |
{ |
2624 |
double x = 0; |
2625 |
double y = 0; |
2626 |
GetTargetLineConnectorPoint(connector, currentLine, ref x, ref y); |
2627 |
if (connector.ConnectedObject == null) |
2628 |
placeRunInputs.AddPoint(x, y); |
2629 |
else if (connector.ConnectedObject.GetType() == typeof(Symbol)) |
2630 |
{ |
2631 |
Symbol targetSymbol = connector.ConnectedObject as Symbol; |
2632 |
GetTargetSymbolConnectorPoint(targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == currentLine), targetSymbol, ref x, ref y); |
2633 |
if (currentLine.CONNECTORS.IndexOf(connector) == 0) |
2634 |
{ |
2635 |
_LMSymbolStart = GetTargetSymbol(targetSymbol, currentLine); |
2636 |
if (_LMSymbolStart != null) |
2637 |
placeRunInputs.AddSymbolTarget(_LMSymbolStart, x, y, diagonal); |
2638 |
else |
2639 |
placeRunInputs.AddPoint(x, y); |
2640 |
} |
2641 |
else |
2642 |
{ |
2643 |
_LMSymbolEnd = GetTargetSymbol(targetSymbol, currentLine); |
2644 |
if (_LMSymbolEnd != null) |
2645 |
placeRunInputs.AddSymbolTarget(_LMSymbolEnd, x, y, diagonal); |
2646 |
else |
2647 |
placeRunInputs.AddPoint(x, y); |
2648 |
} |
2649 |
} |
2650 |
else if (connector.ConnectedObject.GetType() == typeof(Line)) |
2651 |
{ |
2652 |
Line targetLine = connector.ConnectedObject as Line; |
2653 |
if (!string.IsNullOrEmpty(targetLine.SPPID.ModelItemId)) |
2654 |
{ |
2655 |
LMConnector targetConnector = FindTargetLMConnectorForBranch(currentLine, targetLine, ref x, ref y); |
2656 |
if (targetConnector != null) |
2657 |
{ |
2658 |
if (targetLine.SlopeType != SlopeType.HORIZONTAL && targetLine.SlopeType != SlopeType.VERTICAL) |
2659 |
placeRunInputs.AddConnectorTarget(targetConnector, x, y, true); |
2660 |
else |
2661 |
placeRunInputs.AddConnectorTarget(targetConnector, x, y, diagonal); |
2662 |
ChangeLineSPPIDCoordinateByConnector(currentLine, targetLine, x, y, false); |
2663 |
} |
2664 |
else |
2665 |
{ |
2666 |
placeRunInputs.AddPoint(x, y); |
2667 |
ChangeLineSPPIDCoordinateByConnector(currentLine, targetLine, x, y, false); |
2668 |
} |
2669 |
} |
2670 |
else |
2671 |
{ |
2672 |
if (currentLine.CONNECTORS.IndexOf(connector) == 0) |
2673 |
{ |
2674 |
index += 0.01; |
2675 |
if (currentLine.SlopeType == SlopeType.HORIZONTAL) |
2676 |
placeRunInputs.AddPoint(x, -0.1 - index); |
2677 |
else if (currentLine.SlopeType == SlopeType.VERTICAL) |
2678 |
placeRunInputs.AddPoint(-0.1 - index, y); |
2679 |
else |
2680 |
{ |
2681 |
Line nextLine = currentLine.CONNECTORS[0].ConnectedObject as Line; |
2682 |
if (SPPIDUtil.CalcAngle(nextLine.SPPID.START_X, nextLine.SPPID.START_Y, nextLine.SPPID.END_X, nextLine.SPPID.END_Y) < 45) |
2683 |
placeRunInputs.AddPoint(-0.1 - index, y); |
2684 |
else |
2685 |
placeRunInputs.AddPoint(x, -0.1 - index); |
2686 |
} |
2687 |
} |
2688 |
|
2689 |
placeRunInputs.AddPoint(x, y); |
2690 |
|
2691 |
if (currentLine.CONNECTORS.IndexOf(connector) == 1) |
2692 |
{ |
2693 |
index += 0.01; |
2694 |
if (currentLine.SlopeType == SlopeType.HORIZONTAL) |
2695 |
placeRunInputs.AddPoint(x, -0.1 - index); |
2696 |
else if (currentLine.SlopeType == SlopeType.VERTICAL) |
2697 |
placeRunInputs.AddPoint(-0.1 - index, y); |
2698 |
else |
2699 |
{ |
2700 |
Line nextLine = currentLine.CONNECTORS[1].ConnectedObject as Line; |
2701 |
if (SPPIDUtil.CalcAngle(nextLine.SPPID.START_X, nextLine.SPPID.START_Y, nextLine.SPPID.END_X, nextLine.SPPID.END_Y) < 45) |
2702 |
placeRunInputs.AddPoint(-0.1 - index, y); |
2703 |
else |
2704 |
placeRunInputs.AddPoint(x, -0.1 - index); |
2705 |
} |
2706 |
} |
2707 |
} |
2708 |
} |
2709 |
else |
2710 |
placeRunInputs.AddPoint(x, y); |
2711 |
} |
2712 |
|
2713 |
LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
2714 |
if (_lMConnector != null) |
2715 |
{ |
2716 |
_lMConnector.Commit(); |
2717 |
currentLine.SPPID.ModelItemId = _lMConnector.ModelItemID; |
2718 |
|
2719 |
bool bRemodelingStart = false; |
2720 |
if (_LMSymbolStart != null) |
2721 |
NeedReModeling(currentLine, _LMSymbolStart, ref bRemodelingStart); |
2722 |
bool bRemodelingEnd = false; |
2723 |
if (_LMSymbolEnd != null) |
2724 |
NeedReModeling(currentLine, _LMSymbolEnd, ref bRemodelingEnd); |
2725 |
|
2726 |
if (bRemodelingStart || bRemodelingEnd) |
2727 |
ReModelingLine(currentLine, _lMConnector, _LMSymbolStart, _LMSymbolEnd, bRemodelingStart, bRemodelingEnd); |
2728 |
|
2729 |
FlowMarkModeling(currentLine); |
2730 |
|
2731 |
ReleaseCOMObjects(_lMConnector); |
2732 |
|
2733 |
LMModelItem modelItem = dataSource.GetModelItem(currentLine.SPPID.ModelItemId); |
2734 |
if (modelItem != null) |
2735 |
{ |
2736 |
LMAAttribute attribute = modelItem.Attributes["FlowDirection"]; |
2737 |
if (attribute != null) |
2738 |
attribute.set_Value("End 1 is upstream (Inlet)"); |
2739 |
modelItem.Commit(); |
2740 |
} |
2741 |
ReleaseCOMObjects(modelItem); |
2742 |
modelItem = null; |
2743 |
} |
2744 |
else if (!isBranchModeling) |
2745 |
{ |
2746 |
Log.Write("Main Line Modeling : " + currentLine.UID); |
2747 |
} |
2748 |
|
2749 |
List<object> removeLines = currentLine.CONNECTORS.FindAll(x => |
2750 |
x.ConnectedObject != null && |
2751 |
x.ConnectedObject.GetType() == typeof(Line) && |
2752 |
!string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)) |
2753 |
.Select(x => x.ConnectedObject) |
2754 |
.ToList(); |
2755 |
|
2756 |
foreach (var item in removeLines) |
2757 |
RemoveLineForModeling(item as Line); |
2758 |
|
2759 |
ReleaseCOMObjects(_LMAItem); |
2760 |
_LMAItem = null; |
2761 |
ReleaseCOMObjects(placeRunInputs); |
2762 |
placeRunInputs = null; |
2763 |
ReleaseCOMObjects(_LMSymbolStart); |
2764 |
_LMSymbolStart = null; |
2765 |
ReleaseCOMObjects(_LMSymbolEnd); |
2766 |
_LMSymbolEnd = null; |
2767 |
} |
2768 |
} |
2769 |
|
2770 |
private LMConnector JustLineModeling(Line line) |
2771 |
{ |
2772 |
bool diagonal = false; |
2773 |
if (line.SlopeType != SlopeType.HORIZONTAL && line.SlopeType != SlopeType.VERTICAL) |
2774 |
diagonal = true; |
2775 |
_LMAItem _LMAItem = _placement.PIDCreateItem(line.SPPID.MAPPINGNAME); |
2776 |
LMSymbol _LMSymbolStart = null; |
2777 |
LMSymbol _LMSymbolEnd = null; |
2778 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
2779 |
foreach (var connector in line.CONNECTORS) |
2780 |
{ |
2781 |
double x = 0; |
2782 |
double y = 0; |
2783 |
GetTargetLineConnectorPoint(connector, line, ref x, ref y); |
2784 |
if (connector.ConnectedObject == null) |
2785 |
{ |
2786 |
placeRunInputs.AddPoint(x, y); |
2787 |
} |
2788 |
else if (connector.ConnectedObject.GetType() == typeof(Symbol)) |
2789 |
{ |
2790 |
Symbol targetSymbol = connector.ConnectedObject as Symbol; |
2791 |
GetTargetSymbolConnectorPoint(targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == line), targetSymbol, ref x, ref y); |
2792 |
if (line.CONNECTORS.IndexOf(connector) == 0) |
2793 |
{ |
2794 |
_LMSymbolStart = GetTargetSymbol(targetSymbol, line); |
2795 |
if (_LMSymbolStart != null) |
2796 |
placeRunInputs.AddSymbolTarget(_LMSymbolStart, x, y, diagonal); |
2797 |
else |
2798 |
placeRunInputs.AddPoint(x, y); |
2799 |
} |
2800 |
else |
2801 |
{ |
2802 |
_LMSymbolEnd = GetTargetSymbol(targetSymbol, line); |
2803 |
if (_LMSymbolEnd != null) |
2804 |
placeRunInputs.AddSymbolTarget(_LMSymbolEnd, x, y, diagonal); |
2805 |
else |
2806 |
placeRunInputs.AddPoint(x, y); |
2807 |
} |
2808 |
} |
2809 |
else if (connector.ConnectedObject.GetType() == typeof(Line)) |
2810 |
{ |
2811 |
Line targetLine = connector.ConnectedObject as Line; |
2812 |
if (!string.IsNullOrEmpty(targetLine.SPPID.ModelItemId)) |
2813 |
{ |
2814 |
LMConnector targetConnector = FindTargetLMConnectorForBranch(line, targetLine, ref x, ref y); |
2815 |
if (targetConnector != null) |
2816 |
{ |
2817 |
placeRunInputs.AddConnectorTarget(targetConnector, x, y, diagonal); |
2818 |
ChangeLineSPPIDCoordinateByConnector(line, targetLine, x, y, false); |
2819 |
} |
2820 |
else |
2821 |
{ |
2822 |
placeRunInputs.AddPoint(x, y); |
2823 |
ChangeLineSPPIDCoordinateByConnector(line, targetLine, x, y, false); |
2824 |
} |
2825 |
} |
2826 |
else |
2827 |
placeRunInputs.AddPoint(x, y); |
2828 |
} |
2829 |
} |
2830 |
|
2831 |
LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
2832 |
if (_lMConnector != null) |
2833 |
_lMConnector.Commit(); |
2834 |
|
2835 |
ReleaseCOMObjects(_LMAItem); |
2836 |
_LMAItem = null; |
2837 |
ReleaseCOMObjects(placeRunInputs); |
2838 |
placeRunInputs = null; |
2839 |
ReleaseCOMObjects(_LMSymbolStart); |
2840 |
_LMSymbolStart = null; |
2841 |
ReleaseCOMObjects(_LMSymbolEnd); |
2842 |
_LMSymbolEnd = null; |
2843 |
|
2844 |
return _lMConnector; |
2845 |
} |
2846 |
|
2847 |
private void RemoveLineForModeling(Line line) |
2848 |
{ |
2849 |
LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
2850 |
if (modelItem != null) |
2851 |
{ |
2852 |
foreach (LMRepresentation rep in modelItem.Representations) |
2853 |
{ |
2854 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
2855 |
{ |
2856 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
2857 |
dynamic OID = rep.get_GraphicOID().ToString(); |
2858 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
2859 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
2860 |
int verticesCount = lineStringGeometry.VertexCount; |
2861 |
double[] vertices = null; |
2862 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
2863 |
for (int i = 0; i < verticesCount; i++) |
2864 |
{ |
2865 |
double x = 0; |
2866 |
double y = 0; |
2867 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
2868 |
if (verticesCount == 2 && (x < 0 || y < 0)) |
2869 |
_placement.PIDRemovePlacement(rep); |
2870 |
} |
2871 |
ReleaseCOMObjects(_LMConnector); |
2872 |
} |
2873 |
} |
2874 |
|
2875 |
ReleaseCOMObjects(modelItem); |
2876 |
} |
2877 |
} |
2878 |
|
2879 |
private void RemoveLine(Line line) |
2880 |
{ |
2881 |
LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
2882 |
if (modelItem != null) |
2883 |
{ |
2884 |
foreach (LMRepresentation rep in modelItem.Representations) |
2885 |
{ |
2886 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
2887 |
_placement.PIDRemovePlacement(rep); |
2888 |
} |
2889 |
ReleaseCOMObjects(modelItem); |
2890 |
} |
2891 |
line.SPPID.ModelItemId = null; |
2892 |
} |
2893 |
|
2894 |
private void GetConnectedLineGroup(Line line, List<Line> group) |
2895 |
{ |
2896 |
if (!group.Contains(line)) |
2897 |
group.Add(line); |
2898 |
|
2899 |
foreach (var connector in line.CONNECTORS) |
2900 |
{ |
2901 |
if (connector.ConnectedObject != null && |
2902 |
connector.ConnectedObject.GetType() == typeof(Line) && |
2903 |
!group.Contains(connector.ConnectedObject) && |
2904 |
string.IsNullOrEmpty(((Line)connector.ConnectedObject).SPPID.ModelItemId)) |
2905 |
{ |
2906 |
Line connLine = connector.ConnectedObject as Line; |
2907 |
if (line.CONNECTORS.IndexOf(connector) == 0 |
2908 |
&& (!SPPIDUtil.IsBranchLine(connLine, line))) |
2909 |
{ |
2910 |
|
2911 |
group.Insert(group.IndexOf(line), connLine); |
2912 |
GetConnectedLineGroup(connLine, group); |
2913 |
} |
2914 |
else if (line.CONNECTORS.IndexOf(connector) == 1 && !SPPIDUtil.IsBranchLine(connLine, line)) |
2915 |
{ |
2916 |
group.Add(connLine); |
2917 |
GetConnectedLineGroup(connLine, group); |
2918 |
} |
2919 |
} |
2920 |
} |
2921 |
} |
2922 |
|
2923 |
private void LineCoordinateCorrection(List<Line> group) |
2924 |
{ |
2925 |
// 순서대로 전 Item 기준 정렬 |
2926 |
LineCoordinateCorrectionByStart(group); |
2927 |
|
2928 |
// 역으로 심볼이 있을 경우 좌표 보정 |
2929 |
LineCoordinateCorrectionForLastLine(group); |
2930 |
} |
2931 |
|
2932 |
private void LineCoordinateCorrectionByStart(List<Line> group) |
2933 |
{ |
2934 |
for (int i = 0; i < group.Count; i++) |
2935 |
{ |
2936 |
Line line = group[i]; |
2937 |
if (i == 0) |
2938 |
{ |
2939 |
Connector symbolConnector = line.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol)); |
2940 |
if (symbolConnector != null) |
2941 |
LineCoordinateCorrectionByConnItem(line, symbolConnector.ConnectedObject); |
2942 |
} |
2943 |
else if (i != 0) |
2944 |
{ |
2945 |
LineCoordinateCorrectionByConnItem(line, group[i - 1]); |
2946 |
} |
2947 |
} |
2948 |
} |
2949 |
|
2950 |
private void LineCoordinateCorrectionForLastLine(List<Line> group) |
2951 |
{ |
2952 |
Line checkLine = group[group.Count - 1]; |
2953 |
Connector lastSymbolConnector = checkLine.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol)); |
2954 |
if (lastSymbolConnector != null) |
2955 |
{ |
2956 |
LineCoordinateCorrectionByConnItem(checkLine, lastSymbolConnector.ConnectedObject); |
2957 |
for (int i = group.Count - 2; i >= 0; i--) |
2958 |
{ |
2959 |
Line refLine = group[i + 1]; |
2960 |
Line changeline = group[i]; |
2961 |
LineCoordinateCorrectionByConnItem(changeline, refLine); |
2962 |
} |
2963 |
} |
2964 |
} |
2965 |
|
2966 |
private void LineCoordinateCorrectionByConnItem(Line line, object connItem) |
2967 |
{ |
2968 |
double x = 0; |
2969 |
double y = 0; |
2970 |
if (connItem.GetType() == typeof(Symbol)) |
2971 |
{ |
2972 |
Symbol targetSymbol = connItem as Symbol; |
2973 |
Connector targetConnector = targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == line); |
2974 |
if (targetConnector != null) |
2975 |
GetTargetSymbolConnectorPoint(targetConnector, targetSymbol, ref x, ref y); |
2976 |
else |
2977 |
throw new Exception("Target symbol UID : " + targetSymbol.UID + "\r\nLine UID : " + line.UID); |
2978 |
} |
2979 |
else if (connItem.GetType() == typeof(Line)) |
2980 |
{ |
2981 |
Line targetLine = connItem as Line; |
2982 |
GetTargetLineConnectorPoint(targetLine.CONNECTORS.Find(z => z.ConnectedObject == line), targetLine, ref x, ref y); |
2983 |
} |
2984 |
|
2985 |
ChangeLineSPPIDCoordinateByConnector(line, connItem, x, y); |
2986 |
} |
2987 |
private void ChangeLineSPPIDCoordinateByConnector(Line line, object connItem, double x, double y, bool changeOtherCoordinate = true) |
2988 |
{ |
2989 |
bool isReverseX = line.SPPID.END_X - line.SPPID.START_X < 0; |
2990 |
bool isReverseY = line.SPPID.END_Y - line.SPPID.START_Y < 0; |
2991 |
double minLength = GridSetting.GetInstance().Length * 0.5; |
2992 |
double minLengthX = minLength * (!isReverseX ? 1 : -1); |
2993 |
double minLengthY = minLength * (!isReverseY ? 1 : -1); |
2994 |
|
2995 |
Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem); |
2996 |
int index = line.CONNECTORS.IndexOf(connector); |
2997 |
if (index == 0) |
2998 |
{ |
2999 |
line.SPPID.START_X = x; |
3000 |
line.SPPID.START_Y = y; |
3001 |
if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate) |
3002 |
{ |
3003 |
line.SPPID.END_Y = y; |
3004 |
// START_X가 END_X 값을 벗어날 경우 END_X 값 보정 |
3005 |
if ((line.SPPID.END_X - line.SPPID.START_X) * (!isReverseX ? 1 : -1) <= minLength) |
3006 |
{ |
3007 |
line.SPPID.END_X = line.SPPID.START_X + minLengthX; |
3008 |
} |
3009 |
} |
3010 |
else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate) |
3011 |
{ |
3012 |
line.SPPID.END_X = x; |
3013 |
// START_Y가 END_Y 값을 벗어날 경우 END_Y 값 보정 |
3014 |
if ((line.SPPID.END_Y - line.SPPID.START_Y) * (!isReverseY ? 1 : -1) <= minLength) |
3015 |
{ |
3016 |
line.SPPID.END_Y = line.SPPID.START_Y + minLengthY; |
3017 |
} |
3018 |
} |
3019 |
} |
3020 |
else |
3021 |
{ |
3022 |
line.SPPID.END_X = x; |
3023 |
line.SPPID.END_Y = y; |
3024 |
if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate) |
3025 |
{ |
3026 |
line.SPPID.START_Y = y; |
3027 |
// END_X가 START_X 값을 벗어날 경우 START_X 값 보정 |
3028 |
if ((line.SPPID.END_X - line.SPPID.START_X) * (!isReverseX ? 1 : -1) <= minLength) |
3029 |
{ |
3030 |
line.SPPID.START_X = line.SPPID.END_X - minLengthX; |
3031 |
} |
3032 |
} |
3033 |
else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate) |
3034 |
{ |
3035 |
line.SPPID.START_X = x; |
3036 |
// END_Y가 START_Y 값을 벗어날 경우 START_Y 값 보정 |
3037 |
if ((line.SPPID.END_Y - line.SPPID.START_Y) * (!isReverseY ? 1 : -1) <= minLength) |
3038 |
{ |
3039 |
line.SPPID.START_Y = line.SPPID.END_Y - minLengthY; |
3040 |
} |
3041 |
} |
3042 |
} |
3043 |
} |
3044 |
|
3045 |
private void ChangeLineSPPIDCoordinateByConnectorOnlyX(Line line, object connItem, double x) |
3046 |
{ |
3047 |
Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem); |
3048 |
int index = line.CONNECTORS.IndexOf(connector); |
3049 |
if (index == 0) |
3050 |
{ |
3051 |
line.SPPID.START_X = x; |
3052 |
if (line.SlopeType == SlopeType.VERTICAL) |
3053 |
line.SPPID.END_X = x; |
3054 |
} |
3055 |
else |
3056 |
{ |
3057 |
line.SPPID.END_X = x; |
3058 |
if (line.SlopeType == SlopeType.VERTICAL) |
3059 |
line.SPPID.START_X = x; |
3060 |
} |
3061 |
} |
3062 |
|
3063 |
private void ChangeLineSPPIDCoordinateByConnectorOnlyY(Line line, object connItem, double y) |
3064 |
{ |
3065 |
Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem); |
3066 |
int index = line.CONNECTORS.IndexOf(connector); |
3067 |
if (index == 0) |
3068 |
{ |
3069 |
line.SPPID.START_Y = y; |
3070 |
if (line.SlopeType == SlopeType.HORIZONTAL) |
3071 |
line.SPPID.END_Y = y; |
3072 |
} |
3073 |
else |
3074 |
{ |
3075 |
line.SPPID.END_Y = y; |
3076 |
if (line.SlopeType == SlopeType.HORIZONTAL) |
3077 |
line.SPPID.START_Y = y; |
3078 |
} |
3079 |
} |
3080 |
|
3081 |
private void NeedReModeling(Line line, LMSymbol symbol, ref bool result) |
3082 |
{ |
3083 |
if (symbol != null) |
3084 |
{ |
3085 |
string repID = symbol.AsLMRepresentation().Id; |
3086 |
string symbolUID = SPPIDUtil.FindSymbolByRepresentationID(document, repID).UID; |
3087 |
string lineUID = line.UID; |
3088 |
|
3089 |
SpecBreak startSpecBreak = document.SpecBreaks.Find(x => |
3090 |
(x.DownStreamUID == symbolUID || x.UpStreamUID == symbolUID) && |
3091 |
(x.DownStreamUID == lineUID || x.UpStreamUID == lineUID)); |
3092 |
|
3093 |
EndBreak startEndBreak = document.EndBreaks.Find(x => |
3094 |
(x.OWNER == symbolUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbolUID) && |
3095 |
(x.OWNER == lineUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == lineUID)); |
3096 |
|
3097 |
if (startSpecBreak != null || startEndBreak != null) |
3098 |
result = true; |
3099 |
} |
3100 |
} |
3101 |
|
3102 |
/// <summary> |
3103 |
/// Symbol에 붙을 경우 Line을 Remodeling 한다. |
3104 |
/// </summary> |
3105 |
/// <param name="lines"></param> |
3106 |
/// <param name="prevLMConnector"></param> |
3107 |
/// <param name="startSymbol"></param> |
3108 |
/// <param name="endSymbol"></param> |
3109 |
private void ReModelingLine(Line line, LMConnector prevLMConnector, LMSymbol startSymbol, LMSymbol endSymbol, bool bStart, bool bEnd) |
3110 |
{ |
3111 |
string symbolPath = string.Empty; |
3112 |
#region get symbol path |
3113 |
LMModelItem modelItem = dataSource.GetModelItem(prevLMConnector.ModelItemID); |
3114 |
symbolPath = GetSPPIDFileName(modelItem); |
3115 |
ReleaseCOMObjects(modelItem); |
3116 |
#endregion |
3117 |
bool diagonal = false; |
3118 |
if (line.SlopeType != SlopeType.HORIZONTAL && line.SlopeType != SlopeType.VERTICAL) |
3119 |
diagonal = true; |
3120 |
_LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath); |
3121 |
LMConnector newConnector = null; |
3122 |
dynamic OID = prevLMConnector.get_GraphicOID().ToString(); |
3123 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
3124 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
3125 |
int verticesCount = lineStringGeometry.VertexCount; |
3126 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
3127 |
|
3128 |
List<double[]> vertices = new List<double[]>(); |
3129 |
for (int i = 1; i <= verticesCount; i++) |
3130 |
{ |
3131 |
double x = 0; |
3132 |
double y = 0; |
3133 |
lineStringGeometry.GetVertex(i, ref x, ref y); |
3134 |
vertices.Add(new double[] { x, y }); |
3135 |
} |
3136 |
|
3137 |
for (int i = 0; i < vertices.Count; i++) |
3138 |
{ |
3139 |
double[] points = vertices[i]; |
3140 |
// 시작 심볼이 있고 첫번째 좌표일 때 |
3141 |
if (startSymbol != null && i == 0) |
3142 |
{ |
3143 |
if (bStart) |
3144 |
{ |
3145 |
SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i + 1][0], vertices[i + 1][1]); |
3146 |
if (slopeType == SlopeType.HORIZONTAL) |
3147 |
placeRunInputs.AddPoint(points[0], -0.1); |
3148 |
else if (slopeType == SlopeType.VERTICAL) |
3149 |
placeRunInputs.AddPoint(-0.1, points[1]); |
3150 |
else |
3151 |
placeRunInputs.AddPoint(points[0], -0.1); |
3152 |
|
3153 |
placeRunInputs.AddPoint(points[0], points[1]); |
3154 |
} |
3155 |
else |
3156 |
{ |
3157 |
placeRunInputs.AddSymbolTarget(startSymbol, points[0], points[1], diagonal); |
3158 |
} |
3159 |
} |
3160 |
// 마지막 심볼이 있고 마지막 좌표일 때 |
3161 |
else if (endSymbol != null && i == vertices.Count - 1) |
3162 |
{ |
3163 |
if (bEnd) |
3164 |
{ |
3165 |
placeRunInputs.AddPoint(points[0], points[1]); |
3166 |
|
3167 |
SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i - 1][0], vertices[i - 1][1]); |
3168 |
if (slopeType == SlopeType.HORIZONTAL) |
3169 |
placeRunInputs.AddPoint(points[0], -0.1); |
3170 |
else if (slopeType == SlopeType.VERTICAL) |
3171 |
placeRunInputs.AddPoint(-0.1, points[1]); |
3172 |
else |
3173 |
placeRunInputs.AddPoint(points[0], -0.1); |
3174 |
} |
3175 |
else |
3176 |
{ |
3177 |
placeRunInputs.AddSymbolTarget(endSymbol, points[0], points[1], diagonal); |
3178 |
} |
3179 |
} |
3180 |
// 첫번째이며 시작 심볼이 아니고 Connecotr일 경우 |
3181 |
else if (i == 0 && prevLMConnector.ConnectItem1SymbolObject != null) |
3182 |
placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem1SymbolObject, points[0], points[1], diagonal); |
3183 |
// 마지막이며 마지막 심볼이 아니고 Connecotr일 경우 |
3184 |
else if (i == vertices.Count - 1 && prevLMConnector.ConnectItem2SymbolObject != null) |
3185 |
placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem2SymbolObject, points[0], points[1], diagonal); |
3186 |
else |
3187 |
placeRunInputs.AddPoint(points[0], points[1]); |
3188 |
} |
3189 |
|
3190 |
_placement.PIDRemovePlacement(prevLMConnector.AsLMRepresentation()); |
3191 |
newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
3192 |
|
3193 |
ReleaseCOMObjects(placeRunInputs); |
3194 |
ReleaseCOMObjects(_LMAItem); |
3195 |
ReleaseCOMObjects(modelItem); |
3196 |
|
3197 |
if (newConnector != null) |
3198 |
{ |
3199 |
newConnector.Commit(); |
3200 |
if (startSymbol != null && bStart) |
3201 |
{ |
3202 |
_LMAItem = _placement.PIDCreateItem(symbolPath); |
3203 |
placeRunInputs = new PlaceRunInputs(); |
3204 |
placeRunInputs.AddSymbolTarget(startSymbol, vertices[0][0], vertices[0][1]); |
3205 |
placeRunInputs.AddConnectorTarget(newConnector, vertices[0][0], vertices[0][1]); |
3206 |
LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
3207 |
if (_LMConnector != null) |
3208 |
{ |
3209 |
_LMConnector.Commit(); |
3210 |
RemoveConnectorForReModelingLine(newConnector); |
3211 |
ZeroLengthModelItemID.Add(_LMConnector.ModelItemID); |
3212 |
ReleaseCOMObjects(_LMConnector); |
3213 |
} |
3214 |
ReleaseCOMObjects(placeRunInputs); |
3215 |
ReleaseCOMObjects(_LMAItem); |
3216 |
} |
3217 |
|
3218 |
if (endSymbol != null && bEnd) |
3219 |
{ |
3220 |
if (startSymbol != null) |
3221 |
{ |
3222 |
Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(newConnector.ModelItemID); |
3223 |
newConnector = dicVertices.First().Key; |
3224 |
} |
3225 |
|
3226 |
_LMAItem = _placement.PIDCreateItem(symbolPath); |
3227 |
placeRunInputs = new PlaceRunInputs(); |
3228 |
placeRunInputs.AddSymbolTarget(endSymbol, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]); |
3229 |
placeRunInputs.AddConnectorTarget(newConnector, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]); |
3230 |
LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
3231 |
if (_LMConnector != null) |
3232 |
{ |
3233 |
_LMConnector.Commit(); |
3234 |
RemoveConnectorForReModelingLine(newConnector); |
3235 |
ZeroLengthModelItemIDReverse.Add(_LMConnector.ModelItemID); |
3236 |
ReleaseCOMObjects(_LMConnector); |
3237 |
} |
3238 |
ReleaseCOMObjects(placeRunInputs); |
3239 |
ReleaseCOMObjects(_LMAItem); |
3240 |
} |
3241 |
|
3242 |
line.SPPID.ModelItemId = newConnector.ModelItemID; |
3243 |
ReleaseCOMObjects(newConnector); |
3244 |
} |
3245 |
|
3246 |
ReleaseCOMObjects(modelItem); |
3247 |
} |
3248 |
|
3249 |
/// <summary> |
3250 |
/// Remodeling 과정에서 생긴 불필요한 Connector 제거 |
3251 |
/// </summary> |
3252 |
/// <param name="connector"></param> |
3253 |
private void RemoveConnectorForReModelingLine(LMConnector connector) |
3254 |
{ |
3255 |
Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(connector.ModelItemID); |
3256 |
foreach (var item in dicVertices) |
3257 |
{ |
3258 |
if (item.Value.Count == 2) |
3259 |
{ |
3260 |
bool result = false; |
3261 |
foreach (var point in item.Value) |
3262 |
{ |
3263 |
if (point[0] < 0 || point[1] < 0) |
3264 |
{ |
3265 |
result = true; |
3266 |
_placement.PIDRemovePlacement(item.Key.AsLMRepresentation()); |
3267 |
break; |
3268 |
} |
3269 |
} |
3270 |
|
3271 |
if (result) |
3272 |
break; |
3273 |
} |
3274 |
} |
3275 |
foreach (var item in dicVertices) |
3276 |
ReleaseCOMObjects(item.Key); |
3277 |
} |
3278 |
|
3279 |
/// <summary> |
3280 |
/// Symbol이 모델링된 SPPPID Symbol Object를 반환 - 연결된 Symbol이 ChildSymbol일 수도 있기때문에 메서드 개발 |
3281 |
/// </summary> |
3282 |
/// <param name="symbol"></param> |
3283 |
/// <param name="line"></param> |
3284 |
/// <returns></returns> |
3285 |
private LMSymbol GetTargetSymbol(Symbol symbol, Line line) |
3286 |
{ |
3287 |
LMSymbol _LMSymbol = null; |
3288 |
foreach (var connector in symbol.CONNECTORS) |
3289 |
{ |
3290 |
if (connector.CONNECTEDITEM == line.UID) |
3291 |
{ |
3292 |
if (connector.Index == 0) |
3293 |
_LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
3294 |
else |
3295 |
{ |
3296 |
ChildSymbol child = null; |
3297 |
foreach (var childSymbol in symbol.ChildSymbols) |
3298 |
{ |
3299 |
if (childSymbol.Connectors.Contains(connector)) |
3300 |
child = childSymbol; |
3301 |
else |
3302 |
child = GetChildSymbolByConnector(childSymbol, connector); |
3303 |
|
3304 |
if (child != null) |
3305 |
break; |
3306 |
} |
3307 |
|
3308 |
if (child != null) |
3309 |
_LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId); |
3310 |
} |
3311 |
|
3312 |
break; |
3313 |
} |
3314 |
} |
3315 |
|
3316 |
return _LMSymbol; |
3317 |
} |
3318 |
|
3319 |
/// <summary> |
3320 |
/// Connector를 가지고 있는 ChildSymbol Object 반환 |
3321 |
/// </summary> |
3322 |
/// <param name="item"></param> |
3323 |
/// <param name="connector"></param> |
3324 |
/// <returns></returns> |
3325 |
private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector) |
3326 |
{ |
3327 |
foreach (var childSymbol in item.ChildSymbols) |
3328 |
{ |
3329 |
if (childSymbol.Connectors.Contains(connector)) |
3330 |
return childSymbol; |
3331 |
else |
3332 |
return GetChildSymbolByConnector(childSymbol, connector); |
3333 |
} |
3334 |
|
3335 |
return null; |
3336 |
} |
3337 |
|
3338 |
/// <summary> |
3339 |
/// EndBreak 모델링 메서드 |
3340 |
/// </summary> |
3341 |
/// <param name="endBreak"></param> |
3342 |
private void EndBreakModeling(EndBreak endBreak) |
3343 |
{ |
3344 |
object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER); |
3345 |
object connectedItem = SPPIDUtil.FindObjectByUID(document, endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE); |
3346 |
|
3347 |
LMConnector targetLMConnector = FindBreakLineTarget(ownerObj, connectedItem); |
3348 |
if (ownerObj.GetType() == typeof(Symbol) && connectedItem.GetType() == typeof(Symbol) && targetLMConnector != null) |
3349 |
targetLMConnector = ReModelingZeroLengthLMConnectorForSegment(targetLMConnector); |
3350 |
|
3351 |
if (targetLMConnector != null) |
3352 |
{ |
3353 |
// LEADER Line 검사 |
3354 |
bool leaderLine = false; |
3355 |
SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == endBreak.DBUID); |
3356 |
if (symbolMapping != null) |
3357 |
leaderLine = symbolMapping.LEADERLINE; |
3358 |
|
3359 |
SegmentLocation location; |
3360 |
double[] point = GetSegmentPoint(ownerObj, connectedItem, targetLMConnector, out location); |
3361 |
Array array = null; |
3362 |
if (point != null) |
3363 |
array = new double[] { 0, point[0], point[1] }; |
3364 |
else |
3365 |
array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y }; |
3366 |
|
3367 |
LMLabelPersist _LmLabelPersist; |
3368 |
|
3369 |
Property property = endBreak.PROPERTIES.Find(loop => loop.ATTRIBUTE == "Freeze"); |
3370 |
if (property != null && !string.IsNullOrEmpty(property.VALUE) && property.VALUE.Equals("True")) |
3371 |
{ |
3372 |
_LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, null, Rotation: endBreak.ANGLE, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: leaderLine); |
3373 |
} |
3374 |
else |
3375 |
{ |
3376 |
_LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, null, null, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: leaderLine); |
3377 |
} |
3378 |
|
3379 |
if (_LmLabelPersist != null) |
3380 |
{ |
3381 |
_LmLabelPersist.Commit(); |
3382 |
endBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id; |
3383 |
if (_LmLabelPersist.ModelItemObject != null) |
3384 |
endBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID; |
3385 |
endBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID().ToString(); |
3386 |
|
3387 |
MoveDependencyObject(endBreak.SPPID.GraphicOID, location); |
3388 |
|
3389 |
// end break arrange |
3390 |
if (property == null || string.IsNullOrEmpty(property.VALUE) || !property.VALUE.Equals("True")) |
3391 |
{ |
3392 |
MoveSegmentBreak(_LmLabelPersist.RepresentationObject.Id, _LmLabelPersist); |
3393 |
} |
3394 |
|
3395 |
ReleaseCOMObjects(_LmLabelPersist); |
3396 |
} |
3397 |
ReleaseCOMObjects(targetLMConnector); |
3398 |
} |
3399 |
else |
3400 |
{ |
3401 |
Log.Write("End Break UID : " + endBreak.UID); |
3402 |
Log.Write("Can't find targetLMConnector"); |
3403 |
} |
3404 |
} |
3405 |
|
3406 |
private void MoveDependencyObject(string graphicOID, SegmentLocation location) |
3407 |
{ |
3408 |
double x = 0, y = 0; |
3409 |
if (location.HasFlag(SegmentLocation.Up)) |
3410 |
y = GridSetting.GetInstance().Length * 3; |
3411 |
else if (location.HasFlag(SegmentLocation.Down)) |
3412 |
y = -GridSetting.GetInstance().Length * 3; |
3413 |
|
3414 |
if (location.HasFlag(SegmentLocation.Right)) |
3415 |
x = GridSetting.GetInstance().Length * 3; |
3416 |
else if (location.HasFlag(SegmentLocation.Left)) |
3417 |
x = -GridSetting.GetInstance().Length * 3; |
3418 |
|
3419 |
if (x != 0 || y != 0) |
3420 |
{ |
3421 |
radApp.ActiveSelectSet.RemoveAll(); |
3422 |
DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] as DependencyObject; |
3423 |
if (dependency != null) |
3424 |
{ |
3425 |
radApp.ActiveSelectSet.Add(dependency); |
3426 |
Ingr.RAD2D.Transform transform = dependency.GetTransform(); |
3427 |
transform.DefineByMove2d(x, y); |
3428 |
radApp.ActiveSelectSet.Transform(transform, true); |
3429 |
radApp.ActiveSelectSet.RemoveAll(); |
3430 |
} |
3431 |
} |
3432 |
} |
3433 |
|
3434 |
private LMConnector ReModelingZeroLengthLMConnectorForSegment(LMConnector connector, string changeSymbolPath = null) |
3435 |
{ |
3436 |
string symbolPath = string.Empty; |
3437 |
#region get symbol path |
3438 |
if (string.IsNullOrEmpty(changeSymbolPath)) |
3439 |
{ |
3440 |
LMModelItem modelItem = dataSource.GetModelItem(connector.ModelItemID); |
3441 |
symbolPath = GetSPPIDFileName(modelItem); |
3442 |
ReleaseCOMObjects(modelItem); |
3443 |
} |
3444 |
else |
3445 |
symbolPath = changeSymbolPath; |
3446 |
|
3447 |
#endregion |
3448 |
|
3449 |
LMConnector newConnector = null; |
3450 |
dynamic OID = connector.get_GraphicOID().ToString(); |
3451 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
3452 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
3453 |
int verticesCount = lineStringGeometry.VertexCount; |
3454 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
3455 |
_LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath); |
3456 |
|
3457 |
if (Convert.ToBoolean(connector.get_IsZeroLength())) |
3458 |
{ |
3459 |
double[] vertices = null; |
3460 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
3461 |
double x = 0; |
3462 |
double y = 0; |
3463 |
lineStringGeometry.GetVertex(1, ref x, ref y); |
3464 |
|
3465 |
string flowDirection = string.Empty; |
3466 |
LMAAttribute flowAttribute = connector.ModelItemObject.Attributes["FlowDirection"]; |
3467 |
if (flowAttribute != null && !DBNull.Value.Equals(flowAttribute.get_Value())) |
3468 |
flowDirection = flowAttribute.get_Value().ToString(); |
3469 |
|
3470 |
if (flowDirection == "End 1 is downstream (Outlet)") |
3471 |
{ |
3472 |
placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y); |
3473 |
placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y); |
3474 |
flowDirection = "End 1 is upstream (Inlet)"; |
3475 |
} |
3476 |
else |
3477 |
{ |
3478 |
placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y); |
3479 |
placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y); |
3480 |
} |
3481 |
string oldModelItemId = connector.ModelItemID; |
3482 |
_placement.PIDRemovePlacement(connector.AsLMRepresentation()); |
3483 |
newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
3484 |
newConnector.Commit(); |
3485 |
ZeroLengthSymbolToSymbolModelItemID.Add(newConnector.ModelItemID); |
3486 |
if (!string.IsNullOrEmpty(flowDirection)) |
3487 |
newConnector.ModelItemObject.Attributes["FlowDirection"].set_Value(flowDirection); |
3488 |
ReleaseCOMObjects(connector); |
3489 |
|
3490 |
foreach (var line in document.LINES.FindAll(z => z.SPPID.ModelItemId == oldModelItemId)) |
3491 |
{ |
3492 |
foreach (var repId in line.SPPID.Representations) |
3493 |
{ |
3494 |
LMConnector _connector = dataSource.GetConnector(repId); |
3495 |
if (_connector != null && _connector.get_ItemStatus() == "Active") |
3496 |
{ |
3497 |
if (line.SPPID.ModelItemId != _connector.ModelItemID) |
3498 |
{ |
3499 |
line.SPPID.ModelItemId = _connector.ModelItemID; |
3500 |
line.SPPID.Representations = GetRepresentations(line.SPPID.ModelItemId); |
3501 |
} |
3502 |
} |
3503 |
ReleaseCOMObjects(_connector); |
3504 |
_connector = null; |
3505 |
} |
3506 |
} |
3507 |
} |
3508 |
|
3509 |
return newConnector; |
3510 |
} |
3511 |
|
3512 |
/// <summary> |
3513 |
/// SpecBreak Modeling 메서드 |
3514 |
/// </summary> |
3515 |
/// <param name="specBreak"></param> |
3516 |
private void SpecBreakModeling(SpecBreak specBreak) |
3517 |
{ |
3518 |
object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID); |
3519 |
object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID); |
3520 |
|
3521 |
if (upStreamObj != null && |
3522 |
downStreamObj != null) |
3523 |
{ |
3524 |
LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj); |
3525 |
if (upStreamObj.GetType() == typeof(Symbol) && downStreamObj.GetType() == typeof(Symbol) && |
3526 |
targetLMConnector != null && |
3527 |
!IsModelingEndBreak(upStreamObj as Symbol, downStreamObj as Symbol)) |
3528 |
targetLMConnector = ReModelingZeroLengthLMConnectorForSegment(targetLMConnector); |
3529 |
|
3530 |
if (targetLMConnector != null) |
3531 |
{ |
3532 |
foreach (var attribute in specBreak.ATTRIBUTES) |
3533 |
{ |
3534 |
AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID); |
3535 |
if (mapping != null && !string.IsNullOrEmpty(mapping.SPPIDSYMBOLNAME) && mapping.SPPIDSYMBOLNAME != "None") |
3536 |
{ |
3537 |
string MappingPath = mapping.SPPIDSYMBOLNAME; |
3538 |
SegmentLocation location; |
3539 |
double[] point = GetSegmentPoint(upStreamObj, downStreamObj, targetLMConnector, out location); |
3540 |
Array array = null; |
3541 |
if (point != null) |
3542 |
array = new double[] { 0, point[0], point[1] }; |
3543 |
else |
3544 |
array = new double[] { 0, specBreak.SPPID.ORIGINAL_X, specBreak.SPPID.ORIGINAL_Y }; |
3545 |
LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(MappingPath, ref array, null, null, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine); |
3546 |
|
3547 |
if (_LmLabelPersist != null) |
3548 |
{ |
3549 |
_LmLabelPersist.Commit(); |
3550 |
specBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id; |
3551 |
if (_LmLabelPersist.ModelItemObject != null) |
3552 |
specBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID; |
3553 |
specBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID().ToString(); |
3554 |
|
3555 |
MoveDependencyObject(specBreak.SPPID.GraphicOID, location); |
3556 |
|
3557 |
// spec break arrange |
3558 |
MoveSegmentBreak(_LmLabelPersist.RepresentationObject.Id, _LmLabelPersist); |
3559 |
|
3560 |
ReleaseCOMObjects(_LmLabelPersist); |
3561 |
} |
3562 |
} |
3563 |
} |
3564 |
|
3565 |
Property property = specBreak.PROPERTIES.Find(loop => loop.ATTRIBUTE == "Show"); |
3566 |
if (property != null && !string.IsNullOrEmpty(property.VALUE) && property.VALUE.Equals("True")) |
3567 |
{ |
3568 |
// temp |
3569 |
ReleaseCOMObjects(_placement.PIDPlaceSymbol(@"\Design\Annotation\Graphics\Break.sym", specBreak.SPPID.ORIGINAL_X, specBreak.SPPID.ORIGINAL_Y, Rotation: specBreak.ANGLE)); |
3570 |
} |
3571 |
ReleaseCOMObjects(targetLMConnector); |
3572 |
} |
3573 |
else |
3574 |
{ |
3575 |
Log.Write("Spec Break UID : " + specBreak.UID); |
3576 |
Log.Write("Can't find targetLMConnector"); |
3577 |
} |
3578 |
} |
3579 |
} |
3580 |
|
3581 |
private bool IsRhombus(LMLabelPersist labelPersist, out double x, out double y, out double radius) |
3582 |
{ |
3583 |
bool result = false; |
3584 |
x = 0; y = 0; radius = 0; |
3585 |
|
3586 |
string oid = labelPersist.get_GraphicOID().ToString(); |
3587 |
DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[oid] as DependencyObject; |
3588 |
|
3589 |
if (dependency != null) |
3590 |
{ |
3591 |
bool isLabel = false; |
3592 |
foreach (var attributes in dependency.AttributeSets) |
3593 |
{ |
3594 |
foreach (var attribute in attributes) |
3595 |
{ |
3596 |
string name = attribute.Name; |
3597 |
string value = attribute.GetValue().ToString(); |
3598 |
if (name == "DrawingItemType" && value == "LabelPersist") |
3599 |
{ |
3600 |
isLabel = true; |
3601 |
break; |
3602 |
} |
3603 |
} |
3604 |
} |
3605 |
if (isLabel) |
3606 |
{ |
3607 |
double minX = double.MaxValue, minY = double.MaxValue, maxX = double.MinValue, maxY = double.MinValue; |
3608 |
foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects) |
3609 |
{ |
3610 |
if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLine2d) |
3611 |
{ |
3612 |
Ingr.RAD2D.Line2d line2D = drawingObject as Ingr.RAD2D.Line2d; |
3613 |
|
3614 |
double x1, y1, x2, y2; |
3615 |
line2D.GetStartPoint(out x1, out y1); |
3616 |
line2D.GetEndPoint(out x2, out y2); |
3617 |
double tX1 = Math.Min(x1, x2), tY1 = Math.Min(y1, y2), tX2 = Math.Max(x1, x2), tY2 = Math.Max(y1, y2); |
3618 |
if (minX > tX1) |
3619 |
minX = tX1; |
3620 |
if (minY > tY1) |
3621 |
minY = tY1; |
3622 |
if (maxX < tX2) |
3623 |
maxX = tX2; |
3624 |
if (maxY < tY2) |
3625 |
maxY = tY2; |
3626 |
} |
3627 |
} |
3628 |
|
3629 |
double width = Math.Abs(maxX - minX); |
3630 |
double height = Math.Abs(maxY - minY); |
3631 |
double ratio = width / height * 100; |
3632 |
if (ratio > 99d && ratio < 101d) |
3633 |
{ |
3634 |
result = true; |
3635 |
} |
3636 |
x = (maxX + minX) / 2d; |
3637 |
y = (maxY + minY) / 2d; |
3638 |
radius = width / 2d; |
3639 |
} |
3640 |
} |
3641 |
|
3642 |
return result; |
3643 |
} |
3644 |
|
3645 |
private void MoveSegmentBreak(string connectorID, LMLabelPersist labelPersist) |
3646 |
{ |
3647 |
bool bFind = false; |
3648 |
double x, y, radius; |
3649 |
if (IsRhombus(labelPersist, out x, out y, out radius)) |
3650 |
{ |
3651 |
List<double[]> itemPoints = new List<double[]>(); |
3652 |
LMConnector connector = dataSource.GetConnector(connectorID); |
3653 |
foreach (LMLabelPersist label in connector.LabelPersists) |
3654 |
{ |
3655 |
if (!"Active".Equals(label.get_ItemStatus())) |
3656 |
continue; |
3657 |
|
3658 |
if (!label.Id.Equals(labelPersist.Id)) |
3659 |
{ |
3660 |
double centerX, centerY, temp; |
3661 |
if (IsRhombus(label, out centerX, out centerY, out temp)) |
3662 |
{ |
3663 |
bFind = true; |
3664 |
itemPoints.Add(new double[] { centerX, centerY }); |
3665 |
} |
3666 |
} |
3667 |
} |
3668 |
ReleaseCOMObjects(connector); |
3669 |
|
3670 |
|
3671 |
if (bFind) |
3672 |
{ |
3673 |
double[] startPoint = itemPoints.First(); |
3674 |
itemPoints.RemoveAt(0); |
3675 |
|
3676 |
for (int i = 0; i < 8; i++) |
3677 |
{ |
3678 |
double pointX = 0, pointY = 0; |
3679 |
switch (i) |
3680 |
{ |
3681 |
case 0: |
3682 |
pointX = startPoint[0] + radius; |
3683 |
pointY = startPoint[1] + radius; |
3684 |
break; |
3685 |
case 1: |
3686 |
pointX = startPoint[0] + radius + radius; |
3687 |
pointY = startPoint[1]; |
3688 |
break; |
3689 |
case 2: |
3690 |
pointX = startPoint[0] + radius; |
3691 |
pointY = startPoint[1] - radius; |
3692 |
break; |
3693 |
case 3: |
3694 |
pointX = startPoint[0]; |
3695 |
pointY = startPoint[1] - radius - radius; |
3696 |
break; |
3697 |
case 4: |
3698 |
pointX = startPoint[0] - radius; |
3699 |
pointY = startPoint[1] - radius; |
3700 |
break; |
3701 |
case 5: |
3702 |
pointX = startPoint[0] - radius - radius; |
3703 |
pointY = startPoint[1]; |
3704 |
break; |
3705 |
case 6: |
3706 |
pointX = startPoint[0] - radius; |
3707 |
pointY = startPoint[1] + radius; |
3708 |
break; |
3709 |
case 7: |
3710 |
pointX = startPoint[0]; |
3711 |
pointY = startPoint[1] + radius + radius; |
3712 |
break; |
3713 |
default: |
3714 |
break; |
3715 |
} |
3716 |
|
3717 |
if (!ExistSegmentByPoint(pointX, pointY)) |
3718 |
{ |
3719 |
DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[labelPersist.get_GraphicOID().ToString()] as DependencyObject; |
3720 |
if (dependency != null) |
3721 |
{ |
3722 |
radApp.ActiveSelectSet.RemoveAll(); |
3723 |
radApp.ActiveSelectSet.Add(dependency); |
3724 |
Ingr.RAD2D.Transform transform = dependency.GetTransform(); |
3725 |
transform.DefineByMove2d(pointX - x, pointY - y); |
3726 |
radApp.ActiveSelectSet.Transform(transform, true); |
3727 |
radApp.ActiveSelectSet.RemoveAll(); |
3728 |
} |
3729 |
break; |
3730 |
} |
3731 |
} |
3732 |
|
3733 |
bool ExistSegmentByPoint(double pointX, double pointY) |
3734 |
{ |
3735 |
bool result = false; |
3736 |
foreach (var item in itemPoints) |
3737 |
{ |
3738 |
double distance = SPPIDUtil.CalcPointToPointdDistance(item[0], item[1], pointX, pointY); |
3739 |
if (Math.Truncate(distance * 1000000000d).Equals(0)) |
3740 |
result = true; |
3741 |
} |
3742 |
return result; |
3743 |
} |
3744 |
} |
3745 |
} |
3746 |
|
3747 |
if (!bFind) |
3748 |
MoveSegmentBestLocation(labelPersist.get_GraphicOID().ToString(), new double[] { x - radius, y - radius, x + radius, y + radius }, itemRange); |
3749 |
} |
3750 |
|
3751 |
LMConnectors GetConnectors() |
3752 |
{ |
3753 |
LMAFilter filter = new LMAFilter(); |
3754 |
LMACriterion criterion1 = new LMACriterion(); |
3755 |
criterion1.SourceAttributeName = "SP_DRAWINGID"; |
3756 |
criterion1.Operator = "="; |
3757 |
criterion1.set_ValueAttribute(dataSource.PIDMgr.Drawing.ID); |
3758 |
criterion1.Conjunctive = true; |
3759 |
filter.get_Criteria().Add(criterion1); |
3760 |
filter.ItemType = "Connector"; |
3761 |
|
3762 |
LMACriterion criterion2 = new LMACriterion(); |
3763 |
criterion2.SourceAttributeName = "ITEMSTATUS"; |
3764 |
criterion2.Operator = "="; |
3765 |
criterion2.set_ValueAttribute("1"); |
3766 |
criterion2.Conjunctive = true; |
3767 |
filter.get_Criteria().Add(criterion2); |
3768 |
|
3769 |
LMACriterion criterion3 = new LMACriterion(); |
3770 |
criterion3.SourceAttributeName = "INSTOCKPILE"; |
3771 |
criterion3.Operator = "="; |
3772 |
criterion3.set_ValueAttribute("1"); |
3773 |
criterion3.Conjunctive = true; |
3774 |
filter.get_Criteria().Add(criterion3); |
3775 |
|
3776 |
LMConnectors items = new LMConnectors(); |
3777 |
items.Collect(dataSource, Filter: filter); |
3778 |
|
3779 |
ReleaseCOMObjects(filter); |
3780 |
ReleaseCOMObjects(criterion1); |
3781 |
ReleaseCOMObjects(criterion2); |
3782 |
ReleaseCOMObjects(criterion3); |
3783 |
|
3784 |
return items; |
3785 |
} |
3786 |
LMSymbols GetSymbols() |
3787 |
{ |
3788 |
LMAFilter filter = new LMAFilter(); |
3789 |
LMACriterion criterion1 = new LMACriterion(); |
3790 |
criterion1.SourceAttributeName = "SP_DRAWINGID"; |
3791 |
criterion1.Operator = "="; |
3792 |
criterion1.set_ValueAttribute(dataSource.PIDMgr.Drawing.ID); |
3793 |
criterion1.Conjunctive = true; |
3794 |
filter.get_Criteria().Add(criterion1); |
3795 |
filter.ItemType = "Symbol"; |
3796 |
|
3797 |
LMACriterion criterion2 = new LMACriterion(); |
3798 |
criterion2.SourceAttributeName = "ITEMSTATUS"; |
3799 |
criterion2.Operator = "="; |
3800 |
criterion2.set_ValueAttribute("1"); |
3801 |
criterion2.Conjunctive = true; |
3802 |
filter.get_Criteria().Add(criterion2); |
3803 |
|
3804 |
LMACriterion criterion3 = new LMACriterion(); |
3805 |
criterion3.SourceAttributeName = "INSTOCKPILE"; |
3806 |
criterion3.Operator = "="; |
3807 |
criterion3.set_ValueAttribute("1"); |
3808 |
criterion3.Conjunctive = true; |
3809 |
filter.get_Criteria().Add(criterion3); |
3810 |
|
3811 |
LMSymbols items = new LMSymbols(); |
3812 |
items.Collect(dataSource, Filter: filter); |
3813 |
|
3814 |
ReleaseCOMObjects(filter); |
3815 |
ReleaseCOMObjects(criterion1); |
3816 |
ReleaseCOMObjects(criterion2); |
3817 |
ReleaseCOMObjects(criterion3); |
3818 |
|
3819 |
return items; |
3820 |
} |
3821 |
|
3822 |
private void SetConnectorAndSymbolRange() |
3823 |
{ |
3824 |
itemRange = new List<double[]>(); |
3825 |
|
3826 |
LMConnectors connectors = GetConnectors(); |
3827 |
foreach (LMConnector connector in connectors) |
3828 |
{ |
3829 |
List<double[]> vertices = GetConnectorVertices(connector); |
3830 |
for (int i = 0; i < vertices.Count - 1; i++) |
3831 |
{ |
3832 |
double[] point1 = vertices[i]; |
3833 |
double[] point2 = vertices[i + 1]; |
3834 |
double x1 = Math.Min(point1[0], point2[0]), y1 = Math.Min(point1[1], point2[1]), x2 = Math.Max(point1[0], point2[0]), y2 = Math.Max(point1[1], point2[1]); |
3835 |
double gap = 0.0001d; |
3836 |
itemRange.Add(new double[] { x1 - gap, y1 - gap, x2 + gap, y2 + gap }); |
3837 |
} |
3838 |
ReleaseCOMObjects(connector); |
3839 |
} |
3840 |
ReleaseCOMObjects(connectors); |
3841 |
|
3842 |
LMSymbols symbols = GetSymbols(); |
3843 |
foreach (LMSymbol symbol in symbols) |
3844 |
{ |
3845 |
string oid = symbol.get_GraphicOID().ToString(); |
3846 |
DrawingObjectBase drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[oid]; |
3847 |
if (drawingObject != null) |
3848 |
{ |
3849 |
double x1, y1, x2, y2; |
3850 |
drawingObject.Range(out x1, out y1, out x2, out y2); |
3851 |
itemRange.Add(new double[] { x1, y1, x2, y2 }); |
3852 |
} |
3853 |
|
3854 |
ReleaseCOMObjects(symbol); |
3855 |
} |
3856 |
ReleaseCOMObjects(symbols); |
3857 |
} |
3858 |
|
3859 |
private void MoveSegmentBestLocation(string oid, double[] segmentRange, List<double[]> allRanges) |
3860 |
{ |
3861 |
double minValue = Math.Min(segmentRange[2] - segmentRange[0], segmentRange[3] - segmentRange[1]); |
3862 |
double maxValue = Math.Max(segmentRange[2] - segmentRange[0], segmentRange[3] - segmentRange[1]); |
3863 |
|
3864 |
double maxX = 0, maxY = 0; |
3865 |
maxX = maxValue * 10; |
3866 |
maxY = minValue * 10; |
3867 |
|
3868 |
double move = minValue / 10d; |
3869 |
double textGap = minValue / 3d; |
3870 |
segmentRange = new double[] { segmentRange[0] - textGap, segmentRange[1] - textGap, segmentRange[2] + textGap, segmentRange[3] + textGap }; |
3871 |
|
3872 |
|
3873 |
List<double[]> containRanges = new List<double[]>(); |
3874 |
double[] findRange = new double[] { |
3875 |
segmentRange[0] - maxX, segmentRange[1] - maxY, |
3876 |
segmentRange[2] + maxX, segmentRange[3] + maxY}; |
3877 |
|
3878 |
foreach (var range in allRanges) |
3879 |
if (SPPIDUtil.IsOverlap(findRange, range)) |
3880 |
containRanges.Add(range); |
3881 |
|
3882 |
double movePointX = 0, movePointY = 0, distance = double.MaxValue; |
3883 |
for (double x = 0; x < maxX; x = x + move) |
3884 |
for (double y = 0; y < maxY; y = y + move) |
3885 |
for (int i = 0; i < 4; i++) |
3886 |
{ |
3887 |
double tempX = 0d, tempY = 0d; |
3888 |
switch (i) |
3889 |
{ |
3890 |
case 0: |
3891 |
tempX = x; |
3892 |
tempY = y; |
3893 |
break; |
3894 |
case 1: |
3895 |
tempX = -x; |
3896 |
tempY = y; |
3897 |
break; |
3898 |
case 2: |
3899 |
tempX = -x; |
3900 |
tempY = -y; |
3901 |
break; |
3902 |
case 3: |
3903 |
tempX = x; |
3904 |
tempY = -y; |
3905 |
break; |
3906 |
default: |
3907 |
break; |
3908 |
} |
3909 |
|
3910 |
bool result = true; |
3911 |
double[] movedRange = new double[] { segmentRange[0] + tempX, segmentRange[1] + tempY, segmentRange[2] + tempX, segmentRange[3] + tempY }; |
3912 |
foreach (double[] range in containRanges) |
3913 |
{ |
3914 |
if (SPPIDUtil.IsOverlap(range, movedRange)) |
3915 |
{ |
3916 |
result = false; |
3917 |
break; |
3918 |
} |
3919 |
} |
3920 |
|
3921 |
if (result) |
3922 |
{ |
3923 |
//double tempDistance = Utils.CalcDistance(new double[] { 0, 0, 0 }, new double[] { tempX, tempY, 0 }); |
3924 |
double tempDistance = SPPIDUtil.CalcPointToPointdDistance(0, 0, tempX, tempY); |
3925 |
bool bChange = false; |
3926 |
if (distance > tempDistance) |
3927 |
bChange = true; |
3928 |
else if (distance.Equals(tempDistance) && (movePointX.Equals(0d) || movePointY.Equals(0d))) |
3929 |
bChange = true; |
3930 |
|
3931 |
if (bChange) |
3932 |
{ |
3933 |
distance = tempDistance; |
3934 |
movePointX = tempX; |
3935 |
movePointY = tempY; |
3936 |
} |
3937 |
} |
3938 |
} |
3939 |
|
3940 |
DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[oid] as DependencyObject; |
3941 |
if (dependency != null) |
3942 |
{ |
3943 |
radApp.ActiveSelectSet.RemoveAll(); |
3944 |
radApp.ActiveSelectSet.Add(dependency); |
3945 |
Ingr.RAD2D.Transform transform = dependency.GetTransform(); |
3946 |
transform.DefineByMove2d(movePointX, movePointY); |
3947 |
radApp.ActiveSelectSet.Transform(transform, true); |
3948 |
radApp.ActiveSelectSet.RemoveAll(); |
3949 |
} |
3950 |
} |
3951 |
|
3952 |
private LMConnector FindBreakLineTarget(object targetObj, object connectedObj) |
3953 |
{ |
3954 |
LMConnector targetConnector = null; |
3955 |
Symbol targetSymbol = targetObj as Symbol; |
3956 |
Symbol connectedSymbol = connectedObj as Symbol; |
3957 |
Line targetLine = targetObj as Line; |
3958 |
Line connectedLine = connectedObj as Line; |
3959 |
if (targetSymbol != null && connectedSymbol != null) |
3960 |
{ |
3961 |
LMSymbol targetLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); |
3962 |
LMSymbol connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId); |
3963 |
|
3964 |
foreach (LMConnector connector in targetLMSymbol.Avoid1Connectors) |
3965 |
{ |
3966 |
if (connector.get_ItemStatus() != "Active") |
3967 |
continue; |
3968 |
|
3969 |
if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id) |
3970 |
{ |
3971 |
targetConnector = connector; |
3972 |
break; |
3973 |
} |
3974 |
else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id) |
3975 |
{ |
3976 |
targetConnector = connector; |
3977 |
break; |
3978 |
} |
3979 |
} |
3980 |
|
3981 |
foreach (LMConnector connector in targetLMSymbol.Avoid2Connectors) |
3982 |
{ |
3983 |
if (connector.get_ItemStatus() != "Active") |
3984 |
continue; |
3985 |
|
3986 |
if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id) |
3987 |
{ |
3988 |
targetConnector = connector; |
3989 |
break; |
3990 |
} |
3991 |
else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id) |
3992 |
{ |
3993 |
targetConnector = connector; |
3994 |
break; |
3995 |
} |
3996 |
} |
3997 |
|
3998 |
ReleaseCOMObjects(targetLMSymbol); |
3999 |
ReleaseCOMObjects(connectedLMSymbol); |
4000 |
} |
4001 |
else if (targetLine != null && connectedLine != null) |
4002 |
{ |
4003 |
LMModelItem targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId); |
4004 |
LMModelItem connectedModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId); |
4005 |
|
4006 |
if (targetModelItem != null && targetModelItem.get_ItemStatus() == "Active" && connectedModelItem != null && connectedModelItem.get_ItemStatus() == "Active") |
4007 |
{ |
4008 |
foreach (LMRepresentation rep in targetModelItem.Representations) |
4009 |
{ |
4010 |
if (targetConnector != null) |
4011 |
break; |
4012 |
|
4013 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
4014 |
{ |
4015 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
4016 |
|
4017 |
if (IsConnected(_LMConnector, connectedModelItem)) |
4018 |
targetConnector = _LMConnector; |
4019 |
else |
4020 |
ReleaseCOMObjects(_LMConnector); |
4021 |
} |
4022 |
} |
4023 |
|
4024 |
ReleaseCOMObjects(targetModelItem); |
4025 |
} |
4026 |
} |
4027 |
else |
4028 |
{ |
4029 |
LMSymbol connectedLMSymbol = null; |
4030 |
if (connectedSymbol != null) |
4031 |
connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId); |
4032 |
else if (targetSymbol != null) |
4033 |
connectedLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); |
4034 |
else |
4035 |
{ |
4036 |
|
4037 |
} |
4038 |
LMModelItem targetModelItem = null; |
4039 |
if (targetLine != null) |
4040 |
targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId); |
4041 |
else if (connectedLine != null) |
4042 |
targetModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId); |
4043 |
else |
4044 |
{ |
4045 |
|
4046 |
} |
4047 |
if (connectedLMSymbol != null && targetModelItem != null) |
4048 |
{ |
4049 |
foreach (LMConnector connector in connectedLMSymbol.Avoid1Connectors) |
4050 |
{ |
4051 |
if (connector.get_ItemStatus() != "Active") |
4052 |
continue; |
4053 |
|
4054 |
if (IsConnected(connector, targetModelItem)) |
4055 |
{ |
4056 |
targetConnector = connector; |
4057 |
break; |
4058 |
} |
4059 |
} |
4060 |
|
4061 |
if (targetConnector == null) |
4062 |
{ |
4063 |
foreach (LMConnector connector in connectedLMSymbol.Avoid2Connectors) |
4064 |
{ |
4065 |
if (connector.get_ItemStatus() != "Active") |
4066 |
continue; |
4067 |
|
4068 |
if (IsConnected(connector, targetModelItem)) |
4069 |
{ |
4070 |
targetConnector = connector; |
4071 |
break; |
4072 |
} |
4073 |
} |
4074 |
} |
4075 |
} |
4076 |
|
4077 |
} |
4078 |
|
4079 |
return targetConnector; |
4080 |
} |
4081 |
|
4082 |
private double[] GetSegmentPoint(object targetObj, object connObj, LMConnector targetConnector, out SegmentLocation location) |
4083 |
{ |
4084 |
double[] result = null; |
4085 |
Line targetLine = targetObj as Line; |
4086 |
Symbol targetSymbol = targetObj as Symbol; |
4087 |
Line connLine = connObj as Line; |
4088 |
Symbol connSymbol = connObj as Symbol; |
4089 |
location = SegmentLocation.None; |
4090 |
if (Convert.ToBoolean(targetConnector.get_IsZeroLength())) |
4091 |
{ |
4092 |
result = GetConnectorVertices(targetConnector)[0]; |
4093 |
if (targetSymbol != null && connSymbol != null) |
4094 |
{ |
4095 |
SlopeType slopeType = SPPIDUtil.CalcSlope(targetSymbol.SPPID.SPPID_X, targetSymbol.SPPID.SPPID_Y, connSymbol.SPPID.SPPID_X, connSymbol.SPPID.SPPID_Y); |
4096 |
result = new double[] { result[0], result[1] }; |
4097 |
if (slopeType == SlopeType.HORIZONTAL) |
4098 |
location = SegmentLocation.Up; |
4099 |
else if (slopeType == SlopeType.VERTICAL) |
4100 |
location = SegmentLocation.Right; |
4101 |
} |
4102 |
else if (targetLine != null) |
4103 |
{ |
4104 |
result = new double[] { result[0], result[1] }; |
4105 |
if (targetLine.SlopeType == SlopeType.HORIZONTAL) |
4106 |
location = SegmentLocation.Up; |
4107 |
else if (targetLine.SlopeType == SlopeType.VERTICAL) |
4108 |
location = SegmentLocation.Right; |
4109 |
} |
4110 |
else if (connLine != null) |
4111 |
{ |
4112 |
result = new double[] { result[0], result[1] }; |
4113 |
if (connLine.SlopeType == SlopeType.HORIZONTAL) |
4114 |
location = SegmentLocation.Up; |
4115 |
else if (connLine.SlopeType == SlopeType.VERTICAL) |
4116 |
location = SegmentLocation.Right; |
4117 |
} |
4118 |
} |
4119 |
else |
4120 |
{ |
4121 |
if (targetObj.GetType() == typeof(Line) && connObj.GetType() == typeof(Line)) |
4122 |
{ |
4123 |
Line line = connObj as Line; |
4124 |
LMConnector connectedConnector = null; |
4125 |
int connIndex = 0; |
4126 |
LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
4127 |
FindConnectedConnector(targetConnector, modelItem, ref connectedConnector, ref connIndex); |
4128 |
|
4129 |
List<double[]> vertices = GetConnectorVertices(targetConnector); |
4130 |
|
4131 |
ReleaseCOMObjects(modelItem); |
4132 |
ReleaseCOMObjects(connectedConnector); |
4133 |
|
4134 |
if (vertices.Count > 0) |
4135 |
{ |
4136 |
if (connIndex == 1) |
4137 |
result = vertices[0]; |
4138 |
else if (connIndex == 2) |
4139 |
result = vertices[vertices.Count - 1]; |
4140 |
|
4141 |
if (targetLine.SlopeType == SlopeType.HORIZONTAL) |
4142 |
{ |
4143 |
result = new double[] { result[0], result[1] }; |
4144 |
location = SegmentLocation.Up; |
4145 |
if (targetLine.CONNECTORS[0].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_X < targetLine.SPPID.END_X) |
4146 |
location = location | SegmentLocation.Right; |
4147 |
else if (targetLine.CONNECTORS[0].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_X > targetLine.SPPID.END_X) |
4148 |
location = location | SegmentLocation.Left; |
4149 |
else if (targetLine.CONNECTORS[1].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_X < targetLine.SPPID.END_X) |
4150 |
location = location | SegmentLocation.Left; |
4151 |
else if (targetLine.CONNECTORS[1].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_X > targetLine.SPPID.END_X) |
4152 |
location = location | SegmentLocation.Right; |
4153 |
} |
4154 |
else if (targetLine.SlopeType == SlopeType.VERTICAL) |
4155 |
{ |
4156 |
result = new double[] { result[0], result[1] }; |
4157 |
location = SegmentLocation.Right; |
4158 |
if (targetLine.CONNECTORS[0].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_Y < targetLine.SPPID.END_Y) |
4159 |
location = location | SegmentLocation.Up; |
4160 |
else if (targetLine.CONNECTORS[0].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_Y > targetLine.SPPID.END_Y) |
4161 |
location = location | SegmentLocation.Down; |
4162 |
else if (targetLine.CONNECTORS[1].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_Y < targetLine.SPPID.END_Y) |
4163 |
location = location | SegmentLocation.Down; |
4164 |
else if (targetLine.CONNECTORS[1].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_Y > targetLine.SPPID.END_Y) |
4165 |
location = location | SegmentLocation.Up; |
4166 |
} |
4167 |
|
4168 |
} |
4169 |
} |
4170 |
else |
4171 |
{ |
4172 |
Log.Write("error in GetSegemtPoint"); |
4173 |
} |
4174 |
} |
4175 |
|
4176 |
return result; |
4177 |
} |
4178 |
|
4179 |
private bool IsConnected(LMConnector connector, LMModelItem modelItem) |
4180 |
{ |
4181 |
bool result = false; |
4182 |
|
4183 |
foreach (LMRepresentation rep in modelItem.Representations) |
4184 |
{ |
4185 |
if (result) |
4186 |
break; |
4187 |
|
4188 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
4189 |
{ |
4190 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
4191 |
|
4192 |
if (_LMConnector.ConnectItem1SymbolObject != null && |
4193 |
connector.ConnectItem1SymbolObject != null && |
4194 |
_LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id) |
4195 |
{ |
4196 |
result = true; |
4197 |
ReleaseCOMObjects(_LMConnector); |
4198 |
break; |
4199 |
} |
4200 |
else if (_LMConnector.ConnectItem1SymbolObject != null && |
4201 |
connector.ConnectItem2SymbolObject != null && |
4202 |
_LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id) |
4203 |
{ |
4204 |
result = true; |
4205 |
ReleaseCOMObjects(_LMConnector); |
4206 |
break; |
4207 |
} |
4208 |
else if (_LMConnector.ConnectItem2SymbolObject != null && |
4209 |
connector.ConnectItem1SymbolObject != null && |
4210 |
_LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id) |
4211 |
{ |
4212 |
result = true; |
4213 |
ReleaseCOMObjects(_LMConnector); |
4214 |
break; |
4215 |
} |
4216 |
else if (_LMConnector.ConnectItem2SymbolObject != null && |
4217 |
connector.ConnectItem2SymbolObject != null && |
4218 |
_LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id) |
4219 |
{ |
4220 |
result = true; |
4221 |
ReleaseCOMObjects(_LMConnector); |
4222 |
break; |
4223 |
} |
4224 |
|
4225 |
ReleaseCOMObjects(_LMConnector); |
4226 |
} |
4227 |
} |
4228 |
|
4229 |
|
4230 |
return result; |
4231 |
} |
4232 |
|
4233 |
private void FindConnectedConnector(LMConnector connector, LMModelItem modelItem, ref LMConnector connectedConnector, ref int connectorIndex) |
4234 |
{ |
4235 |
foreach (LMRepresentation rep in modelItem.Representations) |
4236 |
{ |
4237 |
if (connectedConnector != null) |
4238 |
break; |
4239 |
|
4240 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
4241 |
{ |
4242 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
4243 |
|
4244 |
if (_LMConnector.ConnectItem1SymbolObject != null && |
4245 |
connector.ConnectItem1SymbolObject != null && |
4246 |
_LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id) |
4247 |
{ |
4248 |
connectedConnector = _LMConnector; |
4249 |
connectorIndex = 1; |
4250 |
break; |
4251 |
} |
4252 |
else if (_LMConnector.ConnectItem1SymbolObject != null && |
4253 |
connector.ConnectItem2SymbolObject != null && |
4254 |
_LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id) |
4255 |
{ |
4256 |
connectedConnector = _LMConnector; |
4257 |
connectorIndex = 2; |
4258 |
break; |
4259 |
} |
4260 |
else if (_LMConnector.ConnectItem2SymbolObject != null && |
4261 |
connector.ConnectItem1SymbolObject != null && |
4262 |
_LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id) |
4263 |
{ |
4264 |
connectedConnector = _LMConnector; |
4265 |
connectorIndex = 1; |
4266 |
break; |
4267 |
} |
4268 |
else if (_LMConnector.ConnectItem2SymbolObject != null && |
4269 |
connector.ConnectItem2SymbolObject != null && |
4270 |
_LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id) |
4271 |
{ |
4272 |
connectedConnector = _LMConnector; |
4273 |
connectorIndex = 2; |
4274 |
break; |
4275 |
} |
4276 |
|
4277 |
if (connectedConnector == null) |
4278 |
ReleaseCOMObjects(_LMConnector); |
4279 |
} |
4280 |
} |
4281 |
} |
4282 |
|
4283 |
/// <summary> |
4284 |
/// FromModelItem을 ToModelItem으로 PipeRunJoin하는 메서드 |
4285 |
/// </summary> |
4286 |
/// <param name="modelItemID1"></param> |
4287 |
/// <param name="modelItemID2"></param> |
4288 |
private void JoinRun(string modelId1, string modelId2, ref string survivorId, bool IsSameConnector = true) |
4289 |
{ |
4290 |
try |
4291 |
{ |
4292 |
LMModelItem modelItem1 = dataSource.GetModelItem(modelId1); |
4293 |
LMConnector connector1 = GetLMConnectorFirst(modelId1); |
4294 |
List<double[]> vertices1 = null; |
4295 |
string graphicOID1 = string.Empty; |
4296 |
if (connector1 != null) |
4297 |
{ |
4298 |
vertices1 = GetConnectorVertices(connector1); |
4299 |
graphicOID1 = connector1.get_GraphicOID(); |
4300 |
} |
4301 |
_LMAItem item1 = modelItem1.AsLMAItem(); |
4302 |
ReleaseCOMObjects(connector1); |
4303 |
connector1 = null; |
4304 |
|
4305 |
LMModelItem modelItem2 = dataSource.GetModelItem(modelId2); |
4306 |
LMConnector connector2 = GetLMConnectorFirst(modelId2); |
4307 |
List<double[]> vertices2 = null; |
4308 |
string graphicOID2 = string.Empty; |
4309 |
if (connector2 != null) |
4310 |
{ |
4311 |
vertices2 = GetConnectorVertices(connector2); |
4312 |
graphicOID2 = connector2.get_GraphicOID(); |
4313 |
} |
4314 |
_LMAItem item2 = modelItem2.AsLMAItem(); |
4315 |
ReleaseCOMObjects(connector2); |
4316 |
connector2 = null; |
4317 |
|
4318 |
// item2가 item1으로 조인 |
4319 |
_placement.PIDJoinRuns(ref item1, ref item2); |
4320 |
item1.Commit(); |
4321 |
item2.Commit(); |
4322 |
|
4323 |
string beforeID = string.Empty; |
4324 |
string afterID = string.Empty; |
4325 |
|
4326 |
if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() != "Active") |
4327 |
{ |
4328 |
beforeID = modelItem2.Id; |
4329 |
afterID = modelItem1.Id; |
4330 |
survivorId = afterID; |
4331 |
} |
4332 |
else if (modelItem1.get_ItemStatus() != "Active" && modelItem2.get_ItemStatus() == "Active") |
4333 |
{ |
4334 |
beforeID = modelItem1.Id; |
4335 |
afterID = modelItem2.Id; |
4336 |
survivorId = afterID; |
4337 |
} |
4338 |
else if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() == "Active") |
4339 |
{ |
4340 |
int model1Cnt = GetConnectorCount(modelId1); |
4341 |
int model2Cnt = GetConnectorCount(modelId2); |
4342 |
if (model1Cnt == 0) |
4343 |
{ |
4344 |
beforeID = modelItem1.Id; |
4345 |
afterID = modelItem2.Id; |
4346 |
survivorId = afterID; |
4347 |
} |
4348 |
else if (model2Cnt == 0) |
4349 |
{ |
4350 |
beforeID = modelItem2.Id; |
4351 |
afterID = modelItem1.Id; |
4352 |
survivorId = afterID; |
4353 |
} |
4354 |
else |
4355 |
survivorId = null; |
4356 |
} |
4357 |
else |
4358 |
{ |
4359 |
Log.Write("잘못된 경우"); |
4360 |
survivorId = null; |
4361 |
} |
4362 |
|
4363 |
if (!string.IsNullOrEmpty(beforeID) && !string.IsNullOrEmpty(afterID)) |
4364 |
{ |
4365 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, beforeID); |
4366 |
foreach (var line in lines) |
4367 |
line.SPPID.ModelItemId = afterID; |
4368 |
} |
4369 |
|
4370 |
ReleaseCOMObjects(modelItem1); |
4371 |
ReleaseCOMObjects(item1); |
4372 |
ReleaseCOMObjects(modelItem2); |
4373 |
ReleaseCOMObjects(item2); |
4374 |
} |
4375 |
catch (Exception ex) |
4376 |
{ |
4377 |
Log.Write("Join Error"); |
4378 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
4379 |
} |
4380 |
} |
4381 |
private bool IsModelingEndBreak(Symbol symbol1, Symbol symbol2) |
4382 |
{ |
4383 |
bool result = false; |
4384 |
List<EndBreak> endBreaks = document.EndBreaks.FindAll(x => |
4385 |
(x.OWNER == symbol1.UID || x.OWNER == symbol2.UID) && |
4386 |
(x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol1.UID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol2.UID)); |
4387 |
|
4388 |
foreach (var item in endBreaks) |
4389 |
{ |
4390 |
if (!string.IsNullOrEmpty(item.SPPID.RepresentationId)) |
4391 |
{ |
4392 |
result = true; |
4393 |
break; |
4394 |
} |
4395 |
} |
4396 |
|
4397 |
return result; |
4398 |
} |
4399 |
private List<string> FindOtherModelItemBySymbolWhereTypePipeRun(LMSymbol symbol, string modelId) |
4400 |
{ |
4401 |
List<string> temp = new List<string>(); |
4402 |
List<LMConnector> connectors = new List<LMConnector>(); |
4403 |
foreach (LMConnector connector in symbol.Avoid1Connectors) |
4404 |
{ |
4405 |
if (connector.get_ItemStatus() != "Active") |
4406 |
continue; |
4407 |
|
4408 |
LMModelItem modelItem = connector.ModelItemObject; |
4409 |
LMSymbol connOtherSymbol = FindOtherConnectedSymbol(connector); |
4410 |
if (modelItem.get_ItemStatus() == "Active" && modelItem.get_ItemTypeName().ToString() == "PipeRun" && modelItem.Id != modelId && !temp.Contains(modelItem.Id)) |
4411 |
temp.Add(modelItem.Id); |
4412 |
|
4413 |
if (temp.Contains(modelItem.Id) && |
4414 |
connOtherSymbol != null && |
4415 |
connOtherSymbol.get_RepresentationType() == "Branch" && |
4416 |
Convert.ToBoolean(connector.get_IsZeroLength())) |
4417 |
temp.Remove(modelItem.Id); |
4418 |
|
4419 |
|
4420 |
if (temp.Contains(modelItem.Id)) |
4421 |
connectors.Add(connector); |
4422 |
ReleaseCOMObjects(connOtherSymbol); |
4423 |
connOtherSymbol = null; |
4424 |
ReleaseCOMObjects(modelItem); |
4425 |
modelItem = null; |
4426 |
} |
4427 |
|
4428 |
foreach (LMConnector connector in symbol.Avoid2Connectors) |
4429 |
{ |
4430 |
if (connector.get_ItemStatus() != "Active") |
4431 |
continue; |
4432 |
|
4433 |
LMModelItem modelItem = connector.ModelItemObject; |
4434 |
LMSymbol connOtherSymbol = FindOtherConnectedSymbol(connector); |
4435 |
if (modelItem.get_ItemStatus() == "Active" && modelItem.get_ItemTypeName().ToString() == "PipeRun" && modelItem.Id != modelId && !temp.Contains(modelItem.Id)) |
4436 |
temp.Add(modelItem.Id); |
4437 |
|
4438 |
if (temp.Contains(modelItem.Id) && |
4439 |
connOtherSymbol != null && |
4440 |
connOtherSymbol.get_RepresentationType() == "Branch" && |
4441 |
Convert.ToBoolean(connector.get_IsZeroLength())) |
4442 |
temp.Remove(modelItem.Id); |
4443 |
|
4444 |
if (temp.Contains(modelItem.Id)) |
4445 |
connectors.Add(connector); |
4446 |
ReleaseCOMObjects(connOtherSymbol); |
4447 |
connOtherSymbol = null; |
4448 |
ReleaseCOMObjects(modelItem); |
4449 |
modelItem = null; |
4450 |
} |
4451 |
|
4452 |
|
4453 |
List<string> result = new List<string>(); |
4454 |
string originalName = GetSPPIDFileName(modelId); |
4455 |
foreach (var connector in connectors) |
4456 |
{ |
4457 |
string fileName = GetSPPIDFileName(connector.ModelItemID); |
4458 |
if (originalName == fileName) |
4459 |
result.Add(connector.ModelItemID); |
4460 |
else |
4461 |
{ |
4462 |
if (document.LINES.Find(x => x.SPPID.ModelItemId == connector.ModelItemID) == null && Convert.ToBoolean(connector.get_IsZeroLength())) |
4463 |
result.Add(connector.ModelItemID); |
4464 |
else |
4465 |
{ |
4466 |
Line line1 = document.LINES.Find(x => x.SPPID.ModelItemId == modelId); |
4467 |
Line line2 = document.LINES.Find(x => x.SPPID.ModelItemId == connector.ModelItemID.ToString()); |
4468 |
if (line1 != null && line2 != null && line1.TYPE == line2.TYPE) |
4469 |
result.Add(connector.ModelItemID); |
4470 |
} |
4471 |
} |
4472 |
} |
4473 |
|
4474 |
foreach (var connector in connectors) |
4475 |
ReleaseCOMObjects(connector); |
4476 |
|
4477 |
return result; |
4478 |
|
4479 |
|
4480 |
LMSymbol FindOtherConnectedSymbol(LMConnector connector) |
4481 |
{ |
4482 |
LMSymbol findResult = null; |
4483 |
if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.Id != symbol.Id && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active") |
4484 |
findResult = connector.ConnectItem1SymbolObject; |
4485 |
else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.Id != symbol.Id && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active") |
4486 |
findResult = connector.ConnectItem2SymbolObject; |
4487 |
|
4488 |
return findResult; |
4489 |
} |
4490 |
} |
4491 |
|
4492 |
/// <summary> |
4493 |
/// PipeRun의 좌표를 가져오는 메서드 |
4494 |
/// </summary> |
4495 |
/// <param name="modelId"></param> |
4496 |
/// <returns></returns> |
4497 |
private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId, bool ContainZeroLength = true) |
4498 |
{ |
4499 |
Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>(); |
4500 |
LMModelItem modelItem = dataSource.GetModelItem(modelId); |
4501 |
|
4502 |
if (modelItem != null) |
4503 |
{ |
4504 |
foreach (LMRepresentation rep in modelItem.Representations) |
4505 |
{ |
4506 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
4507 |
{ |
4508 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
4509 |
if (!ContainZeroLength && Convert.ToBoolean(_LMConnector.get_IsZeroLength())) |
4510 |
{ |
4511 |
ReleaseCOMObjects(_LMConnector); |
4512 |
_LMConnector = null; |
4513 |
continue; |
4514 |
} |
4515 |
connectorVertices.Add(_LMConnector, new List<double[]>()); |
4516 |
dynamic OID = rep.get_GraphicOID().ToString(); |
4517 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
4518 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
4519 |
int verticesCount = lineStringGeometry.VertexCount; |
4520 |
double[] vertices = null; |
4521 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
4522 |
for (int i = 0; i < verticesCount; i++) |
4523 |
{ |
4524 |
double x = 0; |
4525 |
double y = 0; |
4526 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
4527 |
connectorVertices[_LMConnector].Add(new double[] { x, y }); |
4528 |
} |
4529 |
} |
4530 |
} |
4531 |
|
4532 |
ReleaseCOMObjects(modelItem); |
4533 |
} |
4534 |
|
4535 |
return connectorVertices; |
4536 |
} |
4537 |
|
4538 |
private List<double[]> GetConnectorVertices(LMConnector connector) |
4539 |
{ |
4540 |
List<double[]> vertices = new List<double[]>(); |
4541 |
if (connector != null) |
4542 |
{ |
4543 |
dynamic OID = connector.get_GraphicOID().ToString(); |
4544 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
4545 |
if (drawingObject != null) |
4546 |
{ |
4547 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
4548 |
int verticesCount = lineStringGeometry.VertexCount; |
4549 |
double[] value = null; |
4550 |
lineStringGeometry.GetVertices(ref verticesCount, ref value); |
4551 |
for (int i = 0; i < verticesCount; i++) |
4552 |
{ |
4553 |
double x = 0; |
4554 |
double y = 0; |
4555 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
4556 |
vertices.Add(new double[] { x, y }); |
4557 |
} |
4558 |
} |
4559 |
} |
4560 |
return vertices; |
4561 |
} |
4562 |
|
4563 |
private double GetConnectorDistance(LMConnector connector) |
4564 |
{ |
4565 |
double result = 0; |
4566 |
List<double[]> vertices = new List<double[]>(); |
4567 |
if (connector != null) |
4568 |
{ |
4569 |
dynamic OID = connector.get_GraphicOID().ToString(); |
4570 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
4571 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
4572 |
int verticesCount = lineStringGeometry.VertexCount; |
4573 |
double[] value = null; |
4574 |
lineStringGeometry.GetVertices(ref verticesCount, ref value); |
4575 |
for (int i = 0; i < verticesCount; i++) |
4576 |
{ |
4577 |
double x = 0; |
4578 |
double y = 0; |
4579 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
4580 |
vertices.Add(new double[] { x, y }); |
4581 |
if (vertices.Count > 1) |
4582 |
{ |
4583 |
result += SPPIDUtil.CalcPointToPointdDistance(vertices[vertices.Count - 2][0], vertices[vertices.Count - 2][1], x, y); |
4584 |
} |
4585 |
} |
4586 |
} |
4587 |
return result; |
4588 |
} |
4589 |
private double[] GetConnectorRange(LMConnector connector) |
4590 |
{ |
4591 |
double[] result = null; |
4592 |
List<double[]> vertices = new List<double[]>(); |
4593 |
if (connector != null) |
4594 |
{ |
4595 |
dynamic OID = connector.get_GraphicOID().ToString(); |
4596 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
4597 |
double minX = 0; |
4598 |
double minY = 0; |
4599 |
double maxX = 0; |
4600 |
double maxY = 0; |
4601 |
|
4602 |
drawingObject.Range(out minX, out minY, out maxX, out maxY); |
4603 |
result = new double[] { minX, minY, maxX, maxY }; |
4604 |
} |
4605 |
return result; |
4606 |
} |
4607 |
private List<double[]> GetConnectorVertices(dynamic graphicOID) |
4608 |
{ |
4609 |
List<double[]> vertices = null; |
4610 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID]; |
4611 |
if (drawingObject != null) |
4612 |
{ |
4613 |
vertices = new List<double[]>(); |
4614 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
4615 |
int verticesCount = lineStringGeometry.VertexCount; |
4616 |
double[] value = null; |
4617 |
lineStringGeometry.GetVertices(ref verticesCount, ref value); |
4618 |
for (int i = 0; i < verticesCount; i++) |
4619 |
{ |
4620 |
double x = 0; |
4621 |
double y = 0; |
4622 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
4623 |
vertices.Add(new double[] { x, y }); |
4624 |
} |
4625 |
} |
4626 |
return vertices; |
4627 |
} |
4628 |
/// <summary> |
4629 |
/// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식 |
4630 |
/// </summary> |
4631 |
/// <param name="connectorVertices"></param> |
4632 |
/// <param name="connX"></param> |
4633 |
/// <param name="connY"></param> |
4634 |
/// <returns></returns> |
4635 |
private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY) |
4636 |
{ |
4637 |
double length = double.MaxValue; |
4638 |
LMConnector targetConnector = null; |
4639 |
foreach (var item in connectorVertices) |
4640 |
{ |
4641 |
List<double[]> points = item.Value; |
4642 |
for (int i = 0; i < points.Count - 1; i++) |
4643 |
{ |
4644 |
double[] point1 = points[i]; |
4645 |
double[] point2 = points[i + 1]; |
4646 |
double x1 = Math.Min(point1[0], point2[0]); |
4647 |
double y1 = Math.Min(point1[1], point2[1]); |
4648 |
double x2 = Math.Max(point1[0], point2[0]); |
4649 |
double y2 = Math.Max(point1[1], point2[1]); |
4650 |
|
4651 |
if ((x1 <= connX && x2 >= connX) || |
4652 |
(y1 <= connY && y2 >= connY)) |
4653 |
{ |
4654 |
double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY); |
4655 |
if (length >= distance) |
4656 |
{ |
4657 |
targetConnector = item.Key; |
4658 |
length = distance; |
4659 |
} |
4660 |
|
4661 |
distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY); |
4662 |
if (length >= distance) |
4663 |
{ |
4664 |
targetConnector = item.Key; |
4665 |
length = distance; |
4666 |
} |
4667 |
} |
4668 |
} |
4669 |
} |
4670 |
|
4671 |
// 못찾았을때. |
4672 |
length = double.MaxValue; |
4673 |
if (targetConnector == null) |
4674 |
{ |
4675 |
foreach (var item in connectorVertices) |
4676 |
{ |
4677 |
List<double[]> points = item.Value; |
4678 |
|
4679 |
foreach (double[] point in points) |
4680 |
{ |
4681 |
double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY); |
4682 |
if (length >= distance) |
4683 |
{ |
4684 |
targetConnector = item.Key; |
4685 |
length = distance; |
4686 |
} |
4687 |
} |
4688 |
} |
4689 |
} |
4690 |
|
4691 |
return targetConnector; |
4692 |
} |
4693 |
|
4694 |
private LMConnector FindTargetLMConnectorForBranch(Line currentLine, Line targetLine, ref double x, ref double y) |
4695 |
{ |
4696 |
Dictionary<LMConnector, List<double[]>> vertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId); |
4697 |
if (vertices.Count == 0) |
4698 |
return null; |
4699 |
|
4700 |
double length = double.MaxValue; |
4701 |
LMConnector targetConnector = null; |
4702 |
double[] resultPoint = null; |
4703 |
List<double[]> targetVertices = null; |
4704 |
|
4705 |
// Vertices 포인트에 제일 가까운곳 |
4706 |
foreach (var item in vertices) |
4707 |
{ |
4708 |
List<double[]> points = item.Value; |
4709 |
for (int i = 0; i < points.Count; i++) |
4710 |
{ |
4711 |
double[] point = points[i]; |
4712 |
double tempX = point[0]; |
4713 |
double tempY = point[1]; |
4714 |
|
4715 |
double distance = SPPIDUtil.CalcPointToPointdDistance(tempX, tempY, x, y); |
4716 |
if (length >= distance) |
4717 |
{ |
4718 |
targetConnector = item.Key; |
4719 |
length = distance; |
4720 |
resultPoint = point; |
4721 |
targetVertices = item.Value; |
4722 |
} |
4723 |
} |
4724 |
} |
4725 |
|
4726 |
// Vertices Cross에 제일 가까운곳 |
4727 |
foreach (var item in vertices) |
4728 |
{ |
4729 |
List<double[]> points = item.Value; |
4730 |
for (int i = 0; i < points.Count - 1; i++) |
4731 |
{ |
4732 |
double[] point1 = points[i]; |
4733 |
double[] point2 = points[i + 1]; |
4734 |
|
4735 |
double maxLineX = Math.Max(point1[0], point2[0]); |
4736 |
double minLineX = Math.Min(point1[0], point2[0]); |
4737 |
double maxLineY = Math.Max(point1[1], point2[1]); |
4738 |
double minLineY = Math.Min(point1[1], point2[1]); |
4739 |
|
4740 |
SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY); |
4741 |
|
4742 |
double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(currentLine.SPPID.START_X, currentLine.SPPID.START_Y, currentLine.SPPID.END_X, currentLine.SPPID.END_Y, point1[0], point1[1], point2[0], point2[1]); |
4743 |
if (crossingPoint != null) |
4744 |
{ |
4745 |
double distance = SPPIDUtil.CalcPointToPointdDistance(crossingPoint[0], crossingPoint[1], x, y); |
4746 |
if (length >= distance) |
4747 |
{ |
4748 |
if (slope == SlopeType.Slope && |
4749 |
minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] && |
4750 |
minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
4751 |
{ |
4752 |
targetConnector = item.Key; |
4753 |
length = distance; |
4754 |
resultPoint = crossingPoint; |
4755 |
targetVertices = item.Value; |
4756 |
} |
4757 |
else if (slope == SlopeType.HORIZONTAL && |
4758 |
minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0]) |
4759 |
{ |
4760 |
targetConnector = item.Key; |
4761 |
length = distance; |
4762 |
resultPoint = crossingPoint; |
4763 |
targetVertices = item.Value; |
4764 |
} |
4765 |
else if (slope == SlopeType.VERTICAL && |
4766 |
minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
4767 |
{ |
4768 |
targetConnector = item.Key; |
4769 |
length = distance; |
4770 |
resultPoint = crossingPoint; |
4771 |
targetVertices = item.Value; |
4772 |
} |
4773 |
} |
4774 |
} |
4775 |
} |
4776 |
} |
4777 |
|
4778 |
foreach (var item in vertices) |
4779 |
if (item.Key != null && item.Key != targetConnector) |
4780 |
ReleaseCOMObjects(item.Key); |
4781 |
|
4782 |
if (SPPIDUtil.IsBranchLine(currentLine, targetLine)) |
4783 |
{ |
4784 |
double tempResultX = resultPoint[0]; |
4785 |
double tempResultY = resultPoint[1]; |
4786 |
SPPIDUtil.ConvertGridPoint(ref tempResultX, ref tempResultY); |
4787 |
|
4788 |
GridSetting gridSetting = GridSetting.GetInstance(); |
4789 |
for (int i = 0; i < targetVertices.Count; i++) |
4790 |
{ |
4791 |
double[] point = targetVertices[i]; |
4792 |
double tempX = targetVertices[i][0]; |
4793 |
double tempY = targetVertices[i][1]; |
4794 |
SPPIDUtil.ConvertGridPoint(ref tempX, ref tempY); |
4795 |
if (tempX == tempResultX && tempY == tempResultY) |
4796 |
{ |
4797 |
if (i == 0) |
4798 |
{ |
4799 |
LMSymbol connSymbol = targetConnector.ConnectItem1SymbolObject; |
4800 |
bool containZeroLength = false; |
4801 |
if (connSymbol != null) |
4802 |
{ |
4803 |
foreach (LMConnector connector in connSymbol.Connect1Connectors) |
4804 |
{ |
4805 |
if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true) |
4806 |
containZeroLength = true; |
4807 |
} |
4808 |
foreach (LMConnector connector in connSymbol.Connect2Connectors) |
4809 |
{ |
4810 |
if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true) |
4811 |
containZeroLength = true; |
4812 |
} |
4813 |
} |
4814 |
|
4815 |
if (connSymbol == null || |
4816 |
(connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") || |
4817 |
containZeroLength) |
4818 |
{ |
4819 |
bool bCalcX = false; |
4820 |
bool bCalcY = false; |
4821 |
if (targetLine.SlopeType == SlopeType.HORIZONTAL) |
4822 |
bCalcX = true; |
4823 |
else if (targetLine.SlopeType == SlopeType.VERTICAL) |
4824 |
bCalcY = true; |
4825 |
else |
4826 |
{ |
4827 |
bCalcX = true; |
4828 |
bCalcY = true; |
4829 |
} |
4830 |
|
4831 |
if (bCalcX) |
4832 |
{ |
4833 |
double nextX = targetVertices[i + 1][0]; |
4834 |
double newX = 0; |
4835 |
if (nextX > tempX) |
4836 |
{ |
4837 |
newX = tempX + gridSetting.Length; |
4838 |
if (newX > nextX) |
4839 |
newX = (point[0] + nextX) / 2; |
4840 |
} |
4841 |
else |
4842 |
{ |
4843 |
newX = tempX - gridSetting.Length; |
4844 |
if (newX < nextX) |
4845 |
newX = (point[0] + nextX) / 2; |
4846 |
} |
4847 |
resultPoint = new double[] { newX, resultPoint[1] }; |
4848 |
} |
4849 |
|
4850 |
if (bCalcY) |
4851 |
{ |
4852 |
double nextY = targetVertices[i + 1][1]; |
4853 |
double newY = 0; |
4854 |
if (nextY > tempY) |
4855 |
{ |
4856 |
newY = tempY + gridSetting.Length; |
4857 |
if (newY > nextY) |
4858 |
newY = (point[1] + nextY) / 2; |
4859 |
} |
4860 |
else |
4861 |
{ |
4862 |
newY = tempY - gridSetting.Length; |
4863 |
if (newY < nextY) |
4864 |
newY = (point[1] + nextY) / 2; |
4865 |
} |
4866 |
resultPoint = new double[] { resultPoint[0], newY }; |
4867 |
} |
4868 |
} |
4869 |
} |
4870 |
else if (i == targetVertices.Count - 1 && targetVertices.Count != 2) |
4871 |
{ |
4872 |
LMSymbol connSymbol = targetConnector.ConnectItem2SymbolObject; |
4873 |
bool containZeroLength = false; |
4874 |
if (connSymbol != null) |
4875 |
{ |
4876 |
foreach (LMConnector connector in connSymbol.Connect1Connectors) |
4877 |
{ |
4878 |
if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true) |
4879 |
containZeroLength = true; |
4880 |
} |
4881 |
foreach (LMConnector connector in connSymbol.Connect2Connectors) |
4882 |
{ |
4883 |
if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true) |
4884 |
containZeroLength = true; |
4885 |
} |
4886 |
} |
4887 |
|
4888 |
if (connSymbol == null || |
4889 |
(connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") || |
4890 |
containZeroLength) |
4891 |
{ |
4892 |
bool bCalcX = false; |
4893 |
bool bCalcY = false; |
4894 |
if (targetLine.SlopeType == SlopeType.HORIZONTAL) |
4895 |
bCalcX = true; |
4896 |
else if (targetLine.SlopeType == SlopeType.VERTICAL) |
4897 |
bCalcY = true; |
4898 |
else |
4899 |
{ |
4900 |
bCalcX = true; |
4901 |
bCalcY = true; |
4902 |
} |
4903 |
|
4904 |
if (bCalcX) |
4905 |
{ |
4906 |
double nextX = targetVertices[i - 1][0]; |
4907 |
double newX = 0; |
4908 |
if (nextX > tempX) |
4909 |
{ |
4910 |
newX = tempX + gridSetting.Length; |
4911 |
if (newX > nextX) |
4912 |
newX = (point[0] + nextX) / 2; |
4913 |
} |
4914 |
else |
4915 |
{ |
4916 |
newX = tempX - gridSetting.Length; |
4917 |
if (newX < nextX) |
4918 |
newX = (point[0] + nextX) / 2; |
4919 |
} |
4920 |
resultPoint = new double[] { newX, resultPoint[1] }; |
4921 |
} |
4922 |
|
4923 |
if (bCalcY) |
4924 |
{ |
4925 |
double nextY = targetVertices[i - 1][1]; |
4926 |
double newY = 0; |
4927 |
if (nextY > tempY) |
4928 |
{ |
4929 |
newY = tempY + gridSetting.Length; |
4930 |
if (newY > nextY) |
4931 |
newY = (point[1] + nextY) / 2; |
4932 |
} |
4933 |
else |
4934 |
{ |
4935 |
newY = tempY - gridSetting.Length; |
4936 |
if (newY < nextY) |
4937 |
newY = (point[1] + nextY) / 2; |
4938 |
} |
4939 |
resultPoint = new double[] { resultPoint[0], newY }; |
4940 |
} |
4941 |
} |
4942 |
} |
4943 |
break; |
4944 |
} |
4945 |
} |
4946 |
} |
4947 |
|
4948 |
x = resultPoint[0]; |
4949 |
y = resultPoint[1]; |
4950 |
|
4951 |
return targetConnector; |
4952 |
} |
4953 |
|
4954 |
private LMConnector GetLMConnectorOnlyOne(string modelItemID) |
4955 |
{ |
4956 |
LMConnector result = null; |
4957 |
List<LMConnector> connectors = new List<LMConnector>(); |
4958 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemID); |
4959 |
|
4960 |
if (modelItem != null) |
4961 |
{ |
4962 |
foreach (LMRepresentation rep in modelItem.Representations) |
4963 |
{ |
4964 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
4965 |
connectors.Add(dataSource.GetConnector(rep.Id)); |
4966 |
} |
4967 |
|
4968 |
ReleaseCOMObjects(modelItem); |
4969 |
} |
4970 |
|
4971 |
if (connectors.Count == 1) |
4972 |
result = connectors[0]; |
4973 |
else |
4974 |
foreach (var item in connectors) |
4975 |
ReleaseCOMObjects(item); |
4976 |
|
4977 |
return result; |
4978 |
} |
4979 |
|
4980 |
private LMConnector GetLMConnectorFirst(string modelItemID) |
4981 |
{ |
4982 |
LMConnector result = null; |
4983 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemID); |
4984 |
|
4985 |
if (modelItem != null) |
4986 |
{ |
4987 |
foreach (LMRepresentation rep in modelItem.Representations) |
4988 |
{ |
4989 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && |
4990 |
rep.Attributes["ItemStatus"].get_Value() == "Active") |
4991 |
{ |
4992 |
LMConnector connector = dataSource.GetConnector(rep.Id); |
4993 |
if (!Convert.ToBoolean(connector.get_IsZeroLength())) |
4994 |
{ |
4995 |
result = connector; |
4996 |
break; |
4997 |
} |
4998 |
else |
4999 |
{ |
5000 |
ReleaseCOMObjects(connector); |
5001 |
connector = null; |
5002 |
} |
5003 |
} |
5004 |
} |
5005 |
ReleaseCOMObjects(modelItem); |
5006 |
modelItem = null; |
5007 |
} |
5008 |
|
5009 |
return result; |
5010 |
} |
5011 |
|
5012 |
private int GetConnectorCount(string modelItemID) |
5013 |
{ |
5014 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemID); |
5015 |
int result = 0; |
5016 |
if (modelItem != null) |
5017 |
{ |
5018 |
foreach (LMRepresentation rep in modelItem.Representations) |
5019 |
{ |
5020 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
5021 |
result++; |
5022 |
ReleaseCOMObjects(rep); |
5023 |
} |
5024 |
ReleaseCOMObjects(modelItem); |
5025 |
} |
5026 |
|
5027 |
return result; |
5028 |
} |
5029 |
|
5030 |
public List<string> GetRepresentations(string modelItemID) |
5031 |
{ |
5032 |
List<string> result = new List<string>(); ; |
5033 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemID); |
5034 |
if (modelItem != null) |
5035 |
{ |
5036 |
foreach (LMRepresentation rep in modelItem.Representations) |
5037 |
{ |
5038 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
5039 |
result.Add(rep.Id); |
5040 |
} |
5041 |
ReleaseCOMObjects(modelItem); |
5042 |
} |
5043 |
|
5044 |
return result; |
5045 |
} |
5046 |
|
5047 |
private void LineNumberModeling(LineNumber lineNumber) |
5048 |
{ |
5049 |
Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line; |
5050 |
if (line != null) |
5051 |
{ |
5052 |
double x = 0; |
5053 |
double y = 0; |
5054 |
CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation); |
5055 |
|
5056 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId); |
5057 |
LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, x, y); |
5058 |
if (connectedLMConnector != null) |
5059 |
{ |
5060 |
Array points = new double[] { 0, x, y }; |
5061 |
lineNumber.SPPID.SPPID_X = x; |
5062 |
lineNumber.SPPID.SPPID_Y = y; |
5063 |
LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false); |
5064 |
|
5065 |
if (_LmLabelPresist != null) |
5066 |
{ |
5067 |
_LmLabelPresist.Commit(); |
5068 |
lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id; |
5069 |
ReleaseCOMObjects(_LmLabelPresist); |
5070 |
} |
5071 |
} |
5072 |
|
5073 |
foreach (var item in connectorVertices) |
5074 |
ReleaseCOMObjects(item.Key); |
5075 |
} |
5076 |
} |
5077 |
private void LineNumberCorrectModeling(LineNumber lineNumber) |
5078 |
{ |
5079 |
Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line; |
5080 |
if (line == null || line.SPPID.Vertices == null) |
5081 |
return; |
5082 |
|
5083 |
if (!string.IsNullOrEmpty(lineNumber.SPPID.RepresentationId)) |
5084 |
{ |
5085 |
LMLabelPersist removeLabel = dataSource.GetLabelPersist(lineNumber.SPPID.RepresentationId); |
5086 |
if (removeLabel != null) |
5087 |
{ |
5088 |
lineNumber.SPPID.SPPID_X = removeLabel.get_XCoordinate(); |
5089 |
lineNumber.SPPID.SPPID_Y = removeLabel.get_YCoordinate(); |
5090 |
|
5091 |
GridSetting gridSetting = GridSetting.GetInstance(); |
5092 |
LMConnector connector = dataSource.GetConnector(removeLabel.RepresentationID); |
5093 |
|
5094 |
double[] labelRange = null; |
5095 |
GetSPPIDSymbolRange(removeLabel, ref labelRange); |
5096 |
List<double[]> vertices = GetConnectorVertices(connector); |
5097 |
|
5098 |
double[] resultStart = null; |
5099 |
double[] resultEnd = null; |
5100 |
double distance = double.MaxValue; |
5101 |
for (int i = 0; i < vertices.Count - 1; i++) |
5102 |
{ |
5103 |
double[] startPoint = vertices[i]; |
5104 |
double[] endPoint = vertices[i + 1]; |
5105 |
foreach (var item in line.SPPID.Vertices) |
5106 |
{ |
5107 |
double[] lineStartPoint = item[0]; |
5108 |
double[] lineEndPoint = item[item.Count - 1]; |
5109 |
|
5110 |
double tempDistance = SPPIDUtil.CalcPointToPointdDistance(startPoint[0], startPoint[1], lineStartPoint[0], lineStartPoint[1]) + |
5111 |
SPPIDUtil.CalcPointToPointdDistance(endPoint[0], endPoint[1], lineEndPoint[0], lineEndPoint[1]); |
5112 |
if (tempDistance < distance) |
5113 |
{ |
5114 |
distance = tempDistance; |
5115 |
resultStart = startPoint; |
5116 |
resultEnd = endPoint; |
5117 |
} |
5118 |
tempDistance = SPPIDUtil.CalcPointToPointdDistance(startPoint[0], startPoint[1], lineEndPoint[0], lineEndPoint[1]) + |
5119 |
SPPIDUtil.CalcPointToPointdDistance(endPoint[0], endPoint[1], lineStartPoint[0], lineStartPoint[1]); |
5120 |
if (tempDistance < distance) |
5121 |
{ |
5122 |
distance = tempDistance; |
5123 |
resultStart = startPoint; |
5124 |
resultEnd = endPoint; |
5125 |
} |
5126 |
} |
5127 |
} |
5128 |
|
5129 |
if (resultStart != null && resultEnd != null) |
5130 |
{ |
5131 |
SlopeType slope = SPPIDUtil.CalcSlope(resultStart[0], resultStart[1], resultEnd[0], resultEnd[1]); |
5132 |
double lineStartX = 0; |
5133 |
double lineStartY = 0; |
5134 |
double lineEndX = 0; |
5135 |
double lineEndY = 0; |
5136 |
double lineNumberX = 0; |
5137 |
double lineNumberY = 0; |
5138 |
SPPIDUtil.ConvertPointBystring(line.STARTPOINT, ref lineStartX, ref lineStartY); |
5139 |
SPPIDUtil.ConvertPointBystring(line.ENDPOINT, ref lineEndX, ref lineEndY); |
5140 |
|
5141 |
double lineX = (lineStartX + lineEndX) / 2; |
5142 |
double lineY = (lineStartY + lineEndY) / 2; |
5143 |
lineNumberX = (lineNumber.X1 + lineNumber.X2) / 2; |
5144 |
lineNumberY = (lineNumber.Y1 + lineNumber.Y2) / 2; |
5145 |
|
5146 |
double SPPIDCenterX = (resultStart[0] + resultEnd[0]) / 2; |
5147 |
double SPPIDCenterY = (resultStart[1] + resultEnd[1]) / 2; |
5148 |
double labelCenterX = (labelRange[0] + labelRange[2]) / 2; |
5149 |
double labelCenterY = (labelRange[1] + labelRange[3]) / 2; |
5150 |
|
5151 |
double offsetX = 0; |
5152 |
double offsetY = 0; |
5153 |
if (slope == SlopeType.HORIZONTAL) |
5154 |
{ |
5155 |
// Line Number 아래 |
5156 |
if (lineY < lineNumberY) |
5157 |
{ |
5158 |
offsetX = labelCenterX - SPPIDCenterX; |
5159 |
offsetY = labelRange[3] - SPPIDCenterY + gridSetting.Length; |
5160 |
MoveLineNumber(lineNumber, offsetX, offsetY); |
5161 |
} |
5162 |
// Line Number 위 |
5163 |
else |
5164 |
{ |
5165 |
offsetX = labelCenterX - SPPIDCenterX; |
5166 |
offsetY = labelRange[1] - SPPIDCenterY - gridSetting.Length; |
5167 |
MoveLineNumber(lineNumber, offsetX, offsetY); |
5168 |
} |
5169 |
} |
5170 |
else if (slope == SlopeType.VERTICAL) |
5171 |
{ |
5172 |
// Line Number 오르쪽 |
5173 |
if (lineX < lineNumberX) |
5174 |
{ |
5175 |
offsetX = labelRange[0] - SPPIDCenterX - gridSetting.Length; |
5176 |
offsetY = labelCenterY - SPPIDCenterY; |
5177 |
MoveLineNumber(lineNumber, offsetX, offsetY); |
5178 |
} |
5179 |
// Line Number 왼쪽 |
5180 |
else |
5181 |
{ |
5182 |
offsetX = labelRange[2] - SPPIDCenterX + gridSetting.Length; |
5183 |
offsetY = labelCenterY - SPPIDCenterY; |
5184 |
MoveLineNumber(lineNumber, offsetX, offsetY); |
5185 |
} |
5186 |
} |
5187 |
|
5188 |
if (offsetY != 0 || offsetY != 0) |
5189 |
{ |
5190 |
if (connector.ConnectItem1SymbolObject != null && |
5191 |
connector.ConnectItem1SymbolObject.get_RepresentationType() == "OPC") |
5192 |
{ |
5193 |
Ingr.RAD2D.Symbol2d symbol = radApp.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()]; |
5194 |
|
5195 |
double x1, y1, x2, y2, originX, originY; |
5196 |
symbol.Range(out x1, out y1, out x2, out y2); |
5197 |
symbol.GetOrigin(out originX, out originY); |
5198 |
if (originX < lineNumber.SPPID.SPPID_X) |
5199 |
offsetX = -1 * (originX + gridSetting.Length * 30 - labelCenterX); |
5200 |
else |
5201 |
offsetX = -1 * (originX - gridSetting.Length * 30 - labelCenterX); |
5202 |
} |
5203 |
else if (connector.ConnectItem2SymbolObject != null && |
5204 |
connector.ConnectItem2SymbolObject.get_RepresentationType() == "OPC") |
5205 |
{ |
5206 |
Ingr.RAD2D.Symbol2d symbol = radApp.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()]; |
5207 |
|
5208 |
double x1, y1, x2, y2, originX, originY; |
5209 |
symbol.Range(out x1, out y1, out x2, out y2); |
5210 |
symbol.GetOrigin(out originX, out originY); |
5211 |
if (originX < lineNumber.SPPID.SPPID_X) |
5212 |
offsetX = -1 * (originX + gridSetting.Length * 30 - labelCenterX); |
5213 |
else |
5214 |
offsetX = -1 * (originX - gridSetting.Length * 30 - labelCenterX); |
5215 |
} |
5216 |
|
5217 |
radApp.ActiveSelectSet.RemoveAll(); |
5218 |
DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[removeLabel.get_GraphicOID().ToString()] as DependencyObject; |
5219 |
if (dependency != null) |
5220 |
{ |
5221 |
radApp.ActiveSelectSet.Add(dependency); |
5222 |
Ingr.RAD2D.Transform transform = dependency.GetTransform(); |
5223 |
transform.DefineByMove2d(-offsetX, -offsetY); |
5224 |
radApp.ActiveSelectSet.Transform(transform, true); |
5225 |
radApp.ActiveSelectSet.RemoveAll(); |
5226 |
} |
5227 |
} |
5228 |
|
5229 |
void MoveLineNumber(LineNumber moveLineNumber, double x, double y) |
5230 |
{ |
5231 |
moveLineNumber.SPPID.SPPID_X = moveLineNumber.SPPID.SPPID_X - x; |
5232 |
moveLineNumber.SPPID.SPPID_Y = moveLineNumber.SPPID.SPPID_Y - y; |
5233 |
} |
5234 |
} |
5235 |
|
5236 |
|
5237 |
ReleaseCOMObjects(connector); |
5238 |
connector = null; |
5239 |
} |
5240 |
|
5241 |
ReleaseCOMObjects(removeLabel); |
5242 |
removeLabel = null; |
5243 |
} |
5244 |
} |
5245 |
/// <summary> |
5246 |
/// Flow Mark Modeling |
5247 |
/// </summary> |
5248 |
/// <param name="line"></param> |
5249 |
private void FlowMarkModeling(Line line) |
5250 |
{ |
5251 |
if (line.FLOWMARK && !string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(_ETCSetting.FlowMarkSymbolPath)) |
5252 |
{ |
5253 |
LMConnector connector = GetLMConnectorOnlyOne(line.SPPID.ModelItemId); |
5254 |
if (connector != null) |
5255 |
{ |
5256 |
string mappingPath = _ETCSetting.FlowMarkSymbolPath; |
5257 |
List<double[]> vertices = GetConnectorVertices(connector); |
5258 |
vertices = vertices.FindAll(x => x[0] > 0 && x[1] > 0); |
5259 |
double[] point = vertices[vertices.Count - 1]; |
5260 |
Array array = new double[] { 0, point[0], point[1] }; |
5261 |
LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mappingPath, ref array, null, null, LabeledItem: connector.AsLMRepresentation()); |
5262 |
if (_LMLabelPersist != null) |
5263 |
{ |
5264 |
_LMLabelPersist.Commit(); |
5265 |
FlowMarkRepIds.Add(_LMLabelPersist.Id); |
5266 |
ReleaseCOMObjects(_LMLabelPersist); |
5267 |
} |
5268 |
} |
5269 |
} |
5270 |
} |
5271 |
|
5272 |
/// <summary> |
5273 |
/// Line Number 기준으로 모든 Item에 Line Number의 Attribute Input |
5274 |
/// </summary> |
5275 |
/// <param name="lineNumber"></param> |
5276 |
private void InputLineNumberAttribute(LineNumber lineNumber, List<string> endLine) |
5277 |
{ |
5278 |
lineNumber.ATTRIBUTES.Sort(SortAttribute); |
5279 |
int SortAttribute(BaseModel.Attribute a, BaseModel.Attribute b) |
5280 |
{ |
5281 |
if (a.ATTRIBUTE == "Tag Seq No") |
5282 |
return 1; |
5283 |
else if (b.ATTRIBUTE == "Tag Seq No") |
5284 |
return -1; |
5285 |
|
5286 |
return 0; |
5287 |
} |
5288 |
|
5289 |
foreach (LineRun run in lineNumber.RUNS) |
5290 |
{ |
5291 |
foreach (var item in run.RUNITEMS) |
5292 |
{ |
5293 |
if (item.GetType() == typeof(Line)) |
5294 |
{ |
5295 |
Line line = item as Line; |
5296 |
if (line != null && !endLine.Contains(line.SPPID.ModelItemId)) |
5297 |
{ |
5298 |
LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
5299 |
if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
5300 |
{ |
5301 |
foreach (var attribute in lineNumber.ATTRIBUTES) |
5302 |
{ |
5303 |
LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID); |
5304 |
if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
5305 |
{ |
5306 |
LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME]; |
5307 |
if (mapping.SPPIDATTRIBUTENAME == "OperFluidCode" && !string.IsNullOrEmpty(attribute.VALUE)) |
5308 |
{ |
5309 |
LMAAttribute _FluidSystemAttribute = _LMModelItem.Attributes["FluidSystem"]; |
5310 |
if (_FluidSystemAttribute != null) |
5311 |
{ |
5312 |
DataTable dt = SPPID_DB.GetFluidSystemInfo(attribute.VALUE); |
5313 |
if (dt.Rows.Count == 1) |
5314 |
{ |
5315 |
string fluidSystem = dt.Rows[0]["CODELIST_TEXT"].ToString(); |
5316 |
if (DBNull.Value.Equals(_FluidSystemAttribute.get_Value())) |
5317 |
_FluidSystemAttribute.set_Value(fluidSystem); |
5318 |
else if (_FluidSystemAttribute.get_Value() != fluidSystem) |
5319 |
_FluidSystemAttribute.set_Value(fluidSystem); |
5320 |
|
5321 |
if (_LMAAttribute != null) |
5322 |
{ |
5323 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
5324 |
_LMAAttribute.set_Value(attribute.VALUE); |
5325 |
else if (_LMAAttribute.get_Value() != attribute.VALUE) |
5326 |
_LMAAttribute.set_Value(attribute.VALUE); |
5327 |
} |
5328 |
} |
5329 |
if (dt != null) |
5330 |
dt.Dispose(); |
5331 |
} |
5332 |
} |
5333 |
else if (mapping.SPPIDATTRIBUTENAME.Equals("NominalDiameter") && !string.IsNullOrEmpty(attribute.VALUE) && _LMAAttribute != null) |
5334 |
{ |
5335 |
DataRow[] rows = nominalDiameterTable.Select(string.Format("MetricStr = '{0}' OR InchStr = '{0}'", attribute.VALUE)); |
5336 |
|
5337 |
if (rows.Length.Equals(1)) |
5338 |
{ |
5339 |
if (_ETCSetting.UnitSetting != null && _ETCSetting.UnitSetting.Equals("Metric")) |
5340 |
attribute.VALUE = rows[0]["MetricStr"].ToString(); |
5341 |
else |
5342 |
attribute.VALUE = rows[0]["InchStr"].ToString(); |
5343 |
|
5344 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
5345 |
_LMAAttribute.set_Value(attribute.VALUE); |
5346 |
else if (_LMAAttribute.get_Value() != attribute.VALUE) |
5347 |
_LMAAttribute.set_Value(attribute.VALUE); |
5348 |
} |
5349 |
} |
5350 |
else if (_LMAAttribute != null) |
5351 |
{ |
5352 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
5353 |
_LMAAttribute.set_Value(attribute.VALUE); |
5354 |
else if (_LMAAttribute.get_Value() != attribute.VALUE) |
5355 |
_LMAAttribute.set_Value(attribute.VALUE); |
5356 |
} |
5357 |
} |
5358 |
} |
5359 |
_LMModelItem.Commit(); |
5360 |
} |
5361 |
if (_LMModelItem != null) |
5362 |
ReleaseCOMObjects(_LMModelItem); |
5363 |
endLine.Add(line.SPPID.ModelItemId); |
5364 |
} |
5365 |
} |
5366 |
} |
5367 |
} |
5368 |
} |
5369 |
|
5370 |
/// <summary> |
5371 |
/// Symbol Attribute 입력 메서드 |
5372 |
/// </summary> |
5373 |
/// <param name="item"></param> |
5374 |
private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes) |
5375 |
{ |
5376 |
// Object 아이템이 Symbol일 경우 Equipment일 경우 |
5377 |
string sRep = null; |
5378 |
string sModelID = null; |
5379 |
if (targetItem.GetType() == typeof(Symbol)) |
5380 |
sRep = ((Symbol)targetItem).SPPID.RepresentationId; |
5381 |
else if (targetItem.GetType() == typeof(Equipment)) |
5382 |
sRep = ((Equipment)targetItem).SPPID.RepresentationId; |
5383 |
else if (targetItem.GetType() == typeof(Line)) |
5384 |
sModelID = ((Line)targetItem).SPPID.ModelItemId; |
5385 |
|
5386 |
if (!string.IsNullOrEmpty(sRep)) |
5387 |
{ |
5388 |
LMSymbol _LMSymbol = dataSource.GetSymbol(sRep); |
5389 |
LMModelItem _LMModelItem = _LMSymbol.ModelItemObject; |
5390 |
LMAAttributes _Attributes = _LMModelItem.Attributes; |
5391 |
|
5392 |
foreach (var item in targetAttributes) |
5393 |
{ |
5394 |
AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID); |
5395 |
if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None") |
5396 |
{ |
5397 |
if (!mapping.IsText) |
5398 |
{ |
5399 |
LMAAttribute _LMAAttribute = _Attributes[mapping.SPPIDATTRIBUTENAME]; |
5400 |
if (mapping.SPPIDATTRIBUTENAME.Equals("NominalDiameter") && !string.IsNullOrEmpty(item.VALUE) && _LMAAttribute != null) |
5401 |
{ |
5402 |
DataRow[] rows = nominalDiameterTable.Select(string.Format("MetricStr = '{0}' OR InchStr = '{0}'", item.VALUE)); |
5403 |
|
5404 |
if (rows.Length.Equals(1)) |
5405 |
{ |
5406 |
if (_ETCSetting.UnitSetting != null && _ETCSetting.UnitSetting.Equals("Metric")) |
5407 |
item.VALUE = rows[0]["MetricStr"].ToString(); |
5408 |
else |
5409 |
item.VALUE = rows[0]["InchStr"].ToString(); |
5410 |
|
5411 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
5412 |
_LMAAttribute.set_Value(item.VALUE); |
5413 |
else if (_LMAAttribute.get_Value() != item.VALUE) |
5414 |
_LMAAttribute.set_Value(item.VALUE); |
5415 |
} |
5416 |
} |
5417 |
else if (_LMAAttribute != null) |
5418 |
{ |
5419 |
_LMAAttribute.set_Value(item.VALUE); |
5420 |
// OPC 일경우 Attribute 저장 |
5421 |
if (targetItem.GetType() == typeof(Symbol)) |
5422 |
{ |
5423 |
Symbol symbol = targetItem as Symbol; |
5424 |
if (symbol.TYPE == "Piping OPC's" || symbol.TYPE == "Instrument OPC's") |
5425 |
symbol.SPPID.Attributes.Add(new string[] { mapping.SPPIDATTRIBUTENAME, item.VALUE }); |
5426 |
} |
5427 |
} |
5428 |
} |
5429 |
else |
5430 |
DefaultTextModeling(item.VALUE, _LMSymbol.get_XCoordinate(), _LMSymbol.get_YCoordinate()); |
5431 |
} |
5432 |
} |
5433 |
_LMModelItem.Commit(); |
5434 |
|
5435 |
ReleaseCOMObjects(_Attributes); |
5436 |
ReleaseCOMObjects(_LMModelItem); |
5437 |
ReleaseCOMObjects(_LMSymbol); |
5438 |
} |
5439 |
else if (!string.IsNullOrEmpty(sModelID)) |
5440 |
{ |
5441 |
LMModelItem _LMModelItem = dataSource.GetModelItem(sModelID); |
5442 |
LMAAttributes _Attributes = _LMModelItem.Attributes; |
5443 |
|
5444 |
foreach (var item in targetAttributes) |
5445 |
{ |
5446 |
AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID); |
5447 |
if (mapping == null) |
5448 |
continue; |
5449 |
|
5450 |
LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME]; |
5451 |
if (mapping.SPPIDATTRIBUTENAME == "OperFluidCode" && !string.IsNullOrEmpty(item.VALUE)) |
5452 |
{ |
5453 |
LMAAttribute _FluidSystemAttribute = _LMModelItem.Attributes["FluidSystem"]; |
5454 |
if (_FluidSystemAttribute != null) |
5455 |
{ |
5456 |
DataTable dt = SPPID_DB.GetFluidSystemInfo(item.VALUE); |
5457 |
if (dt.Rows.Count == 1) |
5458 |
{ |
5459 |
string fluidSystem = dt.Rows[0]["CODELIST_TEXT"].ToString(); |
5460 |
if (DBNull.Value.Equals(_FluidSystemAttribute.get_Value())) |
5461 |
_FluidSystemAttribute.set_Value(fluidSystem); |
5462 |
else if (_FluidSystemAttribute.get_Value() != fluidSystem) |
5463 |
_FluidSystemAttribute.set_Value(fluidSystem); |
5464 |
|
5465 |
if (_LMAAttribute != null) |
5466 |
{ |
5467 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
5468 |
_LMAAttribute.set_Value(item.VALUE); |
5469 |
else if (_LMAAttribute.get_Value() != item.VALUE) |
5470 |
_LMAAttribute.set_Value(item.VALUE); |
5471 |
} |
5472 |
} |
5473 |
if (dt != null) |
5474 |
dt.Dispose(); |
5475 |
} |
5476 |
} |
5477 |
else if (mapping.SPPIDATTRIBUTENAME.Equals("NominalDiameter") && !string.IsNullOrEmpty(item.VALUE) && _LMAAttribute != null) |
5478 |
{ |
5479 |
DataRow[] rows = nominalDiameterTable.Select(string.Format("MetricStr = '{0}' OR InchStr = '{0}'", item.VALUE)); |
5480 |
|
5481 |
if (rows.Length.Equals(1)) |
5482 |
{ |
5483 |
if (_ETCSetting.UnitSetting != null && _ETCSetting.UnitSetting.Equals("Metric")) |
5484 |
item.VALUE = rows[0]["MetricStr"].ToString(); |
5485 |
else |
5486 |
item.VALUE = rows[0]["InchStr"].ToString(); |
5487 |
|
5488 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
5489 |
_LMAAttribute.set_Value(item.VALUE); |
5490 |
else if (_LMAAttribute.get_Value() != item.VALUE) |
5491 |
_LMAAttribute.set_Value(item.VALUE); |
5492 |
} |
5493 |
} |
5494 |
else if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None") |
5495 |
{ |
5496 |
if (!mapping.IsText) |
5497 |
{ |
5498 |
LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME]; |
5499 |
if (_Attribute != null) |
5500 |
_Attribute.set_Value(item.VALUE); |
5501 |
} |
5502 |
} |
5503 |
} |
5504 |
_LMModelItem.Commit(); |
5505 |
|
5506 |
ReleaseCOMObjects(_Attributes); |
5507 |
ReleaseCOMObjects(_LMModelItem); |
5508 |
} |
5509 |
} |
5510 |
|
5511 |
/// <summary> |
5512 |
/// Input SpecBreak Attribute |
5513 |
/// </summary> |
5514 |
/// <param name="specBreak"></param> |
5515 |
private void InputSpecBreakAttribute(SpecBreak specBreak) |
5516 |
{ |
5517 |
object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID); |
5518 |
object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID); |
5519 |
|
5520 |
if (upStreamObj != null && |
5521 |
downStreamObj != null) |
5522 |
{ |
5523 |
LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj); |
5524 |
|
5525 |
if (targetLMConnector != null) |
5526 |
{ |
5527 |
foreach (LMLabelPersist _LMLabelPersist in targetLMConnector.LabelPersists) |
5528 |
{ |
5529 |
string symbolPath = _LMLabelPersist.get_FileName(); |
5530 |
AttributeMapping mapping = document.AttributeMappings.Find(x => x.SPPIDSYMBOLNAME == symbolPath); |
5531 |
if (mapping != null) |
5532 |
{ |
5533 |
BaseModel.Attribute attribute = specBreak.ATTRIBUTES.Find(y => y.UID == mapping.UID); |
5534 |
if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
5535 |
{ |
5536 |
string[] values = attribute.VALUE.Split(new char[] { ',' }); |
5537 |
if (values.Length == 2) |
5538 |
{ |
5539 |
string upStreamValue = values[0]; |
5540 |
string downStreamValue = values[1]; |
5541 |
|
5542 |
InputAttributeForSpecBreak(upStreamObj, downStreamObj, upStreamValue, downStreamValue, mapping.SPPIDATTRIBUTENAME); |
5543 |
} |
5544 |
} |
5545 |
} |
5546 |
} |
5547 |
|
5548 |
ReleaseCOMObjects(targetLMConnector); |
5549 |
} |
5550 |
} |
5551 |
|
5552 |
|
5553 |
#region 내부에서만 쓰는 메서드 |
5554 |
void InputAttributeForSpecBreak(object _upStreamObj, object _downStreamObj, string upStreamValue, string downStreamValue, string sppidAttributeName) |
5555 |
{ |
5556 |
Symbol upStreamSymbol = _upStreamObj as Symbol; |
5557 |
Line upStreamLine = _upStreamObj as Line; |
5558 |
Symbol downStreamSymbol = _downStreamObj as Symbol; |
5559 |
Line downStreamLine = _downStreamObj as Line; |
5560 |
// 둘다 Line일 경우 |
5561 |
if (upStreamLine != null && downStreamLine != null) |
5562 |
{ |
5563 |
InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue); |
5564 |
InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue); |
5565 |
} |
5566 |
// 둘다 Symbol일 경우 |
5567 |
else if (upStreamSymbol != null && downStreamSymbol != null) |
5568 |
{ |
5569 |
LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamSymbol); |
5570 |
LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId); |
5571 |
LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId); |
5572 |
|
5573 |
foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors) |
5574 |
{ |
5575 |
if (connector.get_ItemStatus() != "Active") |
5576 |
continue; |
5577 |
|
5578 |
if (connector.Id != zeroLenthConnector.Id) |
5579 |
InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue); |
5580 |
} |
5581 |
|
5582 |
foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors) |
5583 |
{ |
5584 |
if (connector.get_ItemStatus() != "Active") |
5585 |
continue; |
5586 |
|
5587 |
if (connector.Id != zeroLenthConnector.Id) |
5588 |
InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue); |
5589 |
} |
5590 |
|
5591 |
foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors) |
5592 |
{ |
5593 |
if (connector.get_ItemStatus() != "Active") |
5594 |
continue; |
5595 |
|
5596 |
if (connector.Id != zeroLenthConnector.Id) |
5597 |
InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue); |
5598 |
} |
5599 |
|
5600 |
foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors) |
5601 |
{ |
5602 |
if (connector.get_ItemStatus() != "Active") |
5603 |
continue; |
5604 |
|
5605 |
if (connector.Id != zeroLenthConnector.Id) |
5606 |
InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue); |
5607 |
} |
5608 |
|
5609 |
ReleaseCOMObjects(zeroLenthConnector); |
5610 |
ReleaseCOMObjects(upStreamLMSymbol); |
5611 |
ReleaseCOMObjects(downStreamLMSymbol); |
5612 |
} |
5613 |
else if (upStreamSymbol != null && downStreamLine != null) |
5614 |
{ |
5615 |
LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamLine); |
5616 |
InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue); |
5617 |
LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId); |
5618 |
|
5619 |
foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors) |
5620 |
{ |
5621 |
if (connector.get_ItemStatus() != "Active") |
5622 |
continue; |
5623 |
|
5624 |
if (connector.Id == zeroLenthConnector.Id) |
5625 |
InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue); |
5626 |
} |
5627 |
|
5628 |
foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors) |
5629 |
{ |
5630 |
if (connector.get_ItemStatus() != "Active") |
5631 |
continue; |
5632 |
|
5633 |
if (connector.Id == zeroLenthConnector.Id) |
5634 |
InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue); |
5635 |
} |
5636 |
|
5637 |
ReleaseCOMObjects(zeroLenthConnector); |
5638 |
ReleaseCOMObjects(upStreamLMSymbol); |
5639 |
} |
5640 |
else if (upStreamLine != null && downStreamSymbol != null) |
5641 |
{ |
5642 |
LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamLine, downStreamSymbol); |
5643 |
InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue); |
5644 |
LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId); |
5645 |
|
5646 |
foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors) |
5647 |
{ |
5648 |
if (connector.get_ItemStatus() != "Active") |
5649 |
continue; |
5650 |
|
5651 |
if (connector.Id == zeroLenthConnector.Id) |
5652 |
InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue); |
5653 |
} |
5654 |
|
5655 |
foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors) |
5656 |
{ |
5657 |
if (connector.get_ItemStatus() != "Active") |
5658 |
continue; |
5659 |
|
5660 |
if (connector.Id == zeroLenthConnector.Id) |
5661 |
InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue); |
5662 |
} |
5663 |
|
5664 |
ReleaseCOMObjects(zeroLenthConnector); |
5665 |
ReleaseCOMObjects(downStreamLMSymbol); |
5666 |
} |
5667 |
} |
5668 |
|
5669 |
void InputLineAttributeForSpecBreakLine(Line line, string attrName, string value) |
5670 |
{ |
5671 |
LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
5672 |
if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
5673 |
{ |
5674 |
LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName]; |
5675 |
if (_LMAAttribute != null) |
5676 |
{ |
5677 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
5678 |
_LMAAttribute.set_Value(value); |
5679 |
else if (_LMAAttribute.get_Value() != value) |
5680 |
_LMAAttribute.set_Value(value); |
5681 |
} |
5682 |
|
5683 |
_LMModelItem.Commit(); |
5684 |
} |
5685 |
if (_LMModelItem != null) |
5686 |
ReleaseCOMObjects(_LMModelItem); |
5687 |
} |
5688 |
|
5689 |
void InputLineAttributeForSpecBreakLMConnector(LMConnector connector, string attrName, string value) |
5690 |
{ |
5691 |
LMModelItem _LMModelItem = dataSource.GetModelItem(connector.ModelItemID); |
5692 |
if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
5693 |
{ |
5694 |
LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName]; |
5695 |
if (_LMAAttribute != null) |
5696 |
{ |
5697 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
5698 |
_LMAAttribute.set_Value(value); |
5699 |
else if (_LMAAttribute.get_Value() != value) |
5700 |
_LMAAttribute.set_Value(value); |
5701 |
} |
5702 |
|
5703 |
_LMModelItem.Commit(); |
5704 |
} |
5705 |
if (_LMModelItem != null) |
5706 |
ReleaseCOMObjects(_LMModelItem); |
5707 |
} |
5708 |
#endregion |
5709 |
} |
5710 |
|
5711 |
private void InputEndBreakAttribute(EndBreak endBreak) |
5712 |
{ |
5713 |
object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER); |
5714 |
object connectedItem = SPPIDUtil.FindObjectByUID(document, endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE); |
5715 |
|
5716 |
if ((ownerObj.GetType() == typeof(Symbol) && connectedItem.GetType() == typeof(Line)) || |
5717 |
(ownerObj.GetType() == typeof(Line) && connectedItem.GetType() == typeof(Symbol))) |
5718 |
{ |
5719 |
LMLabelPersist labelPersist = dataSource.GetLabelPersist(endBreak.SPPID.RepresentationId); |
5720 |
if (labelPersist != null) |
5721 |
{ |
5722 |
LMRepresentation representation = labelPersist.RepresentationObject; |
5723 |
if (representation != null) |
5724 |
{ |
5725 |
LMConnector connector = dataSource.GetConnector(representation.Id); |
5726 |
LMModelItem ZeroLengthModelItem = connector.ModelItemObject; |
5727 |
string modelItemID = connector.ModelItemID; |
5728 |
if (Convert.ToBoolean(connector.get_IsZeroLength())) |
5729 |
{ |
5730 |
List<string> modelItemIDs = new List<string>(); |
5731 |
if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch") |
5732 |
{ |
5733 |
LMSymbol symbol = connector.ConnectItem1SymbolObject; |
5734 |
foreach (LMConnector item in symbol.Connect1Connectors) |
5735 |
{ |
5736 |
if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID) |
5737 |
modelItemIDs.Add(item.ModelItemID); |
5738 |
ReleaseCOMObjects(item); |
5739 |
} |
5740 |
foreach (LMConnector item in symbol.Connect2Connectors) |
5741 |
{ |
5742 |
if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID) |
5743 |
modelItemIDs.Add(item.ModelItemID); |
5744 |
ReleaseCOMObjects(item); |
5745 |
} |
5746 |
ReleaseCOMObjects(symbol); |
5747 |
symbol = null; |
5748 |
} |
5749 |
else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch") |
5750 |
{ |
5751 |
LMSymbol symbol = connector.ConnectItem2SymbolObject; |
5752 |
foreach (LMConnector item in symbol.Connect1Connectors) |
5753 |
{ |
5754 |
if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID) |
5755 |
modelItemIDs.Add(item.ModelItemID); |
5756 |
ReleaseCOMObjects(item); |
5757 |
} |
5758 |
foreach (LMConnector item in symbol.Connect2Connectors) |
5759 |
{ |
5760 |
if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID) |
5761 |
modelItemIDs.Add(item.ModelItemID); |
5762 |
ReleaseCOMObjects(item); |
5763 |
} |
5764 |
ReleaseCOMObjects(symbol); |
5765 |
symbol = null; |
5766 |
} |
5767 |
|
5768 |
modelItemIDs = modelItemIDs.Distinct().ToList(); |
5769 |
if (modelItemIDs.Count == 1) |
5770 |
{ |
5771 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemIDs[0]); |
5772 |
LMConnector onlyOne = GetLMConnectorOnlyOne(modelItem.Id); |
5773 |
if (onlyOne != null && Convert.ToBoolean(onlyOne.get_IsZeroLength())) |
5774 |
{ |
5775 |
bool result = false; |
5776 |
foreach (LMLabelPersist loop in onlyOne.LabelPersists) |
5777 |
{ |
5778 |
if (document.EndBreaks.Find(x => x.SPPID.RepresentationId == loop.RepresentationID) != null) |
5779 |
result = true; |
5780 |
ReleaseCOMObjects(loop); |
5781 |
} |
5782 |
|
5783 |
if (result) |
5784 |
{ |
5785 |
object value = modelItem.Attributes["TagSequenceNo"].get_Value(); |
5786 |
ZeroLengthModelItem.Attributes["TagSequenceNo"].set_Value(value); |
5787 |
//object value2 = modelItem.Attributes["SubUnitNumber"].get_Value(); |
5788 |
//ZeroLengthModelItem.Attributes["SubUnitNumber"].set_Value(value2); |
5789 |
ZeroLengthModelItem.Commit(); |
5790 |
} |
5791 |
else |
5792 |
{ |
5793 |
List<string> loopModelItems = new List<string>(); |
5794 |
if (onlyOne.ConnectItem1SymbolObject.get_RepresentationType() == "Branch") |
5795 |
{ |
5796 |
LMSymbol _symbol = onlyOne.ConnectItem1SymbolObject; |
5797 |
foreach (LMConnector loop in _symbol.Connect1Connectors) |
5798 |
{ |
5799 |
if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID) |
5800 |
loopModelItems.Add(loop.ModelItemID); |
5801 |
ReleaseCOMObjects(loop); |
5802 |
} |
5803 |
foreach (LMConnector loop in _symbol.Connect2Connectors) |
5804 |
{ |
5805 |
if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID) |
5806 |
loopModelItems.Add(loop.ModelItemID); |
5807 |
ReleaseCOMObjects(loop); |
5808 |
} |
5809 |
ReleaseCOMObjects(_symbol); |
5810 |
_symbol = null; |
5811 |
} |
5812 |
else if (onlyOne.ConnectItem2SymbolObject.get_RepresentationType() == "Branch") |
5813 |
{ |
5814 |
LMSymbol _symbol = onlyOne.ConnectItem2SymbolObject; |
5815 |
foreach (LMConnector loop in _symbol.Connect1Connectors) |
5816 |
{ |
5817 |
if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID) |
5818 |
loopModelItems.Add(loop.ModelItemID); |
5819 |
ReleaseCOMObjects(loop); |
5820 |
} |
5821 |
foreach (LMConnector loop in _symbol.Connect2Connectors) |
5822 |
{ |
5823 |
if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID) |
5824 |
loopModelItems.Add(loop.ModelItemID); |
5825 |
ReleaseCOMObjects(loop); |
5826 |
} |
5827 |
ReleaseCOMObjects(_symbol); |
5828 |
_symbol = null; |
5829 |
} |
5830 |
|
5831 |
loopModelItems = loopModelItems.Distinct().ToList(); |
5832 |
if (loopModelItems.Count == 1) |
5833 |
{ |
5834 |
LMModelItem loopModelItem = dataSource.GetModelItem(loopModelItems[0]); |
5835 |
object value = loopModelItem.Attributes["TagSequenceNo"].get_Value(); |
5836 |
//object value2 = loopModelItem.Attributes["SubUnitNumber"].get_Value(); |
5837 |
modelItem.Attributes["TagSequenceNo"].set_Value(value); |
5838 |
//modelItem.Attributes["SubUnitNumber"].set_Value(value2); |
5839 |
modelItem.Commit(); |
5840 |
ZeroLengthModelItem.Attributes["TagSequenceNo"].set_Value(value); |
5841 |
//ZeroLengthModelItem.Attributes["SubUnitNumber"].set_Value(value2); |
5842 |
ZeroLengthModelItem.Commit(); |
5843 |
|
5844 |
ReleaseCOMObjects(loopModelItem); |
5845 |
loopModelItem = null; |
5846 |
} |
5847 |
} |
5848 |
} |
5849 |
else |
5850 |
{ |
5851 |
object value = modelItem.Attributes["TagSequenceNo"].get_Value(); |
5852 |
ZeroLengthModelItem.Attributes["TagSequenceNo"].set_Value(value); |
5853 |
//object value2 = modelItem.Attributes["SubUnitNumber"].get_Value(); |
5854 |
//ZeroLengthModelItem.Attributes["SubUnitNumber"].set_Value(value2); |
5855 |
ZeroLengthModelItem.Commit(); |
5856 |
} |
5857 |
ReleaseCOMObjects(modelItem); |
5858 |
modelItem = null; |
5859 |
ReleaseCOMObjects(onlyOne); |
5860 |
onlyOne = null; |
5861 |
} |
5862 |
} |
5863 |
ReleaseCOMObjects(connector); |
5864 |
connector = null; |
5865 |
ReleaseCOMObjects(ZeroLengthModelItem); |
5866 |
ZeroLengthModelItem = null; |
5867 |
} |
5868 |
ReleaseCOMObjects(representation); |
5869 |
representation = null; |
5870 |
} |
5871 |
ReleaseCOMObjects(labelPersist); |
5872 |
labelPersist = null; |
5873 |
} |
5874 |
} |
5875 |
|
5876 |
/// <summary> |
5877 |
/// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링 |
5878 |
/// </summary> |
5879 |
/// <param name="text"></param> |
5880 |
private void NormalTextModeling(Text text) |
5881 |
{ |
5882 |
LMSymbol _LMSymbol = null; |
5883 |
|
5884 |
LMItemNote _LMItemNote = null; |
5885 |
LMAAttribute _LMAAttribute = null; |
5886 |
|
5887 |
double x = 0; |
5888 |
double y = 0; |
5889 |
double angle = text.ANGLE; |
5890 |
CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation); |
5891 |
|
5892 |
SPPIDUtil.ConvertGridPoint(ref x, ref y); |
5893 |
text.SPPID.SPPID_X = x; |
5894 |
text.SPPID.SPPID_Y = y; |
5895 |
|
5896 |
_LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y, Rotation: angle); |
5897 |
if (_LMSymbol != null) |
5898 |
{ |
5899 |
_LMSymbol.Commit(); |
5900 |
_LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
5901 |
if (_LMItemNote != null) |
5902 |
{ |
5903 |
_LMItemNote.Commit(); |
5904 |
_LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
5905 |
if (_LMAAttribute != null) |
5906 |
{ |
5907 |
_LMAAttribute.set_Value(text.VALUE); |
5908 |
text.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
5909 |
_LMItemNote.Commit(); |
5910 |
|
5911 |
|
5912 |
double[] range = null; |
5913 |
foreach (LMLabelPersist labelPersist in _LMSymbol.LabelPersists) |
5914 |
{ |
5915 |
double[] temp = null; |
5916 |
GetSPPIDSymbolRange(labelPersist, ref temp); |
5917 |
if (temp != null) |
5918 |
{ |
5919 |
if (range == null) |
5920 |
range = temp; |
5921 |
else |
5922 |
{ |
5923 |
range = new double[] { |
5924 |
Math.Min(range[0], temp[0]), |
5925 |
Math.Min(range[1], temp[1]), |
5926 |
Math.Max(range[2], temp[2]), |
5927 |
Math.Max(range[3], temp[3]) |
5928 |
}; |
5929 |
} |
5930 |
} |
5931 |
} |
5932 |
text.SPPID.Range = range; |
5933 |
|
5934 |
if (_LMAAttribute != null) |
5935 |
ReleaseCOMObjects(_LMAAttribute); |
5936 |
if (_LMItemNote != null) |
5937 |
ReleaseCOMObjects(_LMItemNote); |
5938 |
} |
5939 |
|
5940 |
TextCorrectModeling(text); |
5941 |
} |
5942 |
} |
5943 |
if (_LMSymbol != null) |
5944 |
ReleaseCOMObjects(_LMSymbol); |
5945 |
} |
5946 |
|
5947 |
private void DefaultTextModeling(string value, double x, double y) |
5948 |
{ |
5949 |
LMSymbol _LMSymbol = null; |
5950 |
|
5951 |
LMItemNote _LMItemNote = null; |
5952 |
LMAAttribute _LMAAttribute = null; |
5953 |
|
5954 |
_LMSymbol = _placement.PIDPlaceSymbol(_ETCSetting.TextSymbolPath, x, y, Rotation: 0); |
5955 |
if (_LMSymbol != null) |
5956 |
{ |
5957 |
_LMSymbol.Commit(); |
5958 |
_LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
5959 |
if (_LMItemNote != null) |
5960 |
{ |
5961 |
_LMItemNote.Commit(); |
5962 |
_LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
5963 |
if (_LMAAttribute != null) |
5964 |
{ |
5965 |
_LMAAttribute.set_Value(value); |
5966 |
_LMItemNote.Commit(); |
5967 |
|
5968 |
if (_LMAAttribute != null) |
5969 |
ReleaseCOMObjects(_LMAAttribute); |
5970 |
if (_LMItemNote != null) |
5971 |
ReleaseCOMObjects(_LMItemNote); |
5972 |
} |
5973 |
} |
5974 |
} |
5975 |
if (_LMSymbol != null) |
5976 |
ReleaseCOMObjects(_LMSymbol); |
5977 |
} |
5978 |
|
5979 |
private void AssociationTextModeling(Text text) |
5980 |
{ |
5981 |
LMSymbol _LMSymbol = null; |
5982 |
LMConnector connectedLMConnector = null; |
5983 |
object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER); |
5984 |
if (owner != null && (owner.GetType() == typeof(Symbol) || owner.GetType() == typeof(Equipment))) |
5985 |
{ |
5986 |
Symbol symbol = owner as Symbol; |
5987 |
_LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
5988 |
if (_LMSymbol != null) |
5989 |
{ |
5990 |
foreach (BaseModel.Attribute attribute in symbol.ATTRIBUTES.FindAll(x => x.ASSOCITEM == text.UID)) |
5991 |
{ |
5992 |
if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
5993 |
{ |
5994 |
AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME)); |
5995 |
|
5996 |
if (mapping != null) |
5997 |
{ |
5998 |
double x = 0; |
5999 |
double y = 0; |
6000 |
|
6001 |
CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location); |
6002 |
SPPIDUtil.ConvertGridPoint(ref x, ref y); |
6003 |
Array array = new double[] { 0, x, y }; |
6004 |
text.SPPID.SPPID_X = x; |
6005 |
text.SPPID.SPPID_Y = y; |
6006 |
LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine); |
6007 |
if (_LMLabelPersist != null) |
6008 |
{ |
6009 |
text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id; |
6010 |
_LMLabelPersist.Commit(); |
6011 |
ReleaseCOMObjects(_LMLabelPersist); |
6012 |
} |
6013 |
} |
6014 |
} |
6015 |
} |
6016 |
} |
6017 |
} |
6018 |
else if (owner != null && owner.GetType() == typeof(Line)) |
6019 |
{ |
6020 |
Line line = owner as Line; |
6021 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId); |
6022 |
connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y); |
6023 |
|
6024 |
if (connectedLMConnector != null) |
6025 |
{ |
6026 |
foreach (BaseModel.Attribute attribute in line.ATTRIBUTES.FindAll(x => x.ASSOCITEM == text.UID)) |
6027 |
{ |
6028 |
if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
6029 |
{ |
6030 |
AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME)); |
6031 |
|
6032 |
if (mapping != null) |
6033 |
{ |
6034 |
double x = 0; |
6035 |
double y = 0; |
6036 |
CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location); |
6037 |
SPPIDUtil.ConvertGridPoint(ref x, ref y); |
6038 |
Array array = new double[] { 0, x, y }; |
6039 |
|
6040 |
LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine); |
6041 |
if (_LMLabelPersist != null) |
6042 |
{ |
6043 |
text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id; |
6044 |
_LMLabelPersist.Commit(); |
6045 |
|
6046 |
DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_LMLabelPersist.get_GraphicOID().ToString()] as DependencyObject; |
6047 |
if (dependency != null) |
6048 |
{ |
6049 |
radApp.ActiveSelectSet.RemoveAll(); |
6050 |
radApp.ActiveSelectSet.Add(dependency); |
6051 |
Ingr.RAD2D.Transform transform = dependency.GetTransform(); |
6052 |
transform.DefineByMove2d(x - _LMLabelPersist.get_XCoordinate(), y - _LMLabelPersist.get_YCoordinate()); |
6053 |
radApp.ActiveSelectSet.Transform(transform, true); |
6054 |
radApp.ActiveSelectSet.RemoveAll(); |
6055 |
} |
6056 |
|
6057 |
ReleaseCOMObjects(_LMLabelPersist); |
6058 |
} |
6059 |
} |
6060 |
} |
6061 |
} |
6062 |
} |
6063 |
} |
6064 |
if (_LMSymbol != null) |
6065 |
ReleaseCOMObjects(_LMSymbol); |
6066 |
} |
6067 |
|
6068 |
private void TextCorrectModeling(Text text) |
6069 |
{ |
6070 |
if (text.SPPID.Range == null) |
6071 |
return; |
6072 |
|
6073 |
bool needRemodeling = false; |
6074 |
bool loop = true; |
6075 |
GridSetting gridSetting = GridSetting.GetInstance(); |
6076 |
while (loop) |
6077 |
{ |
6078 |
loop = false; |
6079 |
foreach (var overlapText in document.TEXTINFOS) |
6080 |
{ |
6081 |
if (overlapText.ASSOCIATION || overlapText == text || overlapText.SPPID.Range == null) |
6082 |
continue; |
6083 |
|
6084 |
if (SPPIDUtil.IsOverlap(overlapText.SPPID.Range, text.SPPID.Range)) |
6085 |
{ |
6086 |
double percentX = 0; |
6087 |
double percentY = 0; |
6088 |
if (overlapText.X1 <= text.X2 && overlapText.X2 >= text.X1) |
6089 |
{ |
6090 |
double gapX = Math.Min(overlapText.X2, text.X2) - Math.Max(overlapText.X1, text.X1); |
6091 |
percentX = Math.Max(gapX / (overlapText.X2 - overlapText.X1), gapX / (text.X2 - text.X1)); |
6092 |
} |
6093 |
if (overlapText.Y1 <= text.Y2 && overlapText.Y2 >= text.Y1) |
6094 |
{ |
6095 |
double gapY = Math.Min(overlapText.Y2, text.Y2) - Math.Max(overlapText.Y1, text.Y1); |
6096 |
percentY = Math.Max(gapY / (overlapText.Y2 - overlapText.Y1), gapY / (text.Y2 - text.Y1)); |
6097 |
} |
6098 |
|
6099 |
double tempX = 0; |
6100 |
double tempY = 0; |
6101 |
bool overlapX = false; |
6102 |
bool overlapY = false; |
6103 |
SPPIDUtil.CalcOverlap(text.SPPID.Range, overlapText.SPPID.Range, ref tempX, ref tempY, ref overlapX, ref overlapY); |
6104 |
if (percentX >= percentY) |
6105 |
{ |
6106 |
int count = Convert.ToInt32(tempY / gridSetting.Length) + 1; |
6107 |
double move = gridSetting.Length * count; |
6108 |
text.SPPID.SPPID_Y = text.SPPID.SPPID_Y - move; |
6109 |
text.SPPID.Range = new double[] { text.SPPID.Range[0], text.SPPID.Range[1] - move, text.SPPID.Range[2], text.SPPID.Range[3] - move }; |
6110 |
needRemodeling = true; |
6111 |
loop = true; |
6112 |
} |
6113 |
else |
6114 |
{ |
6115 |
int count = Convert.ToInt32(tempX / gridSetting.Length) + 1; |
6116 |
double move = gridSetting.Length * count; |
6117 |
text.SPPID.SPPID_X = text.SPPID.SPPID_X + move; |
6118 |
text.SPPID.Range = new double[] { text.SPPID.Range[0] + move, text.SPPID.Range[1], text.SPPID.Range[2] + move, text.SPPID.Range[3] }; |
6119 |
needRemodeling = true; |
6120 |
loop = true; |
6121 |
} |
6122 |
} |
6123 |
} |
6124 |
} |
6125 |
|
6126 |
|
6127 |
if (needRemodeling) |
6128 |
{ |
6129 |
LMSymbol symbol = dataSource.GetSymbol(text.SPPID.RepresentationId); |
6130 |
_placement.PIDRemovePlacement(symbol.AsLMRepresentation()); |
6131 |
text.SPPID.RepresentationId = null; |
6132 |
|
6133 |
LMItemNote _LMItemNote = null; |
6134 |
LMAAttribute _LMAAttribute = null; |
6135 |
LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, text.SPPID.SPPID_X, text.SPPID.SPPID_Y, Rotation: text.ANGLE); |
6136 |
if (_LMSymbol != null) |
6137 |
{ |
6138 |
_LMSymbol.Commit(); |
6139 |
_LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
6140 |
if (_LMItemNote != null) |
6141 |
{ |
6142 |
_LMItemNote.Commit(); |
6143 |
_LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
6144 |
if (_LMAAttribute != null) |
6145 |
{ |
6146 |
_LMAAttribute.set_Value(text.VALUE); |
6147 |
text.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
6148 |
_LMItemNote.Commit(); |
6149 |
|
6150 |
ReleaseCOMObjects(_LMAAttribute); |
6151 |
ReleaseCOMObjects(_LMItemNote); |
6152 |
} |
6153 |
} |
6154 |
} |
6155 |
|
6156 |
ReleaseCOMObjects(symbol); |
6157 |
symbol = null; |
6158 |
ReleaseCOMObjects(_LMItemNote); |
6159 |
_LMItemNote = null; |
6160 |
ReleaseCOMObjects(_LMAAttribute); |
6161 |
_LMAAttribute = null; |
6162 |
ReleaseCOMObjects(_LMSymbol); |
6163 |
_LMSymbol = null; |
6164 |
} |
6165 |
} |
6166 |
|
6167 |
private void AssociationTextCorrectModeling(Text text, List<Text> endTexts) |
6168 |
{ |
6169 |
if (!string.IsNullOrEmpty(text.SPPID.RepresentationId)) |
6170 |
{ |
6171 |
List<Text> allTexts = new List<Text>(); |
6172 |
LMLabelPersist targetLabel = dataSource.GetLabelPersist(text.SPPID.RepresentationId); |
6173 |
LMRepresentation representation = targetLabel.RepresentationObject; |
6174 |
Symbol symbol = document.SYMBOLS.Find(x => x.SPPID.RepresentationId == representation.Id); |
6175 |
if (targetLabel.RepresentationObject != null && symbol != null) |
6176 |
{ |
6177 |
double[] symbolRange = null; |
6178 |
GetSPPIDSymbolRange(symbol, ref symbolRange, true, true); |
6179 |
if (symbolRange != null) |
6180 |
{ |
6181 |
foreach (LMLabelPersist labelPersist in representation.LabelPersists) |
6182 |
{ |
6183 |
Text findText = document.TEXTINFOS.Find(x => x.SPPID.RepresentationId == labelPersist.AsLMRepresentation().Id && x.ASSOCIATION); |
6184 |
if (findText != null) |
6185 |
{ |
6186 |
double[] range = null; |
6187 |
GetSPPIDSymbolRange(labelPersist, ref range); |
6188 |
findText.SPPID.Range = range; |
6189 |
allTexts.Add(findText); |
6190 |
} |
6191 |
|
6192 |
ReleaseCOMObjects(labelPersist); |
6193 |
} |
6194 |
|
6195 |
if (allTexts.Count > 0) |
6196 |
{ |
6197 |
#region Sort Text By Y |
6198 |
allTexts.Sort(SortTextByY); |
6199 |
int SortTextByY(Text a, Text b) |
6200 |
{ |
6201 |
return b.SPPID.Range[3].CompareTo(a.SPPID.Range[3]); |
6202 |
} |
6203 |
#endregion |
6204 |
|
6205 |
#region 정렬하기전 방향 |
6206 |
List<Text> left = new List<Text>(); |
6207 |
List<Text> down = new List<Text>(); |
6208 |
List<Text> right = new List<Text>(); |
6209 |
List<Text> up = new List<Text>(); |
6210 |
List<List<Text>> sortTexts = new List<List<Text>>() { left, down, right, up }; |
6211 |
foreach (var loopText in allTexts) |
6212 |
{ |
6213 |
double textCenterX = (loopText.X1 + loopText.X2) / 2; |
6214 |
double textCenterY = (loopText.Y1 + loopText.Y2) / 2; |
6215 |
double originX = 0; |
6216 |
double originY = 0; |
6217 |
SPPIDUtil.ConvertPointBystring(symbol.ORIGINALPOINT, ref originX, ref originY); |
6218 |
double angle = SPPIDUtil.CalcAngle(textCenterX, textCenterY, originX, originY); |
6219 |
|
6220 |
if (angle < 45) |
6221 |
{ |
6222 |
// Text 오른쪽 |
6223 |
if (textCenterX > originX) |
6224 |
right.Add(loopText); |
6225 |
// Text 왼쪽 |
6226 |
else |
6227 |
left.Add(loopText); |
6228 |
} |
6229 |
else |
6230 |
{ |
6231 |
// Text 아래쪽 |
6232 |
if (textCenterY > originY) |
6233 |
down.Add(loopText); |
6234 |
// Text 위쪽 |
6235 |
else |
6236 |
up.Add(loopText); |
6237 |
} |
6238 |
} |
6239 |
|
6240 |
#endregion |
6241 |
|
6242 |
foreach (var texts in sortTexts) |
6243 |
{ |
6244 |
if (texts.Count == 0) |
6245 |
continue; |
6246 |
|
6247 |
#region 첫번째 Text로 기준 맞춤 |
6248 |
for (int i = 0; i < texts.Count; i++) |
6249 |
{ |
6250 |
if (i != 0) |
6251 |
{ |
6252 |
Text currentText = texts[i]; |
6253 |
Text prevText = texts[i - 1]; |
6254 |
double minY = prevText.SPPID.Range[1]; |
6255 |
double centerPrevX = (prevText.SPPID.Range[0] + prevText.SPPID.Range[2]) / 2; |
6256 |
double centerX = (currentText.SPPID.Range[0] + currentText.SPPID.Range[2]) / 2; |
6257 |
double _gapX = centerX - centerPrevX; |
6258 |
double _gapY = currentText.SPPID.Range[3] - minY; |
6259 |
MoveText(currentText, _gapX, _gapY); |
6260 |
} |
6261 |
} |
6262 |
List<double> rangeMinX = texts.Select(loopX => loopX.SPPID.Range[0]).ToList(); |
6263 |
List<double> rangeMinY = texts.Select(loopX => loopX.SPPID.Range[1]).ToList(); |
6264 |
List<double> rangeMaxX = texts.Select(loopX => loopX.SPPID.Range[2]).ToList(); |
6265 |
List<double> rangeMaxY = texts.Select(loopX => loopX.SPPID.Range[3]).ToList(); |
6266 |
rangeMinX.Sort(); |
6267 |
rangeMinY.Sort(); |
6268 |
rangeMaxX.Sort(); |
6269 |
rangeMaxY.Sort(); |
6270 |
double allTextCenterX = (rangeMinX[0] + rangeMaxX[rangeMaxX.Count - 1]) / 2; |
6271 |
double allTextCenterY = (rangeMinY[0] + rangeMaxY[rangeMaxY.Count - 1]) / 2; |
6272 |
#endregion |
6273 |
#region 정렬 |
6274 |
Text correctBySymbol = texts[0]; |
6275 |
double textCenterX = (correctBySymbol.X1 + correctBySymbol.X2) / 2; |
6276 |
double textCenterY = (correctBySymbol.Y1 + correctBySymbol.Y2) / 2; |
6277 |
double originX = 0; |
6278 |
double originY = 0; |
6279 |
SPPIDUtil.ConvertPointBystring(symbol.ORIGINALPOINT, ref originX, ref originY); |
6280 |
double angle = SPPIDUtil.CalcAngle(textCenterX, textCenterY, originX, originY); |
6281 |
double symbolCenterX = (symbolRange[0] + symbolRange[2]) / 2; |
6282 |
double symbolCenterY = (symbolRange[1] + symbolRange[3]) / 2; |
6283 |
|
6284 |
double gapX = 0; |
6285 |
double gapY = 0; |
6286 |
if (angle < 45) |
6287 |
{ |
6288 |
// Text 오른쪽 |
6289 |
if (textCenterX > originX) |
6290 |
{ |
6291 |
gapX = rangeMinX[0] - symbolRange[2]; |
6292 |
gapY = allTextCenterY - symbolCenterY; |
6293 |
} |
6294 |
// Text 왼쪽 |
6295 |
else |
6296 |
{ |
6297 |
gapX = rangeMaxX[rangeMaxX.Count - 1] - symbolRange[0]; |
6298 |
gapY = allTextCenterY - symbolCenterY; |
6299 |
} |
6300 |
} |
6301 |
else |
6302 |
{ |
6303 |
// Text 아래쪽 |
6304 |
if (textCenterY > originY) |
6305 |
{ |
6306 |
gapX = allTextCenterX - symbolCenterX; |
6307 |
gapY = rangeMaxY[rangeMaxY.Count - 1] - symbolRange[1]; |
6308 |
} |
6309 |
// Text 위쪽 |
6310 |
else |
6311 |
{ |
6312 |
gapX = allTextCenterX - symbolCenterX; |
6313 |
gapY = rangeMinY[0] - symbolRange[3]; |
6314 |
} |
6315 |
} |
6316 |
|
6317 |
foreach (var item in texts) |
6318 |
{ |
6319 |
MoveText(item, gapX, gapY); |
6320 |
RemodelingAssociationText(item); |
6321 |
} |
6322 |
#endregion |
6323 |
} |
6324 |
} |
6325 |
} |
6326 |
} |
6327 |
|
6328 |
void MoveText(Text moveText, double x, double y) |
6329 |
{ |
6330 |
moveText.SPPID.SPPID_X = moveText.SPPID.SPPID_X - x; |
6331 |
moveText.SPPID.SPPID_Y = moveText.SPPID.SPPID_Y - y; |
6332 |
moveText.SPPID.Range = new double[] { |
6333 |
moveText.SPPID.Range[0] - x, |
6334 |
moveText.SPPID.Range[1]- y, |
6335 |
moveText.SPPID.Range[2]- x, |
6336 |
moveText.SPPID.Range[3]- y |
6337 |
}; |
6338 |
} |
6339 |
|
6340 |
endTexts.AddRange(allTexts); |
6341 |
|
6342 |
ReleaseCOMObjects(targetLabel); |
6343 |
targetLabel = null; |
6344 |
ReleaseCOMObjects(representation); |
6345 |
representation = null; |
6346 |
} |
6347 |
} |
6348 |
|
6349 |
private void RemodelingAssociationText(Text text) |
6350 |
{ |
6351 |
LMLabelPersist removeLabel = dataSource.GetLabelPersist(text.SPPID.RepresentationId); |
6352 |
_placement.PIDRemovePlacement(removeLabel.AsLMRepresentation()); |
6353 |
removeLabel.Commit(); |
6354 |
ReleaseCOMObjects(removeLabel); |
6355 |
removeLabel = null; |
6356 |
|
6357 |
object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER); |
6358 |
if (owner != null && owner.GetType() == typeof(Symbol)) |
6359 |
{ |
6360 |
Symbol symbol = owner as Symbol; |
6361 |
_LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
6362 |
if (_LMSymbol != null) |
6363 |
{ |
6364 |
BaseModel.Attribute attribute = symbol.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID); |
6365 |
if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
6366 |
{ |
6367 |
AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME)); |
6368 |
|
6369 |
if (mapping != null) |
6370 |
{ |
6371 |
double x = 0; |
6372 |
double y = 0; |
6373 |
|
6374 |
Array array = new double[] { 0, text.SPPID.SPPID_X, text.SPPID.SPPID_Y }; |
6375 |
LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine); |
6376 |
if (_LMLabelPersist != null) |
6377 |
{ |
6378 |
text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id; |
6379 |
_LMLabelPersist.Commit(); |
6380 |
} |
6381 |
ReleaseCOMObjects(_LMLabelPersist); |
6382 |
_LMLabelPersist = null; |
6383 |
} |
6384 |
} |
6385 |
} |
6386 |
ReleaseCOMObjects(_LMSymbol); |
6387 |
_LMSymbol = null; |
6388 |
} |
6389 |
} |
6390 |
|
6391 |
/// <summary> |
6392 |
/// Note Modeling |
6393 |
/// </summary> |
6394 |
/// <param name="note"></param> |
6395 |
private void NoteModeling(Note note, List<Note> correctList) |
6396 |
{ |
6397 |
LMSymbol _LMSymbol = null; |
6398 |
LMItemNote _LMItemNote = null; |
6399 |
LMAAttribute _LMAAttribute = null; |
6400 |
|
6401 |
if (string.IsNullOrEmpty(note.OWNER) || note.OWNER == "None") |
6402 |
{ |
6403 |
double x = 0; |
6404 |
double y = 0; |
6405 |
|
6406 |
CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation); |
6407 |
SPPIDUtil.ConvertGridPoint(ref x, ref y); |
6408 |
note.SPPID.SPPID_X = x; |
6409 |
note.SPPID.SPPID_Y = y; |
6410 |
|
6411 |
_LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y); |
6412 |
if (_LMSymbol != null) |
6413 |
{ |
6414 |
_LMSymbol.Commit(); |
6415 |
_LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
6416 |
if (_LMItemNote != null) |
6417 |
{ |
6418 |
_LMItemNote.Commit(); |
6419 |
_LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
6420 |
if (_LMAAttribute != null) |
6421 |
{ |
6422 |
_LMAAttribute.set_Value(note.VALUE); |
6423 |
note.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
6424 |
|
6425 |
double[] range = null; |
6426 |
foreach (LMLabelPersist labelPersist in _LMSymbol.LabelPersists) |
6427 |
{ |
6428 |
double[] temp = null; |
6429 |
GetSPPIDSymbolRange(labelPersist, ref temp); |
6430 |
if (temp != null) |
6431 |
{ |
6432 |
if (range == null) |
6433 |
range = temp; |
6434 |
else |
6435 |
{ |
6436 |
range = new double[] { |
6437 |
Math.Min(range[0], temp[0]), |
6438 |
Math.Min(range[1], temp[1]), |
6439 |
Math.Max(range[2], temp[2]), |
6440 |
Math.Max(range[3], temp[3]) |
6441 |
}; |
6442 |
} |
6443 |
} |
6444 |
} |
6445 |
if (range != null) |
6446 |
correctList.Add(note); |
6447 |
note.SPPID.Range = range; |
6448 |
|
6449 |
|
6450 |
_LMItemNote.Commit(); |
6451 |
} |
6452 |
} |
6453 |
} |
6454 |
} |
6455 |
|
6456 |
if (_LMAAttribute != null) |
6457 |
ReleaseCOMObjects(_LMAAttribute); |
6458 |
if (_LMItemNote != null) |
6459 |
ReleaseCOMObjects(_LMItemNote); |
6460 |
if (_LMSymbol != null) |
6461 |
ReleaseCOMObjects(_LMSymbol); |
6462 |
} |
6463 |
|
6464 |
private void NoteCorrectModeling(Note note, List<Note> endList) |
6465 |
{ |
6466 |
bool needRemodeling = false; |
6467 |
bool loop = true; |
6468 |
GridSetting gridSetting = GridSetting.GetInstance(); |
6469 |
while (loop) |
6470 |
{ |
6471 |
loop = false; |
6472 |
foreach (var overlap in endList) |
6473 |
{ |
6474 |
if (SPPIDUtil.IsOverlap(overlap.SPPID.Range, note.SPPID.Range)) |
6475 |
{ |
6476 |
double tempX = 0; |
6477 |
double tempY = 0; |
6478 |
bool overlapX = false; |
6479 |
bool overlapY = false; |
6480 |
SPPIDUtil.CalcOverlap(note.SPPID.Range, overlap.SPPID.Range, ref tempX, ref tempY, ref overlapX, ref overlapY); |
6481 |
double angle = SPPIDUtil.CalcAngle(note.LOCATION_X, note.LOCATION_Y, overlap.LOCATION_X, overlap.LOCATION_Y); |
6482 |
if (overlapY && angle >= 45) |
6483 |
{ |
6484 |
int count = Convert.ToInt32(tempY / gridSetting.Length) + 1; |
6485 |
double move = gridSetting.Length * count; |
6486 |
note.SPPID.SPPID_Y = note.SPPID.SPPID_Y - move; |
6487 |
note.SPPID.Range = new double[] { note.SPPID.Range[0], note.SPPID.Range[1] - move, note.SPPID.Range[2], note.SPPID.Range[3] - move }; |
6488 |
needRemodeling = true; |
6489 |
loop = true; |
6490 |
} |
6491 |
if (overlapX && angle <= 45) |
6492 |
{ |
6493 |
int count = Convert.ToInt32(tempX / gridSetting.Length) + 1; |
6494 |
double move = gridSetting.Length * count; |
6495 |
note.SPPID.SPPID_X = note.SPPID.SPPID_X + move; |
6496 |
note.SPPID.Range = new double[] { note.SPPID.Range[0] + move, note.SPPID.Range[1], note.SPPID.Range[2] + move, note.SPPID.Range[3] }; |
6497 |
needRemodeling = true; |
6498 |
loop = true; |
6499 |
} |
6500 |
} |
6501 |
} |
6502 |
} |
6503 |
|
6504 |
|
6505 |
if (needRemodeling) |
6506 |
{ |
6507 |
LMSymbol symbol = dataSource.GetSymbol(note.SPPID.RepresentationId); |
6508 |
_placement.PIDRemovePlacement(symbol.AsLMRepresentation()); |
6509 |
note.SPPID.RepresentationId = null; |
6510 |
|
6511 |
LMItemNote _LMItemNote = null; |
6512 |
LMAAttribute _LMAAttribute = null; |
6513 |
LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, note.SPPID.SPPID_X, note.SPPID.SPPID_Y, Rotation: note.ANGLE); |
6514 |
if (_LMSymbol != null) |
6515 |
{ |
6516 |
_LMSymbol.Commit(); |
6517 |
_LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
6518 |
if (_LMItemNote != null) |
6519 |
{ |
6520 |
_LMItemNote.Commit(); |
6521 |
_LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
6522 |
if (_LMAAttribute != null) |
6523 |
{ |
6524 |
_LMAAttribute.set_Value(note.VALUE); |
6525 |
note.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
6526 |
_LMItemNote.Commit(); |
6527 |
|
6528 |
ReleaseCOMObjects(_LMAAttribute); |
6529 |
ReleaseCOMObjects(_LMItemNote); |
6530 |
} |
6531 |
} |
6532 |
} |
6533 |
|
6534 |
ReleaseCOMObjects(symbol); |
6535 |
symbol = null; |
6536 |
ReleaseCOMObjects(_LMItemNote); |
6537 |
_LMItemNote = null; |
6538 |
ReleaseCOMObjects(_LMAAttribute); |
6539 |
_LMAAttribute = null; |
6540 |
ReleaseCOMObjects(_LMSymbol); |
6541 |
_LMSymbol = null; |
6542 |
} |
6543 |
|
6544 |
endList.Add(note); |
6545 |
} |
6546 |
|
6547 |
private void JoinRunBySameType(string modelItemId, ref string survivorId) |
6548 |
{ |
6549 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemId); |
6550 |
if (modelItem != null) |
6551 |
{ |
6552 |
foreach (LMRepresentation rep in modelItem.Representations) |
6553 |
{ |
6554 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
6555 |
{ |
6556 |
LMConnector connector = dataSource.GetConnector(rep.Id); |
6557 |
if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch") |
6558 |
{ |
6559 |
LMSymbol symbol = connector.ConnectItem1SymbolObject; |
6560 |
List<string> modelItemIds = FindOtherModelItemBySymbolWhereTypePipeRun(symbol, modelItem.Id); |
6561 |
if (modelItemIds.Count == 1) |
6562 |
{ |
6563 |
string joinModelItemId = modelItemIds[0]; |
6564 |
JoinRun(joinModelItemId, modelItemId, ref survivorId, false); |
6565 |
if (survivorId != null) |
6566 |
break; |
6567 |
} |
6568 |
} |
6569 |
if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch") |
6570 |
{ |
6571 |
LMSymbol symbol = connector.ConnectItem2SymbolObject; |
6572 |
List<string> modelItemIds = FindOtherModelItemBySymbolWhereTypePipeRun(symbol, modelItem.Id); |
6573 |
if (modelItemIds.Count == 1) |
6574 |
{ |
6575 |
string joinModelItemId = modelItemIds[0]; |
6576 |
JoinRun(joinModelItemId, modelItemId, ref survivorId, false); |
6577 |
if (survivorId != null) |
6578 |
break; |
6579 |
} |
6580 |
} |
6581 |
} |
6582 |
} |
6583 |
} |
6584 |
} |
6585 |
|
6586 |
/// <summary> |
6587 |
/// Label의 좌표를 구하는 메서드(ID2 기준의 좌표 -> SPPID 좌표) |
6588 |
/// </summary> |
6589 |
/// <param name="x"></param> |
6590 |
/// <param name="y"></param> |
6591 |
/// <param name="originX"></param> |
6592 |
/// <param name="originY"></param> |
6593 |
/// <param name="SPPIDLabelLocation"></param> |
6594 |
/// <param name="location"></param> |
6595 |
private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDEtcLocationInfo SPPIDLabelLocation, Location location) |
6596 |
{ |
6597 |
if (location == Location.None) |
6598 |
{ |
6599 |
x = originX; |
6600 |
y = originY; |
6601 |
} |
6602 |
else |
6603 |
{ |
6604 |
if (location.HasFlag(Location.Center)) |
6605 |
{ |
6606 |
x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2; |
6607 |
y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2; |
6608 |
} |
6609 |
|
6610 |
if (location.HasFlag(Location.Left)) |
6611 |
x = SPPIDLabelLocation.X1; |
6612 |
else if (location.HasFlag(Location.Right)) |
6613 |
x = SPPIDLabelLocation.X2; |
6614 |
|
6615 |
if (location.HasFlag(Location.Down)) |
6616 |
y = SPPIDLabelLocation.Y1; |
6617 |
else if (location.HasFlag(Location.Up)) |
6618 |
y = SPPIDLabelLocation.Y2; |
6619 |
} |
6620 |
} |
6621 |
|
6622 |
/// <summary> |
6623 |
/// Symbol의 우선순위 Modeling 목록을 가져온다. |
6624 |
/// 1. Angle Valve |
6625 |
/// 2. 3개로 이루어진 Symbol Group |
6626 |
/// </summary> |
6627 |
/// <returns></returns> |
6628 |
private List<Symbol> GetPrioritySymbol() |
6629 |
{ |
6630 |
DataTable symbolTable = document.SymbolTable; |
6631 |
// List에 순서대로 쌓는다. |
6632 |
List<Symbol> symbols = new List<Symbol>(); |
6633 |
|
6634 |
// Angle Valve 부터 |
6635 |
foreach (var symbol in document.SYMBOLS.FindAll(x => x.CONNECTORS.FindAll(y => y.Index == 0).Count == 2)) |
6636 |
{ |
6637 |
if (!symbols.Contains(symbol)) |
6638 |
{ |
6639 |
double originX = 0; |
6640 |
double originY = 0; |
6641 |
|
6642 |
// ID2 Table에서 Original Point 가져옴. |
6643 |
string OriginalPoint = symbolTable.Select(string.Format("UID = {0}", symbol.DBUID))[0]["OriginalPoint"].ToString(); |
6644 |
SPPIDUtil.ConvertPointBystring(OriginalPoint, ref originX, ref originY); |
6645 |
|
6646 |
SlopeType slopeType1 = SlopeType.None; |
6647 |
SlopeType slopeType2 = SlopeType.None; |
6648 |
foreach (Connector connector in symbol.CONNECTORS.FindAll(x => x.Index == 0)) |
6649 |
{ |
6650 |
double connectorX = 0; |
6651 |
double connectorY = 0; |
6652 |
SPPIDUtil.ConvertPointBystring(connector.CONNECTPOINT, ref connectorX, ref connectorY); |
6653 |
if (slopeType1 == SlopeType.None) |
6654 |
slopeType1 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY); |
6655 |
else |
6656 |
slopeType2 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY); |
6657 |
} |
6658 |
|
6659 |
if ((slopeType1 == SlopeType.VERTICAL && slopeType2 == SlopeType.HORIZONTAL) || |
6660 |
(slopeType2 == SlopeType.VERTICAL && slopeType1 == SlopeType.HORIZONTAL)) |
6661 |
symbols.Add(symbol); |
6662 |
} |
6663 |
} |
6664 |
|
6665 |
List<Symbol> tempSymbols = new List<Symbol>(); |
6666 |
// Conn 갯수 기준 |
6667 |
foreach (var item in document.SYMBOLS) |
6668 |
{ |
6669 |
if (!symbols.Contains(item)) |
6670 |
tempSymbols.Add(item); |
6671 |
} |
6672 |
tempSymbols.Sort(SPPIDUtil.SortSymbolPriority); |
6673 |
symbols.AddRange(tempSymbols); |
6674 |
|
6675 |
return symbols; |
6676 |
} |
6677 |
|
6678 |
private void SetPriorityLine(List<Line> lines) |
6679 |
{ |
6680 |
lines.Sort(SortLinePriority); |
6681 |
|
6682 |
int SortLinePriority(Line a, Line b) |
6683 |
{ |
6684 |
int childRetval = CompareChild(a, b); |
6685 |
if (childRetval != 0) |
6686 |
{ |
6687 |
return childRetval; |
6688 |
} |
6689 |
else |
6690 |
{ |
6691 |
// Branch 없는것부터 |
6692 |
int branchRetval = CompareBranchLine(a, b); |
6693 |
if (branchRetval != 0) |
6694 |
{ |
6695 |
return branchRetval; |
6696 |
} |
6697 |
else |
6698 |
{ |
6699 |
// 아이템 연결 갯수(심볼, Line이면서 Not Branch) |
6700 |
int connItemRetval = CompareConnItem(a, b); |
6701 |
if (connItemRetval != 0) |
6702 |
{ |
6703 |
return connItemRetval; |
6704 |
} |
6705 |
else |
6706 |
{ |
6707 |
// line 길이 |
6708 |
int lengthRetval = CompareLength(a, b); |
6709 |
if (lengthRetval != 0) |
6710 |
{ |
6711 |
return lengthRetval; |
6712 |
} |
6713 |
else |
6714 |
{ |
6715 |
// Symbol 연결 갯수 |
6716 |
int connSymbolRetval = CompareConnSymbol(a, b); |
6717 |
if (connSymbolRetval != 0) |
6718 |
{ |
6719 |
return connSymbolRetval; |
6720 |
} |
6721 |
else |
6722 |
{ |
6723 |
// ConnectedItem이 없는것 |
6724 |
int noneConnRetval = CompareNoneConn(a, b); |
6725 |
if (noneConnRetval != 0) |
6726 |
{ |
6727 |
return noneConnRetval; |
6728 |
} |
6729 |
else |
6730 |
{ |
6731 |
|
6732 |
} |
6733 |
} |
6734 |
} |
6735 |
} |
6736 |
} |
6737 |
} |
6738 |
|
6739 |
return 0; |
6740 |
} |
6741 |
|
6742 |
int CompareChild(Line a, Line b) |
6743 |
{ |
6744 |
int countA = a.CONNECTORS.Count(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Line) && x.ConnectedObject == b); |
6745 |
int countB = a.CONNECTORS.Count(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Line) && x.ConnectedObject == a); |
6746 |
|
6747 |
// 내림차순 |
6748 |
return countA.CompareTo(countB); |
6749 |
} |
6750 |
|
6751 |
int CompareConnSymbol(Line a, Line b) |
6752 |
{ |
6753 |
List<Connector> connectorsA = a.CONNECTORS |
6754 |
.Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol)) |
6755 |
.ToList(); |
6756 |
|
6757 |
List<Connector> connectorsB = b.CONNECTORS |
6758 |
.Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol)) |
6759 |
.ToList(); |
6760 |
|
6761 |
// 내림차순 |
6762 |
return connectorsA.Count.CompareTo(connectorsB.Count); |
6763 |
} |
6764 |
|
6765 |
int CompareLength(Line a, Line b) |
6766 |
{ |
6767 |
double lengthA = Math.Abs(a.SPPID.START_X - a.SPPID.END_X) + Math.Abs(a.SPPID.START_Y - a.SPPID.END_Y); |
6768 |
double lengthB = Math.Abs(b.SPPID.START_X - b.SPPID.END_X) + Math.Abs(b.SPPID.START_Y - b.SPPID.END_Y); |
6769 |
|
6770 |
// 오름차순 |
6771 |
return lengthB.CompareTo(lengthA); |
6772 |
} |
6773 |
|
6774 |
int CompareConnItem(Line a, Line b) |
6775 |
{ |
6776 |
List<Connector> connectorsA = a.CONNECTORS |
6777 |
.Where(conn => conn.ConnectedObject != null && |
6778 |
(conn.ConnectedObject.GetType() == typeof(Symbol) || |
6779 |
(conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, a)))) |
6780 |
.ToList(); |
6781 |
|
6782 |
List<Connector> connectorsB = b.CONNECTORS |
6783 |
.Where(conn => conn.ConnectedObject != null && |
6784 |
(conn.ConnectedObject.GetType() == typeof(Symbol) || |
6785 |
(conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, b)))) |
6786 |
.ToList(); |
6787 |
|
6788 |
// 내림차순 |
6789 |
return connectorsA.Count.CompareTo(connectorsB.Count); |
6790 |
} |
6791 |
|
6792 |
int CompareBranchLine(Line a, Line b) |
6793 |
{ |
6794 |
List<Connector> connectorsA = a.CONNECTORS |
6795 |
.Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(a, conn.ConnectedObject as Line)) |
6796 |
.ToList(); |
6797 |
List<Connector> connectorsB = b.CONNECTORS |
6798 |
.Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(b, conn.ConnectedObject as Line)) |
6799 |
.ToList(); |
6800 |
|
6801 |
// 내림차순 |
6802 |
return connectorsA.Count.CompareTo(connectorsB.Count); |
6803 |
} |
6804 |
|
6805 |
int CompareNoneConn(Line a, Line b) |
6806 |
{ |
6807 |
List<Connector> connectorsA = a.CONNECTORS |
6808 |
.Where(conn => conn.ConnectedObject == null) |
6809 |
.ToList(); |
6810 |
|
6811 |
List<Connector> connectorsB = b.CONNECTORS |
6812 |
.Where(conn => conn.ConnectedObject == null) |
6813 |
.ToList(); |
6814 |
|
6815 |
// 내림차순 |
6816 |
return connectorsA.Count.CompareTo(connectorsB.Count); |
6817 |
} |
6818 |
} |
6819 |
|
6820 |
private void SortText(List<Text> texts) |
6821 |
{ |
6822 |
texts.Sort(Sort); |
6823 |
|
6824 |
int Sort(Text a, Text b) |
6825 |
{ |
6826 |
int yRetval = CompareY(a, b); |
6827 |
if (yRetval != 0) |
6828 |
{ |
6829 |
return yRetval; |
6830 |
} |
6831 |
else |
6832 |
{ |
6833 |
return CompareX(a, b); |
6834 |
} |
6835 |
} |
6836 |
|
6837 |
int CompareY(Text a, Text b) |
6838 |
{ |
6839 |
return a.LOCATION_Y.CompareTo(b.LOCATION_Y); |
6840 |
} |
6841 |
|
6842 |
int CompareX(Text a, Text b) |
6843 |
{ |
6844 |
return a.LOCATION_X.CompareTo(b.LOCATION_X); |
6845 |
} |
6846 |
} |
6847 |
private void SortNote(List<Note> notes) |
6848 |
{ |
6849 |
notes.Sort(Sort); |
6850 |
|
6851 |
int Sort(Note a, Note b) |
6852 |
{ |
6853 |
int yRetval = CompareY(a, b); |
6854 |
if (yRetval != 0) |
6855 |
{ |
6856 |
return yRetval; |
6857 |
} |
6858 |
else |
6859 |
{ |
6860 |
return CompareX(a, b); |
6861 |
} |
6862 |
} |
6863 |
|
6864 |
int CompareY(Note a, Note b) |
6865 |
{ |
6866 |
return a.LOCATION_Y.CompareTo(b.LOCATION_Y); |
6867 |
} |
6868 |
|
6869 |
int CompareX(Note a, Note b) |
6870 |
{ |
6871 |
return a.LOCATION_X.CompareTo(b.LOCATION_X); |
6872 |
} |
6873 |
} |
6874 |
|
6875 |
private void SortBranchLines() |
6876 |
{ |
6877 |
BranchLines.Sort(SortBranchLine); |
6878 |
|
6879 |
int SortBranchLine(Line a, Line b) |
6880 |
{ |
6881 |
int childRetval = CompareChild(a, b); |
6882 |
if (childRetval != 0) |
6883 |
{ |
6884 |
return childRetval; |
6885 |
} |
6886 |
else |
6887 |
{ |
6888 |
int branchRetval = CompareChildBranch(a, b); |
6889 |
if (branchRetval != 0) |
6890 |
{ |
6891 |
return branchRetval; |
6892 |
} |
6893 |
else |
6894 |
{ |
6895 |
// line 길이 |
6896 |
int lengthRetval = CompareLength(a, b); |
6897 |
if (lengthRetval != 0) |
6898 |
{ |
6899 |
return lengthRetval; |
6900 |
} |
6901 |
} |
6902 |
} |
6903 |
return 0; |
6904 |
} |
6905 |
|
6906 |
int CompareLength(Line a, Line b) |
6907 |
{ |
6908 |
double lengthA = Math.Abs(a.SPPID.START_X - a.SPPID.END_X) + Math.Abs(a.SPPID.START_Y - a.SPPID.END_Y); |
6909 |
double lengthB = Math.Abs(b.SPPID.START_X - b.SPPID.END_X) + Math.Abs(b.SPPID.START_Y - b.SPPID.END_Y); |
6910 |
|
6911 |
// 오름차순 |
6912 |
return lengthB.CompareTo(lengthA); |
6913 |
} |
6914 |
|
6915 |
int CompareChildBranch(Line a, Line b) |
6916 |
{ |
6917 |
int countA = document.LINES.Count(c => c.CONNECTORS.Any(n => n.ConnectedObject != null && |
6918 |
n.ConnectedObject.GetType() == typeof(Line) && n.ConnectedObject == a)); |
6919 |
|
6920 |
int countB = document.LINES.Count(c => c.CONNECTORS.Any(n => n.ConnectedObject != null && |
6921 |
n.ConnectedObject.GetType() == typeof(Line) && n.ConnectedObject == b)); |
6922 |
|
6923 |
// 오름차순 |
6924 |
return countB.CompareTo(countA); |
6925 |
} |
6926 |
|
6927 |
int CompareChild(Line a, Line b) |
6928 |
{ |
6929 |
int countA = a.CONNECTORS.Count(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Line) && x.ConnectedObject == b); |
6930 |
int countB = a.CONNECTORS.Count(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Line) && x.ConnectedObject == a); |
6931 |
|
6932 |
// 내림차순 |
6933 |
return countA.CompareTo(countB); |
6934 |
} |
6935 |
} |
6936 |
|
6937 |
private string GetSPPIDFileName(LMModelItem modelItem) |
6938 |
{ |
6939 |
string symbolPath = null; |
6940 |
foreach (LMRepresentation rep in modelItem.Representations) |
6941 |
{ |
6942 |
if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName())) |
6943 |
{ |
6944 |
symbolPath = rep.get_FileName(); |
6945 |
break; |
6946 |
} |
6947 |
} |
6948 |
return symbolPath; |
6949 |
} |
6950 |
|
6951 |
private string GetSPPIDFileName(string modelItemId) |
6952 |
{ |
6953 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemId); |
6954 |
string symbolPath = null; |
6955 |
foreach (LMRepresentation rep in modelItem.Representations) |
6956 |
{ |
6957 |
if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName())) |
6958 |
{ |
6959 |
symbolPath = rep.get_FileName(); |
6960 |
break; |
6961 |
} |
6962 |
} |
6963 |
ReleaseCOMObjects(modelItem); |
6964 |
return symbolPath; |
6965 |
} |
6966 |
|
6967 |
/// <summary> |
6968 |
/// Graphic OID로 해당 Symbol의 크기를 구하여 Zoom |
6969 |
/// </summary> |
6970 |
/// <param name="graphicOID"></param> |
6971 |
/// <param name="milliseconds"></param> |
6972 |
private void ZoomObjectByGraphicOID(string graphicOID, int milliseconds = 150) |
6973 |
{ |
6974 |
if (radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] != null) |
6975 |
{ |
6976 |
double minX = 0; |
6977 |
double minY = 0; |
6978 |
double maxX = 0; |
6979 |
double maxY = 0; |
6980 |
radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID].Range(out minX, out minY, out maxX, out maxY); |
6981 |
radApp.ActiveWindow.ZoomArea2(minX - 0.007, minY - 0.007, maxX + 0.007, maxY + 0.007, null); |
6982 |
|
6983 |
Thread.Sleep(milliseconds); |
6984 |
} |
6985 |
} |
6986 |
|
6987 |
/// <summary> |
6988 |
/// ComObject를 Release |
6989 |
/// </summary> |
6990 |
/// <param name="objVars"></param> |
6991 |
public void ReleaseCOMObjects(params object[] objVars) |
6992 |
{ |
6993 |
if (objVars != null) |
6994 |
{ |
6995 |
int intNewRefCount = 0; |
6996 |
foreach (object obj in objVars) |
6997 |
{ |
6998 |
if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
6999 |
intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
7000 |
} |
7001 |
} |
7002 |
} |
7003 |
|
7004 |
/// IDisposable 구현 |
7005 |
~AutoModeling() |
7006 |
{ |
7007 |
this.Dispose(false); |
7008 |
} |
7009 |
|
7010 |
private bool disposed; |
7011 |
public void Dispose() |
7012 |
{ |
7013 |
this.Dispose(true); |
7014 |
GC.SuppressFinalize(this); |
7015 |
} |
7016 |
|
7017 |
protected virtual void Dispose(bool disposing) |
7018 |
{ |
7019 |
if (this.disposed) return; |
7020 |
if (disposing) |
7021 |
{ |
7022 |
// IDisposable 인터페이스를 구현하는 멤버들을 여기서 정리합니다. |
7023 |
} |
7024 |
// .NET Framework에 의하여 관리되지 않는 외부 리소스들을 여기서 정리합니다. |
7025 |
this.disposed = true; |
7026 |
} |
7027 |
} |
7028 |
} |