프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ f9cc5190

이력 | 보기 | 이력해설 | 다운로드 (169 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
    public class AutoModeling
28
    {
29 809a7640 gaqhf
        Placement _placement;
30
        LMADataSource dataSource;
31 7aee331b gaqhf
        LMDrawing currentDrawing;
32 1ba9c671 gaqhf
        dynamic newDrawing;
33 d19ae675 gaqhf
        dynamic application;
34 5e6ecf05 gaqhf
        Ingr.RAD2D.Application radApp;
35 cfda1fed gaqhf
        SPPID_Document document;
36 b65a7e32 gaqhf
        ETCSetting _ETCSetting;
37 f1c9dbaa gaqhf
38 d5ec4d0f gaqhf
        public string DocumentLabelText { get; set; }
39
40 a0e3dca4 gaqhf
        List<Line> NewBranchLines = new List<Line>();
41 69b7387a gaqhf
        List<Tuple<string, Line, Line>> BranchLines = new List<Tuple<string, Line, Line>>();
42 644f40b3 gaqhf
        List<string> ZeroLengthSymbolToSymbolModelItemID = new List<string>();
43 87f02fc0 gaqhf
        List<string> ZeroLengthModelItemID = new List<string>();
44 1ff0105e gaqhf
        List<string> ZeroLengthModelItemIDReverse = new List<string>();
45 f1a7faf9 gaqhf
        List<Symbol> prioritySymbols;
46 47ad9a46 gaqhf
47 d19ae675 gaqhf
        public AutoModeling(SPPID_Document document, dynamic application, Ingr.RAD2D.Application radApp)
48 cfda1fed gaqhf
        {
49
            this.document = document;
50 d19ae675 gaqhf
            this.application = application;
51 5e6ecf05 gaqhf
            this.radApp = radApp;
52 b65a7e32 gaqhf
            this._ETCSetting = ETCSetting.GetInstance();
53 cfda1fed gaqhf
        }
54
55 02480ac1 gaqhf
        private void SetSystemEditingCommand(bool value)
56
        {
57
            foreach (var item in radApp.Commands)
58
            {
59
                if (item.Argument == "SystemEditingCmd.SystemEditing")
60
                {
61
                    if (item.Checked != value)
62
                    {
63
                        radApp.RunMacro("systemeditingcmd.dll");
64
                        break;
65
                    }
66
67
                }
68
            }
69
        }
70
71 74752074 gaqhf
        /// <summary>
72
        /// 도면 단위당 실행되는 메서드
73
        /// </summary>
74 1ba9c671 gaqhf
        public void Run()
75 c2fef4ca gaqhf
        {
76 224535bb gaqhf
            string drawingNumber = document.DrawingNumber;
77
            string drawingName = document.DrawingName;
78 1ba9c671 gaqhf
            try
79 c2fef4ca gaqhf
            {
80 1ba9c671 gaqhf
                _placement = new Placement();
81
                dataSource = _placement.PIDDataSource;
82
83 224535bb gaqhf
                CreateDocument(ref drawingNumber, ref drawingName);
84 1ba9c671 gaqhf
85 0e0edfad gaqhf
                if (DocumentCoordinateCorrection())
86 310aeb31 gaqhf
                {
87 3734dcc5 gaqhf
                    Log.Write("Start Modeling");
88 965eb728 gaqhf
                    SplashScreenManager.ShowForm(typeof(SPPIDSplashScreen), true, true);
89 9628f54b gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetParent, (IntPtr)radApp.HWnd);
90 f9cc5190 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllStepCount, 15);
91 20972c61 gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetDocumentName, DocumentLabelText);
92 f9cc5190 gaqhf
93 6db30942 gaqhf
                    // Equipment Modeling
94 b01e7456 gaqhf
                    RunEquipmentModeling();
95
                    // Symbol Modeling
96
                    RunSymbolModeling();
97 3939eebf gaqhf
                    // LineRun Line Modeling
98 b01e7456 gaqhf
                    RunLineModeling();
99
                    // Branch Line Modeling
100
                    RunBranchLineModeling();
101
                    // Clear Attribute
102 1ff0105e gaqhf
                    RunClearValueInconsistancy();
103 b01e7456 gaqhf
                    // EndBreak Modeling
104
                    RunEndBreakModeling();
105
                    // SpecBreak Modeling
106
                    RunSpecBreakModeling();
107 d23fe61b gaqhf
                    // Join SameConnector
108 dfac4553 gaqhf
                    RunJoinRunForSameConnector();
109 d23fe61b gaqhf
                    // Check FlowDirection
110 1ff0105e gaqhf
                    RunFlowDirection();
111 32205389 gaqhf
                    // Note Modeling
112
                    RunNoteModeling();
113
                    // Text Modeling
114
                    RunTextModeling();
115
                    // Input LineNumber Attribute
116
                    RunInputLineNumberAttribute();
117
                    // Input Symbol Attribute
118
                    RunInputSymbolAttribute();
119
                    // Input SpecBreak Attribute
120
                    RunInputSpecBreakAttribute();
121
                    // Label Symbol Modeling
122
                    RunLabelSymbolModeling();
123
                    
124 4ba01591 gaqhf
125
                    //// LineRun Line Join
126
                    //SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Join LineRuns");
127
                    //foreach (LineNumber lineNumber in document.LINENUMBERS)
128
                    //    try
129
                    //    {
130
                    //        foreach (LineRun run in lineNumber.RUNS)
131
                    //            JoinRunLine(run);
132
                    //    }
133
                    //    catch (Exception ex)
134
                    //    {
135
                    //        Log.Write("Error in JoinRunLine");
136
                    //        Log.Write("UID : " + lineNumber.UID);
137
                    //        Log.Write(ex.Message);
138
                    //        Log.Write(ex.StackTrace);
139
                    //    }
140
141
                    //// TrimLineRun Line Join
142
                    //foreach (TrimLine trimLine in document.TRIMLINES)
143
                    //    try
144
                    //    {
145
                    //        foreach (LineRun run in trimLine.RUNS)
146
                    //            JoinRunLine(run);
147
                    //    }
148
                    //    catch (Exception ex)
149
                    //    {
150
                    //        Log.Write("Error in JoinRunLine");
151
                    //        Log.Write("UID : " + trimLine.UID);
152
                    //        Log.Write(ex.Message);
153
                    //        Log.Write(ex.StackTrace);
154
                    //    }
155 310aeb31 gaqhf
                }
156 809a7640 gaqhf
            }
157 5e6ecf05 gaqhf
            catch (Exception ex)
158
            {
159 9628f54b gaqhf
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null);
160
                SplashScreenManager.CloseForm(false);
161 5e6ecf05 gaqhf
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
162
            }
163
            finally
164
            {
165 3734dcc5 gaqhf
                Log.Write("End Modeling");
166 1ba9c671 gaqhf
                application.ActiveWindow.Fit();
167 b2d1c1aa gaqhf
168 7aee331b gaqhf
                if (currentDrawing != null)
169
                    ReleaseCOMObjects(currentDrawing);
170
171 b66a2996 gaqhf
                if (radApp.ActiveDocument != null)
172 3939eebf gaqhf
                {
173 1805d3b7 gaqhf
                    radApp.ActiveDocument.Save();
174 1ba9c671 gaqhf
                    ReleaseCOMObjects(newDrawing);
175 3939eebf gaqhf
                }
176 1ba9c671 gaqhf
177 5e6ecf05 gaqhf
                ReleaseCOMObjects(dataSource);
178
                ReleaseCOMObjects(_placement);
179 965eb728 gaqhf
180 224535bb gaqhf
                Project_DB.InsertDrawingInfo(document.PATH, drawingNumber, drawingName, document);
181 9628f54b gaqhf
                if (SplashScreenManager.Default.IsSplashFormVisible)
182
                {
183
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.ClearParent, null);
184
                    SplashScreenManager.CloseForm(false);
185 3734dcc5 gaqhf
                    Log.Write("\r\n");
186 9628f54b gaqhf
                }
187 5e6ecf05 gaqhf
            }
188 65a1ed4b gaqhf
        }
189 b01e7456 gaqhf
        private void RunEquipmentModeling()
190
        {
191
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.Equipments.Count);
192 32205389 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Equipments Modeling");
193 b01e7456 gaqhf
            foreach (Equipment item in document.Equipments)
194
            {
195
                try
196
                {
197
                    EquipmentModeling(item);
198
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.Equipments.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
199
                }
200
                catch (Exception ex)
201
                {
202
                    Log.Write("Error in EquipmentModeling");
203
                    Log.Write("UID : " + item.UID);
204
                    Log.Write(ex.Message);
205
                    Log.Write(ex.StackTrace);
206
                }
207
            }
208
        }
209
        private void RunSymbolModeling()
210
        {
211
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
212 32205389 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Symbol Modeling");
213 b01e7456 gaqhf
            prioritySymbols = GetPrioritySymbol();
214
            foreach (var item in prioritySymbols)
215
            {
216
                try
217
                {
218
                    SymbolModelingBySymbol(item);
219
                }
220
                catch (Exception ex)
221
                {
222
                    Log.Write("Error in SymbolModelingByPriority");
223
                    Log.Write("UID : " + item.UID);
224
                    Log.Write(ex.Message);
225
                    Log.Write(ex.StackTrace);
226
                }
227
            }
228
        }
229
        private void RunLineModeling()
230
        {
231
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count);
232 32205389 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Lines Modeling");
233
            SetPriorityLine();
234 b01e7456 gaqhf
            foreach (var item in document.LINES)
235
            {
236
                try
237
                {
238
                    NewLineModeling(item);
239
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
240
                }
241
                catch (Exception ex)
242
                {
243
                    Log.Write("Error in NewLineModeling");
244
                    Log.Write("UID : " + item.UID);
245
                    Log.Write(ex.Message);
246
                    Log.Write(ex.StackTrace);
247
                }
248
            }
249
        }
250
        private void RunBranchLineModeling()
251
        {
252
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, NewBranchLines.Count);
253 32205389 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Branch Lines Modeling");
254 b01e7456 gaqhf
            int branchCount = NewBranchLines.Count;
255
            while (NewBranchLines.Count > 0)
256
            {
257
                Line item = NewBranchLines[0];
258
                try
259
                {
260
                    SortBranchLines();
261
                    NewLineModeling(item, true);
262
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
263
                }
264
                catch (Exception ex)
265
                {
266
                    Log.Write("Error in NewLineModeling");
267
                    Log.Write("UID : " + item.UID);
268
                    Log.Write(ex.Message);
269
                    Log.Write(ex.StackTrace);
270
                }
271
            }
272
        }
273 1ff0105e gaqhf
        private void RunClearValueInconsistancy()
274 b01e7456 gaqhf
        {
275 32205389 gaqhf
            int count = 1;
276 63fbf592 gaqhf
            bool loop = true;
277
            while (loop)
278 b01e7456 gaqhf
            {
279 63fbf592 gaqhf
                loop = false;
280
                LMAFilter filter = new LMAFilter();
281
                LMACriterion criterion = new LMACriterion();
282
                filter.ItemType = "Relationship";
283
                criterion.SourceAttributeName = "SP_DRAWINGID";
284
                criterion.Operator = "=";
285
                criterion.set_ValueAttribute(currentDrawing.Id);
286
                filter.get_Criteria().Add(criterion);
287
288
                LMRelationships relationships = new LMRelationships();
289
                relationships.Collect(dataSource, Filter: filter);
290
291 d23fe61b gaqhf
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, relationships.Count);
292 f9cc5190 gaqhf
                if (count > 1)
293
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStepMinus, null);
294 32205389 gaqhf
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Clear Inconsistent Property Value - " + count);
295 63fbf592 gaqhf
                foreach (LMRelationship relationship in relationships)
296 b01e7456 gaqhf
                {
297 63fbf592 gaqhf
                    foreach (LMInconsistency inconsistency in relationship.Inconsistencies)
298 b01e7456 gaqhf
                    {
299 63fbf592 gaqhf
                        if (inconsistency.get_InconsistencyTypeIndex() == 1)
300
                        {
301
                            LMModelItem modelItem1 = relationship.Item1RepresentationObject == null ? null : relationship.Item1RepresentationObject.ModelItemObject;
302
                            LMModelItem modelItem2 = relationship.Item2RepresentationObject == null ? null : relationship.Item2RepresentationObject.ModelItemObject;
303
                            string[] array = inconsistency.get_Name().ToString().Split(new char[] { '=' });
304
                            if (modelItem1 != null)
305
                            {
306
                                string attrName = array[0];
307
                                if (attrName.Contains("PipingPoint"))
308
                                {
309
                                    string originalAttr = attrName.Split(new char[] { '.' })[1];
310 d23fe61b gaqhf
                                    int index = Convert.ToInt32(relationship.get_Item1Location());
311
                                    LMAAttribute attribute1 = modelItem1.Attributes["PipingPoint" + index + "." + originalAttr];
312
                                    if (attribute1 != null && !DBNull.Value.Equals(attribute1.get_Value()))
313 63fbf592 gaqhf
                                    {
314 d23fe61b gaqhf
                                        loop = true;
315
                                        attribute1.set_Value(DBNull.Value);
316 63fbf592 gaqhf
                                    }
317
                                }
318
                                else
319
                                {
320
                                    LMAAttribute attribute1 = modelItem1.Attributes[attrName];
321
                                    if (attribute1 != null && !DBNull.Value.Equals(attribute1.get_Value()))
322
                                    {
323
                                        loop = true;
324
                                        attribute1.set_Value(DBNull.Value);
325
                                    }
326
                                }
327
                                modelItem1.Commit();
328
                            }
329
                            if (modelItem2 != null)
330
                            {
331
                                string attrName = array[1];
332
                                if (attrName.Contains("PipingPoint"))
333
                                {
334
                                    string originalAttr = attrName.Split(new char[] { '.' })[1];
335 d23fe61b gaqhf
                                    int index = Convert.ToInt32(relationship.get_Item2Location());
336
                                    LMAAttribute attribute2 = modelItem2.Attributes["PipingPoint" + index + "." + originalAttr];
337
                                    if (attribute2 != null && !DBNull.Value.Equals(attribute2.get_Value()))
338 63fbf592 gaqhf
                                    {
339 d23fe61b gaqhf
                                        attribute2.set_Value(DBNull.Value);
340
                                        loop = true;
341 63fbf592 gaqhf
                                    }
342
                                }
343
                                else
344
                                {
345
                                    LMAAttribute attribute2 = modelItem2.Attributes[attrName];
346
                                    if (attribute2 != null && !DBNull.Value.Equals(attribute2.get_Value()))
347
                                    {
348
                                        attribute2.set_Value(DBNull.Value);
349
                                        loop = true;
350
                                    }
351
                                }
352
                                modelItem2.Commit();
353
                            }
354
                            if (modelItem1 != null)
355
                                ReleaseCOMObjects(modelItem1);
356
                            if (modelItem2 != null)
357
                                ReleaseCOMObjects(modelItem2);
358
                            inconsistency.Commit();
359
                        }
360 b01e7456 gaqhf
                    }
361 63fbf592 gaqhf
                    relationship.Commit();
362 d23fe61b gaqhf
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
363 b01e7456 gaqhf
                }
364 63fbf592 gaqhf
                ReleaseCOMObjects(filter);
365
                ReleaseCOMObjects(criterion);
366
                ReleaseCOMObjects(relationships);
367 32205389 gaqhf
                count++;
368 b01e7456 gaqhf
            }
369
        }
370
        private void RunEndBreakModeling()
371
        {
372
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.EndBreaks.Count);
373
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "EndBreaks Modeling");
374
            foreach (var item in document.EndBreaks)
375
                try
376
                {
377
                    EndBreakModeling(item);
378
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
379 d23fe61b gaqhf
                    if (string.IsNullOrEmpty(item.SPPID.RepresentationId))
380 b01e7456 gaqhf
                        Log.Write("Fail modeling endbreak UID : " + item.UID);
381
                }
382
                catch (Exception ex)
383
                {
384
                    Log.Write("Error in EndBreakModeling");
385
                    Log.Write("UID : " + item.UID);
386
                    Log.Write(ex.Message);
387
                    Log.Write(ex.StackTrace);
388
                }
389
        }
390
        private void RunSpecBreakModeling()
391
        {
392
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SpecBreaks.Count);
393
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "SpecBreaks Modeling");
394
            foreach (var item in document.SpecBreaks)
395
                try
396
                {
397
                    SpecBreakModeling(item);
398
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
399 d23fe61b gaqhf
                    if (string.IsNullOrEmpty(item.SPPID.RepresentationId))
400 b01e7456 gaqhf
                        Log.Write("Fail modeling specbreak UID : " + item.UID);
401
                }
402
                catch (Exception ex)
403
                {
404
                    Log.Write("Error in SpecBreakModeling");
405
                    Log.Write("UID : " + item.UID);
406 9bcb092b gaqhf
                    Log.Write(ex.Message);
407
                    Log.Write(ex.StackTrace);
408
                }
409
        }
410 dfac4553 gaqhf
        private void RunJoinRunForSameConnector()
411
        {
412 d23fe61b gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count);
413 dfac4553 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "PipeRun Join");
414
            foreach (var line in document.LINES)
415
            {
416
                if (!SPPIDUtil.IsSegmentLine(document, line))
417
                {
418
                    foreach (var connector in line.CONNECTORS)
419
                    {
420
                        if (connector.ConnectedObject != null &&
421
                            connector.ConnectedObject.GetType() == typeof(Line) &&
422 d23fe61b gaqhf
                            !SPPIDUtil.IsBranchLine(line, connector.ConnectedObject as Line)) 
423 dfac4553 gaqhf
                        {
424
                            Line connLine = connector.ConnectedObject as Line;
425
                            if (line.SPPID.ModelItemId != connLine.SPPID.ModelItemId)
426
                                JoinPipeRun(connLine.SPPID.ModelItemId, line.SPPID.ModelItemId);
427
                        }
428
                    }
429
                }
430 d23fe61b gaqhf
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
431
            }
432
        }
433
        private void RunFlowDirection()
434
        {
435 644f40b3 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, 
436
                document.LINES.Count + ZeroLengthModelItemID.Count + ZeroLengthModelItemIDReverse.Count + ZeroLengthSymbolToSymbolModelItemID.Count);
437 d23fe61b gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Check Flow Direction");
438
            foreach (var line in document.LINES)
439
            {
440 1ff0105e gaqhf
                if (!string.IsNullOrEmpty(line.SPPID.ModelItemId))
441
                {
442
                    LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
443 644f40b3 gaqhf
                    if (modelItem != null && modelItem.get_ItemStatus() == "Active")
444 1ff0105e gaqhf
                    {
445
                        LMAAttribute attribute = modelItem.Attributes["FlowDirection"];
446
                        if (attribute != null)
447
                        {
448
                            attribute.set_Value("End 1 is upstream (Inlet)");
449
                            modelItem.Commit();
450
                        }
451 d23fe61b gaqhf
452 1ff0105e gaqhf
                        SetFlowDirectionByLine(line.SPPID.ModelItemId);
453
454
                        ReleaseCOMObjects(modelItem);
455
                    }
456
                }
457 d23fe61b gaqhf
458
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
459 dfac4553 gaqhf
            }
460 1ff0105e gaqhf
            foreach (var modelId in ZeroLengthModelItemID)
461
            {
462
                LMModelItem zeroLengthModelItem = dataSource.GetModelItem(modelId);
463
                LMAAttribute attribute = zeroLengthModelItem.Attributes["FlowDirection"];
464 644f40b3 gaqhf
                if (attribute != null && zeroLengthModelItem.get_ItemStatus() == "Active")
465 1ff0105e gaqhf
                {
466
                    attribute.set_Value("End 1 is upstream (Inlet)");
467
                    zeroLengthModelItem.Commit();
468
                }
469
470
                SetFlowDirectionByLine(modelId);
471
472
                ReleaseCOMObjects(zeroLengthModelItem);
473
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
474
            }
475
            foreach (var modelId in ZeroLengthModelItemIDReverse)
476
            {
477
                LMModelItem zeroLengthModelItem = dataSource.GetModelItem(modelId);
478
                LMAAttribute attribute = zeroLengthModelItem.Attributes["FlowDirection"];
479 644f40b3 gaqhf
                if (attribute != null && zeroLengthModelItem.get_ItemStatus() == "Active")
480 1ff0105e gaqhf
                {
481
                    attribute.set_Value("End 1 is downstream (Outlet)");
482
                    zeroLengthModelItem.Commit();
483
                }
484
485
                SetFlowDirectionByLine(modelId);
486
487
                ReleaseCOMObjects(zeroLengthModelItem);
488
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
489
            }
490 644f40b3 gaqhf
            foreach (var modelId in ZeroLengthSymbolToSymbolModelItemID)
491
            {
492
                SetFlowDirectionByLine(modelId);
493
                SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
494
            }
495 1ff0105e gaqhf
496 32205389 gaqhf
            void SetFlowDirectionByLine(string lineModelItemID)
