프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 0b885fb1

이력 | 보기 | 이력해설 | 다운로드 (320 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 0b885fb1 Denny
                // item2가 item1으로 조인
4178
                _placement.PIDJoinRuns(ref item1, ref item2);
4179
                item1.Commit();
4180
                item2.Commit();
4181
4182 ca6e0f51 gaqhf
                string beforeID = string.Empty;
4183
                string afterID = string.Empty;
4184 335b7a24 gaqhf
4185 4d4dce52 esham21
                if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() != "Active")
4186 ca6e0f51 gaqhf
                {
4187
                    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
                    beforeID = modelItem1.Id;
4194
                    afterID = modelItem2.Id;
4195 a31a512e gaqhf
                    survivorId = afterID;
4196 ca6e0f51 gaqhf
                }
4197 4d4dce52 esham21
                else if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() == "Active")
4198 7e680366 gaqhf
                {
4199
                    int model1Cnt = GetConnectorCount(modelId1);
4200
                    int model2Cnt = GetConnectorCount(modelId2);
4201
                    if (model1Cnt == 0)
4202
                    {
4203
                        beforeID = modelItem1.Id;
4204
                        afterID = modelItem2.Id;
4205
                        survivorId = afterID;
4206
                    }
4207
                    else if (model2Cnt == 0)
4208
                    {
4209
                        beforeID = modelItem2.Id;
4210
                        afterID = modelItem1.Id;
4211
                        survivorId = afterID;
4212
                    }
4213
                    else
4214
                        survivorId = null;
4215
                }
4216 ca6e0f51 gaqhf
                else
4217
                {
4218 a31a512e gaqhf
                    Log.Write("잘못된 경우");
4219
                    survivorId = null;
4220 ca6e0f51 gaqhf
                }
4221 87f02fc0 gaqhf
4222 ca6e0f51 gaqhf
                if (!string.IsNullOrEmpty(beforeID) && !string.IsNullOrEmpty(afterID))
4223 7f00b26c gaqhf
                {
4224 ca6e0f51 gaqhf
                    List<Line> lines = SPPIDUtil.FindLinesByModelId(document, beforeID);
4225 7f00b26c gaqhf
                    foreach (var line in lines)
4226 ca6e0f51 gaqhf
                        line.SPPID.ModelItemId = afterID;
4227 65a1ed4b gaqhf
                }
4228 7f00b26c gaqhf
4229 ca6e0f51 gaqhf
                ReleaseCOMObjects(modelItem1);
4230
                ReleaseCOMObjects(item1);
4231
                ReleaseCOMObjects(modelItem2);
4232
                ReleaseCOMObjects(item2);
4233
            }
4234
            catch (Exception ex)
4235 335b7a24 gaqhf
            {
4236 ca6e0f51 gaqhf
                Log.Write("Join Error");
4237 63a112d9 gaqhf
                Log.Write(ex.Message + "\r\n" + ex.StackTrace);
4238 335b7a24 gaqhf
            }
4239
        }
4240
4241 2b8c256c gaqhf
        private bool IsModelingEndBreak(Symbol symbol1, Symbol symbol2)
4242
        {
4243
            bool result = false;
4244
            List<EndBreak> endBreaks = document.EndBreaks.FindAll(x =>
4245
           (x.OWNER == symbol1.UID || x.OWNER == symbol2.UID) &&
4246
           (x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol1.UID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol2.UID));
4247
4248
            foreach (var item in endBreaks)
4249
            {
4250
                if (!string.IsNullOrEmpty(item.SPPID.RepresentationId))
4251
                {
4252
                    result = true;
4253
                    break;
4254
                }
4255
            }
4256
4257
            return result;
4258
        }
4259 a31a512e gaqhf
        private List<string> FindOtherModelItemBySymbolWhereTypePipeRun(LMSymbol symbol, string modelId)
4260
        {
4261 fae4f386 gaqhf
            List<string> temp = new List<string>();
4262
            List<LMConnector> connectors = new List<LMConnector>();
4263 48fd75e2 gaqhf
            foreach (LMConnector connector in symbol.Avoid1Connectors)
4264 a31a512e gaqhf
            {
4265 4d4dce52 esham21
                if (connector.get_ItemStatus() != "Active")
4266 fae4f386 gaqhf
                    continue;
4267
4268 a31a512e gaqhf
                LMModelItem modelItem = connector.ModelItemObject;
4269 fae4f386 gaqhf
                LMSymbol connOtherSymbol = FindOtherConnectedSymbol(connector);
4270 4d4dce52 esham21
                if (modelItem.get_ItemStatus() == "Active" && modelItem.get_ItemTypeName().ToString() == "PipeRun" && modelItem.Id != modelId && !temp.Contains(modelItem.Id))
4271 fae4f386 gaqhf
                    temp.Add(modelItem.Id);
4272
4273
                if (temp.Contains(modelItem.Id) &&
4274
                    connOtherSymbol != null &&
4275 4d4dce52 esham21
                    connOtherSymbol.get_RepresentationType() == "Branch" &&
4276
                    Convert.ToBoolean(connector.get_IsZeroLength()))
4277 fae4f386 gaqhf
                    temp.Remove(modelItem.Id);
4278
4279
4280
                if (temp.Contains(modelItem.Id))
4281
                    connectors.Add(connector);
4282
                ReleaseCOMObjects(connOtherSymbol);
4283
                connOtherSymbol = null;
4284 a31a512e gaqhf
                ReleaseCOMObjects(modelItem);
4285 fae4f386 gaqhf
                modelItem = null;
4286 a31a512e gaqhf
            }
4287
4288 48fd75e2 gaqhf
            foreach (LMConnector connector in symbol.Avoid2Connectors)
4289 a31a512e gaqhf
            {
4290 4d4dce52 esham21
                if (connector.get_ItemStatus() != "Active")
4291 fae4f386 gaqhf
                    continue;
4292
4293 a31a512e gaqhf
                LMModelItem modelItem = connector.ModelItemObject;
4294 fae4f386 gaqhf
                LMSymbol connOtherSymbol = FindOtherConnectedSymbol(connector);
4295 4d4dce52 esham21
                if (modelItem.get_ItemStatus() == "Active" && modelItem.get_ItemTypeName().ToString() == "PipeRun" && modelItem.Id != modelId && !temp.Contains(modelItem.Id))
4296 fae4f386 gaqhf
                    temp.Add(modelItem.Id);
4297
4298
                if (temp.Contains(modelItem.Id) &&
4299
                    connOtherSymbol != null &&
4300 4d4dce52 esham21
                    connOtherSymbol.get_RepresentationType() == "Branch" &&
4301
                    Convert.ToBoolean(connector.get_IsZeroLength()))
4302 fae4f386 gaqhf
                    temp.Remove(modelItem.Id);
4303
4304
                if (temp.Contains(modelItem.Id))
4305
                    connectors.Add(connector);
4306
                ReleaseCOMObjects(connOtherSymbol);
4307
                connOtherSymbol = null;
4308 a31a512e gaqhf
                ReleaseCOMObjects(modelItem);
4309 fae4f386 gaqhf
                modelItem = null;
4310 a31a512e gaqhf
            }
4311
4312 48fd75e2 gaqhf
4313 82d6e5ea gaqhf
            List<string> result = new List<string>();
4314
            string originalName = GetSPPIDFileName(modelId);
4315 fae4f386 gaqhf
            foreach (var connector in connectors)
4316 82d6e5ea gaqhf
            {
4317 4d4dce52 esham21
                string fileName = GetSPPIDFileName(connector.ModelItemID);
4318 82d6e5ea gaqhf
                if (originalName == fileName)
4319 4d4dce52 esham21
                    result.Add(connector.ModelItemID);
4320 82d6e5ea gaqhf
                else
4321
                {
4322 4d4dce52 esham21
                    if (document.LINES.Find(x => x.SPPID.ModelItemId == connector.ModelItemID) == null && Convert.ToBoolean(connector.get_IsZeroLength()))
4323
                        result.Add(connector.ModelItemID);
4324 fae4f386 gaqhf
                    else
4325 82d6e5ea gaqhf
                    {
4326 fae4f386 gaqhf
                        Line line1 = document.LINES.Find(x => x.SPPID.ModelItemId == modelId);
4327
                        Line line2 = document.LINES.Find(x => x.SPPID.ModelItemId == connector.ModelItemID.ToString());
4328
                        if (line1 != null && line2 != null && line1.TYPE == line2.TYPE)
4329 4d4dce52 esham21
                            result.Add(connector.ModelItemID);
4330 82d6e5ea gaqhf
                    }
4331
                }
4332
            }
4333 154d8f43 gaqhf
4334 fae4f386 gaqhf
            foreach (var connector in connectors)
4335 154d8f43 gaqhf
                ReleaseCOMObjects(connector);
4336 2e69e97c gaqhf
4337 82d6e5ea gaqhf
            return result;
4338 fae4f386 gaqhf
4339
4340
            LMSymbol FindOtherConnectedSymbol(LMConnector connector)
4341
            {
4342
                LMSymbol findResult = null;
4343 4d4dce52 esham21
                if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.Id != symbol.Id && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active")
4344 fae4f386 gaqhf
                    findResult = connector.ConnectItem1SymbolObject;
4345 4d4dce52 esham21
                else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.Id != symbol.Id && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active")
4346 fae4f386 gaqhf
                    findResult = connector.ConnectItem2SymbolObject;
4347
4348
                return findResult;
4349
            }
4350 a31a512e gaqhf
        }
4351
4352 74752074 gaqhf
        /// <summary>
4353
        /// PipeRun의 좌표를 가져오는 메서드
4354
        /// </summary>
4355
        /// <param name="modelId"></param>
4356
        /// <returns></returns>
4357 44087b23 gaqhf
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId, bool ContainZeroLength = true)
4358 5e6ecf05 gaqhf
        {
4359
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
4360 310aeb31 gaqhf
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
4361
4362
            if (modelItem != null)
4363 5e6ecf05 gaqhf
            {
4364 310aeb31 gaqhf
                foreach (LMRepresentation rep in modelItem.Representations)
4365 5e6ecf05 gaqhf
                {
4366 4d4dce52 esham21
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
4367 5e6ecf05 gaqhf
                    {
4368
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
4369 4d4dce52 esham21
                        if (!ContainZeroLength && Convert.ToBoolean(_LMConnector.get_IsZeroLength()))
4370 44087b23 gaqhf
                        {
4371
                            ReleaseCOMObjects(_LMConnector);
4372
                            _LMConnector = null;
4373
                            continue;
4374
                        }
4375 5e6ecf05 gaqhf
                        connectorVertices.Add(_LMConnector, new List<double[]>());
4376 4d4dce52 esham21
                        dynamic OID = rep.get_GraphicOID().ToString();
4377
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
4378 5e6ecf05 gaqhf
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
4379
                        int verticesCount = lineStringGeometry.VertexCount;
4380
                        double[] vertices = null;
4381
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
4382
                        for (int i = 0; i < verticesCount; i++)
4383
                        {
4384
                            double x = 0;
4385
                            double y = 0;
4386 4d4dce52 esham21
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
4387 32205389 gaqhf
                            connectorVertices[_LMConnector].Add(new double[] { x, y });
4388 5e6ecf05 gaqhf
                        }
4389
                    }
4390
                }
4391
4392 310aeb31 gaqhf
                ReleaseCOMObjects(modelItem);
4393 5e6ecf05 gaqhf
            }
4394
4395
            return connectorVertices;
4396
        }
4397
4398 32205389 gaqhf
        private List<double[]> GetConnectorVertices(LMConnector connector)
4399
        {
4400
            List<double[]> vertices = new List<double[]>();
4401 02a45794 gaqhf
            if (connector != null)
4402 32205389 gaqhf
            {
4403 4d4dce52 esham21
                dynamic OID = connector.get_GraphicOID().ToString();
4404
                DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
4405 b85669d8 Denny
                if (drawingObject != null)
4406 02a45794 gaqhf
                {
4407 b85669d8 Denny
                    Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
4408
                    int verticesCount = lineStringGeometry.VertexCount;
4409
                    double[] value = null;
4410
                    lineStringGeometry.GetVertices(ref verticesCount, ref value);
4411
                    for (int i = 0; i < verticesCount; i++)
4412
                    {
4413
                        double x = 0;
4414
                        double y = 0;
4415
                        lineStringGeometry.GetVertex(i + 1, ref x, ref y);
4416
                        vertices.Add(new double[] { x, y });
4417
                    }
4418 02a45794 gaqhf
                }
4419 32205389 gaqhf
            }
4420
            return vertices;
4421
        }
4422
4423 b2064e69 gaqhf
        private double GetConnectorDistance(LMConnector connector)
4424
        {
4425
            double result = 0;
4426
            List<double[]> vertices = new List<double[]>();
4427
            if (connector != null)
4428
            {
4429 4d4dce52 esham21
                dynamic OID = connector.get_GraphicOID().ToString();
4430
                DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
4431 b2064e69 gaqhf
                Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
4432
                int verticesCount = lineStringGeometry.VertexCount;
4433
                double[] value = null;
4434
                lineStringGeometry.GetVertices(ref verticesCount, ref value);
4435
                for (int i = 0; i < verticesCount; i++)
4436
                {
4437
                    double x = 0;
4438
                    double y = 0;
4439
                    lineStringGeometry.GetVertex(i + 1, ref x, ref y);
4440
                    vertices.Add(new double[] { x, y });
4441
                    if (vertices.Count > 1)
4442
                    {
4443
                        result += SPPIDUtil.CalcPointToPointdDistance(vertices[vertices.Count - 2][0], vertices[vertices.Count - 2][1], x, y);
4444
                    }
4445
                }
4446
            }
4447
            return result;
4448
        }
4449 f676f99a gaqhf
        private double[] GetConnectorRange(LMConnector connector)
4450
        {
4451
            double[] result = null;
4452
            List<double[]> vertices = new List<double[]>();
4453
            if (connector != null)
4454
            {
4455 4d4dce52 esham21
                dynamic OID = connector.get_GraphicOID().ToString();
4456
                DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
4457 f676f99a gaqhf
                double minX = 0;
4458
                double minY = 0;
4459
                double maxX = 0;
4460
                double maxY = 0;
4461
4462
                drawingObject.Range(out minX, out minY, out maxX, out maxY);
4463
                result = new double[] { minX, minY, maxX, maxY };
4464
            }
4465
            return result;
4466
        }
4467 63a112d9 gaqhf
        private List<double[]> GetConnectorVertices(dynamic graphicOID)
4468
        {
4469
            List<double[]> vertices = null;
4470 4d4dce52 esham21
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID];
4471 63a112d9 gaqhf
            if (drawingObject != null)
4472
            {
4473
                vertices = new List<double[]>();
4474
                Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
4475
                int verticesCount = lineStringGeometry.VertexCount;
4476
                double[] value = null;
4477
                lineStringGeometry.GetVertices(ref verticesCount, ref value);
4478
                for (int i = 0; i < verticesCount; i++)
4479
                {
4480
                    double x = 0;
4481
                    double y = 0;
4482
                    lineStringGeometry.GetVertex(i + 1, ref x, ref y);
4483
                    vertices.Add(new double[] { x, y });
4484
                }
4485
            }
4486
            return vertices;
4487
        }
4488 7c7bcd10 gaqhf
        /// <summary>
4489 a0e3dca4 gaqhf
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식
4490 74752074 gaqhf
        /// </summary>
4491
        /// <param name="connectorVertices"></param>
4492
        /// <param name="connX"></param>
4493
        /// <param name="connY"></param>
4494
        /// <returns></returns>
4495 a0e3dca4 gaqhf
        private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
