프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / Main.vb @ 37fe970d

이력 | 보기 | 이력해설 | 다운로드 (110 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 c2c36314 Gyusu
    Dim _DWG_X = 0.89 '0.695 '1 '
19
    Dim _DWG_Y = 0.61 '0.585 '0.8 '
20
    'Dim _DWG_X = 0.842 '0.695 '1 '
21
    'Dim _DWG_Y = 0.614 '0.585 '0.8 '
22 171ac39d Gyusu
    Dim _IMG_X = 0
23
    Dim _IMG_Y = 0
24
25
    Dim _Unit As String
26 4f359afa Gyusu
27 31d47a80 Gyusu
    'Drawing 전역변수
28
    Dim _objPIDADrawing As Object
29 e282643f Gyusu
    '현재선택한 폴더경로
30
    Dim _selectFolderPath As String
31
32
    Private _Main_trd As Thread
33 54b98e09 Gyusu
    Private _Opc_trd As Thread
34
35
    Private _CompleteConvert As Boolean = False
36 e282643f Gyusu
37 171ac39d Gyusu
    Private _DrawingsList As List(Of Drawing)
38 272662f9 Gyusu
39
40 9e1e7135 Gyusu
    Private _iPipeLineNocnt As Integer
41
    Private _iPipecnt As Integer
42
    Private _iFittingcnt As Integer
43
    Private _iValvecnt As Integer
44
    Private _iInstrumentcnt As Integer
45
    Private _iEquipmentcnt As Integer
46
    Private _iNozzlecnt As Integer
47
48 54b98e09 Gyusu
    Dim _Gembox As New CGembox()
49 41e4023e Gyusu
50
51
    Private _allItem As Integer
52
    Private _Itemcnt As Integer
53 4f359afa Gyusu
    Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
54 54b98e09 Gyusu
        LoadDB()
55
    End Sub
56 272662f9 Gyusu
57 54b98e09 Gyusu
    Private Sub LoadDB()
58 e282643f Gyusu
        If My.Settings.DBPath <> "" And My.Settings.Plant_Hierarchy <> "" Then
59
            Dim sDBPath As String = My.Settings.DBPath
60 54b98e09 Gyusu
61
            _Gembox.isLoadFile(My.Settings.SymbolLibrary)
62
            _Mapping_DB = _Gembox.LoadFileFunc()
63
            '  _Mapping_DB = Load_DB(sDBPath, _DB_TABLE_MAPPING)
64 171ac39d Gyusu
            _Attribute_DB = Load_DB(sDBPath, _DB_TABLE_ATTRIBUTE)
65 39d43554 Gyusu
            _PIDSymbol_DB = Load_DB(sDBPath, _DB_TABLE_SYMBOLNAME)
66 6a6d8ab4 Gyusu
            'TestPID()
67
            'OpenDrawing()
68 e282643f Gyusu
        Else
69
            MessageBox.Show("설정값을 먼저 확인해주세요")
70
        End If
71
    End Sub
72 41e4023e Gyusu
73 e282643f Gyusu
    Public Function GetDrawingInfo(ByVal errorList As ArrayList)
74
        Dim ds As Llama.LMADataSource
75
        ds = New Llama.LMADataSource
76
        Dim lmaItem As Llama.LMAItem
77
        For i = 0 To errorList.Count - 1
78
            lmaItem = ds.GetModelItem(errorList.Item(i).m_strSPID()).AsLMAItem
79
            Dim drawingInfo As DrawingInfo
80
            drawingInfo = GetDrawingName(lmaItem.ItemType, lmaItem.Id)
81
            errorList.Item(i).m_LMAItem = lmaItem
82
            errorList.Item(i).m_strDrawingName = drawingInfo.mDrawingName
83
            errorList.Item(i).m_strDrawingPath = drawingInfo.mPath
84
        Next
85
    End Function
86
    Private mDataSource As Object
87
88
    'Public Sub New()
89
90
    '    '  mDataSource.ProjectNumber = m_Information.InfoSite.SiteName
91
    '    '   mDataSource.SiteNode = m_Information.InfoProject.ProjectINI
92
    '    'm_Information = SPPIDClass.Information.GetInstance()
93
94
    '    'If m_Information.InfoProject.ProjectVersion = SPPIDClass.InfoProject.SPPID_43 Then
95
    '    '    'SPPID4.3용
96
    '    '    mDataSource.ProjectNumber = m_Information.InfoSite.SiteName
97
    '    'Else
98
    '    '    'SPPID2007, SPPID2009용
99
    '    '    mDataSource.ProjectNumber = m_Information.InfoSite.SiteName & "!" & m_Information.InfoSite.SiteName
100
    '    'End If
101
102
    '    '  mDataSource.SiteNode = m_Information.InfoProject.ProjectINI
103
    '    '  mDataSource.ProjectNumber = m_Information.InfoSite.SiteName & "!" & m_Information.InfoSite.SiteName
104
    '    '#If LATE_BINDING Then
105
    '    '        mInstruments = CreateObject("Llama.LMInstruments", "")
106
    '    '        mPipingComps = CreateObject("Llama.LMPipingComps", "")
107
    '    '        mVessels = CreateObject("Llama.LMVessels", "")
108
    '    '        mDrawings = CreateObject("Llama.LMDrawings", "")
109
    '    '        mEquipments = CreateObject("Llama.LMEquipments", "")
110
    '    '        mExchangers = CreateObject("Llama.LMExchangers", "")
111
    '    '        mMechanicals = CreateObject("Llama.LMMechanicals", "")
112
    '    '        mNozzles = CreateObject("Llama.LMNozzles", "")
113
    '    '        mPipeRuns = CreateObject("Llama.LMPipeRuns", "")
114
    '    '        mEquipmentOthers = CreateObject("Llama.LMEquipmentOthers", "")
115
    '    '#Else
116
    '    '        mInstruments = New Llama.LMInstruments
117
    '    '        mPipingComps = New Llama.LMPipingComps
118
    '    '        mVessels = New Llama.LMVessels
119
    '    '        mDrawings = New Llama.LMDrawings
120
    '    '        mEquipments = New Llama.LMEquipments
121
    '    '        mExchangers = New Llama.LMExchangers
122
    '    '        mMechanicals = New Llama.LMMechanicals
123
    '    '        mNozzles = New Llama.LMNozzles
124
    '    '        mPipeRuns = New Llama.LMPipeRuns
125
    '    '        mEquipmentOthers = New Llama.LMEquipmentOthers
126
    '    '#End If
127
    'End Sub
128 559daf6d Gyusu
129
    Function OpenDrawing()
130
        Dim datasource As LMADataSource
131
        Dim objPIDAutoApp As Object
132
        Dim objPIDADrawing As Object
133
        Dim objDrawing As LMDrawing
134
        Dim objDrawings As LMDrawings
135
        datasource = New Llama.LMADataSource
136
        objPIDAutoApp = CreateObject("PIDAutomation.Application")
137
        objDrawings = New Llama.LMDrawings 'New LMDrawings
138 b6996671 Gyusu
        datasource.SiteNode = "\\desktop-9vlq0dp\Test03Site\smartplantv4.ini"
139 559daf6d Gyusu
        datasource.ProjectNumber = "SBR_PBR"
140
        objDrawings.Collect(datasource)
141
142
        For Each objDrawing In objDrawings
143
            If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
144
                objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(objDrawing.Attributes("Name"))
145
                If Not objPIDADrawing Is Nothing Then
146
                    'MsgBox "Drawing " & objDrawing.Attributes("Name").Value & " is opened!"
147
                    objPIDADrawing.CloseDrawing
148
                End If
149
            End If
150
        Next
151
        objPIDAutoApp.Quit
152
        objPIDAutoApp = Nothing
153
        objPIDADrawing = Nothing
154
        objDrawing = Nothing
155
        objDrawings = Nothing
156
    End Function
157
158
159 e282643f Gyusu
    Public Function GetDrawingName(ByVal itemType As String, ByVal itemName As String) As DrawingInfo
160
161
        Dim objFilter As Object
162
        objFilter = CreateObject("Llama.LMAFilter", "")
163
164
        Dim drawingInfo As DrawingInfo
165
        drawingInfo = New DrawingInfo
166
167
        objFilter.Criteria.AddNew("FirstOne")
168
        objFilter.Criteria.Item("FirstOne").SourceAttributeName = "SP_ID"
169
        objFilter.Critedkria.Item("FirstOne").ValueAttribute = itemName
170
171
        objFilter.Criteria.Item("FirstOne").Operator = "="
172
        objFilter.Criteria.AddNew("SecondOne")
173
        objFilter.Criteria.Item("SecondOne").SourceAttributeName = "ItemStatus"
174
        objFilter.Criteria.Item("SecondOne").ValueAttribute = 1
175
        objFilter.Criteria.Item("SecondOne").Operator = "="
176
        objFilter.Criteria.Item("SecondOne").Conjunctive = -1
177
        objFilter.ItemType = itemType
178
179
        Dim PlantItems As Object
180
        PlantItems = CreateObject("Llama.LMPlantItems", "")
181
        PlantItems.Collect(mDataSource, Filter:=objFilter)
182
183
        If PlantItems.Count = 0 Then
184
            drawingInfo.mSpID = "PlantStockpile"
185
        End If
186
187
        For Each PlantItem In PlantItems
188
189
            'If Not PlantItem.Representations.Nth(1).DrawingID.Value.ToString().Equals("0") Then
190
            Try
191
                drawingInfo.mDrawingName = PlantItem.Representations.Nth(1).DrawingObject.Attributes("Name").Value
192
                drawingInfo.mSpID = PlantItem.Representations.Nth(1).DrawingID
193
                drawingInfo.mPath = PlantItem.Representations.Nth(1).DrawingObject.Attributes("Path").Value
194
                Debug.WriteLine("DrawingName : " & drawingInfo.mDrawingName & ", SPID : " & drawingInfo.mSpID & ", Path : " & drawingInfo.mPath)
195
            Catch ex As Exception
196
197
            End Try
198
199
            'End If
200
201
        Next
202
203
        Return drawingInfo
204
205
    End Function
206
207
    Private Sub TestPID()
208
        Try
209 6a6d8ab4 Gyusu
            Const CONST_SPID_OPC As String = "426E89964A7F49208AD79E1F320DA251"
210 e282643f Gyusu
            Dim datasource As LMADataSource
211
            Dim objPIDAutoApp As Object
212
            Dim objPIDADrawing As Object
213
            Dim objDrawing As LMDrawing
214
            Dim objDrawings As LMDrawings
215
            datasource = New LMADataSource
216 6a6d8ab4 Gyusu
            Dim objOPC As LMOPC
217
            Dim objpairOPC As LMOPC
218
            objOPC = datasource.GetOPC(CONST_SPID_OPC)
219
            objpairOPC = objOPC.pairedWithOPCObject
220 e282643f Gyusu
            Dim oObj As Object = Nothing
221
            objDrawing = datasource.GetDrawing(oObj)
222
            objDrawings = New LMDrawings
223
            objDrawings.Collect(datasource)
224
            objPIDAutoApp = GetObject(, "SmartPlantPID.Application") '// CreateObject("PIDAutomation.Application")
225
            For Each objDrawing In objDrawings
226
                If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
227
                    objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(objDrawing.Attributes("Name"))
228
                    If Not objPIDADrawing Is Nothing Then
229
                        MessageBox.Show("Drawing " & objDrawing.Attributes("Name").Value & " is opened!")
230
                        objPIDADrawing.CloseDrawing
231
                    End If
232
                End If
233
            Next
234
            objPIDAutoApp.Quit
235
            objPIDAutoApp = Nothing
236
            objPIDADrawing = Nothing
237
            objDrawing = Nothing
238
            objDrawings = Nothing
239
        Catch ex As Exception
240
        End Try
241 962b2464 Gyusu
    End Sub
242 e282643f Gyusu
243 b6996671 Gyusu
    Public Function SetActiveSiteFromConfigInfo(ByVal strActiveSite As String) As Boolean
244 e282643f Gyusu
        On Error GoTo errHandler
245
        Dim objConfigInfo As Object 'interopigrConfigInfo412.igrConfigInfo
246
        objConfigInfo = CreateObject("interopigrConfigInfo412.igrConfigInfo", "")
247
        If Not objConfigInfo Is Nothing Then
248
            objConfigInfo.ApplicationName = "SmartPlantManager"
249
            objConfigInfo.SetConfigString(3, "SmartPlant Manager", "SiteServer", strActiveSite)
250
            SetActiveSiteFromConfigInfo = True
251
        End If
252
        objConfigInfo = Nothing
253
        Exit Function
254
errHandler:
255
        '    LogAndRaiseError ModuleName & "::GetConfigInfo "
256
    End Function
257 4f359afa Gyusu
258 1229ad76 Gyusu
    Private Function CreateDwg(ByVal oDwgName As String) As Boolean
259
        Dim objPIDADrawing As Object = Nothing
260
        Dim objPIDAutoApp As Object = Nothing
261
        Dim datasource As LMADataSource = Nothing
262 4f359afa Gyusu
        Try
263
            Dim DrawingNumber As String
264
            Dim DrawingName As String
265 1229ad76 Gyusu
            Dim sPlantGroupName As String = "Test"
266
            Dim sTemplateName As String = "\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\P&ID Reference Data\Template Files\Gazprom Project.pid"
267
            Dim objDrawing As LMDrawing
268
            Dim objDrawings As LMDrawings
269
            objDrawings = New LMDrawings
270
            datasource = New LMADataSource
271
            Debug.Print(datasource.ProjectNumber)
272
            Debug.Print(datasource.SiteNode)
273
            Debug.Print(datasource.IsSatellite)
274
            Debug.Print(datasource.GetSystemEditingToolbarSetting)
275
            objDrawings.Collect(datasource)
276
            Dim sPath As String = "‪\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\Plant_Hierarchy\8121\8121-1\188943-8121-PR-DW-011001.pid"
277
            objPIDAutoApp = CreateObject("PIDAutomation.Application")
278 54b98e09 Gyusu
279 1229ad76 Gyusu
            For Each objDrawing In objDrawings
280
                If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
281
                    objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(sPath)
282
                    If Not objPIDADrawing Is Nothing Then
283
                        objPIDADrawing.CloseDrawing
284
                    End If
285
                End If
286
            Next
287 4f359afa Gyusu
288
            Dim extension As String = Path.GetExtension(oDwgName)
289
            oDwgName = oDwgName.Replace(extension, "")
290 1229ad76 Gyusu
291 4f359afa Gyusu
            objPIDAutoApp = CreateObject("PIDAutomation.Application")
292 1229ad76 Gyusu
293
            'For Each objDrawing In objPIDAutoApp.Drawings
294
            '    objDrawing.CloseDrawing(True)
295
            'Next
296
297
            objPIDAutoApp.Drawings.OpenDrawing(oDwgName + ".pid")
298
299
            objPIDAutoApp.ActiveWindow.Fit()
300
301
            Return True
302
        Catch ex As Exception
303
            If objPIDADrawing IsNot Nothing Then
304 4f359afa Gyusu
                objPIDADrawing.CloseDrawing
305
            End If
306 1229ad76 Gyusu
            If objPIDAutoApp IsNot Nothing Then
307
                objPIDAutoApp.Quit
308
            End If
309
            datasource = Nothing
310 4f359afa Gyusu
            objPIDAutoApp = Nothing
311
            objPIDADrawing = Nothing
312
            Return False
313
        End Try
314 1229ad76 Gyusu
        If objPIDADrawing IsNot Nothing Then
315
            objPIDADrawing.CloseDrawing
316
        End If
317 4f359afa Gyusu
318
    End Function
319
320 1229ad76 Gyusu
321 171ac39d Gyusu
    Private Function GetDataFromMappingDB(ByVal sSymbolName As String, ByVal sColumn As String) As String
322
        Dim sValue As String = ""
323 54b98e09 Gyusu
        For Each oDt As DataTable In _Mapping_DB.Tables
324
            If oDt.Rows.Count > 0 Then
325
                Dim oSelectRow() As DataRow = oDt.Select("[img_symbolname] = '" + sSymbolName + "'")
326
                If oSelectRow.Length = 1 Then
327
                    If sColumn = _DB_COLUMN_MAPPING_SPPID_SYMBOLNAME Then
328
                        sValue = oSelectRow(0).Item("SYM FILE NAME").ToString()
329
                    ElseIf sColumn = _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH Then
330
                        sValue = "\" & oSelectRow(0).Item("SYMBOL PATH").ToString() & "\" & oSelectRow(0).Item("SYM FILE NAME").ToString()
331
                    ElseIf sColumn = _DB_COLUMN_MAPPING_SPPID_COMPTPYE Then
332
                        sValue = oSelectRow(0).Item("ITEM TYPE").ToString()
333
                    ElseIf sColumn = _DB_COLUMN_MAPPING_SPPID_CLASS Then
334
                        sValue = oSelectRow(0).Item("CLASS").ToString()
335
                    Else
336
                        sValue = oSelectRow(0).Item("SYMBOL PATH").ToString() & "\" & oSelectRow(0).Item("SYM FILE NAME").ToString()
337
                    End If
338
339
                End If
340 e282643f Gyusu
            End If
341 54b98e09 Gyusu
        Next
342
343 171ac39d Gyusu
        Return sValue
344 4f359afa Gyusu
    End Function
345
346 171ac39d Gyusu
    Private Function GetAttributeMapping(ByVal sAttributeName As String, ByVal sColumn As String) As String
347
        Dim sSPPIDAttribute As String = ""
348
        If _Attribute_DB.Rows.Count > 0 Then
349
            Dim oSelectRow() As DataRow = _Attribute_DB.Select("[pid_attribute] = '" + sAttributeName + "'")
350
            If oSelectRow.Length = 1 Then
351
                sSPPIDAttribute = oSelectRow(0).Item(sColumn).ToString()
352
            End If
353
        End If
354
        Return sSPPIDAttribute
355
    End Function
356 e282643f Gyusu
357 d039e347 Gyusu
    '  Dim _TempSymbolDt As DataTable = Symbol_Dt()
358 6a6d8ab4 Gyusu
359
360 171ac39d Gyusu
    Private Function LoadSymbolInXml(ByVal sXmlPath As String) As Drawing
361 54b98e09 Gyusu
        Try
362
            ''  _TempSymbolDt = Symbol_Dt()
363
            Dim CDrawing As Drawing = New Drawing()
364
            Dim oDt As DataTable = LoadSymbol_DT()
365
            Dim oElement As XElement = XElement.Load(sXmlPath)
366 6a6d8ab4 Gyusu
367 54b98e09 Gyusu
            If oElement IsNot Nothing Then
368
                CDrawing.DwgName = oElement.Element(_XML_DWGNAME).Value
369
                CDrawing.Size = oElement.Element(_XML_DWGSIZE).Value
370
                SplitLocation(CDrawing.Size, _IMG_X, _IMG_Y)
371
                CDrawing.Unit = oElement.Element(_XML_UNIT).Value
372 171ac39d Gyusu
373 54b98e09 Gyusu
                Dim oLineno_list As New List(Of Line_no)
374
                Dim oEqp_list As New List(Of Eqp_no)
375 3acffcee Gyusu
                Dim oTrim_Lineno_list As New List(Of Line_no)
376
                oLineno_list = LoadLineNo(oElement, _XML_CATEGORY_LINENO)
377 54b98e09 Gyusu
                For Each oEqpNo As Object In oElement.Elements(_XML_CATEGORY_EQUIPMENT)
378
                    Dim CEqp_no As Eqp_no = New Eqp_no()
379
                    Dim oSymbol_Dt As DataTable = Symbol_Dt()
380
                    Dim oAttribute_Dt As DataTable = Attribute_Dt()
381 41e4023e Gyusu
                    Dim sUid As String
382 54b98e09 Gyusu
                    For Each oSymbol As Object In oEqpNo.Elements(_XML_CATEGORY_SYMBOL)
383
                        Try
384
                            Dim oAddrow As DataRow = oSymbol_Dt.NewRow()
385
                            Dim oEleObj As XElement
386
                            Dim sName As String
387
                            Dim sLocation As String
388
                            Dim sSize As String
389
                            Dim sAngle As String
390
                            Dim sOriginalPoint As String = ""
391
                            oEleObj = oSymbol.Element(_XML_SYMBOL_UID)
392
                            sUid = oEleObj.Value
393
                            oEleObj = oSymbol.Element(_XML_SYMBOL_NAME)
394
                            sName = oEleObj.Value
395
                            oEleObj = oSymbol.Element(_XML_SYMBOL_LOCATION)
396
                            sLocation = oEleObj.Value
397
                            oEleObj = oSymbol.Element(_XML_SYMBOL_SIZE)
398
                            sSize = oEleObj.Value
399
                            oEleObj = oSymbol.Element(_XML_SYMBOL_ANGLE)
400
                            sAngle = oEleObj.Value
401
                            Try
402
                                oEleObj = oSymbol.Element(_XML_SYMBOL_ORIGINALPOINT)
403
                                sOriginalPoint = oEleObj.Value
404
                            Catch ex As Exception
405
                            End Try
406
                            oAddrow(_XML_SYMBOL_UID) = sUid
407
                            oAddrow(_XML_SYMBOL_NAME) = sName
408
                            oAddrow(_XML_SYMBOL_LOCATION) = sLocation
409
                            oAddrow(_XML_SYMBOL_SIZE) = sSize
410
                            oAddrow(_XML_SYMBOL_ANGLE) = sAngle
411
                            oAddrow(_XML_SYMBOL_SYSTEMPATH) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
412
                            oAddrow(_XML_SYMBOL_TYPE) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_COMPTPYE)