497 1ff0105e gaqhf
            {
498 32205389 gaqhf
                LMModelItem modelItem = dataSource.GetModelItem(lineModelItemID);
499
                if (modelItem != null && modelItem.get_ItemStatus() == "Active")
500 1ff0105e gaqhf
                {
501 32205389 gaqhf
                    LMAAttribute attribute = modelItem.Attributes["FlowDirection"];
502
                    if (attribute != null && !DBNull.Value.Equals(attribute.get_Value()))
503 1ff0105e gaqhf
                    {
504 32205389 gaqhf
                        string sFlowDirection = attribute.get_Value().ToString();
505
                        foreach (LMRepresentation rep in modelItem.Representations)
506 1ff0105e gaqhf
                        {
507 32205389 gaqhf
                            if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
508
                            {
509
                                LMConnector connector = dataSource.GetConnector(rep.Id);
510 1ff0105e gaqhf
511 32205389 gaqhf
                                foreach (LMRelationship relationship in connector.Relation1Relationships)
512
                                    SetSymbolFlowDirectionByRelationShip(relationship, connector, sFlowDirection);
513
                                foreach (LMRelationship relationship in connector.Relation2Relationships)
514
                                    SetSymbolFlowDirectionByRelationShip(relationship, connector, sFlowDirection);
515 1ff0105e gaqhf
516 32205389 gaqhf
                                ReleaseCOMObjects(connector);
517
                            }
518 1ff0105e gaqhf
                        }
519
                    }
520 32205389 gaqhf
                    ReleaseCOMObjects(modelItem);
521 1ff0105e gaqhf
                }
522
523 32205389 gaqhf
                void SetSymbolFlowDirectionByRelationShip(LMRelationship relationship, LMConnector connector, string sFlowDirection)
524 1ff0105e gaqhf
                {
525 32205389 gaqhf
                    // Item2가 Symbol
526
                    if (!DBNull.Value.Equals(relationship.Item1RepresentationID) && relationship.Item1RepresentationID == connector.Id &&
527
                        relationship.Item2RepresentationObject != null && relationship.Item2RepresentationObject.get_RepresentationType() == "Symbol")
528
                    {
529
                        int symbolIndex = Convert.ToInt32(relationship.get_Item2Location());
530
                        int lineIndex = Convert.ToInt32(relationship.get_Item1Location());
531
                        LMModelItem symbolModelItem = relationship.Item2RepresentationObject.ModelItemObject;
532 1ff0105e gaqhf
533 32205389 gaqhf
                        SetSymbolFlowDirection(lineIndex, symbolIndex, sFlowDirection, symbolModelItem);
534 1ff0105e gaqhf
535 32205389 gaqhf
                        symbolModelItem.Commit();
536
                        ReleaseCOMObjects(symbolModelItem);
537
                    }
538
                    // Item1이 Symbol
539
                    else if (!DBNull.Value.Equals(relationship.Item2RepresentationID) && relationship.Item2RepresentationID == connector.Id &&
540
                            relationship.Item1RepresentationObject != null && relationship.Item1RepresentationObject.get_RepresentationType() == "Symbol")
541
                    {
542
                        int symbolIndex = Convert.ToInt32(relationship.get_Item1Location());
543
                        int lineIndex = Convert.ToInt32(relationship.get_Item2Location());
544
                        LMModelItem symbolModelItem = relationship.Item1RepresentationObject.ModelItemObject;
545 1ff0105e gaqhf
546 32205389 gaqhf
                        SetSymbolFlowDirection(lineIndex, symbolIndex, sFlowDirection, symbolModelItem);
547 1ff0105e gaqhf
548 32205389 gaqhf
                        symbolModelItem.Commit();
549
                        ReleaseCOMObjects(symbolModelItem);
550
                    }
551 1ff0105e gaqhf
                }
552
553 32205389 gaqhf
                void SetSymbolFlowDirection(int lineIndex, int symbolIndex, string sFlowDirection, LMModelItem symbolModelItem)
554 1ff0105e gaqhf
                {
555 32205389 gaqhf
                    string attrName = "PipingPoint" + symbolIndex + ".FlowDirection";
556
                    LMAAttribute attribute = symbolModelItem.Attributes[attrName];
557
                    if (attribute != null)
558
                    {
559
                        if (lineIndex == 0 && sFlowDirection == "End 1 is upstream (Inlet)")
560
                            attribute.set_Value("End 1 is downstream (Outlet)");
561
                        else if (lineIndex == 0 && sFlowDirection == "End 1 is downstream (Outlet)")
562
                            attribute.set_Value("End 1 is upstream (Inlet)");
563
                        else if (lineIndex == 1 && sFlowDirection == "End 1 is upstream (Inlet)")
564
                            attribute.set_Value("End 1 is upstream (Inlet)");
565
                        else if (lineIndex == 1 && sFlowDirection == "End 1 is downstream (Outlet)")
566
                            attribute.set_Value("End 1 is downstream (Outlet)");
567
                    }
568 1ff0105e gaqhf
                }
569
            }
570 dfac4553 gaqhf
        }
571 32205389 gaqhf
        private void RunNoteModeling()
572
        {
573
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
574
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Notes Modeling");
575
            foreach (var item in document.NOTES)
576
                try
577
                {
578
                    NoteModeling(item);
579
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
580
                }
581
                catch (Exception ex)
582
                {
583
                    Log.Write("Error in NoteModeling");
584
                    Log.Write("UID : " + item.UID);
585
                    Log.Write(ex.Message);
586
                    Log.Write(ex.StackTrace);
587
                }
588
        }
589
        private void RunTextModeling()
590 9bcb092b gaqhf
        {
591 32205389 gaqhf
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.TEXTINFOS.Count);
592
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Texts Modeling");
593
            foreach (var item in document.TEXTINFOS)
594
                try
595
                {
596
                    TextModeling(item);
597
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
598
                }
599
                catch (Exception ex)
600
                {
601
                    Log.Write("Error in TextModeling");
602
                    Log.Write("UID : " + item.UID);
603
                    Log.Write(ex.Message);
604
                    Log.Write(ex.StackTrace);
605
                }
606
        }
607
        private void RunInputLineNumberAttribute()
608
        {
609
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINENUMBERS.Count);
610
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set LineNumbers Attribute");
611 9bcb092b gaqhf
            foreach (var item in document.LINENUMBERS)
612
                try
613
                {
614 32205389 gaqhf
                    InputLineNumberAttribute(item);
615
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
616 9bcb092b gaqhf
                }
617
                catch (Exception ex)
618
                {
619 32205389 gaqhf
                    Log.Write("Error in InputLineNumberAttribute");
620
                    Log.Write("UID : " + item.UID);
621
                    Log.Write(ex.Message);
622
                    Log.Write(ex.StackTrace);
623
                }
624
        }
625
        private void RunInputSymbolAttribute()
626
        {
627
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
628
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
629
            foreach (var item in document.SYMBOLS)
630
                try
631
                {
632
                    InputSymbolAttribute(item, item.ATTRIBUTES);
633
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
634
                }
635
                catch (Exception ex)
636
                {
637
                    Log.Write("Error in InputSymbolAttribute");
638
                    Log.Write("UID : " + item.UID);
639
                    Log.Write(ex.Message);
640
                    Log.Write(ex.StackTrace);
641
                }
642
        }
643
        private void RunInputSpecBreakAttribute()
644
        {
645
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
646
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Set Symbols Attribute");
647
            foreach (var item in document.SpecBreaks)
648
                try
649
                {
650
                    InputSpecBreakAttribute(item);
651
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
652
                }
653
                catch (Exception ex)
654
                {
655
                    Log.Write("Error in InputSpecBreakAttribute");
656
                    Log.Write("UID : " + item.UID);
657
                    Log.Write(ex.Message);
658
                    Log.Write(ex.StackTrace);
659
                }
660
        }
661
        private void RunLabelSymbolModeling()
662
        {
663
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
664
            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetStep, "Labels Modeling");
665
            foreach (var item in document.SYMBOLS)
666
                try
667
                {
668
                    LabelSymbolModeling(item);
669
                    SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.UpProgress, null);
670
                }
671
                catch (Exception ex)
672
                {
673
                    Log.Write("Error in LabelSymbolModeling");
674 9bcb092b gaqhf
                    Log.Write("UID : " + item.UID);
675 b01e7456 gaqhf
                    Log.Write(ex.Message);
676
                    Log.Write(ex.StackTrace);
677
                }
678
        }
679 65a1ed4b gaqhf
680 74752074 gaqhf
        /// <summary>
681
        /// 도면 생성 메서드
682
        /// </summary>
683 224535bb gaqhf
        private void CreateDocument(ref string drawingNumber, ref string drawingName)
684 0e0edfad gaqhf
        {
685 3734dcc5 gaqhf
            Log.Write("------------------ Start create document ------------------");
686 6d12a734 gaqhf
            GetDrawingNameAndNumber(ref drawingName, ref drawingNumber);
687 3734dcc5 gaqhf
            Log.Write("Drawing name : " + drawingName);
688
            Log.Write("Drawing number : " + drawingNumber);
689 b66a2996 gaqhf
            newDrawing = application.Drawings.Add(document.Unit, document.Template, drawingNumber, drawingName);
690 88bac50c gaqhf
            document.SPPID_DrawingNumber = drawingNumber;
691
            document.SPPID_DrawingName = drawingName;
692 0e0edfad gaqhf
            application.ActiveWindow.Fit();
693
            Thread.Sleep(1000);
694
            application.ActiveWindow.Zoom = 2000;
695
            Thread.Sleep(2000);
696 7aee331b gaqhf
697
            //current LMDrawing 가져오기
698
            LMAFilter filter = new LMAFilter();
699
            LMACriterion criterion = new LMACriterion();
700
            filter.ItemType = "Drawing";
701
            criterion.SourceAttributeName = "Name";
702
            criterion.Operator = "=";
703
            criterion.set_ValueAttribute(drawingName);
704
            filter.get_Criteria().Add(criterion);
705
706
            LMDrawings drawings = new LMDrawings();
707
            drawings.Collect(dataSource, Filter: filter);
708
709
            currentDrawing = ((dynamic)drawings).Nth(1);
710 b66a2996 gaqhf
        }
711
712 02480ac1 gaqhf
        /// <summary>
713
        /// DrawingName, DrawingNumber를 확인하여 중복이 있으면 _1을 붙이고 +1씩 한다.
714
        /// </summary>
715
        /// <param name="drawingName"></param>
716
        /// <param name="drawingNumber"></param>
717 b66a2996 gaqhf
        private void GetDrawingNameAndNumber(ref string drawingName, ref string drawingNumber)
718
        {
719
            LMDrawings drawings = new LMDrawings();
720
            drawings.Collect(dataSource);
721 7f00b26c gaqhf
722 b66a2996 gaqhf
            List<string> drawingNameList = new List<string>();
723
            List<string> drawingNumberList = new List<string>();
724
725
            foreach (LMDrawing item in drawings)
726
            {
727
                drawingNameList.Add(item.Attributes["Name"].get_Value().ToString());
728
                drawingNumberList.Add(item.Attributes["DrawingNumber"].get_Value().ToString());
729
            }
730
731
            int nameLength = drawingName.Length;
732
            while (drawingNameList.Contains(drawingName))
733
            {
734
                if (nameLength == drawingName.Length)
735
                    drawingName += "-1";
736
                else
737
                {
738
                    int index = Convert.ToInt32(drawingName.Remove(0, nameLength + 1));
739
                    drawingName = drawingName.Substring(0, nameLength + 1);
740
                    drawingName += ++index;
741
                }
742
            }
743
744
            int numberLength = drawingNumber.Length;
745
            while (drawingNameList.Contains(drawingNumber))
746
            {
747
                if (numberLength == drawingNumber.Length)
748
                    drawingNumber += "-1";
749
                else
750
                {
751
                    int index = Convert.ToInt32(drawingNumber.Remove(0, numberLength + 1));
752
                    drawingNumber = drawingNumber.Substring(0, numberLength + 1);
753
                    drawingNumber += ++index;
754
                }
755
            }
756
757
            ReleaseCOMObjects(drawings);
758 0e0edfad gaqhf
        }
759
760 74752074 gaqhf
        /// <summary>
761
        /// 도면 크기 구하는 메서드
762
        /// </summary>
763
        /// <returns></returns>
764 0e0edfad gaqhf
        private bool DocumentCoordinateCorrection()
765
        {
766 6a7573b0 gaqhf
            if (Settings.Default.DrawingX != 0 && Settings.Default.DrawingY != 0)
767 0e0edfad gaqhf
            {
768 3734dcc5 gaqhf
                Log.Write("Setting Drawing X, Drawing Y");
769 6a7573b0 gaqhf
                document.SetSPPIDLocation(Settings.Default.DrawingX, Settings.Default.DrawingY);
770 3734dcc5 gaqhf
                Log.Write("Start coordinate correction");
771 c01ce90b gaqhf
                document.CoordinateCorrection();
772 0e0edfad gaqhf
                return true;
773
            }
774
            else
775 3734dcc5 gaqhf
            {
776
                Log.Write("Need Drawing X, Y");
777 0e0edfad gaqhf
                return false;
778 3734dcc5 gaqhf
            }
779 0e0edfad gaqhf
        }
780
781 74752074 gaqhf
        /// <summary>
782
        /// 심볼을 실제로 Modeling 메서드
783
        /// </summary>
784
        /// <param name="symbol"></param>
785
        /// <param name="targetSymbol"></param>
786
        /// <param name="prevSymbol"></param>
787 b2d1c1aa gaqhf
        private void SymbolModeling(Symbol symbol, Symbol targetSymbol)
788 809a7640 gaqhf
        {
789 7f00b26c gaqhf
            // OWNERSYMBOL Attribute, 값을 가지고 있을 경우
790
            BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(attr => attr.ATTRIBUTE == "OWNERSYMBOL");
791
            if (itemAttribute != null && (string.IsNullOrEmpty(itemAttribute.VALUE) || itemAttribute.VALUE != "None"))
792
                return;
793
            // 이미 모델링 됐을 경우
794
            else if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
795
                return;
796 6a7573b0 gaqhf
797 7f00b26c gaqhf
            LMSymbol _LMSymbol = null;
798 809a7640 gaqhf
799 7f00b26c gaqhf
            string mappingPath = symbol.SPPID.MAPPINGNAME;
800
            double x = symbol.SPPID.ORIGINAL_X;
801
            double y = symbol.SPPID.ORIGINAL_Y;
802
            int mirror = 0;
803
            double angle = symbol.ANGLE;
804 2fdb56bf gaqhf
805 7f00b26c gaqhf
            // OPC 일경우 180도 일때 Mirror
806
            if (mappingPath.Contains("Piping OPC's") && angle == Math.PI)
807
                mirror = 1;
808 1ab9a205 gaqhf
809 7f00b26c gaqhf
            // Mirror 계산
810
            if (symbol.FLIP == 1)
811
            {
812
                mirror = 1;
813
                angle += Math.PI;
814
            }
815 1ab9a205 gaqhf
816 7f00b26c gaqhf
            if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId))
817
            {
818
                LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
819
                Connector connector = SPPIDUtil.FindSymbolConnectorByUID(document, symbol.UID, targetSymbol);
820
                if (connector != null)
821
                    GetTargetSymbolConnectorPoint(connector, targetSymbol, ref x, ref y);
822 809a7640 gaqhf
823 7f00b26c gaqhf
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem);
824 809a7640 gaqhf
825 7f00b26c gaqhf
                if (_LMSymbol != null && _TargetItem != null)
826 6a7573b0 gaqhf
                {
827
                    symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
828 ac78b508 gaqhf
829 32205389 gaqhf
                    if (SPPIDUtil.IsSegmentLine(document, symbol, targetSymbol))
830
                    {
831
                        LMConnector reModelingConnector = FindBreakLineTarget(symbol, targetSymbol);
832
                        if (reModelingConnector != null)
833
                            ReModelingLMConnector(reModelingConnector);
834
                    }
835 6a7573b0 gaqhf
                }
836 809a7640 gaqhf
837 7f00b26c gaqhf
                ReleaseCOMObjects(_TargetItem);
838 4d2571ab gaqhf
            }
839 7f00b26c gaqhf
            else
840
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
841
842
            if (_LMSymbol != null)
843 4d2571ab gaqhf
            {
844 7f00b26c gaqhf
                _LMSymbol.Commit();
845
                symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
846
                symbol.SPPID.ModelItemID = _LMSymbol.ModelItemID;
847 32205389 gaqhf
                symbol.SPPID.GraphicOID = _LMSymbol.get_GraphicOID().ToString();
848 7f00b26c gaqhf
849
                foreach (var item in symbol.ChildSymbols)
850
                    CreateChildSymbol(item, _LMSymbol);
851 3734dcc5 gaqhf
852 d9794a6c gaqhf
                symbol.SPPID.SPPID_X = _LMSymbol.get_XCoordinate();
853
                symbol.SPPID.SPPID_Y = _LMSymbol.get_YCoordinate();
854
855
                double[] range = null;
856
                GetSPPIDSymbolRange(symbol, ref range);
857
                symbol.SPPID.SPPID_Min_X = range[0];
858
                symbol.SPPID.SPPID_Min_Y = range[1];
859
                symbol.SPPID.SPPID_Max_X = range[2];
860
                symbol.SPPID.SPPID_Max_Y = range[3];
861
862
                foreach (var item in symbol.SPPID.CorrectionX_GroupSymbols)
863
                    item.SPPID.ORIGINAL_X = symbol.SPPID.SPPID_X;
864
                foreach (var item in symbol.SPPID.CorrectionY_GroupSymbols)
865
                    item.SPPID.ORIGINAL_Y = symbol.SPPID.SPPID_Y;
866
867 3734dcc5 gaqhf
                ReleaseCOMObjects(_LMSymbol);
868 4d2571ab gaqhf
            }
869 809a7640 gaqhf
        }
870
871 d9794a6c gaqhf
        private void RemoveSymbol(Symbol symbol)
872
        {
873
            if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
874
            {
875
                LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
876
                if (_LMSymbol != null)
877
                {
878
                    _placement.PIDRemovePlacement(_LMSymbol.AsLMRepresentation());
879
                    ReleaseCOMObjects(_LMSymbol);
880
                }
881
            }
882
883
            symbol.SPPID.RepresentationId = string.Empty;
884
            symbol.SPPID.ModelItemID = string.Empty;
885
            symbol.SPPID.SPPID_X = double.NaN;
886
            symbol.SPPID.SPPID_Y = double.NaN;
887
            symbol.SPPID.SPPID_Min_X = double.NaN;
888
            symbol.SPPID.SPPID_Min_Y = double.NaN;
889
            symbol.SPPID.SPPID_Max_X = double.NaN;
890
            symbol.SPPID.SPPID_Max_Y = double.NaN;
891
        }
892
893
        private void RemoveSymbol(List<Symbol> symbols)
894
        {
895
            foreach (var symbol in symbols)
896
            {
897
                if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
898
                {
899
                    LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
900
                    if (_LMSymbol != null)
901
                    {
902
                        _placement.PIDRemovePlacement(_LMSymbol.AsLMRepresentation());
903
                        ReleaseCOMObjects(_LMSymbol);
904
                    }
905
                }
906
907
                symbol.SPPID.RepresentationId = string.Empty;
908
                symbol.SPPID.ModelItemID = string.Empty;
909
                symbol.SPPID.SPPID_X = double.NaN;
910
                symbol.SPPID.SPPID_Y = double.NaN;
911
                symbol.SPPID.SPPID_Min_X = double.NaN;
912
                symbol.SPPID.SPPID_Min_Y = double.NaN;
913
                symbol.SPPID.SPPID_Max_X = double.NaN;
914
                symbol.SPPID.SPPID_Max_Y = double.NaN;
915
            }
916
        }
917
918 d1eac84d gaqhf
        /// <summary>
919
        /// ID2의 Symbol Width와 Height를 비교해서 상대적인 SPPID Connector좌표를 가져온다.
920
        /// </summary>
921
        /// <param name="targetConnector"></param>
922
        /// <param name="targetSymbol"></param>
923
        /// <param name="x"></param>
924
        /// <param name="y"></param>
925
        private void GetTargetSymbolConnectorPoint(Connector targetConnector, Symbol targetSymbol, ref double x, ref double y)
926
        {
927
            LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
928 2fdb56bf gaqhf
929
            double[] range = null;
930 d1eac84d gaqhf
            List<double[]> points = new List<double[]>();
931 2fdb56bf gaqhf
            GetSPPIDSymbolRangeAndConnectionPoints(targetSymbol, ref range, points);
932
            double x1 = range[0];
933
            double y1 = range[1];
934
            double x2 = range[2];
935
            double y2 = range[3];
936 d1eac84d gaqhf
937
            // Origin 기준 Connector의 위치차이
938
            double sceneX = 0;
939
            double sceneY = 0;
940
            SPPIDUtil.ConvertPointBystring(targetConnector.SCENECONNECTPOINT, ref sceneX, ref sceneY);
941
            double originX = 0;
942
            double originY = 0;
943
            SPPIDUtil.ConvertPointBystring(targetSymbol.ORIGINALPOINT, ref originX, ref originY);
944
            double gapX = originX - sceneX;
945
            double gapY = originY - sceneY;
946
947
            // SPPID Symbol과 ID2 심볼의 크기 차이
948 026f394f gaqhf
            double sizeWidth = 0;
949
            double sizeHeight = 0;
950
            SPPIDUtil.ConvertPointBystring(targetSymbol.SIZE, ref sizeWidth, ref sizeHeight);
951
            if (sizeWidth == 0 || sizeHeight == 0)
952
                throw new Exception("Check symbol size! \r\nUID : " + targetSymbol.UID);
953
954 d1eac84d gaqhf
            double percentX = (x2 - x1) / sizeWidth;
955
            double percentY = (y2 - y1) / sizeHeight;
956
957
            double SPPIDgapX = gapX * percentX;
958
            double SPPIDgapY = gapY * percentY;
959
960
            double[] SPPIDOriginPoint = new double[] { _TargetItem.get_XCoordinate() - SPPIDgapX, _TargetItem.get_YCoordinate() + SPPIDgapY };
961
            double distance = double.MaxValue;
962
            double[] resultPoint;
963
            foreach (var point in points)
964
            {
965
                double result = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], SPPIDOriginPoint[0], SPPIDOriginPoint[1]);
966
                if (distance > result)
967
                {
968
                    distance = result;
969
                    resultPoint = point;
970
                    x = point[0];
971
                    y = point[1];
972
                }
973
            }
974 2fdb56bf gaqhf
975
            ReleaseCOMObjects(_TargetItem);
976
        }
977
978 a0e3dca4 gaqhf
        private void GetTargetLineConnectorPoint(Connector targetConnector, Line targetLine, ref double x, ref double y)
