프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 46fa58bd

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