프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / SPPIDConverter / Main.vb @ a3dcb1a9

이력 | 보기 | 이력해설 | 다운로드 (90.3 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 _Mapping_DB As DataTable = New DataTable()
14
    Dim _Attribute_DB As DataTable = New DataTable()
15
    Dim _Placement As New Placement
16
    Dim _DWG_X = 0.84 '0.695 '1 '
17
    Dim _DWG_Y = 0.594 '0.585 '0.8 '
18

    
19
    Dim _IMG_X = 0
20
    Dim _IMG_Y = 0
21

    
22
    Dim _Unit As String
23

    
24
    'Drawing 전역변수
25
    Dim _objPIDADrawing As Object
26
    '현재선택한 폴더경로
27
    Dim _selectFolderPath As String
28

    
29
    Private _Main_trd As Thread
30

    
31
    Private _DrawingsList As List(Of Drawing)
32

    
33

    
34
    Private _iPipeLineNocnt As Integer
35
    Private _iPipecnt As Integer
36
    Private _iFittingcnt As Integer
37
    Private _iValvecnt As Integer
38
    Private _iInstrumentcnt As Integer
39
    Private _iEquipmentcnt As Integer
40
    Private _iNozzlecnt As Integer
41

    
42

    
43
    Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
44

    
45
        If My.Settings.DBPath <> "" And My.Settings.Plant_Hierarchy <> "" Then
46
            Dim sDBPath As String = My.Settings.DBPath
47
            _Mapping_DB = Load_DB(sDBPath, _DB_TABLE_MAPPING)
48
            _Attribute_DB = Load_DB(sDBPath, _DB_TABLE_ATTRIBUTE)
49
            'TestPID()
50
            'OpenDrawing()
51
        Else
52
            MessageBox.Show("설정값을 먼저 확인해주세요")
53
        End If
54
    End Sub
55

    
56
    Public Function GetDrawingInfo(ByVal errorList As ArrayList)
57
        Dim ds As Llama.LMADataSource
58
        ds = New Llama.LMADataSource
59
        Dim lmaItem As Llama.LMAItem
60

    
61
        For i = 0 To errorList.Count - 1
62
            lmaItem = ds.GetModelItem(errorList.Item(i).m_strSPID()).AsLMAItem
63
            Dim drawingInfo As DrawingInfo
64
            drawingInfo = GetDrawingName(lmaItem.ItemType, lmaItem.Id)
65
            errorList.Item(i).m_LMAItem = lmaItem
66
            errorList.Item(i).m_strDrawingName = drawingInfo.mDrawingName
67
            errorList.Item(i).m_strDrawingPath = drawingInfo.mPath
68
        Next
69
    End Function
70
    Private mDataSource As Object
71

    
72
    'Public Sub New()
73

    
74
    '    '  mDataSource.ProjectNumber = m_Information.InfoSite.SiteName
75
    '    '   mDataSource.SiteNode = m_Information.InfoProject.ProjectINI
76
    '    'm_Information = SPPIDClass.Information.GetInstance()
77

    
78
    '    'If m_Information.InfoProject.ProjectVersion = SPPIDClass.InfoProject.SPPID_43 Then
79
    '    '    'SPPID4.3용
80
    '    '    mDataSource.ProjectNumber = m_Information.InfoSite.SiteName
81
    '    'Else
82
    '    '    'SPPID2007, SPPID2009용
83
    '    '    mDataSource.ProjectNumber = m_Information.InfoSite.SiteName & "!" & m_Information.InfoSite.SiteName
84
    '    'End If
85

    
86
    '    '  mDataSource.SiteNode = m_Information.InfoProject.ProjectINI
87
    '    '  mDataSource.ProjectNumber = m_Information.InfoSite.SiteName & "!" & m_Information.InfoSite.SiteName
88
    '    '#If LATE_BINDING Then
89
    '    '        mInstruments = CreateObject("Llama.LMInstruments", "")
90
    '    '        mPipingComps = CreateObject("Llama.LMPipingComps", "")
91
    '    '        mVessels = CreateObject("Llama.LMVessels", "")
92
    '    '        mDrawings = CreateObject("Llama.LMDrawings", "")
93
    '    '        mEquipments = CreateObject("Llama.LMEquipments", "")
94
    '    '        mExchangers = CreateObject("Llama.LMExchangers", "")
95
    '    '        mMechanicals = CreateObject("Llama.LMMechanicals", "")
96
    '    '        mNozzles = CreateObject("Llama.LMNozzles", "")
97
    '    '        mPipeRuns = CreateObject("Llama.LMPipeRuns", "")
98
    '    '        mEquipmentOthers = CreateObject("Llama.LMEquipmentOthers", "")
99
    '    '#Else
100
    '    '        mInstruments = New Llama.LMInstruments
101
    '    '        mPipingComps = New Llama.LMPipingComps
102
    '    '        mVessels = New Llama.LMVessels
103
    '    '        mDrawings = New Llama.LMDrawings
104
    '    '        mEquipments = New Llama.LMEquipments
105
    '    '        mExchangers = New Llama.LMExchangers
106
    '    '        mMechanicals = New Llama.LMMechanicals
107
    '    '        mNozzles = New Llama.LMNozzles
108
    '    '        mPipeRuns = New Llama.LMPipeRuns
109
    '    '        mEquipmentOthers = New Llama.LMEquipmentOthers
110
    '    '#End If
111
    'End Sub
112

    
113
    Function OpenDrawing()
114
        Dim datasource As LMADataSource
115
        Dim objPIDAutoApp As Object
116
        Dim objPIDADrawing As Object
117
        Dim objDrawing As LMDrawing
118
        Dim objDrawings As LMDrawings
119
        datasource = New Llama.LMADataSource
120

    
121
        objPIDAutoApp = CreateObject("PIDAutomation.Application")
122
        objDrawings = New Llama.LMDrawings 'New LMDrawings
123

    
124
        datasource.SiteNode = " \\desktop-9vlq0dp\Test03Site\smartplantv4.ini"
125
        datasource.ProjectNumber = "SBR_PBR"
126
        objDrawings.Collect(datasource)
127

    
128

    
129
        For Each objDrawing In objDrawings
130
            If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
131
                objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(objDrawing.Attributes("Name"))
132
                If Not objPIDADrawing Is Nothing Then
133
                    'MsgBox "Drawing " & objDrawing.Attributes("Name").Value & " is opened!"
134
                    objPIDADrawing.CloseDrawing
135
                End If
136
            End If
137
        Next
138
        objPIDAutoApp.Quit
139
        objPIDAutoApp = Nothing
140
        objPIDADrawing = Nothing
141
        objDrawing = Nothing
142
        objDrawings = Nothing
143
    End Function
144

    
145

    
146
    Public Function GetDrawingName(ByVal itemType As String, ByVal itemName As String) As DrawingInfo
147

    
148
        Dim objFilter As Object
149
        objFilter = CreateObject("Llama.LMAFilter", "")
150

    
151
        Dim drawingInfo As DrawingInfo
152
        drawingInfo = New DrawingInfo
153

    
154
        objFilter.Criteria.AddNew("FirstOne")
155
        objFilter.Criteria.Item("FirstOne").SourceAttributeName = "SP_ID"
156
        objFilter.Critedkria.Item("FirstOne").ValueAttribute = itemName
157

    
158
        objFilter.Criteria.Item("FirstOne").Operator = "="
159
        objFilter.Criteria.AddNew("SecondOne")
160
        objFilter.Criteria.Item("SecondOne").SourceAttributeName = "ItemStatus"
161
        objFilter.Criteria.Item("SecondOne").ValueAttribute = 1
162
        objFilter.Criteria.Item("SecondOne").Operator = "="
163
        objFilter.Criteria.Item("SecondOne").Conjunctive = -1
164
        objFilter.ItemType = itemType
165

    
166
        Dim PlantItems As Object
167
        PlantItems = CreateObject("Llama.LMPlantItems", "")
168
        PlantItems.Collect(mDataSource, Filter:=objFilter)
169

    
170
        If PlantItems.Count = 0 Then
171
            drawingInfo.mSpID = "PlantStockpile"
172
        End If
173

    
174
        For Each PlantItem In PlantItems
175

    
176
            'If Not PlantItem.Representations.Nth(1).DrawingID.Value.ToString().Equals("0") Then
177
            Try
178
                drawingInfo.mDrawingName = PlantItem.Representations.Nth(1).DrawingObject.Attributes("Name").Value
179
                drawingInfo.mSpID = PlantItem.Representations.Nth(1).DrawingID
180
                drawingInfo.mPath = PlantItem.Representations.Nth(1).DrawingObject.Attributes("Path").Value
181
                Debug.WriteLine("DrawingName : " & drawingInfo.mDrawingName & ", SPID : " & drawingInfo.mSpID & ", Path : " & drawingInfo.mPath)
182
            Catch ex As Exception
183

    
184
            End Try
185

    
186
            'End If
187

    
188
        Next
189

    
190
        Return drawingInfo
191

    
192
    End Function
193

    
194
    Private Sub TestPID()
195

    
196
        Try
197
            Const CONST_SPID_OPC As String = "426E89964A7F49208AD79E1F320DA251"
198
            Dim datasource As LMADataSource
199
            Dim objPIDAutoApp As Object
200
            Dim objPIDADrawing As Object
201
            Dim objDrawing As LMDrawing
202
            Dim objDrawings As LMDrawings
203
            datasource = New LMADataSource
204
            Dim objOPC As LMOPC
205
            Dim objpairOPC As LMOPC
206
            objOPC = datasource.GetOPC(CONST_SPID_OPC)
207
            objpairOPC = objOPC.pairedWithOPCObject
208

    
209
            Dim oObj As Object = Nothing
210
            objDrawing = datasource.GetDrawing(oObj)
211
            objDrawings = New LMDrawings
212
            objDrawings.Collect(datasource)
213
            objPIDAutoApp = GetObject(, "SmartPlantPID.Application") '// CreateObject("PIDAutomation.Application")
214
            For Each objDrawing In objDrawings
215
                If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
216
                    objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(objDrawing.Attributes("Name"))
217
                    If Not objPIDADrawing Is Nothing Then
218
                        MessageBox.Show("Drawing " & objDrawing.Attributes("Name").Value & " is opened!")
219
                        objPIDADrawing.CloseDrawing
220
                    End If
221
                End If
222
            Next
223
            objPIDAutoApp.Quit
224
            objPIDAutoApp = Nothing
225
            objPIDADrawing = Nothing
226
            objDrawing = Nothing
227
            objDrawings = Nothing
228
        Catch ex As Exception
229

    
230
        End Try
231

    
232

    
233

    
234
    End Sub
235
    Public Function SetActiveSiteFromConfigInfo(ByVal strActiveSite As String) As Boolean
236

    
237
        On Error GoTo errHandler
238
        Dim objConfigInfo As Object 'interopigrConfigInfo412.igrConfigInfo
239
        objConfigInfo = CreateObject("interopigrConfigInfo412.igrConfigInfo", "")
240
        If Not objConfigInfo Is Nothing Then
241
            objConfigInfo.ApplicationName = "SmartPlantManager"
242
            objConfigInfo.SetConfigString(3, "SmartPlant Manager", "SiteServer", strActiveSite)
243
            SetActiveSiteFromConfigInfo = True
244
        End If
245
        objConfigInfo = Nothing
246

    
247
        Exit Function
248

    
249
errHandler:
250
        '    LogAndRaiseError ModuleName & "::GetConfigInfo "
251
    End Function
252

    
253
    Private Function CreateDwg(ByVal oDwgName As String) As Boolean
254
        Dim objPIDADrawing As Object = Nothing
255
        Dim objPIDAutoApp As Object = Nothing
256
        Dim datasource As LMADataSource = Nothing
257
        Try
258
            Dim DrawingNumber As String
259
            Dim DrawingName As String
260
            Dim sPlantGroupName As String = "Test"
261
            Dim sTemplateName As String = "\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\P&ID Reference Data\Template Files\Gazprom Project.pid"
262
            Dim objDrawing As LMDrawing
263
            Dim objDrawings As LMDrawings
264
            objDrawings = New LMDrawings
265
            datasource = New LMADataSource
266
            Debug.Print(datasource.ProjectNumber)
267
            Debug.Print(datasource.SiteNode)
268
            Debug.Print(datasource.IsSatellite)
269
            Debug.Print(datasource.GetSystemEditingToolbarSetting)
270
            objDrawings.Collect(datasource)
271
            Dim sPath As String = "‪\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\Plant_Hierarchy\8121\8121-1\188943-8121-PR-DW-011001.pid"
272
            objPIDAutoApp = CreateObject("PIDAutomation.Application")
273
            For Each objDrawing In objDrawings
274
                If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
275
                    objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(sPath)
276
                    If Not objPIDADrawing Is Nothing Then
277

    
278
                        objPIDADrawing.CloseDrawing
279
                    End If
280
                End If
281
            Next
282

    
283
            Dim extension As String = Path.GetExtension(oDwgName)
284
            oDwgName = oDwgName.Replace(extension, "")
285

    
286
            objPIDAutoApp = CreateObject("PIDAutomation.Application")
287

    
288
            'For Each objDrawing In objPIDAutoApp.Drawings
289
            '    objDrawing.CloseDrawing(True)
290
            'Next
291

    
292
            objPIDAutoApp.Drawings.OpenDrawing(oDwgName + ".pid")
293

    
294
            objPIDAutoApp.ActiveWindow.Fit()
295

    
296
            Return True
297
        Catch ex As Exception
298
            If objPIDADrawing IsNot Nothing Then
299
                objPIDADrawing.CloseDrawing
300
            End If
301
            If objPIDAutoApp IsNot Nothing Then
302
                objPIDAutoApp.Quit
303
            End If
304
            datasource = Nothing
305
            objPIDAutoApp = Nothing
306
            objPIDADrawing = Nothing
307
            Return False
308
        End Try
309
        If objPIDADrawing IsNot Nothing Then
310
            objPIDADrawing.CloseDrawing
311
        End If
312

    
313
    End Function
314

    
315

    
316
    Private Function GetDataFromMappingDB(ByVal sSymbolName As String, ByVal sColumn As String) As String
317
        Dim sValue As String = ""
318
        If _Mapping_DB.Rows.Count > 0 Then
319
            Dim oSelectRow() As DataRow = _Mapping_DB.Select("[pid_symbolname] = '" + sSymbolName + "'")
320
            If oSelectRow.Length = 1 Then
321
                sValue = oSelectRow(0).Item(sColumn).ToString()
322
            End If
323
        End If
324
        Return sValue
325
    End Function
326

    
327
    Private Function GetAttributeMapping(ByVal sAttributeName As String, ByVal sColumn As String) As String
328
        Dim sSPPIDAttribute As String = ""
329
        If _Attribute_DB.Rows.Count > 0 Then
330
            Dim oSelectRow() As DataRow = _Attribute_DB.Select("[pid_attribute] = '" + sAttributeName + "'")
331
            If oSelectRow.Length = 1 Then
332
                sSPPIDAttribute = oSelectRow(0).Item(sColumn).ToString()
333
            End If
334
        End If
335
        Return sSPPIDAttribute
336
    End Function
337

    
338
    '  Dim _TempSymbolDt As DataTable = Symbol_Dt()
339

    
340

    
341
    Private Function LoadSymbolInXml(ByVal sXmlPath As String) As Drawing
342
        ''  _TempSymbolDt = Symbol_Dt()
343
        Dim CDrawing As Drawing = New Drawing()
344
        Dim oDt As DataTable = LoadSymbol_DT()
345
        Dim oElement As XElement = XElement.Load(sXmlPath)
346

    
347
        If oElement IsNot Nothing Then
348
            CDrawing.DwgName = oElement.Element(_XML_DWGNAME).Value
349
            CDrawing.Size = oElement.Element(_XML_DWGSIZE).Value
350
            SplitLocation(CDrawing.Size, _IMG_X, _IMG_Y)
351
            CDrawing.Unit = oElement.Element(_XML_UNIT).Value
352

    
353
            Dim oLineno_list As New List(Of Line_no)
354
            Dim oEqp_list As New List(Of Eqp_no)
355

    
356
            For Each oLineNo As Object In oElement.Elements(_XML_CATEGORY_LINENO)
357
                Dim CLineNo As Line_no = New Line_no()
358
                Try
359
                    CLineNo.Uid = oLineNo.Element(_XML_LINENO_UID).Value
360
                    CLineNo.Text = oLineNo.Element(_XML_LINENO_TEXT).Value
361
                    CLineNo.Location = oLineNo.Element(_XML_LINENO_LOCATION).Value
362
                    CLineNo.Angle = oLineNo.Element(_XML_LINENO_ANGLE).Value
363
                    CLineNo.SystemPath = GetDataFromMappingDB(_XML_CATEGORY_LINENO, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
364
                Catch ex As Exception
365
                    'CLineNo.Text = "PipeLineNo"
366
                    'CLineNo.Uid = "PipeLineNo"
367
                End Try
368

    
369

    
370
                Dim oLine_Dt As DataTable = Line_Dt()
371
                Dim oSymbol_Dt As DataTable = Symbol_Dt()
372
                Dim oAttribute_Dt As DataTable = Attribute_Dt()
373

    
374
                For Each oRun As Object In oLineNo.Elements(_XML_CATEGORY_RUN)
375
                    For Each oLine As Object In oRun.Elements(_XML_CATEGORY_LINE)
376
                        Dim oAddrow As DataRow = oLine_Dt.NewRow()
377
                        Dim oEleObj As XElement
378
                        Dim sUid As String
379
                        Dim sStartpoint As String
380
                        Dim sEndpoint As String
381
                        oEleObj = oLine.Element(_XML_LINE_UID)
382
                        sUid = oEleObj.Value
383
                        oEleObj = oLine.Element(_XML_LINE_STARTPOINT)
384
                        sStartpoint = oEleObj.Value
385
                        oEleObj = oLine.Element(_XML_LINE_ENDPOINT)
386
                        sEndpoint = oEleObj.Value
387

    
388
                        oAddrow(_XML_LINE_UID) = sUid
389
                        oAddrow(_XML_LINE_STARTPOINT) = sStartpoint
390
                        oAddrow(_XML_LINE_ENDPOINT) = sEndpoint
391
                        oAddrow(_XML_LINE_SYSTEMPATH) = GetDataFromMappingDB(_XML_CATEGORY_LINE, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
392
                        oLine_Dt.Rows.Add(oAddrow)
393
                    Next
394

    
395
                    For Each oSymbol As Object In oRun.Elements(_XML_CATEGORY_SYMBOL)
396
                        Dim oAddrow As DataRow = oSymbol_Dt.NewRow()
397
                        Dim oEleObj As XElement
398
                        Dim sUid As String
399
                        Dim sName As String
400
                        Dim sLocation As String
401
                        Dim sSize As String
402
                        Dim sAngle As String
403
                        Dim sOriginalPoint As String = ""
404
                        oEleObj = oSymbol.Element(_XML_SYMBOL_UID)
405
                        sUid = oEleObj.Value
406
                        oEleObj = oSymbol.Element(_XML_SYMBOL_NAME)
407
                        sName = oEleObj.Value
408
                        oEleObj = oSymbol.Element(_XML_SYMBOL_LOCATION)
409
                        sLocation = oEleObj.Value
410
                        oEleObj = oSymbol.Element(_XML_SYMBOL_SIZE)
411
                        sSize = oEleObj.Value
412
                        oEleObj = oSymbol.Element(_XML_SYMBOL_ANGLE)
413
                        sAngle = oEleObj.Value
414
                        Try
415
                            oEleObj = oSymbol.Element(_XML_SYMBOL_ORIGINALPOINT)
416
                            sOriginalPoint = oEleObj.Value
417
                        Catch ex As Exception
418

    
419
                        End Try
420

    
421
                        oAddrow(_XML_SYMBOL_UID) = sUid
422
                        oAddrow(_XML_SYMBOL_NAME) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYMBOLNAME)
423
                        oAddrow(_XML_SYMBOL_LOCATION) = sLocation
424
                        oAddrow(_XML_SYMBOL_SIZE) = sSize
425
                        oAddrow(_XML_SYMBOL_ANGLE) = sAngle
426
                        oAddrow(_XML_SYMBOL_SYSTEMPATH) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
427
                        oAddrow(_XML_SYMBOL_TYPE) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_COMPTPYE)
428
                        oAddrow(_XML_SYMBOL_ORIGINALPOINT) = sOriginalPoint
429

    
430
                        oSymbol_Dt.Rows.Add(oAddrow)
431
                    Next
432

    
433
                    For Each oAtrribute As Object In oRun.Elements(_XML_CATEGORY_ATTRIBUTE)
434

    
435
                        Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
436
                        Dim oEleObj As XElement
437
                        Dim sUid As String
438
                        Dim sName As String
439
                        Dim sValue As String
440

    
441
                        oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
442
                        sUid = oEleObj.Value
443
                        oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
444
                        sName = oEleObj.Value
445
                        oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
446
                        sValue = oEleObj.Value
447

    
448
                        oAddrow(_XML_ATTRIBUTE_UID) = sUid
449
                        oAddrow(_XML_ATTRIBUTE_NAME) = sName
450
                        oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
451
                        oAttribute_Dt.Rows.Add(oAddrow)
452
                    Next
453

    
454
                Next
455
                'Line No Attribute
456
                For Each oAtrribute As Object In oLineNo.Elements(_XML_CATEGORY_ATTRIBUTE)
457

    
458
                    Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
459
                    Dim oEleObj As XElement
460
                    Dim sUid As String
461
                    Dim sName As String
462
                    Dim sValue As String
463

    
464
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
465
                    sUid = oEleObj.Value
466
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
467
                    sName = oEleObj.Value
468
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
469
                    sValue = oEleObj.Value
470

    
471
                    oAddrow(_XML_ATTRIBUTE_UID) = sUid
472
                    oAddrow(_XML_ATTRIBUTE_NAME) = sName
473
                    oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
474
                    oAttribute_Dt.Rows.Add(oAddrow)
475
                Next
476

    
477

    
478
                CLineNo.Dt_Line = oLine_Dt
479
                CLineNo.Dt_Symbol = oSymbol_Dt
480
                CLineNo.Dt_Attribute = oAttribute_Dt
481
                oLineno_list.Add(CLineNo)
482
                'For Each oSymbol As Object In oElement.Elements(_XML_CATEGORY_SYMBOL)
483
                '    Dim oAddrow As DataRow = _TempSymbolDt.NewRow()
484
                '    Dim oEleObj As XElement
485
                '    Dim sUid As String
486
                '    Dim sName As String
487
                '    Dim sLocation As String
488
                '    Dim sSize As String
489
                '    Dim sAngle As String
490
                '    Dim sOriginalPoint As String = ""
491
                '    oEleObj = oSymbol.Element(_XML_SYMBOL_UID)
492
                '    sUid = oEleObj.Value
493
                '    oEleObj = oSymbol.Element(_XML_SYMBOL_NAME)
494
                '    sName = oEleObj.Value
495
                '    oEleObj = oSymbol.Element(_XML_SYMBOL_LOCATION)
496
                '    sLocation = oEleObj.Value
497
                '    oEleObj = oSymbol.Element(_XML_SYMBOL_SIZE)
498
                '    sSize = oEleObj.Value
499
                '    oEleObj = oSymbol.Element(_XML_SYMBOL_ANGLE)
500
                '    sAngle = oEleObj.Value
501
                '    Try
502
                '        oEleObj = oSymbol.Element(_XML_SYMBOL_ORIGINALPOINT)
503
                '        sOriginalPoint = oEleObj.Value
504
                '    Catch ex As Exception
505

    
506
                '    End Try
507
                '    oAddrow(_XML_SYMBOL_UID) = sUid
508
                '    oAddrow(_XML_SYMBOL_NAME) = sName
509
                '    oAddrow(_XML_SYMBOL_LOCATION) = sLocation
510
                '    oAddrow(_XML_SYMBOL_SIZE) = sSize
511
                '    oAddrow(_XML_SYMBOL_ANGLE) = sAngle
512
                '    oAddrow(_XML_SYMBOL_SYSTEMPATH) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
513
                '    oAddrow(_XML_SYMBOL_TYPE) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_COMPTPYE)
514
                '    oAddrow(_XML_SYMBOL_ORIGINALPOINT) = sOriginalPoint
515
                '    _TempSymbolDt.Rows.Add(oAddrow)
516
                'Next
517

    
518
            Next
519

    
520

    
521

    
522
                For Each oEqpNo As Object In oElement.Elements(_XML_CATEGORY_EQUIPMENT)
523
                Dim CEqp_no As Eqp_no = New Eqp_no()
524
                'CEqp_no.Uid = oEqpNo.Element(_XML_EQP_UID).Value
525
                'CEqp_no.Text = oEqpNo.Element(_XML_EQP_TEXT).Value
526
                'CEqp_no.Location = oEqpNo.Element(_XML_EQP_LOCATION).Value
527
                'CEqp_no.Angle = oEqpNo.Element(_XML_EQP_ANGLE).Value
528
                'CEqp_no.SystemPath = GetDataFromMappingDB(_XML_CATEGORY_EQUIPMENT, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
529

    
530
                Dim oSymbol_Dt As DataTable = Symbol_Dt()
531
                Dim oAttribute_Dt As DataTable = Attribute_Dt()
532

    
533

    
534
                For Each oSymbol As Object In oEqpNo.Elements(_XML_CATEGORY_SYMBOL)
535
                    Dim oAddrow As DataRow = oSymbol_Dt.NewRow()
536
                    Dim oEleObj As XElement
537
                    Dim sUid As String
538
                    Dim sName As String
539
                    Dim sLocation As String
540
                    Dim sSize As String
541
                    Dim sAngle As String
542
                    Dim sOriginalPoint As String = ""
543
                    oEleObj = oSymbol.Element(_XML_SYMBOL_UID)
544
                    sUid = oEleObj.Value
545
                    oEleObj = oSymbol.Element(_XML_SYMBOL_NAME)
546
                    sName = oEleObj.Value
547
                    oEleObj = oSymbol.Element(_XML_SYMBOL_LOCATION)
548
                    sLocation = oEleObj.Value
549
                    oEleObj = oSymbol.Element(_XML_SYMBOL_SIZE)
550
                    sSize = oEleObj.Value
551
                    oEleObj = oSymbol.Element(_XML_SYMBOL_ANGLE)
552
                    sAngle = oEleObj.Value
553
                    Try
554
                        oEleObj = oSymbol.Element(_XML_SYMBOL_ORIGINALPOINT)
555
                        sOriginalPoint = oEleObj.Value
556
                    Catch ex As Exception
557

    
558
                    End Try
559

    
560

    
561

    
562
                    oAddrow(_XML_SYMBOL_UID) = sUid
563
                    oAddrow(_XML_SYMBOL_NAME) = sName
564
                    oAddrow(_XML_SYMBOL_LOCATION) = sLocation
565
                    oAddrow(_XML_SYMBOL_SIZE) = sSize
566
                    oAddrow(_XML_SYMBOL_ANGLE) = sAngle
567
                    oAddrow(_XML_SYMBOL_SYSTEMPATH) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
568
                    oAddrow(_XML_SYMBOL_TYPE) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_COMPTPYE)
