프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 6b298450

이력 | 보기 | 이력해설 | 다운로드 (43.9 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
using Llama;
7
using Plaice;
8 8aa6f2db gaqhf
using Ingr.RAD2D.Interop.RAD2D;
9
using Ingr.RAD2D.Internal;
10
using Ingr.RAD2D.Helper;
11 cfda1fed gaqhf
using Converter.BaseModel;
12
using Converter.SPPID.Model;
13
using Converter.SPPID.Properties;
14
using Converter.SPPID.Util;
15
using Converter.SPPID.DB;
16 5e6ecf05 gaqhf
using Ingr.RAD2D.MacroControls.CmdCtrl;
17
using Ingr.RAD2D;
18 5dfb8a24 gaqhf
using System.Windows;
19 cfda1fed gaqhf
using System.Threading;
20 5dfb8a24 gaqhf
using System.Drawing;
21 cfda1fed gaqhf
using Microsoft.VisualBasic;
22
using Newtonsoft.Json;
23
24
namespace Converter.SPPID
25
{
26
    public class AutoModeling
27
    {
28 809a7640 gaqhf
        Placement _placement;
29
        LMADataSource dataSource;
30 5e6ecf05 gaqhf
        Ingr.RAD2D.Application radApp;
31 cfda1fed gaqhf
        SPPID_Document document;
32 f1c9dbaa gaqhf
33 3165c259 gaqhf
        List<Tuple<string, Line, Line>> BranchLines = new List<Tuple<string, Line, Line>>();
34 5e6ecf05 gaqhf
        public AutoModeling(SPPID_Document document, Ingr.RAD2D.Application radApp)
35 cfda1fed gaqhf
        {
36
            this.document = document;
37 5e6ecf05 gaqhf
            this.radApp = radApp;
38 cfda1fed gaqhf
        }
39
40
        public void Run()
41
        {
42 809a7640 gaqhf
            _placement = new Placement();
43
            dataSource = _placement.PIDDataSource;
44 5dfb8a24 gaqhf
            //dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
45
            //dynamic newDrawing = application.Drawings.Add(document.Unit, document.Template, document.DrawingNumber, document.DrawingName);
46
            //application.ActiveWindow.Fit();
47
            //Thread.Sleep(100);
48
            //application.ActiveWindow.Zoom = 60;
49
            //Thread.Sleep(100);
50 5e6ecf05 gaqhf
            try
51 5dfb8a24 gaqhf
            {
52 1efc25a3 gaqhf
                // Equipment Modeling
53 5e6ecf05 gaqhf
                foreach (Equipment equipment in document.Equipments)
54
                    SymbolModeling(equipment as Symbol, null, null);
55 1efc25a3 gaqhf
                // LineRun Symbol Modeling
56 5e6ecf05 gaqhf
                foreach (LineNumber lineNumber in document.LINENUMBERS)
57
                    foreach (LineRun run in lineNumber.RUNS)
58
                        SymbolModelingByRun(run);
59 1efc25a3 gaqhf
                // TrimLineRun Symbol Modeling
60 5e6ecf05 gaqhf
                foreach (TrimLine trimLine in document.TRIMLINES)
61
                    foreach (LineRun run in trimLine.RUNS)
62
                        SymbolModelingByRun(run);
63 1efc25a3 gaqhf
                // LineRun Line Modeling
64 5e6ecf05 gaqhf
                foreach (LineNumber lineNumber in document.LINENUMBERS)
65
                    foreach (LineRun run in lineNumber.RUNS)
66
                        LineModelingByRun(run);
67 1efc25a3 gaqhf
                // TrimLineRun Line Modeling
68 5e6ecf05 gaqhf
                foreach (TrimLine trimLine in document.TRIMLINES)
69
                    foreach (LineRun run in trimLine.RUNS)
70
                        LineModelingByRun(run);
71 1efc25a3 gaqhf
                // Branch Line Modeling
72 3165c259 gaqhf
                foreach (var item in BranchLines)
73 335b7a24 gaqhf
                    BranchLineModeling(item);
74 1efc25a3 gaqhf
                // EndBreak Modeling
75 3165c259 gaqhf
                foreach (var item in document.EndBreaks)
76
                    EndBreakModeling(item);
77 1efc25a3 gaqhf
                // LineNumber Modeling
78 10872260 gaqhf
                foreach (var item in document.LINENUMBERS)
79
                    LineNumberModeling(item);
80 1efc25a3 gaqhf
                // Input Symbol Attribute
81
                foreach (var item in document.SYMBOLS)
82
                    InputSymbolAttribute(item);
83
                // Input Line Attribute
84 10872260 gaqhf
85 1efc25a3 gaqhf
                // Input LineNumber Attribute
86 335b7a24 gaqhf
87 1efc25a3 gaqhf
                // Note Modeling
88 6b298450 gaqhf
                foreach (var item in document.NOTES)
89
                    NoteModeling(item);
90 1efc25a3 gaqhf
                // Text Modeling
91 6b298450 gaqhf
                foreach (var item in document.TEXTINFOS)
92
                    TextModeling(item);
93 1efc25a3 gaqhf
                // LineRun Line Join
94 3165c259 gaqhf
                foreach (LineNumber lineNumber in document.LINENUMBERS)
95
                {
96
97
                    foreach (LineRun run in lineNumber.RUNS)
98
                    {
99
                        JoinRunLine(run);
100
                    }
101
                }
102 1efc25a3 gaqhf
                // TrimLineRun Line Join
103 3165c259 gaqhf
                foreach (TrimLine trimLine in document.TRIMLINES)
104
                {
105
                    foreach (LineRun run in trimLine.RUNS)
106
                    {
107
                        JoinRunLine(run);
108
                    }
109
                }
110 809a7640 gaqhf
            }
111 5e6ecf05 gaqhf
            catch (Exception ex)
112
            {
113
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
114
            }
115
            finally
116
            {
117
                ReleaseCOMObjects(dataSource);
118
                ReleaseCOMObjects(_placement);
119
            }
120
           
121 809a7640 gaqhf
            System.Windows.Forms.MessageBox.Show("end");
122
        }
123 f1c9dbaa gaqhf
124 8aa6f2db gaqhf
        private void LineModelingByRun(LineRun run)
125 809a7640 gaqhf
        {
126
            Line prevLine = null;
127
            List<Line> lines = new List<Line>();
128
            foreach (var item in run.RUNITEMS)
129
            {
130
                // Line일 경우
131
                if (item.GetType() == typeof(Line))
132
                {
133
                    Line line = item as Line;
134
                    if (prevLine == null)
135
                        lines.Add(line);
136
                    else if (prevLine != null)
137
                    {
138
                        if (prevLine.SPPID.MAPPINGNAME == line.SPPID.MAPPINGNAME)
139
                            lines.Add(line);
140
                        else
141 f1c9dbaa gaqhf
                        {
142 809a7640 gaqhf
                            LineModeling(lines);
143
                            lines.Clear();
144
                            lines.Add(line);
145 5dfb8a24 gaqhf
                        }
146
                    }
147
148 809a7640 gaqhf
                    prevLine = line;
149
                }
150
                // Symbol 일 경우
151
                else if (item.GetType() == typeof(Symbol))
152
                {
153 f1c9dbaa gaqhf
                    if (lines.Count > 0)
154 809a7640 gaqhf
                    {
155 f1c9dbaa gaqhf
                        LineModeling(lines);
156 809a7640 gaqhf
                        lines.Clear();
157
                    }
158 5dfb8a24 gaqhf
                }
159
            }
160
161 809a7640 gaqhf
            if (lines.Count > 0)
162
                LineModeling(lines);
163
        }
164 5dfb8a24 gaqhf
165 8aa6f2db gaqhf
        private void SymbolModelingByRun(LineRun run)
166 809a7640 gaqhf
        {
167
            // 양끝 Symbol 검사 후 Line이 나올때까지만 Symbol Modeling
168
            if (run.RUNITEMS.Count > 0)
169
            {
170
                if (run.RUNITEMS[0].GetType() == typeof(Symbol))
171
                    SymbolModelingByRunStart(run.RUNITEMS[0] as Symbol, run);
172
173
                if (run.RUNITEMS[run.RUNITEMS.Count - 1].GetType() == typeof(Symbol))
174
                    SymbolModelingByRunEnd(run.RUNITEMS[run.RUNITEMS.Count - 1] as Symbol, run);
175
            }
176
177
            Symbol prevSymbol = null;
178
            Symbol targetSymbol = null;
179
            foreach (var item in run.RUNITEMS)
180
            {
181
                if (item.GetType() == typeof(Symbol))
182
                {
183
                    Symbol symbol = item as Symbol;
184
                    SymbolModeling(symbol, targetSymbol, prevSymbol);
185
                    prevSymbol = symbol;
186
                    targetSymbol = symbol;
187
                }
188
                else
189
                {
190
                    targetSymbol = null;
191
                }
192
            }
193
        }
194
195 8aa6f2db gaqhf
        private void SymbolModelingByRunStart(Symbol symbol, LineRun run)
196 809a7640 gaqhf
        {
197
            foreach (var connector in symbol.CONNECTORS)
198
            {
199
                object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
200
                if (targetItem != null &&
201
                    (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) &&
202
                    !IsSameLineNumber(symbol, targetItem))
203
                {
204
                    SymbolModeling(symbol, targetItem as Symbol, null);
205
                    for (int i = 1; i < run.RUNITEMS.Count; i++)
206
                    {
207
                        object item = run.RUNITEMS[i];
208
                        if (item.GetType() == typeof(Symbol))
209
                            SymbolModeling(item as Symbol, run.RUNITEMS[i - 1] as Symbol, null);
210
                        else
211
                            break;
212
                    }
213
                    break;
214
                }
215
            }
216
217
218
        }
219
220 8aa6f2db gaqhf
        private void SymbolModelingByRunEnd(Symbol symbol, LineRun run)
221 809a7640 gaqhf
        {
222
            foreach (var connector in symbol.CONNECTORS)
223
            {
224
                object targetItem = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM);
225
                if (targetItem != null &&
226
                    (targetItem.GetType() == typeof(Symbol) || targetItem.GetType() == typeof(Equipment)) &&
227
                    !IsSameLineNumber(symbol, targetItem))
228
                {
229
                    SymbolModeling(symbol, targetItem as Symbol, null);
230
                    for (int i = run.RUNITEMS.Count - 2; i >= 0; i--)
231
                    {
232
                        object item = run.RUNITEMS[i];
233
                        if (item.GetType() == typeof(Symbol))
234
                            SymbolModeling(item as Symbol, run.RUNITEMS[i + 1] as Symbol, null);
235
                        else
236
                            break;
237
                    }
238
                    break;
239
                }
240
            }
241 5dfb8a24 gaqhf
        }
242 cfda1fed gaqhf
243 809a7640 gaqhf
        private void SymbolModeling(Symbol symbol, Symbol targetSymbol, Symbol prevSymbol)
244
        {
245
            if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
246
                return;
247
248
            LMSymbol _LMSymbol = null;
249
250
            string mappingPath = symbol.SPPID.MAPPINGNAME;
251
            double x = symbol.SPPID.ORIGINAL_X;
252
            double y = symbol.SPPID.ORIGINAL_Y;
253
            int mirror = 0;
254
            double angle = symbol.ANGLE;
255
256
            if (targetSymbol != null && !string.IsNullOrEmpty(targetSymbol.SPPID.RepresentationId))
257
            {
258
                LMSymbol _TargetItem = dataSource.GetSymbol(targetSymbol.SPPID.RepresentationId);
259
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem);
260
                ReleaseCOMObjects(_TargetItem);
261
            }
262
            else if (prevSymbol != null)
263
            {
264
                LMSymbol _PrevSymbol = dataSource.GetSymbol(prevSymbol.SPPID.RepresentationId);
265
                SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y);
266
                double prevX = _PrevSymbol.get_XCoordinate();
267
                double prevY = _PrevSymbol.get_YCoordinate();
268
                if (slopeType == SlopeType.HORIZONTAL)
269
                    y = prevY;
270
                else if (slopeType == SlopeType.VERTICAL)
271
                    x = prevX;
272
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
273
            }
274
            else
275
            {
276
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
277
            }
278
279
280
            if (_LMSymbol != null)
281
            {
282
                _LMSymbol.Commit();
283
                symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id;
284
            }
285
286
            ReleaseCOMObjects(_LMSymbol);
287
        }
