프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / Main.vb @ 563df4f4

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

    
21
    Dim _IMG_X = 0
22
    Dim _IMG_Y = 0
23

    
24
    Dim _Unit As String
25

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

    
31
    Private _Main_trd As Thread
32
    Private _Opc_trd As Thread
33

    
34
    Private _CompleteConvert As Boolean = False
35

    
36
    Private _DrawingsList As List(Of Drawing)
37

    
38

    
39
    Private _iPipeLineNocnt As Integer
40
    Private _iPipecnt As Integer
41
    Private _iFittingcnt As Integer
42
    Private _iValvecnt As Integer
43
    Private _iInstrumentcnt As Integer
44
    Private _iEquipmentcnt As Integer
45
    Private _iNozzlecnt As Integer
46

    
47
    Dim _Gembox As New CGembox()
48

    
49

    
50
    Private _allItem As Integer
51
    Private _Itemcnt As Integer
52
    Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
53
        LoadDB()
54
    End Sub
55

    
56
    Private Sub LoadDB()
57
        If My.Settings.DBPath <> "" And My.Settings.Plant_Hierarchy <> "" Then
58
            Dim sDBPath As String = My.Settings.DBPath
59

    
60
            _Gembox.isLoadFile(My.Settings.SymbolLibrary)
61
            _Mapping_DB = _Gembox.LoadFileFunc()
62
            '  _Mapping_DB = Load_DB(sDBPath, _DB_TABLE_MAPPING)
63
            _Attribute_DB = Load_DB(sDBPath, _DB_TABLE_ATTRIBUTE)
64
            _PIDSymbol_DB = Load_DB(sDBPath, _DB_TABLE_SYMBOLNAME)
65
            'TestPID()
66
            'OpenDrawing()
67
        Else
68
            MessageBox.Show("설정값을 먼저 확인해주세요")
69
        End If
70
    End Sub
71

    
72
    Public Function GetDrawingInfo(ByVal errorList As ArrayList)
73
        Dim ds As Llama.LMADataSource
74
        ds = New Llama.LMADataSource
75
        Dim lmaItem As Llama.LMAItem
76
        For i = 0 To errorList.Count - 1
77
            lmaItem = ds.GetModelItem(errorList.Item(i).m_strSPID()).AsLMAItem
78
            Dim drawingInfo As DrawingInfo
79
            drawingInfo = GetDrawingName(lmaItem.ItemType, lmaItem.Id)
80
            errorList.Item(i).m_LMAItem = lmaItem
81
            errorList.Item(i).m_strDrawingName = drawingInfo.mDrawingName
82
            errorList.Item(i).m_strDrawingPath = drawingInfo.mPath
83
        Next
84
    End Function
85
    Private mDataSource As Object
86

    
87
    'Public Sub New()
88

    
89
    '    '  mDataSource.ProjectNumber = m_Information.InfoSite.SiteName
90
    '    '   mDataSource.SiteNode = m_Information.InfoProject.ProjectINI
91
    '    'm_Information = SPPIDClass.Information.GetInstance()
92

    
93
    '    'If m_Information.InfoProject.ProjectVersion = SPPIDClass.InfoProject.SPPID_43 Then
94
    '    '    'SPPID4.3용
95
    '    '    mDataSource.ProjectNumber = m_Information.InfoSite.SiteName
96
    '    'Else
97
    '    '    'SPPID2007, SPPID2009용
98
    '    '    mDataSource.ProjectNumber = m_Information.InfoSite.SiteName & "!" & m_Information.InfoSite.SiteName
99
    '    'End If
100

    
101
    '    '  mDataSource.SiteNode = m_Information.InfoProject.ProjectINI
102
    '    '  mDataSource.ProjectNumber = m_Information.InfoSite.SiteName & "!" & m_Information.InfoSite.SiteName
103
    '    '#If LATE_BINDING Then
104
    '    '        mInstruments = CreateObject("Llama.LMInstruments", "")
105
    '    '        mPipingComps = CreateObject("Llama.LMPipingComps", "")
106
    '    '        mVessels = CreateObject("Llama.LMVessels", "")
107
    '    '        mDrawings = CreateObject("Llama.LMDrawings", "")
108
    '    '        mEquipments = CreateObject("Llama.LMEquipments", "")
109
    '    '        mExchangers = CreateObject("Llama.LMExchangers", "")
110
    '    '        mMechanicals = CreateObject("Llama.LMMechanicals", "")
111
    '    '        mNozzles = CreateObject("Llama.LMNozzles", "")
112
    '    '        mPipeRuns = CreateObject("Llama.LMPipeRuns", "")
113
    '    '        mEquipmentOthers = CreateObject("Llama.LMEquipmentOthers", "")
114
    '    '#Else
115
    '    '        mInstruments = New Llama.LMInstruments
116
    '    '        mPipingComps = New Llama.LMPipingComps
117
    '    '        mVessels = New Llama.LMVessels
118
    '    '        mDrawings = New Llama.LMDrawings
119
    '    '        mEquipments = New Llama.LMEquipments
120
    '    '        mExchangers = New Llama.LMExchangers
121
    '    '        mMechanicals = New Llama.LMMechanicals
122
    '    '        mNozzles = New Llama.LMNozzles
123
    '    '        mPipeRuns = New Llama.LMPipeRuns
124
    '    '        mEquipmentOthers = New Llama.LMEquipmentOthers
125
    '    '#End If
126
    'End Sub
127

    
128
    Function OpenDrawing()
129
        Dim datasource As LMADataSource
130
        Dim objPIDAutoApp As Object
131
        Dim objPIDADrawing As Object
132
        Dim objDrawing As LMDrawing
133
        Dim objDrawings As LMDrawings
134
        datasource = New Llama.LMADataSource
135
        objPIDAutoApp = CreateObject("PIDAutomation.Application")
136
        objDrawings = New Llama.LMDrawings 'New LMDrawings
137
        datasource.SiteNode = "\\desktop-9vlq0dp\Test03Site\smartplantv4.ini"
138
        datasource.ProjectNumber = "SBR_PBR"
139
        objDrawings.Collect(datasource)
140

    
141
        For Each objDrawing In objDrawings
142
            If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
143
                objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(objDrawing.Attributes("Name"))
144
                If Not objPIDADrawing Is Nothing Then
145
                    'MsgBox "Drawing " & objDrawing.Attributes("Name").Value & " is opened!"
146
                    objPIDADrawing.CloseDrawing
147
                End If
148
            End If
149
        Next
150
        objPIDAutoApp.Quit
151
        objPIDAutoApp = Nothing
152
        objPIDADrawing = Nothing
153
        objDrawing = Nothing
154
        objDrawings = Nothing
155
    End Function
156

    
157

    
158
    Public Function GetDrawingName(ByVal itemType As String, ByVal itemName As String) As DrawingInfo
159

    
160
        Dim objFilter As Object
161
        objFilter = CreateObject("Llama.LMAFilter", "")
162

    
163
        Dim drawingInfo As DrawingInfo
164
        drawingInfo = New DrawingInfo
165

    
166
        objFilter.Criteria.AddNew("FirstOne")
167
        objFilter.Criteria.Item("FirstOne").SourceAttributeName = "SP_ID"
168
        objFilter.Critedkria.Item("FirstOne").ValueAttribute = itemName
169

    
170
        objFilter.Criteria.Item("FirstOne").Operator = "="
171
        objFilter.Criteria.AddNew("SecondOne")
172
        objFilter.Criteria.Item("SecondOne").SourceAttributeName = "ItemStatus"
173
        objFilter.Criteria.Item("SecondOne").ValueAttribute = 1
174
        objFilter.Criteria.Item("SecondOne").Operator = "="
175
        objFilter.Criteria.Item("SecondOne").Conjunctive = -1
176
        objFilter.ItemType = itemType
177

    
178
        Dim PlantItems As Object
179
        PlantItems = CreateObject("Llama.LMPlantItems", "")
180
        PlantItems.Collect(mDataSource, Filter:=objFilter)
181

    
182
        If PlantItems.Count = 0 Then
183
            drawingInfo.mSpID = "PlantStockpile"
184
        End If
185

    
186
        For Each PlantItem In PlantItems
187

    
188
            'If Not PlantItem.Representations.Nth(1).DrawingID.Value.ToString().Equals("0") Then
189
            Try
190
                drawingInfo.mDrawingName = PlantItem.Representations.Nth(1).DrawingObject.Attributes("Name").Value
191
                drawingInfo.mSpID = PlantItem.Representations.Nth(1).DrawingID
192
                drawingInfo.mPath = PlantItem.Representations.Nth(1).DrawingObject.Attributes("Path").Value
193
                Debug.WriteLine("DrawingName : " & drawingInfo.mDrawingName & ", SPID : " & drawingInfo.mSpID & ", Path : " & drawingInfo.mPath)
194
            Catch ex As Exception
195

    
196
            End Try
197

    
198
            'End If
199

    
200
        Next
201

    
202
        Return drawingInfo
203

    
204
    End Function
205

    
206
    Private Sub TestPID()
207
        Try
208
            Const CONST_SPID_OPC As String = "426E89964A7F49208AD79E1F320DA251"
209
            Dim datasource As LMADataSource
210
            Dim objPIDAutoApp As Object
211
            Dim objPIDADrawing As Object
212
            Dim objDrawing As LMDrawing
213
            Dim objDrawings As LMDrawings
214
            datasource = New LMADataSource
215
            Dim objOPC As LMOPC
216
            Dim objpairOPC As LMOPC
217
            objOPC = datasource.GetOPC(CONST_SPID_OPC)
218
            objpairOPC = objOPC.pairedWithOPCObject
219
            Dim oObj As Object = Nothing
220
            objDrawing = datasource.GetDrawing(oObj)
221
            objDrawings = New LMDrawings
222
            objDrawings.Collect(datasource)
223
            objPIDAutoApp = GetObject(, "SmartPlantPID.Application") '// CreateObject("PIDAutomation.Application")
224
            For Each objDrawing In objDrawings
225
                If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
226
                    objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(objDrawing.Attributes("Name"))
227
                    If Not objPIDADrawing Is Nothing Then
228
                        MessageBox.Show("Drawing " & objDrawing.Attributes("Name").Value & " is opened!")
229
                        objPIDADrawing.CloseDrawing
230
                    End If
231
                End If
232
            Next
233
            objPIDAutoApp.Quit
234
            objPIDAutoApp = Nothing
235
            objPIDADrawing = Nothing
236
            objDrawing = Nothing
237
            objDrawings = Nothing
238
        Catch ex As Exception
239
        End Try
240
    End Sub
241

    
242
    Public Function SetActiveSiteFromConfigInfo(ByVal strActiveSite As String) As Boolean
243
        On Error GoTo errHandler
244
        Dim objConfigInfo As Object 'interopigrConfigInfo412.igrConfigInfo
245
        objConfigInfo = CreateObject("interopigrConfigInfo412.igrConfigInfo", "")
246
        If Not objConfigInfo Is Nothing Then
247
            objConfigInfo.ApplicationName = "SmartPlantManager"
248
            objConfigInfo.SetConfigString(3, "SmartPlant Manager", "SiteServer", strActiveSite)
249
            SetActiveSiteFromConfigInfo = True
250
        End If
251
        objConfigInfo = Nothing
252
        Exit Function
253
errHandler:
254
        '    LogAndRaiseError ModuleName & "::GetConfigInfo "
255
    End Function
256

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

    
278
            For Each objDrawing In objDrawings
279
                If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
280
                    objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(sPath)
281
                    If Not objPIDADrawing Is Nothing Then
282
                        objPIDADrawing.CloseDrawing
283
                    End If
284
                End If
285
            Next
286

    
287
            Dim extension As String = Path.GetExtension(oDwgName)
288
            oDwgName = oDwgName.Replace(extension, "")
289

    
290
            objPIDAutoApp = CreateObject("PIDAutomation.Application")
291

    
292
            'For Each objDrawing In objPIDAutoApp.Drawings
293
            '    objDrawing.CloseDrawing(True)
294
            'Next
295

    
296
            objPIDAutoApp.Drawings.OpenDrawing(oDwgName + ".pid")
297

    
298
            objPIDAutoApp.ActiveWindow.Fit()
299

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

    
317
    End Function
318

    
319

    
320
    Private Function GetDataFromMappingDB(ByVal sSymbolName As String, ByVal sColumn As String) As String
321
        Dim sValue As String = ""
322
        For Each oDt As DataTable In _Mapping_DB.Tables
323
            If oDt.Rows.Count > 0 Then
324
                Dim oSelectRow() As DataRow = oDt.Select("[img_symbolname] = '" + sSymbolName + "'")
325
                If oSelectRow.Length = 1 Then
326
                    If sColumn = _DB_COLUMN_MAPPING_SPPID_SYMBOLNAME Then
327
                        sValue = oSelectRow(0).Item("SYM FILE NAME").ToString()
328
                    ElseIf sColumn = _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH Then
329
                        sValue = "\" & oSelectRow(0).Item("SYMBOL PATH").ToString() & "\" & oSelectRow(0).Item("SYM FILE NAME").ToString()
330
                    ElseIf sColumn = _DB_COLUMN_MAPPING_SPPID_COMPTPYE Then
331
                        sValue = oSelectRow(0).Item("ITEM TYPE").ToString()
332
                    ElseIf sColumn = _DB_COLUMN_MAPPING_SPPID_CLASS Then
333
                        sValue = oSelectRow(0).Item("CLASS").ToString()
334
                    Else
335
                        sValue = oSelectRow(0).Item("SYMBOL PATH").ToString() & "\" & oSelectRow(0).Item("SYM FILE NAME").ToString()
336
                    End If
337

    
338
                End If
339
            End If
340
        Next
341

    
342
        Return sValue
343
    End Function
