프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 6db0e733

이력 | 보기 | 이력해설 | 다운로드 (187 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 4d2571ab gaqhf
using System.Data;
7 cfda1fed gaqhf
using Llama;
8
using Plaice;
9 8aa6f2db gaqhf
using Ingr.RAD2D.Interop.RAD2D;
10
using Ingr.RAD2D.Internal;
11
using Ingr.RAD2D.Helper;
12 cfda1fed gaqhf
using Converter.BaseModel;
13
using Converter.SPPID.Model;
14
using Converter.SPPID.Properties;
15
using Converter.SPPID.Util;
16
using Converter.SPPID.DB;
17 5e6ecf05 gaqhf
using Ingr.RAD2D.MacroControls.CmdCtrl;
18
using Ingr.RAD2D;
19 5dfb8a24 gaqhf
using System.Windows;
20 cfda1fed gaqhf
using System.Threading;
21 5dfb8a24 gaqhf
using System.Drawing;
22 cfda1fed gaqhf
using Microsoft.VisualBasic;
23
using Newtonsoft.Json;
24 ca214bc3 gaqhf
using DevExpress.XtraSplashScreen;
25 cfda1fed gaqhf
namespace Converter.SPPID
26
{
27
    public class AutoModeling
28
    {
29 809a7640 gaqhf
        Placement _placement;
30
        LMADataSource dataSource;
31 7aee331b gaqhf
        LMDrawing currentDrawing;
32 1ba9c671 gaqhf
        dynamic newDrawing;
33 d19ae675 gaqhf
        dynamic application;
34 5e6ecf05 gaqhf
        Ingr.RAD2D.Application radApp;
35 cfda1fed gaqhf
        SPPID_Document document;
36 b65a7e32 gaqhf
        ETCSetting _ETCSetting;
37 f1c9dbaa gaqhf
38 d5ec4d0f gaqhf
        public string DocumentLabelText { get; set; }
39
40 f3e2693f gaqhf
        List<Line> BranchLines = new List<Line>();
41 644f40b3 gaqhf
        List<string> ZeroLengthSymbolToSymbolModelItemID = new List<string>();
42 87f02fc0 gaqhf
        List<string> ZeroLengthModelItemID = new List<string>();
43 1ff0105e gaqhf
        List<string> ZeroLengthModelItemIDReverse = new List<string>();
44 f1a7faf9 gaqhf
        List<Symbol> prioritySymbols;
45 47ad9a46 gaqhf
46 d19ae675 gaqhf
        public AutoModeling(SPPID_Document document, dynamic application, Ingr.RAD2D.Application radApp)
47 cfda1fed gaqhf
        {
48
            this.document = document;
49 d19ae675 gaqhf
            this.application = application;
50 5e6ecf05 gaqhf
            this.radApp = radApp;
51 b65a7e32 gaqhf
            this._ETCSetting = ETCSetting.GetInstance();
52 cfda1fed gaqhf
        }
53
54 02480ac1 gaqhf
        private void SetSystemEditingCommand(bool value)
55
        {
56
            foreach (var item in radApp.Commands)
57
            {
58
                if (item.Argument == "SystemEditingCmd.SystemEditing")
59
                {
60
                    if (item.Checked != value)
61
                    {
62
                        radApp.RunMacro("systemeditingcmd.dll");
63
                        break;
64
                    }
65
66
                }
67
            }
68
        }
69
70 74752074 gaqhf
        /// <summary>
71
        /// 도면 단위당 실행되는 메서드
72
        /// </summary>
73 1ba9c671 gaqhf
        public void Run()
74 c2fef4ca gaqhf
        {
75 224535bb gaqhf
            string drawingNumber = document.DrawingNumber;
76
            string drawingName = document.DrawingName;
77 1ba9c671 gaqhf
            try
78 c2fef4ca gaqhf
            {
79 1ba9c671 gaqhf
                _placement = new Placement();
80
                dataSource = _placement.PIDDataSource;
81
82 224535bb gaqhf
                CreateDocument(ref drawingNumber, ref drawingName);
83 1ba9c671 gaqhf
84 0e0edfad gaqhf
                if (DocumentCoordinateCorrection())
85 310aeb31 gaqhf
                {
86 3734dcc5 gaqhf
                    Log.Write("Start Modeling");
87 965eb728 gaqhf
                    SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true);
88 9628f54b gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetParent, (IntPtr)radApp.HWnd);
89 cf210438 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllStepCount, 18);
90 20972c61 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText);
91 f9cc5190 gaqhf
92 6db30942 gaqhf
                    // Equipment Modeling
93 b01e7456 gaqhf
                    RunEquipmentModeling();
94
                    // Symbol Modeling
95
                    RunSymbolModeling();
96 3939eebf gaqhf
                    // LineRun Line Modeling
97 b01e7456 gaqhf
                    RunLineModeling();
98
                    // Clear Attribute
99 1ff0105e gaqhf
                    RunClearValueInconsistancy();
100 b01e7456 gaqhf
                    // EndBreak Modeling
101
                    RunEndBreakModeling();
102
                    // SpecBreak Modeling
103
                    RunSpecBreakModeling();
104 d23fe61b gaqhf
                    // Join SameConnector
105 dfac4553 gaqhf
                    RunJoinRunForSameConnector();
106 d23fe61b gaqhf
                    // Check FlowDirection
107 1ff0105e gaqhf
                    RunFlowDirection();
108 d77973b3 gaqhf
                    // Join Run
109
                    RunJoinRun();
110 8701de36 gaqhf
                    //Line Number Modeling
111
                    RunLineNumberModeling();
112 32205389 gaqhf
                    // Note Modeling
113
                    RunNoteModeling();
114
                    // Text Modeling
115
                    RunTextModeling();
116
                    // Input LineNumber Attribute
117
                    RunInputLineNumberAttribute();
118
                    // Input Symbol Attribute
119
                    RunInputSymbolAttribute();
120
                    // Input SpecBreak Attribute
121
                    RunInputSpecBreakAttribute();
122
                    // Label Symbol Modeling
123
                    RunLabelSymbolModeling();
124 4ba01591 gaqhf
125 30ba9ae0 gaqhf
                    // Result Logging
126
                    document.CheckModelingResult();
127 310aeb31 gaqhf
                }
128 809a7640 gaqhf
            }
129 5e6ecf05 gaqhf
            catch (Exception ex)
130
            {
131 9628f54b gaqhf
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null);
132
                SplashScreenManager.CloseForm(false);
133 5e6ecf05 gaqhf
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
134
            }
135
            finally
136
            {
137 3734dcc5 gaqhf
                Log.Write("End Modeling");
138 1ba9c671 gaqhf
                application.ActiveWindow.Fit();
139 b2d1c1aa gaqhf
140 7aee331b gaqhf
                if (currentDrawing != null)
141
                    ReleaseCOMObjects(currentDrawing);
142
143 b66a2996 gaqhf
                if (radApp.ActiveDocument != null)
144 3939eebf gaqhf
                {
145 1805d3b7 gaqhf
                    radApp.ActiveDocument.Save();
146 1ba9c671 gaqhf
                    ReleaseCOMObjects(newDrawing);
147 3939eebf gaqhf
                }
148 1ba9c671 gaqhf
149 5e6ecf05 gaqhf
                ReleaseCOMObjects(dataSource);
150
                ReleaseCOMObjects(_placement);
151 965eb728 gaqhf
152 224535bb gaqhf
                Project_DB.InsertDrawingInfo(document.PATH, drawingNumber, drawingName, document);
153 9628f54b gaqhf
                if (SplashScreenManager.Default.IsSplashFormVisible)
154
                {
155
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null);
156
                    SplashScreenManager.CloseForm(false);
157 3734dcc5 gaqhf
                    Log.Write("\r\n");
158 9628f54b gaqhf
                }
159 5e6ecf05 gaqhf
            }
160 65a1ed4b gaqhf
        }
161 b01e7456 gaqhf
        private void RunEquipmentModeling()
162
        {
163
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.Equipments.Count);
164 32205389 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Equipments Modeling");
165 b01e7456 gaqhf
            foreach (Equipment item in document.Equipments)
166
            {
167
                try
168
                {
169
                    EquipmentModeling(item);
170
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.Equipments.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
171
                }
172
                catch (Exception ex)
173
                {
174
                    Log.Write("Error in EquipmentModeling");
175
                    Log.Write("UID : " + item.UID);
176
                    Log.Write(ex.Message);
177
                    Log.Write(ex.StackTrace);
178
                }
179
            }
180
        }
181
        private void RunSymbolModeling()
182
        {
183
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
184 32205389 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbol Modeling");
185 b01e7456 gaqhf
            prioritySymbols = GetPrioritySymbol();
186
            foreach (var item in prioritySymbols)
187
            {
188
                try
189
                {
190
                    SymbolModelingBySymbol(item);
191
                }
192
                catch (Exception ex)
193
                {
194
                    Log.Write("Error in SymbolModelingByPriority");
195
                    Log.Write("UID : " + item.UID);
196
                    Log.Write(ex.Message);
197
                    Log.Write(ex.StackTrace);
198
                }
199
            }
200
        }
201
        private void RunLineModeling()
202
        {
203 cf210438 gaqhf
            List<Line> AllLine = document.LINES.ToList();
204
            List<Line> stepLast_Line = document.LINES.FindAll(x => x.CONNECTORS.FindAll(y => y.ConnectedObject != null && y.ConnectedObject.GetType() == typeof(Symbol)).Count == 2 &&
205
            !SPPIDUtil.IsBranchedLine(document, x));
206
            List<Line> step1_Line = AllLine.FindAll(x => !stepLast_Line.Contains(x));
207
208
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, step1_Line.Count);
209 02a45794 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling - 1");
210 cf210438 gaqhf
211
            SetPriorityLine(step1_Line);
212
            foreach (var item in step1_Line)
213 b01e7456 gaqhf
            {
214
                try
215
                {
216
                    NewLineModeling(item);
217
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
218
                }
219
                catch (Exception ex)
220
                {
221
                    Log.Write("Error in NewLineModeling");
222
                    Log.Write("UID : " + item.UID);
223
                    Log.Write(ex.Message);
224
                    Log.Write(ex.StackTrace);
225
                }
226
            }
227 cf210438 gaqhf
228 f3e2693f gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, BranchLines.Count);
229 02a45794 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling - 2");
230 f3e2693f gaqhf
            int branchCount = BranchLines.Count;
231
            while (BranchLines.Count > 0)
232 b01e7456 gaqhf
            {
233
                try
234
                {
235
                    SortBranchLines();
236 f3e2693f gaqhf
                    Line item = BranchLines[0];
237 d4c3e39f gaqhf
                    NewLineModeling(item, true);
238
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
239 b01e7456 gaqhf
                }
240
                catch (Exception ex)
241
                {
242
                    Log.Write("Error in NewLineModeling");
243 f3e2693f gaqhf
                    Log.Write("UID : " + BranchLines[0].UID);
244 b01e7456 gaqhf
                    Log.Write(ex.Message);
245
                    Log.Write(ex.StackTrace);
246 a31a512e gaqhf
                    break;
247 b01e7456 gaqhf
                }
248
            }
249 a31a512e gaqhf
250 cf210438 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, stepLast_Line.Count);
251 02a45794 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling - 3");
252 cf210438 gaqhf
            foreach (var item in stepLast_Line)
253 a31a512e gaqhf
            {
254 cf210438 gaqhf
                try
255
                {
256
                    NewLineModeling(item);
257
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
258
                }
259
                catch (Exception ex)
260
                {
261
                    Log.Write("Error in NewLineModeling");
262
                    Log.Write("UID : " + item.UID);
263
                    Log.Write(ex.Message);
264
                    Log.Write(ex.StackTrace);
265
                }
266 a31a512e gaqhf
            }
267 b01e7456 gaqhf
        }
268 1ff0105e gaqhf
        private void RunClearValueInconsistancy()
269 b01e7456 gaqhf
        {
270 32205389 gaqhf
            int count = 1;
271 63fbf592 gaqhf
            bool loop = true;
272
            while (loop)
273 b01e7456 gaqhf
            {
274 63fbf592 gaqhf
                loop = false;
275
                LMAFilter filter = new LMAFilter();
276
                LMACriterion criterion = new LMACriterion();
277
                filter.ItemType = "Relationship";
278
                criterion.SourceAttributeName = "SP_DRAWINGID";
279
                criterion.Operator = "=";
280
                criterion.set_ValueAttribute(currentDrawing.Id);
281
                filter.get_Criteria().Add(criterion);
282
283
                LMRelationships relationships = new LMRelationships();
284
                relationships.Collect(dataSource, Filter: filter);
285
286 d23fe61b gaqhf
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, relationships.Count);
287 f9cc5190 gaqhf
                if (count > 1)
288
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStepMinus, null);
289 32205389 gaqhf
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Clear Inconsistent Property Value - " + count);
290 63fbf592 gaqhf
                foreach (LMRelationship relationship in relationships)
291 b01e7456 gaqhf
                {
292 63fbf592 gaqhf
                    foreach (LMInconsistency inconsistency in relationship.Inconsistencies)
293 b01e7456 gaqhf
                    {
294 63fbf592 gaqhf
                        if (inconsistency.get_InconsistencyTypeIndex() == 1)
295
                        {
296
                            LMModelItem modelItem1 = relationship.Item1RepresentationObject == null ? null : relationship.Item1RepresentationObject.ModelItemObject;
297
                            LMModelItem modelItem2 = relationship.Item2RepresentationObject == null ? null : relationship.Item2RepresentationObject.ModelItemObject;
298
                            string[] array = inconsistency.get_Name().ToString().Split(new char[] { '=' });
299
                            if (modelItem1 != null)
300
                            {
301
                                string attrName = array[0];
302
                                if (attrName.Contains("PipingPoint"))
303
                                {
304
                                    string originalAttr = attrName.Split(new char[] { '.' })[1];
305 d23fe61b gaqhf
                                    int index = Convert.ToInt32(relationship.get_Item1Location());
306
                                    LMAAttribute attribute1 = modelItem1.Attributes["PipingPoint" + index + "." + originalAttr];
307
                                    if (attribute1 != null && !DBNull.Value.Equals(attribute1.get_Value()))
308 63fbf592 gaqhf
                                    {
309 d23fe61b gaqhf
                                        loop = true;
310
                                        attribute1.set_Value(DBNull.Value);
311 63fbf592 gaqhf
                                    }
312
                                }
313
                                else
314
                                {
315
                                    LMAAttribute attribute1 = modelItem1.Attributes[attrName];
316
                                    if (attribute1 != null && !DBNull.Value.Equals(attribute1.get_Value()))
317
                                    {
318
                                        loop = true;
319
                                        attribute1.set_Value(DBNull.Value);
320
                                    }
321
                                }
322
                                modelItem1.Commit();
323
                            }
324
                            if (modelItem2 != null)
325
                            {
326
                                string attrName = array[1];
327
                                if (attrName.Contains("PipingPoint"))
328
                                {
329
                                    string originalAttr = attrName.Split(new char[] { '.' })[1];
330 d23fe61b gaqhf
                                    int index = Convert.ToInt32(relationship.get_Item2Location());
331
                                    LMAAttribute attribute2 = modelItem2.Attributes["PipingPoint" + index + "." + originalAttr];
332
                                    if (attribute2 != null && !DBNull.Value.Equals(attribute2.get_Value()))
333 63fbf592 gaqhf
                                    {
334 d23fe61b gaqhf
                                        attribute2.set_Value(DBNull.Value);
335
                                        loop = true;
336 63fbf592 gaqhf
                                    }
337
                                }
338
                                else
339
                                {
340
                                    LMAAttribute attribute2 = modelItem2.Attributes[attrName];
341
                                    if (attribute2 != null && !DBNull.Value.Equals(attribute2.get_Value()))
342
                                    {
343
                                        attribute2.set_Value(DBNull.Value);
344
                                        loop = true;
345
                                    }
346
                                }
347
                                modelItem2.Commit();
348
                            }
349
                            if (modelItem1 != null)
350
                                ReleaseCOMObjects(modelItem1);
351
                            if (modelItem2 != null)
352
                                ReleaseCOMObjects(modelItem2);
353
                            inconsistency.Commit();
354
                        }
355 b01e7456 gaqhf
                    }
356 63fbf592 gaqhf
                    relationship.Commit();
357 d23fe61b gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
358 b01e7456 gaqhf
                }
359 63fbf592 gaqhf
                ReleaseCOMObjects(filter);
360
                ReleaseCOMObjects(criterion);
361
                ReleaseCOMObjects(relationships);
362 32205389 gaqhf
                count++;
363 b01e7456 gaqhf
            }
364
        }
365
        private void RunEndBreakModeling()
366
        {
367
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.EndBreaks.Count);
368
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling");
369
            foreach (var item in document.EndBreaks)
370
                try
371
                {
372
                    EndBreakModeling(item);
373
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
374
                }
375
                catch (Exception ex)
376
                {
377
                    Log.Write("Error in EndBreakModeling");
378
                    Log.Write("UID : " + item.UID);
379
                    Log.Write(ex.Message);
380
                    Log.Write(ex.StackTrace);
381
                }
382
        }
383
        private void RunSpecBreakModeling()
384
        {
385
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SpecBreaks.Count);
386
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "SpecBreaks Modeling");
387
            foreach (var item in document.SpecBreaks)
388
                try
389
                {
390
                    SpecBreakModeling(item);
391
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
392
                }
393
                catch (Exception ex)
394
                {
395
                    Log.Write("Error in SpecBreakModeling");
396
                    Log.Write("UID : " + item.UID);
397 9bcb092b gaqhf
                    Log.Write(ex.Message);
398
                    Log.Write(ex.StackTrace);
399
                }
400
        }
401 dfac4553 gaqhf
        private void RunJoinRunForSameConnector()
402
        {
403 d23fe61b gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count);
404 ca6e0f51 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "PipeRun Join - 1");
405 dfac4553 gaqhf
            foreach (var line in document.LINES)
406
            {
407
                if (!SPPIDUtil.IsSegmentLine(document, line))
408
                {
409
                    foreach (var connector in line.CONNECTORS)
410
                    {
411
                        if (connector.ConnectedObject != null &&
412
                            connector.ConnectedObject.GetType() == typeof(Line) &&
413 ca6e0f51 gaqhf
                            !SPPIDUtil.IsBranchLine(line, connector.ConnectedObject as Line))
414 dfac4553 gaqhf
                        {
415
                            Line connLine = connector.ConnectedObject as Line;
416 7e4a64a3 gaqhf
                            if (line.SPPID.ModelItemId != connLine.SPPID.ModelItemId && !string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(connLine.SPPID.ModelItemId))
417 a31a512e gaqhf
                            {
418
                                string survivorId = string.Empty;
419
                                JoinRun(connLine.SPPID.ModelItemId, line.SPPID.ModelItemId, ref survivorId);
420
                            }
421
                                
422 dfac4553 gaqhf
                        }
423
                    }
424
                }
425 d23fe61b gaqhf
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
426
            }
427
        }
428 ca6e0f51 gaqhf
        private void RunJoinRun()
429
        {
430
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count);
431
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "PipeRun Join - 2");
432 a31a512e gaqhf
            List<string> endModelID = new List<string>();
433 ca6e0f51 gaqhf
            foreach (var line in document.LINES)
434
            {
435 a31a512e gaqhf
                if (!endModelID.Contains(line.SPPID.ModelItemId))
436
                {
437
                    while (!endModelID.Contains(line.SPPID.ModelItemId))
438
                    {
439
                        string survivorId = string.Empty;
440
                        JoinRunBySameType(line.SPPID.ModelItemId, ref survivorId);
441
                        if (string.IsNullOrEmpty(survivorId))
442
                        {
443
                            endModelID.Add(line.SPPID.ModelItemId);
444
                        }
445
                    }
446
                }
447 ca6e0f51 gaqhf
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
448
            }
449
        }
450 8701de36 gaqhf
        private void RunLineNumberModeling()
451
        {
452
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINENUMBERS.Count);
453
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Number Modeling");
454
            foreach (var item in document.LINENUMBERS)
455
            {
456
                LMLabelPersist label = dataSource.GetLabelPersist(item.SPPID.RepresentationId);
457
                if (label == null || (label != null && label.get_ItemStatus() != "Active"))
458
                {
459
                    ReleaseCOMObjects(label);
460
                    item.SPPID.RepresentationId = null;
461
                    LineNumberModeling(item);
462
                }
463
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
464
            }
465
        }
466 d23fe61b gaqhf
        private void RunFlowDirection()
467
        {
468 644f40b3 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, 
469
                document.LINES.Count + ZeroLengthModelItemID.Count + ZeroLengthModelItemIDReverse.Count + ZeroLengthSymbolToSymbolModelItemID.Count);
470 d23fe61b gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Check Flow Direction");
471
            foreach (var line in document.LINES)
472
            {
473 1ff0105e gaqhf
                if (!string.IsNullOrEmpty(line.SPPID.ModelItemId))
474
                {
475
                    LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
476 644f40b3 gaqhf
                    if (modelItem != null && modelItem.get_ItemStatus() == "Active")
477 1ff0105e gaqhf
                    {
478
                        LMAAttribute attribute = modelItem.Attributes["FlowDirection"];
479
                        if (attribute != null)
480
                        {
481
                            attribute.set_Value("End 1 is upstream (Inlet)");
482
                            modelItem.Commit();
483
                        }
484 d23fe61b gaqhf
485 1ff0105e gaqhf
                        SetFlowDirectionByLine(line.SPPID.ModelItemId);
486
487
                        ReleaseCOMObjects(modelItem);
488
                    }
489
                }
490 d23fe61b gaqhf
491
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
492 dfac4553 gaqhf
            }
493 1ff0105e gaqhf
            foreach (var modelId in ZeroLengthModelItemID)
494
            {
495
                LMModelItem zeroLengthModelItem = dataSource.GetModelItem(modelId);
496
                LMAAttribute attribute = zeroLengthModelItem.Attributes["FlowDirection"];
497 644f40b3 gaqhf
                if (attribute != null && zeroLengthModelItem.get_ItemStatus() == "Active")
498 1ff0105e gaqhf
                {
499
                    attribute.set_Value("End 1 is upstream (Inlet)");
500
                    zeroLengthModelItem.Commit();
501
                }
502
503
                SetFlowDirectionByLine(modelId);
504
505
                ReleaseCOMObjects(zeroLengthModelItem);
506
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
507
            }
508
            foreach (var modelId in ZeroLengthModelItemIDReverse)
509
            {
510
                LMModelItem zeroLengthModelItem = dataSource.GetModelItem(modelId);
511
                LMAAttribute attribute = zeroLengthModelItem.Attributes["FlowDirection"];
512 644f40b3 gaqhf
                if (attribute != null && zeroLengthModelItem.get_ItemStatus() == "Active")
513 1ff0105e gaqhf
                {
514
                    attribute.set_Value("End 1 is downstream (Outlet)");
515
                    zeroLengthModelItem.Commit();
516
                }
517
518
                SetFlowDirectionByLine(modelId);
519
520
                ReleaseCOMObjects(zeroLengthModelItem);
521
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
522
            }