288
289
        private bool IsSameLineNumber(object item, object targetItem)
290
        {
291
            foreach (var lineNumber in document.LINENUMBERS)
292
            {
293
                foreach (var run in lineNumber.RUNS)
294
                {
295
                    foreach (var runItem in run.RUNITEMS)
296
                    {
297
                        if (runItem == item)
298
                        {
299
                            foreach (var findItem in run.RUNITEMS)
300
                            {
301
                                if (findItem == targetItem)
302
                                {
303
                                    return true;
304
                                }
305
                            }
306
307
                            return false;
308
309
                        }
310
                    }
311
                }
312
            }
313
314
            return false;
315
        }
316
317 1b261371 gaqhf
        private void LineModeling(List<Line> lines)
318
        {
319 335b7a24 gaqhf
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
320 1b261371 gaqhf
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
321 f1c9dbaa gaqhf
            LMSymbol _LMSymbol1 = null;
322
            LMSymbol _LMSymbol2 = null;
323 5e6ecf05 gaqhf
            Dictionary<LMConnector, List<double[]>> connectorVertices1 = new Dictionary<LMConnector, List<double[]>>();
324
            LMConnector targetConnector1 = null;
325
            Dictionary<LMConnector, List<double[]>> connectorVertices2 = new Dictionary<LMConnector, List<double[]>>();
326
            LMConnector targetConnector2 = null;
327 335b7a24 gaqhf
328
            Line startBranchLine = null;
329
            Line endBranchLine = null;
330
331 1b261371 gaqhf
            for (int i = 0; i < lines.Count; i++)
332
            {
333
                Line line = lines[i];
334 f1c9dbaa gaqhf
                if (i == 0 || i + 1 != lines.Count)
335
                {
336 809a7640 gaqhf
                    // 시작점에 연결된 Symbol 찾기
337 f1c9dbaa gaqhf
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM);
338
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
339
                    {
340
                        _LMSymbol1 = dataSource.GetSymbol(((Symbol)connItem).SPPID.RepresentationId);
341
                        if (_LMSymbol1 != null)
342
                            placeRunInputs.AddSymbolTarget(_LMSymbol1, line.SPPID.START_X, line.SPPID.START_Y);
343
                        else
344
                            placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
345
                    }
346 335b7a24 gaqhf
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
347 5e6ecf05 gaqhf
                    {
348
                        connectorVertices1 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
349 56bc67e1 gaqhf
                        targetConnector1 = FindTargetLMConnector(connectorVertices1, line.SPPID.START_X, line.SPPID.START_Y, line.SPPID.END_X, line.SPPID.END_Y);
350 5e6ecf05 gaqhf
351
                        if (targetConnector1 != null)
352
                            placeRunInputs.AddConnectorTarget(targetConnector1, line.SPPID.START_X, line.SPPID.START_Y);
353
                        else
354 335b7a24 gaqhf
                        {
355
                            startBranchLine = connItem as Line;
356 5e6ecf05 gaqhf
                            placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
357 335b7a24 gaqhf
                        }
358 5e6ecf05 gaqhf
                    }
359 f1c9dbaa gaqhf
                    else
360
                        placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
361
                }
362
363
                if (i + 1 == lines.Count)
364
                {
365 809a7640 gaqhf
                    // 끝점에 연결된 Symbol 찾기
366 f1c9dbaa gaqhf
                    object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM);
367 5e6ecf05 gaqhf
368
                    if (i != 0)
369
                        placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
370
371 f1c9dbaa gaqhf
                    if (connItem != null && connItem.GetType() == typeof(Symbol))
372
                    {
373
                        _LMSymbol2 = dataSource.GetSymbol(((Symbol)connItem).SPPID.RepresentationId);
374
                        if (_LMSymbol2 != null)
375
                            placeRunInputs.AddSymbolTarget(_LMSymbol2, line.SPPID.END_X, line.SPPID.END_Y);
376
                        else
377
                            placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
378
                            
379
                    }
380 335b7a24 gaqhf
                    else if (connItem != null && connItem.GetType() == typeof(Line) && !lines.Contains(connItem))
381 5e6ecf05 gaqhf
                    {
382
                        connectorVertices2 = GetPipeRunVertices(((Line)connItem).SPPID.ModelItemId);
383 56bc67e1 gaqhf
                        targetConnector2 = FindTargetLMConnector(connectorVertices2, line.SPPID.END_X, line.SPPID.END_Y, line.SPPID.START_X, line.SPPID.START_Y);
384 5e6ecf05 gaqhf
385
                        if (targetConnector2 != null)
386
                            placeRunInputs.AddConnectorTarget(targetConnector2, line.SPPID.END_X, line.SPPID.END_Y);
387
                        else
388 335b7a24 gaqhf
                        {
389
                            endBranchLine = connItem as Line;
390 5e6ecf05 gaqhf
                            placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
391 335b7a24 gaqhf
                        }
392 5e6ecf05 gaqhf
                    }
393 f1c9dbaa gaqhf
                    else
394
                    {
395
                        placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
396
                    }
397
                }
