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