프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ aa3c9d74

이력 | 보기 | 이력해설 | 다운로드 (69.9 KB)

1 cfda1fed gaqhf
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 8aa6f2db gaqhf
using Ingr.RAD2D.Interop.RAD2D;
9
using Ingr.RAD2D.Internal;
10
using Ingr.RAD2D.Helper;
11 cfda1fed gaqhf
using Converter.BaseModel;
12
using Converter.SPPID.Model;
13
using Converter.SPPID.Properties;
14
using Converter.SPPID.Util;
15
using Converter.SPPID.DB;
16 5e6ecf05 gaqhf
using Ingr.RAD2D.MacroControls.CmdCtrl;
17
using Ingr.RAD2D;
18 5dfb8a24 gaqhf
using System.Windows;
19 cfda1fed gaqhf
using System.Threading;
20 5dfb8a24 gaqhf
using System.Drawing;
21 cfda1fed gaqhf
using Microsoft.VisualBasic;
22
using Newtonsoft.Json;
23
24
namespace Converter.SPPID
25
{
26
    public class AutoModeling
27
    {
28 809a7640 gaqhf
        Placement _placement;
29
        LMADataSource dataSource;
30 5e6ecf05 gaqhf
        Ingr.RAD2D.Application radApp;
31 cfda1fed gaqhf
        SPPID_Document document;
32 b65a7e32 gaqhf
        ETCSetting _ETCSetting;
33 f1c9dbaa gaqhf
34 3165c259 gaqhf
        List<Tuple<string, Line, Line>> BranchLines = new List<Tuple<string, Line, Line>>();
35 5e6ecf05 gaqhf
        public AutoModeling(SPPID_Document document, Ingr.RAD2D.Application radApp)
36 cfda1fed gaqhf
        {
37
            this.document = document;
38 5e6ecf05 gaqhf
            this.radApp = radApp;
39 b65a7e32 gaqhf
            this._ETCSetting = ETCSetting.GetInstance();
40 cfda1fed gaqhf
        }
41
42
        public void Run()
43
        {
44 809a7640 gaqhf
            _placement = new Placement();
45
            dataSource = _placement.PIDDataSource;
46 5dfb8a24 gaqhf
            //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 65a1ed4b gaqhf
53
54 5e6ecf05 gaqhf
            try
55 5dfb8a24 gaqhf
            {
56 1efc25a3 gaqhf
                // Equipment Modeling
57 5e6ecf05 gaqhf
                foreach (Equipment equipment in document.Equipments)
58 b9e9f4c8 gaqhf
                {
59
                    EquipmentModeling(equipment);
60
                }
61
                    
62 65a1ed4b gaqhf
                
63 1efc25a3 gaqhf
                // LineRun Symbol Modeling
64 5e6ecf05 gaqhf
                foreach (LineNumber lineNumber in document.LINENUMBERS)
65
                    foreach (LineRun run in lineNumber.RUNS)
66
                        SymbolModelingByRun(run);
67 65a1ed4b gaqhf
                
68 1efc25a3 gaqhf
                // TrimLineRun Symbol Modeling
69 5e6ecf05 gaqhf
                foreach (TrimLine trimLine in document.TRIMLINES)
70
                    foreach (LineRun run in trimLine.RUNS)
71
                        SymbolModelingByRun(run);
72 65a1ed4b gaqhf
                
73 1efc25a3 gaqhf
                // LineRun Line Modeling
74 5e6ecf05 gaqhf
                foreach (LineNumber lineNumber in document.LINENUMBERS)
75
                    foreach (LineRun run in lineNumber.RUNS)
76
                        LineModelingByRun(run);
77 65a1ed4b gaqhf
                
78 1efc25a3 gaqhf
                // TrimLineRun Line Modeling
79 5e6ecf05 gaqhf
                foreach (TrimLine trimLine in document.TRIMLINES)
80
                    foreach (LineRun run in trimLine.RUNS)
81
                        LineModelingByRun(run);
82 65a1ed4b gaqhf
                
83 1efc25a3 gaqhf
                // Branch Line Modeling
84 3165c259 gaqhf
                foreach (var item in BranchLines)
85 335b7a24 gaqhf
                    BranchLineModeling(item);
86 65a1ed4b gaqhf
                
87 1efc25a3 gaqhf
                // EndBreak Modeling
88 3165c259 gaqhf
                foreach (var item in document.EndBreaks)
89
                    EndBreakModeling(item);
90 65a1ed4b gaqhf
                
91 1efc25a3 gaqhf
                // LineNumber Modeling
92 10872260 gaqhf
                foreach (var item in document.LINENUMBERS)
93
                    LineNumberModeling(item);
94 b9e9f4c8 gaqhf
95 1efc25a3 gaqhf
                // LineRun Line Join
96 3165c259 gaqhf
                foreach (LineNumber lineNumber in document.LINENUMBERS)
97
                    foreach (LineRun run in lineNumber.RUNS)
98
                        JoinRunLine(run);
99 65a1ed4b gaqhf
                
100 1efc25a3 gaqhf
                // TrimLineRun Line Join
101 3165c259 gaqhf
                foreach (TrimLine trimLine in document.TRIMLINES)
102
                    foreach (LineRun run in trimLine.RUNS)
103
                        JoinRunLine(run);
104 65a1ed4b gaqhf
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 310aeb31 gaqhf
121
                #region 임시 Label
122
                foreach (var item in document.SYMBOLS)
123
                {
124 8b069d9f gaqhf
                    if (item.SPPID.MAPPINGNAME.Contains("Labels - "))
125 310aeb31 gaqhf
                    {
126
                        SPPIDSymbolInfo info = item.SPPID;
127
                        Array points = new double[] { 0, item.SPPID.ORIGINAL_X, item.SPPID.ORIGINAL_Y };
128 26c6f818 gaqhf
                        string symbolUID = item.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL").VALUE;
129
                        object objectItem = SPPIDUtil.FindObjectByUID(document, symbolUID);
130
                        if (objectItem != null)
131 310aeb31 gaqhf
                        {
132 8b069d9f gaqhf
133 26c6f818 gaqhf
                            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 310aeb31 gaqhf
                            {
141 26c6f818 gaqhf
                                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 8b069d9f gaqhf
                                {
148 26c6f818 gaqhf
                                    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 8b069d9f gaqhf
                                }
171 f9125a54 gaqhf
172
                                
173
174 26c6f818 gaqhf
                                _LMModelItem.Commit();
175
                                _LMLabelPresist.Commit();
176
                                ReleaseCOMObjects(_TargetItem);
177
                                ReleaseCOMObjects(_LMLabelPresist);
178
                                ReleaseCOMObjects(_LMModelItem);
179
                                ReleaseCOMObjects(_Attributes);
180 310aeb31 gaqhf
                            }
181
                        }
182
                    }
183
                }
184
                #endregion
185 809a7640 gaqhf
            }
186 5e6ecf05 gaqhf
            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 65a1ed4b gaqhf
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 809a7640 gaqhf
        }
220 f1c9dbaa gaqhf
221 8aa6f2db gaqhf
        private void LineModelingByRun(LineRun run)
222 809a7640 gaqhf
        {
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 f1c9dbaa gaqhf
                        {
239 f2baa6a3 gaqhf
                            if (lines.Count > 0)
240
                            {
241
                                LineModeling(lines);
242
                                lines.Clear();
243
                            }
244 809a7640 gaqhf
                            lines.Add(line);
245 5dfb8a24 gaqhf
                        }
246
                    }
247
248 809a7640 gaqhf
                    prevLine = line;
249
                }
250
                // Symbol 일 경우
251
                else if (item.GetType() == typeof(Symbol))
252
                {
253 f1c9dbaa gaqhf
                    if (lines.Count > 0)
254 809a7640 gaqhf
                    {
255 f1c9dbaa gaqhf
                        LineModeling(lines);
256 809a7640 gaqhf
                        lines.Clear();
257
                    }
258 5dfb8a24 gaqhf
                }
259
            }