569
                    oAddrow(_XML_SYMBOL_ORIGINALPOINT) = sOriginalPoint
570

    
571
                    oSymbol_Dt.Rows.Add(oAddrow)
572
                Next
573

    
574
                For Each oAtrribute As Object In oEqpNo.Elements(_XML_CATEGORY_ATTRIBUTE)
575

    
576
                    Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
577
                    Dim oEleObj As XElement
578
                    Dim sUid As String
579
                    Dim sName As String
580
                    Dim sValue As String
581

    
582
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
583
                    sUid = oEleObj.Value
584
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
585
                    sName = oEleObj.Value
586
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
587
                    sValue = oEleObj.Value
588

    
589
                    oAddrow(_XML_ATTRIBUTE_UID) = sUid
590
                    oAddrow(_XML_ATTRIBUTE_NAME) = sName
591
                    oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
592
                    oAttribute_Dt.Rows.Add(oAddrow)
593
                Next
594

    
595
                CEqp_no.Dt_Equipment = oSymbol_Dt
596
                CEqp_no.Dt_Attribute = oAttribute_Dt
597
                oEqp_list.Add(CEqp_no)
598

    
599

    
600
            Next
601

    
602
            CDrawing.Line_nos = oLineno_list
603
            CDrawing.Eqp_nos = oEqp_list