398
            }
399
400
            LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
401 335b7a24 gaqhf
402 f1c9dbaa gaqhf
            if (_lMConnector != null)
403
            {
404
                foreach (var line in lines)
405 5e6ecf05 gaqhf
                    line.SPPID.ModelItemId = _lMConnector.ModelItemID;
406 f1c9dbaa gaqhf
                _lMConnector.Commit();
407 335b7a24 gaqhf
                if (startBranchLine != null || endBranchLine != null)
408
                {
409 3165c259 gaqhf
                    BranchLines.Add(new Tuple<string, Line, Line>(_lMConnector.ModelItemID, startBranchLine, endBranchLine));
410 335b7a24 gaqhf
                }
411 1b261371 gaqhf
            }
412 5e6ecf05 gaqhf
413 1b261371 gaqhf
414 f1c9dbaa gaqhf
            if (_LMSymbol1 != null)
415
                ReleaseCOMObjects(_LMSymbol1);
416
            if (_LMSymbol2 != null)
417
                ReleaseCOMObjects(_LMSymbol2);
418 5e6ecf05 gaqhf
            if (targetConnector1 != null)
419
                ReleaseCOMObjects(targetConnector1);
420
            if (targetConnector2 != null)
421
                ReleaseCOMObjects(targetConnector2);
