프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ a9773437

이력 | 보기 | 이력해설 | 다운로드 (261 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 5a9396ae humkyung
    public class AutoModeling : IDisposable
28 cfda1fed gaqhf
    {
29 809a7640 gaqhf
        Placement _placement;
30
        LMADataSource dataSource;
31 4941f5fe gaqhf
        string drawingID;
32 1ba9c671 gaqhf
        dynamic newDrawing;
33 d19ae675 gaqhf
        dynamic application;
34 442bd51e gaqhf
        bool closeDocument;
35 5e6ecf05 gaqhf
        Ingr.RAD2D.Application radApp;
36 cfda1fed gaqhf
        SPPID_Document document;
37 b65a7e32 gaqhf
        ETCSetting _ETCSetting;
38 f1c9dbaa gaqhf
39 d5ec4d0f gaqhf
        public string DocumentLabelText { get; set; }
40
41 f3e2693f gaqhf
        List<Line> BranchLines = new List<Line>();
42 644f40b3 gaqhf
        List<string> ZeroLengthSymbolToSymbolModelItemID = new List<string>();
43 87f02fc0 gaqhf
        List<string> ZeroLengthModelItemID = new List<string>();
44 1ff0105e gaqhf
        List<string> ZeroLengthModelItemIDReverse = new List<string>();
45 f1a7faf9 gaqhf
        List<Symbol> prioritySymbols;
46 47ad9a46 gaqhf
47 4941f5fe gaqhf
        public AutoModeling(SPPID_Document document, bool closeDocument)
48 cfda1fed gaqhf
        {
49 4941f5fe gaqhf
            application = Interaction.GetObject("", "PIDAutomation.Application");
50
            WrapperApplication wApp = new WrapperApplication(application.Application);
51
            radApp = wApp.RADApplication;
52
53 442bd51e gaqhf
            this.closeDocument = closeDocument;
54 cfda1fed gaqhf
            this.document = document;
55 b65a7e32 gaqhf
            this._ETCSetting = ETCSetting.GetInstance();
56 cfda1fed gaqhf
        }
57
58 02480ac1 gaqhf
        private void SetSystemEditingCommand(bool value)
59
        {
60
            foreach (var item in radApp.Commands)
61
            {
62
                if (item.Argument == "SystemEditingCmd.SystemEditing")
63
                {
64
                    if (item.Checked != value)
65
                    {
66
                        radApp.RunMacro("systemeditingcmd.dll");
67
                        break;
68
                    }
69
70
                }
71
            }
72
        }
73
74 74752074 gaqhf
        /// <summary>
75
        /// 도면 단위당 실행되는 메서드
76
        /// </summary>
77 1ba9c671 gaqhf
        public void Run()
78 c2fef4ca gaqhf
        {
79 224535bb gaqhf
            string drawingNumber = document.DrawingNumber;
80
            string drawingName = document.DrawingName;
81 1ba9c671 gaqhf
            try
82 c2fef4ca gaqhf
            {
83 bccacd6c gaqhf
                _placement = new Placement();
84
                dataSource = _placement.PIDDataSource;
85 f14b4e3b gaqhf
                
86 4941f5fe gaqhf
                if (CreateDocument(ref drawingNumber, ref drawingName) && DocumentCoordinateCorrection())
87 310aeb31 gaqhf
                {
88 3734dcc5 gaqhf
                    Log.Write("Start Modeling");
89 965eb728 gaqhf
                    SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true);
90 9628f54b gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetParent, (IntPtr)radApp.HWnd);
91 238eb5d2 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllStepCount, 23);
92 20972c61 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText);
93 f9cc5190 gaqhf
94 fb2d9638 gaqhf
                    // VendorPackage Modeling
95
                    RunVendorPackageModeling();
96 6db30942 gaqhf
                    // Equipment Modeling
97 b01e7456 gaqhf
                    RunEquipmentModeling();
98
                    // Symbol Modeling
99
                    RunSymbolModeling();
100 3939eebf gaqhf
                    // LineRun Line Modeling
101 b01e7456 gaqhf
                    RunLineModeling();
102 f14b4e3b gaqhf
                    // Vent Drain Modeling
103
                    RunVentDrainModeling();
104 e2876f87 gaqhf
                    // Clear Attribute
105
                    RunClearNominalDiameter();
106 d23fe61b gaqhf
                    // Join SameConnector
107 dfac4553 gaqhf
                    RunJoinRunForSameConnector();
108 d77973b3 gaqhf
                    // Join Run
109
                    RunJoinRun();
110 fae4f386 gaqhf
                    // EndBreak Modeling
111
                    RunEndBreakModeling();
112
                    // SpecBreak Modeling
113
                    RunSpecBreakModeling();
114 8701de36 gaqhf
                    //Line Number Modeling
115
                    RunLineNumberModeling();
116 32205389 gaqhf
                    // Note Modeling
117
                    RunNoteModeling();
118
                    // Text Modeling
119
                    RunTextModeling();
120
                    // Input LineNumber Attribute
121
                    RunInputLineNumberAttribute();
122
                    // Input Symbol Attribute
123
                    RunInputSymbolAttribute();
124
                    // Input SpecBreak Attribute
125
                    RunInputSpecBreakAttribute();
126 d8afa58b gaqhf
                    // Input EndBreak Attribute
127
                    RunInputEndBreakAttribute();
128 32205389 gaqhf
                    // Label Symbol Modeling
129
                    RunLabelSymbolModeling();
130 4e865771 gaqhf
                    // Correct Text
131
                    RunCorrectAssociationText();
132 4ba01591 gaqhf
133 30ba9ae0 gaqhf
                    // Result Logging
134
                    document.CheckModelingResult();
135 310aeb31 gaqhf
                }
136 809a7640 gaqhf
            }
137 5e6ecf05 gaqhf
            catch (Exception ex)
138
            {
139 4941f5fe gaqhf
                if (SplashScreenManager.Default != null && SplashScreenManager.Default.IsSplashFormVisible)
140
                {
141
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null);
142
                    SplashScreenManager.CloseForm(false);
143
                    Log.Write("\r\n");
144
                }
145 5e6ecf05 gaqhf
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
146
            }
147
            finally
148
            {
149 154d8f43 gaqhf
                Project_DB.InsertDrawingInfoAndOPCInfo(document.PATH, drawingNumber, drawingName, document);
150 4941f5fe gaqhf
                if (SplashScreenManager.Default != null && SplashScreenManager.Default.IsSplashFormVisible)
151
                {
152
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null);
153
                    SplashScreenManager.CloseForm(false);
154
                    Log.Write("\r\n");
155
                }
156
                Thread.Sleep(1000);
157 b2d1c1aa gaqhf
158 4941f5fe gaqhf
                Log.Write("End Modeling");
159
                radApp.ActiveWindow.Fit();
160 7aee331b gaqhf
161 4941f5fe gaqhf
                ReleaseCOMObjects(application);
162
                application = null;
163 b66a2996 gaqhf
                if (radApp.ActiveDocument != null)
164 3939eebf gaqhf
                {
165 4941f5fe gaqhf
                    if (closeDocument && newDrawing != null)
166
                    {
167
                        newDrawing.Save();
168 442bd51e gaqhf
                        newDrawing.CloseDrawing(true);
169 4941f5fe gaqhf
                        ReleaseCOMObjects(newDrawing);
170
                        newDrawing = null;
171
                    }
172
                    else if (newDrawing == null)
173
                    {
174
                        Log.Write("error document");
175
                    }
176 3939eebf gaqhf
                }
177 1ba9c671 gaqhf
178 5e6ecf05 gaqhf
                ReleaseCOMObjects(dataSource);
179 4941f5fe gaqhf
                dataSource = null;
180 5e6ecf05 gaqhf
                ReleaseCOMObjects(_placement);
181 4941f5fe gaqhf
                _placement = null;
182 965eb728 gaqhf
183 4941f5fe gaqhf
                Thread.Sleep(1000);
184 5e6ecf05 gaqhf
            }
185 65a1ed4b gaqhf
        }
186 5a9396ae humkyung
187 fb2d9638 gaqhf
        private void RunVendorPackageModeling()
188
        {
189
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.VendorPackages.Count);
190
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "VendorPackages Modeling");
191
            foreach (VendorPackage item in document.VendorPackages)
192
            {
193
                try
194
                {
195
                    VendorPackageModeling(item);
196
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
197
                }
198
                catch (Exception ex)
199
                {
200
                    Log.Write("Error in RunVendorPackageModeling");
201
                    Log.Write("UID : " + item.UID);
202
                    Log.Write(ex.Message);
203
                    Log.Write(ex.StackTrace);
204
                }
205
            }
206
        }
207 b01e7456 gaqhf
        private void RunEquipmentModeling()
208
        {
209
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.Equipments.Count);
210 32205389 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Equipments Modeling");
211 b01e7456 gaqhf
            foreach (Equipment item in document.Equipments)
212
            {
213
                try
214
                {
215
                    EquipmentModeling(item);
216
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.Equipments.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
217
                }
218
                catch (Exception ex)
219
                {
220
                    Log.Write("Error in EquipmentModeling");
221
                    Log.Write("UID : " + item.UID);
222
                    Log.Write(ex.Message);
223
                    Log.Write(ex.StackTrace);
224
                }
225
            }
226
        }
227
        private void RunSymbolModeling()
228
        {
229
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
230 32205389 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbol Modeling");
231 b01e7456 gaqhf
            prioritySymbols = GetPrioritySymbol();
232
            foreach (var item in prioritySymbols)
233
            {
234
                try
235
                {
236 f14b4e3b gaqhf
                    if (document.VentDrainSymbol.Contains(item))
237
                        continue;
238 b01e7456 gaqhf
                    SymbolModelingBySymbol(item);
239
                }
240
                catch (Exception ex)
241
                {
242
                    Log.Write("Error in SymbolModelingByPriority");
243
                    Log.Write("UID : " + item.UID);
244
                    Log.Write(ex.Message);
245
                    Log.Write(ex.StackTrace);
246
                }
247
            }
248
        }
249
        private void RunLineModeling()
250
        {
251 cf210438 gaqhf
            List<Line> AllLine = document.LINES.ToList();
252
            List<Line> stepLast_Line = document.LINES.FindAll(x => x.CONNECTORS.FindAll(y => y.ConnectedObject != null && y.ConnectedObject.GetType() == typeof(Symbol)).Count == 2 &&
253
            !SPPIDUtil.IsBranchedLine(document, x));
254
            List<Line> step1_Line = AllLine.FindAll(x => !stepLast_Line.Contains(x));
255
256
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, step1_Line.Count);
257 02a45794 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling - 1");
258 cf210438 gaqhf
259
            SetPriorityLine(step1_Line);
260
            foreach (var item in step1_Line)
261 b01e7456 gaqhf
            {
262
                try
263
                {
264 f14b4e3b gaqhf
                    if (document.VentDrainLine.Contains(item))
265
                        continue;
266 b01e7456 gaqhf
                    NewLineModeling(item);
267
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
268
                }
269
                catch (Exception ex)
270
                {
271
                    Log.Write("Error in NewLineModeling");
272
                    Log.Write("UID : " + item.UID);
273
                    Log.Write(ex.Message);
274
                    Log.Write(ex.StackTrace);
275
                }
276
            }
277 cf210438 gaqhf
278 f3e2693f gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, BranchLines.Count);
279 02a45794 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling - 2");
280 f3e2693f gaqhf
            int branchCount = BranchLines.Count;
281
            while (BranchLines.Count > 0)
282 b01e7456 gaqhf
            {
283
                try
284
                {
285
                    SortBranchLines();
286 f3e2693f gaqhf
                    Line item = BranchLines[0];
287 d4c3e39f gaqhf
                    NewLineModeling(item, true);
288
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
289 b01e7456 gaqhf
                }
290
                catch (Exception ex)
291
                {
292
                    Log.Write("Error in NewLineModeling");
293 f3e2693f gaqhf
                    Log.Write("UID : " + BranchLines[0].UID);
294 b01e7456 gaqhf
                    Log.Write(ex.Message);
295
                    Log.Write(ex.StackTrace);
296 a1a55823 gaqhf
                    BranchLines.Remove(BranchLines[0]);
297 b01e7456 gaqhf
                }
298
            }
299 a31a512e gaqhf
300 cf210438 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, stepLast_Line.Count);
301 02a45794 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling - 3");
302 cf210438 gaqhf
            foreach (var item in stepLast_Line)
303 a31a512e gaqhf
            {
304 cf210438 gaqhf
                try
305
                {
306 f14b4e3b gaqhf
                    if (document.VentDrainLine.Contains(item))
307
                        continue;
308 cf210438 gaqhf
                    NewLineModeling(item);
309
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
310
                }
311
                catch (Exception ex)
312
                {
313
                    Log.Write("Error in NewLineModeling");
314
                    Log.Write("UID : " + item.UID);
315
                    Log.Write(ex.Message);
316
                    Log.Write(ex.StackTrace);
317
                }
318 a31a512e gaqhf
            }
319 b01e7456 gaqhf
        }
320 f14b4e3b gaqhf
        private void RunVentDrainModeling()
321
        {
322
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.VentDrainLine.Count);
323
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Vent Drain Modeling");
324
            foreach (var item in document.VentDrainLine)
325
            {
326
                try
327
                {
328
                    Connector connector = item.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol));
329
                    if (connector != null)
330
                    {
331
                        SetCoordinate();
332
                        SymbolModelingBySymbol(connector.ConnectedObject as Symbol);
333 a2727dce gaqhf
                        NewLineModeling(item, true);
334 f14b4e3b gaqhf
                    }
335
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
336
                }
337
                catch (Exception ex)
338
                {
339
                    Log.Write("Error in NewLineModeling");
340
                    Log.Write("UID : " + item.UID);
341
                    Log.Write(ex.Message);
342
                    Log.Write(ex.StackTrace);
343
                }
344
345
                void SetCoordinate()
346
                {
347
                    Connector branchConnector = item.CONNECTORS.Find(loop => loop.ConnectedObject != null && loop.ConnectedObject.GetType() == typeof(Line));
348
                    if (branchConnector != null)
349
                    {
350
                        Line connLine = branchConnector.ConnectedObject as Line;
351
                        double x = 0;
352
                        double y = 0;
353
                        GetTargetLineConnectorPoint(branchConnector, item, ref x, ref y);
354
                        LMConnector targetConnector = FindTargetLMConnectorForBranch(item, connLine, ref x, ref y);
355
                        if (targetConnector != null)
356
                        {
357
                            List<Symbol> group = new List<Symbol>();
358
                            SPPIDUtil.FindConnectedSymbolGroup(document, item.CONNECTORS.Find(loop => loop != branchConnector).ConnectedObject as Symbol, group);
359
                            if (item.SlopeType == SlopeType.HORIZONTAL)
360
                            {
361
                                item.SPPID.START_Y = y;
362
                                item.SPPID.END_Y = y;
363
                                foreach (var symbol in group)
364
                                {
365
                                    symbol.SPPID.ORIGINAL_Y = y;
366
                                    symbol.SPPID.SPPID_Y = y;
367
                                }
368
                            }
369
                            else if (item.SlopeType == SlopeType.VERTICAL)
370
                            {
371
                                item.SPPID.START_X = x;
372
                                item.SPPID.END_X = x;
373
                                foreach (var symbol in group)
374
                                {
375
                                    symbol.SPPID.ORIGINAL_X = x;
376
                                    symbol.SPPID.SPPID_X = x;
377
                                }
378
                            }
379
                        }
380
                        ReleaseCOMObjects(targetConnector);
381
                        targetConnector = null;
382
                    }
383
                }
384
            }
385
        }
386 9157c1b8 gaqhf
        private void RunClearNominalDiameter()
387
        {
388
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count + document.LINES.Count);
389
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Clear Attribute");
390
            List<string> endClearModelItemID = new List<string>();
391
            for (int i = 0; i < document.LINES.Count; i++)
392
            {
393
                Line item = document.LINES[i];
394
                string modelItemID = item.SPPID.ModelItemId;
395
                if (!string.IsNullOrEmpty(modelItemID))
396
                {
397
                    LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
398
                    if (modelItem != null)
399
                    {
400
                        LMAAttribute attribute = modelItem.Attributes["NominalDiameter"];
401
                        if (attribute != null)
402
                            attribute.set_Value(DBNull.Value);
403
404
                        modelItem.Commit();
405
                        ReleaseCOMObjects(modelItem);
406
                        modelItem = null;
407
                    }
408
                }
409
                if (!endClearModelItemID.Contains(modelItemID))
410
                    endClearModelItemID.Add(modelItemID);
411
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
412
            }
413
            for (int i = 0; i < document.SYMBOLS.Count; i++)
414
            {
415
                Symbol item = document.SYMBOLS[i];
416
                string repID = item.SPPID.RepresentationId;
417
                string modelItemID = item.SPPID.ModelItemID;
418
                if (!string.IsNullOrEmpty(modelItemID))
419
                {
420
                    LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
421
                    if (modelItem != null)
422
                    {
423
                        LMAAttribute attribute = modelItem.Attributes["NominalDiameter"];
424
                        if (attribute != null)
425
                            attribute.set_Value(DBNull.Value);
426
                        int index = 1;
427
                        while (true)
428
                        {
429
                            attribute = modelItem.Attributes[string.Format("PipingPoint{0}.NominalDiameter", index)];
430
                            if (attribute != null)
431
                                attribute.set_Value(DBNull.Value);
432
                            else
433
                                break;
434
                            index++;
435
                        }
436
                        modelItem.Commit();
437
                        ReleaseCOMObjects(modelItem);
438
                        modelItem = null;
439
                    }
440
                }
441
                if (!string.IsNullOrEmpty(repID))
442
                {
443
                    LMSymbol symbol = dataSource.GetSymbol(repID);
444
                    if (symbol != null)
445
                    {
446
                        foreach (LMConnector connector in symbol.Connect1Connectors)
447
                        {
448
                            if (connector.get_ItemStatus() == "Active" && !endClearModelItemID.Contains(connector.ModelItemID))
449
                            {
450
                                endClearModelItemID.Add(connector.ModelItemID);
451
                                LMModelItem modelItem = connector.ModelItemObject;
452
                                if (modelItem != null)
453
                                {
454
                                    LMAAttribute attribute = modelItem.Attributes["NominalDiameter"];
455
                                    if (attribute != null)
456
                                        attribute.set_Value(DBNull.Value);
457
458
                                    modelItem.Commit();
459
                                    ReleaseCOMObjects(modelItem);
460
                                    modelItem = null;
461
                                }
462
                            }
463
                        }
464
                        foreach (LMConnector connector in symbol.Connect2Connectors)
465
                        {
466
                            if (connector.get_ItemStatus() == "Active" && !endClearModelItemID.Contains(connector.ModelItemID))
467
                            {
468
                                endClearModelItemID.Add(connector.ModelItemID);
469
                                LMModelItem modelItem = connector.ModelItemObject;
470
                                if (modelItem != null)
471
                                {
472
                                    LMAAttribute attribute = modelItem.Attributes["NominalDiameter"];
473
                                    if (attribute != null)
474
                                        attribute.set_Value(DBNull.Value);
475
476
                                    modelItem.Commit();
477
                                    ReleaseCOMObjects(modelItem);
478
                                    modelItem = null;
479
                                }
480
                            }
481
                        }
482
                    }
483
                    ReleaseCOMObjects(symbol);
484
                    symbol = null;
485
                }
486
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
487
            }
488
        }
489 1ff0105e gaqhf
        private void RunClearValueInconsistancy()
490 b01e7456 gaqhf
        {
491 32205389 gaqhf
            int count = 1;
492 63fbf592 gaqhf
            bool loop = true;
493
            while (loop)
494 b01e7456 gaqhf
            {
495 63fbf592 gaqhf
                loop = false;
496
                LMAFilter filter = new LMAFilter();
497
                LMACriterion criterion = new LMACriterion();
498
                filter.ItemType = "Relationship";
499
                criterion.SourceAttributeName = "SP_DRAWINGID";
500
                criterion.Operator = "=";
501 4941f5fe gaqhf
                criterion.set_ValueAttribute(drawingID);
502 63fbf592 gaqhf
                filter.get_Criteria().Add(criterion);
503
504
                LMRelationships relationships = new LMRelationships();
505
                relationships.Collect(dataSource, Filter: filter);
506
507 d23fe61b gaqhf
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, relationships.Count);
508 f9cc5190 gaqhf
                if (count > 1)
509
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStepMinus, null);
510 32205389 gaqhf
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Clear Inconsistent Property Value - " + count);
511 63fbf592 gaqhf
                foreach (LMRelationship relationship in relationships)
512 b01e7456 gaqhf
                {
513 63fbf592 gaqhf
                    foreach (LMInconsistency inconsistency in relationship.Inconsistencies)
514 b01e7456 gaqhf
                    {
515 63fbf592 gaqhf
                        if (inconsistency.get_InconsistencyTypeIndex() == 1)
516
                        {
517
                            LMModelItem modelItem1 = relationship.Item1RepresentationObject == null ? null : relationship.Item1RepresentationObject.ModelItemObject;
518
                            LMModelItem modelItem2 = relationship.Item2RepresentationObject == null ? null : relationship.Item2RepresentationObject.ModelItemObject;
519
                            string[] array = inconsistency.get_Name().ToString().Split(new char[] { '=' });
520
                            if (modelItem1 != null)
521
                            {
522
                                string attrName = array[0];
523
                                if (attrName.Contains("PipingPoint"))
524
                                {
525
                                    string originalAttr = attrName.Split(new char[] { '.' })[1];
526 d23fe61b gaqhf
                                    int index = Convert.ToInt32(relationship.get_Item1Location());
527
                                    LMAAttribute attribute1 = modelItem1.Attributes["PipingPoint" + index + "." + originalAttr];
528
                                    if (attribute1 != null && !DBNull.Value.Equals(attribute1.get_Value()))
529 63fbf592 gaqhf
                                    {
530 d23fe61b gaqhf
                                        loop = true;
531
                                        attribute1.set_Value(DBNull.Value);
532 63fbf592 gaqhf
                                    }
533 4941f5fe gaqhf
                                    attribute1 = null;
534 63fbf592 gaqhf
                                }
535
                                else
536
                                {
537
                                    LMAAttribute attribute1 = modelItem1.Attributes[attrName];
538
                                    if (attribute1 != null && !DBNull.Value.Equals(attribute1.get_Value()))
539
                                    {
540
                                        loop = true;
541
                                        attribute1.set_Value(DBNull.Value);
542
                                    }
543 4941f5fe gaqhf
                                    attribute1 = null;
544 63fbf592 gaqhf
                                }
545
                                modelItem1.Commit();
546
                            }
547
                            if (modelItem2 != null)
548
                            {
549
                                string attrName = array[1];
550
                                if (attrName.Contains("PipingPoint"))
551
                                {
552
                                    string originalAttr = attrName.Split(new char[] { '.' })[1];
553 d23fe61b gaqhf
                                    int index = Convert.ToInt32(relationship.get_Item2Location());
554
                                    LMAAttribute attribute2 = modelItem2.Attributes["PipingPoint" + index + "." + originalAttr];
555
                                    if (attribute2 != null && !DBNull.Value.Equals(attribute2.get_Value()))
556 63fbf592 gaqhf
                                    {
557 d23fe61b gaqhf
                                        attribute2.set_Value(DBNull.Value);
558
                                        loop = true;
559 63fbf592 gaqhf
                                    }
560 4941f5fe gaqhf
                                    attribute2 = null;
561 63fbf592 gaqhf
                                }
562
                                else
563
                                {
564
                                    LMAAttribute attribute2 = modelItem2.Attributes[attrName];
565
                                    if (attribute2 != null && !DBNull.Value.Equals(attribute2.get_Value()))
566
                                    {
567
                                        attribute2.set_Value(DBNull.Value);
568
                                        loop = true;
569
                                    }
570 4941f5fe gaqhf
                                    attribute2 = null;
571 63fbf592 gaqhf
                                }
572
                                modelItem2.Commit();
573
                            }
574 4941f5fe gaqhf
                            ReleaseCOMObjects(modelItem1);
575
                            modelItem1 = null;
576
                            ReleaseCOMObjects(modelItem2);
577
                            modelItem2 = null;
578 63fbf592 gaqhf
                            inconsistency.Commit();
579
                        }
580 4941f5fe gaqhf
                        ReleaseCOMObjects(inconsistency);
581 b01e7456 gaqhf
                    }
582 63fbf592 gaqhf
                    relationship.Commit();
583 4941f5fe gaqhf
                    ReleaseCOMObjects(relationship);
584 d23fe61b gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
585 b01e7456 gaqhf
                }
586 63fbf592 gaqhf
                ReleaseCOMObjects(filter);
587 4941f5fe gaqhf
                filter = null;
588 63fbf592 gaqhf
                ReleaseCOMObjects(criterion);
589 4941f5fe gaqhf
                criterion = null;
590 63fbf592 gaqhf
                ReleaseCOMObjects(relationships);
591 4941f5fe gaqhf
                relationships = null;
592 32205389 gaqhf
                count++;
593 b01e7456 gaqhf
            }
594
        }
595
        private void RunEndBreakModeling()
596
        {
597
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.EndBreaks.Count);
598
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling");
599
            foreach (var item in document.EndBreaks)
600
                try
601
                {
602
                    EndBreakModeling(item);
603
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
604
                }
605
                catch (Exception ex)
606
                {
607
                    Log.Write("Error in EndBreakModeling");
608
                    Log.Write("UID : " + item.UID);
609
                    Log.Write(ex.Message);
610
                    Log.Write(ex.StackTrace);
611
                }
612
        }
613
        private void RunSpecBreakModeling()
614
        {
615
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SpecBreaks.Count);
616
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "SpecBreaks Modeling");
617
            foreach (var item in document.SpecBreaks)
618
                try
619
                {
620
                    SpecBreakModeling(item);
621
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
622
                }
623
                catch (Exception ex)
624
                {
625
                    Log.Write("Error in SpecBreakModeling");
626
                    Log.Write("UID : " + item.UID);
627 9bcb092b gaqhf
                    Log.Write(ex.Message);
628
                    Log.Write(ex.StackTrace);
629
                }
630
        }
631 dfac4553 gaqhf
        private void RunJoinRunForSameConnector()
632
        {
633 d23fe61b gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count);
634 ca6e0f51 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "PipeRun Join - 1");
635 dfac4553 gaqhf
            foreach (var line in document.LINES)
636
            {
637 44087b23 gaqhf
                Dictionary<LMConnector, List<double[]>> vertices = GetPipeRunVertices(line.SPPID.ModelItemId, false);
638
                List<List<double[]>> result = new List<List<double[]>>();
639
                foreach (var item in vertices)
640
                {
641
                    ReleaseCOMObjects(item.Key);
642
                    result.Add(item.Value);
643
                }
644
                line.SPPID.Vertices = result;
645
                vertices = null;
646
            }
647
648
            foreach (var line in document.LINES)
649
            {
650 d9fc7084 gaqhf
                foreach (var connector in line.CONNECTORS)
651 dfac4553 gaqhf
                {
652 d9fc7084 gaqhf
                    if (connector.ConnectedObject != null &&
653
                        connector.ConnectedObject.GetType() == typeof(Line) &&
654
                        !SPPIDUtil.IsBranchLine(line, connector.ConnectedObject as Line))
655 dfac4553 gaqhf
                    {
656 d9fc7084 gaqhf
                        Line connLine = connector.ConnectedObject as Line;
657
                        if (line.SPPID.ModelItemId != connLine.SPPID.ModelItemId &&
658
                            !string.IsNullOrEmpty(line.SPPID.ModelItemId) &&
659
                            !string.IsNullOrEmpty(connLine.SPPID.ModelItemId) &&
660
                            !SPPIDUtil.IsSegment(document, line, connLine))
661 dfac4553 gaqhf
                        {
662 d9fc7084 gaqhf
                            string survivorId = string.Empty;
663
                            JoinRun(connLine.SPPID.ModelItemId, line.SPPID.ModelItemId, ref survivorId);
664 dfac4553 gaqhf
                        }
665 d9fc7084 gaqhf
666 dfac4553 gaqhf
                    }
667
                }
668 d23fe61b gaqhf
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
669
            }
670 fae4f386 gaqhf
671
            foreach (var line in document.LINES)
672
                line.SPPID.Representations = GetRepresentations(line.SPPID.ModelItemId);
673 d23fe61b gaqhf
        }
674 ca6e0f51 gaqhf
        private void RunJoinRun()
675
        {
676
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count);
677
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "PipeRun Join - 2");
678 a31a512e gaqhf
            List<string> endModelID = new List<string>();
679 ca6e0f51 gaqhf
            foreach (var line in document.LINES)
680
            {
681 a31a512e gaqhf
                if (!endModelID.Contains(line.SPPID.ModelItemId))
682
                {
683
                    while (!endModelID.Contains(line.SPPID.ModelItemId))
684
                    {
685
                        string survivorId = string.Empty;
686
                        JoinRunBySameType(line.SPPID.ModelItemId, ref survivorId);
687
                        if (string.IsNullOrEmpty(survivorId))
688
                        {
689
                            endModelID.Add(line.SPPID.ModelItemId);
690
                        }
691
                    }
692
                }
693 ca6e0f51 gaqhf
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
694
            }
695
        }
696 8701de36 gaqhf
        private void RunLineNumberModeling()
697
        {
698
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINENUMBERS.Count);
699
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Line Number Modeling");
700
            foreach (var item in document.LINENUMBERS)
701
            {
702
                LMLabelPersist label = dataSource.GetLabelPersist(item.SPPID.RepresentationId);
703
                if (label == null || (label != null && label.get_ItemStatus() != "Active"))
704
                {
705
                    ReleaseCOMObjects(label);
706
                    item.SPPID.RepresentationId = null;
707
                    LineNumberModeling(item);
708
                }
709
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
710
            }
711
        }
712 32205389 gaqhf
        private void RunNoteModeling()
713
        {
714
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
715
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling");
716 1299077b gaqhf
            List<Note> correctList = new List<Note>();
717 32205389 gaqhf
            foreach (var item in document.NOTES)
718
                try
719
                {
720 1299077b gaqhf
                    NoteModeling(item, correctList);
721
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
722
                }
723
                catch (Exception ex)
724
                {
725
                    Log.Write("Error in NoteModeling");
726
                    Log.Write("UID : " + item.UID);
727
                    Log.Write(ex.Message);
728
                    Log.Write(ex.StackTrace);
729
                }
730
731
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, correctList.Count);
732
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Correct Note");
733
            SortNote(correctList);
734
            List<Note> endList = new List<Note>();
735
            if (correctList.Count > 0)
736
                endList.Add(correctList[0]);
737 ba25c427 gaqhf
            foreach (var item in correctList)
738 1299077b gaqhf
                try
739
                {
740
                    if (!endList.Contains(item))
741
                        NoteCorrectModeling(item, endList);
742 32205389 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
743
                }
744
                catch (Exception ex)
745
                {
746
                    Log.Write("Error in NoteModeling");
747
                    Log.Write("UID : " + item.UID);
748
                    Log.Write(ex.Message);
749
                    Log.Write(ex.StackTrace);
750
                }
751
        }
752
        private void RunTextModeling()
753 9bcb092b gaqhf
        {
754 32205389 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.TEXTINFOS.Count);
755
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling");
756 e27329d6 gaqhf
            SortText(document.TEXTINFOS);
757 32205389 gaqhf
            foreach (var item in document.TEXTINFOS)
758
                try
759
                {
760 e27329d6 gaqhf
                    if (item.ASSOCIATION)
761
                        AssociationTextModeling(item);
762
                    else
763
                        NormalTextModeling(item);
764 32205389 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
765
                }
766
                catch (Exception ex)
767
                {
768
                    Log.Write("Error in TextModeling");
769
                    Log.Write("UID : " + item.UID);
770
                    Log.Write(ex.Message);
771
                    Log.Write(ex.StackTrace);
772
                }
773
        }