604
        End If
605
        Return CDrawing
606
    End Function
607

    
608

    
609

    
610
    'Private Function LoadPipeInXml(ByVal sXmlPath As String) As DataTable
611
    '    Try
612
    '        Dim oDt As DataTable = LoadPipe_DT()
613
    '        Dim oElement As XElement = XElement.Load(sXmlPath)
614
    '        If oElement IsNot Nothing Then
615
    '            Dim DWGElement As XElement = oElement.Element("DWGNAME")
616
    '            Dim DWGNAME = DWGElement.Value
617
    '            Dim sXY As XElement = oElement.Element("SIZE")
618
    '            Dim sSize = sXY.Value
619
    '            Dim oSplitDWGPos As String() = sSize.Split(", ")
620

    
621
    '            If IsNumeric(oSplitDWGPos(0)) Then
622
    '                _IMG_X = Double.Parse(oSplitDWGPos(0))
623
    '            End If
624
    '            If IsNumeric(oSplitDWGPos(1)) Then
625
    '                _IMG_Y = Double.Parse(oSplitDWGPos(1))
626
    '            End If
627

    
628
    '            For Each pipes As Object In oElement.Elements("IMGLINES")
629
    '                For Each pipe As Object In pipes.Elements("IMGLINE")
630
    '                    Dim oAddrow As DataRow = oDt.NewRow()
631
    '                    Dim oObj As XElement = pipe.Element("ITEM")
632
    '                    Dim oItem = oObj.Value
633
    '                    ' Dim oSymbolPath As String = "\" + oSymbol + "\" + oClass + "\" + oType + "\" + oItem + ".sym"
634
    '                    Dim oSymbolPath As String = GetSystemPathFromMappingDB(oItem)
635
    '                    oObj = pipe.Element("START")
636
    '                    Dim oStartPoint = oObj.Value
637
    '                    Dim oSplitPos As String() = oStartPoint.Split(", ")
638
    '                    Dim oStartpos_X As Double = 0.0
639
    '                    Dim oStartpos_Y As Double = 0.0
640
    '                    If IsNumeric(oSplitPos(0)) Then
641
    '                        oStartpos_X = Double.Parse(oSplitPos(0))
642
    '                    End If
643
    '                    If IsNumeric(oSplitPos(1)) Then
644
    '                        oStartpos_Y = Double.Parse(oSplitPos(1))
645
    '                    End If
646

    
647
    '                    ConvertPoint(oStartpos_X, oStartpos_Y, _DWG_X, _DWG_Y)
648
    '                    oObj = pipe.Element("End")
649
    '                    Dim oEndPoint = oObj.Value
650
    '                    oSplitPos = oEndPoint.Split(", ")
651
    '                    Dim oEndpos_X As Double = 0.0
652
    '                    Dim oEndpos_Y As Double = 0.0
653
    '                    If IsNumeric(oSplitPos(0)) Then
654
    '                        oEndpos_X = Double.Parse(oSplitPos(0))
655
    '                    End If
656
    '                    If IsNumeric(oSplitPos(1)) Then
657
    '                        oEndpos_Y = Double.Parse(oSplitPos(1))
658
    '                    End If
659
    '                    ConvertPoint(oEndpos_X, oEndpos_Y, _DWG_X, _DWG_Y)
660

    
661
    '                    oAddrow("start_x") = oStartpos_X '+ 0.05
662
    '                    oAddrow("start_y") = oStartpos_Y
663
    '                    oAddrow("end_x") = oEndpos_X
664
    '                    oAddrow("end_y") = oEndpos_Y
665
    '                    oAddrow("SystemPath") = oSymbolPath
666
    '                    oDt.Rows.Add(oAddrow)
667
    '                Next
668
    '            Next
669

    
670
    '        End If
671

    
672

    
673
    '        Return oDt
674
    '    Catch ex As Exception
675
    '        Return Nothing
676
    '    End Try
677
    'End Function
678

    
679

    
680
    Private Sub ConvertPointByImage(ByRef dX As Double, ByRef dY As Double, ByVal dDwgX As Double, ByVal dDwgY As Double)
681

    
682
        Dim calcx As Double = 0
683
        Dim calcy As Double = 0
684
        calcx = (dX * _DWG_X) / dDwgX 'Math.Round((dX * _DWG_X) / dDwgX, 2)
685
        calcy = _DWG_Y - ((dY * _DWG_Y) / dDwgY) '_DWG_Y - Math.Round((dY * _DWG_Y) / dDwgY, 2)
686
        dX = calcx
687
        dY = calcy
688
    End Sub
689

    
690

    
691
    '@brief Convert To SPPID
692
    '@author : Gyusu Park
693
    '@date : 2018-04-10
694
    '@history:
695

    
696
    Private Sub SplitLocation(ByVal sLocation As String, ByRef dX As Double, ByRef dY As Double)
697

    
698
        Dim opointstr As String() = Split(sLocation, ",")
699
        If (opointstr.Length > 1) Then
700
            If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
701
                dX = opointstr(0)
702
                dY = opointstr(1)
703
            End If
704
        End If
705

    
706
    End Sub
707

    
708

    
709

    
710

    
711

    
712

    
713
    Private Function AutoConverting(ByVal oPipe_Dt As DataTable, ByVal oSymbol_Dt As DataTable, ByVal oTreeNode As TreeNode) As Boolean
714
        Dim iTotalCount As Double = oPipe_Dt.Rows.Count + oSymbol_Dt.Rows.Count
715
        Dim iSymbolcount As Double = 0
716

    
717
        Dim lobjDatasource As Object = _Placement.PIDDataSource
718

    
719
        ' lobjDatasource.BeginTransaction()
720
        '  datasource = objPlacement.PIDDataSource
721
        'Dim iPipecnt As Integer = 0
722
        SetListBoxItems(ListBox_Result, " Auto converting 시작....")
723

    
724
        Dim iPipeCnt As Integer = 0
725
        If oPipe_Dt IsNot Nothing Then
726
            For Each oRow As DataRow In oPipe_Dt.Rows
727
                Dim oposition As String = oRow("position").ToString()
728
                Dim oSymbol As String = oRow("SystemPath").ToString()
729

    
730
                Dim objConnector As LMConnector
731
                Dim objInputs As PlaceRunInputs
732
                objInputs = New PlaceRunInputs
733
                Dim oSplitStr As String() = Split(oposition, " ")
734
                For Each sposition As String In oSplitStr
735
                    Dim opointstr As String() = Split(sposition, ", ")
736

    
737
                    If (opointstr.Length > 1) Then
738
                        If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
739
                            Dim ox As Double = opointstr(0)
740
                            Dim oy As Double = opointstr(1)
741
                            ConvertPointByImage(ox, oy, _IMG_X, _IMG_Y)
742
                            objInputs.AddPoint(ox, oy)
743
                        End If
744
                    End If
745
                Next
746
                Dim objItem As LMAItem
747
                objItem = _Placement.PIDCreateItem(oSymbol)
748
                objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
749
                SetListBoxItems(ListBox_Result, " Place PipeLine...." & "(" & (iPipeCnt + 1) & "/" & oPipe_Dt.Rows.Count)
750
                'Dim objPipeRun As LMPipeRun = datasource.GetPipeRun(objConnector.ModelItemID)
