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