260
261 809a7640 gaqhf
            if (lines.Count > 0)
262
                LineModeling(lines);
263
        }
264 5dfb8a24 gaqhf
265 8aa6f2db gaqhf
        private void SymbolModelingByRun(LineRun run)
266 809a7640 gaqhf
        {
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 8aa6f2db gaqhf
        private void SymbolModelingByRunStart(Symbol symbol, LineRun run)
296 809a7640 gaqhf
        {
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 8aa6f2db gaqhf
        private void SymbolModelingByRunEnd(Symbol symbol, LineRun run)
321 809a7640 gaqhf
        {
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 5dfb8a24 gaqhf
        }
342 cfda1fed gaqhf
343 809a7640 gaqhf
        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 b9e9f4c8 gaqhf
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 809a7640 gaqhf
                _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 ac78b508 gaqhf
403 4b4dbca9 gaqhf
                foreach (var item in symbol.ChildSymbols)
404
                    CreateChildSymbol(item, _LMSymbol);
405 809a7640 gaqhf
            }
406
407
            ReleaseCOMObjects(_LMSymbol);
408
        }
409
410 b9e9f4c8 gaqhf
        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 4b4dbca9 gaqhf
        private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol)
513 ac78b508 gaqhf
        {
514 4b4dbca9 gaqhf
            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 ac78b508 gaqhf
530
            ReleaseCOMObjects(_LMSymbol);
531
        }
532
533 809a7640 gaqhf
        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 1b261371 gaqhf
        private void LineModeling(List<Line> lines)