4496 5e6ecf05 gaqhf
        {
4497
            double length = double.MaxValue;
4498
            LMConnector targetConnector = null;
4499
            foreach (var item in connectorVertices)
4500
            {
4501
                List<double[]> points = item.Value;
4502
                for (int i = 0; i < points.Count - 1; i++)
4503
                {
4504
                    double[] point1 = points[i];
4505
                    double[] point2 = points[i + 1];
4506 a0e3dca4 gaqhf
                    double x1 = Math.Min(point1[0], point2[0]);
4507
                    double y1 = Math.Min(point1[1], point2[1]);
4508
                    double x2 = Math.Max(point1[0], point2[0]);
4509
                    double y2 = Math.Max(point1[1], point2[1]);
4510 5e6ecf05 gaqhf
4511 a0e3dca4 gaqhf
                    if ((x1 <= connX && x2 >= connX) ||
4512
                        (y1 <= connY && y2 >= connY))
4513 5e6ecf05 gaqhf
                    {
4514 a0e3dca4 gaqhf
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY);
4515 335b7a24 gaqhf
                        if (length >= distance)
4516 30a9ffce gaqhf
                        {
4517 a0e3dca4 gaqhf
                            targetConnector = item.Key;
4518
                            length = distance;
4519
                        }
4520
4521
                        distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY);
4522
                        if (length >= distance)
4523
                        {
4524
                            targetConnector = item.Key;
4525
                            length = distance;
4526 30a9ffce gaqhf
                        }
4527 5e6ecf05 gaqhf
                    }
4528
                }
4529 c3d2e266 gaqhf
            }
4530
4531 a0e3dca4 gaqhf
            // 못찾았을때.
4532
            length = double.MaxValue;
4533 c3d2e266 gaqhf
            if (targetConnector == null)
4534
            {
4535
                foreach (var item in connectorVertices)
4536
                {
4537
                    List<double[]> points = item.Value;
4538 a0e3dca4 gaqhf
4539
                    foreach (double[] point in points)
4540 c3d2e266 gaqhf
                    {
4541 a0e3dca4 gaqhf
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
4542 c3d2e266 gaqhf
                        if (length >= distance)
4543
                        {
4544
                            targetConnector = item.Key;
4545
                            length = distance;
4546
                        }
4547
                    }
4548
                }
4549 5e6ecf05 gaqhf
            }
4550
4551
            return targetConnector;
4552
        }
4553
4554 a0e3dca4 gaqhf
        private LMConnector FindTargetLMConnectorForBranch(Line line, Line targetLine, ref double x, ref double y)
4555 ac78b508 gaqhf
        {
4556 a0e3dca4 gaqhf
            Dictionary<LMConnector, List<double[]>> vertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId);
4557 0ff6e67f gaqhf
            if (vertices.Count == 0)
4558
                return null;
4559 a0e3dca4 gaqhf
4560 ac78b508 gaqhf
            double length = double.MaxValue;
4561
            LMConnector targetConnector = null;
4562 a0e3dca4 gaqhf
            double[] resultPoint = null;
4563
            List<double[]> targetVertices = null;
4564
4565
            // Vertices 포인트에 제일 가까운곳
4566
            foreach (var item in vertices)
4567 ac78b508 gaqhf
            {
4568
                List<double[]> points = item.Value;
4569 a0e3dca4 gaqhf
                for (int i = 0; i < points.Count; i++)
4570 ac78b508 gaqhf
                {
4571 a0e3dca4 gaqhf
                    double[] point = points[i];
4572
                    double tempX = point[0];
4573
                    double tempY = point[1];
4574
4575
                    double distance = SPPIDUtil.CalcPointToPointdDistance(tempX, tempY, x, y);
4576 ac78b508 gaqhf
                    if (length >= distance)
4577
                    {
4578
                        targetConnector = item.Key;
4579
                        length = distance;
4580 a0e3dca4 gaqhf
                        resultPoint = point;
4581
                        targetVertices = item.Value;
4582 ac78b508 gaqhf
                    }
4583
                }
4584
            }
4585
4586 a0e3dca4 gaqhf
            // Vertices Cross에 제일 가까운곳
4587
            foreach (var item in vertices)
4588 68464385 gaqhf
            {
4589
                List<double[]> points = item.Value;
4590
                for (int i = 0; i < points.Count - 1; i++)
4591
                {
4592
                    double[] point1 = points[i];
4593
                    double[] point2 = points[i + 1];
4594
4595 a0e3dca4 gaqhf
                    double maxLineX = Math.Max(point1[0], point2[0]);
4596
                    double minLineX = Math.Min(point1[0], point2[0]);
4597
                    double maxLineY = Math.Max(point1[1], point2[1]);
4598
                    double minLineY = Math.Min(point1[1], point2[1]);
4599 68464385 gaqhf
4600 a0e3dca4 gaqhf
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
4601
4602
                    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]);
4603
                    if (crossingPoint != null)
4604
                    {
4605
                        double distance = SPPIDUtil.CalcPointToPointdDistance(crossingPoint[0], crossingPoint[1], x, y);
4606 68464385 gaqhf
                        if (length >= distance)
4607
                        {
4608 a0e3dca4 gaqhf
                            if (slope == SlopeType.Slope &&
4609
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
4610
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
4611
                            {
4612
                                targetConnector = item.Key;
4613
                                length = distance;
4614
                                resultPoint = crossingPoint;
4615
                                targetVertices = item.Value;
4616
                            }
4617
                            else if (slope == SlopeType.HORIZONTAL &&
4618
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
4619
                            {
4620
                                targetConnector = item.Key;
4621
                                length = distance;
4622
                                resultPoint = crossingPoint;
4623
                                targetVertices = item.Value;
4624
                            }
4625
                            else if (slope == SlopeType.VERTICAL &&
4626
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
4627
                            {
4628
                                targetConnector = item.Key;
4629
                                length = distance;
4630
                                resultPoint = crossingPoint;
4631
                                targetVertices = item.Value;
4632
                            }
4633 68464385 gaqhf
                        }
4634
                    }
4635
                }
4636
            }
4637
4638 a0e3dca4 gaqhf
            foreach (var item in vertices)
4639
                if (item.Key != null && item.Key != targetConnector)
4640
                    ReleaseCOMObjects(item.Key);
4641
4642
            if (SPPIDUtil.IsBranchLine(line, targetLine))
4643 68464385 gaqhf
            {
4644 a0e3dca4 gaqhf
                double tempResultX = resultPoint[0];
4645
                double tempResultY = resultPoint[1];
4646
                SPPIDUtil.ConvertGridPoint(ref tempResultX, ref tempResultY);
4647 68464385 gaqhf
4648 a0e3dca4 gaqhf
                GridSetting gridSetting = GridSetting.GetInstance();
4649
4650
                for (int i = 0; i < targetVertices.Count; i++)
4651
                {
4652
                    double[] point = targetVertices[i];
4653
                    double tempX = targetVertices[i][0];
4654
                    double tempY = targetVertices[i][1];
4655
                    SPPIDUtil.ConvertGridPoint(ref tempX, ref tempY);
4656
                    if (tempX == tempResultX && tempY == tempResultY)
4657 68464385 gaqhf
                    {
4658 a0e3dca4 gaqhf
                        if (i == 0)
4659 68464385 gaqhf
                        {
4660 a0e3dca4 gaqhf
                            LMSymbol connSymbol = targetConnector.ConnectItem1SymbolObject;
4661 b01e7456 gaqhf
                            bool containZeroLength = false;
4662
                            if (connSymbol != null)
4663 a0e3dca4 gaqhf
                            {
4664 1805d3b7 gaqhf
                                foreach (LMConnector connector in connSymbol.Connect1Connectors)
4665
                                {
4666 4d4dce52 esham21
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
4667 1805d3b7 gaqhf
                                        containZeroLength = true;
4668
                                }
4669
                                foreach (LMConnector connector in connSymbol.Connect2Connectors)
4670 a0e3dca4 gaqhf
                                {
4671 4d4dce52 esham21
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
4672 1805d3b7 gaqhf
                                        containZeroLength = true;
4673 a0e3dca4 gaqhf
                                }
4674 b01e7456 gaqhf
                            }
4675
4676
                            if (connSymbol == null ||
4677 4d4dce52 esham21
                                (connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") ||
4678 b01e7456 gaqhf
                                containZeroLength)
4679
                            {
4680
                                bool bCalcX = false;
4681
                                bool bCalcY = false;
4682
                                if (targetLine.SlopeType == SlopeType.HORIZONTAL)
4683
                                    bCalcX = true;
4684
                                else if (targetLine.SlopeType == SlopeType.VERTICAL)
4685
                                    bCalcY = true;
4686
                                else
4687
                                {
4688
                                    bCalcX = true;
4689
                                    bCalcY = true;
4690
                                }
4691 a0e3dca4 gaqhf
4692 b01e7456 gaqhf
                                if (bCalcX)
4693 a0e3dca4 gaqhf
                                {
4694 b01e7456 gaqhf
                                    double nextX = targetVertices[i + 1][0];
4695
                                    double newX = 0;
4696
                                    if (nextX > tempX)
4697
                                    {
4698
                                        newX = tempX + gridSetting.Length;
4699
                                        if (newX > nextX)
4700
                                            newX = (point[0] + nextX) / 2;
4701
                                    }
4702 a0e3dca4 gaqhf
                                    else
4703
                                    {
4704 b01e7456 gaqhf
                                        newX = tempX - gridSetting.Length;
4705
                                        if (newX < nextX)
4706
                                            newX = (point[0] + nextX) / 2;
4707 a0e3dca4 gaqhf
                                    }
4708 b01e7456 gaqhf
                                    resultPoint = new double[] { newX, resultPoint[1] };
4709
                                }
4710 a0e3dca4 gaqhf
4711 b01e7456 gaqhf
                                if (bCalcY)
4712
                                {
4713
                                    double nextY = targetVertices[i + 1][1];
4714
                                    double newY = 0;
4715
                                    if (nextY > tempY)
4716 a0e3dca4 gaqhf
                                    {
4717 b01e7456 gaqhf
                                        newY = tempY + gridSetting.Length;
4718
                                        if (newY > nextY)
4719
                                            newY = (point[1] + nextY) / 2;
4720 a0e3dca4 gaqhf
                                    }
4721 b01e7456 gaqhf
                                    else
4722 a0e3dca4 gaqhf
                                    {
4723 b01e7456 gaqhf
                                        newY = tempY - gridSetting.Length;
4724
                                        if (newY < nextY)
4725
                                            newY = (point[1] + nextY) / 2;
4726 a0e3dca4 gaqhf
                                    }
4727 b01e7456 gaqhf
                                    resultPoint = new double[] { resultPoint[0], newY };
4728 a0e3dca4 gaqhf
                                }
4729
                            }
4730
                        }
4731
                        else if (i == targetVertices.Count - 1)
4732
                        {
4733
                            LMSymbol connSymbol = targetConnector.ConnectItem2SymbolObject;
4734 b01e7456 gaqhf
                            bool containZeroLength = false;
4735
                            if (connSymbol != null)
4736 a0e3dca4 gaqhf
                            {
4737 1805d3b7 gaqhf
                                foreach (LMConnector connector in connSymbol.Connect1Connectors)
4738
                                {
4739 4d4dce52 esham21
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
4740 1805d3b7 gaqhf
                                        containZeroLength = true;
4741
                                }
4742
                                foreach (LMConnector connector in connSymbol.Connect2Connectors)
4743 a0e3dca4 gaqhf
                                {
4744 4d4dce52 esham21
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
4745 1805d3b7 gaqhf
                                        containZeroLength = true;
4746 a0e3dca4 gaqhf
                                }
4747 b01e7456 gaqhf
                            }
4748
4749
                            if (connSymbol == null ||
4750 4d4dce52 esham21
                                 (connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") ||
4751 b01e7456 gaqhf
                                containZeroLength)
4752
                            {
4753
                                bool bCalcX = false;
4754
                                bool bCalcY = false;
4755
                                if (targetLine.SlopeType == SlopeType.HORIZONTAL)
4756
                                    bCalcX = true;
4757
                                else if (targetLine.SlopeType == SlopeType.VERTICAL)
4758
                                    bCalcY = true;
4759
                                else
4760
                                {
4761
                                    bCalcX = true;
4762
                                    bCalcY = true;
4763
                                }
4764 a0e3dca4 gaqhf
4765 b01e7456 gaqhf
                                if (bCalcX)
4766 a0e3dca4 gaqhf
                                {
4767 b01e7456 gaqhf
                                    double nextX = targetVertices[i - 1][0];
4768
                                    double newX = 0;
4769
                                    if (nextX > tempX)
4770
                                    {
4771
                                        newX = tempX + gridSetting.Length;
4772
                                        if (newX > nextX)
4773
                                            newX = (point[0] + nextX) / 2;
4774
                                    }
4775 a0e3dca4 gaqhf
                                    else
4776
                                    {
4777 b01e7456 gaqhf
                                        newX = tempX - gridSetting.Length;
4778
                                        if (newX < nextX)
4779
                                            newX = (point[0] + nextX) / 2;
4780 a0e3dca4 gaqhf
                                    }
4781 b01e7456 gaqhf
                                    resultPoint = new double[] { newX, resultPoint[1] };
4782
                                }
4783 a0e3dca4 gaqhf
4784 b01e7456 gaqhf
                                if (bCalcY)
4785
                                {
4786
                                    double nextY = targetVertices[i - 1][1];
4787
                                    double newY = 0;
4788
                                    if (nextY > tempY)
4789 a0e3dca4 gaqhf
                                    {
4790 b01e7456 gaqhf
                                        newY = tempY + gridSetting.Length;
4791
                                        if (newY > nextY)
4792
                                            newY = (point[1] + nextY) / 2;
4793 a0e3dca4 gaqhf
                                    }
4794 b01e7456 gaqhf
                                    else
4795 a0e3dca4 gaqhf
                                    {
4796 b01e7456 gaqhf
                                        newY = tempY - gridSetting.Length;
4797
                                        if (newY < nextY)
4798
                                            newY = (point[1] + nextY) / 2;
4799 a0e3dca4 gaqhf
                                    }
4800 b01e7456 gaqhf
                                    resultPoint = new double[] { resultPoint[0], newY };
4801 a0e3dca4 gaqhf
                                }
4802
                            }
4803 68464385 gaqhf
                        }
4804 a0e3dca4 gaqhf
                        break;
4805 68464385 gaqhf
                    }
4806
                }
4807
            }
4808
4809 a0e3dca4 gaqhf
            x = resultPoint[0];
4810
            y = resultPoint[1];
4811
4812 68464385 gaqhf
            return targetConnector;
4813
        }
4814
4815 1ff0105e gaqhf
        private LMConnector GetLMConnectorOnlyOne(string modelItemID)
4816
        {
4817
            LMConnector result = null;
4818
            List<LMConnector> connectors = new List<LMConnector>();
4819
            LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
4820
4821
            if (modelItem != null)
4822
            {
4823
                foreach (LMRepresentation rep in modelItem.Representations)
4824
                {
4825 4d4dce52 esham21
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
4826 1ff0105e gaqhf
                        connectors.Add(dataSource.GetConnector(rep.Id));
4827
                }
4828
4829
                ReleaseCOMObjects(modelItem);
4830
            }
4831
4832
            if (connectors.Count == 1)
4833
                result = connectors[0];
4834
            else
4835
                foreach (var item in connectors)
4836
                    ReleaseCOMObjects(item);
4837
4838
            return result;
4839
        }
4840
4841 63a112d9 gaqhf
        private LMConnector GetLMConnectorFirst(string modelItemID)
4842
        {
4843
            LMConnector result = null;
4844
            LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
4845
4846
            if (modelItem != null)
4847
            {
4848
                foreach (LMRepresentation rep in modelItem.Representations)
4849
                {
4850 4d4dce52 esham21
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" &&
4851
                        rep.Attributes["ItemStatus"].get_Value() == "Active")
4852 63a112d9 gaqhf
                    {
4853
                        LMConnector connector = dataSource.GetConnector(rep.Id);
4854 4d4dce52 esham21
                        if (!Convert.ToBoolean(connector.get_IsZeroLength()))
4855 63a112d9 gaqhf
                        {
4856
                            result = connector;
4857
                            break;
4858
                        }
4859
                        else
4860
                        {
4861
                            ReleaseCOMObjects(connector);
4862
                            connector = null;
4863
                        }
4864
                    }
4865
                }
4866
                ReleaseCOMObjects(modelItem);
4867
                modelItem = null;
4868
            }
4869
4870
            return result;
4871
        }
4872
4873 7e680366 gaqhf
        private int GetConnectorCount(string modelItemID)
4874
        {
4875
            LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
4876
            int result = 0;
4877
            if (modelItem != null)
4878
            {
4879
                foreach (LMRepresentation rep in modelItem.Representations)
4880
                {
4881 4d4dce52 esham21
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
4882 7e680366 gaqhf
                        result++;
4883
                    ReleaseCOMObjects(rep);
4884
                }
4885
                ReleaseCOMObjects(modelItem);
4886
            }
4887
4888
            return result;
4889
        }
4890
4891 fae4f386 gaqhf
        public List<string> GetRepresentations(string modelItemID)
4892
        {
4893
            List<string> result = new List<string>(); ;
4894
            LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
4895
            if (modelItem != null)
4896
            {
4897
                foreach (LMRepresentation rep in modelItem.Representations)
4898
                {
4899 4d4dce52 esham21
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
4900 fae4f386 gaqhf
                        result.Add(rep.Id);
4901
                }
4902
                ReleaseCOMObjects(modelItem);
4903
            }
4904
4905
            return result;
4906
        }
4907
4908 8701de36 gaqhf
        private void LineNumberModeling(LineNumber lineNumber)
4909
        {
4910
            Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line;
4911
            if (line != null)
4912
            {
4913
                double x = 0;
4914
                double y = 0;
4915
                CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
4916
4917
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
4918
                LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, x, y);
4919
                if (connectedLMConnector != null)
4920
                {
4921 4d4dce52 esham21
                    Array points = new double[] { 0, x, y };
4922 44087b23 gaqhf
                    lineNumber.SPPID.SPPID_X = x;
4923
                    lineNumber.SPPID.SPPID_Y = y;
4924 4d4dce52 esham21
                    LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false);
4925 ca6e0f51 gaqhf
4926 8701de36 gaqhf
                    if (_LmLabelPresist != null)
4927
                    {
4928
                        _LmLabelPresist.Commit();
4929
                        lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
4930
                        ReleaseCOMObjects(_LmLabelPresist);
4931
                    }
4932
                }
4933
4934
                foreach (var item in connectorVertices)
4935
                    ReleaseCOMObjects(item.Key);
4936
            }
