프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / Main.vb @ 43fa2b90

이력 | 보기 | 이력해설 | 다운로드 (108 KB)

1 4f359afa Gyusu
Imports System.IO
2
Imports System.Data.SqlClient
3
Imports System.Data.SQLite
4
Imports Plaice
5
Imports Llama
6
Imports PidA
7 962b2464 Gyusu
8 e282643f Gyusu
9
Imports System.Threading
10
11 4f359afa Gyusu
Public Class Main
12
13 54b98e09 Gyusu
    'Dim _Mapping_DB As DataTable = New DataTable()
14
    Dim _Mapping_DB As DataSet = New DataSet()
15 171ac39d Gyusu
    Dim _Attribute_DB As DataTable = New DataTable()
16 39d43554 Gyusu
    Dim _PIDSymbol_DB As DataTable = New DataTable()
17 4f359afa Gyusu
    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 171ac39d Gyusu
    Dim _IMG_X = 0
22
    Dim _IMG_Y = 0
23
24
    Dim _Unit As String
25 4f359afa Gyusu
26 31d47a80 Gyusu
    'Drawing 전역변수
27
    Dim _objPIDADrawing As Object
28 e282643f Gyusu
    '현재선택한 폴더경로
29
    Dim _selectFolderPath As String
30
31
    Private _Main_trd As Thread
32 54b98e09 Gyusu
    Private _Opc_trd As Thread
33
34
    Private _CompleteConvert As Boolean = False
35 e282643f Gyusu
36 171ac39d Gyusu
    Private _DrawingsList As List(Of Drawing)
37 272662f9 Gyusu
38
39 9e1e7135 Gyusu
    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 54b98e09 Gyusu
    Dim _Gembox As New CGembox()
48 41e4023e Gyusu
49
50
    Private _allItem As Integer
51
    Private _Itemcnt As Integer
52 4f359afa Gyusu
    Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
53 54b98e09 Gyusu
        LoadDB()
54
    End Sub
55 272662f9 Gyusu
56 54b98e09 Gyusu
    Private Sub LoadDB()
57 e282643f Gyusu
        If My.Settings.DBPath <> "" And My.Settings.Plant_Hierarchy <> "" Then
58
            Dim sDBPath As String = My.Settings.DBPath
59 54b98e09 Gyusu
60
            _Gembox.isLoadFile(My.Settings.SymbolLibrary)
61
            _Mapping_DB = _Gembox.LoadFileFunc()
62
            '  _Mapping_DB = Load_DB(sDBPath, _DB_TABLE_MAPPING)
63 171ac39d Gyusu
            _Attribute_DB = Load_DB(sDBPath, _DB_TABLE_ATTRIBUTE)
64 39d43554 Gyusu
            _PIDSymbol_DB = Load_DB(sDBPath, _DB_TABLE_SYMBOLNAME)
65 6a6d8ab4 Gyusu
            'TestPID()
66
            'OpenDrawing()
67 e282643f Gyusu
        Else
68
            MessageBox.Show("설정값을 먼저 확인해주세요")
69
        End If
70
    End Sub
71 41e4023e Gyusu
72 e282643f Gyusu
    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 559daf6d Gyusu
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 b6996671 Gyusu
        datasource.SiteNode = "\\desktop-9vlq0dp\Test03Site\smartplantv4.ini"
138 559daf6d Gyusu
        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 e282643f Gyusu
    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 6a6d8ab4 Gyusu
            Const CONST_SPID_OPC As String = "426E89964A7F49208AD79E1F320DA251"
209 e282643f Gyusu
            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 6a6d8ab4 Gyusu
            Dim objOPC As LMOPC
216
            Dim objpairOPC As LMOPC
217
            objOPC = datasource.GetOPC(CONST_SPID_OPC)
218
            objpairOPC = objOPC.pairedWithOPCObject
219 e282643f Gyusu
            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 962b2464 Gyusu
    End Sub
241 e282643f Gyusu
242 b6996671 Gyusu
    Public Function SetActiveSiteFromConfigInfo(ByVal strActiveSite As String) As Boolean
243 e282643f Gyusu
        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 4f359afa Gyusu
257 1229ad76 Gyusu
    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 4f359afa Gyusu
        Try
262
            Dim DrawingNumber As String
263
            Dim DrawingName As String
264 1229ad76 Gyusu
            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 54b98e09 Gyusu
278 1229ad76 Gyusu
            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 4f359afa Gyusu
287
            Dim extension As String = Path.GetExtension(oDwgName)
288
            oDwgName = oDwgName.Replace(extension, "")
289 1229ad76 Gyusu
290 4f359afa Gyusu
            objPIDAutoApp = CreateObject("PIDAutomation.Application")
291 1229ad76 Gyusu
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 4f359afa Gyusu
                objPIDADrawing.CloseDrawing
304
            End If
305 1229ad76 Gyusu
            If objPIDAutoApp IsNot Nothing Then
306
                objPIDAutoApp.Quit
307
            End If
308
            datasource = Nothing
309 4f359afa Gyusu
            objPIDAutoApp = Nothing
310
            objPIDADrawing = Nothing
311
            Return False
312
        End Try
313 1229ad76 Gyusu
        If objPIDADrawing IsNot Nothing Then
314
            objPIDADrawing.CloseDrawing
315
        End If
316 4f359afa Gyusu
317
    End Function
318
319 1229ad76 Gyusu
320 171ac39d Gyusu
    Private Function GetDataFromMappingDB(ByVal sSymbolName As String, ByVal sColumn As String) As String
321
        Dim sValue As String = ""
322 54b98e09 Gyusu
        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 e282643f Gyusu
            End If
340 54b98e09 Gyusu
        Next
341
342 171ac39d Gyusu
        Return sValue
