프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / Main.vb @ 7824381a

이력 | 보기 | 이력해설 | 다운로드 (46.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

    
31

    
32
    Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
33

    
34
        If My.Settings.DBPath <> "" And My.Settings.Plant_Hierarchy <> "" Then
35
            Dim sDBPath As String = My.Settings.DBPath
36
            LoadDB(sDBPath)
37

    
38
            'TestPID()
39
        Else
40
            MessageBox.Show("설정값을 먼저 확인해주세요")
41
        End If
42
    End Sub
43

    
44
    Public Function GetDrawingInfo(ByVal errorList As ArrayList)
45
        Dim ds As Llama.LMADataSource
46
        ds = New Llama.LMADataSource
47
        Dim lmaItem As Llama.LMAItem
48

    
49
        For i = 0 To errorList.Count - 1
50
            lmaItem = ds.GetModelItem(errorList.Item(i).m_strSPID()).AsLMAItem
51
            Dim drawingInfo As DrawingInfo
52
            drawingInfo = GetDrawingName(lmaItem.ItemType, lmaItem.Id)
53
            errorList.Item(i).m_LMAItem = lmaItem
54
            errorList.Item(i).m_strDrawingName = drawingInfo.mDrawingName
55
            errorList.Item(i).m_strDrawingPath = drawingInfo.mPath
56
        Next
57
    End Function
58
    Private mDataSource As Object
59

    
60
    'Public Sub New()
61

    
62
    '    '  mDataSource.ProjectNumber = m_Information.InfoSite.SiteName
63
    '    '   mDataSource.SiteNode = m_Information.InfoProject.ProjectINI
64
    '    'm_Information = SPPIDClass.Information.GetInstance()
65

    
66
    '    'If m_Information.InfoProject.ProjectVersion = SPPIDClass.InfoProject.SPPID_43 Then
67
    '    '    'SPPID4.3용
68
    '    '    mDataSource.ProjectNumber = m_Information.InfoSite.SiteName
69
    '    'Else
70
    '    '    'SPPID2007, SPPID2009용
71
    '    '    mDataSource.ProjectNumber = m_Information.InfoSite.SiteName & "!" & m_Information.InfoSite.SiteName
72
    '    'End If
73

    
74
    '    '  mDataSource.SiteNode = m_Information.InfoProject.ProjectINI
75
    '    '  mDataSource.ProjectNumber = m_Information.InfoSite.SiteName & "!" & m_Information.InfoSite.SiteName
76
    '    '#If LATE_BINDING Then
77
    '    '        mInstruments = CreateObject("Llama.LMInstruments", "")
78
    '    '        mPipingComps = CreateObject("Llama.LMPipingComps", "")
79
    '    '        mVessels = CreateObject("Llama.LMVessels", "")
80
    '    '        mDrawings = CreateObject("Llama.LMDrawings", "")
81
    '    '        mEquipments = CreateObject("Llama.LMEquipments", "")
82
    '    '        mExchangers = CreateObject("Llama.LMExchangers", "")
83
    '    '        mMechanicals = CreateObject("Llama.LMMechanicals", "")
84
    '    '        mNozzles = CreateObject("Llama.LMNozzles", "")
85
    '    '        mPipeRuns = CreateObject("Llama.LMPipeRuns", "")
86
    '    '        mEquipmentOthers = CreateObject("Llama.LMEquipmentOthers", "")
87
    '    '#Else
88
    '    '        mInstruments = New Llama.LMInstruments
89
    '    '        mPipingComps = New Llama.LMPipingComps
90
    '    '        mVessels = New Llama.LMVessels
91
    '    '        mDrawings = New Llama.LMDrawings
92
    '    '        mEquipments = New Llama.LMEquipments
93
    '    '        mExchangers = New Llama.LMExchangers
94
    '    '        mMechanicals = New Llama.LMMechanicals
95
    '    '        mNozzles = New Llama.LMNozzles
96
    '    '        mPipeRuns = New Llama.LMPipeRuns
97
    '    '        mEquipmentOthers = New Llama.LMEquipmentOthers
98
    '    '#End If
99
    'End Sub
100
    Public Function GetDrawingName(ByVal itemType As String, ByVal itemName As String) As DrawingInfo
101

    
102
        Dim objFilter As Object
103
        objFilter = CreateObject("Llama.LMAFilter", "")
104

    
105
        Dim drawingInfo As DrawingInfo
106
        drawingInfo = New DrawingInfo
107

    
108
        objFilter.Criteria.AddNew("FirstOne")
109
        objFilter.Criteria.Item("FirstOne").SourceAttributeName = "SP_ID"
110
        objFilter.Critedkria.Item("FirstOne").ValueAttribute = itemName
111

    
112
        objFilter.Criteria.Item("FirstOne").Operator = "="
113
        objFilter.Criteria.AddNew("SecondOne")
114
        objFilter.Criteria.Item("SecondOne").SourceAttributeName = "ItemStatus"
115
        objFilter.Criteria.Item("SecondOne").ValueAttribute = 1
116
        objFilter.Criteria.Item("SecondOne").Operator = "="
117
        objFilter.Criteria.Item("SecondOne").Conjunctive = -1
118
        objFilter.ItemType = itemType
119

    
120
        Dim PlantItems As Object
121
        PlantItems = CreateObject("Llama.LMPlantItems", "")
122
        PlantItems.Collect(mDataSource, Filter:=objFilter)
123

    
124
        If PlantItems.Count = 0 Then
125
            drawingInfo.mSpID = "PlantStockpile"
126
        End If
127

    
128
        For Each PlantItem In PlantItems
129

    
130
            'If Not PlantItem.Representations.Nth(1).DrawingID.Value.ToString().Equals("0") Then
131
            Try
132
                drawingInfo.mDrawingName = PlantItem.Representations.Nth(1).DrawingObject.Attributes("Name").Value
133
                drawingInfo.mSpID = PlantItem.Representations.Nth(1).DrawingID
134
                drawingInfo.mPath = PlantItem.Representations.Nth(1).DrawingObject.Attributes("Path").Value
135
                Debug.WriteLine("DrawingName : " & drawingInfo.mDrawingName & ", SPID : " & drawingInfo.mSpID & ", Path : " & drawingInfo.mPath)
136
            Catch ex As Exception
137

    
138
            End Try
139

    
140
            'End If
141

    
142
        Next
143

    
144
        Return drawingInfo
145

    
146
    End Function
147

    
148
    Private Sub TestPID()
149

    
150
        Try
151

    
152
            Dim datasource As LMADataSource
153
            Dim objPIDAutoApp As Object
154
            Dim objPIDADrawing As Object
155
            Dim objDrawing As LMDrawing
156
            Dim objDrawings As LMDrawings
157
            datasource = New LMADataSource
158

    
159

    
160
            Dim oObj As Object = Nothing
161
            objDrawing = datasource.GetDrawing(oObj)
162
            objDrawings = New LMDrawings
163
            objDrawings.Collect(datasource)
164
            objPIDAutoApp = GetObject(, "SmartPlantPID.Application") '// CreateObject("PIDAutomation.Application")
165
            For Each objDrawing In objDrawings
166
                If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
167
                    objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(objDrawing.Attributes("Name"))
168
                    If Not objPIDADrawing Is Nothing Then
169
                        MessageBox.Show("Drawing " & objDrawing.Attributes("Name").Value & " is opened!")
170
                        objPIDADrawing.CloseDrawing
171
                    End If
172
                End If
173
            Next
174
            objPIDAutoApp.Quit
175
            objPIDAutoApp = Nothing
176
            objPIDADrawing = Nothing
177
            objDrawing = Nothing
178
            objDrawings = Nothing
179
        Catch ex As Exception
180

    
181
        End Try
182

    
183

    
184

    
185
    End Sub
186
    Public Function SetActiveSiteFromConfigInfo(ByVal strActiveSite As String) As Boolean
187

    
188
        On Error GoTo errHandler
189
        Dim objConfigInfo As Object 'interopigrConfigInfo412.igrConfigInfo
190
        objConfigInfo = CreateObject("interopigrConfigInfo412.igrConfigInfo", "")
191
        If Not objConfigInfo Is Nothing Then
192
            objConfigInfo.ApplicationName = "SmartPlantManager"
193
            objConfigInfo.SetConfigString(3, "SmartPlant Manager", "SiteServer", strActiveSite)
194
            SetActiveSiteFromConfigInfo = True
195
        End If
196
        objConfigInfo = Nothing
197

    
198
        Exit Function
199

    
200
errHandler:
201
        '    LogAndRaiseError ModuleName & "::GetConfigInfo "
202
    End Function
203

    
204
    Private Function CreateDwg(ByVal oDwgName As String) As Boolean
205
        Dim objPIDADrawing As Object = Nothing
206
        Dim objPIDAutoApp As Object = Nothing
207
        Dim datasource As LMADataSource = Nothing
208
        Try
209
            Dim DrawingNumber As String
210
            Dim DrawingName As String
211
            Dim sPlantGroupName As String = "Test"
212
            Dim sTemplateName As String = "\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\P&ID Reference Data\Template Files\Gazprom Project.pid"
213
            Dim objDrawing As LMDrawing
214
            Dim objDrawings As LMDrawings
215
            objDrawings = New LMDrawings
216
            datasource = New LMADataSource
217
            Debug.Print(datasource.ProjectNumber)
218
            Debug.Print(datasource.SiteNode)
219
            Debug.Print(datasource.IsSatellite)
220
            Debug.Print(datasource.GetSystemEditingToolbarSetting)
221
            objDrawings.Collect(datasource)
222
            Dim sPath As String = "‪\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\Plant_Hierarchy\8121\8121-1\188943-8121-PR-DW-011001.pid"
223
            objPIDAutoApp = CreateObject("PIDAutomation.Application")
224
            For Each objDrawing In objDrawings
225
                If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
226
                    objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(sPath)
227
                    If Not objPIDADrawing Is Nothing Then
228

    
229
                        objPIDADrawing.CloseDrawing
230
                    End If
231
                End If
232
            Next
233

    
234
            Dim extension As String = Path.GetExtension(oDwgName)
235
            oDwgName = oDwgName.Replace(extension, "")
236

    
237
            objPIDAutoApp = CreateObject("PIDAutomation.Application")
238

    
239
            'For Each objDrawing In objPIDAutoApp.Drawings
240
            '    objDrawing.CloseDrawing(True)
241
            'Next
242

    
243
            objPIDAutoApp.Drawings.OpenDrawing(oDwgName + ".pid")
244

    
245
            objPIDAutoApp.ActiveWindow.Fit()
246

    
247
            Return True
248
        Catch ex As Exception
249
            If objPIDADrawing IsNot Nothing Then
250
                objPIDADrawing.CloseDrawing
251
            End If
252
            If objPIDAutoApp IsNot Nothing Then
253
                objPIDAutoApp.Quit
254
            End If
255
            datasource = Nothing
256
            objPIDAutoApp = Nothing
257
            objPIDADrawing = Nothing
258
            Return False
259
        End Try
260
        If objPIDADrawing IsNot Nothing Then
261
            objPIDADrawing.CloseDrawing
262
        End If
263

    
264
    End Function
265

    
266

    
267
    Private Function GetSymbolMapping(ByVal oSymbolName As String) As String
268
        Dim oSystemPath As String = ""
269
        If _DB.Rows.Count > 0 Then
270
            Dim oSelectRow() As DataRow = _DB.Select("[pid_symbolname] = '" + oSymbolName + "'")
271
            If oSelectRow.Length = 1 Then
272
                oSystemPath = oSelectRow(0).Item("sppid_systempath").ToString()
273
            End If
274
        End If
275
        Return oSystemPath
276
    End Function
277

    
278

    
279
    Private Function LoadSymbolInXml(ByVal sXmlPath As String) As DataTable
280
        Dim oDt As DataTable = LoadSymbol_DT()
281
        Dim oElement As XElement = XElement.Load(sXmlPath)
282
        If oElement IsNot Nothing Then
283
            For Each symbols As Object In oElement.Elements("SYMBOLS")
284
                For Each page As Object In symbols.Elements("SYMBOL")
285
                    Dim oAddrow As DataRow = oDt.NewRow()
286
                    Dim oObj As XElement = page.Element("NAME")
287
                    Dim oName = oObj.Value
288
                    oObj = page.Element("TEXT")
289
                    Dim oText = oObj.Value
290
                    oObj = page.Element("CLASS")
291
                    Dim oClass = oObj.Value
292
                    oObj = page.Element("TYPE")
293
                    Dim oType = oObj.Value
294
                    oObj = page.Element("ITEM")
295
                    Dim oItem = oObj.Value
296
                    ' Dim oSymbolPath As String = "\" + oSymbol + "\" + oClass + "\" + oType + "\" + oItem + ".sym"
297
                    Dim oSymbolPath As String = GetSymbolMapping(oItem)
298
                    oObj = page.Element("ORIGINALPOINT")
299
                    Dim sOriginPoint = oObj.Value
300
                    oObj = page.Element("ANGLE")
301
                    Dim oAngle = oObj.Value
302
                    Dim oSplitPos As String() = sOriginPoint.Split(",")
303
                    Dim oX As Double = 0.0
304
                    Dim oY As Double = 0.0
305
                    If IsNumeric(oSplitPos(0)) Then
306
                        oX = Double.Parse(oSplitPos(0))
307
                    End If
308
                    If IsNumeric(oSplitPos(1)) Then
309
                        oY = Double.Parse(oSplitPos(1))
310
                    End If
311
                    ConvertPoint(oX, oY, _IMG_X, _IMG_Y)
312
                    oAddrow("x") = oX '+ 0.05
313
                    oAddrow("Y") = oY
314
                    oAddrow("Class") = oClass
315
                    oAddrow("Angle") = oAngle
316
                    oAddrow("SystemPath") = oSymbolPath
317
                    oAddrow("Text") = oText
318
                    oAddrow("Name") = oName
319
                    oAddrow("Item") = oItem
320
                    oAddrow("Type") = oType
321
                    oAddrow("uid") = Guid.NewGuid.ToString()
322
                    oDt.Rows.Add(oAddrow)
323
                Next
324
            Next
325
        End If
326
        Return oDt
327
    End Function
328

    
329

    
330

    
331
    Private Function LoadPipeInXml(ByVal sXmlPath As String) As DataTable
332
        Try
333
            Dim oDt As DataTable = LoadPipe_DT()
334
            Dim oElement As XElement = XElement.Load(sXmlPath)
335
            If oElement IsNot Nothing Then
336
                Dim DWGElement As XElement = oElement.Element("DWGNAME")
337
                Dim DWGNAME = DWGElement.Value
338
                Dim sXY As XElement = oElement.Element("SIZE")
339
                Dim sSize = sXY.Value
340
                Dim oSplitDWGPos As String() = sSize.Split(", ")
341

    
342
                If IsNumeric(oSplitDWGPos(0)) Then
343
                    _IMG_X = Double.Parse(oSplitDWGPos(0))
344
                End If
345
                If IsNumeric(oSplitDWGPos(1)) Then
346
                    _IMG_Y = Double.Parse(oSplitDWGPos(1))
347
                End If
348

    
349
                For Each pipes As Object In oElement.Elements("IMGLINES")
350
                    For Each pipe As Object In pipes.Elements("IMGLINE")
351
                        Dim oAddrow As DataRow = oDt.NewRow()
352
                        Dim oObj As XElement = pipe.Element("ITEM")
353
                        Dim oItem = oObj.Value
354
                        ' Dim oSymbolPath As String = "\" + oSymbol + "\" + oClass + "\" + oType + "\" + oItem + ".sym"
355
                        Dim oSymbolPath As String = GetSymbolMapping(oItem)
356
                        oObj = pipe.Element("START")
357
                        Dim oStartPoint = oObj.Value
358
                        Dim oSplitPos As String() = oStartPoint.Split(", ")
359
                        Dim oStartpos_X As Double = 0.0
360
                        Dim oStartpos_Y As Double = 0.0
361
                        If IsNumeric(oSplitPos(0)) Then
362
                            oStartpos_X = Double.Parse(oSplitPos(0))
363
                        End If
364
                        If IsNumeric(oSplitPos(1)) Then
365
                            oStartpos_Y = Double.Parse(oSplitPos(1))
366
                        End If
367

    
368
                        ConvertPoint(oStartpos_X, oStartpos_Y, _DWG_X, _DWG_Y)
369
                        oObj = pipe.Element("End")
370
                        Dim oEndPoint = oObj.Value
371
                        oSplitPos = oEndPoint.Split(", ")
372
                        Dim oEndpos_X As Double = 0.0
373
                        Dim oEndpos_Y As Double = 0.0
374
                        If IsNumeric(oSplitPos(0)) Then
375
                            oEndpos_X = Double.Parse(oSplitPos(0))
376
                        End If
377
                        If IsNumeric(oSplitPos(1)) Then
378
                            oEndpos_Y = Double.Parse(oSplitPos(1))
379
                        End If
380
                        ConvertPoint(oEndpos_X, oEndpos_Y, _DWG_X, _DWG_Y)
381

    
382
                        oAddrow("start_x") = oStartpos_X '+ 0.05
383
                        oAddrow("start_y") = oStartpos_Y
384
                        oAddrow("end_x") = oEndpos_X
385
                        oAddrow("end_y") = oEndpos_Y
386
                        oAddrow("SystemPath") = oSymbolPath
387
                        oDt.Rows.Add(oAddrow)
388
                    Next
389
                Next
390

    
391
            End If
392

    
393

    
394
            Return oDt
395
        Catch ex As Exception
396
            Return Nothing
397
        End Try
398
    End Function
399

    
400

    
401
    Private Sub ConvertPoint(ByRef dX As Double, ByRef dY As Double, ByVal dDwgX As Double, ByVal dDwgY As Double)
402

    
403
        Dim calcx As Double = 0
404
        Dim calcy As Double = 0
405
        calcx = (dX * _DWG_X) / dDwgX 'Math.Round((dX * _DWG_X) / dDwgX, 2)
406
        calcy = _DWG_Y - (dY * _DWG_Y) / dDwgY '_DWG_Y - Math.Round((dY * _DWG_Y) / dDwgY, 2)
407
        dX = calcx
408
        dY = calcy
409
    End Sub
410

    
411

    
412
    '@brief Convert To SPPID
413
    '@author : Gyusu Park
414
    '@date : 2018-04-10
415
    '@history:
416

    
417
    Private Function AutoConverting(ByVal oPipe_Dt As DataTable, ByVal oSymbol_Dt As DataTable, ByVal oTreeNode As TreeNode) As Boolean
418
        Dim iTotalCount As Double = oPipe_Dt.Rows.Count + oSymbol_Dt.Rows.Count
419
        Dim iSymbolcount As Double = 0
420

    
421
        Dim lobjDatasource As Object = _Placement.PIDDataSource
422

    
423
        ' lobjDatasource.BeginTransaction()
424
        '  datasource = objPlacement.PIDDataSource
425
        'Dim iPipecnt As Integer = 0
426
        SetListBoxItems(ListBox_Result, " Auto converting 시작....")
427

    
428
        Dim iPipeCnt As Integer = 0
429
        If oPipe_Dt IsNot Nothing Then
430
            For Each oRow As DataRow In oPipe_Dt.Rows
431
                Dim oposition As String = oRow("position").ToString()
432
                Dim oSymbol As String = oRow("SystemPath").ToString()
433
                Dim oSplitStr As String() = Split(oposition, " ")
434
                Dim objConnector As LMConnector
435
                Dim objInputs As PlaceRunInputs
436
                objInputs = New PlaceRunInputs
437

    
438
                For Each sposition As String In oSplitStr
439
                    Dim opointstr As String() = Split(sposition, ", ")
440

    
441
                    If (opointstr.Length > 1) Then
442
                        If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
443
                            Dim ox As Double = opointstr(0)
444
                            Dim oy As Double = opointstr(1)
445
                            ConvertPoint(ox, oy, _IMG_X, _IMG_Y)
446
                            objInputs.AddPoint(ox, oy)
447
                        End If
448
                    End If
449
                Next
450
                Dim objItem As LMAItem
451
                objItem = _Placement.PIDCreateItem(oSymbol)
452
                objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
453
                SetListBoxItems(ListBox_Result, " Place PipeLine...." & "(" & (iPipeCnt + 1) & "/" & oPipe_Dt.Rows.Count)
454
                'Dim objPipeRun As LMPipeRun = datasource.GetPipeRun(objConnector.ModelItemID)
455
                'objPipeRun.Attributes("OperFluidCode").Value = "AFS"
456
                'objPipeRun.Commit()
457
                iSymbolcount = iSymbolcount + 1
458
                iPipeCnt = iPipeCnt + 1
459
            Next
460
        End If
461

    
462
        SetListBoxItems(ListBox_Result, " Place PipeLine....완료")
463

    
464
        Dim iAllInstrumentCnt As Integer = oSymbol_Dt.Select("Name = 'INSTRUMENTATION'").Length
465
                    Dim iValveCnt As Integer = oSymbol_Dt.Select("Class = 'VALVES'").Length
466
        Dim iInstrumentCnt As Integer = 1
467
        Dim iFittingsCnt As Integer = 1
468

    
469
        Dim oInsNode As TreeNode = oTreeNode.Nodes.Find(oTreeNode.Name & "\Instruments", True)(0)
470
        Dim oValveNode As TreeNode = oTreeNode.Nodes.Find(oTreeNode.Name & "\Valves", True)(0)
471
        Dim oFittingsNode As TreeNode = oTreeNode.Nodes.Find(oTreeNode.Name & "\Fittings", True)(0)
472
        For Each oRow As DataRow In oSymbol_Dt.Rows
473

    
474
            Try
475

    
476
                Dim sSystemPath As String = oRow("SystemPath").ToString()
477
                Dim sName As String = oRow("Name").ToString()
478
                Dim sType As String = oRow("Type").ToString()
479
                Dim sText As String = oRow("Text").ToString()
480
                Dim sClass As String = oRow("Class").ToString()
481
                Dim sItem As String = oRow("Item").ToString()
482

    
483
                Dim oX As Double = 0.0
484
                Dim oY As Double = 0.0
485
                If IsNumeric(oRow("x").ToString()) Then
486
                    oX = Double.Parse(oRow("x").ToString())
487
                End If
488
                If IsNumeric(oRow("y").ToString()) Then
489
                    oY = Double.Parse(oRow("y").ToString())
490
                End If
491
                Dim oAngle As Double = 0.0
492
                If IsNumeric(oRow("Angle").ToString()) Then
493
                    oAngle = Double.Parse(oRow("Angle").ToString())
494
                End If
495
                '   oSymbol = "\INSTRUMENTation\SYSTEM FUNCTIONS\D C S\DCS FUNC ACCESS IN PRIME LOC.sym"
496
                If sSystemPath <> "" Then
497
                    If sName = _TYPE_Instumentation Then
498

    
499
                        Dim sTagsuffix As String = ""
500
                        Dim sTagSequenceNo As String = ""
501
                        Dim sMeasuredVariableCode As String = ""
502
                        Dim sInstrumentTypeModifier As String = ""
503

    
504
                        If sText <> "" Then
505
                            If sText.Contains(",") Then
506
                                Dim splitstr() As String = sText.Split(",")
507
                                For i = 0 To splitstr.Count - 1
508
                                    If i = 0 Then
509
                                        sMeasuredVariableCode = Mid(splitstr(i), 1, 1)
510
                                        sTagSequenceNo = Mid(splitstr(i), 2, Len(splitstr(i)))
511
                                    Else
512
                                        If Len(splitstr(i)) = 1 Then
513
                                            sInstrumentTypeModifier = splitstr(i)
514
                                        ElseIf Len(splitstr(i)) = 0 Then
515

    
516
                                        ElseIf Len(splitstr(i)) > 1 Then
517
                                            sInstrumentTypeModifier = Mid(splitstr(i), 1, 1)
518
                                            sTagsuffix = Mid(splitstr(i), 2, Len(splitstr(i)))
519
                                        End If
520
                                    End If
521
                                Next
522
                            Else
523
                                sMeasuredVariableCode = Mid(sText, 1, 1)
524
                                sTagSequenceNo = Mid(sText, 2, Len(sText))
525
                            End If
526

    
527
                        End If
528

    
529
                        Dim objInstrSym As LMSymbol
530
                        objInstrSym = _Placement.PIDPlaceSymbol(sSystemPath, oX, oY, , oAngle)
531
                        SetListBoxItems(ListBox_Result, " Place Instrument...." & "(" & (iInstrumentCnt + 1) & "/" & iAllInstrumentCnt & ")")
532

    
533
                        ' SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sTagSequenceNo)
534
                        Dim action As Action = Sub()
535
                                                   oInsNode.Nodes.Add(sClass & "-" & iInstrumentCnt)
536
                                                   oInsNode.ExpandAll()
537
                                               End Sub
538
                        oInsNode.TreeView.Invoke(action)
539

    
540

    
541
                        Dim objInstr As LMInstrument
542
                        objInstr = lobjDatasource.GetInstrument(objInstrSym.ModelItemID)
543

    
544
                        Dim objItem As LMAItem
545
                        objItem = _Placement.PIDCreateItem(sSystemPath)
546

    
547

    
548
                        objInstr.Attributes("MeasuredVariableCode").Value = sMeasuredVariableCode
549
                        objInstr.Attributes("InstrumentTypeModifier").Value = sInstrumentTypeModifier
550
                        objInstr.Attributes("TagSuffix").Value = sTagsuffix
551
                        objInstr.Attributes("TagSequenceNo").Value = sTagSequenceNo
552
                        objInstr.Commit()
553
                        iInstrumentCnt = iInstrumentCnt + 1
554
                    ElseIf sName = "GATE VALVE WITH PLUG" Then
555

    
556
                    ElseIf sName = "MEDIUM 1D 1TO1" Then
557

    
558
                    ElseIf sClass = "VALVES" Then
559
                        Dim action As Action = Sub()
560
                                                   oValveNode.ExpandAll()
561
                                                   oValveNode.Nodes.Add(sClass & "-" & iValveCnt)
562
                                               End Sub
563
                        oValveNode.TreeView.Invoke(action)
564

    
565
                        _Placement.PIDPlaceSymbol(sSystemPath, oX, oY, , oAngle)
566

    
567
                        iValveCnt = iValveCnt + 1
568
                    Else
569
                        Dim action As Action = Sub()
570
                                                   oFittingsNode.ExpandAll()
571
                                                   oFittingsNode.Nodes.Add(sClass & "-" & iFittingsCnt)
572
                                               End Sub
573
                        oFittingsNode.TreeView.Invoke(action)
574
                        _Placement.PIDPlaceSymbol(sSystemPath, oX, oY, , oAngle)
575

    
576
                        iFittingsCnt = iFittingsCnt + 1
577

    
578
                    End If
579
                    iSymbolcount = iSymbolcount + 1
580
                Else
581
                End If
582
            Catch ex As Exception
583

    
584
            End Try
585
            Dim dCalcProgressValue As Double = (iSymbolcount / iTotalCount) * 100
586
            SetProgressbar(ProgressBar_Status, dCalcProgressValue)
587
            '     ProgressBar_Status.Value = (iSymbolcount / iTotalCount) * 100
588

    
589
        Next
590

    
591
        MsgBox("Complete AutoConverting")
592
        SetListBoxItems(ListBox_Result, "Place Instrument....변환완료")
593
        SetListBoxItems(ListBox_Result, "총 symbol:  " & iSymbolcount & "개 변환완료")
594
        SetProgressbar(ProgressBar_Status, 100)
595
        ' MsgBox("symbol: " & iSymbolcount & "개, pipe : " & iPipecnt & "개 변환완료")
596
    End Function
597

    
598

    
599
    Private Sub Tree_XMLFiles_AfterCheck(sender As Object, e As TreeViewEventArgs)
600
        If e.Node.Checked = True Then
601
            For Each oNode As TreeNode In e.Node.Nodes
602
                oNode.Checked = True
603
            Next
604
        Else
605
            For Each oNode As TreeNode In e.Node.Nodes
606
                oNode.Checked = False
607
            Next
608
        End If
609
    End Sub
610

    
611
    Private Sub LoadDB(ByVal sDBPath As String)
612

    
613
        Try
614
            Dim sConnectionstring As String = "Data Source=" & sDBPath & ";Version=3;Synchronous=Off;UTF8Encoding=True;"
615
            Dim conn As SQLiteConnection = New SQLiteConnection(sConnectionstring)
616
            conn.Open()
617
            Dim sQuery As String = "Select * from Mapping"
618
            Dim cmd As SQLiteCommand = conn.CreateCommand()
619
            Dim adapter As SQLiteDataAdapter = New SQLiteDataAdapter(sQuery, conn)
620
            Dim oDataSet As DataSet = New DataSet()
621
            adapter.Fill(oDataSet)
622
            _DB = oDataSet.Tables(0)
623
        Catch ex As Exception
624

    
625
        End Try
626

    
627

    
628
    End Sub
629

    
630

    
631

    
632
    'Private Sub Tree_XMLFiles_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles Tree_XMLFiles.AfterSelect
633
    '    If first_start = False Then Exit Sub
634
    '    Dim pa = e.Node.FullPath.ToString
635

    
636
    '    printfilesfolders_here(pa, e.Node)
637

    
638
    '    displayfiles(pa)
639

    
640
    '    Dim coco As String = ""
641
    '    coco = pa.ToString
642
    '    coco = coco.Replace("\\", "\")
643
    '    Me.Text = coco
644
    '    folders_path = coco
645
    'End Sub
646

    
647
    Sub printfilesfolders_here(ByVal path As String, ByRef itree As TreeNode)
648

    
649
        Dim foldername As String
650
        Dim filename As String
651
        itree.Nodes.Clear()
652
        On Error GoTo eee
653
        For Each foldername In Directory.GetDirectories(path)
654
            On Error GoTo eee
655
            Dim jj = foldername.LastIndexOf("\")
656
            Dim jj1 = foldername.Length - jj
657
            Dim foldr = foldername.Substring((jj + 1), (jj1 - 1))
658
            itree.Nodes.Add(foldr, foldr)
659
        Next ' if you put this next at the end of procedure recursive will be done on first folder only
660
        Exit Sub
661
eee:
662
    End Sub
663

    
664

    
665

    
666
    '    Private Sub Tree_XMLFiles_MouseMove(sender As Object, e As MouseEventArgs) Handles Tree_XMLFiles.MouseMove
667
    '        first_start = True
668
    '    End Sub
669

    
670
    '    Private Sub ListView_File_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView_File.SelectedIndexChanged
671
    '        Dim indexes As ListView.SelectedIndexCollection =
672
    '                         Me.ListView_File.SelectedIndices
673
    '        Dim index As Integer
674

    
675
    '        For Each index In indexes
676
    '            'On Error Resume Next
677
    '            If folders_path.EndsWith("\") = True Then
678
    '                Me.Status_Main.Items(0).Text = folders_path + (Me.ListView_File.Items(index).Text)
679
    '                'On Error Resume Next
680
    '            Else
681
    '                Me.Status_Main.Items(0).Text = folders_path + "\" + (Me.ListView_File.Items(index).Text)
682
    '            End If
683

    
684
    '            Dim infoReader As System.IO.FileInfo
685
    '            infoReader = My.Computer.FileSystem.GetFileInfo(Me.Status_Main.Items(0).Text)
686
    '            Me.Status_Main.Items(1).Text = " Created : " + infoReader.CreationTime.ToString + " " + infoReader.Attributes.ToString
687
    '        Next
688
    '    End Sub
689

    
690
    '    Private Sub Procees()
691
    '        Dim indexes As ListView.SelectedIndexCollection =
692
    '                            Me.ListView_File.SelectedIndices
693
    '        Dim index As Integer
694

    
695
    '        For Each index In indexes
696
    '            'On Error Resume Next
697
    '            If folders_path.EndsWith("\") = True Then
698
    '                On Error GoTo out
699
    '                Me.Status_Main.Items(0).Text = folders_path + (Me.ListView_File.Items(index).Text)
700
    '                On Error GoTo out
701
    '                'On Error Resume Next
702
    '            Else
703
    '                Me.Status_Main.Items(0).Text = folders_path + "\" + (Me.ListView_File.Items(index).Text)
704
    '                On Error GoTo out
705
    '            End If
706

    
707
    '            Dim infoReader As System.IO.FileInfo
708
    '            infoReader = My.Computer.FileSystem.GetFileInfo(Me.Status_Main.Items(0).Text)
709
    '            Me.Status_Main.Items(1).Text = " Created : " + infoReader.CreationTime.ToString + " " + infoReader.Attributes.ToString
710
    '            On Error GoTo out
711
    '            MsgBox(Me.Status_Main.Items(0).Text + " is processed")
712
    '            On Error GoTo out
713
    '        Next
714
    '        Exit Sub
715
    'out:
716
    '        MsgBox(Err.Description)
717
    'End Sub
718

    
719
    Private Function LoadAllDrawing() As DataTable
720

    
721

    
722
        SetListBoxItems(ListBox_Result, "도면정보 로드중....")
723

    
724
        Dim oDt As DataTable = Drawing_Dt()
725
        'Dim oDt As DataTable = Drawing_Dt()
726
        '_objPIDADrawing = CreateObject("PIDAutomation.Application")
727
        'For Each objDrawing In _objPIDADrawing.Drawings
728
        '    Dim sName As String = objDrawing.Attributes("Name").Value
729
        '    Dim sPath As String = objDrawing.Attributes("Path").Value
730
        '    Dim oAddRow As DataRow = oDt.NewRow()
731
        '    oAddRow("Name") = sName
732
        '    oAddRow("Path") = sPath
733
        '    oDt.Rows.Add(oAddRow)
734
        'Next
735
        Dim sHierarchy As String = My.Settings.Plant_Hierarchy
736

    
737

    
738
        Dim files() As String
739
        files = Directory.GetFiles(sHierarchy, "*.pid", SearchOption.AllDirectories)
740
        For Each FileName As String In files
741
            Dim sName As String = FileName
742
            Dim oAddRow As DataRow = oDt.NewRow()
743
            oAddRow("Name") = Path.GetFileNameWithoutExtension(sName)
744
            oAddRow("Path") = FileName
745
            oDt.Rows.Add(oAddRow)
746
            '  Console.WriteLine(FileName)
747
        Next
748

    
749

    
750

    
751
        'Dim datasource As LMADataSource
752
        'Dim objPIDAutoApp As Object
753
        'Dim objPIDADrawing As Object
754
        'Dim objDrawing As LMDrawing
755
        'Dim objDrawings As LMDrawings
756
        'objPIDAutoApp = CreateObject("PIDAutomation.Application")
757
        'objPIDAutoApp = GetObject(, "SmartPlantPID.Application")
758

    
759
        'datasource = CreateObject("Llama.LMADataSource", "")
760
        'Dim oObj As Object = Nothing
761
        'objDrawings = New LMDrawings
762
        'objDrawing = datasource.GetDrawing(oObj)
763

    
764
        'objDrawings.Collect(datasource)
765
        ''     objPIDAutoApp = GetObject(, "SmartPlantPID.Application") '// CreateObject("PIDAutomation.Application")
766
        'For Each objDrawing In objDrawings
767
        '    Dim sName As String = objDrawing.Attributes("Name").Value
768
        '    Dim sPath As String = objDrawing.Attributes("Path").Value
769
        '    Dim oAddRow As DataRow = oDt.NewRow()
770
        '    oAddRow("Name") = sName
771
        '    oAddRow("Path") = sHierarchy & "\" & sPath
772
        '    oDt.Rows.Add(oAddRow)
773
        'Next
774

    
775
        Return oDt
776
    End Function
777

    
778
    Private Function LoadAllDrawing2() As DataTable
779
        Dim datasource As LMADataSource
780
        Dim objPIDAutoApp As Object
781
        Dim objPIDADrawing As Object
782
        Dim objDrawing As Object 'Drawing
783
        'Dim objDrawing As LMDrawing
784
        'Dim objDrawings As LMDrawings
785

    
786
        datasource = New LMADataSource
787

    
788
        '    objDrawings = New LMDrawings
789
        'objDrawings.Collect(datasource)
790
        objPIDAutoApp = CreateObject("PIDAutomation.Application")
791

    
792
        For Each objDrawing In objPIDAutoApp.Drawings
793
            objDrawing.CloseDrawing(True)
794
        Next
795
        Try
796
            objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("UY1-K-2000_P1_300dpi_0321_TEST_1")
797
        Catch ex As Exception
798
            Process.Start("\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\Plant_Hierarchy\8121\8121-1\UY1-K-2000_P1_300dpi_0321_TEST_1.pid")
799
        End Try
800

    
801

    
802

    
803
        Dim sType As Type = objPIDAutoApp.GetType()
804
        Dim iCount As Integer = 0
805
        ' Dim sPath As String = "‪\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\Plant_Hierarchy\8121\8121-1\188943-8121-PR-DW-011001.pid"
806

    
807
        objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("1")
808

    
809
        For Each objDrawing In objPIDAutoApp.Drawings
810
            If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
811
                Try
812

    
813
                    Dim sName As String = objDrawing.Attributes("Name").Value
814

    
815
                    iCount = iCount + 1
816
                    If sName = "UY1-K-2000_P1_300dpi_0321_TEST_1" Then
817
                        objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(objDrawing.Attributes("Name"))
818
                        objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("\8121\8121-1\UY1-K-2000_P1_300dpi_0321_TEST_1.pid")
819
                        If Not objPIDADrawing Is Nothing Then
820
                            objPIDADrawing.CloseDrawing()
821
                        End If
822
                    End If
823

    
824

    
825
                Catch ex As Exception
826

    
827
                End Try
828

    
829
            End If
830
        Next
831
        objPIDAutoApp.Quit
832
        objPIDAutoApp = Nothing
833
        objPIDADrawing = Nothing
834
        objDrawing = Nothing
835
        '   objDrawings = Nothing
836
    End Function
837

    
838
    Dim _XMLList As ListView = New ListView()
839

    
840
    Private Sub ThreadTask()
841

    
842
    End Sub
843

    
844

    
845
    'Private Sub ThreadTask()
846

    
847

    
848
    '    If _XMLList.Items.Count > 0 Then
849

    
850
    '        Dim oDwg_Dt As DataTable = LoadAllDrawing()
851
    '        Dim iDwgCnt As Integer = 0
852
    '        Dim objPIDAutoApp As Object
853
    '        objPIDAutoApp = CreateObject("PIDAutomation.Application")
854

    
855

    
856
    '        Dim myList = DirectCast(Invoke(New GetListViewDelegate(AddressOf GetListViewItems), _XMLList), List(Of String))
857
    '        For i = 0 To myList.Count - 1
858

    
859
    '            Dim sDwgName As String = Path.GetFileNameWithoutExtension(myList(i))
860
    '            Txt_Status.Text = sDwgName & "..(" & i + 1 & "/" & myList.Count & ")"
861
    '            SetListBoxItems(ListBox_Result, Txt_Status.Text & " 처리중....")
862
    '            Dim sDwgNo As String = myList(i)
863
    '            Dim oDwgPath As String = ""
864
    '            oDwgPath = _selectFolderPath + "\" + sDwgNo
865

    
866
    '            Dim sPath As String = OpenDrawing(oDwg_Dt, sDwgName)
867
    '            If sPath <> "" Then
868

    
869
    '                Process.Start(sPath)
870

    
871
    '                Dim bCheckOpenDrawing As Boolean = False
872
    '                While (True)
873
    '                    bCheckOpenDrawing = CheckOpenDrawing()
874
    '                    If bCheckOpenDrawing = True Then
875
    '                        Exit While
876
    '                    Else
877
    '                        Thread.Sleep(2000)
878
    '                    End If
879
    '                End While
880

    
881
    '                If bCheckOpenDrawing Then
882
    '                    SetListBoxItems(ListBox_Result, sDwgName & " 도면 Open....")
883
    '                    Dim oPipe_Dt As DataTable = New DataTable() 'LoadPipeInXml(oDwgPath)
884

    
885
    '                    Dim oSymbol_Dt As DataTable = LoadSymbolInXml(oDwgPath)
886
    '                    Dim oTreeNode As New TreeNode  'SetTreeViewItems(Tree_Result, Tree_Result.Nodes, sDwgName, sDwgName)
887
    '                    'oTreeNode = Tree_Result.Nodes.Find(sDwgName, True)(0)
888
    '                    Dim action As Action = Sub()
889
    '                                               oTreeNode = Tree_Result.Nodes.Add(sDwgName, sDwgName)
890
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Instruments", "Instuments")
891
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Pipes", "Pipes")
892
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Valves", "Valves")
893
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Fittings", "Fittings")
894
    '                                               oTreeNode.ExpandAll()
895
    '                                           End Sub
896
    '                    Tree_Result.Invoke(action)
897

    
898

    
899
    '                    '    oTreeNode.Expand()
900
    '                    SetListBoxItems(ListBox_Result, sDwgName & " Auto converting 대기....")
901
    '                    AutoConverting(oPipe_Dt, oSymbol_Dt, oTreeNode)
902

    
903
    '                End If
904

    
905
    '            End If
906
    '            ''도면 생성
907
    '            'If CreateDwg(sDwgName) Then
908
    '            '    'AutoConverting
909

    
910
    '            'End If
911

    
912
    '        Next
913
    '    End If
914
    'End Sub
915

    
916

    
917
    Private Function CheckOpenDrawing() As Boolean
918
        Try
919

    
920
            Dim lobjDatasource As Object
921
            _Placement = CreateObject("Plaice.Placement", "")
922
            lobjDatasource = _Placement.PIDDataSource
923
            Return True
924
        Catch ex As Exception
925
            Return False
926
        End Try
927

    
928
    End Function
929

    
930

    
931
    Private Sub Btn_Convert_Click(sender As Object, e As EventArgs) Handles Btn_Convert.Click
932

    
933
        Main_Tab.SelectedIndex = 1
934
        ListBox_Result.Items.Clear()
935
        DataGrid_Result.DataSource = New DataTable()
936
        Me.ProgressBar_Status.Visible = True
937
            ProgressBar_Status.Maximum = 100
938
            ProgressBar_Status.Value = 0
939
        ' _selectFolderPath = Tree_XMLFiles.SelectedNode.FullPath.Replace("\\", "\")
940
        _Main_trd = New Thread(AddressOf ThreadTask)
941
        _Main_trd.IsBackground = True
942
        _Main_trd.Start()
943

    
944
    End Sub
945

    
946

    
947
    Private Function GetCheckList(ByVal listviewItem As ListViewItem)
948

    
949
    End Function
950

    
951
    Private Sub newThreadFunc(ByVal state As Object)
952

    
953
    End Sub
954

    
955
    Private Function OpenDrawing(ByVal oDt As DataTable, ByVal sDwgName As String) As String
956
        Dim oRows As DataRow() = oDt.Select("[Name] = '" & sDwgName & "'")
957
        Dim oPath As String = ""
958
        If oRows.Length > 0 Then
959
            oPath = oRows(0).Item("Path").ToString()
960
        End If
961
        Return oPath
962
    End Function
963

    
964

    
965
    Private Sub Btn_Setting_Click(sender As Object, e As EventArgs) Handles Btn_Setting.Click
966
        Dim oSettings As Settings = New Settings()
967
        oSettings.ShowDialog()
968
    End Sub
969

    
970
    Private Sub Btn_Stop_Click(sender As Object, e As EventArgs) Handles Btn_Stop.Click
971
        Try
972
            _Main_trd.Abort()
973
        Catch ex As Exception
974

    
975
        End Try
976
    End Sub
977

    
978
    Private Sub DropDown_File_Click(sender As Object, e As EventArgs) Handles DropDown_File.Click
979

    
980
    End Sub
981

    
982
    Private Sub TestLineToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles TestLineToolStripMenuItem.Click
983

    
984
        Dim objPlacement As New Placement
985
        'PipeLine 
986
        'Nominal diameter -fluidcode- tagseqno-piping material spec - insulation purpose
987
        Dim datasource As LMADataSource
988
        datasource = objPlacement.PIDDataSource
989
        Dim PipeRunLoc As String
990
        Dim objItem As LMAItem
991

    
992
        Dim objConnector As LMConnector
993
        Dim objInputs As PlaceRunInputs
994
        Dim objSymbol As LMSymbol
995
        Dim InstrumentLoc As String
996
        PipeRunLoc = "\Piping\Routing\Process Lines\Primary Piping.sym"
997
        objInputs = New PlaceRunInputs
998
        objInputs.AddPoint(0.1, 0.1)
999
        objInputs.AddPoint(0.2, 0.1)
1000
        objItem = objPlacement.PIDCreateItem(PipeRunLoc)
1001
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
1002
        Dim objPipeRun As LMPipeRun = datasource.GetPipeRun(objConnector.ModelItemID)
1003
        objPipeRun.Attributes("NominalDiameter").Value = "250 mm"
1004
        objPipeRun.Attributes("OperFluidCode").Value = "ADH"
1005
        objPipeRun.Attributes("TagSequenceNo").Value = "0026"
1006
        objPipeRun.Attributes("pipingmaterialsclass").Value = "NA1S"
1007
        objPipeRun.Attributes("InsulPurpose").Value = "H"
1008
        objPipeRun.Commit()
1009
        Dim twopoints(2) As Double
1010
        twopoints(1) = 0.12
1011
        twopoints(2) = 0.11
1012
        'Label
1013
        Dim labelName1 As String = "\Piping\Labels - Piping Segments\Line Number.sym"
1014
        Dim labelpersist As LMLabelPersist
1015

    
1016
        For Each representation In objPipeRun.Representations
1017
            If representation.RepresentationType = "Connector" Then
1018
                labelpersist = objPlacement.PIDPlaceLabel(labelName1,
1019
                twopoints,, 0, LabeledItem:=representation)
1020
            End If
1021
        Next
1022
        'labelpersist = objPlacement.PIDPlaceLabel(labelName1,
1023
        '  twopoints, LabeledItem:=objPipeRun.Representations.Nth(0))
1024
        'twopoints(1) = 0.17
1025
        'twopoints(2) = 0.1
1026
        'labelpersist = objPlacement.PIDPlaceLabel(labelName1,
1027
        '  twopoints, LabeledItem:=objPipeRun.Representations.Nth(0))
1028

    
1029

    
1030
        'Instrument
1031
        InstrumentLoc = "\Instrumentation\Off-Line\Without Implied Components\Single Function\Disc Single-Func Access in Prime Loc.sym"
1032
        objSymbol = objPlacement.PIDPlaceSymbol(InstrumentLoc, 0.15, 0.3, , 0)
1033

    
1034
        Dim objInstr As LMInstrument
1035
        objInstr = datasource.GetInstrument(objSymbol.ModelItemID)
1036
        objInstr.Attributes("MeasuredVariableCode").Value = "L"
1037
        objInstr.Attributes("InstrumentTypeModifier").Value = "G"
1038
        objInstr.Attributes("TagSuffix").Value = ""
1039
        objInstr.Attributes("TagSequenceNo").Value = "4003"
1040
        objInstr.Commit()
1041

    
1042
        objInputs = New PlaceRunInputs
1043
        objInputs.AddConnectorTarget(objConnector, 0.15, 0.1)
1044
        objInputs.AddPoint(0.15, 0.15)
1045
        objInputs.AddPoint(0.12, 0.15)
1046
        objInputs.AddPoint(0.12, 0.2)
1047
        objInputs.AddPoint(0.15, 0.2)
1048
        objInputs.AddSymbolTarget(objSymbol, 0.15, 0.3)
1049
        objItem = objPlacement.PIDCreateItem(PipeRunLoc)
1050

    
1051
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
1052
        objPipeRun = datasource.GetPipeRun(objConnector.ModelItemID)
1053
        twopoints(1) = 0.14
1054
        twopoints(2) = 0.22
1055

    
1056
        For Each representation In objPipeRun.Representations
1057
            If representation.RepresentationType = "Connector" Then
1058
                labelpersist = objPlacement.PIDPlaceLabel(labelName1,
1059
                twopoints,, 1.57, LabeledItem:=representation)
1060
            End If
1061
        Next
1062
        ' Measured Variable Code, Instr Type Modifier 
1063
        ' TagSeqNo, TagSuffix
1064

    
1065

    
1066
        'OPC
1067

    
1068

    
1069
        'Valve
1070

    
1071

    
1072

    
1073

    
1074

    
1075
    End Sub
1076

    
1077
    Private Sub ToolStripDropDownButton1_Click(sender As Object, e As EventArgs) Handles ToolStripDropDownButton1.Click
1078

    
1079
    End Sub
1080

    
1081
    Private Sub LoadXmlToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LoadXmlToolStripMenuItem.Click
1082
        Dim oOpen_Xml = New LoadXml()
1083
        oOpen_Xml = New LoadXml()
1084
        oOpen_Xml.ShowDialog()
1085
        _XMLList = oOpen_Xml.GetCheckList()
1086
        LoadXmlItem()
1087
    End Sub
1088

    
1089

    
1090
    Private Sub LoadXmlItem()
1091
        If Tree_Result.Nodes.Count > 0 Then
1092
            Tree_Result.Nodes(0).Nodes.Clear()
1093

    
1094
            For i = 0 To _XMLList.CheckedItems.Count - 1
1095
                Dim sDwgName As String = Path.GetFileNameWithoutExtension(_XMLList.CheckedItems(i).Text)
1096
                Dim sDwgPath As String = _XMLList.CheckedItems(i).Name
1097
                Dim oNode As TreeNode = Tree_Result.Nodes(0).Nodes.Add(sDwgPath, sDwgName, 15)
1098
                AddSymbolItem(sDwgPath, oNode)
1099
            Next
1100
            Tree_Result.Nodes(0).Expand()
1101
        End If
1102

    
1103
    End Sub
1104

    
1105
    ''' <summary>
1106
    '''  XML Tree 구조 생성 
1107
    ''' </summary>
1108
    ''' <param name="sDwgPath"></param>
1109
    Private Sub AddSymbolItem(ByVal sDwgPath As String, ByVal oParentNode As TreeNode)
1110
        Dim oDt As DataTable = LoadSymbolInXml(sDwgPath)
1111

    
1112
        'PipeLine 구분
1113

    
1114
        'Type구분
1115
        '  Dim oParentNodeName = oParentNode.Text
1116
        Dim oDistinct_Name_Dt As DataTable = oDt.DefaultView.ToTable(True, "Name")
1117
        'Name 별
1118
        For Each oNameRow In oDistinct_Name_Dt.Rows
1119
            Dim sName As String = oNameRow("Name").ToString()
1120
            Dim sNameKey As String = oParentNode.Text & "\" & sName
1121
            Dim oNameNode As TreeNode = oParentNode.Nodes.Add(sNameKey, sName)
1122
            Dim oSelectNameRows As DataRow() = oDt.Select("[Name] = '" & sName & "'")
1123

    
1124
            Dim oDistinct_Class_Dt As DataTable = oSelectNameRows.CopyToDataTable.DefaultView.ToTable(True, "Class")
1125
            'Class 별
1126
            For Each oClassRow In oDistinct_Class_Dt.Rows
1127

    
1128
                Dim sClass As String = oClassRow("Class").ToString()
1129
                If sClass.Contains("'") Then
1130
                    sClass = sClass.Replace("'", "''")
1131
                End If
1132
                Dim sClassKey As String = oNameNode.Name & "\" & sClass
1133
                Dim oClassNode As TreeNode = oNameNode.Nodes.Add(sClassKey, sClass)
1134

    
1135
                Dim oSelectClassRows As DataRow() = oSelectNameRows.CopyToDataTable.Select("[Class] = '" & sClass & "'")
1136
                'Item 별
1137

    
1138
                For Each oItemRow In oSelectClassRows
1139
                    Dim sItem As String = oItemRow("Item").ToString()
1140
                    Dim sItemKey As String = oItemRow("uid").ToString()
1141
                    Dim oItemName As TreeNode = oClassNode.Nodes.Add(sItemKey, sItem)
1142
                Next
1143

    
1144
            Next
1145

    
1146
        Next
1147

    
1148
    End Sub
1149

    
1150
    Private Sub Tree_Result_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles Tree_Result.AfterSelect
1151

    
1152
    End Sub
1153
    ''' <summary>
1154
    ''' Parent 노트 선택시 일괄 체크,해제
1155
    ''' </summary>
1156
    ''' <param name="sender"></param>
1157
    ''' <param name="e"></param>
1158
    Private Sub Tree_Result_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles Tree_Result.AfterCheck
1159
        If e.Node.Checked = True Then
1160
            For Each oNode As TreeNode In e.Node.Nodes
1161
                oNode.Checked = True
1162
            Next
1163
        Else
1164
            For Each oNode As TreeNode In e.Node.Nodes
1165
                oNode.Checked = False
1166
            Next
1167
        End If
1168
    End Sub
1169
End Class
1170

    
1171

    
1172
Public Class DrawingInfo
1173
    Public mDrawingName As String
1174
    Public mSpID As String
1175
    Public mPath As String
1176
End Class
1177

    
1178

    
1179

    
1180

    
1181