523 644f40b3 gaqhf
            foreach (var modelId in ZeroLengthSymbolToSymbolModelItemID)
524
            {
525
                SetFlowDirectionByLine(modelId);
526
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
527
            }
528 1ff0105e gaqhf
529 32205389 gaqhf
            void SetFlowDirectionByLine(string lineModelItemID)
530 1ff0105e gaqhf
            {
531 32205389 gaqhf
                LMModelItem modelItem = dataSource.GetModelItem(lineModelItemID);
532
                if (modelItem != null && modelItem.get_ItemStatus() == "Active")
533 1ff0105e gaqhf
                {
534 32205389 gaqhf
                    LMAAttribute attribute = modelItem.Attributes["FlowDirection"];
535
                    if (attribute != null && !DBNull.Value.Equals(attribute.get_Value()))
536 1ff0105e gaqhf
                    {
537 32205389 gaqhf
                        string sFlowDirection = attribute.get_Value().ToString();
538
                        foreach (LMRepresentation rep in modelItem.Representations)
539 1ff0105e gaqhf
                        {
540 32205389 gaqhf
                            if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
541
                            {
542
                                LMConnector connector = dataSource.GetConnector(rep.Id);
543 1ff0105e gaqhf
544 32205389 gaqhf
                                foreach (LMRelationship relationship in connector.Relation1Relationships)
545
                                    SetSymbolFlowDirectionByRelationShip(relationship, connector, sFlowDirection);
546
                                foreach (LMRelationship relationship in connector.Relation2Relationships)
547
                                    SetSymbolFlowDirectionByRelationShip(relationship, connector, sFlowDirection);
548 1ff0105e gaqhf
549 32205389 gaqhf
                                ReleaseCOMObjects(connector);
550
                            }
551 1ff0105e gaqhf
                        }
552
                    }
553 32205389 gaqhf
                    ReleaseCOMObjects(modelItem);
554 1ff0105e gaqhf
                }
555
556 32205389 gaqhf
                void SetSymbolFlowDirectionByRelationShip(LMRelationship relationship, LMConnector connector, string sFlowDirection)
557 1ff0105e gaqhf
                {
558 32205389 gaqhf
                    // Item2가 Symbol
559
                    if (!DBNull.Value.Equals(relationship.Item1RepresentationID) && relationship.Item1RepresentationID == connector.Id &&
560
                        relationship.Item2RepresentationObject != null && relationship.Item2RepresentationObject.get_RepresentationType() == "Symbol")
561
                    {
562
                        int symbolIndex = Convert.ToInt32(relationship.get_Item2Location());
563
                        int lineIndex = Convert.ToInt32(relationship.get_Item1Location());
564
                        LMModelItem symbolModelItem = relationship.Item2RepresentationObject.ModelItemObject;
565 1ff0105e gaqhf
566 32205389 gaqhf
                        SetSymbolFlowDirection(lineIndex, symbolIndex, sFlowDirection, symbolModelItem);
567 1ff0105e gaqhf
568 32205389 gaqhf
                        symbolModelItem.Commit();
569
                        ReleaseCOMObjects(symbolModelItem);
570
                    }
571
                    // Item1이 Symbol
572
                    else if (!DBNull.Value.Equals(relationship.Item2RepresentationID) && relationship.Item2RepresentationID == connector.Id &&
573
                            relationship.Item1RepresentationObject != null && relationship.Item1RepresentationObject.get_RepresentationType() == "Symbol")
574
                    {
575
                        int symbolIndex = Convert.ToInt32(relationship.get_Item1Location());
576
                        int lineIndex = Convert.ToInt32(relationship.get_Item2Location());
577
                        LMModelItem symbolModelItem = relationship.Item1RepresentationObject.ModelItemObject;
578 1ff0105e gaqhf
579 32205389 gaqhf
                        SetSymbolFlowDirection(lineIndex, symbolIndex, sFlowDirection, symbolModelItem);
580 1ff0105e gaqhf
581 32205389 gaqhf
                        symbolModelItem.Commit();
582
                        ReleaseCOMObjects(symbolModelItem);
583
                    }
584 1ff0105e gaqhf
                }
585
586 32205389 gaqhf
                void SetSymbolFlowDirection(int lineIndex, int symbolIndex, string sFlowDirection, LMModelItem symbolModelItem)
587 1ff0105e gaqhf
                {
588 32205389 gaqhf
                    string attrName = "PipingPoint" + symbolIndex + ".FlowDirection";
589
                    LMAAttribute attribute = symbolModelItem.Attributes[attrName];
590
                    if (attribute != null)
591
                    {
592
                        if (lineIndex == 0 && sFlowDirection == "End 1 is upstream (Inlet)")
593
                            attribute.set_Value("End 1 is downstream (Outlet)");
594
                        else if (lineIndex == 0 && sFlowDirection == "End 1 is downstream (Outlet)")
595
                            attribute.set_Value("End 1 is upstream (Inlet)");
596
                        else if (lineIndex == 1 && sFlowDirection == "End 1 is upstream (Inlet)")
597
                            attribute.set_Value("End 1 is upstream (Inlet)");
598
                        else if (lineIndex == 1 && sFlowDirection == "End 1 is downstream (Outlet)")
599
                            attribute.set_Value("End 1 is downstream (Outlet)");
600
                    }
601 1ff0105e gaqhf
                }
602
            }
603 dfac4553 gaqhf
        }
604 32205389 gaqhf
        private void RunNoteModeling()
605
        {
606
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
607
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling");
608
            foreach (var item in document.NOTES)
609
                try
610
                {
611
                    NoteModeling(item);
612
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
613
                }
614
                catch (Exception ex)
615
                {
616
                    Log.Write("Error in NoteModeling");
617
                    Log.Write("UID : " + item.UID);
618
                    Log.Write(ex.Message);
619
                    Log.Write(ex.StackTrace);
620
                }
621
        }
622
        private void RunTextModeling()
623 9bcb092b gaqhf
        {
624 32205389 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.TEXTINFOS.Count);
625
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling");
626
            foreach (var item in document.TEXTINFOS)
627
                try
628
                {
629
                    TextModeling(item);
630
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
631
                }
632
                catch (Exception ex)
633
                {
634
                    Log.Write("Error in TextModeling");
635
                    Log.Write("UID : " + item.UID);
636
                    Log.Write(ex.Message);
637
                    Log.Write(ex.StackTrace);
638
                }
639
        }
640
        private void RunInputLineNumberAttribute()
641
        {
642
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINENUMBERS.Count);
643
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set LineNumbers Attribute");
644 82d6e5ea gaqhf
            List<string> endLine = new List<string>();
645 9bcb092b gaqhf
            foreach (var item in document.LINENUMBERS)
646
                try
647
                {
648 82d6e5ea gaqhf
                    InputLineNumberAttribute(item, endLine);
649 32205389 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
650 9bcb092b gaqhf
                }
651
                catch (Exception ex)
652
                {
653 32205389 gaqhf
                    Log.Write("Error in InputLineNumberAttribute");
654
                    Log.Write("UID : " + item.UID);
655
                    Log.Write(ex.Message);
656
                    Log.Write(ex.StackTrace);
657
                }
658
        }
659
        private void RunInputSymbolAttribute()
660
        {
661
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
662
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
663
            foreach (var item in document.SYMBOLS)
664
                try
665
                {
666
                    InputSymbolAttribute(item, item.ATTRIBUTES);
667
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
668
                }
669
                catch (Exception ex)
670
                {
671
                    Log.Write("Error in InputSymbolAttribute");
672
                    Log.Write("UID : " + item.UID);
673
                    Log.Write(ex.Message);
674
                    Log.Write(ex.StackTrace);
675
                }
676
        }
677
        private void RunInputSpecBreakAttribute()
678
        {
679
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
680
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
681
            foreach (var item in document.SpecBreaks)
682
                try
683
                {
684
                    InputSpecBreakAttribute(item);
685
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
686
                }
687
                catch (Exception ex)
688
                {
689
                    Log.Write("Error in InputSpecBreakAttribute");
690
                    Log.Write("UID : " + item.UID);
691
                    Log.Write(ex.Message);
692
                    Log.Write(ex.StackTrace);
693
                }
694
        }
695
        private void RunLabelSymbolModeling()
696
        {
697
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
698
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Labels Modeling");
699
            foreach (var item in document.SYMBOLS)
700
                try
701
                {
702
                    LabelSymbolModeling(item);
703
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
704
                }
705
                catch (Exception ex)
706
                {
707
                    Log.Write("Error in LabelSymbolModeling");
708 9bcb092b gaqhf
                    Log.Write("UID : " + item.UID);
709 b01e7456 gaqhf
                    Log.Write(ex.Message);
710
                    Log.Write(ex.StackTrace);
711
                }
712
        }
713 30ba9ae0 gaqhf
        
714 74752074 gaqhf
        /// <summary>
715
        /// 도면 생성 메서드
716
        /// </summary>
717 224535bb gaqhf
        private void CreateDocument(ref string drawingNumber, ref string drawingName)
718 0e0edfad gaqhf
        {
719 3734dcc5 gaqhf
            Log.Write("------------------ Start create document ------------------");
720 6d12a734 gaqhf
            GetDrawingNameAndNumber(ref drawingName, ref drawingNumber);
721 3734dcc5 gaqhf
            Log.Write("Drawing name : " + drawingName);
722
            Log.Write("Drawing number : " + drawingNumber);
723 b66a2996 gaqhf
            newDrawing = application.Drawings.Add(document.Unit, document.Template, drawingNumber, drawingName);
724 88bac50c gaqhf
            document.SPPID_DrawingNumber = drawingNumber;
725
            document.SPPID_DrawingName = drawingName;
726 d4c3e39f gaqhf
            Thread.Sleep(1000);
727 0e0edfad gaqhf
            application.ActiveWindow.Fit();
728
            Thread.Sleep(1000);
729
            application.ActiveWindow.Zoom = 2000;
730
            Thread.Sleep(2000);
731 7aee331b gaqhf
732
            //current LMDrawing 가져오기
733
            LMAFilter filter = new LMAFilter();
734
            LMACriterion criterion = new LMACriterion();
735
            filter.ItemType = "Drawing";
736
            criterion.SourceAttributeName = "Name";
737
            criterion.Operator = "=";
738
            criterion.set_ValueAttribute(drawingName);
739
            filter.get_Criteria().Add(criterion);
740
741
            LMDrawings drawings = new LMDrawings();
742
            drawings.Collect(dataSource, Filter: filter);
743
744
            currentDrawing = ((dynamic)drawings).Nth(1);
745 b66a2996 gaqhf
        }
746
747 02480ac1 gaqhf
        /// <summary>
748
        /// DrawingName, DrawingNumber를 확인하여 중복이 있으면 _1을 붙이고 +1씩 한다.
749
        /// </summary>
750
        /// <param name="drawingName"></param>
751
        /// <param name="drawingNumber"></param>
752 b66a2996 gaqhf
        private void GetDrawingNameAndNumber(ref string drawingName, ref string drawingNumber)
753
        {
754
            LMDrawings drawings = new LMDrawings();
755
            drawings.Collect(dataSource);
756 7f00b26c gaqhf
757 b66a2996 gaqhf
            List<string> drawingNameList = new List<string>();
758
            List<string> drawingNumberList = new List<string>();
759
760
            foreach (LMDrawing item in drawings)
761
            {
762
                drawingNameList.Add(item.Attributes["Name"].get_Value().ToString());
763
                drawingNumberList.Add(item.Attributes["DrawingNumber"].get_Value().ToString());
764
            }
765
766
            int nameLength = drawingName.Length;
767
            while (drawingNameList.Contains(drawingName))
768
            {
769
                if (nameLength == drawingName.Length)
770
                    drawingName += "-1";
771
                else
772
                {
773
                    int index = Convert.ToInt32(drawingName.Remove(0, nameLength + 1));
774
                    drawingName = drawingName.Substring(0, nameLength + 1);
775
                    drawingName += ++index;
776
                }
777
            }
778
779
            int numberLength = drawingNumber.Length;
780
            while (drawingNameList.Contains(drawingNumber))
781
            {
782
                if (numberLength == drawingNumber.Length)
783
                    drawingNumber += "-1";
784
                else
785
                {
786
                    int index = Convert.ToInt32(drawingNumber.Remove(0, numberLength + 1));
787
                    drawingNumber = drawingNumber.Substring(0, numberLength + 1);
788
                    drawingNumber += ++index;
789
                }
790
            }
791
792
            ReleaseCOMObjects(drawings);
793 0e0edfad gaqhf
        }
794
795 74752074 gaqhf
        /// <summary>
796
        /// 도면 크기 구하는 메서드
797
        /// </summary>
798
        /// <returns></returns>
799 0e0edfad gaqhf
        private bool DocumentCoordinateCorrection()
800
        {
801 6a7573b0 gaqhf
            if (Settings.Default.DrawingX != 0 && Settings.Default.DrawingY != 0)
802 0e0edfad gaqhf
            {
803 3734dcc5 gaqhf
                Log.Write("Setting Drawing X, Drawing Y");
804 6a7573b0 gaqhf
                document.SetSPPIDLocation(Settings.Default.DrawingX, Settings.Default.DrawingY);
805 3734dcc5 gaqhf
                Log.Write("Start coordinate correction");
806 c01ce90b gaqhf
                document.CoordinateCorrection();
807 0e0edfad gaqhf
                return true;
808
            }
809
            else
810 3734dcc5 gaqhf
            {
811
                Log.Write("Need Drawing X, Y");
812 0e0edfad gaqhf
                return false;
813 3734dcc5 gaqhf
            }
814 0e0edfad gaqhf
        }
815
816 74752074 gaqhf
        /// <summary>
817
        /// 심볼을 실제로 Modeling 메서드
818
        /// </summary>
819
        /// <param name="symbol"></param>
820
        /// <param name="targetSymbol"></param>
821
        /// <param name="prevSymbol"></param>
822 b2d1c1aa gaqhf
        private void SymbolModeling(Symbol symbol, Symbol targetSymbol)
823 809a7640 gaqhf
        {
824 7f00b26c gaqhf
            // OWNERSYMBOL Attribute, 값을 가지고 있을 경우
825
            BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(attr => attr.ATTRIBUTE == "OWNERSYMBOL");
826
            if (itemAttribute != null && (string.IsNullOrEmpty(itemAttribute.VALUE) || itemAttribute.VALUE != "None"))
827
                return;
828
            // 이미 모델링 됐을 경우
829
            else if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
830
                return;
831 6a7573b0 gaqhf
832 7f00b26c gaqhf
            LMSymbol _LMSymbol = null;
833 809a7640 gaqhf
834 7f00b26c gaqhf
            string mappingPath = symbol.SPPID.MAPPINGNAME;
835
            double x = symbol.SPPID.ORIGINAL_X;
836
            double y = symbol.SPPID.ORIGINAL_Y;
837
            int mirror = 0;
838
            double angle = symbol.ANGLE;
839 2fdb56bf gaqhf
840 7f00b26c gaqhf
            // OPC 일경우 180도 일때 Mirror
841
            if (mappingPath.Contains("Piping OPC's") && angle == Math.PI)
842
                mirror = 1;
843 1ab9a205 gaqhf
844 7f00b26c gaqhf
            // Mirror 계산
845
            if (symbol.FLIP == 1)
846
            {
847
                mirror = 1;
848
                angle += Math.PI;
849
            }
850 1ab9a205 gaqhf
851 7f00b26c gaqhf
            if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId))
852
            {
853
                LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
854
                Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, symbol.UID, targetSymbol);
855
                if (connector != null)
856
                    GetTargetSymbolConnectorPoint(connector, targetSymbol, ref x, ref y);
857 809a7640 gaqhf
858 7f00b26c gaqhf
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem);
859 809a7640 gaqhf
860 7f00b26c gaqhf
                if (_LMSymbol != null && _TargetItem != null)
861 6a7573b0 gaqhf
                {
862
                    symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
863 ac78b508 gaqhf
864 32205389 gaqhf
                    if (SPPIDUtil.IsSegmentLine(document, symbol, targetSymbol))
865
                    {
866
                        LMConnector reModelingConnector = FindBreakLineTarget(symbol, targetSymbol);
867
                        if (reModelingConnector != null)
868
                            ReModelingLMConnector(reModelingConnector);
869
                    }
870 6a7573b0 gaqhf
                }
871 809a7640 gaqhf
872 7f00b26c gaqhf
                ReleaseCOMObjects(_TargetItem);
873 4d2571ab gaqhf
            }
874 7f00b26c gaqhf
            else
875
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
876
877
            if (_LMSymbol != null)
878 4d2571ab gaqhf
            {
879 7f00b26c gaqhf
                _LMSymbol.Commit();
880
                symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
881
                symbol.SPPID.ModelItemID = _LMSymbol.ModelItemID;
882 32205389 gaqhf
                symbol.SPPID.GraphicOID = _LMSymbol.get_GraphicOID().ToString();
883 7f00b26c gaqhf
884
                foreach (var item in symbol.ChildSymbols)
885 7e4a64a3 gaqhf
                    CreateChildSymbol(item, _LMSymbol, symbol);
886 3734dcc5 gaqhf
887 d9794a6c gaqhf
                symbol.SPPID.SPPID_X = _LMSymbol.get_XCoordinate();
888
                symbol.SPPID.SPPID_Y = _LMSymbol.get_YCoordinate();
889
890
                double[] range = null;
891
                GetSPPIDSymbolRange(symbol, ref range);
892
                symbol.SPPID.SPPID_Min_X = range[0];
893
                symbol.SPPID.SPPID_Min_Y = range[1];
894
                symbol.SPPID.SPPID_Max_X = range[2];
895
                symbol.SPPID.SPPID_Max_Y = range[3];
896
897
                foreach (var item in symbol.SPPID.CorrectionX_GroupSymbols)
898
                    item.SPPID.ORIGINAL_X = symbol.SPPID.SPPID_X;
899
                foreach (var item in symbol.SPPID.CorrectionY_GroupSymbols)
900
                    item.SPPID.ORIGINAL_Y = symbol.SPPID.SPPID_Y;
901
902 3734dcc5 gaqhf
                ReleaseCOMObjects(_LMSymbol);
903 4d2571ab gaqhf
            }
904 809a7640 gaqhf
        }
905
906 d9794a6c gaqhf
        private void RemoveSymbol(Symbol symbol)
907
        {
908
            if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
909
            {
910
                LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
911
                if (_LMSymbol != null)
912
                {
913
                    _placement.PIDRemovePlacement(_LMSymbol.AsLMRepresentation());
914
                    ReleaseCOMObjects(_LMSymbol);
915
                }
916
            }
917
918
            symbol.SPPID.RepresentationId = string.Empty;
919
            symbol.SPPID.ModelItemID = string.Empty;
920
            symbol.SPPID.SPPID_X = double.NaN;
921
            symbol.SPPID.SPPID_Y = double.NaN;
922
            symbol.SPPID.SPPID_Min_X = double.NaN;
923
            symbol.SPPID.SPPID_Min_Y = double.NaN;
924
            symbol.SPPID.SPPID_Max_X = double.NaN;
925
            symbol.SPPID.SPPID_Max_Y = double.NaN;
926
        }
927
928
        private void RemoveSymbol(List<Symbol> symbols)
929
        {
930
            foreach (var symbol in symbols)
931
            {
932
                if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
933
                {
934
                    LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
935
                    if (_LMSymbol != null)
936
                    {
937
                        _placement.PIDRemovePlacement(_LMSymbol.AsLMRepresentation());
938
                        ReleaseCOMObjects(_LMSymbol);
939
                    }
940
                }
941
942
                symbol.SPPID.RepresentationId = string.Empty;
943
                symbol.SPPID.ModelItemID = string.Empty;
944
                symbol.SPPID.SPPID_X = double.NaN;
945
                symbol.SPPID.SPPID_Y = double.NaN;
946
                symbol.SPPID.SPPID_Min_X = double.NaN;
947
                symbol.SPPID.SPPID_Min_Y = double.NaN;
948
                symbol.SPPID.SPPID_Max_X = double.NaN;
949
                symbol.SPPID.SPPID_Max_Y = double.NaN;
950
            }
951
        }
952
953 d1eac84d gaqhf
        /// <summary>
954
        /// ID2의 Symbol Width와 Height를 비교해서 상대적인 SPPID Connector좌표를 가져온다.
955
        /// </summary>
956
        /// <param name="targetConnector"></param>
957
        /// <param name="targetSymbol"></param>
958
        /// <param name="x"></param>
959
        /// <param name="y"></param>
960
        private void GetTargetSymbolConnectorPoint(Connector targetConnector, Symbol targetSymbol, ref double x, ref double y)
961
        {
962
            LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
963 2fdb56bf gaqhf
964
            double[] range = null;
965 d1eac84d gaqhf
            List<double[]> points = new List<double[]>();
966 2fdb56bf gaqhf
            GetSPPIDSymbolRangeAndConnectionPoints(targetSymbol, ref range, points);
967
            double x1 = range[0];
968
            double y1 = range[1];
969
            double x2 = range[2];
970
            double y2 = range[3];
971 d1eac84d gaqhf
972
            // Origin 기준 Connector의 위치차이
973
            double sceneX = 0;
974
            double sceneY = 0;
975
            SPPIDUtil.ConvertPointBystring(targetConnector.SCENECONNECTPOINT, ref sceneX, ref sceneY);
976
            double originX = 0;
977
            double originY = 0;
978
            SPPIDUtil.ConvertPointBystring(targetSymbol.ORIGINALPOINT, ref originX, ref originY);
979
            double gapX = originX - sceneX;
980
            double gapY = originY - sceneY;
981
982
            // SPPID Symbol과 ID2 심볼의 크기 차이
983 026f394f gaqhf
            double sizeWidth = 0;
984
            double sizeHeight = 0;
985
            SPPIDUtil.ConvertPointBystring(targetSymbol.SIZE, ref sizeWidth, ref sizeHeight);
986
            if (sizeWidth == 0 || sizeHeight == 0)
987
                throw new Exception("Check symbol size! \r\nUID : " + targetSymbol.UID);
988
989 d1eac84d gaqhf
            double percentX = (x2 - x1) / sizeWidth;
990
            double percentY = (y2 - y1) / sizeHeight;
991
992
            double SPPIDgapX = gapX * percentX;
993
            double SPPIDgapY = gapY * percentY;
994
995
            double[] SPPIDOriginPoint = new double[] { _TargetItem.get_XCoordinate() - SPPIDgapX, _TargetItem.get_YCoordinate() + SPPIDgapY };
996
            double distance = double.MaxValue;
997
            double[] resultPoint;
998
            foreach (var point in points)
999
            {
1000
                double result = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], SPPIDOriginPoint[0], SPPIDOriginPoint[1]);
1001
                if (distance > result)
1002
                {
1003
                    distance = result;
1004
                    resultPoint = point;
1005
                    x = point[0];
1006
                    y = point[1];
1007
                }
1008
            }
1009 2fdb56bf gaqhf
1010
            ReleaseCOMObjects(_TargetItem);
1011
        }
1012
1013 a0e3dca4 gaqhf
        private void GetTargetLineConnectorPoint(Connector targetConnector, Line targetLine, ref double x, ref double y)