343 4f359afa Gyusu
    End Function
344
345 171ac39d Gyusu
    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 e282643f Gyusu
356 d039e347 Gyusu
    '  Dim _TempSymbolDt As DataTable = Symbol_Dt()
357 6a6d8ab4 Gyusu
358
359 171ac39d Gyusu
    Private Function LoadSymbolInXml(ByVal sXmlPath As String) As Drawing
360 54b98e09 Gyusu
        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 6a6d8ab4 Gyusu
366 54b98e09 Gyusu
            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 171ac39d Gyusu
372 54b98e09 Gyusu
                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 d039e347 Gyusu
488 54b98e09 Gyusu
                        Next
489
490
                    Next
491
                    'Line No Attribute
492
                    For Each oAtrribute As Object In oLineNo.Elements(_XML_CATEGORY_ATTRIBUTE)
493 d039e347 Gyusu
                        Try
494 54b98e09 Gyusu
                            Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
495
                            Dim oEleObj As XElement
496 41e4023e Gyusu
                            Dim sUid As String = ""
497 54b98e09 Gyusu
                            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 d039e347 Gyusu
                        Catch ex As Exception
511 171ac39d Gyusu
512 d039e347 Gyusu
                        End Try
513 171ac39d Gyusu
514 d039e347 Gyusu
                    Next
515 54b98e09 Gyusu
                    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 41e4023e Gyusu
                    '    CEqp_no.Uid = oEqpNo.Element(_XML_EQP_UID).Value
558 54b98e09 Gyusu
                    'CEqp_no.Text = oEqpNo.Element(_XML_EQP_TEXT).Value
559
                    'CEqp_no.Location = oEqpNo.Element(_XML_EQP_LOCATION).Value
560 41e4023e Gyusu
                    '   CEqp_no.Angle = oEqpNo.Element(_XML_EQP_ANGLE).Value
561
                    '  CEqp_no.SystemPath = GetDataFromMappingDB(_XML_CATEGORY_EQUIPMENT, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
562 54b98e09 Gyusu
                    Dim oSymbol_Dt As DataTable = Symbol_Dt()
563
                    Dim oAttribute_Dt As DataTable = Attribute_Dt()
564 41e4023e Gyusu
                    Dim sUid As String
565 54b98e09 Gyusu
                    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 d039e347 Gyusu
602
                    Next
603 54b98e09 Gyusu
                    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 41e4023e Gyusu
                            Dim sAttUid As String
608 54b98e09 Gyusu
                            Dim sName As String
609
                            Dim sValue As String
610
                            oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
611 41e4023e Gyusu
                            sAttUid = oEleObj.Value
612 54b98e09 Gyusu
                            oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
613
                            sName = oEleObj.Value
614
                            oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
615
                            sValue = oEleObj.Value
616 41e4023e Gyusu
                            oAddrow(_XML_ATTRIBUTE_UID) = sAttUid
617 54b98e09 Gyusu
                            oAddrow(_XML_ATTRIBUTE_NAME) = sName
618
                            oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
619
                            oAttribute_Dt.Rows.Add(oAddrow)
620
                        Catch ex As Exception
621 171ac39d Gyusu
622 54b98e09 Gyusu
                        End Try
623
624
                    Next
625 41e4023e Gyusu
                    CEqp_no.Uid = sUid
626 54b98e09 Gyusu
                    CEqp_no.Dt_Equipment = oSymbol_Dt
627
                    CEqp_no.Dt_Attribute = oAttribute_Dt
628
                    oEqp_list.Add(CEqp_no)
629 4f359afa Gyusu
                Next
630 54b98e09 Gyusu
                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 4f359afa Gyusu
    End Function
639
640
641
642 171ac39d Gyusu
    '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 4f359afa Gyusu
653 171ac39d Gyusu
    '            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 4f359afa Gyusu
660 171ac39d Gyusu
    '            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 4f359afa Gyusu
679 171ac39d Gyusu
    '                    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 4f359afa Gyusu
693 171ac39d Gyusu
    '                    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 4f359afa Gyusu
704 171ac39d Gyusu
705
    '        Return oDt
706
    '    Catch ex As Exception
707
    '        Return Nothing
708
    '    End Try
709
    'End Function
710 4f359afa Gyusu
711
712 9e1e7135 Gyusu
    Private Sub ConvertPointByImage(ByRef dX As Double, ByRef dY As Double, ByVal dDwgX As Double, ByVal dDwgY As Double)
713 4f359afa Gyusu
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 171ac39d Gyusu
        calcy = _DWG_Y - ((dY * _DWG_Y) / dDwgY) '_DWG_Y - Math.Round((dY * _DWG_Y) / dDwgY, 2)
718 4f359afa Gyusu
        dX = calcx
719
        dY = calcy
720
    End Sub
721
722 e1cde8f2 Gyusu
723
    '@brief Convert To SPPID
724
    '@author : Gyusu Park
725
    '@date : 2018-04-10
726
    '@history:
727
728 171ac39d Gyusu
    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 e1cde8f2 Gyusu
    Private Function AutoConverting(ByVal oPipe_Dt As DataTable, ByVal oSymbol_Dt As DataTable, ByVal oTreeNode As TreeNode) As Boolean
746 e282643f Gyusu
        Dim iTotalCount As Double = oPipe_Dt.Rows.Count + oSymbol_Dt.Rows.Count
747
        Dim iSymbolcount As Double = 0
748
749 e1cde8f2 Gyusu
        Dim lobjDatasource As Object = _Placement.PIDDataSource
750 e282643f Gyusu
751 e1cde8f2 Gyusu
        ' lobjDatasource.BeginTransaction()
752 e282643f Gyusu
        '  datasource = objPlacement.PIDDataSource
753
        'Dim iPipecnt As Integer = 0