774
        private void RunInputLineNumberAttribute()
775
        {
776
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINENUMBERS.Count);
777
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set LineNumbers Attribute");
778 82d6e5ea gaqhf
            List<string> endLine = new List<string>();
779 9bcb092b gaqhf
            foreach (var item in document.LINENUMBERS)
780
                try
781
                {
782 82d6e5ea gaqhf
                    InputLineNumberAttribute(item, endLine);
783 32205389 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
784 9bcb092b gaqhf
                }
785
                catch (Exception ex)
786
                {
787 32205389 gaqhf
                    Log.Write("Error in InputLineNumberAttribute");
788
                    Log.Write("UID : " + item.UID);
789
                    Log.Write(ex.Message);
790
                    Log.Write(ex.StackTrace);
791
                }
792
        }
793
        private void RunInputSymbolAttribute()
794
        {
795
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
796
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
797
            foreach (var item in document.SYMBOLS)
798
                try
799
                {
800
                    InputSymbolAttribute(item, item.ATTRIBUTES);
801
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
802
                }
803
                catch (Exception ex)
804
                {
805
                    Log.Write("Error in InputSymbolAttribute");
806
                    Log.Write("UID : " + item.UID);
807
                    Log.Write(ex.Message);
808
                    Log.Write(ex.StackTrace);
809
                }
810
        }
811
        private void RunInputSpecBreakAttribute()
812
        {
813 d8afa58b gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SpecBreaks.Count);
814
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set SpecBreak Attribute");
815 32205389 gaqhf
            foreach (var item in document.SpecBreaks)
816
                try
817
                {
818
                    InputSpecBreakAttribute(item);
819
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
820
                }
821
                catch (Exception ex)
822
                {
823
                    Log.Write("Error in InputSpecBreakAttribute");
824
                    Log.Write("UID : " + item.UID);
825
                    Log.Write(ex.Message);
826
                    Log.Write(ex.StackTrace);
827
                }
828
        }
829 d8afa58b gaqhf
        private void RunInputEndBreakAttribute()
830
        {
831
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.EndBreaks.Count);
832
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set EndBreak Attribute");
833
            foreach (var item in document.EndBreaks)
834
                try
835
                {
836
                    InputEndBreakAttribute(item);
837
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
838
                }
839
                catch (Exception ex)
840
                {
841
                    Log.Write("Error in RunInputEndBreakAttribute");
842
                    Log.Write("UID : " + item.UID);
843
                    Log.Write(ex.Message);
844
                    Log.Write(ex.StackTrace);
845
                }
846
        }
847 32205389 gaqhf
        private void RunLabelSymbolModeling()
848
        {
849
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
850
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Labels Modeling");
851
            foreach (var item in document.SYMBOLS)
852
                try
853
                {
854
                    LabelSymbolModeling(item);
855
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
856
                }
857
                catch (Exception ex)
858
                {
859
                    Log.Write("Error in LabelSymbolModeling");
860 9bcb092b gaqhf
                    Log.Write("UID : " + item.UID);
861 b01e7456 gaqhf
                    Log.Write(ex.Message);
862
                    Log.Write(ex.StackTrace);
863
                }
864
        }
865 4e865771 gaqhf
        private void RunCorrectAssociationText()
866
        {
867 44087b23 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.TEXTINFOS.Count + document.LINENUMBERS.Count);
868
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Correct Labels");
869 4e865771 gaqhf
            List<Text> endTexts = new List<Text>();
870
            foreach (var item in document.TEXTINFOS)
871
            {
872
                try
873
                {
874
                    if (item.ASSOCIATION && !endTexts.Contains(item))
875
                        AssociationTextCorrectModeling(item, endTexts);
876
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
877
                }
878
                catch (Exception ex)
879
                {
880 44087b23 gaqhf
                    Log.Write("Error in RunCorrectAssociationText");
881 4e865771 gaqhf
                    Log.Write("UID : " + item.UID);
882
                    Log.Write(ex.Message);
883
                    Log.Write(ex.StackTrace);
884
                }
885
                
886
            }
887 44087b23 gaqhf
888
            foreach (var item in document.LINENUMBERS)
889
            {
890
                try
891
                {
892
                    LineNumberCorrectModeling(item);
893
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
894
                }
895
                catch (Exception ex)
896
                {
897
                    Log.Write("Error in RunCorrectAssociationText");
898
                    Log.Write("UID : " + item.UID);
899
                    Log.Write(ex.Message);
900
                    Log.Write(ex.StackTrace);
901
                }
902
            }
903 4e865771 gaqhf
        }
904 74752074 gaqhf
        /// <summary>
905
        /// 도면 생성 메서드
906
        /// </summary>
907 4941f5fe gaqhf
        private bool CreateDocument(ref string drawingNumber, ref string drawingName)
908 0e0edfad gaqhf
        {
909 3734dcc5 gaqhf
            Log.Write("------------------ Start create document ------------------");
910 6d12a734 gaqhf
            GetDrawingNameAndNumber(ref drawingName, ref drawingNumber);
911 3734dcc5 gaqhf
            Log.Write("Drawing name : " + drawingName);
912
            Log.Write("Drawing number : " + drawingNumber);
913 d4c3e39f gaqhf
            Thread.Sleep(1000);
914 4941f5fe gaqhf
            newDrawing = application.Drawings.Add(document.Unit, document.Template, drawingNumber, drawingName);
915
            if (newDrawing != null)
916
            {
917
                document.SPPID_DrawingNumber = drawingNumber;
918
                document.SPPID_DrawingName = drawingName;
919
                Thread.Sleep(1000);
920
                radApp.ActiveWindow.Fit();
921
                Thread.Sleep(1000);
922
                radApp.ActiveWindow.Zoom = 2000;
923
                Thread.Sleep(2000);
924 7aee331b gaqhf
925 4941f5fe gaqhf
                //current LMDrawing 가져오기
926
                LMAFilter filter = new LMAFilter();
927
                LMACriterion criterion = new LMACriterion();
928
                filter.ItemType = "Drawing";
929
                criterion.SourceAttributeName = "Name";
930
                criterion.Operator = "=";
931
                criterion.set_ValueAttribute(drawingName);
932
                filter.get_Criteria().Add(criterion);
933 7aee331b gaqhf
934 4941f5fe gaqhf
                LMDrawings drawings = new LMDrawings();
935
                drawings.Collect(dataSource, Filter: filter);
936
937
                drawingID = ((dynamic)drawings).Nth(1).Id;
938
                ReleaseCOMObjects(filter);
939
                ReleaseCOMObjects(criterion);
940
                ReleaseCOMObjects(drawings);
941
                filter = null;
942
                criterion = null;
943
                drawings = null;
944
            }
945
            else
946
                Log.Write("Fail Create Drawing");
947
948
            if (newDrawing != null)
949
                return true;
950
            else
951
                return false;
952 b66a2996 gaqhf
        }
953
954 02480ac1 gaqhf
        /// <summary>
955
        /// DrawingName, DrawingNumber를 확인하여 중복이 있으면 _1을 붙이고 +1씩 한다.
956
        /// </summary>
957
        /// <param name="drawingName"></param>
958
        /// <param name="drawingNumber"></param>
959 b66a2996 gaqhf
        private void GetDrawingNameAndNumber(ref string drawingName, ref string drawingNumber)
960
        {
961
            LMDrawings drawings = new LMDrawings();
962
            drawings.Collect(dataSource);
963 7f00b26c gaqhf
964 b66a2996 gaqhf
            List<string> drawingNameList = new List<string>();
965
            List<string> drawingNumberList = new List<string>();
966
967
            foreach (LMDrawing item in drawings)
968
            {
969
                drawingNameList.Add(item.Attributes["Name"].get_Value().ToString());
970
                drawingNumberList.Add(item.Attributes["DrawingNumber"].get_Value().ToString());
971
            }
972
973
            int nameLength = drawingName.Length;
974
            while (drawingNameList.Contains(drawingName))
975
            {
976
                if (nameLength == drawingName.Length)
977
                    drawingName += "-1";
978
                else
979
                {
980
                    int index = Convert.ToInt32(drawingName.Remove(0, nameLength + 1));
981
                    drawingName = drawingName.Substring(0, nameLength + 1);
982
                    drawingName += ++index;
983
                }
984
            }
985
986
            int numberLength = drawingNumber.Length;
987
            while (drawingNameList.Contains(drawingNumber))
988
            {
989
                if (numberLength == drawingNumber.Length)
990
                    drawingNumber += "-1";
991
                else
992
                {
993
                    int index = Convert.ToInt32(drawingNumber.Remove(0, numberLength + 1));
994
                    drawingNumber = drawingNumber.Substring(0, numberLength + 1);
995
                    drawingNumber += ++index;
996
                }
997
            }
998
            ReleaseCOMObjects(drawings);
999 4941f5fe gaqhf
            drawings = null;
1000 0e0edfad gaqhf
        }
1001
1002 74752074 gaqhf
        /// <summary>
1003
        /// 도면 크기 구하는 메서드
1004
        /// </summary>
1005
        /// <returns></returns>
1006 0e0edfad gaqhf
        private bool DocumentCoordinateCorrection()
1007
        {
1008 6a7573b0 gaqhf
            if (Settings.Default.DrawingX != 0 && Settings.Default.DrawingY != 0)
1009 0e0edfad gaqhf
            {
1010 3734dcc5 gaqhf
                Log.Write("Setting Drawing X, Drawing Y");
1011 6a7573b0 gaqhf
                document.SetSPPIDLocation(Settings.Default.DrawingX, Settings.Default.DrawingY);
1012 3734dcc5 gaqhf
                Log.Write("Start coordinate correction");
1013 c01ce90b gaqhf
                document.CoordinateCorrection();
1014 0e0edfad gaqhf
                return true;
1015
            }
1016
            else
1017 3734dcc5 gaqhf
            {
1018
                Log.Write("Need Drawing X, Y");
1019 0e0edfad gaqhf
                return false;
1020 3734dcc5 gaqhf
            }
1021 0e0edfad gaqhf
        }
1022
1023 74752074 gaqhf
        /// <summary>
1024
        /// 심볼을 실제로 Modeling 메서드
1025
        /// </summary>
1026 5a9396ae humkyung
        /// <param name="symbol">생성할 심볼</param>
1027
        /// <param name="targetSymbol">연결되어 있는 심볼</param>
1028 b2d1c1aa gaqhf
        private void SymbolModeling(Symbol symbol, Symbol targetSymbol)
1029 809a7640 gaqhf
        {
1030 7f00b26c gaqhf
            // OWNERSYMBOL Attribute, 값을 가지고 있을 경우
1031
            BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(attr => attr.ATTRIBUTE == "OWNERSYMBOL");
1032
            if (itemAttribute != null && (string.IsNullOrEmpty(itemAttribute.VALUE) || itemAttribute.VALUE != "None"))
1033
                return;
1034
            // 이미 모델링 됐을 경우
1035
            else if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
1036
                return;
1037 6a7573b0 gaqhf
1038 7f00b26c gaqhf
            LMSymbol _LMSymbol = null;
1039 809a7640 gaqhf
1040 7f00b26c gaqhf
            string mappingPath = symbol.SPPID.MAPPINGNAME;
1041
            double x = symbol.SPPID.ORIGINAL_X;
1042
            double y = symbol.SPPID.ORIGINAL_Y;
1043
            int mirror = 0;
1044
            double angle = symbol.ANGLE;
1045 2fdb56bf gaqhf
1046 7f00b26c gaqhf
            // OPC 일경우 180도 일때 Mirror
1047
            if (mappingPath.Contains("Piping OPC's") && angle == Math.PI)
1048
                mirror = 1;
1049 1ab9a205 gaqhf
1050 7f00b26c gaqhf
            // Mirror 계산
1051
            if (symbol.FLIP == 1)
1052
            {
1053
                mirror = 1;
1054
                angle += Math.PI;
1055
            }
1056 1ab9a205 gaqhf
1057 7f00b26c gaqhf
            if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId))
1058
            {
1059 5a9396ae humkyung
                LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);   /// RepresentationId로 SPPID 심볼을 찾음
1060 7f00b26c gaqhf
                Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, symbol.UID, targetSymbol);
1061
                if (connector != null)
1062
                    GetTargetSymbolConnectorPoint(connector, targetSymbol, ref x, ref y);
1063 809a7640 gaqhf
1064 147c80c4 gaqhf
                LMConnector temp = LineModelingForSymbolZeroLength(symbol, _TargetItem, x, y);
1065 7f00b26c gaqhf
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem);
1066 147c80c4 gaqhf
                if (temp != null)
1067
                    _placement.PIDRemovePlacement(temp.AsLMRepresentation());
1068
                ReleaseCOMObjects(temp);
1069
                temp = null;
1070 809a7640 gaqhf
1071 7f00b26c gaqhf
                if (_LMSymbol != null && _TargetItem != null)
1072 6a7573b0 gaqhf
                    symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1073 ac78b508 gaqhf
1074 7f00b26c gaqhf
                ReleaseCOMObjects(_TargetItem);
1075 4d2571ab gaqhf
            }
1076 7f00b26c gaqhf
            else
1077
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1078
1079
            if (_LMSymbol != null)
1080 4d2571ab gaqhf
            {
1081 7f00b26c gaqhf
                _LMSymbol.Commit();
1082 60f4405d gaqhf
1083
                // ConnCheck
1084
                List<string> ids = new List<string>();
1085
                foreach (LMConnector item in _LMSymbol.Connect1Connectors)
1086
                {
1087
                    if (item.get_ItemStatus() == "Active" && !ids.Contains(item.Id))
1088
                        ids.Add(item.Id);
1089
                    ReleaseCOMObjects(item);
1090
                }
1091
                foreach (LMConnector item in _LMSymbol.Connect2Connectors)
1092
                {
1093
                    if (item.get_ItemStatus() == "Active" && !ids.Contains(item.Id))
1094
                        ids.Add(item.Id);
1095
                    ReleaseCOMObjects(item);
1096
                }
1097
1098
                int createdSymbolCount = document.SYMBOLS.FindAll(i => i.CONNECTORS.Find(j => j.CONNECTEDITEM == symbol.UID) != null && !string.IsNullOrEmpty(i.SPPID.RepresentationId)).Count;
1099
                if (targetSymbol == null && ids.Count != createdSymbolCount)
1100
                {
1101
                    double currentX = _LMSymbol.get_XCoordinate();
1102
                    double currentY = _LMSymbol.get_YCoordinate();
1103
1104
1105
                }
1106
1107 7f00b26c gaqhf
                symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1108
                symbol.SPPID.ModelItemID = _LMSymbol.ModelItemID;
1109 32205389 gaqhf
                symbol.SPPID.GraphicOID = _LMSymbol.get_GraphicOID().ToString();
1110 7f00b26c gaqhf
1111
                foreach (var item in symbol.ChildSymbols)
1112 7e4a64a3 gaqhf
                    CreateChildSymbol(item, _LMSymbol, symbol);
1113 3734dcc5 gaqhf
1114 d9794a6c gaqhf
                symbol.SPPID.SPPID_X = _LMSymbol.get_XCoordinate();
1115
                symbol.SPPID.SPPID_Y = _LMSymbol.get_YCoordinate();
1116
1117
                double[] range = null;
1118
                GetSPPIDSymbolRange(symbol, ref range);
1119
                symbol.SPPID.SPPID_Min_X = range[0];
1120
                symbol.SPPID.SPPID_Min_Y = range[1];
1121
                symbol.SPPID.SPPID_Max_X = range[2];
1122
                symbol.SPPID.SPPID_Max_Y = range[3];
1123
1124
                foreach (var item in symbol.SPPID.CorrectionX_GroupSymbols)
1125
                    item.SPPID.ORIGINAL_X = symbol.SPPID.SPPID_X;
1126
                foreach (var item in symbol.SPPID.CorrectionY_GroupSymbols)
1127
                    item.SPPID.ORIGINAL_Y = symbol.SPPID.SPPID_Y;
1128
1129 3734dcc5 gaqhf
                ReleaseCOMObjects(_LMSymbol);
1130 4d2571ab gaqhf
            }
1131 809a7640 gaqhf
        }
1132 147c80c4 gaqhf
        /// <summary>
1133
        /// targetX와 targetY 기준 제일 먼 PipingPoint에 TempLine Modeling
1134
        /// Signal Point는 고려하지 않음
1135
        /// </summary>
1136
        /// <param name="symbol"></param>
1137
        /// <param name="_TargetItem"></param>
1138
        /// <param name="targetX"></param>
1139
        /// <param name="targetY"></param>
1140
        /// <returns></returns>
1141
        private LMConnector LineModelingForSymbolZeroLength(Symbol symbol, LMSymbol _TargetItem, double targetX, double targetY)
1142
        {
1143
            LMConnector tempConnector = null;
1144
1145
            List<Symbol> group = new List<Symbol>();
1146
            SPPIDUtil.FindConnectedSymbolGroup(document, symbol, group);
1147
            if (group.FindAll(loopX => !string.IsNullOrEmpty(loopX.SPPID.RepresentationId)).Count == 1)
1148
            {
1149
                List<Connector> connectors = new List<Connector>();
1150
                foreach (var item in group)
1151
                    connectors.AddRange(item.CONNECTORS.FindAll(loopX => loopX.ConnectedObject != null && loopX.ConnectedObject.GetType() == typeof(Line)));
1152
                /// Primary or Secondary Type Line만 고려
1153
                Connector _connector = connectors.Find(loopX => loopX.ConnectedObject != null && loopX.ConnectedObject.GetType() == typeof(Line) &&
1154
                (((Line)loopX.ConnectedObject).TYPE == "Primary" || ((Line)loopX.ConnectedObject).TYPE == "Secondary"));
1155
                if (_connector != null)
1156
                {
1157
                    string sppidLine = ((Line)_connector.ConnectedObject).SPPID.MAPPINGNAME;
1158
                    List<double[]> pointInfos = getPipingPoints(_TargetItem);
1159
                    /// PipingPoint가 2개 이상만
1160
                    if (pointInfos.Count >= 2)
1161
                    {
1162
                        double lineX = 0;
1163
                        double lineY = 0;
1164
                        double length = 0;
1165
                        foreach (var item in pointInfos)
1166
                        {
1167
                            double tempX = item[1];
1168
                            double tempY = item[2];
1169
1170
                            double calcDistance = SPPIDUtil.CalcPointToPointdDistance(targetX, targetY, tempX, tempY);
1171
                            if (calcDistance > length)
1172
                            {
1173
                                lineX = tempX;
1174
                                lineY = tempY;
1175
                            }
1176
                        }
1177
1178
                        _LMAItem _LMAItem = _placement.PIDCreateItem(sppidLine);
1179
                        PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1180
                        placeRunInputs.AddPoint(-1, -1);
1181 c9a4db3a gaqhf
                        placeRunInputs.AddSymbolTarget(_TargetItem, lineX, lineY);
1182 147c80c4 gaqhf
                        tempConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1183
                        if (tempConnector != null)
1184
                            tempConnector.Commit();
1185
                        ReleaseCOMObjects(_LMAItem);
1186
                        _LMAItem = null;
1187
                        ReleaseCOMObjects(placeRunInputs);
1188
                        placeRunInputs = null;
1189
                    }
1190
                }
1191
            }
1192
1193
            return tempConnector;
1194
        }
1195
        /// <summary>
1196
        /// Symbol의 PipingPoints를 구함
1197
        /// SignalPoint는 고려하지 않음
1198
        /// </summary>
1199
        /// <param name="symbol"></param>
1200
        /// <returns></returns>
1201
        private List<double[]> getPipingPoints(LMSymbol symbol)
1202
        {
1203
            LMModelItem modelItem = symbol.ModelItemObject;
1204
            LMPipingPoints pipingPoints = null;
1205
            if (modelItem.get_ItemTypeName() == "PipingComp")
1206
            {
1207
                LMPipingComp pipingComp = dataSource.GetPipingComp(modelItem.Id);
1208
                pipingPoints = pipingComp.PipingPoints;
1209
                ReleaseCOMObjects(pipingComp);
1210
                pipingComp = null;
1211
            }
1212
            else if (modelItem.get_ItemTypeName() == "Instrument")
1213
            {
1214
                LMInstrument instrument = dataSource.GetInstrument(modelItem.Id);
1215
                pipingPoints = instrument.PipingPoints;
1216
                ReleaseCOMObjects(instrument);
1217
                instrument = null;
1218
            }
1219
            else
1220
                Log.Write("다른 Type");
1221
1222
            List<double[]> info = new List<double[]>();
1223
            if (pipingPoints != null)
1224
            {
1225
                foreach (LMPipingPoint pipingPoint in pipingPoints)
1226
                {
1227
                    foreach (LMAAttribute attribute in pipingPoint.Attributes)
1228
                    {
1229
                        if (attribute.Name == "PipingPointNumber")
1230
                        {
1231
                            int index = Convert.ToInt32(attribute.get_Value());
1232
                            if (info.Find(loopX => loopX[0] == index) == null)
1233
                            {
1234
                                double x = 0;
1235
                                double y = 0;
1236
                                if (_placement.PIDConnectPointLocation(symbol, index, ref x, ref y))
1237
                                    info.Add(new double[] { index, x, y });
1238
                            }
1239
                        }
1240
                    }
1241
                }
1242
            }
1243
            ReleaseCOMObjects(modelItem);
1244
            modelItem = null;
1245
            ReleaseCOMObjects(pipingPoints);
1246
            pipingPoints = null;
1247
1248
            return info;
1249
        }
1250 809a7640 gaqhf
1251 d9794a6c gaqhf
        private void RemoveSymbol(Symbol symbol)
1252
        {
1253
            if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
1254
            {
1255
                LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1256
                if (_LMSymbol != null)
1257
                {
1258
                    _placement.PIDRemovePlacement(_LMSymbol.AsLMRepresentation());
1259
                    ReleaseCOMObjects(_LMSymbol);
1260
                }
1261
            }
1262
1263
            symbol.SPPID.RepresentationId = string.Empty;
1264
            symbol.SPPID.ModelItemID = string.Empty;
1265
            symbol.SPPID.SPPID_X = double.NaN;
1266
            symbol.SPPID.SPPID_Y = double.NaN;
1267
            symbol.SPPID.SPPID_Min_X = double.NaN;
1268
            symbol.SPPID.SPPID_Min_Y = double.NaN;
1269
            symbol.SPPID.SPPID_Max_X = double.NaN;
1270
            symbol.SPPID.SPPID_Max_Y = double.NaN;
1271
        }
1272
1273
        private void RemoveSymbol(List<Symbol> symbols)
1274
        {
1275
            foreach (var symbol in symbols)
1276
            {
1277
                if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
1278
                {
1279
                    LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1280
                    if (_LMSymbol != null)
1281
                    {
1282
                        _placement.PIDRemovePlacement(_LMSymbol.AsLMRepresentation());
1283
                        ReleaseCOMObjects(_LMSymbol);
1284
                    }
1285
                }
1286
1287
                symbol.SPPID.RepresentationId = string.Empty;
1288
                symbol.SPPID.ModelItemID = string.Empty;
1289
                symbol.SPPID.SPPID_X = double.NaN;
1290
                symbol.SPPID.SPPID_Y = double.NaN;
1291
                symbol.SPPID.SPPID_Min_X = double.NaN;
1292
                symbol.SPPID.SPPID_Min_Y = double.NaN;
1293
                symbol.SPPID.SPPID_Max_X = double.NaN;
1294
                symbol.SPPID.SPPID_Max_Y = double.NaN;
1295
            }
1296
        }
1297
1298 d1eac84d gaqhf
        /// <summary>
1299
        /// ID2의 Symbol Width와 Height를 비교해서 상대적인 SPPID Connector좌표를 가져온다.
1300
        /// </summary>
1301
        /// <param name="targetConnector"></param>
1302
        /// <param name="targetSymbol"></param>
1303
        /// <param name="x"></param>
1304
        /// <param name="y"></param>
1305
        private void GetTargetSymbolConnectorPoint(Connector targetConnector, Symbol targetSymbol, ref double x, ref double y)
1306
        {
1307
            LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
1308 2fdb56bf gaqhf
1309
            double[] range = null;
1310 d1eac84d gaqhf
            List<double[]> points = new List<double[]>();
1311 2fdb56bf gaqhf
            GetSPPIDSymbolRangeAndConnectionPoints(targetSymbol, ref range, points);
1312
            double x1 = range[0];
1313
            double y1 = range[1];
1314
            double x2 = range[2];
1315
            double y2 = range[3];
1316 d1eac84d gaqhf
1317
            // Origin 기준 Connector의 위치차이
1318
            double sceneX = 0;
1319
            double sceneY = 0;
1320
            SPPIDUtil.ConvertPointBystring(targetConnector.SCENECONNECTPOINT, ref sceneX, ref sceneY);
1321
            double originX = 0;
1322
            double originY = 0;
1323
            SPPIDUtil.ConvertPointBystring(targetSymbol.ORIGINALPOINT, ref originX, ref originY);
1324
            double gapX = originX - sceneX;
1325
            double gapY = originY - sceneY;
1326
1327
            // SPPID Symbol과 ID2 심볼의 크기 차이
1328 026f394f gaqhf
            double sizeWidth = 0;
1329
            double sizeHeight = 0;
1330
            SPPIDUtil.ConvertPointBystring(targetSymbol.SIZE, ref sizeWidth, ref sizeHeight);
1331
            if (sizeWidth == 0 || sizeHeight == 0)
1332
                throw new Exception("Check symbol size! \r\nUID : " + targetSymbol.UID);
1333
1334 d1eac84d gaqhf
            double percentX = (x2 - x1) / sizeWidth;
1335
            double percentY = (y2 - y1) / sizeHeight;
1336
1337
            double SPPIDgapX = gapX * percentX;
1338
            double SPPIDgapY = gapY * percentY;
1339
1340
            double[] SPPIDOriginPoint = new double[] { _TargetItem.get_XCoordinate() - SPPIDgapX, _TargetItem.get_YCoordinate() + SPPIDgapY };
1341
            double distance = double.MaxValue;
1342
            double[] resultPoint;
1343
            foreach (var point in points)
1344
            {
1345
                double result = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], SPPIDOriginPoint[0], SPPIDOriginPoint[1]);
1346
                if (distance > result)
1347
                {
1348
                    distance = result;
1349
                    resultPoint = point;
1350
                    x = point[0];
1351
                    y = point[1];
1352
                }
1353
            }
1354 2fdb56bf gaqhf
1355
            ReleaseCOMObjects(_TargetItem);
1356
        }
1357
1358 a0e3dca4 gaqhf
        private void GetTargetLineConnectorPoint(Connector targetConnector, Line targetLine, ref double x, ref double y)
1359
        {
1360
            int index = targetLine.CONNECTORS.IndexOf(targetConnector);
1361
            if (index == 0)
1362
            {
1363
                x = targetLine.SPPID.START_X;
1364
                y = targetLine.SPPID.START_Y;
1365
            }
1366
            else
1367
            {
1368
                x = targetLine.SPPID.END_X;
1369
                y = targetLine.SPPID.END_Y;
1370
            }
1371
        }
1372
1373 2fdb56bf gaqhf
        /// <summary>
1374
        /// SPPID Symbol의 Range를 구한다.
1375
        /// </summary>
1376
        /// <param name="symbol"></param>
1377
        /// <param name="range"></param>
1378
        private void GetSPPIDSymbolRangeAndConnectionPoints(Symbol symbol, ref double[] range, List<double[]> points)
1379
        {
1380
            LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1381
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1382
            double x1 = 0;
1383
            double y1 = 0;
1384
            double x2 = 0;
1385
            double y2 = 0;
1386
            symbol2d.Range(out x1, out y1, out x2, out y2);
1387
            range = new double[] { x1, y1, x2, y2 };
1388
1389
            for (int i = 1; i < int.MaxValue; i++)
1390
            {
1391
                double connX = 0;
1392
                double connY = 0;
1393
                if (_placement.PIDConnectPointLocation(_TargetItem, i, ref connX, ref connY))
1394
                    points.Add(new double[] { connX, connY });
1395
                else
1396
                    break;
1397
            }
1398
1399
            foreach (var childSymbol in symbol.ChildSymbols)
1400
                GetSPPIDChildSymbolRange(childSymbol, ref range, points);
1401
1402
            ReleaseCOMObjects(_TargetItem);
1403
        }
1404
1405 4e865771 gaqhf
        private void GetSPPIDSymbolRange(Symbol symbol, ref double[] range, bool bOnlySymbol = false, bool bForGraphic = false)
1406 d9794a6c gaqhf
        {
1407
            LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1408 7e4a64a3 gaqhf
            if (_TargetItem != null)
1409
            {
1410
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1411
                double x1 = 0;
1412
                double y1 = 0;
1413
                double x2 = 0;
1414
                double y2 = 0;
1415 4e865771 gaqhf
                if (!bForGraphic)
1416
                {
1417
                    symbol2d.Range(out x1, out y1, out x2, out y2);
1418
                    range = new double[] { x1, y1, x2, y2 };
1419
                }
1420
                else
1421
                {
1422
                    x1 = double.MaxValue;
1423
                    y1 = double.MaxValue;
1424
                    x2 = double.MinValue;
1425
                    y2 = double.MinValue;
1426
                    range = new double[] { x1, y1, x2, y2 };
1427 d9794a6c gaqhf
1428 4e865771 gaqhf
                    foreach (var item in symbol2d.DrawingObjects)
1429
                    {
1430
                        if (item.GetType() == typeof(Ingr.RAD2D.Line2d))
1431
                        {
1432
                            Ingr.RAD2D.Line2d rangeObject = item as Ingr.RAD2D.Line2d;
1433
                            if (rangeObject.Layer == "Default")
1434
                            {
1435
                                rangeObject.Range(out x1, out y1, out x2, out y2);
1436
                                range = new double[] {
1437
                                Math.Min(x1, range[0]),
1438
                                Math.Min(y1, range[1]),
1439
                                Math.Max(x2, range[2]),
1440
                                Math.Max(y2, range[3])
1441
                            };
1442
                            }
1443
                        }
1444
                        else if (item.GetType() == typeof(Ingr.RAD2D.Circle2d))
1445
                        {
1446
                            Ingr.RAD2D.Circle2d rangeObject = item as Ingr.RAD2D.Circle2d;
1447
                            if (rangeObject.Layer == "Default")
1448
                            {
1449
                                rangeObject.Range(out x1, out y1, out x2, out y2);
1450
                                range = new double[] {
1451
                                Math.Min(x1, range[0]),
1452
                                Math.Min(y1, range[1]),
1453
                                Math.Max(x2, range[2]),
1454
                                Math.Max(y2, range[3])
1455
                            };
1456
                            }
1457
                        }
1458
                        else if (item.GetType() == typeof(Ingr.RAD2D.Rectangle2d))
1459
                        {
1460
                            Ingr.RAD2D.Rectangle2d rangeObject = item as Ingr.RAD2D.Rectangle2d;
1461
                            if (rangeObject.Layer == "Default")
1462
                            {
1463
                                rangeObject.Range(out x1, out y1, out x2, out y2);
1464
                                range = new double[] {
1465
                                Math.Min(x1, range[0]),
1466
                                Math.Min(y1, range[1]),
1467
                                Math.Max(x2, range[2]),
1468
                                Math.Max(y2, range[3])
1469
                            };
1470
                            }
1471
                        }
1472
                        else if (item.GetType() == typeof(Ingr.RAD2D.Arc2d))
1473
                        {
1474
                            Ingr.RAD2D.Arc2d rangeObject = item as Ingr.RAD2D.Arc2d;
1475
                            if (rangeObject.Layer == "Default")
1476
                            {
1477
                                rangeObject.Range(out x1, out y1, out x2, out y2);
1478
                                range = new double[] {
1479
                                Math.Min(x1, range[0]),
1480
                                Math.Min(y1, range[1]),
1481
                                Math.Max(x2, range[2]),
1482
                                Math.Max(y2, range[3])
1483
                            };
1484
                            }
1485
                        }
1486
                    }
1487
                }
1488 d9794a6c gaqhf
1489 4e865771 gaqhf
                if (!bOnlySymbol)
1490
                {
1491
                    foreach (var childSymbol in symbol.ChildSymbols)
1492
                        GetSPPIDChildSymbolRange(childSymbol, ref range);
1493
                }
1494 7e4a64a3 gaqhf
                ReleaseCOMObjects(_TargetItem);
1495
            }
1496 d9794a6c gaqhf
        }
