프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ d77973b3

이력 | 보기 | 이력해설 | 다운로드 (177 KB)

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