754 e1cde8f2 Gyusu
        SetListBoxItems(ListBox_Result, " Auto converting 시작....")
755 e282643f Gyusu
756 e1cde8f2 Gyusu
        Dim iPipeCnt As Integer = 0
757 e282643f Gyusu
        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 20c84e05 Gyusu
                Dim oSymbol As String = oRow("SystemPath").ToString()
761 171ac39d Gyusu
762 e282643f Gyusu
                Dim objConnector As LMConnector
763
                Dim objInputs As PlaceRunInputs
764
                objInputs = New PlaceRunInputs
765 171ac39d Gyusu
                Dim oSplitStr As String() = Split(oposition, " ")
766 e282643f Gyusu
                For Each sposition As String In oSplitStr
767 20c84e05 Gyusu
                    Dim opointstr As String() = Split(sposition, ", ")
768 e282643f Gyusu
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 9e1e7135 Gyusu
                            ConvertPointByImage(ox, oy, _IMG_X, _IMG_Y)
774 e282643f Gyusu
                            objInputs.AddPoint(ox, oy)
775
                        End If
776 4f359afa Gyusu
                    End If
777 e282643f Gyusu
                Next
778
                Dim objItem As LMAItem
779 e1cde8f2 Gyusu
                objItem = _Placement.PIDCreateItem(oSymbol)
780
                objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
781
                SetListBoxItems(ListBox_Result, " Place PipeLine...." & "(" & (iPipeCnt + 1) & "/" & oPipe_Dt.Rows.Count)
782 e282643f Gyusu
                'Dim objPipeRun As LMPipeRun = datasource.GetPipeRun(objConnector.ModelItemID)
783
                'objPipeRun.Attributes("OperFluidCode").Value = "AFS"
784
                'objPipeRun.Commit()
785
                iSymbolcount = iSymbolcount + 1
786 e1cde8f2 Gyusu
                iPipeCnt = iPipeCnt + 1
787 e282643f Gyusu
            Next
788
        End If
789 4f359afa Gyusu
790 e1cde8f2 Gyusu
        SetListBoxItems(ListBox_Result, " Place PipeLine....완료")
791
792
        Dim iAllInstrumentCnt As Integer = oSymbol_Dt.Select("Name = 'INSTRUMENTATION'").Length
793 20c84e05 Gyusu
                    Dim iValveCnt As Integer = oSymbol_Dt.Select("Class = 'VALVES'").Length
794 e1cde8f2 Gyusu
        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 e282643f Gyusu
        For Each oRow As DataRow In oSymbol_Dt.Rows
801 4f359afa Gyusu
802 e282643f Gyusu
            Try
803 e1cde8f2 Gyusu
804 20c84e05 Gyusu
                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 e1cde8f2 Gyusu
811 e282643f Gyusu
                Dim oX As Double = 0.0
812
                Dim oY As Double = 0.0
813 20c84e05 Gyusu
                If IsNumeric(oRow("x").ToString()) Then
814
                    oX = Double.Parse(oRow("x").ToString())
815 e282643f Gyusu
                End If
816 20c84e05 Gyusu
                If IsNumeric(oRow("y").ToString()) Then
817
                    oY = Double.Parse(oRow("y").ToString())
818 e282643f Gyusu
                End If
819
                Dim oAngle As Double = 0.0
820 20c84e05 Gyusu
                If IsNumeric(oRow("Angle").ToString()) Then
821
                    oAngle = Double.Parse(oRow("Angle").ToString())
822 e282643f Gyusu
                End If
823
                '   oSymbol = "\INSTRUMENTation\SYSTEM FUNCTIONS\D C S\DCS FUNC ACCESS IN PRIME LOC.sym"
824 e1cde8f2 Gyusu
                If sSystemPath <> "" Then
825
                    If sName = _TYPE_Instumentation Then
826
827 e282643f Gyusu
                        Dim sTagsuffix As String = ""
828
                        Dim sTagSequenceNo As String = ""
829
                        Dim sMeasuredVariableCode As String = ""
830
                        Dim sInstrumentTypeModifier As String = ""
831 e1cde8f2 Gyusu
832
                        If sText <> "" Then
833
                            If sText.Contains(",") Then
834
                                Dim splitstr() As String = sText.Split(",")
835 e282643f Gyusu
                                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 e1cde8f2 Gyusu
                                sMeasuredVariableCode = Mid(sText, 1, 1)
852
                                sTagSequenceNo = Mid(sText, 2, Len(sText))
853 e282643f Gyusu
                            End If
854 4f359afa Gyusu
855 e282643f Gyusu
                        End If
856 4f359afa Gyusu
857 e282643f Gyusu
                        Dim objInstrSym As LMSymbol
858 e1cde8f2 Gyusu
                        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 e282643f Gyusu
                        Dim objInstr As LMInstrument
870
                        objInstr = lobjDatasource.GetInstrument(objInstrSym.ModelItemID)
871 4f359afa Gyusu
872 e282643f Gyusu
                        Dim objItem As LMAItem
873 e1cde8f2 Gyusu
                        objItem = _Placement.PIDCreateItem(sSystemPath)
874
875 4f359afa Gyusu
876 e282643f Gyusu
                        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 e1cde8f2 Gyusu
                        iInstrumentCnt = iInstrumentCnt + 1
882
                    ElseIf sName = "GATE VALVE WITH PLUG" Then
883 4f359afa Gyusu
884 e1cde8f2 Gyusu
                    ElseIf sName = "MEDIUM 1D 1TO1" Then
885 4f359afa Gyusu
886 e1cde8f2 Gyusu
                    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 e282643f Gyusu
                    Else
897 e1cde8f2 Gyusu
                        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 4f359afa Gyusu
906 e282643f Gyusu
                    End If