1014
        {
1015
            int index = targetLine.CONNECTORS.IndexOf(targetConnector);
1016
            if (index == 0)
1017
            {
1018
                x = targetLine.SPPID.START_X;
1019
                y = targetLine.SPPID.START_Y;
1020
            }
1021
            else
1022
            {
1023
                x = targetLine.SPPID.END_X;
1024
                y = targetLine.SPPID.END_Y;
1025
            }
1026
        }
1027
1028 2fdb56bf gaqhf
        /// <summary>
1029
        /// SPPID Symbol의 Range를 구한다.
1030
        /// </summary>
1031
        /// <param name="symbol"></param>
1032
        /// <param name="range"></param>
1033
        private void GetSPPIDSymbolRangeAndConnectionPoints(Symbol symbol, ref double[] range, List<double[]> points)
1034
        {
1035
            LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1036
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1037
            double x1 = 0;
1038
            double y1 = 0;
1039
            double x2 = 0;
1040
            double y2 = 0;
1041
            symbol2d.Range(out x1, out y1, out x2, out y2);
1042
            range = new double[] { x1, y1, x2, y2 };
1043
1044
            for (int i = 1; i < int.MaxValue; i++)
1045
            {
1046
                double connX = 0;
1047
                double connY = 0;
1048
                if (_placement.PIDConnectPointLocation(_TargetItem, i, ref connX, ref connY))
1049
                    points.Add(new double[] { connX, connY });
1050
                else
1051
                    break;
1052
            }
1053
1054
            foreach (var childSymbol in symbol.ChildSymbols)
1055
                GetSPPIDChildSymbolRange(childSymbol, ref range, points);
1056
1057
            ReleaseCOMObjects(_TargetItem);
1058
        }
1059
1060 d9794a6c gaqhf
        private void GetSPPIDSymbolRange(Symbol symbol, ref double[] range)
1061
        {
1062
            LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1063 7e4a64a3 gaqhf
            if (_TargetItem != null)
1064
            {
1065
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1066
                double x1 = 0;
1067
                double y1 = 0;
1068
                double x2 = 0;
1069
                double y2 = 0;
1070
                symbol2d.Range(out x1, out y1, out x2, out y2);
1071
                range = new double[] { x1, y1, x2, y2 };
1072 d9794a6c gaqhf
1073 7e4a64a3 gaqhf
                foreach (var childSymbol in symbol.ChildSymbols)
1074
                    GetSPPIDChildSymbolRange(childSymbol, ref range);
1075 d9794a6c gaqhf
1076 7e4a64a3 gaqhf
                ReleaseCOMObjects(_TargetItem);
1077
            }
1078 d9794a6c gaqhf
        }
1079
1080
        private void GetSPPIDSymbolRange(List<Symbol> symbols, ref double[] range)
1081
        {
1082
            double[] tempRange = new double[] { double.MaxValue, double.MaxValue, double.MinValue, double.MinValue };
1083
            foreach (var symbol in symbols)
1084
            {
1085
                LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1086
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1087
                double x1 = 0;
1088
                double y1 = 0;
1089
                double x2 = 0;
1090
                double y2 = 0;
1091
                symbol2d.Range(out x1, out y1, out x2, out y2);
1092
1093
                tempRange[0] = Math.Min(tempRange[0], x1);
1094
                tempRange[1] = Math.Min(tempRange[1], y1);
1095
                tempRange[2] = Math.Max(tempRange[2], x2);
1096
                tempRange[3] = Math.Max(tempRange[3], y2);
1097
1098
                foreach (var childSymbol in symbol.ChildSymbols)
1099 f1a7faf9 gaqhf
                    GetSPPIDChildSymbolRange(childSymbol, ref tempRange);
1100 d9794a6c gaqhf
1101
                ReleaseCOMObjects(_TargetItem);
1102
            }
1103
1104
            range = tempRange;
1105
        }
1106
1107 2fdb56bf gaqhf
        /// <summary>
1108
        /// Child Modeling 된 Symbol의 Range를 구한다.
1109
        /// </summary>
1110
        /// <param name="childSymbol"></param>
1111
        /// <param name="range"></param>
1112
        private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range, List<double[]> points)
1113
        {
1114
            LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId);
1115 3783c494 gaqhf
            if (_ChildSymbol != null)
1116 2fdb56bf gaqhf
            {
1117 3783c494 gaqhf
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()];
1118
                double x1 = 0;
1119
                double y1 = 0;
1120
                double x2 = 0;
1121
                double y2 = 0;
1122
                symbol2d.Range(out x1, out y1, out x2, out y2);
1123
                range[0] = Math.Min(range[0], x1);
1124
                range[1] = Math.Min(range[1], y1);
1125
                range[2] = Math.Max(range[2], x2);
1126
                range[3] = Math.Max(range[3], y2);
1127
1128
                for (int i = 1; i < int.MaxValue; i++)
1129
                {
1130
                    double connX = 0;
1131
                    double connY = 0;
1132
                    if (_placement.PIDConnectPointLocation(_ChildSymbol, i, ref connX, ref connY))
1133
                        points.Add(new double[] { connX, connY });
1134
                    else
1135
                        break;
1136
                }
1137 2fdb56bf gaqhf
1138 3783c494 gaqhf
                foreach (var loopChildSymbol in childSymbol.ChildSymbols)
1139
                    GetSPPIDChildSymbolRange(loopChildSymbol, ref range, points);
1140 2fdb56bf gaqhf
1141 3783c494 gaqhf
                ReleaseCOMObjects(_ChildSymbol);
1142
            }
1143 d1eac84d gaqhf
        }
1144
1145 d9794a6c gaqhf
        private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range)
1146
        {
1147
            LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId);
1148 7e4a64a3 gaqhf
            if (_ChildSymbol != null)
1149
            {
1150
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()];
1151
                double x1 = 0;
1152
                double y1 = 0;
1153
                double x2 = 0;
1154
                double y2 = 0;
1155
                symbol2d.Range(out x1, out y1, out x2, out y2);
1156
                range[0] = Math.Min(range[0], x1);
1157
                range[1] = Math.Min(range[1], y1);
1158
                range[2] = Math.Max(range[2], x2);
1159
                range[3] = Math.Max(range[3], y2);
1160 d9794a6c gaqhf
1161 7e4a64a3 gaqhf
                foreach (var loopChildSymbol in childSymbol.ChildSymbols)
1162
                    GetSPPIDChildSymbolRange(loopChildSymbol, ref range);
1163
                ReleaseCOMObjects(_ChildSymbol);
1164
            }
1165 d9794a6c gaqhf
        }
1166
1167 d1eac84d gaqhf
        /// <summary>
1168
        /// Label Symbol Modeling
1169
        /// </summary>
1170
        /// <param name="symbol"></param>
1171 73415441 gaqhf
        private void LabelSymbolModeling(Symbol symbol)
1172
        {
1173 fb386b8c gaqhf
            if (string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
1174 73415441 gaqhf
            {
1175 fb386b8c gaqhf
                BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL");
1176
                if (itemAttribute == null || string.IsNullOrEmpty(itemAttribute.VALUE) || itemAttribute.VALUE == "None")
1177
                    return;
1178
                Array points = new double[] { 0, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y };
1179
1180
                string symbolUID = itemAttribute.VALUE;
1181
                object targetItem = SPPIDUtil.FindObjectByUID(document, symbolUID);
1182
                if (targetItem != null &&
1183
                    (targetItem.GetType() == typeof(Symbol) ||
1184
                    targetItem.GetType() == typeof(Equipment)))
1185 73415441 gaqhf
                {
1186 fb386b8c gaqhf
                    // Object 아이템이 Symbol일 경우 Equipment일 경우 
1187
                    string sRep = null;
1188
                    if (targetItem.GetType() == typeof(Symbol))
1189
                        sRep = ((Symbol)targetItem).SPPID.RepresentationId;
1190
                    else if (targetItem.GetType() == typeof(Equipment))
1191
                        sRep = ((Equipment)targetItem).SPPID.RepresentationId;
1192
                    if (!string.IsNullOrEmpty(sRep))
1193 73415441 gaqhf
                    {
1194 fb386b8c gaqhf
                        // LEADER Line 검사
1195
                        bool leaderLine = false;
1196
                        SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
1197
                        if (symbolMapping != null)
1198
                            leaderLine = symbolMapping.LEADERLINE;
1199
1200
                        // Target Symbol Item 가져오고 Label Modeling
1201
                        LMSymbol _TargetItem = dataSource.GetSymbol(sRep);
1202
                        LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: _TargetItem.AsLMRepresentation(), IsLeaderVisible: leaderLine);
1203
1204
                        //Leader 선 센터로
1205
                        if (_LMLabelPresist != null)
1206 73415441 gaqhf
                        {
1207 fb386b8c gaqhf
                            // Target Item에 Label의 Attribute Input
1208
                            InputSymbolAttribute(targetItem, symbol.ATTRIBUTES);
1209
1210 32205389 gaqhf
                            string OID = _LMLabelPresist.get_GraphicOID().ToString();
1211 fb386b8c gaqhf
                            DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID] as DependencyObject;
1212
                            if (dependency != null)
1213 73415441 gaqhf
                            {
1214 fb386b8c gaqhf
                                bool result = false;
1215
                                foreach (var attributes in dependency.AttributeSets)
1216 73415441 gaqhf
                                {
1217 fb386b8c gaqhf
                                    foreach (var attribute in attributes)
1218 73415441 gaqhf
                                    {
1219 fb386b8c gaqhf
                                        string name = attribute.Name;
1220
                                        string value = attribute.GetValue().ToString();
1221
                                        if (name == "DrawingItemType" && value == "LabelPersist")
1222 73415441 gaqhf
                                        {
1223 fb386b8c gaqhf
                                            foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects)
1224 b2d1c1aa gaqhf
                                            {
1225 fb386b8c gaqhf
                                                if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLineString2d)
1226
                                                {
1227
                                                    Ingr.RAD2D.LineString2d lineString2D = drawingObject as Ingr.RAD2D.LineString2d;
1228
                                                    double prevX = _TargetItem.get_XCoordinate();
1229
                                                    double prevY = _TargetItem.get_YCoordinate();
1230
                                                    lineString2D.InsertVertex(lineString2D.VertexCount, prevX, prevY);
1231
                                                    lineString2D.RemoveVertex(lineString2D.VertexCount);
1232
                                                    result = true;
1233
                                                    break;
1234
                                                }
1235 b2d1c1aa gaqhf
                                            }
1236 73415441 gaqhf
                                        }
1237 fb386b8c gaqhf
1238
                                        if (result)
1239
                                            break;
1240 73415441 gaqhf
                                    }
1241 b2d1c1aa gaqhf
1242
                                    if (result)
1243
                                        break;
1244 73415441 gaqhf
                                }
1245
                            }
1246 fb386b8c gaqhf
1247 30ba9ae0 gaqhf
                            symbol.SPPID.RepresentationId = _LMLabelPresist.AsLMRepresentation().Id;
1248 fb386b8c gaqhf
                            _LMLabelPresist.Commit();
1249
                            ReleaseCOMObjects(_LMLabelPresist);
1250 73415441 gaqhf
                        }
1251
1252 fb386b8c gaqhf
                        ReleaseCOMObjects(_TargetItem);
1253 b2d1c1aa gaqhf
                    }
1254 73415441 gaqhf
                }
1255 fb386b8c gaqhf
                else if (targetItem != null && targetItem.GetType() == typeof(Line))
1256 0860c756 gaqhf
                {
1257 fb386b8c gaqhf
                    Line targetLine = targetItem as Line;
1258
                    Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId);
1259
                    LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y);
1260
                    if (connectedLMConnector != null)
1261 0860c756 gaqhf
                    {
1262 fb386b8c gaqhf
                        // LEADER Line 검사
1263
                        bool leaderLine = false;
1264
                        SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
1265
                        if (symbolMapping != null)
1266
                            leaderLine = symbolMapping.LEADERLINE;
1267
1268
                        LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: leaderLine);
1269
                        if (_LMLabelPresist != null)
1270
                        {
1271 6db0e733 gaqhf
                            symbol.SPPID.RepresentationId = _LMLabelPresist.AsLMRepresentation().Id;
1272 fb386b8c gaqhf
                            _LMLabelPresist.Commit();
1273
                            ReleaseCOMObjects(_LMLabelPresist);
1274
                        }
1275
                        ReleaseCOMObjects(connectedLMConnector);
1276 0860c756 gaqhf
                    }
1277
1278 fb386b8c gaqhf
                    foreach (var item in connectorVertices)
1279
                        if (item.Key != null)
1280
                            ReleaseCOMObjects(item.Key);
1281
                }
1282 0860c756 gaqhf
            }
1283 73415441 gaqhf
        }
1284
1285 74752074 gaqhf
        /// <summary>
1286
        /// Equipment를 실제로 Modeling 메서드
1287
        /// </summary>
1288
        /// <param name="equipment"></param>
1289 b9e9f4c8 gaqhf
        private void EquipmentModeling(Equipment equipment)
1290
        {
1291
            if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId))
1292
                return;
1293
1294
            LMSymbol _LMSymbol = null;
1295
            LMSymbol targetItem = null;
1296
            string mappingPath = equipment.SPPID.MAPPINGNAME;
1297
            double x = equipment.SPPID.ORIGINAL_X;
1298
            double y = equipment.SPPID.ORIGINAL_Y;
1299
            int mirror = 0;
1300
            double angle = equipment.ANGLE;
1301
1302 20972c61 gaqhf
            SPPIDUtil.ConvertGridPoint(ref x, ref y);
1303
1304 b9e9f4c8 gaqhf
            Connector connector = equipment.CONNECTORS.Find(conn => !string.IsNullOrEmpty(conn.CONNECTEDITEM) && conn.CONNECTEDITEM != "None");
1305
            if (connector != null)
1306
            {
1307
                Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment;
1308
                if (connEquipment != null)
1309
                {
1310
                    if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
1311
                        EquipmentModeling(connEquipment);
1312
1313
                    if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
1314
                    {
1315
                        targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId);
1316
                        if (targetItem != null)
1317
                        {
1318
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem);
1319
                        }
1320
                        else
1321
                        {
1322
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1323
                        }
1324
                    }
1325
                    else
1326
                    {
1327
                        _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1328
                    }
1329
                }
1330
                else
1331
                {
1332
                    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1333
                }
1334
            }
1335
            else
1336
            {
1337
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1338
            }
1339
1340
            if (_LMSymbol != null)
1341
            {
1342
                _LMSymbol.Commit();
1343
                equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1344 32205389 gaqhf
                equipment.SPPID.GraphicOID = _LMSymbol.get_GraphicOID().ToString();
1345 b9e9f4c8 gaqhf
                ReleaseCOMObjects(_LMSymbol);
1346
            }
1347
1348
            if (targetItem != null)
1349
            {
1350
                ReleaseCOMObjects(targetItem);
1351
            }
1352 7f00b26c gaqhf
1353 b9e9f4c8 gaqhf
            ReleaseCOMObjects(_LMSymbol);
1354
        }
1355
1356 d9794a6c gaqhf
        /// <summary>
1357
        /// 첫 진입점
1358
        /// </summary>
1359
        /// <param name="symbol"></param>
1360
        private void SymbolModelingBySymbol(Symbol symbol)
1361
        {
1362 f1a7faf9 gaqhf
            SymbolModeling(symbol, null);
1363 d9794a6c gaqhf
            List<object> endObjects = new List<object>();
1364
            endObjects.Add(symbol);
1365 f1a7faf9 gaqhf
1366 d9794a6c gaqhf
            foreach (var connector in symbol.CONNECTORS)
1367 4d2571ab gaqhf
            {
1368 d9794a6c gaqhf
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1369
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1370 d1eac84d gaqhf
                {
1371 d9794a6c gaqhf
                    endObjects.Add(connItem);
1372
                    if (connItem.GetType() == typeof(Symbol))
1373 4d2571ab gaqhf
                    {
1374 d9794a6c gaqhf
                        Symbol connSymbol = connItem as Symbol;
1375
                        if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1376 4d2571ab gaqhf
                        {
1377 d9794a6c gaqhf
                            SymbolModeling(connSymbol, symbol);
1378
                        }
1379 6db30942 gaqhf
                        SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1380 f1a7faf9 gaqhf
                        SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1381 d9794a6c gaqhf
                    }
1382
                    else if (connItem.GetType() == typeof(Line))
1383
                    {
1384
                        Line connLine = connItem as Line;
1385 f1a7faf9 gaqhf
                        SymbolModelingByNeerLineLoop(connLine, endObjects, symbol);
1386 d9794a6c gaqhf
                    }
1387
                }
1388
            }
1389
        }
1390 4d2571ab gaqhf
1391 f1a7faf9 gaqhf
        private void SymbolModelingByNeerSymbolLoop(Symbol symbol, List<object> endObjects)
1392 d9794a6c gaqhf
        {
1393
            foreach (var connector in symbol.CONNECTORS)
1394
            {
1395
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1396
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1397
                {
1398
                    if (!endObjects.Contains(connItem))
1399
                    {
1400
                        endObjects.Add(connItem);
1401
                        if (connItem.GetType() == typeof(Symbol))
1402
                        {
1403
                            Symbol connSymbol = connItem as Symbol;
1404
                            if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1405 4d2571ab gaqhf
                            {
1406 d9794a6c gaqhf
                                SymbolModeling(connSymbol, symbol);
1407 4d2571ab gaqhf
                            }
1408 6db30942 gaqhf
                            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1409 f1a7faf9 gaqhf
                            SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1410 4d2571ab gaqhf
                        }
1411 d9794a6c gaqhf
                        else if (connItem.GetType() == typeof(Line))
1412
                        {
1413
                            Line connLine = connItem as Line;
1414 f1a7faf9 gaqhf
                            SymbolModelingByNeerLineLoop(connLine, endObjects, symbol);
1415 d9794a6c gaqhf
                        }
1416
                    }
1417
                }
1418
            }
1419
        }
1420 4d2571ab gaqhf
1421 f1a7faf9 gaqhf
        private void SymbolModelingByNeerLineLoop(Line line, List<object> endObjects, Symbol prevSymbol)
1422 d9794a6c gaqhf
        {
1423
            foreach (var connector in line.CONNECTORS)
1424
            {
1425
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1426
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1427
                {
1428
                    if (!endObjects.Contains(connItem))
1429
                    {
1430
                        endObjects.Add(connItem);
1431
                        if (connItem.GetType() == typeof(Symbol))
1432
                        {
1433
                            Symbol connSymbol = connItem as Symbol;
1434
                            if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1435
                            {
1436
                                List<Symbol> group = new List<Symbol>();
1437
                                SPPIDUtil.FindConnectedSymbolGroup(document, connSymbol, group);
1438 f1a7faf9 gaqhf
                                Symbol priority = prioritySymbols.Find(x => group.Contains(x));
1439
                                List<Symbol> endModelingGroup = new List<Symbol>();
1440
                                if (priority != null)
1441 d9794a6c gaqhf
                                {
1442 f1a7faf9 gaqhf
                                    SymbolGroupModeling(priority, group);
1443 d9794a6c gaqhf
1444
                                    // Range 겹치는지 확인해야함
1445
                                    double[] prevRange = null;
1446
                                    GetSPPIDSymbolRange(prevSymbol, ref prevRange);
1447
                                    double[] groupRange = null;
1448
                                    GetSPPIDSymbolRange(group, ref groupRange);
1449
1450
                                    double distanceX = 0;
1451
                                    double distanceY = 0;
1452 6d12a734 gaqhf
                                    bool overlapX = false;
1453
                                    bool overlapY = false;
1454
                                    SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y);
1455
                                    SPPIDUtil.CalcOverlap(prevRange, groupRange, ref distanceX, ref distanceY, ref overlapX, ref overlapY);
1456
                                    if ((slopeType == SlopeType.HORIZONTAL && overlapX) ||
1457
                                        (slopeType == SlopeType.VERTICAL && overlapY))
1458 d9794a6c gaqhf
                                    {
1459
                                        RemoveSymbol(group);
1460
                                        foreach (var _temp in group)
1461
                                            SPPIDUtil.CalcNewCoordinateForSymbol(_temp, prevSymbol, distanceX, distanceY);
1462
1463 f1a7faf9 gaqhf
                                        SymbolGroupModeling(priority, group);
1464 d9794a6c gaqhf
                                    }
1465
                                }
1466
                                else
1467
                                {
1468
                                    SymbolModeling(connSymbol, null);
1469
                                    // Range 겹치는지 확인해야함
1470
                                    double[] prevRange = null;
1471
                                    GetSPPIDSymbolRange(prevSymbol, ref prevRange);
1472
                                    double[] connRange = null;
1473
                                    GetSPPIDSymbolRange(connSymbol, ref connRange);
1474
1475
                                    double distanceX = 0;
1476
                                    double distanceY = 0;
1477 6d12a734 gaqhf
                                    bool overlapX = false;
1478
                                    bool overlapY = false;
1479
                                    SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y);
1480
                                    SPPIDUtil.CalcOverlap(prevRange, connRange, ref distanceX, ref distanceY, ref overlapX, ref overlapY);
1481
                                    if ((slopeType == SlopeType.HORIZONTAL && overlapX) ||
1482
                                        (slopeType == SlopeType.VERTICAL && overlapY))
1483 d9794a6c gaqhf
                                    {
1484
                                        RemoveSymbol(connSymbol);
1485
                                        SPPIDUtil.CalcNewCoordinateForSymbol(connSymbol, prevSymbol, distanceX, distanceY);
1486
1487
                                        SymbolModeling(connSymbol, null);
1488
                                    }
1489
                                }
1490
                            }
1491 6db30942 gaqhf
                            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1492 f1a7faf9 gaqhf
                            SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1493 d9794a6c gaqhf
                        }
1494
                        else if (connItem.GetType() == typeof(Line))
1495
                        {
1496
                            Line connLine = connItem as Line;
1497
                            if (!SPPIDUtil.IsBranchLine(connLine, line))
1498 f1a7faf9 gaqhf
                                SymbolModelingByNeerLineLoop(connLine, endObjects, prevSymbol);
1499 d9794a6c gaqhf
                        }
1500 4d2571ab gaqhf
                    }
1501 d1eac84d gaqhf
                }
1502
            }
1503
        }
1504
1505 f1a7faf9 gaqhf
        private void SymbolGroupModeling(Symbol firstSymbol, List<Symbol> group)
1506
        {
1507
            List<Symbol> endModelingGroup = new List<Symbol>();
1508
            SymbolModeling(firstSymbol, null);
1509
            endModelingGroup.Add(firstSymbol);
1510
            while (endModelingGroup.Count != group.Count)
1511
            {
1512
                foreach (var _symbol in group)
1513
                {
1514
                    if (!endModelingGroup.Contains(_symbol))
1515
                    {
1516
                        foreach (var _connector in _symbol.CONNECTORS)
1517
                        {
1518
                            Symbol _connSymbol = SPPIDUtil.FindObjectByUID(document, _connector.CONNECTEDITEM) as Symbol;
1519
                            if (_connSymbol != null && endModelingGroup.Contains(_connSymbol))
1520
                            {
1521
                                SymbolModeling(_symbol, _connSymbol);
1522
                                endModelingGroup.Add(_symbol);
1523
                                break;
1524
                            }
1525
                        }
1526
                    }
1527
                }
1528
            }
1529
        }