562
        {
563 335b7a24 gaqhf
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
564 1b261371 gaqhf
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
565 f1c9dbaa gaqhf
            LMSymbol _LMSymbol1 = null;
566
            LMSymbol _LMSymbol2 = null;
567 5e6ecf05 gaqhf
            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 335b7a24 gaqhf
572
            Line startBranchLine = null;
573
            Line endBranchLine = null;
574
575 1b261371 gaqhf
            for (int i = 0; i < lines.Count; i++)
576
            {
577
                Line line = lines[i];
578 f1c9dbaa gaqhf
                if (i == 0 || i + 1 != lines.Count)
579
                {
580 809a7640 gaqhf
                    // 시작점에 연결된 Symbol 찾기
581 f1c9dbaa gaqhf
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM);
582
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
583
                    {
584 f2baa6a3 gaqhf
                        _LMSymbol1 = GetTargetSymbol(connItem as Symbol, line);
585 f1c9dbaa gaqhf
                        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 335b7a24 gaqhf
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
591 5e6ecf05 gaqhf
                    {
592
                        connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
593 56bc67e1 gaqhf
                        targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y);
594 5e6ecf05 gaqhf
595
                        if (targetConnector1 != null)
596
                            placeRunInputs.AddConnectorTarget(targetConnector1, line.SPPID.START_X, line.SPPID.START_Y);
597
                        else
598 335b7a24 gaqhf
                        {
599
                            startBranchLine = connItem as Line;
600 5e6ecf05 gaqhf
                            placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
601 335b7a24 gaqhf
                        }
602 5e6ecf05 gaqhf
                    }
603 f1c9dbaa gaqhf
                    else
604
                        placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
605
                }
606
607
                if (i + 1 == lines.Count)
608
                {
609 809a7640 gaqhf
                    // 끝점에 연결된 Symbol 찾기
610 f1c9dbaa gaqhf
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM);
611 5e6ecf05 gaqhf
612
                    if (i != 0)
613
                        placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
614
615 f1c9dbaa gaqhf
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
616
                    {
617 f2baa6a3 gaqhf
                        _LMSymbol2 = GetTargetSymbol(connItem as Symbol, line);
618 f1c9dbaa gaqhf
                        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 335b7a24 gaqhf
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
625 5e6ecf05 gaqhf
                    {
626
                        connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
627 56bc67e1 gaqhf
                        targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y);
628 5e6ecf05 gaqhf
629
                        if (targetConnector2 != null)
630
                            placeRunInputs.AddConnectorTarget(targetConnector2, line.SPPID.END_X, line.SPPID.END_Y);
631
                        else
632 335b7a24 gaqhf
                        {
633
                            endBranchLine = connItem as Line;
634 5e6ecf05 gaqhf
                            placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
635 335b7a24 gaqhf
                        }
636 5e6ecf05 gaqhf
                    }
637 f1c9dbaa gaqhf
                    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 335b7a24 gaqhf
646 f1c9dbaa gaqhf
            if (_lMConnector != null)
647
            {
648
                foreach (var line in lines)
649 5e6ecf05 gaqhf
                    line.SPPID.ModelItemId = _lMConnector.ModelItemID;
650 f1c9dbaa gaqhf
                _lMConnector.Commit();
651 335b7a24 gaqhf
                if (startBranchLine != null || endBranchLine != null)
652
                {
653 3165c259 gaqhf
                    BranchLines.Add(new Tuple<string, Line, Line>(_lMConnector.ModelItemID, startBranchLine, endBranchLine));
654 335b7a24 gaqhf
                }
655 1b261371 gaqhf
            }
656 5e6ecf05 gaqhf
657 1b261371 gaqhf
658 f1c9dbaa gaqhf
            if (_LMSymbol1 != null)
659
                ReleaseCOMObjects(_LMSymbol1);
660
            if (_LMSymbol2 != null)
661
                ReleaseCOMObjects(_LMSymbol2);
662 5e6ecf05 gaqhf
            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 1b261371 gaqhf
671 f1c9dbaa gaqhf
            ReleaseCOMObjects(_lMConnector);
672 1b261371 gaqhf
            ReleaseCOMObjects(placeRunInputs);
673
            ReleaseCOMObjects(_LMAItem);
674
        }
675
676 f2baa6a3 gaqhf
        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 335b7a24 gaqhf
        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 8b085570 gaqhf
            LMConnector _StartConnector = null;
729
            LMConnector _EndConnector = null;
730 335b7a24 gaqhf
            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 8b085570 gaqhf
                            _StartConnector = item.Key;
747 335b7a24 gaqhf
                            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 8b085570 gaqhf
                            _EndConnector = item.Key;
759 335b7a24 gaqhf
                            lengthEnd = distance;
760
                            endPoints = item.Value;
761
                        }
762
                    }
763
                }
764
            }
765
            #region Branch가 양쪽 전부일 때
766 8b085570 gaqhf
            if (_StartConnector != null && _StartConnector == _EndConnector)
767 335b7a24 gaqhf
            {
768 8b085570 gaqhf
                _placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation());
769 335b7a24 gaqhf
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 8b085570 gaqhf
                LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]);
775 335b7a24 gaqhf
                Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
776 8b085570 gaqhf
                LMConnector _EndTargetConnector = FindTargetLMConnector(endConnectorVertices,
777 335b7a24 gaqhf
                   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 8b085570 gaqhf
                        placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]);
787 335b7a24 gaqhf
                    else if (i == startPoints.Count - 1)
788 8b085570 gaqhf
                        placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]);
789 335b7a24 gaqhf
                    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 8b085570 gaqhf
            #region 양쪽이 다른 Branch 
811 335b7a24 gaqhf
            else
812
            {
813
                // Branch 시작 Connector
814 8b085570 gaqhf
                if (_StartConnector != null)
815 6b298450 gaqhf
                    BranchLineModelingByConnector(branch, _StartConnector, startPoints, true);
816 335b7a24 gaqhf
817 6b298450 gaqhf
                // Branch 끝 Connector
818
                if (_EndConnector != null)
819
                    BranchLineModelingByConnector(branch, _EndConnector, endPoints, false);
820
            }
821
            #endregion
822 335b7a24 gaqhf
823 6b298450 gaqhf
            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 335b7a24 gaqhf
831 6b298450 gaqhf
        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 335b7a24 gaqhf
841 6b298450 gaqhf
            // 같은 Line Run의 Connector 찾기
842
            foreach (var item in connectorVertices)
843
            {
844
                if (item.Key == _Connector)
845
                    continue;
846 335b7a24 gaqhf
847 6b298450 gaqhf
                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 335b7a24 gaqhf
                    {
872 6b298450 gaqhf
                        Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol;
873
                        if (symbol != null)
874 335b7a24 gaqhf
                        {
875 6b298450 gaqhf
                            _SameRunTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
876
                            break;
877 335b7a24 gaqhf
                        }
878
                    }
879 6b298450 gaqhf
                }
880
            }
881 335b7a24 gaqhf
882 6b298450 gaqhf
            // 기존 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 335b7a24 gaqhf
902 6b298450 gaqhf
            for (int i = 0; i < points.Count; i++)
903
            {
904
                double[] point = points[i];
905
                if (i == 0)
906 335b7a24 gaqhf
                {
907 6b298450 gaqhf
                    if (IsStart)
908 335b7a24 gaqhf
                    {
909 6b298450 gaqhf
                        placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
910 335b7a24 gaqhf
                    }
911 6b298450 gaqhf
                    else
912 335b7a24 gaqhf
                    {
913 6b298450 gaqhf
                        if (_SameRunTargetConnector != null)
914
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
915 65a1ed4b gaqhf
                        else if (_SameRunTargetSymbol != null)
916 6b298450 gaqhf
                            placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]);
917
                        else
918
                            placeRunInputs.AddPoint(point[0], point[1]);
919 335b7a24 gaqhf
                    }
