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