1530 d9794a6c gaqhf
1531 d1eac84d gaqhf
        /// <summary>
1532 74752074 gaqhf
        /// 심볼을 실제로 Modeling할때 ChildSymbol이 있다면 Modeling하는 메서드
1533
        /// </summary>
1534
        /// <param name="childSymbol"></param>
1535
        /// <param name="parentSymbol"></param>
1536 7e4a64a3 gaqhf
        private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol, Symbol parent)
1537 ac78b508 gaqhf
        {
1538 4b4dbca9 gaqhf
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()];
1539
            double x1 = 0;
1540
            double x2 = 0;
1541
            double y1 = 0;
1542
            double y2 = 0;
1543
            symbol2d.Range(out x1, out y1, out x2, out y2);
1544
1545
            LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol);
1546
            if (_LMSymbol != null)
1547
            {
1548
                childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1549
                foreach (var item in childSymbol.ChildSymbols)
1550 7e4a64a3 gaqhf
                    CreateChildSymbol(item, _LMSymbol, parent);
1551 4b4dbca9 gaqhf
            }
1552 7f00b26c gaqhf
1553 ac78b508 gaqhf
1554
            ReleaseCOMObjects(_LMSymbol);
1555
        }
1556 dec9ecfd gaqhf
        double index = 0;
1557 32205389 gaqhf
        private void NewLineModeling(Line line, bool isBranchModeling = false)
1558 809a7640 gaqhf
        {
1559 f3e2693f gaqhf
            if (!string.IsNullOrEmpty(line.SPPID.ModelItemId) || (BranchLines.Contains(line) && !isBranchModeling))
1560 a0e3dca4 gaqhf
                return;
1561
1562
            List<Line> group = new List<Line>();
1563
            GetConnectedLineGroup(line, group);
1564
            LineCoordinateCorrection(group);
1565
1566
            foreach (var groupLine in group)
1567 809a7640 gaqhf
            {
1568 e283d483 gaqhf
                if (!isBranchModeling && SPPIDUtil.IsBranchLine(groupLine))
1569 5173ba5d gaqhf
                {
1570 f3e2693f gaqhf
                    BranchLines.Add(groupLine);
1571 5173ba5d gaqhf
                    continue;
1572
                }
1573 f9cc5190 gaqhf
1574 24b5276c gaqhf
                bool diagonal = false;
1575
                if (groupLine.SlopeType != SlopeType.HORIZONTAL && groupLine.SlopeType != SlopeType.VERTICAL)
1576
                    diagonal = true;
1577 5173ba5d gaqhf
                _LMAItem _LMAItem = _placement.PIDCreateItem(groupLine.SPPID.MAPPINGNAME);
1578
                LMSymbol _LMSymbolStart = null;
1579
                LMSymbol _LMSymbolEnd = null;
1580
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1581
                foreach (var connector in groupLine.CONNECTORS)
1582 809a7640 gaqhf
                {
1583 5173ba5d gaqhf
                    double x = 0;
1584
                    double y = 0;
1585
                    GetTargetLineConnectorPoint(connector, groupLine, ref x, ref y);
1586
                    if (connector.ConnectedObject == null)
1587 809a7640 gaqhf
                    {
1588 5173ba5d gaqhf
                        placeRunInputs.AddPoint(x, y);
1589 a0e3dca4 gaqhf
                    }
1590 5173ba5d gaqhf
                    else if (connector.ConnectedObject.GetType() == typeof(Symbol))
1591 a0e3dca4 gaqhf
                    {
1592 5173ba5d gaqhf
                        Symbol targetSymbol = connector.ConnectedObject as Symbol;
1593 f9cc5190 gaqhf
                        GetTargetSymbolConnectorPoint(targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == groupLine), targetSymbol, ref x, ref y);
1594 5173ba5d gaqhf
                        if (groupLine.CONNECTORS.IndexOf(connector) == 0)
1595 a0e3dca4 gaqhf
                        {
1596 5173ba5d gaqhf
                            _LMSymbolStart = GetTargetSymbol(targetSymbol, groupLine);
1597 3783c494 gaqhf
                            if (_LMSymbolStart != null)
1598 24b5276c gaqhf
                                placeRunInputs.AddSymbolTarget(_LMSymbolStart, x, y, diagonal);
1599 3783c494 gaqhf
                            else
1600
                                placeRunInputs.AddPoint(x, y);
1601 5173ba5d gaqhf
                        }
1602
                        else
1603
                        {
1604
                            _LMSymbolEnd = GetTargetSymbol(targetSymbol, groupLine);
1605 3783c494 gaqhf
                            if (_LMSymbolEnd != null)
1606 24b5276c gaqhf
                                placeRunInputs.AddSymbolTarget(_LMSymbolEnd, x, y, diagonal);
1607 3783c494 gaqhf
                            else
1608
                                placeRunInputs.AddPoint(x, y);
1609 a0e3dca4 gaqhf
                        }
1610 5173ba5d gaqhf
                    }
1611
                    else if (connector.ConnectedObject.GetType() == typeof(Line))
1612
                    {
1613
                        Line targetLine = connector.ConnectedObject as Line;
1614
                        if (!string.IsNullOrEmpty(targetLine.SPPID.ModelItemId))
1615 a0e3dca4 gaqhf
                        {
1616 5173ba5d gaqhf
                            LMConnector targetConnector = FindTargetLMConnectorForBranch(line, targetLine, ref x, ref y);
1617 1c944b34 gaqhf
                            if (targetConnector != null)
1618 0ff6e67f gaqhf
                            {
1619
                                placeRunInputs.AddConnectorTarget(targetConnector, x, y, diagonal);
1620
                                ChangeLineSPPIDCoordinateByConnector(groupLine, targetLine, x, y, false);
1621
                            }
1622
                            else
1623
                            {
1624
                                placeRunInputs.AddPoint( x, y);
1625
                                ChangeLineSPPIDCoordinateByConnector(groupLine, targetLine, x, y, false);
1626
                            }
1627 a0e3dca4 gaqhf
                        }
1628 5173ba5d gaqhf
                        else
1629 809a7640 gaqhf
                        {
1630 5173ba5d gaqhf
                            if (groupLine.CONNECTORS.IndexOf(connector) == 0)
1631 a0e3dca4 gaqhf
                            {
1632 dec9ecfd gaqhf
                                index += 0.01;
1633 5173ba5d gaqhf
                                if (groupLine.SlopeType == SlopeType.HORIZONTAL)
1634 dec9ecfd gaqhf
                                    placeRunInputs.AddPoint(x, -0.1 - index);
1635 5173ba5d gaqhf
                                else if (groupLine.SlopeType == SlopeType.VERTICAL)
1636 dec9ecfd gaqhf
                                    placeRunInputs.AddPoint(-0.1 - index, y);
1637 5173ba5d gaqhf
                                else
1638 ca6e0f51 gaqhf
                                {
1639
                                    if (SPPIDUtil.CalcAngle(groupLine.SPPID.START_X, groupLine.SPPID.START_Y, groupLine.SPPID.END_X, groupLine.SPPID.END_Y) < 45)
1640 dec9ecfd gaqhf
                                        placeRunInputs.AddPoint(x, -0.1 - index);
1641 ca6e0f51 gaqhf
                                    else
1642 dec9ecfd gaqhf
                                        placeRunInputs.AddPoint(-0.1 - index, y);
1643 ca6e0f51 gaqhf
                                }
1644 a0e3dca4 gaqhf
                            }
1645 809a7640 gaqhf
1646 5173ba5d gaqhf
                            placeRunInputs.AddPoint(x, y);
1647 809a7640 gaqhf
1648 5173ba5d gaqhf
                            if (groupLine.CONNECTORS.IndexOf(connector) == 1)
1649
                            {
1650 dec9ecfd gaqhf
                                index += 0.01;
1651 5173ba5d gaqhf
                                if (groupLine.SlopeType == SlopeType.HORIZONTAL)
1652 dec9ecfd gaqhf
                                    placeRunInputs.AddPoint(x, -0.1 - index);
1653 5173ba5d gaqhf
                                else if (groupLine.SlopeType == SlopeType.VERTICAL)
1654 dec9ecfd gaqhf
                                    placeRunInputs.AddPoint(-0.1 - index, y);
1655 5173ba5d gaqhf
                                else
1656 ca6e0f51 gaqhf
                                {
1657
                                    if (SPPIDUtil.CalcAngle(groupLine.SPPID.START_X, groupLine.SPPID.START_Y, groupLine.SPPID.END_X, groupLine.SPPID.END_Y) < 45)
1658 dec9ecfd gaqhf
                                        placeRunInputs.AddPoint(x, -0.1 - index);
1659 ca6e0f51 gaqhf
                                    else
1660 dec9ecfd gaqhf
                                        placeRunInputs.AddPoint(-0.1 - index, y);
1661 ca6e0f51 gaqhf
                                }
1662 a0e3dca4 gaqhf
                            }
1663 809a7640 gaqhf
                        }
1664
                    }
1665 5173ba5d gaqhf
                }
1666 809a7640 gaqhf
1667 5173ba5d gaqhf
                LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1668
                if (_lMConnector != null)
1669
                {
1670
                    groupLine.SPPID.ModelItemId = _lMConnector.ModelItemID;
1671
                    bool bRemodelingStart = false;
1672
                    if (_LMSymbolStart != null)
1673
                        NeedReModeling(groupLine, _LMSymbolStart, ref bRemodelingStart);
1674
                    bool bRemodelingEnd = false;
1675
                    if (_LMSymbolEnd != null)
1676
                        NeedReModeling(groupLine, _LMSymbolEnd, ref bRemodelingEnd);
1677
1678
                    if (bRemodelingStart || bRemodelingEnd)
1679
                        ReModelingLine(groupLine, _lMConnector, _LMSymbolStart, _LMSymbolEnd, bRemodelingStart, bRemodelingEnd);
1680 32205389 gaqhf
1681
                    FlowMarkModeling(groupLine);
1682 8701de36 gaqhf
                    LineNumberModelingOnlyOne(groupLine);
1683 32205389 gaqhf
1684 5173ba5d gaqhf
                    ReleaseCOMObjects(_lMConnector);
1685
                }
1686 dec9ecfd gaqhf
                else if (!isBranchModeling)
1687
                {
1688
                    Log.Write("Main Line Modeling : " + groupLine.UID);
1689
                }
1690 809a7640 gaqhf
1691 5173ba5d gaqhf
                List<object> removeLines = groupLine.CONNECTORS.FindAll(x =>
1692
                x.ConnectedObject != null &&
1693
                x.ConnectedObject.GetType() == typeof(Line) &&
1694
                !string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId))
1695
                .Select(x => x.ConnectedObject)
1696
                .ToList();
1697 2fdb56bf gaqhf
1698 5173ba5d gaqhf
                foreach (var item in removeLines)
1699
                    RemoveLineForModeling(item as Line);
1700 5e6ecf05 gaqhf
1701 5173ba5d gaqhf
                if (_LMAItem != null)
1702
                    ReleaseCOMObjects(_LMAItem);
1703
                if (placeRunInputs != null)
1704
                    ReleaseCOMObjects(placeRunInputs);
1705
                if (_LMSymbolStart != null)
1706
                    ReleaseCOMObjects(_LMSymbolStart);
1707
                if (_LMSymbolEnd != null)
1708
                    ReleaseCOMObjects(_LMSymbolEnd);
1709 5e6ecf05 gaqhf
1710 f3e2693f gaqhf
                if (isBranchModeling && BranchLines.Contains(groupLine))
1711
                    BranchLines.Remove(groupLine);
1712 a0e3dca4 gaqhf
            }
1713
        }
1714 5e6ecf05 gaqhf
1715 a0e3dca4 gaqhf
        private void RemoveLineForModeling(Line line)
1716
        {
1717
            LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
1718
            if (modelItem != null)
1719
            {
1720
                foreach (LMRepresentation rep in modelItem.Representations)
1721
                {
1722
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
1723 7f00b26c gaqhf
                    {
1724 a0e3dca4 gaqhf
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
1725 32205389 gaqhf
                        dynamic OID = rep.get_GraphicOID().ToString();
1726 a0e3dca4 gaqhf
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1727
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1728
                        int verticesCount = lineStringGeometry.VertexCount;
1729
                        double[] vertices = null;
1730
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1731
                        for (int i = 0; i < verticesCount; i++)
1732 7f00b26c gaqhf
                        {
1733 a0e3dca4 gaqhf
                            double x = 0;
1734
                            double y = 0;
1735
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1736 6924abc6 gaqhf
                            if (verticesCount == 2 && (x < 0 || y < 0))
1737 a0e3dca4 gaqhf
                                _placement.PIDRemovePlacement(rep);
1738 c2ec33f5 gaqhf
                        }
1739 a0e3dca4 gaqhf
                        ReleaseCOMObjects(_LMConnector);
1740 5e6ecf05 gaqhf
                    }
1741 a0e3dca4 gaqhf
                }
1742 7f00b26c gaqhf
1743 a0e3dca4 gaqhf
                ReleaseCOMObjects(modelItem);
1744
            }
1745
        }
1746
1747
        private void GetConnectedLineGroup(Line line, List<Line> group)
1748
        {
1749
            if (!group.Contains(line))
1750
                group.Add(line);
1751
            foreach (var connector in line.CONNECTORS)
1752
            {
1753
                if (connector.ConnectedObject != null &&
1754
                    connector.ConnectedObject.GetType() == typeof(Line) &&
1755
                    !group.Contains(connector.ConnectedObject) &&
1756
                    string.IsNullOrEmpty(((Line)connector.ConnectedObject).SPPID.ModelItemId))
1757
                {
1758
                    Line connLine = connector.ConnectedObject as Line;
1759
                    if (!SPPIDUtil.IsBranchLine(connLine, line))
1760 24515a3a gaqhf
                    {
1761
                        if (line.CONNECTORS.IndexOf(connector) == 0)
1762
                            group.Insert(0, connLine);
1763
                        else
1764
                            group.Add(connLine);
1765 a0e3dca4 gaqhf
                        GetConnectedLineGroup(connLine, group);
1766 24515a3a gaqhf
                    }
1767 7f00b26c gaqhf
                }
1768
            }
1769 a0e3dca4 gaqhf
        }
1770 7f00b26c gaqhf
1771 a0e3dca4 gaqhf
        private void LineCoordinateCorrection(List<Line> group)
1772
        {
1773
            // 순서대로 전 Item 기준 정렬
1774
            LineCoordinateCorrectionByStart(group);
1775
1776
            // 역으로 심볼이 있을 경우 좌표 보정
1777
            LineCoordinateCorrectionForLastLine(group);
1778
        }
1779
1780
        private void LineCoordinateCorrectionByStart(List<Line> group)
1781
        {
1782
            for (int i = 0; i < group.Count; i++)
1783 7f00b26c gaqhf
            {
1784 a0e3dca4 gaqhf
                Line line = group[i];
1785
                if (i == 0)
1786 7f00b26c gaqhf
                {
1787 a0e3dca4 gaqhf
                    Connector symbolConnector = line.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol));
1788
                    if (symbolConnector != null)
1789
                        LineCoordinateCorrectionByConnItem(line, symbolConnector.ConnectedObject);
1790 7f00b26c gaqhf
                }
1791 a0e3dca4 gaqhf
                else if (i != 0)
1792 7f00b26c gaqhf
                {
1793 a0e3dca4 gaqhf
                    LineCoordinateCorrectionByConnItem(line, group[i - 1]);
1794
                }
1795
            }
1796
        }
1797 b66a2996 gaqhf
1798 a0e3dca4 gaqhf
        private void LineCoordinateCorrectionForLastLine(List<Line> group)
1799
        {
1800
            Line checkLine = group[group.Count - 1];
1801
            Connector lastSymbolConnector = checkLine.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol));
1802
            if (lastSymbolConnector != null)
1803
            {
1804
                LineCoordinateCorrectionByConnItem(checkLine, lastSymbolConnector.ConnectedObject);
1805
                for (int i = group.Count - 2; i >= 0; i--)
1806
                {
1807
                    Line line = group[i + 1];
1808
                    Line prevLine = group[i];
1809 0bbd73b5 gaqhf
1810 a0e3dca4 gaqhf
                    // 같으면 보정
1811
                    if (line.SlopeType == prevLine.SlopeType)
1812
                        LineCoordinateCorrectionByConnItem(prevLine, line);
1813
                    else
1814 c2ec33f5 gaqhf
                    {
1815 a0e3dca4 gaqhf
                        if (line.SlopeType == SlopeType.HORIZONTAL)
1816 d63050d6 gaqhf
                        {
1817 a0e3dca4 gaqhf
                            double prevX = 0;
1818
                            double prevY = 0;
1819
                            GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY);
1820
                            ChangeLineSPPIDCoordinateByConnectorOnlyX(line, prevLine, prevX);
1821 d63050d6 gaqhf
1822 a0e3dca4 gaqhf
                            double x = 0;
1823
                            double y = 0;
1824
                            GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y);
1825
                            ChangeLineSPPIDCoordinateByConnectorOnlyY(prevLine, line, y);
1826 d63050d6 gaqhf
                        }
1827 a0e3dca4 gaqhf
                        else if (line.SlopeType == SlopeType.VERTICAL)
1828 d63050d6 gaqhf
                        {
1829 a0e3dca4 gaqhf
                            double prevX = 0;
1830
                            double prevY = 0;
1831
                            GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY);
1832
                            ChangeLineSPPIDCoordinateByConnectorOnlyY(line, prevLine, prevY);
1833 d63050d6 gaqhf
1834 a0e3dca4 gaqhf
                            double x = 0;
1835
                            double y = 0;
1836
                            GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y);
1837
                            ChangeLineSPPIDCoordinateByConnectorOnlyX(prevLine, line, x);
1838 d63050d6 gaqhf
                        }
1839 a0e3dca4 gaqhf
                        break;
1840 c2ec33f5 gaqhf
                    }
1841 1ab9a205 gaqhf
                }
1842 c2ec33f5 gaqhf
            }
1843 a0e3dca4 gaqhf
        }
1844 7f00b26c gaqhf
1845 a0e3dca4 gaqhf
        private void LineCoordinateCorrectionByConnItem(Line line, object connItem)
1846
        {
1847
            double x = 0;
1848
            double y = 0;
1849
            if (connItem.GetType() == typeof(Symbol))
1850
            {
1851
                Symbol targetSymbol = connItem as Symbol;
1852
                Connector targetConnector = targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == line);
1853
                if (targetConnector != null)
1854
                    GetTargetSymbolConnectorPoint(targetConnector, targetSymbol, ref x, ref y);
1855
                else
1856
                    throw new Exception("Target symbol UID : " + targetSymbol.UID + "\r\nLine UID : " + line.UID);
1857
            }
1858
            else if (connItem.GetType() == typeof(Line))
1859 c2ec33f5 gaqhf
            {
1860 a0e3dca4 gaqhf
                Line targetLine = connItem as Line;
1861
                GetTargetLineConnectorPoint(targetLine.CONNECTORS.Find(z => z.ConnectedObject == line), targetLine, ref x, ref y);
1862
            }
1863 7f00b26c gaqhf
1864 a0e3dca4 gaqhf
            ChangeLineSPPIDCoordinateByConnector(line, connItem, x, y);
1865
        }
1866 7f00b26c gaqhf
1867 a0e3dca4 gaqhf
        private void ChangeLineSPPIDCoordinateByConnector(Line line, object connItem, double x, double y, bool changeOtherCoordinate = true)
1868
        {
1869
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
1870
            int index = line.CONNECTORS.IndexOf(connector);
1871
            if (index == 0)
1872
            {
1873
                line.SPPID.START_X = x;
1874
                line.SPPID.START_Y = y;
1875
                if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate)
1876
                    line.SPPID.END_Y = y;
1877
                else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate)
1878
                    line.SPPID.END_X = x;
1879
            }
1880
            else
1881
            {
1882
                line.SPPID.END_X = x;
1883
                line.SPPID.END_Y = y;
1884
                if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate)
1885
                    line.SPPID.START_Y = y;
1886
                else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate)
1887
                    line.SPPID.START_X = x;
1888 c2ec33f5 gaqhf
            }
1889 a0e3dca4 gaqhf
        }
1890 7f00b26c gaqhf
1891 a0e3dca4 gaqhf
        private void ChangeLineSPPIDCoordinateByConnectorOnlyX(Line line, object connItem, double x)
1892
        {
1893
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
1894
            int index = line.CONNECTORS.IndexOf(connector);
1895
            if (index == 0)
1896
            {
1897
                line.SPPID.START_X = x;
1898
                if (line.SlopeType == SlopeType.VERTICAL)
1899
                    line.SPPID.END_X = x;
1900
            }
1901
            else
1902
            {
1903
                line.SPPID.END_X = x;
1904
                if (line.SlopeType == SlopeType.VERTICAL)
1905
                    line.SPPID.START_X = x;
1906
            }
1907
        }
1908 7f00b26c gaqhf
1909 a0e3dca4 gaqhf
        private void ChangeLineSPPIDCoordinateByConnectorOnlyY(Line line, object connItem, double y)
1910
        {
1911
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
1912
            int index = line.CONNECTORS.IndexOf(connector);
1913
            if (index == 0)
1914
            {
1915
                line.SPPID.START_Y = y;
1916
                if (line.SlopeType == SlopeType.HORIZONTAL)
1917
                    line.SPPID.END_Y = y;
1918
            }
1919
            else
1920
            {
1921
                line.SPPID.END_Y = y;
1922
                if (line.SlopeType == SlopeType.HORIZONTAL)
1923
                    line.SPPID.START_Y = y;
1924
            }
1925 1b261371 gaqhf
        }
1926
1927 0860c756 gaqhf
        private void NeedReModeling(Line line, LMSymbol symbol, ref bool result)
1928 ac82b020 gaqhf
        {
1929 0860c756 gaqhf
            if (symbol != null)
1930 ac82b020 gaqhf
            {
1931 fb386b8c gaqhf
                string repID = symbol.AsLMRepresentation().Id;
1932
                string symbolUID = SPPIDUtil.FindSymbolByRepresentationID(document, repID).UID;
1933
                string lineUID = line.UID;
1934 ac82b020 gaqhf
1935 fb386b8c gaqhf
                SpecBreak startSpecBreak = document.SpecBreaks.Find(x =>
1936
                (x.DownStreamUID == symbolUID || x.UpStreamUID == symbolUID) &&
1937
                (x.DownStreamUID == lineUID || x.UpStreamUID == lineUID));
1938 71ba1ca3 gaqhf
1939 fb386b8c gaqhf
                EndBreak startEndBreak = document.EndBreaks.Find(x =>
1940
                (x.OWNER == symbolUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbolUID) &&
1941
                (x.OWNER == lineUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == lineUID));
1942 ac82b020 gaqhf
1943 fb386b8c gaqhf
                if (startSpecBreak != null || startEndBreak != null)
1944
                    result = true;
1945 ac82b020 gaqhf
            }
1946
        }