413
                            oAddrow(_XML_SYMBOL_ORIGINALPOINT) = sOriginalPoint
414
                            oSymbol_Dt.Rows.Add(oAddrow)
415
                        Catch ex As Exception
416
417
                        End Try
418 d039e347 Gyusu
                    Next
419 54b98e09 Gyusu
                    For Each oAtrribute As Object In oEqpNo.Elements(_XML_CATEGORY_ATTRIBUTE)
420
                        Try
421
                            Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
422
                            Dim oEleObj As XElement
423 41e4023e Gyusu
                            Dim sAttUid As String
424 54b98e09 Gyusu
                            Dim sName As String
425
                            Dim sValue As String
426
                            oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
427 41e4023e Gyusu
                            sAttUid = oEleObj.Value
428 54b98e09 Gyusu
                            oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
429
                            sName = oEleObj.Value
430
                            oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
431
                            sValue = oEleObj.Value
432 41e4023e Gyusu
                            oAddrow(_XML_ATTRIBUTE_UID) = sAttUid
433 54b98e09 Gyusu
                            oAddrow(_XML_ATTRIBUTE_NAME) = sName
434
                            oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
435
                            oAttribute_Dt.Rows.Add(oAddrow)
436
                        Catch ex As Exception
437
                        End Try
438
                    Next
439 41e4023e Gyusu
                    CEqp_no.Uid = sUid
440 54b98e09 Gyusu
                    CEqp_no.Dt_Equipment = oSymbol_Dt
441
                    CEqp_no.Dt_Attribute = oAttribute_Dt
442
                    oEqp_list.Add(CEqp_no)
443 4f359afa Gyusu
                Next
444 3acffcee Gyusu
                oTrim_Lineno_list = LoadLineNo(oElement, _XML_CATEGORY_TRIM_LINENO)
445 54b98e09 Gyusu
                CDrawing.Line_nos = oLineno_list
446
                CDrawing.Eqp_nos = oEqp_list
447 3acffcee Gyusu
                CDrawing.TrimLine_nos = oTrim_Lineno_list
448
449 54b98e09 Gyusu
            End If
450
            Return CDrawing
451
        Catch ex As Exception
452
            Return Nothing
453
        End Try
454
455 4f359afa Gyusu
    End Function
456
457
458 3acffcee Gyusu
    Private Function LoadLineNo(ByVal oElement As XElement, ByVal sLineType As String) As List(Of Line_no)
459
460
        Dim oLineno_list As New List(Of Line_no)
461
462
        For Each oLineNo As Object In oElement.Elements(sLineType)
463
464
            Dim CLineNo As Line_no = New Line_no()
465
            Try
466
                CLineNo.Uid = oLineNo.Element(_XML_LINENO_UID).Value
467
                CLineNo.Text = oLineNo.Element(_XML_LINENO_TEXT).Value
468
                CLineNo.Location = oLineNo.Element(_XML_LINENO_LOCATION).Value
469
                CLineNo.Angle = oLineNo.Element(_XML_LINENO_ANGLE).Value
470
                CLineNo.SystemPath = "\Piping\Labels - Piping Segments\Kemya Line Number.sym" 'GetDataFromMappingDB(_XML_CATEGORY_LINENO, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
471
            Catch ex As Exception
472
                'CLineNo.Text = "PipeLineNo"
473
                'CLineNo.Uid = "PipeLineNo"
474
            End Try
475
476
477
            Dim oLine_Dt As DataTable = Line_Dt()
478
            Dim oSymbol_Dt As DataTable = Symbol_Dt()
479
            Dim oAttribute_Dt As DataTable = Attribute_Dt()
480
481
            For Each oRun As Object In oLineNo.Elements(_XML_CATEGORY_RUN)
482
                For Each oLine As Object In oRun.Elements(_XML_CATEGORY_LINE)
483
                    Try
484
                        Dim oAddrow As DataRow = oLine_Dt.NewRow()
485
                        Dim oEleObj As XElement
486
                        Dim sUid As String
487
                        Dim sStartpoint As String
488
                        Dim sEndpoint As String
489 c2c36314 Gyusu
                        Dim sType As String
490 3acffcee Gyusu
                        oEleObj = oLine.Element(_XML_LINE_UID)
491
                        sUid = oEleObj.Value
492
                        oEleObj = oLine.Element(_XML_LINE_STARTPOINT)
493
                        sStartpoint = oEleObj.Value
494
                        oEleObj = oLine.Element(_XML_LINE_ENDPOINT)
495
                        sEndpoint = oEleObj.Value
496 c2c36314 Gyusu
                        oEleObj = oLine.Element(_XML_LINE_TYPE)
497
                        sType = oEleObj.Value
498 3acffcee Gyusu
                        oAddrow(_XML_LINE_UID) = sUid
499
                        oAddrow(_XML_LINE_STARTPOINT) = sStartpoint
500
                        oAddrow(_XML_LINE_ENDPOINT) = sEndpoint
501
                        oAddrow(_XML_LINE_SYSTEMPATH) = GetDataFromMappingDB(_XML_CATEGORY_LINE, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
502
                        oAddrow(_XML_LINE_DRAWING) = "FALSE"
503 c2c36314 Gyusu
                        oAddrow(_XML_LINE_TYPE) = sType
504 3acffcee Gyusu
                        oLine_Dt.Rows.Add(oAddrow)
505
                    Catch ex As Exception
506
507
                    End Try
508
509
                Next
510
511
                For Each oSymbol As Object In oRun.Elements(_XML_CATEGORY_SYMBOL)
512
                    Try
513
                        Dim oAddrow As DataRow = oSymbol_Dt.NewRow()
514
                        Dim oEleObj As XElement
515
                        Dim sUid As String
516
                        Dim sName As String
517
                        Dim sLocation As String
518
                        Dim sSize As String
519
                        Dim sAngle As String
520
                        Dim sOriginalPoint As String = ""
521
                        oEleObj = oSymbol.Element(_XML_SYMBOL_UID)
522
                        sUid = oEleObj.Value
523
                        oEleObj = oSymbol.Element(_XML_SYMBOL_PARENT)
524
                        sName = oEleObj.Value
525
                        oEleObj = oSymbol.Element(_XML_SYMBOL_LOCATION)
526
                        sLocation = oEleObj.Value
527
                        oEleObj = oSymbol.Element(_XML_SYMBOL_SIZE)
528
                        sSize = oEleObj.Value
529
                        oEleObj = oSymbol.Element(_XML_SYMBOL_ANGLE)
530
                        sAngle = oEleObj.Value
531
                        Try
532
                            oEleObj = oSymbol.Element(_XML_SYMBOL_ORIGINALPOINT)
533
                            sOriginalPoint = oEleObj.Value
534
                        Catch ex As Exception
535
536
                        End Try
537
538
                        oAddrow(_XML_SYMBOL_UID) = sUid
539
                        oAddrow(_XML_SYMBOL_NAME) = IO.Path.GetFileNameWithoutExtension(GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYMBOLNAME))
540
                        oAddrow(_XML_SYMBOL_LOCATION) = sLocation
541
                        oAddrow(_XML_SYMBOL_SIZE) = sSize
542
                        oAddrow(_XML_SYMBOL_ANGLE) = sAngle
543
                        oAddrow(_XML_SYMBOL_SYSTEMPATH) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
544
                        oAddrow(_XML_SYMBOL_TYPE) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_COMPTPYE)
545
                        oAddrow(_XML_SYMBOL_CLASS) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_CLASS)
546
                        oAddrow(_XML_SYMBOL_ORIGINALPOINT) = sOriginalPoint
547
548
                        oSymbol_Dt.Rows.Add(oAddrow)
549
                    Catch ex As Exception
550
551
                    End Try
552
553
                Next
554
555
                For Each oAtrribute As Object In oRun.Elements(_XML_CATEGORY_ATTRIBUTE)
556
                    Try
557
                        Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
558
                        Dim oEleObj As XElement
559
                        Dim sUid As String
560
                        Dim sName As String
561
                        Dim sValue As String
562
563
                        oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
564
                        sUid = oEleObj.Value
565
                        oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
566
                        sName = oEleObj.Value
567
                        oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
568
                        sValue = oEleObj.Value
569
570
                        oAddrow(_XML_ATTRIBUTE_UID) = sUid
571
                        oAddrow(_XML_ATTRIBUTE_NAME) = sName
572
                        oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
573
                        oAttribute_Dt.Rows.Add(oAddrow)
574
                    Catch ex As Exception
575
576
                    End Try
577
578
                Next
579
580
            Next
581
            'Line No Attribute
582
            For Each oAtrribute As Object In oLineNo.Elements(_XML_CATEGORY_ATTRIBUTE)
583
                Try
584
                    Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
585
                    Dim oEleObj As XElement
586
                    Dim sUid As String = ""
587
                    Dim sName As String
588
                    Dim sValue As String
589
590
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
591
                    sUid = oEleObj.Value
592
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
593
                    sName = oEleObj.Value
594
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
595
                    sValue = oEleObj.Value
596
                    oAddrow(_XML_ATTRIBUTE_UID) = sUid
597
                    oAddrow(_XML_ATTRIBUTE_NAME) = sName
598
                    oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
599
                    oAttribute_Dt.Rows.Add(oAddrow)
600
                Catch ex As Exception
601
                End Try
602
            Next
603
            CLineNo.Dt_Line = oLine_Dt
604
            CLineNo.Dt_Symbol = oSymbol_Dt
605
            CLineNo.Dt_Attribute = oAttribute_Dt
606
            oLineno_list.Add(CLineNo)
607
        Next
608
        Return oLineno_list
609
    End Function
610
611 4f359afa Gyusu
612 171ac39d Gyusu
    'Private Function LoadPipeInXml(ByVal sXmlPath As String) As DataTable
613
    '    Try