1497
1498 1299077b gaqhf
        private void GetSPPIDSymbolRange(LMLabelPersist labelPersist, ref double[] range)
1499
        {
1500
            if (labelPersist != null)
1501
            {
1502 4e865771 gaqhf
                double x1 = double.MaxValue;
1503
                double y1 = double.MaxValue;
1504
                double x2 = double.MinValue;
1505
                double y2 = double.MinValue;
1506
                range = new double[] { x1, y1, x2, y2 };
1507
1508 1299077b gaqhf
                Ingr.RAD2D.DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[labelPersist.get_GraphicOID().ToString()] as DependencyObject;
1509 4e865771 gaqhf
                foreach (var item in dependency.DrawingObjects)
1510 1299077b gaqhf
                {
1511 4e865771 gaqhf
                    Ingr.RAD2D.TextBox textBox = item as Ingr.RAD2D.TextBox;
1512
                    if (textBox != null)
1513
                    {
1514
                        if (dependency != null)
1515
                        {
1516
                            double tempX1;
1517
                            double tempY1;
1518
                            double tempX2;
1519
                            double tempY2;
1520
                            textBox.Range(out tempX1, out tempY1, out tempX2, out tempY2);
1521
                            x1 = Math.Min(x1, tempX1);
1522
                            y1 = Math.Min(y1, tempY1);
1523
                            x2 = Math.Max(x2, tempX2);
1524
                            y2 = Math.Max(y2, tempY2);
1525
1526
                            range = new double[] { x1, y1, x2, y2 };
1527
                        }
1528
                    }
1529 1299077b gaqhf
                }
1530 4e865771 gaqhf
                
1531 1299077b gaqhf
            }
1532
        }
1533
1534 d9794a6c gaqhf
        private void GetSPPIDSymbolRange(List<Symbol> symbols, ref double[] range)
1535
        {
1536
            double[] tempRange = new double[] { double.MaxValue, double.MaxValue, double.MinValue, double.MinValue };
1537
            foreach (var symbol in symbols)
1538
            {
1539
                LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1540
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1541
                double x1 = 0;
1542
                double y1 = 0;
1543
                double x2 = 0;
1544
                double y2 = 0;
1545
                symbol2d.Range(out x1, out y1, out x2, out y2);
1546
1547
                tempRange[0] = Math.Min(tempRange[0], x1);
1548
                tempRange[1] = Math.Min(tempRange[1], y1);
1549
                tempRange[2] = Math.Max(tempRange[2], x2);
1550
                tempRange[3] = Math.Max(tempRange[3], y2);
1551
1552
                foreach (var childSymbol in symbol.ChildSymbols)
1553 f1a7faf9 gaqhf
                    GetSPPIDChildSymbolRange(childSymbol, ref tempRange);
1554 d9794a6c gaqhf
1555
                ReleaseCOMObjects(_TargetItem);
1556
            }
1557
1558
            range = tempRange;
1559
        }
1560
1561 2fdb56bf gaqhf
        /// <summary>
1562
        /// Child Modeling 된 Symbol의 Range를 구한다.
1563
        /// </summary>
1564
        /// <param name="childSymbol"></param>
1565
        /// <param name="range"></param>
1566
        private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range, List<double[]> points)
1567
        {
1568
            LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId);
1569 3783c494 gaqhf
            if (_ChildSymbol != null)
1570 2fdb56bf gaqhf
            {
1571 3783c494 gaqhf
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()];
1572
                double x1 = 0;
1573
                double y1 = 0;
1574
                double x2 = 0;
1575
                double y2 = 0;
1576
                symbol2d.Range(out x1, out y1, out x2, out y2);
1577
                range[0] = Math.Min(range[0], x1);
1578
                range[1] = Math.Min(range[1], y1);
1579
                range[2] = Math.Max(range[2], x2);
1580
                range[3] = Math.Max(range[3], y2);
1581
1582
                for (int i = 1; i < int.MaxValue; i++)
1583
                {
1584
                    double connX = 0;
1585
                    double connY = 0;
1586
                    if (_placement.PIDConnectPointLocation(_ChildSymbol, i, ref connX, ref connY))
1587
                        points.Add(new double[] { connX, connY });
1588
                    else
1589
                        break;
1590
                }
1591 2fdb56bf gaqhf
1592 3783c494 gaqhf
                foreach (var loopChildSymbol in childSymbol.ChildSymbols)
1593
                    GetSPPIDChildSymbolRange(loopChildSymbol, ref range, points);
1594 2fdb56bf gaqhf
1595 3783c494 gaqhf
                ReleaseCOMObjects(_ChildSymbol);
1596
            }
1597 d1eac84d gaqhf
        }
1598
1599 d9794a6c gaqhf
        private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range)
1600
        {
1601
            LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId);
1602 7e4a64a3 gaqhf
            if (_ChildSymbol != null)
1603
            {
1604
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()];
1605
                double x1 = 0;
1606
                double y1 = 0;
1607
                double x2 = 0;
1608
                double y2 = 0;
1609
                symbol2d.Range(out x1, out y1, out x2, out y2);
1610
                range[0] = Math.Min(range[0], x1);
1611
                range[1] = Math.Min(range[1], y1);
1612
                range[2] = Math.Max(range[2], x2);
1613
                range[3] = Math.Max(range[3], y2);
1614 d9794a6c gaqhf
1615 7e4a64a3 gaqhf
                foreach (var loopChildSymbol in childSymbol.ChildSymbols)
1616
                    GetSPPIDChildSymbolRange(loopChildSymbol, ref range);
1617
                ReleaseCOMObjects(_ChildSymbol);
1618
            }
1619 d9794a6c gaqhf
        }
1620
1621 d1eac84d gaqhf
        /// <summary>
1622
        /// Label Symbol Modeling
1623
        /// </summary>
1624
        /// <param name="symbol"></param>
1625 73415441 gaqhf
        private void LabelSymbolModeling(Symbol symbol)
1626
        {
1627 fb386b8c gaqhf
            if (string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
1628 73415441 gaqhf
            {
1629 fb386b8c gaqhf
                BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL");
1630
                if (itemAttribute == null || string.IsNullOrEmpty(itemAttribute.VALUE) || itemAttribute.VALUE == "None")
1631
                    return;
1632
                Array points = new double[] { 0, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y };
1633
1634
                string symbolUID = itemAttribute.VALUE;
1635
                object targetItem = SPPIDUtil.FindObjectByUID(document, symbolUID);
1636
                if (targetItem != null &&
1637
                    (targetItem.GetType() == typeof(Symbol) ||
1638
                    targetItem.GetType() == typeof(Equipment)))
1639 73415441 gaqhf
                {
1640 fb386b8c gaqhf
                    // Object 아이템이 Symbol일 경우 Equipment일 경우 
1641
                    string sRep = null;
1642
                    if (targetItem.GetType() == typeof(Symbol))
1643
                        sRep = ((Symbol)targetItem).SPPID.RepresentationId;
1644
                    else if (targetItem.GetType() == typeof(Equipment))
1645
                        sRep = ((Equipment)targetItem).SPPID.RepresentationId;
1646
                    if (!string.IsNullOrEmpty(sRep))
1647 73415441 gaqhf
                    {
1648 fb386b8c gaqhf
                        // LEADER Line 검사
1649
                        bool leaderLine = false;
1650
                        SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
1651
                        if (symbolMapping != null)
1652
                            leaderLine = symbolMapping.LEADERLINE;
1653
1654
                        // Target Symbol Item 가져오고 Label Modeling
1655
                        LMSymbol _TargetItem = dataSource.GetSymbol(sRep);
1656
                        LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: _TargetItem.AsLMRepresentation(), IsLeaderVisible: leaderLine);
1657
1658
                        //Leader 선 센터로
1659
                        if (_LMLabelPresist != null)
1660 73415441 gaqhf
                        {
1661 fb386b8c gaqhf
                            // Target Item에 Label의 Attribute Input
1662
                            InputSymbolAttribute(targetItem, symbol.ATTRIBUTES);
1663
1664 32205389 gaqhf
                            string OID = _LMLabelPresist.get_GraphicOID().ToString();
1665 fb386b8c gaqhf
                            DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID] as DependencyObject;
1666
                            if (dependency != null)
1667 73415441 gaqhf
                            {
1668 fb386b8c gaqhf
                                bool result = false;
1669
                                foreach (var attributes in dependency.AttributeSets)
1670 73415441 gaqhf
                                {
1671 fb386b8c gaqhf
                                    foreach (var attribute in attributes)
1672 73415441 gaqhf
                                    {
1673 fb386b8c gaqhf
                                        string name = attribute.Name;
1674
                                        string value = attribute.GetValue().ToString();
1675
                                        if (name == "DrawingItemType" && value == "LabelPersist")
1676 73415441 gaqhf
                                        {
1677 fb386b8c gaqhf
                                            foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects)
1678 b2d1c1aa gaqhf
                                            {
1679 fb386b8c gaqhf
                                                if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLineString2d)
1680
                                                {
1681
                                                    Ingr.RAD2D.LineString2d lineString2D = drawingObject as Ingr.RAD2D.LineString2d;
1682
                                                    double prevX = _TargetItem.get_XCoordinate();
1683
                                                    double prevY = _TargetItem.get_YCoordinate();
1684
                                                    lineString2D.InsertVertex(lineString2D.VertexCount, prevX, prevY);
1685
                                                    lineString2D.RemoveVertex(lineString2D.VertexCount);
1686
                                                    result = true;
1687
                                                    break;
1688
                                                }
1689 b2d1c1aa gaqhf
                                            }
1690 73415441 gaqhf
                                        }
1691 fb386b8c gaqhf
1692
                                        if (result)
1693
                                            break;
1694 73415441 gaqhf
                                    }
1695 b2d1c1aa gaqhf
1696
                                    if (result)
1697
                                        break;
1698 73415441 gaqhf
                                }
1699
                            }
1700 fb386b8c gaqhf
1701 30ba9ae0 gaqhf
                            symbol.SPPID.RepresentationId = _LMLabelPresist.AsLMRepresentation().Id;
1702 fb386b8c gaqhf
                            _LMLabelPresist.Commit();
1703
                            ReleaseCOMObjects(_LMLabelPresist);
1704 73415441 gaqhf
                        }
1705
1706 fb386b8c gaqhf
                        ReleaseCOMObjects(_TargetItem);
1707 b2d1c1aa gaqhf
                    }
1708 73415441 gaqhf
                }
1709 fb386b8c gaqhf
                else if (targetItem != null && targetItem.GetType() == typeof(Line))
1710 0860c756 gaqhf
                {
1711 fb386b8c gaqhf
                    Line targetLine = targetItem as Line;
1712
                    Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId);
1713
                    LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y);
1714
                    if (connectedLMConnector != null)
1715 0860c756 gaqhf
                    {
1716 fb386b8c gaqhf
                        // LEADER Line 검사
1717
                        bool leaderLine = false;
1718
                        SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
1719
                        if (symbolMapping != null)
1720
                            leaderLine = symbolMapping.LEADERLINE;
1721
1722
                        LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: leaderLine);
1723
                        if (_LMLabelPresist != null)
1724
                        {
1725 6db0e733 gaqhf
                            symbol.SPPID.RepresentationId = _LMLabelPresist.AsLMRepresentation().Id;
1726 fb386b8c gaqhf
                            _LMLabelPresist.Commit();
1727
                            ReleaseCOMObjects(_LMLabelPresist);
1728
                        }
1729
                        ReleaseCOMObjects(connectedLMConnector);
1730 0860c756 gaqhf
                    }
1731
1732 fb386b8c gaqhf
                    foreach (var item in connectorVertices)
1733
                        if (item.Key != null)
1734
                            ReleaseCOMObjects(item.Key);
1735
                }
1736 0860c756 gaqhf
            }
1737 73415441 gaqhf
        }
1738
1739 74752074 gaqhf
        /// <summary>
1740
        /// Equipment를 실제로 Modeling 메서드
1741
        /// </summary>
1742
        /// <param name="equipment"></param>
1743 b9e9f4c8 gaqhf
        private void EquipmentModeling(Equipment equipment)
1744
        {
1745
            if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId))
1746
                return;
1747
1748
            LMSymbol _LMSymbol = null;
1749
            LMSymbol targetItem = null;
1750
            string mappingPath = equipment.SPPID.MAPPINGNAME;
1751
            double x = equipment.SPPID.ORIGINAL_X;
1752
            double y = equipment.SPPID.ORIGINAL_Y;
1753
            int mirror = 0;
1754
            double angle = equipment.ANGLE;
1755
1756 20972c61 gaqhf
            SPPIDUtil.ConvertGridPoint(ref x, ref y);
1757
1758 b9e9f4c8 gaqhf
            Connector connector = equipment.CONNECTORS.Find(conn => !string.IsNullOrEmpty(conn.CONNECTEDITEM) && conn.CONNECTEDITEM != "None");
1759
            if (connector != null)
1760
            {
1761
                Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment;
1762 fb2d9638 gaqhf
                VendorPackage connVendorPackage = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as VendorPackage;
1763 b9e9f4c8 gaqhf
                if (connEquipment != null)
1764
                {
1765
                    if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
1766
                        EquipmentModeling(connEquipment);
1767
1768
                    if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
1769
                    {
1770
                        targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId);
1771
                        if (targetItem != null)
1772
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem);
1773
                        else
1774
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1775
                    }
1776
                    else
1777
                    {
1778
                        _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1779
                    }
1780
                }
1781 fb2d9638 gaqhf
                else if (connVendorPackage != null)
1782
                {
1783
                    if (!string.IsNullOrEmpty(connVendorPackage.SPPID.RepresentationId))
1784
                    {
1785
                        targetItem = dataSource.GetSymbol(connVendorPackage.SPPID.RepresentationId);
1786
                        if (targetItem != null)
1787
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem);
1788
                        else
1789
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1790
                    }
1791
                }
1792 b9e9f4c8 gaqhf
                else
1793
                {
1794
                    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1795
                }
1796
            }
1797
            else
1798
            {
1799
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1800
            }
1801
1802
            if (_LMSymbol != null)
1803
            {
1804
                _LMSymbol.Commit();
1805
                equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1806 32205389 gaqhf
                equipment.SPPID.GraphicOID = _LMSymbol.get_GraphicOID().ToString();
1807 b9e9f4c8 gaqhf
                ReleaseCOMObjects(_LMSymbol);
1808
            }
1809
1810
            if (targetItem != null)
1811
            {
1812
                ReleaseCOMObjects(targetItem);
1813
            }
1814 7f00b26c gaqhf
1815 b9e9f4c8 gaqhf
            ReleaseCOMObjects(_LMSymbol);
1816
        }
1817
1818 fb2d9638 gaqhf
        private void VendorPackageModeling(VendorPackage vendorPackage)
1819
        {
1820
            ETCSetting setting = ETCSetting.GetInstance();
1821
            if (!string.IsNullOrEmpty(setting.VendorPackageSymbolPath))
1822
            {
1823
                string symbolPath = setting.VendorPackageSymbolPath;
1824
                double x = vendorPackage.SPPID.ORIGINAL_X;
1825
                double y = vendorPackage.SPPID.ORIGINAL_Y;
1826
1827
                LMSymbol symbol = _placement.PIDPlaceSymbol(symbolPath, x, y);
1828
                if (symbol != null)
1829
                {
1830
                    symbol.Commit();
1831
                    vendorPackage.SPPID.RepresentationId = symbol.AsLMRepresentation().Id;
1832
                }
1833
1834
                ReleaseCOMObjects(symbol);
1835
                symbol = null;
1836
            }
1837
        }
1838
1839 d9794a6c gaqhf
        /// <summary>
1840
        /// 첫 진입점
1841
        /// </summary>
1842
        /// <param name="symbol"></param>
1843
        private void SymbolModelingBySymbol(Symbol symbol)
1844
        {
1845 5a9396ae humkyung
            SymbolModeling(symbol, null);   /// 심볼을 생성한다
1846 d9794a6c gaqhf
            List<object> endObjects = new List<object>();
1847
            endObjects.Add(symbol);
1848 f1a7faf9 gaqhf
1849 5a9396ae humkyung
            /// 심볼에 연결되어 있는 항목들을 모델링한다
1850 d9794a6c gaqhf
            foreach (var connector in symbol.CONNECTORS)
1851 4d2571ab gaqhf
            {
1852 d9794a6c gaqhf
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1853
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1854 d1eac84d gaqhf
                {
1855 d9794a6c gaqhf
                    endObjects.Add(connItem);
1856
                    if (connItem.GetType() == typeof(Symbol))
1857 4d2571ab gaqhf
                    {
1858 d9794a6c gaqhf
                        Symbol connSymbol = connItem as Symbol;
1859
                        if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1860 4d2571ab gaqhf
                        {
1861 d9794a6c gaqhf
                            SymbolModeling(connSymbol, symbol);
1862
                        }
1863 6db30942 gaqhf
                        SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1864 f1a7faf9 gaqhf
                        SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1865 d9794a6c gaqhf
                    }
1866
                    else if (connItem.GetType() == typeof(Line))
1867
                    {
1868
                        Line connLine = connItem as Line;
1869 f1a7faf9 gaqhf
                        SymbolModelingByNeerLineLoop(connLine, endObjects, symbol);
1870 d9794a6c gaqhf
                    }
1871
                }
1872
            }
1873
        }
1874 4d2571ab gaqhf
1875 f1a7faf9 gaqhf
        private void SymbolModelingByNeerSymbolLoop(Symbol symbol, List<object> endObjects)
1876 d9794a6c gaqhf
        {
1877
            foreach (var connector in symbol.CONNECTORS)
1878
            {
1879
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1880
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1881
                {
1882
                    if (!endObjects.Contains(connItem))
1883
                    {
1884
                        endObjects.Add(connItem);
1885
                        if (connItem.GetType() == typeof(Symbol))
1886
                        {
1887
                            Symbol connSymbol = connItem as Symbol;
1888
                            if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1889 4d2571ab gaqhf
                            {
1890 d9794a6c gaqhf
                                SymbolModeling(connSymbol, symbol);
1891 4d2571ab gaqhf
                            }
1892 6db30942 gaqhf
                            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1893 f1a7faf9 gaqhf
                            SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1894 4d2571ab gaqhf
                        }
1895 d9794a6c gaqhf
                        else if (connItem.GetType() == typeof(Line))
1896
                        {
1897
                            Line connLine = connItem as Line;
1898 f1a7faf9 gaqhf
                            SymbolModelingByNeerLineLoop(connLine, endObjects, symbol);
1899 d9794a6c gaqhf
                        }
1900
                    }
1901
                }
1902
            }
1903
        }
1904 4d2571ab gaqhf
1905 f1a7faf9 gaqhf
        private void SymbolModelingByNeerLineLoop(Line line, List<object> endObjects, Symbol prevSymbol)
1906 d9794a6c gaqhf
        {
1907
            foreach (var connector in line.CONNECTORS)
1908
            {
1909
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1910
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1911
                {
1912
                    if (!endObjects.Contains(connItem))
1913
                    {
1914
                        endObjects.Add(connItem);
1915
                        if (connItem.GetType() == typeof(Symbol))
1916
                        {
1917
                            Symbol connSymbol = connItem as Symbol;
1918
                            if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1919
                            {
1920
                                List<Symbol> group = new List<Symbol>();
1921
                                SPPIDUtil.FindConnectedSymbolGroup(document, connSymbol, group);
1922 f1a7faf9 gaqhf
                                Symbol priority = prioritySymbols.Find(x => group.Contains(x));
1923
                                List<Symbol> endModelingGroup = new List<Symbol>();
1924
                                if (priority != null)
1925 d9794a6c gaqhf
                                {
1926 f1a7faf9 gaqhf
                                    SymbolGroupModeling(priority, group);
1927 d9794a6c gaqhf
1928
                                    // Range 겹치는지 확인해야함
1929
                                    double[] prevRange = null;
1930
                                    GetSPPIDSymbolRange(prevSymbol, ref prevRange);
1931
                                    double[] groupRange = null;
1932
                                    GetSPPIDSymbolRange(group, ref groupRange);
1933
1934
                                    double distanceX = 0;
1935
                                    double distanceY = 0;
1936 6d12a734 gaqhf
                                    bool overlapX = false;
1937
                                    bool overlapY = false;
1938
                                    SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y);
1939
                                    SPPIDUtil.CalcOverlap(prevRange, groupRange, ref distanceX, ref distanceY, ref overlapX, ref overlapY);
1940
                                    if ((slopeType == SlopeType.HORIZONTAL && overlapX) ||
1941
                                        (slopeType == SlopeType.VERTICAL && overlapY))
1942 d9794a6c gaqhf
                                    {
1943
                                        RemoveSymbol(group);
1944
                                        foreach (var _temp in group)
1945
                                            SPPIDUtil.CalcNewCoordinateForSymbol(_temp, prevSymbol, distanceX, distanceY);
1946
1947 f1a7faf9 gaqhf
                                        SymbolGroupModeling(priority, group);
1948 d9794a6c gaqhf
                                    }
1949
                                }
1950
                                else
1951
                                {
1952
                                    SymbolModeling(connSymbol, null);
1953
                                    // Range 겹치는지 확인해야함
1954
                                    double[] prevRange = null;
1955
                                    GetSPPIDSymbolRange(prevSymbol, ref prevRange);
1956
                                    double[] connRange = null;
1957
                                    GetSPPIDSymbolRange(connSymbol, ref connRange);
1958
1959
                                    double distanceX = 0;
1960
                                    double distanceY = 0;
1961 6d12a734 gaqhf
                                    bool overlapX = false;
1962
                                    bool overlapY = false;
1963
                                    SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y);
1964
                                    SPPIDUtil.CalcOverlap(prevRange, connRange, ref distanceX, ref distanceY, ref overlapX, ref overlapY);
1965
                                    if ((slopeType == SlopeType.HORIZONTAL && overlapX) ||
1966
                                        (slopeType == SlopeType.VERTICAL && overlapY))
1967 d9794a6c gaqhf
                                    {
1968
                                        RemoveSymbol(connSymbol);
1969
                                        SPPIDUtil.CalcNewCoordinateForSymbol(connSymbol, prevSymbol, distanceX, distanceY);
1970
1971
                                        SymbolModeling(connSymbol, null);
1972
                                    }
1973
                                }
1974
                            }
1975 6db30942 gaqhf
                            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1976 f1a7faf9 gaqhf
                            SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1977 d9794a6c gaqhf
                        }
1978
                        else if (connItem.GetType() == typeof(Line))
1979
                        {
1980
                            Line connLine = connItem as Line;
1981
                            if (!SPPIDUtil.IsBranchLine(connLine, line))
1982 f1a7faf9 gaqhf
                                SymbolModelingByNeerLineLoop(connLine, endObjects, prevSymbol);
1983 d9794a6c gaqhf
                        }
1984 4d2571ab gaqhf
                    }
1985 d1eac84d gaqhf
                }
1986
            }
1987
        }
1988
1989 f1a7faf9 gaqhf
        private void SymbolGroupModeling(Symbol firstSymbol, List<Symbol> group)
1990
        {
1991
            List<Symbol> endModelingGroup = new List<Symbol>();
1992
            SymbolModeling(firstSymbol, null);
1993
            endModelingGroup.Add(firstSymbol);
1994
            while (endModelingGroup.Count != group.Count)
1995
            {
1996
                foreach (var _symbol in group)
1997
                {
1998
                    if (!endModelingGroup.Contains(_symbol))
1999
                    {
2000
                        foreach (var _connector in _symbol.CONNECTORS)
2001
                        {
2002
                            Symbol _connSymbol = SPPIDUtil.FindObjectByUID(document, _connector.CONNECTEDITEM) as Symbol;
2003
                            if (_connSymbol != null && endModelingGroup.Contains(_connSymbol))
2004
                            {
2005
                                SymbolModeling(_symbol, _connSymbol);
2006
                                endModelingGroup.Add(_symbol);
2007
                                break;
2008
                            }
2009
                        }
2010
                    }
2011
                }
2012
            }
2013
        }
2014 d9794a6c gaqhf
2015 d1eac84d gaqhf
        /// <summary>
2016 74752074 gaqhf
        /// 심볼을 실제로 Modeling할때 ChildSymbol이 있다면 Modeling하는 메서드
2017
        /// </summary>
2018
        /// <param name="childSymbol"></param>
2019
        /// <param name="parentSymbol"></param>
2020 7e4a64a3 gaqhf
        private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol, Symbol parent)
2021 ac78b508 gaqhf
        {
2022 4b4dbca9 gaqhf
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()];
2023
            double x1 = 0;
2024
            double x2 = 0;
2025
            double y1 = 0;
2026
            double y2 = 0;
2027
            symbol2d.Range(out x1, out y1, out x2, out y2);
2028
2029
            LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol);
2030
            if (_LMSymbol != null)
2031
            {
2032 04fcadf1 gaqhf
                _LMSymbol.Commit();
2033 4b4dbca9 gaqhf
                childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
2034
                foreach (var item in childSymbol.ChildSymbols)
2035 7e4a64a3 gaqhf
                    CreateChildSymbol(item, _LMSymbol, parent);
2036 4b4dbca9 gaqhf
            }
2037 7f00b26c gaqhf
2038 ac78b508 gaqhf
2039
            ReleaseCOMObjects(_LMSymbol);
2040
        }
2041 dec9ecfd gaqhf
        double index = 0;
2042 32205389 gaqhf
        private void NewLineModeling(Line line, bool isBranchModeling = false)
2043 809a7640 gaqhf
        {
2044 f3e2693f gaqhf
            if (!string.IsNullOrEmpty(line.SPPID.ModelItemId) || (BranchLines.Contains(line) && !isBranchModeling))
2045 a0e3dca4 gaqhf
                return;
2046
2047
            List<Line> group = new List<Line>();
2048
            GetConnectedLineGroup(line, group);
2049
            LineCoordinateCorrection(group);
2050
2051
            foreach (var groupLine in group)
2052 809a7640 gaqhf
            {
2053 e283d483 gaqhf
                if (!isBranchModeling && SPPIDUtil.IsBranchLine(groupLine))
2054 5173ba5d gaqhf
                {
2055 f3e2693f gaqhf
                    BranchLines.Add(groupLine);
2056 5173ba5d gaqhf
                    continue;
2057
                }
2058 f9cc5190 gaqhf
2059 24b5276c gaqhf
                bool diagonal = false;
2060
                if (groupLine.SlopeType != SlopeType.HORIZONTAL && groupLine.SlopeType != SlopeType.VERTICAL)
2061
                    diagonal = true;
2062 5173ba5d gaqhf
                _LMAItem _LMAItem = _placement.PIDCreateItem(groupLine.SPPID.MAPPINGNAME);
2063
                LMSymbol _LMSymbolStart = null;
2064
                LMSymbol _LMSymbolEnd = null;
2065
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
2066
                foreach (var connector in groupLine.CONNECTORS)
2067 809a7640 gaqhf
                {
2068 5173ba5d gaqhf
                    double x = 0;
2069
                    double y = 0;
2070
                    GetTargetLineConnectorPoint(connector, groupLine, ref x, ref y);
2071
                    if (connector.ConnectedObject == null)
2072 809a7640 gaqhf
                    {
2073 5173ba5d gaqhf
                        placeRunInputs.AddPoint(x, y);
2074 a0e3dca4 gaqhf
                    }
2075 5173ba5d gaqhf
                    else if (connector.ConnectedObject.GetType() == typeof(Symbol))
2076 a0e3dca4 gaqhf
                    {
2077 5173ba5d gaqhf
                        Symbol targetSymbol = connector.ConnectedObject as Symbol;
2078 f9cc5190 gaqhf
                        GetTargetSymbolConnectorPoint(targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == groupLine), targetSymbol, ref x, ref y);
2079 5173ba5d gaqhf
                        if (groupLine.CONNECTORS.IndexOf(connector) == 0)
2080 a0e3dca4 gaqhf
                        {
2081 5173ba5d gaqhf
                            _LMSymbolStart = GetTargetSymbol(targetSymbol, groupLine);
2082 3783c494 gaqhf
                            if (_LMSymbolStart != null)
2083 24b5276c gaqhf
                                placeRunInputs.AddSymbolTarget(_LMSymbolStart, x, y, diagonal);
2084 3783c494 gaqhf
                            else
2085
                                placeRunInputs.AddPoint(x, y);
2086 5173ba5d gaqhf
                        }
2087
                        else
2088
                        {
2089
                            _LMSymbolEnd = GetTargetSymbol(targetSymbol, groupLine);
2090 3783c494 gaqhf
                            if (_LMSymbolEnd != null)
2091 24b5276c gaqhf
                                placeRunInputs.AddSymbolTarget(_LMSymbolEnd, x, y, diagonal);
2092 3783c494 gaqhf
                            else
2093
                                placeRunInputs.AddPoint(x, y);
2094 a0e3dca4 gaqhf
                        }
2095 5173ba5d gaqhf
                    }
2096
                    else if (connector.ConnectedObject.GetType() == typeof(Line))
2097
                    {
2098
                        Line targetLine = connector.ConnectedObject as Line;
2099
                        if (!string.IsNullOrEmpty(targetLine.SPPID.ModelItemId))
2100 a0e3dca4 gaqhf
                        {
2101 5173ba5d gaqhf
                            LMConnector targetConnector = FindTargetLMConnectorForBranch(line, targetLine, ref x, ref y);
2102 1c944b34 gaqhf
                            if (targetConnector != null)
2103 0ff6e67f gaqhf
                            {
2104
                                placeRunInputs.AddConnectorTarget(targetConnector, x, y, diagonal);
2105
                                ChangeLineSPPIDCoordinateByConnector(groupLine, targetLine, x, y, false);
2106
                            }
2107
                            else
2108
                            {
2109
                                placeRunInputs.AddPoint( x, y);
2110
                                ChangeLineSPPIDCoordinateByConnector(groupLine, targetLine, x, y, false);
2111
                            }
2112 a0e3dca4 gaqhf
                        }
2113 5173ba5d gaqhf
                        else
2114 809a7640 gaqhf
                        {
2115 5173ba5d gaqhf
                            if (groupLine.CONNECTORS.IndexOf(connector) == 0)
2116 a0e3dca4 gaqhf
                            {
2117 dec9ecfd gaqhf
                                index += 0.01;
2118 5173ba5d gaqhf
                                if (groupLine.SlopeType == SlopeType.HORIZONTAL)
2119 dec9ecfd gaqhf
                                    placeRunInputs.AddPoint(x, -0.1 - index);
2120 5173ba5d gaqhf
                                else if (groupLine.SlopeType == SlopeType.VERTICAL)
2121 dec9ecfd gaqhf
                                    placeRunInputs.AddPoint(-0.1 - index, y);
2122 5173ba5d gaqhf
                                else
2123 ca6e0f51 gaqhf
                                {
2124 60f4405d gaqhf
                                    Line nextLine = groupLine.CONNECTORS[0].ConnectedObject as Line;
2125
                                    if (SPPIDUtil.CalcAngle(nextLine.SPPID.START_X, nextLine.SPPID.START_Y, nextLine.SPPID.END_X, nextLine.SPPID.END_Y) < 45)
2126 dec9ecfd gaqhf
                                        placeRunInputs.AddPoint(-0.1 - index, y);
2127 60f4405d gaqhf
                                    else
2128
                                        placeRunInputs.AddPoint(x, -0.1 - index);
2129 ca6e0f51 gaqhf
                                }
2130 a0e3dca4 gaqhf
                            }
2131 809a7640 gaqhf
2132 5173ba5d gaqhf
                            placeRunInputs.AddPoint(x, y);
2133 809a7640 gaqhf
2134 5173ba5d gaqhf
                            if (groupLine.CONNECTORS.IndexOf(connector) == 1)
2135
                            {
2136 dec9ecfd gaqhf
                                index += 0.01;
2137 5173ba5d gaqhf
                                if (groupLine.SlopeType == SlopeType.HORIZONTAL)
2138 dec9ecfd gaqhf
                                    placeRunInputs.AddPoint(x, -0.1 - index);
2139 5173ba5d gaqhf
                                else if (groupLine.SlopeType == SlopeType.VERTICAL)
2140 dec9ecfd gaqhf
                                    placeRunInputs.AddPoint(-0.1 - index, y);
2141 5173ba5d gaqhf
                                else
2142 ca6e0f51 gaqhf
                                {
2143 60f4405d gaqhf
                                    Line nextLine = groupLine.CONNECTORS[1].ConnectedObject as Line;
2144
                                    if (SPPIDUtil.CalcAngle(nextLine.SPPID.START_X, nextLine.SPPID.START_Y, nextLine.SPPID.END_X, nextLine.SPPID.END_Y) < 45)
2145 dec9ecfd gaqhf
                                        placeRunInputs.AddPoint(-0.1 - index, y);
2146 60f4405d gaqhf
                                    else
2147
                                        placeRunInputs.AddPoint(x, -0.1 - index);
2148 ca6e0f51 gaqhf
                                }
2149 a0e3dca4 gaqhf
                            }
2150 809a7640 gaqhf
                        }
2151
                    }
2152 5173ba5d gaqhf
                }
2153 809a7640 gaqhf
2154 5173ba5d gaqhf
                LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2155
                if (_lMConnector != null)
2156
                {
2157 04fcadf1 gaqhf
                    _lMConnector.Commit();
2158 5173ba5d gaqhf
                    groupLine.SPPID.ModelItemId = _lMConnector.ModelItemID;
2159 fae4f386 gaqhf
2160 5173ba5d gaqhf
                    bool bRemodelingStart = false;
2161
                    if (_LMSymbolStart != null)
2162
                        NeedReModeling(groupLine, _LMSymbolStart, ref bRemodelingStart);
2163
                    bool bRemodelingEnd = false;
2164
                    if (_LMSymbolEnd != null)
2165
                        NeedReModeling(groupLine, _LMSymbolEnd, ref bRemodelingEnd);
2166
2167
                    if (bRemodelingStart || bRemodelingEnd)
2168
                        ReModelingLine(groupLine, _lMConnector, _LMSymbolStart, _LMSymbolEnd, bRemodelingStart, bRemodelingEnd);
2169 32205389 gaqhf
2170
                    FlowMarkModeling(groupLine);
2171 8701de36 gaqhf
                    LineNumberModelingOnlyOne(groupLine);
2172 32205389 gaqhf
2173 5173ba5d gaqhf
                    ReleaseCOMObjects(_lMConnector);
2174 63a112d9 gaqhf
2175
                    LMModelItem modelItem = dataSource.GetModelItem(groupLine.SPPID.ModelItemId);
2176
                    if (modelItem != null)
2177
                    {
2178
                        LMAAttribute attribute = modelItem.Attributes["FlowDirection"];
2179 4c7a4484 gaqhf
                        if (attribute != null)
2180
                            attribute.set_Value("End 1 is upstream (Inlet)");
2181 63a112d9 gaqhf
                        modelItem.Commit();
2182
                    }
2183
                    ReleaseCOMObjects(modelItem);
2184
                    modelItem = null;
2185 5173ba5d gaqhf
                }
2186 dec9ecfd gaqhf
                else if (!isBranchModeling)
2187
                {
2188
                    Log.Write("Main Line Modeling : " + groupLine.UID);
2189
                }
2190 809a7640 gaqhf
2191 5173ba5d gaqhf
                List<object> removeLines = groupLine.CONNECTORS.FindAll(x =>
2192
                x.ConnectedObject != null &&
2193
                x.ConnectedObject.GetType() == typeof(Line) &&
2194
                !string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId))