344

    
345
    Private Function GetAttributeMapping(ByVal sAttributeName As String, ByVal sColumn As String) As String
346
        Dim sSPPIDAttribute As String = ""
347
        If _Attribute_DB.Rows.Count > 0 Then
348
            Dim oSelectRow() As DataRow = _Attribute_DB.Select("[pid_attribute] = '" + sAttributeName + "'")
349
            If oSelectRow.Length = 1 Then
350
                sSPPIDAttribute = oSelectRow(0).Item(sColumn).ToString()
351
            End If
352
        End If
353
        Return sSPPIDAttribute
354
    End Function
355

    
356
    '  Dim _TempSymbolDt As DataTable = Symbol_Dt()
357

    
358

    
359
    Private Function LoadSymbolInXml(ByVal sXmlPath As String) As Drawing
360
        Try
361
            ''  _TempSymbolDt = Symbol_Dt()
362
            Dim CDrawing As Drawing = New Drawing()
363
            Dim oDt As DataTable = LoadSymbol_DT()
364
            Dim oElement As XElement = XElement.Load(sXmlPath)
365

    
366
            If oElement IsNot Nothing Then
367
                CDrawing.DwgName = oElement.Element(_XML_DWGNAME).Value
368
                CDrawing.Size = oElement.Element(_XML_DWGSIZE).Value
369
                SplitLocation(CDrawing.Size, _IMG_X, _IMG_Y)
370
                CDrawing.Unit = oElement.Element(_XML_UNIT).Value
371

    
372
                Dim oLineno_list As New List(Of Line_no)
373
                Dim oEqp_list As New List(Of Eqp_no)
374

    
375
                For Each oLineNo As Object In oElement.Elements(_XML_CATEGORY_LINENO)
376

    
377
                    Dim CLineNo As Line_no = New Line_no()
378
                    Try
379
                        CLineNo.Uid = oLineNo.Element(_XML_LINENO_UID).Value
380
                        CLineNo.Text = oLineNo.Element(_XML_LINENO_TEXT).Value
381
                        CLineNo.Location = oLineNo.Element(_XML_LINENO_LOCATION).Value
382
                        CLineNo.Angle = oLineNo.Element(_XML_LINENO_ANGLE).Value
383
                        CLineNo.SystemPath = "\Piping\Labels - Piping Segments\Kemya Line Number.sym" 'GetDataFromMappingDB(_XML_CATEGORY_LINENO, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
384
                    Catch ex As Exception
385
                        'CLineNo.Text = "PipeLineNo"
386
                        'CLineNo.Uid = "PipeLineNo"
387
                    End Try
388

    
389

    
390
                    Dim oLine_Dt As DataTable = Line_Dt()
391
                    Dim oSymbol_Dt As DataTable = Symbol_Dt()
392
                    Dim oAttribute_Dt As DataTable = Attribute_Dt()
393

    
394
                    For Each oRun As Object In oLineNo.Elements(_XML_CATEGORY_RUN)
395
                        For Each oLine As Object In oRun.Elements(_XML_CATEGORY_LINE)
396
                            Try
397
                                Dim oAddrow As DataRow = oLine_Dt.NewRow()
398
                                Dim oEleObj As XElement
399
                                Dim sUid As String
400
                                Dim sStartpoint As String
401
                                Dim sEndpoint As String
402
                                oEleObj = oLine.Element(_XML_LINE_UID)
403
                                sUid = oEleObj.Value
404
                                oEleObj = oLine.Element(_XML_LINE_STARTPOINT)
405
                                sStartpoint = oEleObj.Value
406
                                oEleObj = oLine.Element(_XML_LINE_ENDPOINT)
407
                                sEndpoint = oEleObj.Value
408

    
409
                                oAddrow(_XML_LINE_UID) = sUid
410
                                oAddrow(_XML_LINE_STARTPOINT) = sStartpoint
411
                                oAddrow(_XML_LINE_ENDPOINT) = sEndpoint
412
                                oAddrow(_XML_LINE_SYSTEMPATH) = GetDataFromMappingDB(_XML_CATEGORY_LINE, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
413
                                oAddrow(_XML_LINE_DRAWING) = "FALSE"
414
                                oLine_Dt.Rows.Add(oAddrow)
415
                            Catch ex As Exception
416

    
417
                            End Try
418

    
419
                        Next
420

    
421
                        For Each oSymbol As Object In oRun.Elements(_XML_CATEGORY_SYMBOL)
422
                            Try
423
                                Dim oAddrow As DataRow = oSymbol_Dt.NewRow()
424
                                Dim oEleObj As XElement
425
                                Dim sUid As String
426
                                Dim sName As String
427
                                Dim sLocation As String
428
                                Dim sSize As String
429
                                Dim sAngle As String
430
                                Dim sOriginalPoint As String = ""
431
                                oEleObj = oSymbol.Element(_XML_SYMBOL_UID)
432
                                sUid = oEleObj.Value
433
                                oEleObj = oSymbol.Element(_XML_SYMBOL_PARENT)
434
                                sName = oEleObj.Value
435
                                oEleObj = oSymbol.Element(_XML_SYMBOL_LOCATION)
436
                                sLocation = oEleObj.Value
437
                                oEleObj = oSymbol.Element(_XML_SYMBOL_SIZE)
438
                                sSize = oEleObj.Value
439
                                oEleObj = oSymbol.Element(_XML_SYMBOL_ANGLE)
440
                                sAngle = oEleObj.Value
441
                                Try
442
                                    oEleObj = oSymbol.Element(_XML_SYMBOL_ORIGINALPOINT)
443
                                    sOriginalPoint = oEleObj.Value
444
                                Catch ex As Exception
445

    
446
                                End Try
447

    
448
                                oAddrow(_XML_SYMBOL_UID) = sUid
449
                                oAddrow(_XML_SYMBOL_NAME) = IO.Path.GetFileNameWithoutExtension(GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYMBOLNAME))
450
                                oAddrow(_XML_SYMBOL_LOCATION) = sLocation
451
                                oAddrow(_XML_SYMBOL_SIZE) = sSize
452
                                oAddrow(_XML_SYMBOL_ANGLE) = sAngle
453
                                oAddrow(_XML_SYMBOL_SYSTEMPATH) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
454
                                oAddrow(_XML_SYMBOL_TYPE) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_COMPTPYE)
455
                                oAddrow(_XML_SYMBOL_CLASS) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_CLASS)
456
                                oAddrow(_XML_SYMBOL_ORIGINALPOINT) = sOriginalPoint
457

    
458
                                oSymbol_Dt.Rows.Add(oAddrow)
459
                            Catch ex As Exception
460

    
461
                            End Try
462

    
463
                        Next
464

    
465
                        For Each oAtrribute As Object In oRun.Elements(_XML_CATEGORY_ATTRIBUTE)
466
                            Try
467
                                Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
468
                                Dim oEleObj As XElement
469
                                Dim sUid As String
470
                                Dim sName As String
471
                                Dim sValue As String
472

    
473
                                oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
474
                                sUid = oEleObj.Value
475
                                oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
476
                                sName = oEleObj.Value
477
                                oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
478
                                sValue = oEleObj.Value
479

    
480
                                oAddrow(_XML_ATTRIBUTE_UID) = sUid
481
                                oAddrow(_XML_ATTRIBUTE_NAME) = sName
482
                                oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
483
                                oAttribute_Dt.Rows.Add(oAddrow)
484
                            Catch ex As Exception
485

    
486
                            End Try
487

    
488
                        Next
489

    
490
                    Next
491
                    'Line No Attribute
492
                    For Each oAtrribute As Object In oLineNo.Elements(_XML_CATEGORY_ATTRIBUTE)
493
                        Try
494
                            Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
495
                            Dim oEleObj As XElement
496
                            Dim sUid As String = ""
497
                            Dim sName As String
498
                            Dim sValue As String
499

    
500
                            oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
501
                            sUid = oEleObj.Value
502
                            oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
503
                            sName = oEleObj.Value
504
                            oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
505
                            sValue = oEleObj.Value
506
                            oAddrow(_XML_ATTRIBUTE_UID) = sUid
507
                            oAddrow(_XML_ATTRIBUTE_NAME) = sName
508
                            oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
509
                            oAttribute_Dt.Rows.Add(oAddrow)
510
                        Catch ex As Exception
511

    
512
                        End Try
513

    
514
                    Next
515
                    CLineNo.Dt_Line = oLine_Dt
516
                    CLineNo.Dt_Symbol = oSymbol_Dt
517
                    CLineNo.Dt_Attribute = oAttribute_Dt
518
                    oLineno_list.Add(CLineNo)
519
                    'For Each oSymbol As Object In oElement.Elements(_XML_CATEGORY_SYMBOL)
520
                    '    Dim oAddrow As DataRow = _TempSymbolDt.NewRow()
521
                    '    Dim oEleObj As XElement
522
                    '    Dim sUid As String
523
                    '    Dim sName As String
524
                    '    Dim sLocation As String
525
                    '    Dim sSize As String
526
                    '    Dim sAngle As String
527
                    '    Dim sOriginalPoint As String = ""
528
                    '    oEleObj = oSymbol.Element(_XML_SYMBOL_UID)
529
                    '    sUid = oEleObj.Value
530
                    '    oEleObj = oSymbol.Element(_XML_SYMBOL_NAME)
531
                    '    sName = oEleObj.Value
532
                    '    oEleObj = oSymbol.Element(_XML_SYMBOL_LOCATION)
533
                    '    sLocation = oEleObj.Value
534
                    '    oEleObj = oSymbol.Element(_XML_SYMBOL_SIZE)
535
                    '    sSize = oEleObj.Value
536
                    '    oEleObj = oSymbol.Element(_XML_SYMBOL_ANGLE)
537
                    '    sAngle = oEleObj.Value
538
                    '    Try
539
                    '        oEleObj = oSymbol.Element(_XML_SYMBOL_ORIGINALPOINT)
540
                    '        sOriginalPoint = oEleObj.Value
541
                    '    Catch ex As Exception
542

    
543
                    '    End Try
544
                    '    oAddrow(_XML_SYMBOL_UID) = sUid
545
                    '    oAddrow(_XML_SYMBOL_NAME) = sName
546
                    '    oAddrow(_XML_SYMBOL_LOCATION) = sLocation
547
                    '    oAddrow(_XML_SYMBOL_SIZE) = sSize
548
                    '    oAddrow(_XML_SYMBOL_ANGLE) = sAngle
549
                    '    oAddrow(_XML_SYMBOL_SYSTEMPATH) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
550
                    '    oAddrow(_XML_SYMBOL_TYPE) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_COMPTPYE)
551
                    '    oAddrow(_XML_SYMBOL_ORIGINALPOINT) = sOriginalPoint
552
                    '    _TempSymbolDt.Rows.Add(oAddrow)
553
                    'Next
554
                Next
555
                For Each oEqpNo As Object In oElement.Elements(_XML_CATEGORY_EQUIPMENT)
556
                    Dim CEqp_no As Eqp_no = New Eqp_no()
557
                    '    CEqp_no.Uid = oEqpNo.Element(_XML_EQP_UID).Value
558
                    'CEqp_no.Text = oEqpNo.Element(_XML_EQP_TEXT).Value
559
                    'CEqp_no.Location = oEqpNo.Element(_XML_EQP_LOCATION).Value
560
                    '   CEqp_no.Angle = oEqpNo.Element(_XML_EQP_ANGLE).Value
561
                    '  CEqp_no.SystemPath = GetDataFromMappingDB(_XML_CATEGORY_EQUIPMENT, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
562
                    Dim oSymbol_Dt As DataTable = Symbol_Dt()
563
                    Dim oAttribute_Dt As DataTable = Attribute_Dt()
564
                    Dim sUid As String
565
                    For Each oSymbol As Object In oEqpNo.Elements(_XML_CATEGORY_SYMBOL)
566
                        Try
567
                            Dim oAddrow As DataRow = oSymbol_Dt.NewRow()
568
                            Dim oEleObj As XElement
569
                            Dim sName As String
570
                            Dim sLocation As String
571
                            Dim sSize As String
572
                            Dim sAngle As String
573
                            Dim sOriginalPoint As String = ""
574
                            oEleObj = oSymbol.Element(_XML_SYMBOL_UID)
575
                            sUid = oEleObj.Value
576
                            oEleObj = oSymbol.Element(_XML_SYMBOL_NAME)
577
                            sName = oEleObj.Value
578
                            oEleObj = oSymbol.Element(_XML_SYMBOL_LOCATION)
579
                            sLocation = oEleObj.Value
580
                            oEleObj = oSymbol.Element(_XML_SYMBOL_SIZE)
581
                            sSize = oEleObj.Value
582
                            oEleObj = oSymbol.Element(_XML_SYMBOL_ANGLE)
583
                            sAngle = oEleObj.Value
584
                            Try
585
                                oEleObj = oSymbol.Element(_XML_SYMBOL_ORIGINALPOINT)
586
                                sOriginalPoint = oEleObj.Value
587
                            Catch ex As Exception
588
                            End Try
589
                            oAddrow(_XML_SYMBOL_UID) = sUid
590
                            oAddrow(_XML_SYMBOL_NAME) = sName
591
                            oAddrow(_XML_SYMBOL_LOCATION) = sLocation
592
                            oAddrow(_XML_SYMBOL_SIZE) = sSize
593
                            oAddrow(_XML_SYMBOL_ANGLE) = sAngle
594
                            oAddrow(_XML_SYMBOL_SYSTEMPATH) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
595
                            oAddrow(_XML_SYMBOL_TYPE) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_COMPTPYE)
596
                            oAddrow(_XML_SYMBOL_ORIGINALPOINT) = sOriginalPoint
597
                            oSymbol_Dt.Rows.Add(oAddrow)
598
                        Catch ex As Exception
599

    
600
                        End Try
601

    
602
                    Next