422
            foreach (var item in connectorVertices1)
423
                ReleaseCOMObjects(item.Key);
424
            foreach (var item in connectorVertices2)
425
                ReleaseCOMObjects(item.Key);
426 1b261371 gaqhf
427 f1c9dbaa gaqhf
            ReleaseCOMObjects(_lMConnector);
428 1b261371 gaqhf
            ReleaseCOMObjects(placeRunInputs);
429
            ReleaseCOMObjects(_LMAItem);
430
        }
431
432 335b7a24 gaqhf
        private void BranchLineModeling(Tuple<string, Line, Line> branch)
433
        {
434
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
435
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
436
437 8b085570 gaqhf
            LMConnector _StartConnector = null;
438
            LMConnector _EndConnector = null;
439 335b7a24 gaqhf
            double lengthStart = double.MaxValue;
440
            double lengthEnd = double.MaxValue;
441
            List<double[]> startPoints = new List<double[]>();
442
            List<double[]> endPoints = new List<double[]>();
443
444
            foreach (var item in connectorVertices)
445
            {
446
                foreach (var point in item.Value)
447
                {
448
                    // Start Point가 Branch
449
                    if (branch.Item2 != null)
450
                    {
451
                        Line targetLine = branch.Item2;
452
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
453
                        if (lengthStart > distance)
454
                        {
455 8b085570 gaqhf
                            _StartConnector = item.Key;
456 335b7a24 gaqhf
                            lengthStart = distance;
457
                            startPoints = item.Value;
458
                        }
459
                    }
460
                    // End Point가 Branch
461
                    if (branch.Item3 != null)
462
                    {
463
                        Line targetLine = branch.Item3;
464
                        double distance = SPPIDUtil.CalcLineToPointDistance(targetLine.SPPID.START_X, targetLine.SPPID.START_Y, targetLine.SPPID.END_X, targetLine.SPPID.END_Y, point[0], point[1]);
465
                        if (lengthEnd > distance)
466
                        {
467 8b085570 gaqhf
                            _EndConnector = item.Key;
468 335b7a24 gaqhf
                            lengthEnd = distance;
469
                            endPoints = item.Value;
470
                        }
471
                    }
472
                }
473
            }
474
            #region Branch가 양쪽 전부일 때
475 8b085570 gaqhf
            if (_StartConnector != null && _StartConnector == _EndConnector)
476 335b7a24 gaqhf
            {
477 8b085570 gaqhf
                _placement.PIDRemovePlacement(_StartConnector.AsLMRepresentation());
478 335b7a24 gaqhf
479
                _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
480
                PlaceRunInputs placeRunInputs = new PlaceRunInputs();
481
482
                Dictionary<LMConnector, List<double[]>> startConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
483 8b085570 gaqhf
                LMConnector _StartTargetConnector = FindTargetLMConnector(startConnectorVertices, startPoints[0][0], startPoints[0][1], startPoints[1][0], startPoints[1][1]);
484 335b7a24 gaqhf
                Dictionary<LMConnector, List<double[]>> endConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
485 8b085570 gaqhf
                LMConnector _EndTargetConnector = FindTargetLMConnector(endConnectorVertices,
486 335b7a24 gaqhf
                   startPoints[startPoints.Count - 1][0],
487
                   startPoints[startPoints.Count - 1][1],
488
                   startPoints[startPoints.Count - 2][0],
489
                   startPoints[startPoints.Count - 2][1]);
490
491
                for (int i = 0; i < startPoints.Count; i++)
492
                {
493
                    double[] point = startPoints[i];
494
                    if (i == 0)
495 8b085570 gaqhf
                        placeRunInputs.AddConnectorTarget(_StartTargetConnector, point[0], point[1]);
496 335b7a24 gaqhf
                    else if (i == startPoints.Count - 1)
497 8b085570 gaqhf
                        placeRunInputs.AddConnectorTarget(_EndTargetConnector, point[0], point[1]);
498 335b7a24 gaqhf
                    else
499
                        placeRunInputs.AddPoint(point[0], point[1]);
500
                }
501
502
                LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
503
                if (_LMConnector != null)
504
                {
505
                    _LMConnector.Commit();
506
                    foreach (var item in lines)
507
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
508
                }
509
510
                foreach (var item in startConnectorVertices)
511
                    ReleaseCOMObjects(item.Key);
512
                foreach (var item in endConnectorVertices)
513
                    ReleaseCOMObjects(item.Key);
514
                ReleaseCOMObjects(placeRunInputs);
515
                ReleaseCOMObjects(_LMAItem);
516
                ReleaseCOMObjects(_LMConnector);
517
            }
518
            #endregion
519 8b085570 gaqhf
            #region 양쪽이 다른 Branch 
520 335b7a24 gaqhf
            else
521
            {
522
                // Branch 시작 Connector
523 8b085570 gaqhf
                if (_StartConnector != null)
524 6b298450 gaqhf
                    BranchLineModelingByConnector(branch, _StartConnector, startPoints, true);
525 335b7a24 gaqhf
526 6b298450 gaqhf
                // Branch 끝 Connector
527
                if (_EndConnector != null)
528
                    BranchLineModelingByConnector(branch, _EndConnector, endPoints, false);
529
            }
530
            #endregion
531 335b7a24 gaqhf
532 6b298450 gaqhf
            if (_StartConnector != null)
533
                ReleaseCOMObjects(_StartConnector);
534
            if (_EndConnector != null)
535
                ReleaseCOMObjects(_EndConnector);
536
            foreach (var item in connectorVertices)
537
                ReleaseCOMObjects(item.Key);
538
        }