751
                'objPipeRun.Attributes("OperFluidCode").Value = "AFS"
752
                'objPipeRun.Commit()
753
                iSymbolcount = iSymbolcount + 1
754
                iPipeCnt = iPipeCnt + 1
755
            Next
756
        End If
757

    
758
        SetListBoxItems(ListBox_Result, " Place PipeLine....완료")
759

    
760
        Dim iAllInstrumentCnt As Integer = oSymbol_Dt.Select("Name = 'INSTRUMENTATION'").Length
761
                    Dim iValveCnt As Integer = oSymbol_Dt.Select("Class = 'VALVES'").Length
762
        Dim iInstrumentCnt As Integer = 1
763
        Dim iFittingsCnt As Integer = 1
764

    
765
        Dim oInsNode As TreeNode = oTreeNode.Nodes.Find(oTreeNode.Name & "\Instruments", True)(0)
766
        Dim oValveNode As TreeNode = oTreeNode.Nodes.Find(oTreeNode.Name & "\Valves", True)(0)
767
        Dim oFittingsNode As TreeNode = oTreeNode.Nodes.Find(oTreeNode.Name & "\Fittings", True)(0)
768
        For Each oRow As DataRow In oSymbol_Dt.Rows
769

    
770
            Try
771

    
772
                Dim sSystemPath As String = oRow("SystemPath").ToString()
773
                Dim sName As String = oRow("Name").ToString()
774
                Dim sType As String = oRow("Type").ToString()
775
                Dim sText As String = oRow("Text").ToString()
776
                Dim sClass As String = oRow("Class").ToString()
777
                Dim sItem As String = oRow("Item").ToString()
778

    
779
                Dim oX As Double = 0.0
780
                Dim oY As Double = 0.0
781
                If IsNumeric(oRow("x").ToString()) Then
782
                    oX = Double.Parse(oRow("x").ToString())
783
                End If
784
                If IsNumeric(oRow("y").ToString()) Then
785
                    oY = Double.Parse(oRow("y").ToString())
786
                End If
787
                Dim oAngle As Double = 0.0
788
                If IsNumeric(oRow("Angle").ToString()) Then
789
                    oAngle = Double.Parse(oRow("Angle").ToString())
790
                End If
791
                '   oSymbol = "\INSTRUMENTation\SYSTEM FUNCTIONS\D C S\DCS FUNC ACCESS IN PRIME LOC.sym"
792
                If sSystemPath <> "" Then
793
                    If sName = _TYPE_Instumentation Then
794

    
795
                        Dim sTagsuffix As String = ""
796
                        Dim sTagSequenceNo As String = ""
797
                        Dim sMeasuredVariableCode As String = ""
798
                        Dim sInstrumentTypeModifier As String = ""
799

    
800
                        If sText <> "" Then
801
                            If sText.Contains(",") Then
802
                                Dim splitstr() As String = sText.Split(",")
803
                                For i = 0 To splitstr.Count - 1
804
                                    If i = 0 Then
805
                                        sMeasuredVariableCode = Mid(splitstr(i), 1, 1)
806
                                        sTagSequenceNo = Mid(splitstr(i), 2, Len(splitstr(i)))
807
                                    Else
808
                                        If Len(splitstr(i)) = 1 Then
809
                                            sInstrumentTypeModifier = splitstr(i)
810
                                        ElseIf Len(splitstr(i)) = 0 Then
811

    
812
                                        ElseIf Len(splitstr(i)) > 1 Then
813
                                            sInstrumentTypeModifier = Mid(splitstr(i), 1, 1)
814
                                            sTagsuffix = Mid(splitstr(i), 2, Len(splitstr(i)))
815
                                        End If
816
                                    End If
817
                                Next
818
                            Else
819
                                sMeasuredVariableCode = Mid(sText, 1, 1)
820
                                sTagSequenceNo = Mid(sText, 2, Len(sText))
821
                            End If
822

    
823
                        End If
824

    
825
                        Dim objInstrSym As LMSymbol
826
                        objInstrSym = _Placement.PIDPlaceSymbol(sSystemPath, oX, oY, , oAngle)
827
                        SetListBoxItems(ListBox_Result, " Place Instrument...." & "(" & (iInstrumentCnt + 1) & "/" & iAllInstrumentCnt & ")")
828

    
829
                        ' SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sTagSequenceNo)
830
                        Dim action As Action = Sub()
831
                                                   oInsNode.Nodes.Add(sClass & "-" & iInstrumentCnt)
832
                                                   oInsNode.ExpandAll()
833
                                               End Sub
834
                        oInsNode.TreeView.Invoke(action)
835

    
836

    
837
                        Dim objInstr As LMInstrument
838
                        objInstr = lobjDatasource.GetInstrument(objInstrSym.ModelItemID)
839

    
840
                        Dim objItem As LMAItem
841
                        objItem = _Placement.PIDCreateItem(sSystemPath)
842

    
843

    
844
                        objInstr.Attributes("MeasuredVariableCode").Value = sMeasuredVariableCode
845
                        objInstr.Attributes("InstrumentTypeModifier").Value = sInstrumentTypeModifier
846
                        objInstr.Attributes("TagSuffix").Value = sTagsuffix
847
                        objInstr.Attributes("TagSequenceNo").Value = sTagSequenceNo
848
                        objInstr.Commit()
849
                        iInstrumentCnt = iInstrumentCnt + 1
850
                    ElseIf sName = "GATE VALVE WITH PLUG" Then
851

    
852
                    ElseIf sName = "MEDIUM 1D 1TO1" Then
853

    
854
                    ElseIf sClass = "VALVES" Then
855
                        Dim action As Action = Sub()
856
                                                   oValveNode.ExpandAll()
857
                                                   oValveNode.Nodes.Add(sClass & "-" & iValveCnt)
858
                                               End Sub
859
                        oValveNode.TreeView.Invoke(action)
860

    
861
                        _Placement.PIDPlaceSymbol(sSystemPath, oX, oY, , oAngle)
862

    
863
                        iValveCnt = iValveCnt + 1
864
                    Else
865
                        Dim action As Action = Sub()
866
                                                   oFittingsNode.ExpandAll()
867
                                                   oFittingsNode.Nodes.Add(sClass & "-" & iFittingsCnt)
868
                                               End Sub
869
                        oFittingsNode.TreeView.Invoke(action)
870
                        _Placement.PIDPlaceSymbol(sSystemPath, oX, oY, , oAngle)
871

    
872
                        iFittingsCnt = iFittingsCnt + 1
873

    
874
                    End If
875
                    iSymbolcount = iSymbolcount + 1
876
                Else
877
                End If
878
            Catch ex As Exception
879

    
880
            End Try
881
            Dim dCalcProgressValue As Double = (iSymbolcount / iTotalCount) * 100
882
            SetProgressbar(ProgressBar_Status, dCalcProgressValue)
883
            '     ProgressBar_Status.Value = (iSymbolcount / iTotalCount) * 100
884

    
885
        Next
886

    
887
        MsgBox("Complete AutoConverting")
888
        SetListBoxItems(ListBox_Result, "Place Instrument....변환완료")
889
        SetListBoxItems(ListBox_Result, "총 symbol:  " & iSymbolcount & "개 변환완료")
890
        SetProgressbar(ProgressBar_Status, 100)
891
        ' MsgBox("symbol: " & iSymbolcount & "개, pipe : " & iPipecnt & "개 변환완료")
892
    End Function
893

    
894

    
895
    Private Sub Tree_XMLFiles_AfterCheck(sender As Object, e As TreeViewEventArgs)
896
        If e.Node.Checked = True Then
897
            For Each oNode As TreeNode In e.Node.Nodes
898
                oNode.Checked = True
899
            Next
900
        Else
901
            For Each oNode As TreeNode In e.Node.Nodes
902
                oNode.Checked = False
903
            Next
904
        End If
905
    End Sub
906

    
907
    Private Function Load_DB(ByVal sDBPath As String, ByVal sTableName As String) As DataTable
908

    
909
        Try
910
            Dim oDt As New DataTable
911
            Dim sConnectionstring As String = "Data Source=" & sDBPath & ";Version=3;Synchronous=Off;UTF8Encoding=True;"
912
            Dim conn As SQLiteConnection = New SQLiteConnection(sConnectionstring)
913
            conn.Open()
914
            Dim sQuery As String = "Select * from " & sTableName
915
            Dim cmd As SQLiteCommand = conn.CreateCommand()
916
            Dim adapter As SQLiteDataAdapter = New SQLiteDataAdapter(sQuery, conn)
917
            Dim oDataSet As DataSet = New DataSet()
918
            adapter.Fill(oDataSet)
919
            oDt = oDataSet.Tables(0)
920
            Return oDt
921
        Catch ex As Exception
922
            Return Nothing
923
        End Try
924

    
925

    
926
    End Function
927

    
928
    Private Sub Load_AttributeDB(ByVal sDBPath As String)
929

    
930
        Try
931
            Dim sConnectionstring As String = "Data Source=" & sDBPath & ";Version=3;Synchronous=Off;UTF8Encoding=True;"
932
            Dim conn As SQLiteConnection = New SQLiteConnection(sConnectionstring)
933
            conn.Open()
934
            Dim sQuery As String = "Select * from Attribute"
935
            Dim cmd As SQLiteCommand = conn.CreateCommand()
936
            Dim adapter As SQLiteDataAdapter = New SQLiteDataAdapter(sQuery, conn)
937
            Dim oDataSet As DataSet = New DataSet()
938
            adapter.Fill(oDataSet)
939
            _Attribute_DB = oDataSet.Tables(0)
940
        Catch ex As Exception
941

    
942
        End Try
943

    
944

    
945
    End Sub
946

    
947
    'Private Sub Tree_XMLFiles_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles Tree_XMLFiles.AfterSelect
948
    '    If first_start = False Then Exit Sub
949
    '    Dim pa = e.Node.FullPath.ToString
950

    
951
    '    printfilesfolders_here(pa, e.Node)
952

    
953
    '    displayfiles(pa)
954

    
955
    '    Dim coco As String = ""
956
    '    coco = pa.ToString
957
    '    coco = coco.Replace("\\", "\")
958
    '    Me.Text = coco
959
    '    folders_path = coco
960
    'End Sub
961

    
962
    Sub printfilesfolders_here(ByVal path As String, ByRef itree As TreeNode)
963

    
964
        Dim foldername As String
965
        Dim filename As String
966
        itree.Nodes.Clear()
967
        On Error GoTo eee
968
        For Each foldername In Directory.GetDirectories(path)
969
            On Error GoTo eee
