hytos / DTI_PID / SPPIDConverter / AutoModeling.cs @ f1c9dbaa
이력 | 보기 | 이력해설 | 다운로드 (9.52 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 |
|
26 |
SPPID_Document document; |
27 |
|
28 |
|
29 |
public AutoModeling(SPPID_Document document) |
30 |
{ |
31 |
this.document = document; |
32 |
} |
33 |
|
34 |
|
35 |
|
36 |
public void Run() |
37 |
{ |
38 |
//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 |
object prevItem = null; |
53 |
// Symbol 먼저 |
54 |
foreach (var item in run.RUNITEMS) |
55 |
{ |
56 |
if (item.GetType() == typeof(Symbol)) |
57 |
{ |
58 |
Symbol symbol = item as Symbol; |
59 |
SymbolModeling(symbol, prevSymbol, prevItem); |
60 |
prevSymbol = symbol; |
61 |
} |
62 |
prevItem = item; |
63 |
} |
64 |
|
65 |
|
66 |
Line prevLine = null; |
67 |
prevSymbol = null; |
68 |
prevItem = null; |
69 |
List<Line> lines = new List<Line>(); |
70 |
foreach (var item in run.RUNITEMS) |
71 |
{ |
72 |
// Line일 경우 |
73 |
if (item.GetType() == typeof(Line)) |
74 |
{ |
75 |
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 |
} |
101 |
|
102 |
prevItem = item; |
103 |
} |
104 |
|
105 |
if (lines.Count > 0) |
106 |
LineModeling(lines); |
107 |
} |
108 |
} |
109 |
|
110 |
|
111 |
ReleaseCOMObjects(_placement); |
112 |
System.Windows.Forms.MessageBox.Show("end"); |
113 |
} |
114 |
|
115 |
|
116 |
private void TestSource() |
117 |
{ |
118 |
|
119 |
} |
120 |
|
121 |
private void SymbolModeling(Symbol symbol, Symbol prevSymbol, object prevItem) |
122 |
{ |
123 |
LMSymbol _LMSymbol = null; |
124 |
LMADataSource dataSource = _placement.PIDDataSource; |
125 |
|
126 |
string mappingPath = symbol.SPPID.MAPPINGNAME; |
127 |
double x = symbol.SPPID.ORIGINAL_X; |
128 |
double y = symbol.SPPID.ORIGINAL_Y; |
129 |
int mirror = 0; |
130 |
double angle = symbol.ANGLE; |
131 |
LMSymbol _TargetItem = null; |
132 |
|
133 |
if (prevItem != null && prevItem.GetType() == typeof(Symbol)) |
134 |
_TargetItem = dataSource.GetSymbol(((Symbol)prevItem).SPPID.RepresentationId); |
135 |
|
136 |
if (prevSymbol != null) |
137 |
{ |
138 |
SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y); |
139 |
LMSymbol prevLMSymbol = dataSource.GetSymbol(prevSymbol.SPPID.RepresentationId); |
140 |
double prevX = prevLMSymbol.get_XCoordinate(); |
141 |
double prevY = prevLMSymbol.get_YCoordinate(); |
142 |
if (slopeType == SlopeType.HORIZONTAL) |
143 |
y = prevY; |
144 |
else if (slopeType == SlopeType.VERTICAL) |
145 |
x = prevX; |
146 |
|
147 |
ReleaseCOMObjects(prevLMSymbol); |
148 |
} |
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 |
_LMSymbol.Commit(); |
158 |
symbol.SPPID.RepresentationId = _LMSymbol.AsLMRepresentation().Id; |
159 |
} |
160 |
|
161 |
|
162 |
if (_TargetItem != null) |
163 |
ReleaseCOMObjects(_TargetItem); |
164 |
ReleaseCOMObjects(dataSource); |
165 |
ReleaseCOMObjects(_LMSymbol); |
166 |
} |
167 |
|
168 |
private void LineModeling(List<Line> lines) |
169 |
{ |
170 |
object DrwingID = "0"; |
171 |
LMADataSource dataSource = _placement.PIDDataSource; |
172 |
_LMAItem _LMAItem = _placement.PIDCreateItem(lines[0].SPPID.MAPPINGNAME, ref DrwingID); |
173 |
PlaceRunInputs placeRunInputs = new PlaceRunInputs(); |
174 |
LMSymbol _LMSymbol1 = null; |
175 |
LMSymbol _LMSymbol2 = null; |
176 |
for (int i = 0; i < lines.Count; i++) |
177 |
{ |
178 |
Line line = lines[i]; |
179 |
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 |
} |
232 |
|
233 |
|
234 |
if (_LMSymbol1 != null) |
235 |
ReleaseCOMObjects(_LMSymbol1); |
236 |
if (_LMSymbol2 != null) |
237 |
ReleaseCOMObjects(_LMSymbol2); |
238 |
|
239 |
ReleaseCOMObjects(dataSource); |
240 |
ReleaseCOMObjects(_lMConnector); |
241 |
ReleaseCOMObjects(placeRunInputs); |
242 |
ReleaseCOMObjects(_LMAItem); |
243 |
} |
244 |
|
245 |
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 |
|
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 |
} |
271 |
} |