539 335b7a24 gaqhf
540 6b298450 gaqhf
        private void BranchLineModelingByConnector(Tuple<string, Line, Line> branch, LMConnector _Connector, List<double[]> points, bool IsStart)
541
        {
542
            List<Line> lines = SPPIDUtil.FindLinesByModelId(document, branch.Item1);
543
            Dictionary<LMConnector, List<double[]>> connectorVertices = GetPipeRunVertices(branch.Item1);
544
            LMConnector _SameRunTargetConnector = null;
545
            LMSymbol _SameRunTargetSymbol = null;
546
            Dictionary<LMConnector, List<double[]>> branchConnectorVertices = null;
547
            LMConnector _BranchTargetConnector = null;
548
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
549 335b7a24 gaqhf
550 6b298450 gaqhf
            // 같은 Line Run의 Connector 찾기
551
            foreach (var item in connectorVertices)
552
            {
553
                if (item.Key == _Connector)
554
                    continue;
555 335b7a24 gaqhf
556 6b298450 gaqhf
                if (IsStart &&
557
                    !DBNull.Value.Equals(item.Key.ConnectItem1SymbolID) &&
558
                    !DBNull.Value.Equals(_Connector.ConnectItem2SymbolID)&& 
559
                    item.Key.ConnectItem1SymbolID == _Connector.ConnectItem2SymbolID)
560
                {
561
                    _SameRunTargetConnector = item.Key;
562
                    break;
563
                }
564
                else if (!IsStart &&
565
                    !DBNull.Value.Equals(item.Key.ConnectItem2SymbolID) &&
566
                    !DBNull.Value.Equals(_Connector.ConnectItem1SymbolID) && 
567
                    item.Key.ConnectItem2SymbolID == _Connector.ConnectItem1SymbolID)
568
                {
569
                    _SameRunTargetConnector = item.Key;
570
                    break;
571
                }
572
            }
573
574
            // Branch 반대편이 Symbol
575
            if (_SameRunTargetConnector == null)
576
            {
577
                foreach (var line in lines)
578
                {
579
                    foreach (var connector in line.CONNECTORS)
580 335b7a24 gaqhf
                    {
581 6b298450 gaqhf
                        Symbol symbol = SPPIDUtil.FindObjectByUID(document, connector.CONNECTEDITEM) as Symbol;
582
                        if (symbol != null)
583 335b7a24 gaqhf
                        {
584 6b298450 gaqhf
                            _SameRunTargetSymbol = dataSource.GetSymbol(symbol.SPPID.RepresentationId);
585
                            break;
586 335b7a24 gaqhf
                        }
587
                    }
588 6b298450 gaqhf
                }
589
            }
590 335b7a24 gaqhf
591 6b298450 gaqhf
            // 기존 Connector 제거
592
            _placement.PIDRemovePlacement(_Connector.AsLMRepresentation());
593
            
594
            // 시작 Connector일 경우 첫 Point가 TargetConnector를 찾아야함
595
            if (IsStart)
596
            {
597
                branchConnectorVertices = GetPipeRunVertices(branch.Item2.SPPID.ModelItemId);
598
                _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices, points[0][0], points[0][1], points[1][0], points[1][1]);
599
            }
600
            // 끝 Conenctor일 경우 마지막 Point가 TargetConnector를 찾아야함
601
            else
602
            {
603
                branchConnectorVertices = GetPipeRunVertices(branch.Item3.SPPID.ModelItemId);
604
                _BranchTargetConnector = FindTargetLMConnector(branchConnectorVertices,
605
                    points[points.Count - 1][0],
606
                    points[points.Count - 1][1],
607
                    points[points.Count - 2][0],
608
                    points[points.Count - 2][1]);
609
            }
610 335b7a24 gaqhf
611 6b298450 gaqhf
            for (int i = 0; i < points.Count; i++)
612
            {
613
                double[] point = points[i];
614
                if (i == 0)
615 335b7a24 gaqhf
                {
616 6b298450 gaqhf
                    if (IsStart)
617 335b7a24 gaqhf
                    {
618 6b298450 gaqhf
                        placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
619 335b7a24 gaqhf
                    }
620 6b298450 gaqhf
                    else
621 335b7a24 gaqhf
                    {
622 6b298450 gaqhf
                        if (_SameRunTargetConnector != null)
623
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
624
                        else if (_SameRunTargetConnector != null)
625
                            placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]);
626
                        else
627
                            placeRunInputs.AddPoint(point[0], point[1]);
628 335b7a24 gaqhf
                    }
629 6b298450 gaqhf
                }
630
                else if (i == points.Count - 1)
631
                {
632
                    if (IsStart)
633 335b7a24 gaqhf
                    {
634 6b298450 gaqhf
                        if (_SameRunTargetConnector != null)
635
                            placeRunInputs.AddConnectorTarget(_SameRunTargetConnector, point[0], point[1]);
636
                        else if (_SameRunTargetSymbol != null)
637
                            placeRunInputs.AddSymbolTarget(_SameRunTargetSymbol, point[0], point[1]);
638 335b7a24 gaqhf
                        else
639
                            placeRunInputs.AddPoint(point[0], point[1]);
640
                    }
641 6b298450 gaqhf
                    else
642 335b7a24 gaqhf
                    {
643 6b298450 gaqhf
                        placeRunInputs.AddConnectorTarget(_BranchTargetConnector, point[0], point[1]);
644 335b7a24 gaqhf
                    }
645 6b298450 gaqhf
                }
646
                else
647
                    placeRunInputs.AddPoint(point[0], point[1]);
648
            }
649
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME);
650
            LMConnector _LMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
651 335b7a24 gaqhf
652 6b298450 gaqhf
            if (_LMConnector != null)
653
            {
654
                if (_SameRunTargetConnector != null)
655
                {
656
                    JoinPipeRun(_LMConnector.ModelItemID, _SameRunTargetConnector.ModelItemID);
657
                }
658
                else
659
                {
660
                    foreach (var item in lines)
661
                        item.SPPID.ModelItemId = _LMConnector.ModelItemID;
662 335b7a24 gaqhf
                }
663
664 6b298450 gaqhf
                _LMConnector.Commit();
665
                ReleaseCOMObjects(_LMConnector);
666 335b7a24 gaqhf
            }