920 6b298450 gaqhf
                }
921
                else if (i == points.Count - 1)
922
                {
923
                    if (IsStart)
924 335b7a24 gaqhf
                    {
925 6b298450 gaqhf
                        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 335b7a24 gaqhf
                        else
930
                            placeRunInputs.AddPoint(point[0], point[1]);
931
                    }
932 6b298450 gaqhf
                    else
933 335b7a24 gaqhf
                    {
934 f9125a54 gaqhf
                        if (_BranchTargetConnector != null)
935
                        {
936
                            placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
937
                        }
938 335b7a24 gaqhf
                    }
939 6b298450 gaqhf
                }
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 335b7a24 gaqhf
946 6b298450 gaqhf
            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 335b7a24 gaqhf
                }
957
958 6b298450 gaqhf
                _LMConnector.Commit();
959
                ReleaseCOMObjects(_LMConnector);
960 335b7a24 gaqhf
            }
961
962 6b298450 gaqhf
            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 335b7a24 gaqhf
            foreach (var item in connectorVertices)
971
                ReleaseCOMObjects(item.Key);
972 6b298450 gaqhf
            foreach (var item in branchConnectorVertices)
973
                ReleaseCOMObjects(item.Key);
974 335b7a24 gaqhf
        }
975
976 3165c259 gaqhf
        private void EndBreakModeling(EndBreak endBreak)
977 335b7a24 gaqhf
        {
978 10c7195c gaqhf
            object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER);
979 2a4872ec gaqhf
            LMConnector targetLMConnector = null;
980 10c7195c gaqhf
            if (ownerObj !=null && ownerObj.GetType() == typeof(Line))
981 335b7a24 gaqhf
            {
982 10c7195c gaqhf
                Line ownerLine = ownerObj as Line;
983 3165c259 gaqhf
                LMLabelPersist _LmLabelPersist = null;
984 ac78b508 gaqhf
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(ownerLine.SPPID.ModelItemId);
985 3165c259 gaqhf
986 2a4872ec gaqhf
                targetLMConnector = FindTargetLMConnectorByPoint(connectorVertices, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y);
987 b9e9f4c8 gaqhf
                
988 2a4872ec gaqhf
                if (targetLMConnector != null)
989 335b7a24 gaqhf
                {
990 ac78b508 gaqhf
                    Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
991 2a4872ec gaqhf
                    _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
992 ac78b508 gaqhf
                }
993 3165c259 gaqhf
994 ac78b508 gaqhf
                if (_LmLabelPersist != null)
995
                {
996
                    _LmLabelPersist.Commit();
997
                    ReleaseCOMObjects(_LmLabelPersist);
998 335b7a24 gaqhf
                }
999 b9e9f4c8 gaqhf
                else
1000 2a4872ec gaqhf
                    RetryEndBreakModeling(endBreak, targetLMConnector);
1001 b9e9f4c8 gaqhf
1002 ac78b508 gaqhf
                foreach (var item in connectorVertices)
1003
                    ReleaseCOMObjects(item.Key);
1004 2a4872ec gaqhf
1005 335b7a24 gaqhf
            }
1006 10c7195c gaqhf
            else if (ownerObj != null && ownerObj.GetType() == typeof(Symbol))
1007
            {
1008
                Symbol ownerSymbol = ownerObj as Symbol;
1009
                LMSymbol _LMSymbol = dataSource.GetSymbol(ownerSymbol.SPPID.RepresentationId);
1010
1011 2a4872ec gaqhf
                targetLMConnector = null;
1012 10c7195c gaqhf
                double distance = double.MaxValue;
1013 b9e9f4c8 gaqhf
1014 10c7195c gaqhf
                foreach (LMConnector connector in _LMSymbol.Avoid1Connectors)
1015
                {
1016 26c6f818 gaqhf
                    if (connector.get_ItemStatus() == "Active")
1017 10c7195c gaqhf
                    {
1018 26c6f818 gaqhf
                        dynamic OID = connector.get_GraphicOID();
1019
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1020
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1021
                        int verticesCount = lineStringGeometry.VertexCount;
1022
                        double[] vertices = null;
1023
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1024
                        for (int i = 0; i < verticesCount; i++)
1025 10c7195c gaqhf
                        {
1026 26c6f818 gaqhf
                            double x = 0;
1027
                            double y = 0;
1028
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1029
1030 b9e9f4c8 gaqhf
                            double result = SPPIDUtil.CalcPointToPointdDistance(x, y, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y);
1031 26c6f818 gaqhf
                            if (result < distance)
1032
                            {
1033
                                targetLMConnector = connector;
1034
                                distance = result;
1035
                            }
1036 10c7195c gaqhf
                        }
1037
                    }
1038
                }
1039
1040
                foreach (LMConnector connector in _LMSymbol.Avoid2Connectors)
1041
                {
1042 b9e9f4c8 gaqhf
                    if (connector.get_ItemStatus() == "Active")
1043 10c7195c gaqhf
                    {
1044 b9e9f4c8 gaqhf
                        dynamic OID = connector.get_GraphicOID();
1045
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1046
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1047
                        int verticesCount = lineStringGeometry.VertexCount;
1048
                        double[] vertices = null;
1049
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1050
                        for (int i = 0; i < verticesCount; i++)
1051 10c7195c gaqhf
                        {
1052 b9e9f4c8 gaqhf
                            double x = 0;
1053
                            double y = 0;
1054
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1055
1056
                            double result = SPPIDUtil.CalcPointToPointdDistance(x, y, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y);
1057
                            if (result < distance)
1058
                            {
1059
                                targetLMConnector = connector;
1060
                                distance = result;
1061
                            }
1062 10c7195c gaqhf
                        }
1063
                    }
1064
                }
1065
1066
                if (targetLMConnector != null)
1067
                {
1068
                    LMLabelPersist _LmLabelPersist = null;
1069
                    Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
1070
                    _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
1071
                    if (_LmLabelPersist != null)
1072
                    {
1073
                        _LmLabelPersist.Commit();
1074
                        ReleaseCOMObjects(_LmLabelPersist);
1075
                    }
1076 b9e9f4c8 gaqhf
                    else
1077 2a4872ec gaqhf
                        RetryEndBreakModeling(endBreak, targetLMConnector);
1078
                }
1079
                
1080
                ReleaseCOMObjects(_LMSymbol);
1081
            }
