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