667
668 6b298450 gaqhf
            ReleaseCOMObjects(placeRunInputs);
669
            ReleaseCOMObjects(_LMAItem);
670
            if (_BranchTargetConnector != null)
671
                ReleaseCOMObjects(_BranchTargetConnector);
672
            if (_SameRunTargetConnector != null)
673
                ReleaseCOMObjects(_SameRunTargetConnector);
674
            if (_SameRunTargetSymbol != null)
675
                ReleaseCOMObjects(_SameRunTargetSymbol);
676 335b7a24 gaqhf
            foreach (var item in connectorVertices)
677
                ReleaseCOMObjects(item.Key);
678 6b298450 gaqhf
            foreach (var item in branchConnectorVertices)
679
                ReleaseCOMObjects(item.Key);
680 335b7a24 gaqhf
        }
681
682 3165c259 gaqhf
        private void EndBreakModeling(EndBreak endBreak)
683 335b7a24 gaqhf
        {
684 3165c259 gaqhf
            Line ownerLine = SPPIDUtil.FindObjectByUID(document, endBreak.OWNER) as Line;
685
            Line connLine = null;   
686
            Property property = endBreak.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item");
687
            if (property != null)
688
                connLine = SPPIDUtil.FindObjectByUID(document, property.VALUE) as Line;
689 335b7a24 gaqhf
690 3165c259 gaqhf
            if (ownerLine != null && connLine != null)
691 335b7a24 gaqhf
            {
692 3165c259 gaqhf
                LMLabelPersist _LmLabelPersist = null;
693
694
                string lineModelId = ownerLine.SPPID.ModelItemId;
695
                LMPipeRun _LMPipeRun = _placement.PIDDataSource.GetPipeRun(lineModelId);
696
                LMPipeRun _ConnLMPipeRun = _placement.PIDDataSource.GetPipeRun(connLine.SPPID.ModelItemId);
697
                LMConnector connectedLMConnector = null;
698
699
                if (_LMPipeRun != null && _ConnLMPipeRun != null)
700 335b7a24 gaqhf
                {
701 3165c259 gaqhf
                    foreach (LMRepresentation rep in _LMPipeRun.Representations)
702 335b7a24 gaqhf
                    {
703 3165c259 gaqhf
                        if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
704
                        {
705
                            LMConnector _LMConnector = _placement.PIDDataSource.GetConnector(rep.Id);
706
                            if (_LMConnector.ConnectItem1SymbolID != null && !DBNull.Value.Equals(_LMConnector.ConnectItem1SymbolID) && ExistConnItem(_ConnLMPipeRun, _LMConnector.ConnectItem1SymbolID))
707
                            {
708
                                connectedLMConnector = _LMConnector;
709
                                break;
710
                            }
711
                            else if (_LMConnector.ConnectItem2SymbolID != null && !DBNull.Value.Equals(_LMConnector.ConnectItem2SymbolID) && ExistConnItem(_ConnLMPipeRun, _LMConnector.ConnectItem2SymbolID))
712
                            {
713
                                connectedLMConnector = _LMConnector;
714
                                break;
715
                            }
716
                            else
717
                            {
718
                                ReleaseCOMObjects(_LMConnector);
719
                            }
720
                        }
721 335b7a24 gaqhf
                    }
722 3165c259 gaqhf
                    if (connectedLMConnector != null)
723 335b7a24 gaqhf
                    {
724 3165c259 gaqhf
                        Array array = new double[] { 0, endBreak.SPPID.ORIGINAL_X, endBreak.SPPID.ORIGINAL_Y };
725
                        _LmLabelPersist = _placement.PIDPlaceLabel(endBreak.SPPID.MAPPINGNAME, ref array, Rotation: 0, LabeledItem: connectedLMConnector.AsLMRepresentation(), IsLeaderVisible: true);
726
                        ReleaseCOMObjects(connectedLMConnector);
727 335b7a24 gaqhf
                    }
728 3165c259 gaqhf
729
                    ReleaseCOMObjects(_LMPipeRun);
730
                    ReleaseCOMObjects(_ConnLMPipeRun);
731
                    if (_LmLabelPersist != null)
732
                        ReleaseCOMObjects(_LmLabelPersist);
733 335b7a24 gaqhf
                }
734
            }
735 3165c259 gaqhf
        }
736 10872260 gaqhf
737 3165c259 gaqhf
        private bool ExistConnItem(LMPipeRun _LMPipeRun, string ConnItem)
738
        {
739
            foreach (LMRepresentation rep in _LMPipeRun.Representations)
740 335b7a24 gaqhf
            {
741 3165c259 gaqhf
                if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
742 335b7a24 gaqhf
                {
743 3165c259 gaqhf
                    LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
744
                    if (_LMConnector.ConnectItem1SymbolID != null && !DBNull.Value.Equals(_LMConnector.ConnectItem1SymbolID) && _LMConnector.ConnectItem1SymbolID == ConnItem)
745 335b7a24 gaqhf
                    {
746 3165c259 gaqhf
                        ReleaseCOMObjects(_LMConnector);
747
                        return true;
748 335b7a24 gaqhf
                    }
749 3165c259 gaqhf
                    else if (_LMConnector.ConnectItem2SymbolID != null && !DBNull.Value.Equals(_LMConnector.ConnectItem2SymbolID) && _LMConnector.ConnectItem2SymbolID == ConnItem)
750 335b7a24 gaqhf
                    {
751 3165c259 gaqhf
                        ReleaseCOMObjects(_LMConnector);
752
                        return true;
753 335b7a24 gaqhf
                    }
754
                    else
755
                    {
756 3165c259 gaqhf
                        ReleaseCOMObjects(_LMConnector);
757 335b7a24 gaqhf
                    }
758
                }
759
            }
760
761 3165c259 gaqhf
            return false;
762 335b7a24 gaqhf
        }