979
        {
980
            int index = targetLine.CONNECTORS.IndexOf(targetConnector);
981
            if (index == 0)
982
            {
983
                x = targetLine.SPPID.START_X;
984
                y = targetLine.SPPID.START_Y;
985
            }
986
            else
987
            {
988
                x = targetLine.SPPID.END_X;
989
                y = targetLine.SPPID.END_Y;
990
            }
991
        }
992
993 2fdb56bf gaqhf
        /// <summary>
994
        /// SPPID Symbol의 Range를 구한다.
995
        /// </summary>
996
        /// <param name="symbol"></param>
997
        /// <param name="range"></param>
998
        private void GetSPPIDSymbolRangeAndConnectionPoints(Symbol symbol, ref double[] range, List<double[]> points)
999
        {
1000
            LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1001
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1002
            double x1 = 0;
1003
            double y1 = 0;
1004
            double x2 = 0;
1005
            double y2 = 0;
1006
            symbol2d.Range(out x1, out y1, out x2, out y2);
1007
            range = new double[] { x1, y1, x2, y2 };
1008
1009
            for (int i = 1; i < int.MaxValue; i++)
1010
            {
1011
                double connX = 0;
1012
                double connY = 0;
1013
                if (_placement.PIDConnectPointLocation(_TargetItem, i, ref connX, ref connY))
1014
                    points.Add(new double[] { connX, connY });
1015
                else
1016
                    break;
1017
            }
1018
1019
            foreach (var childSymbol in symbol.ChildSymbols)
1020
                GetSPPIDChildSymbolRange(childSymbol, ref range, points);
1021
1022
            ReleaseCOMObjects(_TargetItem);
1023
        }
1024
1025 d9794a6c gaqhf
        private void GetSPPIDSymbolRange(Symbol symbol, ref double[] range)
1026
        {
1027
            LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1028
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1029
            double x1 = 0;
1030
            double y1 = 0;
1031
            double x2 = 0;
1032
            double y2 = 0;
1033
            symbol2d.Range(out x1, out y1, out x2, out y2);
1034
            range = new double[] { x1, y1, x2, y2 };
1035
1036
            foreach (var childSymbol in symbol.ChildSymbols)
1037
                GetSPPIDChildSymbolRange(childSymbol, ref range);
1038
1039
            ReleaseCOMObjects(_TargetItem);
1040
        }
1041
1042
        private void GetSPPIDSymbolRange(List<Symbol> symbols, ref double[] range)
1043
        {
1044
            double[] tempRange = new double[] { double.MaxValue, double.MaxValue, double.MinValue, double.MinValue };
1045
            foreach (var symbol in symbols)
1046
            {
1047
                LMSymbol _TargetItem = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
1048
                Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_TargetItem.get_GraphicOID().ToString()];
1049
                double x1 = 0;
1050
                double y1 = 0;
1051
                double x2 = 0;
1052
                double y2 = 0;
1053
                symbol2d.Range(out x1, out y1, out x2, out y2);
1054
1055
                tempRange[0] = Math.Min(tempRange[0], x1);
1056
                tempRange[1] = Math.Min(tempRange[1], y1);
1057
                tempRange[2] = Math.Max(tempRange[2], x2);
1058
                tempRange[3] = Math.Max(tempRange[3], y2);
1059
1060
                foreach (var childSymbol in symbol.ChildSymbols)
1061 f1a7faf9 gaqhf
                    GetSPPIDChildSymbolRange(childSymbol, ref tempRange);
1062 d9794a6c gaqhf
1063
                ReleaseCOMObjects(_TargetItem);
1064
            }
1065
1066
            range = tempRange;
1067
        }
1068
1069 2fdb56bf gaqhf
        /// <summary>
1070
        /// Child Modeling 된 Symbol의 Range를 구한다.
1071
        /// </summary>
1072
        /// <param name="childSymbol"></param>
1073
        /// <param name="range"></param>
1074
        private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range, List<double[]> points)
1075
        {
1076
            LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId);
1077
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()];
1078
            double x1 = 0;
1079
            double y1 = 0;
1080
            double x2 = 0;
1081
            double y2 = 0;
1082
            symbol2d.Range(out x1, out y1, out x2, out y2);
1083
            range[0] = Math.Min(range[0], x1);
1084
            range[1] = Math.Min(range[1], y1);
1085
            range[2] = Math.Max(range[2], x2);
1086
            range[3] = Math.Max(range[3], y2);
1087
1088
            for (int i = 1; i < int.MaxValue; i++)
1089
            {
1090
                double connX = 0;
1091
                double connY = 0;
1092
                if (_placement.PIDConnectPointLocation(_ChildSymbol, i, ref connX, ref connY))
1093
                    points.Add(new double[] { connX, connY });
1094
                else
1095
                    break;
1096
            }
1097
1098
            foreach (var loopChildSymbol in childSymbol.ChildSymbols)
1099
                GetSPPIDChildSymbolRange(loopChildSymbol, ref range, points);
1100
1101
            ReleaseCOMObjects(_ChildSymbol);
1102 d1eac84d gaqhf
        }
1103
1104 d9794a6c gaqhf
        private void GetSPPIDChildSymbolRange(ChildSymbol childSymbol, ref double[] range)
1105
        {
1106
            LMSymbol _ChildSymbol = dataSource.GetSymbol(childSymbol.SPPID.RepresentationId);
1107
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[_ChildSymbol.get_GraphicOID().ToString()];
1108
            double x1 = 0;
1109
            double y1 = 0;
1110
            double x2 = 0;
1111
            double y2 = 0;
1112
            symbol2d.Range(out x1, out y1, out x2, out y2);
1113
            range[0] = Math.Min(range[0], x1);
1114
            range[1] = Math.Min(range[1], y1);
1115
            range[2] = Math.Max(range[2], x2);
1116
            range[3] = Math.Max(range[3], y2);
1117
1118
            foreach (var loopChildSymbol in childSymbol.ChildSymbols)
1119
                GetSPPIDChildSymbolRange(loopChildSymbol, ref range);
1120
1121
            ReleaseCOMObjects(_ChildSymbol);
1122
        }
1123
1124 d1eac84d gaqhf
        /// <summary>
1125
        /// Label Symbol Modeling
1126
        /// </summary>
1127
        /// <param name="symbol"></param>
1128 73415441 gaqhf
        private void LabelSymbolModeling(Symbol symbol)
1129
        {
1130 fb386b8c gaqhf
            if (string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
1131 73415441 gaqhf
            {
1132 fb386b8c gaqhf
                BaseModel.Attribute itemAttribute = symbol.ATTRIBUTES.Find(x => x.ATTRIBUTE == "OWNERSYMBOL");
1133
                if (itemAttribute == null || string.IsNullOrEmpty(itemAttribute.VALUE) || itemAttribute.VALUE == "None")
1134
                    return;
1135
                Array points = new double[] { 0, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y };
1136
1137
                string symbolUID = itemAttribute.VALUE;
1138
                object targetItem = SPPIDUtil.FindObjectByUID(document, symbolUID);
1139
                if (targetItem != null &&
1140
                    (targetItem.GetType() == typeof(Symbol) ||
1141
                    targetItem.GetType() == typeof(Equipment)))
1142 73415441 gaqhf
                {
1143 fb386b8c gaqhf
                    // Object 아이템이 Symbol일 경우 Equipment일 경우 
1144
                    string sRep = null;
1145
                    if (targetItem.GetType() == typeof(Symbol))
1146
                        sRep = ((Symbol)targetItem).SPPID.RepresentationId;
1147
                    else if (targetItem.GetType() == typeof(Equipment))
1148
                        sRep = ((Equipment)targetItem).SPPID.RepresentationId;
1149
                    if (!string.IsNullOrEmpty(sRep))
1150 73415441 gaqhf
                    {
1151 fb386b8c gaqhf
                        // LEADER Line 검사
1152
                        bool leaderLine = false;
1153
                        SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
1154
                        if (symbolMapping != null)
1155
                            leaderLine = symbolMapping.LEADERLINE;
1156
1157
                        // Target Symbol Item 가져오고 Label Modeling
1158
                        LMSymbol _TargetItem = dataSource.GetSymbol(sRep);
1159
                        LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: _TargetItem.AsLMRepresentation(), IsLeaderVisible: leaderLine);
1160
1161
                        //Leader 선 센터로
1162
                        if (_LMLabelPresist != null)
1163 73415441 gaqhf
                        {
1164 fb386b8c gaqhf
                            // Target Item에 Label의 Attribute Input
1165
                            InputSymbolAttribute(targetItem, symbol.ATTRIBUTES);
1166
1167 32205389 gaqhf
                            string OID = _LMLabelPresist.get_GraphicOID().ToString();
1168 fb386b8c gaqhf
                            DependencyObject dependency = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID] as DependencyObject;
1169
                            if (dependency != null)
1170 73415441 gaqhf
                            {
1171 fb386b8c gaqhf
                                bool result = false;
1172
                                foreach (var attributes in dependency.AttributeSets)
1173 73415441 gaqhf
                                {
1174 fb386b8c gaqhf
                                    foreach (var attribute in attributes)
1175 73415441 gaqhf
                                    {
1176 fb386b8c gaqhf
                                        string name = attribute.Name;
1177
                                        string value = attribute.GetValue().ToString();
1178
                                        if (name == "DrawingItemType" && value == "LabelPersist")
1179 73415441 gaqhf
                                        {
1180 fb386b8c gaqhf
                                            foreach (DrawingObjectBase drawingObject in dependency.DrawingObjects)
1181 b2d1c1aa gaqhf
                                            {
1182 fb386b8c gaqhf
                                                if (drawingObject.Type == Ingr.RAD2D.ObjectType.igLineString2d)
1183
                                                {
1184
                                                    Ingr.RAD2D.LineString2d lineString2D = drawingObject as Ingr.RAD2D.LineString2d;
1185
                                                    double prevX = _TargetItem.get_XCoordinate();
1186
                                                    double prevY = _TargetItem.get_YCoordinate();
1187
                                                    lineString2D.InsertVertex(lineString2D.VertexCount, prevX, prevY);
1188
                                                    lineString2D.RemoveVertex(lineString2D.VertexCount);
1189
                                                    result = true;
1190
                                                    break;
1191
                                                }
1192 b2d1c1aa gaqhf
                                            }
1193 73415441 gaqhf
                                        }
1194 fb386b8c gaqhf
1195
                                        if (result)
1196
                                            break;
1197 73415441 gaqhf
                                    }
1198 b2d1c1aa gaqhf
1199
                                    if (result)
1200
                                        break;
1201 73415441 gaqhf
                                }
1202
                            }
1203 fb386b8c gaqhf
1204
                            _LMLabelPresist.Commit();
1205
                            ReleaseCOMObjects(_LMLabelPresist);
1206 73415441 gaqhf
                        }
1207
1208 fb386b8c gaqhf
                        ReleaseCOMObjects(_TargetItem);
1209 b2d1c1aa gaqhf
                    }
1210 73415441 gaqhf
                }
1211 fb386b8c gaqhf
                else if (targetItem != null && targetItem.GetType() == typeof(Line))
1212 0860c756 gaqhf
                {
1213 fb386b8c gaqhf
                    Line targetLine = targetItem as Line;
1214
                    Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId);
1215
                    LMConnector connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y);
1216
                    if (connectedLMConnector != null)
1217 0860c756 gaqhf
                    {
1218 fb386b8c gaqhf
                        // LEADER Line 검사
1219
                        bool leaderLine = false;
1220
                        SymbolMapping symbolMapping = document.SymbolMappings.Find(x => x.UID == symbol.DBUID);
1221
                        if (symbolMapping != null)
1222
                            leaderLine = symbolMapping.LEADERLINE;
1223
1224
                        LMLabelPersist _LMLabelPresist = _placement.PIDPlaceLabel(symbol.SPPID.MAPPINGNAME, ref points, Rotation: 0, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: leaderLine);
1225
                        if (_LMLabelPresist != null)
1226
                        {
1227
                            _LMLabelPresist.Commit();
1228
                            ReleaseCOMObjects(_LMLabelPresist);
1229
                        }
1230
                        ReleaseCOMObjects(connectedLMConnector);
1231 0860c756 gaqhf
                    }
1232
1233 fb386b8c gaqhf
                    foreach (var item in connectorVertices)
1234
                        if (item.Key != null)
1235
                            ReleaseCOMObjects(item.Key);
1236
                }
1237 0860c756 gaqhf
            }
1238 73415441 gaqhf
        }
1239
1240 74752074 gaqhf
        /// <summary>
1241
        /// Equipment를 실제로 Modeling 메서드
1242
        /// </summary>
1243
        /// <param name="equipment"></param>
1244 b9e9f4c8 gaqhf
        private void EquipmentModeling(Equipment equipment)
1245
        {
1246
            if (!string.IsNullOrEmpty(equipment.SPPID.RepresentationId))
1247
                return;
1248
1249
            LMSymbol _LMSymbol = null;
1250
            LMSymbol targetItem = null;
1251
            string mappingPath = equipment.SPPID.MAPPINGNAME;
1252
            double x = equipment.SPPID.ORIGINAL_X;
1253
            double y = equipment.SPPID.ORIGINAL_Y;
1254
            int mirror = 0;
1255
            double angle = equipment.ANGLE;
1256
1257 20972c61 gaqhf
            SPPIDUtil.ConvertGridPoint(ref x, ref y);
1258
1259 b9e9f4c8 gaqhf
            Connector connector = equipment.CONNECTORS.Find(conn => !string.IsNullOrEmpty(conn.CONNECTEDITEM) && conn.CONNECTEDITEM != "None");
1260
            if (connector != null)
1261
            {
1262
                Equipment connEquipment = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Equipment;
1263
                if (connEquipment != null)
1264
                {
1265
                    if (string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
1266
                        EquipmentModeling(connEquipment);
1267
1268
                    if (!string.IsNullOrEmpty(connEquipment.SPPID.RepresentationId))
1269
                    {
1270
                        targetItem = dataSource.GetSymbol(connEquipment.SPPID.RepresentationId);
1271
                        if (targetItem != null)
1272
                        {
1273
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: targetItem);
1274
                        }
1275
                        else
1276
                        {
1277
                            _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1278
                        }
1279
                    }
1280
                    else
1281
                    {
1282
                        _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1283
                    }
1284
                }
1285
                else
1286
                {
1287
                    _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1288
                }
1289
            }
1290
            else
1291
            {
1292
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
1293
            }
1294
1295
            if (_LMSymbol != null)
1296
            {
1297
                _LMSymbol.Commit();
1298
                equipment.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1299 32205389 gaqhf
                equipment.SPPID.GraphicOID = _LMSymbol.get_GraphicOID().ToString();
1300 b9e9f4c8 gaqhf
                ReleaseCOMObjects(_LMSymbol);
1301
            }
1302
1303
            if (targetItem != null)
1304
            {
1305
                ReleaseCOMObjects(targetItem);
1306
            }
1307 7f00b26c gaqhf
1308 b9e9f4c8 gaqhf
            ReleaseCOMObjects(_LMSymbol);
1309
        }
1310
1311 d9794a6c gaqhf
        /// <summary>
1312
        /// 첫 진입점
1313
        /// </summary>
1314
        /// <param name="symbol"></param>
1315
        private void SymbolModelingBySymbol(Symbol symbol)
1316
        {
1317 f1a7faf9 gaqhf
            SymbolModeling(symbol, null);
1318 d9794a6c gaqhf
            List<object> endObjects = new List<object>();
1319
            endObjects.Add(symbol);
1320 f1a7faf9 gaqhf
1321 d9794a6c gaqhf
            foreach (var connector in symbol.CONNECTORS)
1322 4d2571ab gaqhf
            {
1323 d9794a6c gaqhf
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1324
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1325 d1eac84d gaqhf
                {
1326 d9794a6c gaqhf
                    endObjects.Add(connItem);
1327
                    if (connItem.GetType() == typeof(Symbol))
1328 4d2571ab gaqhf
                    {
1329 d9794a6c gaqhf
                        Symbol connSymbol = connItem as Symbol;
1330
                        if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1331 4d2571ab gaqhf
                        {
1332 d9794a6c gaqhf
                            SymbolModeling(connSymbol, symbol);
1333
                        }
1334 6db30942 gaqhf
                        SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1335 f1a7faf9 gaqhf
                        SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1336 d9794a6c gaqhf
                    }
1337
                    else if (connItem.GetType() == typeof(Line))
1338
                    {
1339
                        Line connLine = connItem as Line;
1340 f1a7faf9 gaqhf
                        SymbolModelingByNeerLineLoop(connLine, endObjects, symbol);
1341 d9794a6c gaqhf
                    }
1342
                }
1343
            }
1344
        }
1345 4d2571ab gaqhf
1346 f1a7faf9 gaqhf
        private void SymbolModelingByNeerSymbolLoop(Symbol symbol, List<object> endObjects)
1347 d9794a6c gaqhf
        {
1348
            foreach (var connector in symbol.CONNECTORS)
1349
            {
1350
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1351
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1352
                {
1353
                    if (!endObjects.Contains(connItem))
1354
                    {
1355
                        endObjects.Add(connItem);
1356
                        if (connItem.GetType() == typeof(Symbol))
1357
                        {
1358
                            Symbol connSymbol = connItem as Symbol;
1359
                            if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1360 4d2571ab gaqhf
                            {
1361 d9794a6c gaqhf
                                SymbolModeling(connSymbol, symbol);
1362 4d2571ab gaqhf
                            }
1363 6db30942 gaqhf
                            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1364 f1a7faf9 gaqhf
                            SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1365 4d2571ab gaqhf
                        }
1366 d9794a6c gaqhf
                        else if (connItem.GetType() == typeof(Line))
1367
                        {
1368
                            Line connLine = connItem as Line;
1369 f1a7faf9 gaqhf
                            SymbolModelingByNeerLineLoop(connLine, endObjects, symbol);
1370 d9794a6c gaqhf
                        }
1371
                    }
1372
                }
1373
            }
1374
        }
1375 4d2571ab gaqhf
1376 f1a7faf9 gaqhf
        private void SymbolModelingByNeerLineLoop(Line line, List<object> endObjects, Symbol prevSymbol)
1377 d9794a6c gaqhf
        {
1378
            foreach (var connector in line.CONNECTORS)
1379
            {
1380
                object connItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
1381
                if (connItem != null && connItem.GetType() != typeof(Equipment))
1382
                {
1383
                    if (!endObjects.Contains(connItem))
1384
                    {
1385
                        endObjects.Add(connItem);
1386
                        if (connItem.GetType() == typeof(Symbol))
1387
                        {
1388
                            Symbol connSymbol = connItem as Symbol;
1389
                            if (string.IsNullOrEmpty(connSymbol.SPPID.RepresentationId))
1390
                            {
1391
                                List<Symbol> group = new List<Symbol>();
1392
                                SPPIDUtil.FindConnectedSymbolGroup(document, connSymbol, group);
1393 f1a7faf9 gaqhf
                                Symbol priority = prioritySymbols.Find(x => group.Contains(x));
1394
                                List<Symbol> endModelingGroup = new List<Symbol>();
1395
                                if (priority != null)
1396 d9794a6c gaqhf
                                {
1397 f1a7faf9 gaqhf
                                    SymbolGroupModeling(priority, group);
1398 d9794a6c gaqhf
1399
                                    // Range 겹치는지 확인해야함
1400
                                    double[] prevRange = null;
1401
                                    GetSPPIDSymbolRange(prevSymbol, ref prevRange);
1402
                                    double[] groupRange = null;
1403
                                    GetSPPIDSymbolRange(group, ref groupRange);
1404
1405
                                    double distanceX = 0;
1406
                                    double distanceY = 0;
1407 6d12a734 gaqhf
                                    bool overlapX = false;
1408
                                    bool overlapY = false;
1409
                                    SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y);
1410
                                    SPPIDUtil.CalcOverlap(prevRange, groupRange, ref distanceX, ref distanceY, ref overlapX, ref overlapY);
1411
                                    if ((slopeType == SlopeType.HORIZONTAL && overlapX) ||
1412
                                        (slopeType == SlopeType.VERTICAL && overlapY))
1413 d9794a6c gaqhf
                                    {
1414
                                        RemoveSymbol(group);
1415
                                        foreach (var _temp in group)
1416
                                            SPPIDUtil.CalcNewCoordinateForSymbol(_temp, prevSymbol, distanceX, distanceY);
1417
1418 f1a7faf9 gaqhf
                                        SymbolGroupModeling(priority, group);
1419 d9794a6c gaqhf
                                    }
1420
                                }
1421
                                else
1422
                                {
1423
                                    SymbolModeling(connSymbol, null);
1424
                                    // Range 겹치는지 확인해야함
1425
                                    double[] prevRange = null;
1426
                                    GetSPPIDSymbolRange(prevSymbol, ref prevRange);
1427
                                    double[] connRange = null;
1428
                                    GetSPPIDSymbolRange(connSymbol, ref connRange);
1429
1430
                                    double distanceX = 0;
1431
                                    double distanceY = 0;
1432 6d12a734 gaqhf
                                    bool overlapX = false;
1433
                                    bool overlapY = false;
1434
                                    SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y);
1435
                                    SPPIDUtil.CalcOverlap(prevRange, connRange, ref distanceX, ref distanceY, ref overlapX, ref overlapY);
1436
                                    if ((slopeType == SlopeType.HORIZONTAL && overlapX) ||
1437
                                        (slopeType == SlopeType.VERTICAL && overlapY))
1438 d9794a6c gaqhf
                                    {
1439
                                        RemoveSymbol(connSymbol);
1440
                                        SPPIDUtil.CalcNewCoordinateForSymbol(connSymbol, prevSymbol, distanceX, distanceY);
1441
1442
                                        SymbolModeling(connSymbol, null);
1443
                                    }
1444
                                }
1445
                            }
1446 6db30942 gaqhf
                            SplashScreenManager.Default.SendCommand(SPPIDSplashScreen.SplashScreenCommand.SetProgress, document.SYMBOLS.FindAll(x => !string.IsNullOrEmpty(x.SPPID.RepresentationId)).Count);
1447 f1a7faf9 gaqhf
                            SymbolModelingByNeerSymbolLoop(connSymbol, endObjects);
1448 d9794a6c gaqhf
                        }
1449
                        else if (connItem.GetType() == typeof(Line))
1450
                        {
1451
                            Line connLine = connItem as Line;
1452
                            if (!SPPIDUtil.IsBranchLine(connLine, line))
1453 f1a7faf9 gaqhf
                                SymbolModelingByNeerLineLoop(connLine, endObjects, prevSymbol);
1454 d9794a6c gaqhf
                        }
1455 4d2571ab gaqhf
                    }
1456 d1eac84d gaqhf
                }