603
                    For Each oAtrribute As Object In oEqpNo.Elements(_XML_CATEGORY_ATTRIBUTE)
604
                        Try
605
                            Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
606
                            Dim oEleObj As XElement
607
                            Dim sAttUid As String
608
                            Dim sName As String
609
                            Dim sValue As String
610
                            oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
611
                            sAttUid = oEleObj.Value
612
                            oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
613
                            sName = oEleObj.Value
614
                            oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
615
                            sValue = oEleObj.Value
616
                            oAddrow(_XML_ATTRIBUTE_UID) = sAttUid
617
                            oAddrow(_XML_ATTRIBUTE_NAME) = sName
618
                            oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
619
                            oAttribute_Dt.Rows.Add(oAddrow)
620
                        Catch ex As Exception
621

    
622
                        End Try
623

    
624
                    Next
625
                    CEqp_no.Uid = sUid
626
                    CEqp_no.Dt_Equipment = oSymbol_Dt
627
                    CEqp_no.Dt_Attribute = oAttribute_Dt
628
                    oEqp_list.Add(CEqp_no)
629
                Next
630
                CDrawing.Line_nos = oLineno_list
631
                CDrawing.Eqp_nos = oEqp_list
632
            End If
633
            Return CDrawing
634
        Catch ex As Exception
635
            Return Nothing
636
        End Try
637

    
638
    End Function
639

    
640

    
641

    
642
    'Private Function LoadPipeInXml(ByVal sXmlPath As String) As DataTable
643
    '    Try
644
    '        Dim oDt As DataTable = LoadPipe_DT()
645
    '        Dim oElement As XElement = XElement.Load(sXmlPath)
646
    '        If oElement IsNot Nothing Then
647
    '            Dim DWGElement As XElement = oElement.Element("DWGNAME")
648
    '            Dim DWGNAME = DWGElement.Value
649
    '            Dim sXY As XElement = oElement.Element("SIZE")
650
    '            Dim sSize = sXY.Value
651
    '            Dim oSplitDWGPos As String() = sSize.Split(", ")
652

    
653
    '            If IsNumeric(oSplitDWGPos(0)) Then
654
    '                _IMG_X = Double.Parse(oSplitDWGPos(0))
655
    '            End If
656
    '            If IsNumeric(oSplitDWGPos(1)) Then
657
    '                _IMG_Y = Double.Parse(oSplitDWGPos(1))
658
    '            End If
659

    
660
    '            For Each pipes As Object In oElement.Elements("IMGLINES")
661
    '                For Each pipe As Object In pipes.Elements("IMGLINE")
662
    '                    Dim oAddrow As DataRow = oDt.NewRow()
663
    '                    Dim oObj As XElement = pipe.Element("ITEM")
664
    '                    Dim oItem = oObj.Value
665
    '                    ' Dim oSymbolPath As String = "\" + oSymbol + "\" + oClass + "\" + oType + "\" + oItem + ".sym"
666
    '                    Dim oSymbolPath As String = GetSystemPathFromMappingDB(oItem)
667
    '                    oObj = pipe.Element("START")
668
    '                    Dim oStartPoint = oObj.Value
669
    '                    Dim oSplitPos As String() = oStartPoint.Split(", ")
670
    '                    Dim oStartpos_X As Double = 0.0
671
    '                    Dim oStartpos_Y As Double = 0.0
672
    '                    If IsNumeric(oSplitPos(0)) Then
673
    '                        oStartpos_X = Double.Parse(oSplitPos(0))
674
    '                    End If
675
    '                    If IsNumeric(oSplitPos(1)) Then
676
    '                        oStartpos_Y = Double.Parse(oSplitPos(1))
677
    '                    End If
678

    
679
    '                    ConvertPoint(oStartpos_X, oStartpos_Y, _DWG_X, _DWG_Y)
680
    '                    oObj = pipe.Element("End")
681
    '                    Dim oEndPoint = oObj.Value
682
    '                    oSplitPos = oEndPoint.Split(", ")
683
    '                    Dim oEndpos_X As Double = 0.0
684
    '                    Dim oEndpos_Y As Double = 0.0
685
    '                    If IsNumeric(oSplitPos(0)) Then
686
    '                        oEndpos_X = Double.Parse(oSplitPos(0))
687
    '                    End If
688
    '                    If IsNumeric(oSplitPos(1)) Then
689
    '                        oEndpos_Y = Double.Parse(oSplitPos(1))
690
    '                    End If
691
    '                    ConvertPoint(oEndpos_X, oEndpos_Y, _DWG_X, _DWG_Y)
692

    
693
    '                    oAddrow("start_x") = oStartpos_X '+ 0.05
694
    '                    oAddrow("start_y") = oStartpos_Y
695
    '                    oAddrow("end_x") = oEndpos_X
696
    '                    oAddrow("end_y") = oEndpos_Y
697
    '                    oAddrow("SystemPath") = oSymbolPath
698
    '                    oDt.Rows.Add(oAddrow)
699
    '                Next
700
    '            Next
701

    
702
    '        End If
703

    
704

    
705
    '        Return oDt
706
    '    Catch ex As Exception
707
    '        Return Nothing
708
    '    End Try
709
    'End Function
710

    
711

    
712
    Private Sub ConvertPointByImage(ByRef dX As Double, ByRef dY As Double, ByVal dDwgX As Double, ByVal dDwgY As Double)
713

    
714
        Dim calcx As Double = 0
715
        Dim calcy As Double = 0
716
        calcx = (dX * _DWG_X) / dDwgX 'Math.Round((dX * _DWG_X) / dDwgX, 2)
717
        calcy = _DWG_Y - ((dY * _DWG_Y) / dDwgY) '_DWG_Y - Math.Round((dY * _DWG_Y) / dDwgY, 2)
718
        dX = calcx
719
        dY = calcy
720
    End Sub
721

    
722

    
723
    '@brief Convert To SPPID
724
    '@author : Gyusu Park
725
    '@date : 2018-04-10
726
    '@history:
727

    
728
    Private Sub SplitLocation(ByVal sLocation As String, ByRef dX As Double, ByRef dY As Double)
729

    
730
        Dim opointstr As String() = Split(sLocation, ",")
731
        If (opointstr.Length > 1) Then
732
            If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
733
                dX = opointstr(0)
734
                dY = opointstr(1)
735
            End If
736
        End If
737

    
738
    End Sub
739

    
740

    
741

    
742

    
743

    
744

    
745
    Private Function AutoConverting(ByVal oPipe_Dt As DataTable, ByVal oSymbol_Dt As DataTable, ByVal oTreeNode As TreeNode) As Boolean
746
        Dim iTotalCount As Double = oPipe_Dt.Rows.Count + oSymbol_Dt.Rows.Count
747
        Dim iSymbolcount As Double = 0
748

    
749
        Dim lobjDatasource As Object = _Placement.PIDDataSource
750

    
751
        ' lobjDatasource.BeginTransaction()
752
        '  datasource = objPlacement.PIDDataSource
753
        'Dim iPipecnt As Integer = 0
754
        SetListBoxItems(ListBox_Result, " Auto converting 시작....")
755

    
756
        Dim iPipeCnt As Integer = 0
757
        If oPipe_Dt IsNot Nothing Then
758
            For Each oRow As DataRow In oPipe_Dt.Rows
759
                Dim oposition As String = oRow("position").ToString()
760
                Dim oSymbol As String = oRow("SystemPath").ToString()
761

    
762
                Dim objConnector As LMConnector
763
                Dim objInputs As PlaceRunInputs
764
                objInputs = New PlaceRunInputs
765
                Dim oSplitStr As String() = Split(oposition, " ")
766
                For Each sposition As String In oSplitStr
767
                    Dim opointstr As String() = Split(sposition, ", ")
768

    
769
                    If (opointstr.Length > 1) Then
770
                        If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
771
                            Dim ox As Double = opointstr(0)
772
                            Dim oy As Double = opointstr(1)
773
                            ConvertPointByImage(ox, oy, _IMG_X, _IMG_Y)
774
                            objInputs.AddPoint(ox, oy)
775
                        End If
776
                    End If
777
                Next
778
                Dim objItem As LMAItem
779
                objItem = _Placement.PIDCreateItem(oSymbol)
780
                objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
781
                SetListBoxItems(ListBox_Result, " Place PipeLine...." & "(" & (iPipeCnt + 1) & "/" & oPipe_Dt.Rows.Count)
782
                'Dim objPipeRun As LMPipeRun = datasource.GetPipeRun(objConnector.ModelItemID)
783
                'objPipeRun.Attributes("OperFluidCode").Value = "AFS"
784
                'objPipeRun.Commit()
785
                iSymbolcount = iSymbolcount + 1
786
                iPipeCnt = iPipeCnt + 1
787
            Next
788
        End If
789

    
790
        SetListBoxItems(ListBox_Result, " Place PipeLine....완료")
791

    
792
        Dim iAllInstrumentCnt As Integer = oSymbol_Dt.Select("Name = 'INSTRUMENTATION'").Length
793
                    Dim iValveCnt As Integer = oSymbol_Dt.Select("Class = 'VALVES'").Length
794
        Dim iInstrumentCnt As Integer = 1
795
        Dim iFittingsCnt As Integer = 1
796

    
797
        Dim oInsNode As TreeNode = oTreeNode.Nodes.Find(oTreeNode.Name & "\Instruments", True)(0)
798
        Dim oValveNode As TreeNode = oTreeNode.Nodes.Find(oTreeNode.Name & "\Valves", True)(0)
799
        Dim oFittingsNode As TreeNode = oTreeNode.Nodes.Find(oTreeNode.Name & "\Fittings", True)(0)
800
        For Each oRow As DataRow In oSymbol_Dt.Rows
801

    
802
            Try
803

    
804
                Dim sSystemPath As String = oRow("SystemPath").ToString()
805
                Dim sName As String = oRow("Name").ToString()
806
                Dim sType As String = oRow("Type").ToString()
807
                Dim sText As String = oRow("Text").ToString()
808
                Dim sClass As String = oRow("Class").ToString()
809
                Dim sItem As String = oRow("Item").ToString()
810

    
811
                Dim oX As Double = 0.0
812
                Dim oY As Double = 0.0
813
                If IsNumeric(oRow("x").ToString()) Then
814
                    oX = Double.Parse(oRow("x").ToString())
815
                End If
816
                If IsNumeric(oRow("y").ToString()) Then
817
                    oY = Double.Parse(oRow("y").ToString())
818
                End If
819
                Dim oAngle As Double = 0.0
820
                If IsNumeric(oRow("Angle").ToString()) Then
821
                    oAngle = Double.Parse(oRow("Angle").ToString())
822
                End If
823
                '   oSymbol = "\INSTRUMENTation\SYSTEM FUNCTIONS\D C S\DCS FUNC ACCESS IN PRIME LOC.sym"
824
                If sSystemPath <> "" Then
825
                    If sName = _TYPE_Instumentation Then
826

    
827
                        Dim sTagsuffix As String = ""
828
                        Dim sTagSequenceNo As String = ""
829
                        Dim sMeasuredVariableCode As String = ""
830
                        Dim sInstrumentTypeModifier As String = ""
831

    
832
                        If sText <> "" Then
833
                            If sText.Contains(",") Then
834
                                Dim splitstr() As String = sText.Split(",")
835
                                For i = 0 To splitstr.Count - 1
836
                                    If i = 0 Then
837
                                        sMeasuredVariableCode = Mid(splitstr(i), 1, 1)
838
                                        sTagSequenceNo = Mid(splitstr(i), 2, Len(splitstr(i)))
839
                                    Else
840
                                        If Len(splitstr(i)) = 1 Then
841
                                            sInstrumentTypeModifier = splitstr(i)
842
                                        ElseIf Len(splitstr(i)) = 0 Then
843

    
844
                                        ElseIf Len(splitstr(i)) > 1 Then
845
                                            sInstrumentTypeModifier = Mid(splitstr(i), 1, 1)
846
                                            sTagsuffix = Mid(splitstr(i), 2, Len(splitstr(i)))
847
                                        End If
848
                                    End If
849
                                Next
850
                            Else
851
                                sMeasuredVariableCode = Mid(sText, 1, 1)
852
                                sTagSequenceNo = Mid(sText, 2, Len(sText))
853
                            End If
854

    
855
                        End If
856

    
857
                        Dim objInstrSym As LMSymbol
858
                        objInstrSym = _Placement.PIDPlaceSymbol(sSystemPath, oX, oY, , oAngle)
859
                        SetListBoxItems(ListBox_Result, " Place Instrument...." & "(" & (iInstrumentCnt + 1) & "/" & iAllInstrumentCnt & ")")
860

    
861
                        ' SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sTagSequenceNo)
862
                        Dim action As Action = Sub()
863
                                                   oInsNode.Nodes.Add(sClass & "-" & iInstrumentCnt)
864
                                                   oInsNode.ExpandAll()
865
                                               End Sub
866
                        oInsNode.TreeView.Invoke(action)
867

    
868

    
869
                        Dim objInstr As LMInstrument
870
                        objInstr = lobjDatasource.GetInstrument(objInstrSym.ModelItemID)
871

    
872
                        Dim objItem As LMAItem
873
                        objItem = _Placement.PIDCreateItem(sSystemPath)
874

    
875

    
876
                        objInstr.Attributes("MeasuredVariableCode").Value = sMeasuredVariableCode
877
                        objInstr.Attributes("InstrumentTypeModifier").Value = sInstrumentTypeModifier
878
                        objInstr.Attributes("TagSuffix").Value = sTagsuffix
879
                        objInstr.Attributes("TagSequenceNo").Value = sTagSequenceNo
880
                        objInstr.Commit()
881
                        iInstrumentCnt = iInstrumentCnt + 1
882
                    ElseIf sName = "GATE VALVE WITH PLUG" Then
883

    
884
                    ElseIf sName = "MEDIUM 1D 1TO1" Then