614
    '        Dim oDt As DataTable = LoadPipe_DT()
615
    '        Dim oElement As XElement = XElement.Load(sXmlPath)
616
    '        If oElement IsNot Nothing Then
617
    '            Dim DWGElement As XElement = oElement.Element("DWGNAME")
618
    '            Dim DWGNAME = DWGElement.Value
619
    '            Dim sXY As XElement = oElement.Element("SIZE")
620
    '            Dim sSize = sXY.Value
621
    '            Dim oSplitDWGPos As String() = sSize.Split(", ")
622 4f359afa Gyusu
623 171ac39d Gyusu
    '            If IsNumeric(oSplitDWGPos(0)) Then
624
    '                _IMG_X = Double.Parse(oSplitDWGPos(0))
625
    '            End If
626
    '            If IsNumeric(oSplitDWGPos(1)) Then
627
    '                _IMG_Y = Double.Parse(oSplitDWGPos(1))
628
    '            End If
629 4f359afa Gyusu
630 171ac39d Gyusu
    '            For Each pipes As Object In oElement.Elements("IMGLINES")
631
    '                For Each pipe As Object In pipes.Elements("IMGLINE")
632
    '                    Dim oAddrow As DataRow = oDt.NewRow()
633
    '                    Dim oObj As XElement = pipe.Element("ITEM")
634
    '                    Dim oItem = oObj.Value
635
    '                    ' Dim oSymbolPath As String = "\" + oSymbol + "\" + oClass + "\" + oType + "\" + oItem + ".sym"
636
    '                    Dim oSymbolPath As String = GetSystemPathFromMappingDB(oItem)
637
    '                    oObj = pipe.Element("START")
638
    '                    Dim oStartPoint = oObj.Value
639
    '                    Dim oSplitPos As String() = oStartPoint.Split(", ")
640
    '                    Dim oStartpos_X As Double = 0.0
641
    '                    Dim oStartpos_Y As Double = 0.0
642
    '                    If IsNumeric(oSplitPos(0)) Then
643
    '                        oStartpos_X = Double.Parse(oSplitPos(0))
644
    '                    End If
645
    '                    If IsNumeric(oSplitPos(1)) Then
646
    '                        oStartpos_Y = Double.Parse(oSplitPos(1))
647
    '                    End If
648 4f359afa Gyusu
649 171ac39d Gyusu
    '                    ConvertPoint(oStartpos_X, oStartpos_Y, _DWG_X, _DWG_Y)
650
    '                    oObj = pipe.Element("End")
651
    '                    Dim oEndPoint = oObj.Value
652
    '                    oSplitPos = oEndPoint.Split(", ")
653
    '                    Dim oEndpos_X As Double = 0.0
654
    '                    Dim oEndpos_Y As Double = 0.0
655
    '                    If IsNumeric(oSplitPos(0)) Then
656
    '                        oEndpos_X = Double.Parse(oSplitPos(0))
657
    '                    End If
658
    '                    If IsNumeric(oSplitPos(1)) Then
659
    '                        oEndpos_Y = Double.Parse(oSplitPos(1))
660
    '                    End If
661
    '                    ConvertPoint(oEndpos_X, oEndpos_Y, _DWG_X, _DWG_Y)
662 4f359afa Gyusu
663 171ac39d Gyusu
    '                    oAddrow("start_x") = oStartpos_X '+ 0.05
664
    '                    oAddrow("start_y") = oStartpos_Y
665
    '                    oAddrow("end_x") = oEndpos_X
666
    '                    oAddrow("end_y") = oEndpos_Y
667
    '                    oAddrow("SystemPath") = oSymbolPath
668
    '                    oDt.Rows.Add(oAddrow)
669
    '                Next
670
    '            Next
671
672
    '        End If
673 4f359afa Gyusu
674 171ac39d Gyusu
675
    '        Return oDt
676
    '    Catch ex As Exception
677
    '        Return Nothing
678
    '    End Try
679
    'End Function
680 4f359afa Gyusu
681
682 9e1e7135 Gyusu
    Private Sub ConvertPointByImage(ByRef dX As Double, ByRef dY As Double, ByVal dDwgX As Double, ByVal dDwgY As Double)
683 4f359afa Gyusu
684
        Dim calcx As Double = 0
685
        Dim calcy As Double = 0
686
        calcx = (dX * _DWG_X) / dDwgX 'Math.Round((dX * _DWG_X) / dDwgX, 2)
687 171ac39d Gyusu
        calcy = _DWG_Y - ((dY * _DWG_Y) / dDwgY) '_DWG_Y - Math.Round((dY * _DWG_Y) / dDwgY, 2)
688 4f359afa Gyusu
        dX = calcx
689
        dY = calcy
690
    End Sub
691
692 e1cde8f2 Gyusu
693
    '@brief Convert To SPPID
694
    '@author : Gyusu Park
695
    '@date : 2018-04-10
696
    '@history:
697
698 171ac39d Gyusu
    Private Sub SplitLocation(ByVal sLocation As String, ByRef dX As Double, ByRef dY As Double)
699
700
        Dim opointstr As String() = Split(sLocation, ",")
701
        If (opointstr.Length > 1) Then
702
            If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
703
                dX = opointstr(0)
704
                dY = opointstr(1)
705
            End If
706
        End If
707
708
    End Sub
709
710
711
712
713
714
715 e1cde8f2 Gyusu
    Private Function AutoConverting(ByVal oPipe_Dt As DataTable, ByVal oSymbol_Dt As DataTable, ByVal oTreeNode As TreeNode) As Boolean
716 e282643f Gyusu
        Dim iTotalCount As Double = oPipe_Dt.Rows.Count + oSymbol_Dt.Rows.Count
717
        Dim iSymbolcount As Double = 0
718
719 e1cde8f2 Gyusu
        Dim lobjDatasource As Object = _Placement.PIDDataSource
720 e282643f Gyusu
721 e1cde8f2 Gyusu
        ' lobjDatasource.BeginTransaction()
722 e282643f Gyusu
        '  datasource = objPlacement.PIDDataSource
723
        'Dim iPipecnt As Integer = 0
724 e1cde8f2 Gyusu
        SetListBoxItems(ListBox_Result, " Auto converting 시작....")
725 e282643f Gyusu
726 e1cde8f2 Gyusu
        Dim iPipeCnt As Integer = 0
727 e282643f Gyusu
        If oPipe_Dt IsNot Nothing Then
728
            For Each oRow As DataRow In oPipe_Dt.Rows
729
                Dim oposition As String = oRow("position").ToString()
730 20c84e05 Gyusu
                Dim oSymbol As String = oRow("SystemPath").ToString()
731 171ac39d Gyusu
732 e282643f Gyusu
                Dim objConnector As LMConnector
733
                Dim objInputs As PlaceRunInputs
734
                objInputs = New PlaceRunInputs
735 171ac39d Gyusu
                Dim oSplitStr As String() = Split(oposition, " ")
736 e282643f Gyusu
                For Each sposition As String In oSplitStr
737 20c84e05 Gyusu
                    Dim opointstr As String() = Split(sposition, ", ")
738 e282643f Gyusu
739
                    If (opointstr.Length > 1) Then
740
                        If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
741
                            Dim ox As Double = opointstr(0)
742
                            Dim oy As Double = opointstr(1)
743 9e1e7135 Gyusu
                            ConvertPointByImage(ox, oy, _IMG_X, _IMG_Y)
744 e282643f Gyusu
                            objInputs.AddPoint(ox, oy)
745
                        End If
746 4f359afa Gyusu
                    End If
747 e282643f Gyusu
                Next
748
                Dim objItem As LMAItem
749 e1cde8f2 Gyusu
                objItem = _Placement.PIDCreateItem(oSymbol)
750
                objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
751
                SetListBoxItems(ListBox_Result, " Place PipeLine...." & "(" & (iPipeCnt + 1) & "/" & oPipe_Dt.Rows.Count)
752 e282643f Gyusu
                'Dim objPipeRun As LMPipeRun = datasource.GetPipeRun(objConnector.ModelItemID)
753
                'objPipeRun.Attributes("OperFluidCode").Value = "AFS"
754
                'objPipeRun.Commit()
755
                iSymbolcount = iSymbolcount + 1
756 e1cde8f2 Gyusu
                iPipeCnt = iPipeCnt + 1
757 e282643f Gyusu
            Next
758
        End If
759 4f359afa Gyusu
760 e1cde8f2 Gyusu
        SetListBoxItems(ListBox_Result, " Place PipeLine....완료")
761
762
        Dim iAllInstrumentCnt As Integer = oSymbol_Dt.Select("Name = 'INSTRUMENTATION'").Length
763 20c84e05 Gyusu
                    Dim iValveCnt As Integer = oSymbol_Dt.Select("Class = 'VALVES'").Length
764 e1cde8f2 Gyusu
        Dim iInstrumentCnt As Integer = 1
765
        Dim iFittingsCnt As Integer = 1
766
767
        Dim oInsNode As TreeNode = oTreeNode.Nodes.Find(oTreeNode.Name & "\Instruments", True)(0)
768
        Dim oValveNode As TreeNode = oTreeNode.Nodes.Find(oTreeNode.Name & "\Valves", True)(0)
769
        Dim oFittingsNode As TreeNode = oTreeNode.Nodes.Find(oTreeNode.Name & "\Fittings", True)(0)
770 e282643f Gyusu
        For Each oRow As DataRow In oSymbol_Dt.Rows
771 4f359afa Gyusu
772 e282643f Gyusu
            Try
773 e1cde8f2 Gyusu
774 20c84e05 Gyusu
                Dim sSystemPath As String = oRow("SystemPath").ToString()
775
                Dim sName As String = oRow("Name").ToString()
776
                Dim sType As String = oRow("Type").ToString()
777
                Dim sText As String = oRow("Text").ToString()
778
                Dim sClass As String = oRow("Class").ToString()
779
                Dim sItem As String = oRow("Item").ToString()
780 e1cde8f2 Gyusu
781 e282643f Gyusu
                Dim oX As Double = 0.0
782
                Dim oY As Double = 0.0
783 20c84e05 Gyusu
                If IsNumeric(oRow("x").ToString()) Then
784
                    oX = Double.Parse(oRow("x").ToString())
785 e282643f Gyusu
                End If
786 20c84e05 Gyusu
                If IsNumeric(oRow("y").ToString()) Then
787
                    oY = Double.Parse(oRow("y").ToString())
788 e282643f Gyusu
                End If
789
                Dim oAngle As Double = 0.0
790 20c84e05 Gyusu
                If IsNumeric(oRow("Angle").ToString()) Then
791
                    oAngle = Double.Parse(oRow("Angle").ToString())
792 e282643f Gyusu
                End If
793
                '   oSymbol = "\INSTRUMENTation\SYSTEM FUNCTIONS\D C S\DCS FUNC ACCESS IN PRIME LOC.sym"
794 e1cde8f2 Gyusu
                If sSystemPath <> "" Then
795
                    If sName = _TYPE_Instumentation Then
796
797 e282643f Gyusu
                        Dim sTagsuffix As String = ""
798
                        Dim sTagSequenceNo As String = ""
799
                        Dim sMeasuredVariableCode As String = ""
800
                        Dim sInstrumentTypeModifier As String = ""
801 e1cde8f2 Gyusu
802
                        If sText <> "" Then
803
                            If sText.Contains(",") Then
804
                                Dim splitstr() As String = sText.Split(",")
805 e282643f Gyusu
                                For i = 0 To splitstr.Count - 1
806
                                    If i = 0 Then
807
                                        sMeasuredVariableCode = Mid(splitstr(i), 1, 1)
808
                                        sTagSequenceNo = Mid(splitstr(i), 2, Len(splitstr(i)))
809
                                    Else
810
                                        If Len(splitstr(i)) = 1 Then
811
                                            sInstrumentTypeModifier = splitstr(i)
812
                                        ElseIf Len(splitstr(i)) = 0 Then
813
814
                                        ElseIf Len(splitstr(i)) > 1 Then
815
                                            sInstrumentTypeModifier = Mid(splitstr(i), 1, 1)
816
                                            sTagsuffix = Mid(splitstr(i), 2, Len(splitstr(i)))
817
                                        End If
818
                                    End If
819
                                Next
820
                            Else
821 e1cde8f2 Gyusu
                                sMeasuredVariableCode = Mid(sText, 1, 1)
822
                                sTagSequenceNo = Mid(sText, 2, Len(sText))
823 e282643f Gyusu
                            End If
824 4f359afa Gyusu
825 e282643f Gyusu
                        End If
826 4f359afa Gyusu
827 e282643f Gyusu
                        Dim objInstrSym As LMSymbol
828 e1cde8f2 Gyusu
                        objInstrSym = _Placement.PIDPlaceSymbol(sSystemPath, oX, oY, , oAngle)
829
                        SetListBoxItems(ListBox_Result, " Place Instrument...." & "(" & (iInstrumentCnt + 1) & "/" & iAllInstrumentCnt & ")")
830
831
                        ' SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sTagSequenceNo)
832
                        Dim action As Action = Sub()
833
                                                   oInsNode.Nodes.Add(sClass & "-" & iInstrumentCnt)
834
                                                   oInsNode.ExpandAll()
835
                                               End Sub
836
                        oInsNode.TreeView.Invoke(action)
837
838
839 e282643f Gyusu
                        Dim objInstr As LMInstrument
840
                        objInstr = lobjDatasource.GetInstrument(objInstrSym.ModelItemID)
841 4f359afa Gyusu
842 e282643f Gyusu
                        Dim objItem As LMAItem
843 e1cde8f2 Gyusu
                        objItem = _Placement.PIDCreateItem(sSystemPath)
844
845 4f359afa Gyusu
846 e282643f Gyusu
                        objInstr.Attributes("MeasuredVariableCode").Value = sMeasuredVariableCode
847
                        objInstr.Attributes("InstrumentTypeModifier").Value = sInstrumentTypeModifier
848
                        objInstr.Attributes("TagSuffix").Value = sTagsuffix
849
                        objInstr.Attributes("TagSequenceNo").Value = sTagSequenceNo
850
                        objInstr.Commit()
851 e1cde8f2 Gyusu
                        iInstrumentCnt = iInstrumentCnt + 1
852
                    ElseIf sName = "GATE VALVE WITH PLUG" Then
853 4f359afa Gyusu
854 e1cde8f2 Gyusu
                    ElseIf sName = "MEDIUM 1D 1TO1" Then
855 4f359afa Gyusu
856 e1cde8f2 Gyusu
                    ElseIf sClass = "VALVES" Then
857
                        Dim action As Action = Sub()
858
                                                   oValveNode.ExpandAll()
859
                                                   oValveNode.Nodes.Add(sClass & "-" & iValveCnt)
860
                                               End Sub
861
                        oValveNode.TreeView.Invoke(action)
862
863
                        _Placement.PIDPlaceSymbol(sSystemPath, oX, oY, , oAngle)
864
865
                        iValveCnt = iValveCnt + 1
866 e282643f Gyusu
                    Else
867 e1cde8f2 Gyusu
                        Dim action As Action = Sub()
868
                                                   oFittingsNode.ExpandAll()
869
                                                   oFittingsNode.Nodes.Add(sClass & "-" & iFittingsCnt)
870
                                               End Sub
871
                        oFittingsNode.TreeView.Invoke(action)
872
                        _Placement.PIDPlaceSymbol(sSystemPath, oX, oY, , oAngle)
873
874
                        iFittingsCnt = iFittingsCnt + 1
875 4f359afa Gyusu
876 e282643f Gyusu
                    End If
877
                    iSymbolcount = iSymbolcount + 1
878
                Else
879 4f359afa Gyusu
                End If
880 e282643f Gyusu
            Catch ex As Exception