907
                    iSymbolcount = iSymbolcount + 1
908
                Else
909 4f359afa Gyusu
                End If
910 e282643f Gyusu
            Catch ex As Exception
911 4f359afa Gyusu
912 e282643f Gyusu
            End Try
913
            Dim dCalcProgressValue As Double = (iSymbolcount / iTotalCount) * 100
914
            SetProgressbar(ProgressBar_Status, dCalcProgressValue)
915
            '     ProgressBar_Status.Value = (iSymbolcount / iTotalCount) * 100
916 e1cde8f2 Gyusu
917 4f359afa Gyusu
        Next
918
919 e1cde8f2 Gyusu
        MsgBox("Complete AutoConverting")
920
        SetListBoxItems(ListBox_Result, "Place Instrument....변환완료")
921
        SetListBoxItems(ListBox_Result, "총 symbol:  " & iSymbolcount & "개 변환완료")
922
        SetProgressbar(ProgressBar_Status, 100)
923 41e4023e Gyusu
924 e282643f Gyusu
        ' MsgBox("symbol: " & iSymbolcount & "개, pipe : " & iPipecnt & "개 변환완료")
925 4f359afa Gyusu
    End Function
926
927
928 272662f9 Gyusu
    Private Sub Tree_XMLFiles_AfterCheck(sender As Object, e As TreeViewEventArgs)
929 4f359afa Gyusu
        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 171ac39d Gyusu
    Private Function Load_DB(ByVal sDBPath As String, ByVal sTableName As String) As DataTable
941 4f359afa Gyusu
942
        Try
943 171ac39d Gyusu
            Dim oDt As New DataTable
944 4f359afa Gyusu
            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 171ac39d Gyusu
            Dim sQuery As String = "Select * from " & sTableName
948 4f359afa Gyusu
            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 171ac39d Gyusu
            oDt = oDataSet.Tables(0)
953
            Return oDt
954 4f359afa Gyusu
        Catch ex As Exception
955 171ac39d Gyusu
            Return Nothing
956 4f359afa Gyusu
        End Try
957
958
959 171ac39d Gyusu
    End Function
960 4f359afa Gyusu
961 171ac39d Gyusu
    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 962b2464 Gyusu
977
978 171ac39d Gyusu
    End Sub
979
980 272662f9 Gyusu
    '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 962b2464 Gyusu
984 272662f9 Gyusu
    '    printfilesfolders_here(pa, e.Node)
985 962b2464 Gyusu
986 272662f9 Gyusu
    '    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 962b2464 Gyusu
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 e282643f Gyusu
1013 962b2464 Gyusu
1014 272662f9 Gyusu
    '    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 962b2464 Gyusu
1067 31d47a80 Gyusu
    Private Function LoadAllDrawing() As DataTable
1068 e282643f Gyusu
1069
1070 e1cde8f2 Gyusu
        SetListBoxItems(ListBox_Result, "도면정보 로드중....")
1071 e282643f Gyusu
1072 31d47a80 Gyusu
        Dim oDt As DataTable = Drawing_Dt()
1073 e282643f Gyusu
        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 31d47a80 Gyusu
            Dim oAddRow As DataRow = oDt.NewRow()
1081 e282643f Gyusu
            oAddRow("Name") = Path.GetFileNameWithoutExtension(sName)
1082
            oAddRow("Path") = FileName
1083 31d47a80 Gyusu
            oDt.Rows.Add(oAddRow)
1084
        Next
1085
        Return oDt
1086
    End Function
1087
1088 e282643f Gyusu
    Private Function LoadAllDrawing2() As DataTable
1089 31d47a80 Gyusu
        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 e282643f Gyusu
    End Function
1147
1148 272662f9 Gyusu
    Dim _XMLList As ListView = New ListView()
1149 e282643f Gyusu
1150 272662f9 Gyusu
1151
1152 e1cde8f2 Gyusu
1153 171ac39d Gyusu
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 9e1e7135 Gyusu
        ' DataGrid_Result.DataSource = New DataTable()
1174 171ac39d Gyusu
        Me.ProgressBar_Status.Visible = True
1175
        ProgressBar_Status.Maximum = 100
1176
        ProgressBar_Status.Value = 0
1177
        ' _selectFolderPath = Tree_XMLFiles.SelectedNode.FullPath.Replace("\\", "\")
1178 54b98e09 Gyusu
        _Main_trd = New Thread(AddressOf ThreadConvert)
1179 171ac39d Gyusu
        _Main_trd.IsBackground = True
1180
        _Main_trd.Start()
1181 54b98e09 Gyusu
        FineOPCForm()
1182
    End Sub
1183 171ac39d Gyusu
1184 54b98e09 Gyusu
    Private Sub FineOPCForm()
1185
        _Opc_trd = New Thread(AddressOf ThreadOPCRemove)
1186
        _Opc_trd.IsBackground = True
1187
        _Opc_trd.Start()
1188 171ac39d Gyusu
    End Sub
1189 54b98e09 Gyusu
1190 7824381a Gyusu
    'Private Sub ThreadTask()
1191 e1cde8f2 Gyusu
1192 e282643f Gyusu
1193 7824381a Gyusu
    '    If _XMLList.Items.Count > 0 Then
1194 31d47a80 Gyusu
1195 7824381a Gyusu
    '        Dim oDwg_Dt As DataTable = LoadAllDrawing()
1196
    '        Dim iDwgCnt As Integer = 0
1197
    '        Dim objPIDAutoApp As Object
1198
    '        objPIDAutoApp = CreateObject("PIDAutomation.Application")
1199 e282643f Gyusu
1200 e1cde8f2 Gyusu
1201 7824381a Gyusu
    '        Dim myList = DirectCast(Invoke(New GetListViewDelegate(AddressOf GetListViewItems), _XMLList), List(Of String))