885

    
886
                    ElseIf sClass = "VALVES" Then
887
                        Dim action As Action = Sub()
888
                                                   oValveNode.ExpandAll()
889
                                                   oValveNode.Nodes.Add(sClass & "-" & iValveCnt)
890
                                               End Sub
891
                        oValveNode.TreeView.Invoke(action)
892

    
893
                        _Placement.PIDPlaceSymbol(sSystemPath, oX, oY, , oAngle)
894

    
895
                        iValveCnt = iValveCnt + 1
896
                    Else
897
                        Dim action As Action = Sub()
898
                                                   oFittingsNode.ExpandAll()
899
                                                   oFittingsNode.Nodes.Add(sClass & "-" & iFittingsCnt)
900
                                               End Sub
901
                        oFittingsNode.TreeView.Invoke(action)
902
                        _Placement.PIDPlaceSymbol(sSystemPath, oX, oY, , oAngle)
903

    
904
                        iFittingsCnt = iFittingsCnt + 1
905

    
906
                    End If
907
                    iSymbolcount = iSymbolcount + 1
908
                Else
909
                End If
910
            Catch ex As Exception
911

    
912
            End Try
913
            Dim dCalcProgressValue As Double = (iSymbolcount / iTotalCount) * 100
914
            SetProgressbar(ProgressBar_Status, dCalcProgressValue)
915
            '     ProgressBar_Status.Value = (iSymbolcount / iTotalCount) * 100
916

    
917
        Next
918

    
919
        MsgBox("Complete AutoConverting")
920
        SetListBoxItems(ListBox_Result, "Place Instrument....변환완료")
921
        SetListBoxItems(ListBox_Result, "총 symbol:  " & iSymbolcount & "개 변환완료")
922
        SetProgressbar(ProgressBar_Status, 100)
923

    
924
        ' MsgBox("symbol: " & iSymbolcount & "개, pipe : " & iPipecnt & "개 변환완료")
925
    End Function
926

    
927

    
928
    Private Sub Tree_XMLFiles_AfterCheck(sender As Object, e As TreeViewEventArgs)
929
        If e.Node.Checked = True Then
930
            For Each oNode As TreeNode In e.Node.Nodes
931
                oNode.Checked = True
932
            Next
933
        Else
934
            For Each oNode As TreeNode In e.Node.Nodes
935
                oNode.Checked = False
936
            Next
937
        End If
938
    End Sub
939

    
940
    Private Function Load_DB(ByVal sDBPath As String, ByVal sTableName As String) As DataTable
941

    
942
        Try
943
            Dim oDt As New DataTable
944
            Dim sConnectionstring As String = "Data Source=" & sDBPath & ";Version=3;Synchronous=Off;UTF8Encoding=True;"
945
            Dim conn As SQLiteConnection = New SQLiteConnection(sConnectionstring)
946
            conn.Open()
947
            Dim sQuery As String = "Select * from " & sTableName
948
            Dim cmd As SQLiteCommand = conn.CreateCommand()
949
            Dim adapter As SQLiteDataAdapter = New SQLiteDataAdapter(sQuery, conn)
950
            Dim oDataSet As DataSet = New DataSet()
951
            adapter.Fill(oDataSet)
952
            oDt = oDataSet.Tables(0)
953
            Return oDt
954
        Catch ex As Exception
955
            Return Nothing
956
        End Try
957

    
958

    
959
    End Function
960

    
961
    Private Sub Load_AttributeDB(ByVal sDBPath As String)
962

    
963
        Try
964
            Dim sConnectionstring As String = "Data Source=" & sDBPath & ";Version=3;Synchronous=Off;UTF8Encoding=True;"
965
            Dim conn As SQLiteConnection = New SQLiteConnection(sConnectionstring)
966
            conn.Open()
967
            Dim sQuery As String = "Select * from Attribute"
968
            Dim cmd As SQLiteCommand = conn.CreateCommand()
969
            Dim adapter As SQLiteDataAdapter = New SQLiteDataAdapter(sQuery, conn)
970
            Dim oDataSet As DataSet = New DataSet()
971
            adapter.Fill(oDataSet)
972
            _Attribute_DB = oDataSet.Tables(0)
973
        Catch ex As Exception
974

    
975
        End Try
976

    
977

    
978
    End Sub
979

    
980
    'Private Sub Tree_XMLFiles_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles Tree_XMLFiles.AfterSelect
981
    '    If first_start = False Then Exit Sub
982
    '    Dim pa = e.Node.FullPath.ToString
983

    
984
    '    printfilesfolders_here(pa, e.Node)
985

    
986
    '    displayfiles(pa)
987

    
988
    '    Dim coco As String = ""
989
    '    coco = pa.ToString
990
    '    coco = coco.Replace("\\", "\")
991
    '    Me.Text = coco
992
    '    folders_path = coco
993
    'End Sub
994

    
995
    Sub printfilesfolders_here(ByVal path As String, ByRef itree As TreeNode)
996

    
997
        Dim foldername As String
998
        Dim filename As String
999
        itree.Nodes.Clear()
1000
        On Error GoTo eee
1001
        For Each foldername In Directory.GetDirectories(path)
1002
            On Error GoTo eee
1003
            Dim jj = foldername.LastIndexOf("\")
1004
            Dim jj1 = foldername.Length - jj
1005
            Dim foldr = foldername.Substring((jj + 1), (jj1 - 1))
1006
            itree.Nodes.Add(foldr, foldr)
1007
        Next ' if you put this next at the end of procedure recursive will be done on first folder only
1008
        Exit Sub
1009
eee:
1010
    End Sub
1011

    
1012

    
1013

    
1014
    '    Private Sub Tree_XMLFiles_MouseMove(sender As Object, e As MouseEventArgs) Handles Tree_XMLFiles.MouseMove
1015
    '        first_start = True
1016
    '    End Sub
1017

    
1018
    '    Private Sub ListView_File_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView_File.SelectedIndexChanged
1019
    '        Dim indexes As ListView.SelectedIndexCollection =
1020
    '                         Me.ListView_File.SelectedIndices
1021
    '        Dim index As Integer
1022

    
1023
    '        For Each index In indexes
1024
    '            'On Error Resume Next
1025
    '            If folders_path.EndsWith("\") = True Then
1026
    '                Me.Status_Main.Items(0).Text = folders_path + (Me.ListView_File.Items(index).Text)
1027
    '                'On Error Resume Next
1028
    '            Else
1029
    '                Me.Status_Main.Items(0).Text = folders_path + "\" + (Me.ListView_File.Items(index).Text)
1030
    '            End If
1031

    
1032
    '            Dim infoReader As System.IO.FileInfo
1033
    '            infoReader = My.Computer.FileSystem.GetFileInfo(Me.Status_Main.Items(0).Text)
1034
    '            Me.Status_Main.Items(1).Text = " Created : " + infoReader.CreationTime.ToString + " " + infoReader.Attributes.ToString
1035
    '        Next
1036
    '    End Sub
1037

    
1038
    '    Private Sub Procees()
1039
    '        Dim indexes As ListView.SelectedIndexCollection =
1040
    '                            Me.ListView_File.SelectedIndices
1041
    '        Dim index As Integer
1042

    
1043
    '        For Each index In indexes
1044
    '            'On Error Resume Next
1045
    '            If folders_path.EndsWith("\") = True Then
1046
    '                On Error GoTo out
1047
    '                Me.Status_Main.Items(0).Text = folders_path + (Me.ListView_File.Items(index).Text)
1048
    '                On Error GoTo out
1049
    '                'On Error Resume Next
1050
    '            Else
1051
    '                Me.Status_Main.Items(0).Text = folders_path + "\" + (Me.ListView_File.Items(index).Text)
1052
    '                On Error GoTo out
1053
    '            End If
1054

    
1055
    '            Dim infoReader As System.IO.FileInfo
1056
    '            infoReader = My.Computer.FileSystem.GetFileInfo(Me.Status_Main.Items(0).Text)
1057
    '            Me.Status_Main.Items(1).Text = " Created : " + infoReader.CreationTime.ToString + " " + infoReader.Attributes.ToString
1058
    '            On Error GoTo out
1059
    '            MsgBox(Me.Status_Main.Items(0).Text + " is processed")
1060
    '            On Error GoTo out
1061
    '        Next
1062
    '        Exit Sub
1063
    'out:
1064
    '        MsgBox(Err.Description)
1065
    'End Sub
1066

    
1067
    Private Function LoadAllDrawing() As DataTable
1068

    
1069

    
1070
        SetListBoxItems(ListBox_Result, "도면정보 로드중....")
1071

    
1072
        Dim oDt As DataTable = Drawing_Dt()
1073
        Dim sHierarchy As String = My.Settings.Plant_Hierarchy
1074

    
1075

    
1076
        Dim files() As String
1077
        files = Directory.GetFiles(sHierarchy, "*.pid", SearchOption.AllDirectories)
1078
        For Each FileName As String In files
1079
            Dim sName As String = FileName
1080
            Dim oAddRow As DataRow = oDt.NewRow()
1081
            oAddRow("Name") = Path.GetFileNameWithoutExtension(sName)
1082
            oAddRow("Path") = FileName
1083
            oDt.Rows.Add(oAddRow)
1084
        Next
1085
        Return oDt
1086
    End Function
1087

    
1088
    Private Function LoadAllDrawing2() As DataTable
1089
        Dim datasource As LMADataSource
1090
        Dim objPIDAutoApp As Object
1091
        Dim objPIDADrawing As Object
1092
        Dim objDrawing As Object 'Drawing
1093
        'Dim objDrawing As LMDrawing
1094
        'Dim objDrawings As LMDrawings
1095

    
1096
        datasource = New LMADataSource
1097

    
1098
        '    objDrawings = New LMDrawings
1099
        'objDrawings.Collect(datasource)
1100
        objPIDAutoApp = CreateObject("PIDAutomation.Application")
1101

    
1102
        For Each objDrawing In objPIDAutoApp.Drawings
1103
            objDrawing.CloseDrawing(True)
1104
        Next
1105
        Try
1106
            objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("UY1-K-2000_P1_300dpi_0321_TEST_1")
1107
        Catch ex As Exception
1108
            Process.Start("\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\Plant_Hierarchy\8121\8121-1\UY1-K-2000_P1_300dpi_0321_TEST_1.pid")
1109
        End Try
1110

    
1111

    
1112

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

    
1117
        objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("1")
1118

    
1119
        For Each objDrawing In objPIDAutoApp.Drawings
1120
            If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
1121
                Try
1122

    
1123
                    Dim sName As String = objDrawing.Attributes("Name").Value
1124

    
1125
                    iCount = iCount + 1
1126
                    If sName = "UY1-K-2000_P1_300dpi_0321_TEST_1" Then
1127
                        objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(objDrawing.Attributes("Name"))
1128
                        objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("\8121\8121-1\UY1-K-2000_P1_300dpi_0321_TEST_1.pid")
1129
                        If Not objPIDADrawing Is Nothing Then
1130
                            objPIDADrawing.CloseDrawing()
1131
                        End If
1132
                    End If
1133

    
1134

    
1135
                Catch ex As Exception
1136

    
1137
                End Try
1138

    
1139
            End If
1140
        Next
1141
        objPIDAutoApp.Quit
1142
        objPIDAutoApp = Nothing
1143
        objPIDADrawing = Nothing
1144
        objDrawing = Nothing
1145
        '   objDrawings = Nothing
1146
    End Function
1147

    
1148
    Dim _XMLList As ListView = New ListView()
1149

    
1150

    
1151

    
1152

    
1153

    
1154

    
1155
    Private Function CheckOpenDrawing() As Boolean
1156
        Try
1157

    
1158
            Dim lobjDatasource As Object
1159
            _Placement = CreateObject("Plaice.Placement", "")
1160
            lobjDatasource = _Placement.PIDDataSource
1161
            Return True
1162
        Catch ex As Exception
1163
            Return False
1164
        End Try
1165

    
1166
    End Function
1167

    
1168

    
1169
    Private Sub Btn_Convert_Click(sender As Object, e As EventArgs) Handles Btn_Convert.Click
1170

    
1171
        Main_Tab.SelectedIndex = 1
1172
        ListBox_Result.Items.Clear()
1173
        ' DataGrid_Result.DataSource = New DataTable()
1174
        Me.ProgressBar_Status.Visible = True
1175
        ProgressBar_Status.Maximum = 100
1176
        ProgressBar_Status.Value = 0
1177
        ' _selectFolderPath = Tree_XMLFiles.SelectedNode.FullPath.Replace("\\", "\")
1178
        _Main_trd = New Thread(AddressOf ThreadConvert)
1179
        _Main_trd.IsBackground = True
1180
        _Main_trd.Start()
1181
        FineOPCForm()
1182
    End Sub
1183

    
1184
    Private Sub FineOPCForm()
1185
        _Opc_trd = New Thread(AddressOf ThreadOPCRemove)
1186
        _Opc_trd.IsBackground = True
1187
        _Opc_trd.Start()
1188
    End Sub
1189

    
1190
    'Private Sub ThreadTask()
1191

    
1192

    
1193
    '    If _XMLList.Items.Count > 0 Then
1194

    
1195
    '        Dim oDwg_Dt As DataTable = LoadAllDrawing()
1196
    '        Dim iDwgCnt As Integer = 0
1197
    '        Dim objPIDAutoApp As Object
1198
    '        objPIDAutoApp = CreateObject("PIDAutomation.Application")
1199

    
1200

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

    
1204
    '            Dim sDwgName As String = Path.GetFileNameWithoutExtension(myList(i))
1205
    '            Txt_Status.Text = sDwgName & "..(" & i + 1 & "/" & myList.Count & ")"
1206
    '            SetListBoxItems(ListBox_Result, Txt_Status.Text & " 처리중....")
1207
    '            Dim sDwgNo As String = myList(i)
1208
    '            Dim oDwgPath As String = ""
1209
    '            oDwgPath = _selectFolderPath + "\" + sDwgNo
1210

    
1211
    '            Dim sPath As String = OpenDrawing(oDwg_Dt, sDwgName)
1212
    '            If sPath <> "" Then
1213

    
1214
    '                Process.Start(sPath)
1215

    
1216
    '                Dim bCheckOpenDrawing As Boolean = False
1217
    '                While (True)
1218
    '                    bCheckOpenDrawing = CheckOpenDrawing()
1219
    '                    If bCheckOpenDrawing = True Then
1220
    '                        Exit While
1221
    '                    Else
1222
    '                        Thread.Sleep(2000)
1223
    '                    End If
1224
    '                End While
1225

    
1226
    '                If bCheckOpenDrawing Then
1227
    '                    SetListBoxItems(ListBox_Result, sDwgName & " 도면 Open....")
1228
    '                    Dim oPipe_Dt As DataTable = New DataTable() 'LoadPipeInXml(oDwgPath)
1229

    
1230
    '                    Dim oSymbol_Dt As DataTable = LoadSymbolInXml(oDwgPath)
1231
    '                    Dim oTreeNode As New TreeNode  'SetTreeViewItems(Tree_Result, Tree_Result.Nodes, sDwgName, sDwgName)
1232
    '                    'oTreeNode = Tree_Result.Nodes.Find(sDwgName, True)(0)
1233
    '                    Dim action As Action = Sub()
1234
    '                                               oTreeNode = Tree_Result.Nodes.Add(sDwgName, sDwgName)
1235
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Instruments", "Instuments")
1236
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Pipes", "Pipes")
1237
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Valves", "Valves")
1238
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Fittings", "Fittings")
1239
    '                                               oTreeNode.ExpandAll()
1240
    '                                           End Sub
1241
    '                    Tree_Result.Invoke(action)
1242

    
1243

    
1244
    '                    '    oTreeNode.Expand()
1245
    '                    SetListBoxItems(ListBox_Result, sDwgName & " Auto converting 대기....")
1246
    '                    AutoConverting(oPipe_Dt, oSymbol_Dt, oTreeNode)
1247

    
1248
    '                End If
1249

    
1250
    '            End If
1251
    '            ''도면 생성
1252
    '            'If CreateDwg(sDwgName) Then
1253
    '            '    'AutoConverting
1254

    
1255
    '            'End If
1256

    
1257
    '        Next
1258
    '    End If
1259
    'End Sub
1260

    
1261
    Dim _objPIDAutoApp As Object
1262

    
1263
    Private Function OpenSPPID(ByVal oDwg_Dt As DataTable, ByVal sDwgName As String) As Boolean
1264
        Dim bCheckOpen As Boolean = False
1265
        '   Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgPath)
1266
        SetListBoxItems(ListBox_Result, sDwgName & " 도면 Open....")
1267
        _objPIDAutoApp = CreateObject("PIDAutomation.Application")
1268

    
1269
        Dim sPath As String = OpenDrawing(oDwg_Dt, sDwgName)
1270
        If sPath <> "" Then
1271
            Process.Start(sPath)
1272
        Else
1273
            Return bCheckOpen
1274
        End If
1275

    
1276
            Dim bCheckOpenDrawing As Boolean = False
1277
            While (True)
1278
                bCheckOpenDrawing = CheckOpenDrawing()
1279
                If bCheckOpenDrawing = True Then
1280
                    bCheckOpen = True
1281
                    Exit While
1282
                Else
1283
                    Thread.Sleep(2000)
1284
                End If
1285
            End While
1286

    
1287

    
1288
            Return bCheckOpen
1289
    End Function
1290

    
1291
    Private Function GetDrawing(ByVal sDwgName As String) As Drawing
1292
        For Each CDrawing In _DrawingsList
1293
            If CDrawing.DwgName.ToUpper() = sDwgName.ToUpper() Then
1294
                Return CDrawing
1295
            End If
1296
        Next
1297
        Return Nothing
1298
    End Function
1299

    
1300
    Private Function GetLineNo(ByVal CDrawing As Drawing, ByVal sLineNoUid As String) As Line_no
1301
        For Each CLineNo In CDrawing.Line_nos
1302
            If CLineNo.Uid = sLineNoUid Then
1303
                Return CLineNo
1304
            End If
1305
        Next
1306
        Return Nothing
1307
    End Function
1308

    
1309
    Private Function GetOnlyPipeLineNo(ByVal CDrawing As Drawing, ByVal sPipeUid As String) As Line_no
1310
        For Each CLineNo In CDrawing.Line_nos
1311
            Dim odt As DataTable = CLineNo.Dt_Line
1312
            If odt.Rows.Count > 0 Then
1313
                If odt.Rows(0)(_XML_LINE_UID).ToString = sPipeUid Then
1314
                    Return CLineNo
1315
                End If
1316
            End If
1317
        Next
1318
        Return Nothing
1319
    End Function
1320

    
1321

    
1322
    Private Function GetEqpNo(ByVal CDrawing As Drawing, ByVal sEqpUid As String) As Eqp_no
1323
        For Each CEqpNo In CDrawing.Eqp_nos
1324
            If CEqpNo.Uid = sEqpUid Then
1325
                Return CEqpNo
1326
            End If
1327
        Next
1328
        Return Nothing
1329
    End Function
1330
    Private Function ConvertPointBystring(ByVal sPoint As String, ByRef dX As Double, ByRef dY As Double) As Boolean
1331
        Try
1332
            Dim opointstr As String() = Split(sPoint, ",")
1333
            If (opointstr.Length > 1) Then
1334
                If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
1335
                    dX = opointstr(0)
1336
                    dY = opointstr(1)
1337

    
1338
                Else
1339
                    dX = 0
1340
                    dY = 0
1341
                    Return False
1342
                End If
1343
            End If
1344
            Return True
1345
        Catch ex As Exception
1346
            Return False
1347
        End Try
1348
    End Function
1349

    
1350

    
1351
    Dim _DrawLine_Dt As DataTable = DrawLind_Dt()
1352

    
1353
    Private Function DrawLine(ByVal sUid As String, ByVal sLineNoUid As String, ByVal oLine_Dt As DataTable, ByVal oAttribute_Dt As DataTable) As LMPipeRun
1354
        Try
1355
            Dim oPipeRun As LMPipeRun
1356
            Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_UID & " = '" + sUid + "'")
