프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ 1b261371

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

1
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
using Converter.BaseModel;
9
using Converter.SPPID.Model;
10
using Converter.SPPID.Properties;
11
using Converter.SPPID.Util;
12
using Converter.SPPID.DB;
13

    
14
using System.Windows;
15
using System.Threading;
16
using System.Drawing;
17
using Microsoft.VisualBasic;
18
using Newtonsoft.Json;
19

    
20
namespace Converter.SPPID
21
{
22
    public class AutoModeling
23
    {
24
        Placement _placement = new Placement();
25
        SPPID_Document document;
26
        public AutoModeling(SPPID_Document document)
27
        {
28
            this.document = document;
29
        }
30

    
31
        public void Run()
32
        {
33
            //dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
34
            //dynamic newDrawing = application.Drawings.Add(document.Unit, document.Template, document.DrawingNumber, document.DrawingName);
35
            //application.ActiveWindow.Fit();
36
            //Thread.Sleep(100);
37
            //application.ActiveWindow.Zoom = 60;
38
            //Thread.Sleep(100);
39

    
40

    
41
            foreach (LineNumber lineNumber in document.LINENUMBERS)
42
            {
43
                foreach (LineNumberRun run in lineNumber.RUNS)
44
                {
45
                    // Run 별로 Modeling
46
                    Symbol prevSymbol = null;
47
                    // Symbol 먼저
48
                    foreach (var item in run.RUNITEMS)
49
                    {
50
                        if (item.GetType() == typeof(Symbol))
51
                        {
52
                            Symbol symbol = item as Symbol;
53
                            SymbolModeling(symbol, prevSymbol);
54
                            prevSymbol = symbol;
55
                        }
56
                    }
57

    
58
                    object prevItem = null;
59
                    prevSymbol = null;
60
                    foreach (var item in run.RUNITEMS)
61
                    {
62
                        if (item.GetType() == typeof(Line))
63
                        {
64
                            
65
                        }
66

    
67
                        prevItem = item;
68
                    }
69

    
70

    
71
                }
72
            }
73

    
74

    
75
            ReleaseCOMObjects(_placement);
76
            System.Windows.Forms.MessageBox.Show("end");
77
        }
78

    
79

    
80
        private void TestSource()
81
        {
82

    
83
        }
84

    
85
        private void SymbolModeling(Symbol symbol, Symbol prevSymbol)
86
        {
87
            LMSymbol _LMSymbol = null;
88

    
89
            string mappingPath = symbol.SPPID.MAPPINGNAME;
90
            double x = symbol.SPPID.ORIGINAL_X;
91
            double y = symbol.SPPID.ORIGINAL_Y;
92
            int mirror = 0;
93
            double angle = symbol.ANGLE;
94
            LMSymbol _TargetItem = null;
95

    
96
            if (prevSymbol != null)
97
            {
98
                SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y);
99
                LMADataSource dataSource = _placement.PIDDataSource;
100
                LMSymbol prevLMSymbol = dataSource.GetSymbol(prevSymbol.SPPID.ITEMOBJECT);
101
                double prevX = prevLMSymbol.get_XCoordinate();
102
                double prevY = prevLMSymbol.get_YCoordinate();
103
                if (slopeType == SlopeType.HORIZONTAL)
104
                    y = prevY;
105
                else if (slopeType == SlopeType.VERTICAL)
106
                    x = prevX;
107

    
108
            }
109
            else
110
            {
111
                
112
            }
113

    
114
            if (_TargetItem == null)
115
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle);
116
            else
117
            {
118
                _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem);
119
                ReleaseCOMObjects(_TargetItem);
120
            }
121

    
122
            if (_LMSymbol != null)
123
            {
124
                symbol.SPPID.ITEMOBJECT = _LMSymbol.AsLMRepresentation().Id;
125
            }
126

    
127
            ReleaseCOMObjects(_LMSymbol);
128
        }
129

    
130
        private void LineModeling(Line line)
131
        {
132
            object DrwingID = "0";
133
            _LMAItem _LMAItem = _placement.PIDCreateItem(line.SPPID.MAPPINGNAME, ref DrwingID);
134
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
135
            placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
136
            placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
137

    
138
            LMConnector lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
139
            lMConnector.Commit();
140

    
141
            ReleaseCOMObjects(lMConnector);
142
            ReleaseCOMObjects(placeRunInputs);
143
            ReleaseCOMObjects(_LMAItem);
144
        }
145

    
146
        private void LineModeling(List<Line> lines)
147
        {
148
            object DrwingID = "0";
149
            _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME, ref DrwingID);
150
            PlaceRunInputs placeRunInputs = new PlaceRunInputs();
151
            for (int i = 0; i < lines.Count; i++)
152
            {
153
                Line line = lines[i];
154
                placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y);
155
                placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y);
156
            }
157
            
158

    
159
            LMConnector lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs);
160
            lMConnector.Commit();
161

    
162
            ReleaseCOMObjects(lMConnector);
163
            ReleaseCOMObjects(placeRunInputs);
164
            ReleaseCOMObjects(_LMAItem);
165
        }
166

    
167
        private void LineNumberModeling(LineNumber lineNumber)
168
        {
169

    
170
        }
171

    
172
        private void TextModeling(Text text)
173
        {
174

    
175
        }
176

    
177
        private void NoteModeling(Note note)
178
        {
179

    
180
        }
181

    
182

    
183
        public void ReleaseCOMObjects(params object[] objVars)
184
        {
185
            int intNewRefCount = 0;
186
            foreach (object obj in objVars)
187
            {
188
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
189
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
190
            }
191
        }
192
    }
193
}
클립보드 이미지 추가 (최대 크기: 500 MB)