881 4f359afa Gyusu
882 e282643f Gyusu
            End Try
883
            Dim dCalcProgressValue As Double = (iSymbolcount / iTotalCount) * 100
884
            SetProgressbar(ProgressBar_Status, dCalcProgressValue)
885
            '     ProgressBar_Status.Value = (iSymbolcount / iTotalCount) * 100
886 e1cde8f2 Gyusu
887 4f359afa Gyusu
        Next
888
889 e1cde8f2 Gyusu
        MsgBox("Complete AutoConverting")
890
        SetListBoxItems(ListBox_Result, "Place Instrument....변환완료")
891
        SetListBoxItems(ListBox_Result, "총 symbol:  " & iSymbolcount & "개 변환완료")
892
        SetProgressbar(ProgressBar_Status, 100)
893 41e4023e Gyusu
894 e282643f Gyusu
        ' MsgBox("symbol: " & iSymbolcount & "개, pipe : " & iPipecnt & "개 변환완료")
895 4f359afa Gyusu
    End Function
896
897
898 272662f9 Gyusu
    Private Sub Tree_XMLFiles_AfterCheck(sender As Object, e As TreeViewEventArgs)
899 4f359afa Gyusu
        If e.Node.Checked = True Then
900
            For Each oNode As TreeNode In e.Node.Nodes
901
                oNode.Checked = True
902
            Next
903
        Else
904
            For Each oNode As TreeNode In e.Node.Nodes
905
                oNode.Checked = False
906
            Next
907
        End If
908
    End Sub
909
910 171ac39d Gyusu
    Private Function Load_DB(ByVal sDBPath As String, ByVal sTableName As String) As DataTable
911 4f359afa Gyusu
912
        Try
913 171ac39d Gyusu
            Dim oDt As New DataTable
914 4f359afa Gyusu
            Dim sConnectionstring As String = "Data Source=" & sDBPath & ";Version=3;Synchronous=Off;UTF8Encoding=True;"
915
            Dim conn As SQLiteConnection = New SQLiteConnection(sConnectionstring)
916
            conn.Open()
917 171ac39d Gyusu
            Dim sQuery As String = "Select * from " & sTableName
918 4f359afa Gyusu
            Dim cmd As SQLiteCommand = conn.CreateCommand()
919
            Dim adapter As SQLiteDataAdapter = New SQLiteDataAdapter(sQuery, conn)
920
            Dim oDataSet As DataSet = New DataSet()
921
            adapter.Fill(oDataSet)
922 171ac39d Gyusu
            oDt = oDataSet.Tables(0)
923
            Return oDt
924 4f359afa Gyusu
        Catch ex As Exception
925 171ac39d Gyusu
            Return Nothing
926 4f359afa Gyusu
        End Try
927
928
929 171ac39d Gyusu
    End Function
930 4f359afa Gyusu
931 171ac39d Gyusu
    Private Sub Load_AttributeDB(ByVal sDBPath As String)
932
933
        Try
934
            Dim sConnectionstring As String = "Data Source=" & sDBPath & ";Version=3;Synchronous=Off;UTF8Encoding=True;"
935
            Dim conn As SQLiteConnection = New SQLiteConnection(sConnectionstring)
936
            conn.Open()
937
            Dim sQuery As String = "Select * from Attribute"
938
            Dim cmd As SQLiteCommand = conn.CreateCommand()
939
            Dim adapter As SQLiteDataAdapter = New SQLiteDataAdapter(sQuery, conn)
940
            Dim oDataSet As DataSet = New DataSet()
941
            adapter.Fill(oDataSet)
942
            _Attribute_DB = oDataSet.Tables(0)
943
        Catch ex As Exception
944
945
        End Try
946 962b2464 Gyusu
947
948 171ac39d Gyusu
    End Sub
949
950 272662f9 Gyusu
    'Private Sub Tree_XMLFiles_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles Tree_XMLFiles.AfterSelect
951
    '    If first_start = False Then Exit Sub
952
    '    Dim pa = e.Node.FullPath.ToString
953 962b2464 Gyusu
954 272662f9 Gyusu
    '    printfilesfolders_here(pa, e.Node)
955 962b2464 Gyusu
956 272662f9 Gyusu
    '    displayfiles(pa)
957
958
    '    Dim coco As String = ""
959
    '    coco = pa.ToString
960
    '    coco = coco.Replace("\\", "\")
961
    '    Me.Text = coco
962
    '    folders_path = coco
963
    'End Sub
964 962b2464 Gyusu
965
    Sub printfilesfolders_here(ByVal path As String, ByRef itree As TreeNode)
966
967
        Dim foldername As String
968
        Dim filename As String
969
        itree.Nodes.Clear()
970
        On Error GoTo eee
971
        For Each foldername In Directory.GetDirectories(path)
972
            On Error GoTo eee
973
            Dim jj = foldername.LastIndexOf("\")
974
            Dim jj1 = foldername.Length - jj
975
            Dim foldr = foldername.Substring((jj + 1), (jj1 - 1))
976
            itree.Nodes.Add(foldr, foldr)
977
        Next ' if you put this next at the end of procedure recursive will be done on first folder only
978
        Exit Sub
979
eee:
980
    End Sub
981
982 e282643f Gyusu
983 962b2464 Gyusu
984 272662f9 Gyusu
    '    Private Sub Tree_XMLFiles_MouseMove(sender As Object, e As MouseEventArgs) Handles Tree_XMLFiles.MouseMove
985
    '        first_start = True
986
    '    End Sub
987
988
    '    Private Sub ListView_File_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView_File.SelectedIndexChanged
989
    '        Dim indexes As ListView.SelectedIndexCollection =
990
    '                         Me.ListView_File.SelectedIndices
991
    '        Dim index As Integer
992
993
    '        For Each index In indexes
994
    '            'On Error Resume Next
995
    '            If folders_path.EndsWith("\") = True Then
996
    '                Me.Status_Main.Items(0).Text = folders_path + (Me.ListView_File.Items(index).Text)
997
    '                'On Error Resume Next
998
    '            Else
999
    '                Me.Status_Main.Items(0).Text = folders_path + "\" + (Me.ListView_File.Items(index).Text)
1000
    '            End If
1001
1002
    '            Dim infoReader As System.IO.FileInfo
1003
    '            infoReader = My.Computer.FileSystem.GetFileInfo(Me.Status_Main.Items(0).Text)
1004
    '            Me.Status_Main.Items(1).Text = " Created : " + infoReader.CreationTime.ToString + " " + infoReader.Attributes.ToString
1005
    '        Next
1006
    '    End Sub
1007
1008
    '    Private Sub Procees()
1009
    '        Dim indexes As ListView.SelectedIndexCollection =
1010
    '                            Me.ListView_File.SelectedIndices
1011
    '        Dim index As Integer
1012
1013
    '        For Each index In indexes
1014
    '            'On Error Resume Next
1015
    '            If folders_path.EndsWith("\") = True Then
1016
    '                On Error GoTo out
1017
    '                Me.Status_Main.Items(0).Text = folders_path + (Me.ListView_File.Items(index).Text)
1018
    '                On Error GoTo out
1019
    '                'On Error Resume Next
1020
    '            Else
1021
    '                Me.Status_Main.Items(0).Text = folders_path + "\" + (Me.ListView_File.Items(index).Text)
1022
    '                On Error GoTo out
1023
    '            End If
1024
1025
    '            Dim infoReader As System.IO.FileInfo
1026
    '            infoReader = My.Computer.FileSystem.GetFileInfo(Me.Status_Main.Items(0).Text)
1027
    '            Me.Status_Main.Items(1).Text = " Created : " + infoReader.CreationTime.ToString + " " + infoReader.Attributes.ToString
1028
    '            On Error GoTo out
1029
    '            MsgBox(Me.Status_Main.Items(0).Text + " is processed")
1030
    '            On Error GoTo out
1031
    '        Next
1032
    '        Exit Sub
1033
    'out:
1034
    '        MsgBox(Err.Description)
1035
    'End Sub
1036 962b2464 Gyusu
1037 31d47a80 Gyusu
    Private Function LoadAllDrawing() As DataTable
1038 e282643f Gyusu
1039
1040 e1cde8f2 Gyusu
        SetListBoxItems(ListBox_Result, "도면정보 로드중....")
1041 e282643f Gyusu
1042 31d47a80 Gyusu
        Dim oDt As DataTable = Drawing_Dt()
1043 e282643f Gyusu
        Dim sHierarchy As String = My.Settings.Plant_Hierarchy
1044
1045
1046
        Dim files() As String
1047
        files = Directory.GetFiles(sHierarchy, "*.pid", SearchOption.AllDirectories)
1048
        For Each FileName As String In files
1049
            Dim sName As String = FileName
1050 31d47a80 Gyusu
            Dim oAddRow As DataRow = oDt.NewRow()
1051 e282643f Gyusu
            oAddRow("Name") = Path.GetFileNameWithoutExtension(sName)
1052
            oAddRow("Path") = FileName
1053 31d47a80 Gyusu
            oDt.Rows.Add(oAddRow)
1054
        Next
1055
        Return oDt
1056
    End Function
1057
1058 e282643f Gyusu
    Private Function LoadAllDrawing2() As DataTable
1059 31d47a80 Gyusu
        Dim datasource As LMADataSource
1060
        Dim objPIDAutoApp As Object
1061
        Dim objPIDADrawing As Object
1062
        Dim objDrawing As Object 'Drawing
1063
        'Dim objDrawing As LMDrawing
1064
        'Dim objDrawings As LMDrawings
1065
1066
        datasource = New LMADataSource
1067
1068
        '    objDrawings = New LMDrawings
1069
        'objDrawings.Collect(datasource)
1070
        objPIDAutoApp = CreateObject("PIDAutomation.Application")
1071
1072
        For Each objDrawing In objPIDAutoApp.Drawings
1073
            objDrawing.CloseDrawing(True)
1074
        Next
1075
        Try
1076
            objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("UY1-K-2000_P1_300dpi_0321_TEST_1")
1077
        Catch ex As Exception
1078
            Process.Start("\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\Plant_Hierarchy\8121\8121-1\UY1-K-2000_P1_300dpi_0321_TEST_1.pid")
1079
        End Try
1080
1081
1082
1083
        Dim sType As Type = objPIDAutoApp.GetType()
1084
        Dim iCount As Integer = 0
1085
        ' Dim sPath As String = "‪\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\Plant_Hierarchy\8121\8121-1\188943-8121-PR-DW-011001.pid"
1086
1087
        objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("1")
1088
1089
        For Each objDrawing In objPIDAutoApp.Drawings
1090
            If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
1091
                Try
1092
1093
                    Dim sName As String = objDrawing.Attributes("Name").Value
1094
1095
                    iCount = iCount + 1
1096
                    If sName = "UY1-K-2000_P1_300dpi_0321_TEST_1" Then
1097
                        objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(objDrawing.Attributes("Name"))
1098
                        objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("\8121\8121-1\UY1-K-2000_P1_300dpi_0321_TEST_1.pid")
1099
                        If Not objPIDADrawing Is Nothing Then
1100
                            objPIDADrawing.CloseDrawing()
1101
                        End If
1102
                    End If
1103
1104
1105
                Catch ex As Exception
1106
1107
                End Try
1108
1109
            End If
1110
        Next
1111
        objPIDAutoApp.Quit
1112
        objPIDAutoApp = Nothing
1113
        objPIDADrawing = Nothing
1114
        objDrawing = Nothing
1115
        '   objDrawings = Nothing
1116 e282643f Gyusu
    End Function
1117
1118 272662f9 Gyusu
    Dim _XMLList As ListView = New ListView()
1119 e282643f Gyusu
1120 272662f9 Gyusu
1121
1122 e1cde8f2 Gyusu
1123 171ac39d Gyusu
1124
1125
    Private Function CheckOpenDrawing() As Boolean
1126
        Try
1127
1128
            Dim lobjDatasource As Object
1129
            _Placement = CreateObject("Plaice.Placement", "")
1130
            lobjDatasource = _Placement.PIDDataSource
1131
            Return True
1132
        Catch ex As Exception
1133
            Return False
1134
        End Try
1135
1136
    End Function
1137
1138
1139
    Private Sub Btn_Convert_Click(sender As Object, e As EventArgs) Handles Btn_Convert.Click
1140
1141
        Main_Tab.SelectedIndex = 1
1142
        ListBox_Result.Items.Clear()
1143 9e1e7135 Gyusu
        ' DataGrid_Result.DataSource = New DataTable()
1144 171ac39d Gyusu
        Me.ProgressBar_Status.Visible = True
1145
        ProgressBar_Status.Maximum = 100
1146
        ProgressBar_Status.Value = 0
1147
        ' _selectFolderPath = Tree_XMLFiles.SelectedNode.FullPath.Replace("\\", "\")
1148 54b98e09 Gyusu
        _Main_trd = New Thread(AddressOf ThreadConvert)
1149 171ac39d Gyusu
        _Main_trd.IsBackground = True
1150
        _Main_trd.Start()
1151 54b98e09 Gyusu
        FineOPCForm()
1152
    End Sub
1153 171ac39d Gyusu
1154 54b98e09 Gyusu
    Private Sub FineOPCForm()
1155
        _Opc_trd = New Thread(AddressOf ThreadOPCRemove)
1156
        _Opc_trd.IsBackground = True
1157
        _Opc_trd.Start()
1158 171ac39d Gyusu
    End Sub
1159 54b98e09 Gyusu
1160 7824381a Gyusu
    'Private Sub ThreadTask()
1161 e1cde8f2 Gyusu
1162 e282643f Gyusu
1163 7824381a Gyusu
    '    If _XMLList.Items.Count > 0 Then
1164 31d47a80 Gyusu
1165 7824381a Gyusu
    '        Dim oDwg_Dt As DataTable = LoadAllDrawing()
1166
    '        Dim iDwgCnt As Integer = 0
1167
    '        Dim objPIDAutoApp As Object
1168
    '        objPIDAutoApp = CreateObject("PIDAutomation.Application")
1169 e282643f Gyusu
1170 e1cde8f2 Gyusu
1171 7824381a Gyusu
    '        Dim myList = DirectCast(Invoke(New GetListViewDelegate(AddressOf GetListViewItems), _XMLList), List(Of String))
1172
    '        For i = 0 To myList.Count - 1
1173 e1cde8f2 Gyusu
1174 7824381a Gyusu
    '            Dim sDwgName As String = Path.GetFileNameWithoutExtension(myList(i))
1175
    '            Txt_Status.Text = sDwgName & "..(" & i + 1 & "/" & myList.Count & ")"
1176
    '            SetListBoxItems(ListBox_Result, Txt_Status.Text & " 처리중....")
1177
    '            Dim sDwgNo As String = myList(i)
1178
    '            Dim oDwgPath As String = ""
1179
    '            oDwgPath = _selectFolderPath + "\" + sDwgNo
1180 e1cde8f2 Gyusu
1181 7824381a Gyusu
    '            Dim sPath As String = OpenDrawing(oDwg_Dt, sDwgName)
1182
    '            If sPath <> "" Then
1183 e1cde8f2 Gyusu
1184 7824381a Gyusu
    '                Process.Start(sPath)
1185 e1cde8f2 Gyusu
1186 7824381a Gyusu
    '                Dim bCheckOpenDrawing As Boolean = False
1187
    '                While (True)
1188
    '                    bCheckOpenDrawing = CheckOpenDrawing()
1189
    '                    If bCheckOpenDrawing = True Then
1190
    '                        Exit While
1191
    '                    Else
1192
    '                        Thread.Sleep(2000)
1193
    '                    End If
1194
    '                End While
1195 e1cde8f2 Gyusu
1196 7824381a Gyusu
    '                If bCheckOpenDrawing Then
1197
    '                    SetListBoxItems(ListBox_Result, sDwgName & " 도면 Open....")
1198
    '                    Dim oPipe_Dt As DataTable = New DataTable() 'LoadPipeInXml(oDwgPath)
1199 e282643f Gyusu
1200 7824381a Gyusu
    '                    Dim oSymbol_Dt As DataTable = LoadSymbolInXml(oDwgPath)
1201
    '                    Dim oTreeNode As New TreeNode  'SetTreeViewItems(Tree_Result, Tree_Result.Nodes, sDwgName, sDwgName)
1202
    '                    'oTreeNode = Tree_Result.Nodes.Find(sDwgName, True)(0)
1203
    '                    Dim action As Action = Sub()
1204
    '                                               oTreeNode = Tree_Result.Nodes.Add(sDwgName, sDwgName)
1205
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Instruments", "Instuments")
1206
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Pipes", "Pipes")
1207
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Valves", "Valves")
1208
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Fittings", "Fittings")
1209
    '                                               oTreeNode.ExpandAll()
1210
    '                                           End Sub
1211
    '                    Tree_Result.Invoke(action)
1212 e1cde8f2 Gyusu
1213 e282643f Gyusu
1214 7824381a Gyusu
    '                    '    oTreeNode.Expand()
1215
    '                    SetListBoxItems(ListBox_Result, sDwgName & " Auto converting 대기....")
1216
    '                    AutoConverting(oPipe_Dt, oSymbol_Dt, oTreeNode)
1217 4f359afa Gyusu
1218 7824381a Gyusu
    '                End If
1219
1220
    '            End If
1221
    '            ''도면 생성
1222
    '            'If CreateDwg(sDwgName) Then
1223
    '            '    'AutoConverting
1224
1225
    '            'End If
1226
1227
    '        Next
1228
    '    End If
1229
    'End Sub
1230 e282643f Gyusu
1231 171ac39d Gyusu
    Dim _objPIDAutoApp As Object
1232 e282643f Gyusu
1233 171ac39d Gyusu
    Private Function OpenSPPID(ByVal oDwg_Dt As DataTable, ByVal sDwgName As String) As Boolean
1234
        Dim bCheckOpen As Boolean = False
1235
        '   Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgPath)
1236
        SetListBoxItems(ListBox_Result, sDwgName & " 도면 Open....")
1237
        _objPIDAutoApp = CreateObject("PIDAutomation.Application")
1238 e1cde8f2 Gyusu
1239 171ac39d Gyusu
        Dim sPath As String = OpenDrawing(oDwg_Dt, sDwgName)
1240
        If sPath <> "" Then
1241
            Process.Start(sPath)
1242
        Else
1243
            Return bCheckOpen
1244
        End If
1245
1246
            Dim bCheckOpenDrawing As Boolean = False
1247
            While (True)
1248
                bCheckOpenDrawing = CheckOpenDrawing()
1249
                If bCheckOpenDrawing = True Then
1250
                    bCheckOpen = True
1251
                    Exit While
1252
                Else
1253
                    Thread.Sleep(2000)
1254
                End If
1255
            End While
1256
1257
1258
            Return bCheckOpen
1259
    End Function
1260
1261
    Private Function GetDrawing(ByVal sDwgName As String) As Drawing
1262
        For Each CDrawing In _DrawingsList
1263 559daf6d Gyusu
            If CDrawing.DwgName.ToUpper() = sDwgName.ToUpper() Then
1264 171ac39d Gyusu
                Return CDrawing
1265
            End If
1266
        Next
1267
        Return Nothing
1268
    End Function
1269
1270
    Private Function GetLineNo(ByVal CDrawing As Drawing, ByVal sLineNoUid As String) As Line_no
1271
        For Each CLineNo In CDrawing.Line_nos
1272
            If CLineNo.Uid = sLineNoUid Then
1273
                Return CLineNo
1274
            End If
1275
        Next
1276
        Return Nothing
1277
    End Function
1278
1279 3acffcee Gyusu
    Private Function GetTrimLineNo(ByVal CDrawing As Drawing, ByVal sLineNoUid As String) As Line_no
1280
        For Each CLineNo In CDrawing.TrimLine_nos
1281
            If CLineNo.Uid = sLineNoUid Then
1282
                Return CLineNo
1283
            End If
1284
        Next
1285
        Return Nothing
1286
    End Function
1287
1288
1289 6a6d8ab4 Gyusu
    Private Function GetOnlyPipeLineNo(ByVal CDrawing As Drawing, ByVal sPipeUid As String) As Line_no
1290
        For Each CLineNo In CDrawing.Line_nos
1291
            Dim odt As DataTable = CLineNo.Dt_Line
1292
            If odt.Rows.Count > 0 Then
1293
                If odt.Rows(0)(_XML_LINE_UID).ToString = sPipeUid Then
1294
                    Return CLineNo
1295
                End If
1296
            End If
1297
        Next
1298
        Return Nothing
1299
    End Function
1300
1301
1302
    Private Function GetEqpNo(ByVal CDrawing As Drawing, ByVal sEqpUid As String) As Eqp_no
1303
        For Each CEqpNo In CDrawing.Eqp_nos
1304
            If CEqpNo.Uid = sEqpUid Then
1305
                Return CEqpNo
1306
            End If
1307
        Next
1308
        Return Nothing
1309
    End Function
1310 9e1e7135 Gyusu
    Private Function ConvertPointBystring(ByVal sPoint As String, ByRef dX As Double, ByRef dY As Double) As Boolean
1311 171ac39d Gyusu
        Try
1312
            Dim opointstr As String() = Split(sPoint, ",")
1313
            If (opointstr.Length > 1) Then
1314
                If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
1315
                    dX = opointstr(0)
1316
                    dY = opointstr(1)
1317 9e1e7135 Gyusu
1318 171ac39d Gyusu
                Else
1319
                    dX = 0
1320
                    dY = 0
1321
                    Return False
1322
                End If
1323
            End If
1324 e1cde8f2 Gyusu
            Return True
1325
        Catch ex As Exception
1326
            Return False
1327
        End Try
1328 171ac39d Gyusu
    End Function
1329
1330 54b98e09 Gyusu
1331
    Dim _DrawLine_Dt As DataTable = DrawLind_Dt()
1332
1333 3acffcee Gyusu
    Private Function DrawLine(ByVal sUid As String, ByVal sLineNoUid As String, ByVal oLine_Dt As DataTable,
1334
                              ByVal oAttribute_Dt As DataTable, ByRef oPiperun_Dt As DataTable) As LMPipeRun
1335 171ac39d Gyusu
        Try
1336 3acffcee Gyusu
            Dim oPipeRun As LMPipeRun = Nothing
1337 171ac39d Gyusu
            Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_UID & " = '" + sUid + "'")