1357
            Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
1358

    
1359
            If oPipeRow.Length > 0 Then
1360
                Dim oDatasource As Object = _Placement.PIDDataSource
1361
                Dim objItem As LMAItem
1362
                Dim objConnector As LMConnector
1363
                Dim objInputs As PlaceRunInputs
1364
                objInputs = New PlaceRunInputs
1365
                Dim dOriginalStart_x As Double = 0.0
1366
                Dim dOriginalStart_y As Double = 0.0
1367
                Dim dOriginalEnd_x As Double = 0.0
1368
                Dim dOriginalEnd_y As Double = 0.0
1369
                Dim dStart_x As Double = 0.0
1370
                Dim dStart_y As Double = 0.0
1371
                Dim dEnd_x As Double = 0.0
1372
                Dim dEnd_y As Double = 0.0
1373
                Dim sSystempath As String = "\Piping\Routing\Process Lines\Primary Piping.sym" ' oPipeRow(0)(_XML_LINE_SYSTEMPATH).ToString()
1374
                Dim sStartpoint As String = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
1375
                Dim sEndpoint As String = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
1376
                Dim sPipeUid As String = oPipeRow(0)(_XML_LINE_UID).ToString()
1377

    
1378
                ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
1379
                dStart_x = dOriginalStart_x
1380
                dStart_y = dOriginalStart_y
1381

    
1382
                If ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y) Then
1383
                    dEnd_x = dOriginalEnd_x
1384
                    dEnd_y = dOriginalEnd_y
1385

    
1386
                    '   라인보정(oLine_Dt, sPipeUid, dStart_x, dStart_y, dEnd_x, dEnd_y)
1387
                    '//Overlap 보정
1388
                    'If FindOverlapLine(oLine_Dt, sPipeUid, dStart_x, dStart_y, dEnd_x, dEnd_y) = False Then
1389
                    '    '//떨어진 라인 보정
1390
                    '    Dim dSeperate_start_x As Double = dStart_x
1391
                    '    Dim dSeperate_start_y As Double = dStart_y
1392
                    '    Dim dSeperate_end_x As Double = dEnd_x
1393
                    '    Dim dSeperate_end_y As Double = dEnd_y
1394
                    '    CalcSperateLine(dSeperate_start_x, dSeperate_start_y, dSeperate_end_x, dSeperate_end_y)
1395
                    '    If (FindOverlapLine(oLine_Dt, sPipeUid, dSeperate_start_x, dSeperate_start_y, dSeperate_end_x, dSeperate_end_y)) Then
1396
                    '        dStart_x = dSeperate_start_x
1397
                    '        dStart_y = dSeperate_start_y
1398
                    '        dEnd_x = dSeperate_end_x
1399
                    '        dEnd_y = dSeperate_end_y
1400
                    '    End If
1401
                    'End If
1402

    
1403
                    ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
1404
                    ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
1405
                    If dStart_x <> 0 And dStart_y <> 0 And dEnd_x <> 0 And dEnd_y <> 0 Then
1406

    
1407
                        Dim iConnType As Integer = ModelingLine(dStart_x, dStart_y, dEnd_x, dEnd_y, sUid)
1408
                        If iConnType = 1 Then
1409
                            objInputs.AddLocatedTarget(dStart_x, dStart_y)
1410
                            objInputs.AddPoint(dEnd_x, dEnd_y)
1411
                        ElseIf iConnType = 2 Then
1412
                            objInputs.AddLocatedTarget(dEnd_x, dEnd_y)
1413
                            objInputs.AddPoint(dStart_x, dStart_y)
1414
                        ElseIf iConnType = 3 Then
1415
                            objInputs.AddLocatedTarget(dEnd_x, dEnd_y)
1416
                            objInputs.AddPoint(dStart_x, dStart_y)
1417
                        ElseIf iConnType = 4 Then
1418
                            objInputs.AddLocatedTarget(dStart_x, dStart_y)
1419
                            objInputs.AddPoint(dEnd_x, dEnd_y)
1420
                        Else
1421
                            objInputs.AddPoint(dStart_x, dStart_y)
1422
                            objInputs.AddPoint(dEnd_x, dEnd_y)
1423
                        End If
1424
                        objInputs.AddPoint(dStart_x, dStart_y)
1425
                        objInputs.AddPoint(dEnd_x, dEnd_y)
1426
                        AddModelingLine(dStart_x, dStart_y, dEnd_x, dEnd_y, sUid)
1427
                        objItem = _Placement.PIDCreateItem(sSystempath)
1428
                        _iPipecnt = _iPipecnt + 1
1429
                        SetListBoxItems(ListBox_Result, "Place PipeLine..(" & dOriginalStart_x & "," & dOriginalStart_y & ") - (" & dOriginalEnd_x & "," & dOriginalEnd_y & ").." & _iPipecnt & " count ")
1430
                        objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
1431
                        oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
1432
                        oPipeRun.Attributes("FlowDirection").Value = "End 1 is upstream (Inlet)"
1433
                        If oAttributeRow.Length > 0 Then
1434
                            For Each oAttribute In oAttributeRow
1435
                                Try
1436
                                    Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
1437
                                    Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
1438
                                    Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
1439
                                    oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
1440
                                Catch ex As Exception
1441

    
1442
                                End Try
1443

    
1444

    
1445
                            Next
1446
                            oPipeRun.Commit()
1447
                        End If
1448
                        'Flow Direction 
1449
                        'Dim sFlowDirectionPath As String = GetDataFromMappingDB(_XML_CATEGORY_FLOWDIRECITON, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
1450
                        'Dim dFlowDirectionAngle As Double = 0.0
1451
                        'If dStart_y <> dEnd_y Then
1452
                        '    If dStart_y > dEnd_y Then
1453
                        '        dFlowDirectionAngle = -1.57
1454
                        '    Else
1455
                        '        dFlowDirectionAngle = 1.57
1456
                        '    End If
1457
                        'End If
1458
                        'If dStart_x <> dEnd_x Then
1459
                        '    If dStart_x > dEnd_x Then
1460
                        '        dFlowDirectionAngle = 3.14
1461
                        '    Else
1462
                        '        dFlowDirectionAngle = 0
1463
                        '    End If
1464
                        'End If
1465

    
1466
                        '_Placement.PIDPlaceSymbol(sFlowDirectionPath, dEnd_x, dEnd_y, , dFlowDirectionAngle)
1467
                    End If
1468
                End If
1469
                _Itemcnt = _Itemcnt + 1
1470
                Dim dCalcProgressValue As Double = (_Itemcnt / _allItem) * 100
1471
                SetProgressbar(ProgressBar_Status, dCalcProgressValue)
1472
                Label_Progress.Text = Math.Round(dCalcProgressValue, 0) & "%"
1473
            End If
1474
            Return oPipeRun
1475
        Catch ex As Exception
1476
            Return Nothing
1477
        End Try
1478
    End Function
1479

    
1480
    Private Sub AddModelingLine(ByVal dStart_x As Double, ByVal dStart_y As Double, ByVal dEnd_x As Double, ByVal dEnd_y As Double, ByVal sUid As String)
1481
        Dim oAddRow = _DrawLine_Dt.NewRow()
1482
        oAddRow(_XML_LINE_UID) = sUid
1483
        oAddRow(_XML_LINE_STARTPOINT_X) = dStart_x
1484
        oAddRow(_XML_LINE_STARTPOINT_Y) = dStart_y
1485
        oAddRow(_XML_LINE_ENDPOINT_X) = dEnd_x