1082
        }
1083 b9e9f4c8 gaqhf
1084 2a4872ec gaqhf
        private void RetryEndBreakModeling(EndBreak endBreak, LMConnector targetLMConnector)
1085
        {
1086
            bool isZeroLength = Convert.ToBoolean(targetLMConnector.get_IsZeroLength());
1087
            Array array = null;
1088
            LMLabelPersist _LMLabelPersist = null;
1089
            LMConnector _LMConnector = null;
1090
            dynamic OID = targetLMConnector.get_GraphicOID();
1091
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1092
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1093
            int verticesCount = lineStringGeometry.VertexCount;
1094
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1095
            _LMAItem _LMAItem = _placement.PIDCreateItem(@"\Piping\Routing\Process Lines\Primary Piping.sym");
1096 b9e9f4c8 gaqhf
1097 2a4872ec gaqhf
            if (isZeroLength)
1098
            {
1099
                double[] vertices = null;
1100
                lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1101
                double x = 0;
1102
                double y = 0;
1103
                lineStringGeometry.GetVertex(1, ref x, ref y);
1104 b9e9f4c8 gaqhf
1105 2a4872ec gaqhf
                placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem1SymbolObject, x, y);
1106
                placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem2SymbolObject, x, y);
1107 b9e9f4c8 gaqhf
1108 2a4872ec gaqhf
                _placement.PIDRemovePlacement(targetLMConnector.AsLMRepresentation());
1109
                _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1110
1111
                array = new double[] { 0, x, y };
1112
                _LMLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: _LMConnector.AsLMRepresentation(), IsLeaderVisible: true);
1113
            }
1114
            else
1115
            {
1116
                List<double[]> vertices = new List<double[]>();
1117
                for (int i = 1; i <= verticesCount; i++)
1118
                {
1119
                    double x = 0;
1120
                    double y = 0;
1121
                    lineStringGeometry.GetVertex(i, ref x, ref y);
1122
                    vertices.Add(new double[] { x, y });
1123
                }
1124
1125
                for (int i = 0; i < vertices.Count; i++)
1126
                {
1127
                    double[] points = vertices[i];
1128
                    if (i == 0)
1129
                    {
1130
                        if (targetLMConnector.ConnectItem1SymbolObject != null)
1131
                            placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem1SymbolObject, points[0], points[1]);
1132
                        else
1133
                            placeRunInputs.AddPoint(points[0], points[1]);
1134 b9e9f4c8 gaqhf
                    }
1135 2a4872ec gaqhf
                    else if (i == vertices.Count - 1)
1136
                    {
1137
                        if (targetLMConnector.ConnectItem2SymbolObject != null)
1138
                            placeRunInputs.AddSymbolTarget(targetLMConnector.ConnectItem2SymbolObject, points[0], points[1]);
1139
                        else
1140
                            placeRunInputs.AddPoint(points[0], points[1]);
1141
                    }
1142
                    else
1143
                        placeRunInputs.AddPoint(points[0], points[1]);
1144 10c7195c gaqhf
                }
1145 2a4872ec gaqhf
1146
                List<Line> lines = SPPIDUtil.FindLinesByModelId(document, targetLMConnector.ModelItemID);
1147 b9e9f4c8 gaqhf
                
1148 2a4872ec gaqhf
                _placement.PIDRemovePlacement(targetLMConnector.AsLMRepresentation());
1149
                _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1150
1151
                foreach (var line in lines)
1152
                    line.SPPID.ModelItemId = _LMConnector.ModelItemID;
1153
1154
                array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
1155
                _LMLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: _LMConnector.AsLMRepresentation(), IsLeaderVisible: true);
1156 10c7195c gaqhf
            }
1157 2a4872ec gaqhf
1158
1159
            if (_LMLabelPersist != null)
1160
            {
1161
                _LMLabelPersist.Commit();
1162
                ReleaseCOMObjects(_LMLabelPersist);
1163
            }
1164
            else
1165
            {
1166
                
1167
            }
1168
1169
            ReleaseCOMObjects(_LMConnector);
1170
            ReleaseCOMObjects(placeRunInputs);
1171
            ReleaseCOMObjects(_LMAItem);
1172 3165c259 gaqhf
        }
1173 10872260 gaqhf
1174 335b7a24 gaqhf
        private void JoinPipeRun(string fromModelItemId, string toModelItemId)
