프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 919bb48e

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