2195
                .Select(x => x.ConnectedObject)
2196
                .ToList();
2197 2fdb56bf gaqhf
2198 5173ba5d gaqhf
                foreach (var item in removeLines)
2199
                    RemoveLineForModeling(item as Line);
2200 5e6ecf05 gaqhf
2201 5173ba5d gaqhf
                if (_LMAItem != null)
2202
                    ReleaseCOMObjects(_LMAItem);
2203
                if (placeRunInputs != null)
2204
                    ReleaseCOMObjects(placeRunInputs);
2205
                if (_LMSymbolStart != null)
2206
                    ReleaseCOMObjects(_LMSymbolStart);
2207
                if (_LMSymbolEnd != null)
2208
                    ReleaseCOMObjects(_LMSymbolEnd);
2209 5e6ecf05 gaqhf
2210 f3e2693f gaqhf
                if (isBranchModeling && BranchLines.Contains(groupLine))
2211
                    BranchLines.Remove(groupLine);
2212 a0e3dca4 gaqhf
            }
2213
        }
2214 5e6ecf05 gaqhf
2215 a0e3dca4 gaqhf
        private void RemoveLineForModeling(Line line)
2216
        {
2217
            LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
2218
            if (modelItem != null)
2219
            {
2220
                foreach (LMRepresentation rep in modelItem.Representations)
2221
                {
2222
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2223 7f00b26c gaqhf
                    {
2224 a0e3dca4 gaqhf
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2225 32205389 gaqhf
                        dynamic OID = rep.get_GraphicOID().ToString();
2226 a0e3dca4 gaqhf
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2227
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2228
                        int verticesCount = lineStringGeometry.VertexCount;
2229
                        double[] vertices = null;
2230
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
2231
                        for (int i = 0; i < verticesCount; i++)
2232 7f00b26c gaqhf
                        {
2233 a0e3dca4 gaqhf
                            double x = 0;
2234
                            double y = 0;
2235
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
2236 6924abc6 gaqhf
                            if (verticesCount == 2 && (x < 0 || y < 0))
2237 a0e3dca4 gaqhf
                                _placement.PIDRemovePlacement(rep);
2238 c2ec33f5 gaqhf
                        }
2239 a0e3dca4 gaqhf
                        ReleaseCOMObjects(_LMConnector);
2240 5e6ecf05 gaqhf
                    }
2241 a0e3dca4 gaqhf
                }
2242 7f00b26c gaqhf
2243 a0e3dca4 gaqhf
                ReleaseCOMObjects(modelItem);
2244
            }
2245
        }
2246
2247
        private void GetConnectedLineGroup(Line line, List<Line> group)
2248
        {
2249
            if (!group.Contains(line))
2250
                group.Add(line);
2251
            foreach (var connector in line.CONNECTORS)
2252
            {
2253
                if (connector.ConnectedObject != null &&
2254
                    connector.ConnectedObject.GetType() == typeof(Line) &&
2255
                    !group.Contains(connector.ConnectedObject) &&
2256
                    string.IsNullOrEmpty(((Line)connector.ConnectedObject).SPPID.ModelItemId))
2257
                {
2258
                    Line connLine = connector.ConnectedObject as Line;
2259
                    if (!SPPIDUtil.IsBranchLine(connLine, line))
2260 24515a3a gaqhf
                    {
2261
                        if (line.CONNECTORS.IndexOf(connector) == 0)
2262
                            group.Insert(0, connLine);
2263
                        else
2264
                            group.Add(connLine);
2265 a0e3dca4 gaqhf
                        GetConnectedLineGroup(connLine, group);
2266 24515a3a gaqhf
                    }
2267 7f00b26c gaqhf
                }
2268
            }
2269 a0e3dca4 gaqhf
        }
2270 7f00b26c gaqhf
2271 a0e3dca4 gaqhf
        private void LineCoordinateCorrection(List<Line> group)
2272
        {
2273
            // 순서대로 전 Item 기준 정렬
2274
            LineCoordinateCorrectionByStart(group);
2275
2276
            // 역으로 심볼이 있을 경우 좌표 보정
2277
            LineCoordinateCorrectionForLastLine(group);
2278
        }
2279
2280
        private void LineCoordinateCorrectionByStart(List<Line> group)
2281
        {
2282
            for (int i = 0; i < group.Count; i++)
2283 7f00b26c gaqhf
            {
2284 a0e3dca4 gaqhf
                Line line = group[i];
2285
                if (i == 0)
2286 7f00b26c gaqhf
                {
2287 a0e3dca4 gaqhf
                    Connector symbolConnector = line.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol));
2288
                    if (symbolConnector != null)
2289
                        LineCoordinateCorrectionByConnItem(line, symbolConnector.ConnectedObject);
2290 7f00b26c gaqhf
                }
2291 a0e3dca4 gaqhf
                else if (i != 0)
2292 7f00b26c gaqhf
                {
2293 a0e3dca4 gaqhf
                    LineCoordinateCorrectionByConnItem(line, group[i - 1]);
2294
                }
2295
            }
2296
        }
2297 b66a2996 gaqhf
2298 a0e3dca4 gaqhf
        private void LineCoordinateCorrectionForLastLine(List<Line> group)
2299
        {
2300
            Line checkLine = group[group.Count - 1];
2301
            Connector lastSymbolConnector = checkLine.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol));
2302
            if (lastSymbolConnector != null)
2303
            {
2304
                LineCoordinateCorrectionByConnItem(checkLine, lastSymbolConnector.ConnectedObject);
2305
                for (int i = group.Count - 2; i >= 0; i--)
2306
                {
2307
                    Line line = group[i + 1];
2308
                    Line prevLine = group[i];
2309 0bbd73b5 gaqhf
2310 a0e3dca4 gaqhf
                    // 같으면 보정
2311
                    if (line.SlopeType == prevLine.SlopeType)
2312
                        LineCoordinateCorrectionByConnItem(prevLine, line);
2313
                    else
2314 c2ec33f5 gaqhf
                    {
2315 a0e3dca4 gaqhf
                        if (line.SlopeType == SlopeType.HORIZONTAL)
2316 d63050d6 gaqhf
                        {
2317 a0e3dca4 gaqhf
                            double prevX = 0;
2318
                            double prevY = 0;
2319
                            GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY);
2320
                            ChangeLineSPPIDCoordinateByConnectorOnlyX(line, prevLine, prevX);
2321 d63050d6 gaqhf
2322 a0e3dca4 gaqhf
                            double x = 0;
2323
                            double y = 0;
2324
                            GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y);
2325
                            ChangeLineSPPIDCoordinateByConnectorOnlyY(prevLine, line, y);
2326 d63050d6 gaqhf
                        }
2327 a0e3dca4 gaqhf
                        else if (line.SlopeType == SlopeType.VERTICAL)
2328 d63050d6 gaqhf
                        {
2329 a0e3dca4 gaqhf
                            double prevX = 0;
2330
                            double prevY = 0;
2331
                            GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY);
2332
                            ChangeLineSPPIDCoordinateByConnectorOnlyY(line, prevLine, prevY);
2333 d63050d6 gaqhf
2334 a0e3dca4 gaqhf
                            double x = 0;
2335
                            double y = 0;
2336
                            GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y);
2337
                            ChangeLineSPPIDCoordinateByConnectorOnlyX(prevLine, line, x);
2338 d63050d6 gaqhf
                        }
2339 a0e3dca4 gaqhf
                        break;
2340 c2ec33f5 gaqhf
                    }
2341 1ab9a205 gaqhf
                }
2342 c2ec33f5 gaqhf
            }
2343 a0e3dca4 gaqhf
        }
2344 7f00b26c gaqhf
2345 a0e3dca4 gaqhf
        private void LineCoordinateCorrectionByConnItem(Line line, object connItem)
2346
        {
2347
            double x = 0;
2348
            double y = 0;
2349
            if (connItem.GetType() == typeof(Symbol))
2350
            {
2351
                Symbol targetSymbol = connItem as Symbol;
2352
                Connector targetConnector = targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == line);
2353
                if (targetConnector != null)
2354
                    GetTargetSymbolConnectorPoint(targetConnector, targetSymbol, ref x, ref y);
2355
                else
2356
                    throw new Exception("Target symbol UID : " + targetSymbol.UID + "\r\nLine UID : " + line.UID);
2357
            }
2358
            else if (connItem.GetType() == typeof(Line))
2359 c2ec33f5 gaqhf
            {
2360 a0e3dca4 gaqhf
                Line targetLine = connItem as Line;
2361
                GetTargetLineConnectorPoint(targetLine.CONNECTORS.Find(z => z.ConnectedObject == line), targetLine, ref x, ref y);
2362
            }
2363 7f00b26c gaqhf
2364 a0e3dca4 gaqhf
            ChangeLineSPPIDCoordinateByConnector(line, connItem, x, y);
2365
        }
2366 7f00b26c gaqhf
2367 a0e3dca4 gaqhf
        private void ChangeLineSPPIDCoordinateByConnector(Line line, object connItem, double x, double y, bool changeOtherCoordinate = true)
2368
        {
2369
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
2370
            int index = line.CONNECTORS.IndexOf(connector);
2371
            if (index == 0)
2372
            {
2373
                line.SPPID.START_X = x;
2374
                line.SPPID.START_Y = y;
2375
                if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate)
2376
                    line.SPPID.END_Y = y;
2377
                else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate)
2378
                    line.SPPID.END_X = x;
2379
            }
2380
            else
2381
            {
2382
                line.SPPID.END_X = x;
2383
                line.SPPID.END_Y = y;
2384
                if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate)
2385
                    line.SPPID.START_Y = y;
2386
                else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate)
2387
                    line.SPPID.START_X = x;
2388 c2ec33f5 gaqhf
            }
2389 a0e3dca4 gaqhf
        }
2390 7f00b26c gaqhf
2391 a0e3dca4 gaqhf
        private void ChangeLineSPPIDCoordinateByConnectorOnlyX(Line line, object connItem, double x)
2392
        {
2393
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
2394
            int index = line.CONNECTORS.IndexOf(connector);
2395
            if (index == 0)
2396
            {
2397
                line.SPPID.START_X = x;
2398
                if (line.SlopeType == SlopeType.VERTICAL)
2399
                    line.SPPID.END_X = x;
2400
            }
2401
            else
2402
            {
2403
                line.SPPID.END_X = x;
2404
                if (line.SlopeType == SlopeType.VERTICAL)
2405
                    line.SPPID.START_X = x;
2406
            }
2407
        }
2408 7f00b26c gaqhf
2409 a0e3dca4 gaqhf
        private void ChangeLineSPPIDCoordinateByConnectorOnlyY(Line line, object connItem, double y)
2410
        {
2411
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
2412
            int index = line.CONNECTORS.IndexOf(connector);
2413
            if (index == 0)
2414
            {
2415
                line.SPPID.START_Y = y;
2416
                if (line.SlopeType == SlopeType.HORIZONTAL)
2417
                    line.SPPID.END_Y = y;
2418
            }
2419
            else
2420
            {
2421
                line.SPPID.END_Y = y;
2422
                if (line.SlopeType == SlopeType.HORIZONTAL)
2423
                    line.SPPID.START_Y = y;
2424
            }
2425 1b261371 gaqhf
        }
2426
2427 0860c756 gaqhf
        private void NeedReModeling(Line line, LMSymbol symbol, ref bool result)
2428 ac82b020 gaqhf
        {
2429 0860c756 gaqhf
            if (symbol != null)
2430 ac82b020 gaqhf
            {
2431 fb386b8c gaqhf
                string repID = symbol.AsLMRepresentation().Id;
2432
                string symbolUID = SPPIDUtil.FindSymbolByRepresentationID(document, repID).UID;
2433
                string lineUID = line.UID;
2434 ac82b020 gaqhf
2435 fb386b8c gaqhf
                SpecBreak startSpecBreak = document.SpecBreaks.Find(x =>
2436
                (x.DownStreamUID == symbolUID || x.UpStreamUID == symbolUID) &&
2437
                (x.DownStreamUID == lineUID || x.UpStreamUID == lineUID));
2438 71ba1ca3 gaqhf
2439 fb386b8c gaqhf
                EndBreak startEndBreak = document.EndBreaks.Find(x =>
2440
                (x.OWNER == symbolUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbolUID) &&
2441
                (x.OWNER == lineUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == lineUID));
2442 ac82b020 gaqhf
2443 fb386b8c gaqhf
                if (startSpecBreak != null || startEndBreak != null)
2444
                    result = true;
2445 ac82b020 gaqhf
            }
2446
        }
2447 7f00b26c gaqhf
2448 74752074 gaqhf
        /// <summary>
2449 1ab9a205 gaqhf
        /// Symbol에 붙을 경우 Line을 Remodeling 한다.
2450
        /// </summary>
2451
        /// <param name="lines"></param>
2452
        /// <param name="prevLMConnector"></param>
2453
        /// <param name="startSymbol"></param>
2454
        /// <param name="endSymbol"></param>
2455 5173ba5d gaqhf
        private void ReModelingLine(Line line, LMConnector prevLMConnector, LMSymbol startSymbol, LMSymbol endSymbol, bool bStart, bool bEnd)
2456 1ab9a205 gaqhf
        {
2457
            string symbolPath = string.Empty;
2458
            #region get symbol path
2459
            LMModelItem modelItem = dataSource.GetModelItem(prevLMConnector.ModelItemID);
2460 a31a512e gaqhf
            symbolPath = GetSPPIDFileName(modelItem);
2461 d77973b3 gaqhf
            ReleaseCOMObjects(modelItem);
2462 1ab9a205 gaqhf
            #endregion
2463 24b5276c gaqhf
            bool diagonal = false;
2464
            if (line.SlopeType != SlopeType.HORIZONTAL && line.SlopeType != SlopeType.VERTICAL)
2465
                diagonal = true;
2466 1ab9a205 gaqhf
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
2467
            LMConnector newConnector = null;
2468 32205389 gaqhf
            dynamic OID = prevLMConnector.get_GraphicOID().ToString();
2469 1ab9a205 gaqhf
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2470
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2471
            int verticesCount = lineStringGeometry.VertexCount;
2472
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
2473 7f00b26c gaqhf
2474 1ab9a205 gaqhf
            List<double[]> vertices = new List<double[]>();
2475
            for (int i = 1; i <= verticesCount; i++)
2476
            {
2477
                double x = 0;
2478
                double y = 0;
2479
                lineStringGeometry.GetVertex(i, ref x, ref y);
2480
                vertices.Add(new double[] { x, y });
2481
            }
2482
2483
            for (int i = 0; i < vertices.Count; i++)
2484
            {
2485
                double[] points = vertices[i];
2486
                // 시작 심볼이 있고 첫번째 좌표일 때
2487
                if (startSymbol != null && i == 0)
2488
                {
2489 ac82b020 gaqhf
                    if (bStart)
2490
                    {
2491
                        SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i + 1][0], vertices[i + 1][1]);
2492
                        if (slopeType == SlopeType.HORIZONTAL)
2493
                            placeRunInputs.AddPoint(points[0], -0.1);
2494
                        else if (slopeType == SlopeType.VERTICAL)
2495
                            placeRunInputs.AddPoint(-0.1, points[1]);
2496
                        else
2497
                            placeRunInputs.AddPoint(points[0], -0.1);
2498 1ab9a205 gaqhf
2499 ac82b020 gaqhf
                        placeRunInputs.AddPoint(points[0], points[1]);
2500
                    }
2501
                    else
2502
                    {
2503 24b5276c gaqhf
                        placeRunInputs.AddSymbolTarget(startSymbol, points[0], points[1], diagonal);
2504 ac82b020 gaqhf
                    }
2505 1ab9a205 gaqhf
                }
2506
                // 마지막 심볼이 있고 마지막 좌표일 때
2507
                else if (endSymbol != null && i == vertices.Count - 1)
2508
                {
2509 ac82b020 gaqhf
                    if (bEnd)
2510
                    {
2511
                        placeRunInputs.AddPoint(points[0], points[1]);
2512 1ab9a205 gaqhf
2513 ac82b020 gaqhf
                        SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i - 1][0], vertices[i - 1][1]);
2514
                        if (slopeType == SlopeType.HORIZONTAL)
2515
                            placeRunInputs.AddPoint(points[0], -0.1);
2516
                        else if (slopeType == SlopeType.VERTICAL)
2517
                            placeRunInputs.AddPoint(-0.1, points[1]);
2518
                        else
2519
                            placeRunInputs.AddPoint(points[0], -0.1);
2520
                    }
2521 1ab9a205 gaqhf
                    else
2522 ac82b020 gaqhf
                    {
2523 24b5276c gaqhf
                        placeRunInputs.AddSymbolTarget(endSymbol, points[0], points[1], diagonal);
2524 ac82b020 gaqhf
                    }
2525 1ab9a205 gaqhf
                }
2526
                // 첫번째이며 시작 심볼이 아니고 Connecotr일 경우
2527
                else if (i == 0 && prevLMConnector.ConnectItem1SymbolObject != null)
2528 24b5276c gaqhf
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem1SymbolObject, points[0], points[1], diagonal);
2529 1ab9a205 gaqhf
                // 마지막이며 마지막 심볼이 아니고 Connecotr일 경우
2530
                else if (i == vertices.Count - 1 && prevLMConnector.ConnectItem2SymbolObject != null)
2531 24b5276c gaqhf
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem2SymbolObject, points[0], points[1], diagonal);
2532 1ab9a205 gaqhf
                else
2533
                    placeRunInputs.AddPoint(points[0], points[1]);
2534
            }
2535
2536
            _placement.PIDRemovePlacement(prevLMConnector.AsLMRepresentation());
2537
            newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2538
2539
            ReleaseCOMObjects(placeRunInputs);
2540
            ReleaseCOMObjects(_LMAItem);
2541
            ReleaseCOMObjects(modelItem);
2542
2543
            if (newConnector != null)
2544
            {
2545 04fcadf1 gaqhf
                newConnector.Commit();
2546 ac82b020 gaqhf
                if (startSymbol != null && bStart)
2547 1ab9a205 gaqhf
                {
2548
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
2549
                    placeRunInputs = new PlaceRunInputs();
2550 f1a7faf9 gaqhf
                    placeRunInputs.AddSymbolTarget(startSymbol, vertices[0][0], vertices[0][1]);
2551
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[0][0], vertices[0][1]);
2552 1ab9a205 gaqhf
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2553
                    if (_LMConnector != null)
2554
                    {
2555 04fcadf1 gaqhf
                        _LMConnector.Commit();
2556 1ab9a205 gaqhf
                        RemoveConnectorForReModelingLine(newConnector);
2557 87f02fc0 gaqhf
                        ZeroLengthModelItemID.Add(_LMConnector.ModelItemID);
2558 1ab9a205 gaqhf
                        ReleaseCOMObjects(_LMConnector);
2559
                    }
2560
                    ReleaseCOMObjects(placeRunInputs);
2561
                    ReleaseCOMObjects(_LMAItem);
2562
                }
2563
2564 ac82b020 gaqhf
                if (endSymbol != null && bEnd)
2565 1ab9a205 gaqhf
                {
2566
                    if (startSymbol != null)
2567
                    {
2568
                        Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(newConnector.ModelItemID);
2569
                        newConnector = dicVertices.First().Key;
2570
                    }
2571
2572
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
2573
                    placeRunInputs = new PlaceRunInputs();
2574 f1a7faf9 gaqhf
                    placeRunInputs.AddSymbolTarget(endSymbol, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
2575
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
2576 1ab9a205 gaqhf
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2577
                    if (_LMConnector != null)
2578
                    {
2579 04fcadf1 gaqhf
                        _LMConnector.Commit();
2580 1ab9a205 gaqhf
                        RemoveConnectorForReModelingLine(newConnector);
2581 1ff0105e gaqhf
                        ZeroLengthModelItemIDReverse.Add(_LMConnector.ModelItemID);
2582 1ab9a205 gaqhf
                        ReleaseCOMObjects(_LMConnector);
2583
                    }
2584
                    ReleaseCOMObjects(placeRunInputs);
2585
                    ReleaseCOMObjects(_LMAItem);
2586
                }
2587
2588 5173ba5d gaqhf
                line.SPPID.ModelItemId = newConnector.ModelItemID;
2589 1ab9a205 gaqhf
                ReleaseCOMObjects(newConnector);
2590
            }
2591
2592
            ReleaseCOMObjects(modelItem);
2593
        }
2594
2595
        /// <summary>
2596
        /// Remodeling 과정에서 생긴 불필요한 Connector 제거
2597
        /// </summary>
2598
        /// <param name="connector"></param>
2599
        private void RemoveConnectorForReModelingLine(LMConnector connector)
2600
        {
2601
            Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(connector.ModelItemID);
2602
            foreach (var item in dicVertices)
2603
            {
2604 1805d3b7 gaqhf
                if (item.Value.Count == 2)
2605 1ab9a205 gaqhf
                {
2606 1805d3b7 gaqhf
                    bool result = false;
2607
                    foreach (var point in item.Value)
2608 1ab9a205 gaqhf
                    {
2609 1805d3b7 gaqhf
                        if (point[0] < 0 || point[1] < 0)
2610
                        {
2611
                            result = true;
2612
                            _placement.PIDRemovePlacement(item.Key.AsLMRepresentation());
2613
                            break;
2614
                        }
2615 1ab9a205 gaqhf
                    }
2616
2617 1805d3b7 gaqhf
                    if (result)
2618
                        break;
2619
                }
2620 1ab9a205 gaqhf
            }
2621
            foreach (var item in dicVertices)
2622
                ReleaseCOMObjects(item.Key);
2623
        }
2624
2625
        /// <summary>
2626 74752074 gaqhf
        /// Symbol이 모델링된 SPPPID Symbol Object를 반환 - 연결된 Symbol이 ChildSymbol일 수도 있기때문에 메서드 개발
2627
        /// </summary>
2628
        /// <param name="symbol"></param>
2629
        /// <param name="line"></param>
2630
        /// <returns></returns>
2631 f2baa6a3 gaqhf
        private LMSymbol GetTargetSymbol(Symbol symbol, Line line)
2632
        {
2633
            LMSymbol _LMSymbol = null;
2634
            foreach (var connector in symbol.CONNECTORS)
2635
            {
2636 a0e3dca4 gaqhf
                if (connector.CONNECTEDITEM == line.UID)
2637 6b298450 gaqhf
                {
2638 a0e3dca4 gaqhf
                    if (connector.Index == 0)
2639
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
2640
                    else
2641 0860c756 gaqhf
                    {
2642 a0e3dca4 gaqhf
                        ChildSymbol child = null;
2643
                        foreach (var childSymbol in symbol.ChildSymbols)
2644 0860c756 gaqhf
                        {
2645 a0e3dca4 gaqhf
                            if (childSymbol.Connectors.Contains(connector))
2646
                                child = childSymbol;
2647
                            else
2648
                                child = GetChildSymbolByConnector(childSymbol, connector);
2649
2650
                            if (child != null)
2651 0860c756 gaqhf
                                break;
2652
                        }
2653
2654 a0e3dca4 gaqhf
                        if (child != null)
2655
                            _LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId);
2656 0860c756 gaqhf
                    }
2657
2658 a0e3dca4 gaqhf
                    break;
2659 335b7a24 gaqhf
                }
2660 a0e3dca4 gaqhf
            }
2661 335b7a24 gaqhf
2662 a0e3dca4 gaqhf
            return _LMSymbol;
2663
        }
2664
2665
        /// <summary>
2666
        /// Connector를 가지고 있는 ChildSymbol Object 반환
2667
        /// </summary>
2668
        /// <param name="item"></param>
2669
        /// <param name="connector"></param>
2670
        /// <returns></returns>
2671
        private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector)
2672
        {
2673
            foreach (var childSymbol in item.ChildSymbols)
2674
            {
2675
                if (childSymbol.Connectors.Contains(connector))
2676
                    return childSymbol;
2677
                else
2678
                    return GetChildSymbolByConnector(childSymbol, connector);
2679 335b7a24 gaqhf
            }
2680
2681 a0e3dca4 gaqhf
            return null;
2682 335b7a24 gaqhf
        }
2683
2684 74752074 gaqhf
        /// <summary>
2685
        /// EndBreak 모델링 메서드
2686
        /// </summary>
2687
        /// <param name="endBreak"></param>
2688 3165c259 gaqhf
        private void EndBreakModeling(EndBreak endBreak)
2689 335b7a24 gaqhf
        {
2690 10c7195c gaqhf
            object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER);
2691 1ab9a205 gaqhf
            object connectedItem = SPPIDUtil.FindObjectByUID(document, endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE);
2692 fae4f386 gaqhf
2693 1ab9a205 gaqhf
            LMConnector targetLMConnector = FindBreakLineTarget(ownerObj, connectedItem);
2694 fae4f386 gaqhf
            if (ownerObj.GetType() == typeof(Symbol) && connectedItem.GetType() == typeof(Symbol) && targetLMConnector != null)
2695
                targetLMConnector = ReModelingZeroLengthLMConnectorForSegment(targetLMConnector);
2696 3165c259 gaqhf
2697 1ab9a205 gaqhf
            if (targetLMConnector != null)
2698 10c7195c gaqhf
            {
2699 02a45794 gaqhf
                double[] point = GetSegmentPoint(ownerObj, connectedItem, targetLMConnector);
2700
                Array array = null;
2701
                if (point != null)
2702
                    array = new double[] { 0, point[0], point[1] };
2703
                else
2704
                    array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
2705
                LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
2706 5173ba5d gaqhf
                if (_LmLabelPersist != null)
2707
                {
2708 04fcadf1 gaqhf
                    _LmLabelPersist.Commit();
2709 5173ba5d gaqhf
                    endBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id;
2710 d23fe61b gaqhf
                    if (_LmLabelPersist.ModelItemObject != null)
2711
                        endBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID;
2712 32205389 gaqhf
                    endBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID().ToString();
2713 5173ba5d gaqhf
                    ReleaseCOMObjects(_LmLabelPersist);
2714
                }
2715
                ReleaseCOMObjects(targetLMConnector);
2716 2a4872ec gaqhf
            }
2717 f9eba687 gaqhf
            else
2718
            {
2719
                Log.Write("End Break UID : " + endBreak.UID);
2720
                Log.Write("Can't find targetLMConnector");
2721
            }
2722 2a4872ec gaqhf
        }
2723 b9e9f4c8 gaqhf
2724 fae4f386 gaqhf
        private LMConnector ReModelingZeroLengthLMConnectorForSegment(LMConnector connector, string changeSymbolPath = null)
2725 02480ac1 gaqhf
        {
2726 de97eaaa gaqhf
            string symbolPath = string.Empty;
2727
            #region get symbol path
2728 d77973b3 gaqhf
            if (string.IsNullOrEmpty(changeSymbolPath))
2729
            {
2730
                LMModelItem modelItem = dataSource.GetModelItem(connector.ModelItemID);
2731
                symbolPath = GetSPPIDFileName(modelItem);
2732
                ReleaseCOMObjects(modelItem);
2733
            }
2734
            else
2735
                symbolPath = changeSymbolPath;
2736
            
2737 de97eaaa gaqhf
            #endregion
2738
2739 02480ac1 gaqhf
            LMConnector newConnector = null;
2740 32205389 gaqhf
            dynamic OID = connector.get_GraphicOID().ToString();
2741 02480ac1 gaqhf
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2742
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2743
            int verticesCount = lineStringGeometry.VertexCount;
2744
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
2745 de97eaaa gaqhf
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
2746 02480ac1 gaqhf
2747
            if (Convert.ToBoolean(connector.get_IsZeroLength()))
2748
            {
2749
                double[] vertices = null;
2750
                lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
2751
                double x = 0;
2752
                double y = 0;
2753
                lineStringGeometry.GetVertex(1, ref x, ref y);
2754
2755 32205389 gaqhf
                string flowDirection = string.Empty;
2756
                LMAAttribute flowAttribute = connector.ModelItemObject.Attributes["FlowDirection"];
2757
                if (flowAttribute != null && !DBNull.Value.Equals(flowAttribute.get_Value()))
2758
                    flowDirection = flowAttribute.get_Value().ToString();
2759
2760 3fdf052a gaqhf
                if (flowDirection == "End 1 is downstream (Outlet)")
2761
                {
2762
                    placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y);
2763
                    placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y);
2764
                    flowDirection = "End 1 is upstream (Inlet)";
2765
                }
