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