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