4937
        }
4938 44087b23 gaqhf
        private void LineNumberCorrectModeling(LineNumber lineNumber)
4939
        {
4940
            Line line = SPPIDUtil.FindObjectByUID(document, lineNumber.CONNLINE) as Line;
4941
            if (line == null || line.SPPID.Vertices == null)
4942
                return;
4943
4944
            if (!string.IsNullOrEmpty(lineNumber.SPPID.RepresentationId))
4945
            {
4946
                LMLabelPersist removeLabel = dataSource.GetLabelPersist(lineNumber.SPPID.RepresentationId);
4947
                if (removeLabel != null)
4948 3d92d75d gaqhf
                {
4949 4d4dce52 esham21
                    lineNumber.SPPID.SPPID_X = removeLabel.get_XCoordinate();
4950
                    lineNumber.SPPID.SPPID_Y = removeLabel.get_YCoordinate();
4951 3d92d75d gaqhf
4952 44087b23 gaqhf
                    GridSetting gridSetting = GridSetting.GetInstance();
4953 898e39fe gaqhf
                    LMConnector connector = dataSource.GetConnector(removeLabel.RepresentationID);
4954 3d92d75d gaqhf
4955 44087b23 gaqhf
                    double[] labelRange = null;
4956
                    GetSPPIDSymbolRange(removeLabel, ref labelRange);
4957
                    List<double[]> vertices = GetConnectorVertices(connector);
4958
4959
                    double[] resultStart = null;
4960
                    double[] resultEnd = null;
4961
                    double distance = double.MaxValue;
4962
                    for (int i = 0; i < vertices.Count - 1; i++)
4963
                    {
4964
                        double[] startPoint = vertices[i];
4965
                        double[] endPoint = vertices[i + 1];
4966
                        foreach (var item in line.SPPID.Vertices)
4967
                        {
4968
                            double[] lineStartPoint = item[0];
4969
                            double[] lineEndPoint = item[item.Count - 1];
4970
4971
                            double tempDistance = SPPIDUtil.CalcPointToPointdDistance(startPoint[0], startPoint[1], lineStartPoint[0], lineStartPoint[1]) +
4972
                                SPPIDUtil.CalcPointToPointdDistance(endPoint[0], endPoint[1], lineEndPoint[0], lineEndPoint[1]);
4973
                            if (tempDistance < distance)
4974
                            {
4975
                                distance = tempDistance;
4976
                                resultStart = startPoint;
4977
                                resultEnd = endPoint;
4978
                            }
4979
                            tempDistance = SPPIDUtil.CalcPointToPointdDistance(startPoint[0], startPoint[1], lineEndPoint[0], lineEndPoint[1]) +
4980
                                SPPIDUtil.CalcPointToPointdDistance(endPoint[0], endPoint[1], lineStartPoint[0], lineStartPoint[1]);
4981
                            if (tempDistance < distance)
4982
                            {
4983
                                distance = tempDistance;
4984
                                resultStart = startPoint;
4985
                                resultEnd = endPoint;
4986
                            }
4987
                        }
4988
                    }
4989
4990
                    if (resultStart != null && resultEnd != null)
4991
                    {
4992
                        SlopeType slope = SPPIDUtil.CalcSlope(resultStart[0], resultStart[1], resultEnd[0], resultEnd[1]);
4993
                        double lineStartX = 0;
4994
                        double lineStartY = 0;
4995
                        double lineEndX = 0;
4996
                        double lineEndY = 0;
4997
                        double lineNumberX = 0;
4998
                        double lineNumberY = 0;
4999
                        SPPIDUtil.ConvertPointBystring(line.STARTPOINT, ref lineStartX, ref lineStartY);
5000
                        SPPIDUtil.ConvertPointBystring(line.ENDPOINT, ref lineEndX, ref lineEndY);
5001
5002
                        double lineX = (lineStartX + lineEndX) / 2;
5003
                        double lineY = (lineStartY + lineEndY) / 2;
5004
                        lineNumberX = (lineNumber.X1 + lineNumber.X2) / 2;
5005
                        lineNumberY = (lineNumber.Y1 + lineNumber.Y2) / 2;
5006
5007
                        double SPPIDCenterX = (resultStart[0] + resultEnd[0]) / 2;
5008
                        double SPPIDCenterY = (resultStart[1] + resultEnd[1]) / 2;
5009
                        double labelCenterX = (labelRange[0] + labelRange[2]) / 2;
5010
                        double labelCenterY = (labelRange[1] + labelRange[3]) / 2;
5011
5012
                        double offsetX = 0;
5013
                        double offsetY = 0;
5014
                        if (slope == SlopeType.HORIZONTAL)
5015
                        {
5016
                            // Line Number 아래
5017
                            if (lineY < lineNumberY)
5018
                            {
5019
                                offsetX = labelCenterX - SPPIDCenterX;
5020
                                offsetY = labelRange[3] - SPPIDCenterY + gridSetting.Length;
5021
                                MoveLineNumber(lineNumber, offsetX, offsetY);
5022
                            }
5023
                            // Line Number 위
5024
                            else
5025
                            {
5026
                                offsetX = labelCenterX - SPPIDCenterX;
5027
                                offsetY = labelRange[1] - SPPIDCenterY - gridSetting.Length;
5028
                                MoveLineNumber(lineNumber, offsetX, offsetY);
5029
                            }
5030
                        }
5031
                        else if (slope == SlopeType.VERTICAL)
5032
                        {
5033
                            // Line Number 오르쪽
5034
                            if (lineX < lineNumberX)
5035
                            {
5036
                                offsetX = labelRange[0] - SPPIDCenterX - gridSetting.Length;
5037
                                offsetY = labelCenterY - SPPIDCenterY;
5038
                                MoveLineNumber(lineNumber, offsetX, offsetY);
5039
                            }
5040
                            // Line Number 왼쪽
5041
                            else
5042
                            {
5043
                                offsetX = labelRange[2] - SPPIDCenterX + gridSetting.Length;
5044
                                offsetY = labelCenterY - SPPIDCenterY;
5045
                                MoveLineNumber(lineNumber, offsetX, offsetY);
5046
                            }
5047
                        }
5048
5049 898e39fe gaqhf
                        if (offsetY != 0 || offsetY != 0)
5050 44087b23 gaqhf
                        {
5051 898e39fe gaqhf
                            if (connector.ConnectItem1SymbolObject != null &&
5052 4d4dce52 esham21
                                connector.ConnectItem1SymbolObject.get_RepresentationType() == "OPC")
5053 898e39fe gaqhf
                            {
5054 4d4dce52 esham21
                                Ingr.RAD2D.Symbol2d symbol = radApp.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()];
5055 898e39fe gaqhf
5056
                                double x1, y1, x2, y2, originX, originY;
5057
                                symbol.Range(out x1, out y1, out x2, out y2);
5058
                                symbol.GetOrigin(out originX, out originY);
5059
                                if (originX < lineNumber.SPPID.SPPID_X)
5060 9a441e35 gaqhf
                                    offsetX = -1 * (originX + gridSetting.Length * 30 - labelCenterX);
5061 898e39fe gaqhf
                                else
5062 9a441e35 gaqhf
                                    offsetX = -1 * (originX - gridSetting.Length * 30 - labelCenterX);
5063 898e39fe gaqhf
                            }
5064
                            else if (connector.ConnectItem2SymbolObject != null &&
5065 4d4dce52 esham21
                                    connector.ConnectItem2SymbolObject.get_RepresentationType() == "OPC")
5066 898e39fe gaqhf
                            {
5067 4d4dce52 esham21
                                Ingr.RAD2D.Symbol2d symbol = radApp.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()];
5068 898e39fe gaqhf
5069
                                double x1, y1, x2, y2, originX, originY;
5070
                                symbol.Range(out x1, out y1, out x2, out y2);
5071
                                symbol.GetOrigin(out originX, out originY);
5072
                                if (originX < lineNumber.SPPID.SPPID_X)
5073 9a441e35 gaqhf
                                    offsetX = -1 * (originX + gridSetting.Length * 30 - labelCenterX);
5074 898e39fe gaqhf
                                else
5075 9a441e35 gaqhf
                                    offsetX = -1 * (originX - gridSetting.Length * 30 - labelCenterX);
5076 898e39fe gaqhf
                            }
5077
5078 3d92d75d gaqhf
                            radApp.ActiveSelectSet.RemoveAll();
5079 4d4dce52 esham21
                            DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[removeLabel.get_GraphicOID().ToString()] as DependencyObject;
5080 3d92d75d gaqhf
                            if (dependency != null)
5081 44087b23 gaqhf
                            {
5082 3d92d75d gaqhf
                                radApp.ActiveSelectSet.Add(dependency);
5083
                                Ingr.RAD2D.Transform transform = dependency.GetTransform();
5084
                                transform.DefineByMove2d(-offsetX, -offsetY);
5085
                                radApp.ActiveSelectSet.Transform(transform, true);
5086
                                radApp.ActiveSelectSet.RemoveAll();
5087 44087b23 gaqhf
                            }
5088
                        }
5089
5090
                        void MoveLineNumber(LineNumber moveLineNumber, double x, double y)
5091
                        {
5092
                            moveLineNumber.SPPID.SPPID_X = moveLineNumber.SPPID.SPPID_X - x;
5093
                            moveLineNumber.SPPID.SPPID_Y = moveLineNumber.SPPID.SPPID_Y - y;
5094
                        }
5095
                    }
5096
5097
5098
                    ReleaseCOMObjects(connector);
5099
                    connector = null;
5100
                }
5101
5102
                ReleaseCOMObjects(removeLabel);
5103
                removeLabel = null;
5104
            }
5105
        }
5106 74752074 gaqhf
        /// <summary>
5107 b2d1c1aa gaqhf
        /// Flow Mark Modeling
5108
        /// </summary>
5109
        /// <param name="line"></param>
5110
        private void FlowMarkModeling(Line line)
5111
        {
5112 a0965e07 gaqhf
            if (line.FLOWMARK && !string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(_ETCSetting.FlowMarkSymbolPath))
5113 b2d1c1aa gaqhf
            {
5114 32205389 gaqhf
                LMConnector connector = GetLMConnectorOnlyOne(line.SPPID.ModelItemId);
5115
                if (connector != null)
5116 b2d1c1aa gaqhf
                {
5117 32205389 gaqhf
                    string mappingPath = _ETCSetting.FlowMarkSymbolPath;
5118
                    List<double[]> vertices = GetConnectorVertices(connector);
5119
                    vertices = vertices.FindAll(x => x[0] > 0 && x[1] > 0);
5120
                    double[] point = vertices[vertices.Count - 1];
5121 4d4dce52 esham21
                    Array array = new double[] { 0, point[0], point[1] };
5122 5adeae43 esham21
                    LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mappingPath, ref array, null, null, LabeledItem: connector.AsLMRepresentation());
5123 32205389 gaqhf
                    if (_LMLabelPersist != null)
5124 04fcadf1 gaqhf
                    {
5125
                        _LMLabelPersist.Commit();
5126 c5b2c7ff gaqhf
                        FlowMarkRepIds.Add(_LMLabelPersist.Id);
5127 32205389 gaqhf
                        ReleaseCOMObjects(_LMLabelPersist);
5128 04fcadf1 gaqhf
                    }
5129 b2d1c1aa gaqhf
                }
5130
            }
5131
        }
5132
5133
        /// <summary>
5134 74752074 gaqhf
        /// Line Number 기준으로 모든 Item에 Line Number의 Attribute Input
5135
        /// </summary>
5136
        /// <param name="lineNumber"></param>
5137 82d6e5ea gaqhf
        private void InputLineNumberAttribute(LineNumber lineNumber, List<string> endLine)