1486
        oAddRow(_XML_LINE_ENDPOINT_Y) = dEnd_y
1487
        _DrawLine_Dt.Rows.Add(oAddRow)
1488
    End Sub
1489

    
1490

    
1491
    Private Function ModelingLine(ByVal dStart_x As Double, ByVal dStart_y As Double, ByVal dEnd_x As Double, ByVal dEnd_y As Double, ByVal sUid As String) As Integer
1492
        'Dim oFindRows_1 As DataRow() = _DrawLine_Dt.Select("start_x = '" & dStart_x & "' and start_y = '" & dStart_y & "' and uid <> '" & sUid & "'")
1493

    
1494
        'Dim oFindRows_2 As DataRow() = _DrawLine_Dt.Select("end_x = '" & dEnd_x & "' and end_y = '" & dEnd_y & "' and uid <> '" & sUid & "'")
1495

    
1496
        'Dim oFindRows_3 As DataRow() = _DrawLine_Dt.Select("start_x = '" & dEnd_x & "' and start_y = '" & dEnd_y & "' and uid <> '" & sUid & "'")
1497

    
1498
        'Dim oFindRows_4 As DataRow() = _DrawLine_Dt.Select("end_x = '" & dStart_x & "' and end_y = '" & dStart_y & "' and uid <> '" & sUid & "'")
1499

    
1500
        'If oFindRows_1.Length > 0 Then
1501
        '    Return 1
1502
        'ElseIf oFindRows_2.Length > 0 Then
1503
        '    Return 2
1504
        'ElseIf oFindRows_3.Length > 0 Then
1505
        '    Return 3
1506
        'ElseIf oFindRows_4.Length > 0 Then
1507
        '    Return 4
1508
        'Else
1509
        '    Return 0
1510
        'End If
1511
        Return 0
1512
    End Function
1513

    
1514
    Private Function FindConnectionPoint(ByVal dX As Double, ByVal dY As Double)
1515

    
1516

    
1517
    End Function
1518

    
1519
    Private Sub PlaceEquipment(ByVal sUid As String, ByVal oSymbol_Dt As DataTable, ByVal oAttribute_Dt As DataTable)
1520
        Try
1521
            Dim oSymbolRow() As DataRow = oSymbol_Dt.Select(_XML_SYMBOL_UID & " = '" + sUid + "'")
1522
            Dim oAttributeRow() As DataRow
1523
            If oAttribute_Dt.Rows.Count > 0 Then
1524
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
1525
            End If
1526
            If oSymbolRow.Length > 0 Then
1527
                Dim oDatasource As Object = _Placement.PIDDataSource
1528
                Dim sSymbolCompType As String = oSymbolRow(0)(_XML_SYMBOL_TYPE).ToString()
1529
                Dim sSystemPath As String = oSymbolRow(0)(_XML_SYMBOL_SYSTEMPATH).ToString()
1530
                Dim sClass As String = oSymbolRow(0)(_XML_SYMBOL_CLASS).ToString()
1531
                Dim sLocation As String = oSymbolRow(0)(_XML_SYMBOL_LOCATION).ToString()
1532
                Dim sOriginalPoint As String = oSymbolRow(0)(_XML_SYMBOL_ORIGINALPOINT).ToString()
1533
                Dim dAngle As Double = 0.0
1534
                If IsNumeric(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString()) Then
1535
                    dAngle = Double.Parse(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString())
1536
                End If
1537
                Dim dLocationX As Double = 0.0
1538
                Dim dLocationY As Double = 0.0
1539
                Dim dX As Double = 0.0
1540
                Dim dY As Double = 0.0
1541

    
1542
                If ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY) Then
1543
                    dX = dLocationX
1544
                    dY = dLocationY
1545
                    ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1546
                    _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1547
                    SetListBoxItems(ListBox_Result, "Place Equipment..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1548
                End If
1549
            End If
1550
        Catch ex As Exception
1551

    
1552
        End Try
1553

    
1554

    
1555
    End Sub
1556

    
1557
    Private Function DrawSymbol(ByVal sUid As String, ByVal sLineNoUid As String, ByVal oSymbol_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal oLine_Dt As DataTable) As Boolean
1558
        Try
1559

    
1560
            Dim oSymbolRow() As DataRow = oSymbol_Dt.Select(_XML_SYMBOL_UID & " = '" + sUid + "'")
1561
            Dim oAttributeRow() As DataRow
1562
            If oAttribute_Dt.Rows.Count > 0 Then
1563
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
1564
            End If
1565

    
1566
            If oSymbolRow.Length > 0 Then
1567
                Dim oDatasource As Object = _Placement.PIDDataSource
1568
                Dim sSymbolCompType As String = oSymbolRow(0)(_XML_SYMBOL_TYPE).ToString()
1569
                Dim sSystemPath As String = oSymbolRow(0)(_XML_SYMBOL_SYSTEMPATH).ToString()
1570
                Dim sClass As String = oSymbolRow(0)(_XML_SYMBOL_CLASS).ToString()
1571
                Dim sLocation As String = oSymbolRow(0)(_XML_SYMBOL_LOCATION).ToString()
1572
                Dim sOriginalPoint As String = oSymbolRow(0)(_XML_SYMBOL_ORIGINALPOINT).ToString()
1573
                Dim dAngle As Double = 0.0
1574
                If IsNumeric(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString()) Then
1575
                    dAngle = Double.Parse(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString())
1576
                End If
1577

    
1578
                Dim objSymbol As LMSymbol
1579
                Dim dLocationX As Double = 0.0
1580
                Dim dLocationY As Double = 0.0
1581
                Dim dX As Double = 0.0
1582
                Dim dY As Double = 0.0
1583

    
1584
                If ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY) Then
1585
                    dX = dLocationX
1586
                    dY = dLocationY
1587
                    If sSymbolCompType = "" Or sSymbolCompType = "Piping OPC's" Then
1588
                        FindConnectionLine(oLine_Dt, dX, dY)
1589
                    End If
1590

    
1591
                    ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1592
                        Dim oInstrument As LMInstrument
1593
                    If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
1594
                        _iInstrumentcnt = _iInstrumentcnt + 1
1595
                        objSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1596
                        SetListBoxItems(ListBox_Result, "Place Instrument..(" & dLocationX & "," & dLocationY & ")..." & _iInstrumentcnt & " count ")
1597
                        oInstrument = oDatasource.GetInstrument(objSymbol.ModelItemID)
1598
                        Try
1599
                            If oAttributeRow.Length > 0 Then
1600
                                For Each oAttribute In oAttributeRow
1601
                                    Try
1602
                                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
1603
                                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
1604
                                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
1605
                                        oInstrument.Attributes(sSPPIDAttribute).Value = sPIDValue
1606
                                    Catch ex As Exception
1607

    
1608
                                    End Try
1609

    
1610
                                Next
1611
                                oInstrument.Commit()
1612
                            End If
1613
                        Catch ex As Exception
1614
                        End Try
1615
                    ElseIf sSymbolCompType.ToUpper() = _DB_FITTINGS.ToUpper() Then
1616
                        _iValvecnt = _iValvecnt + 1
1617
                        _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1618
                        SetListBoxItems(ListBox_Result, "Place Valve..(" & dLocationX & "," & dLocationY & ")..." & _iValvecnt & " count ")
1619

    
1620
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_FITTINGS.ToUpper() Then
1621
                        _iFittingcnt = _iFittingcnt + 1
1622
                        If sSystemPath.Contains(",") Then
1623

    
1624
                            Dim sDuplicatePath As String() = sSystemPath.Split(",")
1625
                            Dim sMainSymbol As String = ""
1626
                            Dim sSubSymbol As String = ""
1627
                            For Each sPath In sDuplicatePath
1628
                                If sMainSymbol = "" Then
1629
                                    sMainSymbol = sPath.Replace(vbLf, "")
1630
                                Else
1631
                                    sSubSymbol = sPath.Replace(vbLf, "")
1632
                                End If
1633
                            Next
1634
                            Dim oSymbolObj As LMSymbol = _Placement.PIDPlaceSymbol(sMainSymbol, dX, dY, , dAngle)
1635
                            Dim dConnpos_x As Double = 0.0
1636
                            Dim dConnpos_y As Double = 0.0
1637
                            _Placement.PIDConnectPointLocation(oSymbolObj, 2, dConnpos_x, dConnpos_y)
1638
                            '   _Placement.PIDPlaceSymbol(sSubSymbol, dConnpos_x, dConnpos_y, dAngle, TargetItem:=oSymbolObj.AsLMRepresentation)
1639
                            _Placement.PIDPlaceSymbol(sSubSymbol, dConnpos_x, dConnpos_y,, dAngle)
1640

    
1641
                        Else
1642
                            _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1643
                        End If