2766
                else
2767
                {
2768
                    placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y);
2769
                    placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y);
2770
                }
2771 fae4f386 gaqhf
                string oldModelItemId = connector.ModelItemID;
2772 02480ac1 gaqhf
                _placement.PIDRemovePlacement(connector.AsLMRepresentation());
2773
                newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2774 04fcadf1 gaqhf
                newConnector.Commit();
2775 644f40b3 gaqhf
                ZeroLengthSymbolToSymbolModelItemID.Add(newConnector.ModelItemID);
2776 32205389 gaqhf
                if (!string.IsNullOrEmpty(flowDirection))
2777
                    newConnector.ModelItemObject.Attributes["FlowDirection"].set_Value(flowDirection);
2778 fae4f386 gaqhf
                ReleaseCOMObjects(connector);
2779 02480ac1 gaqhf
2780 fae4f386 gaqhf
                foreach (var line in document.LINES.FindAll(z => z.SPPID.ModelItemId == oldModelItemId))
2781 02480ac1 gaqhf
                {
2782 fae4f386 gaqhf
                    foreach (var repId in line.SPPID.Representations)
2783 02480ac1 gaqhf
                    {
2784 fae4f386 gaqhf
                        LMConnector _connector = dataSource.GetConnector(repId);
2785
                        if (_connector != null && _connector.get_ItemStatus() == "Active")
2786
                        {
2787
                            if (line.SPPID.ModelItemId != _connector.ModelItemID)
2788
                            {
2789
                                line.SPPID.ModelItemId = _connector.ModelItemID;
2790
                                line.SPPID.Representations = GetRepresentations(line.SPPID.ModelItemId);
2791
                            }
2792
                        }
2793
                        ReleaseCOMObjects(_connector);
2794
                        _connector = null;
2795 02480ac1 gaqhf
                    }
2796
                }
2797
            }
2798
2799
            return newConnector;
2800
        }
2801
2802 74752074 gaqhf
        /// <summary>
2803 53c81765 gaqhf
        /// SpecBreak Modeling 메서드
2804
        /// </summary>
2805
        /// <param name="specBreak"></param>
2806
        private void SpecBreakModeling(SpecBreak specBreak)
2807
        {
2808
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
2809
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
2810
2811
            if (upStreamObj != null &&
2812
                downStreamObj != null)
2813
            {
2814 1ab9a205 gaqhf
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
2815 fae4f386 gaqhf
                if (upStreamObj.GetType() == typeof(Symbol) && downStreamObj.GetType() == typeof(Symbol) && targetLMConnector != null)
2816
                    targetLMConnector = ReModelingZeroLengthLMConnectorForSegment(targetLMConnector);
2817
2818 1ab9a205 gaqhf
                if (targetLMConnector != null)
2819 53c81765 gaqhf
                {
2820 16584d30 gaqhf
                    foreach (var attribute in specBreak.ATTRIBUTES)
2821 53c81765 gaqhf
                    {
2822 16584d30 gaqhf
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID);
2823
                        if (mapping != null && !string.IsNullOrEmpty(mapping.SPPIDSYMBOLNAME) && mapping.SPPIDSYMBOLNAME != "None")
2824
                        {
2825
                            string MappingPath = mapping.SPPIDSYMBOLNAME;
2826 02a45794 gaqhf
                            double[] point = GetSegmentPoint(upStreamObj, downStreamObj, targetLMConnector);
2827
                            Array array = null;
2828
                            if (point != null)
2829
                                array = new double[] { 0, point[0], point[1] };
2830
                            else
2831
                                array = new double[] { 0, specBreak.SPPID.ORIGINAL_X, specBreak.SPPID.ORIGINAL_Y };
2832
                            LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(MappingPath, ref array, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
2833 53c81765 gaqhf
2834 16584d30 gaqhf
                            if (_LmLabelPersist != null)
2835
                            {
2836 04fcadf1 gaqhf
                                _LmLabelPersist.Commit();
2837 5173ba5d gaqhf
                                specBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id;
2838 d23fe61b gaqhf
                                if (_LmLabelPersist.ModelItemObject != null)
2839
                                    specBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID;
2840 32205389 gaqhf
                                specBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID().ToString();
2841 16584d30 gaqhf
                                ReleaseCOMObjects(_LmLabelPersist);
2842
                            }
2843
                        }
2844
                    }
2845 1ab9a205 gaqhf
                    ReleaseCOMObjects(targetLMConnector);
2846
                }
2847 f9eba687 gaqhf
                else
2848
                {
2849
                    Log.Write("Spec Break UID : " + specBreak.UID);
2850
                    Log.Write("Can't find targetLMConnector");
2851
                }
2852 1ab9a205 gaqhf
            }
2853
        }
2854 53c81765 gaqhf
2855 1ab9a205 gaqhf
        private LMConnector FindBreakLineTarget(object targetObj, object connectedObj)
2856
        {
2857
            LMConnector targetConnector = null;
2858
            Symbol targetSymbol = targetObj as Symbol;
2859
            Symbol connectedSymbol = connectedObj as Symbol;
2860
            Line targetLine = targetObj as Line;
2861
            Line connectedLine = connectedObj as Line;
2862
            if (targetSymbol != null && connectedSymbol != null)
2863
            {
2864
                LMSymbol targetLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
2865
                LMSymbol connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId);
2866
2867
                foreach (LMConnector connector in targetLMSymbol.Avoid1Connectors)
2868
                {
2869
                    if (connector.get_ItemStatus() != "Active")
2870
                        continue;
2871
2872
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
2873
                    {
2874
                        targetConnector = connector;
2875
                        break;
2876
                    }
2877
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
2878
                    {
2879
                        targetConnector = connector;
2880
                        break;
2881 53c81765 gaqhf
                    }
2882
                }
2883 1ab9a205 gaqhf
2884
                foreach (LMConnector connector in targetLMSymbol.Avoid2Connectors)
2885 53c81765 gaqhf
                {
2886 1ab9a205 gaqhf
                    if (connector.get_ItemStatus() != "Active")
2887
                        continue;
2888 53c81765 gaqhf
2889 1ab9a205 gaqhf
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
2890
                    {
2891
                        targetConnector = connector;
2892
                        break;
2893
                    }
2894
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
2895
                    {
2896
                        targetConnector = connector;
2897
                        break;
2898 53c81765 gaqhf
                    }
2899
                }
2900 1ab9a205 gaqhf
2901
                ReleaseCOMObjects(targetLMSymbol);
2902
                ReleaseCOMObjects(connectedLMSymbol);
2903
            }
2904
            else if (targetLine != null && connectedLine != null)
2905
            {
2906
                LMModelItem targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId);
2907
                LMModelItem connectedModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
2908
2909 d77973b3 gaqhf
                if (targetModelItem != null && targetModelItem.get_ItemStatus() == "Active" && connectedModelItem != null && connectedModelItem.get_ItemStatus() == "Active")
2910 53c81765 gaqhf
                {
2911 1ab9a205 gaqhf
                    foreach (LMRepresentation rep in targetModelItem.Representations)
2912 53c81765 gaqhf
                    {
2913 1ab9a205 gaqhf
                        if (targetConnector != null)
2914
                            break;
2915 53c81765 gaqhf
2916 1ab9a205 gaqhf
                        if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2917 53c81765 gaqhf
                        {
2918 1ab9a205 gaqhf
                            LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2919
2920
                            if (IsConnected(_LMConnector, connectedModelItem))
2921
                                targetConnector = _LMConnector;
2922
                            else
2923
                                ReleaseCOMObjects(_LMConnector);
2924 53c81765 gaqhf
                        }
2925
                    }
2926 1ab9a205 gaqhf
2927
                    ReleaseCOMObjects(targetModelItem);
2928 53c81765 gaqhf
                }
2929 1ab9a205 gaqhf
            }
2930
            else
2931
            {
2932 340515a2 gaqhf
                LMSymbol connectedLMSymbol = null;
2933
                if (connectedSymbol != null)
2934
                    connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId);
2935
                else if (targetSymbol != null)
2936
                    connectedLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
2937
                else
2938
                {
2939
2940
                }
2941
                LMModelItem targetModelItem = null;
2942
                if (targetLine != null)
2943
                    targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId);
2944
                else if (connectedLine != null)
2945
                    targetModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
2946
                else
2947
                {
2948
2949
                }
2950 1ab9a205 gaqhf
                if (connectedLMSymbol != null && targetModelItem != null)
2951 53c81765 gaqhf
                {
2952 1ab9a205 gaqhf
                    foreach (LMConnector connector in connectedLMSymbol.Avoid1Connectors)
2953
                    {
2954 ac82b020 gaqhf
                        if (connector.get_ItemStatus() != "Active")
2955
                            continue;
2956
2957 1ab9a205 gaqhf
                        if (IsConnected(connector, targetModelItem))
2958
                        {
2959
                            targetConnector = connector;
2960
                            break;
2961
                        }
2962
                    }
2963 53c81765 gaqhf
2964 1ab9a205 gaqhf
                    if (targetConnector == null)
2965 53c81765 gaqhf
                    {
2966 1ab9a205 gaqhf
                        foreach (LMConnector connector in connectedLMSymbol.Avoid2Connectors)
2967 53c81765 gaqhf
                        {
2968 ac82b020 gaqhf
                            if (connector.get_ItemStatus() != "Active")
2969
                                continue;
2970
2971 1ab9a205 gaqhf
                            if (IsConnected(connector, targetModelItem))
2972 53c81765 gaqhf
                            {
2973 1ab9a205 gaqhf
                                targetConnector = connector;
2974
                                break;
2975 53c81765 gaqhf
                            }
2976
                        }
2977
                    }
2978
                }
2979
2980 1ab9a205 gaqhf
            }
2981 02480ac1 gaqhf
2982 1ab9a205 gaqhf
            return targetConnector;
2983
        }
2984 53c81765 gaqhf
2985 02a45794 gaqhf
        private double[] GetSegmentPoint(object targetObj, object connObj, LMConnector targetConnector)
2986
        {
2987
            double[] result = null;
2988 28d05cc2 gaqhf
            Line targetLine = targetObj as Line;
2989
            Symbol targetSymbol = targetObj as Symbol;
2990
            Line connLine = connObj as Line;
2991
            Symbol connSymbol = connObj as Symbol;
2992
2993 f9eba687 gaqhf
            double zeroLengthMove = GridSetting.GetInstance().Length * 3;
2994
            double lineMove = GridSetting.GetInstance().Length * 3;
2995 02a45794 gaqhf
            if (Convert.ToBoolean(targetConnector.get_IsZeroLength()))
2996
            {
2997 28d05cc2 gaqhf
                result = GetConnectorVertices(targetConnector)[0];
2998
                if (targetSymbol != null && connSymbol != null)
2999
                {
3000
                    SlopeType slopeType = SPPIDUtil.CalcSlope(targetSymbol.SPPID.SPPID_X, targetSymbol.SPPID.SPPID_Y, connSymbol.SPPID.SPPID_X, connSymbol.SPPID.SPPID_Y);
3001
                    if (slopeType == SlopeType.HORIZONTAL)
3002 9157c1b8 gaqhf
                        result = new double[] { result[0], result[1] - zeroLengthMove };
3003 28d05cc2 gaqhf
                    else if (slopeType == SlopeType.VERTICAL)
3004 4e865771 gaqhf
                        result = new double[] { result[0] + zeroLengthMove, result[1] };
3005 28d05cc2 gaqhf
                }
3006
                else if (targetLine != null)
3007
                {
3008
                    if (targetLine.SlopeType == SlopeType.HORIZONTAL)
3009 9157c1b8 gaqhf
                        result = new double[] { result[0], result[1] - zeroLengthMove };
3010 28d05cc2 gaqhf
                    else if (targetLine.SlopeType == SlopeType.VERTICAL)
3011 4e865771 gaqhf
                        result = new double[] { result[0] + zeroLengthMove, result[1] };
3012 28d05cc2 gaqhf
                }
3013
                else if (connLine != null)
3014
                {
3015
                    if (connLine.SlopeType == SlopeType.HORIZONTAL)
3016 9157c1b8 gaqhf
                        result = new double[] { result[0], result[1] - zeroLengthMove };
3017 28d05cc2 gaqhf
                    else if (connLine.SlopeType == SlopeType.VERTICAL)
3018 4e865771 gaqhf
                        result = new double[] { result[0] + zeroLengthMove, result[1] };
3019 28d05cc2 gaqhf
                }
3020 02a45794 gaqhf
            }
3021
            else
3022
            {
3023
                if (targetObj.GetType() == typeof(Line) && connObj.GetType() == typeof(Line))
3024
                {
3025
                    Line line = connObj as Line;
3026
                    LMConnector connectedConnector = null;
3027
                    int connIndex = 0;
3028
                    LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
3029
                    FindConnectedConnector(targetConnector, modelItem, ref connectedConnector, ref connIndex);
3030
3031
                    List<double[]> vertices = GetConnectorVertices(targetConnector);
3032
3033
                    ReleaseCOMObjects(modelItem);
3034
                    ReleaseCOMObjects(connectedConnector);
3035
3036
                    if (vertices.Count > 0)
3037
                    {
3038
                        if (connIndex == 1)
3039 28d05cc2 gaqhf
                            result = vertices[0];
3040 02a45794 gaqhf
                        else if (connIndex == 2)
3041 28d05cc2 gaqhf
                            result = vertices[vertices.Count - 1];
3042
3043
                        if (targetLine.SlopeType == SlopeType.HORIZONTAL)
3044
                        {
3045 9157c1b8 gaqhf
                            result = new double[] { result[0], result[1] - lineMove };
3046 28d05cc2 gaqhf
                            if (targetLine.CONNECTORS[0].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_X < targetLine.SPPID.END_X)
3047
                            {
3048 783f8357 gaqhf
                                result = new double[] { result[0] - lineMove, result[1] };
3049 28d05cc2 gaqhf
                            }
3050
                            else if (targetLine.CONNECTORS[0].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_X > targetLine.SPPID.END_X)
3051
                            {
3052 783f8357 gaqhf
                                result = new double[] { result[0] + lineMove, result[1] };
3053 28d05cc2 gaqhf
                            }
3054
                            else if (targetLine.CONNECTORS[1].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_X < targetLine.SPPID.END_X)
3055
                            {
3056 783f8357 gaqhf
                                result = new double[] { result[0] + lineMove, result[1] };
3057 28d05cc2 gaqhf
                            }
3058
                            else if (targetLine.CONNECTORS[1].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_X > targetLine.SPPID.END_X)
3059
                            {
3060 783f8357 gaqhf
                                result = new double[] { result[0] - lineMove, result[1] };
3061 28d05cc2 gaqhf
                            }
3062
                        }
3063
                        else if (targetLine.SlopeType == SlopeType.VERTICAL)
3064
                        {
3065 9157c1b8 gaqhf
                            result = new double[] { result[0] - lineMove, result[1] };
3066 28d05cc2 gaqhf
                            if (targetLine.CONNECTORS[0].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_Y < targetLine.SPPID.END_Y)
3067
                            {
3068 783f8357 gaqhf
                                result = new double[] { result[0], result[1] - lineMove };
3069 28d05cc2 gaqhf
                            }
3070
                            else if (targetLine.CONNECTORS[0].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_Y > targetLine.SPPID.END_Y)
3071
                            {
3072 783f8357 gaqhf
                                result = new double[] { result[0], result[1] + lineMove };
3073 28d05cc2 gaqhf
                            }
3074
                            else if (targetLine.CONNECTORS[1].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_Y < targetLine.SPPID.END_Y)
3075
                            {
3076 783f8357 gaqhf
                                result = new double[] { result[0], result[1] + lineMove };
3077 28d05cc2 gaqhf
                            }
3078
                            else if (targetLine.CONNECTORS[1].CONNECTEDITEM == connLine.UID && targetLine.SPPID.START_Y > targetLine.SPPID.END_Y)
3079
                            {
3080 783f8357 gaqhf
                                result = new double[] { result[0], result[1] - lineMove };
3081 28d05cc2 gaqhf
                            }
3082
                        }
3083
                            
3084 02a45794 gaqhf
                    }
3085
                }
3086
                else
3087
                {
3088
                    Log.Write("error in GetSegemtPoint");
3089
                }
3090
            }
3091
3092
            return result;
3093
        }
3094
3095 1ab9a205 gaqhf
        private bool IsConnected(LMConnector connector, LMModelItem modelItem)
3096
        {
3097
            bool result = false;
3098
3099
            foreach (LMRepresentation rep in modelItem.Representations)
3100
            {
3101
                if (result)
3102
                    break;
3103
3104
                if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
3105
                {
3106
                    LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
3107
3108
                    if (_LMConnector.ConnectItem1SymbolObject != null &&
3109
                        connector.ConnectItem1SymbolObject != null &&
3110
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
3111 53c81765 gaqhf
                    {
3112 1ab9a205 gaqhf
                        result = true;
3113
                        ReleaseCOMObjects(_LMConnector);
3114
                        break;
3115
                    }
3116
                    else if (_LMConnector.ConnectItem1SymbolObject != null &&
3117
                        connector.ConnectItem2SymbolObject != null &&
3118
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
3119
                    {
3120
                        result = true;
3121
                        ReleaseCOMObjects(_LMConnector);
3122
                        break;
3123
                    }
3124
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
3125
                        connector.ConnectItem1SymbolObject != null &&
3126
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
3127
                    {
3128
                        result = true;
3129
                        ReleaseCOMObjects(_LMConnector);
3130
                        break;
3131
                    }
3132
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
3133
                        connector.ConnectItem2SymbolObject != null &&
3134
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
3135
                    {
3136
                        result = true;
3137
                        ReleaseCOMObjects(_LMConnector);
3138
                        break;
3139 53c81765 gaqhf
                    }
3140
3141 1ab9a205 gaqhf
                    ReleaseCOMObjects(_LMConnector);
3142
                }
3143 53c81765 gaqhf
            }
3144 1ab9a205 gaqhf
3145
3146
            return result;
3147 53c81765 gaqhf
        }
3148
3149 02a45794 gaqhf
        private void FindConnectedConnector(LMConnector connector, LMModelItem modelItem, ref LMConnector connectedConnector, ref int connectorIndex)
3150
        {
3151
            foreach (LMRepresentation rep in modelItem.Representations)
3152
            {
3153
                if (connectedConnector != null)
3154
                    break;
3155
3156
                if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
3157
                {
3158
                    LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
3159
3160
                    if (_LMConnector.ConnectItem1SymbolObject != null &&
3161
                        connector.ConnectItem1SymbolObject != null &&
3162
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
3163
                    {
3164
                        connectedConnector = _LMConnector;
3165
                        connectorIndex = 1;
3166
                        break;
3167
                    }
3168
                    else if (_LMConnector.ConnectItem1SymbolObject != null &&
3169
                        connector.ConnectItem2SymbolObject != null &&
3170
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
3171
                    {
3172
                        connectedConnector = _LMConnector;
3173
                        connectorIndex = 2;
3174
                        break;
3175
                    }
3176
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
3177
                        connector.ConnectItem1SymbolObject != null &&
3178
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
3179
                    {
3180
                        connectedConnector = _LMConnector;
3181
                        connectorIndex = 1;
3182
                        break;
3183
                    }
3184
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
3185
                        connector.ConnectItem2SymbolObject != null &&
3186
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
3187
                    {
3188
                        connectedConnector = _LMConnector;
3189
                        connectorIndex = 2;
3190
                        break;
3191
                    }
3192
3193
                    if (connectedConnector == null)
3194
                        ReleaseCOMObjects(_LMConnector);
3195
                }
3196
            }
3197
        }
3198
3199 53c81765 gaqhf
        /// <summary>
3200 74752074 gaqhf
        /// FromModelItem을 ToModelItem으로 PipeRunJoin하는 메서드
3201
        /// </summary>
3202 644f40b3 gaqhf
        /// <param name="modelItemID1"></param>
3203
        /// <param name="modelItemID2"></param>
3204 90662b0b gaqhf
        private void JoinRun(string modelId1, string modelId2, ref string survivorId, bool IsSameConnector = true)
3205 335b7a24 gaqhf
        {
3206 ca6e0f51 gaqhf
            try
3207 644f40b3 gaqhf
            {
3208 a31a512e gaqhf
                LMModelItem modelItem1 = dataSource.GetModelItem(modelId1);
3209 63a112d9 gaqhf
                LMConnector connector1 = GetLMConnectorFirst(modelId1);
3210
                List<double[]> vertices1 = null;
3211
                string graphicOID1 = string.Empty;
3212
                if (connector1 != null)
3213
                {
3214
                    vertices1 = GetConnectorVertices(connector1);
3215
                    graphicOID1 = connector1.get_GraphicOID();
3216
                }
3217 ca6e0f51 gaqhf
                _LMAItem item1 = modelItem1.AsLMAItem();
3218 63a112d9 gaqhf
                ReleaseCOMObjects(connector1);
3219
                connector1 = null;
3220
3221 a31a512e gaqhf
                LMModelItem modelItem2 = dataSource.GetModelItem(modelId2);
3222 63a112d9 gaqhf
                LMConnector connector2 = GetLMConnectorFirst(modelId2);
3223
                List<double[]> vertices2 = null;
3224
                string graphicOID2 = string.Empty;
3225
                if (connector2 != null)
3226
                {
3227
                    vertices2 = GetConnectorVertices(connector2);
3228
                    graphicOID2 = connector2.get_GraphicOID();
3229
                }
3230 ca6e0f51 gaqhf
                _LMAItem item2 = modelItem2.AsLMAItem();
3231 63a112d9 gaqhf
                ReleaseCOMObjects(connector2);
3232
                connector2 = null;
3233 644f40b3 gaqhf
3234 ca6e0f51 gaqhf
                // item2가 item1으로 조인
3235
                _placement.PIDJoinRuns(ref item1, ref item2);
3236
                item1.Commit();
3237
                item2.Commit();
3238 7f00b26c gaqhf
3239 ca6e0f51 gaqhf
                string beforeID = string.Empty;
3240
                string afterID = string.Empty;
3241 335b7a24 gaqhf
3242 ca6e0f51 gaqhf
                if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() != "Active")
3243
                {
3244
                    beforeID = modelItem2.Id;
3245
                    afterID = modelItem1.Id;
3246 a31a512e gaqhf
                    survivorId = afterID;
3247 ca6e0f51 gaqhf
                }
3248
                else if (modelItem1.get_ItemStatus() != "Active" && modelItem2.get_ItemStatus() == "Active")
3249
                {
3250
                    beforeID = modelItem1.Id;
3251
                    afterID = modelItem2.Id;
3252 a31a512e gaqhf
                    survivorId = afterID;
3253 ca6e0f51 gaqhf
                }
3254 a31a512e gaqhf
                else if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() == "Active")
3255 7e680366 gaqhf
                {
3256
                    int model1Cnt = GetConnectorCount(modelId1);
3257
                    int model2Cnt = GetConnectorCount(modelId2);
3258
                    if (model1Cnt == 0)
3259
                    {
3260
                        beforeID = modelItem1.Id;
3261
                        afterID = modelItem2.Id;
3262
                        survivorId = afterID;
3263
                    }
3264
                    else if (model2Cnt == 0)
3265
                    {
3266
                        beforeID = modelItem2.Id;
3267
                        afterID = modelItem1.Id;
3268
                        survivorId = afterID;
3269
                    }
3270
                    else
3271
                        survivorId = null;
3272
                }
3273 ca6e0f51 gaqhf
                else
3274
                {
3275 a31a512e gaqhf
                    Log.Write("잘못된 경우");
3276
                    survivorId = null;
3277 ca6e0f51 gaqhf
                }
3278 87f02fc0 gaqhf
3279 ca6e0f51 gaqhf
                if (!string.IsNullOrEmpty(beforeID) && !string.IsNullOrEmpty(afterID))
3280 7f00b26c gaqhf
                {
3281 ca6e0f51 gaqhf
                    List<Line> lines = SPPIDUtil.FindLinesByModelId(document, beforeID);
3282 7f00b26c gaqhf
                    foreach (var line in lines)
3283 ca6e0f51 gaqhf
                        line.SPPID.ModelItemId = afterID;
3284 65a1ed4b gaqhf
                }
3285 7f00b26c gaqhf
3286 ca6e0f51 gaqhf
                ReleaseCOMObjects(modelItem1);
3287
                ReleaseCOMObjects(item1);
3288
                ReleaseCOMObjects(modelItem2);
3289
                ReleaseCOMObjects(item2);
3290
            }
3291
            catch (Exception ex)
3292 335b7a24 gaqhf
            {
3293 ca6e0f51 gaqhf
                Log.Write("Join Error");
3294 63a112d9 gaqhf
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
3295 335b7a24 gaqhf
            }
3296
        }
3297
3298 a31a512e gaqhf
        private List<string> FindOtherModelItemBySymbolWhereTypePipeRun(LMSymbol symbol, string modelId)
3299
        {
3300 fae4f386 gaqhf
            List<string> temp = new List<string>();
3301
            List<LMConnector> connectors = new List<LMConnector>();
3302 48fd75e2 gaqhf
            foreach (LMConnector connector in symbol.Avoid1Connectors)
3303 a31a512e gaqhf
            {
3304 fae4f386 gaqhf
                if (connector.get_ItemStatus() != "Active")
3305
                    continue;
3306
3307 a31a512e gaqhf
                LMModelItem modelItem = connector.ModelItemObject;
3308 fae4f386 gaqhf
                LMSymbol connOtherSymbol = FindOtherConnectedSymbol(connector);
3309
                if (modelItem.get_ItemStatus() == "Active" && modelItem.get_ItemTypeName().ToString() == "PipeRun" && modelItem.Id != modelId && !temp.Contains(modelItem.Id))
3310
                    temp.Add(modelItem.Id);
3311
3312
                if (temp.Contains(modelItem.Id) &&
3313
                    connOtherSymbol != null &&
3314
                    connOtherSymbol.get_RepresentationType() == "Branch" &&
3315
                    Convert.ToBoolean(connector.get_IsZeroLength()))
3316
                    temp.Remove(modelItem.Id);
3317
3318
3319
                if (temp.Contains(modelItem.Id))
3320
                    connectors.Add(connector);
3321
                ReleaseCOMObjects(connOtherSymbol);
3322
                connOtherSymbol = null;
3323 a31a512e gaqhf
                ReleaseCOMObjects(modelItem);
3324 fae4f386 gaqhf
                modelItem = null;
3325 a31a512e gaqhf
            }
3326
3327 48fd75e2 gaqhf
            foreach (LMConnector connector in symbol.Avoid2Connectors)
3328 a31a512e gaqhf
            {
3329 fae4f386 gaqhf
                if (connector.get_ItemStatus() != "Active")
3330
                    continue;
3331
3332 a31a512e gaqhf
                LMModelItem modelItem = connector.ModelItemObject;
3333 fae4f386 gaqhf
                LMSymbol connOtherSymbol = FindOtherConnectedSymbol(connector);
3334
                if (modelItem.get_ItemStatus() == "Active" && modelItem.get_ItemTypeName().ToString() == "PipeRun" && modelItem.Id != modelId && !temp.Contains(modelItem.Id))
3335
                    temp.Add(modelItem.Id);
3336
3337
                if (temp.Contains(modelItem.Id) &&
3338
                    connOtherSymbol != null &&
3339
                    connOtherSymbol.get_RepresentationType() == "Branch" &&
3340
                    Convert.ToBoolean(connector.get_IsZeroLength()))
3341
                    temp.Remove(modelItem.Id);
3342
3343
                if (temp.Contains(modelItem.Id))
3344
                    connectors.Add(connector);
3345
                ReleaseCOMObjects(connOtherSymbol);
3346
                connOtherSymbol = null;
3347 a31a512e gaqhf
                ReleaseCOMObjects(modelItem);
3348 fae4f386 gaqhf
                modelItem = null;
3349 a31a512e gaqhf
            }
3350
3351 48fd75e2 gaqhf
3352 82d6e5ea gaqhf
            List<string> result = new List<string>();
3353
            string originalName = GetSPPIDFileName(modelId);
3354 fae4f386 gaqhf
            foreach (var connector in connectors)
3355 82d6e5ea gaqhf
            {
3356 fae4f386 gaqhf
                string fileName = GetSPPIDFileName(connector.ModelItemID);
3357 82d6e5ea gaqhf
                if (originalName == fileName)
3358 fae4f386 gaqhf
                    result.Add(connector.ModelItemID);
3359 82d6e5ea gaqhf
                else
3360
                {
3361 fae4f386 gaqhf
                    if (document.LINES.Find(x => x.SPPID.ModelItemId == connector.ModelItemID) == null && Convert.ToBoolean(connector.get_IsZeroLength()))
3362
                        result.Add(connector.ModelItemID);
3363
                    else
3364 82d6e5ea gaqhf
                    {
3365 fae4f386 gaqhf
                        Line line1 = document.LINES.Find(x => x.SPPID.ModelItemId == modelId);
3366
                        Line line2 = document.LINES.Find(x => x.SPPID.ModelItemId == connector.ModelItemID.ToString());
3367
                        if (line1 != null && line2 != null && line1.TYPE == line2.TYPE)
3368
                            result.Add(connector.ModelItemID);
3369 82d6e5ea gaqhf
                    }
3370
                }
3371
            }
3372 154d8f43 gaqhf
3373 fae4f386 gaqhf
            foreach (var connector in connectors)
3374 154d8f43 gaqhf
                ReleaseCOMObjects(connector);
3375 82d6e5ea gaqhf
            
3376
            return result;
3377 fae4f386 gaqhf
3378
3379
            LMSymbol FindOtherConnectedSymbol(LMConnector connector)
3380
            {
3381
                LMSymbol findResult = null;
3382
                if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.Id != symbol.Id && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active")
3383
                    findResult = connector.ConnectItem1SymbolObject;
3384
                else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.Id != symbol.Id && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active")
3385
                    findResult = connector.ConnectItem2SymbolObject;
3386
3387
                return findResult;
3388
            }
3389 a31a512e gaqhf
        }
3390
3391 74752074 gaqhf
        /// <summary>
3392
        /// PipeRun의 좌표를 가져오는 메서드
3393
        /// </summary>
3394
        /// <param name="modelId"></param>
3395
        /// <returns></returns>
3396 44087b23 gaqhf
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId, bool ContainZeroLength = true)
3397 5e6ecf05 gaqhf
        {
3398
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
3399 310aeb31 gaqhf
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
3400
3401
            if (modelItem != null)
3402 5e6ecf05 gaqhf
            {
3403 310aeb31 gaqhf
                foreach (LMRepresentation rep in modelItem.Representations)
3404 5e6ecf05 gaqhf
                {
3405
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
3406
                    {
3407
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
3408 44087b23 gaqhf
                        if (!ContainZeroLength && Convert.ToBoolean(_LMConnector.get_IsZeroLength()))
3409
                        {
3410
                            ReleaseCOMObjects(_LMConnector);
3411
                            _LMConnector = null;
3412
                            continue;
3413
                        }
3414 5e6ecf05 gaqhf
                        connectorVertices.Add(_LMConnector, new List<double[]>());
3415 32205389 gaqhf
                        dynamic OID = rep.get_GraphicOID().ToString();
3416 335b7a24 gaqhf
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
3417 5e6ecf05 gaqhf
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
3418
                        int verticesCount = lineStringGeometry.VertexCount;
3419
                        double[] vertices = null;
3420
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
3421
                        for (int i = 0; i < verticesCount; i++)
3422
                        {
3423
                            double x = 0;
3424
                            double y = 0;
3425
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
3426 32205389 gaqhf
                            connectorVertices[_LMConnector].Add(new double[] { x, y });
3427 5e6ecf05 gaqhf
                        }
3428
                    }
3429
                }
3430
3431 310aeb31 gaqhf
                ReleaseCOMObjects(modelItem);
3432 5e6ecf05 gaqhf
            }
3433
3434
            return connectorVertices;
3435
        }
3436
3437 32205389 gaqhf
        private List<double[]> GetConnectorVertices(LMConnector connector)
3438
        {
3439
            List<double[]> vertices = new List<double[]>();
3440 02a45794 gaqhf
            if (connector != null)
3441 32205389 gaqhf
            {
3442 02a45794 gaqhf
                dynamic OID = connector.get_GraphicOID().ToString();
3443
                DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
3444
                Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
3445
                int verticesCount = lineStringGeometry.VertexCount;
3446
                double[] value = null;
3447
                lineStringGeometry.GetVertices(ref verticesCount, ref value);
3448
                for (int i = 0; i < verticesCount; i++)
3449
                {
3450
                    double x = 0;
3451
                    double y = 0;
3452
                    lineStringGeometry.GetVertex(i + 1, ref x, ref y);
3453
                    vertices.Add(new double[] { x, y });
3454
                }
3455 32205389 gaqhf
            }
3456
            return vertices;
3457
        }
3458
3459 63a112d9 gaqhf
        private List<double[]> GetConnectorVertices(dynamic graphicOID)
3460
        {
3461
            List<double[]> vertices = null;
3462
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID];
3463
            if (drawingObject != null)
3464
            {
3465
                vertices = new List<double[]>();
3466
                Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
3467
                int verticesCount = lineStringGeometry.VertexCount;
3468
                double[] value = null;
3469
                lineStringGeometry.GetVertices(ref verticesCount, ref value);
3470
                for (int i = 0; i < verticesCount; i++)
3471
                {
3472
                    double x = 0;
3473
                    double y = 0;
3474
                    lineStringGeometry.GetVertex(i + 1, ref x, ref y);
3475
                    vertices.Add(new double[] { x, y });
3476
                }
3477
            }
3478
            return vertices;
3479
        }