1947 7f00b26c gaqhf
1948 74752074 gaqhf
        /// <summary>
1949 1ab9a205 gaqhf
        /// Symbol에 붙을 경우 Line을 Remodeling 한다.
1950
        /// </summary>
1951
        /// <param name="lines"></param>
1952
        /// <param name="prevLMConnector"></param>
1953
        /// <param name="startSymbol"></param>
1954
        /// <param name="endSymbol"></param>
1955 5173ba5d gaqhf
        private void ReModelingLine(Line line, LMConnector prevLMConnector, LMSymbol startSymbol, LMSymbol endSymbol, bool bStart, bool bEnd)
1956 1ab9a205 gaqhf
        {
1957
            string symbolPath = string.Empty;
1958
            #region get symbol path
1959
            LMModelItem modelItem = dataSource.GetModelItem(prevLMConnector.ModelItemID);
1960 a31a512e gaqhf
            symbolPath = GetSPPIDFileName(modelItem);
1961 d77973b3 gaqhf
            ReleaseCOMObjects(modelItem);
1962 1ab9a205 gaqhf
            #endregion
1963 24b5276c gaqhf
            bool diagonal = false;
1964
            if (line.SlopeType != SlopeType.HORIZONTAL && line.SlopeType != SlopeType.VERTICAL)
1965
                diagonal = true;
1966 1ab9a205 gaqhf
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
1967
            LMConnector newConnector = null;
1968 32205389 gaqhf
            dynamic OID = prevLMConnector.get_GraphicOID().ToString();
1969 1ab9a205 gaqhf
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1970
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1971
            int verticesCount = lineStringGeometry.VertexCount;
1972
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1973 7f00b26c gaqhf
1974 1ab9a205 gaqhf
            List<double[]> vertices = new List<double[]>();
1975
            for (int i = 1; i <= verticesCount; i++)
1976
            {
1977
                double x = 0;
1978
                double y = 0;
1979
                lineStringGeometry.GetVertex(i, ref x, ref y);
1980
                vertices.Add(new double[] { x, y });
1981
            }
1982
1983
            for (int i = 0; i < vertices.Count; i++)
1984
            {
1985
                double[] points = vertices[i];
1986
                // 시작 심볼이 있고 첫번째 좌표일 때
1987
                if (startSymbol != null && i == 0)
1988
                {
1989 ac82b020 gaqhf
                    if (bStart)
1990
                    {
1991
                        SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i + 1][0], vertices[i + 1][1]);
1992
                        if (slopeType == SlopeType.HORIZONTAL)
1993
                            placeRunInputs.AddPoint(points[0], -0.1);
1994
                        else if (slopeType == SlopeType.VERTICAL)
1995
                            placeRunInputs.AddPoint(-0.1, points[1]);
1996
                        else
1997
                            placeRunInputs.AddPoint(points[0], -0.1);
1998 1ab9a205 gaqhf
1999 ac82b020 gaqhf
                        placeRunInputs.AddPoint(points[0], points[1]);
2000
                    }
2001
                    else
2002
                    {
2003 24b5276c gaqhf
                        placeRunInputs.AddSymbolTarget(startSymbol, points[0], points[1], diagonal);
2004 ac82b020 gaqhf
                    }
2005 1ab9a205 gaqhf
                }
2006
                // 마지막 심볼이 있고 마지막 좌표일 때
2007
                else if (endSymbol != null && i == vertices.Count - 1)
2008
                {
2009 ac82b020 gaqhf
                    if (bEnd)
2010
                    {
2011
                        placeRunInputs.AddPoint(points[0], points[1]);
2012 1ab9a205 gaqhf
2013 ac82b020 gaqhf
                        SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i - 1][0], vertices[i - 1][1]);
2014
                        if (slopeType == SlopeType.HORIZONTAL)
2015
                            placeRunInputs.AddPoint(points[0], -0.1);
2016
                        else if (slopeType == SlopeType.VERTICAL)
2017
                            placeRunInputs.AddPoint(-0.1, points[1]);
2018
                        else
2019
                            placeRunInputs.AddPoint(points[0], -0.1);
2020
                    }
2021 1ab9a205 gaqhf
                    else
2022 ac82b020 gaqhf
                    {
2023 24b5276c gaqhf
                        placeRunInputs.AddSymbolTarget(endSymbol, points[0], points[1], diagonal);
2024 ac82b020 gaqhf
                    }
2025 1ab9a205 gaqhf
                }
2026
                // 첫번째이며 시작 심볼이 아니고 Connecotr일 경우
2027
                else if (i == 0 && prevLMConnector.ConnectItem1SymbolObject != null)
2028 24b5276c gaqhf
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem1SymbolObject, points[0], points[1], diagonal);
2029 1ab9a205 gaqhf
                // 마지막이며 마지막 심볼이 아니고 Connecotr일 경우
2030
                else if (i == vertices.Count - 1 && prevLMConnector.ConnectItem2SymbolObject != null)
2031 24b5276c gaqhf
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem2SymbolObject, points[0], points[1], diagonal);
2032 1ab9a205 gaqhf
                else
2033
                    placeRunInputs.AddPoint(points[0], points[1]);
2034
            }
2035
2036
            _placement.PIDRemovePlacement(prevLMConnector.AsLMRepresentation());
2037
            newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2038
2039
            ReleaseCOMObjects(placeRunInputs);
2040
            ReleaseCOMObjects(_LMAItem);
2041
            ReleaseCOMObjects(modelItem);
2042
2043
            if (newConnector != null)
2044
            {
2045 ac82b020 gaqhf
                if (startSymbol != null && bStart)
2046 1ab9a205 gaqhf
                {
2047
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
2048
                    placeRunInputs = new PlaceRunInputs();
2049 f1a7faf9 gaqhf
                    placeRunInputs.AddSymbolTarget(startSymbol, vertices[0][0], vertices[0][1]);
2050
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[0][0], vertices[0][1]);
2051 1ab9a205 gaqhf
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2052
                    if (_LMConnector != null)
2053
                    {
2054
                        RemoveConnectorForReModelingLine(newConnector);
2055 87f02fc0 gaqhf
                        ZeroLengthModelItemID.Add(_LMConnector.ModelItemID);
2056 1ab9a205 gaqhf
                        ReleaseCOMObjects(_LMConnector);
2057
                    }
2058
                    ReleaseCOMObjects(placeRunInputs);
2059
                    ReleaseCOMObjects(_LMAItem);
2060
                }
2061
2062 ac82b020 gaqhf
                if (endSymbol != null && bEnd)
2063 1ab9a205 gaqhf
                {
2064
                    if (startSymbol != null)
2065
                    {
2066
                        Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(newConnector.ModelItemID);
2067
                        newConnector = dicVertices.First().Key;
2068
                    }
2069
2070
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
2071
                    placeRunInputs = new PlaceRunInputs();
2072 f1a7faf9 gaqhf
                    placeRunInputs.AddSymbolTarget(endSymbol, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
2073
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
2074 1ab9a205 gaqhf
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2075
                    if (_LMConnector != null)
2076
                    {
2077
                        RemoveConnectorForReModelingLine(newConnector);
2078 1ff0105e gaqhf
                        ZeroLengthModelItemIDReverse.Add(_LMConnector.ModelItemID);
2079 1ab9a205 gaqhf
                        ReleaseCOMObjects(_LMConnector);
2080
                    }
2081
                    ReleaseCOMObjects(placeRunInputs);
2082
                    ReleaseCOMObjects(_LMAItem);
2083
                }
2084
2085 5173ba5d gaqhf
                line.SPPID.ModelItemId = newConnector.ModelItemID;
2086 1ab9a205 gaqhf
                ReleaseCOMObjects(newConnector);
2087
            }
2088
2089
            ReleaseCOMObjects(modelItem);
2090
        }
2091
2092
        /// <summary>
2093
        /// Remodeling 과정에서 생긴 불필요한 Connector 제거
2094
        /// </summary>
2095
        /// <param name="connector"></param>
2096
        private void RemoveConnectorForReModelingLine(LMConnector connector)
2097
        {
2098
            Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(connector.ModelItemID);
2099
            foreach (var item in dicVertices)
2100
            {
2101 1805d3b7 gaqhf
                if (item.Value.Count == 2)
2102 1ab9a205 gaqhf
                {
2103 1805d3b7 gaqhf
                    bool result = false;
2104
                    foreach (var point in item.Value)
2105 1ab9a205 gaqhf
                    {
2106 1805d3b7 gaqhf
                        if (point[0] < 0 || point[1] < 0)
2107
                        {
2108
                            result = true;
2109
                            _placement.PIDRemovePlacement(item.Key.AsLMRepresentation());
2110
                            break;
2111
                        }
2112 1ab9a205 gaqhf
                    }
2113
2114 1805d3b7 gaqhf
                    if (result)
2115
                        break;
2116
                }
2117 1ab9a205 gaqhf
            }
2118
            foreach (var item in dicVertices)
2119
                ReleaseCOMObjects(item.Key);
2120
        }
2121
2122
        /// <summary>
2123 74752074 gaqhf
        /// Symbol이 모델링된 SPPPID Symbol Object를 반환 - 연결된 Symbol이 ChildSymbol일 수도 있기때문에 메서드 개발
2124
        /// </summary>
2125
        /// <param name="symbol"></param>
2126
        /// <param name="line"></param>
2127
        /// <returns></returns>
2128 f2baa6a3 gaqhf
        private LMSymbol GetTargetSymbol(Symbol symbol, Line line)
2129
        {
2130
            LMSymbol _LMSymbol = null;
2131
            foreach (var connector in symbol.CONNECTORS)
2132
            {
2133 a0e3dca4 gaqhf
                if (connector.CONNECTEDITEM == line.UID)
2134 6b298450 gaqhf
                {
2135 a0e3dca4 gaqhf
                    if (connector.Index == 0)
2136
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
2137
                    else
2138 0860c756 gaqhf
                    {
2139 a0e3dca4 gaqhf
                        ChildSymbol child = null;
2140
                        foreach (var childSymbol in symbol.ChildSymbols)
2141 0860c756 gaqhf
                        {
2142 a0e3dca4 gaqhf
                            if (childSymbol.Connectors.Contains(connector))
2143
                                child = childSymbol;
2144
                            else
2145
                                child = GetChildSymbolByConnector(childSymbol, connector);
2146
2147
                            if (child != null)
2148 0860c756 gaqhf
                                break;
2149
                        }
2150
2151 a0e3dca4 gaqhf
                        if (child != null)
2152
                            _LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId);
2153 0860c756 gaqhf
                    }
2154
2155 a0e3dca4 gaqhf
                    break;
2156 335b7a24 gaqhf
                }
2157 a0e3dca4 gaqhf
            }
2158 335b7a24 gaqhf
2159 a0e3dca4 gaqhf
            return _LMSymbol;
2160
        }
2161
2162
        /// <summary>
2163
        /// Connector를 가지고 있는 ChildSymbol Object 반환
2164
        /// </summary>
2165
        /// <param name="item"></param>
2166
        /// <param name="connector"></param>
2167
        /// <returns></returns>
2168
        private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector)
2169
        {
2170
            foreach (var childSymbol in item.ChildSymbols)
2171
            {
2172
                if (childSymbol.Connectors.Contains(connector))
2173
                    return childSymbol;
2174
                else
2175
                    return GetChildSymbolByConnector(childSymbol, connector);
2176 335b7a24 gaqhf
            }
2177
2178 a0e3dca4 gaqhf
            return null;
2179 335b7a24 gaqhf
        }
2180
2181 74752074 gaqhf
        /// <summary>
2182
        /// EndBreak 모델링 메서드
2183
        /// </summary>
2184
        /// <param name="endBreak"></param>
2185 3165c259 gaqhf
        private void EndBreakModeling(EndBreak endBreak)
2186 335b7a24 gaqhf
        {
2187 10c7195c gaqhf
            object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER);
2188 1ab9a205 gaqhf
            object connectedItem = SPPIDUtil.FindObjectByUID(document, endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE);
2189
            LMConnector targetLMConnector = FindBreakLineTarget(ownerObj, connectedItem);
2190 3165c259 gaqhf
2191 1ab9a205 gaqhf
            if (targetLMConnector != null)
2192 10c7195c gaqhf
            {
2193 02a45794 gaqhf
                double[] point = GetSegmentPoint(ownerObj, connectedItem, targetLMConnector);
2194
                Array array = null;
2195
                if (point != null)
2196
                    array = new double[] { 0, point[0], point[1] };
2197
                else
2198
                    array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
2199
                LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
2200 5173ba5d gaqhf
                if (_LmLabelPersist != null)
2201
                {
2202
                    endBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id;
2203 d23fe61b gaqhf
                    if (_LmLabelPersist.ModelItemObject != null)
2204
                        endBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID;
2205 32205389 gaqhf
                    endBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID().ToString();
2206 5173ba5d gaqhf
                    ReleaseCOMObjects(_LmLabelPersist);
2207
                }
2208
                ReleaseCOMObjects(targetLMConnector);
2209 2a4872ec gaqhf
            }
2210
        }
2211 b9e9f4c8 gaqhf
2212 d77973b3 gaqhf
        private LMConnector ReModelingLMConnector(LMConnector connector, string changeSymbolPath = null)
2213 02480ac1 gaqhf
        {
2214 de97eaaa gaqhf
            string symbolPath = string.Empty;
2215
            #region get symbol path
2216 d77973b3 gaqhf
            if (string.IsNullOrEmpty(changeSymbolPath))
2217
            {
2218
                LMModelItem modelItem = dataSource.GetModelItem(connector.ModelItemID);
2219
                symbolPath = GetSPPIDFileName(modelItem);
2220
                ReleaseCOMObjects(modelItem);
2221
            }
2222
            else
2223
                symbolPath = changeSymbolPath;
2224
            
2225 de97eaaa gaqhf
            #endregion
2226
2227 02480ac1 gaqhf
            LMConnector newConnector = null;
2228 32205389 gaqhf
            dynamic OID = connector.get_GraphicOID().ToString();
2229 02480ac1 gaqhf
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2230
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2231
            int verticesCount = lineStringGeometry.VertexCount;
2232
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
2233 de97eaaa gaqhf
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
2234 02480ac1 gaqhf
2235
            if (Convert.ToBoolean(connector.get_IsZeroLength()))
2236
            {
2237
                double[] vertices = null;
2238
                lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
2239
                double x = 0;
2240
                double y = 0;
2241
                lineStringGeometry.GetVertex(1, ref x, ref y);
2242
2243 32205389 gaqhf
                string flowDirection = string.Empty;
2244
                LMAAttribute flowAttribute = connector.ModelItemObject.Attributes["FlowDirection"];
2245
                if (flowAttribute != null && !DBNull.Value.Equals(flowAttribute.get_Value()))
2246
                    flowDirection = flowAttribute.get_Value().ToString();
2247
2248 3fdf052a gaqhf
                if (flowDirection == "End 1 is downstream (Outlet)")
2249
                {
2250
                    placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y);
2251
                    placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y);
2252
                    flowDirection = "End 1 is upstream (Inlet)";
2253
                }
2254
                else
2255
                {
2256
                    placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y);
2257
                    placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y);
2258
                }
2259
2260 02480ac1 gaqhf
                _placement.PIDRemovePlacement(connector.AsLMRepresentation());
2261
                newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2262 644f40b3 gaqhf
                ZeroLengthSymbolToSymbolModelItemID.Add(newConnector.ModelItemID);
2263 32205389 gaqhf
                if (!string.IsNullOrEmpty(flowDirection))
2264
                    newConnector.ModelItemObject.Attributes["FlowDirection"].set_Value(flowDirection);
2265 02480ac1 gaqhf
            }
2266
            else
2267
            {
2268
                List<double[]> vertices = new List<double[]>();
2269
                for (int i = 1; i <= verticesCount; i++)
2270
                {
2271
                    double x = 0;
2272
                    double y = 0;
2273
                    lineStringGeometry.GetVertex(i, ref x, ref y);
2274
                    vertices.Add(new double[] { x, y });
2275
                }
2276
2277
                for (int i = 0; i < vertices.Count; i++)
2278
                {
2279
                    double[] points = vertices[i];
2280
                    if (i == 0)
2281
                    {
2282
                        if (connector.ConnectItem1SymbolObject != null)
2283 f1a7faf9 gaqhf
                            placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, points[0], points[1]);
2284 02480ac1 gaqhf
                        else
2285
                            placeRunInputs.AddPoint(points[0], points[1]);
2286
                    }
2287
                    else if (i == vertices.Count - 1)
2288
                    {
2289
                        if (connector.ConnectItem2SymbolObject != null)
2290 f1a7faf9 gaqhf
                            placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, points[0], points[1]);
2291 02480ac1 gaqhf
                        else
2292
                            placeRunInputs.AddPoint(points[0], points[1]);
2293
                    }
2294
                    else
2295
                        placeRunInputs.AddPoint(points[0], points[1]);
2296
                }
2297
2298
                List<Line> lines = SPPIDUtil.FindLinesByModelId(document, connector.ModelItemID);
2299
2300
                _placement.PIDRemovePlacement(connector.AsLMRepresentation());
2301
                newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2302
2303
                foreach (var line in lines)
2304
                    line.SPPID.ModelItemId = newConnector.ModelItemID;
2305
            }
2306
2307
2308
            return newConnector;
2309
        }
2310
2311 74752074 gaqhf
        /// <summary>
2312 53c81765 gaqhf
        /// SpecBreak Modeling 메서드
2313
        /// </summary>
2314
        /// <param name="specBreak"></param>
2315
        private void SpecBreakModeling(SpecBreak specBreak)
2316
        {
2317
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
2318
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
2319
2320
            if (upStreamObj != null &&
2321
                downStreamObj != null)
2322
            {
2323 1ab9a205 gaqhf
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
2324
2325
                if (targetLMConnector != null)
2326 53c81765 gaqhf
                {
2327 16584d30 gaqhf
                    foreach (var attribute in specBreak.ATTRIBUTES)
2328 53c81765 gaqhf
                    {
2329 16584d30 gaqhf
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID);
2330
                        if (mapping != null && !string.IsNullOrEmpty(mapping.SPPIDSYMBOLNAME) && mapping.SPPIDSYMBOLNAME != "None")
2331
                        {
2332
                            string MappingPath = mapping.SPPIDSYMBOLNAME;
2333 02a45794 gaqhf
                            double[] point = GetSegmentPoint(upStreamObj, downStreamObj, targetLMConnector);
2334
                            Array array = null;
2335
                            if (point != null)
2336
                                array = new double[] { 0, point[0], point[1] };
2337
                            else
2338
                                array = new double[] { 0, specBreak.SPPID.ORIGINAL_X, specBreak.SPPID.ORIGINAL_Y };
2339
                            LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(MappingPath, ref array, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
2340 53c81765 gaqhf
2341 16584d30 gaqhf
                            if (_LmLabelPersist != null)
2342
                            {
2343 5173ba5d gaqhf
                                specBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id;
2344 d23fe61b gaqhf
                                if (_LmLabelPersist.ModelItemObject != null)
2345
                                    specBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID;
2346 32205389 gaqhf
                                specBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID().ToString();
2347 16584d30 gaqhf
                                ReleaseCOMObjects(_LmLabelPersist);
2348
                            }
2349
                        }
2350
                    }
2351 1ab9a205 gaqhf
                    ReleaseCOMObjects(targetLMConnector);
2352
                }
2353
            }
2354
        }
2355 53c81765 gaqhf
2356 1ab9a205 gaqhf
        private LMConnector FindBreakLineTarget(object targetObj, object connectedObj)
2357
        {
2358
            LMConnector targetConnector = null;
2359
            Symbol targetSymbol = targetObj as Symbol;
2360
            Symbol connectedSymbol = connectedObj as Symbol;
2361
            Line targetLine = targetObj as Line;
2362
            Line connectedLine = connectedObj as Line;
2363
            if (targetSymbol != null && connectedSymbol != null)
2364
            {
2365
                LMSymbol targetLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
2366
                LMSymbol connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId);
2367
2368
                foreach (LMConnector connector in targetLMSymbol.Avoid1Connectors)
2369
                {
2370
                    if (connector.get_ItemStatus() != "Active")
2371
                        continue;
2372
2373
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
2374
                    {
2375
                        targetConnector = connector;
2376
                        break;
2377
                    }
2378
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
2379
                    {
2380
                        targetConnector = connector;
2381
                        break;
2382 53c81765 gaqhf
                    }
2383
                }
2384 1ab9a205 gaqhf
2385
                foreach (LMConnector connector in targetLMSymbol.Avoid2Connectors)
2386 53c81765 gaqhf
                {
2387 1ab9a205 gaqhf
                    if (connector.get_ItemStatus() != "Active")
2388
                        continue;
2389 53c81765 gaqhf
2390 1ab9a205 gaqhf
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
2391
                    {
2392
                        targetConnector = connector;
2393
                        break;
2394
                    }
2395
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
2396
                    {
2397
                        targetConnector = connector;
2398
                        break;
2399 53c81765 gaqhf
                    }
2400
                }
2401 1ab9a205 gaqhf
2402
                ReleaseCOMObjects(targetLMSymbol);
2403
                ReleaseCOMObjects(connectedLMSymbol);
2404
            }
2405
            else if (targetLine != null && connectedLine != null)
2406
            {
2407
                LMModelItem targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId);
2408
                LMModelItem connectedModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
2409
2410 d77973b3 gaqhf
                if (targetModelItem != null && targetModelItem.get_ItemStatus() == "Active" && connectedModelItem != null && connectedModelItem.get_ItemStatus() == "Active")
2411 53c81765 gaqhf
                {
2412 1ab9a205 gaqhf
                    foreach (LMRepresentation rep in targetModelItem.Representations)
2413 53c81765 gaqhf
                    {
2414 1ab9a205 gaqhf
                        if (targetConnector != null)
2415
                            break;
2416 53c81765 gaqhf
2417 1ab9a205 gaqhf
                        if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2418 53c81765 gaqhf
                        {
2419 1ab9a205 gaqhf
                            LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2420
2421
                            if (IsConnected(_LMConnector, connectedModelItem))
2422
                                targetConnector = _LMConnector;
2423
                            else
2424
                                ReleaseCOMObjects(_LMConnector);
2425 53c81765 gaqhf
                        }
2426
                    }
2427 1ab9a205 gaqhf
2428
                    ReleaseCOMObjects(targetModelItem);
2429 53c81765 gaqhf
                }
2430 1ab9a205 gaqhf
            }
2431
            else
2432
            {
2433 340515a2 gaqhf
                LMSymbol connectedLMSymbol = null;
2434
                if (connectedSymbol != null)
2435
                    connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId);
2436
                else if (targetSymbol != null)
2437
                    connectedLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
2438
                else
2439
                {
2440
2441
                }
2442
                LMModelItem targetModelItem = null;
2443
                if (targetLine != null)
2444
                    targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId);
2445
                else if (connectedLine != null)
2446
                    targetModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
2447
                else
2448
                {
2449
2450
                }