1457
            }
1458
        }
1459
1460 f1a7faf9 gaqhf
        private void SymbolGroupModeling(Symbol firstSymbol, List<Symbol> group)
1461
        {
1462
            List<Symbol> endModelingGroup = new List<Symbol>();
1463
            SymbolModeling(firstSymbol, null);
1464
            endModelingGroup.Add(firstSymbol);
1465
            while (endModelingGroup.Count != group.Count)
1466
            {
1467
                foreach (var _symbol in group)
1468
                {
1469
                    if (!endModelingGroup.Contains(_symbol))
1470
                    {
1471
                        foreach (var _connector in _symbol.CONNECTORS)
1472
                        {
1473
                            Symbol _connSymbol = SPPIDUtil.FindObjectByUID(document, _connector.CONNECTEDITEM) as Symbol;
1474
                            if (_connSymbol != null && endModelingGroup.Contains(_connSymbol))
1475
                            {
1476
                                SymbolModeling(_symbol, _connSymbol);
1477
                                endModelingGroup.Add(_symbol);
1478
                                break;
1479
                            }
1480
                        }
1481
                    }
1482
                }
1483
            }
1484
        }
1485 d9794a6c gaqhf
1486 d1eac84d gaqhf
        /// <summary>
1487 74752074 gaqhf
        /// 심볼을 실제로 Modeling할때 ChildSymbol이 있다면 Modeling하는 메서드
1488
        /// </summary>
1489
        /// <param name="childSymbol"></param>
1490
        /// <param name="parentSymbol"></param>
1491 4b4dbca9 gaqhf
        private void CreateChildSymbol(ChildSymbol childSymbol, LMSymbol parentSymbol)
1492 ac78b508 gaqhf
        {
1493 4b4dbca9 gaqhf
            Ingr.RAD2D.Symbol2d symbol2d = radApp.ActiveDocument.ActiveSheet.DrawingObjects[parentSymbol.get_GraphicOID().ToString()];
1494
            double x1 = 0;
1495
            double x2 = 0;
1496
            double y1 = 0;
1497
            double y2 = 0;
1498
            symbol2d.Range(out x1, out y1, out x2, out y2);
1499
1500
            LMSymbol _LMSymbol = _placement.PIDPlaceSymbol(childSymbol.SPPID.MAPPINGNAME, (x1 + x2) / 2, (y1 + y2) / 2, TargetItem: parentSymbol);
1501
            if (_LMSymbol != null)
1502
            {
1503
                childSymbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
1504
                foreach (var item in childSymbol.ChildSymbols)
1505
                    CreateChildSymbol(item, _LMSymbol);
1506
            }
1507 7f00b26c gaqhf
1508 ac78b508 gaqhf
1509
            ReleaseCOMObjects(_LMSymbol);
1510
        }
1511
1512 32205389 gaqhf
        private void NewLineModeling(Line line, bool isBranchModeling = false)
1513 809a7640 gaqhf
        {
1514 a0e3dca4 gaqhf
            if (!string.IsNullOrEmpty(line.SPPID.ModelItemId) || (NewBranchLines.Contains(line) && !isBranchModeling))
1515
                return;
1516
1517
            List<Line> group = new List<Line>();
1518
            GetConnectedLineGroup(line, group);
1519
            LineCoordinateCorrection(group);
1520
1521
            foreach (var groupLine in group)
1522 809a7640 gaqhf
            {
1523 5173ba5d gaqhf
                if (!isBranchModeling && SPPIDUtil.IsBranchLine(groupLine))
1524
                {
1525
                    NewBranchLines.Add(groupLine);
1526
                    continue;
1527
                }
1528 f9cc5190 gaqhf
1529 5173ba5d gaqhf
                _LMAItem _LMAItem = _placement.PIDCreateItem(groupLine.SPPID.MAPPINGNAME);
1530
                LMSymbol _LMSymbolStart = null;
1531
                LMSymbol _LMSymbolEnd = null;
1532
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1533
                foreach (var connector in groupLine.CONNECTORS)
1534 809a7640 gaqhf
                {
1535 5173ba5d gaqhf
                    double x = 0;
1536
                    double y = 0;
1537
                    GetTargetLineConnectorPoint(connector, groupLine, ref x, ref y);
1538
                    if (connector.ConnectedObject == null)
1539 809a7640 gaqhf
                    {
1540 5173ba5d gaqhf
                        placeRunInputs.AddPoint(x, y);
1541 a0e3dca4 gaqhf
                    }
1542 5173ba5d gaqhf
                    else if (connector.ConnectedObject.GetType() == typeof(Symbol))
1543 a0e3dca4 gaqhf
                    {
1544 5173ba5d gaqhf
                        Symbol targetSymbol = connector.ConnectedObject as Symbol;
1545 f9cc5190 gaqhf
                        GetTargetSymbolConnectorPoint(targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == groupLine), targetSymbol, ref x, ref y);
1546 5173ba5d gaqhf
                        if (groupLine.CONNECTORS.IndexOf(connector) == 0)
1547 a0e3dca4 gaqhf
                        {
1548 5173ba5d gaqhf
                            _LMSymbolStart = GetTargetSymbol(targetSymbol, groupLine);
1549
                            placeRunInputs.AddSymbolTarget(_LMSymbolStart, x, y);
1550
                        }
1551
                        else
1552
                        {
1553
                            _LMSymbolEnd = GetTargetSymbol(targetSymbol, groupLine);
1554
                            placeRunInputs.AddSymbolTarget(_LMSymbolEnd, x, y);
1555 a0e3dca4 gaqhf
                        }
1556 5173ba5d gaqhf
                    }
1557
                    else if (connector.ConnectedObject.GetType() == typeof(Line))
1558
                    {
1559
                        Line targetLine = connector.ConnectedObject as Line;
1560
                        if (!string.IsNullOrEmpty(targetLine.SPPID.ModelItemId))
1561 a0e3dca4 gaqhf
                        {
1562 5173ba5d gaqhf
                            LMConnector targetConnector = FindTargetLMConnectorForBranch(line, targetLine, ref x, ref y);
1563
                            placeRunInputs.AddConnectorTarget(targetConnector, x, y);
1564
                            ChangeLineSPPIDCoordinateByConnector(groupLine, targetLine, x, y, false);
1565 a0e3dca4 gaqhf
                        }
1566 5173ba5d gaqhf
                        else
1567 809a7640 gaqhf
                        {
1568 5173ba5d gaqhf
                            if (groupLine.CONNECTORS.IndexOf(connector) == 0)
1569 a0e3dca4 gaqhf
                            {
1570 5173ba5d gaqhf
                                if (groupLine.SlopeType == SlopeType.HORIZONTAL)
1571
                                    placeRunInputs.AddPoint(x, -0.1);
1572
                                else if (groupLine.SlopeType == SlopeType.VERTICAL)
1573
                                    placeRunInputs.AddPoint(-0.1, y);
1574
                                else
1575
                                    placeRunInputs.AddPoint(x, -0.1);
1576 a0e3dca4 gaqhf
                            }
1577 809a7640 gaqhf
1578 5173ba5d gaqhf
                            placeRunInputs.AddPoint(x, y);
1579 809a7640 gaqhf
1580 5173ba5d gaqhf
                            if (groupLine.CONNECTORS.IndexOf(connector) == 1)
1581
                            {
1582
                                if (groupLine.SlopeType == SlopeType.HORIZONTAL)
1583
                                    placeRunInputs.AddPoint(x, -0.1);
1584
                                else if (groupLine.SlopeType == SlopeType.VERTICAL)
1585
                                    placeRunInputs.AddPoint(-0.1, y);
1586
                                else
1587
                                    placeRunInputs.AddPoint(x, -0.1);
1588 a0e3dca4 gaqhf
                            }
1589 809a7640 gaqhf
                        }
1590
                    }
1591 5173ba5d gaqhf
                }
1592 809a7640 gaqhf
1593 5173ba5d gaqhf
                LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1594
                if (_lMConnector != null)
1595
                {
1596
                    groupLine.SPPID.ModelItemId = _lMConnector.ModelItemID;
1597
                    bool bRemodelingStart = false;
1598
                    if (_LMSymbolStart != null)
1599
                        NeedReModeling(groupLine, _LMSymbolStart, ref bRemodelingStart);
1600
                    bool bRemodelingEnd = false;
1601
                    if (_LMSymbolEnd != null)
1602
                        NeedReModeling(groupLine, _LMSymbolEnd, ref bRemodelingEnd);
1603
1604
                    if (bRemodelingStart || bRemodelingEnd)
1605
                        ReModelingLine(groupLine, _lMConnector, _LMSymbolStart, _LMSymbolEnd, bRemodelingStart, bRemodelingEnd);
1606 32205389 gaqhf
1607
                    FlowMarkModeling(groupLine);
1608
                    LineNumberModeling(groupLine);
1609
1610 5173ba5d gaqhf
                    ReleaseCOMObjects(_lMConnector);
1611
                }
1612 809a7640 gaqhf
1613 5173ba5d gaqhf
                List<object> removeLines = groupLine.CONNECTORS.FindAll(x =>
1614
                x.ConnectedObject != null &&
1615
                x.ConnectedObject.GetType() == typeof(Line) &&
1616
                !string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId))
1617
                .Select(x => x.ConnectedObject)
1618
                .ToList();
1619 2fdb56bf gaqhf
1620 5173ba5d gaqhf
                foreach (var item in removeLines)
1621
                    RemoveLineForModeling(item as Line);
1622 5e6ecf05 gaqhf
1623 5173ba5d gaqhf
                if (_LMAItem != null)
1624
                    ReleaseCOMObjects(_LMAItem);
1625
                if (placeRunInputs != null)
1626
                    ReleaseCOMObjects(placeRunInputs);
1627
                if (_LMSymbolStart != null)
1628
                    ReleaseCOMObjects(_LMSymbolStart);
1629
                if (_LMSymbolEnd != null)
1630
                    ReleaseCOMObjects(_LMSymbolEnd);
1631 5e6ecf05 gaqhf
1632 5173ba5d gaqhf
                if (isBranchModeling && NewBranchLines.Contains(groupLine))
1633
                    NewBranchLines.Remove(groupLine);
1634 a0e3dca4 gaqhf
            }
1635
        }
1636 5e6ecf05 gaqhf
1637 a0e3dca4 gaqhf
        private void RemoveLineForModeling(Line line)
1638
        {
1639
            LMModelItem modelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
1640
            if (modelItem != null)
1641
            {
1642
                foreach (LMRepresentation rep in modelItem.Representations)
1643
                {
1644
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
1645 7f00b26c gaqhf
                    {
1646 a0e3dca4 gaqhf
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
1647 32205389 gaqhf
                        dynamic OID = rep.get_GraphicOID().ToString();
1648 a0e3dca4 gaqhf
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1649
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1650
                        int verticesCount = lineStringGeometry.VertexCount;
1651
                        double[] vertices = null;
1652
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
1653
                        for (int i = 0; i < verticesCount; i++)
1654 7f00b26c gaqhf
                        {
1655 a0e3dca4 gaqhf
                            double x = 0;
1656
                            double y = 0;
1657
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
1658
                            if (verticesCount == 2 && x < 0 || y < 0)
1659
                                _placement.PIDRemovePlacement(rep);
1660 c2ec33f5 gaqhf
                        }
1661 a0e3dca4 gaqhf
                        ReleaseCOMObjects(_LMConnector);
1662 5e6ecf05 gaqhf
                    }
1663 a0e3dca4 gaqhf
                }
1664 7f00b26c gaqhf
1665 a0e3dca4 gaqhf
                ReleaseCOMObjects(modelItem);
1666
            }
1667
        }
1668
1669
        private void GetConnectedLineGroup(Line line, List<Line> group)
1670
        {
1671
            if (!group.Contains(line))
1672
                group.Add(line);
1673
            foreach (var connector in line.CONNECTORS)
1674
            {
1675
                if (connector.ConnectedObject != null &&
1676
                    connector.ConnectedObject.GetType() == typeof(Line) &&
1677
                    !group.Contains(connector.ConnectedObject) &&
1678
                    string.IsNullOrEmpty(((Line)connector.ConnectedObject).SPPID.ModelItemId))
1679
                {
1680
                    Line connLine = connector.ConnectedObject as Line;
1681
                    if (!SPPIDUtil.IsBranchLine(connLine, line))
1682
                        GetConnectedLineGroup(connLine, group);
1683 7f00b26c gaqhf
                }
1684
            }
1685 a0e3dca4 gaqhf
        }
1686 7f00b26c gaqhf
1687 a0e3dca4 gaqhf
        private void LineCoordinateCorrection(List<Line> group)
1688
        {
1689
            // 순서대로 전 Item 기준 정렬
1690
            LineCoordinateCorrectionByStart(group);
1691
1692
            // 역으로 심볼이 있을 경우 좌표 보정
1693
            LineCoordinateCorrectionForLastLine(group);
1694
        }
1695
1696
        private void LineCoordinateCorrectionByStart(List<Line> group)
1697
        {
1698
            for (int i = 0; i < group.Count; i++)
1699 7f00b26c gaqhf
            {
1700 a0e3dca4 gaqhf
                Line line = group[i];
1701
                if (i == 0)
1702 7f00b26c gaqhf
                {
1703 a0e3dca4 gaqhf
                    Connector symbolConnector = line.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol));
1704
                    if (symbolConnector != null)
1705
                        LineCoordinateCorrectionByConnItem(line, symbolConnector.ConnectedObject);
1706 7f00b26c gaqhf
                }
1707 a0e3dca4 gaqhf
                else if (i != 0)
1708 7f00b26c gaqhf
                {
1709 a0e3dca4 gaqhf
                    LineCoordinateCorrectionByConnItem(line, group[i - 1]);
1710
                }
1711
            }
1712
        }
1713 b66a2996 gaqhf
1714 a0e3dca4 gaqhf
        private void LineCoordinateCorrectionForLastLine(List<Line> group)
1715
        {
1716
            Line checkLine = group[group.Count - 1];
1717
            Connector lastSymbolConnector = checkLine.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Symbol));
1718
            if (lastSymbolConnector != null)
1719
            {
1720
                LineCoordinateCorrectionByConnItem(checkLine, lastSymbolConnector.ConnectedObject);
1721
                for (int i = group.Count - 2; i >= 0; i--)
1722
                {
1723
                    Line line = group[i + 1];
1724
                    Line prevLine = group[i];
1725 0bbd73b5 gaqhf
1726 a0e3dca4 gaqhf
                    // 같으면 보정
1727
                    if (line.SlopeType == prevLine.SlopeType)
1728
                        LineCoordinateCorrectionByConnItem(prevLine, line);
1729
                    else
1730 c2ec33f5 gaqhf
                    {
1731 a0e3dca4 gaqhf
                        if (line.SlopeType == SlopeType.HORIZONTAL)
1732 d63050d6 gaqhf
                        {
1733 a0e3dca4 gaqhf
                            double prevX = 0;
1734
                            double prevY = 0;
1735
                            GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY);
1736
                            ChangeLineSPPIDCoordinateByConnectorOnlyX(line, prevLine, prevX);
1737 d63050d6 gaqhf
1738 a0e3dca4 gaqhf
                            double x = 0;
1739
                            double y = 0;
1740
                            GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y);
1741
                            ChangeLineSPPIDCoordinateByConnectorOnlyY(prevLine, line, y);
1742 d63050d6 gaqhf
                        }
1743 a0e3dca4 gaqhf
                        else if (line.SlopeType == SlopeType.VERTICAL)
1744 d63050d6 gaqhf
                        {
1745 a0e3dca4 gaqhf
                            double prevX = 0;
1746
                            double prevY = 0;
1747
                            GetTargetLineConnectorPoint(prevLine.CONNECTORS.Find(z => z.ConnectedObject == line), prevLine, ref prevX, ref prevY);
1748
                            ChangeLineSPPIDCoordinateByConnectorOnlyY(line, prevLine, prevY);
1749 d63050d6 gaqhf
1750 a0e3dca4 gaqhf
                            double x = 0;
1751
                            double y = 0;
1752
                            GetTargetLineConnectorPoint(line.CONNECTORS.Find(z => z.ConnectedObject == prevLine), line, ref x, ref y);
1753
                            ChangeLineSPPIDCoordinateByConnectorOnlyX(prevLine, line, x);
1754 d63050d6 gaqhf
                        }
1755 a0e3dca4 gaqhf
                        break;
1756 c2ec33f5 gaqhf
                    }
1757 1ab9a205 gaqhf
                }
1758 c2ec33f5 gaqhf
            }
1759 a0e3dca4 gaqhf
        }
1760 7f00b26c gaqhf
1761 a0e3dca4 gaqhf
        private void LineCoordinateCorrectionByConnItem(Line line, object connItem)
1762
        {
1763
            double x = 0;
1764
            double y = 0;
1765
            if (connItem.GetType() == typeof(Symbol))
1766
            {
1767
                Symbol targetSymbol = connItem as Symbol;
1768
                Connector targetConnector = targetSymbol.CONNECTORS.Find(z => z.ConnectedObject == line);
1769
                if (targetConnector != null)
1770
                    GetTargetSymbolConnectorPoint(targetConnector, targetSymbol, ref x, ref y);
1771
                else
1772
                    throw new Exception("Target symbol UID : " + targetSymbol.UID + "\r\nLine UID : " + line.UID);
1773
            }
1774
            else if (connItem.GetType() == typeof(Line))
1775 c2ec33f5 gaqhf
            {
1776 a0e3dca4 gaqhf
                Line targetLine = connItem as Line;
1777
                GetTargetLineConnectorPoint(targetLine.CONNECTORS.Find(z => z.ConnectedObject == line), targetLine, ref x, ref y);
1778
            }
1779 7f00b26c gaqhf
1780 a0e3dca4 gaqhf
            ChangeLineSPPIDCoordinateByConnector(line, connItem, x, y);
1781
        }
1782 7f00b26c gaqhf
1783 a0e3dca4 gaqhf
        private void ChangeLineSPPIDCoordinateByConnector(Line line, object connItem, double x, double y, bool changeOtherCoordinate = true)
1784
        {
1785
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
1786
            int index = line.CONNECTORS.IndexOf(connector);
1787
            if (index == 0)
1788
            {
1789
                line.SPPID.START_X = x;
1790
                line.SPPID.START_Y = y;
1791
                if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate)
1792
                    line.SPPID.END_Y = y;
1793
                else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate)
1794
                    line.SPPID.END_X = x;
1795
            }
1796
            else
1797
            {
1798
                line.SPPID.END_X = x;
1799
                line.SPPID.END_Y = y;
1800
                if (line.SlopeType == SlopeType.HORIZONTAL && changeOtherCoordinate)
1801
                    line.SPPID.START_Y = y;
1802
                else if (line.SlopeType == SlopeType.VERTICAL && changeOtherCoordinate)
1803
                    line.SPPID.START_X = x;
1804 c2ec33f5 gaqhf
            }
1805 a0e3dca4 gaqhf
        }
1806 7f00b26c gaqhf
1807 a0e3dca4 gaqhf
        private void ChangeLineSPPIDCoordinateByConnectorOnlyX(Line line, object connItem, double x)
1808
        {
1809
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
1810
            int index = line.CONNECTORS.IndexOf(connector);
1811
            if (index == 0)
1812
            {
1813
                line.SPPID.START_X = x;
1814
                if (line.SlopeType == SlopeType.VERTICAL)
1815
                    line.SPPID.END_X = x;
1816
            }
1817
            else
1818
            {
1819
                line.SPPID.END_X = x;
1820
                if (line.SlopeType == SlopeType.VERTICAL)
1821
                    line.SPPID.START_X = x;
1822
            }
1823
        }
1824 7f00b26c gaqhf
1825 a0e3dca4 gaqhf
        private void ChangeLineSPPIDCoordinateByConnectorOnlyY(Line line, object connItem, double y)
1826
        {
1827
            Connector connector = line.CONNECTORS.Find(z => z.ConnectedObject == connItem);
1828
            int index = line.CONNECTORS.IndexOf(connector);
1829
            if (index == 0)
1830
            {
1831
                line.SPPID.START_Y = y;
1832
                if (line.SlopeType == SlopeType.HORIZONTAL)
1833
                    line.SPPID.END_Y = y;
1834
            }
1835
            else
1836
            {
1837
                line.SPPID.END_Y = y;
1838
                if (line.SlopeType == SlopeType.HORIZONTAL)
1839
                    line.SPPID.START_Y = y;
1840
            }
1841 1b261371 gaqhf
        }
1842
1843 0860c756 gaqhf
        private void NeedReModeling(Line line, LMSymbol symbol, ref bool result)