1338
            Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
1339
1340
            If oPipeRow.Length > 0 Then
1341
                Dim oDatasource As Object = _Placement.PIDDataSource
1342
                Dim objItem As LMAItem
1343
                Dim objConnector As LMConnector
1344
                Dim objInputs As PlaceRunInputs
1345
                objInputs = New PlaceRunInputs
1346 9e1e7135 Gyusu
                Dim dOriginalStart_x As Double = 0.0
1347
                Dim dOriginalStart_y As Double = 0.0
1348
                Dim dOriginalEnd_x As Double = 0.0
1349
                Dim dOriginalEnd_y As Double = 0.0
1350 171ac39d Gyusu
                Dim dStart_x As Double = 0.0
1351
                Dim dStart_y As Double = 0.0
1352
                Dim dEnd_x As Double = 0.0
1353
                Dim dEnd_y As Double = 0.0
1354 c2c36314 Gyusu
1355
                Dim sType As String = oPipeRow(0)(_XML_LINE_TYPE).ToString()
1356
1357 54b98e09 Gyusu
                Dim sSystempath As String = "\Piping\Routing\Process Lines\Primary Piping.sym" ' oPipeRow(0)(_XML_LINE_SYSTEMPATH).ToString()
1358 c2c36314 Gyusu
                If sType.ToUpper() = "ELECTRIC" Then
1359
                    sSystempath = "\Instrumentation\Signal Line\Electric.sym"
1360
                ElseIf sType.ToUpper() = "CONNECT TO PROCESS" Then
1361
                    sSystempath = "\Instrumentation\Signal Line\Connect to Process.sym"
1362
                Else
1363
                End If
1364 171ac39d Gyusu
                Dim sStartpoint As String = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
1365
                Dim sEndpoint As String = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
1366 460d6abd Gyusu
                Dim sPipeUid As String = oPipeRow(0)(_XML_LINE_UID).ToString()
1367
1368 3acffcee Gyusu
                Dim oAddPiperunRow As DataRow = oPiperun_Dt.NewRow()
1369 9e1e7135 Gyusu
                ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
1370
                dStart_x = dOriginalStart_x
1371
                dStart_y = dOriginalStart_y
1372 460d6abd Gyusu
1373 9e1e7135 Gyusu
                If ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y) Then
1374
                    dEnd_x = dOriginalEnd_x
1375
                    dEnd_y = dOriginalEnd_y
1376 54b98e09 Gyusu
1377
                    '   라인보정(oLine_Dt, sPipeUid, dStart_x, dStart_y, dEnd_x, dEnd_y)
1378 460d6abd Gyusu
                    '//Overlap 보정
1379 54b98e09 Gyusu
                    'If FindOverlapLine(oLine_Dt, sPipeUid, dStart_x, dStart_y, dEnd_x, dEnd_y) = False Then
1380
                    '    '//떨어진 라인 보정
1381
                    '    Dim dSeperate_start_x As Double = dStart_x
1382
                    '    Dim dSeperate_start_y As Double = dStart_y
1383
                    '    Dim dSeperate_end_x As Double = dEnd_x
1384
                    '    Dim dSeperate_end_y As Double = dEnd_y
1385
                    '    CalcSperateLine(dSeperate_start_x, dSeperate_start_y, dSeperate_end_x, dSeperate_end_y)
1386
                    '    If (FindOverlapLine(oLine_Dt, sPipeUid, dSeperate_start_x, dSeperate_start_y, dSeperate_end_x, dSeperate_end_y)) Then
1387
                    '        dStart_x = dSeperate_start_x
1388
                    '        dStart_y = dSeperate_start_y
1389
                    '        dEnd_x = dSeperate_end_x
1390
                    '        dEnd_y = dSeperate_end_y
1391
                    '    End If
1392
                    'End If
1393 460d6abd Gyusu
1394
                    ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
1395 9e1e7135 Gyusu
                    ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
1396 171ac39d Gyusu
                    If dStart_x <> 0 And dStart_y <> 0 And dEnd_x <> 0 And dEnd_y <> 0 Then
1397 460d6abd Gyusu
1398 41e4023e Gyusu
                        Dim iConnType As Integer = ModelingLine(dStart_x, dStart_y, dEnd_x, dEnd_y, sUid)
1399
                        If iConnType = 1 Then
1400
                            objInputs.AddLocatedTarget(dStart_x, dStart_y)
1401
                            objInputs.AddPoint(dEnd_x, dEnd_y)
1402
                        ElseIf iConnType = 2 Then
1403
                            objInputs.AddLocatedTarget(dEnd_x, dEnd_y)
1404
                            objInputs.AddPoint(dStart_x, dStart_y)
1405
                        ElseIf iConnType = 3 Then
1406
                            objInputs.AddLocatedTarget(dEnd_x, dEnd_y)
1407
                            objInputs.AddPoint(dStart_x, dStart_y)
1408
                        ElseIf iConnType = 4 Then
1409
                            objInputs.AddLocatedTarget(dStart_x, dStart_y)
1410
                            objInputs.AddPoint(dEnd_x, dEnd_y)
1411
                        Else
1412
                            objInputs.AddPoint(dStart_x, dStart_y)
1413
                            objInputs.AddPoint(dEnd_x, dEnd_y)
1414
                        End If
1415 171ac39d Gyusu
                        objInputs.AddPoint(dStart_x, dStart_y)
1416
                        objInputs.AddPoint(dEnd_x, dEnd_y)
1417 41e4023e Gyusu
                        AddModelingLine(dStart_x, dStart_y, dEnd_x, dEnd_y, sUid)
1418 171ac39d Gyusu
                        objItem = _Placement.PIDCreateItem(sSystempath)
1419 9e1e7135 Gyusu
                        _iPipecnt = _iPipecnt + 1
1420 6a6d8ab4 Gyusu
                        SetListBoxItems(ListBox_Result, "Place PipeLine..(" & dOriginalStart_x & "," & dOriginalStart_y & ") - (" & dOriginalEnd_x & "," & dOriginalEnd_y & ").." & _iPipecnt & " count ")
1421 171ac39d Gyusu
                        objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
1422
                        oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
1423 559daf6d Gyusu
                        oPipeRun.Attributes("FlowDirection").Value = "End 1 is upstream (Inlet)"
1424 171ac39d Gyusu
                        If oAttributeRow.Length > 0 Then
1425
                            For Each oAttribute In oAttributeRow
1426 54b98e09 Gyusu
                                Try
1427
                                    Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
1428
                                    Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
1429
                                    Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
1430
                                    oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
1431
                                Catch ex As Exception
1432
1433
                                End Try
1434
1435 559daf6d Gyusu
1436 171ac39d Gyusu
                            Next
1437
                            oPipeRun.Commit()
1438
                        End If
1439 6a6d8ab4 Gyusu
                        'Flow Direction 
1440 3acffcee Gyusu
                        Dim sFlowDirectionPath As String = "\Piping\Labels - Piping Segments\Flow Direction.sym" 'GetDataFromMappingDB(_XML_CATEGORY_FLOWDIRECITON, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
1441
                        Dim dFlowDirectionAngle As Double = 0.0
1442
                        If dStart_y <> dEnd_y Then
1443
                            If dStart_y > dEnd_y Then
1444
                                dFlowDirectionAngle = -1.57
1445
                            Else
1446
                                dFlowDirectionAngle = 1.57
1447
                            End If
1448
                        End If
1449
                        If dStart_x <> dEnd_x Then
1450
                            If dStart_x > dEnd_x Then
1451
                                dFlowDirectionAngle = 3.14
1452
                            Else
1453
                                dFlowDirectionAngle = 0
1454
                            End If
1455
                        End If
1456
1457
                        _Placement.PIDPlaceSymbol(sFlowDirectionPath, dEnd_x, dEnd_y, , dFlowDirectionAngle)
1458 171ac39d Gyusu
                    End If
1459
                End If
1460 41e4023e Gyusu
                _Itemcnt = _Itemcnt + 1
1461
                Dim dCalcProgressValue As Double = (_Itemcnt / _allItem) * 100
1462
                SetProgressbar(ProgressBar_Status, dCalcProgressValue)
1463
                Label_Progress.Text = Math.Round(dCalcProgressValue, 0) & "%"
1464 3acffcee Gyusu
1465
                oAddPiperunRow("Piperun") = oPipeRun
1466
                oAddPiperunRow("startx") = dOriginalStart_x
1467
                oAddPiperunRow("starty") = dOriginalStart_y
1468
                oAddPiperunRow("endx") = dOriginalEnd_x
1469
                oAddPiperunRow("endy") = dOriginalEnd_y
1470
                oPiperun_Dt.Rows.Add(oAddPiperunRow)
1471
1472 171ac39d Gyusu
            End If
1473
            Return oPipeRun
1474
        Catch ex As Exception
1475
            Return Nothing
1476
        End Try
1477 e1cde8f2 Gyusu
    End Function
1478
1479 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)
1480 54b98e09 Gyusu
        Dim oAddRow = _DrawLine_Dt.NewRow()
1481 41e4023e Gyusu
        oAddRow(_XML_LINE_UID) = sUid
