프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 4ee5c4bf

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