1844 ac82b020 gaqhf
        {
1845 0860c756 gaqhf
            if (symbol != null)
1846 ac82b020 gaqhf
            {
1847 fb386b8c gaqhf
                string repID = symbol.AsLMRepresentation().Id;
1848
                string symbolUID = SPPIDUtil.FindSymbolByRepresentationID(document, repID).UID;
1849
                string lineUID = line.UID;
1850 ac82b020 gaqhf
1851 fb386b8c gaqhf
                SpecBreak startSpecBreak = document.SpecBreaks.Find(x =>
1852
                (x.DownStreamUID == symbolUID || x.UpStreamUID == symbolUID) &&
1853
                (x.DownStreamUID == lineUID || x.UpStreamUID == lineUID));
1854 71ba1ca3 gaqhf
1855 fb386b8c gaqhf
                EndBreak startEndBreak = document.EndBreaks.Find(x =>
1856
                (x.OWNER == symbolUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbolUID) &&
1857
                (x.OWNER == lineUID || x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == lineUID));
1858 ac82b020 gaqhf
1859 fb386b8c gaqhf
                if (startSpecBreak != null || startEndBreak != null)
1860
                    result = true;
1861 ac82b020 gaqhf
            }
1862
        }
1863 7f00b26c gaqhf
1864 74752074 gaqhf
        /// <summary>
1865 1ab9a205 gaqhf
        /// Symbol에 붙을 경우 Line을 Remodeling 한다.
1866
        /// </summary>
1867
        /// <param name="lines"></param>
1868
        /// <param name="prevLMConnector"></param>
1869
        /// <param name="startSymbol"></param>
1870
        /// <param name="endSymbol"></param>
1871 5173ba5d gaqhf
        private void ReModelingLine(Line line, LMConnector prevLMConnector, LMSymbol startSymbol, LMSymbol endSymbol, bool bStart, bool bEnd)
1872 1ab9a205 gaqhf
        {
1873
            string symbolPath = string.Empty;
1874
            #region get symbol path
1875
            LMModelItem modelItem = dataSource.GetModelItem(prevLMConnector.ModelItemID);
1876
            foreach (LMRepresentation rep in modelItem.Representations)
1877
            {
1878
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
1879
                {
1880
                    symbolPath = rep.get_FileName();
1881
                    break;
1882
                }
1883
            }
1884
            #endregion
1885
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
1886
            LMConnector newConnector = null;
1887 32205389 gaqhf
            dynamic OID = prevLMConnector.get_GraphicOID().ToString();
1888 1ab9a205 gaqhf
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1889
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
1890
            int verticesCount = lineStringGeometry.VertexCount;
1891
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
1892 7f00b26c gaqhf
1893 1ab9a205 gaqhf
            List<double[]> vertices = new List<double[]>();
1894
            for (int i = 1; i <= verticesCount; i++)
1895
            {
1896
                double x = 0;
1897
                double y = 0;
1898
                lineStringGeometry.GetVertex(i, ref x, ref y);
1899
                vertices.Add(new double[] { x, y });
1900
            }
1901
1902
            for (int i = 0; i < vertices.Count; i++)
1903
            {
1904
                double[] points = vertices[i];
1905
                // 시작 심볼이 있고 첫번째 좌표일 때
1906
                if (startSymbol != null && i == 0)
1907
                {
1908 ac82b020 gaqhf
                    if (bStart)
1909
                    {
1910
                        SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i + 1][0], vertices[i + 1][1]);
1911
                        if (slopeType == SlopeType.HORIZONTAL)
1912
                            placeRunInputs.AddPoint(points[0], -0.1);
1913
                        else if (slopeType == SlopeType.VERTICAL)
1914
                            placeRunInputs.AddPoint(-0.1, points[1]);
1915
                        else
1916
                            placeRunInputs.AddPoint(points[0], -0.1);
1917 1ab9a205 gaqhf
1918 ac82b020 gaqhf
                        placeRunInputs.AddPoint(points[0], points[1]);
1919
                    }
1920
                    else
1921
                    {
1922 f1a7faf9 gaqhf
                        placeRunInputs.AddSymbolTarget(startSymbol, points[0], points[1]);
1923 ac82b020 gaqhf
                    }
1924 1ab9a205 gaqhf
                }
1925
                // 마지막 심볼이 있고 마지막 좌표일 때
1926
                else if (endSymbol != null && i == vertices.Count - 1)
1927
                {
1928 ac82b020 gaqhf
                    if (bEnd)
1929
                    {
1930
                        placeRunInputs.AddPoint(points[0], points[1]);
1931 1ab9a205 gaqhf
1932 ac82b020 gaqhf
                        SlopeType slopeType = SPPIDUtil.CalcSlope(points[0], points[1], vertices[i - 1][0], vertices[i - 1][1]);
1933
                        if (slopeType == SlopeType.HORIZONTAL)
1934
                            placeRunInputs.AddPoint(points[0], -0.1);
1935
                        else if (slopeType == SlopeType.VERTICAL)
1936
                            placeRunInputs.AddPoint(-0.1, points[1]);
1937
                        else
1938
                            placeRunInputs.AddPoint(points[0], -0.1);
1939
                    }
1940 1ab9a205 gaqhf
                    else
1941 ac82b020 gaqhf
                    {
1942 f1a7faf9 gaqhf
                        placeRunInputs.AddSymbolTarget(endSymbol, points[0], points[1]);
1943 ac82b020 gaqhf
                    }
1944 1ab9a205 gaqhf
                }
1945
                // 첫번째이며 시작 심볼이 아니고 Connecotr일 경우
1946
                else if (i == 0 && prevLMConnector.ConnectItem1SymbolObject != null)
1947 f1a7faf9 gaqhf
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem1SymbolObject, points[0], points[1]);
1948 1ab9a205 gaqhf
                // 마지막이며 마지막 심볼이 아니고 Connecotr일 경우
1949
                else if (i == vertices.Count - 1 && prevLMConnector.ConnectItem2SymbolObject != null)
1950 f1a7faf9 gaqhf
                    placeRunInputs.AddSymbolTarget(prevLMConnector.ConnectItem2SymbolObject, points[0], points[1]);
1951 1ab9a205 gaqhf
                else
1952
                    placeRunInputs.AddPoint(points[0], points[1]);
1953
            }
1954
1955
            _placement.PIDRemovePlacement(prevLMConnector.AsLMRepresentation());
1956
            newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1957
1958
            ReleaseCOMObjects(placeRunInputs);
1959
            ReleaseCOMObjects(_LMAItem);
1960
            ReleaseCOMObjects(modelItem);
1961
1962
            if (newConnector != null)
1963
            {
1964 ac82b020 gaqhf
                if (startSymbol != null && bStart)
1965 1ab9a205 gaqhf
                {
1966
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
1967
                    placeRunInputs = new PlaceRunInputs();
1968 f1a7faf9 gaqhf
                    placeRunInputs.AddSymbolTarget(startSymbol, vertices[0][0], vertices[0][1]);
1969
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[0][0], vertices[0][1]);
1970 1ab9a205 gaqhf
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1971
                    if (_LMConnector != null)
1972
                    {
1973
                        RemoveConnectorForReModelingLine(newConnector);
1974 87f02fc0 gaqhf
                        ZeroLengthModelItemID.Add(_LMConnector.ModelItemID);
1975 1ab9a205 gaqhf
                        ReleaseCOMObjects(_LMConnector);
1976
                    }
1977
                    ReleaseCOMObjects(placeRunInputs);
1978
                    ReleaseCOMObjects(_LMAItem);
1979
                }
1980
1981 ac82b020 gaqhf
                if (endSymbol != null && bEnd)
1982 1ab9a205 gaqhf
                {
1983
                    if (startSymbol != null)
1984
                    {
1985
                        Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(newConnector.ModelItemID);
1986
                        newConnector = dicVertices.First().Key;
1987
                    }
1988
1989
                    _LMAItem = _placement.PIDCreateItem(symbolPath);
1990
                    placeRunInputs = new PlaceRunInputs();
1991 f1a7faf9 gaqhf
                    placeRunInputs.AddSymbolTarget(endSymbol, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
1992
                    placeRunInputs.AddConnectorTarget(newConnector, vertices[vertices.Count - 1][0], vertices[vertices.Count - 1][1]);
1993 1ab9a205 gaqhf
                    LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
1994
                    if (_LMConnector != null)
1995
                    {
1996
                        RemoveConnectorForReModelingLine(newConnector);
1997 1ff0105e gaqhf
                        ZeroLengthModelItemIDReverse.Add(_LMConnector.ModelItemID);
1998 1ab9a205 gaqhf
                        ReleaseCOMObjects(_LMConnector);
1999
                    }
2000
                    ReleaseCOMObjects(placeRunInputs);
2001
                    ReleaseCOMObjects(_LMAItem);
2002
                }
2003
2004 5173ba5d gaqhf
                line.SPPID.ModelItemId = newConnector.ModelItemID;
2005 1ab9a205 gaqhf
                ReleaseCOMObjects(newConnector);
2006
            }
2007
2008
            ReleaseCOMObjects(modelItem);
2009
        }
2010
2011
        /// <summary>
2012
        /// Remodeling 과정에서 생긴 불필요한 Connector 제거
2013
        /// </summary>
2014
        /// <param name="connector"></param>
2015
        private void RemoveConnectorForReModelingLine(LMConnector connector)
2016
        {
2017
            Dictionary<LMConnector, List<double[]>> dicVertices = GetPipeRunVertices(connector.ModelItemID);
2018
            foreach (var item in dicVertices)
2019
            {
2020 1805d3b7 gaqhf
                if (item.Value.Count == 2)
2021 1ab9a205 gaqhf
                {
2022 1805d3b7 gaqhf
                    bool result = false;
2023
                    foreach (var point in item.Value)
2024 1ab9a205 gaqhf
                    {
2025 1805d3b7 gaqhf
                        if (point[0] < 0 || point[1] < 0)
2026
                        {
2027
                            result = true;
2028
                            _placement.PIDRemovePlacement(item.Key.AsLMRepresentation());
2029
                            break;
2030
                        }
2031 1ab9a205 gaqhf
                    }
2032
2033 1805d3b7 gaqhf
                    if (result)
2034
                        break;
2035
                }
2036 1ab9a205 gaqhf
            }
2037
            foreach (var item in dicVertices)
2038
                ReleaseCOMObjects(item.Key);
2039
        }
2040
2041
        /// <summary>
2042 74752074 gaqhf
        /// Symbol이 모델링된 SPPPID Symbol Object를 반환 - 연결된 Symbol이 ChildSymbol일 수도 있기때문에 메서드 개발
2043
        /// </summary>
2044
        /// <param name="symbol"></param>
2045
        /// <param name="line"></param>
2046
        /// <returns></returns>
2047 f2baa6a3 gaqhf
        private LMSymbol GetTargetSymbol(Symbol symbol, Line line)
2048
        {
2049
            LMSymbol _LMSymbol = null;
2050
            foreach (var connector in symbol.CONNECTORS)
2051
            {
2052 a0e3dca4 gaqhf
                if (connector.CONNECTEDITEM == line.UID)
2053 6b298450 gaqhf
                {
2054 a0e3dca4 gaqhf
                    if (connector.Index == 0)
2055
                        _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
2056
                    else
2057 0860c756 gaqhf
                    {
2058 a0e3dca4 gaqhf
                        ChildSymbol child = null;
2059
                        foreach (var childSymbol in symbol.ChildSymbols)
2060 0860c756 gaqhf
                        {
2061 a0e3dca4 gaqhf
                            if (childSymbol.Connectors.Contains(connector))
2062
                                child = childSymbol;
2063
                            else
2064
                                child = GetChildSymbolByConnector(childSymbol, connector);
2065
2066
                            if (child != null)
2067 0860c756 gaqhf
                                break;
2068
                        }
2069
2070 a0e3dca4 gaqhf
                        if (child != null)
2071
                            _LMSymbol = dataSource.GetSymbol(child.SPPID.RepresentationId);
2072 0860c756 gaqhf
                    }
2073
2074 a0e3dca4 gaqhf
                    break;
2075 335b7a24 gaqhf
                }
2076 a0e3dca4 gaqhf
            }
2077 335b7a24 gaqhf
2078 a0e3dca4 gaqhf
            return _LMSymbol;
2079
        }
2080
2081
        /// <summary>
2082
        /// Connector를 가지고 있는 ChildSymbol Object 반환
2083
        /// </summary>
2084
        /// <param name="item"></param>
2085
        /// <param name="connector"></param>
2086
        /// <returns></returns>
2087
        private ChildSymbol GetChildSymbolByConnector(ChildSymbol item, Connector connector)
2088
        {
2089
            foreach (var childSymbol in item.ChildSymbols)
2090
            {
2091
                if (childSymbol.Connectors.Contains(connector))
2092
                    return childSymbol;
2093
                else
2094
                    return GetChildSymbolByConnector(childSymbol, connector);
2095 335b7a24 gaqhf
            }
2096
2097 a0e3dca4 gaqhf
            return null;
2098 335b7a24 gaqhf
        }
2099
2100 74752074 gaqhf
        /// <summary>
2101
        /// EndBreak 모델링 메서드
2102
        /// </summary>
2103
        /// <param name="endBreak"></param>
2104 3165c259 gaqhf
        private void EndBreakModeling(EndBreak endBreak)
2105 335b7a24 gaqhf
        {
2106 10c7195c gaqhf
            object ownerObj = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER);
2107 1ab9a205 gaqhf
            object connectedItem = SPPIDUtil.FindObjectByUID(document, endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE);
2108
            LMConnector targetLMConnector = FindBreakLineTarget(ownerObj, connectedItem);
2109 3165c259 gaqhf
2110 1ab9a205 gaqhf
            if (targetLMConnector != null)
2111 10c7195c gaqhf
            {
2112 1ab9a205 gaqhf
                Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
2113
                LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
2114 5173ba5d gaqhf
                if (_LmLabelPersist != null)
2115
                {
2116
                    endBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id;
2117 d23fe61b gaqhf
                    if (_LmLabelPersist.ModelItemObject != null)
2118
                        endBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID;
2119 32205389 gaqhf
                    endBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID().ToString();
2120 5173ba5d gaqhf
                    ReleaseCOMObjects(_LmLabelPersist);
2121
                }
2122
                ReleaseCOMObjects(targetLMConnector);
2123 2a4872ec gaqhf
            }
2124
        }
2125 b9e9f4c8 gaqhf
2126 02480ac1 gaqhf
        private LMConnector ReModelingLMConnector(LMConnector connector)
2127
        {
2128 de97eaaa gaqhf
            string symbolPath = string.Empty;
2129
            #region get symbol path
2130
            LMModelItem modelItem = dataSource.GetModelItem(connector.ModelItemID);
2131
            foreach (LMRepresentation rep in modelItem.Representations)
2132
            {
2133
                if (!DBNull.Value.Equals(rep.get_FileName()) && !string.IsNullOrEmpty(rep.get_FileName()))
2134
                {
2135
                    symbolPath = rep.get_FileName();
2136
                    break;
2137
                }
2138
            }
2139
            #endregion
2140
2141 02480ac1 gaqhf
            LMConnector newConnector = null;
2142 32205389 gaqhf
            dynamic OID = connector.get_GraphicOID().ToString();
2143 02480ac1 gaqhf
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2144
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2145
            int verticesCount = lineStringGeometry.VertexCount;
2146
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
2147 de97eaaa gaqhf
            _LMAItem _LMAItem = _placement.PIDCreateItem(symbolPath);
2148 02480ac1 gaqhf
2149
            if (Convert.ToBoolean(connector.get_IsZeroLength()))
2150
            {
2151
                double[] vertices = null;
2152
                lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
2153
                double x = 0;
2154
                double y = 0;
2155
                lineStringGeometry.GetVertex(1, ref x, ref y);
2156
2157 f1a7faf9 gaqhf
                placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, x, y);
2158
                placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, x, y);
2159 02480ac1 gaqhf
2160 32205389 gaqhf
                string flowDirection = string.Empty;
2161
                LMAAttribute flowAttribute = connector.ModelItemObject.Attributes["FlowDirection"];
2162
                if (flowAttribute != null && !DBNull.Value.Equals(flowAttribute.get_Value()))
2163
                    flowDirection = flowAttribute.get_Value().ToString();
2164
2165 02480ac1 gaqhf
                _placement.PIDRemovePlacement(connector.AsLMRepresentation());
2166
                newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2167 644f40b3 gaqhf
                ZeroLengthSymbolToSymbolModelItemID.Add(newConnector.ModelItemID);
2168 32205389 gaqhf
                if (!string.IsNullOrEmpty(flowDirection))
2169
                    newConnector.ModelItemObject.Attributes["FlowDirection"].set_Value(flowDirection);
2170 02480ac1 gaqhf
            }
2171
            else
2172
            {
2173
                List<double[]> vertices = new List<double[]>();
2174
                for (int i = 1; i <= verticesCount; i++)
2175
                {
2176
                    double x = 0;
2177
                    double y = 0;
2178
                    lineStringGeometry.GetVertex(i, ref x, ref y);
2179
                    vertices.Add(new double[] { x, y });
2180
                }
2181
2182
                for (int i = 0; i < vertices.Count; i++)
2183
                {
2184
                    double[] points = vertices[i];
2185
                    if (i == 0)
2186
                    {
2187
                        if (connector.ConnectItem1SymbolObject != null)
2188 f1a7faf9 gaqhf
                            placeRunInputs.AddSymbolTarget(connector.ConnectItem1SymbolObject, points[0], points[1]);
2189 02480ac1 gaqhf
                        else
2190
                            placeRunInputs.AddPoint(points[0], points[1]);
2191
                    }
2192
                    else if (i == vertices.Count - 1)
2193
                    {
2194
                        if (connector.ConnectItem2SymbolObject != null)
2195 f1a7faf9 gaqhf
                            placeRunInputs.AddSymbolTarget(connector.ConnectItem2SymbolObject, points[0], points[1]);
2196 02480ac1 gaqhf
                        else
2197
                            placeRunInputs.AddPoint(points[0], points[1]);
2198
                    }
2199
                    else
2200
                        placeRunInputs.AddPoint(points[0], points[1]);
2201
                }
2202
2203
                List<Line> lines = SPPIDUtil.FindLinesByModelId(document, connector.ModelItemID);
2204
2205
                _placement.PIDRemovePlacement(connector.AsLMRepresentation());
2206
                newConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
2207
2208
                foreach (var line in lines)
2209
                    line.SPPID.ModelItemId = newConnector.ModelItemID;
2210
            }
2211
2212
2213
            return newConnector;
2214
        }
2215
2216 74752074 gaqhf
        /// <summary>
2217 53c81765 gaqhf
        /// SpecBreak Modeling 메서드
2218
        /// </summary>
2219
        /// <param name="specBreak"></param>
2220
        private void SpecBreakModeling(SpecBreak specBreak)
2221
        {
2222
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
2223
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
2224
2225
            if (upStreamObj != null &&
2226
                downStreamObj != null)
2227
            {
2228 1ab9a205 gaqhf
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
2229
2230
                if (targetLMConnector != null)
2231 53c81765 gaqhf
                {
2232 16584d30 gaqhf
                    foreach (var attribute in specBreak.ATTRIBUTES)
2233 53c81765 gaqhf
                    {
2234 16584d30 gaqhf
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID);
2235
                        if (mapping != null && !string.IsNullOrEmpty(mapping.SPPIDSYMBOLNAME) && mapping.SPPIDSYMBOLNAME != "None")
2236
                        {
2237
                            string MappingPath = mapping.SPPIDSYMBOLNAME;
2238
                            Array array = new double[] { 0, specBreak.SPPID.ORIGINAL_X, specBreak.SPPID.ORIGINAL_Y };
2239
                            LMLabelPersist _LmLabelPersist = _placement.PIDPlaceLabel(MappingPath, ref array, Rotation: specBreak.ANGLE, LabeledItem: targetLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
2240 53c81765 gaqhf
2241 16584d30 gaqhf
                            if (_LmLabelPersist != null)
2242
                            {
2243 5173ba5d gaqhf
                                specBreak.SPPID.RepresentationId = _LmLabelPersist.AsLMRepresentation().Id;
2244 d23fe61b gaqhf
                                if (_LmLabelPersist.ModelItemObject != null)
2245
                                    specBreak.SPPID.ModelItemID = _LmLabelPersist.ModelItemID;
2246 32205389 gaqhf
                                specBreak.SPPID.GraphicOID = _LmLabelPersist.get_GraphicOID().ToString();
2247 16584d30 gaqhf
                                ReleaseCOMObjects(_LmLabelPersist);
2248
                            }
2249
                        }
2250
                    }
2251 1ab9a205 gaqhf
                    ReleaseCOMObjects(targetLMConnector);
2252
                }
2253
            }
2254
        }
2255 53c81765 gaqhf
2256 1ab9a205 gaqhf
        private LMConnector FindBreakLineTarget(object targetObj, object connectedObj)
2257
        {
2258
            LMConnector targetConnector = null;
2259
            Symbol targetSymbol = targetObj as Symbol;
2260
            Symbol connectedSymbol = connectedObj as Symbol;
2261
            Line targetLine = targetObj as Line;
2262
            Line connectedLine = connectedObj as Line;
2263
            if (targetSymbol != null && connectedSymbol != null)
2264
            {
2265
                LMSymbol targetLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
2266
                LMSymbol connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId);
2267
2268
                foreach (LMConnector connector in targetLMSymbol.Avoid1Connectors)
2269
                {
2270
                    if (connector.get_ItemStatus() != "Active")
2271
                        continue;
2272
2273
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
2274
                    {
2275
                        targetConnector = connector;
2276
                        break;
2277
                    }
2278
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
2279
                    {
2280
                        targetConnector = connector;
2281
                        break;
2282 53c81765 gaqhf
                    }
2283
                }
2284 1ab9a205 gaqhf
2285
                foreach (LMConnector connector in targetLMSymbol.Avoid2Connectors)
2286 53c81765 gaqhf
                {
2287 1ab9a205 gaqhf
                    if (connector.get_ItemStatus() != "Active")
2288
                        continue;
2289 53c81765 gaqhf
2290 1ab9a205 gaqhf
                    if (connector.ConnectItem1SymbolObject.Id == connectedLMSymbol.Id)
2291
                    {
2292
                        targetConnector = connector;
2293
                        break;
2294
                    }
2295
                    else if (connector.ConnectItem2SymbolObject.Id == connectedLMSymbol.Id)
2296
                    {
2297
                        targetConnector = connector;
2298
                        break;
2299 53c81765 gaqhf
                    }
2300
                }
2301 1ab9a205 gaqhf
2302
                ReleaseCOMObjects(targetLMSymbol);
2303
                ReleaseCOMObjects(connectedLMSymbol);
2304
            }