1175
        {
1176 310aeb31 gaqhf
            LMModelItem modelItem1 = dataSource.GetModelItem(toModelItemId);
1177
            _LMAItem item1 = modelItem1.AsLMAItem();
1178
            LMModelItem modelItem2 = dataSource.GetModelItem(fromModelItemId);
1179
            _LMAItem item2 = modelItem2.AsLMAItem();
1180
            
1181 335b7a24 gaqhf
            // item2가 item1으로 조인
1182
            try
1183
            {
1184
                _placement.PIDJoinRuns(ref item1, ref item2);
1185 65a1ed4b gaqhf
                item1.Commit();
1186
                item2.Commit();
1187 335b7a24 gaqhf
            }
1188
            catch (Exception ex)
1189
            {
1190
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
1191
            }
1192
            finally
1193
            {
1194 310aeb31 gaqhf
                ReleaseCOMObjects(modelItem1);
1195
                ReleaseCOMObjects(item1);
1196
                ReleaseCOMObjects(modelItem2);
1197
                ReleaseCOMObjects(item2);
1198 335b7a24 gaqhf
            }
1199
        }
1200
1201
        private void AutoJoinPipeRun(string modelItemId)
1202
        {
1203 310aeb31 gaqhf
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
1204
            _LMAItem item = modelItem.AsLMAItem();
1205 65a1ed4b gaqhf
            try
1206
            {
1207
                string modelitemID = item.Id;
1208
                _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item);
1209
                string afterModelItemID = item.Id;
1210
                if (modelitemID != afterModelItemID)
1211
                {
1212
                    List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID);
1213
                    foreach (var line in lines)
1214
                        line.SPPID.ModelItemId = afterModelItemID;
1215
                }
1216
                item.Commit();
1217
            }
1218
            catch (Exception ex)
1219
            {
1220
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
1221
            }
1222
            finally
1223
            {
1224 310aeb31 gaqhf
                ReleaseCOMObjects(modelItem);
1225
                ReleaseCOMObjects(item);
1226 65a1ed4b gaqhf
            }
1227 335b7a24 gaqhf
        }
1228
1229
        private void JoinRunLine(LineRun run)
1230
        {
1231
            string modelItemId = string.Empty;
1232
            foreach (var item in run.RUNITEMS)
1233
            {
1234
                if (item.GetType() == typeof(Line))
1235
                {
1236
                    Line line = item as Line;
1237
                    if (modelItemId != line.SPPID.ModelItemId)
1238
                    {
1239
                        AutoJoinPipeRun(line.SPPID.ModelItemId);
1240
                        modelItemId = line.SPPID.ModelItemId;
1241
                    }
1242
                }
1243
            }
1244
        }
1245
1246 5e6ecf05 gaqhf
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
1247
        {
1248
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
1249 310aeb31 gaqhf
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
1250
1251
            if (modelItem != null)
1252 5e6ecf05 gaqhf
            {
1253 310aeb31 gaqhf
                foreach (LMRepresentation rep in modelItem.Representations)
1254 5e6ecf05 gaqhf
                {
1255
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
1256
                    {
1257
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
1258
                        connectorVertices.Add(_LMConnector, new List<double[]>());
1259
                        dynamic OID = rep.get_GraphicOID();
1260 335b7a24 gaqhf
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1261 5e6ecf05 gaqhf
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1262
                        int verticesCount = lineStringGeometry.VertexCount;
1263
                        double[] vertices = null;
1264
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1265
                        for (int i = 0; i < verticesCount; i++)
1266
                        {
1267
                            double x = 0;
1268
                            double y = 0;
1269
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1270 335b7a24 gaqhf
                            connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) });
1271 5e6ecf05 gaqhf
                        }
1272
                    }
1273
                }
1274
1275 310aeb31 gaqhf
                ReleaseCOMObjects(modelItem);
1276 5e6ecf05 gaqhf
            }
1277
1278
            return connectorVertices;
1279
        }
1280
1281 56bc67e1 gaqhf
        private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2)
1282 5e6ecf05 gaqhf
        {
1283
            double length = double.MaxValue;
1284
            LMConnector targetConnector = null;
1285
            foreach (var item in connectorVertices)
1286
            {
1287
                List<double[]> points = item.Value;
1288
                for (int i = 0; i < points.Count - 1; i++)
1289
                {
1290
                    double[] point1 = points[i];
1291
                    double[] point2 = points[i + 1];
1292
1293 335b7a24 gaqhf
                    double maxLineX = Math.Max(point1[0], point2[0]);
1294
                    double minLineX = Math.Min(point1[0], point2[0]);
1295
                    double maxLineY = Math.Max(point1[1], point2[1]);
1296
                    double minLineY = Math.Min(point1[1], point2[1]);
1297
1298
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
1299
1300 56bc67e1 gaqhf
                    // 두직선의 교차점
1301
                    double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]);
1302
                    if (crossingPoint != null)
1303 5e6ecf05 gaqhf
                    {
1304 30a9ffce gaqhf
                        double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]);
1305 335b7a24 gaqhf
                        if (length >= distance)
1306 30a9ffce gaqhf
                        {
1307 335b7a24 gaqhf
                            if (slope == SlopeType.Slope &&
1308
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
1309
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
1310
                            {
1311
                                targetConnector = item.Key;
1312
                                length = distance;
1313
                            }
1314
                            else if (slope == SlopeType.HORIZONTAL &&
1315
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
1316
                            {
1317
                                targetConnector = item.Key;
1318
                                length = distance;
1319
                            }
1320
                            else if (slope == SlopeType.VERTICAL &&
1321
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
1322
                            {
1323
                                targetConnector = item.Key;
1324
                                length = distance;
1325
                            }
1326 30a9ffce gaqhf
                        }
1327 5e6ecf05 gaqhf
                    }
1328
                }
1329
            }
1330
1331
            return targetConnector;
1332
        }