1644

    
1645

    
1646
                        SetListBoxItems(ListBox_Result, "Place Fitting..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1647
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() And sClass.ToUpper() = _SYMBOL_ACTUATORS.ToUpper() Then
1648
                        _iFittingcnt = _iFittingcnt + 1
1649
                        Dim sDuplicatePath As String() = sSystemPath.Split(",")
1650
                        Dim sMainSymbol As String = ""
1651
                        Dim sSubSymbol As String = ""
1652
                        For Each sPath In sDuplicatePath
1653
                            If sMainSymbol = "" Then
1654
                                sMainSymbol = sPath.Replace(vbLf, "")
1655
                            Else
1656
                                sSubSymbol = sPath.Replace(vbLf, "")
1657
                            End If
1658
                        Next
1659
                        Dim oSymbolObj As LMSymbol = _Placement.PIDPlaceSymbol(sMainSymbol, dX, dY, , dAngle)
1660
                        Dim dSymbolpos_x As Double = oSymbolObj.XCoordinate
1661
                        Dim dSymbolpos_y As Double = oSymbolObj.YCoordinate
1662
                        _Placement.PIDPlaceSymbol(sSubSymbol, dSymbolpos_x, dSymbolpos_y, , dAngle, TargetItem:=oSymbolObj.AsLMAItem)
1663

    
1664
                    Else
1665
                        _iFittingcnt = _iFittingcnt + 1
1666
                        _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1667
                        SetListBoxItems(ListBox_Result, "Place Fitting..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1668
                        End If
1669

    
1670
                    End If
1671
                _Itemcnt = _Itemcnt + 1
1672
                Dim dCalcProgressValue As Double = (_Itemcnt / _allItem) * 100
1673
                SetProgressbar(ProgressBar_Status, dCalcProgressValue)
1674
                Label_Progress.Text = Math.Round(dCalcProgressValue, 0) & "%"
1675
            End If
1676

    
1677
        Catch ex As Exception
1678
            Return False
1679
        End Try
1680
    End Function
1681

    
1682

    
1683
    Private Sub FindConnectionLine(ByVal oLine_Dt As DataTable, ByRef dx As Double, ByRef dy As Double)
1684

    
1685
        Try
1686
            For Each oRow In oLine_Dt.Rows
1687
                Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1688
                Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1689
                Dim d기준s_x As Double = 0
1690
                Dim d기준s_y As Double = 0
1691
                Dim d기준e_x As Double = 0
1692
                Dim d기준e_y As Double = 0
1693
                ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1694
                ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1695
                If dx + 300 > d기준s_x And dx - 300 < d기준s_x And dy + 300 > d기준s_y And dy - 300 < d기준s_y Then
1696
                    dx = d기준s_x
1697
                    dy = d기준s_y
1698
                ElseIf dx + 300 > d기준e_x And dx - 300 < d기준e_x And dy + 300 > d기준e_y And dy - 300 < d기준e_y Then
1699
                    dx = d기준e_x
1700
                    dy = d기준e_y
1701
                End If
1702
            Next
1703
        Catch ex As Exception
1704
        End Try
1705
    End Sub
1706

    
1707

    
1708
    Dim _라인보정기준값 As Integer = 10
1709

    
1710
    Private Function 라인보정(ByRef oLine_Dt As DataTable, ByVal sUid As String, ByRef dsx As Double, ByRef dsy As Double,
1711
                                      ByRef dex As Double, ByRef dey As Double)
1712
        Try
1713
            Dim bCheck라인 As Boolean = False
1714
            '일치하는 Line 찾기
1715
            For Each oRow In oLine_Dt.Rows
1716
                Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1717
                Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1718
                Dim sBUid As String = oRow(_XML_LINE_UID).ToString()
1719
                If sBUid <> sUid Then
1720
                    Dim d기준s_x As Double = 0
1721
                    Dim d기준s_y As Double = 0
1722
                    Dim d기준e_x As Double = 0
1723
                    Dim d기준e_y As Double = 0
1724
                    ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1725
                    ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1726

    
1727
                    If (dsx = d기준s_x And dsy = d기준s_y) Or (dsx = d기준e_x And dsy = d기준e_y) Or
1728
                       (dex = d기준s_x And dey = d기준s_y) Or (dex = d기준e_x And dey = d기준e_y) Then
1729
                        bCheck라인 = True
1730
                    End If
1731
                End If
1732
            Next
1733

    
1734
            If bCheck라인 = False Then
1735
                For Each oRow In oLine_Dt.Rows
1736
                    Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1737
                    Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1738
                    Dim sBUid As String = oRow(_XML_LINE_UID).ToString()
1739
                    If sBUid <> sUid Then
1740
                        Dim d기준s_x As Double = 0
1741
                        Dim d기준s_y As Double = 0
1742
                        Dim d기준e_x As Double = 0
1743
                        Dim d기준e_y As Double = 0
1744
                        ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1745
                        ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1746
                        If ((dsx - _라인보정기준값 <= d기준s_x And dsx + _라인보정기준값 >= d기준s_x) And (dsy - _라인보정기준값 <= d기준s_y And dsy + _라인보정기준값 >= d기준s_y)) Then
1747
                            oRow(_XML_LINE_STARTPOINT) = dsx & "," & dsy
1748
                            bCheck라인 = True
1749
                            Exit For
1750
                        ElseIf ((dsx - _라인보정기준값 <= d기준e_x And dsx + _라인보정기준값 >= d기준e_x) And (dsy - _라인보정기준값 <= d기준e_y And dsy + _라인보정기준값 >= d기준e_y)) Then
1751
                            oRow(_XML_LINE_ENDPOINT) = dsx & "," & dsy
1752
                            bCheck라인 = True
1753
                            Exit For
1754
                        ElseIf ((dex - _라인보정기준값 <= d기준s_x And dex + _라인보정기준값 >= d기준s_x) And (dey - _라인보정기준값 <= d기준s_y And dey + _라인보정기준값 >= d기준s_y)) Then
1755
                            oRow(_XML_LINE_STARTPOINT) = dex & "," & dey
1756
                            bCheck라인 = True
1757
                            Exit For
1758
                        ElseIf ((dex - _라인보정기준값 <= d기준e_x And dex + _라인보정기준값 >= d기준e_x) And (dey - _라인보정기준값 <= d기준e_y And dey + _라인보정기준값 >= d기준e_y)) Then
1759
                            oRow(_XML_LINE_ENDPOINT) = dex & "," & dey
1760
                            bCheck라인 = True
1761
                            Exit For
1762
                        End If
1763

    
1764
                    End If
1765
                Next
1766
            End If
1767

    
1768
            Return bCheck라인
1769
        Catch ex As Exception
1770
            Return False
1771
        End Try
1772

    
1773

    
1774
    End Function
1775

    
1776
    Private Function FindOverlapLine(ByVal oLine_Dt As DataTable, ByVal sUid As String, ByRef dsx As Double, ByRef dsy As Double,
1777
                                      ByRef dex As Double, ByRef dey As Double)
1778
        Try
1779
            Dim bCheckOverlap As Boolean = False
1780
            For Each oRow In oLine_Dt.Rows
1781
                Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1782
                Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1783
                Dim sBUid As String = oRow(_XML_LINE_UID).ToString()
1784
                If sBUid <> sUid Then
1785
                    Dim d기준s_x As Double = 0
1786
                    Dim d기준s_y As Double = 0
1787
                    Dim d기준e_x As Double = 0
1788
                    Dim d기준e_y As Double = 0
1789
                    ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1790
                    ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1791
                    If (d기준s_x <= dsx And d기준e_x >= dex And
1792
                        d기준s_y <= dsy And d기준e_y >= dey) Then
1793
                        '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1794
                        If dsy - d기준s_y > d기준e_y - dey Then
1795
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1796
                            If dResultCalc < 10 Then
1797
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1798
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1799
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1800
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1801
                                If dCalcStartY = 0 Then
1802
                                    dey = d기준e_y
1803
                                Else
1804
                                    dey = dCalcStartY
1805
                                End If
1806
                            End If
1807
                        Else
1808
                            '  Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1809
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1810
                            If dResultCalc < 10 Then
1811
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1812
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1813
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1814
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1815
                                If dCalcStartY = 0 Then
1816
                                    dsy = d기준s_y
1817
                                Else
1818
                                    dsy = dCalcStartY
1819
                                End If
1820
                            End If
1821
                        End If
1822
                        bCheckOverlap = True
1823
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
1824
                            d기준s_y <= dey And d기준e_y >= dsy Then
1825
                        '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1826
                        If dey - d기준s_y > d기준e_y - dsy Then
1827
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1828
                            If dResultCalc < 10 Then
1829
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1830
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1831
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1832
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1833
                                If dCalcStartY = 0 Then
1834
                                    dsy = d기준e_y
1835
                                Else
1836
                                    dsy = dCalcStartY
1837
                                End If
1838

    
1839
                            End If
1840
                            '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1841
                        Else
1842
                            '  Dim dResultCalc As Double = (Math.Abs((dsy - d기준s_y)) / Math.Abs((d기준e_y - dey))) * 100
1843
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1844
                            If dResultCalc < 10 Then
1845
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1846
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1847
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1848
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1849
                                If dCalcStartY = 0 Then
1850
                                    dey = d기준e_y
1851
                                Else
1852
                                    dey = dCalcStartY
1853
                                End If
1854
                            End If
1855
                        End If
1856
                        bCheckOverlap = True
1857
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
1858
                            d기준s_y <= dey And d기준e_y >= dsy Then
1859

    
1860
                        If dsx - d기준s_x > d기준e_x - dex Then
1861
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1862
                            If dResultCalc < 10 Then
1863
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1864
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1865
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1866
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1867
                                If dCalcStartX = 0 Then
1868
                                    dex = d기준e_x
1869
                                Else
1870
                                    dex = dCalcStartX
1871
                                End If
1872
                            End If
1873
                        Else
1874
                            '  Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1875
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1876
                            If dResultCalc < 10 Then
1877
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1878
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1879
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1880
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1881
                                If dCalcStartX = 0 Then
1882
                                    dsx = d기준s_x
1883
                                Else
1884
                                    dsx = dCalcStartX
1885
                                End If
1886
                            End If
1887
                        End If
1888
                        bCheckOverlap = True
1889
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
1890
                            d기준s_y <= dey And d기준e_y >= dsy Then
1891

    
1892
                        If dex - d기준s_x > d기준e_x - dsx Then
1893
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1894
                            If dResultCalc < 10 Then
1895
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1896
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1897
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1898
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1899
                                If dCalcStartX = 0 Then
1900
                                    dsx = d기준e_x
1901
                                Else
1902
                                    dsx = dCalcStartX
1903
                                End If
1904
                            End If
1905
                        Else
1906
                            ' Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1907
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1908
                            If dResultCalc < 10 Then
1909
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1910
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1911
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1912
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1913
                                If dCalcStartX = 0 Then
1914
                                    dex = d기준s_x
1915
                                Else
1916
                                    dex = dCalcStartX
1917
                                End If
1918
                            End If
1919

    
1920
                        End If
1921
                        bCheckOverlap = True
1922
                    End If
1923
                End If
1924
            Next
1925
            Return bCheckOverlap
1926
        Catch ex As Exception
1927
            Return False
1928
        End Try
1929
    End Function
1930

    
1931
    Private Sub CalcSperateLine(ByRef dStartX As Double, ByRef dStartY As Double,
1932
                                      ByRef dEndX As Double, ByRef dEndY As Double)
1933
        Try
1934
            Dim dRange As Double = 1 'Line 전체 길이의 10%씩 늘이기
1935
            If Math.Abs(dStartX - dEndX) > Math.Abs(dStartY - dEndY) Then
1936
                Dim dCalc_x As Double = Math.Abs(dStartX - dEndX) * 0.1
1937
                If dStartX > dEndX Then
1938
                    dStartX = dStartX + dCalc_x
1939
                    dEndX = dEndX - dCalc_x
1940
                Else
1941
                    dEndX = dEndX + dCalc_x
1942
                    dStartX = dStartX - dCalc_x
1943
                End If
1944
            Else
1945
                Dim dCalc_y As Double = Math.Abs(dStartY - dEndY) * 0.1
1946
                If dStartY > dEndY Then
1947
                    dStartY = dStartY + dCalc_y
1948
                    dEndY = dEndY - dCalc_y
1949
                Else
1950
                    dEndY = dEndY + dCalc_y
1951
                    dStartY = dStartY - dCalc_y
1952
                End If
1953
            End If
1954

    
1955

    
1956

    
1957
        Catch ex As Exception
1958

    
1959
        End Try
1960

    
1961

    
1962
    End Sub
1963

    
1964
    Private Function DrawLineNo(ByVal oPiperun As LMPipeRun, ByVal CLine_No As Line_no) As Boolean
1965
        Try
1966
            Dim oDatasource As Object = _Placement.PIDDataSource
1967
            Dim sLocation = CLine_No.Location
1968
            Dim dLocationx As Double = 0.0
1969
            Dim dLocationy As Double = 0.0
1970

    
1971
            Dim dX As Double = 0.0
1972
            Dim dY As Double = 0.0
1973
            If ConvertPointBystring(sLocation, dLocationx, dLocationy) Then
1974
                dX = dLocationx
1975
                dY = dLocationy
1976
                ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1977
                Dim dLineNoLocation(2) As Double
1978
                dLineNoLocation(1) = dX
1979
                dLineNoLocation(2) = dY
1980
                'Label
1981
                Dim sSystemPath As String = CLine_No.SystemPath
1982
                Dim dAngle As Double = CLine_No.Angle
1983
                Dim labelpersist As LMLabelPersist
1984

    
1985
                For Each representation In oPiperun.Representations
1986
                    If representation.RepresentationType = "Connector" Then
1987
                        labelpersist = _Placement.PIDPlaceLabel(sSystemPath,
1988
                        dLineNoLocation,, dAngle, LabeledItem:=representation)
1989
                        _iPipeLineNocnt = _iPipeLineNocnt + 1
1990
                        SetListBoxItems(ListBox_Result, "Place PipeLineNo Label..(" & dLocationx & "," & dLocationy & ")..." & _iPipeLineNocnt & " count ")
1991
                    End If
1992
                Next
1993
                Return True
1994
            Else
1995
                Return False
1996
            End If
1997

    
1998
        Catch ex As Exception
1999
            Return False
2000
        End Try
2001
    End Function
2002

    
2003

    
2004
    Private Sub InitItemCount()
2005
        _iPipeLineNocnt = 0
2006
        _iPipecnt = 0
2007
        _iFittingcnt = 0
2008
        _iValvecnt = 0
2009
        _iInstrumentcnt = 0
2010
        _iEquipmentcnt = 0
2011
        _iNozzlecnt = 0
2012
    End Sub
2013

    
2014
    Private Function GetAllCheckNodeCount() As Integer
2015
        _allItem = 0
2016
        For i = 0 To Tree_Result.Nodes.Count - 1
2017
            For j = 0 To Tree_Result.Nodes(i).Nodes.Count - 1
2018
                For k = 0 To Tree_Result.Nodes(i).Nodes(j).Nodes.Count - 1
2019
                    For l = 0 To Tree_Result.Nodes(i).Nodes(j).Nodes(k).Nodes.Count - 1
2020
                        If Tree_Result.Nodes(i).Nodes(j).Nodes(k).Nodes(l).Checked = True Then
2021
                            _allItem = _allItem + 1
2022
                        End If
2023
                    Next
2024
                Next
2025
            Next
2026
        Next
2027
        Return _allItem
2028
    End Function
2029

    
2030

    
2031
    Private Function AutoModeling() As Boolean
2032
        Try
2033
            _CompleteConvert = False
2034
            Label_Progress.Text = "0%"
2035
            SetListBoxItems(ListBox_Result, " Auto converting 시작....")
2036
            Dim oDwg_Dt As DataTable = LoadAllDrawing()
2037
            _allItem = GetAllCheckNodeCount()
2038
            For Each oDrwing As TreeNode In Tree_Result.Nodes
2039
                For Each oDwgNode As TreeNode In oDrwing.Nodes
2040
                    Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
2041
                    Dim CDrawing As Drawing = GetDrawing(sDwgName)
2042
                    If CDrawing IsNot Nothing Then
2043
                        If OpenSPPID(oDwg_Dt, oDwgNode.Text) Then
2044
                            InitItemCount()
2045
                            Dim iAllLineNoCount As Integer = Tree_Result.Nodes.Count ' GetCheckNodeCount(oLinenoNode)
2046
                            Dim iLineNoCount As Integer = 0 ' GetCheckNodeCount(oLinenoNode)
2047
                            SetListBoxItems(ListBox_Result, "Place " & CDrawing.DwgName & "....")
2048
                            For Each oNode As TreeNode In oDwgNode.Nodes
2049
                                Dim iItemcnt As Integer = 0
2050
                                Dim sNodeUid As String = oNode.Name
2051
                                If sNodeUid <> "PipeLineNo" Then
2052
                                    Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
2053
                                    If CLineNo IsNot Nothing Then
2054
                                        Dim oPipeRun As LMPipeRun = Nothing
2055
                                        Dim oLine_Dt As DataTable = CLineNo.Dt_Line
2056
                                        Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
2057
                                        Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
2058
                                        Dim oDrawLinenoLabel As Boolean = False
2059
                                        For Each oLineNode As TreeNode In oNode.Nodes
2060
                                            Dim oRun As LMPipeRun = Nothing
2061
                                            iItemcnt = iItemcnt + 1
2062
                                            Dim sLineUid As String = oLineNode.Name
2063
                                            If oLineNode.Checked Then
2064
                                                Dim sUid As String = oLineNode.Name
2065
                                                If oLine_Dt.Select("[" & _XML_LINE_UID & "]= '" & sUid & "'").Length = 1 Then
2066
                                                    oRun = DrawLine(sUid, sNodeUid, oLine_Dt, oAttribute_Dt)
2067
                                                    If oPipeRun Is Nothing Then
2068
                                                        oPipeRun = oRun
2069
                                                    End If
2070
                                                End If
2071
                                                    'If oDrawLinenoLabel = False Then
2072
                                                    '    DrawLineNo(oPipeRun, CLineNo)
2073
                                                    'End If
2074
                                                    oDrawLinenoLabel = True
2075
                                            End If
2076
                                            If oNode.Nodes.Count - 1 = iItemcnt And oDrawLinenoLabel Then
2077
                                                Try
2078
                                                    DrawLineNo(oPipeRun, CLineNo)
2079
                                                Catch ex As Exception
2080

    
2081
                                                End Try
2082

    
2083
                                            End If
2084
                                        Next
2085
                                        For Each oSymbolNode As TreeNode In oNode.Nodes
2086
                                            If oSymbolNode.Checked Then
2087
                                                Dim sUid As String = oSymbolNode.Name
2088
                                                If oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "]= '" & sUid & "'").Length = 1 Then
2089
                                                    DrawSymbol(sUid, sNodeUid, oSymbol_Dt, oAttribute_Dt, CLineNo.Dt_Line)
2090
                                                End If
2091
                                            End If
2092
                                        Next
2093
                                        iLineNoCount = iLineNoCount + 1
2094
                                    End If
2095
                                    Dim CEqpNo As Eqp_no = GetEqpNo(CDrawing, sNodeUid)
2096
                                    If CEqpNo IsNot Nothing Then
2097
                                        Dim oSymbol_Dt As DataTable = CEqpNo.Dt_Equipment
2098
                                        Dim oAttribute_Dt As DataTable = CEqpNo.Dt_Attribute
2099
                                        For Each oSymbolNode As TreeNode In oNode.Nodes
2100
                                            If oSymbolNode.Checked Then
2101
                                                Dim sUid As String = oSymbolNode.Name
2102
                                                PlaceEquipment(sUid, oSymbol_Dt, oAttribute_Dt)
2103
                                                ' DrawSymbol(sUid, sNodeUid, oSymbol_Dt, oAttribute_Dt, CLineNo.Dt_Line)
2104
                                            End If
2105
                                        Next
2106
                                    End If
2107
                                Else
2108
                                    Dim oDrawLinenoLabel As Boolean = False
2109
                                    For Each oLineNode As TreeNode In oNode.Nodes
2110
                                        Dim CLineNo As Line_no = GetOnlyPipeLineNo(CDrawing, oLineNode.Name)
2111
                                        Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
2112
                                        Dim oLine_Dt As DataTable = CLineNo.Dt_Line
2113
                                        Dim sLineUid As String = oLineNode.Name
2114
                                        If oLineNode.Checked Then
2115
                                            Dim sUid As String = oLineNode.Name
2116
                                            DrawLine(sUid, sNodeUid, oLine_Dt, oAttribute_Dt)
2117
                                        End If
2118
                                    Next
2119
                                End If
2120

    
2121

    
2122

    
2123
                            Next
2124
                        End If
2125
                    End If
2126
                Next
2127
            Next
2128
            SetProgressbar(ProgressBar_Status, 100)
2129
            Label_Progress.Text = "100%"
2130
            SetListBoxItems(ListBox_Result, " Auto converting 완료")
2131
            _CompleteConvert = True
2132
            Return True
2133
        Catch ex As Exception
2134
            Return False
2135
        End Try
2136
    End Function
2137

    
2138

    
2139

    
2140
    Private Sub ThreadConvert()
2141
        If _DrawingsList IsNot Nothing Then
2142
            If _DrawingsList.Count > 0 Then
2143
                AutoModeling()
2144
            End If
2145
        End If
2146
    End Sub
2147

    
2148
    Private Sub ThreadOPCRemove()
2149
        While _CompleteConvert = False
2150
            Dim oFindOPC As New FindOpc
2151
            oFindOPC.RemoveOPCDlg()
2152
        End While
2153

    
2154
    End Sub
2155

    
2156

    
2157
    Private Function OpenDrawing(ByVal oDt As DataTable, ByVal sDwgName As String) As String
2158
        Dim oRows As DataRow() = oDt.Select("[Name] = '" & sDwgName & "'")
2159
        Dim oPath As String = ""
2160
        If oRows.Length > 0 Then
2161
            oPath = oRows(0).Item("Path").ToString()
2162
        End If
2163
        Return oPath
2164
    End Function
2165

    
2166
    Private Sub LoadXmlToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LoadXmlToolStripMenuItem.Click
2167
        If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
2168
            LoadDB()
2169
            LoadXmlItem(FolderBrowserDialog1.SelectedPath)
2170
        End If
2171
    End Sub
2172
    Private Sub LoadXmlItem(ByVal sFolderPath As String)
2173
        _DrawingsList = New List(Of Drawing)
2174
        Dim sfileEntries As String() = Directory.GetFiles(sFolderPath)
2175
        If Tree_Result.Nodes.Count > 0 Then
2176
            Tree_Result.Nodes(0).Nodes.Clear()
2177
            For Each sfileName In sfileEntries
2178
                Dim sExtension As String = Path.GetExtension(sfileName)
2179
                If sExtension = ".xml" Then
2180
                    Dim sDwgName As String = Path.GetFileNameWithoutExtension(sfileName)
2181
                    Dim sDwgPath As String = sfileName
2182
                    Dim oNode As TreeNode = Tree_Result.Nodes(0).Nodes.Add(sDwgPath, sDwgName, 15)
2183
                    Dim oDwg As Drawing = AddSymbolItem(sDwgPath, oNode)
2184
                    _DrawingsList.Add(oDwg)
2185
                End If
2186
            Next
2187
            Tree_Result.Nodes(0).Expand()
2188
        End If
2189
    End Sub
2190

    
2191

    
2192
    ''' <summary>
2193
    '''  XML Tree 구조 생성 
2194
    ''' </summary>
2195
    ''' <param name="sDwgPath"></param>
2196
    Private Function AddSymbolItem(ByVal sDwgPath As String, ByVal oParentNode As TreeNode) As Drawing
2197
        Dim oDwg_Ds As Drawing = LoadSymbolInXml(sDwgPath)
2198
        If oDwg_Ds IsNot Nothing Then
2199
            Dim oLineLists As List(Of Line_no) = oDwg_Ds.Line_nos
2200

    
2201
            Dim oEqpLists As List(Of Eqp_no) = oDwg_Ds.Eqp_nos
2202
            Dim oPipe As Boolean = False
2203
            Dim oFitting As Boolean = False
2204
            Dim oOnlyPipesNode As TreeNode
2205
            Dim oOnlyFittingsNode As TreeNode
2206
            'PipeLine 구분
2207

    
2208
            For Each oLinelist In oLineLists
2209
                Dim sLineNoUid As String = oLinelist.Uid
2210
                Dim sLineNo As String = oLinelist.Text
2211
                Dim oLineNoNode As TreeNode = oParentNode.Nodes.Add(sLineNoUid, sLineNo)
2212
                For Each oLineRow In oLinelist.Dt_Line.Rows
2213
                    Dim sLineUid As String = oLineRow(_XML_LINE_UID)
2214
                    Dim oPipeNode As TreeNode = oLineNoNode.Nodes.Add(sLineUid, "Pipe")
2215
                    oPipeNode.Tag = sLineNoUid
2216
                Next
2217
                For Each oSymbolRow In oLinelist.Dt_Symbol.Rows
2218
                    Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID)