2305
            else if (targetLine != null && connectedLine != null)
2306
            {
2307
                LMModelItem targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId);
2308
                LMModelItem connectedModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
2309
2310
                if (targetModelItem != null && connectedModelItem != null)
2311 53c81765 gaqhf
                {
2312 1ab9a205 gaqhf
                    foreach (LMRepresentation rep in targetModelItem.Representations)
2313 53c81765 gaqhf
                    {
2314 1ab9a205 gaqhf
                        if (targetConnector != null)
2315
                            break;
2316 53c81765 gaqhf
2317 1ab9a205 gaqhf
                        if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2318 53c81765 gaqhf
                        {
2319 1ab9a205 gaqhf
                            LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2320
2321
                            if (IsConnected(_LMConnector, connectedModelItem))
2322
                                targetConnector = _LMConnector;
2323
                            else
2324
                                ReleaseCOMObjects(_LMConnector);
2325 53c81765 gaqhf
                        }
2326
                    }
2327 1ab9a205 gaqhf
2328
                    ReleaseCOMObjects(targetModelItem);
2329 53c81765 gaqhf
                }
2330 1ab9a205 gaqhf
            }
2331
            else
2332
            {
2333 340515a2 gaqhf
                LMSymbol connectedLMSymbol = null;
2334
                if (connectedSymbol != null)
2335
                    connectedLMSymbol = dataSource.GetSymbol(connectedSymbol.SPPID.RepresentationId);
2336
                else if (targetSymbol != null)
2337
                    connectedLMSymbol = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
2338
                else
2339
                {
2340
2341
                }
2342
                LMModelItem targetModelItem = null;
2343
                if (targetLine != null)
2344
                    targetModelItem = dataSource.GetModelItem(targetLine.SPPID.ModelItemId);
2345
                else if (connectedLine != null)
2346
                    targetModelItem = dataSource.GetModelItem(connectedLine.SPPID.ModelItemId);
2347
                else
2348
                {
2349
2350
                }
2351 1ab9a205 gaqhf
                if (connectedLMSymbol != null && targetModelItem != null)
2352 53c81765 gaqhf
                {
2353 1ab9a205 gaqhf
                    foreach (LMConnector connector in connectedLMSymbol.Avoid1Connectors)
2354
                    {
2355 ac82b020 gaqhf
                        if (connector.get_ItemStatus() != "Active")
2356
                            continue;
2357
2358 1ab9a205 gaqhf
                        if (IsConnected(connector, targetModelItem))
2359
                        {
2360
                            targetConnector = connector;
2361
                            break;
2362
                        }
2363
                    }
2364 53c81765 gaqhf
2365 1ab9a205 gaqhf
                    if (targetConnector == null)
2366 53c81765 gaqhf
                    {
2367 1ab9a205 gaqhf
                        foreach (LMConnector connector in connectedLMSymbol.Avoid2Connectors)
2368 53c81765 gaqhf
                        {
2369 ac82b020 gaqhf
                            if (connector.get_ItemStatus() != "Active")
2370
                                continue;
2371
2372 1ab9a205 gaqhf
                            if (IsConnected(connector, targetModelItem))
2373 53c81765 gaqhf
                            {
2374 1ab9a205 gaqhf
                                targetConnector = connector;
2375
                                break;
2376 53c81765 gaqhf
                            }
2377
                        }
2378
                    }
2379
                }
2380
2381 1ab9a205 gaqhf
            }
2382 02480ac1 gaqhf
2383 1ab9a205 gaqhf
            return targetConnector;
2384
        }
2385 53c81765 gaqhf
2386 1ab9a205 gaqhf
        private bool IsConnected(LMConnector connector, LMModelItem modelItem)
2387
        {
2388
            bool result = false;
2389
2390
            foreach (LMRepresentation rep in modelItem.Representations)
2391
            {
2392
                if (result)
2393
                    break;
2394
2395
                if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2396
                {
2397
                    LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2398
2399
                    if (_LMConnector.ConnectItem1SymbolObject != null &&
2400
                        connector.ConnectItem1SymbolObject != null &&
2401
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2402 53c81765 gaqhf
                    {
2403 1ab9a205 gaqhf
                        result = true;
2404
                        ReleaseCOMObjects(_LMConnector);
2405
                        break;
2406
                    }
2407
                    else if (_LMConnector.ConnectItem1SymbolObject != null &&
2408
                        connector.ConnectItem2SymbolObject != null &&
2409
                        _LMConnector.ConnectItem1SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2410
                    {
2411
                        result = true;
2412
                        ReleaseCOMObjects(_LMConnector);
2413
                        break;
2414
                    }
2415
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2416
                        connector.ConnectItem1SymbolObject != null &&
2417
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem1SymbolObject.Id)
2418
                    {
2419
                        result = true;
2420
                        ReleaseCOMObjects(_LMConnector);
2421
                        break;
2422
                    }
2423
                    else if (_LMConnector.ConnectItem2SymbolObject != null &&
2424
                        connector.ConnectItem2SymbolObject != null &&
2425
                        _LMConnector.ConnectItem2SymbolObject.Id == connector.ConnectItem2SymbolObject.Id)
2426
                    {
2427
                        result = true;
2428
                        ReleaseCOMObjects(_LMConnector);
2429
                        break;
2430 53c81765 gaqhf
                    }
2431
2432 1ab9a205 gaqhf
                    ReleaseCOMObjects(_LMConnector);
2433
                }
2434 53c81765 gaqhf
            }
2435 1ab9a205 gaqhf
2436
2437
            return result;
2438 53c81765 gaqhf
        }
2439
2440
        /// <summary>
2441 74752074 gaqhf
        /// FromModelItem을 ToModelItem으로 PipeRunJoin하는 메서드
2442
        /// </summary>
2443 644f40b3 gaqhf
        /// <param name="modelItemID1"></param>
2444
        /// <param name="modelItemID2"></param>
2445
        private void JoinPipeRun(string modelItemID1, string modelItemID2)
2446 335b7a24 gaqhf
        {
2447 644f40b3 gaqhf
            LMModelItem modelItem1 = dataSource.GetModelItem(modelItemID2);
2448 310aeb31 gaqhf
            _LMAItem item1 = modelItem1.AsLMAItem();
2449 644f40b3 gaqhf
            LMModelItem modelItem2 = dataSource.GetModelItem(modelItemID1);
2450 310aeb31 gaqhf
            _LMAItem item2 = modelItem2.AsLMAItem();
2451 3939eebf gaqhf
2452 7f00b26c gaqhf
            // item2가 item1으로 조인
2453
            _placement.PIDJoinRuns(ref item1, ref item2);
2454
            item1.Commit();
2455
            item2.Commit();
2456
2457 644f40b3 gaqhf
            string beforeID = string.Empty;
2458
            string afterID = string.Empty;
2459
2460
            if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() != "Active")
2461
            {
2462
                beforeID = modelItem2.Id;
2463
                afterID = modelItem1.Id;
2464
            }
2465
            else if (modelItem1.get_ItemStatus() != "Active" && modelItem2.get_ItemStatus() == "Active")
2466
            {
2467
                beforeID = modelItem1.Id;
2468
                afterID = modelItem2.Id;
2469
            }
2470
            else
2471
            {
2472
                throw new Exception("확인 필요한 케이스");
2473
            }
2474
2475
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, beforeID);
2476 7f00b26c gaqhf
            foreach (var line in lines)
2477 644f40b3 gaqhf
                line.SPPID.ModelItemId = afterID;
2478 7f00b26c gaqhf
2479
            ReleaseCOMObjects(modelItem1);
2480
            ReleaseCOMObjects(item1);
2481
            ReleaseCOMObjects(modelItem2);
2482
            ReleaseCOMObjects(item2);
2483 335b7a24 gaqhf
        }
2484
2485 74752074 gaqhf
        /// <summary>
2486
        /// PipeRun을 자동으로 Join하는 메서드
2487
        /// </summary>
2488
        /// <param name="modelItemId"></param>
2489 335b7a24 gaqhf
        private void AutoJoinPipeRun(string modelItemId)
2490
        {
2491 310aeb31 gaqhf
            LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
2492
            _LMAItem item = modelItem.AsLMAItem();
2493 7f00b26c gaqhf
            if (modelItem.get_ItemStatus() == "Active")
2494 65a1ed4b gaqhf
            {
2495 7f00b26c gaqhf
                string modelitemID = item.Id;
2496
                _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item);
2497
                string afterModelItemID = item.Id;
2498 87f02fc0 gaqhf
2499 7f00b26c gaqhf
                if (modelitemID != afterModelItemID)
2500
                {
2501
                    List<Line> lines = SPPIDUtil.FindLinesByModelId(document, modelitemID);
2502
                    foreach (var line in lines)
2503
                        line.SPPID.ModelItemId = afterModelItemID;
2504 65a1ed4b gaqhf
                }
2505 7f00b26c gaqhf
                item.Commit();
2506 65a1ed4b gaqhf
            }
2507 7f00b26c gaqhf
2508
            ReleaseCOMObjects(modelItem);
2509
            ReleaseCOMObjects(item);
2510 335b7a24 gaqhf
        }
2511
2512 74752074 gaqhf
        /// <summary>
2513
        /// LineRun에 있는 Line들을 Join하는 진입 메서드
2514
        /// </summary>
2515
        /// <param name="run"></param>
2516 335b7a24 gaqhf
        private void JoinRunLine(LineRun run)
2517
        {
2518
            string modelItemId = string.Empty;
2519
            foreach (var item in run.RUNITEMS)
2520
            {
2521
                if (item.GetType() == typeof(Line))
2522
                {
2523
                    Line line = item as Line;
2524 1ba9c671 gaqhf
                    AutoJoinPipeRun(line.SPPID.ModelItemId);
2525
                    modelItemId = line.SPPID.ModelItemId;
2526 335b7a24 gaqhf
                }
2527
            }
2528
        }
2529
2530 74752074 gaqhf
        /// <summary>
2531
        /// PipeRun의 좌표를 가져오는 메서드
2532
        /// </summary>
2533
        /// <param name="modelId"></param>
2534
        /// <returns></returns>
2535 5e6ecf05 gaqhf
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
2536
        {
2537
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
2538 310aeb31 gaqhf
            LMModelItem modelItem = dataSource.GetModelItem(modelId);
2539
2540
            if (modelItem != null)
2541 5e6ecf05 gaqhf
            {
2542 310aeb31 gaqhf
                foreach (LMRepresentation rep in modelItem.Representations)
2543 5e6ecf05 gaqhf
                {
2544
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2545
                    {
2546
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
2547
                        connectorVertices.Add(_LMConnector, new List<double[]>());
2548 32205389 gaqhf
                        dynamic OID = rep.get_GraphicOID().ToString();
2549 335b7a24 gaqhf
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2550 5e6ecf05 gaqhf
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2551
                        int verticesCount = lineStringGeometry.VertexCount;
2552
                        double[] vertices = null;
2553
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
2554
                        for (int i = 0; i < verticesCount; i++)
2555
                        {
2556
                            double x = 0;
2557
                            double y = 0;
2558
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
2559 32205389 gaqhf
                            connectorVertices[_LMConnector].Add(new double[] { x, y });
2560 5e6ecf05 gaqhf
                        }
2561
                    }
2562
                }
2563
2564 310aeb31 gaqhf
                ReleaseCOMObjects(modelItem);
2565 5e6ecf05 gaqhf
            }
2566
2567
            return connectorVertices;
2568
        }
2569
2570 32205389 gaqhf
        private List<double[]> GetConnectorVertices(LMConnector connector)
2571
        {
2572
            List<double[]> vertices = new List<double[]>();
2573
            dynamic OID = connector.get_GraphicOID().ToString();
2574
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
2575
            Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
2576
            int verticesCount = lineStringGeometry.VertexCount;
2577
            double[] value = null;
2578
            lineStringGeometry.GetVertices(ref verticesCount, ref value);
2579
            for (int i = 0; i < verticesCount; i++)
2580
            {
2581
                double x = 0;
2582
                double y = 0;
2583
                lineStringGeometry.GetVertex(i + 1, ref x, ref y);
2584
                vertices.Add(new double[] { x, y });
2585
            }
2586
            return vertices;
2587
        }
2588
2589 7c7bcd10 gaqhf
        /// <summary>
2590 a0e3dca4 gaqhf
        /// 좌표로 PipeRun의 Connector중에 어느 Connector에 가까운지/붙을지 가져오는 메서드 - 조건에 안맞아서 못찾을시 제일 가까운 점으로 가져오는 방식
2591 74752074 gaqhf
        /// </summary>
2592
        /// <param name="connectorVertices"></param>
2593
        /// <param name="connX"></param>
2594
        /// <param name="connY"></param>
2595
        /// <returns></returns>
2596 a0e3dca4 gaqhf
        private LMConnector FindTargetLMConnectorForLabel(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY)
2597 5e6ecf05 gaqhf
        {
2598
            double length = double.MaxValue;
2599
            LMConnector targetConnector = null;
2600
            foreach (var item in connectorVertices)
2601
            {
2602
                List<double[]> points = item.Value;
2603
                for (int i = 0; i < points.Count - 1; i++)
2604
                {
2605
                    double[] point1 = points[i];
2606
                    double[] point2 = points[i + 1];
2607 a0e3dca4 gaqhf
                    double x1 = Math.Min(point1[0], point2[0]);
2608
                    double y1 = Math.Min(point1[1], point2[1]);
2609
                    double x2 = Math.Max(point1[0], point2[0]);
2610
                    double y2 = Math.Max(point1[1], point2[1]);
2611 5e6ecf05 gaqhf
2612 a0e3dca4 gaqhf
                    if ((x1 <= connX && x2 >= connX) ||
2613
                        (y1 <= connY && y2 >= connY))
2614 5e6ecf05 gaqhf
                    {
2615 a0e3dca4 gaqhf
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point1[0], point1[1], connX, connY);
2616 335b7a24 gaqhf
                        if (length >= distance)
2617 30a9ffce gaqhf
                        {
2618 a0e3dca4 gaqhf
                            targetConnector = item.Key;
2619
                            length = distance;
2620
                        }
2621
2622
                        distance = SPPIDUtil.CalcPointToPointdDistance(point2[0], point2[1], connX, connY);
2623
                        if (length >= distance)
2624
                        {
2625
                            targetConnector = item.Key;
2626
                            length = distance;
2627 30a9ffce gaqhf
                        }
2628 5e6ecf05 gaqhf
                    }
2629
                }
2630 c3d2e266 gaqhf
            }
2631
2632 a0e3dca4 gaqhf
            // 못찾았을때.
2633
            length = double.MaxValue;
2634 c3d2e266 gaqhf
            if (targetConnector == null)
2635
            {
2636
                foreach (var item in connectorVertices)
2637
                {
2638
                    List<double[]> points = item.Value;
2639 a0e3dca4 gaqhf
2640
                    foreach (double[] point in points)
2641 c3d2e266 gaqhf
                    {
2642 a0e3dca4 gaqhf
                        double distance = SPPIDUtil.CalcPointToPointdDistance(point[0], point[1], connX, connY);
2643 c3d2e266 gaqhf
                        if (length >= distance)
2644
                        {
2645
                            targetConnector = item.Key;
2646
                            length = distance;
2647
                        }
2648
                    }
2649
                }
2650 5e6ecf05 gaqhf
            }
2651
2652
            return targetConnector;
2653
        }
2654
2655 a0e3dca4 gaqhf
        private LMConnector FindTargetLMConnectorForBranch(Line line, Line targetLine, ref double x, ref double y)