5138 a7e9beec gaqhf
        {
5139 f4571b5d gaqhf
            lineNumber.ATTRIBUTES.Sort(SortAttribute);
5140
            int SortAttribute(BaseModel.Attribute a, BaseModel.Attribute b)
5141
            {
5142
                if (a.ATTRIBUTE == "Tag Seq No")
5143
                    return 1;
5144
                else if (b.ATTRIBUTE == "Tag Seq No")
5145
                    return -1;
5146
5147
                return 0;
5148
            }
5149
5150 8634af60 gaqhf
            foreach (LineRun run in lineNumber.RUNS)
5151 a7e9beec gaqhf
            {
5152 8634af60 gaqhf
                foreach (var item in run.RUNITEMS)
5153 a7e9beec gaqhf
                {
5154 16fb3441 gaqhf
                    if (item.GetType() == typeof(Line))
5155 8634af60 gaqhf
                    {
5156
                        Line line = item as Line;
5157 82d6e5ea gaqhf
                        if (line != null && !endLine.Contains(line.SPPID.ModelItemId))
5158 a7e9beec gaqhf
                        {
5159 8634af60 gaqhf
                            LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
5160 4d4dce52 esham21
                            if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
5161 a7e9beec gaqhf
                            {
5162 8634af60 gaqhf
                                foreach (var attribute in lineNumber.ATTRIBUTES)
5163
                                {
5164
                                    LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
5165 b2d1c1aa gaqhf
                                    if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
5166 8634af60 gaqhf
                                    {
5167
                                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
5168 41e26743 gaqhf
                                        if (mapping.SPPIDATTRIBUTENAME == "OperFluidCode" && !string.IsNullOrEmpty(attribute.VALUE))
5169
                                        {
5170
                                            LMAAttribute _FluidSystemAttribute = _LMModelItem.Attributes["FluidSystem"];
5171
                                            if (_FluidSystemAttribute != null)
5172
                                            {
5173
                                                DataTable dt = SPPID_DB.GetFluidSystemInfo(attribute.VALUE);
5174
                                                if (dt.Rows.Count == 1)
5175
                                                {
5176
                                                    string fluidSystem = dt.Rows[0]["CODELIST_TEXT"].ToString();
5177 4d4dce52 esham21
                                                    if (DBNull.Value.Equals(_FluidSystemAttribute.get_Value()))
5178
                                                        _FluidSystemAttribute.set_Value(fluidSystem);
5179
                                                    else if (_FluidSystemAttribute.get_Value() != fluidSystem)
5180
                                                        _FluidSystemAttribute.set_Value(fluidSystem);
5181 41e26743 gaqhf
5182
                                                    if (_LMAAttribute != null)
5183
                                                    {
5184 4d4dce52 esham21
                                                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
5185
                                                            _LMAAttribute.set_Value(attribute.VALUE);
5186
                                                        else if (_LMAAttribute.get_Value() != attribute.VALUE)
5187
                                                            _LMAAttribute.set_Value(attribute.VALUE);
5188 41e26743 gaqhf
                                                    }
5189
                                                }
5190
                                                if (dt != null)
5191
                                                    dt.Dispose();
5192
                                            }
5193
                                        }
5194 c9264d17 gaqhf
                                        else if (mapping.SPPIDATTRIBUTENAME.Equals("NominalDiameter") && !string.IsNullOrEmpty(attribute.VALUE) && _LMAAttribute != null)
5195
                                        {
5196 52599bc7 gaqhf
                                            DataRow[] rows = nominalDiameterTable.Select(string.Format("MetricStr = '{0}' OR InchStr = '{0}'", attribute.VALUE));
5197
5198
                                            if (rows.Length.Equals(1))
5199
                                            {
5200
                                                if (_ETCSetting.UnitSetting != null && _ETCSetting.UnitSetting.Equals("Metric"))
5201
                                                    attribute.VALUE = rows[0]["MetricStr"].ToString();
5202
                                                else
5203
                                                    attribute.VALUE = rows[0]["InchStr"].ToString();
5204
5205 4d4dce52 esham21
                                                if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
5206
                                                    _LMAAttribute.set_Value(attribute.VALUE);
5207
                                                else if (_LMAAttribute.get_Value() != attribute.VALUE)
5208
                                                    _LMAAttribute.set_Value(attribute.VALUE);
5209 52599bc7 gaqhf
                                            }
5210 c9264d17 gaqhf
                                        }
5211 41e26743 gaqhf
                                        else if (_LMAAttribute != null)
5212 8634af60 gaqhf
                                        {
5213 4d4dce52 esham21
                                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
5214
                                                _LMAAttribute.set_Value(attribute.VALUE);
5215
                                            else if (_LMAAttribute.get_Value() != attribute.VALUE)
5216
                                                _LMAAttribute.set_Value(attribute.VALUE);
5217 8634af60 gaqhf
                                        }
5218
                                    }
5219
                                }
5220 68464385 gaqhf
                                _LMModelItem.Commit();
5221 a7e9beec gaqhf
                            }
5222 8634af60 gaqhf
                            if (_LMModelItem != null)
5223
                                ReleaseCOMObjects(_LMModelItem);
5224 82d6e5ea gaqhf
                            endLine.Add(line.SPPID.ModelItemId);
5225 a7e9beec gaqhf
                        }
5226
                    }
5227
                }
5228
            }
5229
        }
5230
5231 74752074 gaqhf
        /// <summary>
5232
        /// Symbol Attribute 입력 메서드
5233
        /// </summary>
5234 73415441 gaqhf
        /// <param name="item"></param>
5235
        private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes)
5236 1efc25a3 gaqhf
        {
5237 7f00b26c gaqhf
            // Object 아이템이 Symbol일 경우 Equipment일 경우 
5238
            string sRep = null;
5239 77a869a8 gaqhf
            string sModelID = null;
5240 7f00b26c gaqhf
            if (targetItem.GetType() == typeof(Symbol))
5241
                sRep = ((Symbol)targetItem).SPPID.RepresentationId;
5242
            else if (targetItem.GetType() == typeof(Equipment))
5243
                sRep = ((Equipment)targetItem).SPPID.RepresentationId;
5244 77a869a8 gaqhf
            else if (targetItem.GetType() == typeof(Line))
5245
                sModelID = ((Line)targetItem).SPPID.ModelItemId;
5246 f8b99593 gaqhf
5247 7f00b26c gaqhf
            if (!string.IsNullOrEmpty(sRep))
5248 1efc25a3 gaqhf
            {
5249 7f00b26c gaqhf
                LMSymbol _LMSymbol = dataSource.GetSymbol(sRep);
5250 f8b99593 gaqhf
                LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
5251
                LMAAttributes _Attributes = _LMModelItem.Attributes;
5252
5253 7f00b26c gaqhf
                foreach (var item in targetAttributes)
5254
                {
5255
                    AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
5256
                    if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None")
5257 65a1ed4b gaqhf
                    {
5258 1ecaaba8 gaqhf
                        if (!mapping.IsText)
5259 30ba9ae0 gaqhf
                        {
5260 c9264d17 gaqhf
                            LMAAttribute _LMAAttribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
5261
                            if (mapping.SPPIDATTRIBUTENAME.Equals("NominalDiameter") && !string.IsNullOrEmpty(item.VALUE) && _LMAAttribute != null)
5262 b7a29053 gaqhf
                            {
5263 52599bc7 gaqhf
                                DataRow[] rows = nominalDiameterTable.Select(string.Format("MetricStr = '{0}' OR InchStr = '{0}'", item.VALUE));
5264
5265
                                if (rows.Length.Equals(1))
5266
                                {
5267
                                    if (_ETCSetting.UnitSetting != null && _ETCSetting.UnitSetting.Equals("Metric"))
5268
                                        item.VALUE = rows[0]["MetricStr"].ToString();
5269
                                    else
5270
                                        item.VALUE = rows[0]["InchStr"].ToString();
5271
5272 4d4dce52 esham21
                                    if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
5273
                                        _LMAAttribute.set_Value(item.VALUE);
5274
                                    else if (_LMAAttribute.get_Value() != item.VALUE)
5275
                                        _LMAAttribute.set_Value(item.VALUE);
5276 52599bc7 gaqhf
                                }
5277 c9264d17 gaqhf
                            }
5278
                            else if (_LMAAttribute != null)
5279
                            {
5280 4d4dce52 esham21
                                _LMAAttribute.set_Value(item.VALUE);
5281 1ecaaba8 gaqhf
                                // OPC 일경우 Attribute 저장
5282
                                if (targetItem.GetType() == typeof(Symbol))
5283
                                {
5284
                                    Symbol symbol = targetItem as Symbol;
5285
                                    if (symbol.TYPE == "Piping OPC's" || symbol.TYPE == "Instrument OPC's")
5286
                                        symbol.SPPID.Attributes.Add(new string[] { mapping.SPPIDATTRIBUTENAME, item.VALUE });
5287
                                }
5288 b7a29053 gaqhf
                            }
5289 30ba9ae0 gaqhf
                        }
5290 1ecaaba8 gaqhf
                        else
5291 4d4dce52 esham21
                            DefaultTextModeling(item.VALUE, _LMSymbol.get_XCoordinate(), _LMSymbol.get_YCoordinate());
5292 65a1ed4b gaqhf
                    }
5293 ac78b508 gaqhf
                }
5294 f8b99593 gaqhf
                _LMModelItem.Commit();
5295 7f00b26c gaqhf
5296
                ReleaseCOMObjects(_Attributes);
5297 f8b99593 gaqhf
                ReleaseCOMObjects(_LMModelItem);
5298 7f00b26c gaqhf
                ReleaseCOMObjects(_LMSymbol);
5299 1efc25a3 gaqhf
            }
5300 77a869a8 gaqhf
            else if (!string.IsNullOrEmpty(sModelID))
5301
            {
5302
                LMModelItem _LMModelItem = dataSource.GetModelItem(sModelID);
5303
                LMAAttributes _Attributes = _LMModelItem.Attributes;
5304
5305
                foreach (var item in targetAttributes)
5306
                {
5307
                    AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
5308 f969dc62 gaqhf
                    if (mapping == null)
5309
                        continue;
5310
                    
5311 2e92b956 gaqhf
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
5312
                    if (mapping.SPPIDATTRIBUTENAME == "OperFluidCode" && !string.IsNullOrEmpty(item.VALUE))
5313
                    {
5314
                        LMAAttribute _FluidSystemAttribute = _LMModelItem.Attributes["FluidSystem"];
5315
                        if (_FluidSystemAttribute != null)
5316
                        {
5317
                            DataTable dt = SPPID_DB.GetFluidSystemInfo(item.VALUE);
5318
                            if (dt.Rows.Count == 1)
5319
                            {
5320
                                string fluidSystem = dt.Rows[0]["CODELIST_TEXT"].ToString();
5321 4d4dce52 esham21
                                if (DBNull.Value.Equals(_FluidSystemAttribute.get_Value()))
5322
                                    _FluidSystemAttribute.set_Value(fluidSystem);
5323
                                else if (_FluidSystemAttribute.get_Value() != fluidSystem)
5324
                                    _FluidSystemAttribute.set_Value(fluidSystem);
5325 2e92b956 gaqhf
5326
                                if (_LMAAttribute != null)
5327
                                {
5328 4d4dce52 esham21
                                    if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
5329
                                        _LMAAttribute.set_Value(item.VALUE);
5330
                                    else if (_LMAAttribute.get_Value() != item.VALUE)
5331
                                        _LMAAttribute.set_Value(item.VALUE);
5332 2e92b956 gaqhf
                                }
5333
                            }
5334
                            if (dt != null)
5335
                                dt.Dispose();
5336
                        }
5337
                    }
5338 c9264d17 gaqhf
                    else if (mapping.SPPIDATTRIBUTENAME.Equals("NominalDiameter") && !string.IsNullOrEmpty(item.VALUE) && _LMAAttribute != null)
5339
                    {
5340 52599bc7 gaqhf
                        DataRow[] rows = nominalDiameterTable.Select(string.Format("MetricStr = '{0}' OR InchStr = '{0}'", item.VALUE));
5341
5342
                        if (rows.Length.Equals(1))
5343
                        {
5344
                            if (_ETCSetting.UnitSetting != null && _ETCSetting.UnitSetting.Equals("Metric"))
5345
                                item.VALUE = rows[0]["MetricStr"].ToString();
5346
                            else
5347
                                item.VALUE = rows[0]["InchStr"].ToString();
5348
5349 4d4dce52 esham21
                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
5350
                                _LMAAttribute.set_Value(item.VALUE);
5351
                            else if (_LMAAttribute.get_Value() != item.VALUE)
5352
                                _LMAAttribute.set_Value(item.VALUE);
5353 52599bc7 gaqhf
                        }
5354 c9264d17 gaqhf
                    }
5355 2e92b956 gaqhf
                    else if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None")
5356 77a869a8 gaqhf
                    {
5357
                        if (!mapping.IsText)
5358
                        {
5359
                            LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
5360
                            if (_Attribute != null)
5361 4d4dce52 esham21
                                _Attribute.set_Value(item.VALUE);
5362 77a869a8 gaqhf
                        }
5363
                    }
5364
                }
5365
                _LMModelItem.Commit();
5366
5367
                ReleaseCOMObjects(_Attributes);
5368
                ReleaseCOMObjects(_LMModelItem);
5369
            }
5370 1efc25a3 gaqhf
        }
5371
5372 74752074 gaqhf
        /// <summary>
5373 16584d30 gaqhf
        /// Input SpecBreak Attribute
5374
        /// </summary>
5375
        /// <param name="specBreak"></param>
5376
        private void InputSpecBreakAttribute(SpecBreak specBreak)
5377
        {
5378 7f00b26c gaqhf
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
5379
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
5380
5381
            if (upStreamObj != null &&
5382
                downStreamObj != null)
5383 16584d30 gaqhf
            {
5384 7f00b26c gaqhf
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
5385 16584d30 gaqhf
5386 7f00b26c gaqhf
                if (targetLMConnector != null)
5387 16584d30 gaqhf
                {
5388 7f00b26c gaqhf
                    foreach (LMLabelPersist _LMLabelPersist in targetLMConnector.LabelPersists)
5389 16584d30 gaqhf
                    {
5390 4d4dce52 esham21
                        string symbolPath = _LMLabelPersist.get_FileName();
5391 7f00b26c gaqhf
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.SPPIDSYMBOLNAME == symbolPath);
5392
                        if (mapping != null)
5393 16584d30 gaqhf
                        {
5394 7f00b26c gaqhf
                            BaseModel.Attribute attribute = specBreak.ATTRIBUTES.Find(y => y.UID == mapping.UID);
5395
                            if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
5396 16584d30 gaqhf
                            {
5397 7f00b26c gaqhf
                                string[] values = attribute.VALUE.Split(new char[] { ',' });
5398
                                if (values.Length == 2)
5399 16584d30 gaqhf
                                {
5400 7f00b26c gaqhf
                                    string upStreamValue = values[0];
5401
                                    string downStreamValue = values[1];
5402 16584d30 gaqhf
5403 7f00b26c gaqhf
                                    InputAttributeForSpecBreak(upStreamObj, downStreamObj, upStreamValue, downStreamValue, mapping.SPPIDATTRIBUTENAME);
5404 16584d30 gaqhf
                                }
5405
                            }
5406
                        }
5407
                    }
5408 7f00b26c gaqhf
5409
                    ReleaseCOMObjects(targetLMConnector);
5410 16584d30 gaqhf
                }
5411
            }
5412 7f00b26c gaqhf
5413 16584d30 gaqhf
5414
            #region 내부에서만 쓰는 메서드
5415 7f00b26c gaqhf
            void InputAttributeForSpecBreak(object _upStreamObj, object _downStreamObj, string upStreamValue, string downStreamValue, string sppidAttributeName)
5416 16584d30 gaqhf
            {
5417 7f00b26c gaqhf
                Symbol upStreamSymbol = _upStreamObj as Symbol;
5418
                Line upStreamLine = _upStreamObj as Line;
5419
                Symbol downStreamSymbol = _downStreamObj as Symbol;
5420
                Line downStreamLine = _downStreamObj as Line;
5421
                // 둘다 Line일 경우
5422
                if (upStreamLine != null && downStreamLine != null)
5423 16584d30 gaqhf
                {
5424 7f00b26c gaqhf
                    InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
5425
                    InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
5426
                }
5427
                // 둘다 Symbol일 경우
5428
                else if (upStreamSymbol != null && downStreamSymbol != null)
5429
                {
5430
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamSymbol);
5431
                    LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
5432
                    LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
5433 16584d30 gaqhf
5434 7f00b26c gaqhf
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
5435
                    {
5436 4d4dce52 esham21
                        if (connector.get_ItemStatus() != "Active")
5437 7f00b26c gaqhf
                            continue;
5438 16584d30 gaqhf
5439 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
5440
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
5441
                    }
5442 16584d30 gaqhf
5443 7f00b26c gaqhf
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
5444
                    {
5445 4d4dce52 esham21
                        if (connector.get_ItemStatus() != "Active")
5446 7f00b26c gaqhf
                            continue;
5447 16584d30 gaqhf
5448 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
5449
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
5450
                    }
5451 16584d30 gaqhf
5452 7f00b26c gaqhf
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
5453
                    {
5454 4d4dce52 esham21
                        if (connector.get_ItemStatus() != "Active")
5455 7f00b26c gaqhf
                            continue;
5456 16584d30 gaqhf
5457 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
5458
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
5459
                    }
5460 16584d30 gaqhf
5461 7f00b26c gaqhf
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
5462
                    {
5463 4d4dce52 esham21
                        if (connector.get_ItemStatus() != "Active")
5464 7f00b26c gaqhf
                            continue;
5465 16584d30 gaqhf
5466 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
5467
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
5468 16584d30 gaqhf
                    }
5469
5470 7f00b26c gaqhf
                    ReleaseCOMObjects(zeroLenthConnector);
5471
                    ReleaseCOMObjects(upStreamLMSymbol);
5472
                    ReleaseCOMObjects(downStreamLMSymbol);
5473
                }