1482 54b98e09 Gyusu
        oAddRow(_XML_LINE_STARTPOINT_X) = dStart_x
1483
        oAddRow(_XML_LINE_STARTPOINT_Y) = dStart_y
1484
        oAddRow(_XML_LINE_ENDPOINT_X) = dEnd_x
1485
        oAddRow(_XML_LINE_ENDPOINT_Y) = dEnd_y
1486
        _DrawLine_Dt.Rows.Add(oAddRow)
1487
    End Sub
1488
1489
1490 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
1491
        'Dim oFindRows_1 As DataRow() = _DrawLine_Dt.Select("start_x = '" & dStart_x & "' and start_y = '" & dStart_y & "' and uid <> '" & sUid & "'")
1492 54b98e09 Gyusu
1493 41e4023e Gyusu
        'Dim oFindRows_2 As DataRow() = _DrawLine_Dt.Select("end_x = '" & dEnd_x & "' and end_y = '" & dEnd_y & "' and uid <> '" & sUid & "'")
1494 54b98e09 Gyusu
1495 41e4023e Gyusu
        'Dim oFindRows_3 As DataRow() = _DrawLine_Dt.Select("start_x = '" & dEnd_x & "' and start_y = '" & dEnd_y & "' and uid <> '" & sUid & "'")
1496 54b98e09 Gyusu
1497 41e4023e Gyusu
        'Dim oFindRows_4 As DataRow() = _DrawLine_Dt.Select("end_x = '" & dStart_x & "' and end_y = '" & dStart_y & "' and uid <> '" & sUid & "'")
1498 54b98e09 Gyusu
1499 41e4023e Gyusu
        'If oFindRows_1.Length > 0 Then
1500
        '    Return 1
1501
        'ElseIf oFindRows_2.Length > 0 Then
1502
        '    Return 2
1503
        'ElseIf oFindRows_3.Length > 0 Then
1504
        '    Return 3
1505
        'ElseIf oFindRows_4.Length > 0 Then
1506
        '    Return 4
1507
        'Else
1508
        '    Return 0
1509
        'End If
1510
        Return 0
1511 54b98e09 Gyusu
    End Function
1512
1513
    Private Function FindConnectionPoint(ByVal dX As Double, ByVal dY As Double)
1514
1515
1516
    End Function
1517
1518 41e4023e Gyusu
    Private Sub PlaceEquipment(ByVal sUid As String, ByVal oSymbol_Dt As DataTable, ByVal oAttribute_Dt As DataTable)
1519
        Try
1520
            Dim oSymbolRow() As DataRow = oSymbol_Dt.Select(_XML_SYMBOL_UID & " = '" + sUid + "'")
1521
            Dim oAttributeRow() As DataRow
1522
            If oAttribute_Dt.Rows.Count > 0 Then
1523
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
1524
            End If
1525
            If oSymbolRow.Length > 0 Then
1526
                Dim oDatasource As Object = _Placement.PIDDataSource
1527
                Dim sSymbolCompType As String = oSymbolRow(0)(_XML_SYMBOL_TYPE).ToString()
1528
                Dim sSystemPath As String = oSymbolRow(0)(_XML_SYMBOL_SYSTEMPATH).ToString()
1529
                Dim sClass As String = oSymbolRow(0)(_XML_SYMBOL_CLASS).ToString()
1530
                Dim sLocation As String = oSymbolRow(0)(_XML_SYMBOL_LOCATION).ToString()
1531
                Dim sOriginalPoint As String = oSymbolRow(0)(_XML_SYMBOL_ORIGINALPOINT).ToString()
1532
                Dim dAngle As Double = 0.0
1533
                If IsNumeric(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString()) Then
1534
                    dAngle = Double.Parse(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString())
1535
                End If
1536
                Dim dLocationX As Double = 0.0
1537
                Dim dLocationY As Double = 0.0
1538
                Dim dX As Double = 0.0
1539
                Dim dY As Double = 0.0
1540
1541
                If ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY) Then
1542
                    dX = dLocationX
1543
                    dY = dLocationY
1544
                    ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1545
                    _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1546
                    SetListBoxItems(ListBox_Result, "Place Equipment..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1547
                End If
1548
            End If
1549
        Catch ex As Exception
1550
1551
        End Try
1552
1553
1554
    End Sub
1555 54b98e09 Gyusu
1556
    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
1557 171ac39d Gyusu
        Try
1558 e282643f Gyusu
1559 171ac39d Gyusu
            Dim oSymbolRow() As DataRow = oSymbol_Dt.Select(_XML_SYMBOL_UID & " = '" + sUid + "'")
1560 6a6d8ab4 Gyusu
            Dim oAttributeRow() As DataRow
1561
            If oAttribute_Dt.Rows.Count > 0 Then
1562 460d6abd Gyusu
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
1563 6a6d8ab4 Gyusu
            End If
1564
1565 171ac39d Gyusu
            If oSymbolRow.Length > 0 Then
1566
                Dim oDatasource As Object = _Placement.PIDDataSource
1567
                Dim sSymbolCompType As String = oSymbolRow(0)(_XML_SYMBOL_TYPE).ToString()
1568
                Dim sSystemPath As String = oSymbolRow(0)(_XML_SYMBOL_SYSTEMPATH).ToString()
1569 54b98e09 Gyusu
                Dim sClass As String = oSymbolRow(0)(_XML_SYMBOL_CLASS).ToString()
1570 171ac39d Gyusu
                Dim sLocation As String = oSymbolRow(0)(_XML_SYMBOL_LOCATION).ToString()
1571 9e1e7135 Gyusu
                Dim sOriginalPoint As String = oSymbolRow(0)(_XML_SYMBOL_ORIGINALPOINT).ToString()
1572 171ac39d Gyusu
                Dim dAngle As Double = 0.0
1573
                If IsNumeric(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString()) Then
1574
                    dAngle = Double.Parse(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString())
1575
                End If
1576
1577
                Dim objSymbol As LMSymbol
1578 9e1e7135 Gyusu
                Dim dLocationX As Double = 0.0
1579
                Dim dLocationY As Double = 0.0
1580 171ac39d Gyusu
                Dim dX As Double = 0.0
1581
                Dim dY As Double = 0.0
1582
1583 9e1e7135 Gyusu
                If ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY) Then
1584
                    dX = dLocationX
1585
                    dY = dLocationY
1586 54b98e09 Gyusu
                    If sSymbolCompType = "" Or sSymbolCompType = "Piping OPC's" Then
1587
                        FindConnectionLine(oLine_Dt, dX, dY)
1588
                    End If
1589
1590 9e1e7135 Gyusu
                    ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1591 54b98e09 Gyusu
                        Dim oInstrument As LMInstrument
1592
                    If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
1593 9e1e7135 Gyusu
                        _iInstrumentcnt = _iInstrumentcnt + 1
1594 171ac39d Gyusu
                        objSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1595 6a6d8ab4 Gyusu
                        SetListBoxItems(ListBox_Result, "Place Instrument..(" & dLocationX & "," & dLocationY & ")..." & _iInstrumentcnt & " count ")
1596 171ac39d Gyusu
                        oInstrument = oDatasource.GetInstrument(objSymbol.ModelItemID)
1597 6a6d8ab4 Gyusu
                        Try
1598
                            If oAttributeRow.Length > 0 Then
1599
                                For Each oAttribute In oAttributeRow
1600 54b98e09 Gyusu
                                    Try
1601
                                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
1602
                                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
1603
                                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
1604
                                        oInstrument.Attributes(sSPPIDAttribute).Value = sPIDValue
1605
                                    Catch ex As Exception
1606
1607
                                    End Try
1608
1609 6a6d8ab4 Gyusu
                                Next
1610
                                oInstrument.Commit()
1611
                            End If
1612
                        Catch ex As Exception
1613
                        End Try
1614 54b98e09 Gyusu
                    ElseIf sSymbolCompType.ToUpper() = _DB_FITTINGS.ToUpper() Then
1615 9e1e7135 Gyusu
                        _iValvecnt = _iValvecnt + 1
1616 171ac39d Gyusu
                        _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1617 6a6d8ab4 Gyusu
                        SetListBoxItems(ListBox_Result, "Place Valve..(" & dLocationX & "," & dLocationY & ")..." & _iValvecnt & " count ")
1618 171ac39d Gyusu
1619 54b98e09 Gyusu
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_FITTINGS.ToUpper() Then
1620 9e1e7135 Gyusu
                        _iFittingcnt = _iFittingcnt + 1
1621 d039e347 Gyusu
                        If sSystemPath.Contains(",") Then
1622
1623
                            Dim sDuplicatePath As String() = sSystemPath.Split(",")
1624
                            Dim sMainSymbol As String = ""
1625
                            Dim sSubSymbol As String = ""
1626
                            For Each sPath In sDuplicatePath
1627
                                If sMainSymbol = "" Then
1628
                                    sMainSymbol = sPath.Replace(vbLf, "")
1629
                                Else
1630
                                    sSubSymbol = sPath.Replace(vbLf, "")
1631
                                End If
1632
                            Next
1633
                            Dim oSymbolObj As LMSymbol = _Placement.PIDPlaceSymbol(sMainSymbol, dX, dY, , dAngle)
1634
                            Dim dConnpos_x As Double = 0.0
1635
                            Dim dConnpos_y As Double = 0.0
1636
                            _Placement.PIDConnectPointLocation(oSymbolObj, 2, dConnpos_x, dConnpos_y)
1637
                            '   _Placement.PIDPlaceSymbol(sSubSymbol, dConnpos_x, dConnpos_y, dAngle, TargetItem:=oSymbolObj.AsLMRepresentation)
1638
                            _Placement.PIDPlaceSymbol(sSubSymbol, dConnpos_x, dConnpos_y,, dAngle)
1639
1640
                        Else
1641
                            _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1642
                        End If