2451 1ab9a205 gaqhf
                if (connectedLMSymbol != null && targetModelItem != null)
2452 53c81765 gaqhf
                {
2453 1ab9a205 gaqhf
                    foreach (LMConnector connector in connectedLMSymbol.Avoid1Connectors)
2454
                    {
2455 ac82b020 gaqhf
                        if (connector.get_ItemStatus() != "Active")
2456
                            continue;
2457
2458 1ab9a205 gaqhf
                        if (IsConnected(connector, targetModelItem))
2459
                        {
2460
                            targetConnector = connector;
2461
                            break;
2462
                        }
2463
                    }
2464 53c81765 gaqhf
2465 1ab9a205 gaqhf
                    if (targetConnector == null)
2466 53c81765 gaqhf
                    {
2467 1ab9a205 gaqhf
                        foreach (LMConnector connector in connectedLMSymbol.Avoid2Connectors)
2468 53c81765 gaqhf
                        {
2469 ac82b020 gaqhf
                            if (connector.get_ItemStatus() != "Active")
2470
                                continue;
2471
2472 1ab9a205 gaqhf
                            if (IsConnected(connector, targetModelItem))
2473 53c81765 gaqhf
                            {
2474 1ab9a205 gaqhf
                                targetConnector = connector;
2475
                                break;
2476 53c81765 gaqhf
                            }
2477
                        }
2478
                    }
2479
                }
2480
2481 1ab9a205 gaqhf
            }
2482 02480ac1 gaqhf
2483 1ab9a205 gaqhf
            return targetConnector;
2484
        }
2485 53c81765 gaqhf
2486 02a45794 gaqhf
        private double[] GetSegmentPoint(object targetObj, object connObj, LMConnector targetConnector)
2487
        {
2488
            double[] result = null;
2489
            if (Convert.ToBoolean(targetConnector.get_IsZeroLength()))
2490
            {
2491
                return GetConnectorVertices(targetConnector)[0];
2492
            }
2493
            else
2494
            {
2495
                if (targetObj.GetType() == typeof(Line) && connObj.GetType() == typeof(Line))
2496
                {
2497
                    Line line = connObj as Line;
2498
                    LMConnector connectedConnector = null;
2499
                    int connIndex = 0;
2500
                    LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
2501
                    FindConnectedConnector(targetConnector, modelItem, ref connectedConnector, ref connIndex);
2502
2503
                    List<double[]> vertices = GetConnectorVertices(targetConnector);
2504
2505
                    ReleaseCOMObjects(modelItem);
2506
                    ReleaseCOMObjects(connectedConnector);
2507
2508
                    if (vertices.Count > 0)
2509
                    {
2510
                        if (connIndex == 1)
2511
                            return vertices[0];
2512
                        else if (connIndex == 2)
2513
                            return vertices[vertices.Count - 1];
2514
                    }
2515
                }
2516
                else
2517
                {
2518
                    Log.Write("error in GetSegemtPoint");
2519
                }
2520
            }
2521
2522
            return result;
2523
        }
2524
2525 1ab9a205 gaqhf
        private bool IsConnected(LMConnector connector, LMModelItem modelItem)
2526
        {
2527
            bool result = false;
2528
2529
            foreach (LMRepresentation rep in modelItem.Representations)
2530
            {
2531
                if (result)
2532
                    break;
2533
2534
                if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2535
                {
2536
                    LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2537
2538
                    if (_LMConnector.ConnectItem1SymbolObject != null &&
2539
                        connector.ConnectItem1SymbolObject != null &&
2540
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2541 53c81765 gaqhf
                    {
2542 1ab9a205 gaqhf
                        result = true;
2543
                        ReleaseCOMObjects(_LMConnector);
2544
                        break;
2545
                    }
2546
                    else if (_LMConnector.ConnectItem1SymbolObject != null &&
2547
                        connector.ConnectItem2SymbolObject != null &&
2548
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2549
                    {
2550
                        result = true;
2551
                        ReleaseCOMObjects(_LMConnector);
2552
                        break;
2553
                    }
2554
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2555
                        connector.ConnectItem1SymbolObject != null &&
2556
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2557
                    {
2558
                        result = true;
2559
                        ReleaseCOMObjects(_LMConnector);
2560
                        break;
2561
                    }
2562
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2563
                        connector.ConnectItem2SymbolObject != null &&
2564
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2565
                    {
2566
                        result = true;
2567
                        ReleaseCOMObjects(_LMConnector);
2568
                        break;
2569 53c81765 gaqhf
                    }
2570
2571 1ab9a205 gaqhf
                    ReleaseCOMObjects(_LMConnector);
2572
                }
2573 53c81765 gaqhf
            }
2574 1ab9a205 gaqhf
2575
2576
            return result;
2577 53c81765 gaqhf
        }
2578
2579 02a45794 gaqhf
        private void FindConnectedConnector(LMConnector connector, LMModelItem modelItem, ref LMConnector connectedConnector, ref int connectorIndex)
2580
        {
2581
            foreach (LMRepresentation rep in modelItem.Representations)
2582
            {
2583
                if (connectedConnector != null)
2584
                    break;
2585
2586
                if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2587
                {
2588
                    LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2589
2590
                    if (_LMConnector.ConnectItem1SymbolObject != null &&
2591
                        connector.ConnectItem1SymbolObject != null &&
2592
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2593
                    {
2594
                        connectedConnector = _LMConnector;
2595
                        connectorIndex = 1;
2596
                        break;
2597
                    }
2598
                    else if (_LMConnector.ConnectItem1SymbolObject != null &&
2599
                        connector.ConnectItem2SymbolObject != null &&
2600
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2601
                    {
2602
                        connectedConnector = _LMConnector;
2603
                        connectorIndex = 2;
2604
                        break;
2605
                    }
2606
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2607
                        connector.ConnectItem1SymbolObject != null &&
2608
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2609
                    {
2610
                        connectedConnector = _LMConnector;
2611
                        connectorIndex = 1;
2612
                        break;
2613
                    }
2614
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2615
                        connector.ConnectItem2SymbolObject != null &&
2616
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2617
                    {
2618
                        connectedConnector = _LMConnector;
2619
                        connectorIndex = 2;
2620
                        break;
2621
                    }
2622
2623
                    if (connectedConnector == null)
2624
                        ReleaseCOMObjects(_LMConnector);
2625
                }
2626
            }
2627
        }
2628
2629 53c81765 gaqhf
        /// <summary>
2630 74752074 gaqhf
        /// FromModelItem을 ToModelItem으로 PipeRunJoin하는 메서드
2631
        /// </summary>
2632 644f40b3 gaqhf
        /// <param name="modelItemID1"></param>
2633
        /// <param name="modelItemID2"></param>
2634 a31a512e gaqhf
        private void JoinRun(string modelId1, string modelId2, ref string survivorId)
2635 335b7a24 gaqhf
        {
2636 ca6e0f51 gaqhf
            try
2637 644f40b3 gaqhf
            {
2638 a31a512e gaqhf
                LMModelItem modelItem1 = dataSource.GetModelItem(modelId1);
2639 ca6e0f51 gaqhf
                _LMAItem item1 = modelItem1.AsLMAItem();
2640 a31a512e gaqhf
                LMModelItem modelItem2 = dataSource.GetModelItem(modelId2);
2641 ca6e0f51 gaqhf
                _LMAItem item2 = modelItem2.AsLMAItem();
2642 644f40b3 gaqhf
2643 ca6e0f51 gaqhf
                // item2가 item1으로 조인
2644
                _placement.PIDJoinRuns(ref item1, ref item2);
2645
                item1.Commit();
2646
                item2.Commit();
2647 7f00b26c gaqhf
2648 ca6e0f51 gaqhf
                string beforeID = string.Empty;
2649
                string afterID = string.Empty;
2650 335b7a24 gaqhf
2651 ca6e0f51 gaqhf
                if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() != "Active")
2652
                {
2653
                    beforeID = modelItem2.Id;
2654
                    afterID = modelItem1.Id;
2655 a31a512e gaqhf
                    survivorId = afterID;
2656 be7159c9 gaqhf
                    LMAAttribute attribute = modelItem1.Attributes["FlowDirection"];
2657
                    if (attribute != null)
2658
                        attribute.set_Value("End 1 is upstream (Inlet)");
2659 ca6e0f51 gaqhf
                }
2660
                else if (modelItem1.get_ItemStatus() != "Active" && modelItem2.get_ItemStatus() == "Active")
2661
                {
2662
                    beforeID = modelItem1.Id;
2663
                    afterID = modelItem2.Id;
2664 a31a512e gaqhf
                    survivorId = afterID;
2665 be7159c9 gaqhf
                    LMAAttribute attribute = modelItem2.Attributes["FlowDirection"];
2666
                    if (attribute != null)
2667
                        attribute.set_Value("End 1 is upstream (Inlet)");
2668 ca6e0f51 gaqhf
                }
2669 a31a512e gaqhf
                else if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() == "Active")
2670
                    survivorId = null;
2671 ca6e0f51 gaqhf
                else
2672
                {
2673 a31a512e gaqhf
                    Log.Write("잘못된 경우");
2674
                    survivorId = null;
2675 ca6e0f51 gaqhf
                }
2676 87f02fc0 gaqhf
2677 ca6e0f51 gaqhf
                if (!string.IsNullOrEmpty(beforeID) && !string.IsNullOrEmpty(afterID))
2678 7f00b26c gaqhf
                {
2679 ca6e0f51 gaqhf
                    List<Line> lines = SPPIDUtil.FindLinesByModelId(document, beforeID);
2680 7f00b26c gaqhf
                    foreach (var line in lines)
2681 ca6e0f51 gaqhf
                        line.SPPID.ModelItemId = afterID;
2682 65a1ed4b gaqhf
                }
2683 7f00b26c gaqhf
2684 ca6e0f51 gaqhf
                ReleaseCOMObjects(modelItem1);
2685
                ReleaseCOMObjects(item1);
2686
                ReleaseCOMObjects(modelItem2);
2687
                ReleaseCOMObjects(item2);
2688
            }
2689
            catch (Exception ex)
2690 335b7a24 gaqhf
            {
2691 ca6e0f51 gaqhf
                Log.Write("Join Error");
2692
                Log.Write(ex.Message);
2693 335b7a24 gaqhf
            }
2694
        }
2695
2696 a31a512e gaqhf
        private List<string> FindOtherModelItemBySymbolWhereTypePipeRun(LMSymbol symbol, string modelId)
2697
        {
2698
            List<string> modelItemIDs = new List<string>();
2699 48fd75e2 gaqhf
            foreach (LMConnector connector in symbol.Avoid1Connectors)
2700 a31a512e gaqhf
            {
2701
                LMModelItem modelItem = connector.ModelItemObject;
2702
                if (modelItem.get_ItemStatus() == "Active" && modelItem.get_ItemTypeName().ToString() == "PipeRun" && modelItem.Id != modelId)
2703
                    modelItemIDs.Add(modelItem.Id);
2704
                ReleaseCOMObjects(modelItem);
2705
                ReleaseCOMObjects(connector);
2706
            }
2707
2708 48fd75e2 gaqhf
            foreach (LMConnector connector in symbol.Avoid2Connectors)
2709 a31a512e gaqhf
            {
2710
                LMModelItem modelItem = connector.ModelItemObject;
2711
                if (modelItem.get_ItemStatus() == "Active" && modelItem.get_ItemTypeName().ToString() == "PipeRun" && modelItem.Id != modelId)
2712
                    modelItemIDs.Add(modelItem.Id);
2713
                ReleaseCOMObjects(modelItem);
2714
                ReleaseCOMObjects(connector);
2715
            }
2716
2717 48fd75e2 gaqhf
2718 82d6e5ea gaqhf
            List<string> result = new List<string>();
2719
            modelItemIDs = modelItemIDs.Distinct().ToList();
2720
            string originalName = GetSPPIDFileName(modelId);
2721
            foreach (var item in modelItemIDs)
2722
            {
2723
                string fileName = GetSPPIDFileName(item);
2724
                if (originalName == fileName)
2725
                    result.Add(item);
2726
                else
2727
                {
2728
                    LMConnector connector = GetLMConnectorOnlyOne(item);
2729
                    if (connector != null && Convert.ToBoolean(connector.get_IsZeroLength()))
2730
                    {
2731
                        result.Add(item);
2732
                        ReleaseCOMObjects(connector);
2733
                    }
2734
                }
2735
            }
2736
            
2737
            return result;
2738 a31a512e gaqhf
        }
2739
2740 74752074 gaqhf
        /// <summary>
2741
        /// PipeRun의 좌표를 가져오는 메서드
2742
        /// </summary>
2743
        /// <param name="modelId"></param>
2744
        /// <returns></returns>
2745 5e6ecf05 gaqhf
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
2746
        {
2747
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
2748 310aeb31 gaqhf
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
2749
2750
            if (modelItem != null)
2751 5e6ecf05 gaqhf
            {
2752 310aeb31 gaqhf
                foreach (LMRepresentation rep in modelItem.Representations)
2753 5e6ecf05 gaqhf
                {
2754
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2755
                    {
2756
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2757
                        connectorVertices.Add(_LMConnector, new List<double[]>());
2758 32205389 gaqhf
                        dynamic OID = rep.get_GraphicOID().ToString();
2759 335b7a24 gaqhf
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2760 5e6ecf05 gaqhf
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2761
                        int verticesCount = lineStringGeometry.VertexCount;
2762
                        double[] vertices = null;
2763
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
2764
                        for (int i = 0; i < verticesCount; i++)
2765
                        {
2766
                            double x = 0;
2767
                            double y = 0;
2768
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
2769 32205389 gaqhf
                            connectorVertices[_LMConnector].Add(new double[] { x, y });
2770 5e6ecf05 gaqhf
                        }
2771
                    }
2772
                }
2773
2774 310aeb31 gaqhf
                ReleaseCOMObjects(modelItem);
2775 5e6ecf05 gaqhf
            }
2776
2777
            return connectorVertices;
2778
        }
2779
2780 32205389 gaqhf
        private List<double[]> GetConnectorVertices(LMConnector connector)
2781
        {
2782
            List<double[]> vertices = new List<double[]>();
2783 02a45794 gaqhf
            if (connector != null)
2784 32205389 gaqhf
            {
2785 02a45794 gaqhf
                dynamic OID = connector.get_GraphicOID().ToString();
2786
                DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2787
                Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2788
                int verticesCount = lineStringGeometry.VertexCount;
2789
                double[] value = null;
2790
                lineStringGeometry.GetVertices(ref verticesCount, ref value);
2791
                for (int i = 0; i < verticesCount; i++)
2792
                {
2793
                    double x = 0;
2794
                    double y = 0;
2795
                    lineStringGeometry.GetVertex(i + 1, ref x, ref y);
2796
                    vertices.Add(new double[] { x, y });
2797
                }
2798 32205389 gaqhf
            }
2799
            return vertices;
2800
        }
2801
2802 7c7bcd10 gaqhf
        /// <summary>
2803 a0e3dca4 gaqhf
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식
2804 74752074 gaqhf
        /// </summary>
2805
        /// <param name="connectorVertices"></param>
2806
        /// <param name="connX"></param>
2807
        /// <param name="connY"></param>
2808
        /// <returns></returns>
2809 a0e3dca4 gaqhf
        private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
2810 5e6ecf05 gaqhf
        {
2811
            double length = double.MaxValue;
2812
            LMConnector targetConnector = null;
2813
            foreach (var item in connectorVertices)
2814
            {
2815
                List<double[]> points = item.Value;
2816
                for (int i = 0; i < points.Count - 1; i++)
2817
                {
2818
                    double[] point1 = points[i];
2819
                    double[] point2 = points[i + 1];
2820 a0e3dca4 gaqhf
                    double x1 = Math.Min(point1[0], point2[0]);
2821
                    double y1 = Math.Min(point1[1], point2[1]);
2822
                    double x2 = Math.Max(point1[0], point2[0]);
2823
                    double y2 = Math.Max(point1[1], point2[1]);
2824 5e6ecf05 gaqhf
2825 a0e3dca4 gaqhf
                    if ((x1 <= connX && x2 >= connX) ||
2826
                        (y1 <= connY && y2 >= connY))
2827 5e6ecf05 gaqhf
                    {
2828 a0e3dca4 gaqhf
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY);
2829 335b7a24 gaqhf
                        if (length >= distance)
2830 30a9ffce gaqhf
                        {
2831 a0e3dca4 gaqhf
                            targetConnector = item.Key;
2832
                            length = distance;
2833
                        }
2834
2835
                        distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY);
2836
                        if (length >= distance)
2837
                        {
2838
                            targetConnector = item.Key;
2839
                            length = distance;
2840 30a9ffce gaqhf
                        }
2841 5e6ecf05 gaqhf
                    }
2842
                }
2843 c3d2e266 gaqhf
            }
2844
2845 a0e3dca4 gaqhf
            // 못찾았을때.
2846
            length = double.MaxValue;
2847 c3d2e266 gaqhf
            if (targetConnector == null)
2848
            {
2849
                foreach (var item in connectorVertices)
2850
                {
2851
                    List<double[]> points = item.Value;
2852 a0e3dca4 gaqhf
2853
                    foreach (double[] point in points)
2854 c3d2e266 gaqhf
                    {
2855 a0e3dca4 gaqhf
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
2856 c3d2e266 gaqhf
                        if (length >= distance)
2857
                        {
2858
                            targetConnector = item.Key;
2859
                            length = distance;
2860
                        }
2861
                    }
2862
                }
2863 5e6ecf05 gaqhf
            }
2864
2865
            return targetConnector;
2866
        }
2867
2868 a0e3dca4 gaqhf
        private LMConnector FindTargetLMConnectorForBranch(Line line, Line targetLine, ref double x, ref double y)
2869 ac78b508 gaqhf
        {
2870 a0e3dca4 gaqhf
            Dictionary<LMConnector, List<double[]>> vertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId);
2871 0ff6e67f gaqhf
            if (vertices.Count == 0)
2872
                return null;
2873 a0e3dca4 gaqhf
2874 ac78b508 gaqhf
            double length = double.MaxValue;
2875
            LMConnector targetConnector = null;
2876 a0e3dca4 gaqhf
            double[] resultPoint = null;
2877
            List<double[]> targetVertices = null;
2878
2879
            // Vertices 포인트에 제일 가까운곳
2880
            foreach (var item in vertices)
2881 ac78b508 gaqhf
            {
2882
                List<double[]> points = item.Value;
2883 a0e3dca4 gaqhf
                for (int i = 0; i < points.Count; i++)
2884 ac78b508 gaqhf
                {
2885 a0e3dca4 gaqhf
                    double[] point = points[i];
2886
                    double tempX = point[0];
2887
                    double tempY = point[1];
2888
2889
                    double distance = SPPIDUtil.CalcPointToPointdDistance(tempX, tempY, x, y);
2890 ac78b508 gaqhf
                    if (length >= distance)
2891
                    {
2892
                        targetConnector = item.Key;
2893
                        length = distance;
2894 a0e3dca4 gaqhf
                        resultPoint = point;
2895
                        targetVertices = item.Value;
2896 ac78b508 gaqhf
                    }
2897
                }
2898
            }
2899
2900 a0e3dca4 gaqhf
            // Vertices Cross에 제일 가까운곳
2901
            foreach (var item in vertices)