5474
                else if (upStreamSymbol != null && downStreamLine != null)
5475
                {
5476
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamLine);
5477
                    InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
5478
                    LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
5479 16584d30 gaqhf
5480 7f00b26c gaqhf
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
5481
                    {
5482 4d4dce52 esham21
                        if (connector.get_ItemStatus() != "Active")
5483 7f00b26c gaqhf
                            continue;
5484 16584d30 gaqhf
5485 c993d55a gaqhf
                        if (connector.Id == zeroLenthConnector.Id)
5486 7f00b26c gaqhf
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
5487
                    }
5488 16584d30 gaqhf
5489 7f00b26c gaqhf
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
5490
                    {
5491 4d4dce52 esham21
                        if (connector.get_ItemStatus() != "Active")
5492 7f00b26c gaqhf
                            continue;
5493 16584d30 gaqhf
5494 c993d55a gaqhf
                        if (connector.Id == zeroLenthConnector.Id)
5495 7f00b26c gaqhf
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
5496 16584d30 gaqhf
                    }
5497
5498 7f00b26c gaqhf
                    ReleaseCOMObjects(zeroLenthConnector);
5499
                    ReleaseCOMObjects(upStreamLMSymbol);
5500
                }
5501
                else if (upStreamLine != null && downStreamSymbol != null)
5502
                {
5503
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamLine, downStreamSymbol);
5504
                    InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
5505
                    LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
5506 16584d30 gaqhf
5507 7f00b26c gaqhf
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
5508
                    {
5509 4d4dce52 esham21
                        if (connector.get_ItemStatus() != "Active")
5510 7f00b26c gaqhf
                            continue;
5511 16584d30 gaqhf
5512 c993d55a gaqhf
                        if (connector.Id == zeroLenthConnector.Id)
5513 7f00b26c gaqhf
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
5514
                    }
5515 16584d30 gaqhf
5516 7f00b26c gaqhf
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
5517
                    {
5518 4d4dce52 esham21
                        if (connector.get_ItemStatus() != "Active")
5519 7f00b26c gaqhf
                            continue;
5520 16584d30 gaqhf
5521 c993d55a gaqhf
                        if (connector.Id == zeroLenthConnector.Id)
5522 7f00b26c gaqhf
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
5523 16584d30 gaqhf
                    }
5524 7f00b26c gaqhf
5525
                    ReleaseCOMObjects(zeroLenthConnector);
5526
                    ReleaseCOMObjects(downStreamLMSymbol);
5527 16584d30 gaqhf
                }
5528
            }
5529
5530
            void InputLineAttributeForSpecBreakLine(Line line, string attrName, string value)
5531
            {
5532 7f00b26c gaqhf
                LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
5533 4d4dce52 esham21
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
5534 16584d30 gaqhf
                {
5535 7f00b26c gaqhf
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
5536
                    if (_LMAAttribute != null)
5537 16584d30 gaqhf
                    {
5538 4d4dce52 esham21
                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
5539
                            _LMAAttribute.set_Value(value);
5540
                        else if (_LMAAttribute.get_Value() != value)
5541
                            _LMAAttribute.set_Value(value);
5542 16584d30 gaqhf
                    }
5543 7f00b26c gaqhf
5544
                    _LMModelItem.Commit();
5545 16584d30 gaqhf
                }
5546 7f00b26c gaqhf
                if (_LMModelItem != null)
5547
                    ReleaseCOMObjects(_LMModelItem);
5548 16584d30 gaqhf
            }
5549
5550
            void InputLineAttributeForSpecBreakLMConnector(LMConnector connector, string attrName, string value)
5551
            {
5552 7f00b26c gaqhf
                LMModelItem _LMModelItem = dataSource.GetModelItem(connector.ModelItemID);
5553 4d4dce52 esham21
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
5554 16584d30 gaqhf
                {
5555 7f00b26c gaqhf
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
5556
                    if (_LMAAttribute != null)
5557 16584d30 gaqhf
                    {
5558 4d4dce52 esham21
                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
5559
                            _LMAAttribute.set_Value(value);
5560
                        else if (_LMAAttribute.get_Value() != value)
5561
                            _LMAAttribute.set_Value(value);
5562 16584d30 gaqhf
                    }
5563 7f00b26c gaqhf
5564
                    _LMModelItem.Commit();
5565 16584d30 gaqhf
                }
5566 7f00b26c gaqhf
                if (_LMModelItem != null)
5567
                    ReleaseCOMObjects(_LMModelItem);
5568 16584d30 gaqhf
            }
5569
            #endregion
5570
        }
5571
5572 d8afa58b gaqhf
        private void InputEndBreakAttribute(EndBreak endBreak)
5573
        {
5574
            object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER);
5575
            object connectedItem = SPPIDUtil.FindObjectByUID(document, endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE);
5576
5577
            if ((ownerObj.GetType() == typeof(Symbol) && connectedItem.GetType() == typeof(Line)) ||
5578
                (ownerObj.GetType() == typeof(Line) && connectedItem.GetType() == typeof(Symbol)))
5579
            {
5580
                LMLabelPersist labelPersist = dataSource.GetLabelPersist(endBreak.SPPID.RepresentationId);
5581
                if (labelPersist != null)
5582
                {
5583
                    LMRepresentation representation = labelPersist.RepresentationObject;
5584
                    if (representation != null)
5585
                    {
5586
                        LMConnector connector = dataSource.GetConnector(representation.Id);
5587
                        LMModelItem ZeroLengthModelItem = connector.ModelItemObject;
5588 4d4dce52 esham21
                        string modelItemID = connector.ModelItemID;
5589
                        if (Convert.ToBoolean(connector.get_IsZeroLength()))
5590 d8afa58b gaqhf
                        {
5591
                            List<string> modelItemIDs = new List<string>();
5592 4d4dce52 esham21
                            if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch")
5593 d8afa58b gaqhf
                            {
5594
                                LMSymbol symbol = connector.ConnectItem1SymbolObject;
5595
                                foreach (LMConnector item in symbol.Connect1Connectors)
5596
                                {
5597 4d4dce52 esham21
                                    if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID)
5598
                                        modelItemIDs.Add(item.ModelItemID);
5599 d8afa58b gaqhf
                                    ReleaseCOMObjects(item);
5600
                                }
5601
                                foreach (LMConnector item in symbol.Connect2Connectors)
5602
                                {
5603 4d4dce52 esham21
                                    if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID)
5604
                                        modelItemIDs.Add(item.ModelItemID);
5605 d8afa58b gaqhf
                                    ReleaseCOMObjects(item);
5606
                                }
5607
                                ReleaseCOMObjects(symbol);
5608
                                symbol = null;
5609
                            }
5610 4d4dce52 esham21
                            else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch")
5611 d8afa58b gaqhf
                            {
5612
                                LMSymbol symbol = connector.ConnectItem2SymbolObject;
5613
                                foreach (LMConnector item in symbol.Connect1Connectors)
5614
                                {
5615 4d4dce52 esham21
                                    if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID)
5616
                                        modelItemIDs.Add(item.ModelItemID);
5617 d8afa58b gaqhf
                                    ReleaseCOMObjects(item);
5618
                                }
5619
                                foreach (LMConnector item in symbol.Connect2Connectors)
5620
                                {
5621 4d4dce52 esham21
                                    if (item.get_ItemStatus() == "Active" && item.ModelItemID != modelItemID)
5622
                                        modelItemIDs.Add(item.ModelItemID);
5623 d8afa58b gaqhf
                                    ReleaseCOMObjects(item);
5624
                                }
5625
                                ReleaseCOMObjects(symbol);
5626
                                symbol = null;
5627
                            }
5628
5629
                            modelItemIDs = modelItemIDs.Distinct().ToList();
5630
                            if (modelItemIDs.Count == 1)
5631
                            {
5632
                                LMModelItem modelItem = dataSource.GetModelItem(modelItemIDs[0]);
5633 3ebe4712 gaqhf
                                LMConnector onlyOne = GetLMConnectorOnlyOne(modelItem.Id);
5634 4d4dce52 esham21
                                if (onlyOne != null && Convert.ToBoolean(onlyOne.get_IsZeroLength()))
5635 3ebe4712 gaqhf
                                {
5636
                                    bool result = false;
5637
                                    foreach (LMLabelPersist loop in onlyOne.LabelPersists)
5638
                                    {
5639 4d4dce52 esham21
                                        if (document.EndBreaks.Find(x => x.SPPID.RepresentationId == loop.RepresentationID) != null)
5640 3ebe4712 gaqhf
                                            result = true;
5641
                                        ReleaseCOMObjects(loop);
5642
                                    }
5643
5644
                                    if (result)
5645
                                    {
5646 4d4dce52 esham21
                                        object value = modelItem.Attributes["TagSequenceNo"].get_Value();
5647
                                        ZeroLengthModelItem.Attributes["TagSequenceNo"].set_Value(value);
5648 d2cffa33 esham21
                                        //object value2 = modelItem.Attributes["SubUnitNumber"].get_Value();
5649
                                        //ZeroLengthModelItem.Attributes["SubUnitNumber"].set_Value(value2);
5650 3ebe4712 gaqhf
                                        ZeroLengthModelItem.Commit();
5651
                                    }
5652
                                    else
5653
                                    {
5654
                                        List<string> loopModelItems = new List<string>();
5655 4d4dce52 esham21
                                        if (onlyOne.ConnectItem1SymbolObject.get_RepresentationType() == "Branch")
5656 3ebe4712 gaqhf
                                        {
5657
                                            LMSymbol _symbol = onlyOne.ConnectItem1SymbolObject;
5658
                                            foreach (LMConnector loop in _symbol.Connect1Connectors)
5659
                                            {
5660 4d4dce52 esham21
                                                if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID)
5661
                                                    loopModelItems.Add(loop.ModelItemID);
5662 3ebe4712 gaqhf
                                                ReleaseCOMObjects(loop);
5663
                                            }
5664 a7c63998 gaqhf
                                            foreach (LMConnector loop in _symbol.Connect2Connectors)
5665
                                            {
5666 4d4dce52 esham21
                                                if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID)
5667
                                                    loopModelItems.Add(loop.ModelItemID);
5668 a7c63998 gaqhf
                                                ReleaseCOMObjects(loop);
5669
                                            }
5670 3ebe4712 gaqhf
                                            ReleaseCOMObjects(_symbol);
5671
                                            _symbol = null;
5672
                                        }
5673 4d4dce52 esham21
                                        else if (onlyOne.ConnectItem2SymbolObject.get_RepresentationType() == "Branch")
5674 3ebe4712 gaqhf
                                        {
5675 a7c63998 gaqhf
                                            LMSymbol _symbol = onlyOne.ConnectItem2SymbolObject;
5676 3ebe4712 gaqhf
                                            foreach (LMConnector loop in _symbol.Connect1Connectors)
5677
                                            {
5678 4d4dce52 esham21
                                                if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID)
5679
                                                    loopModelItems.Add(loop.ModelItemID);
5680 3ebe4712 gaqhf
                                                ReleaseCOMObjects(loop);
5681
                                            }
5682 a7c63998 gaqhf
                                            foreach (LMConnector loop in _symbol.Connect2Connectors)
5683
                                            {
5684 4d4dce52 esham21
                                                if (loop.get_ItemStatus() == "Active" && loop.ModelItemID != onlyOne.ModelItemID)
5685
                                                    loopModelItems.Add(loop.ModelItemID);
5686 a7c63998 gaqhf
                                                ReleaseCOMObjects(loop);
5687
                                            }
5688 3ebe4712 gaqhf
                                            ReleaseCOMObjects(_symbol);
5689
                                            _symbol = null;
5690
                                        }
5691
5692
                                        loopModelItems = loopModelItems.Distinct().ToList();
5693
                                        if (loopModelItems.Count == 1)
5694
                                        {
5695
                                            LMModelItem loopModelItem = dataSource.GetModelItem(loopModelItems[0]);
5696 4d4dce52 esham21
                                            object value = loopModelItem.Attributes["TagSequenceNo"].get_Value();
5697 d2cffa33 esham21
                                            //object value2 = loopModelItem.Attributes["SubUnitNumber"].get_Value();
5698 4d4dce52 esham21
                                            modelItem.Attributes["TagSequenceNo"].set_Value(value);
5699 d2cffa33 esham21
                                            //modelItem.Attributes["SubUnitNumber"].set_Value(value2);
5700 e1c86c6a gaqhf
                                            modelItem.Commit();
5701 4d4dce52 esham21
                                            ZeroLengthModelItem.Attributes["TagSequenceNo"].set_Value(value);
5702 d2cffa33 esham21
                                            //ZeroLengthModelItem.Attributes["SubUnitNumber"].set_Value(value2);
5703 3ebe4712 gaqhf
                                            ZeroLengthModelItem.Commit();
5704
5705
                                            ReleaseCOMObjects(loopModelItem);
5706
                                            loopModelItem = null;
5707
                                        }
5708
                                    }
5709
                                }
5710
                                else
5711
                                {
5712 4d4dce52 esham21
                                    object value = modelItem.Attributes["TagSequenceNo"].get_Value();
5713
                                    ZeroLengthModelItem.Attributes["TagSequenceNo"].set_Value(value);
5714 d2cffa33 esham21
                                    //object value2 = modelItem.Attributes["SubUnitNumber"].get_Value();
5715
                                    //ZeroLengthModelItem.Attributes["SubUnitNumber"].set_Value(value2);
5716 3ebe4712 gaqhf
                                    ZeroLengthModelItem.Commit();
5717
                                }
5718 d8afa58b gaqhf
                                ReleaseCOMObjects(modelItem);
5719
                                modelItem = null;
5720 3ebe4712 gaqhf
                                ReleaseCOMObjects(onlyOne);
5721
                                onlyOne = null;
5722 d8afa58b gaqhf
                            }
5723
                        }
5724
                        ReleaseCOMObjects(connector);
5725
                        connector = null;
5726
                        ReleaseCOMObjects(ZeroLengthModelItem);
5727
                        ZeroLengthModelItem = null;
5728
                    }
5729
                    ReleaseCOMObjects(representation);
5730
                    representation = null;
5731
                }
5732
                ReleaseCOMObjects(labelPersist);
5733
                labelPersist = null;
5734
            }
5735
        }
5736
5737 16584d30 gaqhf
        /// <summary>
5738 74752074 gaqhf
        /// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링
5739
        /// </summary>
5740
        /// <param name="text"></param>
5741 e27329d6 gaqhf
        private void NormalTextModeling(Text text)
5742 cfda1fed gaqhf
        {
5743 6b298450 gaqhf
            LMSymbol _LMSymbol = null;
5744 e27329d6 gaqhf
5745
            LMItemNote _LMItemNote = null;
5746
            LMAAttribute _LMAAttribute = null;
5747
5748
            double x = 0;
5749
            double y = 0;
5750
            double angle = text.ANGLE;
5751
            CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation);
5752
5753
            SPPIDUtil.ConvertGridPoint(ref x, ref y);
5754
            text.SPPID.SPPID_X = x;
5755
            text.SPPID.SPPID_Y = y;
5756
5757 4d4dce52 esham21
            _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y, Rotation: angle);
5758 e27329d6 gaqhf
            if (_LMSymbol != null)
