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