프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 5a25b6b0

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