2656 ac78b508 gaqhf
        {
2657 a0e3dca4 gaqhf
            Dictionary<LMConnector, List<double[]>> vertices = GetPipeRunVertices(targetLine.SPPID.ModelItemId);
2658
2659 ac78b508 gaqhf
            double length = double.MaxValue;
2660
            LMConnector targetConnector = null;
2661 a0e3dca4 gaqhf
            double[] resultPoint = null;
2662
            List<double[]> targetVertices = null;
2663
2664
            // Vertices 포인트에 제일 가까운곳
2665
            foreach (var item in vertices)
2666 ac78b508 gaqhf
            {
2667
                List<double[]> points = item.Value;
2668 a0e3dca4 gaqhf
                for (int i = 0; i < points.Count; i++)
2669 ac78b508 gaqhf
                {
2670 a0e3dca4 gaqhf
                    double[] point = points[i];
2671
                    double tempX = point[0];
2672
                    double tempY = point[1];
2673
2674
                    double distance = SPPIDUtil.CalcPointToPointdDistance(tempX, tempY, x, y);
2675 ac78b508 gaqhf
                    if (length >= distance)
2676
                    {
2677
                        targetConnector = item.Key;
2678
                        length = distance;
2679 a0e3dca4 gaqhf
                        resultPoint = point;
2680
                        targetVertices = item.Value;
2681 ac78b508 gaqhf
                    }
2682
                }
2683
            }
2684
2685 a0e3dca4 gaqhf
            // Vertices Cross에 제일 가까운곳
2686
            foreach (var item in vertices)
2687 68464385 gaqhf
            {
2688
                List<double[]> points = item.Value;
2689
                for (int i = 0; i < points.Count - 1; i++)
2690
                {
2691
                    double[] point1 = points[i];
2692
                    double[] point2 = points[i + 1];
2693
2694 a0e3dca4 gaqhf
                    double maxLineX = Math.Max(point1[0], point2[0]);
2695
                    double minLineX = Math.Min(point1[0], point2[0]);
2696
                    double maxLineY = Math.Max(point1[1], point2[1]);
2697
                    double minLineY = Math.Min(point1[1], point2[1]);
2698 68464385 gaqhf
2699 a0e3dca4 gaqhf
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
2700
2701
                    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]);
2702
                    if (crossingPoint != null)
2703
                    {
2704
                        double distance = SPPIDUtil.CalcPointToPointdDistance(crossingPoint[0], crossingPoint[1], x, y);
2705 68464385 gaqhf
                        if (length >= distance)
2706
                        {
2707 a0e3dca4 gaqhf
                            if (slope == SlopeType.Slope &&
2708
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
2709
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
2710
                            {
2711
                                targetConnector = item.Key;
2712
                                length = distance;
2713
                                resultPoint = crossingPoint;
2714
                                targetVertices = item.Value;
2715
                            }
2716
                            else if (slope == SlopeType.HORIZONTAL &&
2717
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
2718
                            {
2719
                                targetConnector = item.Key;
2720
                                length = distance;
2721
                                resultPoint = crossingPoint;
2722
                                targetVertices = item.Value;
2723
                            }
2724
                            else if (slope == SlopeType.VERTICAL &&
2725
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
2726
                            {
2727
                                targetConnector = item.Key;
2728
                                length = distance;
2729
                                resultPoint = crossingPoint;
2730
                                targetVertices = item.Value;
2731
                            }
2732 68464385 gaqhf
                        }
2733
                    }
2734
                }
2735
            }
2736
2737 a0e3dca4 gaqhf
            foreach (var item in vertices)
2738
                if (item.Key != null && item.Key != targetConnector)
2739
                    ReleaseCOMObjects(item.Key);
2740
2741
            if (SPPIDUtil.IsBranchLine(line, targetLine))
2742 68464385 gaqhf
            {
2743 a0e3dca4 gaqhf
                double tempResultX = resultPoint[0];
2744
                double tempResultY = resultPoint[1];
2745
                SPPIDUtil.ConvertGridPoint(ref tempResultX, ref tempResultY);
2746 68464385 gaqhf
2747 a0e3dca4 gaqhf
                GridSetting gridSetting = GridSetting.GetInstance();
2748
2749
                for (int i = 0; i < targetVertices.Count; i++)
2750
                {
2751
                    double[] point = targetVertices[i];
2752
                    double tempX = targetVertices[i][0];
2753
                    double tempY = targetVertices[i][1];
2754
                    SPPIDUtil.ConvertGridPoint(ref tempX, ref tempY);
2755
                    if (tempX == tempResultX && tempY == tempResultY)
2756 68464385 gaqhf
                    {
2757 a0e3dca4 gaqhf
                        if (i == 0)
2758 68464385 gaqhf
                        {
2759 a0e3dca4 gaqhf
                            LMSymbol connSymbol = targetConnector.ConnectItem1SymbolObject;
2760 b01e7456 gaqhf
                            bool containZeroLength = false;
2761
                            if (connSymbol != null)
2762 a0e3dca4 gaqhf
                            {
2763 1805d3b7 gaqhf
                                foreach (LMConnector connector in connSymbol.Connect1Connectors)
2764
                                {
2765 b01e7456 gaqhf
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
2766 1805d3b7 gaqhf
                                        containZeroLength = true;
2767
                                }
2768
                                foreach (LMConnector connector in connSymbol.Connect2Connectors)
2769 a0e3dca4 gaqhf
                                {
2770 b01e7456 gaqhf
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
2771 1805d3b7 gaqhf
                                        containZeroLength = true;
2772 a0e3dca4 gaqhf
                                }
2773 b01e7456 gaqhf
                            }
2774
2775
                            if (connSymbol == null ||
2776
                                (connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") ||
2777
                                containZeroLength)
2778
                            {
2779
                                bool bCalcX = false;
2780
                                bool bCalcY = false;
2781
                                if (targetLine.SlopeType == SlopeType.HORIZONTAL)
2782
                                    bCalcX = true;
2783
                                else if (targetLine.SlopeType == SlopeType.VERTICAL)
2784
                                    bCalcY = true;
2785
                                else
2786
                                {
2787
                                    bCalcX = true;
2788
                                    bCalcY = true;
2789
                                }
2790 a0e3dca4 gaqhf
2791 b01e7456 gaqhf
                                if (bCalcX)
2792 a0e3dca4 gaqhf
                                {
2793 b01e7456 gaqhf
                                    double nextX = targetVertices[i + 1][0];
2794
                                    double newX = 0;
2795
                                    if (nextX > tempX)
2796
                                    {
2797
                                        newX = tempX + gridSetting.Length;
2798
                                        if (newX > nextX)
2799
                                            newX = (point[0] + nextX) / 2;
2800
                                    }
2801 a0e3dca4 gaqhf
                                    else
2802
                                    {
2803 b01e7456 gaqhf
                                        newX = tempX - gridSetting.Length;
2804
                                        if (newX < nextX)
2805
                                            newX = (point[0] + nextX) / 2;
2806 a0e3dca4 gaqhf
                                    }
2807 b01e7456 gaqhf
                                    resultPoint = new double[] { newX, resultPoint[1] };
2808
                                }
2809 a0e3dca4 gaqhf
2810 b01e7456 gaqhf
                                if (bCalcY)
2811
                                {
2812
                                    double nextY = targetVertices[i + 1][1];
2813
                                    double newY = 0;
2814
                                    if (nextY > tempY)
2815 a0e3dca4 gaqhf
                                    {
2816 b01e7456 gaqhf
                                        newY = tempY + gridSetting.Length;
2817
                                        if (newY > nextY)
2818
                                            newY = (point[1] + nextY) / 2;
2819 a0e3dca4 gaqhf
                                    }
2820 b01e7456 gaqhf
                                    else
2821 a0e3dca4 gaqhf
                                    {
2822 b01e7456 gaqhf
                                        newY = tempY - gridSetting.Length;
2823
                                        if (newY < nextY)
2824
                                            newY = (point[1] + nextY) / 2;
2825 a0e3dca4 gaqhf
                                    }
2826 b01e7456 gaqhf
                                    resultPoint = new double[] { resultPoint[0], newY };
2827 a0e3dca4 gaqhf
                                }
2828
                            }
2829
                        }
2830
                        else if (i == targetVertices.Count - 1)
2831
                        {
2832
                            LMSymbol connSymbol = targetConnector.ConnectItem2SymbolObject;
2833 b01e7456 gaqhf
                            bool containZeroLength = false;
2834
                            if (connSymbol != null)
2835 a0e3dca4 gaqhf
                            {
2836 1805d3b7 gaqhf
                                foreach (LMConnector connector in connSymbol.Connect1Connectors)
2837
                                {
2838 b01e7456 gaqhf
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
2839 1805d3b7 gaqhf
                                        containZeroLength = true;
2840
                                }
2841
                                foreach (LMConnector connector in connSymbol.Connect2Connectors)
2842 a0e3dca4 gaqhf
                                {
2843 b01e7456 gaqhf
                                    if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()) == true)
2844 1805d3b7 gaqhf
                                        containZeroLength = true;
2845 a0e3dca4 gaqhf
                                }
2846 b01e7456 gaqhf
                            }
2847
2848
                            if (connSymbol == null ||
2849
                                 (connSymbol != null && connSymbol.get_ItemStatus() == "Active" && connSymbol.get_RepresentationType() != "Branch") ||
2850
                                containZeroLength)
2851
                            {
2852
                                bool bCalcX = false;
2853
                                bool bCalcY = false;
2854
                                if (targetLine.SlopeType == SlopeType.HORIZONTAL)
2855
                                    bCalcX = true;
2856
                                else if (targetLine.SlopeType == SlopeType.VERTICAL)
2857
                                    bCalcY = true;
2858
                                else
2859
                                {
2860
                                    bCalcX = true;
2861
                                    bCalcY = true;
2862
                                }
2863 a0e3dca4 gaqhf
2864 b01e7456 gaqhf
                                if (bCalcX)
2865 a0e3dca4 gaqhf
                                {
2866 b01e7456 gaqhf
                                    double nextX = targetVertices[i - 1][0];
2867
                                    double newX = 0;
2868
                                    if (nextX > tempX)
2869
                                    {
2870
                                        newX = tempX + gridSetting.Length;
2871
                                        if (newX > nextX)
2872
                                            newX = (point[0] + nextX) / 2;
2873
                                    }
2874 a0e3dca4 gaqhf
                                    else
2875
                                    {
2876 b01e7456 gaqhf
                                        newX = tempX - gridSetting.Length;
2877
                                        if (newX < nextX)
2878
                                            newX = (point[0] + nextX) / 2;
2879 a0e3dca4 gaqhf
                                    }
2880 b01e7456 gaqhf
                                    resultPoint = new double[] { newX, resultPoint[1] };
2881
                                }
2882 a0e3dca4 gaqhf
2883 b01e7456 gaqhf
                                if (bCalcY)
2884
                                {
2885
                                    double nextY = targetVertices[i - 1][1];
2886
                                    double newY = 0;
2887
                                    if (nextY > tempY)
2888 a0e3dca4 gaqhf
                                    {
2889 b01e7456 gaqhf
                                        newY = tempY + gridSetting.Length;
2890
                                        if (newY > nextY)
2891
                                            newY = (point[1] + nextY) / 2;
2892 a0e3dca4 gaqhf
                                    }
2893 b01e7456 gaqhf
                                    else
2894 a0e3dca4 gaqhf
                                    {
2895 b01e7456 gaqhf
                                        newY = tempY - gridSetting.Length;
2896
                                        if (newY < nextY)
2897
                                            newY = (point[1] + nextY) / 2;
2898 a0e3dca4 gaqhf
                                    }
2899 b01e7456 gaqhf
                                    resultPoint = new double[] { resultPoint[0], newY };
2900 a0e3dca4 gaqhf
                                }
2901
                            }
2902 68464385 gaqhf
                        }
2903 a0e3dca4 gaqhf
                        break;
2904 68464385 gaqhf
                    }
2905
                }
2906
            }
2907
2908 a0e3dca4 gaqhf
            x = resultPoint[0];
2909
            y = resultPoint[1];
2910
2911 68464385 gaqhf
            return targetConnector;
2912
        }
2913
2914 1ff0105e gaqhf
        private LMConnector GetLMConnectorOnlyOne(string modelItemID)
2915
        {
2916
            LMConnector result = null;
2917
            List<LMConnector> connectors = new List<LMConnector>();
2918
            LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
2919
2920
            if (modelItem != null)
2921
            {
2922
                foreach (LMRepresentation rep in modelItem.Representations)
2923
                {
2924
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
2925
                        connectors.Add(dataSource.GetConnector(rep.Id));
2926
                }
2927
2928
                ReleaseCOMObjects(modelItem);
2929
            }
2930
2931
            if (connectors.Count == 1)
2932
                result = connectors[0];
2933
            else
2934
                foreach (var item in connectors)
2935
                    ReleaseCOMObjects(item);
2936
2937
            return result;
2938
        }
2939
2940 74752074 gaqhf
        /// <summary>
2941
        /// Line Number Symbol을 실제로 Modeling하는 메서드
2942
        /// </summary>
2943
        /// <param name="lineNumber"></param>
2944 32205389 gaqhf
        private void LineNumberModeling(Line line)
2945 cfda1fed gaqhf
        {
2946 32205389 gaqhf
            LineNumber lineNumber = document.LINENUMBERS.Find(x => x.CONNLINE == line.UID);
2947
            if (lineNumber != null)
2948 10872260 gaqhf
            {
2949 32205389 gaqhf
                LMConnector connectedLMConnector = GetLMConnectorOnlyOne(line.SPPID.ModelItemId);
2950 340515a2 gaqhf
                if (connectedLMConnector != null)
2951
                {
2952
                    double x = 0;
2953
                    double y = 0;
2954
                    CalcLabelLocation(ref x, ref y, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y, lineNumber.SPPIDLabelLocation, _ETCSetting.LineNumberLocation);
2955 b65a7e32 gaqhf
2956 340515a2 gaqhf
                    Array points = new double[] { 0, x, y };
2957
                    LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: false);
2958 cfda1fed gaqhf
2959 340515a2 gaqhf
                    if (_LmLabelPresist != null)
2960
                    {
2961
                        _LmLabelPresist.Commit();
2962
                        lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
2963
                        ReleaseCOMObjects(_LmLabelPresist);
2964
                    }
2965 c3d2e266 gaqhf
                }
2966 10872260 gaqhf
            }
2967 cfda1fed gaqhf
        }
2968 74752074 gaqhf
        /// <summary>
2969 b2d1c1aa gaqhf
        /// Flow Mark Modeling
2970
        /// </summary>
2971
        /// <param name="line"></param>
2972
        private void FlowMarkModeling(Line line)
2973
        {
2974 a0965e07 gaqhf
            if (line.FLOWMARK && !string.IsNullOrEmpty(line.SPPID.ModelItemId) && !string.IsNullOrEmpty(_ETCSetting.FlowMarkSymbolPath))
2975 b2d1c1aa gaqhf
            {
2976 32205389 gaqhf
                LMConnector connector = GetLMConnectorOnlyOne(line.SPPID.ModelItemId);
2977
                if (connector != null)
2978 b2d1c1aa gaqhf
                {
2979 32205389 gaqhf
                    string mappingPath = _ETCSetting.FlowMarkSymbolPath;
2980
                    List<double[]> vertices = GetConnectorVertices(connector);
2981
                    vertices = vertices.FindAll(x => x[0] > 0 && x[1] > 0);
2982
                    double[] point = vertices[vertices.Count - 1];
2983
                    Array array = new double[] { 0, point[0], point[1] };
2984
                    LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mappingPath, ref array, LabeledItem: connector.AsLMRepresentation());
2985
                    if (_LMLabelPersist != null)
2986
                        ReleaseCOMObjects(_LMLabelPersist);
2987 b2d1c1aa gaqhf
                }
2988
            }
2989
        }
2990
2991
        /// <summary>
2992 74752074 gaqhf
        /// Line Number 기준으로 모든 Item에 Line Number의 Attribute Input
2993
        /// </summary>
2994
        /// <param name="lineNumber"></param>
2995 a7e9beec gaqhf
        private void InputLineNumberAttribute(LineNumber lineNumber)
2996
        {
2997 8634af60 gaqhf
            foreach (LineRun run in lineNumber.RUNS)
2998 a7e9beec gaqhf
            {
2999 8634af60 gaqhf
                foreach (var item in run.RUNITEMS)
3000 a7e9beec gaqhf
                {
3001 32205389 gaqhf
                    //if (item.GetType() == typeof(Symbol))
3002
                    //{
3003
                    //    Symbol symbol = item as Symbol;
3004
                    //    LMSymbol _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
3005
                    //    if (_LMSymbol != null)
3006
                    //    {
3007
                    //        LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
3008
3009
                    //        if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3010
                    //        {
3011
                    //            foreach (var attribute in lineNumber.ATTRIBUTES)
3012
                    //            {
3013
                    //                LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
3014
                    //                if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3015
                    //                {
3016
                    //                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
3017
                    //                    if (_LMAAttribute != null)
3018
                    //                    {
3019
                    //                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3020
                    //                            _LMAAttribute.set_Value(attribute.VALUE);
3021
                    //                        else if (_LMAAttribute.get_Value() != attribute.VALUE)
3022
                    //                            _LMAAttribute.set_Value(attribute.VALUE);
3023
                    //                    }
3024
                    //                }
3025
                    //            }
3026
                    //            _LMModelItem.Commit();
3027
                    //        }
3028
                    //        if (_LMModelItem != null)
3029
                    //            ReleaseCOMObjects(_LMModelItem);
3030
                    //    }
3031
                    //    if (_LMSymbol != null)
3032
                    //        ReleaseCOMObjects(_LMSymbol);
3033
                    //}
3034
                    //else
3035
                    if (item.GetType() == typeof(Line))
3036 8634af60 gaqhf
                    {
3037
                        Line line = item as Line;
3038
                        if (line != null)
3039 a7e9beec gaqhf
                        {
3040 8634af60 gaqhf
                            LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
3041
                            if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3042 a7e9beec gaqhf
                            {
3043 8634af60 gaqhf
                                foreach (var attribute in lineNumber.ATTRIBUTES)
3044
                                {
3045
                                    LineNumberMapping mapping = document.LineNumberMappings.Find(x => x.UID == attribute.UID);
3046 b2d1c1aa gaqhf
                                    if (mapping != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3047 8634af60 gaqhf
                                    {
3048
                                        LMAAttribute _LMAAttribute = _LMModelItem.Attributes[mapping.SPPIDATTRIBUTENAME];
3049
                                        if (_LMAAttribute != null)
3050
                                        {
3051
                                            if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3052
                                                _LMAAttribute.set_Value(attribute.VALUE);
3053
                                            else if (_LMAAttribute.get_Value() != attribute.VALUE)
3054
                                                _LMAAttribute.set_Value(attribute.VALUE);
3055 7f00b26c gaqhf
3056 8634af60 gaqhf
                                        }
3057
                                    }
3058
                                }
3059 68464385 gaqhf
                                _LMModelItem.Commit();
3060 a7e9beec gaqhf
                            }
3061 8634af60 gaqhf
                            if (_LMModelItem != null)
3062
                                ReleaseCOMObjects(_LMModelItem);
3063 32205389 gaqhf
3064
                            break;
3065 a7e9beec gaqhf
                        }
3066
                    }
3067
                }
3068
            }
3069
        }
3070
3071 74752074 gaqhf
        /// <summary>
3072
        /// Symbol Attribute 입력 메서드
3073
        /// </summary>
3074 73415441 gaqhf
        /// <param name="item"></param>
3075
        private void InputSymbolAttribute(object targetItem, List<BaseModel.Attribute> targetAttributes)
3076 1efc25a3 gaqhf
        {
3077 7f00b26c gaqhf
3078
            // Object 아이템이 Symbol일 경우 Equipment일 경우 
3079
            string sRep = null;
3080
            if (targetItem.GetType() == typeof(Symbol))
3081
                sRep = ((Symbol)targetItem).SPPID.RepresentationId;
3082
            else if (targetItem.GetType() == typeof(Equipment))
3083
                sRep = ((Equipment)targetItem).SPPID.RepresentationId;
3084
3085
            if (!string.IsNullOrEmpty(sRep))
3086 1efc25a3 gaqhf
            {
3087 7f00b26c gaqhf
                LMSymbol _LMSymbol = dataSource.GetSymbol(sRep);
3088
                LMModelItem _LMModelItem = _LMSymbol.ModelItemObject;
3089
                LMAAttributes _Attributes = _LMModelItem.Attributes;
3090 402ef5b1 gaqhf
3091 7f00b26c gaqhf
                foreach (var item in targetAttributes)
3092
                {
3093
                    AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == item.UID);
3094
                    if (mapping != null && !string.IsNullOrEmpty(item.VALUE) && item.VALUE != "None")
3095 65a1ed4b gaqhf
                    {
3096 7f00b26c gaqhf
                        LMAAttribute _Attribute = _Attributes[mapping.SPPIDATTRIBUTENAME];
3097
                        if (_Attribute != null)
3098
                            _Attribute.set_Value(item.VALUE);
3099 65a1ed4b gaqhf
                    }
3100 ac78b508 gaqhf
                }
3101 7f00b26c gaqhf
                _LMModelItem.Commit();
3102
3103
                ReleaseCOMObjects(_Attributes);
3104
                ReleaseCOMObjects(_LMModelItem);
3105
                ReleaseCOMObjects(_LMSymbol);
3106 1efc25a3 gaqhf
            }
3107
        }
3108
3109 74752074 gaqhf
        /// <summary>
3110 16584d30 gaqhf
        /// Input SpecBreak Attribute
3111
        /// </summary>
3112
        /// <param name="specBreak"></param>
3113
        private void InputSpecBreakAttribute(SpecBreak specBreak)
3114
        {
3115 7f00b26c gaqhf
            object upStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.UpStreamUID);
3116
            object downStreamObj = SPPIDUtil.FindObjectByUID(document, specBreak.DownStreamUID);
3117
3118
            if (upStreamObj != null &&
3119
                downStreamObj != null)
3120 16584d30 gaqhf
            {
3121 7f00b26c gaqhf
                LMConnector targetLMConnector = FindBreakLineTarget(upStreamObj, downStreamObj);
3122 16584d30 gaqhf
3123 7f00b26c gaqhf
                if (targetLMConnector != null)
3124 16584d30 gaqhf
                {
3125 7f00b26c gaqhf
                    foreach (LMLabelPersist _LMLabelPersist in targetLMConnector.LabelPersists)
3126 16584d30 gaqhf
                    {
3127 7f00b26c gaqhf
                        string symbolPath = _LMLabelPersist.get_FileName();
3128
                        AttributeMapping mapping = document.AttributeMappings.Find(x => x.SPPIDSYMBOLNAME == symbolPath);
3129
                        if (mapping != null)
3130 16584d30 gaqhf
                        {
3131 7f00b26c gaqhf
                            BaseModel.Attribute attribute = specBreak.ATTRIBUTES.Find(y => y.UID == mapping.UID);
3132
                            if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3133 16584d30 gaqhf
                            {
3134 7f00b26c gaqhf
                                string[] values = attribute.VALUE.Split(new char[] { ',' });
3135
                                if (values.Length == 2)
3136 16584d30 gaqhf
                                {
3137 7f00b26c gaqhf
                                    string upStreamValue = values[0];
3138
                                    string downStreamValue = values[1];
3139 16584d30 gaqhf
3140 7f00b26c gaqhf
                                    InputAttributeForSpecBreak(upStreamObj, downStreamObj, upStreamValue, downStreamValue, mapping.SPPIDATTRIBUTENAME);
3141 16584d30 gaqhf
                                }
3142
                            }
3143
                        }
3144
                    }
3145 7f00b26c gaqhf
3146
                    ReleaseCOMObjects(targetLMConnector);
3147 16584d30 gaqhf
                }
3148
            }
3149 7f00b26c gaqhf
3150 16584d30 gaqhf
3151
            #region 내부에서만 쓰는 메서드
3152 7f00b26c gaqhf
            void InputAttributeForSpecBreak(object _upStreamObj, object _downStreamObj, string upStreamValue, string downStreamValue, string sppidAttributeName)
3153 16584d30 gaqhf
            {
3154 7f00b26c gaqhf
                Symbol upStreamSymbol = _upStreamObj as Symbol;
3155
                Line upStreamLine = _upStreamObj as Line;
3156
                Symbol downStreamSymbol = _downStreamObj as Symbol;
3157
                Line downStreamLine = _downStreamObj as Line;
3158
                // 둘다 Line일 경우
3159
                if (upStreamLine != null && downStreamLine != null)
3160 16584d30 gaqhf
                {
3161 7f00b26c gaqhf
                    InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
3162
                    InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
3163
                }
3164
                // 둘다 Symbol일 경우
3165
                else if (upStreamSymbol != null && downStreamSymbol != null)
3166
                {
3167
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamSymbol);
3168
                    LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
3169
                    LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
3170 16584d30 gaqhf
3171 7f00b26c gaqhf
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
3172
                    {
3173
                        if (connector.get_ItemStatus() != "Active")
3174
                            continue;
3175 16584d30 gaqhf
3176 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
3177
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3178
                    }
3179 16584d30 gaqhf
3180 7f00b26c gaqhf
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
3181
                    {
3182
                        if (connector.get_ItemStatus() != "Active")
3183
                            continue;
3184 16584d30 gaqhf
3185 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
3186
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3187
                    }
3188 16584d30 gaqhf
3189 7f00b26c gaqhf
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
3190
                    {
3191
                        if (connector.get_ItemStatus() != "Active")
3192
                            continue;
3193 16584d30 gaqhf
3194 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
3195
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3196
                    }
3197 16584d30 gaqhf
3198 7f00b26c gaqhf
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
3199
                    {
3200
                        if (connector.get_ItemStatus() != "Active")
3201
                            continue;
3202 16584d30 gaqhf
3203 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
3204
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3205 16584d30 gaqhf
                    }
3206
3207 7f00b26c gaqhf
                    ReleaseCOMObjects(zeroLenthConnector);
3208
                    ReleaseCOMObjects(upStreamLMSymbol);
3209
                    ReleaseCOMObjects(downStreamLMSymbol);
3210
                }
3211
                else if (upStreamSymbol != null && downStreamLine != null)
3212
                {
3213
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamSymbol, downStreamLine);
3214
                    InputLineAttributeForSpecBreakLine(downStreamLine, sppidAttributeName, downStreamValue);
3215
                    LMSymbol upStreamLMSymbol = dataSource.GetSymbol(upStreamSymbol.SPPID.RepresentationId);
3216 16584d30 gaqhf
3217 7f00b26c gaqhf
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid1Connectors)
3218
                    {
3219
                        if (connector.get_ItemStatus() != "Active")
3220
                            continue;
3221 16584d30 gaqhf
3222 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
3223
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3224
                    }
3225 16584d30 gaqhf
3226 7f00b26c gaqhf
                    foreach (LMConnector connector in upStreamLMSymbol.Avoid2Connectors)
3227
                    {
3228
                        if (connector.get_ItemStatus() != "Active")
3229
                            continue;
3230 16584d30 gaqhf
3231 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
3232
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, upStreamValue);
3233 16584d30 gaqhf
                    }
3234
3235 7f00b26c gaqhf
                    ReleaseCOMObjects(zeroLenthConnector);
3236
                    ReleaseCOMObjects(upStreamLMSymbol);
3237
                }
3238
                else if (upStreamLine != null && downStreamSymbol != null)
