프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ baa87c88

이력 | 보기 | 이력해설 | 다운로드 (330 KB)

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