hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ d77973b3
이력 | 보기 | 이력해설 | 다운로드 (16.1 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.ComponentModel; |
4 |
using System.Drawing; |
5 |
using System.Data; |
6 |
using System.Linq; |
7 |
using System.Text; |
8 |
using System.Threading.Tasks; |
9 |
using System.Windows.Forms; |
10 |
using System.Threading; |
11 |
using System.IO; |
12 |
using Microsoft.VisualBasic; |
13 |
using Ingr.RAD2D; |
14 |
using Converter.BaseModel; |
15 |
using Converter.SPPID.Properties; |
16 |
using Converter.SPPID.DB; |
17 |
using Converter.SPPID.Util; |
18 |
using Converter.SPPID.Form; |
19 |
using Converter.SPPID.Model; |
20 |
using Plaice; |
21 |
using Llama; |
22 |
using DevExpress.XtraSplashScreen; |
23 |
using Newtonsoft.Json; |
24 |
using System.Runtime.InteropServices; |
25 |
|
26 |
namespace Converter.SPPID.Wrapper |
27 |
{ |
28 |
public partial class ConverterDocking : UserControl |
29 |
{ |
30 |
Ingr.RAD2D.Application radApp; |
31 |
dynamic application; |
32 |
public ConverterDocking() |
33 |
{ |
34 |
InitializeComponent(); |
35 |
application = Interaction.GetObject("", "PIDAutomation.Application"); |
36 |
WrapperApplication wApp = new WrapperApplication(application.Application); |
37 |
radApp = wApp.RADApplication; |
38 |
|
39 |
try |
40 |
{ |
41 |
textEditDrawingX.EditValue = Settings.Default.DrawingX; |
42 |
textEditDrawingY.EditValue = Settings.Default.DrawingY; |
43 |
} |
44 |
catch (Exception ex) |
45 |
{ |
46 |
StringBuilder sb = new StringBuilder(); |
47 |
sb.AppendLine(ex.Message); |
48 |
sb.AppendLine(ex.StackTrace); |
49 |
MessageBox.Show(sb.ToString()); |
50 |
} |
51 |
|
52 |
#if DEBUG |
53 |
simpleButton1.Visible = true; |
54 |
|
55 |
|
56 |
#endif |
57 |
} |
58 |
|
59 |
private void btnConverter_Click(object sender, EventArgs e) |
60 |
{ |
61 |
ConverterForm converterForm = new ConverterForm(); |
62 |
if (converterForm.ShowDialog() == DialogResult.OK) |
63 |
{ |
64 |
try |
65 |
{ |
66 |
CloseOPCForm.Run(); |
67 |
|
68 |
for (int i = 0; i < converterForm.Documents.Count; i++) |
69 |
{ |
70 |
SPPID_Document document = converterForm.Documents[i]; |
71 |
if (document.SetSPPIDMapping() && document.Enable) |
72 |
{ |
73 |
AutoModeling modeling = new AutoModeling(document, application, radApp); |
74 |
modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count); |
75 |
modeling.Run(); |
76 |
} |
77 |
} |
78 |
} |
79 |
catch (Exception ex) |
80 |
{ |
81 |
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
82 |
} |
83 |
finally |
84 |
{ |
85 |
CloseOPCForm.Stop(); |
86 |
} |
87 |
|
88 |
MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
89 |
} |
90 |
} |
91 |
|
92 |
private void btnLinkOPC_Click(object sender, EventArgs e) |
93 |
{ |
94 |
LMADataSource dataSource = new LMADataSource(); |
95 |
LMDrawings drawings = new LMDrawings(); |
96 |
|
97 |
//try |
98 |
{ |
99 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
100 |
_ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath; |
101 |
if (Project_DB.ConnTestAndCreateTable()) |
102 |
{ |
103 |
DataTable dt = Project_DB.SelectSPPID_DB_INFO(); |
104 |
if (dt.Columns.Count > 0 && dt.Rows.Count > 0) |
105 |
SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString()); |
106 |
else |
107 |
SPPID_DBInfo.Clear(); |
108 |
|
109 |
SPPID_DBInfo sPPID_DBInfo = SPPID_DBInfo.GetInstance(); |
110 |
if (sPPID_DBInfo.Enable) |
111 |
{ |
112 |
drawings.Collect(dataSource); |
113 |
|
114 |
DataTable drawingTable = Project_DB.SelectDrawingInfo(); |
115 |
drawingTable.Columns.Add("EXIST", typeof(bool)); |
116 |
drawingTable.Columns.Add("SPPIDPATH", typeof(string)); |
117 |
|
118 |
foreach (LMDrawing item in drawings) |
119 |
{ |
120 |
DataRow[] rows = drawingTable.Select(string.Format("DRAWINGNUMBER = '{0}'", item.Attributes["DrawingNumber"].get_Value())); |
121 |
foreach (DataRow row in rows) |
122 |
{ |
123 |
row["EXIST"] = true; |
124 |
row["DRAWINGNAME"] = item.Attributes["Name"].get_Value(); |
125 |
row["SPPIDPATH"] = item.get_Path(); |
126 |
} |
127 |
} |
128 |
|
129 |
List<SPPID_Document> allDocuments = new List<SPPID_Document>(); |
130 |
foreach (DataRow row in drawingTable.Rows) |
131 |
allDocuments.Add((SPPID_Document)row["DOCUMENT"]); |
132 |
|
133 |
AutoModeling_OPC opc = new AutoModeling_OPC(allDocuments, application, radApp); |
134 |
opc.Run(); |
135 |
} |
136 |
} |
137 |
else |
138 |
{ |
139 |
MessageBox.Show(Msg.ConnectionFail, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
140 |
} |
141 |
} |
142 |
//catch (Exception ex) |
143 |
{ |
144 |
//MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
145 |
} |
146 |
//finally |
147 |
{ |
148 |
ReleaseCOMObjects(dataSource); |
149 |
ReleaseCOMObjects(drawings); |
150 |
} |
151 |
} |
152 |
|
153 |
public void ReleaseCOMObjects(params object[] objVars) |
154 |
{ |
155 |
int intNewRefCount = 0; |
156 |
foreach (object obj in objVars) |
157 |
{ |
158 |
if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
159 |
intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
160 |
} |
161 |
} |
162 |
|
163 |
private void btnGetDrawingSize_Click(object sender, EventArgs e) |
164 |
{ |
165 |
if (radApp.ActiveSelectSet.Count > 0) |
166 |
{ |
167 |
DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject; |
168 |
if (line2D != null) |
169 |
{ |
170 |
double minX = 0; |
171 |
double minY = 0; |
172 |
double maxX = 0; |
173 |
double maxY = 0; |
174 |
line2D.Range(out minX, out minY, out maxX, out maxY); |
175 |
|
176 |
Settings.Default.DrawingX = maxX - minX; |
177 |
Settings.Default.DrawingY = maxY - minY; |
178 |
Settings.Default.Save(); |
179 |
|
180 |
textEditDrawingX.EditValue = Settings.Default.DrawingX; |
181 |
textEditDrawingY.EditValue = Settings.Default.DrawingY; |
182 |
} |
183 |
else |
184 |
MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
185 |
} |
186 |
else |
187 |
MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
188 |
} |
189 |
|
190 |
#region TEST |
191 |
Placement _placement = new Placement(); |
192 |
LMADataSource dataSource; |
193 |
bool first = true; |
194 |
LMDrawing currentDrawing; |
195 |
private void simpleButton1_Click(object sender, EventArgs e) |
196 |
{ |
197 |
dataSource = _placement.PIDDataSource; |
198 |
|
199 |
string projectNumber = dataSource.ProjectNumber; |
200 |
LMActiveProject activeProject = dataSource.GetActiveProject(); |
201 |
LMAEnumAttLists enumAttLists = dataSource.CodeLists; |
202 |
|
203 |
AutoJoinPipeRun(); |
204 |
} |
205 |
private void AutoJoinPipeRun() |
206 |
{ |
207 |
string modelItemId = null; |
208 |
List<double[]> vertices = new List<double[]>(); |
209 |
if (radApp.ActiveSelectSet.Count == 0) |
210 |
{ |
211 |
return; |
212 |
} |
213 |
dynamic OID = radApp.ActiveSelectSet[0].Key(); |
214 |
DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID]; |
215 |
foreach (var attributes in drawingObject.AttributeSets) |
216 |
{ |
217 |
foreach (var attribute in attributes) |
218 |
{ |
219 |
if (attribute.Name == "ModelID") |
220 |
modelItemId = attribute.GetValue().ToString(); |
221 |
} |
222 |
} |
223 |
radApp.ActiveSelectSet.RemoveAll(); |
224 |
|
225 |
|
226 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemId); |
227 |
LMPipeRun run = dataSource.GetPipeRun(modelItem.Id); |
228 |
dynamic dd = run.get_Name(); |
229 |
LMAAttribute att = run.Attributes["FileName"]; |
230 |
//foreach (LMRepresentation rep in modelItem.Representations) |
231 |
//{ |
232 |
// if (!DBNull.Value.Equals(rep.get_FileName())) |
233 |
// { |
234 |
// rep.set_FileName(@"\Instrumentation\Signal Line\Connect to Process.sym"); |
235 |
// } |
236 |
//} |
237 |
|
238 |
|
239 |
} |
240 |
private void JoinRun(string modelId, string mainModelId, ref string survivorId) |
241 |
{ |
242 |
try |
243 |
{ |
244 |
LMModelItem modelItem1 = dataSource.GetModelItem(modelId); |
245 |
_LMAItem item1 = modelItem1.AsLMAItem(); |
246 |
LMModelItem modelItem2 = dataSource.GetModelItem(mainModelId); |
247 |
_LMAItem item2 = modelItem2.AsLMAItem(); |
248 |
|
249 |
// item2가 item1으로 조인 |
250 |
_placement.PIDJoinRuns(ref item1, ref item2); |
251 |
item1.Commit(); |
252 |
item2.Commit(); |
253 |
|
254 |
string beforeID = string.Empty; |
255 |
string afterID = string.Empty; |
256 |
|
257 |
if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() != "Active") |
258 |
{ |
259 |
beforeID = modelItem2.Id; |
260 |
afterID = modelItem1.Id; |
261 |
survivorId = afterID; |
262 |
} |
263 |
else if (modelItem1.get_ItemStatus() != "Active" && modelItem2.get_ItemStatus() == "Active") |
264 |
{ |
265 |
beforeID = modelItem1.Id; |
266 |
afterID = modelItem2.Id; |
267 |
survivorId = afterID; |
268 |
} |
269 |
else if (modelItem1.get_ItemStatus() == "Active" && modelItem2.get_ItemStatus() == "Active") |
270 |
survivorId = null; |
271 |
else |
272 |
{ |
273 |
Log.Write("잘못된 경우"); |
274 |
survivorId = null; |
275 |
} |
276 |
|
277 |
|
278 |
//if (!string.IsNullOrEmpty(beforeID) && !string.IsNullOrEmpty(afterID)) |
279 |
//{ |
280 |
// List<Line> lines = SPPIDUtil.FindLinesByModelId(document, beforeID); |
281 |
// foreach (var line in lines) |
282 |
// line.SPPID.ModelItemId = afterID; |
283 |
//} |
284 |
|
285 |
ReleaseCOMObjects(modelItem1); |
286 |
ReleaseCOMObjects(item1); |
287 |
ReleaseCOMObjects(modelItem2); |
288 |
ReleaseCOMObjects(item2); |
289 |
} |
290 |
catch (Exception ex) |
291 |
{ |
292 |
Log.Write("Join Error"); |
293 |
Log.Write(ex.Message); |
294 |
} |
295 |
} |
296 |
|
297 |
private void JoinRunBySameType(string modelItemId, ref string survivorId) |
298 |
{ |
299 |
LMModelItem modelItem = dataSource.GetModelItem(modelItemId); |
300 |
if (modelItem != null) |
301 |
{ |
302 |
foreach (LMRepresentation rep in modelItem.Representations) |
303 |
{ |
304 |
if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active") |
305 |
{ |
306 |
LMConnector connector = dataSource.GetConnector(rep.Id); |
307 |
if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch") |
308 |
{ |
309 |
LMSymbol symbol = connector.ConnectItem1SymbolObject; |
310 |
List<string> modelItemIds = FindOtherModelItemBySymbolWhereTypePipeRun(symbol, modelItem.Id); |
311 |
if (modelItemIds.Count == 1) |
312 |
{ |
313 |
JoinRun(modelItemIds[0], modelItemId, ref survivorId); |
314 |
if (survivorId != null) |
315 |
break; |
316 |
} |
317 |
} |
318 |
if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch") |
319 |
{ |
320 |
LMSymbol symbol = connector.ConnectItem2SymbolObject; |
321 |
List<string> modelItemIds = FindOtherModelItemBySymbolWhereTypePipeRun(symbol, modelItem.Id); |
322 |
if (modelItemIds.Count == 1) |
323 |
{ |
324 |
JoinRun(modelItemIds[0], modelItemId, ref survivorId); |
325 |
if (survivorId != null) |
326 |
break; |
327 |
} |
328 |
} |
329 |
} |
330 |
} |
331 |
} |
332 |
} |
333 |
|
334 |
private List<string> FindOtherModelItemBySymbolWhereTypePipeRun(LMSymbol symbol, string modelId) |
335 |
{ |
336 |
List<string> modelItemIDs = new List<string>(); |
337 |
foreach (LMConnector connector in symbol.Connect1Connectors) |
338 |
{ |
339 |
LMModelItem modelItem = connector.ModelItemObject; |
340 |
if (modelItem.get_ItemStatus() == "Active" && modelItem.get_ItemTypeName().ToString() == "PipeRun" && modelItem.Id != modelId) |
341 |
modelItemIDs.Add(modelItem.Id); |
342 |
ReleaseCOMObjects(modelItem); |
343 |
ReleaseCOMObjects(connector); |
344 |
} |
345 |
|
346 |
foreach (LMConnector connector in symbol.Connect2Connectors) |
347 |
{ |
348 |
LMModelItem modelItem = connector.ModelItemObject; |
349 |
if (modelItem.get_ItemStatus() == "Active" && modelItem.get_ItemTypeName().ToString() == "PipeRun" && modelItem.Id != modelId) |
350 |
modelItemIDs.Add(modelItem.Id); |
351 |
ReleaseCOMObjects(modelItem); |
352 |
ReleaseCOMObjects(connector); |
353 |
} |
354 |
|
355 |
return modelItemIDs; |
356 |
} |
357 |
|
358 |
private void FindOtherModelItemBySymbolWhereTypePipeRunLoop() |
359 |
{ |
360 |
|
361 |
} |
362 |
|
363 |
private void JoinRunOnlyPipeRun() |
364 |
{ |
365 |
|
366 |
} |
367 |
|
368 |
private void GetConnectPointsCount(LMSymbol symbol,ref int pipeRunCount, ref int signalCount) |
369 |
{ |
370 |
string typeName = symbol.ModelItemObject.get_ItemTypeName().ToString(); |
371 |
if (typeName == "Instrument") |
372 |
{ |
373 |
LMInstrument item = dataSource.GetInstrument(symbol.ModelItemID); |
374 |
pipeRunCount = item.PipingPoints.Count; |
375 |
signalCount = item.SignalPoints.Count; |
376 |
ReleaseCOMObjects(item); |
377 |
} |
378 |
else if (typeName == "PipingComp") |
379 |
{ |
380 |
LMPipingComp item = dataSource.GetPipingComp(symbol.ModelItemID); |
381 |
pipeRunCount = item.PipingPoints.Count; |
382 |
signalCount = item.SignalPoints.Count; |
383 |
ReleaseCOMObjects(item); |
384 |
} |
385 |
} |
386 |
|
387 |
|
388 |
|
389 |
private void TESTLine() |
390 |
{ |
391 |
Placement _placement = new Placement(); |
392 |
LMADataSource dataSource = _placement.PIDDataSource;//placement.PIDDataSource; |
393 |
|
394 |
foreach (var attributes in radApp.ActiveSelectSet[0].AttributeSets) |
395 |
{ |
396 |
foreach (var attribute in attributes) |
397 |
{ |
398 |
if (attribute.Name == "ModelID") |
399 |
{ |
400 |
LMModelItem modelItem = dataSource.GetModelItem(attribute.GetValue().ToString()); |
401 |
foreach (LMRepresentation representation in modelItem.Representations) |
402 |
{ |
403 |
//representa |
404 |
} |
405 |
} |
406 |
} |
407 |
} |
408 |
} |
409 |
#endregion |
410 |
|
411 |
|
412 |
[DllImport("user32.dll")] |
413 |
public static extern int FindWindow(string lpClassName, string lpWindowName); |
414 |
|
415 |
[DllImport("user32.dll", SetLastError = true)] |
416 |
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId); |
417 |
|
418 |
} |
419 |
} |