hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ b265df51
이력 | 보기 | 이력해설 | 다운로드 (82.6 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Threading.Tasks; |
6 |
using Llama; |
7 |
using Plaice; |
8 |
using Ingr.RAD2D.Interop.RAD2D; |
9 |
using Ingr.RAD2D.Internal; |
10 |
using Ingr.RAD2D.Helper; |
11 |
using Converter.BaseModel; |
12 |
using Converter.SPPID.Model; |
13 |
using Converter.SPPID.Properties; |
14 |
using Converter.SPPID.Util; |
15 |
using Converter.SPPID.DB; |
16 |
using Ingr.RAD2D.MacroControls.CmdCtrl; |
17 |
using Ingr.RAD2D; |
18 |
using System.Windows; |
19 |
using System.Threading; |
20 |
using System.Drawing; |
21 |
using Microsoft.VisualBasic; |
22 |
using Newtonsoft.Json; |
23 |
|
24 |
using DevExpress.XtraSplashScreen; |
25 |
namespace Converter.SPPID |
26 |
{ |
27 |
public class AutoModeling |
28 |
{ |
29 |
Placement _placement; |
30 |
LMADataSource dataSource; |
31 |
dynamic newDrawing; |
32 |
dynamic application; |
33 |
Ingr.RAD2D.Application radApp; |
34 |
SPPID_Document document; |
35 |
ETCSetting _ETCSetting; |
36 |
|
37 |
public string DocumentLabelText { get; set; } |
38 |
|
39 |
int CurrentCount; |
40 |
|
41 |
List <Tuple<string, Line, Line>> BranchLines = new List<Tuple<string, Line, Line>>(); |
42 |
public AutoModeling(SPPID_Document document, dynamic application, Ingr.RAD2D.Application radApp) |
43 |
{ |
44 |
this.document = document; |
45 |
this.application = application; |
46 |
this.radApp = radApp; |
47 |
this._ETCSetting = ETCSetting.GetInstance(); |
48 |
} |
49 |
|
50 |
private int ClacProgressCount() |
51 |
{ |
52 |
int EquipCount = 0; |
53 |
int SymbolCount = 0; |
54 |
int LineCount = 0; |
55 |
int NoteCount = 0; |
56 |
int TextCount = 0; |
57 |
int EndBreakCount = 0; |
58 |
int LineNumberCount = 0; |
59 |
|
60 |
EquipCount = document.Equipments.Count; |
61 |
SymbolCount = document.SYMBOLS.Count; |
62 |
SymbolCount = SymbolCount * 3; |
63 |
|
64 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
65 |
foreach (LineRun run in lineNumber.RUNS) |
66 |
foreach (var item in run.RUNITEMS) |
67 |
if (item.GetType() == typeof(Line)) |
68 |
LineCount++; |
69 |
foreach (TrimLine trimLine in document.TRIMLINES) |
70 |
foreach (LineRun run in trimLine.RUNS) |
71 |
foreach (var item in run.RUNITEMS) |
72 |
if (item.GetType() == typeof(Line)) |
73 |
LineCount++; |
74 |
|
75 |
LineCount = LineCount * 2; |
76 |
NoteCount = document.NOTES.Count; |
77 |
TextCount = document.TEXTINFOS.Count; |
78 |
EndBreakCount = document.EndBreaks.Count; |
79 |
LineNumberCount = document.LINENUMBERS.Count; |
80 |
LineNumberCount = LineNumberCount * 2; |
81 |
|
82 |
return EquipCount + SymbolCount + LineCount + NoteCount + TextCount + EndBreakCount; |
83 |
} |
84 |
|
85 |
public void Run() |
86 |
{ |
87 |
try |
88 |
{ |
89 |
_placement = new Placement(); |
90 |
dataSource = _placement.PIDDataSource; |
91 |
|
92 |
newDrawing = application.Drawings.Add(document.Unit, document.Template, document.DrawingNumber, document.DrawingName); |
93 |
application.ActiveWindow.Fit(); |
94 |
Thread.Sleep(500); |
95 |
application.ActiveWindow.Zoom = 2000; |
96 |
Thread.Sleep(1000); |
97 |
|
98 |
double maxX = 0; |
99 |
double maxY = 0; |
100 |
foreach (object drawingObj in radApp.ActiveDocument.ActiveSheet.DrawingObjects) |
101 |
{ |
102 |
Ingr.RAD2D.SmartFrame2d smartFrame2d = drawingObj as Ingr.RAD2D.SmartFrame2d; |
103 |
if (smartFrame2d != null) |
104 |
{ |
105 |
double x1 = 0; |
106 |
double x2 = 0; |
107 |
double y1 = 0; |
108 |
double y2 = 0; |
109 |
smartFrame2d.Range(out x1, out y1, out x2, out y2); |
110 |
maxX = Math.Max(x2, maxX); |
111 |
maxY = Math.Max(y2, maxY); |
112 |
} |
113 |
} |
114 |
if (maxX != 0 && maxY != 0) |
115 |
{ |
116 |
document.SetSPPIDLocation(maxX, maxY); |
117 |
int AllCount = ClacProgressCount(); |
118 |
|
119 |
SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true); |
120 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetParent, (IntPtr)radApp.HWnd); |
121 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllStep, AllCount); |
122 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText); |
123 |
|
124 |
// Equipment Modeling |
125 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Equipments Modeling"); |
126 |
foreach (Equipment equipment in document.Equipments) |
127 |
EquipmentModeling(equipment); |
128 |
|
129 |
// LineRun Symbol Modeling |
130 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbols Modeling"); |
131 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
132 |
foreach (LineRun run in lineNumber.RUNS) |
133 |
SymbolModelingByRun(run); |
134 |
// TrimLineRun Symbol Modeling |
135 |
foreach (TrimLine trimLine in document.TRIMLINES) |
136 |
foreach (LineRun run in trimLine.RUNS) |
137 |
SymbolModelingByRun(run); |
138 |
|
139 |
// LineRun Line Modeling |
140 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Lines Modeling"); |
141 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
142 |
foreach (LineRun run in lineNumber.RUNS) |
143 |
LineModelingByRun(run); |
144 |
// TrimLineRun Line Modeling |
145 |
foreach (TrimLine trimLine in document.TRIMLINES) |
146 |
foreach (LineRun run in trimLine.RUNS) |
147 |
LineModelingByRun(run); |
148 |
|
149 |
// Branch Line Modeling |
150 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Branch Lines Modeling"); |
151 |
foreach (var item in BranchLines) |
152 |
BranchLineModeling(item); |
153 |
|
154 |
// EndBreak Modeling |
155 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling"); |
156 |
foreach (var item in document.EndBreaks) |
157 |
EndBreakModeling(item); |
158 |
|
159 |
// LineNumber Modeling |
160 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "LineNumbers Modeling"); |
161 |
foreach (var item in document.LINENUMBERS) |
162 |
LineNumberModeling(item); |
163 |
|
164 |
// Note Modeling |
165 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling"); |
166 |
foreach (var item in document.NOTES) |
167 |
NoteModeling(item); |
168 |
|
169 |
// Text Modeling |
170 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling"); |
171 |
foreach (var item in document.TEXTINFOS) |
172 |
TextModeling(item); |
173 |
|
174 |
// LineRun Line Join |
175 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "LineRuns Join"); |
176 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
177 |
foreach (LineRun run in lineNumber.RUNS) |
178 |
JoinRunLine(run); |
179 |
// TrimLineRun Line Join |
180 |
foreach (TrimLine trimLine in document.TRIMLINES) |
181 |
foreach (LineRun run in trimLine.RUNS) |
182 |
JoinRunLine(run); |
183 |
|
184 |
// Input LineNumber Attribute |
185 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Lines Attribute"); |
186 |
foreach (var item in document.LINENUMBERS) |
187 |
InputLineNumberAttribute(item); |
188 |
|
189 |
// Input Symbol Attribute |
190 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute"); |
191 |
foreach (var item in document.SYMBOLS) |
192 |
InputSymbolAttribute(item); |
193 |
|
194 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Labels Modeling"); |
195 |
#region 임시 Label |
196 |
foreach (var item in document.SYMBOLS) |
197 |
{ |
198 |
if (item.SPPID.MAPPINGNAME.Contains("Labels - ")) |
199 |
{ |
200 |
SPPIDSymbolInfo info = item.SPPID; |
201 |
Array points = new double[] { 0, item.SPPID.ORIGINAL_X, item.SPPID.ORIGINAL_Y }; |
202 |
BaseModel.Attribute itemAttribute = item.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL"); |
203 |
if (itemAttribute == null) |
204 |
continue; |
205 |
string symbolUID = item.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL").VALUE; |
206 |
object objectItem = SPPIDUtil.FindObjectByUID(document, symbolUID); |
207 |
if (objectItem != null) |
208 |
{ |
209 |
|
210 |
string sRep = null; |
211 |
if (objectItem.GetType() == typeof(Symbol)) |
212 |
sRep = ((Symbol)objectItem).SPPID.RepresentationId; |
213 |
else if (objectItem.GetType() == typeof(Equipment)) |
214 |
sRep = ((Equipment)objectItem).SPPID.RepresentationId; |
215 |
|
216 |
if (!string.IsNullOrEmpty(sRep)) |
217 |
{ |
218 |
bool leaderLine = false; |
219 |
SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == item.DBUID); |
220 |
if (symbolMapping != null) |
221 |
leaderLine = symbolMapping.LEADERLINE; |
222 |
|
223 |
LMSymbol _TargetItem = dataSource.GetSymbol(sRep); |
224 |
LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(item.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: _TargetItem.AsLMRepresentation(), IsLeaderVisible: leaderLine); |
225 |
LMModelItem _LMModelItem = _TargetItem.ModelItemObject; |
226 |
LMAAttributes _Attributes = _LMModelItem.Attributes; |
227 |
|
228 |
foreach (var attribute in item.ATTRIBUTES) |
229 |
{ |
230 |
if (!string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None") |
231 |
{ |
232 |
AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID); |
233 |
if (mapping != null) |
234 |
{ |
235 |
LMAAttribute _LMAAttribute = _Attributes[mapping.SPPIDATTRIBUTENAME]; |
236 |
if (mapping.SPPIDATTRIBUTENAME.Contains("Description")) |
237 |
{ |
238 |
if (!DBNull.Value.Equals(_LMAAttribute.get_Value()) && !string.IsNullOrEmpty(_LMAAttribute.get_Value())) |
239 |
{ |
240 |
string value = _LMAAttribute.get_Value() + "\n" + attribute.VALUE; |
241 |
_LMAAttribute.set_Value(value); |
242 |
} |
243 |
else |
244 |
{ |
245 |
_LMAAttribute.set_Value(attribute.VALUE); |
246 |
} |
247 |
} |
248 |
else if (_LMAAttribute != null) |
249 |
_LMAAttribute.set_Value(attribute.VALUE); |
250 |
} |
251 |
} |
252 |
} |
253 |
|
254 |
//Leader 선 센터로 |
255 |
string OID = _LMLabelPresist.get_GraphicOID(); |
256 |
DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID] as DependencyObject; |
257 |
if (dependency != null) |
258 |
{ |
259 |
bool result = false; |
260 |
foreach (var attributes in dependency.AttributeSets) |
261 |
{ |
262 |
foreach (var attribute in attributes) |
263 |
{ |
264 |
string name = attribute.Name; |
265 |
string value = attribute.GetValue().ToString(); |
266 |
if (name == "DrawingItemType" && value == "LabelPersist") |
267 |
{ |
268 |
foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects) |
269 |
{ |
270 |
if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLineString2d) |
271 |
{ |
272 |
Ingr.RAD2D.LineString2d lineString2D = drawingObject as Ingr.RAD2D.LineString2d; |
273 |
double prevX = _TargetItem.get_XCoordinate(); |
274 |
double prevY = _TargetItem.get_YCoordinate(); |
275 |
lineString2D.InsertVertex(lineString2D.VertexCount, prevX, prevY); |
276 |
lineString2D.RemoveVertex(lineString2D.VertexCount); |
277 |
result = true; |
278 |
break; |
279 |
} |
280 |
} |
281 |
} |
282 |
|
283 |
if (result) |
284 |
break; |
285 |
} |
286 |
|
287 |
if (result) |
288 |
break; |
289 |
} |
290 |
} |
291 |
|
292 |
|
293 |
_LMModelItem.Commit(); |
294 |
_LMLabelPresist.Commit(); |
295 |
ReleaseCOMObjects(_TargetItem); |
296 |
ReleaseCOMObjects(_LMLabelPresist); |
297 |
ReleaseCOMObjects(_LMModelItem); |
298 |
ReleaseCOMObjects(_Attributes); |
299 |
} |
300 |
} |
301 |
} |
302 |
|
303 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
304 |
} |
305 |
#endregion |
306 |
|
307 |
|
308 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, AllCount); |
309 |
} |
310 |
} |
311 |
catch (Exception ex) |
312 |
{ |
313 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
314 |
} |
315 |
finally |
316 |
{ |
317 |
application.ActiveWindow.Fit(); |
318 |
|
319 |
if (newDrawing != null) |
320 |
{ |
321 |
radApp.ActiveDocument.SaveOnClose = false; |
322 |
radApp.ActiveDocument.Save(); |
323 |
ReleaseCOMObjects(newDrawing); |
324 |
} |
325 |
|
326 |
ReleaseCOMObjects(dataSource); |
327 |
ReleaseCOMObjects(_placement); |
328 |
|
329 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null); |
330 |
SplashScreenManager.CloseForm(false); |
331 |
} |
332 |
} |
333 |
|
334 |
private void LineModelingByRun(LineRun run) |
335 |
{ |
336 |
Line prevLine = null; |
337 |
List<Line> lines = new List<Line>(); |
338 |
foreach (var item in run.RUNITEMS) |
339 |
{ |
340 |
// Line일 경우 |
341 |
if (item.GetType() == typeof(Line)) |
342 |
{ |
343 |
Line line = item as Line; |
344 |
if (prevLine == null) |
345 |
lines.Add(line); |
346 |
else if (prevLine != null) |
347 |
{ |
348 |
if (prevLine.SPPID.MAPPINGNAME == line.SPPID.MAPPINGNAME) |
349 |
lines.Add(line); |
350 |
else |
351 |
{ |
352 |
if (lines.Count > 0) |
353 |
{ |
354 |
LineModeling(lines); |
355 |
lines.Clear(); |
356 |
} |
357 |
lines.Add(line); |
358 |
} |
359 |
} |
360 |
|
361 |
prevLine = line; |
362 |
|
363 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
364 |
} |
365 |
// Symbol 일 경우 |
366 |
else if (item.GetType() == typeof(Symbol)) |
367 |
{ |
368 |
if (lines.Count > 0) |
369 |
{ |
370 |
LineModeling(lines); |
371 |
lines.Clear(); |
372 |
} |
373 |
} |
374 |
} |
375 |
|
376 |
if (lines.Count > 0) |
377 |
LineModeling(lines); |
378 |
} |
379 |
|
380 |
private void SymbolModelingByRun(LineRun run) |
381 |
{ |
382 |
// 양끝 Symbol 검사 후 Line이 나올때까지만 Symbol Modeling |
383 |
if (run.RUNITEMS.Count > 0) |
384 |
{ |
385 |
if (run.RUNITEMS[0].GetType() == typeof(Symbol)) |
386 |
SymbolModelingByRunStart(run.RUNITEMS[0] as Symbol, run); |
387 |
|
388 |
if (run.RUNITEMS[run.RUNITEMS.Count - 1].GetType() == typeof(Symbol)) |
389 |
SymbolModelingByRunEnd(run.RUNITEMS[run.RUNITEMS.Count - 1] as Symbol, run); |
390 |
} |
391 |
|
392 |
Symbol prevSymbol = null; |
393 |
Symbol targetSymbol = null; |
394 |
foreach (var item in run.RUNITEMS) |
395 |
{ |
396 |
if (item.GetType() == typeof(Symbol)) |
397 |
{ |
398 |
Symbol symbol = item as Symbol; |
399 |
SymbolModeling(symbol, targetSymbol, prevSymbol); |
400 |
prevSymbol = symbol; |
401 |
targetSymbol = symbol; |
402 |
} |
403 |
else |
404 |
{ |
405 |
targetSymbol = null; |
406 |
} |
407 |
} |
408 |
} |
409 |
|
410 |
private void SymbolModelingByRunStart(Symbol symbol, LineRun run) |
411 |
{ |
412 |
foreach (var connector in symbol.CONNECTORS) |
413 |
{ |
414 |
object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
415 |
if (targetItem != null && |
416 |
(targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) && |
417 |
!IsSameLineNumber(symbol, targetItem)) |
418 |
{ |
419 |
SymbolModeling(symbol, targetItem as Symbol, null); |
420 |
for (int i = 1; i < run.RUNITEMS.Count; i++) |
421 |
{ |
422 |
object item = run.RUNITEMS[i]; |
423 |
if (item.GetType() == typeof(Symbol)) |
424 |
SymbolModeling(item as Symbol, run.RUNITEMS[i - 1] as Symbol, null); |
425 |
else |
426 |
break; |
427 |
} |
428 |
break; |
429 |
} |
430 |
} |
431 |
|
432 |
|
433 |
} |
434 |
|
435 |
private void SymbolModelingByRunEnd(Symbol symbol, LineRun run) |
436 |
{ |
437 |
foreach (var connector in symbol.CONNECTORS) |
438 |
{ |
439 |
object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
440 |
if (targetItem != null && |
441 |
(targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) && |
442 |
!IsSameLineNumber(symbol, targetItem)) |
443 |
{ |
444 |
SymbolModeling(symbol, targetItem as Symbol, null); |
445 |
for (int i = run.RUNITEMS.Count - 2; i >= 0; i--) |
446 |
{ |
447 |
object item = run.RUNITEMS[i]; |
448 |
if (item.GetType() == typeof(Symbol)) |
449 |
SymbolModeling(item as Symbol, run.RUNITEMS[i + 1] as Symbol, null); |
450 |
else |
451 |
break; |
452 |
} |
453 |
break; |
454 |
} |
455 |
} |
456 |
} |
457 |
|
458 |
private void SymbolModeling(Symbol symbol, Symbol targetSymbol, Symbol prevSymbol) |
459 |
{ |
460 |
// 임시 |
461 |
if (symbol.SPPID.MAPPINGNAME.Contains("Labels - ")) |
462 |
return; |
463 |
|
464 |
if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
465 |
return; |
466 |
|
467 |
LMSymbol _LMSymbol = null; |
468 |
|
469 |
string mappingPath = symbol.SPPID.MAPPINGNAME; |
470 |
double x = symbol.SPPID.ORIGINAL_X; |
471 |
double y = symbol.SPPID.ORIGINAL_Y; |
472 |
int mirror = 0; |
473 |
double angle = symbol.ANGLE; |
474 |
// 임시 |
475 |
if (mappingPath.Contains("Piping OPC's") && angle == Math.PI) |
476 |
{ |
477 |
mirror = 1; |
478 |
} |
479 |
|
480 |
|
481 |
if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId)) |
482 |
{ |
483 |
LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); |
484 |
|
485 |
Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()]; |
486 |
double x1 = 0; |
487 |
double x2 = 0; |
488 |
double y1 = 0; |
489 |
double y2 = 0; |
490 |
symbol2d.Range(out x1, out y1, out x2, out y2); |
491 |
|
492 |
if (y2 < y) |
493 |
y = y2; |
494 |
else if (y1 > y) |
495 |
y = y1; |
496 |
|
497 |
if (x2 < x) |
498 |
x = x2; |
499 |
else if (x1 > x) |
500 |
x = x1; |
501 |
|
502 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem); |
503 |
ReleaseCOMObjects(_TargetItem); |
504 |
} |
505 |
else if (prevSymbol != null) |
506 |
{ |
507 |
LMSymbol _PrevSymbol = dataSource.GetSymbol(prevSymbol.SPPID.RepresentationId); |
508 |
SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y); |
509 |
double prevX = _PrevSymbol.get_XCoordinate(); |
510 |
double prevY = _PrevSymbol.get_YCoordinate(); |
511 |
if (slopeType == SlopeType.HORIZONTAL) |
512 |
y = prevY; |
513 |
else if (slopeType == SlopeType.VERTICAL) |
514 |
x = prevX; |
515 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
516 |
} |
517 |
else |
518 |
{ |
519 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
520 |
} |
521 |
|
522 |
|
523 |
if (_LMSymbol != null) |
524 |
{ |
525 |
_LMSymbol.Commit(); |
526 |
symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
527 |
|
528 |
foreach (var item in symbol.ChildSymbols) |
529 |
CreateChildSymbol(item, _LMSymbol); |
530 |
} |
531 |
|
532 |
ReleaseCOMObjects(_LMSymbol); |
533 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
534 |
} |
535 |
|
536 |
private void EquipmentModeling(Equipment equipment) |
537 |
{ |
538 |
if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId)) |
539 |
return; |
540 |
|
541 |
LMSymbol _LMSymbol = null; |
542 |
LMSymbol targetItem = null; |
543 |
string mappingPath = equipment.SPPID.MAPPINGNAME; |
544 |
double x = equipment.SPPID.ORIGINAL_X; |
545 |
double y = equipment.SPPID.ORIGINAL_Y; |
546 |
int mirror = 0; |
547 |
double angle = equipment.ANGLE; |
548 |
|
549 |
Connector connector = equipment.CONNECTORS.Find(conn => !string.IsNullOrEmpty(conn.CONNECTEDITEM) && conn.CONNECTEDITEM != "None"); |
550 |
if (connector != null) |
551 |
{ |
552 |
Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment; |
553 |
if (connEquipment != null) |
554 |
{ |
555 |
if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId)) |
556 |
EquipmentModeling(connEquipment); |
557 |
|
558 |
if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId)) |
559 |
{ |
560 |
targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId); |
561 |
if (targetItem != null) |
562 |
{ |
563 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem); |
564 |
} |
565 |
else |
566 |
{ |
567 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
568 |
} |
569 |
} |
570 |
else |
571 |
{ |
572 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
573 |
} |
574 |
} |
575 |
else |
576 |
{ |
577 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
578 |
} |
579 |
} |
580 |
else |
581 |
{ |
582 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
583 |
} |
584 |
|
585 |
if (_LMSymbol != null) |
586 |
{ |
587 |
_LMSymbol.Commit(); |
588 |
equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
589 |
ReleaseCOMObjects(_LMSymbol); |
590 |
} |
591 |
|
592 |
if (targetItem != null) |
593 |
{ |
594 |
ReleaseCOMObjects(targetItem); |
595 |
} |
596 |
|
597 |
ReleaseCOMObjects(_LMSymbol); |
598 |
|
599 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
600 |
} |
601 |
|
602 |
private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol) |
603 |
{ |
604 |
Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()]; |
605 |
double x1 = 0; |
606 |
double x2 = 0; |
607 |
double y1 = 0; |
608 |
double y2 = 0; |
609 |
symbol2d.Range(out x1, out y1, out x2, out y2); |
610 |
|
611 |
LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol); |
612 |
if (_LMSymbol != null) |
613 |
{ |
614 |
childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
615 |
foreach (var item in childSymbol.ChildSymbols) |
616 |
CreateChildSymbol(item, _LMSymbol); |
617 |
} |
618 |
|
619 |
|
620 |
ReleaseCOMObjects(_LMSymbol); |
621 |
} |
622 |
|
623 |
private bool IsSameLineNumber(object item, object targetItem) |
624 |
{ |
625 |
foreach (var lineNumber in document.LINENUMBERS) |
626 |
{ |
627 |
foreach (var run in lineNumber.RUNS) |
628 |
{ |
629 |
foreach (var runItem in run.RUNITEMS) |
630 |
{ |
631 |
if (runItem == item) |
632 |
{ |
633 |
foreach (var findItem in run.RUNITEMS) |
634 |
{ |
635 |
if (findItem == targetItem) |
636 |
{ |
637 |
return true; |
638 |
} |
639 |
} |
640 |
|
641 |
return false; |
642 |
|
643 |
} |
644 |
} |
645 |
} |
646 |
} |
647 |
|
648 |
return false; |
649 |
} |
650 |
|
651 |
private void LineModeling(List<Line> lines) |
652 |
{ |
653 |
_LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
654 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
655 |
LMSymbol _LMSymbol1 = null; |
656 |
LMSymbol _LMSymbol2 = null; |
657 |
Dictionary<LMConnector, List<double[]>> connectorVertices1 = new Dictionary<LMConnector, List<double[]>>(); |
658 |
LMConnector targetConnector1 = null; |
659 |
Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>(); |
660 |
LMConnector targetConnector2 = null; |
661 |
|
662 |
Line startBranchLine = null; |
663 |
Line endBranchLine = null; |
664 |
|
665 |
for (int i = 0; i < lines.Count; i++) |
666 |
{ |
667 |
Line line = lines[i]; |
668 |
if (i == 0 || i + 1 != lines.Count) |
669 |
{ |
670 |
// 시작점에 연결된 Symbol 찾기 |
671 |
object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM); |
672 |
if (connItem != null && connItem.GetType() == typeof(Symbol)) |
673 |
{ |
674 |
_LMSymbol1 = GetTargetSymbol(connItem as Symbol, line); |
675 |
if (_LMSymbol1 != null) |
676 |
placeRunInputs.AddSymbolTarget(_LMSymbol1, line.SPPID.START_X, line.SPPID.START_Y); |
677 |
else |
678 |
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
679 |
} |
680 |
else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem)) |
681 |
{ |
682 |
connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId); |
683 |
targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y); |
684 |
|
685 |
if (targetConnector1 != null) |
686 |
placeRunInputs.AddConnectorTarget(targetConnector1, line.SPPID.START_X, line.SPPID.START_Y); |
687 |
else |
688 |
{ |
689 |
startBranchLine = connItem as Line; |
690 |
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
691 |
} |
692 |
} |
693 |
else |
694 |
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
695 |
} |
696 |
|
697 |
if (i + 1 == lines.Count) |
698 |
{ |
699 |
// 끝점에 연결된 Symbol 찾기 |
700 |
object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM); |
701 |
|
702 |
if (i != 0) |
703 |
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
704 |
|
705 |
if (connItem != null && connItem.GetType() == typeof(Symbol)) |
706 |
{ |
707 |
_LMSymbol2 = GetTargetSymbol(connItem as Symbol, line); |
708 |
if (_LMSymbol2 != null) |
709 |
placeRunInputs.AddSymbolTarget(_LMSymbol2, line.SPPID.END_X, line.SPPID.END_Y); |
710 |
else |
711 |
placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
712 |
|
713 |
} |
714 |
else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem)) |
715 |
{ |
716 |
connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId); |
717 |
targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y); |
718 |
|
719 |
if (targetConnector2 != null) |
720 |
placeRunInputs.AddConnectorTarget(targetConnector2, line.SPPID.END_X, line.SPPID.END_Y); |
721 |
else |
722 |
{ |
723 |
endBranchLine = connItem as Line; |
724 |
placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
725 |
} |
726 |
} |
727 |
else |
728 |
{ |
729 |
placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
730 |
} |
731 |
} |
732 |
} |
733 |
|
734 |
LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
735 |
|
736 |
if (_lMConnector != null) |
737 |
{ |
738 |
foreach (var line in lines) |
739 |
line.SPPID.ModelItemId = _lMConnector.ModelItemID; |
740 |
_lMConnector.Commit(); |
741 |
if (startBranchLine != null || endBranchLine != null) |
742 |
{ |
743 |
BranchLines.Add(new Tuple<string, Line, Line>(_lMConnector.ModelItemID, startBranchLine, endBranchLine)); |
744 |
} |
745 |
} |
746 |
|
747 |
|
748 |
if (_LMSymbol1 != null) |
749 |
ReleaseCOMObjects(_LMSymbol1); |
750 |
if (_LMSymbol2 != null) |
751 |
ReleaseCOMObjects(_LMSymbol2); |
752 |
if (targetConnector1 != null) |
753 |
ReleaseCOMObjects(targetConnector1); |
754 |
if (targetConnector2 != null) |
755 |
ReleaseCOMObjects(targetConnector2); |
756 |
foreach (var item in connectorVertices1) |
757 |
ReleaseCOMObjects(item.Key); |
758 |
foreach (var item in connectorVertices2) |
759 |
ReleaseCOMObjects(item.Key); |
760 |
|
761 |
ReleaseCOMObjects(_lMConnector); |
762 |
ReleaseCOMObjects(placeRunInputs); |
763 |
ReleaseCOMObjects(_LMAItem); |
764 |
} |
765 |
|
766 |
private LMSymbol GetTargetSymbol(Symbol symbol, Line line) |
767 |
{ |
768 |
LMSymbol _LMSymbol = null; |
769 |
foreach (var connector in symbol.CONNECTORS) |
770 |
{ |
771 |
if (connector.CONNECTEDITEM == line.UID) |
772 |
{ |
773 |
if (connector.Index == 0) |
774 |
_LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
775 |
else |
776 |
{ |
777 |
ChildSymbol child = null; |
778 |
foreach (var childSymbol in symbol.ChildSymbols) |
779 |
{ |
780 |
if (childSymbol.Connectors.Contains(connector)) |
781 |
child = childSymbol; |
782 |
else |
783 |
child = GetChildSymbolByConnector(childSymbol, connector); |
784 |
|
785 |
if (child != null) |
786 |
break; |
787 |
} |
788 |
|
789 |
if (child != null) |
790 |
_LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId); |
791 |
} |
792 |
|
793 |
break; |
794 |
} |
795 |
} |
796 |
|
797 |
return _LMSymbol; |
798 |
} |
799 |
|
800 |
private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector) |
801 |
{ |
802 |
foreach (var childSymbol in item.ChildSymbols) |
803 |
{ |
804 |
if (childSymbol.Connectors.Contains(connector)) |
805 |
return childSymbol; |
806 |
else |
807 |
return GetChildSymbolByConnector(childSymbol, connector); |
808 |
} |
809 |
|
810 |
return null; |
811 |
} |
812 |
|
813 |
private void BranchLineModeling(Tuple<string, Line, Line> branch) |
814 |
{ |
815 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1); |
816 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1); |
817 |
|
818 |
LMConnector _StartConnector = null; |
819 |
LMConnector _EndConnector = null; |
820 |
double lengthStart = double.MaxValue; |
821 |
double lengthEnd = double.MaxValue; |
822 |
List<double[]> startPoints = new List<double[]>(); |
823 |
List<double[]> endPoints = new List<double[]>(); |
824 |
|
825 |
foreach (var item in connectorVertices) |
826 |
{ |
827 |
foreach (var point in item.Value) |
828 |
{ |
829 |
// Start Point가 Branch |
830 |
if (branch.Item2 != null) |
831 |
{ |
832 |
Line targetLine = branch.Item2; |
833 |
double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]); |
834 |
if (lengthStart > distance) |
835 |
{ |
836 |
_StartConnector = item.Key; |
837 |
lengthStart = distance; |
838 |
startPoints = item.Value; |
839 |
} |
840 |
} |
841 |
// End Point가 Branch |
842 |
if (branch.Item3 != null) |
843 |
{ |
844 |
Line targetLine = branch.Item3; |
845 |
double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]); |
846 |
if (lengthEnd > distance) |
847 |
{ |
848 |
_EndConnector = item.Key; |
849 |
lengthEnd = distance; |
850 |
endPoints = item.Value; |
851 |
} |
852 |
} |
853 |
} |
854 |
} |
855 |
#region Branch가 양쪽 전부일 때 |
856 |
if (_StartConnector != null && _StartConnector == _EndConnector) |
857 |
{ |
858 |
_placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation()); |
859 |
|
860 |
_LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
861 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
862 |
|
863 |
Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId); |
864 |
LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]); |
865 |
Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId); |
866 |
LMConnector _EndTargetConnector = FindTargetLMConnector(endConnectorVertices, |
867 |
startPoints[startPoints.Count - 1][0], |
868 |
startPoints[startPoints.Count - 1][1], |
869 |
startPoints[startPoints.Count - 2][0], |
870 |
startPoints[startPoints.Count - 2][1]); |
871 |
|
872 |
for (int i = 0; i < startPoints.Count; i++) |
873 |
{ |
874 |
double[] point = startPoints[i]; |
875 |
if (i == 0) |
876 |
placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]); |
877 |
else if (i == startPoints.Count - 1) |
878 |
placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]); |
879 |
else |
880 |
placeRunInputs.AddPoint(point[0], point[1]); |
881 |
} |
882 |
|
883 |
LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
884 |
if (_LMConnector != null) |
885 |
{ |
886 |
_LMConnector.Commit(); |
887 |
foreach (var item in lines) |
888 |
item.SPPID.ModelItemId = _LMConnector.ModelItemID; |
889 |
} |
890 |
|
891 |
foreach (var item in startConnectorVertices) |
892 |
ReleaseCOMObjects(item.Key); |
893 |
foreach (var item in endConnectorVertices) |
894 |
ReleaseCOMObjects(item.Key); |
895 |
ReleaseCOMObjects(placeRunInputs); |
896 |
ReleaseCOMObjects(_LMAItem); |
897 |
ReleaseCOMObjects(_LMConnector); |
898 |
} |
899 |
#endregion |
900 |
#region 양쪽이 다른 Branch |
901 |
else |
902 |
{ |
903 |
// Branch 시작 Connector |
904 |
if (_StartConnector != null) |
905 |
BranchLineModelingByConnector(branch, _StartConnector, startPoints, true); |
906 |
|
907 |
// Branch 끝 Connector |
908 |
if (_EndConnector != null) |
909 |
BranchLineModelingByConnector(branch, _EndConnector, endPoints, false); |
910 |
} |
911 |
#endregion |
912 |
|
913 |
if (_StartConnector != null) |
914 |
ReleaseCOMObjects(_StartConnector); |
915 |
if (_EndConnector != null) |
916 |
ReleaseCOMObjects(_EndConnector); |
917 |
foreach (var item in connectorVertices) |
918 |
ReleaseCOMObjects(item.Key); |
919 |
} |
920 |
|
921 |
private void BranchLineModelingByConnector(Tuple<string, Line, Line> branch, LMConnector _Connector, List<double[]> points, bool IsStart) |
922 |
{ |
923 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1); |
924 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1); |
925 |
LMConnector _SameRunTargetConnector = null; |
926 |
LMSymbol _SameRunTargetSymbol = null; |
927 |
Dictionary<LMConnector, List<double[]>> branchConnectorVertices = null; |
928 |
LMConnector _BranchTargetConnector = null; |
929 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
930 |
|
931 |
// 같은 Line Run의 Connector 찾기 |
932 |
foreach (var item in connectorVertices) |
933 |
{ |
934 |
if (item.Key == _Connector) |
935 |
continue; |
936 |
|
937 |
if (IsStart && |
938 |
!DBNull.Value.Equals(item.Key.ConnectItem1SymbolID) && |
939 |
!DBNull.Value.Equals(_Connector.ConnectItem2SymbolID)&& |
940 |
item.Key.ConnectItem1SymbolID == _Connector.ConnectItem2SymbolID) |
941 |
{ |
942 |
_SameRunTargetConnector = item.Key; |
943 |
break; |
944 |
} |
945 |
else if (!IsStart && |
946 |
!DBNull.Value.Equals(item.Key.ConnectItem2SymbolID) && |
947 |
!DBNull.Value.Equals(_Connector.ConnectItem1SymbolID) && |
948 |
item.Key.ConnectItem2SymbolID == _Connector.ConnectItem1SymbolID) |
949 |
{ |
950 |
_SameRunTargetConnector = item.Key; |
951 |
break; |
952 |
} |
953 |
} |
954 |
|
955 |
// Branch 반대편이 Symbol |
956 |
if (_SameRunTargetConnector == null) |
957 |
{ |
958 |
foreach (var line in lines) |
959 |
{ |
960 |
foreach (var connector in line.CONNECTORS) |
961 |
{ |
962 |
Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol; |
963 |
if (symbol != null) |
964 |
{ |
965 |
_SameRunTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
966 |
break; |
967 |
} |
968 |
} |
969 |
} |
970 |
} |
971 |
|
972 |
// 기존 Connector 제거 |
973 |
_placement.PIDRemovePlacement(_Connector.AsLMRepresentation()); |
974 |
|
975 |
// 시작 Connector일 경우 첫 Point가 TargetConnector를 찾아야함 |
976 |
if (IsStart) |
977 |
{ |
978 |
branchConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId); |
979 |
_BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, points[0][0], points[0][1], points[1][0], points[1][1]); |
980 |
} |
981 |
// 끝 Conenctor일 경우 마지막 Point가 TargetConnector를 찾아야함 |
982 |
else |
983 |
{ |
984 |
branchConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId); |
985 |
_BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, |
986 |
points[points.Count - 1][0], |
987 |
points[points.Count - 1][1], |
988 |
points[points.Count - 2][0], |
989 |
points[points.Count - 2][1]); |
990 |
} |
991 |
|
992 |
for (int i = 0; i < points.Count; i++) |
993 |
{ |
994 |
double[] point = points[i]; |
995 |
if (i == 0) |
996 |
{ |
997 |
if (IsStart) |
998 |
{ |
999 |
placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]); |
1000 |
} |
1001 |
else |
1002 |
{ |
1003 |
if (_SameRunTargetConnector != null) |
1004 |
placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]); |
1005 |
else if (_SameRunTargetSymbol != null) |
1006 |
placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]); |
1007 |
else |
1008 |
placeRunInputs.AddPoint(point[0], point[1]); |
1009 |
} |
1010 |
} |
1011 |
else if (i == points.Count - 1) |
1012 |
{ |
1013 |
if (IsStart) |
1014 |
{ |
1015 |
if (_SameRunTargetConnector != null) |
1016 |
placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]); |
1017 |
else if (_SameRunTargetSymbol != null) |
1018 |
placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]); |
1019 |
else |
1020 |
placeRunInputs.AddPoint(point[0], point[1]); |
1021 |
} |
1022 |
else |
1023 |
{ |
1024 |
if (_BranchTargetConnector != null) |
1025 |
{ |
1026 |
placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]); |
1027 |
} |
1028 |
} |
1029 |
} |
1030 |
else |
1031 |
placeRunInputs.AddPoint(point[0], point[1]); |
1032 |
} |
1033 |
_LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
1034 |
LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
1035 |
|
1036 |
if (_LMConnector != null) |
1037 |
{ |
1038 |
if (_SameRunTargetConnector != null) |
1039 |
{ |
1040 |
JoinPipeRun(_LMConnector.ModelItemID, _SameRunTargetConnector.ModelItemID); |
1041 |
} |
1042 |
else |
1043 |
{ |
1044 |
foreach (var item in lines) |
1045 |
item.SPPID.ModelItemId = _LMConnector.ModelItemID; |
1046 |
} |
1047 |
|
1048 |
_LMConnector.Commit(); |
1049 |
ReleaseCOMObjects(_LMConnector); |
1050 |
} |
1051 |
|
1052 |
ReleaseCOMObjects(placeRunInputs); |
1053 |
ReleaseCOMObjects(_LMAItem); |
1054 |
if (_BranchTargetConnector != null) |
1055 |
ReleaseCOMObjects(_BranchTargetConnector); |
1056 |
if (_SameRunTargetConnector != null) |
1057 |
ReleaseCOMObjects(_SameRunTargetConnector); |
1058 |
if (_SameRunTargetSymbol != null) |
1059 |
ReleaseCOMObjects(_SameRunTargetSymbol); |
1060 |
foreach (var item in connectorVertices) |
1061 |
ReleaseCOMObjects(item.Key); |
1062 |
foreach (var item in branchConnectorVertices) |
1063 |
ReleaseCOMObjects(item.Key); |
1064 |
} |
1065 |
|
1066 |
private void EndBreakModeling(EndBreak endBreak) |
1067 |
{ |
1068 |
object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER); |
1069 |
LMConnector targetLMConnector = null; |
1070 |
if (ownerObj !=null && ownerObj.GetType() == typeof(Line)) |
1071 |
{ |
1072 |
Line ownerLine = ownerObj as Line; |
1073 |
LMLabelPersist _LmLabelPersist = null; |
1074 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(ownerLine.SPPID.ModelItemId); |
1075 |
|
1076 |
targetLMConnector = FindTargetLMConnectorByPoint(connectorVertices, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y); |
1077 |
|
1078 |
if (targetLMConnector != null) |
1079 |
{ |
1080 |
//double[] point = connectorVertices[targetLMConnector][connectorVertices[targetLMConnector].Count - 1]; |
1081 |
//Array array = new double[] { 0, point[0], point[1] }; |
1082 |
Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y }; |
1083 |
_LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
1084 |
} |
1085 |
|
1086 |
if (_LmLabelPersist != null) |
1087 |
{ |
1088 |
_LmLabelPersist.Commit(); |
1089 |
ReleaseCOMObjects(_LmLabelPersist); |
1090 |
} |
1091 |
else |
1092 |
RetryEndBreakModeling(endBreak, targetLMConnector); |
1093 |
|
1094 |
foreach (var item in connectorVertices) |
1095 |
ReleaseCOMObjects(item.Key); |
1096 |
|
1097 |
} |
1098 |
else if (ownerObj != null && ownerObj.GetType() == typeof(Symbol)) |
1099 |
{ |
1100 |
Symbol ownerSymbol = ownerObj as Symbol; |
1101 |
LMSymbol _LMSymbol = dataSource.GetSymbol(ownerSymbol.SPPID.RepresentationId); |
1102 |
|
1103 |
targetLMConnector = null; |
1104 |
double distance = double.MaxValue; |
1105 |
|
1106 |
foreach (LMConnector connector in _LMSymbol.Avoid1Connectors) |
1107 |
{ |
1108 |
if (connector.get_ItemStatus() == "Active") |
1109 |
{ |
1110 |
dynamic OID = connector.get_GraphicOID(); |
1111 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
1112 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
1113 |
int verticesCount = lineStringGeometry.VertexCount; |
1114 |
double[] vertices = null; |
1115 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
1116 |
for (int i = 0; i < verticesCount; i++) |
1117 |
{ |
1118 |
double x = 0; |
1119 |
double y = 0; |
1120 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
1121 |
|
1122 |
double result = SPPIDUtil.CalcPointToPointdDistance(x, y, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y); |
1123 |
if (result < distance) |
1124 |
{ |
1125 |
targetLMConnector = connector; |
1126 |
distance = result; |
1127 |
} |
1128 |
} |
1129 |
} |
1130 |
} |
1131 |
|
1132 |
foreach (LMConnector connector in _LMSymbol.Avoid2Connectors) |
1133 |
{ |
1134 |
if (connector.get_ItemStatus() == "Active") |
1135 |
{ |
1136 |
dynamic OID = connector.get_GraphicOID(); |
1137 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
1138 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
1139 |
int verticesCount = lineStringGeometry.VertexCount; |
1140 |
double[] vertices = null; |
1141 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
1142 |
for (int i = 0; i < verticesCount; i++) |
1143 |
{ |
1144 |
double x = 0; |
1145 |
double y = 0; |
1146 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
1147 |
|
1148 |
double result = SPPIDUtil.CalcPointToPointdDistance(x, y, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y); |
1149 |
if (result < distance) |
1150 |
{ |
1151 |
targetLMConnector = connector; |
1152 |
distance = result; |
1153 |
} |
1154 |
} |
1155 |
} |
1156 |
} |
1157 |
|
1158 |
if (targetLMConnector != null) |
1159 |
{ |
1160 |
LMLabelPersist _LmLabelPersist = null; |
1161 |
Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y }; |
1162 |
_LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
1163 |
if (_LmLabelPersist != null) |
1164 |
{ |
1165 |
_LmLabelPersist.Commit(); |
1166 |
ReleaseCOMObjects(_LmLabelPersist); |
1167 |
} |
1168 |
else |
1169 |
RetryEndBreakModeling(endBreak, targetLMConnector); |
1170 |
} |
1171 |
|
1172 |
ReleaseCOMObjects(_LMSymbol); |
1173 |
} |
1174 |
|
1175 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
1176 |
} |
1177 |
|
1178 |
private void RetryEndBreakModeling(EndBreak endBreak, LMConnector targetLMConnector) |
1179 |
{ |
1180 |
bool isZeroLength = Convert.ToBoolean(targetLMConnector.get_IsZeroLength()); |
1181 |
Array array = null; |
1182 |
LMLabelPersist _LMLabelPersist = null; |
1183 |
LMConnector _LMConnector = null; |
1184 |
dynamic OID = targetLMConnector.get_GraphicOID(); |
1185 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
1186 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
1187 |
int verticesCount = lineStringGeometry.VertexCount; |
1188 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
1189 |
_LMAItem _LMAItem = _placement.PIDCreateItem(@"\Piping\Routing\Process Lines\Primary Piping.sym"); |
1190 |
|
1191 |
if (isZeroLength) |
1192 |
{ |
1193 |
double[] vertices = null; |
1194 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
1195 |
double x = 0; |
1196 |
double y = 0; |
1197 |
lineStringGeometry.GetVertex(1, ref x, ref y); |
1198 |
|
1199 |
placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem1SymbolObject, x, y); |
1200 |
placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem2SymbolObject, x, y); |
1201 |
|
1202 |
_placement.PIDRemovePlacement(targetLMConnector.AsLMRepresentation()); |
1203 |
_LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
1204 |
|
1205 |
array = new double[] { 0, x, y }; |
1206 |
_LMLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: _LMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
1207 |
|
1208 |
AutoJoinPipeRun(_LMConnector.ModelItemID); |
1209 |
} |
1210 |
else |
1211 |
{ |
1212 |
List<double[]> vertices = new List<double[]>(); |
1213 |
for (int i = 1; i <= verticesCount; i++) |
1214 |
{ |
1215 |
double x = 0; |
1216 |
double y = 0; |
1217 |
lineStringGeometry.GetVertex(i, ref x, ref y); |
1218 |
vertices.Add(new double[] { x, y }); |
1219 |
} |
1220 |
|
1221 |
for (int i = 0; i < vertices.Count; i++) |
1222 |
{ |
1223 |
double[] points = vertices[i]; |
1224 |
if (i == 0) |
1225 |
{ |
1226 |
if (targetLMConnector.ConnectItem1SymbolObject != null) |
1227 |
placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem1SymbolObject, points[0], points[1]); |
1228 |
else |
1229 |
placeRunInputs.AddPoint(points[0], points[1]); |
1230 |
} |
1231 |
else if (i == vertices.Count - 1) |
1232 |
{ |
1233 |
if (targetLMConnector.ConnectItem2SymbolObject != null) |
1234 |
placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem2SymbolObject, points[0], points[1]); |
1235 |
else |
1236 |
placeRunInputs.AddPoint(points[0], points[1]); |
1237 |
} |
1238 |
else |
1239 |
placeRunInputs.AddPoint(points[0], points[1]); |
1240 |
} |
1241 |
|
1242 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, targetLMConnector.ModelItemID); |
1243 |
|
1244 |
_placement.PIDRemovePlacement(targetLMConnector.AsLMRepresentation()); |
1245 |
_LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
1246 |
|
1247 |
array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y }; |
1248 |
_LMLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: _LMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
1249 |
|
1250 |
AutoJoinPipeRun(_LMConnector.ModelItemID); |
1251 |
foreach (var line in lines) |
1252 |
line.SPPID.ModelItemId = _LMConnector.ModelItemID; |
1253 |
} |
1254 |
|
1255 |
|
1256 |
if (_LMLabelPersist != null) |
1257 |
{ |
1258 |
_LMLabelPersist.Commit(); |
1259 |
ReleaseCOMObjects(_LMLabelPersist); |
1260 |
} |
1261 |
else |
1262 |
{ |
1263 |
|
1264 |
} |
1265 |
|
1266 |
ReleaseCOMObjects(_LMConnector); |
1267 |
ReleaseCOMObjects(placeRunInputs); |
1268 |
ReleaseCOMObjects(_LMAItem); |
1269 |
} |
1270 |
|
1271 |
private void JoinPipeRun(string fromModelItemId, string toModelItemId) |
1272 |
{ |
1273 |
LMModelItem modelItem1 = dataSource.GetModelItem(toModelItemId); |
1274 |
_LMAItem item1 = modelItem1.AsLMAItem(); |
1275 |
LMModelItem modelItem2 = dataSource.GetModelItem(fromModelItemId); |
1276 |
_LMAItem item2 = modelItem2.AsLMAItem(); |
1277 |
|
1278 |
// item2가 item1으로 조인 |
1279 |
try |
1280 |
{ |
1281 |
_placement.PIDJoinRuns(ref item1, ref item2); |
1282 |
item1.Commit(); |
1283 |
item2.Commit(); |
1284 |
|
1285 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, fromModelItemId); |
1286 |
foreach (var line in lines) |
1287 |
line.SPPID.ModelItemId = toModelItemId; |
1288 |
} |
1289 |
catch (Exception ex) |
1290 |
{ |
1291 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
1292 |
} |
1293 |
finally |
1294 |
{ |
1295 |
ReleaseCOMObjects(modelItem1); |
1296 |
ReleaseCOMObjects(item1); |
1297 |
ReleaseCOMObjects(modelItem2); |
1298 |
ReleaseCOMObjects(item2); |
1299 |
} |
1300 |
} |
1301 |
|
1302 |
private void AutoJoinPipeRun(string modelItemId) |
1303 |
{ |
1304 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemId); |
1305 |
_LMAItem item = modelItem.AsLMAItem(); |
1306 |
try |
1307 |
{ |
1308 |
string modelitemID = item.Id; |
1309 |
_placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item); |
1310 |
string afterModelItemID = item.Id; |
1311 |
|
1312 |
if (modelitemID != afterModelItemID) |
1313 |
{ |
1314 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID); |
1315 |
foreach (var line in lines) |
1316 |
line.SPPID.ModelItemId = afterModelItemID; |
1317 |
} |
1318 |
item.Commit(); |
1319 |
} |
1320 |
catch (Exception ex) |
1321 |
{ |
1322 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
1323 |
} |
1324 |
finally |
1325 |
{ |
1326 |
ReleaseCOMObjects(modelItem); |
1327 |
ReleaseCOMObjects(item); |
1328 |
} |
1329 |
} |
1330 |
|
1331 |
private void JoinRunLine(LineRun run) |
1332 |
{ |
1333 |
string modelItemId = string.Empty; |
1334 |
foreach (var item in run.RUNITEMS) |
1335 |
{ |
1336 |
if (item.GetType() == typeof(Line)) |
1337 |
{ |
1338 |
Line line = item as Line; |
1339 |
AutoJoinPipeRun(line.SPPID.ModelItemId); |
1340 |
modelItemId = line.SPPID.ModelItemId; |
1341 |
|
1342 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
1343 |
} |
1344 |
} |
1345 |
} |
1346 |
|
1347 |
private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId) |
1348 |
{ |
1349 |
Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>(); |
1350 |
LMModelItem modelItem = dataSource.GetModelItem(modelId); |
1351 |
|
1352 |
if (modelItem != null) |
1353 |
{ |
1354 |
foreach (LMRepresentation rep in modelItem.Representations) |
1355 |
{ |
1356 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
1357 |
{ |
1358 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
1359 |
connectorVertices.Add(_LMConnector, new List<double[]>()); |
1360 |
dynamic OID = rep.get_GraphicOID(); |
1361 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
1362 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
1363 |
int verticesCount = lineStringGeometry.VertexCount; |
1364 |
double[] vertices = null; |
1365 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
1366 |
for (int i = 0; i < verticesCount; i++) |
1367 |
{ |
1368 |
double x = 0; |
1369 |
double y = 0; |
1370 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
1371 |
connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) }); |
1372 |
} |
1373 |
} |
1374 |
} |
1375 |
|
1376 |
ReleaseCOMObjects(modelItem); |
1377 |
} |
1378 |
|
1379 |
return connectorVertices; |
1380 |
} |
1381 |
|
1382 |
private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2) |
1383 |
{ |
1384 |
double length = double.MaxValue; |
1385 |
LMConnector targetConnector = null; |
1386 |
foreach (var item in connectorVertices) |
1387 |
{ |
1388 |
List<double[]> points = item.Value; |
1389 |
for (int i = 0; i < points.Count - 1; i++) |
1390 |
{ |
1391 |
double[] point1 = points[i]; |
1392 |
double[] point2 = points[i + 1]; |
1393 |
|
1394 |
double maxLineX = Math.Max(point1[0], point2[0]); |
1395 |
double minLineX = Math.Min(point1[0], point2[0]); |
1396 |
double maxLineY = Math.Max(point1[1], point2[1]); |
1397 |
double minLineY = Math.Min(point1[1], point2[1]); |
1398 |
|
1399 |
SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY); |
1400 |
|
1401 |
// 두직선의 교차점 |
1402 |
double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]); |
1403 |
if (crossingPoint != null) |
1404 |
{ |
1405 |
double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]); |
1406 |
if (length >= distance) |
1407 |
{ |
1408 |
if (slope == SlopeType.Slope && |
1409 |
minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] && |
1410 |
minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
1411 |
{ |
1412 |
targetConnector = item.Key; |
1413 |
length = distance; |
1414 |
} |
1415 |
else if (slope == SlopeType.HORIZONTAL && |
1416 |
minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0]) |
1417 |
{ |
1418 |
targetConnector = item.Key; |
1419 |
length = distance; |
1420 |
} |
1421 |
else if (slope == SlopeType.VERTICAL && |
1422 |
minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
1423 |
{ |
1424 |
targetConnector = item.Key; |
1425 |
length = distance; |
1426 |
} |
1427 |
} |
1428 |
} |
1429 |
} |
1430 |
|
1431 |
|
1432 |
} |
1433 |
|
1434 |
if (targetConnector == null) |
1435 |
{ |
1436 |
foreach (var item in connectorVertices) |
1437 |
{ |
1438 |
List<double[]> points = item.Value; |
1439 |
foreach (var point in points) |
1440 |
{ |
1441 |
double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, point[0], point[1]); |
1442 |
if (length >= distance) |
1443 |
{ |
1444 |
targetConnector = item.Key; |
1445 |
length = distance; |
1446 |
} |
1447 |
} |
1448 |
} |
1449 |
|
1450 |
} |
1451 |
|
1452 |
return targetConnector; |
1453 |
} |
1454 |
|
1455 |
private LMConnector FindTargetLMConnectorByPoint(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY) |
1456 |
{ |
1457 |
double length = double.MaxValue; |
1458 |
LMConnector targetConnector = null; |
1459 |
foreach (var item in connectorVertices) |
1460 |
{ |
1461 |
List<double[]> points = item.Value; |
1462 |
|
1463 |
foreach (double[] point in points) |
1464 |
{ |
1465 |
double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY); |
1466 |
if (length >= distance) |
1467 |
{ |
1468 |
targetConnector = item.Key; |
1469 |
length = distance; |
1470 |
} |
1471 |
} |
1472 |
} |
1473 |
|
1474 |
return targetConnector; |
1475 |
} |
1476 |
|
1477 |
private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY) |
1478 |
{ |
1479 |
double length = double.MaxValue; |
1480 |
LMConnector targetConnector = null; |
1481 |
foreach (var item in connectorVertices) |
1482 |
{ |
1483 |
List<double[]> points = item.Value; |
1484 |
for (int i = 0; i < points.Count - 1; i++) |
1485 |
{ |
1486 |
double[] point1 = points[i]; |
1487 |
double[] point2 = points[i + 1]; |
1488 |
double x1 = Math.Min(point1[0], point2[0]); |
1489 |
double y1 = Math.Min(point1[1], point2[1]); |
1490 |
double x2 = Math.Max(point1[0], point2[0]); |
1491 |
double y2 = Math.Max(point1[1], point2[1]); |
1492 |
|
1493 |
if ((x1 <= connX && x2 >= connX) || |
1494 |
(y1 <= connY && y2 >= connY)) |
1495 |
{ |
1496 |
double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY); |
1497 |
if (length >= distance) |
1498 |
{ |
1499 |
targetConnector = item.Key; |
1500 |
length = distance; |
1501 |
} |
1502 |
|
1503 |
distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY); |
1504 |
if (length >= distance) |
1505 |
{ |
1506 |
targetConnector = item.Key; |
1507 |
length = distance; |
1508 |
} |
1509 |
} |
1510 |
} |
1511 |
} |
1512 |
|
1513 |
// 못찾았을때. |
1514 |
length = double.MaxValue; |
1515 |
if (targetConnector == null) |
1516 |
{ |
1517 |
foreach (var item in connectorVertices) |
1518 |
{ |
1519 |
List<double[]> points = item.Value; |
1520 |
|
1521 |
foreach (double[] point in points) |
1522 |
{ |
1523 |
double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY); |
1524 |
if (length >= distance) |
1525 |
{ |
1526 |
targetConnector = item.Key; |
1527 |
length = distance; |
1528 |
} |
1529 |
} |
1530 |
} |
1531 |
} |
1532 |
|
1533 |
return targetConnector; |
1534 |
} |
1535 |
|
1536 |
private void LineNumberModeling(LineNumber lineNumber) |
1537 |
{ |
1538 |
Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line; |
1539 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId); |
1540 |
LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y); |
1541 |
if (connectedLMConnector != null) |
1542 |
{ |
1543 |
double x = 0; |
1544 |
double y = 0; |
1545 |
CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation); |
1546 |
|
1547 |
Array points = new double[] { 0, x, y }; |
1548 |
LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false); |
1549 |
|
1550 |
foreach (var item in connectorVertices) |
1551 |
ReleaseCOMObjects(item.Key); |
1552 |
if (_LmLabelPresist != null) |
1553 |
{ |
1554 |
_LmLabelPresist.Commit(); |
1555 |
lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id; |
1556 |
ReleaseCOMObjects(_LmLabelPresist); |
1557 |
} |
1558 |
else |
1559 |
{ |
1560 |
|
1561 |
} |
1562 |
} |
1563 |
|
1564 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
1565 |
} |
1566 |
|
1567 |
private void InputLineNumberAttribute(LineNumber lineNumber) |
1568 |
{ |
1569 |
foreach (LineRun run in lineNumber.RUNS) |
1570 |
{ |
1571 |
foreach (var item in run.RUNITEMS) |
1572 |
{ |
1573 |
if (item.GetType() == typeof(Symbol)) |
1574 |
{ |
1575 |
Symbol symbol = item as Symbol; |
1576 |
LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
1577 |
LMModelItem _LMModelItem = _LMSymbol.ModelItemObject; |
1578 |
|
1579 |
if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
1580 |
{ |
1581 |
foreach (var attribute in lineNumber.ATTRIBUTES) |
1582 |
{ |
1583 |
LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID); |
1584 |
if (mapping != null) |
1585 |
{ |
1586 |
LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME]; |
1587 |
if (_LMAAttribute != null) |
1588 |
{ |
1589 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
1590 |
_LMAAttribute.set_Value(attribute.VALUE); |
1591 |
else if (_LMAAttribute.get_Value() != attribute.VALUE) |
1592 |
_LMAAttribute.set_Value(attribute.VALUE); |
1593 |
} |
1594 |
} |
1595 |
} |
1596 |
_LMModelItem.Commit(); |
1597 |
} |
1598 |
if (_LMModelItem != null) |
1599 |
ReleaseCOMObjects(_LMModelItem); |
1600 |
if (_LMSymbol != null) |
1601 |
ReleaseCOMObjects(_LMSymbol); |
1602 |
} |
1603 |
else if (item.GetType() == typeof(Line)) |
1604 |
{ |
1605 |
Line line = item as Line; |
1606 |
if (line != null) |
1607 |
{ |
1608 |
LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId); |
1609 |
if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active") |
1610 |
{ |
1611 |
foreach (var attribute in lineNumber.ATTRIBUTES) |
1612 |
{ |
1613 |
LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID); |
1614 |
if (mapping != null) |
1615 |
{ |
1616 |
LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME]; |
1617 |
if (_LMAAttribute != null) |
1618 |
{ |
1619 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
1620 |
_LMAAttribute.set_Value(attribute.VALUE); |
1621 |
else if (_LMAAttribute.get_Value() != attribute.VALUE) |
1622 |
_LMAAttribute.set_Value(attribute.VALUE); |
1623 |
|
1624 |
} |
1625 |
} |
1626 |
} |
1627 |
_LMModelItem.Commit(); |
1628 |
} |
1629 |
if (_LMModelItem != null) |
1630 |
ReleaseCOMObjects(_LMModelItem); |
1631 |
} |
1632 |
} |
1633 |
} |
1634 |
} |
1635 |
|
1636 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
1637 |
} |
1638 |
|
1639 |
private void InputSymbolAttribute(Symbol symbol) |
1640 |
{ |
1641 |
try |
1642 |
{ |
1643 |
if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
1644 |
{ |
1645 |
LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
1646 |
LMModelItem _LMModelItem = _LMSymbol.ModelItemObject; |
1647 |
LMAAttributes _Attributes = _LMModelItem.Attributes; |
1648 |
|
1649 |
foreach (var item in symbol.PROPERTIES) |
1650 |
{ |
1651 |
|
1652 |
|
1653 |
} |
1654 |
|
1655 |
foreach (var item in symbol.ATTRIBUTES) |
1656 |
{ |
1657 |
AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID); |
1658 |
if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None") |
1659 |
{ |
1660 |
LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME]; |
1661 |
if (_Attribute != null) |
1662 |
{ |
1663 |
// 임시 |
1664 |
if (item.ATTRIBUTETYPE == "String") |
1665 |
{ |
1666 |
if (!string.IsNullOrEmpty(item.VALUE)) |
1667 |
{ |
1668 |
if (!DBNull.Value.Equals(_Attribute.get_Value()) && !string.IsNullOrEmpty(_Attribute.get_Value())) |
1669 |
{ |
1670 |
string value = _Attribute.get_Value() + "\n" + item.VALUE; |
1671 |
_Attribute.set_Value(value); |
1672 |
} |
1673 |
else |
1674 |
{ |
1675 |
_Attribute.set_Value(item.VALUE); |
1676 |
} |
1677 |
} |
1678 |
} |
1679 |
else |
1680 |
{ |
1681 |
_Attribute.set_Value(item.VALUE); |
1682 |
} |
1683 |
} |
1684 |
} |
1685 |
} |
1686 |
|
1687 |
foreach (var item in symbol.ASSOCIATIONS) |
1688 |
{ |
1689 |
|
1690 |
} |
1691 |
|
1692 |
ReleaseCOMObjects(_LMSymbol); |
1693 |
ReleaseCOMObjects(_Attributes); |
1694 |
ReleaseCOMObjects(_LMModelItem); |
1695 |
} |
1696 |
} |
1697 |
catch (Exception ex) |
1698 |
{ |
1699 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
1700 |
} |
1701 |
|
1702 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
1703 |
} |
1704 |
|
1705 |
private void TextModeling(Text text) |
1706 |
{ |
1707 |
LMSymbol _LMSymbol = null; |
1708 |
try |
1709 |
{ |
1710 |
//if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None") |
1711 |
if (text.ASSOCIATION) |
1712 |
{ |
1713 |
object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER); |
1714 |
if (owner.GetType() == typeof(Symbol)) |
1715 |
{ |
1716 |
Symbol symbol = owner as Symbol; |
1717 |
_LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
1718 |
if (_LMSymbol != null) |
1719 |
{ |
1720 |
Association association = symbol.ASSOCIATIONS.Find(x => x.VALUE == text.UID); |
1721 |
List<BaseModel.Attribute> attributes = symbol.ATTRIBUTES.FindAll(x => x.ATTRIBUTETYPE == association.TYPE); |
1722 |
AttributeMapping mapping = null; |
1723 |
foreach (var attribute in attributes) |
1724 |
{ |
1725 |
if (string.IsNullOrEmpty(attribute.VALUE) || attribute.VALUE == "None") |
1726 |
continue; |
1727 |
|
1728 |
mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME)); |
1729 |
if (mapping != null) |
1730 |
break; |
1731 |
} |
1732 |
|
1733 |
if (mapping != null) |
1734 |
{ |
1735 |
double x = 0; |
1736 |
double y = 0; |
1737 |
|
1738 |
CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location); |
1739 |
Array array = new double[] { 0, x, y }; |
1740 |
|
1741 |
LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine); |
1742 |
if (_LMLabelPersist!=null) |
1743 |
{ |
1744 |
_LMLabelPersist.Commit(); |
1745 |
ReleaseCOMObjects(_LMLabelPersist); |
1746 |
} |
1747 |
} |
1748 |
} |
1749 |
} |
1750 |
else if (owner.GetType() == typeof(Line)) |
1751 |
{ |
1752 |
|
1753 |
} |
1754 |
} |
1755 |
else |
1756 |
{ |
1757 |
LMItemNote _LMItemNote = null; |
1758 |
LMAAttribute _LMAAttribute = null; |
1759 |
|
1760 |
double x = 0; |
1761 |
double y = 0; |
1762 |
|
1763 |
CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation); |
1764 |
|
1765 |
_LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y); |
1766 |
_LMSymbol.Commit(); |
1767 |
_LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
1768 |
_LMItemNote.Commit(); |
1769 |
_LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
1770 |
_LMAAttribute.set_Value(text.VALUE); |
1771 |
_LMItemNote.Commit(); |
1772 |
|
1773 |
if (_LMAAttribute != null) |
1774 |
ReleaseCOMObjects(_LMAAttribute); |
1775 |
if (_LMItemNote != null) |
1776 |
ReleaseCOMObjects(_LMItemNote); |
1777 |
} |
1778 |
} |
1779 |
catch (Exception ex) |
1780 |
{ |
1781 |
|
1782 |
} |
1783 |
finally |
1784 |
{ |
1785 |
if (_LMSymbol != null) |
1786 |
ReleaseCOMObjects(_LMSymbol); |
1787 |
} |
1788 |
|
1789 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
1790 |
} |
1791 |
|
1792 |
private void NoteModeling(Note note) |
1793 |
{ |
1794 |
LMSymbol _LMSymbol = null; |
1795 |
LMItemNote _LMItemNote = null; |
1796 |
LMAAttribute _LMAAttribute = null; |
1797 |
|
1798 |
try |
1799 |
{ |
1800 |
double x = 0; |
1801 |
double y = 0; |
1802 |
|
1803 |
CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation); |
1804 |
|
1805 |
_LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y); |
1806 |
_LMSymbol.Commit(); |
1807 |
_LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
1808 |
_LMItemNote.Commit(); |
1809 |
_LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
1810 |
_LMAAttribute.set_Value(note.VALUE); |
1811 |
_LMItemNote.Commit(); |
1812 |
} |
1813 |
catch (Exception ex) |
1814 |
{ |
1815 |
|
1816 |
} |
1817 |
finally |
1818 |
{ |
1819 |
if (_LMAAttribute != null) |
1820 |
ReleaseCOMObjects(_LMAAttribute); |
1821 |
if (_LMItemNote != null) |
1822 |
ReleaseCOMObjects(_LMItemNote); |
1823 |
if (_LMSymbol != null) |
1824 |
ReleaseCOMObjects(_LMSymbol); |
1825 |
} |
1826 |
|
1827 |
SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, ++CurrentCount); |
1828 |
} |
1829 |
|
1830 |
private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location) |
1831 |
{ |
1832 |
if (location == Location.None) |
1833 |
{ |
1834 |
x = originX; |
1835 |
y = originY; |
1836 |
} |
1837 |
else |
1838 |
{ |
1839 |
if (location.HasFlag(Location.Center)) |
1840 |
{ |
1841 |
x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2; |
1842 |
y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2; |
1843 |
} |
1844 |
|
1845 |
if (location.HasFlag(Location.Left)) |
1846 |
x = SPPIDLabelLocation.X1; |
1847 |
else if (location.HasFlag(Location.Right)) |
1848 |
x = SPPIDLabelLocation.X2; |
1849 |
|
1850 |
if (location.HasFlag(Location.Down)) |
1851 |
y = SPPIDLabelLocation.Y1; |
1852 |
else if (location.HasFlag(Location.Up)) |
1853 |
y = SPPIDLabelLocation.Y2; |
1854 |
} |
1855 |
} |
1856 |
|
1857 |
public void ReleaseCOMObjects(params object[] objVars) |
1858 |
{ |
1859 |
int intNewRefCount = 0; |
1860 |
foreach (object obj in objVars) |
1861 |
{ |
1862 |
if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
1863 |
intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
1864 |
} |
1865 |
} |
1866 |
} |
1867 |
} |