1202
    '        For i = 0 To myList.Count - 1
1203 e1cde8f2 Gyusu
1204 7824381a Gyusu
    '            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 e1cde8f2 Gyusu
1211 7824381a Gyusu
    '            Dim sPath As String = OpenDrawing(oDwg_Dt, sDwgName)
1212
    '            If sPath <> "" Then
1213 e1cde8f2 Gyusu
1214 7824381a Gyusu
    '                Process.Start(sPath)
1215 e1cde8f2 Gyusu
1216 7824381a Gyusu
    '                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 e1cde8f2 Gyusu
1226 7824381a Gyusu
    '                If bCheckOpenDrawing Then
1227
    '                    SetListBoxItems(ListBox_Result, sDwgName & " 도면 Open....")
1228
    '                    Dim oPipe_Dt As DataTable = New DataTable() 'LoadPipeInXml(oDwgPath)
1229 e282643f Gyusu
1230 7824381a Gyusu
    '                    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 e1cde8f2 Gyusu
1243 e282643f Gyusu
1244 7824381a Gyusu
    '                    '    oTreeNode.Expand()
1245
    '                    SetListBoxItems(ListBox_Result, sDwgName & " Auto converting 대기....")
1246
    '                    AutoConverting(oPipe_Dt, oSymbol_Dt, oTreeNode)
1247 4f359afa Gyusu
1248 7824381a Gyusu
    '                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 e282643f Gyusu
1261 171ac39d Gyusu
    Dim _objPIDAutoApp As Object
1262 e282643f Gyusu
1263 171ac39d Gyusu
    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 e1cde8f2 Gyusu
1269 171ac39d Gyusu
        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 559daf6d Gyusu
            If CDrawing.DwgName.ToUpper() = sDwgName.ToUpper() Then
1294 171ac39d Gyusu
                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 6a6d8ab4 Gyusu
    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 9e1e7135 Gyusu
    Private Function ConvertPointBystring(ByVal sPoint As String, ByRef dX As Double, ByRef dY As Double) As Boolean
1331 171ac39d Gyusu
        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 9e1e7135 Gyusu
1338 171ac39d Gyusu
                Else
1339
                    dX = 0
1340
                    dY = 0
1341
                    Return False
1342
                End If
1343
            End If
1344 e1cde8f2 Gyusu
            Return True
1345
        Catch ex As Exception
1346
            Return False
1347
        End Try
1348 171ac39d Gyusu
    End Function
1349
1350 54b98e09 Gyusu
1351
    Dim _DrawLine_Dt As DataTable = DrawLind_Dt()
1352
1353 9e1e7135 Gyusu
    Private Function DrawLine(ByVal sUid As String, ByVal sLineNoUid As String, ByVal oLine_Dt As DataTable, ByVal oAttribute_Dt As DataTable) As LMPipeRun
1354 171ac39d Gyusu
        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 9e1e7135 Gyusu
                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 171ac39d Gyusu
                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 54b98e09 Gyusu
                Dim sSystempath As String = "\Piping\Routing\Process Lines\Primary Piping.sym" ' oPipeRow(0)(_XML_LINE_SYSTEMPATH).ToString()
1374 171ac39d Gyusu
                Dim sStartpoint As String = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
1375
                Dim sEndpoint As String = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
1376 460d6abd Gyusu
                Dim sPipeUid As String = oPipeRow(0)(_XML_LINE_UID).ToString()
1377
1378 9e1e7135 Gyusu
                ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
1379
                dStart_x = dOriginalStart_x
1380
                dStart_y = dOriginalStart_y
1381 460d6abd Gyusu
1382 9e1e7135 Gyusu
                If ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y) Then
1383
                    dEnd_x = dOriginalEnd_x
1384
                    dEnd_y = dOriginalEnd_y
1385 54b98e09 Gyusu
1386
                    '   라인보정(oLine_Dt, sPipeUid, dStart_x, dStart_y, dEnd_x, dEnd_y)
1387 460d6abd Gyusu
                    '//Overlap 보정
1388 54b98e09 Gyusu
                    '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 460d6abd Gyusu
1403
                    ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
1404 9e1e7135 Gyusu
                    ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
1405 171ac39d Gyusu
                    If dStart_x <> 0 And dStart_y <> 0 And dEnd_x <> 0 And dEnd_y <> 0 Then
1406 460d6abd Gyusu
1407 41e4023e Gyusu
                        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 171ac39d Gyusu
                        objInputs.AddPoint(dStart_x, dStart_y)
1425
                        objInputs.AddPoint(dEnd_x, dEnd_y)
1426 41e4023e Gyusu
                        AddModelingLine(dStart_x, dStart_y, dEnd_x, dEnd_y, sUid)
1427 171ac39d Gyusu
                        objItem = _Placement.PIDCreateItem(sSystempath)
1428 9e1e7135 Gyusu
                        _iPipecnt = _iPipecnt + 1
1429 6a6d8ab4 Gyusu
                        SetListBoxItems(ListBox_Result, "Place PipeLine..(" & dOriginalStart_x & "," & dOriginalStart_y & ") - (" & dOriginalEnd_x & "," & dOriginalEnd_y & ").." & _iPipecnt & " count ")
1430 171ac39d Gyusu
                        objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
1431
                        oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
1432 559daf6d Gyusu
                        oPipeRun.Attributes("FlowDirection").Value = "End 1 is upstream (Inlet)"
1433 171ac39d Gyusu
                        If oAttributeRow.Length > 0 Then
1434
                            For Each oAttribute In oAttributeRow
1435 54b98e09 Gyusu
                                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 559daf6d Gyusu
1445 171ac39d Gyusu
                            Next
1446
                            oPipeRun.Commit()
