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