프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 48fd75e2

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