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