1643
1644
1645 6a6d8ab4 Gyusu
                        SetListBoxItems(ListBox_Result, "Place Fitting..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1646 54b98e09 Gyusu
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() And sClass.ToUpper() = _SYMBOL_ACTUATORS.ToUpper() Then
1647 d039e347 Gyusu
                        _iFittingcnt = _iFittingcnt + 1
1648
                        Dim sDuplicatePath As String() = sSystemPath.Split(",")
1649
                        Dim sMainSymbol As String = ""
1650
                        Dim sSubSymbol As String = ""
1651
                        For Each sPath In sDuplicatePath
1652
                            If sMainSymbol = "" Then
1653
                                sMainSymbol = sPath.Replace(vbLf, "")
1654
                            Else
1655
                                sSubSymbol = sPath.Replace(vbLf, "")
1656
                            End If
1657
                        Next
1658
                        Dim oSymbolObj As LMSymbol = _Placement.PIDPlaceSymbol(sMainSymbol, dX, dY, , dAngle)
1659
                        Dim dSymbolpos_x As Double = oSymbolObj.XCoordinate
1660
                        Dim dSymbolpos_y As Double = oSymbolObj.YCoordinate
1661
                        _Placement.PIDPlaceSymbol(sSubSymbol, dSymbolpos_x, dSymbolpos_y, , dAngle, TargetItem:=oSymbolObj.AsLMAItem)
1662
1663 171ac39d Gyusu
                    Else
1664 9e1e7135 Gyusu
                        _iFittingcnt = _iFittingcnt + 1
1665 171ac39d Gyusu
                        _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1666 6a6d8ab4 Gyusu
                        SetListBoxItems(ListBox_Result, "Place Fitting..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1667 54b98e09 Gyusu
                        End If
1668
1669 171ac39d Gyusu
                    End If
1670 41e4023e Gyusu
                _Itemcnt = _Itemcnt + 1
1671
                Dim dCalcProgressValue As Double = (_Itemcnt / _allItem) * 100
1672
                SetProgressbar(ProgressBar_Status, dCalcProgressValue)
1673
                Label_Progress.Text = Math.Round(dCalcProgressValue, 0) & "%"
1674
            End If
1675 171ac39d Gyusu
1676 54b98e09 Gyusu
        Catch ex As Exception
1677
            Return False
1678
        End Try
1679
    End Function
1680
1681
1682
    Private Sub FindConnectionLine(ByVal oLine_Dt As DataTable, ByRef dx As Double, ByRef dy As Double)
1683
1684
        Try
1685
            For Each oRow In oLine_Dt.Rows
1686
                Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1687
                Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1688
                Dim d기준s_x As Double = 0
1689
                Dim d기준s_y As Double = 0
1690
                Dim d기준e_x As Double = 0
1691
                Dim d기준e_y As Double = 0
1692
                ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1693
                ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1694
                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
1695
                    dx = d기준s_x
1696
                    dy = d기준s_y
1697
                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
1698
                    dx = d기준e_x
1699
                    dy = d기준e_y
1700
                End If
1701
            Next
1702
        Catch ex As Exception
1703
        End Try
1704
    End Sub
1705
1706
1707
    Dim _라인보정기준값 As Integer = 10
1708
1709
    Private Function 라인보정(ByRef oLine_Dt As DataTable, ByVal sUid As String, ByRef dsx As Double, ByRef dsy As Double,
1710
                                      ByRef dex As Double, ByRef dey As Double)
1711
        Try
1712
            Dim bCheck라인 As Boolean = False
1713
            '일치하는 Line 찾기
1714
            For Each oRow In oLine_Dt.Rows
1715
                Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1716
                Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1717
                Dim sBUid As String = oRow(_XML_LINE_UID).ToString()
1718
                If sBUid <> sUid Then
1719
                    Dim d기준s_x As Double = 0
1720
                    Dim d기준s_y As Double = 0
1721
                    Dim d기준e_x As Double = 0
1722
                    Dim d기준e_y As Double = 0
1723
                    ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1724
                    ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1725
1726
                    If (dsx = d기준s_x And dsy = d기준s_y) Or (dsx = d기준e_x And dsy = d기준e_y) Or
1727
                       (dex = d기준s_x And dey = d기준s_y) Or (dex = d기준e_x And dey = d기준e_y) Then
1728
                        bCheck라인 = True
1729
                    End If
1730
                End If
1731
            Next
1732
1733
            If bCheck라인 = False Then
1734
                For Each oRow In oLine_Dt.Rows
1735
                    Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1736
                    Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1737
                    Dim sBUid As String = oRow(_XML_LINE_UID).ToString()
1738
                    If sBUid <> sUid Then
1739
                        Dim d기준s_x As Double = 0
1740
                        Dim d기준s_y As Double = 0
1741
                        Dim d기준e_x As Double = 0
1742
                        Dim d기준e_y As Double = 0
1743
                        ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1744
                        ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1745
                        If ((dsx - _라인보정기준값 <= d기준s_x And dsx + _라인보정기준값 >= d기준s_x) And (dsy - _라인보정기준값 <= d기준s_y And dsy + _라인보정기준값 >= d기준s_y)) Then
1746
                            oRow(_XML_LINE_STARTPOINT) = dsx & "," & dsy
1747
                            bCheck라인 = True
1748
                            Exit For
1749
                        ElseIf ((dsx - _라인보정기준값 <= d기준e_x And dsx + _라인보정기준값 >= d기준e_x) And (dsy - _라인보정기준값 <= d기준e_y And dsy + _라인보정기준값 >= d기준e_y)) Then
1750
                            oRow(_XML_LINE_ENDPOINT) = dsx & "," & dsy
1751
                            bCheck라인 = True
1752
                            Exit For
1753
                        ElseIf ((dex - _라인보정기준값 <= d기준s_x And dex + _라인보정기준값 >= d기준s_x) And (dey - _라인보정기준값 <= d기준s_y And dey + _라인보정기준값 >= d기준s_y)) Then
1754
                            oRow(_XML_LINE_STARTPOINT) = dex & "," & dey
1755
                            bCheck라인 = True
1756
                            Exit For
1757
                        ElseIf ((dex - _라인보정기준값 <= d기준e_x And dex + _라인보정기준값 >= d기준e_x) And (dey - _라인보정기준값 <= d기준e_y And dey + _라인보정기준값 >= d기준e_y)) Then
1758
                            oRow(_XML_LINE_ENDPOINT) = dex & "," & dey
1759
                            bCheck라인 = True
1760
                            Exit For
1761
                        End If
1762
1763
                    End If
1764
                Next
1765 171ac39d Gyusu
            End If
1766
1767 54b98e09 Gyusu
            Return bCheck라인
1768 171ac39d Gyusu
        Catch ex As Exception
1769
            Return False
1770
        End Try
1771 54b98e09 Gyusu
1772
1773 171ac39d Gyusu
    End Function
1774
1775 460d6abd Gyusu
    Private Function FindOverlapLine(ByVal oLine_Dt As DataTable, ByVal sUid As String, ByRef dsx As Double, ByRef dsy As Double,
1776
                                      ByRef dex As Double, ByRef dey As Double)
1777
        Try
1778
            Dim bCheckOverlap As Boolean = False
1779
            For Each oRow In oLine_Dt.Rows
1780
                Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1781
                Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1782
                Dim sBUid As String = oRow(_XML_LINE_UID).ToString()
1783
                If sBUid <> sUid Then
1784
                    Dim d기준s_x As Double = 0
1785
                    Dim d기준s_y As Double = 0
1786
                    Dim d기준e_x As Double = 0
1787
                    Dim d기준e_y As Double = 0
1788
                    ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1789
                    ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1790 54b98e09 Gyusu
                    If (d기준s_x <= dsx And d기준e_x >= dex And
1791
                        d기준s_y <= dsy And d기준e_y >= dey) Then
1792 460d6abd Gyusu
                        '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1793
                        If dsy - d기준s_y > d기준e_y - dey Then
1794
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1795
                            If dResultCalc < 10 Then
1796
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1797
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1798
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1799
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1800
                                If dCalcStartY = 0 Then
1801
                                    dey = d기준e_y
1802
                                Else
1803
                                    dey = dCalcStartY
1804
                                End If
1805
                            End If
1806
                        Else
1807 abb01e6c Gyusu
                            '  Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1808
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1809 460d6abd Gyusu
                            If dResultCalc < 10 Then
1810
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1811
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1812
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1813
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1814
                                If dCalcStartY = 0 Then
1815
                                    dsy = d기준s_y
1816
                                Else
1817
                                    dsy = dCalcStartY
1818
                                End If
1819
                            End If
1820
                        End If
1821
                        bCheckOverlap = True
1822
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
1823
                            d기준s_y <= dey And d기준e_y >= dsy Then
1824
                        '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1825
                        If dey - d기준s_y > d기준e_y - dsy Then
1826
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1827
                            If dResultCalc < 10 Then
1828
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1829
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1830
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1831
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1832
                                If dCalcStartY = 0 Then
1833 abb01e6c Gyusu
                                    dsy = d기준e_y
1834 460d6abd Gyusu
                                Else
1835 abb01e6c Gyusu
                                    dsy = dCalcStartY
1836 460d6abd Gyusu
                                End If
1837
1838
                            End If
1839
                            '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1840
                        Else
1841 abb01e6c Gyusu
                            '  Dim dResultCalc As Double = (Math.Abs((dsy - d기준s_y)) / Math.Abs((d기준e_y - dey))) * 100
1842
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1843 460d6abd Gyusu
                            If dResultCalc < 10 Then
1844
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1845
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1846
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1847
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1848
                                If dCalcStartY = 0 Then
1849 abb01e6c Gyusu
                                    dey = d기준e_y
1850 460d6abd Gyusu
                                Else
1851 abb01e6c Gyusu
                                    dey = dCalcStartY
1852 460d6abd Gyusu
                                End If
1853
                            End If
1854
                        End If
1855
                        bCheckOverlap = True
1856
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
1857
                            d기준s_y <= dey And d기준e_y >= dsy Then
1858
1859
                        If dsx - d기준s_x > d기준e_x - dex Then
1860
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1861
                            If dResultCalc < 10 Then
1862
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1863
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1864
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1865
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1866
                                If dCalcStartX = 0 Then
1867
                                    dex = d기준e_x
1868
                                Else
1869
                                    dex = dCalcStartX
1870
                                End If
1871
                            End If
1872
                        Else
1873 abb01e6c Gyusu
                            '  Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1874
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1875 460d6abd Gyusu
                            If dResultCalc < 10 Then
1876
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1877
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1878
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1879
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1880
                                If dCalcStartX = 0 Then
1881
                                    dsx = d기준s_x
1882
                                Else
1883
                                    dsx = dCalcStartX
1884
                                End If
1885
                            End If
1886
                        End If
1887
                        bCheckOverlap = True
1888
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
1889
                            d기준s_y <= dey And d기준e_y >= dsy Then
1890
1891
                        If dex - d기준s_x > d기준e_x - dsx Then
1892
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1893
                            If dResultCalc < 10 Then
1894
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1895
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1896
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1897
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1898
                                If dCalcStartX = 0 Then
1899 abb01e6c Gyusu
                                    dsx = d기준e_x
1900 460d6abd Gyusu
                                Else
1901 abb01e6c Gyusu
                                    dsx = dCalcStartX
1902 460d6abd Gyusu
                                End If
1903
                            End If
1904
                        Else
1905 abb01e6c Gyusu
                            ' Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1906
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1907 460d6abd Gyusu
                            If dResultCalc < 10 Then
1908
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1909
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1910
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1911
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1912
                                If dCalcStartX = 0 Then
1913 abb01e6c Gyusu
                                    dex = d기준s_x
1914 460d6abd Gyusu
                                Else
1915 abb01e6c Gyusu
                                    dex = dCalcStartX
1916 460d6abd Gyusu
                                End If
1917
                            End If
1918
1919
                        End If
1920
                        bCheckOverlap = True
1921
                    End If
1922
                End If
1923
            Next
1924 3acffcee Gyusu
1925 460d6abd Gyusu
            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 3acffcee Gyusu
    Private Function DrawLineNo(ByVal oPipeRun_Dt As DataTable, ByVal CLine_No As Line_no) As Boolean
1965 171ac39d Gyusu
        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 3acffcee Gyusu
1977
                For Each oRow In oPipeRun_Dt.Rows
1978
                    Dim dStartx As Double = Double.Parse(oRow("startx").ToString())
1979
                    Dim dStarty As Double = Double.Parse(oRow("starty").ToString())
1980
                    Dim dEndx As Double = Double.Parse(oRow("endx").ToString())
1981
                    Dim dEndy As Double = Double.Parse(oRow("endy").ToString())
1982
1983
                    Dim dStartSum As Double = Math.Abs(dStartx - dLocationx) + Math.Abs(dStarty - dLocationy)
1984
                    Dim dEndSum As Double = Math.Abs(dEndx - dLocationx) + Math.Abs(dEndy - dLocationy)
1985
                    If dStartSum > dEndSum Then
1986
                        oRow("value") = dEndSum
1987
                    Else
1988
                        oRow("value") = dStartSum
1989 171ac39d Gyusu
                    End If
1990 3acffcee Gyusu
1991 171ac39d Gyusu
                Next
1992 3acffcee Gyusu
1993
                Dim dataView As New DataView(oPipeRun_Dt)
1994
                dataView.Sort = " value asc"
1995
                Dim oDt As DataTable = dataView.ToTable()
1996
1997
                If oDt.Rows.Count > 0 Then
1998
                    Try
1999
                        Dim oPiperun As LMPipeRun = CType(oDt.Rows(0)("Piperun"), LMPipeRun)
2000
                        ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
2001
                        Dim dLineNoLocation(2) As Double
2002
                        dLineNoLocation(1) = dX
2003
                        dLineNoLocation(2) = dY
2004
                        'Label
2005
                        Dim sSystemPath As String = CLine_No.SystemPath
2006
                        Dim dAngle As Double = CLine_No.Angle
2007
                        Dim labelpersist As LMLabelPersist
2008
2009
                        For Each representation In oPiperun.Representations
2010
                            If representation.RepresentationType = "Connector" Then
2011
                                labelpersist = _Placement.PIDPlaceLabel(sSystemPath,
2012
                                dLineNoLocation,, dAngle, LabeledItem:=representation)
2013
                                _iPipeLineNocnt = _iPipeLineNocnt + 1
2014
                                SetListBoxItems(ListBox_Result, "Place PipeLineNo Label..(" & dLocationx & "," & dLocationy & ")..." & _iPipeLineNocnt & " count ")
2015
                            End If
2016
                        Next
2017
                    Catch ex As Exception
2018
2019
                    End Try
2020
2021
2022
                End If
2023
2024
2025
2026 171ac39d Gyusu
                Return True
2027
            Else
2028
                Return False
2029
            End If
2030
2031
        Catch ex As Exception
2032
            Return False
2033
        End Try
2034
    End Function
2035
2036 9e1e7135 Gyusu
2037
    Private Sub InitItemCount()
2038
        _iPipeLineNocnt = 0
2039
        _iPipecnt = 0
2040
        _iFittingcnt = 0
2041
        _iValvecnt = 0
2042
        _iInstrumentcnt = 0
2043
        _iEquipmentcnt = 0
2044 3acffcee Gyusu
        _iNozzlecnt = 1
2045
2046 9e1e7135 Gyusu
    End Sub
2047 171ac39d Gyusu
2048 41e4023e Gyusu
    Private Function GetAllCheckNodeCount() As Integer
2049
        _allItem = 0
2050
        For i = 0 To Tree_Result.Nodes.Count - 1
2051
            For j = 0 To Tree_Result.Nodes(i).Nodes.Count - 1
2052
                For k = 0 To Tree_Result.Nodes(i).Nodes(j).Nodes.Count - 1
2053
                    For l = 0 To Tree_Result.Nodes(i).Nodes(j).Nodes(k).Nodes.Count - 1
2054
                        If Tree_Result.Nodes(i).Nodes(j).Nodes(k).Nodes(l).Checked = True Then
2055
                            _allItem = _allItem + 1
2056
                        End If
2057
                    Next
2058
                Next
2059
            Next
2060
        Next
2061
        Return _allItem
2062
    End Function
2063 54b98e09 Gyusu
2064
2065 171ac39d Gyusu
    Private Function AutoModeling() As Boolean
2066
        Try
2067 54b98e09 Gyusu
            _CompleteConvert = False
2068 41e4023e Gyusu
            Label_Progress.Text = "0%"
2069 171ac39d Gyusu
            SetListBoxItems(ListBox_Result, " Auto converting 시작....")
2070
            Dim oDwg_Dt As DataTable = LoadAllDrawing()
2071 41e4023e Gyusu
            _allItem = GetAllCheckNodeCount()
2072 171ac39d Gyusu
            For Each oDrwing As TreeNode In Tree_Result.Nodes
2073
                For Each oDwgNode As TreeNode In oDrwing.Nodes
2074
                    Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
2075 54b98e09 Gyusu
                    Dim CDrawing As Drawing = GetDrawing(sDwgName)
2076
                    If CDrawing IsNot Nothing Then
2077 9e1e7135 Gyusu
                        If OpenSPPID(oDwg_Dt, oDwgNode.Text) Then
2078
                            InitItemCount()
2079
                            Dim iAllLineNoCount As Integer = Tree_Result.Nodes.Count ' GetCheckNodeCount(oLinenoNode)
2080
                            Dim iLineNoCount As Integer = 0 ' GetCheckNodeCount(oLinenoNode)
2081 6a6d8ab4 Gyusu
                            SetListBoxItems(ListBox_Result, "Place " & CDrawing.DwgName & "....")
2082
                            For Each oNode As TreeNode In oDwgNode.Nodes
2083 54b98e09 Gyusu
                                Dim iItemcnt As Integer = 0
2084 6a6d8ab4 Gyusu
                                Dim sNodeUid As String = oNode.Name
2085 3acffcee Gyusu
                                Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
2086
2087 6a6d8ab4 Gyusu
                                If sNodeUid <> "PipeLineNo" Then
2088
                                    Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
2089
                                    If CLineNo IsNot Nothing Then
2090
                                        Dim oLine_Dt As DataTable = CLineNo.Dt_Line
2091
                                        Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
2092
                                        Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
2093
                                        Dim oDrawLinenoLabel As Boolean = False
2094 3acffcee Gyusu
2095 6a6d8ab4 Gyusu
                                        For Each oLineNode As TreeNode In oNode.Nodes
2096 54b98e09 Gyusu
                                            iItemcnt = iItemcnt + 1
2097 6a6d8ab4 Gyusu
                                            Dim sLineUid As String = oLineNode.Name
2098
                                            If oLineNode.Checked Then
2099
                                                Dim sUid As String = oLineNode.Name
2100
                                                If oLine_Dt.Select("[" & _XML_LINE_UID & "]= '" & sUid & "'").Length = 1 Then
2101 3acffcee Gyusu
                                                    DrawLine(sUid, sNodeUid, oLine_Dt, oAttribute_Dt, oPipeRun_Dt)
2102
2103 6a6d8ab4 Gyusu
                                                End If
2104 3acffcee Gyusu
                                                'If oDrawLinenoLabel = False Then
2105
                                                '    DrawLineNo(oPipeRun, CLineNo)
2106
                                                'End If
2107
                                                oDrawLinenoLabel = True
2108 41e4023e Gyusu
                                            End If
2109
                                            If oNode.Nodes.Count - 1 = iItemcnt And oDrawLinenoLabel Then
2110
                                                Try
2111 3acffcee Gyusu
                                                    DrawLineNo(oPipeRun_Dt, CLineNo)
2112 41e4023e Gyusu
                                                Catch ex As Exception
2113
2114
                                                End Try
2115
2116 6a6d8ab4 Gyusu
                                            End If
2117
                                        Next
2118
                                        For Each oSymbolNode As TreeNode In oNode.Nodes
2119
                                            If oSymbolNode.Checked Then
2120
                                                Dim sUid As String = oSymbolNode.Name
2121
                                                If oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "]= '" & sUid & "'").Length = 1 Then
2122 54b98e09 Gyusu
                                                    DrawSymbol(sUid, sNodeUid, oSymbol_Dt, oAttribute_Dt, CLineNo.Dt_Line)
2123 6a6d8ab4 Gyusu
                                                End If
2124
                                            End If
2125
                                        Next
2126
                                        iLineNoCount = iLineNoCount + 1
2127
                                    End If
2128 3acffcee Gyusu
2129
2130
                                    Dim CTrimLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
2131
                                    If CTrimLineNo IsNot Nothing Then
2132
                                        Dim oLine_Dt As DataTable = CTrimLineNo.Dt_Line
2133
                                        Dim oSymbol_Dt As DataTable = CTrimLineNo.Dt_Symbol
2134
                                        Dim oAttribute_Dt As DataTable = CTrimLineNo.Dt_Attribute
2135
                                        Dim oDrawLinenoLabel As Boolean = False
2136
2137
                                        For Each oLineNode As TreeNode In oNode.Nodes
2138
                                            iItemcnt = iItemcnt + 1
2139
                                            Dim sLineUid As String = oLineNode.Name
2140
                                            If oLineNode.Checked Then
2141
                                                Dim sUid As String = oLineNode.Name
2142
                                                If oLine_Dt.Select("[" & _XML_LINE_UID & "]= '" & sUid & "'").Length = 1 Then
2143
                                                    DrawLine(sUid, sNodeUid, oLine_Dt, oAttribute_Dt, oPipeRun_Dt)
2144
2145
                                                End If
2146
                                                'If oDrawLinenoLabel = False Then
2147
                                                '    DrawLineNo(oPipeRun, CLineNo)
2148
                                                'End If
2149
                                                oDrawLinenoLabel = True
2150
                                            End If
2151
                                        Next
2152
                                        For Each oSymbolNode As TreeNode In oNode.Nodes
2153
                                            If oSymbolNode.Checked Then
2154
                                                Dim sUid As String = oSymbolNode.Name
2155
                                                If oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "]= '" & sUid & "'").Length = 1 Then