5759 6b298450 gaqhf
            {
5760 e27329d6 gaqhf
                _LMSymbol.Commit();
5761
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
5762
                if (_LMItemNote != null)
5763 ea80efaa gaqhf
                {
5764 e27329d6 gaqhf
                    _LMItemNote.Commit();
5765
                    _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
5766
                    if (_LMAAttribute != null)
5767 ea80efaa gaqhf
                    {
5768 4d4dce52 esham21
                        _LMAAttribute.set_Value(text.VALUE);
5769 e27329d6 gaqhf
                        text.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
5770
                        _LMItemNote.Commit();
5771 0860c756 gaqhf
5772
5773 e27329d6 gaqhf
                        double[] range = null;
5774
                        foreach (LMLabelPersist labelPersist in _LMSymbol.LabelPersists)
5775
                        {
5776
                            double[] temp = null;
5777
                            GetSPPIDSymbolRange(labelPersist, ref temp);
5778
                            if (temp != null)
5779
                            {
5780
                                if (range == null)
5781
                                    range = temp;
5782
                                else
5783 0860c756 gaqhf
                                {
5784 e27329d6 gaqhf
                                    range = new double[] {
5785
                                            Math.Min(range[0], temp[0]),
5786
                                            Math.Min(range[1], temp[1]),
5787
                                            Math.Max(range[2], temp[2]),
5788
                                            Math.Max(range[3], temp[3])
5789
                                        };
5790 0860c756 gaqhf
                                }
5791
                            }
5792
                        }
5793 e27329d6 gaqhf
                        text.SPPID.Range = range;
5794
5795
                        if (_LMAAttribute != null)
5796
                            ReleaseCOMObjects(_LMAAttribute);
5797
                        if (_LMItemNote != null)
5798
                            ReleaseCOMObjects(_LMItemNote);
5799 ea80efaa gaqhf
                    }
5800 e27329d6 gaqhf
5801
                    TextCorrectModeling(text);
5802 ea80efaa gaqhf
                }
5803 e27329d6 gaqhf
            }
5804
            if (_LMSymbol != null)
5805
                ReleaseCOMObjects(_LMSymbol);
5806
        }
5807 ea80efaa gaqhf
5808 1ecaaba8 gaqhf
        private void DefaultTextModeling(string value, double x, double y)
5809
        {
5810
            LMSymbol _LMSymbol = null;
5811
5812
            LMItemNote _LMItemNote = null;
5813
            LMAAttribute _LMAAttribute = null;
5814
5815 4d4dce52 esham21
            _LMSymbol = _placement.PIDPlaceSymbol(_ETCSetting.TextSymbolPath, x, y, Rotation: 0);
5816 1ecaaba8 gaqhf
            if (_LMSymbol != null)
5817
            {
5818
                _LMSymbol.Commit();
5819
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
5820
                if (_LMItemNote != null)
5821
                {
5822
                    _LMItemNote.Commit();
5823
                    _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
5824
                    if (_LMAAttribute != null)
5825
                    {
5826 4d4dce52 esham21
                        _LMAAttribute.set_Value(value);
5827 1ecaaba8 gaqhf
                        _LMItemNote.Commit();
5828
5829
                        if (_LMAAttribute != null)
5830
                            ReleaseCOMObjects(_LMAAttribute);
5831
                        if (_LMItemNote != null)
5832
                            ReleaseCOMObjects(_LMItemNote);
5833
                    }
5834
                }
5835
            }
5836
            if (_LMSymbol != null)
5837
                ReleaseCOMObjects(_LMSymbol);
5838
        }
5839
5840 e27329d6 gaqhf
        private void AssociationTextModeling(Text text)
5841
        {
5842
            LMSymbol _LMSymbol = null;
5843
            LMConnector connectedLMConnector = null;
5844
            object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
5845 b0d80571 gaqhf
            if (owner != null && (owner.GetType() == typeof(Symbol) || owner.GetType() == typeof(Equipment)))
5846 e27329d6 gaqhf
            {
5847
                Symbol symbol = owner as Symbol;
5848
                _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
5849
                if (_LMSymbol != null)
5850
                {
5851 8214047e gaqhf
                    foreach (BaseModel.Attribute attribute in symbol.ATTRIBUTES.FindAll(x => x.ASSOCITEM == text.UID))
5852 7f00b26c gaqhf
                    {
5853 8214047e gaqhf
                        if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
5854 7f00b26c gaqhf
                        {
5855 8214047e gaqhf
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
5856 7f00b26c gaqhf
5857 8214047e gaqhf
                            if (mapping != null)
5858 83c14a07 gaqhf
                            {
5859 8214047e gaqhf
                                double x = 0;
5860
                                double y = 0;
5861
5862
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
5863
                                SPPIDUtil.ConvertGridPoint(ref x, ref y);
5864 4d4dce52 esham21
                                Array array = new double[] { 0, x, y };
5865 8214047e gaqhf
                                text.SPPID.SPPID_X = x;
5866
                                text.SPPID.SPPID_Y = y;
5867 4d4dce52 esham21
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
5868 8214047e gaqhf
                                if (_LMLabelPersist != null)
5869
                                {
5870
                                    text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id;
5871
                                    _LMLabelPersist.Commit();
5872
                                    ReleaseCOMObjects(_LMLabelPersist);
5873
                                }
5874 7f00b26c gaqhf
                            }
5875
                        }
5876
                    }
5877 ea80efaa gaqhf
                }
5878 6b298450 gaqhf
            }
5879 e27329d6 gaqhf
            else if (owner != null && owner.GetType() == typeof(Line))
5880 6b298450 gaqhf
            {
5881 e27329d6 gaqhf
                Line line = owner as Line;
5882
                Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
5883
                connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y);
5884 1299077b gaqhf
5885 e27329d6 gaqhf
                if (connectedLMConnector != null)
5886 30ba9ae0 gaqhf
                {
5887 8214047e gaqhf
                    foreach (BaseModel.Attribute attribute in line.ATTRIBUTES.FindAll(x => x.ASSOCITEM == text.UID))
5888 30ba9ae0 gaqhf
                    {
5889 8214047e gaqhf
                        if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
5890 e27329d6 gaqhf
                        {
5891 8214047e gaqhf
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
5892 1299077b gaqhf
5893 8214047e gaqhf
                            if (mapping != null)
5894 1299077b gaqhf
                            {
5895 8214047e gaqhf
                                double x = 0;
5896
                                double y = 0;
5897
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
5898
                                SPPIDUtil.ConvertGridPoint(ref x, ref y);
5899 4d4dce52 esham21
                                Array array = new double[] { 0, x, y };
5900 8214047e gaqhf
5901 4d4dce52 esham21
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
5902 8214047e gaqhf
                                if (_LMLabelPersist != null)
5903 85d3b2eb gaqhf
                                {
5904 8214047e gaqhf
                                    text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id;
5905
                                    _LMLabelPersist.Commit();
5906 85d3b2eb gaqhf
5907 4d4dce52 esham21
                                    DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_LMLabelPersist.get_GraphicOID().ToString()] as DependencyObject;
5908 8214047e gaqhf
                                    if (dependency != null)
5909
                                    {
5910
                                        radApp.ActiveSelectSet.RemoveAll();
5911
                                        radApp.ActiveSelectSet.Add(dependency);
5912
                                        Ingr.RAD2D.Transform transform = dependency.GetTransform();
5913 4d4dce52 esham21
                                        transform.DefineByMove2d(x - _LMLabelPersist.get_XCoordinate(), y - _LMLabelPersist.get_YCoordinate());
5914 8214047e gaqhf
                                        radApp.ActiveSelectSet.Transform(transform, true);
5915
                                        radApp.ActiveSelectSet.RemoveAll();
5916
                                    }
5917
5918
                                    ReleaseCOMObjects(_LMLabelPersist);
5919
                                }
5920 1299077b gaqhf
                            }
5921 30ba9ae0 gaqhf
                        }
5922
                    }
5923
                }
5924 6b298450 gaqhf
            }
5925 7f00b26c gaqhf
            if (_LMSymbol != null)
5926
                ReleaseCOMObjects(_LMSymbol);
5927 cfda1fed gaqhf
        }
5928
5929 e27329d6 gaqhf
        private void TextCorrectModeling(Text text)
5930 1299077b gaqhf
        {
5931 e27329d6 gaqhf
            if (text.SPPID.Range == null)
5932
                return;
5933
5934 1299077b gaqhf
            bool needRemodeling = false;
5935
            bool loop = true;
5936
            GridSetting gridSetting = GridSetting.GetInstance();
5937
            while (loop)
5938
            {
5939
                loop = false;
5940 e27329d6 gaqhf
                foreach (var overlapText in document.TEXTINFOS)
5941 1299077b gaqhf
                {
5942 e27329d6 gaqhf
                    if (overlapText.ASSOCIATION || overlapText == text || overlapText.SPPID.Range == null)
5943
                        continue;
5944
5945 1299077b gaqhf
                    if (SPPIDUtil.IsOverlap(overlapText.SPPID.Range, text.SPPID.Range))
5946
                    {
5947 e27329d6 gaqhf
                        double percentX = 0;
5948
                        double percentY = 0;
5949
                        if (overlapText.X1 <= text.X2 && overlapText.X2 >= text.X1)
5950
                        {
5951
                            double gapX = Math.Min(overlapText.X2, text.X2) - Math.Max(overlapText.X1, text.X1);
5952
                            percentX = Math.Max(gapX / (overlapText.X2 - overlapText.X1), gapX / (text.X2 - text.X1));
5953
                        }
5954
                        if (overlapText.Y1 <= text.Y2 && overlapText.Y2 >= text.Y1)
5955
                        {
5956
                            double gapY = Math.Min(overlapText.Y2, text.Y2) - Math.Max(overlapText.Y1, text.Y1);
5957
                            percentY = Math.Max(gapY / (overlapText.Y2 - overlapText.Y1), gapY / (text.Y2 - text.Y1));
5958
                        }
5959
5960 1299077b gaqhf
                        double tempX = 0;
5961
                        double tempY = 0;
5962
                        bool overlapX = false;
5963
                        bool overlapY = false;
5964
                        SPPIDUtil.CalcOverlap(text.SPPID.Range, overlapText.SPPID.Range, ref tempX, ref tempY, ref overlapX, ref overlapY);
5965 e27329d6 gaqhf
                        if (percentX >= percentY)
5966 1299077b gaqhf
                        {
5967
                            int count = Convert.ToInt32(tempY / gridSetting.Length) + 1;
5968
                            double move = gridSetting.Length * count;
5969
                            text.SPPID.SPPID_Y = text.SPPID.SPPID_Y - move;
5970
                            text.SPPID.Range = new double[] { text.SPPID.Range[0], text.SPPID.Range[1] - move, text.SPPID.Range[2], text.SPPID.Range[3] - move };
5971
                            needRemodeling = true;
5972
                            loop = true;
5973
                        }
5974 e27329d6 gaqhf
                        else
5975 1299077b gaqhf
                        {
5976
                            int count = Convert.ToInt32(tempX / gridSetting.Length) + 1;
5977
                            double move = gridSetting.Length * count;
5978
                            text.SPPID.SPPID_X = text.SPPID.SPPID_X + move;
5979
                            text.SPPID.Range = new double[] { text.SPPID.Range[0] + move, text.SPPID.Range[1], text.SPPID.Range[2] + move, text.SPPID.Range[3] };
5980
                            needRemodeling = true;
5981
                            loop = true;
5982
                        }
5983
                    }
5984
                }
5985
            }
5986 2e69e97c gaqhf
5987 1299077b gaqhf
5988
            if (needRemodeling)
5989
            {
5990
                LMSymbol symbol = dataSource.GetSymbol(text.SPPID.RepresentationId);
5991
                _placement.PIDRemovePlacement(symbol.AsLMRepresentation());
5992
                text.SPPID.RepresentationId = null;
5993
5994
                LMItemNote _LMItemNote = null;
5995
                LMAAttribute _LMAAttribute = null;
5996 4d4dce52 esham21
                LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, text.SPPID.SPPID_X, text.SPPID.SPPID_Y, Rotation: text.ANGLE);
5997 1299077b gaqhf
                if (_LMSymbol != null)
5998
                {
5999
                    _LMSymbol.Commit();
6000
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
6001
                    if (_LMItemNote != null)
6002
                    {
6003
                        _LMItemNote.Commit();
6004
                        _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
6005
                        if (_LMAAttribute != null)
6006
                        {
6007 4d4dce52 esham21
                            _LMAAttribute.set_Value(text.VALUE);
6008 1299077b gaqhf
                            text.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
6009
                            _LMItemNote.Commit();
6010
6011
                            ReleaseCOMObjects(_LMAAttribute);
6012
                            ReleaseCOMObjects(_LMItemNote);
6013
                        }
6014
                    }
6015
                }
6016
6017
                ReleaseCOMObjects(symbol);
6018
                symbol = null;
6019
                ReleaseCOMObjects(_LMItemNote);
6020
                _LMItemNote = null;
6021
                ReleaseCOMObjects(_LMAAttribute);
6022
                _LMAAttribute = null;
6023
                ReleaseCOMObjects(_LMSymbol);
6024
                _LMSymbol = null;
6025
            }
6026
        }
6027
6028 4e865771 gaqhf
        private void AssociationTextCorrectModeling(Text text, List<Text> endTexts)