3480 7c7bcd10 gaqhf
        /// <summary>
3481 a0e3dca4 gaqhf
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식
3482 74752074 gaqhf
        /// </summary>
3483
        /// <param name="connectorVertices"></param>
3484
        /// <param name="connX"></param>
3485
        /// <param name="connY"></param>
3486
        /// <returns></returns>
3487 a0e3dca4 gaqhf
        private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
3488 5e6ecf05 gaqhf
        {
3489
            double length = double.MaxValue;
3490
            LMConnector targetConnector = null;
3491
            foreach (var item in connectorVertices)
3492
            {
3493
                List<double[]> points = item.Value;
3494
                for (int i = 0; i < points.Count - 1; i++)
3495
                {
3496
                    double[] point1 = points[i];
3497
                    double[] point2 = points[i + 1];
3498 a0e3dca4 gaqhf
                    double x1 = Math.Min(point1[0], point2[0]);
3499
                    double y1 = Math.Min(point1[1], point2[1]);
3500
                    double x2 = Math.Max(point1[0], point2[0]);
3501
                    double y2 = Math.Max(point1[1], point2[1]);
3502 5e6ecf05 gaqhf
3503 a0e3dca4 gaqhf
                    if ((x1 <= connX && x2 >= connX) ||
3504
                        (y1 <= connY && y2 >= connY))
3505 5e6ecf05 gaqhf
                    {
3506 a0e3dca4 gaqhf
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY);
3507 335b7a24 gaqhf
                        if (length >= distance)
3508 30a9ffce gaqhf
                        {
3509 a0e3dca4 gaqhf
                            targetConnector = item.Key;
3510
                            length = distance;
3511
                        }
3512
3513
                        distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY);
3514
                        if (length >= distance)
3515
                        {
3516
                            targetConnector = item.Key;
3517
                            length = distance;
3518 30a9ffce gaqhf
                        }
3519 5e6ecf05 gaqhf
                    }
3520
                }
3521 c3d2e266 gaqhf
            }
3522
3523 a0e3dca4 gaqhf
            // 못찾았을때.
3524
            length = double.MaxValue;
3525 c3d2e266 gaqhf
            if (targetConnector == null)
3526
            {
3527
                foreach (var item in connectorVertices)
3528
                {
3529
                    List<double[]> points = item.Value;
3530 a0e3dca4 gaqhf
3531
                    foreach (double[] point in points)
3532 c3d2e266 gaqhf
                    {
3533 a0e3dca4 gaqhf
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
3534 c3d2e266 gaqhf
                        if (length >= distance)
3535
                        {
3536
                            targetConnector = item.Key;
3537
                            length = distance;
3538
                        }
3539
                    }
3540
                }
3541 5e6ecf05 gaqhf
            }
3542
3543
            return targetConnector;
3544
        }
3545
3546 a0e3dca4 gaqhf
        private LMConnector FindTargetLMConnectorForBranch(Line line, Line targetLine, ref double x, ref double y)
3547 ac78b508 gaqhf
        {
3548 a0e3dca4 gaqhf
            Dictionary<LMConnector, List<double[]>> vertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId);
3549 0ff6e67f gaqhf
            if (vertices.Count == 0)
3550
                return null;
3551 a0e3dca4 gaqhf
3552 ac78b508 gaqhf
            double length = double.MaxValue;
3553
            LMConnector targetConnector = null;
3554 a0e3dca4 gaqhf
            double[] resultPoint = null;
3555
            List<double[]> targetVertices = null;
3556
3557
            // Vertices 포인트에 제일 가까운곳
3558
            foreach (var item in vertices)
3559 ac78b508 gaqhf
            {
3560
                List<double[]> points = item.Value;
3561 a0e3dca4 gaqhf
                for (int i = 0; i < points.Count; i++)
3562 ac78b508 gaqhf
                {
3563 a0e3dca4 gaqhf
                    double[] point = points[i];
3564
                    double tempX = point[0];
3565
                    double tempY = point[1];
3566
3567
                    double distance = SPPIDUtil.CalcPointToPointdDistance(tempX, tempY, x, y);
3568 ac78b508 gaqhf
                    if (length >= distance)
3569
                    {
3570
                        targetConnector = item.Key;
3571
                        length = distance;
3572 a0e3dca4 gaqhf
                        resultPoint = point;
3573
                        targetVertices = item.Value;
3574 ac78b508 gaqhf
                    }
3575
                }
3576
            }
3577
3578 a0e3dca4 gaqhf
            // Vertices Cross에 제일 가까운곳
3579
            foreach (var item in vertices)
3580 68464385 gaqhf
            {
3581
                List<double[]> points = item.Value;
3582
                for (int i = 0; i < points.Count - 1; i++)
3583
                {
3584
                    double[] point1 = points[i];
3585
                    double[] point2 = points[i + 1];
3586
3587 a0e3dca4 gaqhf
                    double maxLineX = Math.Max(point1[0], point2[0]);
3588
                    double minLineX = Math.Min(point1[0], point2[0]);
3589
                    double maxLineY = Math.Max(point1[1], point2[1]);
3590
                    double minLineY = Math.Min(point1[1], point2[1]);
3591 68464385 gaqhf
3592 a0e3dca4 gaqhf
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
3593
3594
                    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]);
3595
                    if (crossingPoint != null)
3596
                    {
3597
                        double distance = SPPIDUtil.CalcPointToPointdDistance(crossingPoint[0], crossingPoint[1], x, y);
3598 68464385 gaqhf
                        if (length >= distance)
3599
                        {
3600 a0e3dca4 gaqhf
                            if (slope == SlopeType.Slope &&
3601
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
3602
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
3603
                            {
3604
                                targetConnector = item.Key;
3605
                                length = distance;
3606
                                resultPoint = crossingPoint;
3607
                                targetVertices = item.Value;
3608
                            }
3609
                            else if (slope == SlopeType.HORIZONTAL &&
3610
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
3611
                            {
3612
                                targetConnector = item.Key;
3613
                                length = distance;
3614
                                resultPoint = crossingPoint;
3615
                                targetVertices = item.Value;
3616
                            }
3617
                            else if (slope == SlopeType.VERTICAL &&
3618
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
3619
                            {
3620
                                targetConnector = item.Key;
3621
                                length = distance;
3622
                                resultPoint = crossingPoint;
3623
                                targetVertices = item.Value;
3624
                            }
3625 68464385 gaqhf
                        }
3626
                    }
3627
                }
3628
            }
3629
3630 a0e3dca4 gaqhf
            foreach (var item in vertices)
3631
                if (item.Key != null && item.Key != targetConnector)
3632
                    ReleaseCOMObjects(item.Key);
3633
3634
            if (SPPIDUtil.IsBranchLine(line, targetLine))
3635 68464385 gaqhf
            {
3636 a0e3dca4 gaqhf
                double tempResultX = resultPoint[0];
3637
                double tempResultY = resultPoint[1];
3638
                SPPIDUtil.ConvertGridPoint(ref tempResultX, ref tempResultY);
3639 68464385 gaqhf
3640 a0e3dca4 gaqhf
                GridSetting gridSetting = GridSetting.GetInstance();
3641
3642
                for (int i = 0; i < targetVertices.Count; i++)
3643
                {
3644
                    double[] point = targetVertices[i];
3645
                    double tempX = targetVertices[i][0];
3646
                    double tempY = targetVertices[i][1];
3647
                    SPPIDUtil.ConvertGridPoint(ref tempX, ref tempY);
3648
                    if (tempX == tempResultX && tempY == tempResultY)
3649 68464385 gaqhf
                    {
3650 a0e3dca4 gaqhf
                        if (i == 0)
3651 68464385 gaqhf
                        {
3652 a0e3dca4 gaqhf
                            LMSymbol connSymbol = targetConnector.ConnectItem1SymbolObject;
3653 b01e7456 gaqhf
                            bool containZeroLength = false;
3654
                            if (connSymbol != null)
3655 a0e3dca4 gaqhf
                            {
3656 1805d3b7 gaqhf
                                foreach (LMConnector connector in connSymbol.Connect1Connectors)
3657
                                {
3658 b01e7456 gaqhf
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
3659 1805d3b7 gaqhf
                                        containZeroLength = true;
3660
                                }
3661
                                foreach (LMConnector connector in connSymbol.Connect2Connectors)
3662 a0e3dca4 gaqhf
                                {
3663 b01e7456 gaqhf
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
3664 1805d3b7 gaqhf
                                        containZeroLength = true;
3665 a0e3dca4 gaqhf
                                }
3666 b01e7456 gaqhf
                            }
3667
3668
                            if (connSymbol == null ||
3669
                                (connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") ||
3670
                                containZeroLength)
3671
                            {
3672
                                bool bCalcX = false;
3673
                                bool bCalcY = false;
3674
                                if (targetLine.SlopeType == SlopeType.HORIZONTAL)
3675
                                    bCalcX = true;
3676
                                else if (targetLine.SlopeType == SlopeType.VERTICAL)
3677
                                    bCalcY = true;
3678
                                else
3679
                                {
3680
                                    bCalcX = true;
3681
                                    bCalcY = true;
3682
                                }
3683 a0e3dca4 gaqhf
3684 b01e7456 gaqhf
                                if (bCalcX)
3685 a0e3dca4 gaqhf
                                {
3686 b01e7456 gaqhf
                                    double nextX = targetVertices[i + 1][0];
3687
                                    double newX = 0;
3688
                                    if (nextX > tempX)
3689
                                    {
3690
                                        newX = tempX + gridSetting.Length;
3691
                                        if (newX > nextX)
3692
                                            newX = (point[0] + nextX) / 2;
3693
                                    }
3694 a0e3dca4 gaqhf
                                    else
3695
                                    {
3696 b01e7456 gaqhf
                                        newX = tempX - gridSetting.Length;
3697
                                        if (newX < nextX)
3698
                                            newX = (point[0] + nextX) / 2;
3699 a0e3dca4 gaqhf
                                    }
3700 b01e7456 gaqhf
                                    resultPoint = new double[] { newX, resultPoint[1] };
3701
                                }
3702 a0e3dca4 gaqhf
3703 b01e7456 gaqhf
                                if (bCalcY)
3704
                                {
3705
                                    double nextY = targetVertices[i + 1][1];
3706
                                    double newY = 0;
3707
                                    if (nextY > tempY)
3708 a0e3dca4 gaqhf
                                    {
3709 b01e7456 gaqhf
                                        newY = tempY + gridSetting.Length;
3710
                                        if (newY > nextY)
3711
                                            newY = (point[1] + nextY) / 2;
3712 a0e3dca4 gaqhf
                                    }
3713 b01e7456 gaqhf
                                    else
3714 a0e3dca4 gaqhf
                                    {
3715 b01e7456 gaqhf
                                        newY = tempY - gridSetting.Length;
3716
                                        if (newY < nextY)
3717
                                            newY = (point[1] + nextY) / 2;
3718 a0e3dca4 gaqhf
                                    }
3719 b01e7456 gaqhf
                                    resultPoint = new double[] { resultPoint[0], newY };
3720 a0e3dca4 gaqhf
                                }
3721
                            }
3722
                        }
3723
                        else if (i == targetVertices.Count - 1)
3724
                        {
3725
                            LMSymbol connSymbol = targetConnector.ConnectItem2SymbolObject;
3726 b01e7456 gaqhf
                            bool containZeroLength = false;
3727
                            if (connSymbol != null)
3728 a0e3dca4 gaqhf
                            {
3729 1805d3b7 gaqhf
                                foreach (LMConnector connector in connSymbol.Connect1Connectors)
3730
                                {
3731 b01e7456 gaqhf
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
3732 1805d3b7 gaqhf
                                        containZeroLength = true;
3733
                                }
3734
                                foreach (LMConnector connector in connSymbol.Connect2Connectors)
3735 a0e3dca4 gaqhf
                                {
3736 b01e7456 gaqhf
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
3737 1805d3b7 gaqhf
                                        containZeroLength = true;
3738 a0e3dca4 gaqhf
                                }
3739 b01e7456 gaqhf
                            }
3740
3741
                            if (connSymbol == null ||
3742
                                 (connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") ||
3743
                                containZeroLength)
3744
                            {
3745
                                bool bCalcX = false;
3746
                                bool bCalcY = false;
3747
                                if (targetLine.SlopeType == SlopeType.HORIZONTAL)
3748
                                    bCalcX = true;
3749
                                else if (targetLine.SlopeType == SlopeType.VERTICAL)
3750
                                    bCalcY = true;
3751
                                else
3752
                                {
3753
                                    bCalcX = true;
3754
                                    bCalcY = true;
3755
                                }
3756 a0e3dca4 gaqhf
3757 b01e7456 gaqhf
                                if (bCalcX)
3758 a0e3dca4 gaqhf
                                {
3759 b01e7456 gaqhf
                                    double nextX = targetVertices[i - 1][0];
3760
                                    double newX = 0;
3761
                                    if (nextX > tempX)
3762
                                    {
3763
                                        newX = tempX + gridSetting.Length;
3764
                                        if (newX > nextX)
3765
                                            newX = (point[0] + nextX) / 2;
3766
                                    }
3767 a0e3dca4 gaqhf
                                    else
3768
                                    {
3769 b01e7456 gaqhf
                                        newX = tempX - gridSetting.Length;
3770
                                        if (newX < nextX)
3771
                                            newX = (point[0] + nextX) / 2;
3772 a0e3dca4 gaqhf
                                    }
3773 b01e7456 gaqhf
                                    resultPoint = new double[] { newX, resultPoint[1] };
3774
                                }
3775 a0e3dca4 gaqhf
3776 b01e7456 gaqhf
                                if (bCalcY)
3777
                                {
3778
                                    double nextY = targetVertices[i - 1][1];
3779
                                    double newY = 0;
3780
                                    if (nextY > tempY)
3781 a0e3dca4 gaqhf
                                    {
3782 b01e7456 gaqhf
                                        newY = tempY + gridSetting.Length;
3783
                                        if (newY > nextY)
3784
                                            newY = (point[1] + nextY) / 2;
3785 a0e3dca4 gaqhf
                                    }
3786 b01e7456 gaqhf
                                    else
3787 a0e3dca4 gaqhf
                                    {
3788 b01e7456 gaqhf
                                        newY = tempY - gridSetting.Length;
3789
                                        if (newY < nextY)
3790
                                            newY = (point[1] + nextY) / 2;
3791 a0e3dca4 gaqhf
                                    }
3792 b01e7456 gaqhf
                                    resultPoint = new double[] { resultPoint[0], newY };
3793 a0e3dca4 gaqhf
                                }
3794
                            }
3795 68464385 gaqhf
                        }
3796 a0e3dca4 gaqhf
                        break;
3797 68464385 gaqhf
                    }
3798
                }
3799
            }
3800
3801 a0e3dca4 gaqhf
            x = resultPoint[0];
3802
            y = resultPoint[1];
3803
3804 68464385 gaqhf
            return targetConnector;
3805
        }
3806
3807 1ff0105e gaqhf
        private LMConnector GetLMConnectorOnlyOne(string modelItemID)
3808
        {
3809
            LMConnector result = null;
3810
            List<LMConnector> connectors = new List<LMConnector>();
3811
            LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
3812
3813
            if (modelItem != null)
3814
            {
3815
                foreach (LMRepresentation rep in modelItem.Representations)
3816
                {
3817
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
3818
                        connectors.Add(dataSource.GetConnector(rep.Id));
3819
                }
3820
3821
                ReleaseCOMObjects(modelItem);
3822
            }
3823
3824
            if (connectors.Count == 1)
3825
                result = connectors[0];
3826
            else
3827
                foreach (var item in connectors)
3828
                    ReleaseCOMObjects(item);
3829
3830
            return result;
3831
        }
3832
3833 63a112d9 gaqhf
        private LMConnector GetLMConnectorFirst(string modelItemID)
3834
        {
3835
            LMConnector result = null;
3836
            LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
3837
3838
            if (modelItem != null)
3839
            {
3840
                foreach (LMRepresentation rep in modelItem.Representations)
3841
                {
3842
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && 
3843
                        rep.Attributes["ItemStatus"].get_Value() == "Active")
3844
                    {
3845
                        LMConnector connector = dataSource.GetConnector(rep.Id);
3846
                        if (!Convert.ToBoolean(connector.get_IsZeroLength()))
3847
                        {
3848
                            result = connector;
3849
                            break;
3850
                        }
3851
                        else
3852
                        {
3853
                            ReleaseCOMObjects(connector);
3854
                            connector = null;
3855
                        }
3856
                    }
3857
                }
3858
                ReleaseCOMObjects(modelItem);
3859
                modelItem = null;
3860
            }
3861
3862
            return result;
3863
        }
3864
3865 7e680366 gaqhf
        private int GetConnectorCount(string modelItemID)
3866
        {
3867
            LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
3868
            int result = 0;
3869
            if (modelItem != null)
3870
            {
3871
                foreach (LMRepresentation rep in modelItem.Representations)
3872
                {
3873
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
3874
                        result++;
3875
                    ReleaseCOMObjects(rep);
3876
                }
3877
                ReleaseCOMObjects(modelItem);
3878
            }
3879
3880
            return result;
3881
        }
3882
3883 fae4f386 gaqhf
        public List<string> GetRepresentations(string modelItemID)
3884
        {
3885
            List<string> result = new List<string>(); ;
3886
            LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
3887
            if (modelItem != null)
3888
            {
3889
                foreach (LMRepresentation rep in modelItem.Representations)
3890
                {
3891
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
3892
                        result.Add(rep.Id);
3893
                }
3894
                ReleaseCOMObjects(modelItem);
3895
            }
3896
3897
            return result;
3898
        }
3899
3900 74752074 gaqhf
        /// <summary>
3901
        /// Line Number Symbol을 실제로 Modeling하는 메서드
3902
        /// </summary>
3903
        /// <param name="lineNumber"></param>
3904 8701de36 gaqhf
        private void LineNumberModelingOnlyOne(Line line)
3905 cfda1fed gaqhf
        {
3906 32205389 gaqhf
            LineNumber lineNumber = document.LINENUMBERS.Find(x => x.CONNLINE == line.UID);
3907
            if (lineNumber != null)
3908 10872260 gaqhf
            {
3909 32205389 gaqhf
                LMConnector connectedLMConnector = GetLMConnectorOnlyOne(line.SPPID.ModelItemId);
3910 340515a2 gaqhf
                if (connectedLMConnector != null)
3911
                {
3912
                    double x = 0;
3913
                    double y = 0;
3914
                    CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
3915 b65a7e32 gaqhf
3916 340515a2 gaqhf
                    Array points = new double[] { 0, x, y };
3917 44087b23 gaqhf
                    lineNumber.SPPID.SPPID_X = x;
3918
                    lineNumber.SPPID.SPPID_Y = y;
3919 340515a2 gaqhf
                    LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false);
3920 cfda1fed gaqhf
3921 340515a2 gaqhf
                    if (_LmLabelPresist != null)
3922
                    {
3923
                        _LmLabelPresist.Commit();
3924
                        lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
3925
                        ReleaseCOMObjects(_LmLabelPresist);
3926
                    }
3927 c3d2e266 gaqhf
                }
3928 10872260 gaqhf
            }
3929 cfda1fed gaqhf
        }
3930 02a45794 gaqhf
3931 8701de36 gaqhf
        private void LineNumberModeling(LineNumber lineNumber)
3932
        {
3933
            Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line;
3934
            if (line != null)
3935
            {
3936
                double x = 0;
3937
                double y = 0;
3938
                CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
3939
3940
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
3941
                LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, x, y);
3942
                if (connectedLMConnector != null)
3943
                {
3944
                    Array points = new double[] { 0, x, y };
3945 44087b23 gaqhf
                    lineNumber.SPPID.SPPID_X = x;
3946
                    lineNumber.SPPID.SPPID_Y = y;
3947 8701de36 gaqhf
                    LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false);
3948 ca6e0f51 gaqhf
3949 8701de36 gaqhf
                    if (_LmLabelPresist != null)
3950
                    {
3951
                        _LmLabelPresist.Commit();
3952
                        lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
3953
                        ReleaseCOMObjects(_LmLabelPresist);
3954
                    }
3955
                }
3956
3957
                foreach (var item in connectorVertices)
3958
                    ReleaseCOMObjects(item.Key);
3959
            }
3960
        }
3961 44087b23 gaqhf
        private void LineNumberCorrectModeling(LineNumber lineNumber)
3962
        {
3963
            Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line;
3964
            if (line == null || line.SPPID.Vertices == null)
3965
                return;
3966
3967
            if (!string.IsNullOrEmpty(lineNumber.SPPID.RepresentationId))
3968
            {
3969
                LMLabelPersist removeLabel = dataSource.GetLabelPersist(lineNumber.SPPID.RepresentationId);
3970
                if (removeLabel != null)
3971
                {
3972
                    GridSetting gridSetting = GridSetting.GetInstance();
3973
                    double[] labelRange = null;
3974
                    GetSPPIDSymbolRange(removeLabel, ref labelRange);
3975
                    LMConnector connector = dataSource.GetConnector(removeLabel.RepresentationID);
3976
                    List<double[]> vertices = GetConnectorVertices(connector);
3977
3978
                    double[] resultStart = null;
3979
                    double[] resultEnd = null;
3980
                    double distance = double.MaxValue;
3981
                    for (int i = 0; i < vertices.Count - 1; i++)
3982
                    {
3983
                        double[] startPoint = vertices[i];
3984
                        double[] endPoint = vertices[i + 1];
3985
                        foreach (var item in line.SPPID.Vertices)
3986
                        {
3987
                            double[] lineStartPoint = item[0];
3988
                            double[] lineEndPoint = item[item.Count - 1];
3989
3990
                            double tempDistance = SPPIDUtil.CalcPointToPointdDistance(startPoint[0], startPoint[1], lineStartPoint[0], lineStartPoint[1]) +
3991
                                SPPIDUtil.CalcPointToPointdDistance(endPoint[0], endPoint[1], lineEndPoint[0], lineEndPoint[1]);
3992
                            if (tempDistance < distance)
3993
                            {
3994
                                distance = tempDistance;
3995
                                resultStart = startPoint;
3996
                                resultEnd = endPoint;
3997
                            }
3998
                            tempDistance = SPPIDUtil.CalcPointToPointdDistance(startPoint[0], startPoint[1], lineEndPoint[0], lineEndPoint[1]) +
3999
                                SPPIDUtil.CalcPointToPointdDistance(endPoint[0], endPoint[1], lineStartPoint[0], lineStartPoint[1]);
4000
                            if (tempDistance < distance)
4001
                            {
4002
                                distance = tempDistance;
4003
                                resultStart = startPoint;
4004
                                resultEnd = endPoint;
4005
                            }
4006
                        }
4007
                    }
4008
4009
                    if (resultStart != null && resultEnd != null)
4010
                    {
4011
                        SlopeType slope = SPPIDUtil.CalcSlope(resultStart[0], resultStart[1], resultEnd[0], resultEnd[1]);
4012
                        double lineStartX = 0;
4013
                        double lineStartY = 0;
4014
                        double lineEndX = 0;
4015
                        double lineEndY = 0;
4016
                        double lineNumberX = 0;
4017
                        double lineNumberY = 0;
4018
                        SPPIDUtil.ConvertPointBystring(line.STARTPOINT, ref lineStartX, ref lineStartY);
4019
                        SPPIDUtil.ConvertPointBystring(line.ENDPOINT, ref lineEndX, ref lineEndY);
4020
4021
                        double lineX = (lineStartX + lineEndX) / 2;
4022
                        double lineY = (lineStartY + lineEndY) / 2;
4023
                        lineNumberX = (lineNumber.X1 + lineNumber.X2) / 2;
4024
                        lineNumberY = (lineNumber.Y1 + lineNumber.Y2) / 2;
4025
4026
                        double SPPIDCenterX = (resultStart[0] + resultEnd[0]) / 2;
4027
                        double SPPIDCenterY = (resultStart[1] + resultEnd[1]) / 2;
4028
                        double labelCenterX = (labelRange[0] + labelRange[2]) / 2;
4029
                        double labelCenterY = (labelRange[1] + labelRange[3]) / 2;
4030
4031
                        double offsetX = 0;
4032
                        double offsetY = 0;
4033
                        if (slope == SlopeType.HORIZONTAL)
4034
                        {
4035
                            // Line Number 아래
4036
                            if (lineY < lineNumberY)
4037
                            {
4038
                                offsetX = labelCenterX - SPPIDCenterX;
4039
                                offsetY = labelRange[3] - SPPIDCenterY + gridSetting.Length;
4040
                                MoveLineNumber(lineNumber, offsetX, offsetY);
4041
                            }
4042
                            // Line Number 위
4043
                            else
4044
                            {
4045
                                offsetX = labelCenterX - SPPIDCenterX;
4046
                                offsetY = labelRange[1] - SPPIDCenterY - gridSetting.Length;
4047
                                MoveLineNumber(lineNumber, offsetX, offsetY);
4048
                            }
4049
                        }
4050
                        else if (slope == SlopeType.VERTICAL)
4051
                        {
4052
                            // Line Number 오르쪽
4053
                            if (lineX < lineNumberX)
4054
                            {
4055
                                offsetX = labelRange[0] - SPPIDCenterX - gridSetting.Length;
4056
                                offsetY = labelCenterY - SPPIDCenterY;
4057
                                MoveLineNumber(lineNumber, offsetX, offsetY);
4058
                            }
4059
                            // Line Number 왼쪽
4060
                            else
4061
                            {
4062
                                offsetX = labelRange[2] - SPPIDCenterX + gridSetting.Length;
4063
                                offsetY = labelCenterY - SPPIDCenterY;
4064
                                MoveLineNumber(lineNumber, offsetX, offsetY);
4065
                            }
4066
                        }
4067
4068
                        if (offsetY != 0 && offsetY != 0)
4069
                        {
4070
                            _placement.PIDRemovePlacement(removeLabel.AsLMRepresentation());
4071
                            Array points = new double[] { 0, lineNumber.SPPID.SPPID_X, lineNumber.SPPID.SPPID_Y };
4072
                            LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connector.AsLMRepresentation(), IsLeaderVisible: false);
4073
4074
                            if (_LmLabelPresist != null)
4075
                            {
4076
                                _LmLabelPresist.Commit();
4077
                                lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
4078
                            }
4079
                            ReleaseCOMObjects(_LmLabelPresist);
4080
                            _LmLabelPresist = null; 
4081
                        }
4082
4083
                        void MoveLineNumber(LineNumber moveLineNumber, double x, double y)
4084
                        {
4085
                            moveLineNumber.SPPID.SPPID_X = moveLineNumber.SPPID.SPPID_X - x;
4086
                            moveLineNumber.SPPID.SPPID_Y = moveLineNumber.SPPID.SPPID_Y - y;
4087
                        }
4088
                    }
4089
4090
4091
                    ReleaseCOMObjects(connector);
4092
                    connector = null;
4093
                }
4094
4095
                ReleaseCOMObjects(removeLabel);
4096
                removeLabel = null;
4097
            }
4098
        }
4099 74752074 gaqhf
        /// <summary>
4100 b2d1c1aa gaqhf
        /// Flow Mark Modeling
4101
        /// </summary>
4102
        /// <param name="line"></param>
4103
        private void FlowMarkModeling(Line line)
4104
        {
4105 a0965e07 gaqhf
            if (line.FLOWMARK && !string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(_ETCSetting.FlowMarkSymbolPath))
4106 b2d1c1aa gaqhf
            {
4107 32205389 gaqhf
                LMConnector connector = GetLMConnectorOnlyOne(line.SPPID.ModelItemId);
4108
                if (connector != null)
4109 b2d1c1aa gaqhf
                {
4110 32205389 gaqhf
                    string mappingPath = _ETCSetting.FlowMarkSymbolPath;
4111
                    List<double[]> vertices = GetConnectorVertices(connector);
4112
                    vertices = vertices.FindAll(x => x[0] > 0 && x[1] > 0);
4113
                    double[] point = vertices[vertices.Count - 1];
4114
                    Array array = new double[] { 0, point[0], point[1] };
4115
                    LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mappingPath, ref array, LabeledItem: connector.AsLMRepresentation());
4116
                    if (_LMLabelPersist != null)
4117 04fcadf1 gaqhf
                    {
4118
                        _LMLabelPersist.Commit();
4119 32205389 gaqhf
                        ReleaseCOMObjects(_LMLabelPersist);
4120 04fcadf1 gaqhf
                    }
4121
                        
4122 b2d1c1aa gaqhf
                }
4123
            }
4124
        }
4125
4126
        /// <summary>
4127 74752074 gaqhf
        /// Line Number 기준으로 모든 Item에 Line Number의 Attribute Input
4128
        /// </summary>
4129
        /// <param name="lineNumber"></param>
4130 82d6e5ea gaqhf
        private void InputLineNumberAttribute(LineNumber lineNumber, List<string> endLine)