2902 68464385 gaqhf
            {
2903
                List<double[]> points = item.Value;
2904
                for (int i = 0; i < points.Count - 1; i++)
2905
                {
2906
                    double[] point1 = points[i];
2907
                    double[] point2 = points[i + 1];
2908
2909 a0e3dca4 gaqhf
                    double maxLineX = Math.Max(point1[0], point2[0]);
2910
                    double minLineX = Math.Min(point1[0], point2[0]);
2911
                    double maxLineY = Math.Max(point1[1], point2[1]);
2912
                    double minLineY = Math.Min(point1[1], point2[1]);
2913 68464385 gaqhf
2914 a0e3dca4 gaqhf
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
2915
2916
                    double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y, point1[0], point1[1], point2[0], point2[1]);
2917
                    if (crossingPoint != null)
2918
                    {
2919
                        double distance = SPPIDUtil.CalcPointToPointdDistance(crossingPoint[0], crossingPoint[1], x, y);
2920 68464385 gaqhf
                        if (length >= distance)
2921
                        {
2922 a0e3dca4 gaqhf
                            if (slope == SlopeType.Slope &&
2923
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
2924
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
2925
                            {
2926
                                targetConnector = item.Key;
2927
                                length = distance;
2928
                                resultPoint = crossingPoint;
2929
                                targetVertices = item.Value;
2930
                            }
2931
                            else if (slope == SlopeType.HORIZONTAL &&
2932
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
2933
                            {
2934
                                targetConnector = item.Key;
2935
                                length = distance;
2936
                                resultPoint = crossingPoint;
2937
                                targetVertices = item.Value;
2938
                            }
2939
                            else if (slope == SlopeType.VERTICAL &&
2940
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
2941
                            {
2942
                                targetConnector = item.Key;
2943
                                length = distance;
2944
                                resultPoint = crossingPoint;
2945
                                targetVertices = item.Value;
2946
                            }
2947 68464385 gaqhf
                        }
2948
                    }
2949
                }
2950
            }
2951
2952 a0e3dca4 gaqhf
            foreach (var item in vertices)
2953
                if (item.Key != null && item.Key != targetConnector)
2954
                    ReleaseCOMObjects(item.Key);
2955
2956
            if (SPPIDUtil.IsBranchLine(line, targetLine))
2957 68464385 gaqhf
            {
2958 a0e3dca4 gaqhf
                double tempResultX = resultPoint[0];
2959
                double tempResultY = resultPoint[1];
2960
                SPPIDUtil.ConvertGridPoint(ref tempResultX, ref tempResultY);
2961 68464385 gaqhf
2962 a0e3dca4 gaqhf
                GridSetting gridSetting = GridSetting.GetInstance();
2963
2964
                for (int i = 0; i < targetVertices.Count; i++)
2965
                {
2966
                    double[] point = targetVertices[i];
2967
                    double tempX = targetVertices[i][0];
2968
                    double tempY = targetVertices[i][1];
2969
                    SPPIDUtil.ConvertGridPoint(ref tempX, ref tempY);
2970
                    if (tempX == tempResultX && tempY == tempResultY)
2971 68464385 gaqhf
                    {
2972 a0e3dca4 gaqhf
                        if (i == 0)
2973 68464385 gaqhf
                        {
2974 a0e3dca4 gaqhf
                            LMSymbol connSymbol = targetConnector.ConnectItem1SymbolObject;
2975 b01e7456 gaqhf
                            bool containZeroLength = false;
2976
                            if (connSymbol != null)
2977 a0e3dca4 gaqhf
                            {
2978 1805d3b7 gaqhf
                                foreach (LMConnector connector in connSymbol.Connect1Connectors)
2979
                                {
2980 b01e7456 gaqhf
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
2981 1805d3b7 gaqhf
                                        containZeroLength = true;
2982
                                }
2983
                                foreach (LMConnector connector in connSymbol.Connect2Connectors)
2984 a0e3dca4 gaqhf
                                {
2985 b01e7456 gaqhf
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
2986 1805d3b7 gaqhf
                                        containZeroLength = true;
2987 a0e3dca4 gaqhf
                                }
2988 b01e7456 gaqhf
                            }
2989
2990
                            if (connSymbol == null ||
2991
                                (connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") ||
2992
                                containZeroLength)
2993
                            {
2994
                                bool bCalcX = false;
2995
                                bool bCalcY = false;
2996
                                if (targetLine.SlopeType == SlopeType.HORIZONTAL)
2997
                                    bCalcX = true;
2998
                                else if (targetLine.SlopeType == SlopeType.VERTICAL)
2999
                                    bCalcY = true;
3000
                                else
3001
                                {
3002
                                    bCalcX = true;
3003
                                    bCalcY = true;
3004
                                }
3005 a0e3dca4 gaqhf
3006 b01e7456 gaqhf
                                if (bCalcX)
3007 a0e3dca4 gaqhf
                                {
3008 b01e7456 gaqhf
                                    double nextX = targetVertices[i + 1][0];
3009
                                    double newX = 0;
3010
                                    if (nextX > tempX)
3011
                                    {
3012
                                        newX = tempX + gridSetting.Length;
3013
                                        if (newX > nextX)
3014
                                            newX = (point[0] + nextX) / 2;
3015
                                    }
3016 a0e3dca4 gaqhf
                                    else
3017
                                    {
3018 b01e7456 gaqhf
                                        newX = tempX - gridSetting.Length;
3019
                                        if (newX < nextX)
3020
                                            newX = (point[0] + nextX) / 2;
3021 a0e3dca4 gaqhf
                                    }
3022 b01e7456 gaqhf
                                    resultPoint = new double[] { newX, resultPoint[1] };
3023
                                }
3024 a0e3dca4 gaqhf
3025 b01e7456 gaqhf
                                if (bCalcY)
3026
                                {
3027
                                    double nextY = targetVertices[i + 1][1];
3028
                                    double newY = 0;
3029
                                    if (nextY > tempY)
3030 a0e3dca4 gaqhf
                                    {
3031 b01e7456 gaqhf
                                        newY = tempY + gridSetting.Length;
3032
                                        if (newY > nextY)
3033
                                            newY = (point[1] + nextY) / 2;
3034 a0e3dca4 gaqhf
                                    }
3035 b01e7456 gaqhf
                                    else
3036 a0e3dca4 gaqhf
                                    {
3037 b01e7456 gaqhf
                                        newY = tempY - gridSetting.Length;
3038
                                        if (newY < nextY)
3039
                                            newY = (point[1] + nextY) / 2;
3040 a0e3dca4 gaqhf
                                    }
3041 b01e7456 gaqhf
                                    resultPoint = new double[] { resultPoint[0], newY };
3042 a0e3dca4 gaqhf
                                }
3043
                            }
3044
                        }
3045
                        else if (i == targetVertices.Count - 1)
3046
                        {
3047
                            LMSymbol connSymbol = targetConnector.ConnectItem2SymbolObject;
3048 b01e7456 gaqhf
                            bool containZeroLength = false;
3049
                            if (connSymbol != null)
3050 a0e3dca4 gaqhf
                            {
3051 1805d3b7 gaqhf
                                foreach (LMConnector connector in connSymbol.Connect1Connectors)
3052
                                {
3053 b01e7456 gaqhf
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
3054 1805d3b7 gaqhf
                                        containZeroLength = true;
3055
                                }
3056
                                foreach (LMConnector connector in connSymbol.Connect2Connectors)
3057 a0e3dca4 gaqhf
                                {
3058 b01e7456 gaqhf
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
3059 1805d3b7 gaqhf
                                        containZeroLength = true;
3060 a0e3dca4 gaqhf
                                }
3061 b01e7456 gaqhf
                            }
3062
3063
                            if (connSymbol == null ||
3064
                                 (connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") ||
3065
                                containZeroLength)
3066
                            {
3067
                                bool bCalcX = false;
3068
                                bool bCalcY = false;
3069
                                if (targetLine.SlopeType == SlopeType.HORIZONTAL)
3070
                                    bCalcX = true;
3071
                                else if (targetLine.SlopeType == SlopeType.VERTICAL)
3072
                                    bCalcY = true;
3073
                                else
3074
                                {
3075
                                    bCalcX = true;
3076
                                    bCalcY = true;
3077
                                }
3078 a0e3dca4 gaqhf
3079 b01e7456 gaqhf
                                if (bCalcX)
3080 a0e3dca4 gaqhf
                                {
3081 b01e7456 gaqhf
                                    double nextX = targetVertices[i - 1][0];
3082
                                    double newX = 0;
3083
                                    if (nextX > tempX)
3084
                                    {
3085
                                        newX = tempX + gridSetting.Length;
3086
                                        if (newX > nextX)
3087
                                            newX = (point[0] + nextX) / 2;
3088
                                    }
3089 a0e3dca4 gaqhf
                                    else
3090
                                    {
3091 b01e7456 gaqhf
                                        newX = tempX - gridSetting.Length;
3092
                                        if (newX < nextX)
3093
                                            newX = (point[0] + nextX) / 2;
3094 a0e3dca4 gaqhf
                                    }
3095 b01e7456 gaqhf
                                    resultPoint = new double[] { newX, resultPoint[1] };
3096
                                }
3097 a0e3dca4 gaqhf
3098 b01e7456 gaqhf
                                if (bCalcY)
3099
                                {
3100
                                    double nextY = targetVertices[i - 1][1];
3101
                                    double newY = 0;
3102
                                    if (nextY > tempY)
3103 a0e3dca4 gaqhf
                                    {
3104 b01e7456 gaqhf
                                        newY = tempY + gridSetting.Length;
3105
                                        if (newY > nextY)
3106
                                            newY = (point[1] + nextY) / 2;
3107 a0e3dca4 gaqhf
                                    }
3108 b01e7456 gaqhf
                                    else
3109 a0e3dca4 gaqhf
                                    {
3110 b01e7456 gaqhf
                                        newY = tempY - gridSetting.Length;
3111
                                        if (newY < nextY)
3112
                                            newY = (point[1] + nextY) / 2;
3113 a0e3dca4 gaqhf
                                    }
3114 b01e7456 gaqhf
                                    resultPoint = new double[] { resultPoint[0], newY };
3115 a0e3dca4 gaqhf
                                }
3116
                            }
3117 68464385 gaqhf
                        }
3118 a0e3dca4 gaqhf
                        break;
3119 68464385 gaqhf
                    }
3120
                }
3121
            }
3122
3123 a0e3dca4 gaqhf
            x = resultPoint[0];
3124
            y = resultPoint[1];
3125
3126 68464385 gaqhf
            return targetConnector;
3127
        }
3128
3129 1ff0105e gaqhf
        private LMConnector GetLMConnectorOnlyOne(string modelItemID)
3130
        {
3131
            LMConnector result = null;
3132
            List<LMConnector> connectors = new List<LMConnector>();
3133
            LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
3134
3135
            if (modelItem != null)
3136
            {
3137
                foreach (LMRepresentation rep in modelItem.Representations)
3138
                {
3139
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
3140
                        connectors.Add(dataSource.GetConnector(rep.Id));
3141
                }
3142
3143
                ReleaseCOMObjects(modelItem);
3144
            }
3145
3146
            if (connectors.Count == 1)
3147
                result = connectors[0];
3148
            else
3149
                foreach (var item in connectors)
3150
                    ReleaseCOMObjects(item);
3151
3152
            return result;
3153
        }
3154
3155 74752074 gaqhf
        /// <summary>
3156
        /// Line Number Symbol을 실제로 Modeling하는 메서드
3157
        /// </summary>
3158
        /// <param name="lineNumber"></param>
3159 8701de36 gaqhf
        private void LineNumberModelingOnlyOne(Line line)
3160 cfda1fed gaqhf
        {
3161 32205389 gaqhf
            LineNumber lineNumber = document.LINENUMBERS.Find(x => x.CONNLINE == line.UID);
3162
            if (lineNumber != null)
3163 10872260 gaqhf
            {
3164 32205389 gaqhf
                LMConnector connectedLMConnector = GetLMConnectorOnlyOne(line.SPPID.ModelItemId);
3165 340515a2 gaqhf
                if (connectedLMConnector != null)
3166
                {
3167
                    double x = 0;
3168
                    double y = 0;
3169
                    CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
3170 b65a7e32 gaqhf
3171 340515a2 gaqhf
                    Array points = new double[] { 0, x, y };
3172
                    LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false);
3173 cfda1fed gaqhf
3174 340515a2 gaqhf
                    if (_LmLabelPresist != null)
3175
                    {
3176
                        _LmLabelPresist.Commit();
3177
                        lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
3178
                        ReleaseCOMObjects(_LmLabelPresist);
3179
                    }
3180 c3d2e266 gaqhf
                }
3181 10872260 gaqhf
            }
3182 cfda1fed gaqhf
        }
3183 02a45794 gaqhf
3184 8701de36 gaqhf
        private void LineNumberModeling(LineNumber lineNumber)
3185
        {
3186
            Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line;
3187
            if (line != null)
3188
            {
3189
                double x = 0;
3190
                double y = 0;
3191
                CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
3192
3193
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
3194
                LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, x, y);
3195
                if (connectedLMConnector != null)
3196
                {
3197
                    Array points = new double[] { 0, x, y };
3198
                    LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false);
3199 ca6e0f51 gaqhf
3200 8701de36 gaqhf
                    if (_LmLabelPresist != null)
3201
                    {
3202
                        _LmLabelPresist.Commit();
3203
                        lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
3204
                        ReleaseCOMObjects(_LmLabelPresist);
3205
                    }
3206
                }
3207
3208
                foreach (var item in connectorVertices)
3209
                    ReleaseCOMObjects(item.Key);
3210
            }
3211
        }
3212 74752074 gaqhf
        /// <summary>
3213 b2d1c1aa gaqhf
        /// Flow Mark Modeling
3214
        /// </summary>
3215
        /// <param name="line"></param>
3216
        private void FlowMarkModeling(Line line)
3217
        {
3218 a0965e07 gaqhf
            if (line.FLOWMARK && !string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(_ETCSetting.FlowMarkSymbolPath))
3219 b2d1c1aa gaqhf
            {
3220 32205389 gaqhf
                LMConnector connector = GetLMConnectorOnlyOne(line.SPPID.ModelItemId);
3221
                if (connector != null)
3222 b2d1c1aa gaqhf
                {
3223 32205389 gaqhf
                    string mappingPath = _ETCSetting.FlowMarkSymbolPath;
3224
                    List<double[]> vertices = GetConnectorVertices(connector);
3225
                    vertices = vertices.FindAll(x => x[0] > 0 && x[1] > 0);
3226
                    double[] point = vertices[vertices.Count - 1];
3227
                    Array array = new double[] { 0, point[0], point[1] };
3228
                    LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mappingPath, ref array, LabeledItem: connector.AsLMRepresentation());
3229
                    if (_LMLabelPersist != null)
3230
                        ReleaseCOMObjects(_LMLabelPersist);
3231 b2d1c1aa gaqhf
                }
3232
            }
3233
        }
3234
3235
        /// <summary>
3236 74752074 gaqhf
        /// Line Number 기준으로 모든 Item에 Line Number의 Attribute Input
3237
        /// </summary>
3238
        /// <param name="lineNumber"></param>
3239 82d6e5ea gaqhf
        private void InputLineNumberAttribute(LineNumber lineNumber, List<string> endLine)
3240 a7e9beec gaqhf
        {
3241 8634af60 gaqhf
            foreach (LineRun run in lineNumber.RUNS)
3242 a7e9beec gaqhf
            {
3243 8634af60 gaqhf
                foreach (var item in run.RUNITEMS)
3244 a7e9beec gaqhf
                {
3245 48fd75e2 gaqhf
                    if (item.GetType() == typeof(Symbol))
3246
                    {
3247
                        Symbol symbol = item as Symbol;
3248
                        LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
3249
                        if (_LMSymbol != null)
3250
                        {
3251
                            LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
3252
3253
                            if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3254
                            {
3255
                                foreach (var attribute in lineNumber.ATTRIBUTES)
3256
                                {
3257
                                    LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
3258
                                    if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3259
                                    {
3260
                                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
3261
                                        if (_LMAAttribute != null)
3262
                                        {
3263
                                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3264
                                                _LMAAttribute.set_Value(attribute.VALUE);
3265
                                            else if (_LMAAttribute.get_Value() != attribute.VALUE)
3266
                                                _LMAAttribute.set_Value(attribute.VALUE);
3267
                                        }
3268
                                    }
3269
                                }
3270
                                _LMModelItem.Commit();
3271
                            }
3272
                            if (_LMModelItem != null)
3273
                                ReleaseCOMObjects(_LMModelItem);
3274
                        }
3275
                        if (_LMSymbol != null)
3276
                            ReleaseCOMObjects(_LMSymbol);
3277
                    }
3278
                    else if (item.GetType() == typeof(Line))
3279 8634af60 gaqhf
                    {
3280
                        Line line = item as Line;
3281 82d6e5ea gaqhf
                        if (line != null && !endLine.Contains(line.SPPID.ModelItemId))
3282 a7e9beec gaqhf
                        {
3283 8634af60 gaqhf
                            LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
3284
                            if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3285 a7e9beec gaqhf
                            {
3286 8634af60 gaqhf
                                foreach (var attribute in lineNumber.ATTRIBUTES)
3287
                                {
3288
                                    LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
3289 b2d1c1aa gaqhf
                                    if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3290 8634af60 gaqhf
                                    {
3291
                                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
3292
                                        if (_LMAAttribute != null)
3293
                                        {
3294
                                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3295
                                                _LMAAttribute.set_Value(attribute.VALUE);
3296
                                            else if (_LMAAttribute.get_Value() != attribute.VALUE)
3297
                                                _LMAAttribute.set_Value(attribute.VALUE);
3298 7f00b26c gaqhf
3299 8634af60 gaqhf
                                        }
3300
                                    }
3301
                                }
3302 68464385 gaqhf
                                _LMModelItem.Commit();
3303 a7e9beec gaqhf
                            }
3304 8634af60 gaqhf
                            if (_LMModelItem != null)
3305
                                ReleaseCOMObjects(_LMModelItem);
3306 82d6e5ea gaqhf
                            endLine.Add(line.SPPID.ModelItemId);
3307 a7e9beec gaqhf
                        }
3308
                    }
3309
                }
3310
            }
3311
        }
3312
3313 74752074 gaqhf
        /// <summary>
3314
        /// Symbol Attribute 입력 메서드
3315
        /// </summary>
3316 73415441 gaqhf
        /// <param name="item"></param>
3317
        private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes)
3318 1efc25a3 gaqhf
        {
3319 7f00b26c gaqhf
            // Object 아이템이 Symbol일 경우 Equipment일 경우 
3320
            string sRep = null;
3321
            if (targetItem.GetType() == typeof(Symbol))
3322
                sRep = ((Symbol)targetItem).SPPID.RepresentationId;
3323
            else if (targetItem.GetType() == typeof(Equipment))
3324
                sRep = ((Equipment)targetItem).SPPID.RepresentationId;
3325
3326
            if (!string.IsNullOrEmpty(sRep))
3327 1efc25a3 gaqhf
            {
3328 7f00b26c gaqhf
                LMSymbol _LMSymbol = dataSource.GetSymbol(sRep);
3329
                LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
3330
                LMAAttributes _Attributes = _LMModelItem.Attributes;
3331 ca6e0f51 gaqhf
                
3332 7f00b26c gaqhf
                foreach (var item in targetAttributes)
3333
                {
3334
                    AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
3335
                    if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None")
3336 65a1ed4b gaqhf
                    {
3337 7f00b26c gaqhf
                        LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
3338
                        if (_Attribute != null)
3339 30ba9ae0 gaqhf
                        {
3340
                            object associItem = SPPIDUtil.FindObjectByUID(document, item.ASSOCITEM);
3341
                            if (associItem != null)
3342
                            {
3343
                                if (associItem.GetType() == typeof(Text))
3344
                                {
3345
                                    Text text = associItem as Text;
3346
                                    text.SPPID.RepresentationId = "Attribute";
3347
                                }
3348
                                else if (associItem.GetType() == typeof(Note))
3349
                                {
3350
                                    Note note = associItem as Note;
3351
                                    note.SPPID.RepresentationId = "Attribute";
3352
                                }
3353
                            }
3354 7f00b26c gaqhf
                            _Attribute.set_Value(item.VALUE);
3355 30ba9ae0 gaqhf
                        }
3356
                            
3357 65a1ed4b gaqhf
                    }
3358 ac78b508 gaqhf
                }
3359 7f00b26c gaqhf
                _LMModelItem.Commit();
3360
3361
                ReleaseCOMObjects(_Attributes);
3362
                ReleaseCOMObjects(_LMModelItem);
3363
                ReleaseCOMObjects(_LMSymbol);
3364 1efc25a3 gaqhf
            }
3365
        }
3366
3367 74752074 gaqhf
        /// <summary>
3368 16584d30 gaqhf
        /// Input SpecBreak Attribute
3369
        /// </summary>
3370
        /// <param name="specBreak"></param>
3371
        private void InputSpecBreakAttribute(SpecBreak specBreak)
3372
        {
3373 7f00b26c gaqhf
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
3374
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
3375
3376
            if (upStreamObj != null &&
3377
                downStreamObj != null)
3378 16584d30 gaqhf
            {
3379 7f00b26c gaqhf
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
3380 16584d30 gaqhf
3381 7f00b26c gaqhf
                if (targetLMConnector != null)
3382 16584d30 gaqhf
                {
3383 7f00b26c gaqhf
                    foreach (LMLabelPersist _LMLabelPersist in targetLMConnector.LabelPersists)
3384 16584d30 gaqhf
                    {
3385 7f00b26c gaqhf
                        string symbolPath = _LMLabelPersist.get_FileName();
3386
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.SPPIDSYMBOLNAME == symbolPath);
3387
                        if (mapping != null)
3388 16584d30 gaqhf
                        {
3389 7f00b26c gaqhf
                            BaseModel.Attribute attribute = specBreak.ATTRIBUTES.Find(y => y.UID == mapping.UID);
3390
                            if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3391 16584d30 gaqhf
                            {
3392 7f00b26c gaqhf
                                string[] values = attribute.VALUE.Split(new char[] { ',' });
3393
                                if (values.Length == 2)
3394 16584d30 gaqhf
                                {
3395 7f00b26c gaqhf
                                    string upStreamValue = values[0];
3396
                                    string downStreamValue = values[1];
3397 16584d30 gaqhf
3398 7f00b26c gaqhf
                                    InputAttributeForSpecBreak(upStreamObj, downStreamObj, upStreamValue, downStreamValue, mapping.SPPIDATTRIBUTENAME);
3399 16584d30 gaqhf
                                }
3400
                            }
3401
                        }
3402
                    }
3403 7f00b26c gaqhf
3404
                    ReleaseCOMObjects(targetLMConnector);
3405 16584d30 gaqhf
                }
3406
            }
3407 7f00b26c gaqhf
3408 16584d30 gaqhf
3409
            #region 내부에서만 쓰는 메서드
3410 7f00b26c gaqhf
            void InputAttributeForSpecBreak(object _upStreamObj, object _downStreamObj, string upStreamValue, string downStreamValue, string sppidAttributeName)
3411 16584d30 gaqhf
            {
3412 7f00b26c gaqhf
                Symbol upStreamSymbol = _upStreamObj as Symbol;
3413
                Line upStreamLine = _upStreamObj as Line;
3414
                Symbol downStreamSymbol = _downStreamObj as Symbol;
3415
                Line downStreamLine = _downStreamObj as Line;
3416
                // 둘다 Line일 경우
3417
                if (upStreamLine != null && downStreamLine != null)
3418 16584d30 gaqhf
                {
3419 7f00b26c gaqhf
                    InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
3420
                    InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
3421
                }
3422
                // 둘다 Symbol일 경우
3423
                else if (upStreamSymbol != null && downStreamSymbol != null)
3424
                {
3425
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamSymbol);
3426
                    LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
3427
                    LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
3428 16584d30 gaqhf
3429 7f00b26c gaqhf
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
3430
                    {
3431
                        if (connector.get_ItemStatus() != "Active")
3432
                            continue;
3433 16584d30 gaqhf
3434 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
3435
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3436
                    }
3437 16584d30 gaqhf
3438 7f00b26c gaqhf
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
3439
                    {
3440
                        if (connector.get_ItemStatus() != "Active")
3441
                            continue;
3442 16584d30 gaqhf
3443 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
3444
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3445
                    }
3446 16584d30 gaqhf
3447 7f00b26c gaqhf
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
3448
                    {
3449
                        if (connector.get_ItemStatus() != "Active")
3450
                            continue;
3451 16584d30 gaqhf
3452 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
3453
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3454
                    }
3455 16584d30 gaqhf
3456 7f00b26c gaqhf
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
3457
                    {
3458
                        if (connector.get_ItemStatus() != "Active")
3459
                            continue;
3460 16584d30 gaqhf
3461 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
3462
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3463 16584d30 gaqhf
                    }
3464
3465 7f00b26c gaqhf
                    ReleaseCOMObjects(zeroLenthConnector);
3466
                    ReleaseCOMObjects(upStreamLMSymbol);
3467
                    ReleaseCOMObjects(downStreamLMSymbol);
3468
                }
3469
                else if (upStreamSymbol != null && downStreamLine != null)
3470
                {
3471
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamLine);
3472
                    InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
3473
                    LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
3474 16584d30 gaqhf
3475 7f00b26c gaqhf
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
3476
                    {
3477
                        if (connector.get_ItemStatus() != "Active")
3478
                            continue;
3479 16584d30 gaqhf
3480 c993d55a gaqhf
                        if (connector.Id == zeroLenthConnector.Id)
3481 7f00b26c gaqhf
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3482
                    }
3483 16584d30 gaqhf
3484 7f00b26c gaqhf
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
3485
                    {
3486
                        if (connector.get_ItemStatus() != "Active")
3487
                            continue;
3488 16584d30 gaqhf
3489 c993d55a gaqhf
                        if (connector.Id == zeroLenthConnector.Id)
3490 7f00b26c gaqhf
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3491 16584d30 gaqhf
                    }
3492
3493 7f00b26c gaqhf
                    ReleaseCOMObjects(zeroLenthConnector);
3494
                    ReleaseCOMObjects(upStreamLMSymbol);
3495
                }
3496
                else if (upStreamLine != null && downStreamSymbol != null)
3497
                {
3498
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamLine, downStreamSymbol);
3499
                    InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
3500
                    LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
3501 16584d30 gaqhf
3502 7f00b26c gaqhf
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
3503
                    {
3504
                        if (connector.get_ItemStatus() != "Active")
3505
                            continue;
3506 16584d30 gaqhf
3507 c993d55a gaqhf
                        if (connector.Id == zeroLenthConnector.Id)
3508 7f00b26c gaqhf
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3509
                    }
3510 16584d30 gaqhf
3511 7f00b26c gaqhf
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
3512
                    {
3513
                        if (connector.get_ItemStatus() != "Active")
3514
                            continue;
3515 16584d30 gaqhf
3516 c993d55a gaqhf
                        if (connector.Id == zeroLenthConnector.Id)
3517 7f00b26c gaqhf
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3518 16584d30 gaqhf
                    }
