hytos / DTI_PID / SPPIDConverter / Main.vb @ 8ac8bb85
이력 | 보기 | 이력해설 | 다운로드 (37.4 KB)
1 |
Imports System.IO |
---|---|
2 |
Imports System.Data.SqlClient |
3 |
Imports System.Data.SQLite |
4 |
Imports Plaice |
5 |
Imports Llama |
6 |
Imports PidA |
7 |
|
8 |
|
9 |
Imports System.Threading |
10 |
|
11 |
Public Class Main |
12 |
|
13 |
Dim _DB As DataTable = New DataTable() |
14 |
Dim _Placement As New Placement |
15 |
Dim _DWG_X = 0.84 '0.695 '1 ' |
16 |
Dim _DWG_Y = 0.594 '0.585 '0.8 ' |
17 |
|
18 |
Dim _IMG_X = 9933 |
19 |
Dim _IMG_Y = 7016 |
20 |
|
21 |
'Drawing 전역변수 |
22 |
Dim _objPIDADrawing As Object |
23 |
'현재선택한 폴더경로 |
24 |
Dim _selectFolderPath As String |
25 |
|
26 |
Private _Main_trd As Thread |
27 |
|
28 |
|
29 |
|
30 |
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load |
31 |
SetUpListViewColumns() |
32 |
LoadTree() |
33 |
If My.Settings.DBPath <> "" And My.Settings.Plant_Hierarchy <> "" Then |
34 |
Dim sDBPath As String = My.Settings.DBPath |
35 |
LoadDB(sDBPath) |
36 |
'TestPID() |
37 |
Else |
38 |
MessageBox.Show("설정값을 먼저 확인해주세요") |
39 |
End If |
40 |
End Sub |
41 |
|
42 |
Public Function GetDrawingInfo(ByVal errorList As ArrayList) |
43 |
Dim ds As Llama.LMADataSource |
44 |
ds = New Llama.LMADataSource |
45 |
Dim lmaItem As Llama.LMAItem |
46 |
|
47 |
For i = 0 To errorList.Count - 1 |
48 |
lmaItem = ds.GetModelItem(errorList.Item(i).m_strSPID()).AsLMAItem |
49 |
Dim drawingInfo As DrawingInfo |
50 |
drawingInfo = GetDrawingName(lmaItem.ItemType, lmaItem.Id) |
51 |
errorList.Item(i).m_LMAItem = lmaItem |
52 |
errorList.Item(i).m_strDrawingName = drawingInfo.mDrawingName |
53 |
errorList.Item(i).m_strDrawingPath = drawingInfo.mPath |
54 |
Next |
55 |
End Function |
56 |
Private mDataSource As Object |
57 |
|
58 |
'Public Sub New() |
59 |
|
60 |
' ' mDataSource.ProjectNumber = m_Information.InfoSite.SiteName |
61 |
' ' mDataSource.SiteNode = m_Information.InfoProject.ProjectINI |
62 |
' 'm_Information = SPPIDClass.Information.GetInstance() |
63 |
|
64 |
' 'If m_Information.InfoProject.ProjectVersion = SPPIDClass.InfoProject.SPPID_43 Then |
65 |
' ' 'SPPID4.3용 |
66 |
' ' mDataSource.ProjectNumber = m_Information.InfoSite.SiteName |
67 |
' 'Else |
68 |
' ' 'SPPID2007, SPPID2009용 |
69 |
' ' mDataSource.ProjectNumber = m_Information.InfoSite.SiteName & "!" & m_Information.InfoSite.SiteName |
70 |
' 'End If |
71 |
|
72 |
' ' mDataSource.SiteNode = m_Information.InfoProject.ProjectINI |
73 |
' ' mDataSource.ProjectNumber = m_Information.InfoSite.SiteName & "!" & m_Information.InfoSite.SiteName |
74 |
' '#If LATE_BINDING Then |
75 |
' ' mInstruments = CreateObject("Llama.LMInstruments", "") |
76 |
' ' mPipingComps = CreateObject("Llama.LMPipingComps", "") |
77 |
' ' mVessels = CreateObject("Llama.LMVessels", "") |
78 |
' ' mDrawings = CreateObject("Llama.LMDrawings", "") |
79 |
' ' mEquipments = CreateObject("Llama.LMEquipments", "") |
80 |
' ' mExchangers = CreateObject("Llama.LMExchangers", "") |
81 |
' ' mMechanicals = CreateObject("Llama.LMMechanicals", "") |
82 |
' ' mNozzles = CreateObject("Llama.LMNozzles", "") |
83 |
' ' mPipeRuns = CreateObject("Llama.LMPipeRuns", "") |
84 |
' ' mEquipmentOthers = CreateObject("Llama.LMEquipmentOthers", "") |
85 |
' '#Else |
86 |
' ' mInstruments = New Llama.LMInstruments |
87 |
' ' mPipingComps = New Llama.LMPipingComps |
88 |
' ' mVessels = New Llama.LMVessels |
89 |
' ' mDrawings = New Llama.LMDrawings |
90 |
' ' mEquipments = New Llama.LMEquipments |
91 |
' ' mExchangers = New Llama.LMExchangers |
92 |
' ' mMechanicals = New Llama.LMMechanicals |
93 |
' ' mNozzles = New Llama.LMNozzles |
94 |
' ' mPipeRuns = New Llama.LMPipeRuns |
95 |
' ' mEquipmentOthers = New Llama.LMEquipmentOthers |
96 |
' '#End If |
97 |
'End Sub |
98 |
Public Function GetDrawingName(ByVal itemType As String, ByVal itemName As String) As DrawingInfo |
99 |
|
100 |
Dim objFilter As Object |
101 |
objFilter = CreateObject("Llama.LMAFilter", "") |
102 |
|
103 |
Dim drawingInfo As DrawingInfo |
104 |
drawingInfo = New DrawingInfo |
105 |
|
106 |
objFilter.Criteria.AddNew("FirstOne") |
107 |
objFilter.Criteria.Item("FirstOne").SourceAttributeName = "SP_ID" |
108 |
objFilter.Critedkria.Item("FirstOne").ValueAttribute = itemName |
109 |
|
110 |
objFilter.Criteria.Item("FirstOne").Operator = "=" |
111 |
objFilter.Criteria.AddNew("SecondOne") |
112 |
objFilter.Criteria.Item("SecondOne").SourceAttributeName = "ItemStatus" |
113 |
objFilter.Criteria.Item("SecondOne").ValueAttribute = 1 |
114 |
objFilter.Criteria.Item("SecondOne").Operator = "=" |
115 |
objFilter.Criteria.Item("SecondOne").Conjunctive = -1 |
116 |
objFilter.ItemType = itemType |
117 |
|
118 |
Dim PlantItems As Object |
119 |
PlantItems = CreateObject("Llama.LMPlantItems", "") |
120 |
PlantItems.Collect(mDataSource, Filter:=objFilter) |
121 |
|
122 |
If PlantItems.Count = 0 Then |
123 |
drawingInfo.mSpID = "PlantStockpile" |
124 |
End If |
125 |
|
126 |
For Each PlantItem In PlantItems |
127 |
|
128 |
'If Not PlantItem.Representations.Nth(1).DrawingID.Value.ToString().Equals("0") Then |
129 |
Try |
130 |
drawingInfo.mDrawingName = PlantItem.Representations.Nth(1).DrawingObject.Attributes("Name").Value |
131 |
drawingInfo.mSpID = PlantItem.Representations.Nth(1).DrawingID |
132 |
drawingInfo.mPath = PlantItem.Representations.Nth(1).DrawingObject.Attributes("Path").Value |
133 |
Debug.WriteLine("DrawingName : " & drawingInfo.mDrawingName & ", SPID : " & drawingInfo.mSpID & ", Path : " & drawingInfo.mPath) |
134 |
Catch ex As Exception |
135 |
|
136 |
End Try |
137 |
|
138 |
'End If |
139 |
|
140 |
Next |
141 |
|
142 |
Return drawingInfo |
143 |
|
144 |
End Function |
145 |
|
146 |
Private Sub TestPID() |
147 |
|
148 |
Try |
149 |
|
150 |
Dim datasource As LMADataSource |
151 |
Dim objPIDAutoApp As Object |
152 |
Dim objPIDADrawing As Object |
153 |
Dim objDrawing As LMDrawing |
154 |
Dim objDrawings As LMDrawings |
155 |
datasource = New LMADataSource |
156 |
|
157 |
|
158 |
Dim oObj As Object = Nothing |
159 |
objDrawing = datasource.GetDrawing(oObj) |
160 |
objDrawings = New LMDrawings |
161 |
objDrawings.Collect(datasource) |
162 |
objPIDAutoApp = GetObject(, "SmartPlantPID.Application") '// CreateObject("PIDAutomation.Application") |
163 |
For Each objDrawing In objDrawings |
164 |
If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active |
165 |
objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(objDrawing.Attributes("Name")) |
166 |
If Not objPIDADrawing Is Nothing Then |
167 |
MessageBox.Show("Drawing " & objDrawing.Attributes("Name").Value & " is opened!") |
168 |
objPIDADrawing.CloseDrawing |
169 |
End If |
170 |
End If |
171 |
Next |
172 |
objPIDAutoApp.Quit |
173 |
objPIDAutoApp = Nothing |
174 |
objPIDADrawing = Nothing |
175 |
objDrawing = Nothing |
176 |
objDrawings = Nothing |
177 |
Catch ex As Exception |
178 |
|
179 |
End Try |
180 |
|
181 |
|
182 |
|
183 |
End Sub |
184 |
Public Function SetActiveSiteFromConfigInfo(ByVal strActiveSite As String) As Boolean |
185 |
|
186 |
On Error GoTo errHandler |
187 |
Dim objConfigInfo As Object 'interopigrConfigInfo412.igrConfigInfo |
188 |
objConfigInfo = CreateObject("interopigrConfigInfo412.igrConfigInfo", "") |
189 |
If Not objConfigInfo Is Nothing Then |
190 |
objConfigInfo.ApplicationName = "SmartPlantManager" |
191 |
objConfigInfo.SetConfigString(3, "SmartPlant Manager", "SiteServer", strActiveSite) |
192 |
SetActiveSiteFromConfigInfo = True |
193 |
End If |
194 |
objConfigInfo = Nothing |
195 |
|
196 |
Exit Function |
197 |
|
198 |
errHandler: |
199 |
' LogAndRaiseError ModuleName & "::GetConfigInfo " |
200 |
End Function |
201 |
Private Sub LoadTree() |
202 |
|
203 |
Dim i As Integer |
204 |
Dim j() As String |
205 |
j = Directory.GetLogicalDrives |
206 |
For i = 0 To UBound(j) |
207 |
|
208 |
Dim cdrive As System.IO.DriveInfo |
209 |
cdrive = My.Computer.FileSystem.GetDriveInfo(j(i).ToString) |
210 |
|
211 |
Select Case cdrive.DriveType |
212 |
Case DriveType.Fixed |
213 |
Tree_XMLFiles.Nodes.Add(j(i), j(i).ToString, 3) |
214 |
Case DriveType.CDRom |
215 |
Tree_XMLFiles.Nodes.Add(j(i), j(i).ToString, 11) |
216 |
Case DriveType.Network |
217 |
Tree_XMLFiles.Nodes.Add(j(i), j(i).ToString, 5) |
218 |
Case DriveType.Removable |
219 |
Tree_XMLFiles.Nodes.Add(j(i), j(i).ToString, 12) |
220 |
End Select |
221 |
|
222 |
Next |
223 |
End Sub |
224 |
|
225 |
Private Sub SetUpListViewColumns() |
226 |
' TODO: Add code to set up listview columns |
227 |
ListView_File.Columns.Add(" Name ") |
228 |
' ListView_File.Columns.Add(" Size ") |
229 |
' ListView_File.Columns.Add(" Extension ") |
230 |
ListView_File.Columns.Add(" Date Modified ") |
231 |
SetView(View.Details) |
232 |
End Sub |
233 |
|
234 |
|
235 |
Private Sub SetView(ByVal View As System.Windows.Forms.View) |
236 |
ListView_File.View = View.Details |
237 |
End Sub |
238 |
|
239 |
|
240 |
|
241 |
Private Sub InitXMLTree(ByVal sFolderPath As String) |
242 |
Tree_XMLFiles.Nodes.Clear() |
243 |
Dim oRootNode As TreeNode = Tree_XMLFiles.Nodes.Add("XML") |
244 |
'.XML 만 로드 |
245 |
Dim sfileEntries As String() = Directory.GetFiles(sFolderPath, "*.xml") |
246 |
' Process the list of files found in the directory. |
247 |
Dim sfileName As String |
248 |
For Each sfileName In sfileEntries |
249 |
oRootNode.Nodes.Add(sfileName) |
250 |
Next sfileName |
251 |
oRootNode.ExpandAll() |
252 |
End Sub |
253 |
|
254 |
|
255 |
|
256 |
|
257 |
Private Function CreateDwg(ByVal oDwgName As String) As Boolean |
258 |
Dim objPIDADrawing As Object = Nothing |
259 |
Dim objPIDAutoApp As Object = Nothing |
260 |
Dim datasource As LMADataSource = Nothing |
261 |
Try |
262 |
Dim DrawingNumber As String |
263 |
Dim DrawingName As String |
264 |
Dim sPlantGroupName As String = "Test" |
265 |
Dim sTemplateName As String = "\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\P&ID Reference Data\Template Files\Gazprom Project.pid" |
266 |
Dim objDrawing As LMDrawing |
267 |
Dim objDrawings As LMDrawings |
268 |
objDrawings = New LMDrawings |
269 |
datasource = New LMADataSource |
270 |
Debug.Print(datasource.ProjectNumber) |
271 |
Debug.Print(datasource.SiteNode) |
272 |
Debug.Print(datasource.IsSatellite) |
273 |
Debug.Print(datasource.GetSystemEditingToolbarSetting) |
274 |
objDrawings.Collect(datasource) |
275 |
Dim sPath As String = "\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\Plant_Hierarchy\8121\8121-1\188943-8121-PR-DW-011001.pid" |
276 |
objPIDAutoApp = CreateObject("PIDAutomation.Application") |
277 |
For Each objDrawing In objDrawings |
278 |
If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active |
279 |
objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(sPath) |
280 |
If Not objPIDADrawing Is Nothing Then |
281 |
|
282 |
objPIDADrawing.CloseDrawing |
283 |
End If |
284 |
End If |
285 |
Next |
286 |
|
287 |
Dim extension As String = Path.GetExtension(oDwgName) |
288 |
oDwgName = oDwgName.Replace(extension, "") |
289 |
|
290 |
objPIDAutoApp = CreateObject("PIDAutomation.Application") |
291 |
|
292 |
'For Each objDrawing In objPIDAutoApp.Drawings |
293 |
' objDrawing.CloseDrawing(True) |
294 |
'Next |
295 |
|
296 |
objPIDAutoApp.Drawings.OpenDrawing(oDwgName + ".pid") |
297 |
|
298 |
objPIDAutoApp.ActiveWindow.Fit() |
299 |
|
300 |
Return True |
301 |
Catch ex As Exception |
302 |
If objPIDADrawing IsNot Nothing Then |
303 |
objPIDADrawing.CloseDrawing |
304 |
End If |
305 |
If objPIDAutoApp IsNot Nothing Then |
306 |
objPIDAutoApp.Quit |
307 |
End If |
308 |
datasource = Nothing |
309 |
objPIDAutoApp = Nothing |
310 |
objPIDADrawing = Nothing |
311 |
Return False |
312 |
End Try |
313 |
If objPIDADrawing IsNot Nothing Then |
314 |
objPIDADrawing.CloseDrawing |
315 |
End If |
316 |
|
317 |
End Function |
318 |
|
319 |
|
320 |
#Region "Load Pipe" |
321 |
Private Function LoadPipe_DT() As DataTable |
322 |
Dim oDt As New DataTable |
323 |
oDt.Columns.Add("start_x") |
324 |
oDt.Columns.Add("start_y") |
325 |
oDt.Columns.Add("end_x") |
326 |
oDt.Columns.Add("end_y") |
327 |
oDt.Columns.Add("Symbol") |
328 |
Return oDt |
329 |
|
330 |
End Function |
331 |
|
332 |
#End Region |
333 |
|
334 |
#Region "Load Symbol" |
335 |
Private Function LoadSymbol_DT() As DataTable |
336 |
Dim oDt As New DataTable |
337 |
oDt.Columns.Add("Name") |
338 |
oDt.Columns.Add("x") |
339 |
oDt.Columns.Add("y") |
340 |
oDt.Columns.Add("Angle") |
341 |
oDt.Columns.Add("Symbol") |
342 |
oDt.Columns.Add("Text") |
343 |
Return oDt |
344 |
End Function |
345 |
|
346 |
#End Region |
347 |
|
348 |
Private Function GetSymbolMapping(ByVal oSymbolName As String) As String |
349 |
Dim oSystemPath As String = "" |
350 |
If _DB.Rows.Count > 0 Then |
351 |
Dim oSelectRow() As DataRow = _DB.Select("[pid_symbolname] = '" + oSymbolName + "'") |
352 |
If oSelectRow.Length = 1 Then |
353 |
oSystemPath = oSelectRow(0).Item("sppid_systempath").ToString() |
354 |
End If |
355 |
End If |
356 |
Return oSystemPath |
357 |
End Function |
358 |
|
359 |
|
360 |
Private Function LoadSymbolInXml(ByVal sXmlPath As String) As DataTable |
361 |
Dim oDt As DataTable = LoadSymbol_DT() |
362 |
Dim oElement As XElement = XElement.Load(sXmlPath) |
363 |
If oElement IsNot Nothing Then |
364 |
For Each symbols As Object In oElement.Elements("SYMBOLS") |
365 |
For Each page As Object In symbols.Elements("SYMBOL") |
366 |
Dim oAddrow As DataRow = oDt.NewRow() |
367 |
Dim oObj As XElement = page.Element("NAME") |
368 |
Dim oSymbol = oObj.Value |
369 |
oObj = page.Element("TEXT") |
370 |
Dim oText = oObj.Value |
371 |
oObj = page.Element("CLASS") |
372 |
Dim oClass = oObj.Value |
373 |
oObj = page.Element("TYPE") |
374 |
Dim oType = oObj.Value |
375 |
oObj = page.Element("ITEM") |
376 |
Dim oItem = oObj.Value |
377 |
' Dim oSymbolPath As String = "\" + oSymbol + "\" + oClass + "\" + oType + "\" + oItem + ".sym" |
378 |
Dim oSymbolPath As String = GetSymbolMapping(oItem) |
379 |
oObj = page.Element("ORIGINALPOINT") |
380 |
Dim sOriginPoint = oObj.Value |
381 |
oObj = page.Element("ANGLE") |
382 |
Dim oAngle = oObj.Value |
383 |
Dim oSplitPos As String() = sOriginPoint.Split(",") |
384 |
Dim oX As Double = 0.0 |
385 |
Dim oY As Double = 0.0 |
386 |
If IsNumeric(oSplitPos(0)) Then |
387 |
oX = Double.Parse(oSplitPos(0)) |
388 |
End If |
389 |
If IsNumeric(oSplitPos(1)) Then |
390 |
oY = Double.Parse(oSplitPos(1)) |
391 |
End If |
392 |
ConvertPoint(oX, oY, _IMG_X, _IMG_Y) |
393 |
oAddrow("X") = oX '+ 0.05 |
394 |
oAddrow("Y") = oY |
395 |
oAddrow("Angle") = oAngle |
396 |
oAddrow("Symbol") = oSymbolPath |
397 |
oAddrow("Text") = oText |
398 |
oAddrow("Name") = oSymbol |
399 |
oDt.Rows.Add(oAddrow) |
400 |
Next |
401 |
Next |
402 |
End If |
403 |
Return oDt |
404 |
End Function |
405 |
|
406 |
|
407 |
|
408 |
Private Function LoadPipeInXml(ByVal sXmlPath As String) As DataTable |
409 |
Try |
410 |
Dim oDt As DataTable = LoadPipe_DT() |
411 |
Dim oElement As XElement = XElement.Load(sXmlPath) |
412 |
If oElement IsNot Nothing Then |
413 |
Dim DWGElement As XElement = oElement.Element("DWGNAME") |
414 |
Dim DWGNAME = DWGElement.Value |
415 |
Dim sXY As XElement = oElement.Element("SIZE") |
416 |
Dim sSize = sXY.Value |
417 |
Dim oSplitDWGPos As String() = sSize.Split(",") |
418 |
|
419 |
If IsNumeric(oSplitDWGPos(0)) Then |
420 |
_IMG_X = Double.Parse(oSplitDWGPos(0)) |
421 |
End If |
422 |
If IsNumeric(oSplitDWGPos(1)) Then |
423 |
_IMG_Y = Double.Parse(oSplitDWGPos(1)) |
424 |
End If |
425 |
|
426 |
For Each pipes As Object In oElement.Elements("IMGLINES") |
427 |
For Each pipe As Object In pipes.Elements("IMGLINE") |
428 |
Dim oAddrow As DataRow = oDt.NewRow() |
429 |
Dim oObj As XElement = pipe.Element("ITEM") |
430 |
Dim oItem = oObj.Value |
431 |
' Dim oSymbolPath As String = "\" + oSymbol + "\" + oClass + "\" + oType + "\" + oItem + ".sym" |
432 |
Dim oSymbolPath As String = GetSymbolMapping(oItem) |
433 |
oObj = pipe.Element("START") |
434 |
Dim oStartPoint = oObj.Value |
435 |
Dim oSplitPos As String() = oStartPoint.Split(",") |
436 |
Dim oStartpos_X As Double = 0.0 |
437 |
Dim oStartpos_Y As Double = 0.0 |
438 |
If IsNumeric(oSplitPos(0)) Then |
439 |
oStartpos_X = Double.Parse(oSplitPos(0)) |
440 |
End If |
441 |
If IsNumeric(oSplitPos(1)) Then |
442 |
oStartpos_Y = Double.Parse(oSplitPos(1)) |
443 |
End If |
444 |
|
445 |
ConvertPoint(oStartpos_X, oStartpos_Y, _DWG_X, _DWG_Y) |
446 |
oObj = pipe.Element("END") |
447 |
Dim oEndPoint = oObj.Value |
448 |
oSplitPos = oEndPoint.Split(",") |
449 |
Dim oEndpos_X As Double = 0.0 |
450 |
Dim oEndpos_Y As Double = 0.0 |
451 |
If IsNumeric(oSplitPos(0)) Then |
452 |
oEndpos_X = Double.Parse(oSplitPos(0)) |
453 |
End If |
454 |
If IsNumeric(oSplitPos(1)) Then |
455 |
oEndpos_Y = Double.Parse(oSplitPos(1)) |
456 |
End If |
457 |
ConvertPoint(oEndpos_X, oEndpos_Y, _DWG_X, _DWG_Y) |
458 |
|
459 |
oAddrow("start_x") = oStartpos_X '+ 0.05 |
460 |
oAddrow("start_y") = oStartpos_Y |
461 |
oAddrow("end_x") = oEndpos_X |
462 |
oAddrow("end_y") = oEndpos_Y |
463 |
oAddrow("Symbol") = oSymbolPath |
464 |
oDt.Rows.Add(oAddrow) |
465 |
Next |
466 |
Next |
467 |
|
468 |
End If |
469 |
|
470 |
|
471 |
Return oDt |
472 |
Catch ex As Exception |
473 |
Return Nothing |
474 |
End Try |
475 |
End Function |
476 |
|
477 |
|
478 |
Private Sub ConvertPoint(ByRef dX As Double, ByRef dY As Double, ByVal dDwgX As Double, ByVal dDwgY As Double) |
479 |
|
480 |
Dim calcx As Double = 0 |
481 |
Dim calcy As Double = 0 |
482 |
calcx = (dX * _DWG_X) / dDwgX 'Math.Round((dX * _DWG_X) / dDwgX, 2) |
483 |
calcy = _DWG_Y - (dY * _DWG_Y) / dDwgY '_DWG_Y - Math.Round((dY * _DWG_Y) / dDwgY, 2) |
484 |
dX = calcx |
485 |
dY = calcy |
486 |
End Sub |
487 |
|
488 |
Private Function AutoConverting(ByVal oPipe_Dt As DataTable, ByVal oSymbol_Dt As DataTable) As Boolean |
489 |
Dim iTotalCount As Double = oPipe_Dt.Rows.Count + oSymbol_Dt.Rows.Count |
490 |
Dim iSymbolcount As Double = 0 |
491 |
Dim objPlacement As Object |
492 |
Dim lobjDatasource As Object |
493 |
objPlacement = CreateObject("Plaice.Placement", "") |
494 |
|
495 |
lobjDatasource = objPlacement.PIDDataSource |
496 |
lobjDatasource.BeginTransaction() |
497 |
|
498 |
' datasource = objPlacement.PIDDataSource |
499 |
'Dim iPipecnt As Integer = 0 |
500 |
|
501 |
If oPipe_Dt IsNot Nothing Then |
502 |
For Each oRow As DataRow In oPipe_Dt.Rows |
503 |
Dim oposition As String = oRow("position").ToString() |
504 |
Dim oSymbol As String = oRow("Symbol").ToString() |
505 |
Dim oSplitStr As String() = Split(oposition, " ") |
506 |
Dim objConnector As LMConnector |
507 |
Dim objInputs As PlaceRunInputs |
508 |
objInputs = New PlaceRunInputs |
509 |
|
510 |
For Each sposition As String In oSplitStr |
511 |
Dim opointstr As String() = Split(sposition, ",") |
512 |
|
513 |
If (opointstr.Length > 1) Then |
514 |
If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then |
515 |
Dim ox As Double = opointstr(0) |
516 |
Dim oy As Double = opointstr(1) |
517 |
ConvertPoint(ox, oy, _IMG_X, _IMG_Y) |
518 |
objInputs.AddPoint(ox, oy) |
519 |
End If |
520 |
End If |
521 |
Next |
522 |
Dim objItem As LMAItem |
523 |
objItem = objPlacement.PIDCreateItem(oSymbol) |
524 |
objConnector = objPlacement.PIDPlaceRun(objItem, objInputs) |
525 |
|
526 |
'Dim objPipeRun As LMPipeRun = datasource.GetPipeRun(objConnector.ModelItemID) |
527 |
'objPipeRun.Attributes("OperFluidCode").Value = "AFS" |
528 |
'objPipeRun.Commit() |
529 |
iSymbolcount = iSymbolcount + 1 |
530 |
|
531 |
|
532 |
|
533 |
|
534 |
Next |
535 |
End If |
536 |
|
537 |
|
538 |
|
539 |
For Each oRow As DataRow In oSymbol_Dt.Rows |
540 |
|
541 |
Try |
542 |
Dim oSymbol As String = oRow("Symbol").ToString() |
543 |
Dim oType As String = oRow("Name").ToString() |
544 |
Dim oText As String = oRow("Text").ToString() |
545 |
Dim oX As Double = 0.0 |
546 |
Dim oY As Double = 0.0 |
547 |
If IsNumeric(oRow("x").ToString()) Then |
548 |
oX = Double.Parse(oRow("x").ToString()) |
549 |
End If |
550 |
If IsNumeric(oRow("y").ToString()) Then |
551 |
oY = Double.Parse(oRow("y").ToString()) |
552 |
End If |
553 |
Dim oAngle As Double = 0.0 |
554 |
If IsNumeric(oRow("Angle").ToString()) Then |
555 |
oAngle = Double.Parse(oRow("Angle").ToString()) |
556 |
End If |
557 |
' oSymbol = "\INSTRUMENTation\SYSTEM FUNCTIONS\D C S\DCS FUNC ACCESS IN PRIME LOC.sym" |
558 |
If oSymbol <> "" Then |
559 |
If oType = "INSTRUMENTATION" Then |
560 |
Dim sTagsuffix As String = "" |
561 |
Dim sTagSequenceNo As String = "" |
562 |
Dim sMeasuredVariableCode As String = "" |
563 |
Dim sInstrumentTypeModifier As String = "" |
564 |
If oText <> "" Then |
565 |
If oText.Contains(",") Then |
566 |
Dim splitstr() As String = oText.Split(",") |
567 |
For i = 0 To splitstr.Count - 1 |
568 |
If i = 0 Then |
569 |
sMeasuredVariableCode = Mid(splitstr(i), 1, 1) |
570 |
sTagSequenceNo = Mid(splitstr(i), 2, Len(splitstr(i))) |
571 |
Else |
572 |
If Len(splitstr(i)) = 1 Then |
573 |
sInstrumentTypeModifier = splitstr(i) |
574 |
ElseIf Len(splitstr(i)) = 0 Then |
575 |
|
576 |
ElseIf Len(splitstr(i)) > 1 Then |
577 |
sInstrumentTypeModifier = Mid(splitstr(i), 1, 1) |
578 |
sTagsuffix = Mid(splitstr(i), 2, Len(splitstr(i))) |
579 |
End If |
580 |
End If |
581 |
Next |
582 |
Else |
583 |
sMeasuredVariableCode = Mid(oText, 1, 1) |
584 |
sTagSequenceNo = Mid(oText, 2, Len(oText)) |
585 |
End If |
586 |
|
587 |
End If |
588 |
|
589 |
Dim objInstrSym As LMSymbol |
590 |
objInstrSym = objPlacement.PIDPlaceSymbol(oSymbol, oX, oY, , oAngle) |
591 |
Dim objInstr As LMInstrument |
592 |
objInstr = lobjDatasource.GetInstrument(objInstrSym.ModelItemID) |
593 |
|
594 |
Dim objItem As LMAItem |
595 |
objItem = objPlacement.PIDCreateItem(oSymbol) |
596 |
|
597 |
objInstr.Attributes("MeasuredVariableCode").Value = sMeasuredVariableCode |
598 |
objInstr.Attributes("InstrumentTypeModifier").Value = sInstrumentTypeModifier |
599 |
objInstr.Attributes("TagSuffix").Value = sTagsuffix |
600 |
objInstr.Attributes("TagSequenceNo").Value = sTagSequenceNo |
601 |
objInstr.Commit() |
602 |
ElseIf oType = "GATE VALVE WITH PLUG" Then |
603 |
|
604 |
ElseIf oType = "MEDIUM 1D 1TO1" Then |
605 |
|
606 |
1: |
607 |
Else |
608 |
objPlacement.PIDPlaceSymbol(oSymbol, oX, oY, , oAngle) |
609 |
|
610 |
End If |
611 |
iSymbolcount = iSymbolcount + 1 |
612 |
Else |
613 |
End If |
614 |
Catch ex As Exception |
615 |
|
616 |
End Try |
617 |
Dim dCalcProgressValue As Double = (iSymbolcount / iTotalCount) * 100 |
618 |
SetProgressbar(ProgressBar_Status, dCalcProgressValue) |
619 |
' ProgressBar_Status.Value = (iSymbolcount / iTotalCount) * 100 |
620 |
Next |
621 |
|
622 |
MsgBox("symbol: " & iSymbolcount & "개 변환완료") |
623 |
' MsgBox("symbol: " & iSymbolcount & "개, pipe : " & iPipecnt & "개 변환완료") |
624 |
End Function |
625 |
|
626 |
|
627 |
Private Sub Tree_XMLFiles_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles Tree_XMLFiles.AfterCheck |
628 |
If e.Node.Checked = True Then |
629 |
For Each oNode As TreeNode In e.Node.Nodes |
630 |
oNode.Checked = True |
631 |
Next |
632 |
Else |
633 |
For Each oNode As TreeNode In e.Node.Nodes |
634 |
oNode.Checked = False |
635 |
Next |
636 |
End If |
637 |
End Sub |
638 |
|
639 |
Private Sub LoadDB(ByVal sDBPath As String) |
640 |
|
641 |
Try |
642 |
Dim sConnectionstring As String = "Data Source=" & sDBPath & ";Version=3;Synchronous=Off;UTF8Encoding=True;" |
643 |
Dim conn As SQLiteConnection = New SQLiteConnection(sConnectionstring) |
644 |
conn.Open() |
645 |
Dim sQuery As String = "Select * from Mapping" |
646 |
Dim cmd As SQLiteCommand = conn.CreateCommand() |
647 |
Dim adapter As SQLiteDataAdapter = New SQLiteDataAdapter(sQuery, conn) |
648 |
Dim oDataSet As DataSet = New DataSet() |
649 |
adapter.Fill(oDataSet) |
650 |
_DB = oDataSet.Tables(0) |
651 |
Catch ex As Exception |
652 |
|
653 |
End Try |
654 |
|
655 |
|
656 |
End Sub |
657 |
|
658 |
Dim first_start As Boolean = False |
659 |
Dim folders_path As String |
660 |
|
661 |
Private Sub Tree_XMLFiles_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles Tree_XMLFiles.AfterSelect |
662 |
If first_start = False Then Exit Sub |
663 |
Dim pa = e.Node.FullPath.ToString |
664 |
|
665 |
printfilesfolders_here(pa, e.Node) |
666 |
|
667 |
displayfiles(pa) |
668 |
|
669 |
''be careful ! displayfils comes BEFORE you change // to / in pa !!! |
670 |
Dim coco As String = "" |
671 |
coco = pa.ToString |
672 |
coco = coco.Replace("\\", "\") |
673 |
Me.Text = coco |
674 |
folders_path = coco |
675 |
End Sub |
676 |
|
677 |
Sub printfilesfolders_here(ByVal path As String, ByRef itree As TreeNode) |
678 |
|
679 |
Dim foldername As String |
680 |
Dim filename As String |
681 |
itree.Nodes.Clear() |
682 |
On Error GoTo eee |
683 |
For Each foldername In Directory.GetDirectories(path) |
684 |
On Error GoTo eee |
685 |
Dim jj = foldername.LastIndexOf("\") |
686 |
Dim jj1 = foldername.Length - jj |
687 |
Dim foldr = foldername.Substring((jj + 1), (jj1 - 1)) |
688 |
itree.Nodes.Add(foldr, foldr) |
689 |
Next ' if you put this next at the end of procedure recursive will be done on first folder only |
690 |
Exit Sub |
691 |
eee: |
692 |
End Sub |
693 |
|
694 |
Sub displayfiles(ByVal path As String) |
695 |
|
696 |
Dim lvItem As ListViewItem |
697 |
ListView_File.Items.Clear() |
698 |
|
699 |
' lvItem = ListView.Items.Add("ListViewItem1") |
700 |
' lvItem.SubItems.AddRange(New String() {"Size", "extention", "date modified"}) |
701 |
|
702 |
Dim filename As String |
703 |
On Error GoTo wwq |
704 |
' Directory.GetFiles(path).Length. |
705 |
'Me.ProgressBar_Status.Maximum = Directory.GetFiles(path).Length + 1 |
706 |
'Me.ProgressBar_Status.Value = 0 |
707 |
For Each filename In Directory.GetFiles(path) |
708 |
On Error GoTo wwq |
709 |
Dim jj_ = filename.LastIndexOf("\") |
710 |
Dim jj1_ = filename.Length - jj_ |
711 |
Dim fil = filename.Substring((jj_ + 1), (jj1_ - 1)) |
712 |
If fil.Contains(".xml") Then |
713 |
' Me.ProgressBar_Status.Value = Me.ProgressBar_Status.Value + 1 |
714 |
' ListView.Items.Add(fil, 13) ''old 13 28 |
715 |
lvItem = ListView_File.Items.Add(fil, 13) '2 5 7 work, 0 alos |
716 |
Dim infoReader As System.IO.FileInfo |
717 |
infoReader = My.Computer.FileSystem.GetFileInfo(filename) |
718 |
' lvItem.SubItems.AddRange(New String() {infoReader.Length.ToString + " Byte", infoReader.Extension.ToString, infoReader.LastWriteTime}) |
719 |
lvItem.SubItems.AddRange(New String() {infoReader.LastWriteTime}) |
720 |
ListView_File.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent) |
721 |
End If |
722 |
|
723 |
|
724 |
Next |
725 |
Exit Sub |
726 |
wwq: |
727 |
MsgBox(Err.Description) |
728 |
End Sub |
729 |
|
730 |
Private Sub Tree_XMLFiles_MouseMove(sender As Object, e As MouseEventArgs) Handles Tree_XMLFiles.MouseMove |
731 |
first_start = True |
732 |
End Sub |
733 |
|
734 |
Private Sub ListView_File_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView_File.SelectedIndexChanged |
735 |
Dim indexes As ListView.SelectedIndexCollection = |
736 |
Me.ListView_File.SelectedIndices |
737 |
Dim index As Integer |
738 |
|
739 |
For Each index In indexes |
740 |
'On Error Resume Next |
741 |
If folders_path.EndsWith("\") = True Then |
742 |
Me.Status_Main.Items(0).Text = folders_path + (Me.ListView_File.Items(index).Text) |
743 |
'On Error Resume Next |
744 |
Else |
745 |
Me.Status_Main.Items(0).Text = folders_path + "\" + (Me.ListView_File.Items(index).Text) |
746 |
End If |
747 |
|
748 |
Dim infoReader As System.IO.FileInfo |
749 |
infoReader = My.Computer.FileSystem.GetFileInfo(Me.Status_Main.Items(0).Text) |
750 |
Me.Status_Main.Items(1).Text = " Created : " + infoReader.CreationTime.ToString + " " + infoReader.Attributes.ToString |
751 |
Next |
752 |
End Sub |
753 |
|
754 |
Private Sub Procees() |
755 |
Dim indexes As ListView.SelectedIndexCollection = |
756 |
Me.ListView_File.SelectedIndices |
757 |
Dim index As Integer |
758 |
|
759 |
For Each index In indexes |
760 |
'On Error Resume Next |
761 |
If folders_path.EndsWith("\") = True Then |
762 |
On Error GoTo out |
763 |
Me.Status_Main.Items(0).Text = folders_path + (Me.ListView_File.Items(index).Text) |
764 |
On Error GoTo out |
765 |
'On Error Resume Next |
766 |
Else |
767 |
Me.Status_Main.Items(0).Text = folders_path + "\" + (Me.ListView_File.Items(index).Text) |
768 |
On Error GoTo out |
769 |
End If |
770 |
|
771 |
Dim infoReader As System.IO.FileInfo |
772 |
infoReader = My.Computer.FileSystem.GetFileInfo(Me.Status_Main.Items(0).Text) |
773 |
Me.Status_Main.Items(1).Text = " Created : " + infoReader.CreationTime.ToString + " " + infoReader.Attributes.ToString |
774 |
On Error GoTo out |
775 |
MsgBox(Me.Status_Main.Items(0).Text + " is processed") |
776 |
On Error GoTo out |
777 |
Next |
778 |
Exit Sub |
779 |
out: |
780 |
MsgBox(Err.Description) |
781 |
End Sub |
782 |
|
783 |
Private Function LoadAllDrawing() As DataTable |
784 |
|
785 |
|
786 |
|
787 |
|
788 |
Dim oDt As DataTable = Drawing_Dt() |
789 |
'Dim oDt As DataTable = Drawing_Dt() |
790 |
'_objPIDADrawing = CreateObject("PIDAutomation.Application") |
791 |
'For Each objDrawing In _objPIDADrawing.Drawings |
792 |
' Dim sName As String = objDrawing.Attributes("Name").Value |
793 |
' Dim sPath As String = objDrawing.Attributes("Path").Value |
794 |
' Dim oAddRow As DataRow = oDt.NewRow() |
795 |
' oAddRow("Name") = sName |
796 |
' oAddRow("Path") = sPath |
797 |
' oDt.Rows.Add(oAddRow) |
798 |
'Next |
799 |
Dim sHierarchy As String = My.Settings.Plant_Hierarchy |
800 |
|
801 |
|
802 |
Dim files() As String |
803 |
files = Directory.GetFiles(sHierarchy, "*.pid", SearchOption.AllDirectories) |
804 |
For Each FileName As String In files |
805 |
Dim sName As String = FileName |
806 |
Dim oAddRow As DataRow = oDt.NewRow() |
807 |
oAddRow("Name") = Path.GetFileNameWithoutExtension(sName) |
808 |
oAddRow("Path") = FileName |
809 |
oDt.Rows.Add(oAddRow) |
810 |
' Console.WriteLine(FileName) |
811 |
Next |
812 |
|
813 |
|
814 |
|
815 |
'Dim datasource As LMADataSource |
816 |
'Dim objPIDAutoApp As Object |
817 |
'Dim objPIDADrawing As Object |
818 |
'Dim objDrawing As LMDrawing |
819 |
'Dim objDrawings As LMDrawings |
820 |
'objPIDAutoApp = CreateObject("PIDAutomation.Application") |
821 |
'objPIDAutoApp = GetObject(, "SmartPlantPID.Application") |
822 |
|
823 |
'datasource = CreateObject("Llama.LMADataSource", "") |
824 |
'Dim oObj As Object = Nothing |
825 |
'objDrawings = New LMDrawings |
826 |
'objDrawing = datasource.GetDrawing(oObj) |
827 |
|
828 |
'objDrawings.Collect(datasource) |
829 |
'' objPIDAutoApp = GetObject(, "SmartPlantPID.Application") '// CreateObject("PIDAutomation.Application") |
830 |
'For Each objDrawing In objDrawings |
831 |
' Dim sName As String = objDrawing.Attributes("Name").Value |
832 |
' Dim sPath As String = objDrawing.Attributes("Path").Value |
833 |
' Dim oAddRow As DataRow = oDt.NewRow() |
834 |
' oAddRow("Name") = sName |
835 |
' oAddRow("Path") = sHierarchy & "\" & sPath |
836 |
' oDt.Rows.Add(oAddRow) |
837 |
'Next |
838 |
|
839 |
Return oDt |
840 |
End Function |
841 |
|
842 |
Private Function LoadAllDrawing2() As DataTable |
843 |
Dim datasource As LMADataSource |
844 |
Dim objPIDAutoApp As Object |
845 |
Dim objPIDADrawing As Object |
846 |
Dim objDrawing As Object 'Drawing |
847 |
'Dim objDrawing As LMDrawing |
848 |
'Dim objDrawings As LMDrawings |
849 |
|
850 |
datasource = New LMADataSource |
851 |
|
852 |
' objDrawings = New LMDrawings |
853 |
'objDrawings.Collect(datasource) |
854 |
objPIDAutoApp = CreateObject("PIDAutomation.Application") |
855 |
|
856 |
For Each objDrawing In objPIDAutoApp.Drawings |
857 |
objDrawing.CloseDrawing(True) |
858 |
Next |
859 |
Try |
860 |
objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("UY1-K-2000_P1_300dpi_0321_TEST_1") |
861 |
Catch ex As Exception |
862 |
Process.Start("\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\Plant_Hierarchy\8121\8121-1\UY1-K-2000_P1_300dpi_0321_TEST_1.pid") |
863 |
End Try |
864 |
|
865 |
|
866 |
|
867 |
Dim sType As Type = objPIDAutoApp.GetType() |
868 |
Dim iCount As Integer = 0 |
869 |
' Dim sPath As String = "\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\Plant_Hierarchy\8121\8121-1\188943-8121-PR-DW-011001.pid" |
870 |
|
871 |
objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("1") |
872 |
|
873 |
For Each objDrawing In objPIDAutoApp.Drawings |
874 |
If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active |
875 |
Try |
876 |
|
877 |
Dim sName As String = objDrawing.Attributes("Name").Value |
878 |
|
879 |
iCount = iCount + 1 |
880 |
If sName = "UY1-K-2000_P1_300dpi_0321_TEST_1" Then |
881 |
objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(objDrawing.Attributes("Name")) |
882 |
objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("\8121\8121-1\UY1-K-2000_P1_300dpi_0321_TEST_1.pid") |
883 |
If Not objPIDADrawing Is Nothing Then |
884 |
objPIDADrawing.CloseDrawing() |
885 |
End If |
886 |
End If |
887 |
|
888 |
|
889 |
Catch ex As Exception |
890 |
|
891 |
End Try |
892 |
|
893 |
End If |
894 |
Next |
895 |
objPIDAutoApp.Quit |
896 |
objPIDAutoApp = Nothing |
897 |
objPIDADrawing = Nothing |
898 |
objDrawing = Nothing |
899 |
' objDrawings = Nothing |
900 |
End Function |
901 |
|
902 |
|
903 |
|
904 |
|
905 |
Private Sub ThreadTask() |
906 |
If ListView_File.Items.Count > 0 Then |
907 |
Dim oDwg_Dt As DataTable = LoadAllDrawing() |
908 |
Dim iDwgCnt As Integer = 0 |
909 |
|
910 |
Dim myList = DirectCast(Invoke(New GetListViewDelegate(AddressOf GetListViewItems), ListView_File), List(Of String)) |
911 |
For i = 0 To myList.Count - 1 |
912 |
|
913 |
Dim sDwgName As String = Path.GetFileNameWithoutExtension(myList(i)) |
914 |
Txt_Status.Text = sDwgName & "..(" & i + 1 & "/" & myList.Count & ")" |
915 |
|
916 |
Dim sDwgNo As String = myList(i) |
917 |
Dim oDwgPath As String = "" |
918 |
oDwgPath = _selectFolderPath + "\" + sDwgNo |
919 |
|
920 |
Dim sPath As String = OpenDrawing(oDwg_Dt, sDwgName) |
921 |
If sPath <> "" Then |
922 |
Process.Start(sPath) |
923 |
|
924 |
Dim oPipe_Dt As DataTable = New DataTable() 'LoadPipeInXml(oDwgPath) |
925 |
Dim oSymbol_Dt As DataTable = LoadSymbolInXml(oDwgPath) |
926 |
AutoConverting(oPipe_Dt, oSymbol_Dt) |
927 |
End If |
928 |
''도면 생성 |
929 |
'If CreateDwg(sDwgName) Then |
930 |
' 'AutoConverting |
931 |
|
932 |
'End If |
933 |
|
934 |
Next |
935 |
End If |
936 |
End Sub |
937 |
|
938 |
|
939 |
|
940 |
Private Sub Btn_Convert_Click(sender As Object, e As EventArgs) Handles Btn_Convert.Click |
941 |
Me.ProgressBar_Status.Visible = True |
942 |
ProgressBar_Status.Maximum = 100 |
943 |
ProgressBar_Status.Value = 0 |
944 |
_selectFolderPath = Tree_XMLFiles.SelectedNode.FullPath.Replace("\\", "\") |
945 |
_Main_trd = New Thread(AddressOf ThreadTask) |
946 |
_Main_trd.IsBackground = True |
947 |
_Main_trd.Start() |
948 |
|
949 |
End Sub |
950 |
|
951 |
|
952 |
Private Function GetCheckList(ByVal listviewItem As ListViewItem) |
953 |
|
954 |
End Function |
955 |
|
956 |
Private Sub newThreadFunc(ByVal state As Object) |
957 |
|
958 |
End Sub |
959 |
|
960 |
Private Function OpenDrawing(ByVal oDt As DataTable, ByVal sDwgName As String) As String |
961 |
Dim oRows As DataRow() = oDt.Select("[Name] = '" & sDwgName & "'") |
962 |
Dim oPath As String = "" |
963 |
If oRows.Length > 0 Then |
964 |
oPath = oRows(0).Item("Path").ToString() |
965 |
End If |
966 |
Return oPath |
967 |
End Function |
968 |
|
969 |
|
970 |
Private Sub Btn_Setting_Click(sender As Object, e As EventArgs) Handles Btn_Setting.Click |
971 |
Dim oSettings As Settings = New Settings() |
972 |
oSettings.ShowDialog() |
973 |
End Sub |
974 |
|
975 |
Private Sub Btn_Stop_Click(sender As Object, e As EventArgs) Handles Btn_Stop.Click |
976 |
|
977 |
End Sub |
978 |
|
979 |
Private Sub DropDown_File_Click(sender As Object, e As EventArgs) Handles DropDown_File.Click |
980 |
|
981 |
End Sub |
982 |
|
983 |
|
984 |
|
985 |
|
986 |
|
987 |
End Class |
988 |
|
989 |
|
990 |
Public Class DrawingInfo |
991 |
Public mDrawingName As String |
992 |
Public mSpID As String |
993 |
Public mPath As String |
994 |
End Class |
995 |
|
996 |
|
997 |
|
998 |
|
999 |
|