4131 a7e9beec gaqhf
        {
4132 8634af60 gaqhf
            foreach (LineRun run in lineNumber.RUNS)
4133 a7e9beec gaqhf
            {
4134 8634af60 gaqhf
                foreach (var item in run.RUNITEMS)
4135 a7e9beec gaqhf
                {
4136 48fd75e2 gaqhf
                    if (item.GetType() == typeof(Symbol))
4137
                    {
4138
                        Symbol symbol = item as Symbol;
4139
                        LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
4140
                        if (_LMSymbol != null)
4141
                        {
4142
                            LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
4143
4144
                            if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
4145
                            {
4146
                                foreach (var attribute in lineNumber.ATTRIBUTES)
4147
                                {
4148
                                    LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
4149
                                    if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
4150
                                    {
4151
                                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
4152
                                        if (_LMAAttribute != null)
4153
                                        {
4154
                                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
4155
                                                _LMAAttribute.set_Value(attribute.VALUE);
4156
                                            else if (_LMAAttribute.get_Value() != attribute.VALUE)
4157
                                                _LMAAttribute.set_Value(attribute.VALUE);
4158
                                        }
4159
                                    }
4160
                                }
4161
                                _LMModelItem.Commit();
4162
                            }
4163
                            if (_LMModelItem != null)
4164
                                ReleaseCOMObjects(_LMModelItem);
4165
                        }
4166
                        if (_LMSymbol != null)
4167
                            ReleaseCOMObjects(_LMSymbol);
4168
                    }
4169
                    else if (item.GetType() == typeof(Line))
4170 8634af60 gaqhf
                    {
4171
                        Line line = item as Line;
4172 82d6e5ea gaqhf
                        if (line != null && !endLine.Contains(line.SPPID.ModelItemId))
4173 a7e9beec gaqhf
                        {
4174 8634af60 gaqhf
                            LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
4175
                            if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
4176 a7e9beec gaqhf
                            {
4177 8634af60 gaqhf
                                foreach (var attribute in lineNumber.ATTRIBUTES)
4178
                                {
4179
                                    LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
4180 b2d1c1aa gaqhf
                                    if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
4181 8634af60 gaqhf
                                    {
4182
                                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
4183
                                        if (_LMAAttribute != null)
4184
                                        {
4185
                                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
4186
                                                _LMAAttribute.set_Value(attribute.VALUE);
4187
                                            else if (_LMAAttribute.get_Value() != attribute.VALUE)
4188
                                                _LMAAttribute.set_Value(attribute.VALUE);
4189 7f00b26c gaqhf
4190 8634af60 gaqhf
                                        }
4191
                                    }
4192
                                }
4193 68464385 gaqhf
                                _LMModelItem.Commit();
4194 a7e9beec gaqhf
                            }
4195 8634af60 gaqhf
                            if (_LMModelItem != null)
4196
                                ReleaseCOMObjects(_LMModelItem);
4197 82d6e5ea gaqhf
                            endLine.Add(line.SPPID.ModelItemId);
4198 a7e9beec gaqhf
                        }
4199
                    }
4200
                }
4201
            }
4202
        }
4203
4204 74752074 gaqhf
        /// <summary>
4205
        /// Symbol Attribute 입력 메서드
4206
        /// </summary>
4207 73415441 gaqhf
        /// <param name="item"></param>
4208
        private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes)
4209 1efc25a3 gaqhf
        {
4210 7f00b26c gaqhf
            // Object 아이템이 Symbol일 경우 Equipment일 경우 
4211
            string sRep = null;
4212
            if (targetItem.GetType() == typeof(Symbol))
4213
                sRep = ((Symbol)targetItem).SPPID.RepresentationId;
4214
            else if (targetItem.GetType() == typeof(Equipment))
4215
                sRep = ((Equipment)targetItem).SPPID.RepresentationId;
4216
4217
            if (!string.IsNullOrEmpty(sRep))
4218 1efc25a3 gaqhf
            {
4219 7f00b26c gaqhf
                LMSymbol _LMSymbol = dataSource.GetSymbol(sRep);
4220
                LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
4221
                LMAAttributes _Attributes = _LMModelItem.Attributes;
4222 ca6e0f51 gaqhf
                
4223 7f00b26c gaqhf
                foreach (var item in targetAttributes)
4224
                {
4225
                    AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
4226
                    if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None")
4227 65a1ed4b gaqhf
                    {
4228 7f00b26c gaqhf
                        LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
4229
                        if (_Attribute != null)
4230 30ba9ae0 gaqhf
                        {
4231 4e865771 gaqhf
                            //object associItem = SPPIDUtil.FindObjectByUID(document, item.ASSOCITEM);
4232
                            //if (associItem != null)
4233
                            //{
4234
                            //    if (associItem.GetType() == typeof(Text))
4235
                            //    {
4236
                            //        Text text = associItem as Text;
4237
                            //        text.SPPID.RepresentationId = "Attribute";
4238
                            //    }
4239
                            //    else if (associItem.GetType() == typeof(Note))
4240
                            //    {
4241
                            //        Note note = associItem as Note;
4242
                            //        note.SPPID.RepresentationId = "Attribute";
4243
                            //    }
4244
                            //}
4245 7f00b26c gaqhf
                            _Attribute.set_Value(item.VALUE);
4246 b7a29053 gaqhf
                            // OPC 일경우 Attribute 저장
4247
                            if (targetItem.GetType() == typeof(Symbol))
4248
                            {
4249
                                Symbol symbol = targetItem as Symbol;
4250
                                if (symbol.TYPE == "Piping OPC's" || symbol.TYPE == "Instrument OPC's")
4251
                                    symbol.SPPID.Attributes.Add(new string[] { mapping.SPPIDATTRIBUTENAME, item.VALUE });
4252
                            }
4253 30ba9ae0 gaqhf
                        }
4254 65a1ed4b gaqhf
                    }
4255 ac78b508 gaqhf
                }
4256 7f00b26c gaqhf
                _LMModelItem.Commit();
4257
4258
                ReleaseCOMObjects(_Attributes);
4259
                ReleaseCOMObjects(_LMModelItem);
4260
                ReleaseCOMObjects(_LMSymbol);
4261 1efc25a3 gaqhf
            }
4262
        }
4263
4264 74752074 gaqhf
        /// <summary>
4265 16584d30 gaqhf
        /// Input SpecBreak Attribute
4266
        /// </summary>
4267
        /// <param name="specBreak"></param>
4268
        private void InputSpecBreakAttribute(SpecBreak specBreak)
4269
        {
4270 7f00b26c gaqhf
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
4271
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
4272
4273
            if (upStreamObj != null &&
4274
                downStreamObj != null)
4275 16584d30 gaqhf
            {
4276 7f00b26c gaqhf
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
4277 16584d30 gaqhf
4278 7f00b26c gaqhf
                if (targetLMConnector != null)
4279 16584d30 gaqhf
                {
4280 7f00b26c gaqhf
                    foreach (LMLabelPersist _LMLabelPersist in targetLMConnector.LabelPersists)
4281 16584d30 gaqhf
                    {
4282 7f00b26c gaqhf
                        string symbolPath = _LMLabelPersist.get_FileName();
4283
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.SPPIDSYMBOLNAME == symbolPath);
4284
                        if (mapping != null)
4285 16584d30 gaqhf
                        {
4286 7f00b26c gaqhf
                            BaseModel.Attribute attribute = specBreak.ATTRIBUTES.Find(y => y.UID == mapping.UID);
4287
                            if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
4288 16584d30 gaqhf
                            {
4289 7f00b26c gaqhf
                                string[] values = attribute.VALUE.Split(new char[] { ',' });
4290
                                if (values.Length == 2)
4291 16584d30 gaqhf
                                {
4292 7f00b26c gaqhf
                                    string upStreamValue = values[0];
4293
                                    string downStreamValue = values[1];
4294 16584d30 gaqhf
4295 7f00b26c gaqhf
                                    InputAttributeForSpecBreak(upStreamObj, downStreamObj, upStreamValue, downStreamValue, mapping.SPPIDATTRIBUTENAME);
4296 16584d30 gaqhf
                                }
4297
                            }
4298
                        }
4299
                    }
4300 7f00b26c gaqhf
4301
                    ReleaseCOMObjects(targetLMConnector);
4302 16584d30 gaqhf
                }
4303
            }
4304 7f00b26c gaqhf
4305 16584d30 gaqhf
4306
            #region 내부에서만 쓰는 메서드
4307 7f00b26c gaqhf
            void InputAttributeForSpecBreak(object _upStreamObj, object _downStreamObj, string upStreamValue, string downStreamValue, string sppidAttributeName)
4308 16584d30 gaqhf
            {
4309 7f00b26c gaqhf
                Symbol upStreamSymbol = _upStreamObj as Symbol;
4310
                Line upStreamLine = _upStreamObj as Line;
4311
                Symbol downStreamSymbol = _downStreamObj as Symbol;
4312
                Line downStreamLine = _downStreamObj as Line;
4313
                // 둘다 Line일 경우
4314
                if (upStreamLine != null && downStreamLine != null)
4315 16584d30 gaqhf
                {
4316 7f00b26c gaqhf
                    InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
4317
                    InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
4318
                }
4319
                // 둘다 Symbol일 경우
4320
                else if (upStreamSymbol != null && downStreamSymbol != null)
4321
                {
4322
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamSymbol);
4323
                    LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
4324
                    LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
4325 16584d30 gaqhf
4326 7f00b26c gaqhf
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
4327
                    {
4328
                        if (connector.get_ItemStatus() != "Active")
4329
                            continue;
4330 16584d30 gaqhf
4331 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
4332
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
4333
                    }
4334 16584d30 gaqhf
4335 7f00b26c gaqhf
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
4336
                    {
4337
                        if (connector.get_ItemStatus() != "Active")
4338
                            continue;
4339 16584d30 gaqhf
4340 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
4341
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
4342
                    }
4343 16584d30 gaqhf
4344 7f00b26c gaqhf
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
4345
                    {
4346
                        if (connector.get_ItemStatus() != "Active")
4347
                            continue;
4348 16584d30 gaqhf
4349 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
4350
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
4351
                    }
4352 16584d30 gaqhf
4353 7f00b26c gaqhf
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
4354
                    {
4355
                        if (connector.get_ItemStatus() != "Active")
4356
                            continue;
4357 16584d30 gaqhf
4358 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
4359
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
4360 16584d30 gaqhf
                    }
4361
4362 7f00b26c gaqhf
                    ReleaseCOMObjects(zeroLenthConnector);
4363
                    ReleaseCOMObjects(upStreamLMSymbol);
4364
                    ReleaseCOMObjects(downStreamLMSymbol);
4365
                }
4366
                else if (upStreamSymbol != null && downStreamLine != null)
4367
                {
4368
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamLine);
4369
                    InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
4370
                    LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
4371 16584d30 gaqhf
4372 7f00b26c gaqhf
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
4373
                    {
4374
                        if (connector.get_ItemStatus() != "Active")
4375
                            continue;
4376 16584d30 gaqhf
4377 c993d55a gaqhf
                        if (connector.Id == zeroLenthConnector.Id)
4378 7f00b26c gaqhf
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
4379
                    }
4380 16584d30 gaqhf
4381 7f00b26c gaqhf
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
4382
                    {
4383
                        if (connector.get_ItemStatus() != "Active")
4384
                            continue;
4385 16584d30 gaqhf
4386 c993d55a gaqhf
                        if (connector.Id == zeroLenthConnector.Id)
4387 7f00b26c gaqhf
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
4388 16584d30 gaqhf
                    }
4389
4390 7f00b26c gaqhf
                    ReleaseCOMObjects(zeroLenthConnector);
4391
                    ReleaseCOMObjects(upStreamLMSymbol);
4392
                }
4393
                else if (upStreamLine != null && downStreamSymbol != null)
4394
                {
4395
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamLine, downStreamSymbol);
4396
                    InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
4397
                    LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
4398 16584d30 gaqhf
4399 7f00b26c gaqhf
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
4400
                    {
4401
                        if (connector.get_ItemStatus() != "Active")
4402
                            continue;
4403 16584d30 gaqhf
4404 c993d55a gaqhf
                        if (connector.Id == zeroLenthConnector.Id)
4405 7f00b26c gaqhf
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
4406
                    }
4407 16584d30 gaqhf
4408 7f00b26c gaqhf
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
4409
                    {
4410
                        if (connector.get_ItemStatus() != "Active")
4411
                            continue;
4412 16584d30 gaqhf
4413 c993d55a gaqhf
                        if (connector.Id == zeroLenthConnector.Id)
4414 7f00b26c gaqhf
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
4415 16584d30 gaqhf
                    }
4416 7f00b26c gaqhf
4417
                    ReleaseCOMObjects(zeroLenthConnector);
4418
                    ReleaseCOMObjects(downStreamLMSymbol);
4419 16584d30 gaqhf
                }
4420
            }
4421
4422
            void InputLineAttributeForSpecBreakLine(Line line, string attrName, string value)
4423
            {
4424 7f00b26c gaqhf
                LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
4425
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
4426 16584d30 gaqhf
                {
4427 7f00b26c gaqhf
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
4428
                    if (_LMAAttribute != null)
4429 16584d30 gaqhf
                    {
4430 7f00b26c gaqhf
                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
4431
                            _LMAAttribute.set_Value(value);
4432
                        else if (_LMAAttribute.get_Value() != value)
4433
                            _LMAAttribute.set_Value(value);
4434 16584d30 gaqhf
                    }
4435 7f00b26c gaqhf
4436
                    _LMModelItem.Commit();
4437 16584d30 gaqhf
                }
4438 7f00b26c gaqhf
                if (_LMModelItem != null)
4439
                    ReleaseCOMObjects(_LMModelItem);
4440 16584d30 gaqhf
            }
4441
4442
            void InputLineAttributeForSpecBreakLMConnector(LMConnector connector, string attrName, string value)
4443
            {
4444 7f00b26c gaqhf
                LMModelItem _LMModelItem = dataSource.GetModelItem(connector.ModelItemID);
4445
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
4446 16584d30 gaqhf
                {
4447 7f00b26c gaqhf
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
4448
                    if (_LMAAttribute != null)
4449 16584d30 gaqhf
                    {
4450 7f00b26c gaqhf
                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
4451
                            _LMAAttribute.set_Value(value);
4452
                        else if (_LMAAttribute.get_Value() != value)
4453
                            _LMAAttribute.set_Value(value);
4454 16584d30 gaqhf
                    }
4455 7f00b26c gaqhf
4456
                    _LMModelItem.Commit();
4457 16584d30 gaqhf
                }
4458 7f00b26c gaqhf
                if (_LMModelItem != null)
4459
                    ReleaseCOMObjects(_LMModelItem);
4460 16584d30 gaqhf
            }
4461
            #endregion
4462
        }
4463
4464 d8afa58b gaqhf
        private void InputEndBreakAttribute(EndBreak endBreak)
4465
        {
4466
            object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER);
4467
            object connectedItem = SPPIDUtil.FindObjectByUID(document, endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE);
4468
4469
            if ((ownerObj.GetType() == typeof(Symbol) && connectedItem.GetType() == typeof(Line)) ||
4470
                (ownerObj.GetType() == typeof(Line) && connectedItem.GetType() == typeof(Symbol)))
4471
            {
4472
                LMLabelPersist labelPersist = dataSource.GetLabelPersist(endBreak.SPPID.RepresentationId);
4473
                if (labelPersist != null)
4474
                {
4475
                    LMRepresentation representation = labelPersist.RepresentationObject;
4476
                    if (representation != null)
4477
                    {
4478
                        LMConnector connector = dataSource.GetConnector(representation.Id);
4479
                        LMModelItem ZeroLengthModelItem = connector.ModelItemObject;
4480
                        string modelItemID = connector.ModelItemID;
4481
                        if (Convert.ToBoolean(connector.get_IsZeroLength()))
4482
                        {
4483
                            List<string> modelItemIDs = new List<string>();
4484
                            if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch")
4485
                            {
4486
                                LMSymbol symbol = connector.ConnectItem1SymbolObject;
4487
                                foreach (LMConnector item in symbol.Connect1Connectors)
4488
                                {
4489
                                    if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID)
4490
                                        modelItemIDs.Add(item.ModelItemID);
4491
                                    ReleaseCOMObjects(item);
4492
                                }
4493
                                foreach (LMConnector item in symbol.Connect2Connectors)
4494
                                {
4495
                                    if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID)
4496
                                        modelItemIDs.Add(item.ModelItemID);
4497
                                    ReleaseCOMObjects(item);
4498
                                }
4499
                                ReleaseCOMObjects(symbol);
4500
                                symbol = null;
4501
                            }
4502
                            else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch")
4503
                            {
4504
                                LMSymbol symbol = connector.ConnectItem2SymbolObject;
4505
                                foreach (LMConnector item in symbol.Connect1Connectors)
4506
                                {
4507
                                    if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID)
4508
                                        modelItemIDs.Add(item.ModelItemID);
4509
                                    ReleaseCOMObjects(item);
4510
                                }
4511
                                foreach (LMConnector item in symbol.Connect2Connectors)
4512
                                {
4513
                                    if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID)
4514
                                        modelItemIDs.Add(item.ModelItemID);
4515
                                    ReleaseCOMObjects(item);
4516
                                }
4517
                                ReleaseCOMObjects(symbol);
4518
                                symbol = null;
4519
                            }
4520
4521
                            modelItemIDs = modelItemIDs.Distinct().ToList();
4522
                            if (modelItemIDs.Count == 1)
4523
                            {
4524
                                LMModelItem modelItem = dataSource.GetModelItem(modelItemIDs[0]);
4525 3ebe4712 gaqhf
                                LMConnector onlyOne = GetLMConnectorOnlyOne(modelItem.Id);
4526
                                if (onlyOne != null && Convert.ToBoolean(onlyOne.get_IsZeroLength()))
4527
                                {
4528
                                    bool result = false;
4529
                                    foreach (LMLabelPersist loop in onlyOne.LabelPersists)
4530
                                    {
4531
                                        if (document.EndBreaks.Find(x => x.SPPID.RepresentationId == loop.RepresentationID) != null)
4532
                                            result = true;
4533
                                        ReleaseCOMObjects(loop);
4534
                                    }
4535
4536
                                    if (result)
4537
                                    {
4538
                                        object value = modelItem.Attributes["TagSequenceNo"].get_Value();
4539
                                        ZeroLengthModelItem.Attributes["TagSequenceNo"].set_Value(value);
4540
                                        ZeroLengthModelItem.Commit();
4541
                                    }
4542
                                    else
4543
                                    {
4544
                                        List<string> loopModelItems = new List<string>();
4545
                                        if (onlyOne.ConnectItem1SymbolObject.get_RepresentationType() == "Branch")
4546
                                        {
4547
                                            LMSymbol _symbol = onlyOne.ConnectItem1SymbolObject;
4548
                                            foreach (LMConnector loop in _symbol.Connect1Connectors)
4549
                                            {
4550
                                                if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID)
4551
                                                    loopModelItems.Add(loop.ModelItemID);
4552
                                                ReleaseCOMObjects(loop);
4553
                                            }
4554 a7c63998 gaqhf
                                            foreach (LMConnector loop in _symbol.Connect2Connectors)
4555
                                            {
4556
                                                if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID)
4557
                                                    loopModelItems.Add(loop.ModelItemID);
4558
                                                ReleaseCOMObjects(loop);
4559
                                            }
4560 3ebe4712 gaqhf
                                            ReleaseCOMObjects(_symbol);
4561
                                            _symbol = null;
4562
                                        }
4563
                                        else if (onlyOne.ConnectItem2SymbolObject.get_RepresentationType() == "Branch")
4564
                                        {
4565 a7c63998 gaqhf
                                            LMSymbol _symbol = onlyOne.ConnectItem2SymbolObject;
4566 3ebe4712 gaqhf
                                            foreach (LMConnector loop in _symbol.Connect1Connectors)
4567
                                            {
4568
                                                if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID)
4569
                                                    loopModelItems.Add(loop.ModelItemID);
4570
                                                ReleaseCOMObjects(loop);
4571
                                            }
4572 a7c63998 gaqhf
                                            foreach (LMConnector loop in _symbol.Connect2Connectors)
4573
                                            {
4574
                                                if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID)
4575
                                                    loopModelItems.Add(loop.ModelItemID);
4576
                                                ReleaseCOMObjects(loop);
4577
                                            }
4578 3ebe4712 gaqhf
                                            ReleaseCOMObjects(_symbol);
4579
                                            _symbol = null;
4580
                                        }
4581
4582
                                        loopModelItems = loopModelItems.Distinct().ToList();
4583
                                        if (loopModelItems.Count == 1)
4584
                                        {
4585
                                            LMModelItem loopModelItem = dataSource.GetModelItem(loopModelItems[0]);
4586
                                            object value = loopModelItem.Attributes["TagSequenceNo"].get_Value();
4587 e1c86c6a gaqhf
                                            modelItem.Attributes["TagSequenceNo"].set_Value(value);
4588
                                            modelItem.Commit();
4589 3ebe4712 gaqhf
                                            ZeroLengthModelItem.Attributes["TagSequenceNo"].set_Value(value);
4590
                                            ZeroLengthModelItem.Commit();
4591
4592
                                            ReleaseCOMObjects(loopModelItem);
4593
                                            loopModelItem = null;
4594
                                        }
4595
                                    }
4596
                                }
4597
                                else
4598
                                {
4599
                                    object value = modelItem.Attributes["TagSequenceNo"].get_Value();
4600
                                    ZeroLengthModelItem.Attributes["TagSequenceNo"].set_Value(value);
4601
                                    ZeroLengthModelItem.Commit();
4602
                                }
4603 d8afa58b gaqhf
                                ReleaseCOMObjects(modelItem);
4604
                                modelItem = null;
4605 3ebe4712 gaqhf
                                ReleaseCOMObjects(onlyOne);
4606
                                onlyOne = null;
4607 d8afa58b gaqhf
                            }
4608
                        }
4609
                        ReleaseCOMObjects(connector);
4610
                        connector = null;
4611
                        ReleaseCOMObjects(ZeroLengthModelItem);
4612
                        ZeroLengthModelItem = null;
4613
                    }
4614
                    ReleaseCOMObjects(representation);
4615
                    representation = null;
4616
                }
4617
                ReleaseCOMObjects(labelPersist);
4618
                labelPersist = null;
4619
            }
4620
        }
4621
4622 16584d30 gaqhf
        /// <summary>
4623 74752074 gaqhf
        /// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링
4624
        /// </summary>
4625
        /// <param name="text"></param>
4626 e27329d6 gaqhf
        private void NormalTextModeling(Text text)
4627 cfda1fed gaqhf
        {
4628 6b298450 gaqhf
            LMSymbol _LMSymbol = null;
4629 e27329d6 gaqhf
4630
            LMItemNote _LMItemNote = null;
4631
            LMAAttribute _LMAAttribute = null;
4632
4633
            double x = 0;
4634
            double y = 0;
4635
            double angle = text.ANGLE;
4636
            CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation);
4637
4638
            SPPIDUtil.ConvertGridPoint(ref x, ref y);
4639
            text.SPPID.SPPID_X = x;
4640
            text.SPPID.SPPID_Y = y;
4641
4642
            _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y, Rotation: angle);
4643
            if (_LMSymbol != null)
4644 6b298450 gaqhf
            {
4645 e27329d6 gaqhf
                _LMSymbol.Commit();
4646
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
4647
                if (_LMItemNote != null)
4648 ea80efaa gaqhf
                {
4649 e27329d6 gaqhf
                    _LMItemNote.Commit();
4650
                    _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
4651
                    if (_LMAAttribute != null)
4652 ea80efaa gaqhf
                    {
4653 e27329d6 gaqhf
                        _LMAAttribute.set_Value(text.VALUE);
4654
                        text.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
4655
                        _LMItemNote.Commit();
4656 0860c756 gaqhf
4657
4658 e27329d6 gaqhf
                        double[] range = null;
4659
                        foreach (LMLabelPersist labelPersist in _LMSymbol.LabelPersists)
4660
                        {
4661
                            double[] temp = null;
4662
                            GetSPPIDSymbolRange(labelPersist, ref temp);
4663
                            if (temp != null)
4664
                            {
4665
                                if (range == null)
4666
                                    range = temp;
4667
                                else
4668 0860c756 gaqhf
                                {
4669 e27329d6 gaqhf
                                    range = new double[] {
4670
                                            Math.Min(range[0], temp[0]),
4671
                                            Math.Min(range[1], temp[1]),
4672
                                            Math.Max(range[2], temp[2]),
4673
                                            Math.Max(range[3], temp[3])
4674
                                        };
4675 0860c756 gaqhf
                                }
4676
                            }
4677
                        }
4678 e27329d6 gaqhf
                        text.SPPID.Range = range;
4679
4680
                        if (_LMAAttribute != null)
4681
                            ReleaseCOMObjects(_LMAAttribute);
4682
                        if (_LMItemNote != null)
4683
                            ReleaseCOMObjects(_LMItemNote);
4684 ea80efaa gaqhf
                    }
4685 e27329d6 gaqhf
4686
                    TextCorrectModeling(text);
4687 ea80efaa gaqhf
                }
4688 e27329d6 gaqhf
            }
4689
            if (_LMSymbol != null)
4690
                ReleaseCOMObjects(_LMSymbol);
4691
        }
4692 ea80efaa gaqhf
4693 e27329d6 gaqhf
        private void AssociationTextModeling(Text text)
4694
        {
4695
            LMSymbol _LMSymbol = null;
4696
            LMConnector connectedLMConnector = null;
4697
            object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
4698
            if (owner != null && owner.GetType() == typeof(Symbol))
4699
            {
4700
                Symbol symbol = owner as Symbol;
4701
                _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
4702
                if (_LMSymbol != null)
4703
                {
4704
                    BaseModel.Attribute attribute = symbol.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
4705
                    if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
4706 7f00b26c gaqhf
                    {
4707 e27329d6 gaqhf
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
4708
4709
                        if (mapping != null)
4710 7f00b26c gaqhf
                        {
4711 e27329d6 gaqhf
                            double x = 0;
4712
                            double y = 0;
4713 7f00b26c gaqhf
4714 e27329d6 gaqhf
                            CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
4715
                            SPPIDUtil.ConvertGridPoint(ref x, ref y);
4716
                            Array array = new double[] { 0, x, y };
4717
                            text.SPPID.SPPID_X = x;
4718
                            text.SPPID.SPPID_Y = y;
4719
                            LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
4720
                            if (_LMLabelPersist != null)
4721 83c14a07 gaqhf
                            {
4722 e27329d6 gaqhf
                                text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id;
4723
                                _LMLabelPersist.Commit();
4724
                                ReleaseCOMObjects(_LMLabelPersist);
4725 7f00b26c gaqhf
                            }
4726
                        }
4727
                    }
4728 ea80efaa gaqhf
                }
4729 6b298450 gaqhf
            }
4730 e27329d6 gaqhf
            else if (owner != null && owner.GetType() == typeof(Line))
4731 6b298450 gaqhf
            {
4732 e27329d6 gaqhf
                Line line = owner as Line;
4733
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
4734
                connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y);
4735 1299077b gaqhf
4736 e27329d6 gaqhf
                if (connectedLMConnector != null)
4737 30ba9ae0 gaqhf
                {
4738 e27329d6 gaqhf
                    BaseModel.Attribute attribute = line.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
4739
                    if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
4740 30ba9ae0 gaqhf
                    {
4741 e27329d6 gaqhf
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
4742 30ba9ae0 gaqhf
4743 e27329d6 gaqhf
                        if (mapping != null)
4744
                        {
4745
                            double x = 0;
4746
                            double y = 0;
4747
                            CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
4748
                            SPPIDUtil.ConvertGridPoint(ref x, ref y);
4749
                            Array array = new double[] { 0, x, y };
4750 1299077b gaqhf
4751 e27329d6 gaqhf
                            LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
4752
                            if (_LMLabelPersist != null)
4753 1299077b gaqhf
                            {
4754 e27329d6 gaqhf
                                text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id;
4755
                                _LMLabelPersist.Commit();
4756
                                ReleaseCOMObjects(_LMLabelPersist);
4757 1299077b gaqhf
                            }
4758 30ba9ae0 gaqhf
                        }
4759
                    }
4760
                }
4761 6b298450 gaqhf
            }
4762 7f00b26c gaqhf
            if (_LMSymbol != null)
4763
                ReleaseCOMObjects(_LMSymbol);
4764 cfda1fed gaqhf
        }
4765
4766 e27329d6 gaqhf
        private void TextCorrectModeling(Text text)
4767 1299077b gaqhf
        {
4768 e27329d6 gaqhf
            if (text.SPPID.Range == null)
4769
                return;
4770
4771 1299077b gaqhf
            bool needRemodeling = false;
4772
            bool loop = true;
4773
            GridSetting gridSetting = GridSetting.GetInstance();
4774
            while (loop)
4775
            {
4776
                loop = false;
4777 e27329d6 gaqhf
                foreach (var overlapText in document.TEXTINFOS)
4778 1299077b gaqhf
                {
4779 e27329d6 gaqhf
                    if (overlapText.ASSOCIATION || overlapText == text || overlapText.SPPID.Range == null)
4780
                        continue;
4781
4782 1299077b gaqhf
                    if (SPPIDUtil.IsOverlap(overlapText.SPPID.Range, text.SPPID.Range))
4783
                    {
4784 e27329d6 gaqhf
                        double percentX = 0;
4785
                        double percentY = 0;
4786
                        if (overlapText.X1 <= text.X2 && overlapText.X2 >= text.X1)
4787
                        {
4788
                            double gapX = Math.Min(overlapText.X2, text.X2) - Math.Max(overlapText.X1, text.X1);
4789
                            percentX = Math.Max(gapX / (overlapText.X2 - overlapText.X1), gapX / (text.X2 - text.X1));
4790
                        }
4791
                        if (overlapText.Y1 <= text.Y2 && overlapText.Y2 >= text.Y1)
4792
                        {
4793
                            double gapY = Math.Min(overlapText.Y2, text.Y2) - Math.Max(overlapText.Y1, text.Y1);
4794
                            percentY = Math.Max(gapY / (overlapText.Y2 - overlapText.Y1), gapY / (text.Y2 - text.Y1));
4795
                        }
4796
4797 1299077b gaqhf
                        double tempX = 0;
4798
                        double tempY = 0;
4799
                        bool overlapX = false;
4800
                        bool overlapY = false;
4801
                        SPPIDUtil.CalcOverlap(text.SPPID.Range, overlapText.SPPID.Range, ref tempX, ref tempY, ref overlapX, ref overlapY);
4802 e27329d6 gaqhf
                        if (percentX >= percentY)
4803 1299077b gaqhf
                        {
4804
                            int count = Convert.ToInt32(tempY / gridSetting.Length) + 1;
4805
                            double move = gridSetting.Length * count;
4806
                            text.SPPID.SPPID_Y = text.SPPID.SPPID_Y - move;
4807
                            text.SPPID.Range = new double[] { text.SPPID.Range[0], text.SPPID.Range[1] - move, text.SPPID.Range[2], text.SPPID.Range[3] - move };
4808
                            needRemodeling = true;
4809
                            loop = true;
4810
                        }
4811 e27329d6 gaqhf
                        else
4812 1299077b gaqhf
                        {
4813
                            int count = Convert.ToInt32(tempX / gridSetting.Length) + 1;
4814
                            double move = gridSetting.Length * count;
4815
                            text.SPPID.SPPID_X = text.SPPID.SPPID_X + move;
4816
                            text.SPPID.Range = new double[] { text.SPPID.Range[0] + move, text.SPPID.Range[1], text.SPPID.Range[2] + move, text.SPPID.Range[3] };
4817
                            needRemodeling = true;
4818
                            loop = true;
4819
                        }
4820
                    }
4821
                }
4822
            }
4823
            
4824
4825
            if (needRemodeling)
4826
            {
4827
                LMSymbol symbol = dataSource.GetSymbol(text.SPPID.RepresentationId);
4828
                _placement.PIDRemovePlacement(symbol.AsLMRepresentation());
4829
                text.SPPID.RepresentationId = null;
4830
4831
                LMItemNote _LMItemNote = null;
4832
                LMAAttribute _LMAAttribute = null;
4833
                LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, text.SPPID.SPPID_X, text.SPPID.SPPID_Y, Rotation: text.ANGLE);
4834
                if (_LMSymbol != null)
4835
                {
4836
                    _LMSymbol.Commit();
4837
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
4838
                    if (_LMItemNote != null)
4839
                    {
4840
                        _LMItemNote.Commit();
4841
                        _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
4842
                        if (_LMAAttribute != null)
4843
                        {
4844
                            _LMAAttribute.set_Value(text.VALUE);
4845
                            text.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
4846
                            _LMItemNote.Commit();
4847
4848
                            ReleaseCOMObjects(_LMAAttribute);
4849
                            ReleaseCOMObjects(_LMItemNote);
4850
                        }
4851
                    }
4852
                }
4853
4854
                ReleaseCOMObjects(symbol);
4855
                symbol = null;
4856
                ReleaseCOMObjects(_LMItemNote);
4857
                _LMItemNote = null;
4858
                ReleaseCOMObjects(_LMAAttribute);
4859
                _LMAAttribute = null;
4860
                ReleaseCOMObjects(_LMSymbol);
4861
                _LMSymbol = null;
4862
            }