970
            Dim jj = foldername.LastIndexOf("\")
971
            Dim jj1 = foldername.Length - jj
972
            Dim foldr = foldername.Substring((jj + 1), (jj1 - 1))
973
            itree.Nodes.Add(foldr, foldr)
974
        Next ' if you put this next at the end of procedure recursive will be done on first folder only
975
        Exit Sub
976
eee:
977
    End Sub
978

    
979

    
980

    
981
    '    Private Sub Tree_XMLFiles_MouseMove(sender As Object, e As MouseEventArgs) Handles Tree_XMLFiles.MouseMove
982
    '        first_start = True
983
    '    End Sub
984

    
985
    '    Private Sub ListView_File_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView_File.SelectedIndexChanged
986
    '        Dim indexes As ListView.SelectedIndexCollection =
987
    '                         Me.ListView_File.SelectedIndices
988
    '        Dim index As Integer
989

    
990
    '        For Each index In indexes
991
    '            'On Error Resume Next
992
    '            If folders_path.EndsWith("\") = True Then
993
    '                Me.Status_Main.Items(0).Text = folders_path + (Me.ListView_File.Items(index).Text)
994
    '                'On Error Resume Next
995
    '            Else
996
    '                Me.Status_Main.Items(0).Text = folders_path + "\" + (Me.ListView_File.Items(index).Text)
997
    '            End If
998

    
999
    '            Dim infoReader As System.IO.FileInfo
1000
    '            infoReader = My.Computer.FileSystem.GetFileInfo(Me.Status_Main.Items(0).Text)
1001
    '            Me.Status_Main.Items(1).Text = " Created : " + infoReader.CreationTime.ToString + " " + infoReader.Attributes.ToString
1002
    '        Next
1003
    '    End Sub
1004

    
1005
    '    Private Sub Procees()
1006
    '        Dim indexes As ListView.SelectedIndexCollection =
1007
    '                            Me.ListView_File.SelectedIndices
1008
    '        Dim index As Integer
1009

    
1010
    '        For Each index In indexes
1011
    '            'On Error Resume Next
1012
    '            If folders_path.EndsWith("\") = True Then
1013
    '                On Error GoTo out
1014
    '                Me.Status_Main.Items(0).Text = folders_path + (Me.ListView_File.Items(index).Text)
1015
    '                On Error GoTo out
1016
    '                'On Error Resume Next
1017
    '            Else
1018
    '                Me.Status_Main.Items(0).Text = folders_path + "\" + (Me.ListView_File.Items(index).Text)
1019
    '                On Error GoTo out
1020
    '            End If
1021

    
1022
    '            Dim infoReader As System.IO.FileInfo
1023
    '            infoReader = My.Computer.FileSystem.GetFileInfo(Me.Status_Main.Items(0).Text)
1024
    '            Me.Status_Main.Items(1).Text = " Created : " + infoReader.CreationTime.ToString + " " + infoReader.Attributes.ToString
1025
    '            On Error GoTo out
1026
    '            MsgBox(Me.Status_Main.Items(0).Text + " is processed")
1027
    '            On Error GoTo out
1028
    '        Next
1029
    '        Exit Sub
1030
    'out:
1031
    '        MsgBox(Err.Description)
1032
    'End Sub
1033

    
1034
    Private Function LoadAllDrawing() As DataTable
1035

    
1036

    
1037
        SetListBoxItems(ListBox_Result, "도면정보 로드중....")
1038

    
1039
        Dim oDt As DataTable = Drawing_Dt()
1040
        Dim sHierarchy As String = My.Settings.Plant_Hierarchy
1041

    
1042

    
1043
        Dim files() As String
1044
        files = Directory.GetFiles(sHierarchy, "*.pid", SearchOption.AllDirectories)
1045
        For Each FileName As String In files
1046
            Dim sName As String = FileName
1047
            Dim oAddRow As DataRow = oDt.NewRow()
1048
            oAddRow("Name") = Path.GetFileNameWithoutExtension(sName)
1049
            oAddRow("Path") = FileName
1050
            oDt.Rows.Add(oAddRow)
1051
        Next
1052
        Return oDt
1053
    End Function
1054

    
1055
    Private Function LoadAllDrawing2() As DataTable
1056
        Dim datasource As LMADataSource
1057
        Dim objPIDAutoApp As Object
1058
        Dim objPIDADrawing As Object
1059
        Dim objDrawing As Object 'Drawing
1060
        'Dim objDrawing As LMDrawing
1061
        'Dim objDrawings As LMDrawings
1062

    
1063
        datasource = New LMADataSource
1064

    
1065
        '    objDrawings = New LMDrawings
1066
        'objDrawings.Collect(datasource)
1067
        objPIDAutoApp = CreateObject("PIDAutomation.Application")
1068

    
1069
        For Each objDrawing In objPIDAutoApp.Drawings
1070
            objDrawing.CloseDrawing(True)
1071
        Next
1072
        Try
1073
            objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("UY1-K-2000_P1_300dpi_0321_TEST_1")
1074
        Catch ex As Exception
1075
            Process.Start("\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\Plant_Hierarchy\8121\8121-1\UY1-K-2000_P1_300dpi_0321_TEST_1.pid")
1076
        End Try
1077

    
1078

    
1079

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

    
1084
        objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("1")
1085

    
1086
        For Each objDrawing In objPIDAutoApp.Drawings
1087
            If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
1088
                Try
1089

    
1090
                    Dim sName As String = objDrawing.Attributes("Name").Value
1091

    
1092
                    iCount = iCount + 1
1093
                    If sName = "UY1-K-2000_P1_300dpi_0321_TEST_1" Then
1094
                        objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(objDrawing.Attributes("Name"))
1095
                        objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("\8121\8121-1\UY1-K-2000_P1_300dpi_0321_TEST_1.pid")
1096
                        If Not objPIDADrawing Is Nothing Then
1097
                            objPIDADrawing.CloseDrawing()
1098
                        End If
1099
                    End If
1100

    
1101

    
1102
                Catch ex As Exception
1103

    
1104
                End Try
1105

    
1106
            End If
1107
        Next
1108
        objPIDAutoApp.Quit
1109
        objPIDAutoApp = Nothing
1110
        objPIDADrawing = Nothing
1111
        objDrawing = Nothing
1112
        '   objDrawings = Nothing
1113
    End Function
1114

    
1115
    Dim _XMLList As ListView = New ListView()
1116

    
1117

    
1118

    
1119

    
1120

    
1121

    
1122
    Private Function CheckOpenDrawing() As Boolean
1123
        Try
1124

    
1125
            Dim lobjDatasource As Object
1126
            _Placement = CreateObject("Plaice.Placement", "")
1127
            lobjDatasource = _Placement.PIDDataSource
1128
            Return True
1129
        Catch ex As Exception
1130
            Return False
1131
        End Try
1132

    
1133
    End Function
1134

    
1135

    
1136
    Private Sub Btn_Convert_Click(sender As Object, e As EventArgs) Handles Btn_Convert.Click
1137

    
1138
        Main_Tab.SelectedIndex = 1
1139
        ListBox_Result.Items.Clear()
1140
        ' DataGrid_Result.DataSource = New DataTable()
1141
        Me.ProgressBar_Status.Visible = True
1142
        ProgressBar_Status.Maximum = 100
1143
        ProgressBar_Status.Value = 0
1144
        ' _selectFolderPath = Tree_XMLFiles.SelectedNode.FullPath.Replace("\\", "\")
1145
        _Main_trd = New Thread(AddressOf ThreadTask)
1146
        _Main_trd.IsBackground = True
1147
        _Main_trd.Start()
1148

    
1149
    End Sub
1150
    'Private Sub ThreadTask()
1151

    
1152

    
1153
    '    If _XMLList.Items.Count > 0 Then
1154

    
1155
    '        Dim oDwg_Dt As DataTable = LoadAllDrawing()
1156
    '        Dim iDwgCnt As Integer = 0
1157
    '        Dim objPIDAutoApp As Object
1158
    '        objPIDAutoApp = CreateObject("PIDAutomation.Application")
1159

    
1160

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

    
1164
    '            Dim sDwgName As String = Path.GetFileNameWithoutExtension(myList(i))
1165
    '            Txt_Status.Text = sDwgName & "..(" & i + 1 & "/" & myList.Count & ")"
1166
    '            SetListBoxItems(ListBox_Result, Txt_Status.Text & " 처리중....")
1167
    '            Dim sDwgNo As String = myList(i)
1168
    '            Dim oDwgPath As String = ""
1169
    '            oDwgPath = _selectFolderPath + "\" + sDwgNo
1170

    
1171
    '            Dim sPath As String = OpenDrawing(oDwg_Dt, sDwgName)
1172
    '            If sPath <> "" Then
1173

    
1174
    '                Process.Start(sPath)
1175

    
1176
    '                Dim bCheckOpenDrawing As Boolean = False
1177
    '                While (True)
1178
    '                    bCheckOpenDrawing = CheckOpenDrawing()
1179
    '                    If bCheckOpenDrawing = True Then
1180
    '                        Exit While
1181
    '                    Else
1182
    '                        Thread.Sleep(2000)
1183
    '                    End If
1184
    '                End While
1185

    
1186
    '                If bCheckOpenDrawing Then
1187
    '                    SetListBoxItems(ListBox_Result, sDwgName & " 도면 Open....")
1188
    '                    Dim oPipe_Dt As DataTable = New DataTable() 'LoadPipeInXml(oDwgPath)
1189

    
1190
    '                    Dim oSymbol_Dt As DataTable = LoadSymbolInXml(oDwgPath)
1191
    '                    Dim oTreeNode As New TreeNode  'SetTreeViewItems(Tree_Result, Tree_Result.Nodes, sDwgName, sDwgName)
1192
    '                    'oTreeNode = Tree_Result.Nodes.Find(sDwgName, True)(0)
1193
    '                    Dim action As Action = Sub()
1194
    '                                               oTreeNode = Tree_Result.Nodes.Add(sDwgName, sDwgName)
1195
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Instruments", "Instuments")
1196
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Pipes", "Pipes")
1197
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Valves", "Valves")
1198
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Fittings", "Fittings")
1199
    '                                               oTreeNode.ExpandAll()
1200
    '                                           End Sub
1201
    '                    Tree_Result.Invoke(action)
1202

    
1203

    
1204
    '                    '    oTreeNode.Expand()
1205
    '                    SetListBoxItems(ListBox_Result, sDwgName & " Auto converting 대기....")
1206
    '                    AutoConverting(oPipe_Dt, oSymbol_Dt, oTreeNode)
1207

    
1208
    '                End If
1209

    
1210
    '            End If
1211
    '            ''도면 생성
1212
    '            'If CreateDwg(sDwgName) Then
1213
    '            '    'AutoConverting
1214

    
1215
    '            'End If
1216

    
1217
    '        Next
1218
    '    End If
1219
    'End Sub
1220

    
1221
    Dim _objPIDAutoApp As Object
1222

    
1223
    Private Function OpenSPPID(ByVal oDwg_Dt As DataTable, ByVal sDwgName As String) As Boolean
1224
        Dim bCheckOpen As Boolean = False
1225
        '   Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgPath)
1226
        SetListBoxItems(ListBox_Result, sDwgName & " 도면 Open....")
1227
        _objPIDAutoApp = CreateObject("PIDAutomation.Application")
1228

    
1229
        Dim sPath As String = OpenDrawing(oDwg_Dt, sDwgName)
1230
        If sPath <> "" Then
1231
            Process.Start(sPath)
1232
        Else
1233
            Return bCheckOpen
1234
        End If
1235

    
1236
            Dim bCheckOpenDrawing As Boolean = False
1237
            While (True)
1238
                bCheckOpenDrawing = CheckOpenDrawing()
1239
                If bCheckOpenDrawing = True Then
1240
                    bCheckOpen = True
1241
                    Exit While
1242
                Else
1243
                    Thread.Sleep(2000)
1244
                End If
1245
            End While
1246

    
1247

    
1248
            Return bCheckOpen
1249
    End Function
1250

    
1251
    Private Function GetDrawing(ByVal sDwgName As String) As Drawing
1252
        For Each CDrawing In _DrawingsList
1253
            If CDrawing.DwgName.ToUpper() = sDwgName.ToUpper() Then
1254
                Return CDrawing
1255
            End If
1256
        Next
1257
        Return Nothing
1258
    End Function
1259

    
1260
    Private Function GetLineNo(ByVal CDrawing As Drawing, ByVal sLineNoUid As String) As Line_no
1261
        For Each CLineNo In CDrawing.Line_nos
1262
            If CLineNo.Uid = sLineNoUid Then
1263
                Return CLineNo
1264
            End If
1265
        Next
1266
        Return Nothing
1267
    End Function
1268

    
1269
    Private Function GetOnlyPipeLineNo(ByVal CDrawing As Drawing, ByVal sPipeUid As String) As Line_no
1270
        For Each CLineNo In CDrawing.Line_nos
1271
            Dim odt As DataTable = CLineNo.Dt_Line
1272
            If odt.Rows.Count > 0 Then
1273
                If odt.Rows(0)(_XML_LINE_UID).ToString = sPipeUid Then
1274
                    Return CLineNo
1275
                End If
1276
            End If
1277
        Next
1278
        Return Nothing
1279
    End Function
1280

    
1281

    
1282
    Private Function GetEqpNo(ByVal CDrawing As Drawing, ByVal sEqpUid As String) As Eqp_no
1283
        For Each CEqpNo In CDrawing.Eqp_nos
1284
            If CEqpNo.Uid = sEqpUid Then
1285
                Return CEqpNo
1286
            End If
1287
        Next
1288
        Return Nothing
1289
    End Function
1290
    Private Function ConvertPointBystring(ByVal sPoint As String, ByRef dX As Double, ByRef dY As Double) As Boolean
1291
        Try
1292
            Dim opointstr As String() = Split(sPoint, ",")
1293
            If (opointstr.Length > 1) Then
1294
                If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
1295
                    dX = opointstr(0)
1296
                    dY = opointstr(1)
1297

    
1298
                Else
1299
                    dX = 0
1300
                    dY = 0
1301
                    Return False
1302
                End If
1303
            End If
1304
            Return True
1305
        Catch ex As Exception
1306
            Return False
1307
        End Try
1308
    End Function
1309

    
1310
    Private Function DrawLine(ByVal sUid As String, ByVal sLineNoUid As String, ByVal oLine_Dt As DataTable, ByVal oAttribute_Dt As DataTable) As LMPipeRun
1311
        Try
1312
            Dim oPipeRun As LMPipeRun
1313
            Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_UID & " = '" + sUid + "'")