1447
                        End If
1448 6a6d8ab4 Gyusu
                        '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 171ac39d Gyusu
                    End If
1468
                End If
1469 41e4023e Gyusu
                _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 171ac39d Gyusu
            End If
1474
            Return oPipeRun
1475
        Catch ex As Exception
1476
            Return Nothing
1477
        End Try
1478 e1cde8f2 Gyusu
    End Function
1479
1480 41e4023e Gyusu
    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 54b98e09 Gyusu
        Dim oAddRow = _DrawLine_Dt.NewRow()
1482 41e4023e Gyusu
        oAddRow(_XML_LINE_UID) = sUid
1483 54b98e09 Gyusu
        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 41e4023e Gyusu
    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 54b98e09 Gyusu
1494 41e4023e Gyusu
        'Dim oFindRows_2 As DataRow() = _DrawLine_Dt.Select("end_x = '" & dEnd_x & "' and end_y = '" & dEnd_y & "' and uid <> '" & sUid & "'")
1495 54b98e09 Gyusu
1496 41e4023e Gyusu
        'Dim oFindRows_3 As DataRow() = _DrawLine_Dt.Select("start_x = '" & dEnd_x & "' and start_y = '" & dEnd_y & "' and uid <> '" & sUid & "'")
1497 54b98e09 Gyusu
1498 41e4023e Gyusu
        'Dim oFindRows_4 As DataRow() = _DrawLine_Dt.Select("end_x = '" & dStart_x & "' and end_y = '" & dStart_y & "' and uid <> '" & sUid & "'")
1499 54b98e09 Gyusu
1500 41e4023e Gyusu
        '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 54b98e09 Gyusu
    End Function
1513
1514
    Private Function FindConnectionPoint(ByVal dX As Double, ByVal dY As Double)
1515
1516
1517
    End Function
1518
1519 41e4023e Gyusu
    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 54b98e09 Gyusu
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 171ac39d Gyusu
        Try
1559 e282643f Gyusu
1560 171ac39d Gyusu
            Dim oSymbolRow() As DataRow = oSymbol_Dt.Select(_XML_SYMBOL_UID & " = '" + sUid + "'")
1561 6a6d8ab4 Gyusu
            Dim oAttributeRow() As DataRow
1562
            If oAttribute_Dt.Rows.Count > 0 Then
1563 460d6abd Gyusu
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
1564 6a6d8ab4 Gyusu
            End If
1565
1566 171ac39d Gyusu
            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 54b98e09 Gyusu
                Dim sClass As String = oSymbolRow(0)(_XML_SYMBOL_CLASS).ToString()
1571 171ac39d Gyusu
                Dim sLocation As String = oSymbolRow(0)(_XML_SYMBOL_LOCATION).ToString()
1572 9e1e7135 Gyusu
                Dim sOriginalPoint As String = oSymbolRow(0)(_XML_SYMBOL_ORIGINALPOINT).ToString()
1573 171ac39d Gyusu
                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 9e1e7135 Gyusu
                Dim dLocationX As Double = 0.0
1580
                Dim dLocationY As Double = 0.0
1581 171ac39d Gyusu
                Dim dX As Double = 0.0
1582
                Dim dY As Double = 0.0
1583
1584 9e1e7135 Gyusu
                If ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY) Then
1585
                    dX = dLocationX
1586
                    dY = dLocationY
1587 54b98e09 Gyusu
                    If sSymbolCompType = "" Or sSymbolCompType = "Piping OPC's" Then
1588
                        FindConnectionLine(oLine_Dt, dX, dY)
1589
                    End If
1590
1591 9e1e7135 Gyusu
                    ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1592 54b98e09 Gyusu
                        Dim oInstrument As LMInstrument
1593
                    If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
1594 9e1e7135 Gyusu
                        _iInstrumentcnt = _iInstrumentcnt + 1
1595 171ac39d Gyusu
                        objSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1596 6a6d8ab4 Gyusu
                        SetListBoxItems(ListBox_Result, "Place Instrument..(" & dLocationX & "," & dLocationY & ")..." & _iInstrumentcnt & " count ")
1597 171ac39d Gyusu
                        oInstrument = oDatasource.GetInstrument(objSymbol.ModelItemID)
1598 6a6d8ab4 Gyusu
                        Try
1599
                            If oAttributeRow.Length > 0 Then
1600
                                For Each oAttribute In oAttributeRow
1601 54b98e09 Gyusu
                                    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 6a6d8ab4 Gyusu
                                Next
1611
                                oInstrument.Commit()
1612
                            End If
1613
                        Catch ex As Exception
1614
                        End Try
1615 54b98e09 Gyusu
                    ElseIf sSymbolCompType.ToUpper() = _DB_FITTINGS.ToUpper() Then
1616 9e1e7135 Gyusu
                        _iValvecnt = _iValvecnt + 1
1617 171ac39d Gyusu
                        _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1618 6a6d8ab4 Gyusu
                        SetListBoxItems(ListBox_Result, "Place Valve..(" & dLocationX & "," & dLocationY & ")..." & _iValvecnt & " count ")
1619 171ac39d Gyusu
1620 54b98e09 Gyusu
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_FITTINGS.ToUpper() Then
1621 9e1e7135 Gyusu
                        _iFittingcnt = _iFittingcnt + 1