4863
        }
4864
4865 4e865771 gaqhf
        private void AssociationTextCorrectModeling(Text text, List<Text> endTexts)
4866
        {
4867
            if (!string.IsNullOrEmpty(text.SPPID.RepresentationId))
4868
            {
4869
                List<Text> texts = new List<Text>();
4870
                LMLabelPersist targetLabel = dataSource.GetLabelPersist(text.SPPID.RepresentationId);
4871
                LMRepresentation representation = targetLabel.RepresentationObject;
4872
                Symbol symbol = document.SYMBOLS.Find(x => x.SPPID.RepresentationId == representation.Id);
4873
                if (targetLabel.RepresentationObject != null && symbol != null)
4874
                {
4875
                    double[] symbolRange = null;
4876
                    GetSPPIDSymbolRange(symbol, ref symbolRange, true, true);
4877
                    if (symbolRange != null)
4878
                    {
4879
                        foreach (LMLabelPersist labelPersist in representation.LabelPersists)
4880
                        {
4881
                            Text findText = document.TEXTINFOS.Find(x => x.SPPID.RepresentationId == labelPersist.AsLMRepresentation().Id && x.ASSOCIATION);
4882
                            if (findText != null)
4883
                            {
4884
                                double[] range = null;
4885
                                GetSPPIDSymbolRange(labelPersist, ref range);
4886
                                findText.SPPID.Range = range;
4887
                                texts.Add(findText);
4888
                            }
4889
4890
                            ReleaseCOMObjects(labelPersist);
4891
                        }
4892
4893
                        if (texts.Count > 0)
4894
                        {
4895
                            #region Sort Text By Y
4896
                            texts.Sort(SortTextByY);
4897
                            int SortTextByY(Text a, Text b)
4898
                            {
4899
                                return b.SPPID.Range[3].CompareTo(a.SPPID.Range[3]);
4900
                            }
4901
                            #endregion
4902
4903
                            #region 첫번째 Text로 기준 맞춤
4904
                            for (int i = 0; i < texts.Count; i++)
4905
                            {
4906
                                if (i != 0)
4907
                                {
4908
                                    Text currentText = texts[i];
4909
                                    Text prevText = texts[i - 1];
4910
                                    double minY = prevText.SPPID.Range[1];
4911
                                    double centerPrevX = (prevText.SPPID.Range[0] + prevText.SPPID.Range[2]) / 2;
4912
                                    double centerX = (currentText.SPPID.Range[0] + currentText.SPPID.Range[2]) / 2;
4913
                                    double _gapX = centerX - centerPrevX;
4914
                                    double _gapY = currentText.SPPID.Range[3] - minY;
4915
                                    MoveText(currentText, _gapX, _gapY);
4916
                                }
4917
                            }
4918
                            List<double> rangeMinX = texts.Select(loopX => loopX.SPPID.Range[0]).ToList();
4919
                            List<double> rangeMinY = texts.Select(loopX => loopX.SPPID.Range[1]).ToList();
4920
                            List<double> rangeMaxX = texts.Select(loopX => loopX.SPPID.Range[2]).ToList();
4921
                            List<double> rangeMaxY = texts.Select(loopX => loopX.SPPID.Range[3]).ToList();
4922
                            rangeMinX.Sort();
4923
                            rangeMinY.Sort();
4924
                            rangeMaxX.Sort();
4925
                            rangeMaxY.Sort();
4926
                            double allTextCenterX = (rangeMinX[0] + rangeMaxX[rangeMaxX.Count - 1]) / 2;
4927
                            double allTextCenterY = (rangeMinY[0] + rangeMaxY[rangeMaxY.Count - 1]) / 2;
4928
                            #endregion
4929
4930
                            Text correctBySymbol = texts[0];
4931
                            double textCenterX = (text.X1 + text.X2) / 2;
4932
                            double textCenterY = (text.Y1 + text.Y2) / 2;
4933
                            double originX = 0;
4934
                            double originY = 0;
4935
                            SPPIDUtil.ConvertPointBystring(symbol.ORIGINALPOINT, ref originX, ref originY);
4936
                            double angle = SPPIDUtil.CalcAngle(textCenterX, textCenterY, originX, originY);
4937
                            double symbolCenterX = (symbolRange[0] + symbolRange[2]) / 2;
4938
                            double symbolCenterY = (symbolRange[1] + symbolRange[3]) / 2;
4939
4940
                            double gapX = 0;
4941
                            double gapY = 0;
4942
                            if (angle < 45)
4943
                            {
4944
                                // Text 오른쪽
4945
                                if (textCenterX > originX)
4946
                                {
4947
                                    gapX = rangeMinX[0] - symbolRange[2];
4948
                                    gapY = allTextCenterY - symbolCenterY;
4949
                                }
4950
                                // Text 왼쪽
4951
                                else
4952
                                {
4953
                                    gapX = rangeMaxX[rangeMaxX.Count - 1] - symbolRange[0];
4954
                                    gapY = allTextCenterY - symbolCenterY;
4955
                                }
4956
                            }
4957
                            else
4958
                            {
4959
                                // Text 아래쪽
4960
                                if (textCenterY > originY)
4961
                                {
4962
                                    gapX = allTextCenterX - symbolCenterX;
4963
                                    gapY = rangeMaxY[rangeMaxY.Count - 1] - symbolRange[1];
4964
                                }
4965
                                // Text 위쪽
4966
                                else
4967
                                {
4968
                                    gapX = allTextCenterX - symbolCenterX;
4969
                                    gapY = rangeMinY[0] - symbolRange[3];
4970
                                }
4971
                            }
4972
4973
                            foreach (var item in texts)
4974
                            {
4975
                                MoveText(item, gapX, gapY);
4976
                                RemodelingAssociationText(item);
4977
                            }
4978
                        }
4979
                    }
4980
                }
4981
4982
                void MoveText(Text moveText, double x, double y)
4983
                {
4984
                    moveText.SPPID.SPPID_X = moveText.SPPID.SPPID_X - x;
4985
                    moveText.SPPID.SPPID_Y = moveText.SPPID.SPPID_Y - y;
4986
                    moveText.SPPID.Range = new double[] {
4987
                        moveText.SPPID.Range[0] - x,
4988
                        moveText.SPPID.Range[1]- y,
4989
                        moveText.SPPID.Range[2]- x,
4990
                        moveText.SPPID.Range[3]- y
4991
                    };
4992
                }
4993
4994
                endTexts.AddRange(texts);
4995
4996
                ReleaseCOMObjects(targetLabel);
4997
                targetLabel = null;
4998
                ReleaseCOMObjects(representation);
4999
                representation = null;
5000
            }
5001
        }
5002
5003
        private void RemodelingAssociationText(Text text)
5004
        {
5005
            LMLabelPersist removeLabel = dataSource.GetLabelPersist(text.SPPID.RepresentationId);
5006
            _placement.PIDRemovePlacement(removeLabel.AsLMRepresentation());
5007
            removeLabel.Commit();
5008
            ReleaseCOMObjects(removeLabel);
5009
            removeLabel = null;
5010
5011
            object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
5012
            if (owner != null && owner.GetType() == typeof(Symbol))
5013
            {
5014
                Symbol symbol = owner as Symbol;
5015
                _LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
5016
                if (_LMSymbol != null)
5017
                {
5018
                    BaseModel.Attribute attribute = symbol.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
5019
                    if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
5020
                    {
5021
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
5022
5023
                        if (mapping != null)
5024
                        {
5025
                            double x = 0;
5026
                            double y = 0;
5027
5028
                            Array array = new double[] { 0, text.SPPID.SPPID_X, text.SPPID.SPPID_Y };
5029
                            LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
5030
                            if (_LMLabelPersist != null)
5031
                            {
5032
                                text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id;
5033
                                _LMLabelPersist.Commit();
5034
                            }
5035
                            ReleaseCOMObjects(_LMLabelPersist);
5036
                            _LMLabelPersist = null;
5037
                        }
5038
                    }
5039
                }
5040
                ReleaseCOMObjects(_LMSymbol);
5041
                _LMSymbol = null;
5042
            }
5043
        }
5044
5045 74752074 gaqhf
        /// <summary>
5046
        /// Note Modeling
5047
        /// </summary>
5048
        /// <param name="note"></param>
5049 1299077b gaqhf
        private void NoteModeling(Note note, List<Note> correctList)
5050 cfda1fed gaqhf
        {
5051 6b298450 gaqhf
            LMSymbol _LMSymbol = null;
5052
            LMItemNote _LMItemNote = null;
5053
            LMAAttribute _LMAAttribute = null;
5054
5055 7f00b26c gaqhf
            if (string.IsNullOrEmpty(note.OWNER) || note.OWNER == "None")
5056 6b298450 gaqhf
            {
5057 7f00b26c gaqhf
                double x = 0;
5058
                double y = 0;
5059 fc0a8c33 gaqhf
5060 7f00b26c gaqhf
                CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation);
5061 1299077b gaqhf
                SPPIDUtil.ConvertGridPoint(ref x, ref y);
5062
                note.SPPID.SPPID_X = x;
5063
                note.SPPID.SPPID_Y = y;
5064 fc0a8c33 gaqhf
5065 7f00b26c gaqhf
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y);
5066 30ba9ae0 gaqhf
                if (_LMSymbol != null)
5067
                {
5068
                    _LMSymbol.Commit();
5069
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
5070
                    if (_LMItemNote != null)
5071
                    {
5072
                        _LMItemNote.Commit();
5073
                        _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
5074
                        if (_LMAAttribute != null)
5075
                        {
5076
                            _LMAAttribute.set_Value(note.VALUE);
5077
                            note.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
5078 1299077b gaqhf
5079
                            double[] range = null;
5080
                            foreach (LMLabelPersist labelPersist in _LMSymbol.LabelPersists)
5081
                            {
5082
                                double[] temp = null;
5083
                                GetSPPIDSymbolRange(labelPersist, ref temp);
5084
                                if (temp != null)
5085
                                {
5086
                                    if (range == null)
5087
                                        range = temp;
5088
                                    else
5089
                                    {
5090
                                        range = new double[] {
5091
                                            Math.Min(range[0], temp[0]),
5092
                                            Math.Min(range[1], temp[1]),
5093
                                            Math.Max(range[2], temp[2]),
5094
                                            Math.Max(range[3], temp[3])
5095
                                        };
5096
                                    }
5097
                                }
5098
                            }
5099
                            if (range != null)
5100
                                correctList.Add(note);
5101
                            note.SPPID.Range = range;
5102
5103
5104 30ba9ae0 gaqhf
                            _LMItemNote.Commit();
5105
                        }
5106
                    }
5107
                }
5108 6b298450 gaqhf
            }
5109 cfda1fed gaqhf
5110 7f00b26c gaqhf
            if (_LMAAttribute != null)
5111
                ReleaseCOMObjects(_LMAAttribute);
5112
            if (_LMItemNote != null)
5113
                ReleaseCOMObjects(_LMItemNote);
5114
            if (_LMSymbol != null)
5115
                ReleaseCOMObjects(_LMSymbol);
5116 cfda1fed gaqhf
        }
5117
5118 1299077b gaqhf
        private void NoteCorrectModeling(Note note, List<Note> endList)
5119
        {
5120
            bool needRemodeling = false;
5121
            bool loop = true;
5122
            GridSetting gridSetting = GridSetting.GetInstance();
5123
            while (loop)
5124
            {
5125
                loop = false;
5126
                foreach (var overlap in endList)
5127
                {
5128 ba25c427 gaqhf
                    if (SPPIDUtil.IsOverlap(overlap.SPPID.Range, note.SPPID.Range))
5129 1299077b gaqhf
                    {
5130 ba25c427 gaqhf
                        double tempX = 0;
5131
                        double tempY = 0;
5132
                        bool overlapX = false;
5133
                        bool overlapY = false;
5134
                        SPPIDUtil.CalcOverlap(note.SPPID.Range, overlap.SPPID.Range, ref tempX, ref tempY, ref overlapX, ref overlapY);
5135
                        double angle = SPPIDUtil.CalcAngle(note.LOCATION_X, note.LOCATION_Y, overlap.LOCATION_X, overlap.LOCATION_Y);
5136
                        if (overlapY && angle >= 45)
5137 1299077b gaqhf
                        {
5138 ba25c427 gaqhf
                            int count = Convert.ToInt32(tempY / gridSetting.Length) + 1;
5139
                            double move = gridSetting.Length * count;
5140
                            note.SPPID.SPPID_Y = note.SPPID.SPPID_Y - move;
5141
                            note.SPPID.Range = new double[] { note.SPPID.Range[0], note.SPPID.Range[1] - move, note.SPPID.Range[2], note.SPPID.Range[3] - move };
5142
                            needRemodeling = true;
5143
                            loop = true;
5144
                        }
5145
                        if (overlapX && angle <= 45)
5146
                        {
5147
                            int count = Convert.ToInt32(tempX / gridSetting.Length) + 1;
5148
                            double move = gridSetting.Length * count;
5149
                            note.SPPID.SPPID_X = note.SPPID.SPPID_X + move;
5150
                            note.SPPID.Range = new double[] { note.SPPID.Range[0] + move, note.SPPID.Range[1], note.SPPID.Range[2] + move, note.SPPID.Range[3] };
5151
                            needRemodeling = true;
5152
                            loop = true;
5153 1299077b gaqhf
                        }
5154
                    }
5155
                }
5156
            }
5157
5158
5159
            if (needRemodeling)
5160
            {
5161
                LMSymbol symbol = dataSource.GetSymbol(note.SPPID.RepresentationId);
5162
                _placement.PIDRemovePlacement(symbol.AsLMRepresentation());
5163
                note.SPPID.RepresentationId = null;
5164
5165
                LMItemNote _LMItemNote = null;
5166
                LMAAttribute _LMAAttribute = null;
5167
                LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, note.SPPID.SPPID_X, note.SPPID.SPPID_Y, Rotation: note.ANGLE);
5168
                if (_LMSymbol != null)
5169
                {
5170
                    _LMSymbol.Commit();
5171
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
5172
                    if (_LMItemNote != null)
5173
                    {
5174
                        _LMItemNote.Commit();
5175
                        _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
5176
                        if (_LMAAttribute != null)
5177
                        {
5178
                            _LMAAttribute.set_Value(note.VALUE);
5179
                            note.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
5180
                            _LMItemNote.Commit();
5181
5182
                            ReleaseCOMObjects(_LMAAttribute);
5183
                            ReleaseCOMObjects(_LMItemNote);
5184
                        }
5185
                    }
5186
                }
5187
5188
                ReleaseCOMObjects(symbol);
5189
                symbol = null;
5190
                ReleaseCOMObjects(_LMItemNote);
5191
                _LMItemNote = null;
5192
                ReleaseCOMObjects(_LMAAttribute);
5193
                _LMAAttribute = null;
5194
                ReleaseCOMObjects(_LMSymbol);
5195
                _LMSymbol = null;
5196
            }
5197
5198
            endList.Add(note);
5199
        }
5200
5201 a31a512e gaqhf
        private void JoinRunBySameType(string modelItemId, ref string survivorId)
5202 ca6e0f51 gaqhf
        {
5203 a31a512e gaqhf
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
5204
            if (modelItem != null)
5205 ca6e0f51 gaqhf
            {
5206 a31a512e gaqhf
                foreach (LMRepresentation rep in modelItem.Representations)
5207
                {
5208
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
5209
                    {
5210
                        LMConnector connector = dataSource.GetConnector(rep.Id);
5211
                        if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch")
5212
                        {
5213
                            LMSymbol symbol = connector.ConnectItem1SymbolObject;
5214
                            List<string> modelItemIds = FindOtherModelItemBySymbolWhereTypePipeRun(symbol, modelItem.Id);
5215
                            if (modelItemIds.Count == 1)
5216
                            {
5217 d77973b3 gaqhf
                                string joinModelItemId = modelItemIds[0];
5218 63a112d9 gaqhf
                                JoinRun(joinModelItemId, modelItemId, ref survivorId, false);
5219 a31a512e gaqhf
                                if (survivorId != null)
5220
                                    break;
5221
                            }
5222
                        }
5223
                        if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch")
5224
                        {
5225
                            LMSymbol symbol = connector.ConnectItem2SymbolObject;
5226
                            List<string> modelItemIds = FindOtherModelItemBySymbolWhereTypePipeRun(symbol, modelItem.Id);
5227
                            if (modelItemIds.Count == 1)
5228
                            {
5229 d77973b3 gaqhf
                                string joinModelItemId = modelItemIds[0];
5230 63a112d9 gaqhf
                                JoinRun(joinModelItemId, modelItemId, ref survivorId, false);
5231 a31a512e gaqhf
                                if (survivorId != null)
5232
                                    break;
5233
                            }
5234
                        }
5235
                    }
5236
                }
5237 ca6e0f51 gaqhf
            }
5238 dec9ecfd gaqhf
        }
5239
5240 d9794a6c gaqhf
        /// <summary>
5241 74752074 gaqhf
        /// Label의 좌표를 구하는 메서드(ID2 기준의 좌표 -> SPPID 좌표)
5242
        /// </summary>
5243
        /// <param name="x"></param>
5244
        /// <param name="y"></param>
5245
        /// <param name="originX"></param>
5246
        /// <param name="originY"></param>
5247
        /// <param name="SPPIDLabelLocation"></param>
5248
        /// <param name="location"></param>
5249 b65a7e32 gaqhf
        private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location)
5250
        {
5251
            if (location == Location.None)
5252
            {
5253
                x = originX;
5254
                y = originY;
5255
            }
5256
            else
5257
            {
5258
                if (location.HasFlag(Location.Center))
5259
                {
5260
                    x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2;
5261
                    y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2;
5262
                }
5263
5264
                if (location.HasFlag(Location.Left))
5265
                    x = SPPIDLabelLocation.X1;
5266
                else if (location.HasFlag(Location.Right))
5267
                    x = SPPIDLabelLocation.X2;
5268
5269
                if (location.HasFlag(Location.Down))
5270
                    y = SPPIDLabelLocation.Y1;
5271
                else if (location.HasFlag(Location.Up))
5272
                    y = SPPIDLabelLocation.Y2;
5273
            }
5274
        }
5275 5a4b8f32 gaqhf
5276 74752074 gaqhf
        /// <summary>
5277 4d2571ab gaqhf
        /// Symbol의 우선순위 Modeling 목록을 가져온다.
5278
        /// 1. Angle Valve
5279
        /// 2. 3개로 이루어진 Symbol Group
5280
        /// </summary>
5281
        /// <returns></returns>
5282
        private List<Symbol> GetPrioritySymbol()
5283
        {
5284
            DataTable symbolTable = document.SymbolTable;
5285
            // List에 순서대로 쌓는다.
5286
            List<Symbol> symbols = new List<Symbol>();
5287 3734dcc5 gaqhf
5288 4d2571ab gaqhf
            // Angle Valve 부터
5289 d9794a6c gaqhf
            foreach (var symbol in document.SYMBOLS.FindAll(x => x.CONNECTORS.FindAll(y => y.Index == 0).Count == 2))
5290 4d2571ab gaqhf
            {
5291
                if (!symbols.Contains(symbol))
5292
                {
5293
                    double originX = 0;
5294
                    double originY = 0;
5295
5296
                    // ID2 Table에서 Original Point 가져옴.
5297 7f00b26c gaqhf
                    string OriginalPoint = symbolTable.Select(string.Format("UID = {0}", symbol.DBUID))[0]["OriginalPoint"].ToString();
5298 4d2571ab gaqhf
                    SPPIDUtil.ConvertPointBystring(OriginalPoint, ref originX, ref originY);
5299
5300
                    SlopeType slopeType1 = SlopeType.None;
5301
                    SlopeType slopeType2 = SlopeType.None;
5302 d9794a6c gaqhf
                    foreach (Connector connector in symbol.CONNECTORS.FindAll(x => x.Index == 0))
5303 4d2571ab gaqhf
                    {
5304
                        double connectorX = 0;
5305
                        double connectorY = 0;
5306
                        SPPIDUtil.ConvertPointBystring(connector.CONNECTPOINT, ref connectorX, ref connectorY);
5307
                        if (slopeType1 == SlopeType.None)
5308
                            slopeType1 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
5309
                        else
5310
                            slopeType2 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
5311
                    }
5312
5313
                    if ((slopeType1 == SlopeType.VERTICAL && slopeType2 == SlopeType.HORIZONTAL) ||
5314
                        (slopeType2 == SlopeType.VERTICAL && slopeType1 == SlopeType.HORIZONTAL))
5315
                        symbols.Add(symbol);
5316
                }
5317
            }
5318
5319 f1a7faf9 gaqhf
            List<Symbol> tempSymbols = new List<Symbol>();
5320
            // Conn 갯수 기준
5321 d9794a6c gaqhf
            foreach (var item in document.SYMBOLS)
5322
            {
5323 f1a7faf9 gaqhf
                if (!symbols.Contains(item))
5324
                    tempSymbols.Add(item);
5325 d9794a6c gaqhf
            }
5326 f1a7faf9 gaqhf
            tempSymbols.Sort(SortSymbolPriority);
5327
            symbols.AddRange(tempSymbols);
5328 4d2571ab gaqhf
5329
            return symbols;
5330
        }
5331
5332 cf210438 gaqhf
        private void SetPriorityLine(List<Line> lines)
5333 d63050d6 gaqhf
        {
5334 cf210438 gaqhf
            lines.Sort(SortLinePriority);
5335 d63050d6 gaqhf
5336
            int SortLinePriority(Line a, Line b)
5337
            {
5338
                // Branch 없는것부터
5339
                int branchRetval = CompareBranchLine(a, b);
5340
                if (branchRetval != 0)
5341
                {
5342
                    return branchRetval;
5343
                }
5344
                else
5345
                {
5346
                    // Symbol 연결 갯수
5347
                    int connSymbolRetval = CompareConnSymbol(a, b);
5348
                    if (connSymbolRetval != 0)
5349
                    {
5350
                        return connSymbolRetval;
5351
                    }
5352
                    else
5353
                    {
5354 24515a3a gaqhf
                        // 아이템 연결 갯수(심볼, Line이면서 Not Branch)
5355
                        int connItemRetval = CompareConnItem(a, b);
5356
                        if (connItemRetval != 0)
5357 d63050d6 gaqhf
                        {
5358 24515a3a gaqhf
                            return connItemRetval;
5359 d63050d6 gaqhf
                        }
5360
                        else
5361
                        {
5362 24515a3a gaqhf
                            // ConnectedItem이 없는것
5363
                            int noneConnRetval = CompareNoneConn(a, b);
5364
                            if (noneConnRetval != 0)
5365 d63050d6 gaqhf
                            {
5366 24515a3a gaqhf
                                return noneConnRetval;
5367 d63050d6 gaqhf
                            }
5368
                            else
5369
                            {
5370
5371
                            }
5372
                        }
5373
                    }
5374
                }
5375
5376
                return 0;
5377
            }
5378
5379 e283d483 gaqhf
            int CompareNotSegmentLine(Line a, Line b)
5380
            {
5381
                List<Connector> connectorsA = a.CONNECTORS
5382
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
5383
                    .ToList();
5384
5385
                List<Connector> connectorsB = b.CONNECTORS
5386
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
5387
                    .ToList();
5388
5389
                // 오름차순
5390
                return connectorsB.Count.CompareTo(connectorsA.Count);
5391
            }
5392
5393 d63050d6 gaqhf
            int CompareConnSymbol(Line a, Line b)
5394
            {
5395
                List<Connector> connectorsA = a.CONNECTORS
5396
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
5397
                    .ToList();
5398
5399
                List<Connector> connectorsB = b.CONNECTORS
5400
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
5401
                    .ToList();
5402
5403
                // 오름차순
5404
                return connectorsB.Count.CompareTo(connectorsA.Count);
5405
            }
5406
5407
            int CompareConnItem(Line a, Line b)
5408
            {
5409
                List<Connector> connectorsA = a.CONNECTORS
5410
                    .Where(conn => conn.ConnectedObject != null && 
5411
                    (conn.ConnectedObject.GetType() == typeof(Symbol) || 
5412
                    (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, a))))
5413
                    .ToList();
5414
5415
                List<Connector> connectorsB = b.CONNECTORS
5416
                    .Where(conn => conn.ConnectedObject != null &&
5417
                    (conn.ConnectedObject.GetType() == typeof(Symbol) ||
5418
                    (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, b))))
5419
                    .ToList();
5420
5421
                // 오름차순
5422
                return connectorsB.Count.CompareTo(connectorsA.Count);
5423
            }
5424
5425
            int CompareBranchLine(Line a, Line b)
5426
            {
5427
                List<Connector> connectorsA = a.CONNECTORS
5428
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(a, conn.ConnectedObject as Line))
5429
                    .ToList();
5430
                List<Connector> connectorsB = b.CONNECTORS
5431
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(b, conn.ConnectedObject as Line))
5432
                    .ToList();
5433
5434
                // 내림차순
5435
                return connectorsA.Count.CompareTo(connectorsB.Count);
5436
            }
5437
5438
            int CompareNoneConn(Line a, Line b)
5439
            {
5440
                List<Connector> connectorsA = a.CONNECTORS
5441
                    .Where(conn => conn.ConnectedObject == null)
5442
                    .ToList();
5443
5444
                List<Connector> connectorsB = b.CONNECTORS
5445
                    .Where(conn => conn.ConnectedObject == null)
5446
                    .ToList();
5447
5448
                // 오름차순
5449
                return connectorsB.Count.CompareTo(connectorsA.Count);
5450
            }
5451
        }
5452
5453 1299077b gaqhf
        private void SortText(List<Text> texts)
5454
        {
5455
            texts.Sort(Sort);
5456
5457
            int Sort(Text a, Text b)
5458
            {
5459
                int yRetval = CompareY(a, b);
5460
                if (yRetval != 0)
5461
                {
5462
                    return yRetval;
5463
                }
5464
                else
5465
                {
5466
                    return CompareX(a, b);
5467
                }
5468
            }
5469
5470
            int CompareY(Text a, Text b)
5471
            {
5472
                return a.LOCATION_Y.CompareTo(b.LOCATION_Y);
5473
            }
5474
5475
            int CompareX(Text a, Text b)
5476
            {
5477
                return a.LOCATION_X.CompareTo(b.LOCATION_X);
5478
            }
5479
        }
5480
        private void SortNote(List<Note> notes)
5481
        {
5482
            notes.Sort(Sort);
5483
5484
            int Sort(Note a, Note b)
5485
            {
5486
                int yRetval = CompareY(a, b);
5487
                if (yRetval != 0)
5488
                {
5489
                    return yRetval;
5490
                }
5491
                else
5492
                {
5493
                    return CompareX(a, b);
5494
                }
5495
            }
5496
5497
            int CompareY(Note a, Note b)
5498
            {
5499
                return a.LOCATION_Y.CompareTo(b.LOCATION_Y);
5500
            }
5501
5502
            int CompareX(Note a, Note b)
5503
            {
5504
                return a.LOCATION_X.CompareTo(b.LOCATION_X);
5505
            }
5506
        }
5507
5508 a0e3dca4 gaqhf
        private void SortBranchLines()
5509
        {
5510 f3e2693f gaqhf
            BranchLines.Sort(SortBranchLine);
5511 a0e3dca4 gaqhf
            int SortBranchLine(Line a, Line b)
5512
            {
5513
                int countA = a.CONNECTORS.FindAll(x => x.ConnectedObject != null &&
5514
                 x.ConnectedObject.GetType() == typeof(Line) &&
5515
                 SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, a) &&
5516
                 string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count;
5517
5518
                int countB = b.CONNECTORS.FindAll(x => x.ConnectedObject != null &&
5519
                 x.ConnectedObject.GetType() == typeof(Line) &&
5520
                 SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, b) &&
5521
                 string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count;
5522
5523
                // 내림차순
5524
                return countA.CompareTo(countB);
5525
            }
5526
        }
5527
5528 f1a7faf9 gaqhf
        private static int SortSymbolPriority(Symbol a, Symbol b)
5529
        {
5530
            int countA = a.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count;
5531
            int countB = b.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count;
5532
            int retval = countB.CompareTo(countA);
5533
            if (retval != 0)
5534
                return retval;
5535
            else
5536
                return a.SPPID.ORIGINAL_X.CompareTo(b.SPPID.ORIGINAL_X);
5537
        }
5538
5539 a31a512e gaqhf
        private string GetSPPIDFileName(LMModelItem modelItem)
5540
        {
5541
            string symbolPath = null;
5542
            foreach (LMRepresentation rep in modelItem.Representations)
5543
            {
5544
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
5545
                {
5546
                    symbolPath = rep.get_FileName();
5547
                    break;
5548
                }
5549
            }
5550
            return symbolPath;
5551
        }
5552
5553 82d6e5ea gaqhf
        private string GetSPPIDFileName(string modelItemId)
5554
        {
5555
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
5556
            string symbolPath = null;
5557
            foreach (LMRepresentation rep in modelItem.Representations)
5558
            {
5559
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
5560
                {
5561
                    symbolPath = rep.get_FileName();
5562
                    break;
5563
                }
5564
            }
5565
            ReleaseCOMObjects(modelItem);
5566
            return symbolPath;
5567
        }
5568
5569 4d2571ab gaqhf
        /// <summary>
5570 b2d1c1aa gaqhf
        /// Graphic OID로 해당 Symbol의 크기를 구하여 Zoom
5571
        /// </summary>
5572
        /// <param name="graphicOID"></param>
5573
        /// <param name="milliseconds"></param>
5574
        private void ZoomObjectByGraphicOID(string graphicOID, int milliseconds = 150)
5575
        {
5576
            if (radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] != null)
5577
            {
5578
                double minX = 0;
5579
                double minY = 0;
5580
                double maxX = 0;
5581
                double maxY = 0;
5582
                radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID].Range(out minX, out minY, out maxX, out maxY);
5583
                radApp.ActiveWindow.ZoomArea2(minX - 0.007, minY - 0.007, maxX + 0.007, maxY + 0.007, null);
5584
5585
                Thread.Sleep(milliseconds);
5586
            }
5587
        }
5588
5589
        /// <summary>
5590 74752074 gaqhf
        /// ComObject를 Release
5591
        /// </summary>
5592
        /// <param name="objVars"></param>
5593 5a4b8f32 gaqhf
        public void ReleaseCOMObjects(params object[] objVars)
5594
        {
5595 02a45794 gaqhf
            if (objVars != null)
5596 5a4b8f32 gaqhf
            {
5597 02a45794 gaqhf
                int intNewRefCount = 0;
5598
                foreach (object obj in objVars)
5599
                {
5600
                    if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
5601
                        intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
5602
                }
5603 5a4b8f32 gaqhf
            }
5604
        }
5605 5a9396ae humkyung
5606
        /// IDisposable 구현
5607
        ~AutoModeling()
5608
        {
5609
            this.Dispose(false);
5610
        }
5611
5612
        private bool disposed;
5613
        public void Dispose()
5614
        {
5615
            this.Dispose(true);
5616
            GC.SuppressFinalize(this);
5617
        }
5618
5619
        protected virtual void Dispose(bool disposing)
5620
        {
5621
            if (this.disposed) return;
5622
            if (disposing)
5623
            {
5624
                // IDisposable 인터페이스를 구현하는 멤버들을 여기서 정리합니다.
5625
            }
5626
            // .NET Framework에 의하여 관리되지 않는 외부 리소스들을 여기서 정리합니다.
5627
            this.disposed = true;
5628
        }
5629 cfda1fed gaqhf
    }
5630
}
클립보드 이미지 추가 (최대 크기: 500 MB)