1333
1334 ac78b508 gaqhf
        private LMConnector FindTargetLMConnectorByPoint(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
1335
        {
1336
            double length = double.MaxValue;
1337
            LMConnector targetConnector = null;
1338
            foreach (var item in connectorVertices)
1339
            {
1340
                List<double[]> points = item.Value;
1341
1342
                foreach (double[] point in points)
1343
                {
1344
                    double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
1345
                    if (length >= distance)
1346
                    {
1347
                        targetConnector = item.Key;
1348
                        length = distance;
1349
                    }
1350
                }
1351
            }
1352
1353
            return targetConnector;
1354
        }
1355
1356 cfda1fed gaqhf
        private void LineNumberModeling(LineNumber lineNumber)
1357
        {
1358 f4880c6a gaqhf
            Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line;
1359
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
1360
            LMConnector connectedLMConnector = FindTargetLMConnectorByPoint(connectorVertices, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y);
1361
            if (connectedLMConnector != null)
1362 10872260 gaqhf
            {
1363 b65a7e32 gaqhf
                double x = 0;
1364
                double y = 0;
1365
                CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
1366
1367
                Array points = new double[] { 0, x, y };
1368 f4880c6a gaqhf
                LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false);
1369
                _LmLabelPresist.Commit();
1370 cfda1fed gaqhf
1371 f4880c6a gaqhf
                foreach (var item in connectorVertices)
1372
                    ReleaseCOMObjects(item.Key);
1373
                if (_LmLabelPresist != null)
1374
                {
1375
                    lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
1376
                    ReleaseCOMObjects(_LmLabelPresist);
1377 10872260 gaqhf
                }
1378
            }
1379 cfda1fed gaqhf
        }
1380
1381 a7e9beec gaqhf
        private void InputLineNumberAttribute(LineNumber lineNumber)
1382
        {
1383
            foreach (var run in lineNumber.RUNS)
1384
            {
1385
                foreach (var item in run.RUNITEMS)
1386
                {
1387
                    if (item.GetType() == typeof(Line))
1388
                    {
1389
                        Line line = item as Line;
1390 a3557cbc gaqhf
                        LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
1391
                        if (_LMModelItem.get_ItemStatus() == "Active")
1392 a7e9beec gaqhf
                        {
1393 a3557cbc gaqhf
                            foreach (var attribute in lineNumber.ATTRIBUTES)
1394 a7e9beec gaqhf
                            {
1395 a3557cbc gaqhf
                                LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
1396
                                if (mapping != null)
1397 a7e9beec gaqhf
                                {
1398 a3557cbc gaqhf
                                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
1399
                                    if (_LMAAttribute != null)
1400
                                    {
1401
                                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
1402
                                            _LMAAttribute.set_Value(attribute.VALUE);
1403
                                        else if (_LMAAttribute.get_Value() != attribute.VALUE)
1404
                                            _LMAAttribute.set_Value(attribute.VALUE);
1405
                                    }
1406 a7e9beec gaqhf
                                }
1407
                            }
1408 a3557cbc gaqhf
                            _LMModelItem.Commit();
1409
                            break;
1410 a7e9beec gaqhf
                        }
1411 f9125a54 gaqhf
                        ReleaseCOMObjects(_LMModelItem);
1412 a7e9beec gaqhf
                    }
1413
                }
1414
            }
1415
        }
1416
1417 1efc25a3 gaqhf
        private void InputSymbolAttribute(Symbol symbol)
1418
        {
1419 ac78b508 gaqhf
            try
1420 1efc25a3 gaqhf
            {
1421 ac78b508 gaqhf
                if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
1422 402ef5b1 gaqhf
                {
1423 ac78b508 gaqhf
                    LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1424 310aeb31 gaqhf
                    LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
1425 ea80efaa gaqhf
                    LMAAttributes _Attributes = _LMModelItem.Attributes;
1426 402ef5b1 gaqhf
1427 ac78b508 gaqhf
                    foreach (var item in symbol.PROPERTIES)
1428
                    {
1429 1efc25a3 gaqhf
1430
1431 ac78b508 gaqhf
                    }
1432
1433
                    foreach (var item in symbol.ATTRIBUTES)
1434 65a1ed4b gaqhf
                    {
1435 ac78b508 gaqhf
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
1436 26c6f818 gaqhf
                        if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None")
1437 ac78b508 gaqhf
                        {
1438
                            LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
1439
                            if (_Attribute != null)
1440 8b069d9f gaqhf
                            {
1441
                                // 임시
1442
                                if (item.ATTRIBUTETYPE == "String")
1443
                                {
1444
                                    if (!string.IsNullOrEmpty(item.VALUE))
1445
                                    {
1446
                                        if (!DBNull.Value.Equals(_Attribute.get_Value()) && !string.IsNullOrEmpty(_Attribute.get_Value()))
1447
                                        {
1448
                                            string value = _Attribute.get_Value() + "\n" + item.VALUE;
1449
                                            _Attribute.set_Value(value);
1450
                                        }
1451
                                        else
1452
                                        {
1453
                                            _Attribute.set_Value(item.VALUE);
1454
                                        }
1455
                                    }
1456
                                }
1457
                                else
1458
                                {
1459
                                    _Attribute.set_Value(item.VALUE);
1460
                                }
1461
                            }
1462 ac78b508 gaqhf
                        }
1463 65a1ed4b gaqhf
                    }
1464 1efc25a3 gaqhf
1465 ac78b508 gaqhf
                    foreach (var item in symbol.ASSOCIATIONS)
1466
                    {
1467 1efc25a3 gaqhf
1468 ac78b508 gaqhf
                    }
1469 402ef5b1 gaqhf
1470 ac78b508 gaqhf
                    ReleaseCOMObjects(_LMSymbol);
1471 ea80efaa gaqhf
                    ReleaseCOMObjects(_Attributes);
1472
                    ReleaseCOMObjects(_LMModelItem);
1473 ac78b508 gaqhf
                }
1474
            }
1475
            catch (Exception ex)
1476
            {
1477
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
1478 1efc25a3 gaqhf
            }
1479
        }
