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