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