1622 d039e347 Gyusu
                        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 6a6d8ab4 Gyusu
                        SetListBoxItems(ListBox_Result, "Place Fitting..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1647 54b98e09 Gyusu
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() And sClass.ToUpper() = _SYMBOL_ACTUATORS.ToUpper() Then
1648 d039e347 Gyusu
                        _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 171ac39d Gyusu
                    Else
1665 9e1e7135 Gyusu
                        _iFittingcnt = _iFittingcnt + 1
1666 171ac39d Gyusu
                        _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1667 6a6d8ab4 Gyusu
                        SetListBoxItems(ListBox_Result, "Place Fitting..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1668 54b98e09 Gyusu
                        End If
1669
1670 171ac39d Gyusu
                    End If
1671 41e4023e Gyusu
                _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 171ac39d Gyusu
1677 54b98e09 Gyusu
        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 171ac39d Gyusu
            End If
1767
1768 54b98e09 Gyusu
            Return bCheck라인
1769 171ac39d Gyusu
        Catch ex As Exception
1770
            Return False
1771
        End Try
1772 54b98e09 Gyusu
1773
1774 171ac39d Gyusu
    End Function
1775
1776 460d6abd Gyusu
    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 54b98e09 Gyusu
                    If (d기준s_x <= dsx And d기준e_x >= dex And
1792
                        d기준s_y <= dsy And d기준e_y >= dey) Then
1793 460d6abd Gyusu
                        '겹쳐서 오버되는 길이가 오버되지 않는 길이의 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 abb01e6c Gyusu
                            '  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 460d6abd Gyusu
                            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 abb01e6c Gyusu
                                    dsy = d기준e_y
1835 460d6abd Gyusu
                                Else
1836 abb01e6c Gyusu
                                    dsy = dCalcStartY
1837 460d6abd Gyusu
                                End If
1838
1839
                            End If
1840
                            '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1841
                        Else
1842 abb01e6c Gyusu
                            '  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 460d6abd Gyusu
                            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 abb01e6c Gyusu
                                    dey = d기준e_y
1851 460d6abd Gyusu
                                Else
1852 abb01e6c Gyusu
                                    dey = dCalcStartY
1853 460d6abd Gyusu
                                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 abb01e6c Gyusu
                            '  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 460d6abd Gyusu
                            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 abb01e6c Gyusu
                                    dsx = d기준e_x
1901 460d6abd Gyusu
                                Else
1902 abb01e6c Gyusu
                                    dsx = dCalcStartX
1903 460d6abd Gyusu
                                End If
1904
                            End If
1905
                        Else
1906 abb01e6c Gyusu
                            ' 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 460d6abd Gyusu
                            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 abb01e6c Gyusu
                                    dex = d기준s_x
1915 460d6abd Gyusu
                                Else
1916 abb01e6c Gyusu
                                    dex = dCalcStartX
1917 460d6abd Gyusu
                                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 54b98e09 Gyusu
            Dim dRange As Double = 1 'Line 전체 길이의 10%씩 늘이기
1935 460d6abd Gyusu
            If Math.Abs(dStartX - dEndX) > Math.Abs(dStartY - dEndY) Then
1936 54b98e09 Gyusu
                Dim dCalc_x As Double = Math.Abs(dStartX - dEndX) * 0.1
1937 460d6abd Gyusu
                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 54b98e09 Gyusu
                Dim dCalc_y As Double = Math.Abs(dStartY - dEndY) * 0.1
1946 460d6abd Gyusu
                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 171ac39d Gyusu
    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 9e1e7135 Gyusu
            Dim dLocationx As Double = 0.0
1969
            Dim dLocationy As Double = 0.0
1970
1971 171ac39d Gyusu
            Dim dX As Double = 0.0
1972
            Dim dY As Double = 0.0
1973 9e1e7135 Gyusu
            If ConvertPointBystring(sLocation, dLocationx, dLocationy) Then
1974
                dX = dLocationx
1975
                dY = dLocationy
1976
                ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1977 171ac39d Gyusu
                Dim dLineNoLocation(2) As Double
1978
                dLineNoLocation(1) = dX
1979
                dLineNoLocation(2) = dY
1980
                'Label
1981
                Dim sSystemPath As String = CLine_No.SystemPath
1982 9e1e7135 Gyusu
                Dim dAngle As Double = CLine_No.Angle
1983 171ac39d Gyusu
                Dim labelpersist As LMLabelPersist
1984
1985
                For Each representation In oPiperun.Representations
1986
                    If representation.RepresentationType = "Connector" Then
1987
                        labelpersist = _Placement.PIDPlaceLabel(sSystemPath,
1988 9e1e7135 Gyusu
                        dLineNoLocation,, dAngle, LabeledItem:=representation)
1989
                        _iPipeLineNocnt = _iPipeLineNocnt + 1
1990 6a6d8ab4 Gyusu
                        SetListBoxItems(ListBox_Result, "Place PipeLineNo Label..(" & dLocationx & "," & dLocationy & ")..." & _iPipeLineNocnt & " count ")
1991 171ac39d Gyusu
                    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 9e1e7135 Gyusu
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 171ac39d Gyusu
2014 41e4023e Gyusu
    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 54b98e09 Gyusu
2030
2031 171ac39d Gyusu
    Private Function AutoModeling() As Boolean
2032
        Try
2033 54b98e09 Gyusu
            _CompleteConvert = False
2034 41e4023e Gyusu
            Label_Progress.Text = "0%"
2035 171ac39d Gyusu
            SetListBoxItems(ListBox_Result, " Auto converting 시작....")
2036
            Dim oDwg_Dt As DataTable = LoadAllDrawing()
2037 41e4023e Gyusu
            _allItem = GetAllCheckNodeCount()
2038 171ac39d Gyusu
            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 54b98e09 Gyusu
                    Dim CDrawing As Drawing = GetDrawing(sDwgName)
2042
                    If CDrawing IsNot Nothing Then
2043 9e1e7135 Gyusu
                        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 6a6d8ab4 Gyusu
                            SetListBoxItems(ListBox_Result, "Place " & CDrawing.DwgName & "....")
2048
                            For Each oNode As TreeNode In oDwgNode.Nodes
2049 54b98e09 Gyusu
                                Dim iItemcnt As Integer = 0
2050 6a6d8ab4 Gyusu
                                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 54b98e09 Gyusu
                                        Dim oPipeRun As LMPipeRun = Nothing
2055 6a6d8ab4 Gyusu
                                        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 41e4023e Gyusu
                                            Dim oRun As LMPipeRun = Nothing
2061 54b98e09 Gyusu
                                            iItemcnt = iItemcnt + 1
2062 6a6d8ab4 Gyusu
                                            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 41e4023e Gyusu
                                                    oRun = DrawLine(sUid, sNodeUid, oLine_Dt, oAttribute_Dt)
2067
                                                    If oPipeRun Is Nothing Then
2068
                                                        oPipeRun = oRun
2069
                                                    End If
2070 6a6d8ab4 Gyusu
                                                End If
2071 41e4023e Gyusu
                                                    '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 54b98e09 Gyusu
                                                    DrawLineNo(oPipeRun, CLineNo)
2079 41e4023e Gyusu
                                                Catch ex As Exception
2080
2081
                                                End Try
2082
2083 6a6d8ab4 Gyusu
                                            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 54b98e09 Gyusu
                                                    DrawSymbol(sUid, sNodeUid, oSymbol_Dt, oAttribute_Dt, CLineNo.Dt_Line)
2090 6a6d8ab4 Gyusu
                                                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 41e4023e Gyusu
                                                PlaceEquipment(sUid, oSymbol_Dt, oAttribute_Dt)
2103
                                                ' DrawSymbol(sUid, sNodeUid, oSymbol_Dt, oAttribute_Dt, CLineNo.Dt_Line)
2104 6a6d8ab4 Gyusu
                                            End If
2105
                                        Next
2106
                                    End If
2107
                                Else
2108 171ac39d Gyusu
                                    Dim oDrawLinenoLabel As Boolean = False
2109 6a6d8ab4 Gyusu
                                    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 9e1e7135 Gyusu
                                        Dim sLineUid As String = oLineNode.Name
2114
                                        If oLineNode.Checked Then
2115
                                            Dim sUid As String = oLineNode.Name
2116 6a6d8ab4 Gyusu
                                            DrawLine(sUid, sNodeUid, oLine_Dt, oAttribute_Dt)
2117 171ac39d Gyusu
                                        End If
2118 9e1e7135 Gyusu
                                    Next
2119
                                End If
2120 41e4023e Gyusu
2121
2122
2123 9e1e7135 Gyusu
                            Next
2124 171ac39d Gyusu
                        End If
2125 9e1e7135 Gyusu
                    End If
2126 171ac39d Gyusu
                Next
2127
            Next
2128
            SetProgressbar(ProgressBar_Status, 100)
2129 41e4023e Gyusu
            Label_Progress.Text = "100%"
2130 171ac39d Gyusu
            SetListBoxItems(ListBox_Result, " Auto converting 완료")
2131 54b98e09 Gyusu
            _CompleteConvert = True
2132 171ac39d Gyusu
            Return True
2133
        Catch ex As Exception
2134
            Return False
2135
        End Try
2136
    End Function
2137
2138
2139
2140 54b98e09 Gyusu
    Private Sub ThreadConvert()
2141 559daf6d Gyusu
        If _DrawingsList IsNot Nothing Then
2142
            If _DrawingsList.Count > 0 Then
2143
                AutoModeling()
2144
            End If
2145 171ac39d Gyusu
        End If
2146 e282643f Gyusu
    End Sub
2147
2148 54b98e09 Gyusu
    Private Sub ThreadOPCRemove()
2149
        While _CompleteConvert = False
2150
            Dim oFindOPC As New FindOpc
2151
            oFindOPC.RemoveOPCDlg()
2152
        End While
2153 e282643f Gyusu
2154 54b98e09 Gyusu
    End Sub
2155 171ac39d Gyusu
2156 e282643f Gyusu
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 272662f9 Gyusu
    Private Sub LoadXmlToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LoadXmlToolStripMenuItem.Click
2167 171ac39d Gyusu
        If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
2168 54b98e09 Gyusu
            LoadDB()
2169 171ac39d Gyusu
            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 272662f9 Gyusu
2191
2192 20c84e05 Gyusu
    ''' <summary>
2193
    '''  XML Tree 구조 생성 
2194
    ''' </summary>
2195
    ''' <param name="sDwgPath"></param>
2196 171ac39d Gyusu
    Private Function AddSymbolItem(ByVal sDwgPath As String, ByVal oParentNode As TreeNode) As Drawing
2197
        Dim oDwg_Ds As Drawing = LoadSymbolInXml(sDwgPath)
2198 54b98e09 Gyusu
        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 20c84e05 Gyusu
2225 54b98e09 Gyusu
                '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 6a6d8ab4 Gyusu
2236 272662f9 Gyusu
2237 6a6d8ab4 Gyusu
2238
2239 54b98e09 Gyusu
                '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 d039e347 Gyusu
2256 54b98e09 Gyusu
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 171ac39d Gyusu
            Next
2264 54b98e09 Gyusu
        End If
2265
2266 171ac39d Gyusu
        Return oDwg_Ds
2267
    End Function
2268 272662f9 Gyusu
    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 171ac39d Gyusu
2280 559daf6d Gyusu
    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 42c0013c Gyusu
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 39d43554 Gyusu
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 41e4023e Gyusu
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 e282643f Gyusu
End Class
2354
2355
2356
Public Class DrawingInfo
2357
    Public mDrawingName As String
2358
    Public mSpID As String
2359
    Public mPath As String
2360 4f359afa Gyusu
End Class
2361 e282643f Gyusu
2362
2363
2364
클립보드 이미지 추가 (최대 크기: 500 MB)