6029
        {
6030
            if (!string.IsNullOrEmpty(text.SPPID.RepresentationId))
6031
            {
6032 8c7fc81a gaqhf
                List<Text> allTexts = new List<Text>();
6033 4e865771 gaqhf
                LMLabelPersist targetLabel = dataSource.GetLabelPersist(text.SPPID.RepresentationId);
6034
                LMRepresentation representation = targetLabel.RepresentationObject;
6035
                Symbol symbol = document.SYMBOLS.Find(x => x.SPPID.RepresentationId == representation.Id);
6036
                if (targetLabel.RepresentationObject != null && symbol != null)
6037
                {
6038
                    double[] symbolRange = null;
6039
                    GetSPPIDSymbolRange(symbol, ref symbolRange, true, true);
6040
                    if (symbolRange != null)
6041
                    {
6042
                        foreach (LMLabelPersist labelPersist in representation.LabelPersists)
6043
                        {
6044
                            Text findText = document.TEXTINFOS.Find(x => x.SPPID.RepresentationId == labelPersist.AsLMRepresentation().Id && x.ASSOCIATION);
6045
                            if (findText != null)
6046
                            {
6047
                                double[] range = null;
6048
                                GetSPPIDSymbolRange(labelPersist, ref range);
6049
                                findText.SPPID.Range = range;
6050 8c7fc81a gaqhf
                                allTexts.Add(findText);
6051 4e865771 gaqhf
                            }
6052
6053
                            ReleaseCOMObjects(labelPersist);
6054
                        }
6055
6056 8c7fc81a gaqhf
                        if (allTexts.Count > 0)
6057 4e865771 gaqhf
                        {
6058
                            #region Sort Text By Y
6059 8c7fc81a gaqhf
                            allTexts.Sort(SortTextByY);
6060 4e865771 gaqhf
                            int SortTextByY(Text a, Text b)
6061
                            {
6062
                                return b.SPPID.Range[3].CompareTo(a.SPPID.Range[3]);
6063
                            }
6064
                            #endregion
6065
6066 8c7fc81a gaqhf
                            #region 정렬하기전 방향
6067
                            List<Text> left = new List<Text>();
6068
                            List<Text> down = new List<Text>();
6069
                            List<Text> right = new List<Text>();
6070
                            List<Text> up = new List<Text>();
6071
                            List<List<Text>> sortTexts = new List<List<Text>>() { left, down, right, up };
6072
                            foreach (var loopText in allTexts)
6073 4e865771 gaqhf
                            {
6074 8c7fc81a gaqhf
                                double textCenterX = (loopText.X1 + loopText.X2) / 2;
6075
                                double textCenterY = (loopText.Y1 + loopText.Y2) / 2;
6076
                                double originX = 0;
6077
                                double originY = 0;
6078
                                SPPIDUtil.ConvertPointBystring(symbol.ORIGINALPOINT, ref originX, ref originY);
6079
                                double angle = SPPIDUtil.CalcAngle(textCenterX, textCenterY, originX, originY);
6080
6081
                                if (angle < 45)
6082
                                {
6083
                                    // Text 오른쪽
6084
                                    if (textCenterX > originX)
6085
                                        right.Add(loopText);
6086
                                    // Text 왼쪽
6087
                                    else
6088 2e69e97c gaqhf
                                        left.Add(loopText);
6089 8c7fc81a gaqhf
                                }
6090
                                else
6091 4e865771 gaqhf
                                {
6092 8c7fc81a gaqhf
                                    // Text 아래쪽
6093
                                    if (textCenterY > originY)
6094
                                        down.Add(loopText);
6095
                                    // Text 위쪽
6096
                                    else
6097
                                        up.Add(loopText);
6098 4e865771 gaqhf
                                }
6099
                            }
6100 2e69e97c gaqhf
6101 4e865771 gaqhf
                            #endregion
6102
6103 8c7fc81a gaqhf
                            foreach (var texts in sortTexts)
6104 4e865771 gaqhf
                            {
6105 2e69e97c gaqhf
                                if (texts.Count == 0)
6106 8c7fc81a gaqhf
                                    continue;
6107 2e69e97c gaqhf
6108 8c7fc81a gaqhf
                                #region 첫번째 Text로 기준 맞춤
6109
                                for (int i = 0; i < texts.Count; i++)
6110 4e865771 gaqhf
                                {
6111 8c7fc81a gaqhf
                                    if (i != 0)
6112
                                    {
6113
                                        Text currentText = texts[i];
6114
                                        Text prevText = texts[i - 1];
6115
                                        double minY = prevText.SPPID.Range[1];
6116
                                        double centerPrevX = (prevText.SPPID.Range[0] + prevText.SPPID.Range[2]) / 2;
6117
                                        double centerX = (currentText.SPPID.Range[0] + currentText.SPPID.Range[2]) / 2;
6118
                                        double _gapX = centerX - centerPrevX;
6119
                                        double _gapY = currentText.SPPID.Range[3] - minY;
6120
                                        MoveText(currentText, _gapX, _gapY);
6121
                                    }
6122 4e865771 gaqhf
                                }
6123 8c7fc81a gaqhf
                                List<double> rangeMinX = texts.Select(loopX => loopX.SPPID.Range[0]).ToList();
6124
                                List<double> rangeMinY = texts.Select(loopX => loopX.SPPID.Range[1]).ToList();
6125
                                List<double> rangeMaxX = texts.Select(loopX => loopX.SPPID.Range[2]).ToList();
6126
                                List<double> rangeMaxY = texts.Select(loopX => loopX.SPPID.Range[3]).ToList();
6127
                                rangeMinX.Sort();
6128
                                rangeMinY.Sort();
6129
                                rangeMaxX.Sort();
6130
                                rangeMaxY.Sort();
6131
                                double allTextCenterX = (rangeMinX[0] + rangeMaxX[rangeMaxX.Count - 1]) / 2;
6132
                                double allTextCenterY = (rangeMinY[0] + rangeMaxY[rangeMaxY.Count - 1]) / 2;
6133
                                #endregion
6134
                                #region 정렬
6135
                                Text correctBySymbol = texts[0];
6136
                                double textCenterX = (correctBySymbol.X1 + correctBySymbol.X2) / 2;
6137
                                double textCenterY = (correctBySymbol.Y1 + correctBySymbol.Y2) / 2;
6138
                                double originX = 0;
6139
                                double originY = 0;
6140
                                SPPIDUtil.ConvertPointBystring(symbol.ORIGINALPOINT, ref originX, ref originY);
6141
                                double angle = SPPIDUtil.CalcAngle(textCenterX, textCenterY, originX, originY);
6142
                                double symbolCenterX = (symbolRange[0] + symbolRange[2]) / 2;
6143
                                double symbolCenterY = (symbolRange[1] + symbolRange[3]) / 2;
6144
6145
                                double gapX = 0;
6146
                                double gapY = 0;
6147
                                if (angle < 45)
6148 4e865771 gaqhf
                                {
6149 8c7fc81a gaqhf
                                    // Text 오른쪽
6150
                                    if (textCenterX > originX)
6151
                                    {
6152
                                        gapX = rangeMinX[0] - symbolRange[2];
6153
                                        gapY = allTextCenterY - symbolCenterY;
6154
                                    }
6155
                                    // Text 왼쪽
6156
                                    else
6157
                                    {
6158
                                        gapX = rangeMaxX[rangeMaxX.Count - 1] - symbolRange[0];
6159
                                        gapY = allTextCenterY - symbolCenterY;
6160
                                    }
6161 4e865771 gaqhf
                                }
6162
                                else
6163
                                {
6164 8c7fc81a gaqhf
                                    // Text 아래쪽
6165
                                    if (textCenterY > originY)
6166
                                    {
6167
                                        gapX = allTextCenterX - symbolCenterX;
6168
                                        gapY = rangeMaxY[rangeMaxY.Count - 1] - symbolRange[1];
6169
                                    }
6170
                                    // Text 위쪽
6171
                                    else
6172
                                    {
6173
                                        gapX = allTextCenterX - symbolCenterX;
6174
                                        gapY = rangeMinY[0] - symbolRange[3];
6175
                                    }
6176 4e865771 gaqhf
                                }
6177
6178 8c7fc81a gaqhf
                                foreach (var item in texts)
6179
                                {
6180
                                    MoveText(item, gapX, gapY);
6181
                                    RemodelingAssociationText(item);
6182
                                }
6183
                                #endregion
6184 4e865771 gaqhf
                            }
6185
                        }
6186
                    }
6187
                }
6188
6189
                void MoveText(Text moveText, double x, double y)
6190
                {
6191
                    moveText.SPPID.SPPID_X = moveText.SPPID.SPPID_X - x;
6192
                    moveText.SPPID.SPPID_Y = moveText.SPPID.SPPID_Y - y;
6193
                    moveText.SPPID.Range = new double[] {
6194
                        moveText.SPPID.Range[0] - x,
6195
                        moveText.SPPID.Range[1]- y,
6196
                        moveText.SPPID.Range[2]- x,
6197
                        moveText.SPPID.Range[3]- y
6198
                    };
6199
                }
6200
6201 8c7fc81a gaqhf
                endTexts.AddRange(allTexts);
6202 4e865771 gaqhf
6203
                ReleaseCOMObjects(targetLabel);
6204
                targetLabel = null;
6205
                ReleaseCOMObjects(representation);
6206
                representation = null;
6207
            }
6208
        }
6209
6210
        private void RemodelingAssociationText(Text text)
6211
        {
6212
            LMLabelPersist removeLabel = dataSource.GetLabelPersist(text.SPPID.RepresentationId);
6213
            _placement.PIDRemovePlacement(removeLabel.AsLMRepresentation());
6214
            removeLabel.Commit();
6215
            ReleaseCOMObjects(removeLabel);
6216
            removeLabel = null;
6217
6218
            object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
6219
            if (owner != null && owner.GetType() == typeof(Symbol))
6220
            {
6221
                Symbol symbol = owner as Symbol;
6222 4d4dce52 esham21
                _LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
6223 4e865771 gaqhf
                if (_LMSymbol != null)
6224
                {
6225
                    BaseModel.Attribute attribute = symbol.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
6226
                    if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
6227
                    {
6228
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
6229
6230
                        if (mapping != null)
6231
                        {
6232
                            double x = 0;
6233
                            double y = 0;
6234
6235 4d4dce52 esham21
                            Array array = new double[] { 0, text.SPPID.SPPID_X, text.SPPID.SPPID_Y };
6236
                            LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
6237 4e865771 gaqhf
                            if (_LMLabelPersist != null)
6238
                            {
6239
                                text.SPPID.RepresentationId = _LMLabelPersist.AsLMRepresentation().Id;
6240
                                _LMLabelPersist.Commit();
6241
                            }
6242
                            ReleaseCOMObjects(_LMLabelPersist);
6243
                            _LMLabelPersist = null;
6244
                        }
6245
                    }
6246
                }
6247
                ReleaseCOMObjects(_LMSymbol);
6248
                _LMSymbol = null;
6249
            }
6250
        }
6251
6252 74752074 gaqhf
        /// <summary>
6253
        /// Note Modeling
6254
        /// </summary>
6255
        /// <param name="note"></param>
6256 1299077b gaqhf
        private void NoteModeling(Note note, List<Note> correctList)
6257 cfda1fed gaqhf
        {
6258 6b298450 gaqhf
            LMSymbol _LMSymbol = null;
6259
            LMItemNote _LMItemNote = null;
6260
            LMAAttribute _LMAAttribute = null;
6261
6262 7f00b26c gaqhf
            if (string.IsNullOrEmpty(note.OWNER) || note.OWNER == "None")
6263 6b298450 gaqhf
            {
6264 7f00b26c gaqhf
                double x = 0;
6265
                double y = 0;
6266 fc0a8c33 gaqhf
6267 7f00b26c gaqhf
                CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation);
6268 1299077b gaqhf
                SPPIDUtil.ConvertGridPoint(ref x, ref y);
6269
                note.SPPID.SPPID_X = x;
6270
                note.SPPID.SPPID_Y = y;
6271 fc0a8c33 gaqhf
6272 7f00b26c gaqhf
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y);
6273 30ba9ae0 gaqhf
                if (_LMSymbol != null)
6274
                {
6275
                    _LMSymbol.Commit();
6276
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
6277
                    if (_LMItemNote != null)
6278
                    {
6279
                        _LMItemNote.Commit();
6280
                        _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
6281
                        if (_LMAAttribute != null)
6282
                        {
6283 4d4dce52 esham21
                            _LMAAttribute.set_Value(note.VALUE);
6284 30ba9ae0 gaqhf
                            note.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
6285 1299077b gaqhf
6286
                            double[] range = null;
6287
                            foreach (LMLabelPersist labelPersist in _LMSymbol.LabelPersists)
6288
                            {
6289
                                double[] temp = null;
6290
                                GetSPPIDSymbolRange(labelPersist, ref temp);
6291
                                if (temp != null)
6292
                                {
6293
                                    if (range == null)
6294
                                        range = temp;
6295
                                    else
6296
                                    {
6297
                                        range = new double[] {
6298
                                            Math.Min(range[0], temp[0]),
6299
                                            Math.Min(range[1], temp[1]),
6300
                                            Math.Max(range[2], temp[2]),
6301
                                            Math.Max(range[3], temp[3])
6302
                                        };
6303
                                    }
6304
                                }
6305
                            }
6306
                            if (range != null)
6307
                                correctList.Add(note);
6308
                            note.SPPID.Range = range;
6309
6310
6311 30ba9ae0 gaqhf
                            _LMItemNote.Commit();
6312
                        }
6313
                    }
6314
                }
6315 6b298450 gaqhf
            }
6316 cfda1fed gaqhf
6317 7f00b26c gaqhf
            if (_LMAAttribute != null)
6318
                ReleaseCOMObjects(_LMAAttribute);
6319
            if (_LMItemNote != null)
6320
                ReleaseCOMObjects(_LMItemNote);
6321
            if (_LMSymbol != null)
6322
                ReleaseCOMObjects(_LMSymbol);
6323 cfda1fed gaqhf
        }
6324
6325 1299077b gaqhf
        private void NoteCorrectModeling(Note note, List<Note> endList)
6326
        {
6327
            bool needRemodeling = false;
6328
            bool loop = true;
6329
            GridSetting gridSetting = GridSetting.GetInstance();
6330
            while (loop)
6331
            {
6332
                loop = false;
6333
                foreach (var overlap in endList)
6334
                {
6335 ba25c427 gaqhf
                    if (SPPIDUtil.IsOverlap(overlap.SPPID.Range, note.SPPID.Range))
6336 1299077b gaqhf
                    {
6337 ba25c427 gaqhf
                        double tempX = 0;
6338
                        double tempY = 0;
6339
                        bool overlapX = false;
6340
                        bool overlapY = false;
6341
                        SPPIDUtil.CalcOverlap(note.SPPID.Range, overlap.SPPID.Range, ref tempX, ref tempY, ref overlapX, ref overlapY);
6342
                        double angle = SPPIDUtil.CalcAngle(note.LOCATION_X, note.LOCATION_Y, overlap.LOCATION_X, overlap.LOCATION_Y);
6343
                        if (overlapY && angle >= 45)
6344 1299077b gaqhf
                        {
6345 ba25c427 gaqhf
                            int count = Convert.ToInt32(tempY / gridSetting.Length) + 1;
6346
                            double move = gridSetting.Length * count;
6347
                            note.SPPID.SPPID_Y = note.SPPID.SPPID_Y - move;
6348
                            note.SPPID.Range = new double[] { note.SPPID.Range[0], note.SPPID.Range[1] - move, note.SPPID.Range[2], note.SPPID.Range[3] - move };
6349
                            needRemodeling = true;
6350
                            loop = true;
6351
                        }
6352
                        if (overlapX && angle <= 45)
6353
                        {
6354
                            int count = Convert.ToInt32(tempX / gridSetting.Length) + 1;
6355
                            double move = gridSetting.Length * count;
6356
                            note.SPPID.SPPID_X = note.SPPID.SPPID_X + move;
6357
                            note.SPPID.Range = new double[] { note.SPPID.Range[0] + move, note.SPPID.Range[1], note.SPPID.Range[2] + move, note.SPPID.Range[3] };
6358
                            needRemodeling = true;
6359
                            loop = true;
6360 1299077b gaqhf
                        }
6361
                    }
6362
                }
6363
            }
6364
6365
6366
            if (needRemodeling)
6367
            {
6368
                LMSymbol symbol = dataSource.GetSymbol(note.SPPID.RepresentationId);
6369
                _placement.PIDRemovePlacement(symbol.AsLMRepresentation());
6370
                note.SPPID.RepresentationId = null;
6371
6372
                LMItemNote _LMItemNote = null;
6373
                LMAAttribute _LMAAttribute = null;
6374 4d4dce52 esham21
                LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, note.SPPID.SPPID_X, note.SPPID.SPPID_Y, Rotation: note.ANGLE);
6375 1299077b gaqhf
                if (_LMSymbol != null)
6376
                {
6377
                    _LMSymbol.Commit();
6378
                    _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
6379
                    if (_LMItemNote != null)
6380
                    {
6381
                        _LMItemNote.Commit();
6382
                        _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
6383
                        if (_LMAAttribute != null)
6384
                        {
6385 4d4dce52 esham21
                            _LMAAttribute.set_Value(note.VALUE);
6386 1299077b gaqhf
                            note.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
6387
                            _LMItemNote.Commit();
6388
6389
                            ReleaseCOMObjects(_LMAAttribute);
6390
                            ReleaseCOMObjects(_LMItemNote);
6391
                        }
6392
                    }
6393
                }
6394
6395
                ReleaseCOMObjects(symbol);
6396
                symbol = null;
6397
                ReleaseCOMObjects(_LMItemNote);
6398
                _LMItemNote = null;
6399
                ReleaseCOMObjects(_LMAAttribute);
6400
                _LMAAttribute = null;
6401
                ReleaseCOMObjects(_LMSymbol);
6402
                _LMSymbol = null;
6403
            }
6404
6405
            endList.Add(note);
6406
        }
6407
6408 a31a512e gaqhf
        private void JoinRunBySameType(string modelItemId, ref string survivorId)
