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