3239
                {
3240
                    LMConnector zeroLenthConnector = FindBreakLineTarget(upStreamLine, downStreamSymbol);
3241
                    InputLineAttributeForSpecBreakLine(upStreamLine, sppidAttributeName, upStreamValue);
3242
                    LMSymbol downStreamLMSymbol = dataSource.GetSymbol(downStreamSymbol.SPPID.RepresentationId);
3243 16584d30 gaqhf
3244 7f00b26c gaqhf
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid1Connectors)
3245
                    {
3246
                        if (connector.get_ItemStatus() != "Active")
3247
                            continue;
3248 16584d30 gaqhf
3249 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
3250
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3251
                    }
3252 16584d30 gaqhf
3253 7f00b26c gaqhf
                    foreach (LMConnector connector in downStreamLMSymbol.Avoid2Connectors)
3254
                    {
3255
                        if (connector.get_ItemStatus() != "Active")
3256
                            continue;
3257 16584d30 gaqhf
3258 7f00b26c gaqhf
                        if (connector.Id != zeroLenthConnector.Id)
3259
                            InputLineAttributeForSpecBreakLMConnector(connector, sppidAttributeName, downStreamValue);
3260 16584d30 gaqhf
                    }
3261 7f00b26c gaqhf
3262
                    ReleaseCOMObjects(zeroLenthConnector);
3263
                    ReleaseCOMObjects(downStreamLMSymbol);
3264 16584d30 gaqhf
                }
3265
            }
3266
3267
            void InputLineAttributeForSpecBreakLine(Line line, string attrName, string value)
3268
            {
3269 7f00b26c gaqhf
                LMModelItem _LMModelItem = dataSource.GetModelItem(line.SPPID.ModelItemId);
3270
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3271 16584d30 gaqhf
                {
3272 7f00b26c gaqhf
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
3273
                    if (_LMAAttribute != null)
3274 16584d30 gaqhf
                    {
3275 7f00b26c gaqhf
                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3276
                            _LMAAttribute.set_Value(value);
3277
                        else if (_LMAAttribute.get_Value() != value)
3278
                            _LMAAttribute.set_Value(value);
3279 16584d30 gaqhf
                    }
3280 7f00b26c gaqhf
3281
                    _LMModelItem.Commit();
3282 16584d30 gaqhf
                }
3283 7f00b26c gaqhf
                if (_LMModelItem != null)
3284
                    ReleaseCOMObjects(_LMModelItem);
3285 16584d30 gaqhf
            }
3286
3287
            void InputLineAttributeForSpecBreakLMConnector(LMConnector connector, string attrName, string value)
3288
            {
3289 7f00b26c gaqhf
                LMModelItem _LMModelItem = dataSource.GetModelItem(connector.ModelItemID);
3290
                if (_LMModelItem != null && _LMModelItem.get_ItemStatus() == "Active")
3291 16584d30 gaqhf
                {
3292 7f00b26c gaqhf
                    LMAAttribute _LMAAttribute = _LMModelItem.Attributes[attrName];
3293
                    if (_LMAAttribute != null)
3294 16584d30 gaqhf
                    {
3295 7f00b26c gaqhf
                        if (DBNull.Value.Equals(_LMAAttribute.get_Value()))
3296
                            _LMAAttribute.set_Value(value);
3297
                        else if (_LMAAttribute.get_Value() != value)
3298
                            _LMAAttribute.set_Value(value);
3299 16584d30 gaqhf
                    }
3300 7f00b26c gaqhf
3301
                    _LMModelItem.Commit();
3302 16584d30 gaqhf
                }
3303 7f00b26c gaqhf
                if (_LMModelItem != null)
3304
                    ReleaseCOMObjects(_LMModelItem);
3305 16584d30 gaqhf
            }
3306
            #endregion
3307
        }
3308
3309
        /// <summary>
3310 74752074 gaqhf
        /// Text Modeling - Association일 경우는 Text대신 해당 맵핑된 Symbol로 모델링
3311
        /// </summary>
3312
        /// <param name="text"></param>
3313 cfda1fed gaqhf
        private void TextModeling(Text text)
3314
        {
3315 6b298450 gaqhf
            LMSymbol _LMSymbol = null;
3316 0860c756 gaqhf
            LMConnector connectedLMConnector = null;
3317 7f00b26c gaqhf
            //if (text.ASSOCIATION && !string.IsNullOrEmpty(text.OWNER) && text.OWNER != "None")
3318
            if (text.ASSOCIATION)
3319 6b298450 gaqhf
            {
3320 7f00b26c gaqhf
                object owner = SPPIDUtil.FindObjectByUID(document, text.OWNER);
3321
                if (owner.GetType() == typeof(Symbol))
3322 ea80efaa gaqhf
                {
3323 7f00b26c gaqhf
                    Symbol symbol = owner as Symbol;
3324
                    _LMSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
3325
                    if (_LMSymbol != null)
3326 ea80efaa gaqhf
                    {
3327 7f00b26c gaqhf
                        BaseModel.Attribute attribute = symbol.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
3328 3734dcc5 gaqhf
                        if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3329 0860c756 gaqhf
                        {
3330 7f00b26c gaqhf
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
3331 0860c756 gaqhf
3332
                            if (mapping != null)
3333
                            {
3334
                                double x = 0;
3335
                                double y = 0;
3336
3337
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
3338
                                Array array = new double[] { 0, x, y };
3339
3340 7f00b26c gaqhf
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: _LMSymbol.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
3341 0860c756 gaqhf
                                if (_LMLabelPersist != null)
3342
                                {
3343
                                    _LMLabelPersist.Commit();
3344
                                    ReleaseCOMObjects(_LMLabelPersist);
3345
                                }
3346
                            }
3347
                        }
3348 ea80efaa gaqhf
                    }
3349
                }
3350 7f00b26c gaqhf
                else if (owner.GetType() == typeof(Line))
3351 ea80efaa gaqhf
                {
3352 7f00b26c gaqhf
                    Line line = owner as Line;
3353
                    Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(line.SPPID.ModelItemId);
3354
                    connectedLMConnector = FindTargetLMConnectorForLabel(connectorVertices, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y);
3355 ea80efaa gaqhf
3356 7f00b26c gaqhf
                    if (connectedLMConnector != null)
3357
                    {
3358 83c14a07 gaqhf
                        BaseModel.Attribute attribute = line.ATTRIBUTES.Find(x => x.ASSOCITEM == text.UID);
3359
                        if (attribute != null && !string.IsNullOrEmpty(attribute.VALUE) && attribute.VALUE != "None")
3360 7f00b26c gaqhf
                        {
3361 83c14a07 gaqhf
                            AttributeMapping mapping = document.AttributeMappings.Find(x => x.UID == attribute.UID && !string.IsNullOrEmpty(x.SPPIDSYMBOLNAME));
3362 7f00b26c gaqhf
3363
                            if (mapping != null)
3364 83c14a07 gaqhf
                            {
3365
                                double x = 0;
3366
                                double y = 0;
3367 b65a7e32 gaqhf
3368 83c14a07 gaqhf
                                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, mapping.Location);
3369
                                Array array = new double[] { 0, x, y };
3370 ea80efaa gaqhf
3371 83c14a07 gaqhf
                                LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mapping.SPPIDSYMBOLNAME, ref array, Rotation: text.ANGLE, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: mapping.LeaderLine);
3372
                                if (_LMLabelPersist != null)
3373
                                {
3374
                                    _LMLabelPersist.Commit();
3375
                                    ReleaseCOMObjects(_LMLabelPersist);
3376
                                }
3377 7f00b26c gaqhf
                            }
3378
                        }
3379
                    }
3380 ea80efaa gaqhf
                }
3381 6b298450 gaqhf
            }
3382 7f00b26c gaqhf
            else
3383 6b298450 gaqhf
            {
3384 7f00b26c gaqhf
                LMItemNote _LMItemNote = null;
3385
                LMAAttribute _LMAAttribute = null;
3386 cfda1fed gaqhf
3387 7f00b26c gaqhf
                double x = 0;
3388
                double y = 0;
3389
                double angle = text.ANGLE;
3390
                CalcLabelLocation(ref x, ref y, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y, text.SPPIDLabelLocation, _ETCSetting.TextLocation);
3391
3392
                _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, x, y, Rotation: angle);
3393
                _LMSymbol.Commit();
3394
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
3395
                _LMItemNote.Commit();
3396
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
3397
                _LMAAttribute.set_Value(text.VALUE);
3398
                _LMItemNote.Commit();
3399
3400
                if (_LMAAttribute != null)
3401
                    ReleaseCOMObjects(_LMAAttribute);
3402
                if (_LMItemNote != null)
3403
                    ReleaseCOMObjects(_LMItemNote);
3404 6b298450 gaqhf
            }
3405 7f00b26c gaqhf
            if (_LMSymbol != null)
3406
                ReleaseCOMObjects(_LMSymbol);
3407 cfda1fed gaqhf
        }
3408
3409 74752074 gaqhf
        /// <summary>
3410
        /// Note Modeling
3411
        /// </summary>
3412
        /// <param name="note"></param>
3413 cfda1fed gaqhf
        private void NoteModeling(Note note)
3414
        {
3415 6b298450 gaqhf
            LMSymbol _LMSymbol = null;
3416
            LMItemNote _LMItemNote = null;
3417
            LMAAttribute _LMAAttribute = null;
3418
3419 7f00b26c gaqhf
            if (string.IsNullOrEmpty(note.OWNER) || note.OWNER == "None")
3420 6b298450 gaqhf
            {
3421 7f00b26c gaqhf
                double x = 0;
3422
                double y = 0;
3423 fc0a8c33 gaqhf
3424 7f00b26c gaqhf
                CalcLabelLocation(ref x, ref y, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y, note.SPPIDLabelLocation, _ETCSetting.NoteLocation);
3425 fc0a8c33 gaqhf
3426 7f00b26c gaqhf
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, x, y);
3427
                _LMSymbol.Commit();
3428
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
3429
                _LMItemNote.Commit();
3430
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
3431
                _LMAAttribute.set_Value(note.VALUE);
3432
                _LMItemNote.Commit();
3433 6b298450 gaqhf
            }
3434 cfda1fed gaqhf
3435 7f00b26c gaqhf
            if (_LMAAttribute != null)
3436
                ReleaseCOMObjects(_LMAAttribute);
3437
            if (_LMItemNote != null)
3438
                ReleaseCOMObjects(_LMItemNote);
3439
            if (_LMSymbol != null)
3440
                ReleaseCOMObjects(_LMSymbol);
3441 cfda1fed gaqhf
        }
3442
3443 d9794a6c gaqhf
        /// <summary>
3444 74752074 gaqhf
        /// Label의 좌표를 구하는 메서드(ID2 기준의 좌표 -> SPPID 좌표)
3445
        /// </summary>
3446
        /// <param name="x"></param>
3447
        /// <param name="y"></param>
3448
        /// <param name="originX"></param>
3449
        /// <param name="originY"></param>
3450
        /// <param name="SPPIDLabelLocation"></param>
3451
        /// <param name="location"></param>
3452 b65a7e32 gaqhf
        private void CalcLabelLocation(ref double x, ref double y, double originX, double originY, SPPIDLabelLocationInfo SPPIDLabelLocation, Location location)
3453
        {
3454
            if (location == Location.None)
3455
            {
3456
                x = originX;
3457
                y = originY;
3458
            }
3459
            else
3460
            {
3461
                if (location.HasFlag(Location.Center))
3462
                {
3463
                    x = (SPPIDLabelLocation.X1 + SPPIDLabelLocation.X2) / 2;
3464
                    y = (SPPIDLabelLocation.Y1 + SPPIDLabelLocation.Y2) / 2;
3465
                }
3466
3467
                if (location.HasFlag(Location.Left))
3468
                    x = SPPIDLabelLocation.X1;
3469
                else if (location.HasFlag(Location.Right))
3470
                    x = SPPIDLabelLocation.X2;
3471
3472
                if (location.HasFlag(Location.Down))
3473
                    y = SPPIDLabelLocation.Y1;
3474
                else if (location.HasFlag(Location.Up))
3475
                    y = SPPIDLabelLocation.Y2;
3476
            }
3477
        }
3478 5a4b8f32 gaqhf
3479 74752074 gaqhf
        /// <summary>
3480 4d2571ab gaqhf
        /// Symbol의 우선순위 Modeling 목록을 가져온다.
3481
        /// 1. Angle Valve
3482
        /// 2. 3개로 이루어진 Symbol Group
3483
        /// </summary>
3484
        /// <returns></returns>
3485
        private List<Symbol> GetPrioritySymbol()
3486
        {
3487
            DataTable symbolTable = document.SymbolTable;
3488
            // List에 순서대로 쌓는다.
3489
            List<Symbol> symbols = new List<Symbol>();
3490 3734dcc5 gaqhf
3491 4d2571ab gaqhf
            // Angle Valve 부터
3492 d9794a6c gaqhf
            foreach (var symbol in document.SYMBOLS.FindAll(x => x.CONNECTORS.FindAll(y => y.Index == 0).Count == 2))
3493 4d2571ab gaqhf
            {
3494
                if (!symbols.Contains(symbol))
3495
                {
3496
                    double originX = 0;
3497
                    double originY = 0;
3498
3499
                    // ID2 Table에서 Original Point 가져옴.
3500 7f00b26c gaqhf
                    string OriginalPoint = symbolTable.Select(string.Format("UID = {0}", symbol.DBUID))[0]["OriginalPoint"].ToString();
3501 4d2571ab gaqhf
                    SPPIDUtil.ConvertPointBystring(OriginalPoint, ref originX, ref originY);
3502
3503
                    SlopeType slopeType1 = SlopeType.None;
3504
                    SlopeType slopeType2 = SlopeType.None;
3505 d9794a6c gaqhf
                    foreach (Connector connector in symbol.CONNECTORS.FindAll(x => x.Index == 0))
3506 4d2571ab gaqhf
                    {
3507
                        double connectorX = 0;
3508
                        double connectorY = 0;
3509
                        SPPIDUtil.ConvertPointBystring(connector.CONNECTPOINT, ref connectorX, ref connectorY);
3510
                        if (slopeType1 == SlopeType.None)
3511
                            slopeType1 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
3512
                        else
3513
                            slopeType2 = SPPIDUtil.CalcSlope(originX, originY, connectorX, connectorY);
3514
                    }
3515
3516
                    if ((slopeType1 == SlopeType.VERTICAL && slopeType2 == SlopeType.HORIZONTAL) ||
3517
                        (slopeType2 == SlopeType.VERTICAL && slopeType1 == SlopeType.HORIZONTAL))
3518
                        symbols.Add(symbol);
3519
                }
3520
            }
3521
3522 f1a7faf9 gaqhf
            List<Symbol> tempSymbols = new List<Symbol>();
3523
            // Conn 갯수 기준
3524 d9794a6c gaqhf
            foreach (var item in document.SYMBOLS)
3525
            {
3526 f1a7faf9 gaqhf
                if (!symbols.Contains(item))
3527
                    tempSymbols.Add(item);
3528 d9794a6c gaqhf
            }
3529 f1a7faf9 gaqhf
            tempSymbols.Sort(SortSymbolPriority);
3530
            symbols.AddRange(tempSymbols);
3531 4d2571ab gaqhf
3532
            return symbols;
3533
        }
3534
3535 d63050d6 gaqhf
        private void SetPriorityLine()
3536
        {
3537
            document.LINES.Sort(SortLinePriority);
3538
3539
            int SortLinePriority(Line a, Line b)
3540
            {
3541
                // Branch 없는것부터
3542
                int branchRetval = CompareBranchLine(a, b);
3543
                if (branchRetval != 0)
3544
                {
3545
                    return branchRetval;
3546
                }
3547
                else
3548
                {
3549
                    // Symbol 연결 갯수
3550
                    int connSymbolRetval = CompareConnSymbol(a, b);
3551
                    if (connSymbolRetval != 0)
3552
                    {
3553
                        return connSymbolRetval;
3554
                    }
3555
                    else
3556
                    {
3557
                        // 아이템 연결 갯수(심볼, Line이면서 Not Branch)
3558
                        int connItemRetval = CompareConnItem(a, b);
3559
                        if (connItemRetval != 0)
3560
                        {
3561
                            return connItemRetval;
3562
                        }
3563
                        else
3564
                        {
3565
                            // ConnectedItem이 없는것
3566
                            int noneConnRetval = CompareNoneConn(a, b);
3567
                            if (noneConnRetval != 0)
3568
                            {
3569
                                return noneConnRetval;
3570
                            }
3571
                            else
3572
                            {
3573
3574
                            }
3575
                        }
3576
                    }
3577
                }
3578
3579
                return 0;
3580
            }
3581
3582
            int CompareConnSymbol(Line a, Line b)
3583
            {
3584
                List<Connector> connectorsA = a.CONNECTORS
3585
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
3586
                    .ToList();
3587
3588
                List<Connector> connectorsB = b.CONNECTORS
3589
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Symbol))
3590
                    .ToList();
3591
3592
                // 오름차순
3593
                return connectorsB.Count.CompareTo(connectorsA.Count);
3594
            }
3595
3596
            int CompareConnItem(Line a, Line b)
3597
            {
3598
                List<Connector> connectorsA = a.CONNECTORS
3599
                    .Where(conn => conn.ConnectedObject != null && 
3600
                    (conn.ConnectedObject.GetType() == typeof(Symbol) || 
3601
                    (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, a))))
3602
                    .ToList();
3603
3604
                List<Connector> connectorsB = b.CONNECTORS
3605
                    .Where(conn => conn.ConnectedObject != null &&
3606
                    (conn.ConnectedObject.GetType() == typeof(Symbol) ||
3607
                    (conn.ConnectedObject.GetType() == typeof(Line) && !SPPIDUtil.IsBranchLine((Line)conn.ConnectedObject, b))))
3608
                    .ToList();
3609
3610
                // 오름차순
3611
                return connectorsB.Count.CompareTo(connectorsA.Count);
3612
            }
3613
3614
            int CompareBranchLine(Line a, Line b)
3615
            {
3616
                List<Connector> connectorsA = a.CONNECTORS
3617
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(a, conn.ConnectedObject as Line))
3618
                    .ToList();
3619
                List<Connector> connectorsB = b.CONNECTORS
3620
                    .Where(conn => conn.ConnectedObject != null && conn.ConnectedObject.GetType() == typeof(Line) && SPPIDUtil.IsBranchLine(b, conn.ConnectedObject as Line))
3621
                    .ToList();
3622
3623
                // 내림차순
3624
                return connectorsA.Count.CompareTo(connectorsB.Count);
3625
            }
3626
3627
            int CompareNoneConn(Line a, Line b)
3628
            {
3629
                List<Connector> connectorsA = a.CONNECTORS
3630
                    .Where(conn => conn.ConnectedObject == null)
3631
                    .ToList();
3632
3633
                List<Connector> connectorsB = b.CONNECTORS
3634
                    .Where(conn => conn.ConnectedObject == null)
3635
                    .ToList();
3636
3637
                // 오름차순
3638
                return connectorsB.Count.CompareTo(connectorsA.Count);
3639
            }
3640
        }
3641
3642 a0e3dca4 gaqhf
        private void SortBranchLines()
3643
        {
3644
            NewBranchLines.Sort(SortBranchLine);
3645
            int SortBranchLine(Line a, Line b)
3646
            {
3647
                int countA = a.CONNECTORS.FindAll(x => x.ConnectedObject != null &&
3648
                 x.ConnectedObject.GetType() == typeof(Line) &&
3649
                 SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, a) &&
3650
                 string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count;
3651
3652
                int countB = b.CONNECTORS.FindAll(x => x.ConnectedObject != null &&
3653
                 x.ConnectedObject.GetType() == typeof(Line) &&
3654
                 SPPIDUtil.IsBranchLine(x.ConnectedObject as Line, b) &&
3655
                 string.IsNullOrEmpty(((Line)x.ConnectedObject).SPPID.ModelItemId)).Count;
3656
3657
                // 내림차순
3658
                return countA.CompareTo(countB);
3659
            }
3660
        }
3661
3662 f1a7faf9 gaqhf
        private static int SortSymbolPriority(Symbol a, Symbol b)
3663
        {
3664
            int countA = a.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count;
3665
            int countB = b.CONNECTORS.FindAll(x => !string.IsNullOrEmpty(x.CONNECTEDITEM) && x.CONNECTEDITEM != "None").Count;
3666
            int retval = countB.CompareTo(countA);
3667
            if (retval != 0)
3668
                return retval;
3669
            else
3670
                return a.SPPID.ORIGINAL_X.CompareTo(b.SPPID.ORIGINAL_X);
3671
        }
3672
3673 4d2571ab gaqhf
        /// <summary>
3674 b2d1c1aa gaqhf
        /// Graphic OID로 해당 Symbol의 크기를 구하여 Zoom
3675
        /// </summary>
3676
        /// <param name="graphicOID"></param>
3677
        /// <param name="milliseconds"></param>
3678
        private void ZoomObjectByGraphicOID(string graphicOID, int milliseconds = 150)
3679
        {
3680
            if (radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID] != null)
3681
            {
3682
                double minX = 0;
3683
                double minY = 0;
3684
                double maxX = 0;
3685
                double maxY = 0;
3686
                radApp.ActiveDocument.ActiveSheet.DrawingObjects[graphicOID].Range(out minX, out minY, out maxX, out maxY);
3687
                radApp.ActiveWindow.ZoomArea2(minX - 0.007, minY - 0.007, maxX + 0.007, maxY + 0.007, null);
3688
3689
                Thread.Sleep(milliseconds);
3690
            }
3691
        }
3692
3693
        /// <summary>
3694 74752074 gaqhf
        /// ComObject를 Release
3695
        /// </summary>
3696
        /// <param name="objVars"></param>
3697 5a4b8f32 gaqhf
        public void ReleaseCOMObjects(params object[] objVars)
3698
        {
3699
            int intNewRefCount = 0;
3700
            foreach (object obj in objVars)
3701
            {
3702
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
3703
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
3704
            }
3705
        }
3706 cfda1fed gaqhf
    }
3707
}
클립보드 이미지 추가 (최대 크기: 500 MB)