1314
            Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
1315

    
1316
            If oPipeRow.Length > 0 Then
1317
                Dim oDatasource As Object = _Placement.PIDDataSource
1318
                Dim objItem As LMAItem
1319
                Dim objConnector As LMConnector
1320
                Dim objInputs As PlaceRunInputs
1321
                objInputs = New PlaceRunInputs
1322
                Dim dOriginalStart_x As Double = 0.0
1323
                Dim dOriginalStart_y As Double = 0.0
1324
                Dim dOriginalEnd_x As Double = 0.0
1325
                Dim dOriginalEnd_y As Double = 0.0
1326

    
1327
                Dim dStart_x As Double = 0.0
1328
                Dim dStart_y As Double = 0.0
1329
                Dim dEnd_x As Double = 0.0
1330
                Dim dEnd_y As Double = 0.0
1331
                Dim sSystempath As String = oPipeRow(0)(_XML_LINE_SYSTEMPATH).ToString()
1332
                Dim sStartpoint As String = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
1333
                Dim sEndpoint As String = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
1334
                Dim sPipeUid As String = oPipeRow(0)(_XML_LINE_UID).ToString()
1335

    
1336
                ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
1337
                dStart_x = dOriginalStart_x
1338
                dStart_y = dOriginalStart_y
1339

    
1340
                If ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y) Then
1341
                    dEnd_x = dOriginalEnd_x
1342
                    dEnd_y = dOriginalEnd_y
1343
                    '//Overlap 보정
1344
                    If FindOverlapLine(oLine_Dt, sPipeUid, dStart_x, dStart_y, dEnd_x, dEnd_y) = False Then
1345
                        '//떨어진 라인 보정
1346
                        Dim dSeperate_start_x As Double = dStart_x
1347
                        Dim dSeperate_start_y As Double = dStart_y
1348
                        Dim dSeperate_end_x As Double = dEnd_x
1349
                        Dim dSeperate_end_y As Double = dEnd_y
1350
                        CalcSperateLine(dSeperate_start_x, dSeperate_start_y, dSeperate_end_x, dSeperate_end_y)
1351
                        If (FindOverlapLine(oLine_Dt, sPipeUid, dSeperate_start_x, dSeperate_start_y, dSeperate_end_x, dSeperate_end_y)) Then
1352
                            dStart_x = dSeperate_start_x
1353
                            dStart_y = dSeperate_start_y
1354
                            dEnd_x = dSeperate_end_x
1355
                            dEnd_y = dSeperate_end_y
1356
                        End If
1357

    
1358
                    End If
1359
                    ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
1360
                    ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
1361
                    If dStart_x <> 0 And dStart_y <> 0 And dEnd_x <> 0 And dEnd_y <> 0 Then
1362

    
1363
                        objInputs.AddPoint(dStart_x, dStart_y)
1364
                        objInputs.AddPoint(dEnd_x, dEnd_y)
1365
                        objItem = _Placement.PIDCreateItem(sSystempath)
1366
                        _iPipecnt = _iPipecnt + 1
1367
                        SetListBoxItems(ListBox_Result, "Place PipeLine..(" & dOriginalStart_x & "," & dOriginalStart_y & ") - (" & dOriginalEnd_x & "," & dOriginalEnd_y & ").." & _iPipecnt & " count ")
1368
                        objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
1369
                        oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
1370
                        oPipeRun.Attributes("FlowDirection").Value = "End 1 is upstream (Inlet)"
1371
                        If oAttributeRow.Length > 0 Then
1372
                            For Each oAttribute In oAttributeRow
1373
                                Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
1374
                                Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
1375
                                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
1376
                                oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
1377

    
1378
                            Next
1379
                            oPipeRun.Commit()
1380
                        End If
1381
                        'Flow Direction 
1382
                        'Dim sFlowDirectionPath As String = GetDataFromMappingDB(_XML_CATEGORY_FLOWDIRECITON, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
1383
                        'Dim dFlowDirectionAngle As Double = 0.0
1384
                        'If dStart_y <> dEnd_y Then
1385
                        '    If dStart_y > dEnd_y Then
1386
                        '        dFlowDirectionAngle = -1.57
1387
                        '    Else
1388
                        '        dFlowDirectionAngle = 1.57
1389
                        '    End If
1390
                        'End If
1391
                        'If dStart_x <> dEnd_x Then
1392
                        '    If dStart_x > dEnd_x Then
1393
                        '        dFlowDirectionAngle = 3.14
1394
                        '    Else
1395
                        '        dFlowDirectionAngle = 0
1396
                        '    End If
1397
                        'End If
1398

    
1399
                        '_Placement.PIDPlaceSymbol(sFlowDirectionPath, dEnd_x, dEnd_y, , dFlowDirectionAngle)
1400
                    End If
1401
                End If
1402

    
1403

    
1404
            End If
1405
            Return oPipeRun
1406
        Catch ex As Exception
1407
            Return Nothing
1408
        End Try
1409
    End Function
1410

    
1411
    Private Function DrawSymbol(ByVal sUid As String, ByVal sLineNoUid As String, ByVal oSymbol_Dt As DataTable, ByVal oAttribute_Dt As DataTable) As Boolean
1412
        Try
1413

    
1414
            Dim oSymbolRow() As DataRow = oSymbol_Dt.Select(_XML_SYMBOL_UID & " = '" + sUid + "'")
1415
            Dim oAttributeRow() As DataRow
1416
            If oAttribute_Dt.Rows.Count > 0 Then
1417
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
1418
            End If
1419

    
1420
            If oSymbolRow.Length > 0 Then
1421
                Dim oDatasource As Object = _Placement.PIDDataSource
1422
                Dim sSymbolCompType As String = oSymbolRow(0)(_XML_SYMBOL_TYPE).ToString()
1423
                Dim sSystemPath As String = oSymbolRow(0)(_XML_SYMBOL_SYSTEMPATH).ToString()
1424
                Dim sLocation As String = oSymbolRow(0)(_XML_SYMBOL_LOCATION).ToString()
1425
                Dim sOriginalPoint As String = oSymbolRow(0)(_XML_SYMBOL_ORIGINALPOINT).ToString()
1426
                Dim dAngle As Double = 0.0
1427
                If IsNumeric(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString()) Then
1428
                    dAngle = Double.Parse(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString())
1429
                End If
1430

    
1431
                Dim objSymbol As LMSymbol
1432
                Dim dLocationX As Double = 0.0
1433
                Dim dLocationY As Double = 0.0
1434
                Dim dX As Double = 0.0
1435
                Dim dY As Double = 0.0
1436

    
1437
                If ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY) Then
1438
                    dX = dLocationX
1439
                    dY = dLocationY
1440
                    ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1441
                    Dim oInstrument As LMInstrument
1442
                    If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT Then
1443
                        _iInstrumentcnt = _iInstrumentcnt + 1
1444
                        objSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1445
                        SetListBoxItems(ListBox_Result, "Place Instrument..(" & dLocationX & "," & dLocationY & ")..." & _iInstrumentcnt & " count ")
1446
                        oInstrument = oDatasource.GetInstrument(objSymbol.ModelItemID)
1447
                        Try
1448
                            If oAttributeRow.Length > 0 Then
1449
                                For Each oAttribute In oAttributeRow
1450
                                    Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
1451
                                    Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
1452
                                    Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
1453
                                    oInstrument.Attributes(sSPPIDAttribute).Value = sPIDValue
1454
                                Next
1455
                                oInstrument.Commit()
1456
                            End If
1457
                        Catch ex As Exception
1458

    
1459
                        End Try
1460

    
1461

    
1462
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_VALVES Then
1463
                        _iValvecnt = _iValvecnt + 1
1464
                        _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1465
                        SetListBoxItems(ListBox_Result, "Place Valve..(" & dLocationX & "," & dLocationY & ")..." & _iValvecnt & " count ")
1466

    
1467
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_FITTINGS Then
1468
                        _iFittingcnt = _iFittingcnt + 1
1469
                        If sSystemPath.Contains(",") Then
1470

    
1471
                            Dim sDuplicatePath As String() = sSystemPath.Split(",")
1472
                            Dim sMainSymbol As String = ""
1473
                            Dim sSubSymbol As String = ""
1474
                            For Each sPath In sDuplicatePath
1475
                                If sMainSymbol = "" Then
1476
                                    sMainSymbol = sPath.Replace(vbLf, "")
1477
                                Else
1478
                                    sSubSymbol = sPath.Replace(vbLf, "")
1479
                                End If
1480
                            Next
1481
                            Dim oSymbolObj As LMSymbol = _Placement.PIDPlaceSymbol(sMainSymbol, dX, dY, , dAngle)
1482
                            Dim dConnpos_x As Double = 0.0
1483
                            Dim dConnpos_y As Double = 0.0
1484
                            _Placement.PIDConnectPointLocation(oSymbolObj, 2, dConnpos_x, dConnpos_y)
1485
                            '   _Placement.PIDPlaceSymbol(sSubSymbol, dConnpos_x, dConnpos_y, dAngle, TargetItem:=oSymbolObj.AsLMRepresentation)
1486
                            _Placement.PIDPlaceSymbol(sSubSymbol, dConnpos_x, dConnpos_y,, dAngle)
1487

    
1488
                        Else
1489
                            _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1490
                        End If
