프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ e2876f87

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