2156
                                                    DrawSymbol(sUid, sNodeUid, oSymbol_Dt, oAttribute_Dt, CTrimLineNo.Dt_Line)
2157
                                                End If
2158
                                            End If
2159
                                        Next
2160
                                        iLineNoCount = iLineNoCount + 1
2161
                                    End If
2162
2163 6a6d8ab4 Gyusu
                                    Dim CEqpNo As Eqp_no = GetEqpNo(CDrawing, sNodeUid)
2164
                                    If CEqpNo IsNot Nothing Then
2165
                                        Dim oSymbol_Dt As DataTable = CEqpNo.Dt_Equipment
2166
                                        Dim oAttribute_Dt As DataTable = CEqpNo.Dt_Attribute
2167
                                        For Each oSymbolNode As TreeNode In oNode.Nodes
2168
                                            If oSymbolNode.Checked Then
2169
                                                Dim sUid As String = oSymbolNode.Name
2170 41e4023e Gyusu
                                                PlaceEquipment(sUid, oSymbol_Dt, oAttribute_Dt)
2171
                                                ' DrawSymbol(sUid, sNodeUid, oSymbol_Dt, oAttribute_Dt, CLineNo.Dt_Line)
2172 6a6d8ab4 Gyusu
                                            End If
2173
                                        Next
2174
                                    End If
2175
                                Else
2176 171ac39d Gyusu
                                    Dim oDrawLinenoLabel As Boolean = False
2177 6a6d8ab4 Gyusu
                                    For Each oLineNode As TreeNode In oNode.Nodes
2178
                                        Dim CLineNo As Line_no = GetOnlyPipeLineNo(CDrawing, oLineNode.Name)
2179
                                        Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
2180
                                        Dim oLine_Dt As DataTable = CLineNo.Dt_Line
2181 9e1e7135 Gyusu
                                        Dim sLineUid As String = oLineNode.Name
2182
                                        If oLineNode.Checked Then
2183
                                            Dim sUid As String = oLineNode.Name
2184 3acffcee Gyusu
                                            DrawLine(sUid, sNodeUid, oLine_Dt, oAttribute_Dt, oPipeRun_Dt)
2185 171ac39d Gyusu
                                        End If
2186 9e1e7135 Gyusu
                                    Next
2187
                                End If
2188 41e4023e Gyusu
2189
2190
2191 9e1e7135 Gyusu
                            Next
2192 171ac39d Gyusu
                        End If
2193 9e1e7135 Gyusu
                    End If
2194 171ac39d Gyusu
                Next
2195
            Next
2196
            SetProgressbar(ProgressBar_Status, 100)
2197 41e4023e Gyusu
            Label_Progress.Text = "100%"
2198 171ac39d Gyusu
            SetListBoxItems(ListBox_Result, " Auto converting 완료")
2199 54b98e09 Gyusu
            _CompleteConvert = True
2200 171ac39d Gyusu
            Return True
2201
        Catch ex As Exception
2202
            Return False
2203
        End Try
2204
    End Function
2205
2206
2207
2208 54b98e09 Gyusu
    Private Sub ThreadConvert()
2209 559daf6d Gyusu
        If _DrawingsList IsNot Nothing Then
2210
            If _DrawingsList.Count > 0 Then
2211
                AutoModeling()
2212
            End If
2213 171ac39d Gyusu
        End If
2214 e282643f Gyusu
    End Sub
2215
2216 54b98e09 Gyusu
    Private Sub ThreadOPCRemove()
2217
        While _CompleteConvert = False
2218
            Dim oFindOPC As New FindOpc
2219
            oFindOPC.RemoveOPCDlg()
2220
        End While
2221 e282643f Gyusu
2222 54b98e09 Gyusu
    End Sub
2223 171ac39d Gyusu
2224 e282643f Gyusu
2225
    Private Function OpenDrawing(ByVal oDt As DataTable, ByVal sDwgName As String) As String
2226
        Dim oRows As DataRow() = oDt.Select("[Name] = '" & sDwgName & "'")
2227
        Dim oPath As String = ""
2228
        If oRows.Length > 0 Then
2229
            oPath = oRows(0).Item("Path").ToString()
2230
        End If
2231
        Return oPath
2232
    End Function
2233
2234 272662f9 Gyusu
    Private Sub LoadXmlToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LoadXmlToolStripMenuItem.Click
2235 171ac39d Gyusu
        If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
2236 54b98e09 Gyusu
            LoadDB()
2237 171ac39d Gyusu
            LoadXmlItem(FolderBrowserDialog1.SelectedPath)
2238
        End If
2239
    End Sub
2240
    Private Sub LoadXmlItem(ByVal sFolderPath As String)
2241
        _DrawingsList = New List(Of Drawing)
2242
        Dim sfileEntries As String() = Directory.GetFiles(sFolderPath)
2243
        If Tree_Result.Nodes.Count > 0 Then
2244
            Tree_Result.Nodes(0).Nodes.Clear()
2245
            For Each sfileName In sfileEntries
2246
                Dim sExtension As String = Path.GetExtension(sfileName)
2247
                If sExtension = ".xml" Then
2248
                    Dim sDwgName As String = Path.GetFileNameWithoutExtension(sfileName)
2249
                    Dim sDwgPath As String = sfileName
2250
                    Dim oNode As TreeNode = Tree_Result.Nodes(0).Nodes.Add(sDwgPath, sDwgName, 15)
2251
                    Dim oDwg As Drawing = AddSymbolItem(sDwgPath, oNode)
2252
                    _DrawingsList.Add(oDwg)
2253
                End If
2254
            Next
2255
            Tree_Result.Nodes(0).Expand()
2256
        End If
2257
    End Sub
2258 272662f9 Gyusu
2259
2260 20c84e05 Gyusu
    ''' <summary>
2261
    '''  XML Tree 구조 생성 
2262
    ''' </summary>
2263
    ''' <param name="sDwgPath"></param>
2264 171ac39d Gyusu
    Private Function AddSymbolItem(ByVal sDwgPath As String, ByVal oParentNode As TreeNode) As Drawing
2265
        Dim oDwg_Ds As Drawing = LoadSymbolInXml(sDwgPath)
2266 54b98e09 Gyusu
        If oDwg_Ds IsNot Nothing Then
2267
            Dim oLineLists As List(Of Line_no) = oDwg_Ds.Line_nos
2268
2269
            Dim oEqpLists As List(Of Eqp_no) = oDwg_Ds.Eqp_nos
2270 3acffcee Gyusu
2271
            Dim oTrimLineLists As List(Of Line_no) = oDwg_Ds.TrimLine_nos
2272
2273 54b98e09 Gyusu
            Dim oPipe As Boolean = False
2274
            Dim oFitting As Boolean = False
2275
            Dim oOnlyPipesNode As TreeNode
2276
            Dim oOnlyFittingsNode As TreeNode
2277
            'PipeLine 구분
2278
2279
            For Each oLinelist In oLineLists
2280
                Dim sLineNoUid As String = oLinelist.Uid
2281
                Dim sLineNo As String = oLinelist.Text
2282
                Dim oLineNoNode As TreeNode = oParentNode.Nodes.Add(sLineNoUid, sLineNo)
2283
                For Each oLineRow In oLinelist.Dt_Line.Rows
2284
                    Dim sLineUid As String = oLineRow(_XML_LINE_UID)
2285
                    Dim oPipeNode As TreeNode = oLineNoNode.Nodes.Add(sLineUid, "Pipe")
2286
                    oPipeNode.Tag = sLineNoUid
2287
                Next
2288
                For Each oSymbolRow In oLinelist.Dt_Symbol.Rows
2289
                    Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID)
2290
                    Dim sSymbolName As String = oSymbolRow(_XML_SYMBOL_NAME)
2291
                    Dim oSymbolNode As TreeNode = oLineNoNode.Nodes.Add(sSymbolUid, sSymbolName)
2292
                    oSymbolNode.Tag = sLineNoUid
2293
                Next
2294
            Next
2295 3acffcee Gyusu
2296 54b98e09 Gyusu
            For Each oEqplist In oEqpLists
2297
                Dim sEqpUid As String = oEqplist.Uid
2298
                Dim sEqpNo As String = "EQUIPMENT"
2299
                Dim oEqpNode As TreeNode = oParentNode.Nodes.Add(sEqpUid, sEqpNo)
2300 d039e347 Gyusu
2301 54b98e09 Gyusu
2302
                For Each oSymbolRow In oEqplist.Dt_Equipment.Rows
2303
                    Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID)
2304
                    Dim sSymbolName As String = oSymbolRow(_XML_SYMBOL_NAME)
2305
                    Dim oSymbolNode As TreeNode = oEqpNode.Nodes.Add(sSymbolUid, sSymbolName)
2306
                    oSymbolNode.Tag = sEqpUid
2307
                Next
2308 171ac39d Gyusu
            Next
2309 3acffcee Gyusu
            Dim sTrimLine As String = "TrimLineNos"
2310
            Dim iTrimLinecnt As Integer = 1
2311
            For Each oTrimLinelist In oTrimLineLists
2312
                Dim sLineNoUid As String = oTrimLinelist.Uid
2313
                Dim sLineNo As String = sTrimLine & "_" & iTrimLinecnt
2314
                Dim oLineNoNode As TreeNode = oParentNode.Nodes.Add(sLineNoUid, sLineNo)
2315
                For Each oLineRow In oTrimLinelist.Dt_Line.Rows
2316
                    Dim sLineUid As String = oLineRow(_XML_LINE_UID)
2317
                    Dim oPipeNode As TreeNode = oLineNoNode.Nodes.Add(sLineUid, "Pipe")
2318
                    oPipeNode.Tag = sLineNoUid
2319
                Next
2320
                For Each oSymbolRow In oTrimLinelist.Dt_Symbol.Rows
2321
                    Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID)
2322
                    Dim sSymbolName As String = oSymbolRow(_XML_SYMBOL_NAME)
2323
                    Dim oSymbolNode As TreeNode = oLineNoNode.Nodes.Add(sSymbolUid, sSymbolName)
2324
                    oSymbolNode.Tag = sLineNoUid
2325
                Next
2326
                iTrimLinecnt = iTrimLinecnt + 1
2327
            Next
2328
2329 54b98e09 Gyusu
        End If
2330
2331 171ac39d Gyusu
        Return oDwg_Ds
2332
    End Function
2333 272662f9 Gyusu
    Private Sub Tree_Result_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles Tree_Result.AfterCheck
2334
        If e.Node.Checked = True Then
2335
            For Each oNode As TreeNode In e.Node.Nodes
2336
                oNode.Checked = True
2337
            Next
2338
        Else
2339
            For Each oNode As TreeNode In e.Node.Nodes
2340
                oNode.Checked = False
2341
            Next
2342
        End If
2343
    End Sub
2344 171ac39d Gyusu
2345 559daf6d Gyusu
    Private Sub Btn_Setting_Click(sender As Object, e As EventArgs) Handles Btn_Setting.Click
2346
        Dim oSettings As Settings = New Settings()
2347
        oSettings.ShowDialog()
2348
    End Sub
2349 42c0013c Gyusu
2350
    Private Sub Btn_TestNozzle_Click(sender As Object, e As EventArgs) Handles Btn_TestNozzle.Click
2351
2352
        Dim sVessel_ID As String = "841D5E640AE5421B9A017DDC2E87FF11"
2353
        Dim objVessel As LMVessel
2354
        objVessel = _Placement.PIDDataSource.GetVessel(sVessel_ID)
2355
        Dim oVesselLocation As LMLocations = objVessel.Locations
2356
        Dim symVessel As LMSymbol = _Placement.PIDDataSource.GetSymbol(objVessel.Representations.Nth(1).Id)
2357
        Dim XCoordinate As String = symVessel.Attributes("XCoordinate").Value
2358
        Dim YCoordinate As String = symVessel.Attributes("YCoordinate").Value
2359
        symVessel.Attributes("XCoordinate").Value = XCoordinate + 0.01
2360
        symVessel.Attributes("YCoordinate").Value = YCoordinate + 0.01
2361
        symVessel.Commit()
2362
        Dim sValve_ID As String = "DB7B0CA8A2664A6BA7A9615764BA62B0"
2363
        Dim objValve As LMSymbol
2364
        Dim objValves As LMPipingComp = _Placement.PIDDataSource.GetPipingComp(sValve_ID)
2365
2366
        objValve = _Placement.PIDDataSource.GetSymbol(objValves.Representations.Nth(1).Id)
2367
        objValve.Commit()
2368
        Dim dVesselX As Double = XCoordinate
2369
        Dim dVesselY As Double = YCoordinate
2370
        Dim X1 As Double, Y1 As Double, X2 As Double, Y2 As Double
2371
2372
        _Placement.PIDConnectPointLocation(objValve, 1, X1, Y1)
2373
2374
        _Placement.PIDConnectPointLocation(objValve, 2, X2, Y2)
2375
2376
        Dim nozzlename As String = "\Equipment Components\Nozzles\Flanged Nozzle.sym"
2377
        Dim dCalc_x As Double = 0
2378
        Dim dCalc_y As Double = 0
2379
2380
        If dVesselX - X2 > 0 Then
2381
            dCalc_x = dVesselX - (dVesselX - X2)
2382
        Else
2383
            dCalc_x = dVesselX + (X2 - dVesselX)
2384
        End If
2385
        If dVesselY - Y2 > 0 Then
2386
            dCalc_y = dVesselY - (dVesselY - Y2)
2387
        Else
2388
            dCalc_y = dVesselY + (Y2 - dVesselY)
2389
        End If
2390
2391
        Dim objNozzle As LMSymbol = _Placement.PIDPlaceSymbol(nozzlename, dCalc_x, dCalc_y,
2392
            TargetItem:=symVessel.AsLMRepresentation)
2393
2394
        Dim blnSuccess As Boolean = _Placement.PIDConnectPointLocation(objNozzle, 1, X1, Y1)
2395
        blnSuccess = _Placement.PIDConnectPointLocation(objNozzle, 2, X1, Y1)
2396
2397
        objValve = _Placement.PIDPlaceSymbol(objValve.FileName, X1, Y1, ExistingItem:=objValve.AsLMAItem,
2398
          TargetItem:=objNozzle.AsLMRepresentation)
2399
2400
2401
2402
    End Sub
2403 39d43554 Gyusu
2404
    Private Sub Btn_SymbolLibrary_Click(sender As Object, e As EventArgs) Handles Btn_SymbolLibrary.Click
2405
        Dim oMapping As New Mapping(_PIDSymbol_DB)
2406
        oMapping.Show()
2407
    End Sub
2408 41e4023e Gyusu
2409
    Private Sub Btn_Stop_Click(sender As Object, e As EventArgs) Handles Btn_Stop.Click
2410
        Try
2411
            SetListBoxItems(ListBox_Result, " Auto converting 중지....")
2412
            _Main_trd.Abort()
2413
            _Opc_trd.Abort()
2414
        Catch ex As Exception
2415
2416
        End Try
2417
    End Sub
2418 e282643f Gyusu
End Class
2419
2420
2421
Public Class DrawingInfo
2422
    Public mDrawingName As String
2423
    Public mSpID As String
2424
    Public mPath As String
2425 4f359afa Gyusu
End Class
2426 e282643f Gyusu
2427
2428
2429
클립보드 이미지 추가 (최대 크기: 500 MB)