1491

    
1492

    
1493
                        SetListBoxItems(ListBox_Result, "Place Fitting..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1494
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_ACTUATORS Then
1495
                        _iFittingcnt = _iFittingcnt + 1
1496
                        Dim sDuplicatePath As String() = sSystemPath.Split(",")
1497
                        Dim sMainSymbol As String = ""
1498
                        Dim sSubSymbol As String = ""
1499
                        For Each sPath In sDuplicatePath
1500
                            If sMainSymbol = "" Then
1501
                                sMainSymbol = sPath.Replace(vbLf, "")
1502
                            Else
1503
                                sSubSymbol = sPath.Replace(vbLf, "")
1504
                            End If
1505
                        Next
1506
                        Dim oSymbolObj As LMSymbol = _Placement.PIDPlaceSymbol(sMainSymbol, dX, dY, , dAngle)
1507
                        Dim dSymbolpos_x As Double = oSymbolObj.XCoordinate
1508
                        Dim dSymbolpos_y As Double = oSymbolObj.YCoordinate
1509
                        _Placement.PIDPlaceSymbol(sSubSymbol, dSymbolpos_x, dSymbolpos_y, , dAngle, TargetItem:=oSymbolObj.AsLMAItem)
1510

    
1511
                    Else
1512
                        _iFittingcnt = _iFittingcnt + 1
1513
                        _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1514
                        SetListBoxItems(ListBox_Result, "Place Fitting..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1515
                    End If
1516

    
1517
                End If
1518

    
1519
            End If
1520

    
1521
        Catch ex As Exception
1522
            Return False
1523
        End Try
1524
    End Function
1525

    
1526
    Private Function FindOverlapLine(ByVal oLine_Dt As DataTable, ByVal sUid As String, ByRef dsx As Double, ByRef dsy As Double,
1527
                                      ByRef dex As Double, ByRef dey As Double)
1528
        Try
1529
            Dim bCheckOverlap As Boolean = False
1530

    
1531
            For Each oRow In oLine_Dt.Rows
1532

    
1533
                Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1534
                Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1535
                Dim sBUid As String = oRow(_XML_LINE_UID).ToString()
1536
                If sBUid <> sUid Then
1537
                    Dim d기준s_x As Double = 0
1538
                    Dim d기준s_y As Double = 0
1539
                    Dim d기준e_x As Double = 0
1540
                    Dim d기준e_y As Double = 0
1541
                    ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1542
                    ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1543

    
1544
                    If (d기준s_x <= dsx And d기준e_x >= dex) And
1545
                        d기준s_y <= dsy And d기준e_y >= dey Then
1546
                        '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1547
                        If dsy - d기준s_y > d기준e_y - dey Then
1548
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1549
                            If dResultCalc < 10 Then
1550
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1551
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1552
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1553
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1554
                                If dCalcStartY = 0 Then
1555
                                    dey = d기준e_y
1556
                                Else
1557
                                    dey = dCalcStartY
1558
                                End If
1559

    
1560
                            End If
1561

    
1562
                        Else
1563
                            Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1564
                            If dResultCalc < 10 Then
1565
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1566
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1567
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1568
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1569

    
1570
                                If dCalcStartY = 0 Then
1571
                                    dsy = d기준s_y
1572
                                Else
1573
                                    dsy = dCalcStartY
1574
                                End If
1575

    
1576
                            End If
1577

    
1578
                        End If
1579
                        bCheckOverlap = True
1580
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
1581
                            d기준s_y <= dey And d기준e_y >= dsy Then
1582
                        '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1583
                        If dey - d기준s_y > d기준e_y - dsy Then
1584
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1585
                            If dResultCalc < 10 Then
1586
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1587
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1588
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1589
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1590
                                If dCalcStartY = 0 Then
1591
                                    dey = d기준e_y
1592
                                Else
1593
                                    dey = dCalcStartY
1594
                                End If
1595

    
1596
                            End If
1597

    
1598
                            '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1599

    
1600
                        Else
1601
                            Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1602
                            If dResultCalc < 10 Then
1603
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1604
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1605
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1606
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1607
                                If dCalcStartY = 0 Then
1608
                                    dsy = d기준s_y
1609
                                Else
1610
                                    dsy = dCalcStartY
1611
                                End If
1612
                            End If
1613

    
1614
                        End If
1615
                        bCheckOverlap = True
1616
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
1617
                            d기준s_y <= dey And d기준e_y >= dsy Then
1618

    
1619
                        If dsx - d기준s_x > d기준e_x - dex Then
1620
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1621
                            If dResultCalc < 10 Then
1622
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1623
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1624
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1625
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1626
                                If dCalcStartX = 0 Then
1627
                                    dex = d기준e_x
1628
                                Else
1629
                                    dex = dCalcStartX
1630
                                End If
1631
                            End If
1632
                        Else
1633
                            Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1634
                            If dResultCalc < 10 Then
1635
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1636
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1637
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1638
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1639
                                If dCalcStartX = 0 Then
1640
                                    dsx = d기준s_x
1641
                                Else
1642
                                    dsx = dCalcStartX
1643
                                End If
1644
                            End If
1645

    
1646
                        End If
1647

    
1648
                        bCheckOverlap = True
1649
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
1650
                            d기준s_y <= dey And d기준e_y >= dsy Then
1651

    
1652
                        If dex - d기준s_x > d기준e_x - dsx Then
1653
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1654
                            If dResultCalc < 10 Then
1655
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1656
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1657
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1658
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1659
                                If dCalcStartX = 0 Then
1660
                                    dex = d기준e_x
1661
                                Else
1662
                                    dex = dCalcStartX
1663
                                End If
1664
                            End If
1665
                        Else
1666
                            Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1667
                            If dResultCalc < 10 Then
1668
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1669
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1670
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1671
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1672
                                If dCalcStartX = 0 Then
1673
                                    dsx = d기준s_x
1674
                                Else
1675
                                    dsx = dCalcStartX
1676
                                End If
1677
                            End If
1678

    
1679
                        End If
1680
                        bCheckOverlap = True
1681
                    End If
1682
                End If
1683
            Next
1684
            Return bCheckOverlap
1685
        Catch ex As Exception
1686
            Return False
1687
        End Try
1688

    
1689

    
1690
    End Function
1691

    
1692
    Private Sub CalcSperateLine(ByRef dStartX As Double, ByRef dStartY As Double,
1693
                                      ByRef dEndX As Double, ByRef dEndY As Double)
1694
        Try
1695
            Dim dRange As Double = 1 'Line 전체 길이의 1%씩 늘이기
1696
            If Math.Abs(dStartX - dEndX) > Math.Abs(dStartY - dEndY) Then
1697
                Dim dCalc_x As Double = Math.Abs(dStartX - dEndX) / 100
1698
                If dStartX > dEndX Then
1699
                    dStartX = dStartX + dCalc_x
1700
                    dEndX = dEndX - dCalc_x
1701
                Else
1702
                    dEndX = dEndX + dCalc_x
1703
                    dStartX = dStartX - dCalc_x
1704
                End If
1705
            Else
1706
                Dim dCalc_y As Double = Math.Abs(dStartY - dEndY) / 100
1707
                If dStartY > dEndY Then
1708
                    dStartY = dStartY + dCalc_y
1709
                    dEndY = dEndY - dCalc_y
1710
                Else
1711
                    dEndY = dEndY + dCalc_y
1712
                    dStartY = dStartY - dCalc_y
1713
                End If
1714
            End If
1715

    
1716

    
1717

    
1718
        Catch ex As Exception
1719

    
1720
        End Try
1721

    
1722

    
1723
    End Sub
1724

    
1725
    Private Function DrawLineNo(ByVal oPiperun As LMPipeRun, ByVal CLine_No As Line_no) As Boolean
1726
        Try
1727
            Dim oDatasource As Object = _Placement.PIDDataSource
1728
            Dim sLocation = CLine_No.Location
1729
            Dim dLocationx As Double = 0.0
1730
            Dim dLocationy As Double = 0.0
1731

    
1732
            Dim dX As Double = 0.0
1733
            Dim dY As Double = 0.0
1734
            If ConvertPointBystring(sLocation, dLocationx, dLocationy) Then
1735
                dX = dLocationx
1736
                dY = dLocationy
1737
                ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1738
                Dim dLineNoLocation(2) As Double
1739
                dLineNoLocation(1) = dX
1740
                dLineNoLocation(2) = dY
1741
                'Label
1742
                Dim sSystemPath As String = CLine_No.SystemPath
1743
                Dim dAngle As Double = CLine_No.Angle
1744
                Dim labelpersist As LMLabelPersist
1745

    
1746
                For Each representation In oPiperun.Representations
1747
                    If representation.RepresentationType = "Connector" Then
1748
                        labelpersist = _Placement.PIDPlaceLabel(sSystemPath,
1749
                        dLineNoLocation,, dAngle, LabeledItem:=representation)
1750
                        _iPipeLineNocnt = _iPipeLineNocnt + 1
1751
                        SetListBoxItems(ListBox_Result, "Place PipeLineNo Label..(" & dLocationx & "," & dLocationy & ")..." & _iPipeLineNocnt & " count ")
1752
                    End If
1753
                Next
1754
                Return True
1755
            Else
1756
                Return False
1757
            End If
1758

    
1759
        Catch ex As Exception
1760
            Return False
1761
        End Try
1762
    End Function
1763

    
1764

    
1765
    Private Sub InitItemCount()
1766
        _iPipeLineNocnt = 0
1767
        _iPipecnt = 0
1768
        _iFittingcnt = 0
1769
        _iValvecnt = 0
1770
        _iInstrumentcnt = 0
1771
        _iEquipmentcnt = 0
1772
        _iNozzlecnt = 0
1773
    End Sub
1774

    
1775
    Private Function AutoModeling() As Boolean
1776
        Try
1777

    
1778
            SetListBoxItems(ListBox_Result, " Auto converting 시작....")
1779
            Dim oDwg_Dt As DataTable = LoadAllDrawing()
1780
            For Each oDrwing As TreeNode In Tree_Result.Nodes
1781
                For Each oDwgNode As TreeNode In oDrwing.Nodes
1782

    
1783
                    Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
1784
                        Dim  CDrawing As Drawing = GetDrawing(sDwgName)
1785
                        If CDrawing IsNot Nothing Then
1786
                        If OpenSPPID(oDwg_Dt, oDwgNode.Text) Then
1787
                            InitItemCount()
1788
                            Dim iAllLineNoCount As Integer = Tree_Result.Nodes.Count ' GetCheckNodeCount(oLinenoNode)
1789
                            Dim iLineNoCount As Integer = 0 ' GetCheckNodeCount(oLinenoNode)
1790
                            SetListBoxItems(ListBox_Result, "Place " & CDrawing.DwgName & "....")
1791

    
1792
                            For Each oNode As TreeNode In oDwgNode.Nodes
1793

    
1794
                                Dim sNodeUid As String = oNode.Name
1795
                                If sNodeUid <> "PipeLineNo" Then
1796
                                    Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
1797
                                    If CLineNo IsNot Nothing Then
1798
                                        Dim oPipeRun As LMPipeRun
1799
                                        Dim oLine_Dt As DataTable = CLineNo.Dt_Line
1800
                                        Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
1801
                                        Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
1802
                                        Dim oDrawLinenoLabel As Boolean = False
1803
                                        For Each oLineNode As TreeNode In oNode.Nodes
1804
                                            Dim sLineUid As String = oLineNode.Name
1805
                                            If oLineNode.Checked Then
1806
                                                Dim sUid As String = oLineNode.Name
1807
                                                If oLine_Dt.Select("[" & _XML_LINE_UID & "]= '" & sUid & "'").Length = 1 Then
1808
                                                    oPipeRun = DrawLine(sUid, sNodeUid, oLine_Dt, oAttribute_Dt)
1809
                                                    If oDrawLinenoLabel = False Then
1810
                                                        DrawLineNo(oPipeRun, CLineNo)
1811
                                                        oDrawLinenoLabel = True
1812
                                                    End If
1813
                                                End If
1814

    
1815

    
1816
                                            End If
1817
                                        Next
1818

    
1819
                                        For Each oSymbolNode As TreeNode In oNode.Nodes
1820
                                            If oSymbolNode.Checked Then
1821
                                                Dim sUid As String = oSymbolNode.Name
1822
                                                If oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "]= '" & sUid & "'").Length = 1 Then
1823
                                                    DrawSymbol(sUid, sNodeUid, oSymbol_Dt, oAttribute_Dt)
1824
                                                End If
1825

    
1826
                                            End If
1827
                                        Next
1828
                                        iLineNoCount = iLineNoCount + 1
1829
                                    End If
1830

    
1831
                                    Dim CEqpNo As Eqp_no = GetEqpNo(CDrawing, sNodeUid)
1832

    
1833
                                    If CEqpNo IsNot Nothing Then
1834
                                        Dim oSymbol_Dt As DataTable = CEqpNo.Dt_Equipment
1835
                                        Dim oAttribute_Dt As DataTable = CEqpNo.Dt_Attribute
1836
                                        For Each oSymbolNode As TreeNode In oNode.Nodes
1837
                                            If oSymbolNode.Checked Then
1838
                                                Dim sUid As String = oSymbolNode.Name
1839
                                                DrawSymbol(sUid, sNodeUid, oSymbol_Dt, oAttribute_Dt)
1840
                                            End If
1841
                                        Next
1842
                                    End If
1843

    
1844

    
1845

    
1846
                                Else
1847

    
1848
                                    Dim oDrawLinenoLabel As Boolean = False
1849
                                    For Each oLineNode As TreeNode In oNode.Nodes
1850
                                        Dim CLineNo As Line_no = GetOnlyPipeLineNo(CDrawing, oLineNode.Name)
1851
                                        Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
1852
                                        Dim oLine_Dt As DataTable = CLineNo.Dt_Line
1853
                                        Dim sLineUid As String = oLineNode.Name
1854
                                        If oLineNode.Checked Then
1855
                                            Dim sUid As String = oLineNode.Name
1856
                                            DrawLine(sUid, sNodeUid, oLine_Dt, oAttribute_Dt)
1857
                                        End If
1858
                                    Next
1859

    
1860

    
1861

    
1862

    
1863
                                End If
1864

    
1865

    
1866
                                '      Dim dCalcProgressValue As Double = (iLineNoCount / iLineNoCount) * 100
1867
                                'SetProgressbar(ProgressBar_Status, dCalcProgressValue)
1868
                            Next
1869

    
1870
                        End If
1871
                    End If
1872

    
1873
                Next
1874

    
1875

    
1876

    
1877
            Next
1878
            SetProgressbar(ProgressBar_Status, 100)
1879
            SetListBoxItems(ListBox_Result, " Auto converting 완료")
1880
            Return True
1881
        Catch ex As Exception
1882
            Return False
1883
        End Try
1884
    End Function
1885

    
1886

    
1887

    
1888
    Private Sub ThreadTask()
1889
        If _DrawingsList IsNot Nothing Then
1890
            If _DrawingsList.Count > 0 Then
1891
                AutoModeling()
1892
            End If
1893
        End If
1894

    
1895

    
1896
    End Sub
1897

    
1898

    
1899

    
1900

    
1901
    Private Function OpenDrawing(ByVal oDt As DataTable, ByVal sDwgName As String) As String
1902
        Dim oRows As DataRow() = oDt.Select("[Name] = '" & sDwgName & "'")
1903
        Dim oPath As String = ""
1904
        If oRows.Length > 0 Then
1905
            oPath = oRows(0).Item("Path").ToString()
1906
        End If
1907
        Return oPath
1908
    End Function
1909

    
1910
    Private Sub LoadXmlToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LoadXmlToolStripMenuItem.Click
1911
        If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
1912
            LoadXmlItem(FolderBrowserDialog1.SelectedPath)
1913
        End If
1914
    End Sub
1915
    Private Sub LoadXmlItem(ByVal sFolderPath As String)
1916
        _DrawingsList = New List(Of Drawing)
1917
        Dim sfileEntries As String() = Directory.GetFiles(sFolderPath)
1918
        If Tree_Result.Nodes.Count > 0 Then
1919
            Tree_Result.Nodes(0).Nodes.Clear()
1920
            For Each sfileName In sfileEntries
1921
                Dim sExtension As String = Path.GetExtension(sfileName)
1922
                If sExtension = ".xml" Then
1923
                    Dim sDwgName As String = Path.GetFileNameWithoutExtension(sfileName)
1924
                    Dim sDwgPath As String = sfileName
1925
                    Dim oNode As TreeNode = Tree_Result.Nodes(0).Nodes.Add(sDwgPath, sDwgName, 15)
1926
                    Dim oDwg As Drawing = AddSymbolItem(sDwgPath, oNode)
1927
                    _DrawingsList.Add(oDwg)
1928
                End If
1929
            Next
1930
            Tree_Result.Nodes(0).Expand()
1931
        End If
1932
    End Sub
1933

    
1934

    
1935
    ''' <summary>
1936
    '''  XML Tree 구조 생성 
1937
    ''' </summary>
1938
    ''' <param name="sDwgPath"></param>
1939
    Private Function AddSymbolItem(ByVal sDwgPath As String, ByVal oParentNode As TreeNode) As Drawing
1940
        Dim oDwg_Ds As Drawing = LoadSymbolInXml(sDwgPath)
1941

    
1942
        Dim oLineLists As List(Of Line_no) = oDwg_Ds.Line_nos
1943

    
1944
        Dim oEqpLists As List(Of Eqp_no) = oDwg_Ds.Eqp_nos
1945
        Dim oPipe As Boolean = False
1946
        Dim oFitting As Boolean = False
1947
        Dim oOnlyPipesNode As TreeNode
1948
        Dim oOnlyFittingsNode As TreeNode
1949
        'PipeLine 구분
1950

    
1951
        For Each oLinelist In oLineLists
1952
            Dim sLineNoUid As String = oLinelist.Uid
1953
            Dim sLineNo As String = oLinelist.Text
1954
            Dim oLineNoNode As TreeNode = oParentNode.Nodes.Add(sLineNoUid, sLineNo)
1955
            For Each oLineRow In oLinelist.Dt_Line.Rows
1956
                Dim sLineUid As String = oLineRow(_XML_LINE_UID)
1957
                Dim oPipeNode As TreeNode = oLineNoNode.Nodes.Add(sLineUid, "Pipe")
1958
                oPipeNode.Tag = sLineNoUid
1959
            Next
1960
            For Each oSymbolRow In oLinelist.Dt_Symbol.Rows
1961
                Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID)
