프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ cd53e782

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