hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ a7e9beec
이력 | 보기 | 이력해설 | 다운로드 (48.2 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 |
namespace Converter.SPPID |
25 |
{ |
26 |
public class AutoModeling |
27 |
{ |
28 |
Placement _placement; |
29 |
LMADataSource dataSource; |
30 |
Ingr.RAD2D.Application radApp; |
31 |
SPPID_Document document; |
32 |
|
33 |
List<Tuple<string, Line, Line>> BranchLines = new List<Tuple<string, Line, Line>>(); |
34 |
public AutoModeling(SPPID_Document document, Ingr.RAD2D.Application radApp) |
35 |
{ |
36 |
this.document = document; |
37 |
this.radApp = radApp; |
38 |
} |
39 |
|
40 |
public void Run() |
41 |
{ |
42 |
_placement = new Placement(); |
43 |
dataSource = _placement.PIDDataSource; |
44 |
//dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
45 |
//dynamic newDrawing = application.Drawings.Add(document.Unit, document.Template, document.DrawingNumber, document.DrawingName); |
46 |
//application.ActiveWindow.Fit(); |
47 |
//Thread.Sleep(100); |
48 |
//application.ActiveWindow.Zoom = 60; |
49 |
//Thread.Sleep(100); |
50 |
|
51 |
|
52 |
try |
53 |
{ |
54 |
// Equipment Modeling |
55 |
foreach (Equipment equipment in document.Equipments) |
56 |
SymbolModeling(equipment as Symbol, null, null); |
57 |
|
58 |
// LineRun Symbol Modeling |
59 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
60 |
foreach (LineRun run in lineNumber.RUNS) |
61 |
SymbolModelingByRun(run); |
62 |
|
63 |
// TrimLineRun Symbol Modeling |
64 |
foreach (TrimLine trimLine in document.TRIMLINES) |
65 |
foreach (LineRun run in trimLine.RUNS) |
66 |
SymbolModelingByRun(run); |
67 |
|
68 |
// LineRun Line Modeling |
69 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
70 |
foreach (LineRun run in lineNumber.RUNS) |
71 |
LineModelingByRun(run); |
72 |
|
73 |
// TrimLineRun Line Modeling |
74 |
foreach (TrimLine trimLine in document.TRIMLINES) |
75 |
foreach (LineRun run in trimLine.RUNS) |
76 |
LineModelingByRun(run); |
77 |
|
78 |
// Branch Line Modeling |
79 |
foreach (var item in BranchLines) |
80 |
BranchLineModeling(item); |
81 |
|
82 |
// EndBreak Modeling |
83 |
foreach (var item in document.EndBreaks) |
84 |
EndBreakModeling(item); |
85 |
|
86 |
// LineNumber Modeling |
87 |
foreach (var item in document.LINENUMBERS) |
88 |
LineNumberModeling(item); |
89 |
|
90 |
// LineRun Line Join |
91 |
foreach (LineNumber lineNumber in document.LINENUMBERS) |
92 |
foreach (LineRun run in lineNumber.RUNS) |
93 |
JoinRunLine(run); |
94 |
|
95 |
// TrimLineRun Line Join |
96 |
foreach (TrimLine trimLine in document.TRIMLINES) |
97 |
foreach (LineRun run in trimLine.RUNS) |
98 |
JoinRunLine(run); |
99 |
|
100 |
// Note Modeling |
101 |
foreach (var item in document.NOTES) |
102 |
NoteModeling(item); |
103 |
|
104 |
// Text Modeling |
105 |
foreach (var item in document.TEXTINFOS) |
106 |
TextModeling(item); |
107 |
|
108 |
// Input LineNumber Attribute |
109 |
foreach (var item in document.LINENUMBERS) |
110 |
InputLineNumberAttribute(item); |
111 |
|
112 |
// Input Symbol Attribute |
113 |
foreach (var item in document.SYMBOLS) |
114 |
InputSymbolAttribute(item); |
115 |
} |
116 |
catch (Exception ex) |
117 |
{ |
118 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
119 |
} |
120 |
finally |
121 |
{ |
122 |
ReleaseCOMObjects(dataSource); |
123 |
ReleaseCOMObjects(_placement); |
124 |
} |
125 |
|
126 |
//System.Windows.Forms.MessageBox.Show("end"); |
127 |
} |
128 |
|
129 |
public void Test() |
130 |
{ |
131 |
_placement = new Placement(); |
132 |
dataSource = _placement.PIDDataSource; |
133 |
|
134 |
DependencyObject drawingObject = radApp.ActiveDocument.SelectSet[0] as DependencyObject; |
135 |
if (drawingObject != null) |
136 |
{ |
137 |
string modelitemID = drawingObject.AttributeSets[0][5].GetValue().ToString(); |
138 |
radApp.ActiveDocument.SelectSet.RemoveAll(); |
139 |
LMPipeRun run = dataSource.GetPipeRun(modelitemID); |
140 |
_LMAItem item = run.AsLMAItem(); |
141 |
string modelitemID2 = item.Id; |
142 |
_placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item); |
143 |
string afterModelItemID = item.Id; |
144 |
if (modelitemID2 != afterModelItemID) |
145 |
{ |
146 |
|
147 |
} |
148 |
} |
149 |
} |
150 |
|
151 |
private void LineModelingByRun(LineRun run) |
152 |
{ |
153 |
Line prevLine = null; |
154 |
List<Line> lines = new List<Line>(); |
155 |
foreach (var item in run.RUNITEMS) |
156 |
{ |
157 |
// Line일 경우 |
158 |
if (item.GetType() == typeof(Line)) |
159 |
{ |
160 |
Line line = item as Line; |
161 |
if (prevLine == null) |
162 |
lines.Add(line); |
163 |
else if (prevLine != null) |
164 |
{ |
165 |
if (prevLine.SPPID.MAPPINGNAME == line.SPPID.MAPPINGNAME) |
166 |
lines.Add(line); |
167 |
else |
168 |
{ |
169 |
LineModeling(lines); |
170 |
lines.Clear(); |
171 |
lines.Add(line); |
172 |
} |
173 |
} |
174 |
|
175 |
prevLine = line; |
176 |
} |
177 |
// Symbol 일 경우 |
178 |
else if (item.GetType() == typeof(Symbol)) |
179 |
{ |
180 |
if (lines.Count > 0) |
181 |
{ |
182 |
LineModeling(lines); |
183 |
lines.Clear(); |
184 |
} |
185 |
} |
186 |
} |
187 |
|
188 |
if (lines.Count > 0) |
189 |
LineModeling(lines); |
190 |
} |
191 |
|
192 |
private void SymbolModelingByRun(LineRun run) |
193 |
{ |
194 |
// 양끝 Symbol 검사 후 Line이 나올때까지만 Symbol Modeling |
195 |
if (run.RUNITEMS.Count > 0) |
196 |
{ |
197 |
if (run.RUNITEMS[0].GetType() == typeof(Symbol)) |
198 |
SymbolModelingByRunStart(run.RUNITEMS[0] as Symbol, run); |
199 |
|
200 |
if (run.RUNITEMS[run.RUNITEMS.Count - 1].GetType() == typeof(Symbol)) |
201 |
SymbolModelingByRunEnd(run.RUNITEMS[run.RUNITEMS.Count - 1] as Symbol, run); |
202 |
} |
203 |
|
204 |
Symbol prevSymbol = null; |
205 |
Symbol targetSymbol = null; |
206 |
foreach (var item in run.RUNITEMS) |
207 |
{ |
208 |
if (item.GetType() == typeof(Symbol)) |
209 |
{ |
210 |
Symbol symbol = item as Symbol; |
211 |
SymbolModeling(symbol, targetSymbol, prevSymbol); |
212 |
prevSymbol = symbol; |
213 |
targetSymbol = symbol; |
214 |
} |
215 |
else |
216 |
{ |
217 |
targetSymbol = null; |
218 |
} |
219 |
} |
220 |
} |
221 |
|
222 |
private void SymbolModelingByRunStart(Symbol symbol, LineRun run) |
223 |
{ |
224 |
foreach (var connector in symbol.CONNECTORS) |
225 |
{ |
226 |
object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
227 |
if (targetItem != null && |
228 |
(targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) && |
229 |
!IsSameLineNumber(symbol, targetItem)) |
230 |
{ |
231 |
SymbolModeling(symbol, targetItem as Symbol, null); |
232 |
for (int i = 1; i < run.RUNITEMS.Count; i++) |
233 |
{ |
234 |
object item = run.RUNITEMS[i]; |
235 |
if (item.GetType() == typeof(Symbol)) |
236 |
SymbolModeling(item as Symbol, run.RUNITEMS[i - 1] as Symbol, null); |
237 |
else |
238 |
break; |
239 |
} |
240 |
break; |
241 |
} |
242 |
} |
243 |
|
244 |
|
245 |
} |
246 |
|
247 |
private void SymbolModelingByRunEnd(Symbol symbol, LineRun run) |
248 |
{ |
249 |
foreach (var connector in symbol.CONNECTORS) |
250 |
{ |
251 |
object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM); |
252 |
if (targetItem != null && |
253 |
(targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) && |
254 |
!IsSameLineNumber(symbol, targetItem)) |
255 |
{ |
256 |
SymbolModeling(symbol, targetItem as Symbol, null); |
257 |
for (int i = run.RUNITEMS.Count - 2; i >= 0; i--) |
258 |
{ |
259 |
object item = run.RUNITEMS[i]; |
260 |
if (item.GetType() == typeof(Symbol)) |
261 |
SymbolModeling(item as Symbol, run.RUNITEMS[i + 1] as Symbol, null); |
262 |
else |
263 |
break; |
264 |
} |
265 |
break; |
266 |
} |
267 |
} |
268 |
} |
269 |
|
270 |
private void SymbolModeling(Symbol symbol, Symbol targetSymbol, Symbol prevSymbol) |
271 |
{ |
272 |
if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
273 |
return; |
274 |
|
275 |
LMSymbol _LMSymbol = null; |
276 |
|
277 |
string mappingPath = symbol.SPPID.MAPPINGNAME; |
278 |
double x = symbol.SPPID.ORIGINAL_X; |
279 |
double y = symbol.SPPID.ORIGINAL_Y; |
280 |
int mirror = 0; |
281 |
double angle = symbol.ANGLE; |
282 |
|
283 |
if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId)) |
284 |
{ |
285 |
LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId); |
286 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem); |
287 |
ReleaseCOMObjects(_TargetItem); |
288 |
} |
289 |
else if (prevSymbol != null) |
290 |
{ |
291 |
LMSymbol _PrevSymbol = dataSource.GetSymbol(prevSymbol.SPPID.RepresentationId); |
292 |
SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y); |
293 |
double prevX = _PrevSymbol.get_XCoordinate(); |
294 |
double prevY = _PrevSymbol.get_YCoordinate(); |
295 |
if (slopeType == SlopeType.HORIZONTAL) |
296 |
y = prevY; |
297 |
else if (slopeType == SlopeType.VERTICAL) |
298 |
x = prevX; |
299 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
300 |
} |
301 |
else |
302 |
{ |
303 |
_LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
304 |
} |
305 |
|
306 |
|
307 |
if (_LMSymbol != null) |
308 |
{ |
309 |
_LMSymbol.Commit(); |
310 |
symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
311 |
} |
312 |
|
313 |
ReleaseCOMObjects(_LMSymbol); |
314 |
} |
315 |
|
316 |
private bool IsSameLineNumber(object item, object targetItem) |
317 |
{ |
318 |
foreach (var lineNumber in document.LINENUMBERS) |
319 |
{ |
320 |
foreach (var run in lineNumber.RUNS) |
321 |
{ |
322 |
foreach (var runItem in run.RUNITEMS) |
323 |
{ |
324 |
if (runItem == item) |
325 |
{ |
326 |
foreach (var findItem in run.RUNITEMS) |
327 |
{ |
328 |
if (findItem == targetItem) |
329 |
{ |
330 |
return true; |
331 |
} |
332 |
} |
333 |
|
334 |
return false; |
335 |
|
336 |
} |
337 |
} |
338 |
} |
339 |
} |
340 |
|
341 |
return false; |
342 |
} |
343 |
|
344 |
private void LineModeling(List<Line> lines) |
345 |
{ |
346 |
_LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
347 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
348 |
LMSymbol _LMSymbol1 = null; |
349 |
LMSymbol _LMSymbol2 = null; |
350 |
Dictionary<LMConnector, List<double[]>> connectorVertices1 = new Dictionary<LMConnector, List<double[]>>(); |
351 |
LMConnector targetConnector1 = null; |
352 |
Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>(); |
353 |
LMConnector targetConnector2 = null; |
354 |
|
355 |
Line startBranchLine = null; |
356 |
Line endBranchLine = null; |
357 |
|
358 |
for (int i = 0; i < lines.Count; i++) |
359 |
{ |
360 |
Line line = lines[i]; |
361 |
if (i == 0 || i + 1 != lines.Count) |
362 |
{ |
363 |
// 시작점에 연결된 Symbol 찾기 |
364 |
object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM); |
365 |
if (connItem != null && connItem.GetType() == typeof(Symbol)) |
366 |
{ |
367 |
_LMSymbol1 = dataSource.GetSymbol(((Symbol)connItem).SPPID.RepresentationId); |
368 |
if (_LMSymbol1 != null) |
369 |
placeRunInputs.AddSymbolTarget(_LMSymbol1, line.SPPID.START_X, line.SPPID.START_Y); |
370 |
else |
371 |
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
372 |
} |
373 |
else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem)) |
374 |
{ |
375 |
connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId); |
376 |
targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y); |
377 |
|
378 |
if (targetConnector1 != null) |
379 |
placeRunInputs.AddConnectorTarget(targetConnector1, line.SPPID.START_X, line.SPPID.START_Y); |
380 |
else |
381 |
{ |
382 |
startBranchLine = connItem as Line; |
383 |
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
384 |
} |
385 |
} |
386 |
else |
387 |
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
388 |
} |
389 |
|
390 |
if (i + 1 == lines.Count) |
391 |
{ |
392 |
// 끝점에 연결된 Symbol 찾기 |
393 |
object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM); |
394 |
|
395 |
if (i != 0) |
396 |
placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
397 |
|
398 |
if (connItem != null && connItem.GetType() == typeof(Symbol)) |
399 |
{ |
400 |
_LMSymbol2 = dataSource.GetSymbol(((Symbol)connItem).SPPID.RepresentationId); |
401 |
if (_LMSymbol2 != null) |
402 |
placeRunInputs.AddSymbolTarget(_LMSymbol2, line.SPPID.END_X, line.SPPID.END_Y); |
403 |
else |
404 |
placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
405 |
|
406 |
} |
407 |
else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem)) |
408 |
{ |
409 |
connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId); |
410 |
targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y); |
411 |
|
412 |
if (targetConnector2 != null) |
413 |
placeRunInputs.AddConnectorTarget(targetConnector2, line.SPPID.END_X, line.SPPID.END_Y); |
414 |
else |
415 |
{ |
416 |
endBranchLine = connItem as Line; |
417 |
placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
418 |
} |
419 |
} |
420 |
else |
421 |
{ |
422 |
placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
423 |
} |
424 |
} |
425 |
} |
426 |
|
427 |
LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
428 |
|
429 |
if (_lMConnector != null) |
430 |
{ |
431 |
foreach (var line in lines) |
432 |
line.SPPID.ModelItemId = _lMConnector.ModelItemID; |
433 |
_lMConnector.Commit(); |
434 |
if (startBranchLine != null || endBranchLine != null) |
435 |
{ |
436 |
BranchLines.Add(new Tuple<string, Line, Line>(_lMConnector.ModelItemID, startBranchLine, endBranchLine)); |
437 |
} |
438 |
} |
439 |
|
440 |
|
441 |
if (_LMSymbol1 != null) |
442 |
ReleaseCOMObjects(_LMSymbol1); |
443 |
if (_LMSymbol2 != null) |
444 |
ReleaseCOMObjects(_LMSymbol2); |
445 |
if (targetConnector1 != null) |
446 |
ReleaseCOMObjects(targetConnector1); |
447 |
if (targetConnector2 != null) |
448 |
ReleaseCOMObjects(targetConnector2); |
449 |
foreach (var item in connectorVertices1) |
450 |
ReleaseCOMObjects(item.Key); |
451 |
foreach (var item in connectorVertices2) |
452 |
ReleaseCOMObjects(item.Key); |
453 |
|
454 |
ReleaseCOMObjects(_lMConnector); |
455 |
ReleaseCOMObjects(placeRunInputs); |
456 |
ReleaseCOMObjects(_LMAItem); |
457 |
} |
458 |
|
459 |
private void BranchLineModeling(Tuple<string, Line, Line> branch) |
460 |
{ |
461 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1); |
462 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1); |
463 |
|
464 |
LMConnector _StartConnector = null; |
465 |
LMConnector _EndConnector = null; |
466 |
double lengthStart = double.MaxValue; |
467 |
double lengthEnd = double.MaxValue; |
468 |
List<double[]> startPoints = new List<double[]>(); |
469 |
List<double[]> endPoints = new List<double[]>(); |
470 |
|
471 |
foreach (var item in connectorVertices) |
472 |
{ |
473 |
foreach (var point in item.Value) |
474 |
{ |
475 |
// Start Point가 Branch |
476 |
if (branch.Item2 != null) |
477 |
{ |
478 |
Line targetLine = branch.Item2; |
479 |
double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]); |
480 |
if (lengthStart > distance) |
481 |
{ |
482 |
_StartConnector = item.Key; |
483 |
lengthStart = distance; |
484 |
startPoints = item.Value; |
485 |
} |
486 |
} |
487 |
// End Point가 Branch |
488 |
if (branch.Item3 != null) |
489 |
{ |
490 |
Line targetLine = branch.Item3; |
491 |
double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]); |
492 |
if (lengthEnd > distance) |
493 |
{ |
494 |
_EndConnector = item.Key; |
495 |
lengthEnd = distance; |
496 |
endPoints = item.Value; |
497 |
} |
498 |
} |
499 |
} |
500 |
} |
501 |
#region Branch가 양쪽 전부일 때 |
502 |
if (_StartConnector != null && _StartConnector == _EndConnector) |
503 |
{ |
504 |
_placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation()); |
505 |
|
506 |
_LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
507 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
508 |
|
509 |
Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId); |
510 |
LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]); |
511 |
Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId); |
512 |
LMConnector _EndTargetConnector = FindTargetLMConnector(endConnectorVertices, |
513 |
startPoints[startPoints.Count - 1][0], |
514 |
startPoints[startPoints.Count - 1][1], |
515 |
startPoints[startPoints.Count - 2][0], |
516 |
startPoints[startPoints.Count - 2][1]); |
517 |
|
518 |
for (int i = 0; i < startPoints.Count; i++) |
519 |
{ |
520 |
double[] point = startPoints[i]; |
521 |
if (i == 0) |
522 |
placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]); |
523 |
else if (i == startPoints.Count - 1) |
524 |
placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]); |
525 |
else |
526 |
placeRunInputs.AddPoint(point[0], point[1]); |
527 |
} |
528 |
|
529 |
LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
530 |
if (_LMConnector != null) |
531 |
{ |
532 |
_LMConnector.Commit(); |
533 |
foreach (var item in lines) |
534 |
item.SPPID.ModelItemId = _LMConnector.ModelItemID; |
535 |
} |
536 |
|
537 |
foreach (var item in startConnectorVertices) |
538 |
ReleaseCOMObjects(item.Key); |
539 |
foreach (var item in endConnectorVertices) |
540 |
ReleaseCOMObjects(item.Key); |
541 |
ReleaseCOMObjects(placeRunInputs); |
542 |
ReleaseCOMObjects(_LMAItem); |
543 |
ReleaseCOMObjects(_LMConnector); |
544 |
} |
545 |
#endregion |
546 |
#region 양쪽이 다른 Branch |
547 |
else |
548 |
{ |
549 |
// Branch 시작 Connector |
550 |
if (_StartConnector != null) |
551 |
BranchLineModelingByConnector(branch, _StartConnector, startPoints, true); |
552 |
|
553 |
// Branch 끝 Connector |
554 |
if (_EndConnector != null) |
555 |
BranchLineModelingByConnector(branch, _EndConnector, endPoints, false); |
556 |
} |
557 |
#endregion |
558 |
|
559 |
if (_StartConnector != null) |
560 |
ReleaseCOMObjects(_StartConnector); |
561 |
if (_EndConnector != null) |
562 |
ReleaseCOMObjects(_EndConnector); |
563 |
foreach (var item in connectorVertices) |
564 |
ReleaseCOMObjects(item.Key); |
565 |
} |
566 |
|
567 |
private void BranchLineModelingByConnector(Tuple<string, Line, Line> branch, LMConnector _Connector, List<double[]> points, bool IsStart) |
568 |
{ |
569 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1); |
570 |
Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1); |
571 |
LMConnector _SameRunTargetConnector = null; |
572 |
LMSymbol _SameRunTargetSymbol = null; |
573 |
Dictionary<LMConnector, List<double[]>> branchConnectorVertices = null; |
574 |
LMConnector _BranchTargetConnector = null; |
575 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
576 |
|
577 |
// 같은 Line Run의 Connector 찾기 |
578 |
foreach (var item in connectorVertices) |
579 |
{ |
580 |
if (item.Key == _Connector) |
581 |
continue; |
582 |
|
583 |
if (IsStart && |
584 |
!DBNull.Value.Equals(item.Key.ConnectItem1SymbolID) && |
585 |
!DBNull.Value.Equals(_Connector.ConnectItem2SymbolID)&& |
586 |
item.Key.ConnectItem1SymbolID == _Connector.ConnectItem2SymbolID) |
587 |
{ |
588 |
_SameRunTargetConnector = item.Key; |
589 |
break; |
590 |
} |
591 |
else if (!IsStart && |
592 |
!DBNull.Value.Equals(item.Key.ConnectItem2SymbolID) && |
593 |
!DBNull.Value.Equals(_Connector.ConnectItem1SymbolID) && |
594 |
item.Key.ConnectItem2SymbolID == _Connector.ConnectItem1SymbolID) |
595 |
{ |
596 |
_SameRunTargetConnector = item.Key; |
597 |
break; |
598 |
} |
599 |
} |
600 |
|
601 |
// Branch 반대편이 Symbol |
602 |
if (_SameRunTargetConnector == null) |
603 |
{ |
604 |
foreach (var line in lines) |
605 |
{ |
606 |
foreach (var connector in line.CONNECTORS) |
607 |
{ |
608 |
Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol; |
609 |
if (symbol != null) |
610 |
{ |
611 |
_SameRunTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
612 |
break; |
613 |
} |
614 |
} |
615 |
} |
616 |
} |
617 |
|
618 |
// 기존 Connector 제거 |
619 |
_placement.PIDRemovePlacement(_Connector.AsLMRepresentation()); |
620 |
|
621 |
// 시작 Connector일 경우 첫 Point가 TargetConnector를 찾아야함 |
622 |
if (IsStart) |
623 |
{ |
624 |
branchConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId); |
625 |
_BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, points[0][0], points[0][1], points[1][0], points[1][1]); |
626 |
} |
627 |
// 끝 Conenctor일 경우 마지막 Point가 TargetConnector를 찾아야함 |
628 |
else |
629 |
{ |
630 |
branchConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId); |
631 |
_BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, |
632 |
points[points.Count - 1][0], |
633 |
points[points.Count - 1][1], |
634 |
points[points.Count - 2][0], |
635 |
points[points.Count - 2][1]); |
636 |
} |
637 |
|
638 |
for (int i = 0; i < points.Count; i++) |
639 |
{ |
640 |
double[] point = points[i]; |
641 |
if (i == 0) |
642 |
{ |
643 |
if (IsStart) |
644 |
{ |
645 |
placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]); |
646 |
} |
647 |
else |
648 |
{ |
649 |
if (_SameRunTargetConnector != null) |
650 |
placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]); |
651 |
else if (_SameRunTargetSymbol != null) |
652 |
placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]); |
653 |
else |
654 |
placeRunInputs.AddPoint(point[0], point[1]); |
655 |
} |
656 |
} |
657 |
else if (i == points.Count - 1) |
658 |
{ |
659 |
if (IsStart) |
660 |
{ |
661 |
if (_SameRunTargetConnector != null) |
662 |
placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]); |
663 |
else if (_SameRunTargetSymbol != null) |
664 |
placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]); |
665 |
else |
666 |
placeRunInputs.AddPoint(point[0], point[1]); |
667 |
} |
668 |
else |
669 |
{ |
670 |
placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]); |
671 |
} |
672 |
} |
673 |
else |
674 |
placeRunInputs.AddPoint(point[0], point[1]); |
675 |
} |
676 |
_LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME); |
677 |
LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
678 |
|
679 |
if (_LMConnector != null) |
680 |
{ |
681 |
if (_SameRunTargetConnector != null) |
682 |
{ |
683 |
JoinPipeRun(_LMConnector.ModelItemID, _SameRunTargetConnector.ModelItemID); |
684 |
} |
685 |
else |
686 |
{ |
687 |
foreach (var item in lines) |
688 |
item.SPPID.ModelItemId = _LMConnector.ModelItemID; |
689 |
} |
690 |
|
691 |
_LMConnector.Commit(); |
692 |
ReleaseCOMObjects(_LMConnector); |
693 |
} |
694 |
|
695 |
ReleaseCOMObjects(placeRunInputs); |
696 |
ReleaseCOMObjects(_LMAItem); |
697 |
if (_BranchTargetConnector != null) |
698 |
ReleaseCOMObjects(_BranchTargetConnector); |
699 |
if (_SameRunTargetConnector != null) |
700 |
ReleaseCOMObjects(_SameRunTargetConnector); |
701 |
if (_SameRunTargetSymbol != null) |
702 |
ReleaseCOMObjects(_SameRunTargetSymbol); |
703 |
foreach (var item in connectorVertices) |
704 |
ReleaseCOMObjects(item.Key); |
705 |
foreach (var item in branchConnectorVertices) |
706 |
ReleaseCOMObjects(item.Key); |
707 |
} |
708 |
|
709 |
private void EndBreakModeling(EndBreak endBreak) |
710 |
{ |
711 |
Line ownerLine = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER) as Line; |
712 |
Line connLine = null; |
713 |
Property property = endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item"); |
714 |
if (property != null) |
715 |
connLine = SPPIDUtil.FindObjectByUID(document, property.VALUE) as Line; |
716 |
|
717 |
if (ownerLine != null && connLine != null) |
718 |
{ |
719 |
LMLabelPersist _LmLabelPersist = null; |
720 |
|
721 |
string lineModelId = ownerLine.SPPID.ModelItemId; |
722 |
LMPipeRun _LMPipeRun = _placement.PIDDataSource.GetPipeRun(lineModelId); |
723 |
LMPipeRun _ConnLMPipeRun = _placement.PIDDataSource.GetPipeRun(connLine.SPPID.ModelItemId); |
724 |
LMConnector connectedLMConnector = null; |
725 |
|
726 |
if (_LMPipeRun != null && _ConnLMPipeRun != null) |
727 |
{ |
728 |
foreach (LMRepresentation rep in _LMPipeRun.Representations) |
729 |
{ |
730 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
731 |
{ |
732 |
LMConnector _LMConnector = _placement.PIDDataSource.GetConnector(rep.Id); |
733 |
if (_LMConnector.ConnectItem1SymbolID != null && !DBNull.Value.Equals(_LMConnector.ConnectItem1SymbolID) && ExistConnItem(_ConnLMPipeRun, _LMConnector.ConnectItem1SymbolID)) |
734 |
{ |
735 |
connectedLMConnector = _LMConnector; |
736 |
break; |
737 |
} |
738 |
else if (_LMConnector.ConnectItem2SymbolID != null && !DBNull.Value.Equals(_LMConnector.ConnectItem2SymbolID) && ExistConnItem(_ConnLMPipeRun, _LMConnector.ConnectItem2SymbolID)) |
739 |
{ |
740 |
connectedLMConnector = _LMConnector; |
741 |
break; |
742 |
} |
743 |
else |
744 |
{ |
745 |
ReleaseCOMObjects(_LMConnector); |
746 |
} |
747 |
} |
748 |
} |
749 |
if (connectedLMConnector != null) |
750 |
{ |
751 |
Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y }; |
752 |
_LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: true); |
753 |
ReleaseCOMObjects(connectedLMConnector); |
754 |
} |
755 |
|
756 |
ReleaseCOMObjects(_LMPipeRun); |
757 |
ReleaseCOMObjects(_ConnLMPipeRun); |
758 |
if (_LmLabelPersist != null) |
759 |
ReleaseCOMObjects(_LmLabelPersist); |
760 |
} |
761 |
} |
762 |
} |
763 |
|
764 |
private bool ExistConnItem(LMPipeRun _LMPipeRun, string ConnItem) |
765 |
{ |
766 |
foreach (LMRepresentation rep in _LMPipeRun.Representations) |
767 |
{ |
768 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
769 |
{ |
770 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
771 |
if (_LMConnector.ConnectItem1SymbolID != null && !DBNull.Value.Equals(_LMConnector.ConnectItem1SymbolID) && _LMConnector.ConnectItem1SymbolID == ConnItem) |
772 |
{ |
773 |
ReleaseCOMObjects(_LMConnector); |
774 |
return true; |
775 |
} |
776 |
else if (_LMConnector.ConnectItem2SymbolID != null && !DBNull.Value.Equals(_LMConnector.ConnectItem2SymbolID) && _LMConnector.ConnectItem2SymbolID == ConnItem) |
777 |
{ |
778 |
ReleaseCOMObjects(_LMConnector); |
779 |
return true; |
780 |
} |
781 |
else |
782 |
{ |
783 |
ReleaseCOMObjects(_LMConnector); |
784 |
} |
785 |
} |
786 |
} |
787 |
|
788 |
return false; |
789 |
} |
790 |
|
791 |
private void JoinPipeRun(string fromModelItemId, string toModelItemId) |
792 |
{ |
793 |
LMPipeRun run1 = dataSource.GetPipeRun(toModelItemId); |
794 |
LMPipeRun run2 = dataSource.GetPipeRun(fromModelItemId); |
795 |
// item2가 item1으로 조인 |
796 |
try |
797 |
{ |
798 |
_LMAItem item1 = run1.AsLMAItem(); |
799 |
_LMAItem item2 = run2.AsLMAItem(); |
800 |
|
801 |
_placement.PIDJoinRuns(ref item1, ref item2); |
802 |
item1.Commit(); |
803 |
item2.Commit(); |
804 |
} |
805 |
catch (Exception ex) |
806 |
{ |
807 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
808 |
} |
809 |
finally |
810 |
{ |
811 |
ReleaseCOMObjects(run1); |
812 |
ReleaseCOMObjects(run2); |
813 |
} |
814 |
} |
815 |
|
816 |
private void AutoJoinPipeRun(string modelItemId) |
817 |
{ |
818 |
LMPipeRun run = dataSource.GetPipeRun(modelItemId); |
819 |
try |
820 |
{ |
821 |
_LMAItem item = run.AsLMAItem(); |
822 |
string modelitemID = item.Id; |
823 |
_placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item); |
824 |
string afterModelItemID = item.Id; |
825 |
if (modelitemID != afterModelItemID) |
826 |
{ |
827 |
List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID); |
828 |
foreach (var line in lines) |
829 |
line.SPPID.ModelItemId = afterModelItemID; |
830 |
} |
831 |
item.Commit(); |
832 |
} |
833 |
catch (Exception ex) |
834 |
{ |
835 |
System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
836 |
} |
837 |
finally |
838 |
{ |
839 |
ReleaseCOMObjects(run); |
840 |
} |
841 |
} |
842 |
|
843 |
private void JoinRunLine(LineRun run) |
844 |
{ |
845 |
string modelItemId = string.Empty; |
846 |
foreach (var item in run.RUNITEMS) |
847 |
{ |
848 |
if (item.GetType() == typeof(Line)) |
849 |
{ |
850 |
Line line = item as Line; |
851 |
if (modelItemId != line.SPPID.ModelItemId) |
852 |
{ |
853 |
AutoJoinPipeRun(line.SPPID.ModelItemId); |
854 |
modelItemId = line.SPPID.ModelItemId; |
855 |
} |
856 |
} |
857 |
} |
858 |
} |
859 |
|
860 |
private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId) |
861 |
{ |
862 |
Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>(); |
863 |
LMPipeRun _LMPipeRun = dataSource.GetPipeRun(modelId); |
864 |
if (_LMPipeRun != null) |
865 |
{ |
866 |
foreach (LMRepresentation rep in _LMPipeRun.Representations) |
867 |
{ |
868 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
869 |
{ |
870 |
LMConnector _LMConnector = dataSource.GetConnector(rep.Id); |
871 |
connectorVertices.Add(_LMConnector, new List<double[]>()); |
872 |
dynamic OID = rep.get_GraphicOID(); |
873 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
874 |
Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d; |
875 |
int verticesCount = lineStringGeometry.VertexCount; |
876 |
double[] vertices = null; |
877 |
lineStringGeometry.GetVertices(ref verticesCount, ref vertices); |
878 |
for (int i = 0; i < verticesCount; i++) |
879 |
{ |
880 |
double x = 0; |
881 |
double y = 0; |
882 |
lineStringGeometry.GetVertex(i + 1, ref x, ref y); |
883 |
connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) }); |
884 |
} |
885 |
} |
886 |
} |
887 |
|
888 |
ReleaseCOMObjects(_LMPipeRun); |
889 |
} |
890 |
|
891 |
return connectorVertices; |
892 |
} |
893 |
|
894 |
private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2) |
895 |
{ |
896 |
double length = double.MaxValue; |
897 |
LMConnector targetConnector = null; |
898 |
foreach (var item in connectorVertices) |
899 |
{ |
900 |
List<double[]> points = item.Value; |
901 |
for (int i = 0; i < points.Count - 1; i++) |
902 |
{ |
903 |
double[] point1 = points[i]; |
904 |
double[] point2 = points[i + 1]; |
905 |
|
906 |
double maxLineX = Math.Max(point1[0], point2[0]); |
907 |
double minLineX = Math.Min(point1[0], point2[0]); |
908 |
double maxLineY = Math.Max(point1[1], point2[1]); |
909 |
double minLineY = Math.Min(point1[1], point2[1]); |
910 |
|
911 |
SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY); |
912 |
|
913 |
// 두직선의 교차점 |
914 |
double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]); |
915 |
if (crossingPoint != null) |
916 |
{ |
917 |
double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]); |
918 |
if (length >= distance) |
919 |
{ |
920 |
if (slope == SlopeType.Slope && |
921 |
minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] && |
922 |
minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
923 |
{ |
924 |
targetConnector = item.Key; |
925 |
length = distance; |
926 |
} |
927 |
else if (slope == SlopeType.HORIZONTAL && |
928 |
minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0]) |
929 |
{ |
930 |
targetConnector = item.Key; |
931 |
length = distance; |
932 |
} |
933 |
else if (slope == SlopeType.VERTICAL && |
934 |
minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1]) |
935 |
{ |
936 |
targetConnector = item.Key; |
937 |
length = distance; |
938 |
} |
939 |
} |
940 |
} |
941 |
} |
942 |
} |
943 |
|
944 |
return targetConnector; |
945 |
} |
946 |
|
947 |
private void LineNumberModeling(LineNumber lineNumber) |
948 |
{ |
949 |
Line line = null; |
950 |
foreach (var lineRun in lineNumber.RUNS) |
951 |
{ |
952 |
foreach (var item in lineRun.RUNITEMS) |
953 |
{ |
954 |
line = item as Line; |
955 |
if (line != null && !string.IsNullOrEmpty(line.SPPID.ModelItemId)) |
956 |
break; |
957 |
else |
958 |
line = null; |
959 |
} |
960 |
if (line != null) |
961 |
break; |
962 |
} |
963 |
|
964 |
if (line != null && !string.IsNullOrEmpty(line.SPPID.ModelItemId)) |
965 |
{ |
966 |
Array points = new double[] { 0, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y }; |
967 |
LMPipeRun _pipeRun = dataSource.GetPipeRun(line.SPPID.ModelItemId); |
968 |
if (_pipeRun != null) |
969 |
{ |
970 |
foreach (LMRepresentation rep in _pipeRun.Representations) |
971 |
{ |
972 |
if (rep.get_RepresentationType() == "Connector" && rep.get_ItemStatus() == "Active") |
973 |
{ |
974 |
LMConnector _LmConnector = dataSource.GetConnector(rep.Id); |
975 |
LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: _LmConnector.AsLMRepresentation(), IsLeaderVisible: false); |
976 |
_LmLabelPresist.Commit(); |
977 |
|
978 |
if (_LmConnector != null) |
979 |
ReleaseCOMObjects(_LmConnector); |
980 |
if (_LmLabelPresist != null) |
981 |
{ |
982 |
lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id; |
983 |
ReleaseCOMObjects(_LmConnector); |
984 |
} |
985 |
|
986 |
break; |
987 |
} |
988 |
} |
989 |
|
990 |
ReleaseCOMObjects(_pipeRun); |
991 |
} |
992 |
} |
993 |
} |
994 |
|
995 |
private void InputLineNumberAttribute(LineNumber lineNumber) |
996 |
{ |
997 |
foreach (var run in lineNumber.RUNS) |
998 |
{ |
999 |
foreach (var item in run.RUNITEMS) |
1000 |
{ |
1001 |
if (item.GetType() == typeof(Line)) |
1002 |
{ |
1003 |
Line line = item as Line; |
1004 |
LMPipeRun _LMPipeRun = dataSource.GetPipeRun(line.SPPID.ModelItemId); |
1005 |
foreach (var attribute in lineNumber.ATTRIBUTES) |
1006 |
{ |
1007 |
LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID); |
1008 |
if (mapping != null) |
1009 |
{ |
1010 |
LMAAttribute _LMAAttribute = _LMPipeRun.Attributes[mapping.SPPIDATTRIBUTENAME]; |
1011 |
if (_LMAAttribute != null) |
1012 |
{ |
1013 |
if (DBNull.Value.Equals(_LMAAttribute.get_Value())) |
1014 |
_LMAAttribute.set_Value(attribute.VALUE); |
1015 |
else if (_LMAAttribute.get_Value() != attribute.VALUE) |
1016 |
_LMAAttribute.set_Value(attribute.VALUE); |
1017 |
} |
1018 |
} |
1019 |
} |
1020 |
|
1021 |
_LMPipeRun.Commit(); |
1022 |
ReleaseCOMObjects(_LMPipeRun); |
1023 |
break; |
1024 |
} |
1025 |
} |
1026 |
} |
1027 |
} |
1028 |
|
1029 |
private void InputSymbolAttribute(Symbol symbol) |
1030 |
{ |
1031 |
if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId)) |
1032 |
{ |
1033 |
LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId); |
1034 |
LMPipingComp _LMPipingComp = null; |
1035 |
LMInstrument _LMInstrument = null; |
1036 |
LMAAttributes _Attributes = null; |
1037 |
|
1038 |
if (_LMSymbol.get_FileName().Contains("Instrumentation")) |
1039 |
{ |
1040 |
_LMInstrument = dataSource.GetInstrument(_LMSymbol.ModelItemID); |
1041 |
_Attributes = _LMInstrument.Attributes; |
1042 |
} |
1043 |
else |
1044 |
{ |
1045 |
_LMPipingComp = dataSource.GetPipingComp(_LMSymbol.ModelItemID); |
1046 |
_Attributes = _LMPipingComp.Attributes; |
1047 |
} |
1048 |
|
1049 |
foreach (var item in symbol.PROPERTIES) |
1050 |
{ |
1051 |
|
1052 |
|
1053 |
} |
1054 |
|
1055 |
foreach (var item in symbol.ATTRIBUTES) |
1056 |
{ |
1057 |
AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID); |
1058 |
if (mapping != null) |
1059 |
{ |
1060 |
LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME]; |
1061 |
if (_Attribute != null) |
1062 |
_Attribute.set_Value(item.VALUE); |
1063 |
} |
1064 |
} |
1065 |
|
1066 |
foreach (var item in symbol.ASSOCIATIONS) |
1067 |
{ |
1068 |
|
1069 |
} |
1070 |
|
1071 |
ReleaseCOMObjects(_LMSymbol); |
1072 |
if (_LMPipingComp != null) |
1073 |
{ |
1074 |
_LMPipingComp.Commit(); |
1075 |
ReleaseCOMObjects(_LMPipingComp); |
1076 |
} |
1077 |
if (_LMInstrument != null) |
1078 |
{ |
1079 |
_LMInstrument.Commit(); |
1080 |
ReleaseCOMObjects(_LMInstrument); |
1081 |
} |
1082 |
|
1083 |
|
1084 |
} |
1085 |
} |
1086 |
|
1087 |
private void TextModeling(Text text) |
1088 |
{ |
1089 |
LMSymbol _LMSymbol = null; |
1090 |
LMItemNote _LMItemNote = null; |
1091 |
LMAAttribute _LMAAttribute = null; |
1092 |
|
1093 |
try |
1094 |
{ |
1095 |
_LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y); |
1096 |
_LMSymbol.Commit(); |
1097 |
_LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
1098 |
_LMItemNote.Commit(); |
1099 |
_LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
1100 |
_LMAAttribute.set_Value(text.VALUE); |
1101 |
_LMItemNote.Commit(); |
1102 |
} |
1103 |
catch (Exception ex) |
1104 |
{ |
1105 |
|
1106 |
} |
1107 |
finally |
1108 |
{ |
1109 |
if (_LMAAttribute != null) |
1110 |
ReleaseCOMObjects(_LMAAttribute); |
1111 |
if (_LMItemNote != null) |
1112 |
ReleaseCOMObjects(_LMItemNote); |
1113 |
if (_LMSymbol != null) |
1114 |
ReleaseCOMObjects(_LMSymbol); |
1115 |
} |
1116 |
} |
1117 |
|
1118 |
private void NoteModeling(Note note) |
1119 |
{ |
1120 |
LMSymbol _LMSymbol = null; |
1121 |
LMItemNote _LMItemNote = null; |
1122 |
LMAAttribute _LMAAttribute = null; |
1123 |
|
1124 |
try |
1125 |
{ |
1126 |
_LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y); |
1127 |
_LMSymbol.Commit(); |
1128 |
_LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID); |
1129 |
_LMItemNote.Commit(); |
1130 |
_LMAAttribute = _LMItemNote.Attributes["Note.Body"]; |
1131 |
_LMAAttribute.set_Value(note.VALUE); |
1132 |
_LMItemNote.Commit(); |
1133 |
} |
1134 |
catch (Exception ex) |
1135 |
{ |
1136 |
|
1137 |
} |
1138 |
finally |
1139 |
{ |
1140 |
if (_LMAAttribute != null) |
1141 |
ReleaseCOMObjects(_LMAAttribute); |
1142 |
if (_LMItemNote != null) |
1143 |
ReleaseCOMObjects(_LMItemNote); |
1144 |
if (_LMSymbol != null) |
1145 |
ReleaseCOMObjects(_LMSymbol); |
1146 |
} |
1147 |
|
1148 |
} |
1149 |
|
1150 |
public void ReleaseCOMObjects(params object[] objVars) |
1151 |
{ |
1152 |
int intNewRefCount = 0; |
1153 |
foreach (object obj in objVars) |
1154 |
{ |
1155 |
if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
1156 |
intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
1157 |
} |
1158 |
} |
1159 |
} |
1160 |
} |