1962
                Dim sSymbolName As String = oSymbolRow(_XML_SYMBOL_NAME)
1963
                Dim oSymbolNode As TreeNode = oLineNoNode.Nodes.Add(sSymbolUid, sSymbolName)
1964
                oSymbolNode.Tag = sLineNoUid
1965
            Next
1966
            'If sLineNo <> "PipeLineNo" Then
1967

    
1968
            'Else
1969
            '    'If oPipe = False Then
1970
            '    '    oOnlyPipesNode = oParentNode.Nodes.Add("PipeLineNo", "PipeLineNo")
1971
            '    '    oPipe = True
1972
            '    'End If
1973
            '    'For Each oLineRow In oLinelist.Dt_Line.Rows
1974
            '    '    Dim sLineUid As String = oLineRow(_XML_SYMBOL_UID)
1975
            '    '    Dim oPipeNode As TreeNode = oOnlyPipesNode.Nodes.Add(sLineUid, "Pipe")
1976
            '    '    oPipeNode.Tag = sLineNoUid
1977
            '    'Next
1978

    
1979

    
1980

    
1981

    
1982
            'End If
1983
        Next
1984
        'For Each oSymbolRow In _TempSymbolDt.Rows
1985
        '    If oFitting = False Then
1986
        '        oOnlyFittingsNode = oParentNode.Nodes.Add("Symbols", "Symbols")
1987
        '        oFitting = True
1988
        '    End If
1989
        '    Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID)
1990
        '    Dim sSymbolName As String = oSymbolRow(_XML_SYMBOL_NAME)
1991
        '    Dim oSymbolNode As TreeNode = oOnlyFittingsNode.Nodes.Add(sSymbolUid, sSymbolName)
1992
        '    oSymbolNode.Tag = sSymbolUid
1993
        'Next
1994
        For Each oEqplist In oEqpLists
1995
            Dim sEqpUid As String = oEqplist.Uid
1996
            Dim sEqpNo As String = "EQUIPMENT"
1997
            Dim oEqpNode As TreeNode = oParentNode.Nodes.Add(sEqpUid, sEqpNo)
1998

    
1999

    
2000
            For Each oSymbolRow In oEqplist.Dt_Equipment.Rows
2001
                Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID)
2002
                Dim sSymbolName As String = oSymbolRow(_XML_SYMBOL_NAME)
2003
                Dim oSymbolNode As TreeNode = oEqpNode.Nodes.Add(sSymbolUid, sSymbolName)
2004
                oSymbolNode.Tag = sEqpUid
2005
            Next
2006
        Next
2007
        Return oDwg_Ds
2008
    End Function
2009
    Private Sub Tree_Result_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles Tree_Result.AfterCheck
2010
        If e.Node.Checked = True Then
2011
            For Each oNode As TreeNode In e.Node.Nodes
2012
                oNode.Checked = True
2013
            Next
2014
        Else
2015
            For Each oNode As TreeNode In e.Node.Nodes
2016
                oNode.Checked = False
2017
            Next
2018
        End If
2019
    End Sub
2020

    
2021
    Private Sub Btn_Setting_Click(sender As Object, e As EventArgs) Handles Btn_Setting.Click
2022
        Dim oSettings As Settings = New Settings()
2023
        oSettings.ShowDialog()
2024
    End Sub
2025

    
2026
    Private Sub Btn_TestNozzle_Click(sender As Object, e As EventArgs) Handles Btn_TestNozzle.Click
2027

    
2028
        Dim sVessel_ID As String = "841D5E640AE5421B9A017DDC2E87FF11"
2029
        Dim objVessel As LMVessel
2030
        objVessel = _Placement.PIDDataSource.GetVessel(sVessel_ID)
2031
        Dim oVesselLocation As LMLocations = objVessel.Locations
2032
        Dim symVessel As LMSymbol = _Placement.PIDDataSource.GetSymbol(objVessel.Representations.Nth(1).Id)
2033
        Dim XCoordinate As String = symVessel.Attributes("XCoordinate").Value
2034
        Dim YCoordinate As String = symVessel.Attributes("YCoordinate").Value
2035
        symVessel.Attributes("XCoordinate").Value = XCoordinate + 0.01
2036
        symVessel.Attributes("YCoordinate").Value = YCoordinate + 0.01
2037
        symVessel.Commit()
2038
        Dim sValve_ID As String = "DB7B0CA8A2664A6BA7A9615764BA62B0"
2039
        Dim objValve As LMSymbol
2040
        Dim objValves As LMPipingComp = _Placement.PIDDataSource.GetPipingComp(sValve_ID)
2041

    
2042
        objValve = _Placement.PIDDataSource.GetSymbol(objValves.Representations.Nth(1).Id)
2043
        objValve.Commit()
2044
        Dim dVesselX As Double = XCoordinate
2045
        Dim dVesselY As Double = YCoordinate
2046
        Dim X1 As Double, Y1 As Double, X2 As Double, Y2 As Double
2047

    
2048
        _Placement.PIDConnectPointLocation(objValve, 1, X1, Y1)
2049

    
2050
        _Placement.PIDConnectPointLocation(objValve, 2, X2, Y2)
2051

    
2052
        Dim nozzlename As String = "\Equipment Components\Nozzles\Flanged Nozzle.sym"
2053
        Dim dCalc_x As Double = 0
2054
        Dim dCalc_y As Double = 0
2055

    
2056
        If dVesselX - X2 > 0 Then
2057
            dCalc_x = dVesselX - (dVesselX - X2)
2058
        Else
2059
            dCalc_x = dVesselX + (X2 - dVesselX)
2060
        End If
2061
        If dVesselY - Y2 > 0 Then
2062
            dCalc_y = dVesselY - (dVesselY - Y2)
2063
        Else
2064
            dCalc_y = dVesselY + (Y2 - dVesselY)
2065
        End If
2066

    
2067

    
2068

    
2069

    
2070

    
2071
        Dim objNozzle As LMSymbol = _Placement.PIDPlaceSymbol(nozzlename, dCalc_x, dCalc_y,
2072
            TargetItem:=symVessel.AsLMRepresentation)
2073

    
2074
        Dim blnSuccess As Boolean = _Placement.PIDConnectPointLocation(objNozzle, 1, X1, Y1)
2075
        blnSuccess = _Placement.PIDConnectPointLocation(objNozzle, 2, X1, Y1)
2076

    
2077
        objValve = _Placement.PIDPlaceSymbol(objValve.FileName, X1, Y1, ExistingItem:=objValve.AsLMAItem,
2078
          TargetItem:=objNozzle.AsLMRepresentation)
2079

    
2080

    
2081

    
2082
    End Sub
2083
End Class
2084

    
2085

    
2086
Public Class DrawingInfo
2087
    Public mDrawingName As String
2088
    Public mSpID As String
2089
    Public mPath As String
2090
End Class
2091

    
2092

    
2093

    
2094

    
2095

    
클립보드 이미지 추가 (최대 크기: 500 MB)