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