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