1480
1481 cfda1fed gaqhf
        private void TextModeling(Text text)
1482
        {
1483 6b298450 gaqhf
            LMSymbol _LMSymbol = null;
1484
            try
1485
            {
1486 8b069d9f gaqhf
                //if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None")
1487
                if (text.ASSOCIATION)
1488 ea80efaa gaqhf
                {
1489
                    object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
1490
                    if (owner.GetType() == typeof(Symbol))
1491
                    {
1492
                        Symbol symbol = owner as Symbol;
1493
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1494
                        if (_LMSymbol != null)
1495
                        {
1496
                            Association association = symbol.ASSOCIATIONS.Find(x => x.VALUE == text.UID);
1497
                            List<BaseModel.Attribute> attributes = symbol.ATTRIBUTES.FindAll(x => x.ATTRIBUTETYPE == association.TYPE);
1498
                            AttributeMapping mapping = null;
1499
                            foreach (var attribute in attributes)
1500
                            {
1501 26c6f818 gaqhf
                                if (string.IsNullOrEmpty(attribute.VALUE) || attribute.VALUE == "None")
1502
                                    continue;
1503
1504 ea80efaa gaqhf
                                 mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
1505
                                if (mapping != null)
1506
                                    break;  
1507
                            }
1508
1509
                            if (mapping != null)
1510
                            {
1511 1a3a74a8 gaqhf
                                double x = 0;
1512
                                double y = 0;
1513
1514 b65a7e32 gaqhf
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
1515
                                Array array = new double[] { 0, x, y };
1516 1a3a74a8 gaqhf
1517 ea80efaa gaqhf
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: true);
1518
                                if (_LMLabelPersist!=null)
1519
                                {
1520 f9125a54 gaqhf
                                    _LMLabelPersist.Commit();
1521 ea80efaa gaqhf
                                    ReleaseCOMObjects(_LMLabelPersist);
1522
                                }
1523
                            }
1524
                        }
1525
                    }
1526
                    else if (owner.GetType() == typeof(Line))
1527
                    {
1528
1529
                    }
1530
                }
1531
                else
1532
                {
1533
                    LMItemNote _LMItemNote = null;
1534
                    LMAAttribute _LMAAttribute = null;
1535
1536 b65a7e32 gaqhf
                    double x = 0;
1537
                    double y = 0;
1538
1539
                    CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation);
1540
1541
                    _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y);
1542 ea80efaa gaqhf
                    _LMSymbol.Commit();
1543
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
1544
                    _LMItemNote.Commit();
1545
                    _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
1546
                    _LMAAttribute.set_Value(text.VALUE);
1547
                    _LMItemNote.Commit();
1548
1549
                    if (_LMAAttribute != null)
1550
                        ReleaseCOMObjects(_LMAAttribute);
1551
                    if (_LMItemNote != null)
1552
                        ReleaseCOMObjects(_LMItemNote);
1553
                }
1554 6b298450 gaqhf
            }
1555
            catch (Exception ex)
1556
            {
1557 cfda1fed gaqhf
1558 6b298450 gaqhf
            }
1559
            finally
1560
            {
1561
                if (_LMSymbol != null)
1562
                    ReleaseCOMObjects(_LMSymbol);
1563
            }
1564 cfda1fed gaqhf
        }
1565
1566
        private void NoteModeling(Note note)
1567
        {
1568 6b298450 gaqhf
            LMSymbol _LMSymbol = null;
1569
            LMItemNote _LMItemNote = null;
1570
            LMAAttribute _LMAAttribute = null;
1571
1572
            try
1573
            {
1574 b65a7e32 gaqhf
                double x = 0;
1575
                double y = 0;
1576
1577
                CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation);
1578
1579
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y);
1580 6b298450 gaqhf
                _LMSymbol.Commit();
1581
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
1582
                _LMItemNote.Commit();
1583
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
1584
                _LMAAttribute.set_Value(note.VALUE);
1585
                _LMItemNote.Commit();
1586
            }
1587
            catch (Exception ex)
1588
            {
1589 cfda1fed gaqhf
1590 6b298450 gaqhf
            }
1591
            finally
1592
            {
1593
                if (_LMAAttribute != null)
1594
                    ReleaseCOMObjects(_LMAAttribute);
1595
                if (_LMItemNote != null)
1596
                    ReleaseCOMObjects(_LMItemNote);
1597
                if (_LMSymbol != null)
1598
                    ReleaseCOMObjects(_LMSymbol);
1599
            }
1600
            
1601 cfda1fed gaqhf
        }
1602
1603 b65a7e32 gaqhf
        private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location)
1604
        {
1605
            if (location == Location.None)
1606
            {
1607
                x = originX;
1608
                y = originY;
1609
            }
1610
            else
1611
            {
1612
                if (location.HasFlag(Location.Center))
1613
                {
1614
                    x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2;
1615
                    y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2;
1616
                }
1617
1618
                if (location.HasFlag(Location.Left))
1619
                    x = SPPIDLabelLocation.X1;
1620
                else if (location.HasFlag(Location.Right))
1621
                    x = SPPIDLabelLocation.X2;
1622
1623
                if (location.HasFlag(Location.Down))
1624
                    y = SPPIDLabelLocation.Y1;
1625
                else if (location.HasFlag(Location.Up))
1626
                    y = SPPIDLabelLocation.Y2;
1627
            }
1628
        }
1629 5a4b8f32 gaqhf
1630
        public void ReleaseCOMObjects(params object[] objVars)
1631
        {
1632
            int intNewRefCount = 0;
1633
            foreach (object obj in objVars)
1634
            {
1635
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
1636
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
1637
            }
1638
        }
1639 cfda1fed gaqhf
    }
1640
}
클립보드 이미지 추가 (최대 크기: 500 MB)