6409 ca6e0f51 gaqhf
        {
6410 a31a512e gaqhf
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
6411
            if (modelItem != null)
6412 ca6e0f51 gaqhf
            {
6413 a31a512e gaqhf
                foreach (LMRepresentation rep in modelItem.Representations)
6414
                {
6415 4d4dce52 esham21
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
6416 a31a512e gaqhf
                    {
6417
                        LMConnector connector = dataSource.GetConnector(rep.Id);
6418 4d4dce52 esham21
                        if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch")
6419 a31a512e gaqhf
                        {
6420
                            LMSymbol symbol = connector.ConnectItem1SymbolObject;
6421
                            List<string> modelItemIds = FindOtherModelItemBySymbolWhereTypePipeRun(symbol, modelItem.Id);
6422
                            if (modelItemIds.Count == 1)
6423
                            {
6424 d77973b3 gaqhf
                                string joinModelItemId = modelItemIds[0];
6425 63a112d9 gaqhf
                                JoinRun(joinModelItemId, modelItemId, ref survivorId, false);
6426 a31a512e gaqhf
                                if (survivorId != null)
6427
                                    break;
6428
                            }
6429
                        }
6430 4d4dce52 esham21
                        if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch")
6431 a31a512e gaqhf
                        {
6432
                            LMSymbol symbol = connector.ConnectItem2SymbolObject;
6433
                            List<string> modelItemIds = FindOtherModelItemBySymbolWhereTypePipeRun(symbol, modelItem.Id);
6434
                            if (modelItemIds.Count == 1)
6435
                            {
6436 d77973b3 gaqhf
                                string joinModelItemId = modelItemIds[0];
6437 63a112d9 gaqhf
                                JoinRun(joinModelItemId, modelItemId, ref survivorId, false);
6438 a31a512e gaqhf
                                if (survivorId != null)
6439
                                    break;
6440
                            }
6441
                        }
6442
                    }
6443
                }
6444 ca6e0f51 gaqhf
            }
6445 dec9ecfd gaqhf
        }
6446
6447 d9794a6c gaqhf
        /// <summary>
6448 74752074 gaqhf
        /// Label의 좌표를 구하는 메서드(ID2 기준의 좌표 -> SPPID 좌표)
6449
        /// </summary>
6450
        /// <param name="x"></param>
6451
        /// <param name="y"></param>
6452
        /// <param name="originX"></param>
6453
        /// <param name="originY"></param>
6454
        /// <param name="SPPIDLabelLocation"></param>
6455
        /// <param name="location"></param>
6456 b65a7e32 gaqhf
        private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location)
6457
        {
6458
            if (location == Location.None)
6459
            {
6460
                x = originX;
6461
                y = originY;
6462
            }
6463
            else
6464
            {
6465
                if (location.HasFlag(Location.Center))
6466
                {
6467
                    x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2;
6468
                    y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2;
6469
                }
6470
6471
                if (location.HasFlag(Location.Left))
6472
                    x = SPPIDLabelLocation.X1;
6473
                else if (location.HasFlag(Location.Right))
6474
                    x = SPPIDLabelLocation.X2;
6475
6476
                if (location.HasFlag(Location.Down))
6477
                    y = SPPIDLabelLocation.Y1;
6478
                else if (location.HasFlag(Location.Up))
6479
                    y = SPPIDLabelLocation.Y2;
6480
            }
6481
        }
6482 5a4b8f32 gaqhf
6483 74752074 gaqhf
        /// <summary>
6484 4d2571ab gaqhf
        /// Symbol의 우선순위 Modeling 목록을 가져온다.
6485
        /// 1. Angle Valve
6486
        /// 2. 3개로 이루어진 Symbol Group
6487
        /// </summary>
6488
        /// <returns></returns>
6489
        private List<Symbol> GetPrioritySymbol()
6490
        {
6491
            DataTable symbolTable = document.SymbolTable;
6492
            // List에 순서대로 쌓는다.
6493
            List<Symbol> symbols = new List<Symbol>();
6494 3734dcc5 gaqhf
6495 4d2571ab gaqhf
            // Angle Valve 부터
6496 d9794a6c gaqhf
            foreach (var symbol in document.SYMBOLS.FindAll(x => x.CONNECTORS.FindAll(y => y.Index == 0).Count == 2))
6497 4d2571ab gaqhf
            {
6498
                if (!symbols.Contains(symbol))
6499
                {
6500
                    double originX = 0;
6501
                    double originY = 0;
6502
6503
                    // ID2 Table에서 Original Point 가져옴.
6504 7f00b26c gaqhf
                    string OriginalPoint = symbolTable.Select(string.Format("UID = {0}", symbol.DBUID))[0]["OriginalPoint"].ToString();
6505 4d2571ab gaqhf
                    SPPIDUtil.ConvertPointBystring(OriginalPoint, ref originX, ref originY);
6506
6507
                    SlopeType slopeType1 = SlopeType.None;
6508
                    SlopeType slopeType2 = SlopeType.None;
6509 d9794a6c gaqhf
                    foreach (Connector connector in symbol.CONNECTORS.FindAll(x => x.Index == 0))
6510 4d2571ab gaqhf
                    {
6511
                        double connectorX = 0;
6512
                        double connectorY = 0;
6513
                        SPPIDUtil.ConvertPointBystring(connector.CONNECTPOINT, ref connectorX, ref connectorY);
6514
                        if (slopeType1 == SlopeType.None)
6515
                            slopeType1 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
6516
                        else
6517
                            slopeType2 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
6518
                    }
6519
6520
                    if ((slopeType1 == SlopeType.VERTICAL && slopeType2 == SlopeType.HORIZONTAL) ||
6521
                        (slopeType2 == SlopeType.VERTICAL && slopeType1 == SlopeType.HORIZONTAL))
6522
                        symbols.Add(symbol);
6523
                }
6524
            }
6525
6526 f1a7faf9 gaqhf
            List<Symbol> tempSymbols = new List<Symbol>();
6527
            // Conn 갯수 기준
6528 d9794a6c gaqhf
            foreach (var item in document.SYMBOLS)
6529
            {
6530 f1a7faf9 gaqhf
                if (!symbols.Contains(item))
6531
                    tempSymbols.Add(item);
6532 d9794a6c gaqhf
            }
6533 20f9fa83 Denny
            tempSymbols.Sort(SPPIDUtil.SortSymbolPriority);
6534 f1a7faf9 gaqhf
            symbols.AddRange(tempSymbols);
6535 4d2571ab gaqhf
6536
            return symbols;
6537
        }
6538
6539 cf210438 gaqhf
        private void SetPriorityLine(List<Line> lines)
6540 d63050d6 gaqhf
        {
6541 cf210438 gaqhf
            lines.Sort(SortLinePriority);
6542 d63050d6 gaqhf
6543
            int SortLinePriority(Line a, Line b)
6544
            {
6545
                // Branch 없는것부터
6546
                int branchRetval = CompareBranchLine(a, b);
6547
                if (branchRetval != 0)
6548
                {
6549
                    return branchRetval;
6550
                }
6551
                else
6552
                {
6553
                    // Symbol 연결 갯수
6554
                    int connSymbolRetval = CompareConnSymbol(a, b);
6555
                    if (connSymbolRetval != 0)
6556
                    {
6557
                        return connSymbolRetval;
6558
                    }
6559
                    else
6560
                    {
6561 24515a3a gaqhf
                        // 아이템 연결 갯수(심볼, Line이면서 Not Branch)
6562
                        int connItemRetval = CompareConnItem(a, b);
6563
                        if (connItemRetval != 0)
6564 d63050d6 gaqhf
                        {
6565 24515a3a gaqhf
                            return connItemRetval;
6566 d63050d6 gaqhf
                        }
6567
                        else
6568
                        {
6569 24515a3a gaqhf
                            // ConnectedItem이 없는것
6570
                            int noneConnRetval = CompareNoneConn(a, b);
6571
                            if (noneConnRetval != 0)
6572 d63050d6 gaqhf
                            {
6573 24515a3a gaqhf
                                return noneConnRetval;
6574 d63050d6 gaqhf
                            }
6575
                            else
6576
                            {
6577
6578
                            }
6579
                        }
6580
                    }
6581
                }
6582
6583
                return 0;
6584
            }
6585
6586 e283d483 gaqhf
            int CompareNotSegmentLine(Line a, Line b)
6587
            {
6588
                List<Connector> connectorsA = a.CONNECTORS
6589
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
6590
                    .ToList();
6591
6592
                List<Connector> connectorsB = b.CONNECTORS
6593
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
6594
                    .ToList();
6595
6596
                // 오름차순
6597
                return connectorsB.Count.CompareTo(connectorsA.Count);
6598
            }
6599
6600 d63050d6 gaqhf
            int CompareConnSymbol(Line a, Line b)
6601
            {
6602
                List<Connector> connectorsA = a.CONNECTORS
6603
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
6604
                    .ToList();
6605
6606
                List<Connector> connectorsB = b.CONNECTORS
6607
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
6608
                    .ToList();
6609
6610
                // 오름차순
6611
                return connectorsB.Count.CompareTo(connectorsA.Count);
6612
            }
6613
6614
            int CompareConnItem(Line a, Line b)
6615
            {
6616
                List<Connector> connectorsA = a.CONNECTORS
6617 2e69e97c gaqhf
                    .Where(conn => conn.ConnectedObject != null &&
6618
                    (conn.ConnectedObject.GetType() == typeof(Symbol) ||
6619 d63050d6 gaqhf
                    (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, a))))
6620
                    .ToList();
6621
6622
                List<Connector> connectorsB = b.CONNECTORS
6623
                    .Where(conn => conn.ConnectedObject != null &&
6624
                    (conn.ConnectedObject.GetType() == typeof(Symbol) ||
6625
                    (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, b))))
6626
                    .ToList();
6627
6628
                // 오름차순
6629
                return connectorsB.Count.CompareTo(connectorsA.Count);
6630
            }
6631
6632
            int CompareBranchLine(Line a, Line b)
6633
            {
6634
                List<Connector> connectorsA = a.CONNECTORS
6635
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(a, conn.ConnectedObject as Line))
6636
                    .ToList();
6637
                List<Connector> connectorsB = b.CONNECTORS
6638
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(b, conn.ConnectedObject as Line))
6639
                    .ToList();
6640
6641
                // 내림차순
6642
                return connectorsA.Count.CompareTo(connectorsB.Count);
6643
            }
6644
6645
            int CompareNoneConn(Line a, Line b)
6646
            {
6647
                List<Connector> connectorsA = a.CONNECTORS
6648
                    .Where(conn => conn.ConnectedObject == null)
6649
                    .ToList();
6650
6651
                List<Connector> connectorsB = b.CONNECTORS
6652
                    .Where(conn => conn.ConnectedObject == null)
6653
                    .ToList();
6654
6655
                // 오름차순
6656
                return connectorsB.Count.CompareTo(connectorsA.Count);
6657
            }
6658
        }
6659
6660 1299077b gaqhf
        private void SortText(List<Text> texts)
6661
        {
6662
            texts.Sort(Sort);
6663
6664
            int Sort(Text a, Text b)
6665
            {
6666
                int yRetval = CompareY(a, b);
6667
                if (yRetval != 0)
6668
                {
6669
                    return yRetval;
6670
                }
6671
                else
6672
                {
6673
                    return CompareX(a, b);
6674
                }
6675
            }
6676
6677
            int CompareY(Text a, Text b)
6678
            {
6679
                return a.LOCATION_Y.CompareTo(b.LOCATION_Y);
6680
            }
6681
6682
            int CompareX(Text a, Text b)
6683
            {
6684
                return a.LOCATION_X.CompareTo(b.LOCATION_X);
6685
            }
6686
        }
6687
        private void SortNote(List<Note> notes)
6688
        {
6689
            notes.Sort(Sort);
6690
6691
            int Sort(Note a, Note b)
6692
            {
6693
                int yRetval = CompareY(a, b);
6694
                if (yRetval != 0)
6695
                {
6696
                    return yRetval;
6697
                }
6698
                else
6699
                {
6700
                    return CompareX(a, b);
6701
                }
6702
            }
6703
6704
            int CompareY(Note a, Note b)
6705
            {
6706
                return a.LOCATION_Y.CompareTo(b.LOCATION_Y);
6707
            }
6708
6709
            int CompareX(Note a, Note b)
6710
            {
6711
                return a.LOCATION_X.CompareTo(b.LOCATION_X);
6712
            }
6713
        }
6714
6715 a0e3dca4 gaqhf
        private void SortBranchLines()
6716
        {
6717 f3e2693f gaqhf
            BranchLines.Sort(SortBranchLine);
6718 a0e3dca4 gaqhf
            int SortBranchLine(Line a, Line b)
6719
            {
6720
                int countA = a.CONNECTORS.FindAll(x => x.ConnectedObject != null &&
6721
                 x.ConnectedObject.GetType() == typeof(Line) &&
6722
                 SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, a) &&
6723
                 string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count;
6724
6725
                int countB = b.CONNECTORS.FindAll(x => x.ConnectedObject != null &&
6726
                 x.ConnectedObject.GetType() == typeof(Line) &&
6727
                 SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, b) &&
6728
                 string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count;
6729
6730
                // 내림차순
6731
                return countA.CompareTo(countB);
6732
            }
6733
        }
6734
6735 20f9fa83 Denny
        
6736 f1a7faf9 gaqhf
6737 a31a512e gaqhf
        private string GetSPPIDFileName(LMModelItem modelItem)
6738
        {
6739
            string symbolPath = null;
6740
            foreach (LMRepresentation rep in modelItem.Representations)
6741
            {
6742 4d4dce52 esham21
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
6743 a31a512e gaqhf
                {
6744 4d4dce52 esham21
                    symbolPath = rep.get_FileName();
6745 a31a512e gaqhf
                    break;
6746
                }
6747
            }
6748
            return symbolPath;
6749
        }
6750
6751 82d6e5ea gaqhf
        private string GetSPPIDFileName(string modelItemId)
6752
        {
6753
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
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 82d6e5ea gaqhf
                {
6759 4d4dce52 esham21
                    symbolPath = rep.get_FileName();
6760 82d6e5ea gaqhf
                    break;
6761
                }
6762
            }
6763
            ReleaseCOMObjects(modelItem);
6764
            return symbolPath;
6765
        }
6766
6767 4d2571ab gaqhf
        /// <summary>
6768 4d4dce52 esham21
        /// Graphic OID로 해당 Symbol의 크기를 구하여 Zoom
6769
        /// </summary>
6770
        /// <param name="graphicOID"></param>
6771
        /// <param name="milliseconds"></param>
6772
        private void ZoomObjectByGraphicOID(string graphicOID, int milliseconds = 150)
6773
        {
6774
            if (radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] != null)
6775
            {
6776
                double minX = 0;
6777
                double minY = 0;
6778
                double maxX = 0;
6779
                double maxY = 0;
6780
                radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID].Range(out minX, out minY, out maxX, out maxY);
6781
                radApp.ActiveWindow.ZoomArea2(minX - 0.007, minY - 0.007, maxX + 0.007, maxY + 0.007, null);
6782
6783
                Thread.Sleep(milliseconds);
6784
            }
6785
        }
6786
6787
        /// <summary>
6788 74752074 gaqhf
        /// ComObject를 Release
6789
        /// </summary>
6790
        /// <param name="objVars"></param>
6791 5a4b8f32 gaqhf
        public void ReleaseCOMObjects(params object[] objVars)
6792
        {
6793 02a45794 gaqhf
            if (objVars != null)
6794 5a4b8f32 gaqhf
            {
6795 02a45794 gaqhf
                int intNewRefCount = 0;
6796
                foreach (object obj in objVars)
6797
                {
6798
                    if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
6799
                        intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
6800
                }
6801 5a4b8f32 gaqhf
            }
6802
        }
6803 5a9396ae humkyung
6804
        /// IDisposable 구현
6805
        ~AutoModeling()
6806
        {
6807
            this.Dispose(false);
6808
        }
6809
6810
        private bool disposed;
6811
        public void Dispose()
6812
        {
6813
            this.Dispose(true);
6814
            GC.SuppressFinalize(this);
6815
        }
6816
6817
        protected virtual void Dispose(bool disposing)
6818
        {
6819
            if (this.disposed) return;
6820
            if (disposing)
6821
            {
6822
                // IDisposable 인터페이스를 구현하는 멤버들을 여기서 정리합니다.
6823
            }
6824
            // .NET Framework에 의하여 관리되지 않는 외부 리소스들을 여기서 정리합니다.
6825
            this.disposed = true;
6826
        }
6827 cfda1fed gaqhf
    }
6828
}
클립보드 이미지 추가 (최대 크기: 500 MB)