2219
                    Dim sSymbolName As String = oSymbolRow(_XML_SYMBOL_NAME)
2220
                    Dim oSymbolNode As TreeNode = oLineNoNode.Nodes.Add(sSymbolUid, sSymbolName)
2221
                    oSymbolNode.Tag = sLineNoUid
2222
                Next
2223
                'If sLineNo <> "PipeLineNo" Then
2224

    
2225
                'Else
2226
                '    'If oPipe = False Then
2227
                '    '    oOnlyPipesNode = oParentNode.Nodes.Add("PipeLineNo", "PipeLineNo")
2228
                '    '    oPipe = True
2229
                '    'End If
2230
                '    'For Each oLineRow In oLinelist.Dt_Line.Rows
2231
                '    '    Dim sLineUid As String = oLineRow(_XML_SYMBOL_UID)
2232
                '    '    Dim oPipeNode As TreeNode = oOnlyPipesNode.Nodes.Add(sLineUid, "Pipe")
2233
                '    '    oPipeNode.Tag = sLineNoUid
2234
                '    'Next
2235

    
2236

    
2237

    
2238

    
2239
                'End If
2240
            Next
2241
            'For Each oSymbolRow In _TempSymbolDt.Rows
2242
            '    If oFitting = False Then
2243
            '        oOnlyFittingsNode = oParentNode.Nodes.Add("Symbols", "Symbols")
2244
            '        oFitting = True
2245
            '    End If
2246
            '    Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID)
2247
            '    Dim sSymbolName As String = oSymbolRow(_XML_SYMBOL_NAME)
2248
            '    Dim oSymbolNode As TreeNode = oOnlyFittingsNode.Nodes.Add(sSymbolUid, sSymbolName)
2249
            '    oSymbolNode.Tag = sSymbolUid
2250
            'Next
2251
            For Each oEqplist In oEqpLists
2252
                Dim sEqpUid As String = oEqplist.Uid
2253
                Dim sEqpNo As String = "EQUIPMENT"
2254
                Dim oEqpNode As TreeNode = oParentNode.Nodes.Add(sEqpUid, sEqpNo)
2255

    
2256

    
2257
                For Each oSymbolRow In oEqplist.Dt_Equipment.Rows
2258
                    Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID)
2259
                    Dim sSymbolName As String = oSymbolRow(_XML_SYMBOL_NAME)
2260
                    Dim oSymbolNode As TreeNode = oEqpNode.Nodes.Add(sSymbolUid, sSymbolName)
2261
                    oSymbolNode.Tag = sEqpUid
2262
                Next
2263
            Next
2264
        End If
2265

    
2266
        Return oDwg_Ds
2267
    End Function
2268
    Private Sub Tree_Result_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles Tree_Result.AfterCheck
2269
        If e.Node.Checked = True Then
2270
            For Each oNode As TreeNode In e.Node.Nodes
2271
                oNode.Checked = True
2272
            Next
2273
        Else
2274
            For Each oNode As TreeNode In e.Node.Nodes
2275
                oNode.Checked = False
2276
            Next
2277
        End If
2278
    End Sub
2279

    
2280
    Private Sub Btn_Setting_Click(sender As Object, e As EventArgs) Handles Btn_Setting.Click
2281
        Dim oSettings As Settings = New Settings()
2282
        oSettings.ShowDialog()
2283
    End Sub
2284

    
2285
    Private Sub Btn_TestNozzle_Click(sender As Object, e As EventArgs) Handles Btn_TestNozzle.Click
2286

    
2287
        Dim sVessel_ID As String = "841D5E640AE5421B9A017DDC2E87FF11"
2288
        Dim objVessel As LMVessel
2289
        objVessel = _Placement.PIDDataSource.GetVessel(sVessel_ID)
2290
        Dim oVesselLocation As LMLocations = objVessel.Locations
2291
        Dim symVessel As LMSymbol = _Placement.PIDDataSource.GetSymbol(objVessel.Representations.Nth(1).Id)
2292
        Dim XCoordinate As String = symVessel.Attributes("XCoordinate").Value
2293
        Dim YCoordinate As String = symVessel.Attributes("YCoordinate").Value
2294
        symVessel.Attributes("XCoordinate").Value = XCoordinate + 0.01
2295
        symVessel.Attributes("YCoordinate").Value = YCoordinate + 0.01
2296
        symVessel.Commit()
2297
        Dim sValve_ID As String = "DB7B0CA8A2664A6BA7A9615764BA62B0"
2298
        Dim objValve As LMSymbol
2299
        Dim objValves As LMPipingComp = _Placement.PIDDataSource.GetPipingComp(sValve_ID)
2300

    
2301
        objValve = _Placement.PIDDataSource.GetSymbol(objValves.Representations.Nth(1).Id)
2302
        objValve.Commit()
2303
        Dim dVesselX As Double = XCoordinate
2304
        Dim dVesselY As Double = YCoordinate
2305
        Dim X1 As Double, Y1 As Double, X2 As Double, Y2 As Double
2306

    
2307
        _Placement.PIDConnectPointLocation(objValve, 1, X1, Y1)
2308

    
2309
        _Placement.PIDConnectPointLocation(objValve, 2, X2, Y2)
2310

    
2311
        Dim nozzlename As String = "\Equipment Components\Nozzles\Flanged Nozzle.sym"
2312
        Dim dCalc_x As Double = 0
2313
        Dim dCalc_y As Double = 0
2314

    
2315
        If dVesselX - X2 > 0 Then
2316
            dCalc_x = dVesselX - (dVesselX - X2)
2317
        Else
2318
            dCalc_x = dVesselX + (X2 - dVesselX)
2319
        End If
2320
        If dVesselY - Y2 > 0 Then
2321
            dCalc_y = dVesselY - (dVesselY - Y2)
2322
        Else
2323
            dCalc_y = dVesselY + (Y2 - dVesselY)
2324
        End If
2325

    
2326
        Dim objNozzle As LMSymbol = _Placement.PIDPlaceSymbol(nozzlename, dCalc_x, dCalc_y,
2327
            TargetItem:=symVessel.AsLMRepresentation)
2328

    
2329
        Dim blnSuccess As Boolean = _Placement.PIDConnectPointLocation(objNozzle, 1, X1, Y1)
2330
        blnSuccess = _Placement.PIDConnectPointLocation(objNozzle, 2, X1, Y1)
2331

    
2332
        objValve = _Placement.PIDPlaceSymbol(objValve.FileName, X1, Y1, ExistingItem:=objValve.AsLMAItem,
2333
          TargetItem:=objNozzle.AsLMRepresentation)
2334

    
2335

    
2336

    
2337
    End Sub
2338

    
2339
    Private Sub Btn_SymbolLibrary_Click(sender As Object, e As EventArgs) Handles Btn_SymbolLibrary.Click
2340
        Dim oMapping As New Mapping(_PIDSymbol_DB)
2341
        oMapping.Show()
2342
    End Sub
2343

    
2344
    Private Sub Btn_Stop_Click(sender As Object, e As EventArgs) Handles Btn_Stop.Click
2345
        Try
2346
            SetListBoxItems(ListBox_Result, " Auto converting 중지....")
2347
            _Main_trd.Abort()
2348
            _Opc_trd.Abort()
2349
        Catch ex As Exception
2350

    
2351
        End Try
2352
    End Sub
2353
End Class
2354

    
2355

    
2356
Public Class DrawingInfo
2357
    Public mDrawingName As String
2358
    Public mSpID As String
2359
    Public mPath As String
2360
End Class
2361

    
2362

    
2363

    
2364

    
2365

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