프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ c16dd916

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