프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ e302a79f

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