hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ f1c9dbaa
이력 | 보기 | 이력해설 | 다운로드 (9.52 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 | 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 | 5dfb8a24 | gaqhf | using System.Windows; |
15 | cfda1fed | gaqhf | using System.Threading; |
16 | 5dfb8a24 | gaqhf | using System.Drawing; |
17 | cfda1fed | gaqhf | using Microsoft.VisualBasic; |
18 | using Newtonsoft.Json; |
||
19 | |||
20 | namespace Converter.SPPID |
||
21 | { |
||
22 | public class AutoModeling |
||
23 | { |
||
24 | 5dfb8a24 | gaqhf | Placement _placement = new Placement(); |
25 | f1c9dbaa | gaqhf | |
26 | cfda1fed | gaqhf | SPPID_Document document; |
27 | f1c9dbaa | gaqhf | |
28 | |||
29 | cfda1fed | gaqhf | public AutoModeling(SPPID_Document document) |
30 | { |
||
31 | this.document = document; |
||
32 | } |
||
33 | |||
34 | f1c9dbaa | gaqhf | |
35 | |||
36 | cfda1fed | gaqhf | public void Run() |
37 | { |
||
38 | 5dfb8a24 | gaqhf | //dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
39 | //dynamic newDrawing = application.Drawings.Add(document.Unit, document.Template, document.DrawingNumber, document.DrawingName); |
||
40 | //application.ActiveWindow.Fit(); |
||
41 | //Thread.Sleep(100); |
||
42 | //application.ActiveWindow.Zoom = 60; |
||
43 | //Thread.Sleep(100); |
||
44 | |||
45 | |||
46 | foreach (LineNumber lineNumber in document.LINENUMBERS) |
||
47 | { |
||
48 | foreach (LineNumberRun run in lineNumber.RUNS) |
||
49 | { |
||
50 | // Run 별로 Modeling |
||
51 | Symbol prevSymbol = null; |
||
52 | f1c9dbaa | gaqhf | object prevItem = null; |
53 | 1b261371 | gaqhf | // Symbol 먼저 |
54 | foreach (var item in run.RUNITEMS) |
||
55 | 5dfb8a24 | gaqhf | { |
56 | if (item.GetType() == typeof(Symbol)) |
||
57 | { |
||
58 | Symbol symbol = item as Symbol; |
||
59 | f1c9dbaa | gaqhf | SymbolModeling(symbol, prevSymbol, prevItem); |
60 | 5dfb8a24 | gaqhf | prevSymbol = symbol; |
61 | } |
||
62 | f1c9dbaa | gaqhf | prevItem = item; |
63 | 1b261371 | gaqhf | } |
64 | |||
65 | f1c9dbaa | gaqhf | |
66 | Line prevLine = null; |
||
67 | 1b261371 | gaqhf | prevSymbol = null; |
68 | f1c9dbaa | gaqhf | prevItem = null; |
69 | List<Line> lines = new List<Line>(); |
||
70 | 1b261371 | gaqhf | foreach (var item in run.RUNITEMS) |
71 | { |
||
72 | f1c9dbaa | gaqhf | // Line일 경우 |
73 | 1b261371 | gaqhf | if (item.GetType() == typeof(Line)) |
74 | 5dfb8a24 | gaqhf | { |
75 | f1c9dbaa | gaqhf | Line line = item as Line; |
76 | if (prevLine == null) |
||
77 | lines.Add(line); |
||
78 | else if (prevLine != null) |
||
79 | { |
||
80 | if (prevLine.SPPID.MAPPINGNAME == line.SPPID.MAPPINGNAME) |
||
81 | lines.Add(line); |
||
82 | else |
||
83 | { |
||
84 | LineModeling(lines); |
||
85 | lines.Clear(); |
||
86 | lines.Add(line); |
||
87 | } |
||
88 | } |
||
89 | |||
90 | prevLine = line; |
||
91 | } |
||
92 | // Symbol 일 경우 |
||
93 | else if (item.GetType() == typeof(Symbol)) |
||
94 | { |
||
95 | if (lines.Count > 0) |
||
96 | { |
||
97 | LineModeling(lines); |
||
98 | lines.Clear(); |
||
99 | } |
||
100 | 5dfb8a24 | gaqhf | } |
101 | |||
102 | prevItem = item; |
||
103 | } |
||
104 | |||
105 | f1c9dbaa | gaqhf | if (lines.Count > 0) |
106 | LineModeling(lines); |
||
107 | 5dfb8a24 | gaqhf | } |
108 | } |
||
109 | |||
110 | |||
111 | ReleaseCOMObjects(_placement); |
||
112 | System.Windows.Forms.MessageBox.Show("end"); |
||
113 | } |
||
114 | cfda1fed | gaqhf | |
115 | 1b261371 | gaqhf | |
116 | 5dfb8a24 | gaqhf | private void TestSource() |
117 | { |
||
118 | cfda1fed | gaqhf | |
119 | } |
||
120 | |||
121 | f1c9dbaa | gaqhf | private void SymbolModeling(Symbol symbol, Symbol prevSymbol, object prevItem) |
122 | cfda1fed | gaqhf | { |
123 | 5dfb8a24 | gaqhf | LMSymbol _LMSymbol = null; |
124 | f1c9dbaa | gaqhf | LMADataSource dataSource = _placement.PIDDataSource; |
125 | 5dfb8a24 | gaqhf | |
126 | string mappingPath = symbol.SPPID.MAPPINGNAME; |
||
127 | 1b261371 | gaqhf | double x = symbol.SPPID.ORIGINAL_X; |
128 | double y = symbol.SPPID.ORIGINAL_Y; |
||
129 | 5dfb8a24 | gaqhf | int mirror = 0; |
130 | double angle = symbol.ANGLE; |
||
131 | LMSymbol _TargetItem = null; |
||
132 | |||
133 | f1c9dbaa | gaqhf | if (prevItem != null && prevItem.GetType() == typeof(Symbol)) |
134 | _TargetItem = dataSource.GetSymbol(((Symbol)prevItem).SPPID.RepresentationId); |
||
135 | |||
136 | 5dfb8a24 | gaqhf | if (prevSymbol != null) |
137 | { |
||
138 | 1b261371 | gaqhf | SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y); |
139 | f1c9dbaa | gaqhf | LMSymbol prevLMSymbol = dataSource.GetSymbol(prevSymbol.SPPID.RepresentationId); |
140 | 1b261371 | gaqhf | double prevX = prevLMSymbol.get_XCoordinate(); |
141 | double prevY = prevLMSymbol.get_YCoordinate(); |
||
142 | 5dfb8a24 | gaqhf | if (slopeType == SlopeType.HORIZONTAL) |
143 | 1b261371 | gaqhf | y = prevY; |
144 | 5dfb8a24 | gaqhf | else if (slopeType == SlopeType.VERTICAL) |
145 | 1b261371 | gaqhf | x = prevX; |
146 | 5dfb8a24 | gaqhf | |
147 | f1c9dbaa | gaqhf | ReleaseCOMObjects(prevLMSymbol); |
148 | 5dfb8a24 | gaqhf | } |
149 | |||
150 | if (_TargetItem == null) |
||
151 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle); |
||
152 | else |
||
153 | _LMSymbol = _placement.PIDPlaceSymbol(mappingPath, x, y, Mirror: mirror, Rotation: angle, TargetItem: _TargetItem); |
||
154 | |||
155 | if (_LMSymbol != null) |
||
156 | { |
||
157 | f1c9dbaa | gaqhf | _LMSymbol.Commit(); |
158 | symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
||
159 | 5dfb8a24 | gaqhf | } |
160 | |||
161 | |||
162 | f1c9dbaa | gaqhf | if (_TargetItem != null) |
163 | ReleaseCOMObjects(_TargetItem); |
||
164 | ReleaseCOMObjects(dataSource); |
||
165 | ReleaseCOMObjects(_LMSymbol); |
||
166 | cfda1fed | gaqhf | } |
167 | |||
168 | 1b261371 | gaqhf | private void LineModeling(List<Line> lines) |
169 | { |
||
170 | object DrwingID = "0"; |
||
171 | f1c9dbaa | gaqhf | LMADataSource dataSource = _placement.PIDDataSource; |
172 | 1b261371 | gaqhf | _LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME, ref DrwingID); |
173 | PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
||
174 | f1c9dbaa | gaqhf | LMSymbol _LMSymbol1 = null; |
175 | LMSymbol _LMSymbol2 = null; |
||
176 | 1b261371 | gaqhf | for (int i = 0; i < lines.Count; i++) |
177 | { |
||
178 | Line line = lines[i]; |
||
179 | f1c9dbaa | gaqhf | if (i == 0 || i + 1 != lines.Count) |
180 | { |
||
181 | object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[0].CONNECTEDITEM); |
||
182 | if (connItem != null && connItem.GetType() == typeof(Symbol)) |
||
183 | { |
||
184 | _LMSymbol1 = dataSource.GetSymbol(((Symbol)connItem).SPPID.RepresentationId); |
||
185 | if (_LMSymbol1 != null) |
||
186 | placeRunInputs.AddSymbolTarget(_LMSymbol1, line.SPPID.START_X, line.SPPID.START_Y); |
||
187 | else |
||
188 | placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
||
189 | } |
||
190 | else |
||
191 | placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
||
192 | } |
||
193 | |||
194 | if (i + 1 == lines.Count) |
||
195 | { |
||
196 | object connItem = SPPIDUtil.FindObjectByUID(document, line.CONNECTORS[1].CONNECTEDITEM); |
||
197 | if (connItem != null && connItem.GetType() == typeof(Symbol)) |
||
198 | { |
||
199 | _LMSymbol2 = dataSource.GetSymbol(((Symbol)connItem).SPPID.RepresentationId); |
||
200 | if (_LMSymbol2 != null) |
||
201 | { |
||
202 | if (i != 0) |
||
203 | placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
||
204 | |||
205 | placeRunInputs.AddSymbolTarget(_LMSymbol2, line.SPPID.END_X, line.SPPID.END_Y); |
||
206 | } |
||
207 | else |
||
208 | { |
||
209 | if (i != 0) |
||
210 | placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
||
211 | placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
||
212 | } |
||
213 | |||
214 | } |
||
215 | else |
||
216 | { |
||
217 | if (i != 0) |
||
218 | placeRunInputs.AddPoint(line.SPPID.START_X, line.SPPID.START_Y); |
||
219 | placeRunInputs.AddPoint(line.SPPID.END_X, line.SPPID.END_Y); |
||
220 | } |
||
221 | } |
||
222 | } |
||
223 | |||
224 | |||
225 | LMConnector _lMConnector = _placement.PIDPlaceRun(_LMAItem, placeRunInputs); |
||
226 | if (_lMConnector != null) |
||
227 | { |
||
228 | foreach (var line in lines) |
||
229 | line.SPPID.RepresentationId = _lMConnector.AsLMRepresentation().Id; |
||
230 | _lMConnector.Commit(); |
||
231 | 1b261371 | gaqhf | } |
232 | |||
233 | |||
234 | f1c9dbaa | gaqhf | if (_LMSymbol1 != null) |
235 | ReleaseCOMObjects(_LMSymbol1); |
||
236 | if (_LMSymbol2 != null) |
||
237 | ReleaseCOMObjects(_LMSymbol2); |
||
238 | 1b261371 | gaqhf | |
239 | f1c9dbaa | gaqhf | ReleaseCOMObjects(dataSource); |
240 | ReleaseCOMObjects(_lMConnector); |
||
241 | 1b261371 | gaqhf | ReleaseCOMObjects(placeRunInputs); |
242 | ReleaseCOMObjects(_LMAItem); |
||
243 | } |
||
244 | |||
245 | cfda1fed | gaqhf | private void LineNumberModeling(LineNumber lineNumber) |
246 | { |
||
247 | |||
248 | } |
||
249 | |||
250 | private void TextModeling(Text text) |
||
251 | { |
||
252 | |||
253 | } |
||
254 | |||
255 | private void NoteModeling(Note note) |
||
256 | { |
||
257 | |||
258 | } |
||
259 | |||
260 | 5dfb8a24 | gaqhf | |
261 | public void ReleaseCOMObjects(params object[] objVars) |
||
262 | { |
||
263 | int intNewRefCount = 0; |
||
264 | foreach (object obj in objVars) |
||
265 | { |
||
266 | if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
||
267 | intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
||
268 | } |
||
269 | } |
||
270 | cfda1fed | gaqhf | } |
271 | } |