3519 7f00b26c gaqhf
3520
                    ReleaseCOMObjects(zeroLenthConnector);
3521
                    ReleaseCOMObjects(downStreamLMSymbol);
3522 16584d30 gaqhf
                }
3523
            }
3524
3525
            void InputLineAttributeForSpecBreakLine(Line line, string attrName, string value)
3526
            {
3527 7f00b26c gaqhf
                LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
3528
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3529 16584d30 gaqhf
                {
3530 7f00b26c gaqhf
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
3531
                    if (_LMAAttribute != null)
3532 16584d30 gaqhf
                    {
3533 7f00b26c gaqhf
                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3534
                            _LMAAttribute.set_Value(value);
3535
                        else if (_LMAAttribute.get_Value() != value)
3536
                            _LMAAttribute.set_Value(value);
3537 16584d30 gaqhf
                    }
3538 7f00b26c gaqhf
3539
                    _LMModelItem.Commit();
3540 16584d30 gaqhf
                }
3541 7f00b26c gaqhf
                if (_LMModelItem != null)
3542
                    ReleaseCOMObjects(_LMModelItem);
3543 16584d30 gaqhf
            }
3544
3545
            void InputLineAttributeForSpecBreakLMConnector(LMConnector connector, string attrName, string value)
3546
            {
3547 7f00b26c gaqhf
                LMModelItem _LMModelItem = dataSource.GetModelItem(connector.ModelItemID);
3548
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3549 16584d30 gaqhf
                {
3550 7f00b26c gaqhf
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
3551
                    if (_LMAAttribute != null)
3552 16584d30 gaqhf
                    {
3553 7f00b26c gaqhf
                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3554
                            _LMAAttribute.set_Value(value);
3555
                        else if (_LMAAttribute.get_Value() != value)
3556
                            _LMAAttribute.set_Value(value);
3557 16584d30 gaqhf
                    }
3558 7f00b26c gaqhf
3559
                    _LMModelItem.Commit();
3560 16584d30 gaqhf
                }
3561 7f00b26c gaqhf
                if (_LMModelItem != null)
3562
                    ReleaseCOMObjects(_LMModelItem);
3563 16584d30 gaqhf
            }
3564
            #endregion
3565
        }
3566
3567
        /// <summary>
3568 74752074 gaqhf
        /// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링
3569
        /// </summary>
3570
        /// <param name="text"></param>
3571 cfda1fed gaqhf
        private void TextModeling(Text text)
3572
        {
3573 6b298450 gaqhf
            LMSymbol _LMSymbol = null;
3574 0860c756 gaqhf
            LMConnector connectedLMConnector = null;
3575 7f00b26c gaqhf
            //if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None")
3576
            if (text.ASSOCIATION)
3577 6b298450 gaqhf
            {
3578 7f00b26c gaqhf
                object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
3579 3783c494 gaqhf
                if (owner != null && owner.GetType() == typeof(Symbol))
3580 ea80efaa gaqhf
                {
3581 7f00b26c gaqhf
                    Symbol symbol = owner as Symbol;
3582
                    _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
3583
                    if (_LMSymbol != null)
3584 ea80efaa gaqhf
                    {
3585 7f00b26c gaqhf
                        BaseModel.Attribute attribute = symbol.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
3586 3734dcc5 gaqhf
                        if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3587 0860c756 gaqhf
                        {
3588 7f00b26c gaqhf
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
3589 0860c756 gaqhf
3590
                            if (mapping != null)
3591
                            {
3592
                                double x = 0;
3593
                                double y = 0;
3594
3595
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
3596
                                Array array = new double[] { 0, x, y };
3597
3598 7f00b26c gaqhf
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
3599 0860c756 gaqhf
                                if (_LMLabelPersist != null)
3600
                                {
3601 30ba9ae0 gaqhf
                                    text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id;
3602 0860c756 gaqhf
                                    _LMLabelPersist.Commit();
3603
                                    ReleaseCOMObjects(_LMLabelPersist);
3604
                                }
3605
                            }
3606
                        }
3607 ea80efaa gaqhf
                    }
3608
                }
3609 3783c494 gaqhf
                else if (owner != null && owner.GetType() == typeof(Line))
3610 ea80efaa gaqhf
                {
3611 7f00b26c gaqhf
                    Line line = owner as Line;
3612
                    Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
3613
                    connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y);
3614 ea80efaa gaqhf
3615 7f00b26c gaqhf
                    if (connectedLMConnector != null)
3616
                    {
3617 83c14a07 gaqhf
                        BaseModel.Attribute attribute = line.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
3618
                        if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3619 7f00b26c gaqhf
                        {
3620 83c14a07 gaqhf
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
3621 7f00b26c gaqhf
3622
                            if (mapping != null)
3623 83c14a07 gaqhf
                            {
3624
                                double x = 0;
3625
                                double y = 0;
3626 b65a7e32 gaqhf
3627 83c14a07 gaqhf
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
3628
                                Array array = new double[] { 0, x, y };
3629 ea80efaa gaqhf
3630 83c14a07 gaqhf
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
3631
                                if (_LMLabelPersist != null)
3632
                                {
3633 30ba9ae0 gaqhf
                                    text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id;
3634 83c14a07 gaqhf
                                    _LMLabelPersist.Commit();
3635
                                    ReleaseCOMObjects(_LMLabelPersist);
3636
                                }
3637 7f00b26c gaqhf
                            }
3638
                        }
3639
                    }
3640 ea80efaa gaqhf
                }
3641 6b298450 gaqhf
            }
3642 7f00b26c gaqhf
            else
3643 6b298450 gaqhf
            {
3644 7f00b26c gaqhf
                LMItemNote _LMItemNote = null;
3645
                LMAAttribute _LMAAttribute = null;
3646 cfda1fed gaqhf
3647 7f00b26c gaqhf
                double x = 0;
3648
                double y = 0;
3649
                double angle = text.ANGLE;
3650
                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation);
3651
3652
                _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y, Rotation: angle);
3653 30ba9ae0 gaqhf
                if (_LMSymbol != null)
3654
                {
3655
                    _LMSymbol.Commit();
3656
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
3657
                    if (_LMItemNote != null)
3658
                    {
3659
                        _LMItemNote.Commit();
3660
                        _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
3661
                        if (_LMAAttribute != null)
3662
                        {
3663
                            _LMAAttribute.set_Value(text.VALUE);
3664
                            text.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
3665
                            _LMItemNote.Commit();
3666
3667
                            if (_LMAAttribute != null)
3668
                                ReleaseCOMObjects(_LMAAttribute);
3669
                            if (_LMItemNote != null)
3670
                                ReleaseCOMObjects(_LMItemNote);
3671
                        }
3672
                    }
3673
                }
3674 6b298450 gaqhf
            }
3675 7f00b26c gaqhf
            if (_LMSymbol != null)
3676
                ReleaseCOMObjects(_LMSymbol);
3677 cfda1fed gaqhf
        }
3678
3679 74752074 gaqhf
        /// <summary>
3680
        /// Note Modeling
3681
        /// </summary>
3682
        /// <param name="note"></param>
3683 cfda1fed gaqhf
        private void NoteModeling(Note note)
3684
        {
3685 6b298450 gaqhf
            LMSymbol _LMSymbol = null;
3686
            LMItemNote _LMItemNote = null;
3687
            LMAAttribute _LMAAttribute = null;
3688
3689 7f00b26c gaqhf
            if (string.IsNullOrEmpty(note.OWNER) || note.OWNER == "None")
3690 6b298450 gaqhf
            {
3691 7f00b26c gaqhf
                double x = 0;
3692
                double y = 0;
3693 fc0a8c33 gaqhf
3694 7f00b26c gaqhf
                CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation);
3695 fc0a8c33 gaqhf
3696 7f00b26c gaqhf
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y);
3697 30ba9ae0 gaqhf
                if (_LMSymbol != null)
3698
                {
3699
                    _LMSymbol.Commit();
3700
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
3701
                    if (_LMItemNote != null)
3702
                    {
3703
                        _LMItemNote.Commit();
3704
                        _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
3705
                        if (_LMAAttribute != null)
3706
                        {
3707
                            _LMAAttribute.set_Value(note.VALUE);
3708
                            note.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
3709
                            _LMItemNote.Commit();
3710
                        }
3711
                    }
3712
                }
3713 6b298450 gaqhf
            }
3714 cfda1fed gaqhf
3715 7f00b26c gaqhf
            if (_LMAAttribute != null)
3716
                ReleaseCOMObjects(_LMAAttribute);
3717
            if (_LMItemNote != null)
3718
                ReleaseCOMObjects(_LMItemNote);
3719
            if (_LMSymbol != null)
3720
                ReleaseCOMObjects(_LMSymbol);
3721 cfda1fed gaqhf
        }
3722
3723 a31a512e gaqhf
        private void JoinRunBySameType(string modelItemId, ref string survivorId)
3724 ca6e0f51 gaqhf
        {
3725 a31a512e gaqhf
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
3726
            if (modelItem != null)
3727 ca6e0f51 gaqhf
            {
3728 a31a512e gaqhf
                foreach (LMRepresentation rep in modelItem.Representations)
3729
                {
3730
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
3731
                    {
3732
                        LMConnector connector = dataSource.GetConnector(rep.Id);
3733
                        if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch")
3734
                        {
3735
                            LMSymbol symbol = connector.ConnectItem1SymbolObject;
3736
                            List<string> modelItemIds = FindOtherModelItemBySymbolWhereTypePipeRun(symbol, modelItem.Id);
3737
                            if (modelItemIds.Count == 1)
3738
                            {
3739 d77973b3 gaqhf
                                string joinModelItemId = modelItemIds[0];
3740
                                JoinRun(joinModelItemId, modelItemId, ref survivorId);
3741 a31a512e gaqhf
                                if (survivorId != null)
3742
                                    break;
3743
                            }
3744
                        }
3745
                        if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch")
3746
                        {
3747
                            LMSymbol symbol = connector.ConnectItem2SymbolObject;
3748
                            List<string> modelItemIds = FindOtherModelItemBySymbolWhereTypePipeRun(symbol, modelItem.Id);
3749
                            if (modelItemIds.Count == 1)
3750
                            {
3751 d77973b3 gaqhf
                                string joinModelItemId = modelItemIds[0];
3752
                                JoinRun(joinModelItemId, modelItemId, ref survivorId);
3753 a31a512e gaqhf
                                if (survivorId != null)
3754
                                    break;
3755
                            }
3756
                        }
3757
                    }
3758
                }
3759 ca6e0f51 gaqhf
            }
3760 dec9ecfd gaqhf
        }
3761
3762 d9794a6c gaqhf
        /// <summary>
3763 74752074 gaqhf
        /// Label의 좌표를 구하는 메서드(ID2 기준의 좌표 -> SPPID 좌표)
3764
        /// </summary>
3765
        /// <param name="x"></param>
3766
        /// <param name="y"></param>
3767
        /// <param name="originX"></param>
3768
        /// <param name="originY"></param>
3769
        /// <param name="SPPIDLabelLocation"></param>
3770
        /// <param name="location"></param>
3771 b65a7e32 gaqhf
        private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location)
3772
        {
3773
            if (location == Location.None)
3774
            {
3775
                x = originX;
3776
                y = originY;
3777
            }
3778
            else
3779
            {
3780
                if (location.HasFlag(Location.Center))
3781
                {
3782
                    x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2;
3783
                    y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2;
3784
                }
3785
3786
                if (location.HasFlag(Location.Left))
3787
                    x = SPPIDLabelLocation.X1;
3788
                else if (location.HasFlag(Location.Right))
3789
                    x = SPPIDLabelLocation.X2;
3790
3791
                if (location.HasFlag(Location.Down))
3792
                    y = SPPIDLabelLocation.Y1;
3793
                else if (location.HasFlag(Location.Up))
3794
                    y = SPPIDLabelLocation.Y2;
3795
            }
3796
        }
3797 5a4b8f32 gaqhf
3798 74752074 gaqhf
        /// <summary>
3799 4d2571ab gaqhf
        /// Symbol의 우선순위 Modeling 목록을 가져온다.
3800
        /// 1. Angle Valve
3801
        /// 2. 3개로 이루어진 Symbol Group
3802
        /// </summary>
3803
        /// <returns></returns>
3804
        private List<Symbol> GetPrioritySymbol()
3805
        {
3806
            DataTable symbolTable = document.SymbolTable;
3807
            // List에 순서대로 쌓는다.
3808
            List<Symbol> symbols = new List<Symbol>();
3809 3734dcc5 gaqhf
3810 4d2571ab gaqhf
            // Angle Valve 부터
3811 d9794a6c gaqhf
            foreach (var symbol in document.SYMBOLS.FindAll(x => x.CONNECTORS.FindAll(y => y.Index == 0).Count == 2))
3812 4d2571ab gaqhf
            {
3813
                if (!symbols.Contains(symbol))
3814
                {
3815
                    double originX = 0;
3816
                    double originY = 0;
3817
3818
                    // ID2 Table에서 Original Point 가져옴.
3819 7f00b26c gaqhf
                    string OriginalPoint = symbolTable.Select(string.Format("UID = {0}", symbol.DBUID))[0]["OriginalPoint"].ToString();
3820 4d2571ab gaqhf
                    SPPIDUtil.ConvertPointBystring(OriginalPoint, ref originX, ref originY);
3821
3822
                    SlopeType slopeType1 = SlopeType.None;
3823
                    SlopeType slopeType2 = SlopeType.None;
3824 d9794a6c gaqhf
                    foreach (Connector connector in symbol.CONNECTORS.FindAll(x => x.Index == 0))
3825 4d2571ab gaqhf
                    {
3826
                        double connectorX = 0;
3827
                        double connectorY = 0;
3828
                        SPPIDUtil.ConvertPointBystring(connector.CONNECTPOINT, ref connectorX, ref connectorY);
3829
                        if (slopeType1 == SlopeType.None)
3830
                            slopeType1 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
3831
                        else
3832
                            slopeType2 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
3833
                    }
3834
3835
                    if ((slopeType1 == SlopeType.VERTICAL && slopeType2 == SlopeType.HORIZONTAL) ||
3836
                        (slopeType2 == SlopeType.VERTICAL && slopeType1 == SlopeType.HORIZONTAL))
3837
                        symbols.Add(symbol);
3838
                }
3839
            }
3840
3841 f1a7faf9 gaqhf
            List<Symbol> tempSymbols = new List<Symbol>();
3842
            // Conn 갯수 기준
3843 d9794a6c gaqhf
            foreach (var item in document.SYMBOLS)
3844
            {
3845 f1a7faf9 gaqhf
                if (!symbols.Contains(item))
3846
                    tempSymbols.Add(item);
3847 d9794a6c gaqhf
            }
3848 f1a7faf9 gaqhf
            tempSymbols.Sort(SortSymbolPriority);
3849
            symbols.AddRange(tempSymbols);
3850 4d2571ab gaqhf
3851
            return symbols;
3852
        }
3853
3854 cf210438 gaqhf
        private void SetPriorityLine(List<Line> lines)
3855 d63050d6 gaqhf
        {
3856 cf210438 gaqhf
            lines.Sort(SortLinePriority);
3857 d63050d6 gaqhf
3858
            int SortLinePriority(Line a, Line b)
3859
            {
3860
                // Branch 없는것부터
3861
                int branchRetval = CompareBranchLine(a, b);
3862
                if (branchRetval != 0)
3863
                {
3864
                    return branchRetval;
3865
                }
3866
                else
3867
                {
3868
                    // Symbol 연결 갯수
3869
                    int connSymbolRetval = CompareConnSymbol(a, b);
3870
                    if (connSymbolRetval != 0)
3871
                    {
3872
                        return connSymbolRetval;
3873
                    }
3874
                    else
3875
                    {
3876 24515a3a gaqhf
                        // 아이템 연결 갯수(심볼, Line이면서 Not Branch)
3877
                        int connItemRetval = CompareConnItem(a, b);
3878
                        if (connItemRetval != 0)
3879 d63050d6 gaqhf
                        {
3880 24515a3a gaqhf
                            return connItemRetval;
3881 d63050d6 gaqhf
                        }
3882
                        else
3883
                        {
3884 24515a3a gaqhf
                            // ConnectedItem이 없는것
3885
                            int noneConnRetval = CompareNoneConn(a, b);
3886
                            if (noneConnRetval != 0)
3887 d63050d6 gaqhf
                            {
3888 24515a3a gaqhf
                                return noneConnRetval;
3889 d63050d6 gaqhf
                            }
3890
                            else
3891
                            {
3892
3893
                            }
3894
                        }
3895
                    }
3896
                }
3897
3898
                return 0;
3899
            }
3900
3901 e283d483 gaqhf
            int CompareNotSegmentLine(Line a, Line b)
3902
            {
3903
                List<Connector> connectorsA = a.CONNECTORS
3904
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
3905
                    .ToList();
3906
3907
                List<Connector> connectorsB = b.CONNECTORS
3908
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
3909
                    .ToList();
3910
3911
                // 오름차순
3912
                return connectorsB.Count.CompareTo(connectorsA.Count);
3913
            }
3914
3915 d63050d6 gaqhf
            int CompareConnSymbol(Line a, Line b)
3916
            {
3917
                List<Connector> connectorsA = a.CONNECTORS
3918
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
3919
                    .ToList();
3920
3921
                List<Connector> connectorsB = b.CONNECTORS
3922
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
3923
                    .ToList();
3924
3925
                // 오름차순
3926
                return connectorsB.Count.CompareTo(connectorsA.Count);
3927
            }
3928
3929
            int CompareConnItem(Line a, Line b)
3930
            {
3931
                List<Connector> connectorsA = a.CONNECTORS
3932
                    .Where(conn => conn.ConnectedObject != null && 
3933
                    (conn.ConnectedObject.GetType() == typeof(Symbol) || 
3934
                    (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, a))))
3935
                    .ToList();
3936
3937
                List<Connector> connectorsB = b.CONNECTORS
3938
                    .Where(conn => conn.ConnectedObject != null &&
3939
                    (conn.ConnectedObject.GetType() == typeof(Symbol) ||
3940
                    (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, b))))
3941
                    .ToList();
3942
3943
                // 오름차순
3944
                return connectorsB.Count.CompareTo(connectorsA.Count);
3945
            }
3946
3947
            int CompareBranchLine(Line a, Line b)
3948
            {
3949
                List<Connector> connectorsA = a.CONNECTORS
3950
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(a, conn.ConnectedObject as Line))
3951
                    .ToList();
3952
                List<Connector> connectorsB = b.CONNECTORS
3953
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(b, conn.ConnectedObject as Line))
3954
                    .ToList();
3955
3956
                // 내림차순
3957
                return connectorsA.Count.CompareTo(connectorsB.Count);
3958
            }
3959
3960
            int CompareNoneConn(Line a, Line b)
3961
            {
3962
                List<Connector> connectorsA = a.CONNECTORS
3963
                    .Where(conn => conn.ConnectedObject == null)
3964
                    .ToList();
3965
3966
                List<Connector> connectorsB = b.CONNECTORS
3967
                    .Where(conn => conn.ConnectedObject == null)
3968
                    .ToList();
3969
3970
                // 오름차순
3971
                return connectorsB.Count.CompareTo(connectorsA.Count);
3972
            }
3973
        }
3974
3975 a0e3dca4 gaqhf
        private void SortBranchLines()
3976
        {
3977 f3e2693f gaqhf
            BranchLines.Sort(SortBranchLine);
3978 a0e3dca4 gaqhf
            int SortBranchLine(Line a, Line b)
3979
            {
3980
                int countA = a.CONNECTORS.FindAll(x => x.ConnectedObject != null &&
3981
                 x.ConnectedObject.GetType() == typeof(Line) &&
3982
                 SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, a) &&
3983
                 string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count;
3984
3985
                int countB = b.CONNECTORS.FindAll(x => x.ConnectedObject != null &&
3986
                 x.ConnectedObject.GetType() == typeof(Line) &&
3987
                 SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, b) &&
3988
                 string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count;
3989
3990
                // 내림차순
3991
                return countA.CompareTo(countB);
3992
            }
3993
        }
3994
3995 f1a7faf9 gaqhf
        private static int SortSymbolPriority(Symbol a, Symbol b)
3996
        {
3997
            int countA = a.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count;
3998
            int countB = b.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count;
3999
            int retval = countB.CompareTo(countA);
4000
            if (retval != 0)
4001
                return retval;
4002
            else
4003
                return a.SPPID.ORIGINAL_X.CompareTo(b.SPPID.ORIGINAL_X);
4004
        }
4005
4006 a31a512e gaqhf
        private string GetSPPIDFileName(LMModelItem modelItem)
4007
        {
4008
            string symbolPath = null;
4009
            foreach (LMRepresentation rep in modelItem.Representations)
4010
            {
4011
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
4012
                {
4013
                    symbolPath = rep.get_FileName();
4014
                    break;
4015
                }
4016
            }
4017
            return symbolPath;
4018
        }
4019
4020 82d6e5ea gaqhf
        private string GetSPPIDFileName(string modelItemId)
4021
        {
4022
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
4023
            string symbolPath = null;
4024
            foreach (LMRepresentation rep in modelItem.Representations)
4025
            {
4026
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
4027
                {
4028
                    symbolPath = rep.get_FileName();
4029
                    break;
4030
                }
4031
            }
4032
            ReleaseCOMObjects(modelItem);
4033
            return symbolPath;
4034
        }
4035
4036 4d2571ab gaqhf
        /// <summary>
4037 b2d1c1aa gaqhf
        /// Graphic OID로 해당 Symbol의 크기를 구하여 Zoom
4038
        /// </summary>
4039
        /// <param name="graphicOID"></param>
4040
        /// <param name="milliseconds"></param>
4041
        private void ZoomObjectByGraphicOID(string graphicOID, int milliseconds = 150)
4042
        {
4043
            if (radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] != null)
4044
            {
4045
                double minX = 0;
4046
                double minY = 0;
4047
                double maxX = 0;
4048
                double maxY = 0;
4049
                radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID].Range(out minX, out minY, out maxX, out maxY);
4050
                radApp.ActiveWindow.ZoomArea2(minX - 0.007, minY - 0.007, maxX + 0.007, maxY + 0.007, null);
4051
4052
                Thread.Sleep(milliseconds);
4053
            }
4054
        }
4055
4056
        /// <summary>
4057 74752074 gaqhf
        /// ComObject를 Release
4058
        /// </summary>
4059
        /// <param name="objVars"></param>
4060 5a4b8f32 gaqhf
        public void ReleaseCOMObjects(params object[] objVars)
4061
        {
4062 02a45794 gaqhf
            if (objVars != null)
4063 5a4b8f32 gaqhf
            {
4064 02a45794 gaqhf
                int intNewRefCount = 0;
4065
                foreach (object obj in objVars)
4066
                {
4067
                    if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
4068
                        intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
4069
                }
4070 5a4b8f32 gaqhf
            }
4071
        }
4072 cfda1fed gaqhf
    }
4073
}