763
764
        private void JoinPipeRun(string fromModelItemId, string toModelItemId)
765
        {
766
            LMPipeRun run1 = dataSource.GetPipeRun(toModelItemId);
767
            LMPipeRun run2 = dataSource.GetPipeRun(fromModelItemId);
768
            // item2가 item1으로 조인
769
            try
770
            {
771
                _LMAItem item1 = run1.AsLMAItem();
772
                _LMAItem item2 = run2.AsLMAItem();
773
774
                _placement.PIDJoinRuns(ref item1, ref item2);
775
                List<Line> lines = SPPIDUtil.FindLinesByModelId(document, fromModelItemId);
776
                foreach (var line in lines)
777
                    line.SPPID.ModelItemId = toModelItemId;
778
779
            }
780
            catch (Exception ex)
781
            {
782
                System.Windows.Forms.MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
783
            }
784
            finally
785
            {
786
                ReleaseCOMObjects(run1);
787
                ReleaseCOMObjects(run2);
788
            }
789
        }
790
791
        private void AutoJoinPipeRun(string modelItemId)
792
        {
793
            LMPipeRun run = dataSource.GetPipeRun(modelItemId);
794
            _LMAItem item = run.AsLMAItem();
795
            _placement.PIDAutoJoin(item, AutoJoinEndConstants.autoJoin_Both, ref item);
796
        }
797
798
        private void JoinRunLine(LineRun run)
799
        {
800
            string modelItemId = string.Empty;
801
            foreach (var item in run.RUNITEMS)
802
            {
803
                if (item.GetType() == typeof(Line))
804
                {
805
                    Line line = item as Line;
806
                    if (modelItemId != line.SPPID.ModelItemId)
807
                    {
808
                        AutoJoinPipeRun(line.SPPID.ModelItemId);
809
                        modelItemId = line.SPPID.ModelItemId;
810
                    }
811
                    //if (string.IsNullOrEmpty(modelItemId))
812
                    //{
813
                    //    modelItemId = line.SPPID.ModelItemId;
814
                    //}
815
                    //else if(modelItemId != line.SPPID.ModelItemId)
816
                    //{
817
                    //    JoinPipeRun(line.SPPID.ModelItemId, modelItemId);
818
                    //}
819
                }
820
            }
821
        }
822
823 5e6ecf05 gaqhf
        private Dictionary<LMConnector, List<double[]>> GetPipeRunVertices(string modelId)
824
        {
825
            Dictionary<LMConnector, List<double[]>> connectorVertices = new Dictionary<LMConnector, List<double[]>>();
826
            LMPipeRun _LMPipeRun = dataSource.GetPipeRun(modelId);
827
            if (_LMPipeRun != null)
828
            {
829
                foreach (LMRepresentation rep in _LMPipeRun.Representations)
830
                {
831
                    if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
832
                    {
833
                        LMConnector _LMConnector = dataSource.GetConnector(rep.Id);
834
                        connectorVertices.Add(_LMConnector, new List<double[]>());
835
                        dynamic OID = rep.get_GraphicOID();
836 335b7a24 gaqhf
                        DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
837 5e6ecf05 gaqhf
                        Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
838
                        int verticesCount = lineStringGeometry.VertexCount;
839
                        double[] vertices = null;
840
                        lineStringGeometry.GetVertices(ref verticesCount, ref vertices);
841
                        for (int i = 0; i < verticesCount; i++)
842
                        {
843
                            double x = 0;
844
                            double y = 0;
845
                            lineStringGeometry.GetVertex(i + 1, ref x, ref y);
846 335b7a24 gaqhf
                            connectorVertices[_LMConnector].Add(new double[] { Math.Round(x, 10), Math.Round(y, 10) });
847 5e6ecf05 gaqhf
                        }
848
                    }
849
                }
850
851
                ReleaseCOMObjects(_LMPipeRun);
852
            }
853
854
            return connectorVertices;
855
        }
856
857 56bc67e1 gaqhf
        private LMConnector FindTargetLMConnector(Dictionary<LMConnector, List<double[]>> connectorVertices, double connX, double connY, double x2, double y2)
858 5e6ecf05 gaqhf
        {
859
            double length = double.MaxValue;
860
            LMConnector targetConnector = null;
861
            foreach (var item in connectorVertices)
862
            {
863
                List<double[]> points = item.Value;
864
                for (int i = 0; i < points.Count - 1; i++)
865
                {
866
                    double[] point1 = points[i];
867
                    double[] point2 = points[i + 1];
868
869 335b7a24 gaqhf
                    double maxLineX = Math.Max(point1[0], point2[0]);
870
                    double minLineX = Math.Min(point1[0], point2[0]);
871
                    double maxLineY = Math.Max(point1[1], point2[1]);
872
                    double minLineY = Math.Min(point1[1], point2[1]);
873
874
                    SlopeType slope = SPPIDUtil.CalcSlope(minLineX, minLineY, maxLineX, maxLineY);
875
876 56bc67e1 gaqhf
                    // 두직선의 교차점
877
                    double[] crossingPoint = SPPIDUtil.CalcLineCrossingPoint(connX, connY, x2, y2, point1[0], point1[1], point2[0], point2[1]);
878
                    if (crossingPoint != null)
879 5e6ecf05 gaqhf
                    {
880 30a9ffce gaqhf
                        double distance = SPPIDUtil.CalcPointToPointdDistance(connX, connY, crossingPoint[0], crossingPoint[1]);
881 335b7a24 gaqhf
                        if (length >= distance)
882 30a9ffce gaqhf
                        {
883 335b7a24 gaqhf
                            if (slope == SlopeType.Slope &&
884
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0] &&
885
                                minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
886
                            {
887
                                targetConnector = item.Key;
888
                                length = distance;
889
                            }
890
                            else if (slope == SlopeType.HORIZONTAL &&
891
                                minLineX <= crossingPoint[0] && maxLineX >= crossingPoint[0])
892
                            {
893
                                targetConnector = item.Key;
894
                                length = distance;
895
                            }
896
                            else if (slope == SlopeType.VERTICAL &&
897
                               minLineY <= crossingPoint[1] && maxLineY >= crossingPoint[1])
898
                            {
899
                                targetConnector = item.Key;
900
                                length = distance;
901
                            }
902 30a9ffce gaqhf
                        }
903 5e6ecf05 gaqhf
                    }
904
                }
905
            }
906
907
            return targetConnector;
908
        }
909
910 cfda1fed gaqhf
        private void LineNumberModeling(LineNumber lineNumber)
911
        {
912 10872260 gaqhf
            Line line = null;
913
            foreach (var lineRun in lineNumber.RUNS)
914
            {
915
                foreach (var item in lineRun.RUNITEMS)
916
                {
917
                    line = item as Line;
918
                    if (line != null && !string.IsNullOrEmpty(line.SPPID.ModelItemId))
919
                        break;
920
                    else
921
                        line = null;
922
                }
923
                if (line != null)
924
                    break;
925
            }
926
927
            if (line != null && !string.IsNullOrEmpty(line.SPPID.ModelItemId))
928
            {
929
                Array points = new double[] { 0, lineNumber.SPPID.ORIGINAL_X, lineNumber.SPPID.ORIGINAL_Y };
930
                LMPipeRun _pipeRun = dataSource.GetPipeRun(line.SPPID.ModelItemId);
931
                if (_pipeRun != null)
932
                {
933
                    foreach (LMRepresentation rep in _pipeRun.Representations)
934
                    {
935
                        if (rep.get_RepresentationType() == "Connector" && rep.get_ItemStatus() == "Active")
936
                        {
937
                            LMConnector _LmConnector = dataSource.GetConnector(rep.Id);
938
                            LMLabelPersist _LmLabelPresist = _placement.PIDPlaceLabel(lineNumber.SPPID.MAPPINGNAME, ref points, Rotation: lineNumber.ANGLE, LabeledItem: _LmConnector.AsLMRepresentation(), IsLeaderVisible: false);
939
                            _LmLabelPresist.Commit();
940 cfda1fed gaqhf
941 10872260 gaqhf
                            if (_LmConnector != null)
942
                                ReleaseCOMObjects(_LmConnector);
943
                            if (_LmLabelPresist != null)
944
                            {
945
                                lineNumber.SPPID.RepresentationId = _LmLabelPresist.AsLMRepresentation().Id;
946
                                ReleaseCOMObjects(_LmConnector);
947
                            }
948
949
                            break;
950
                        }
951
                    }
952
953
                    ReleaseCOMObjects(_pipeRun);
954
                }
955
            }
956 cfda1fed gaqhf
        }
957
958 1efc25a3 gaqhf
        private void InputSymbolAttribute(Symbol symbol)
959
        {
960
            if (!string.IsNullOrEmpty(symbol.SPPID.RepresentationId))
961
            {
962
                foreach (var item in symbol.PROPERTIES)
963
                {
964
                    
965
966
                }
967
968
                foreach (var item in symbol.ATTRIBUTES)
969
                {
970
971
972
                }
973
            }
974
        }
975
976 cfda1fed gaqhf
        private void TextModeling(Text text)
977
        {
978 6b298450 gaqhf
            LMSymbol _LMSymbol = null;
979
            LMItemNote _LMItemNote = null;
980
            LMAAttribute _LMAAttribute = null;
981
982
            try
983
            {
984
                _LMSymbol = _placement.PIDPlaceSymbol(text.SPPID.MAPPINGNAME, text.SPPID.ORIGINAL_X, text.SPPID.ORIGINAL_Y);
985
                _LMSymbol.Commit();
986
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
987
                _LMItemNote.Commit();
988
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
989
                _LMAAttribute.set_Value(text.VALUE);
990
                _LMItemNote.Commit();
991
            }
992
            catch (Exception ex)
993
            {
994 cfda1fed gaqhf
995 6b298450 gaqhf
            }
996
            finally
997
            {
998
                if (_LMAAttribute != null)
999
                    ReleaseCOMObjects(_LMAAttribute);
1000
                if (_LMItemNote != null)
1001
                    ReleaseCOMObjects(_LMItemNote);
1002
                if (_LMSymbol != null)
1003
                    ReleaseCOMObjects(_LMSymbol);
1004
            }
1005 cfda1fed gaqhf
        }
1006
1007
        private void NoteModeling(Note note)
1008
        {
1009 6b298450 gaqhf
            LMSymbol _LMSymbol = null;
1010
            LMItemNote _LMItemNote = null;
1011
            LMAAttribute _LMAAttribute = null;
1012
1013
            try
1014
            {
1015
                _LMSymbol = _placement.PIDPlaceSymbol(note.SPPID.MAPPINGNAME, note.SPPID.ORIGINAL_X, note.SPPID.ORIGINAL_Y);
1016
                _LMSymbol.Commit();
1017
                _LMItemNote = _placement.PIDDataSource.GetItemNote(_LMSymbol.ModelItemID);
1018
                _LMItemNote.Commit();
1019
                _LMAAttribute = _LMItemNote.Attributes["Note.Body"];
1020
                _LMAAttribute.set_Value(note.VALUE);
1021
                _LMItemNote.Commit();
1022
            }
1023
            catch (Exception ex)
1024
            {
1025 cfda1fed gaqhf
1026 6b298450 gaqhf
            }
1027
            finally
1028
            {
1029
                if (_LMAAttribute != null)
1030
                    ReleaseCOMObjects(_LMAAttribute);
1031
                if (_LMItemNote != null)
1032
                    ReleaseCOMObjects(_LMItemNote);
1033
                if (_LMSymbol != null)
1034
                    ReleaseCOMObjects(_LMSymbol);
1035
            }
1036
            
1037 cfda1fed gaqhf
        }
1038
1039 5dfb8a24 gaqhf
        public void ReleaseCOMObjects(params object[] objVars)
1040
        {
1041
            int intNewRefCount = 0;
1042
            foreach (object obj in objVars)
1043
            {
1044
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
1045
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
1046
            }
1047
        }
1048 cfda1fed gaqhf
    }
1049
}
클립보드 이미지 추가 (최대 크기: 500 MB)