프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / Main.vb @ bb2a0c79

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

1
Imports System.IO
2
Imports System.Data.SqlClient
3
Imports System.Data.SQLite
4
Imports Plaice
5
Imports Llama
6
Imports PidA
7

    
8

    
9
Imports System.Threading
10

    
11
Public Class Main
12

    
13
    'Dim _Mapping_DB As DataTable = New DataTable()
14
    Dim _Mapping_DB As DataSet = New DataSet()
15
    Dim _Attribute_DB As DataTable = New DataTable()
16
    Dim _PIDSymbol_DB As DataTable = New DataTable()
17
    Dim _ResultModeling_DT As DataTable = New DataTable()
18

    
19

    
20
    Dim _Placement As New Placement
21
    Dim _DWG_X = 0.875 '0.695 '1 '
22
    Dim _DWG_Y = 0.617 '0.585 '0.8 '
23
    'Dim _DWG_X = 0.842 '0.695 '1 '
24
    'Dim _DWG_Y = 0.614 '0.585 '0.8 '
25
    Dim _IMG_X = 0
26
    Dim _IMG_Y = 0
27

    
28
    Dim _Unit As String
29

    
30
    'Drawing 전역변수
31
    Dim _objPIDADrawing As Object
32
    '현재선택한 폴더경로
33
    Dim _selectFolderPath As String
34

    
35
    Private _Main_trd As Thread
36
    Private _Opc_trd As Thread
37

    
38
    Private _CompleteConvert As Boolean = False
39

    
40
    Private _DrawingsList As List(Of Drawing)
41

    
42

    
43
    Private _iPipeLineNocnt As Integer
44
    Private _iPipecnt As Integer
45
    Private _iFittingcnt As Integer
46
    Private _iValvecnt As Integer
47
    Private _iInstrumentcnt As Integer
48
    Private _iEquipmentcnt As Integer
49
    Private _iNozzlecnt As Integer
50
    Private _iPipintOpccnt As Integer
51

    
52
    Dim _Gembox As New CGembox()
53

    
54

    
55
    Private _allItem As Integer
56
    Private _Itemcnt As Integer
57
    Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
58
        LoadDB()
59
    End Sub
60

    
61
    Private Sub LoadDB()
62
        If My.Settings.DBPath <> "" And My.Settings.Plant_Hierarchy <> "" Then
63
            Dim sDBPath As String = My.Settings.DBPath
64

    
65
            _Gembox.isLoadFile(My.Settings.SymbolLibrary)
66
            _Mapping_DB = _Gembox.LoadFileFunc()
67
            '  _Mapping_DB = Load_DB(sDBPath, _DB_TABLE_MAPPING)
68
            _Attribute_DB = Load_DB(sDBPath, _DB_TABLE_ATTRIBUTE)
69
            _PIDSymbol_DB = Load_DB(sDBPath, _DB_TABLE_SYMBOLNAME)
70
            _ResultModeling_DT = ModelingResult_Dt()
71
            'TestPID()
72
            'OpenDrawing()
73
        Else
74
            MessageBox.Show("설정값을 먼저 확인해주세요")
75
        End If
76
    End Sub
77

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

    
93
    'Public Sub New()
94

    
95
    '    '  mDataSource.ProjectNumber = m_Information.InfoSite.SiteName
96
    '    '   mDataSource.SiteNode = m_Information.InfoProject.ProjectINI
97
    '    'm_Information = SPPIDClass.Information.GetInstance()
98

    
99
    '    'If m_Information.InfoProject.ProjectVersion = SPPIDClass.InfoProject.SPPID_43 Then
100
    '    '    'SPPID4.3용
101
    '    '    mDataSource.ProjectNumber = m_Information.InfoSite.SiteName
102
    '    'Else
103
    '    '    'SPPID2007, SPPID2009용
104
    '    '    mDataSource.ProjectNumber = m_Information.InfoSite.SiteName & "!" & m_Information.InfoSite.SiteName
105
    '    'End If
106

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

    
134
    Function OpenDrawing()
135
        Dim datasource As LMADataSource
136
        Dim objPIDAutoApp As Object
137
        Dim objPIDADrawing As Object
138
        Dim objDrawing As LMDrawing
139
        Dim objDrawings As LMDrawings
140
        datasource = New Llama.LMADataSource
141
        objPIDAutoApp = CreateObject("PIDAutomation.Application")
142
        objDrawings = New Llama.LMDrawings 'New LMDrawings
143
        datasource.SiteNode = "\\desktop-9vlq0dp\Test03Site\smartplantv4.ini"
144
        datasource.ProjectNumber = "SBR_PBR"
145
        objDrawings.Collect(datasource)
146

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

    
163

    
164
    Public Function GetDrawingName(ByVal itemType As String, ByVal itemName As String) As DrawingInfo
165

    
166
        Dim objFilter As Object
167
        objFilter = CreateObject("Llama.LMAFilter", "")
168

    
169
        Dim drawingInfo As DrawingInfo
170
        drawingInfo = New DrawingInfo
171

    
172
        objFilter.Criteria.AddNew("FirstOne")
173
        objFilter.Criteria.Item("FirstOne").SourceAttributeName = "SP_ID"
174
        objFilter.Critedkria.Item("FirstOne").ValueAttribute = itemName
175

    
176
        objFilter.Criteria.Item("FirstOne").Operator = "="
177
        objFilter.Criteria.AddNew("SecondOne")
178
        objFilter.Criteria.Item("SecondOne").SourceAttributeName = "ItemStatus"
179
        objFilter.Criteria.Item("SecondOne").ValueAttribute = 1
180
        objFilter.Criteria.Item("SecondOne").Operator = "="
181
        objFilter.Criteria.Item("SecondOne").Conjunctive = -1
182
        objFilter.ItemType = itemType
183

    
184
        Dim PlantItems As Object
185
        PlantItems = CreateObject("Llama.LMPlantItems", "")
186
        PlantItems.Collect(mDataSource, Filter:=objFilter)
187

    
188
        If PlantItems.Count = 0 Then
189
            drawingInfo.mSpID = "PlantStockpile"
190
        End If
191

    
192
        For Each PlantItem In PlantItems
193

    
194
            'If Not PlantItem.Representations.Nth(1).DrawingID.Value.ToString().Equals("0") Then
195
            Try
196
                drawingInfo.mDrawingName = PlantItem.Representations.Nth(1).DrawingObject.Attributes("Name").Value
197
                drawingInfo.mSpID = PlantItem.Representations.Nth(1).DrawingID
198
                drawingInfo.mPath = PlantItem.Representations.Nth(1).DrawingObject.Attributes("Path").Value
199
                Debug.WriteLine("DrawingName : " & drawingInfo.mDrawingName & ", SPID : " & drawingInfo.mSpID & ", Path : " & drawingInfo.mPath)
200
            Catch ex As Exception
201

    
202
            End Try
203

    
204
            'End If
205

    
206
        Next
207

    
208
        Return drawingInfo
209

    
210
    End Function
211

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

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

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

    
284
            For Each objDrawing In objDrawings
285
                If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
286
                    objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(sPath)
287
                    If Not objPIDADrawing Is Nothing Then
288
                        objPIDADrawing.CloseDrawing
289
                    End If
290
                End If
291
            Next
292

    
293
            Dim extension As String = Path.GetExtension(oDwgName)
294
            oDwgName = oDwgName.Replace(extension, "")
295

    
296
            objPIDAutoApp = CreateObject("PIDAutomation.Application")
297

    
298
            'For Each objDrawing In objPIDAutoApp.Drawings
299
            '    objDrawing.CloseDrawing(True)
300
            'Next
301

    
302
            objPIDAutoApp.Drawings.OpenDrawing(oDwgName + ".pid")
303

    
304
            objPIDAutoApp.ActiveWindow.Fit()
305

    
306
            Return True
307
        Catch ex As Exception
308
            If objPIDADrawing IsNot Nothing Then
309
                objPIDADrawing.CloseDrawing
310
            End If
311
            If objPIDAutoApp IsNot Nothing Then
312
                objPIDAutoApp.Quit
313
            End If
314
            datasource = Nothing
315
            objPIDAutoApp = Nothing
316
            objPIDADrawing = Nothing
317
            Return False
318
        End Try
319
        If objPIDADrawing IsNot Nothing Then
320
            objPIDADrawing.CloseDrawing
321
        End If
322

    
323
    End Function
324

    
325

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

    
344
                End If
345
            End If
346
        Next
347

    
348
        Return sValue
349
    End Function
350

    
351
    Private Function GetAttributeMapping(ByVal sAttributeName As String, ByVal sColumn As String) As String
352
        Dim sSPPIDAttribute As String = ""
353
        If _Attribute_DB.Rows.Count > 0 Then
354
            Dim oSelectRow() As DataRow = _Attribute_DB.Select("[pid_attribute] = '" + sAttributeName + "'")
355
            If oSelectRow.Length = 1 Then
356
                sSPPIDAttribute = oSelectRow(0).Item(sColumn).ToString()
357
            End If
358
        End If
359
        Return sSPPIDAttribute
360
    End Function
361

    
362
    '  Dim _TempSymbolDt As DataTable = Symbol_Dt()
363

    
364

    
365
    Private Function LoadSymbolInXml(ByVal sXmlPath As String) As Drawing
366
        Try
367
            ''  _TempSymbolDt = Symbol_Dt()
368
            Dim CDrawing As Drawing = New Drawing()
369
            Dim oDt As DataTable = LoadSymbol_DT()
370
            Dim oElement As XElement = XElement.Load(sXmlPath)
371

    
372
            If oElement IsNot Nothing Then
373
                CDrawing.DwgName = oElement.Element(_XML_DWGNAME).Value
374
                CDrawing.Size = oElement.Element(_XML_DWGSIZE).Value
375
                SplitLocation(CDrawing.Size, _IMG_X, _IMG_Y)
376
                CDrawing.Unit = oElement.Element(_XML_UNIT).Value
377

    
378
                Dim oLineno_list As New List(Of Line_no)
379
                Dim oEqp_list As New List(Of Eqp_no)
380
                Dim oTrim_Lineno_list As New List(Of Line_no)
381
                oLineno_list = LoadLineNo(oElement, _XML_CATEGORY_LINENO)
382
                For Each oEqpNo As Object In oElement.Elements(_XML_CATEGORY_EQUIPMENT)
383
                    Dim CEqp_no As Eqp_no = New Eqp_no()
384
                    Dim oSymbol_Dt As DataTable = Symbol_Dt()
385
                    Dim oAttribute_Dt As DataTable = Attribute_Dt()
386
                    Dim sUid As String
387
                    For Each oSymbol As Object In oEqpNo.Elements(_XML_CATEGORY_SYMBOL)
388
                        Try
389
                            Dim  oAddrow As DataRow = oSymbol_Dt.NewRow()
390
                            Dim oEleObj As XElement
391
                            Dim sName As String
392
                            Dim sLocation As String
393
                            Dim sSize As String
394
                            Dim sAngle As String
395
                            Dim   sOriginalPoint As String = ""
396
                            Dim sConnectionPoint As String = ""
397
                            oEleObj = oSymbol.Element(_XML_SYMBOL_UID)
398
                            sUid = oEleObj.Value
399
                            oEleObj = oSymbol.Element(_XML_SYMBOL_NAME)
400
                            sName = oEleObj.Value
401
                            oEleObj = oSymbol.Element(_XML_SYMBOL_LOCATION)
402
                            sLocation = oEleObj.Value
403
                            oEleObj = oSymbol.Element(_XML_SYMBOL_SIZE)
404
                            sSize = oEleObj.Value
405
                            oEleObj = oSymbol.Element(_XML_SYMBOL_ANGLE)
406
                            sAngle = oEleObj.Value
407
                            oEleObj = oSymbol.Element(_XML_SYMBOL_CONNECTIONPOINT)
408
                            sConnectionPoint = oEleObj.Value
409
                            Try
410
                                oEleObj = oSymbol.Element(_XML_SYMBOL_ORIGINALPOINT)
411
                                sOriginalPoint = oEleObj.Value
412
                            Catch ex As Exception
413
                            End Try
414
                            oAddrow(_XML_SYMBOL_UID) = sUid
415
                            oAddrow(_XML_SYMBOL_NAME) = sName
416
                            oAddrow(_XML_SYMBOL_LOCATION) = sLocation
417
                            oAddrow(_XML_SYMBOL_SIZE) = sSize
418
                            oAddrow(_XML_SYMBOL_ANGLE) = sAngle
419
                            oAddrow(_XML_SYMBOL_SYSTEMPATH) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
420
                            oAddrow(_XML_SYMBOL_TYPE) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_COMPTPYE)
421
                            oAddrow(_XML_SYMBOL_ORIGINALPOINT) = sOriginalPoint
422
                            oAddrow(_XML_SYMBOL_CONNECTIONPOINT) = sConnectionPoint
423
                            oAddrow(_XML_SYMBOL_DRAWING_TF) = "FALSE"
424
                            oSymbol_Dt.Rows.Add(oAddrow)
425
                        Catch ex As Exception
426

    
427
                        End Try
428
                    Next
429
                    For Each oAtrribute As Object In oEqpNo.Elements(_XML_CATEGORY_ATTRIBUTE)
430
                        Try
431
                            Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
432
                            Dim oEleObj As XElement
433
                            Dim sAttUid As String
434
                            Dim sName As String
435
                            Dim sValue As String
436
                            oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
437
                            sAttUid = oEleObj.Value
438
                            oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
439
                            sName = oEleObj.Value
440
                            oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
441
                            sValue = oEleObj.Value
442
                            oAddrow(_XML_ATTRIBUTE_UID) = sAttUid
443
                            oAddrow(_XML_ATTRIBUTE_NAME) = sName
444
                            oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
445
                            oAttribute_Dt.Rows.Add(oAddrow)
446
                        Catch ex As Exception
447
                        End Try
448
                    Next
449
                    CEqp_no.Uid = sUid
450
                    CEqp_no.Dt_Equipment = oSymbol_Dt
451
                    CEqp_no.Dt_Attribute = oAttribute_Dt
452
                    oEqp_list.Add(CEqp_no)
453
                Next
454
                oTrim_Lineno_list = LoadLineNo(oElement, _XML_CATEGORY_TRIM_LINENO)
455
                CDrawing.Line_nos = oLineno_list
456
                CDrawing.Eqp_nos = oEqp_list
457
                CDrawing.TrimLine_nos = oTrim_Lineno_list
458

    
459
            End If
460
            Return CDrawing
461
        Catch ex As Exception
462
            Return Nothing
463
        End Try
464

    
465
    End Function
466

    
467

    
468
    Private Function LoadLineNo(ByVal oElement As XElement, ByVal sLineType As String) As List(Of Line_no)
469

    
470
        Dim oLineno_list As New List(Of Line_no)
471

    
472
        For Each oLineNo As Object In oElement.Elements(sLineType)
473

    
474
            Dim CLineNo As Line_no = New Line_no()
475
            Try
476
                CLineNo.Uid = oLineNo.Element(_XML_LINENO_UID).Value
477
                CLineNo.Text = oLineNo.Element(_XML_LINENO_TEXT).Value
478
                CLineNo.Location = oLineNo.Element(_XML_LINENO_LOCATION).Value
479
                CLineNo.Angle = oLineNo.Element(_XML_LINENO_ANGLE).Value
480
                CLineNo.SystemPath = "\Piping\Labels - Piping Segments\Kemya Line Number.sym" 'GetDataFromMappingDB(_XML_CATEGORY_LINENO, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
481
            Catch ex As Exception
482
                'CLineNo.Text = "PipeLineNo"
483
                'CLineNo.Uid = "PipeLineNo"
484
            End Try
485

    
486

    
487
            Dim oLine_Dt As DataTable = Line_Dt()
488
            Dim oSymbol_Dt As DataTable = Symbol_Dt()
489
            Dim oAttribute_Dt As DataTable = Attribute_Dt()
490

    
491
            For Each oRun As Object In oLineNo.Elements(_XML_CATEGORY_RUN)
492
                For Each oLine As Object In oRun.Elements(_XML_CATEGORY_LINE)
493
                    Try
494
                        Dim oAddrow As DataRow = oLine_Dt.NewRow()
495
                        Dim oEleObj As XElement
496
                        Dim sUid As String
497
                        Dim sStartpoint As String
498
                        Dim sEndpoint As String
499
                        Dim sType As String
500
                        oEleObj = oLine.Element(_XML_LINE_UID)
501
                        sUid = oEleObj.Value
502
                        If oLine_Dt.Select(_XML_LINE_UID & "='" & sUid & "'").Length = 0 Then
503
                            oEleObj = oLine.Element(_XML_LINE_STARTPOINT)
504
                            sStartpoint = oEleObj.Value
505
                            oEleObj = oLine.Element(_XML_LINE_ENDPOINT)
506
                            sEndpoint = oEleObj.Value
507
                            oEleObj = oLine.Element(_XML_LINE_TYPE)
508
                            sType = oEleObj.Value
509
                            oAddrow(_XML_LINE_UID) = sUid
510
                            oAddrow(_XML_LINE_STARTPOINT) = sStartpoint
511
                            oAddrow(_XML_LINE_ENDPOINT) = sEndpoint
512
                            oAddrow(_XML_LINE_SYSTEMPATH) = GetDataFromMappingDB(_XML_CATEGORY_LINE, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
513
                            oAddrow(_XML_LINE_DRAWING_TF) = "FALSE"
514
                            oAddrow(_XML_LINE_TYPE) = sType
515
                            oLine_Dt.Rows.Add(oAddrow)
516
                        Else
517

    
518
                        End If
519

    
520
                    Catch ex As Exception
521

    
522
                    End Try
523

    
524
                Next
525

    
526
                For Each oSymbol As Object In oRun.Elements(_XML_CATEGORY_SYMBOL)
527
                    Try
528
                        Dim oAddrow As DataRow = oSymbol_Dt.NewRow()
529
                        Dim oEleObj As XElement
530
                        Dim sUid As String
531
                        Dim sName As String
532
                        Dim sLocation As String
533
                        Dim sSize As String
534
                        Dim sAngle As String
535
                        Dim sOriginalPoint As String = ""
536
                        Dim sConnectionPoint As String = ""
537
                        oEleObj = oSymbol.Element(_XML_SYMBOL_UID)
538
                        sUid = oEleObj.Value
539
                        oEleObj = oSymbol.Element(_XML_SYMBOL_PARENT)
540
                        sName = oEleObj.Value
541
                        oEleObj = oSymbol.Element(_XML_SYMBOL_LOCATION)
542
                        sLocation = oEleObj.Value
543
                        oEleObj = oSymbol.Element(_XML_SYMBOL_SIZE)
544
                        sSize = oEleObj.Value
545
                        oEleObj = oSymbol.Element(_XML_SYMBOL_ANGLE)
546
                        sAngle = oEleObj.Value
547
                        oEleObj = oSymbol.Element(_XML_SYMBOL_CONNECTIONPOINT)
548
                        sConnectionPoint = oEleObj.Value
549
                        Try
550
                            oEleObj = oSymbol.Element(_XML_SYMBOL_ORIGINALPOINT)
551
                            sOriginalPoint = oEleObj.Value
552
                        Catch ex As Exception
553

    
554
                        End Try
555

    
556
                        oAddrow(_XML_SYMBOL_UID) = sUid
557
                        oAddrow(_XML_SYMBOL_NAME) = IO.Path.GetFileNameWithoutExtension(GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYMBOLNAME))
558
                        oAddrow(_XML_SYMBOL_LOCATION) = sLocation
559
                        oAddrow(_XML_SYMBOL_SIZE) = sSize
560
                        oAddrow(_XML_SYMBOL_ANGLE) = sAngle
561
                        oAddrow(_XML_SYMBOL_SYSTEMPATH) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
562
                        oAddrow(_XML_SYMBOL_TYPE) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_COMPTPYE)
563
                        oAddrow(_XML_SYMBOL_CLASS) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_CLASS)
564
                        oAddrow(_XML_SYMBOL_ORIGINALPOINT) = sOriginalPoint
565
                        oAddrow(_XML_SYMBOL_CONNECTIONPOINT) = sConnectionPoint
566
                        oAddrow(_XML_SYMBOL_DRAWING_TF) = "FALSE"
567
                        oSymbol_Dt.Rows.Add(oAddrow)
568
                    Catch ex As Exception
569

    
570
                    End Try
571

    
572
                Next
573

    
574
                For Each oAtrribute As Object In oRun.Elements(_XML_CATEGORY_ATTRIBUTE)
575
                    Try
576
                        Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
577
                        Dim oEleObj As XElement
578
                        Dim sUid As String
579
                        Dim sName As String
580
                        Dim sValue As String
581

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

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

    
595
                    End Try
596

    
597
                Next
598

    
599
            Next
600
            'Line No Attribute
601
            For Each oAtrribute As Object In oLineNo.Elements(_XML_CATEGORY_ATTRIBUTE)
602
                Try
603
                    Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
604
                    Dim oEleObj As XElement
605
                    Dim sUid As String = ""
606
                    Dim sName As String
607
                    Dim sValue As String
608

    
609
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
610
                    sUid = oEleObj.Value
611
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
612
                    sName = oEleObj.Value
613
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
614
                    sValue = oEleObj.Value
615
                    oAddrow(_XML_ATTRIBUTE_UID) = sUid
616
                    oAddrow(_XML_ATTRIBUTE_NAME) = sName
617
                    oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
618
                    oAttribute_Dt.Rows.Add(oAddrow)
619
                Catch ex As Exception
620
                End Try
621
            Next
622
            CLineNo.Dt_Line = oLine_Dt
623
            CLineNo.Dt_Symbol = oSymbol_Dt
624
            CLineNo.Dt_Attribute = oAttribute_Dt
625
            oLineno_list.Add(CLineNo)
626
        Next
627
        Return oLineno_list
628
    End Function
629

    
630

    
631
    'Private Function LoadPipeInXml(ByVal sXmlPath As String) As DataTable
632
    '    Try
633
    '        Dim oDt As DataTable = LoadPipe_DT()
634
    '        Dim oElement As XElement = XElement.Load(sXmlPath)
635
    '        If oElement IsNot Nothing Then
636
    '            Dim DWGElement As XElement = oElement.Element("DWGNAME")
637
    '            Dim DWGNAME = DWGElement.Value
638
    '            Dim sXY As XElement = oElement.Element("SIZE")
639
    '            Dim sSize = sXY.Value
640
    '            Dim oSplitDWGPos As String() = sSize.Split(", ")
641

    
642
    '            If IsNumeric(oSplitDWGPos(0)) Then
643
    '                _IMG_X = Double.Parse(oSplitDWGPos(0))
644
    '            End If
645
    '            If IsNumeric(oSplitDWGPos(1)) Then
646
    '                _IMG_Y = Double.Parse(oSplitDWGPos(1))
647
    '            End If
648

    
649
    '            For Each pipes As Object In oElement.Elements("IMGLINES")
650
    '                For Each pipe As Object In pipes.Elements("IMGLINE")
651
    '                    Dim oAddrow As DataRow = oDt.NewRow()
652
    '                    Dim oObj As XElement = pipe.Element("ITEM")
653
    '                    Dim oItem = oObj.Value
654
    '                    ' Dim oSymbolPath As String = "\" + oSymbol + "\" + oClass + "\" + oType + "\" + oItem + ".sym"
655
    '                    Dim oSymbolPath As String = GetSystemPathFromMappingDB(oItem)
656
    '                    oObj = pipe.Element("START")
657
    '                    Dim oStartPoint = oObj.Value
658
    '                    Dim oSplitPos As String() = oStartPoint.Split(", ")
659
    '                    Dim oStartpos_X As Double = 0.0
660
    '                    Dim oStartpos_Y As Double = 0.0
661
    '                    If IsNumeric(oSplitPos(0)) Then
662
    '                        oStartpos_X = Double.Parse(oSplitPos(0))
663
    '                    End If
664
    '                    If IsNumeric(oSplitPos(1)) Then
665
    '                        oStartpos_Y = Double.Parse(oSplitPos(1))
666
    '                    End If
667

    
668
    '                    ConvertPoint(oStartpos_X, oStartpos_Y, _DWG_X, _DWG_Y)
669
    '                    oObj = pipe.Element("End")
670
    '                    Dim oEndPoint = oObj.Value
671
    '                    oSplitPos = oEndPoint.Split(", ")
672
    '                    Dim oEndpos_X As Double = 0.0
673
    '                    Dim oEndpos_Y As Double = 0.0
674
    '                    If IsNumeric(oSplitPos(0)) Then
675
    '                        oEndpos_X = Double.Parse(oSplitPos(0))
676
    '                    End If
677
    '                    If IsNumeric(oSplitPos(1)) Then
678
    '                        oEndpos_Y = Double.Parse(oSplitPos(1))
679
    '                    End If
680
    '                    ConvertPoint(oEndpos_X, oEndpos_Y, _DWG_X, _DWG_Y)
681

    
682
    '                    oAddrow("start_x") = oStartpos_X '+ 0.05
683
    '                    oAddrow("start_y") = oStartpos_Y
684
    '                    oAddrow("end_x") = oEndpos_X
685
    '                    oAddrow("end_y") = oEndpos_Y
686
    '                    oAddrow("SystemPath") = oSymbolPath
687
    '                    oDt.Rows.Add(oAddrow)
688
    '                Next
689
    '            Next
690

    
691
    '        End If
692

    
693

    
694
    '        Return oDt
695
    '    Catch ex As Exception
696
    '        Return Nothing
697
    '    End Try
698
    'End Function
699

    
700

    
701
    Private Sub ConvertPointByImage(ByRef dX As Double, ByRef dY As Double, ByVal dDwgX As Double, ByVal dDwgY As Double)
702

    
703
        Dim calcx As Double = 0
704
        Dim calcy As Double = 0
705
        calcx = (dX * _DWG_X) / dDwgX 'Math.Round((dX * _DWG_X) / dDwgX, 2)
706
        calcy = _DWG_Y - ((dY * _DWG_Y) / dDwgY) '_DWG_Y - Math.Round((dY * _DWG_Y) / dDwgY, 2)
707
        dX = calcx
708
        dY = calcy
709
    End Sub
710

    
711

    
712
    '@brief Convert To SPPID
713
    '@author : Gyusu Park
714
    '@date : 2018-04-10
715
    '@history:
716

    
717
    Private Sub SplitLocation(ByVal sLocation As String, ByRef dX As Double, ByRef dY As Double)
718

    
719
        Dim opointstr As String() = Split(sLocation, ",")
720
        If (opointstr.Length > 1) Then
721
            If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
722
                dX = opointstr(0)
723
                dY = opointstr(1)
724
            End If
725
        End If
726

    
727
    End Sub
728

    
729

    
730

    
731

    
732

    
733

    
734
    Private Function AutoConverting(ByVal oPipe_Dt As DataTable, ByVal oSymbol_Dt As DataTable, ByVal oTreeNode As TreeNode) As Boolean
735
        Dim iTotalCount As Double = oPipe_Dt.Rows.Count + oSymbol_Dt.Rows.Count
736
        Dim iSymbolcount As Double = 0
737

    
738
        Dim lobjDatasource As Object = _Placement.PIDDataSource
739

    
740
        ' lobjDatasource.BeginTransaction()
741
        '  datasource = objPlacement.PIDDataSource
742
        'Dim iPipecnt As Integer = 0
743
        SetListBoxItems(ListBox_Result, " Auto converting 시작....")
744

    
745
        Dim iPipeCnt As Integer = 0
746
        If oPipe_Dt IsNot Nothing Then
747
            For Each oRow As DataRow In oPipe_Dt.Rows
748
                Dim oposition As String = oRow("position").ToString()
749
                Dim oSymbol As String = oRow("SystemPath").ToString()
750

    
751
                Dim objConnector As LMConnector
752
                Dim objInputs As PlaceRunInputs
753
                objInputs = New PlaceRunInputs
754
                Dim oSplitStr As String() = Split(oposition, " ")
755
                For Each sposition As String In oSplitStr
756
                    Dim opointstr As String() = Split(sposition, ", ")
757

    
758
                    If (opointstr.Length > 1) Then
759
                        If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
760
                            Dim ox As Double = opointstr(0)
761
                            Dim oy As Double = opointstr(1)
762
                            ConvertPointByImage(ox, oy, _IMG_X, _IMG_Y)
763
                            objInputs.AddPoint(ox, oy)
764
                        End If
765
                    End If
766
                Next
767
                Dim objItem As LMAItem
768
                objItem = _Placement.PIDCreateItem(oSymbol)
769
                objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
770
                SetListBoxItems(ListBox_Result, " Place PipeLine...." & "(" & (iPipeCnt + 1) & "/" & oPipe_Dt.Rows.Count)
771
                'Dim objPipeRun As LMPipeRun = datasource.GetPipeRun(objConnector.ModelItemID)
772
                'objPipeRun.Attributes("OperFluidCode").Value = "AFS"
773
                'objPipeRun.Commit()
774
                iSymbolcount = iSymbolcount + 1
775
                iPipeCnt = iPipeCnt + 1
776
            Next
777
        End If
778

    
779
        SetListBoxItems(ListBox_Result, " Place PipeLine....완료")
780

    
781
        Dim iAllInstrumentCnt As Integer = oSymbol_Dt.Select("Name = 'INSTRUMENTATION'").Length
782
                    Dim iValveCnt As Integer = oSymbol_Dt.Select("Class = 'VALVES'").Length
783
        Dim iInstrumentCnt As Integer = 1
784
        Dim iFittingsCnt As Integer = 1
785

    
786
        Dim oInsNode As TreeNode = oTreeNode.Nodes.Find(oTreeNode.Name & "\Instruments", True)(0)
787
        Dim oValveNode As TreeNode = oTreeNode.Nodes.Find(oTreeNode.Name & "\Valves", True)(0)
788
        Dim oFittingsNode As TreeNode = oTreeNode.Nodes.Find(oTreeNode.Name & "\Fittings", True)(0)
789
        For Each oRow As DataRow In oSymbol_Dt.Rows
790

    
791
            Try
792

    
793
                Dim sSystemPath As String = oRow("SystemPath").ToString()
794
                Dim sName As String = oRow("Name").ToString()
795
                Dim sType As String = oRow("Type").ToString()
796
                Dim sText As String = oRow("Text").ToString()
797
                Dim sClass As String = oRow("Class").ToString()
798
                Dim sItem As String = oRow("Item").ToString()
799

    
800
                Dim oX As Double = 0.0
801
                Dim oY As Double = 0.0
802
                If IsNumeric(oRow("x").ToString()) Then
803
                    oX = Double.Parse(oRow("x").ToString())
804
                End If
805
                If IsNumeric(oRow("y").ToString()) Then
806
                    oY = Double.Parse(oRow("y").ToString())
807
                End If
808
                Dim oAngle As Double = 0.0
809
                If IsNumeric(oRow("Angle").ToString()) Then
810
                    oAngle = Double.Parse(oRow("Angle").ToString())
811
                End If
812
                '   oSymbol = "\INSTRUMENTation\SYSTEM FUNCTIONS\D C S\DCS FUNC ACCESS IN PRIME LOC.sym"
813
                If sSystemPath <> "" Then
814
                    If sName = _TYPE_Instumentation Then
815

    
816
                        Dim sTagsuffix As String = ""
817
                        Dim sTagSequenceNo As String = ""
818
                        Dim sMeasuredVariableCode As String = ""
819
                        Dim sInstrumentTypeModifier As String = ""
820

    
821
                        If sText <> "" Then
822
                            If sText.Contains(",") Then
823
                                Dim splitstr() As String = sText.Split(",")
824
                                For i = 0 To splitstr.Count - 1
825
                                    If i = 0 Then
826
                                        sMeasuredVariableCode = Mid(splitstr(i), 1, 1)
827
                                        sTagSequenceNo = Mid(splitstr(i), 2, Len(splitstr(i)))
828
                                    Else
829
                                        If Len(splitstr(i)) = 1 Then
830
                                            sInstrumentTypeModifier = splitstr(i)
831
                                        ElseIf Len(splitstr(i)) = 0 Then
832

    
833
                                        ElseIf Len(splitstr(i)) > 1 Then
834
                                            sInstrumentTypeModifier = Mid(splitstr(i), 1, 1)
835
                                            sTagsuffix = Mid(splitstr(i), 2, Len(splitstr(i)))
836
                                        End If
837
                                    End If
838
                                Next
839
                            Else
840
                                sMeasuredVariableCode = Mid(sText, 1, 1)
841
                                sTagSequenceNo = Mid(sText, 2, Len(sText))
842
                            End If
843

    
844
                        End If
845

    
846
                        Dim objInstrSym As LMSymbol
847
                        objInstrSym = _Placement.PIDPlaceSymbol(sSystemPath, oX, oY, , oAngle)
848
                        SetListBoxItems(ListBox_Result, " Place Instrument...." & "(" & (iInstrumentCnt + 1) & "/" & iAllInstrumentCnt & ")")
849

    
850
                        ' SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sTagSequenceNo)
851
                        Dim action As Action = Sub()
852
                                                   oInsNode.Nodes.Add(sClass & "-" & iInstrumentCnt)
853
                                                   oInsNode.ExpandAll()
854
                                               End Sub
855
                        oInsNode.TreeView.Invoke(action)
856

    
857

    
858
                        Dim objInstr As LMInstrument
859
                        objInstr = lobjDatasource.GetInstrument(objInstrSym.ModelItemID)
860

    
861
                        Dim objItem As LMAItem
862
                        objItem = _Placement.PIDCreateItem(sSystemPath)
863

    
864

    
865
                        objInstr.Attributes("MeasuredVariableCode").Value = sMeasuredVariableCode
866
                        objInstr.Attributes("InstrumentTypeModifier").Value = sInstrumentTypeModifier
867
                        objInstr.Attributes("TagSuffix").Value = sTagsuffix
868
                        objInstr.Attributes("TagSequenceNo").Value = sTagSequenceNo
869
                        objInstr.Commit()
870
                        iInstrumentCnt = iInstrumentCnt + 1
871
                    ElseIf sName = "GATE VALVE WITH PLUG" Then
872

    
873
                    ElseIf sName = "MEDIUM 1D 1TO1" Then
874

    
875
                    ElseIf sClass = "VALVES" Then
876
                        Dim action As Action = Sub()
877
                                                   oValveNode.ExpandAll()
878
                                                   oValveNode.Nodes.Add(sClass & "-" & iValveCnt)
879
                                               End Sub
880
                        oValveNode.TreeView.Invoke(action)
881

    
882
                        _Placement.PIDPlaceSymbol(sSystemPath, oX, oY, , oAngle)
883

    
884
                        iValveCnt = iValveCnt + 1
885
                    Else
886
                        Dim action As Action = Sub()
887
                                                   oFittingsNode.ExpandAll()
888
                                                   oFittingsNode.Nodes.Add(sClass & "-" & iFittingsCnt)
889
                                               End Sub
890
                        oFittingsNode.TreeView.Invoke(action)
891
                        _Placement.PIDPlaceSymbol(sSystemPath, oX, oY, , oAngle)
892

    
893
                        iFittingsCnt = iFittingsCnt + 1
894

    
895
                    End If
896
                    iSymbolcount = iSymbolcount + 1
897
                Else
898
                End If
899
            Catch ex As Exception
900

    
901
            End Try
902
            Dim dCalcProgressValue As Double = (iSymbolcount / iTotalCount) * 100
903
            SetProgressbar(ProgressBar_Status, dCalcProgressValue)
904
            '     ProgressBar_Status.Value = (iSymbolcount / iTotalCount) * 100
905

    
906
        Next
907

    
908
        MsgBox("Complete AutoConverting")
909
        SetListBoxItems(ListBox_Result, "Place Instrument....변환완료")
910
        SetListBoxItems(ListBox_Result, "총 symbol:  " & iSymbolcount & "개 변환완료")
911
        SetProgressbar(ProgressBar_Status, 100)
912

    
913
        ' MsgBox("symbol: " & iSymbolcount & "개, pipe : " & iPipecnt & "개 변환완료")
914
    End Function
915

    
916

    
917
    Private Sub Tree_XMLFiles_AfterCheck(sender As Object, e As TreeViewEventArgs)
918
        If e.Node.Checked = True Then
919
            For Each oNode As TreeNode In e.Node.Nodes
920
                oNode.Checked = True
921
            Next
922
        Else
923
            For Each oNode As TreeNode In e.Node.Nodes
924
                oNode.Checked = False
925
            Next
926
        End If
927
    End Sub
928

    
929
    Private Function Load_DB(ByVal sDBPath As String, ByVal sTableName As String) As DataTable
930

    
931
        Try
932
            Dim oDt As New DataTable
933
            Dim sConnectionstring As String = "Data Source=" & sDBPath & ";Version=3;Synchronous=Off;UTF8Encoding=True;"
934
            Dim conn As SQLiteConnection = New SQLiteConnection(sConnectionstring)
935
            conn.Open()
936
            Dim sQuery As String = "Select * from " & sTableName
937
            Dim cmd As SQLiteCommand = conn.CreateCommand()
938
            Dim adapter As SQLiteDataAdapter = New SQLiteDataAdapter(sQuery, conn)
939
            Dim oDataSet As DataSet = New DataSet()
940
            adapter.Fill(oDataSet)
941
            oDt = oDataSet.Tables(0)
942
            Return oDt
943
        Catch ex As Exception
944
            Return Nothing
945
        End Try
946

    
947

    
948
    End Function
949

    
950
    Private Sub Load_AttributeDB(ByVal sDBPath As String)
951

    
952
        Try
953
            Dim sConnectionstring As String = "Data Source=" & sDBPath & ";Version=3;Synchronous=Off;UTF8Encoding=True;"
954
            Dim conn As SQLiteConnection = New SQLiteConnection(sConnectionstring)
955
            conn.Open()
956
            Dim sQuery As String = "Select * from Attribute"
957
            Dim cmd As SQLiteCommand = conn.CreateCommand()
958
            Dim adapter As SQLiteDataAdapter = New SQLiteDataAdapter(sQuery, conn)
959
            Dim oDataSet As DataSet = New DataSet()
960
            adapter.Fill(oDataSet)
961
            _Attribute_DB = oDataSet.Tables(0)
962
        Catch ex As Exception
963

    
964
        End Try
965

    
966

    
967
    End Sub
968

    
969
    'Private Sub Tree_XMLFiles_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles Tree_XMLFiles.AfterSelect
970
    '    If first_start = False Then Exit Sub
971
    '    Dim pa = e.Node.FullPath.ToString
972

    
973
    '    printfilesfolders_here(pa, e.Node)
974

    
975
    '    displayfiles(pa)
976

    
977
    '    Dim coco As String = ""
978
    '    coco = pa.ToString
979
    '    coco = coco.Replace("\\", "\")
980
    '    Me.Text = coco
981
    '    folders_path = coco
982
    'End Sub
983

    
984
    Sub printfilesfolders_here(ByVal path As String, ByRef itree As TreeNode)
985

    
986
        Dim foldername As String
987
        Dim filename As String
988
        itree.Nodes.Clear()
989
        On Error GoTo eee
990
        For Each foldername In Directory.GetDirectories(path)
991
            On Error GoTo eee
992
            Dim jj = foldername.LastIndexOf("\")
993
            Dim jj1 = foldername.Length - jj
994
            Dim foldr = foldername.Substring((jj + 1), (jj1 - 1))
995
            itree.Nodes.Add(foldr, foldr)
996
        Next ' if you put this next at the end of procedure recursive will be done on first folder only
997
        Exit Sub
998
eee:
999
    End Sub
1000

    
1001

    
1002

    
1003
    '    Private Sub Tree_XMLFiles_MouseMove(sender As Object, e As MouseEventArgs) Handles Tree_XMLFiles.MouseMove
1004
    '        first_start = True
1005
    '    End Sub
1006

    
1007
    '    Private Sub ListView_File_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView_File.SelectedIndexChanged
1008
    '        Dim indexes As ListView.SelectedIndexCollection =
1009
    '                         Me.ListView_File.SelectedIndices
1010
    '        Dim index As Integer
1011

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

    
1021
    '            Dim infoReader As System.IO.FileInfo
1022
    '            infoReader = My.Computer.FileSystem.GetFileInfo(Me.Status_Main.Items(0).Text)
1023
    '            Me.Status_Main.Items(1).Text = " Created : " + infoReader.CreationTime.ToString + " " + infoReader.Attributes.ToString
1024
    '        Next
1025
    '    End Sub
1026

    
1027
    '    Private Sub Procees()
1028
    '        Dim indexes As ListView.SelectedIndexCollection =
1029
    '                            Me.ListView_File.SelectedIndices
1030
    '        Dim index As Integer
1031

    
1032
    '        For Each index In indexes
1033
    '            'On Error Resume Next
1034
    '            If folders_path.EndsWith("\") = True Then
1035
    '                On Error GoTo out
1036
    '                Me.Status_Main.Items(0).Text = folders_path + (Me.ListView_File.Items(index).Text)
1037
    '                On Error GoTo out
1038
    '                'On Error Resume Next
1039
    '            Else
1040
    '                Me.Status_Main.Items(0).Text = folders_path + "\" + (Me.ListView_File.Items(index).Text)
1041
    '                On Error GoTo out
1042
    '            End If
1043

    
1044
    '            Dim infoReader As System.IO.FileInfo
1045
    '            infoReader = My.Computer.FileSystem.GetFileInfo(Me.Status_Main.Items(0).Text)
1046
    '            Me.Status_Main.Items(1).Text = " Created : " + infoReader.CreationTime.ToString + " " + infoReader.Attributes.ToString
1047
    '            On Error GoTo out
1048
    '            MsgBox(Me.Status_Main.Items(0).Text + " is processed")
1049
    '            On Error GoTo out
1050
    '        Next
1051
    '        Exit Sub
1052
    'out:
1053
    '        MsgBox(Err.Description)
1054
    'End Sub
1055

    
1056
    Private Function LoadAllDrawing() As DataTable
1057

    
1058

    
1059
        SetListBoxItems(ListBox_Result, "도면정보 로드중....")
1060

    
1061
        Dim oDt As DataTable = Drawing_Dt()
1062
        Dim sHierarchy As String = My.Settings.Plant_Hierarchy
1063

    
1064

    
1065
        Dim files() As String
1066
        files = Directory.GetFiles(sHierarchy, "*.pid", SearchOption.AllDirectories)
1067
        For Each FileName As String In files
1068
            Dim sName As String = FileName
1069
            Dim oAddRow As DataRow = oDt.NewRow()
1070
            oAddRow("Name") = Path.GetFileNameWithoutExtension(sName)
1071
            oAddRow("Path") = FileName
1072
            oDt.Rows.Add(oAddRow)
1073
        Next
1074
        Return oDt
1075
    End Function
1076

    
1077
    Private Function LoadAllDrawing2() As DataTable
1078
        Dim datasource As LMADataSource
1079
        Dim objPIDAutoApp As Object
1080
        Dim objPIDADrawing As Object
1081
        Dim objDrawing As Object 'Drawing
1082
        'Dim objDrawing As LMDrawing
1083
        'Dim objDrawings As LMDrawings
1084

    
1085
        datasource = New LMADataSource
1086

    
1087
        '    objDrawings = New LMDrawings
1088
        'objDrawings.Collect(datasource)
1089
        objPIDAutoApp = CreateObject("PIDAutomation.Application")
1090

    
1091
        For Each objDrawing In objPIDAutoApp.Drawings
1092
            objDrawing.CloseDrawing(True)
1093
        Next
1094
        Try
1095
            objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("UY1-K-2000_P1_300dpi_0321_TEST_1")
1096
        Catch ex As Exception
1097
            Process.Start("\\desktop-9vlq0dp\Test02Site\P188943_SPPID_Plant\Plant_Hierarchy\8121\8121-1\UY1-K-2000_P1_300dpi_0321_TEST_1.pid")
1098
        End Try
1099

    
1100

    
1101

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

    
1106
        objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("1")
1107

    
1108
        For Each objDrawing In objPIDAutoApp.Drawings
1109
            If objDrawing.Attributes("ItemStatus").Index = 1 Then '1 stands for Active
1110
                Try
1111

    
1112
                    Dim sName As String = objDrawing.Attributes("Name").Value
1113

    
1114
                    iCount = iCount + 1
1115
                    If sName = "UY1-K-2000_P1_300dpi_0321_TEST_1" Then
1116
                        objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing(objDrawing.Attributes("Name"))
1117
                        objPIDADrawing = objPIDAutoApp.Drawings.OpenDrawing("\8121\8121-1\UY1-K-2000_P1_300dpi_0321_TEST_1.pid")
1118
                        If Not objPIDADrawing Is Nothing Then
1119
                            objPIDADrawing.CloseDrawing()
1120
                        End If
1121
                    End If
1122

    
1123

    
1124
                Catch ex As Exception
1125

    
1126
                End Try
1127

    
1128
            End If
1129
        Next
1130
        objPIDAutoApp.Quit
1131
        objPIDAutoApp = Nothing
1132
        objPIDADrawing = Nothing
1133
        objDrawing = Nothing
1134
        '   objDrawings = Nothing
1135
    End Function
1136

    
1137
    Dim _XMLList As ListView = New ListView()
1138

    
1139

    
1140

    
1141

    
1142

    
1143

    
1144
    Private Function CheckOpenDrawing() As Boolean
1145
        Try
1146

    
1147
            Dim lobjDatasource As Object
1148
            _Placement = CreateObject("Plaice.Placement", "")
1149
            lobjDatasource = _Placement.PIDDataSource
1150
            Return True
1151
        Catch ex As Exception
1152
            Return False
1153
        End Try
1154

    
1155
    End Function
1156

    
1157

    
1158
    Private Sub Btn_Convert_Click(sender As Object, e As EventArgs) Handles Btn_Convert.Click
1159

    
1160
        Main_Tab.SelectedIndex = 1
1161
        ListBox_Result.Items.Clear()
1162
        ' DataGrid_Result.DataSource = New DataTable()
1163
        Me.ProgressBar_Status.Visible = True
1164
        ProgressBar_Status.Maximum = 100
1165
        ProgressBar_Status.Value = 0
1166
        ' _selectFolderPath = Tree_XMLFiles.SelectedNode.FullPath.Replace("\\", "\")
1167
        _Main_trd = New Thread(AddressOf ThreadConvert)
1168
        _Main_trd.IsBackground = True
1169
        _Main_trd.Start()
1170
        FineOPCForm()
1171
    End Sub
1172

    
1173
    Private Sub FineOPCForm()
1174
        _Opc_trd = New Thread(AddressOf ThreadOPCRemove)
1175
        _Opc_trd.IsBackground = True
1176
        _Opc_trd.Start()
1177
    End Sub
1178

    
1179
    'Private Sub ThreadTask()
1180

    
1181

    
1182
    '    If _XMLList.Items.Count > 0 Then
1183

    
1184
    '        Dim oDwg_Dt As DataTable = LoadAllDrawing()
1185
    '        Dim iDwgCnt As Integer = 0
1186
    '        Dim objPIDAutoApp As Object
1187
    '        objPIDAutoApp = CreateObject("PIDAutomation.Application")
1188

    
1189

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

    
1193
    '            Dim sDwgName As String = Path.GetFileNameWithoutExtension(myList(i))
1194
    '            Txt_Status.Text = sDwgName & "..(" & i + 1 & "/" & myList.Count & ")"
1195
    '            SetListBoxItems(ListBox_Result, Txt_Status.Text & " 처리중....")
1196
    '            Dim sDwgNo As String = myList(i)
1197
    '            Dim oDwgPath As String = ""
1198
    '            oDwgPath = _selectFolderPath + "\" + sDwgNo
1199

    
1200
    '            Dim sPath As String = OpenDrawing(oDwg_Dt, sDwgName)
1201
    '            If sPath <> "" Then
1202

    
1203
    '                Process.Start(sPath)
1204

    
1205
    '                Dim bCheckOpenDrawing As Boolean = False
1206
    '                While (True)
1207
    '                    bCheckOpenDrawing = CheckOpenDrawing()
1208
    '                    If bCheckOpenDrawing = True Then
1209
    '                        Exit While
1210
    '                    Else
1211
    '                        Thread.Sleep(2000)
1212
    '                    End If
1213
    '                End While
1214

    
1215
    '                If bCheckOpenDrawing Then
1216
    '                    SetListBoxItems(ListBox_Result, sDwgName & " 도면 Open....")
1217
    '                    Dim oPipe_Dt As DataTable = New DataTable() 'LoadPipeInXml(oDwgPath)
1218

    
1219
    '                    Dim oSymbol_Dt As DataTable = LoadSymbolInXml(oDwgPath)
1220
    '                    Dim oTreeNode As New TreeNode  'SetTreeViewItems(Tree_Result, Tree_Result.Nodes, sDwgName, sDwgName)
1221
    '                    'oTreeNode = Tree_Result.Nodes.Find(sDwgName, True)(0)
1222
    '                    Dim action As Action = Sub()
1223
    '                                               oTreeNode = Tree_Result.Nodes.Add(sDwgName, sDwgName)
1224
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Instruments", "Instuments")
1225
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Pipes", "Pipes")
1226
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Valves", "Valves")
1227
    '                                               SetTreeViewItems(Tree_Result, oTreeNode.Nodes, sDwgName & "\Fittings", "Fittings")
1228
    '                                               oTreeNode.ExpandAll()
1229
    '                                           End Sub
1230
    '                    Tree_Result.Invoke(action)
1231

    
1232

    
1233
    '                    '    oTreeNode.Expand()
1234
    '                    SetListBoxItems(ListBox_Result, sDwgName & " Auto converting 대기....")
1235
    '                    AutoConverting(oPipe_Dt, oSymbol_Dt, oTreeNode)
1236

    
1237
    '                End If
1238

    
1239
    '            End If
1240
    '            ''도면 생성
1241
    '            'If CreateDwg(sDwgName) Then
1242
    '            '    'AutoConverting
1243

    
1244
    '            'End If
1245

    
1246
    '        Next
1247
    '    End If
1248
    'End Sub
1249

    
1250
    Dim _objPIDAutoApp As Object
1251

    
1252
    Private Function OpenSPPID(ByVal oDwg_Dt As DataTable, ByVal sDwgName As String) As Boolean
1253
        Dim bCheckOpen As Boolean = False
1254
        '   Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgPath)
1255
        SetListBoxItems(ListBox_Result, sDwgName & " 도면 Open....")
1256
        _objPIDAutoApp = CreateObject("PIDAutomation.Application")
1257

    
1258
        Dim sPath As String = OpenDrawing(oDwg_Dt, sDwgName)
1259
        If sPath <> "" Then
1260
            Process.Start(sPath)
1261
        Else
1262
            Return bCheckOpen
1263
        End If
1264

    
1265
            Dim bCheckOpenDrawing As Boolean = False
1266
            While (True)
1267
                bCheckOpenDrawing = CheckOpenDrawing()
1268
                If bCheckOpenDrawing = True Then
1269
                    bCheckOpen = True
1270
                    Exit While
1271
                Else
1272
                    Thread.Sleep(2000)
1273
                End If
1274
            End While
1275

    
1276

    
1277
            Return bCheckOpen
1278
    End Function
1279

    
1280
    Private Function GetDrawing(ByVal sDwgName As String) As Drawing
1281
        For Each CDrawing In _DrawingsList
1282
            If CDrawing.DwgName.ToUpper() = sDwgName.ToUpper() Then
1283
                Return CDrawing
1284
            End If
1285
        Next
1286
        Return Nothing
1287
    End Function
1288

    
1289
    Private Function GetLineNo(ByVal CDrawing As Drawing, ByVal sLineNoUid As String) As Line_no
1290
        For Each CLineNo In CDrawing.Line_nos
1291
            If CLineNo.Uid = sLineNoUid Then
1292
                Return CLineNo
1293
            End If
1294
        Next
1295
        Return Nothing
1296
    End Function
1297

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

    
1307

    
1308

    
1309
    Private Function GetPipeFromConnection(ByVal CDrawing As Drawing, ByVal sSymbolUid As String, ByRef sConnTypeNo As String) As DataTable
1310
        For Each CLineNo In CDrawing.Line_nos
1311
            Dim odt As DataTable = CLineNo.Dt_Line
1312
            If odt.Rows.Count > 0 Then
1313
                If odt.Rows(0)(_XML_LINE_Conn1_Uid).ToString = sSymbolUid Then
1314
                    sConnTypeNo = "1"
1315
                    Return odt
1316
                ElseIf odt.Rows(0)(_XML_LINE_Conn2_Uid).ToString() = sSymbolUid Then
1317
                    sConnTypeNo = "2"
1318
                    Return odt
1319
                End If
1320
            End If
1321
        Next
1322
        Return New DataTable
1323
    End Function
1324

    
1325
    Private Function GetSymbolFromConnection(ByVal CDrawing As Drawing, ByVal sSymbolUid As String, ByRef sConnTypeNo As String) As DataTable
1326
        For Each CLineNo In CDrawing.Line_nos
1327
            Dim odt As DataTable = CLineNo.Dt_Symbol
1328
            If odt.Rows.Count > 0 Then
1329
                If odt.Rows(0)(_XML_SYMBOL_Conn1_Uid).ToString = sSymbolUid Then
1330
                    sConnTypeNo = "1"
1331
                    Return odt
1332
                ElseIf odt.Rows(0)(_XML_SYMBOL_Conn2_Uid).ToString() = sSymbolUid Then
1333
                    sConnTypeNo = "2"
1334
                    Return odt
1335
                ElseIf odt.Rows(0)(_XML_SYMBOL_Conn3_Uid).ToString() = sSymbolUid Then
1336
                    sConnTypeNo = "3"
1337
                    Return odt
1338
                ElseIf odt.Rows(0)(_XML_SYMBOL_Conn4_Uid).ToString() = sSymbolUid Then
1339
                    sConnTypeNo = "4"
1340
                    Return odt
1341
                End If
1342
            End If
1343
        Next
1344
        Return New DataTable
1345
    End Function
1346

    
1347
    Private Function GetEqpNo(ByVal CDrawing As Drawing, ByVal sEqpUid As String) As Eqp_no
1348
        For Each CEqpNo In CDrawing.Eqp_nos
1349
            If CEqpNo.Uid = sEqpUid Then
1350
                Return CEqpNo
1351
            End If
1352
        Next
1353
        Return Nothing
1354
    End Function
1355
    Private Function ConvertPointBystring(ByVal sPoint As String, ByRef dX As Double, ByRef dY As Double) As Boolean
1356
        Try
1357
            Dim opointstr As String() = Split(sPoint, ",")
1358
            If (opointstr.Length > 1) Then
1359
                If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
1360
                    dX = opointstr(0)
1361
                    dY = opointstr(1)
1362

    
1363
                Else
1364
                    dX = 0
1365
                    dY = 0
1366
                    Return False
1367
                End If
1368
            End If
1369
            Return True
1370
        Catch ex As Exception
1371
            Return False
1372
        End Try
1373
    End Function
1374

    
1375

    
1376
    Dim _DrawLine_Dt As DataTable = DrawLind_Dt()
1377

    
1378
    Private Function DrawLine(ByVal sUid As String, ByVal sLineNoUid As String, ByVal oLine_Dt As DataTable,
1379
                              ByVal oAttribute_Dt As DataTable, ByRef oPiperun_Dt As DataTable) As LMPipeRun
1380
        Try
1381
            Dim oPipeRun As LMPipeRun = Nothing
1382
            Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_UID & " = '" + sUid + "'")
1383
            Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
1384

    
1385
            If oPipeRow.Length > 0 Then
1386
                Dim oDatasource As Object = _Placement.PIDDataSource
1387
                Dim objItem As LMAItem
1388
                Dim objConnector As LMConnector
1389
                Dim objInputs As PlaceRunInputs
1390
                objInputs = New PlaceRunInputs
1391
                Dim dOriginalStart_x As Double = 0.0
1392
                Dim dOriginalStart_y As Double = 0.0
1393
                Dim dOriginalEnd_x As Double = 0.0
1394
                Dim dOriginalEnd_y As Double = 0.0
1395
                Dim dStart_x As Double = 0.0
1396
                Dim dStart_y As Double = 0.0
1397
                Dim dEnd_x As Double = 0.0
1398
                Dim dEnd_y As Double = 0.0
1399

    
1400
                Dim sType As String = oPipeRow(0)(_XML_LINE_TYPE).ToString()
1401

    
1402
                Dim sSystempath As String = "\Piping\Routing\Process Lines\Primary Piping.sym" ' oPipeRow(0)(_XML_LINE_SYSTEMPATH).ToString()
1403
                If sType.ToUpper() = "ELECTRIC" Then
1404
                    sSystempath = "\Instrumentation\Signal Line\Electric.sym"
1405
                ElseIf sType.ToUpper() = "CONNECT TO PROCESS" Then
1406
                    sSystempath = "\Instrumentation\Signal Line\Connect to Process.sym"
1407
                Else
1408
                End If
1409
                Dim sStartpoint As String = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
1410
                Dim sEndpoint As String = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
1411
                Dim sPipeUid As String = oPipeRow(0)(_XML_LINE_UID).ToString()
1412

    
1413
                Dim oAddPiperunRow As DataRow = oPiperun_Dt.NewRow()
1414
                ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
1415
                dStart_x = dOriginalStart_x
1416
                dStart_y = dOriginalStart_y
1417

    
1418
                If ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y) Then
1419
                    dEnd_x = dOriginalEnd_x
1420
                    dEnd_y = dOriginalEnd_y
1421

    
1422
                    '라인보정(oLine_Dt, sPipeUid, dStart_x, dStart_y, dEnd_x, dEnd_y)
1423
                    '//Overlap 보정
1424
                    'If FindOverlapLine(oLine_Dt, sPipeUid, dStart_x, dStart_y, dEnd_x, dEnd_y) = False Then
1425
                    '    '//떨어진 라인 보정
1426
                    '    Dim dSeperate_start_x As Double = dStart_x
1427
                    '    Dim dSeperate_start_y As Double = dStart_y
1428
                    '    Dim dSeperate_end_x As Double = dEnd_x
1429
                    '    Dim dSeperate_end_y As Double = dEnd_y
1430
                    '    CalcSperateLine(dSeperate_start_x, dSeperate_start_y, dSeperate_end_x, dSeperate_end_y)
1431
                    '    If (FindOverlapLine(oLine_Dt, sPipeUid, dSeperate_start_x, dSeperate_start_y, dSeperate_end_x, dSeperate_end_y)) Then
1432
                    '        dStart_x = dSeperate_start_x
1433
                    '        dStart_y = dSeperate_start_y
1434
                    '        dEnd_x = dSeperate_end_x
1435
                    '        dEnd_y = dSeperate_end_y
1436
                    '    End If
1437
                    'End If
1438

    
1439
                    ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
1440
                    ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
1441
                    If dStart_x <> 0 And dStart_y <> 0 And dEnd_x <> 0 And dEnd_y <> 0 Then
1442

    
1443
                        Dim iConnType As Integer = ModelingLine(dStart_x, dStart_y, dEnd_x, dEnd_y, sUid)
1444
                        If iConnType = 1 Then
1445
                            objInputs.AddLocatedTarget(dStart_x, dStart_y)
1446
                            objInputs.AddPoint(dEnd_x, dEnd_y)
1447
                        ElseIf iConnType = 2 Then
1448
                            objInputs.AddLocatedTarget(dEnd_x, dEnd_y)
1449
                            objInputs.AddPoint(dStart_x, dStart_y)
1450
                        ElseIf iConnType = 3 Then
1451
                            objInputs.AddLocatedTarget(dEnd_x, dEnd_y)
1452
                            objInputs.AddPoint(dStart_x, dStart_y)
1453
                        ElseIf iConnType = 4 Then
1454
                            objInputs.AddLocatedTarget(dStart_x, dStart_y)
1455
                            objInputs.AddPoint(dEnd_x, dEnd_y)
1456
                        Else
1457
                            objInputs.AddPoint(dStart_x, dStart_y)
1458
                            objInputs.AddPoint(dEnd_x, dEnd_y)
1459
                        End If
1460
                        objInputs.AddPoint(dStart_x, dStart_y)
1461
                        objInputs.AddPoint(dEnd_x, dEnd_y)
1462
                        AddModelingLine(dStart_x, dStart_y, dEnd_x, dEnd_y, sUid)
1463
                        objItem = _Placement.PIDCreateItem(sSystempath)
1464
                        _iPipecnt = _iPipecnt + 1
1465
                        SetListBoxItems(ListBox_Result, "Place PipeLine..(" & dOriginalStart_x & "," & dOriginalStart_y & ") - (" & dOriginalEnd_x & "," & dOriginalEnd_y & ").." & _iPipecnt & " count ")
1466
                        objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
1467
                        oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
1468
                        oPipeRun.Attributes("FlowDirection").Value = "End 1 is upstream (Inlet)"
1469
                        If oAttributeRow.Length > 0 Then
1470
                            For Each oAttribute In oAttributeRow
1471
                                Try
1472
                                    Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
1473
                                    Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
1474
                                    If sPIDValue.Contains("'") Then
1475
                                        sPIDValue = sPIDValue.Replace("'", """")
1476
                                    End If
1477

    
1478
                                    Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
1479
                                    oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
1480
                                Catch ex As Exception
1481

    
1482
                                End Try
1483

    
1484

    
1485
                            Next
1486
                            oPipeRun.Commit()
1487
                        End If
1488
                        'Flow Direction 
1489
                        'Dim sFlowDirectionPath As String = "\Piping\Labels - Piping Segments\Flow Direction.sym" 'GetDataFromMappingDB(_XML_CATEGORY_FLOWDIRECITON, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
1490
                        'Dim dFlowDirectionAngle As Double = 0.0
1491
                        'If dStart_y <> dEnd_y Then
1492
                        '    If dStart_y > dEnd_y Then
1493
                        '        dFlowDirectionAngle = -1.57
1494
                        '    Else
1495
                        '        dFlowDirectionAngle = 1.57
1496
                        '    End If
1497
                        'End If
1498
                        'If dStart_x <> dEnd_x Then
1499
                        '    If dStart_x > dEnd_x Then
1500
                        '        dFlowDirectionAngle = 3.14
1501
                        '    Else
1502
                        '        dFlowDirectionAngle = 0
1503
                        '    End If
1504
                        'End If
1505

    
1506
                        '_Placement.PIDPlaceSymbol(sFlowDirectionPath, dEnd_x, dEnd_y, , dFlowDirectionAngle)
1507
                    End If
1508
                End If
1509
                _Itemcnt = _Itemcnt + 1
1510
                Dim dCalcProgressValue As Double = (_Itemcnt / _allItem) * 100
1511
                SetProgressbar(ProgressBar_Status, dCalcProgressValue)
1512
                Label_Progress.Text = Math.Round(dCalcProgressValue, 0) & "%"
1513

    
1514
                oAddPiperunRow("Piperun") = oPipeRun
1515
                oAddPiperunRow("startx") = dOriginalStart_x
1516
                oAddPiperunRow("starty") = dOriginalStart_y
1517
                oAddPiperunRow("endx") = dOriginalEnd_x
1518
                oAddPiperunRow("endy") = dOriginalEnd_y
1519
                oPiperun_Dt.Rows.Add(oAddPiperunRow)
1520

    
1521
            End If
1522
            Return oPipeRun
1523
        Catch ex As Exception
1524
            Return Nothing
1525
        End Try
1526
    End Function
1527

    
1528
    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)
1529
        Dim oAddRow = _DrawLine_Dt.NewRow()
1530
        oAddRow(_XML_LINE_UID) = sUid
1531
        oAddRow(_XML_LINE_STARTPOINT_X) = dStart_x
1532
        oAddRow(_XML_LINE_STARTPOINT_Y) = dStart_y
1533
        oAddRow(_XML_LINE_ENDPOINT_X) = dEnd_x
1534
        oAddRow(_XML_LINE_ENDPOINT_Y) = dEnd_y
1535
        _DrawLine_Dt.Rows.Add(oAddRow)
1536
    End Sub
1537

    
1538

    
1539
    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
1540
        'Dim oFindRows_1 As DataRow() = _DrawLine_Dt.Select("start_x = '" & dStart_x & "' and start_y = '" & dStart_y & "' and uid <> '" & sUid & "'")
1541

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

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

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

    
1548
        'If oFindRows_1.Length > 0 Then
1549
        '    Return 1
1550
        'ElseIf oFindRows_2.Length > 0 Then
1551
        '    Return 2
1552
        'ElseIf oFindRows_3.Length > 0 Then
1553
        '    Return 3
1554
        'ElseIf oFindRows_4.Length > 0 Then
1555
        '    Return 4
1556
        'Else
1557
        '    Return 0
1558
        'End If
1559
        Return 0
1560
    End Function
1561

    
1562
    Private Function FindConnectionPoint(ByVal dX As Double, ByVal dY As Double)
1563

    
1564

    
1565
    End Function
1566

    
1567
    Private Sub PlaceEquipment(ByVal sUid As String, ByVal oSymbol_Dt As DataTable, ByVal oAttribute_Dt As DataTable)
1568
        Try
1569
            Dim oSymbolRow() As DataRow = oSymbol_Dt.Select(_XML_SYMBOL_UID & " = '" + sUid + "'")
1570
            Dim oAttributeRow() As DataRow
1571
            If oAttribute_Dt.Rows.Count > 0 Then
1572
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
1573
            End If
1574
            If oSymbolRow.Length > 0 Then
1575
                Dim oDatasource As Object = _Placement.PIDDataSource
1576
                Dim sSymbolCompType As String = oSymbolRow(0)(_XML_SYMBOL_TYPE).ToString()
1577
                Dim sSystemPath As String = oSymbolRow(0)(_XML_SYMBOL_SYSTEMPATH).ToString()
1578
                Dim sClass As String = oSymbolRow(0)(_XML_SYMBOL_CLASS).ToString()
1579
                Dim sLocation As String = oSymbolRow(0)(_XML_SYMBOL_LOCATION).ToString()
1580
                Dim sOriginalPoint As String = oSymbolRow(0)(_XML_SYMBOL_ORIGINALPOINT).ToString()
1581
                Dim dAngle As Double = 0.0
1582
                If IsNumeric(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString()) Then
1583
                    dAngle = Double.Parse(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString())
1584
                End If
1585
                Dim dLocationX As Double = 0.0
1586
                Dim dLocationY As Double = 0.0
1587
                Dim dX As Double = 0.0
1588
                Dim dY As Double = 0.0
1589

    
1590
                If ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY) Then
1591
                    dX = dLocationX
1592
                    dY = dLocationY
1593
                    ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1594
                    _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1595
                    SetListBoxItems(ListBox_Result, "Place Equipment..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1596
                End If
1597
            End If
1598
        Catch ex As Exception
1599

    
1600
        End Try
1601

    
1602

    
1603
    End Sub
1604

    
1605
    Private Function PlacePipingOPC(ByVal sUid As String, ByVal sLineUid As String, ByVal oOPCRow As DataRow, ByVal oAttribute_Dt As DataTable) As LMSymbol
1606
        Try
1607
            Dim oAttributeRow() As DataRow
1608
            If oAttribute_Dt.Rows.Count > 0 Then
1609
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
1610
            End If
1611
            Dim oDatasource As Object = _Placement.PIDDataSource
1612
            Dim sSymbolCompType As String = oOPCRow(_XML_SYMBOL_TYPE).ToString()
1613
            Dim sSystemPath As String = oOPCRow(_XML_SYMBOL_SYSTEMPATH).ToString()
1614
            Dim sClass As String = oOPCRow(_XML_SYMBOL_CLASS).ToString()
1615
            Dim sLocation As String = oOPCRow(_XML_SYMBOL_LOCATION).ToString()
1616
            Dim sOriginalPoint As String = oOPCRow(_XML_SYMBOL_ORIGINALPOINT).ToString()
1617
            Dim dAngle As Double = 0.0
1618
            If IsNumeric(oOPCRow(_XML_SYMBOL_ANGLE).ToString()) Then
1619
                dAngle = Double.Parse(oOPCRow(_XML_SYMBOL_ANGLE).ToString())
1620
            End If
1621

    
1622
            Dim dLocationX As Double = 0.0
1623
            Dim dLocationY As Double = 0.0
1624
            Dim dX As Double = 0.0
1625
            Dim dY As Double = 0.0
1626
            Dim oLMSymbol As LMSymbol = Nothing
1627
            If ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY) Then
1628
                dX = dLocationX
1629
                dY = dLocationY
1630
                ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1631
                _iPipintOpccnt = _iPipintOpccnt + 1
1632
                oLMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1633
                '모델링된 형상은 Drawing True 로 처리
1634
                oOPCRow(_XML_SYMBOL_DRAWING_TF) = "TRUE"
1635
                SetListBoxItems(ListBox_Result, "Place Piping OPC..(" & dLocationX & "," & dLocationY & ")..." & _iPipintOpccnt & " count ")
1636

    
1637
                Dim dConn_X1 As Double, dConn_Y1 As Double, dConn_X2 As Double, dConn_Y2 As Double
1638
                _Placement.PIDConnectPointLocation(oLMSymbol, 1, dConn_X1, dConn_Y1)
1639
                _Placement.PIDConnectPointLocation(oLMSymbol, 2, dConn_X2, dConn_Y2)
1640

    
1641
                'Dim oAddrow As DataRow = _ResultModeling_DT.NewRow()
1642
                'oAddrow(_Modeling_Uid) = sUid
1643
                'oAddrow(_Modeling_Location_X) = dLocationX
1644
                'oAddrow(_Modeling_Location_Y) = dLocationY
1645
                'oAddrow(_Modeling_LineNoUid) = sLineUid
1646
                'oAddrow(_Modeling_Type) = sSymbolCompType
1647
                'oAddrow(_Modeling_Connection1_X) = dConn_X1
1648
                'oAddrow(_Modeling_Connection1_Y) = dConn_Y1
1649
                'oAddrow(_Modeling_Connection2_X) = dConn_X2
1650
                'oAddrow(_Modeling_Connection2_X) = dConn_Y2
1651
                'oAddrow(_Modeling_LMSymbol) = oLMSymbol
1652

    
1653
                '_ResultModeling_DT.Rows.Add(oAddrow)
1654
            End If
1655
            _Itemcnt = _Itemcnt + 1
1656
            Dim dCalcProgressValue As Double = (_Itemcnt / _allItem) * 100
1657
            SetProgressbar(ProgressBar_Status, dCalcProgressValue)
1658
            Label_Progress.Text = Math.Round(dCalcProgressValue, 0) & "%"
1659
            Return oLMSymbol
1660
        Catch ex As Exception
1661

    
1662
        End Try
1663
        Return Nothing
1664

    
1665
    End Function
1666

    
1667

    
1668
    Private Function DrawSymbol(ByVal sUid As String, ByVal oSymbol_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal oLine_Dt As DataTable) As Boolean
1669
        Try
1670

    
1671
            Dim oSymbolRow() As DataRow = oSymbol_Dt.Select(_XML_SYMBOL_UID & " = '" + sUid + "'")
1672
            Dim oAttributeRow() As DataRow
1673
            If oAttribute_Dt.Rows.Count > 0 Then
1674
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
1675
            End If
1676

    
1677
            If oSymbolRow.Length > 0 Then
1678
                Dim oDatasource As Object = _Placement.PIDDataSource
1679
                Dim sSymbolCompType As String = oSymbolRow(0)(_XML_SYMBOL_TYPE).ToString()
1680
                Dim sSystemPath As String = oSymbolRow(0)(_XML_SYMBOL_SYSTEMPATH).ToString()
1681
                Dim sClass As String = oSymbolRow(0)(_XML_SYMBOL_CLASS).ToString()
1682
                Dim sLocation As String = oSymbolRow(0)(_XML_SYMBOL_LOCATION).ToString()
1683
                Dim sOriginalPoint As String = oSymbolRow(0)(_XML_SYMBOL_ORIGINALPOINT).ToString()
1684
                Dim dAngle As Double = 0.0
1685
                If IsNumeric(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString()) Then
1686
                    dAngle = Double.Parse(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString())
1687
                End If
1688

    
1689
                Dim objSymbol As LMSymbol
1690
                Dim dLocationX As Double = 0.0
1691
                Dim dLocationY As Double = 0.0
1692
                Dim dX As Double = 0.0
1693
                Dim dY As Double = 0.0
1694

    
1695
                If ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY) Then
1696
                    dX = dLocationX
1697
                    dY = dLocationY
1698
                    If sSymbolCompType = "" Or sSymbolCompType = "Piping OPC's" Then
1699
                        FindConnectionLine(oLine_Dt, dX, dY)
1700
                    End If
1701

    
1702
                    ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1703
                    Dim oInstrument As LMInstrument
1704
                    If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
1705
                        _iInstrumentcnt = _iInstrumentcnt + 1
1706
                        objSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1707
                        SetListBoxItems(ListBox_Result, "Place Instrument..(" & dLocationX & "," & dLocationY & ")..." & _iInstrumentcnt & " count ")
1708
                        oInstrument = oDatasource.GetInstrument(objSymbol.ModelItemID)
1709
                        Try
1710
                            If oAttributeRow.Length > 0 Then
1711
                                For Each oAttribute In oAttributeRow
1712
                                    Try
1713
                                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
1714
                                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
1715
                                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
1716
                                        oInstrument.Attributes(sSPPIDAttribute).Value = sPIDValue
1717
                                    Catch ex As Exception
1718

    
1719
                                    End Try
1720

    
1721
                                Next
1722
                                oInstrument.Commit()
1723
                            End If
1724
                        Catch ex As Exception
1725
                        End Try
1726
                    ElseIf sSymbolCompType.ToUpper() = _DB_FITTINGS.ToUpper() Then
1727
                        _iValvecnt = _iValvecnt + 1
1728
                        _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1729
                        SetListBoxItems(ListBox_Result, "Place Valve..(" & dLocationX & "," & dLocationY & ")..." & _iValvecnt & " count ")
1730

    
1731
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_FITTINGS.ToUpper() Then
1732
                        _iFittingcnt = _iFittingcnt + 1
1733
                        If sSystemPath.Contains(",") Then
1734

    
1735
                            Dim sDuplicatePath As String() = sSystemPath.Split(",")
1736
                            Dim sMainSymbol As String = ""
1737
                            Dim sSubSymbol As String = ""
1738
                            For Each sPath In sDuplicatePath
1739
                                If sMainSymbol = "" Then
1740
                                    sMainSymbol = sPath.Replace(vbLf, "")
1741
                                Else
1742
                                    sSubSymbol = sPath.Replace(vbLf, "")
1743
                                End If
1744
                            Next
1745
                            Dim oSymbolObj As LMSymbol = _Placement.PIDPlaceSymbol(sMainSymbol, dX, dY, , dAngle)
1746
                            Dim dConnpos_x As Double = 0.0
1747
                            Dim dConnpos_y As Double = 0.0
1748
                            _Placement.PIDConnectPointLocation(oSymbolObj, 2, dConnpos_x, dConnpos_y)
1749
                            '   _Placement.PIDPlaceSymbol(sSubSymbol, dConnpos_x, dConnpos_y, dAngle, TargetItem:=oSymbolObj.AsLMRepresentation)
1750
                            _Placement.PIDPlaceSymbol(sSubSymbol, dConnpos_x, dConnpos_y,, dAngle)
1751

    
1752
                        Else
1753
                            _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1754
                        End If
1755

    
1756

    
1757
                        SetListBoxItems(ListBox_Result, "Place Fitting..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1758
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() And sClass.ToUpper() = _SYMBOL_ACTUATORS.ToUpper() Then
1759
                        _iFittingcnt = _iFittingcnt + 1
1760
                        Dim sDuplicatePath As String() = sSystemPath.Split(",")
1761
                        Dim sMainSymbol As String = ""
1762
                        Dim sSubSymbol As String = ""
1763
                        For Each sPath In sDuplicatePath
1764
                            If sMainSymbol = "" Then
1765
                                sMainSymbol = sPath.Replace(vbLf, "")
1766
                            Else
1767
                                sSubSymbol = sPath.Replace(vbLf, "")
1768
                            End If
1769
                        Next
1770
                        Dim oSymbolObj As LMSymbol = _Placement.PIDPlaceSymbol(sMainSymbol, dX, dY, , dAngle)
1771
                        Dim dSymbolpos_x As Double = oSymbolObj.XCoordinate
1772
                        Dim dSymbolpos_y As Double = oSymbolObj.YCoordinate
1773
                        _Placement.PIDPlaceSymbol(sSubSymbol, dSymbolpos_x, dSymbolpos_y, , dAngle, TargetItem:=oSymbolObj.AsLMAItem)
1774

    
1775
                    Else
1776
                        _iFittingcnt = _iFittingcnt + 1
1777
                        _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1778
                        SetListBoxItems(ListBox_Result, "Place Fitting..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1779
                    End If
1780

    
1781
                End If
1782
                _Itemcnt = _Itemcnt + 1
1783
                Dim dCalcProgressValue As Double = (_Itemcnt / _allItem) * 100
1784
                SetProgressbar(ProgressBar_Status, dCalcProgressValue)
1785
                Label_Progress.Text = Math.Round(dCalcProgressValue, 0) & "%"
1786
            End If
1787

    
1788
        Catch ex As Exception
1789
            Return False
1790
        End Try
1791
    End Function
1792

    
1793

    
1794
    Private Sub FindConnectionLine(ByVal oLine_Dt As DataTable, ByRef dx As Double, ByRef dy As Double)
1795

    
1796
        Try
1797
            For Each oRow In oLine_Dt.Rows
1798
                Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1799
                Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1800
                Dim d기준s_x As Double = 0
1801
                Dim d기준s_y As Double = 0
1802
                Dim d기준e_x As Double = 0
1803
                Dim d기준e_y As Double = 0
1804
                ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1805
                ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1806
                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
1807
                    dx = d기준s_x
1808
                    dy = d기준s_y
1809
                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
1810
                    dx = d기준e_x
1811
                    dy = d기준e_y
1812
                End If
1813
            Next
1814
        Catch ex As Exception
1815
        End Try
1816
    End Sub
1817

    
1818

    
1819
    Dim _라인보정기준값 As Integer = 10
1820

    
1821
    Private Function 라인보정(ByRef oLine_Dt As DataTable, ByVal sUid As String, ByRef dsx As Double, ByRef dsy As Double,
1822
                                      ByRef dex As Double, ByRef dey As Double)
1823
        Try
1824
            Dim bCheck라인 As Boolean = False
1825
            '일치하는 Line 찾기
1826
            For Each oRow In oLine_Dt.Rows
1827
                Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1828
                Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1829
                Dim sBUid As String = oRow(_XML_LINE_UID).ToString()
1830
                If sBUid <> sUid Then
1831
                    Dim d기준s_x As Double = 0
1832
                    Dim d기준s_y As Double = 0
1833
                    Dim d기준e_x As Double = 0
1834
                    Dim d기준e_y As Double = 0
1835
                    ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1836
                    ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1837

    
1838
                    If (dsx = d기준s_x And dsy = d기준s_y) Or (dsx = d기준e_x And dsy = d기준e_y) Or
1839
                       (dex = d기준s_x And dey = d기준s_y) Or (dex = d기준e_x And dey = d기준e_y) Then
1840
                        bCheck라인 = True
1841
                    End If
1842
                End If
1843
            Next
1844

    
1845
            If bCheck라인 = False Then
1846
                For Each oRow In oLine_Dt.Rows
1847
                    Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1848
                    Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1849
                    Dim sBUid As String = oRow(_XML_LINE_UID).ToString()
1850
                    If sBUid <> sUid Then
1851
                        Dim d기준s_x As Double = 0
1852
                        Dim d기준s_y As Double = 0
1853
                        Dim d기준e_x As Double = 0
1854
                        Dim d기준e_y As Double = 0
1855
                        ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1856
                        ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1857
                        If ((dsx - _라인보정기준값 <= d기준s_x And dsx + _라인보정기준값 >= d기준s_x) And (dsy - _라인보정기준값 <= d기준s_y And dsy + _라인보정기준값 >= d기준s_y)) Then
1858
                            oRow(_XML_LINE_STARTPOINT) = dsx & "," & dsy
1859
                            bCheck라인 = True
1860
                            Exit For
1861
                        ElseIf ((dsx - _라인보정기준값 <= d기준e_x And dsx + _라인보정기준값 >= d기준e_x) And (dsy - _라인보정기준값 <= d기준e_y And dsy + _라인보정기준값 >= d기준e_y)) Then
1862
                            oRow(_XML_LINE_ENDPOINT) = dsx & "," & dsy
1863
                            bCheck라인 = True
1864
                            Exit For
1865
                        ElseIf ((dex - _라인보정기준값 <= d기준s_x And dex + _라인보정기준값 >= d기준s_x) And (dey - _라인보정기준값 <= d기준s_y And dey + _라인보정기준값 >= d기준s_y)) Then
1866
                            oRow(_XML_LINE_STARTPOINT) = dex & "," & dey
1867
                            bCheck라인 = True
1868
                            Exit For
1869
                        ElseIf ((dex - _라인보정기준값 <= d기준e_x And dex + _라인보정기준값 >= d기준e_x) And (dey - _라인보정기준값 <= d기준e_y And dey + _라인보정기준값 >= d기준e_y)) Then
1870
                            oRow(_XML_LINE_ENDPOINT) = dex & "," & dey
1871
                            bCheck라인 = True
1872
                            Exit For
1873
                        End If
1874

    
1875
                    End If
1876
                Next
1877
            End If
1878

    
1879
            Return bCheck라인
1880
        Catch ex As Exception
1881
            Return False
1882
        End Try
1883

    
1884

    
1885
    End Function
1886

    
1887
    Private Function FindOverlapLine(ByVal oLine_Dt As DataTable, ByVal sUid As String, ByRef dsx As Double, ByRef dsy As Double,
1888
                                      ByRef dex As Double, ByRef dey As Double)
1889
        Try
1890
            Dim bCheckOverlap As Boolean = False
1891
            For Each oRow In oLine_Dt.Rows
1892
                Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1893
                Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1894
                Dim sBUid As String = oRow(_XML_LINE_UID).ToString()
1895
                If sBUid <> sUid Then
1896
                    Dim d기준s_x As Double = 0
1897
                    Dim d기준s_y As Double = 0
1898
                    Dim d기준e_x As Double = 0
1899
                    Dim d기준e_y As Double = 0
1900
                    ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1901
                    ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1902
                    If (d기준s_x <= dsx And d기준e_x >= dex And
1903
                        d기준s_y <= dsy And d기준e_y >= dey) Then
1904
                        '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1905
                        If dsy - d기준s_y > d기준e_y - dey Then
1906
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1907
                            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기준s_y - d기준e_y)
1910
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1911
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1912
                                If dCalcStartY = 0 Then
1913
                                    dey = d기준e_y
1914
                                Else
1915
                                    dey = dCalcStartY
1916
                                End If
1917
                            End If
1918
                        Else
1919
                            '  Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1920
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1921
                            If dResultCalc < 10 Then
1922
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1923
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1924
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1925
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1926
                                If dCalcStartY = 0 Then
1927
                                    dsy = d기준s_y
1928
                                Else
1929
                                    dsy = dCalcStartY
1930
                                End If
1931
                            End If
1932
                        End If
1933
                        bCheckOverlap = True
1934
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
1935
                            d기준s_y <= dey And d기준e_y >= dsy Then
1936
                        '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1937
                        If dey - d기준s_y > d기준e_y - dsy Then
1938
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1939
                            If dResultCalc < 10 Then
1940
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1941
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1942
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1943
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1944
                                If dCalcStartY = 0 Then
1945
                                    dsy = d기준e_y
1946
                                Else
1947
                                    dsy = dCalcStartY
1948
                                End If
1949

    
1950
                            End If
1951
                            '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1952
                        Else
1953
                            '  Dim dResultCalc As Double = (Math.Abs((dsy - d기준s_y)) / Math.Abs((d기준e_y - dey))) * 100
1954
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1955
                            If dResultCalc < 10 Then
1956
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1957
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1958
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1959
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1960
                                If dCalcStartY = 0 Then
1961
                                    dey = d기준e_y
1962
                                Else
1963
                                    dey = dCalcStartY
1964
                                End If
1965
                            End If
1966
                        End If
1967
                        bCheckOverlap = True
1968
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
1969
                            d기준s_y <= dey And d기준e_y >= dsy Then
1970

    
1971
                        If dsx - d기준s_x > d기준e_x - dex Then
1972
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1973
                            If dResultCalc < 10 Then
1974
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1975
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1976
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1977
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1978
                                If dCalcStartX = 0 Then
1979
                                    dex = d기준e_x
1980
                                Else
1981
                                    dex = dCalcStartX
1982
                                End If
1983
                            End If
1984
                        Else
1985
                            '  Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1986
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1987
                            If dResultCalc < 10 Then
1988
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1989
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1990
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1991
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1992
                                If dCalcStartX = 0 Then
1993
                                    dsx = d기준s_x
1994
                                Else
1995
                                    dsx = dCalcStartX
1996
                                End If
1997
                            End If
1998
                        End If
1999
                        bCheckOverlap = True
2000
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
2001
                            d기준s_y <= dey And d기준e_y >= dsy Then
2002

    
2003
                        If dex - d기준s_x > d기준e_x - dsx Then
2004
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
2005
                            If dResultCalc < 10 Then
2006
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
2007
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
2008
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
2009
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
2010
                                If dCalcStartX = 0 Then
2011
                                    dsx = d기준e_x
2012
                                Else
2013
                                    dsx = dCalcStartX
2014
                                End If
2015
                            End If
2016
                        Else
2017
                            ' Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
2018
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
2019
                            If dResultCalc < 10 Then
2020
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
2021
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
2022
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
2023
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
2024
                                If dCalcStartX = 0 Then
2025
                                    dex = d기준s_x
2026
                                Else
2027
                                    dex = dCalcStartX
2028
                                End If
2029
                            End If
2030

    
2031
                        End If
2032
                        bCheckOverlap = True
2033
                    End If
2034
                End If
2035
            Next
2036

    
2037
            Return bCheckOverlap
2038
        Catch ex As Exception
2039
            Return False
2040
        End Try
2041
    End Function
2042

    
2043
    Private Sub CalcSperateLine(ByRef dStartX As Double, ByRef dStartY As Double,
2044
                                      ByRef dEndX As Double, ByRef dEndY As Double)
2045
        Try
2046
            Dim dRange As Double = 1 'Line 전체 길이의 10%씩 늘이기
2047
            If Math.Abs(dStartX - dEndX) > Math.Abs(dStartY - dEndY) Then
2048
                Dim dCalc_x As Double = Math.Abs(dStartX - dEndX) * 0.1
2049
                If dStartX > dEndX Then
2050
                    dStartX = dStartX + dCalc_x
2051
                    dEndX = dEndX - dCalc_x
2052
                Else
2053
                    dEndX = dEndX + dCalc_x
2054
                    dStartX = dStartX - dCalc_x
2055
                End If
2056
            Else
2057
                Dim dCalc_y As Double = Math.Abs(dStartY - dEndY) * 0.1
2058
                If dStartY > dEndY Then
2059
                    dStartY = dStartY + dCalc_y
2060
                    dEndY = dEndY - dCalc_y
2061
                Else
2062
                    dEndY = dEndY + dCalc_y
2063
                    dStartY = dStartY - dCalc_y
2064
                End If
2065
            End If
2066

    
2067
        Catch ex As Exception
2068

    
2069
        End Try
2070

    
2071

    
2072
    End Sub
2073

    
2074
    Private Function DrawLineNo(ByVal oPipeRun_Dt As DataTable, ByVal CLine_No As Line_no) As Boolean
2075
        Try
2076
            Dim oDatasource As Object = _Placement.PIDDataSource
2077
            Dim sLocation = CLine_No.Location
2078
            Dim dLocationx As Double = 0.0
2079
            Dim dLocationy As Double = 0.0
2080

    
2081
            Dim dX As Double = 0.0
2082
            Dim dY As Double = 0.0
2083
            If ConvertPointBystring(sLocation, dLocationx, dLocationy) Then
2084
                dX = dLocationx
2085
                dY = dLocationy
2086

    
2087
                For Each oRow In oPipeRun_Dt.Rows
2088
                    Dim dStartx As Double = Double.Parse(oRow("startx").ToString())
2089
                    Dim dStarty As Double = Double.Parse(oRow("starty").ToString())
2090
                    Dim dEndx As Double = Double.Parse(oRow("endx").ToString())
2091
                    Dim dEndy As Double = Double.Parse(oRow("endy").ToString())
2092

    
2093
                    Dim dStartSum As Double = Math.Abs(dStartx - dLocationx) + Math.Abs(dStarty - dLocationy)
2094
                    Dim dEndSum As Double = Math.Abs(dEndx - dLocationx) + Math.Abs(dEndy - dLocationy)
2095
                    If dStartSum > dEndSum Then
2096
                        oRow("value") = dEndSum
2097
                    Else
2098
                        oRow("value") = dStartSum
2099
                    End If
2100

    
2101
                Next
2102
                Dim dataView As New DataView(oPipeRun_Dt)
2103
                dataView.Sort = " value asc"
2104
                Dim oDt As DataTable = dataView.ToTable()
2105
                If oDt.Rows.Count > 0 Then
2106
                    Try
2107
                        Dim oPiperun As LMPipeRun = CType(oDt.Rows(0)("Piperun"), LMPipeRun)
2108
                        ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
2109
                        Dim dLineNoLocation(2) As Double
2110
                        dLineNoLocation(1) = dX
2111
                        dLineNoLocation(2) = dY
2112
                        'Label
2113
                        Dim sSystemPath As String = CLine_No.SystemPath
2114
                        Dim dAngle As Double = CLine_No.Angle
2115
                        Dim labelpersist As LMLabelPersist
2116

    
2117
                        For Each representation In oPiperun.Representations
2118
                            If representation.RepresentationType = "Connector" Then
2119
                                labelpersist = _Placement.PIDPlaceLabel(sSystemPath,
2120
                                dLineNoLocation,, dAngle, LabeledItem:=representation)
2121
                                _iPipeLineNocnt = _iPipeLineNocnt + 1
2122
                                SetListBoxItems(ListBox_Result, "Place PipeLineNo Label..(" & dLocationx & "," & dLocationy & ")..." & _iPipeLineNocnt & " count ")
2123
                            End If
2124
                        Next
2125
                    Catch ex As Exception
2126

    
2127
                    End Try
2128

    
2129

    
2130
                End If
2131

    
2132

    
2133

    
2134
                Return True
2135
            Else
2136
                Return False
2137
            End If
2138

    
2139
        Catch ex As Exception
2140
            Return False
2141
        End Try
2142
    End Function
2143

    
2144

    
2145
    Private Sub InitItemCount()
2146
        _iPipeLineNocnt = 0
2147
        _iPipecnt = 0
2148
        _iFittingcnt = 0
2149
        _iValvecnt = 0
2150
        _iInstrumentcnt = 0
2151
        _iEquipmentcnt = 0
2152
        _iNozzlecnt = 1
2153
        _iPipintOpccnt = 0
2154

    
2155
    End Sub
2156

    
2157
    Private Function GetAllCheckNodeCount() As Integer
2158
        _allItem = 0
2159
        For i = 0 To Tree_Result.Nodes.Count - 1
2160
            For j = 0 To Tree_Result.Nodes(i).Nodes.Count - 1
2161
                For k = 0 To Tree_Result.Nodes(i).Nodes(j).Nodes.Count - 1
2162
                    For l = 0 To Tree_Result.Nodes(i).Nodes(j).Nodes(k).Nodes.Count - 1
2163
                        If Tree_Result.Nodes(i).Nodes(j).Nodes(k).Nodes(l).Checked = True Then
2164
                            _allItem = _allItem + 1
2165
                        End If
2166
                    Next
2167
                Next
2168
            Next
2169
        Next
2170
        Return _allItem
2171
    End Function
2172

    
2173

    
2174
    ''' <summary>
2175
    ''' Equipment 모델링
2176
    ''' </summary>
2177
    Private Sub EquipmentModeling(ByVal oDwg_Dt As DataTable)
2178
        For Each oDrwing As TreeNode In Tree_Result.Nodes
2179
            For Each oDwgNode As TreeNode In oDrwing.Nodes
2180
                Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
2181
                Dim CDrawing As Drawing = GetDrawing(sDwgName)
2182
                If CDrawing IsNot Nothing Then
2183
                    If OpenSPPID(oDwg_Dt, oDwgNode.Text) Then
2184
                        InitItemCount()
2185
                        SetListBoxItems(ListBox_Result, "Place " & CDrawing.DwgName & "....")
2186
                        For Each oNode As TreeNode In oDwgNode.Nodes
2187
                            Dim iItemcnt As Integer = 0
2188
                            Dim sNodeUid As String = oNode.Name
2189
                            Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
2190
                            '1.Equipment
2191
                            '2.Piping OPC
2192
                            '3.OPC 시작되는 Line
2193
                            'Equipment 생성
2194
                            Dim CEqpNo As Eqp_no = GetEqpNo(CDrawing, sNodeUid)
2195
                            If CEqpNo IsNot Nothing Then
2196
                                Dim oSymbol_Dt As DataTable = CEqpNo.Dt_Equipment
2197
                                Dim oAttribute_Dt As DataTable = CEqpNo.Dt_Attribute
2198
                                For Each oSymbolNode As TreeNode In oNode.Nodes
2199
                                    If oSymbolNode.Checked Then
2200
                                        Dim sUid As String = oSymbolNode.Name
2201
                                        PlaceEquipment(sUid, oSymbol_Dt, oAttribute_Dt)
2202
                                    End If
2203
                                Next
2204
                            End If
2205
                        Next
2206
                    End If
2207
                End If
2208
            Next
2209
        Next
2210
    End Sub
2211

    
2212
    Private Sub ManualCheckNode(ByRef oDt As DataTable)
2213
        For Each oDrwing As TreeNode In Tree_Result.Nodes
2214
            For Each oDwgNode As TreeNode In oDrwing.Nodes
2215
                For Each oNode As TreeNode In oDwgNode.Nodes
2216
                    For Each oSymbolNode As TreeNode In oNode.Nodes
2217
                        Dim sUid As String = oSymbolNode.Name
2218
                        Dim oSelectRows() As DataRow = oDt.Select("[" & _XML_SYMBOL_UID & "] = '" & sUid & "'")
2219
                        If oSelectRows.Length = 1 Then
2220
                            If oSymbolNode.Checked Then
2221
                                oSelectRows(0)(_XML_SYMBOL_Check) = "TRUE"
2222
                            Else
2223
                                oSelectRows(0)(_XML_SYMBOL_Check) = "FALSE"
2224
                            End If
2225
                        End If
2226

    
2227
                    Next
2228
                Next
2229
            Next
2230
        Next
2231

    
2232
    End Sub
2233

    
2234
    Private Sub PipingModeling()
2235

    
2236
        Try
2237
            For Each oDrwing As TreeNode In Tree_Result.Nodes
2238
                For Each oDwgNode As TreeNode In oDrwing.Nodes
2239
                    Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
2240
                    Dim CDrawing As Drawing = GetDrawing(sDwgName)
2241
                    If CDrawing IsNot Nothing Then
2242
                        Dim iAllLineNoCount As Integer = Tree_Result.Nodes.Count ' GetCheckNodeCount(oLinenoNode)
2243
                        Dim iPipingOPC_count As Integer = 0 ' GetCheckNodeCount(oLinenoNode)
2244
                        SetListBoxItems(ListBox_Result, "Place " & CDrawing.DwgName & "....")
2245
                        For Each oNode As TreeNode In oDwgNode.Nodes
2246
                            Dim iItemcnt As Integer = 0
2247
                            Dim sNodeUid As String = oNode.Name
2248
                            Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
2249
                            '1.Equipment
2250
                            '2.Piping OPC
2251
                            '3.OPC 시작되는 Line
2252
                            'Equipment 생성
2253
                            'If sNodeUid <> "PipeLineNo" Then
2254
                            Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
2255
                            If CLineNo IsNot Nothing Then
2256
                                Dim oLine_Dt As DataTable = CLineNo.Dt_Line
2257
                                Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
2258
                                Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
2259
                                Dim oDrawLinenoLabel As Boolean = False
2260

    
2261
                                ManualCheckNode(oLine_Dt)
2262
                                ManualCheckNode(oSymbol_Dt)
2263

    
2264
                                For Each oSymbolNode As TreeNode In oNode.Nodes
2265
                                    If oSymbolNode.Checked Then
2266
                                        Dim sUid As String = oSymbolNode.Name
2267
                                        Dim oOpc_Rows As DataRow() = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "]= '" & sUid & "' And [" &
2268
                                                                                       _XML_SYMBOL_Check & "] = 'TRUE'")
2269
                                        If oOpc_Rows.Length = 1 Then
2270
                                            If oOpc_Rows(0)(_XML_SYMBOL_TYPE) = _XML_PIPINGOPC Then
2271
                                                Dim oOPCSymbol As LMSymbol = PlacePipingOPC(sUid, CLineNo.Uid, oOpc_Rows(0), oAttribute_Dt)
2272
                                                iPipingOPC_count = iPipingOPC_count + 1
2273
                                                OPCTOLineRouting(oLine_Dt, oAttribute_Dt, oOPCSymbol, sUid, CLineNo.Uid)
2274
                                                '   LineRouting(oLine_Dt, oAttribute_Dt, CLineNo.Uid)
2275
                                                '   SymbolModeling(oSymbol_Dt, oAttribute_Dt, CLineNo.Uid)
2276
                                            End If
2277
                                        End If
2278
                                    End If
2279
                                Next
2280
                                For Each oSymbolNode As TreeNode In oNode.Nodes
2281
                                    If oSymbolNode.Checked Then
2282
                                        Dim sUid As String = oSymbolNode.Name
2283
                                        LineRouting(oLine_Dt, oAttribute_Dt, CLineNo.Uid)
2284
                                    End If
2285
                                Next
2286
                                For Each oSymbolNode As TreeNode In oNode.Nodes
2287
                                    If oSymbolNode.Checked Then
2288
                                        Dim sUid As String = oSymbolNode.Name
2289
                                        Dim oSymbolRow As DataRow() = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "]= '" & sUid & "' And [" & _XML_SYMBOL_DRAWING_TF & "] = 'False' And [" &
2290
                                                                                       _XML_SYMBOL_Check & "] = 'TRUE'")
2291
                                        If oSymbolRow.Length = 1 Then
2292
                                            '   SymbolModeling(oSymbol_Dt, oAttribute_Dt, CLineNo.Uid, oSymbolRow(0))
2293
                                            SymbolModeling(CDrawing, oSymbolRow(0), oAttribute_Dt)
2294
                                        End If
2295
                                    End If
2296
                                Next
2297
                            End If
2298
                        Next
2299
                    End If
2300
                Next
2301
            Next
2302
        Catch ex As Exception
2303

    
2304
        End Try
2305
    End Sub
2306

    
2307

    
2308
    Private Sub FindNearPoint(ByVal oOPCSymbol As LMSymbol, ByRef dNear_x As Double, ByRef dNear_y As Double)
2309
        Dim oConnectionPoints_x(4) As Double
2310
        Dim oConnectionPoints_y(4) As Double
2311

    
2312
        Try
2313
            _Placement.PIDConnectPointLocation(oOPCSymbol, 1, oConnectionPoints_x(0), oConnectionPoints_y(0))
2314
            _Placement.PIDConnectPointLocation(oOPCSymbol, 2, oConnectionPoints_x(1), oConnectionPoints_y(1))
2315
            _Placement.PIDConnectPointLocation(oOPCSymbol, 3, oConnectionPoints_x(2), oConnectionPoints_y(2))
2316
            _Placement.PIDConnectPointLocation(oOPCSymbol, 4, oConnectionPoints_x(3), oConnectionPoints_y(3))
2317
            Dim iNearPoint As Integer = 0
2318
            Dim dGap As Double = 0
2319
            For i = 0 To 3
2320
                If dGap = 0 Then
2321
                    iNearPoint = i
2322
                    dGap = Math.Abs(oConnectionPoints_x(i) - dNear_x) + Math.Abs(oConnectionPoints_y(i) - dNear_y)
2323
                Else
2324
                    If dGap >= Math.Abs(oConnectionPoints_x(i) - dNear_x) + Math.Abs(oConnectionPoints_y(i) - dNear_y) Then
2325
                        iNearPoint = i
2326
                        dGap = Math.Abs(oConnectionPoints_x(i) - dNear_x) + Math.Abs(oConnectionPoints_y(i) - dNear_y)
2327
                    End If
2328
                End If
2329
            Next
2330
            dNear_x = oConnectionPoints_x(iNearPoint)
2331
            dNear_y = oConnectionPoints_y(iNearPoint)
2332
        Catch ex As Exception
2333

    
2334
        End Try
2335

    
2336
    End Sub
2337

    
2338
    Private Function GetPipeType(ByVal sType As String) As String
2339
        Dim sSystempath As String = "\Piping\Routing\Process Lines\Primary Piping.sym" ' oPipeRow(0)(_XML_LINE_SYSTEMPATH).ToString()
2340
        If sType.ToUpper() = "ELECTRIC" Then
2341
            sSystempath = "\Instrumentation\Signal Line\Electric.sym"
2342
        ElseIf sType.ToUpper() = "CONNECT TO PROCESS" Then
2343
            sSystempath = "\Instrumentation\Signal Line\Connect to Process.sym"
2344
        Else
2345
        End If
2346
        Return sSystempath
2347
    End Function
2348

    
2349
    Private Sub InitAutoRouting()
2350
        For Each oDrwing As TreeNode In Tree_Result.Nodes
2351
            For Each oDwgNode As TreeNode In oDrwing.Nodes
2352
                Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
2353
                Dim CDrawing As Drawing = GetDrawing(sDwgName)
2354
                If CDrawing IsNot Nothing Then
2355
                    Dim iAllLineNoCount As Integer = Tree_Result.Nodes.Count ' GetCheckNodeCount(oLinenoNode)
2356
                    Dim iPipingOPC_count As Integer = 0 ' GetCheckNodeCount(oLinenoNode)
2357
                    SetListBoxItems(ListBox_Result, "Place " & CDrawing.DwgName & "....")
2358
                    For Each oNode As TreeNode In oDwgNode.Nodes
2359
                        Dim iItemcnt As Integer = 0
2360
                        Dim sNodeUid As String = oNode.Name
2361
                        Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
2362
                        Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
2363
                        If CLineNo IsNot Nothing Then
2364
                            Dim oLine_Dt As DataTable = CLineNo.Dt_Line
2365
                            Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
2366

    
2367
                            For Each oLineRow In oLine_Dt.Rows
2368
                                oLineRow(_XML_LINE_SPID) = ""
2369
                                oLineRow(_XML_LINE_DRAWING_TF) = "FALSE"
2370
                            Next
2371
                            For Each oSymbolRow In oSymbol_Dt.Rows
2372
                                oSymbolRow(_XML_SYMBOL_SPID) = ""
2373
                                oSymbolRow(_XML_SYMBOL_DRAWING_TF) = "FALSE"
2374
                            Next
2375

    
2376
                        End If
2377
                    Next
2378
                End If
2379
            Next
2380
        Next
2381
    End Sub
2382

    
2383

    
2384

    
2385

    
2386

    
2387

    
2388
    Private Function CheckBranchLine(ByVal oLine_Dt As DataTable, ByVal dStartX As Double, ByVal dStartY As Double,
2389
                                ByRef dEndX As Double, ByRef dEndY As Double, ByRef sBranchType As String, ByRef oLMConnector As LMConnector) As Boolean
2390

    
2391
        Try
2392
            Dim oModelingLineRows() As DataRow = oLine_Dt.Select("[" & _XML_LINE_DRAWING_TF & "] = 'TRUE' And [" & _XML_LINE_SPID & "] <> ''")
2393
            For Each oModelrow In oModelingLineRows
2394
                Dim sStartPoint As String = oModelrow(_XML_LINE_STARTPOINT)
2395
                Dim sEndPoint As String = oModelrow(_XML_LINE_ENDPOINT)
2396
                Dim dModelStartX As Double
2397
                Dim dModelStartY As Double
2398
                Dim dModelEndX As Double
2399
                Dim dModelEndY As Double
2400
                ConvertPointBystring(sStartPoint, dModelStartX, dModelStartY)
2401
                ConvertPointBystring(sEndPoint, dModelEndX, dModelEndY)
2402
                ConvertPointByImage(dModelStartX, dModelStartY, _IMG_X, _IMG_Y)
2403
                ConvertPointByImage(dModelEndX, dModelEndY, _IMG_X, _IMG_Y)
2404
                Dim dGap As Double = 0.0002
2405
                Dim d기준x As Double = (dModelStartX + dModelEndX) / 2
2406
                Dim d기준y As Double = (dModelStartY + dModelEndY) / 2
2407
                Try
2408
                    oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
2409
                Catch ex As Exception
2410

    
2411
                End Try
2412
                Dim oRun As LMPipeRun = Nothing
2413
                Try
2414

    
2415
                    oRun = _Placement.PIDDataSource.GetPipeRun(oLMConnector.ModelItemID)
2416
                    Dim dResultCalc As Double = -1
2417
                    For Each objRep In oRun.Representations
2418
                        If objRep.Attributes("RepresentationType").Value = "Connector" And objRep.Attributes("ItemStatus").Value = "Active" Then
2419
                            Dim objConnector As LMConnector = _Placement.PIDDataSource.GetConnector(objRep.ID)
2420
                            For Each objConnectorVertex In objConnector.ConnectorVertices
2421
                                Dim dConn_X As Double = objConnectorVertex.Attributes("XCoordinate").Value
2422
                                Dim dConn_Y As Double = objConnectorVertex.Attributes("YCoordinate").Value
2423
                                Dim dStartCalc As Double = Math.Abs(dStartX - dConn_X) + Math.Abs(dStartY - dConn_Y)
2424

    
2425
                                If dResultCalc > dStartCalc Or dResultCalc = -1 Then
2426
                                    dResultCalc = dStartCalc
2427
                                    oLMConnector = objConnector
2428
                                    d기준x = dConn_X
2429
                                    d기준y = dConn_Y
2430
                                End If
2431
                                Dim dEndCalc As Double = Math.Abs(dEndX - dConn_X) + Math.Abs(dEndY - dConn_Y)
2432
                                If dResultCalc > dEndCalc Then
2433
                                    dResultCalc = dEndCalc
2434
                                    oLMConnector = objConnector
2435
                                    d기준x = dConn_X
2436
                                    d기준y = dConn_Y
2437
                                End If
2438
                            Next
2439
                        End If
2440
                    Next
2441
                    '        _Placement.PIDConnectPointLocation(oRun, 1, dModelStartX, dModelEndX)
2442
                    '       _Placement.PIDConnectPointLocation(oRun, 2, dModelEndX, dModelEndY)
2443
                Catch ex As Exception
2444
                End Try
2445

    
2446

    
2447
                'Dim sSPID As String = oModelrow(_XML_LINE_SPID).ToString()
2448
                'Dim oPipeRun As LMPipeRun = _Placement.PIDDataSource.Get PipeRun(sSPID)
2449
                'If dModelStartX + dGap > dStartX And dModelStartX - dGap < dStartX And
2450
                '        dModelStartY + dGap > dStartY And dModelStartY - dGap < dStartY Then
2451
                '    dStartX = dModelStartX
2452
                '    dStartY = dModelStartY
2453
                'ElseIf dModelEndX + dGap > dStartX And dModelEndX - dGap < dStartX And
2454
                '        dModelEndY + dGap > dStartY And dModelEndY - dGap < dStartY Then
2455
                '    dStartX = dModelEndX
2456
                '    dStartY = dModelEndY
2457
                'End If
2458

    
2459
                'Vetical
2460
                If Math.Abs(dModelStartX - dModelEndX) <= Math.Abs(dModelStartY - dModelEndY) Then
2461
                    If Math.Abs(dStartX - dEndX) >= Math.Abs(dStartY - dEndY) Then
2462
                        'Horizontal 
2463
                        ' dGap = 0.0002 'Math.Abs(dStartX - dEndX) / 20
2464
                        '기준선의 Y범위안에 가로선이 포함되어야됨
2465
                        If (dModelStartY + dGap >= dStartY And dModelEndY - dGap <= dStartY) Or
2466
                            (dModelStartY - dGap <= dStartY And dModelEndY + dGap >= dStartY) And
2467
                            (dModelStartY + dGap >= dEndY And dModelEndY - dGap <= dEndY) Or
2468
                            (dModelStartY - dGap <= dEndY And dModelEndY + dGap >= dEndY) Then
2469
                            '기준선보다 왼쪽에 가로선이 있을때
2470
                            If d기준x >= dStartX And d기준x >= dEndX Then
2471
                                If dStartX >= dEndX Then
2472
                                    'dStartX 좌표를 기준으로 Gap만큼 더했을때 기준선보다 큰지 확인
2473
                                    If dStartX + dGap >= d기준x Then
2474
                                        dStartX = d기준x
2475
                                        sBranchType = "1"
2476
                                        Return True
2477
                                    End If
2478
                                Else
2479
                                    'dEndX 좌표를 기준으로 Gap만큼 더했을때 기준선보다 큰지 확인
2480
                                    If dEndX + dGap >= d기준x Then
2481
                                        dEndX = d기준x
2482
                                        sBranchType = "2"
2483
                                        Return True
2484
                                    End If
2485
                                End If
2486
                                '기준선보다 오른쪽에 가로선이 있을때
2487
                            ElseIf d기준x <= dStartX And d기준x <= dEndX Then
2488
                                If dStartX >= dEndX Then
2489
                                    'dEndX 좌표를 기준으로 Gap만큼 뺐을때 기준선보다 작은지 확인
2490
                                    If dEndX - dGap <= d기준x Then
2491
                                        dEndX = d기준x
2492
                                        sBranchType = "2"
2493
                                        Return True
2494
                                    End If
2495
                                Else
2496
                                    'dStartX 좌표를 기준으로 Gap만큼 뺐을때 기준선보다 작은지 확인
2497
                                    If dStartX - dGap <= d기준x Then
2498
                                        dStartX = d기준x
2499
                                        sBranchType = "1"
2500
                                        Return True
2501
                                    End If
2502
                                End If
2503
                            Else
2504
                                '기준선과 세로선이 겹칠때
2505
                                If (d기준x >= dStartX And d기준x <= dEndX) Or
2506
                                        (d기준x <= dStartX And d기준x >= dEndX) Then
2507
                                    If (dModelStartY <= dStartY And dModelEndY >= dEndY) Or
2508
                                        (dModelStartY >= dStartY And dModelEndY <= dEndY) Then
2509
                                        '기준선이 dStartX와 dEndX중 어느쪽에 가까운지 확인
2510
                                        '가로선의 왼쪽점과 기준선이 가까울때는 gap만큼 뺐을때 기준선보다 작은지확인
2511
                                        '가로선의 오른쪽점과 기준선이 가까울때는 gap만큼 더했을때 기준선보다 큰지확인
2512
                                        If Math.Abs(d기준x - dStartX) >= Math.Abs(d기준x - dEndX) Then
2513
                                            'EndX점이 기준선과 더 가까이 있음
2514
                                            If dStartX >= dEndX Then
2515
                                                '가로선의 왼쪽점과 기준선이 가까우므로 gap만큼 뺐을때 기준선보다 작은지확인
2516
                                                If dEndX - dGap <= d기준x Then
2517
                                                    dEndX = d기준x
2518
                                                    sBranchType = "4"
2519
                                                    Return True
2520
                                                End If
2521
                                            Else
2522
                                                '가로선의 오른쪽점과 기준선이 가까우므로 gap만큼 더했을때 기준선보다 큰지확인
2523
                                                If dEndX + dGap >= d기준x Then
2524
                                                    dEndX = d기준x
2525
                                                    sBranchType = "4"
2526
                                                    Return True
2527
                                                End If
2528

    
2529
                                            End If
2530
                                        Else
2531
                                            'dStartX점이 기준선과 더 가까이 있음
2532
                                            If dStartX >= dEndX Then
2533
                                                '가로선의 오른쪽점과 기준선이 가까우므로 gap만큼 더했을때 기준선보다 큰지확인
2534
                                                If dStartX + dGap >= d기준x Then
2535
                                                    dStartX = d기준x
2536
                                                    sBranchType = "3"
2537
                                                    Return True
2538
                                                End If
2539

    
2540
                                            Else
2541
                                                '가로선의 왼쪽점과 기준선이 가까우므로 gap만큼 뺐을때 기준선보다 작은지확인
2542
                                                If dStartX - dGap <= d기준x Then
2543
                                                    dStartX = d기준x
2544
                                                    sBranchType = "3"
2545
                                                    Return True
2546
                                                End If
2547
                                            End If
2548
                                        End If
2549
                                    End If
2550

    
2551
                                End If
2552
                            End If
2553
                        End If
2554

    
2555
                    End If
2556
                    Else
2557
                    'Horizontal
2558
                    If Math.Abs(dModelStartX - dModelEndX) >= Math.Abs(dModelStartY - dModelEndY) Then
2559
                        'Vertical
2560
                        If Math.Abs(dStartX - dEndX) <= Math.Abs(dStartY - dEndY) Then
2561
                            '  dGap = 0.0015 'Math.Abs(dStartY - dEndY) / 80
2562

    
2563
                            '기준선의 X범위안에 세로선이 포함되어야됨
2564
                            If ((dModelStartX + dGap >= dStartX And dModelEndX - dGap <= dStartX) Or
2565
                            (dModelStartX - dGap <= dStartX And dModelEndX + dGap >= dStartX)) And
2566
                            ((dModelStartX + dGap >= dEndX And dModelEndX - dGap <= dEndX) Or
2567
                            (dModelStartX - dGap <= dEndX And dModelEndX + dGap >= dEndX)) Then
2568

    
2569

    
2570
                                '가로선보다 아래에 세로선이 있을때
2571
                                If d기준y >= dStartY And d기준y >= dEndY Then
2572
                                    If dStartY >= dEndY Then
2573
                                        'dStartY 좌표를 기준으로 Gap만큼 더했을때 기준선보다 큰지 확인
2574
                                        If dStartY + dGap >= d기준y Then
2575
                                            dStartY = d기준y
2576
                                            sBranchType = "3"
2577
                                            Return True
2578
                                        End If
2579
                                    Else
2580
                                        'dEndY 좌표를 기준으로 Gap만큼 더했을때 기준선보다 큰지 확인
2581
                                        If dEndY + dGap >= d기준y Then
2582
                                            dEndY = d기준y
2583

    
2584
                                            If Math.Abs(dEndX - dModelStartX) > Math.Abs(dEndX - dModelEndX) Then
2585
                                                dEndX = dModelEndX
2586
                                            Else
2587
                                                dEndX = dModelStartX
2588
                                            End If
2589

    
2590
                                            sBranchType = "4"
2591
                                            Return True
2592
                                        End If
2593
                                    End If
2594
                                    '기준선보다 위에 세로선이 있을때
2595
                                ElseIf d기준y <= dStartY And d기준y <= dEndY Then
2596
                                    If dStartY >= dEndY Then
2597
                                        'dEndY 좌표를 기준으로 Gap만큼 뺐을때 기준선보다 작은지 확인
2598
                                        If dEndY - dGap <= d기준y Then
2599
                                            dEndY = d기준y
2600
                                            sBranchType = "4"
2601
                                            Return True
2602
                                        End If
2603
                                    Else
2604
                                        'dStartY 좌표를 기준으로 Gap만큼 뺐을때 기준선보다 작은지 확인
2605
                                        If dStartY - dGap <= d기준y Then
2606
                                            dStartY = d기준y
2607
                                            sBranchType = "3"
2608
                                            Return True
2609
                                        End If
2610
                                    End If
2611
                                Else
2612
                                    '기준선과 세로선이 겹칠때
2613
                                    If (d기준y >= dStartY And d기준y <= dEndY) Or
2614
                                            (d기준y <= dStartY And d기준y >= dEndY) Then
2615
                                        '기준선이 dStartY와 dEndY중 어느쪽에 가까운지 확인
2616
                                        '세로선의 윗점과 기준선이 가까울때는 gap만큼 뺐을때 기준선보다 작은지확인
2617
                                        '세로선의 아래점과 기준선이 가까울때는 gap만큼 더했을때 기준선보다 큰지확인
2618
                                        If (dModelStartX <= dStartX And dModelEndX >= dEndX) Or
2619
                                            (dModelStartX >= dStartX And dModelEndX <= dEndX) Then
2620
                                            If Math.Abs(d기준y - dStartY) >= Math.Abs(d기준y - dEndY) Then
2621
                                                'Endy점이 기준선과 더 가까이 있음
2622
                                                If dStartY >= dEndY Then
2623
                                                    '세로선의 아래점과 기준선이 가까우므로 gap만큼 더했을때 기준선보다 큰지확인
2624
                                                    If dEndY + dGap >= d기준y Then
2625
                                                        dEndY = d기준y
2626
                                                        sBranchType = "4"
2627
                                                        Return True
2628
                                                    End If
2629
                                                Else
2630
                                                    '세로선의 윗점과 기준선이 가까우므로 gap만큼 뺐을때 기준선보다 작은지확인
2631
                                                    If dEndY - dGap <= d기준y Then
2632
                                                        dEndY = d기준y
2633
                                                        sBranchType = "4"
2634
                                                        Return True
2635
                                                    End If
2636
                                                End If
2637
                                            Else
2638
                                                'dStartY점이 기준선과 더 가까이 있음
2639
                                                If dStartY >= dEndY Then
2640
                                                    '세로선의 윗점과 기준선이 가까우므로 gap만큼 뺐을때 기준선보다 작은지확인
2641
                                                    If dStartY - dGap <= d기준y Then
2642
                                                        dStartY = d기준y
2643
                                                        sBranchType = "3"
2644
                                                        Return True
2645
                                                    End If
2646
                                                Else
2647
                                                    '세로선의 아래점과 기준선이 가까우므로 gap만큼 더했을때 기준선보다 큰지확인
2648
                                                    If dStartY + dGap >= d기준y Then
2649
                                                        dStartY = d기준y
2650
                                                        sBranchType = "3"
2651
                                                        Return True
2652
                                                    End If
2653
                                                End If
2654
                                            End If
2655
                                        End If
2656

    
2657
                                    End If
2658
                                End If
2659

    
2660

    
2661
                            End If
2662

    
2663
                        End If
2664
                    End If
2665
                End If
2666
            Next
2667
        Catch ex As Exception
2668

    
2669
        End Try
2670
        oLMConnector = Nothing
2671
        Return False
2672
    End Function
2673

    
2674
    Private Sub OPCTOLineRouting(ByRef oLine_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal oOPCSymbol As LMSymbol,
2675
                            ByVal sOPCUid As String, ByVal sLineNoUid As String)
2676
        Try
2677
            Dim oDatasource As Object = _Placement.PIDDataSource
2678
            Dim objItem As LMAItem
2679
            Dim objConnector As LMConnector
2680
            Dim objInputs As PlaceRunInputs
2681
            objInputs = New PlaceRunInputs
2682
            Dim dOriginalStart_x As Double = 0.0
2683
            Dim dOriginalStart_y As Double = 0.0
2684
            Dim dOriginalEnd_x As Double = 0.0
2685
            Dim dOriginalEnd_y As Double = 0.0
2686
            Dim dStart_x As Double = 0.0
2687
            Dim dStart_y As Double = 0.0
2688
            Dim dEnd_x As Double = 0.0
2689
            Dim dEnd_y As Double = 0.0
2690

    
2691
            Dim oPipeRun As LMPipeRun = Nothing
2692
            Dim sStartpoint As String = ""
2693
            Dim sEndpoint As String = ""
2694
            Dim iConnType As Integer = 0
2695
            Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_Conn1_Uid & " = '" + sOPCUid + "' And [" &
2696
                                                                                       _XML_SYMBOL_Check & "] = 'TRUE'")
2697
            Dim sPipeUid As String = ""
2698
            If oPipeRow.Length = 0 Then
2699
                oPipeRow = oLine_Dt.Select(_XML_LINE_Conn2_Uid & " = '" + sOPCUid + "' And [" &
2700
                        _XML_SYMBOL_Check & "] = 'TRUE'")
2701
            Else
2702
                sPipeUid = oPipeRow(0)(_XML_LINE_UID).ToString()
2703
                iConnType = 1
2704
            End If
2705
            Dim oAddUid_List As New List(Of String)
2706
            If oPipeRow.Length = 1 Then
2707
                If sPipeUid = "" Then
2708
                    sPipeUid = oPipeRow(0)(_XML_LINE_UID).ToString()
2709
                    iConnType = 2
2710
                End If
2711
                oAddUid_List.Add(sPipeUid)
2712
                sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
2713
                sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
2714
                ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
2715
                dStart_x = dOriginalStart_x
2716
                dStart_y = dOriginalStart_y
2717
                ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
2718
                dEnd_x = dOriginalEnd_x
2719
                dEnd_y = dOriginalEnd_y
2720
                ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
2721
                ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
2722

    
2723
                'OPC Connection Point가져와서 연결(2018-07-12)
2724
                If iConnType = 1 Then
2725
                    FindNearPoint(oOPCSymbol, dStart_x, dStart_y)
2726
                    objInputs.AddSymbolTarget(oOPCSymbol, dStart_x, dStart_y)
2727
                    objInputs.AddPoint(dEnd_x, dEnd_y)
2728
                Else
2729
                    FindNearPoint(oOPCSymbol, dEnd_x, dEnd_y)
2730
                    objInputs.AddSymbolTarget(oOPCSymbol, dEnd_x, dEnd_y)
2731
                    objInputs.AddPoint(dStart_x, dStart_y)
2732
                End If
2733
                oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
2734

    
2735
                While True
2736
                    '    objInputs.Clear()
2737
                    Dim oAddPipeRow() As DataRow = oLine_Dt.Select("[" & _XML_LINE_Conn1_Uid & "] = '" + sPipeUid + "' and " &
2738
                                                                 "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And [" &
2739
                                                                                       _XML_SYMBOL_Check & "] = 'TRUE'")
2740
                    If oAddPipeRow.Length = 0 Then
2741
                        oAddPipeRow = oLine_Dt.Select("[" & _XML_LINE_Conn2_Uid & "] = '" + sPipeUid + "' and " &
2742
                                                                 "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And [" &
2743
                                                                                       _XML_SYMBOL_Check & "] = 'TRUE'")
2744
                        sPipeUid = ""
2745
                    Else
2746
                        iConnType = 1
2747
                        sPipeUid = oAddPipeRow(0)(_XML_LINE_UID).ToString()
2748
                    End If
2749
                    If oAddPipeRow.Length = 1 Then
2750
                        If sPipeUid = "" Then
2751
                            sPipeUid = oAddPipeRow(0)(_XML_LINE_UID).ToString()
2752
                            iConnType = 2
2753
                        End If
2754
                        oAddUid_List.Add(sPipeUid)
2755
                        sStartpoint = oAddPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
2756
                        sEndpoint = oAddPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
2757
                        ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
2758
                        dStart_x = dOriginalStart_x
2759
                        dStart_y = dOriginalStart_y
2760
                        ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
2761
                        dEnd_x = dOriginalEnd_x
2762
                        dEnd_y = dOriginalEnd_y
2763
                        ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
2764
                        ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
2765
                        If iConnType = 1 Then
2766
                            objInputs.AddPoint(dEnd_x, dEnd_y)
2767
                            ' objInputs.AddPoint(dStart_x, dStart_y)
2768
                        Else
2769
                            'objInputs.AddConnectorTarget(objConnector, dStart_x, dStart_y)
2770
                            '  objInputs.AddPoint(dStart_x, dStart_y)
2771
                            '  objInputs.AddPoint(dEnd_x, dEnd_y)
2772
                            objInputs.AddPoint(dStart_x, dStart_y)
2773
                        End If
2774

    
2775
                        oAddPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
2776
                    Else
2777
                        Exit While
2778
                    End If
2779

    
2780
                End While
2781
                Dim sType As String = oPipeRow(0)(_XML_LINE_TYPE).ToString()
2782
                Dim sSystemPath As String = GetPipeType(sType)
2783

    
2784
                objItem = _Placement.PIDCreateItem(sSystemPath)
2785
                objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
2786
                For i = 0 To oAddUid_List.Count - 1
2787
                    Dim oUpdateRow As DataRow() = oLine_Dt.Select(_XML_LINE_UID & " = '" + oAddUid_List(i) + "'")
2788
                    If oUpdateRow.Length = 1 Then
2789
                        oUpdateRow(0)(_XML_LINE_SPID) = objConnector.ModelItemID
2790
                        oUpdateRow(0)(_XML_LINE_LMCONNECTOR) = objConnector
2791
                    End If
2792
                Next
2793

    
2794

    
2795
                oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
2796
                Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
2797
                If oAttributeRow.Length > 0 Then
2798
                    For Each oAttribute In oAttributeRow
2799
                        Try
2800
                            Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
2801
                            Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
2802
                            If sPIDValue.Contains("'") Then
2803
                                sPIDValue = sPIDValue.Replace("'", """")
2804
                            End If
2805
                            Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
2806
                            oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
2807
                        Catch ex As Exception
2808
                        End Try
2809
                    Next
2810
                    oPipeRun.Commit()
2811
                End If
2812

    
2813
            End If
2814

    
2815
        Catch ex As Exception
2816
        End Try
2817
    End Sub
2818

    
2819
    Private Function AddUidList중복체크(ByVal sUidList As List(Of String), ByVal sAddUid As String) As Boolean
2820

    
2821
        For Each sUid In sUidList
2822
            If sUid = sAddUid Then
2823
                Return False
2824
            End If
2825
        Next
2826
        Return True
2827
    End Function
2828

    
2829
    Private Sub LineRouting(ByRef oLine_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal sLineNoUid As String)
2830
        Try
2831
            Dim oDatasource As Object = _Placement.PIDDataSource
2832
            Dim objItem As LMAItem
2833
            Dim objConnector As LMConnector
2834
            Dim objInputs As PlaceRunInputs
2835
            objInputs = New PlaceRunInputs
2836
            Dim dOriginalStart_x As Double = 0.0
2837
            Dim dOriginalStart_y As Double = 0.0
2838
            Dim dOriginalEnd_x As Double = 0.0
2839
            Dim dOriginalEnd_y As Double = 0.0
2840
            Dim dStart_x As Double = 0.0
2841
            Dim dStart_y As Double = 0.0
2842
            Dim dEnd_x As Double = 0.0
2843
            Dim dEnd_y As Double = 0.0
2844
            Dim oPipeRun As LMPipeRun = Nothing
2845
            Dim sStartpoint As String = ""
2846
            Dim sEndpoint As String = ""
2847
            Dim iConnType As Integer = 0
2848
            Dim pLMConnector As LMConnector = Nothing
2849
            For Each oLinerow In oLine_Dt.Rows
2850
                Dim sPipeUid As String = oLinerow(_XML_LINE_UID).ToString()
2851
                Dim sCheckModeling As Boolean = False
2852
                objInputs.Clear()
2853
                Dim oAddUid_List As New List(Of String)
2854
                Try
2855
                    Dim oAddPipeRow() As DataRow = oLine_Dt.Select("[" & _XML_LINE_Conn1_Uid & "] = '" + sPipeUid + "' and " &
2856
                                                            "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And [" &
2857
                                                            _XML_SYMBOL_Check & "] = 'TRUE'")
2858
                    If oAddPipeRow.Length = 0 Then
2859
                        oAddPipeRow = oLine_Dt.Select("[" & _XML_LINE_Conn2_Uid & "] = '" + sPipeUid + "' and " &
2860
                                                        "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And [" &
2861
                                                        _XML_SYMBOL_Check & "] = 'TRUE'")
2862
                        sPipeUid = ""
2863
                    Else
2864
                        iConnType = 1
2865
                        sPipeUid = oAddPipeRow(0)(_XML_LINE_UID).ToString()
2866
                    End If
2867
                    If oAddPipeRow.Length = 1 Then
2868
                        sCheckModeling = True
2869
                        If sPipeUid = "" Then
2870
                            sPipeUid = oAddPipeRow(0)(_XML_LINE_UID).ToString()
2871
                            iConnType = 2
2872
                        End If
2873
                        If AddUidList중복체크(oAddUid_List, sPipeUid) Then
2874
                            oAddUid_List.Add(sPipeUid)
2875
                        End If
2876
                        sStartpoint = oAddPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
2877
                        sEndpoint = oAddPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
2878
                        ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
2879
                        dStart_x = dOriginalStart_x
2880
                        dStart_y = dOriginalStart_y
2881
                        ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
2882
                        dEnd_x = dOriginalEnd_x
2883
                        dEnd_y = dOriginalEnd_y
2884
                        ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
2885
                        ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
2886
                        Dim sBranchType As String = ""
2887
                        If (CheckBranchLine(oLine_Dt, dStart_x, dStart_y, dEnd_x, dEnd_y, sBranchType, pLMConnector)) Then
2888
                            Try
2889
                                If pLMConnector Is Nothing Then
2890
                                    objInputs.AddPoint(dStart_x, dStart_y)
2891
                                    objInputs.AddPoint(dEnd_x, dEnd_y)
2892
                                Else
2893
                                    If sBranchType = "1" Then
2894
                                        objInputs.AddConnectorTarget(pLMConnector, dStart_x, dStart_y)
2895
                                        objInputs.AddPoint(dEnd_x, dEnd_y)
2896
                                    ElseIf sBranchType = "2" Then
2897
                                        objInputs.AddConnectorTarget(pLMConnector, dEnd_x, dEnd_y)
2898
                                        objInputs.AddPoint(dStart_x, dStart_y)
2899
                                    ElseIf sBranchType = "3" Then
2900
                                        objInputs.AddConnectorTarget(pLMConnector, dStart_x, dStart_y)
2901
                                        objInputs.AddPoint(dEnd_x, dEnd_y)
2902
                                    ElseIf sBranchType = "4" Then
2903
                                        objInputs.AddConnectorTarget(pLMConnector, dEnd_x, dEnd_y)
2904
                                        objInputs.AddPoint(dStart_x, dStart_y)
2905
                                    End If
2906
                                End If
2907
                            Catch ex As Exception
2908
                            End Try
2909
                        Else
2910
                            objInputs.AddPoint(dStart_x, dStart_y)
2911
                            objInputs.AddPoint(dEnd_x, dEnd_y)
2912
                        End If
2913
                        oAddPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
2914
                    Else
2915
                        Dim CheckTF As String = oLinerow(_XML_LINE_DRAWING_TF).ToString()
2916
                        Dim CheckSelect As String = oLinerow(_XML_LINE_Check).ToString()
2917
                        If CheckTF = "FALSE" And CheckSelect = "TRUE" Then
2918
                            sPipeUid = oLinerow(_XML_LINE_UID).ToString()
2919
                            oAddUid_List.Clear()
2920
                            oAddUid_List.Add(sPipeUid)
2921
                            sCheckModeling = True
2922
                            sStartpoint = oLinerow(_XML_LINE_STARTPOINT).ToString()
2923
                            sEndpoint = oLinerow(_XML_LINE_ENDPOINT).ToString()
2924
                            ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
2925
                            dStart_x = dOriginalStart_x
2926
                            dStart_y = dOriginalStart_y
2927
                            ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
2928
                            dEnd_x = dOriginalEnd_x
2929
                            dEnd_y = dOriginalEnd_y
2930
                            ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
2931
                            ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
2932
                            Dim sBranchType As String = ""
2933
                            If (CheckBranchLine(oLine_Dt, dStart_x, dStart_y, dEnd_x, dEnd_y, sBranchType, pLMConnector)) Then
2934
                                Try
2935
                                    If sBranchType = "1" Then
2936
                                        objInputs.AddPoint(dEnd_x, dEnd_y)
2937
                                        objInputs.AddConnectorTarget(pLMConnector, dStart_x, dStart_y)
2938
                                    ElseIf sBranchType = "2" Then
2939
                                        objInputs.AddPoint(dStart_x, dStart_y)
2940
                                        objInputs.AddConnectorTarget(pLMConnector, dEnd_x, dEnd_y)
2941
                                    ElseIf sBranchType = "3" Then
2942
                                        objInputs.AddPoint(dEnd_x, dEnd_y)
2943
                                        objInputs.AddConnectorTarget(pLMConnector, dStart_x, dStart_y)
2944
                                    ElseIf sBranchType = "4" Then
2945
                                        objInputs.AddPoint(dStart_x, dStart_y)
2946
                                        objInputs.AddConnectorTarget(pLMConnector, dEnd_x, dEnd_y)
2947

    
2948

    
2949
                                    End If
2950
                                Catch ex As Exception
2951

    
2952
                                End Try
2953
                            Else
2954
                                objInputs.AddPoint(dStart_x, dStart_y)
2955
                                objInputs.AddPoint(dEnd_x, dEnd_y)
2956
                            End If
2957
                            oLinerow(_XML_LINE_DRAWING_TF) = "TRUE"
2958
                        End If
2959
                    End If
2960
                Catch ex As Exception
2961
                End Try
2962
                If sCheckModeling Then
2963
                    Dim sType As String = oLinerow(_XML_LINE_TYPE).ToString()
2964
                    Dim sSystemPath As String = GetPipeType(sType)
2965
                    objItem = _Placement.PIDCreateItem(sSystemPath)
2966
                    objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
2967
                    For i = 0 To oAddUid_List.Count - 1
2968
                        Dim oUpdateRow As DataRow() = oLine_Dt.Select(_XML_LINE_UID & " = '" + oAddUid_List(i) + "'")
2969
                        If oUpdateRow.Length = 1 Then
2970
                            oUpdateRow(0)(_XML_LINE_SPID) = objConnector.ModelItemID
2971
                            oUpdateRow(0)(_XML_LINE_LMCONNECTOR) = objConnector
2972
                        End If
2973
                    Next
2974

    
2975
                    oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
2976
                    oAddUid_List.Clear()
2977

    
2978
                    Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
2979
                    If oAttributeRow.Length > 0 Then
2980
                        For Each oAttribute In oAttributeRow
2981
                            Try
2982
                                Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
2983
                                Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
2984
                                If sPIDValue.Contains("'") Then
2985
                                    sPIDValue = sPIDValue.Replace("'", """")
2986
                                End If
2987
                                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
2988
                                oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
2989
                            Catch ex As Exception
2990
                            End Try
2991
                        Next
2992
                        oPipeRun.Commit()
2993
                    End If
2994

    
2995
                    If pLMConnector IsNot Nothing Then
2996
                        Dim sID_1 As String = pLMConnector.ModelItemID
2997
                        Dim sID_2 As String = objConnector.ModelItemID
2998
                        Dim objSurvivorItem As LMAItem = Nothing
2999
                        Dim oPipeRun1 As LMPipeRun = oDatasource.GetPipeRun(sID_1)
3000
                        Dim oPipeRun2 As LMPipeRun = oDatasource.GetPipeRun(sID_2)
3001
                        _Placement.PIDJoinRuns(oPipeRun1, oPipeRun2)
3002
                        '     oDatasource.CommitTransaction()
3003
                        '_Placement.PIDAutoJoin(oPipeRun1.AsLMAItem, AutoJoinEndConstants.autoJoin_End, objSurvivorItem)
3004
                        'oPipeRun1.Commit()
3005
                        'oDatasource.CommitTransaction()
3006
                        'objSurvivorItem = Nothing
3007
                        '_Placement.PIDAutoJoin(oPipeRun2.AsLMAItem, AutoJoinEndConstants.autoJoin_Start, objSurvivorItem)
3008
                        'oPipeRun2.Commit()
3009
                        'oDatasource.CommitTransaction()
3010
                    End If
3011
                    sCheckModeling = False
3012
                End If
3013
            Next
3014
        Catch ex As Exception
3015
        End Try
3016
    End Sub
3017

    
3018

    
3019
    Private Sub SymbolModeling(ByVal CDrawing As Drawing, ByVal oSymbolRow As DataRow, ByVal oAttribute_Dt As DataTable)
3020
        Try
3021
            Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID).ToString()
3022
            Dim sConnTypeNo As String = ""
3023
            ' Line과 연결되어있는 Symbol인지 확인
3024
            Dim oLine_Dt As DataTable = GetPipeFromConnection(CDrawing, sSymbolUid, sConnTypeNo)
3025
            'Symbol과 연결되어 있는 Symbol인지 확인
3026
            Dim oSymbol_Dt As DataTable = GetSymbolFromConnection(CDrawing, sSymbolUid, sConnTypeNo)
3027
            Dim oSymbol As LMSymbol = Nothing
3028
            Dim sSPID As String = oSymbolRow(_XML_SYMBOL_SPID).ToString()
3029
            Dim sSystemPath As String = oSymbolRow(_XML_SYMBOL_SYSTEMPATH).ToString()
3030
            Dim oDatasource As Object = _Placement.PIDDataSource
3031
            Dim sSymbolCompType As String = oSymbolRow(_XML_SYMBOL_TYPE).ToString()
3032

    
3033
            Dim dAngle As Double = 0.0
3034
            If IsNumeric(oSymbolRow(_XML_SYMBOL_ANGLE).ToString()) Then
3035
                dAngle = Double.Parse(oSymbolRow(_XML_SYMBOL_ANGLE).ToString())
3036
            End If
3037

    
3038
            Dim dLocationX As Double = 0.0
3039
            Dim dLocationY As Double = 0.0
3040
            Dim dX As Double = 0.0
3041
            Dim dY As Double = 0.0
3042
            Dim sOriginalPoint As String = oSymbolRow(_XML_SYMBOL_ORIGINALPOINT).ToString()
3043
            ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY)
3044
            dX = dLocationX
3045
            dY = dLocationY
3046
            ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
3047
            Dim bCheckModeling As Boolean = False
3048

    
3049
            If oLine_Dt.Rows.Count > 0 Then
3050

    
3051
                If sSPID <> "" Then
3052
                    Dim dX1 As Double = 0
3053
                    Dim dX2 As Double = 0
3054
                    Dim dY1 As Double = 0
3055
                    Dim dY2 As Double = 0
3056
                    Dim oLMSymbol As LMSymbol = oDatasource.GetSymbol(sSPID)
3057
                    _Placement.PIDConnectPointLocation(oLMSymbol, 1, dX1, dY1)
3058
                    _Placement.PIDConnectPointLocation(oLMSymbol, 2, dX2, dY2)
3059

    
3060
                    Dim dCalcPoint As Double = -1
3061
                    Dim dModeling_X As Double = 0
3062
                    Dim dModeling_Y As Double = 0
3063
                    If dX1 <> 0 And dY1 <> 0 Then
3064
                        dCalcPoint = Math.Abs(dX1 - dX) + Math.Abs(dY1 - dY)
3065
                        dModeling_X = dX1
3066
                        dModeling_Y = dY1
3067
                    End If
3068
                    If dX2 <> 0 And dY2 <> 0 Then
3069

    
3070
                        If (Math.Abs(dX2 - dX) + Math.Abs(dY2 - dY) > dCalcPoint) Then
3071
                            dCalcPoint = Math.Abs(dX2 - dX) + Math.Abs(dY2 - dY)
3072
                            dModeling_X = dX2
3073
                            dModeling_Y = dY2
3074
                        End If
3075
                    End If
3076

    
3077

    
3078

    
3079
                    If dModeling_X <> 0 And dModeling_Y <> 0 Then
3080
                        oSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dModeling_X, dModeling_Y,, dAngle, ExistingItem:=oLMSymbol.AsLMAItem,
3081
                            TargetItem:=oLMSymbol.AsLMRepresentation)
3082
                        bCheckModeling = True
3083
                    End If
3084

    
3085

    
3086
                End If
3087
            End If
3088
            If oSymbol_Dt.Rows.Count > 0 Then
3089
                If sSPID <> "" Then
3090
                    Dim dX1 As Double = 0
3091
                    Dim dX2 As Double = 0
3092
                    Dim dX3 As Double = 0
3093
                    Dim dX4 As Double = 0
3094
                    Dim dY1 As Double = 0
3095
                    Dim dY2 As Double = 0
3096
                    Dim dY3 As Double = 0
3097
                    Dim dY4 As Double = 0
3098
                    Dim oLMSymbol As LMSymbol = oDatasource.GetSymbol(sSPID)
3099
                    _Placement.PIDConnectPointLocation(oLMSymbol, 1, dX1, dY1)
3100
                    _Placement.PIDConnectPointLocation(oLMSymbol, 2, dX2, dY2)
3101
                    _Placement.PIDConnectPointLocation(oLMSymbol, 3, dX3, dY3)
3102
                    _Placement.PIDConnectPointLocation(oLMSymbol, 4, dX4, dY4)
3103

    
3104
                    Dim dCalcPoint As Double = -1
3105
                    Dim dModeling_X As Double = 0
3106
                    Dim dModeling_Y As Double = 0
3107
                    If dX1 <> 0 And dY1 <> 0 Then
3108
                        dCalcPoint = Math.Abs(dX1 - dX) + Math.Abs(dY1 - dY)
3109
                        dModeling_X = dX1
3110
                        dModeling_Y = dY1
3111
                    End If
3112
                    If dX2 <> 0 And dY2 <> 0 Then
3113

    
3114
                        If (Math.Abs(dX2 - dX) + Math.Abs(dY2 - dY) > dCalcPoint) Then
3115
                            dCalcPoint = Math.Abs(dX2 - dX) + Math.Abs(dY2 - dY)
3116
                            dModeling_X = dX2
3117
                            dModeling_Y = dY2
3118
                        End If
3119
                    End If
3120
                    If dX3 <> 0 And dY3 <> 0 Then
3121
                        If (Math.Abs(dX3 - dX) + Math.Abs(dY3 - dY) > dCalcPoint) Then
3122
                            dCalcPoint = Math.Abs(dX3 - dX) + Math.Abs(dY3 - dY)
3123
                            dModeling_X = dX3
3124
                            dModeling_Y = dY3
3125
                        End If
3126
                    End If
3127
                    If dX4 <> 0 And dY4 <> 0 Then
3128
                        If (Math.Abs(dX4 - dX) + Math.Abs(dY4 - dY) > dCalcPoint) Then
3129
                            dCalcPoint = Math.Abs(dX4 - dX) + Math.Abs(dY4 - dY)
3130
                            dModeling_X = dX4
3131
                            dModeling_Y = dY4
3132
                        End If
3133
                    End If
3134
                    If dModeling_X <> 0 And dModeling_Y <> 0 Then
3135
                        oSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dModeling_X, dModeling_Y,, dAngle, ExistingItem:=oLMSymbol.AsLMAItem,
3136
                            TargetItem:=oLMSymbol.AsLMRepresentation)
3137
                        bCheckModeling = True
3138
                    End If
3139

    
3140

    
3141
                End If
3142

    
3143
            End If
3144

    
3145
            If (oLine_Dt.Rows.Count = 0 And oSymbol_Dt.Rows.Count = 0) Or bCheckModeling = False Then
3146
                oSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
3147
                SetListBoxItems(ListBox_Result, "Place Fittings..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
3148
                _iFittingcnt = _iFittingcnt + 1
3149
            End If
3150
            Dim oAttributeRow() As DataRow
3151
            oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sSymbolUid + "'")
3152
            If oAttribute_Dt.Rows.Count > 0 Then
3153

    
3154
                If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
3155
                    Dim oInstrument As LMInstrument
3156
                    oInstrument = oDatasource.GetInstrument(oSymbol.ModelItemID)
3157
                    Try
3158
                        If oAttributeRow.Length > 0 Then
3159
                            For Each oAttribute In oAttributeRow
3160
                                Try
3161
                                    Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
3162
                                    Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
3163
                                    Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
3164
                                    oInstrument.Attributes(sSPPIDAttribute).Value = sPIDValue
3165
                                Catch ex As Exception
3166
                                End Try
3167
                            Next
3168
                            oInstrument.Commit()
3169
                        End If
3170
                    Catch ex As Exception
3171
                    End Try
3172
                Else
3173
                    Try
3174
                        If oAttributeRow.Length > 0 And oSymbol IsNot Nothing Then
3175
                            For Each oAttribute In oAttributeRow
3176
                                Try
3177
                                    Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
3178
                                    Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
3179

    
3180
                                    If sPIDAttribute = "SIZE" Then
3181

    
3182
                                        'Nominal diamter1,2속성이름뭔지 찾아봐야됨 (2018-07-20)
3183
                                        If sPIDValue.Contains("x") Then
3184
                                            Dim sSplitSize() As String = sPIDValue.Split("x")
3185
                                            If sSplitSize.Count > 1 Then
3186
                                                'Connection Point와 연결되어 있는 라인을 가져와서 라인프로퍼티를 변경
3187
                                                Dim oConnector_1 As LMConnector = Nothing
3188
                                                Dim oConnector_2 As LMConnector = Nothing
3189
                                                If oSymbol IsNot Nothing Then
3190
                                                    If oSymbol.Connect1Connectors.Count >= 1 Then
3191
                                                        For Each Tconnector In oSymbol.Connect1Connectors
3192
                                                            If Tconnector.ItemStatus = "Active" Then
3193
                                                                If Tconnector.ModelItemObject.ItemTypeName = "PipeRun" Then
3194
                                                                    oConnector_1 = Tconnector
3195
                                                                End If
3196
                                                            End If
3197
                                                        Next
3198
                                                    End If
3199
                                                    If oSymbol.Connect1Connectors.Count >= 1 Then
3200
                                                        For Each Tconnector In oSymbol.Connect1Connectors
3201
                                                            If Tconnector.ItemStatus = "Active" Then
3202
                                                                If Tconnector.ModelItemObject.ItemTypeName = "PipeRun" Then
3203
                                                                    oConnector_2 = Tconnector
3204
                                                                End If
3205
                                                            End If
3206
                                                        Next
3207
                                                    End If
3208
                                                End If
3209
                                                Dim oPipeRun1 As LMPipeRun = oDatasource.GetPipeRun(oConnector_1.ModelItemID)
3210
                                                Dim oPipeRun2 As LMPipeRun = oDatasource.GetPipeRun(oConnector_2.ModelItemID)
3211
                                                If dAngle = 3.14 Then
3212
                                                    oPipeRun1.Attributes("NominalDiameter").Value = sSplitSize(1)
3213
                                                    oPipeRun2.Attributes("NominalDiameter").Value = sSplitSize(0)
3214
                                                Else
3215
                                                    oPipeRun1.Attributes("NominalDiameter").Value = sSplitSize(0)
3216
                                                    oPipeRun2.Attributes("NominalDiameter").Value = sSplitSize(1)
3217
                                                End If
3218

    
3219

    
3220
                                            End If
3221

    
3222
                                        Else
3223
                                            Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
3224
                                            oSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
3225
                                        End If
3226
                                    Else
3227
                                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
3228
                                        oSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
3229
                                    End If
3230

    
3231
                                Catch ex As Exception
3232
                                End Try
3233
                            Next
3234
                            oSymbol.Commit()
3235
                        End If
3236
                    Catch ex As Exception
3237
                    End Try
3238
                End If
3239
            End If
3240
        Catch ex As Exception
3241
        End Try
3242
    End Sub
3243

    
3244
    Private Function SymbolModeling(ByVal oSymbol_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal sLineNoUid As String, ByVal oSymbolRow As DataRow) As Boolean
3245
        Try
3246
            Dim oAttributeRow() As DataRow
3247
            Dim sUid As String = oSymbolRow(_XML_SYMBOL_UID).ToString()
3248
            If oAttribute_Dt.Rows.Count > 0 Then
3249
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
3250
                Dim oDatasource As Object = _Placement.PIDDataSource
3251
                Dim sSymbolCompType As String = oSymbolRow(_XML_SYMBOL_TYPE).ToString()
3252
                Dim sSystemPath As String = oSymbolRow(_XML_SYMBOL_SYSTEMPATH).ToString()
3253
                Dim sClass As String = oSymbolRow(_XML_SYMBOL_CLASS).ToString()
3254
                Dim sLocation As String = oSymbolRow(_XML_SYMBOL_LOCATION).ToString()
3255
                Dim sOriginalPoint As String = oSymbolRow(_XML_SYMBOL_ORIGINALPOINT).ToString()
3256
                Dim dAngle As Double = 0.0
3257
                If IsNumeric(oSymbolRow(_XML_SYMBOL_ANGLE).ToString()) Then
3258
                    dAngle = Double.Parse(oSymbolRow(_XML_SYMBOL_ANGLE).ToString())
3259
                End If
3260
                Dim objSymbol As LMSymbol
3261
                Dim dLocationX As Double = 0.0
3262
                Dim dLocationY As Double = 0.0
3263
                Dim dX As Double = 0.0
3264
                Dim dY As Double = 0.0
3265
                If ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY) Then
3266
                    dX = dLocationX
3267
                    dY = dLocationY
3268
                    ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
3269
                    Dim oInstrument As LMInstrument
3270
                    If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
3271
                        _iInstrumentcnt = _iInstrumentcnt + 1
3272
                        objSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
3273
                        SetListBoxItems(ListBox_Result, "Place Instrument..(" & dLocationX & "," & dLocationY & ")..." & _iInstrumentcnt & " count ")
3274
                        oInstrument = oDatasource.GetInstrument(objSymbol.ModelItemID)
3275
                        Try
3276
                            If oAttributeRow.Length > 0 Then
3277
                                For Each oAttribute In oAttributeRow
3278
                                    Try
3279
                                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
3280
                                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
3281
                                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
3282
                                        oInstrument.Attributes(sSPPIDAttribute).Value = sPIDValue
3283
                                    Catch ex As Exception
3284
                                    End Try
3285
                                Next
3286
                                oInstrument.Commit()
3287
                            End If
3288
                        Catch ex As Exception
3289
                        End Try
3290
                    ElseIf sSymbolCompType.ToUpper() = _DB_FITTINGS.ToUpper() Then
3291
                        _iValvecnt = _iValvecnt + 1
3292
                        _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
3293
                        SetListBoxItems(ListBox_Result, "Place Valve..(" & dLocationX & "," & dLocationY & ")..." & _iValvecnt & " count ")
3294
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_FITTINGS.ToUpper() Then
3295
                        _iFittingcnt = _iFittingcnt + 1
3296
                        If sSystemPath.Contains(",") Then
3297
                            Dim sDuplicatePath As String() = sSystemPath.Split(",")
3298
                            Dim sMainSymbol As String = ""
3299
                            Dim sSubSymbol As String = ""
3300
                            For Each sPath In sDuplicatePath
3301
                                If sMainSymbol = "" Then
3302
                                    sMainSymbol = sPath.Replace(vbLf, "")
3303
                                Else
3304
                                    sSubSymbol = sPath.Replace(vbLf, "")
3305
                                End If
3306
                            Next
3307
                            Dim oSymbolObj As LMSymbol = _Placement.PIDPlaceSymbol(sMainSymbol, dX, dY, , dAngle)
3308
                            Dim dConnpos_x As Double = 0.0
3309
                            Dim dConnpos_y As Double = 0.0
3310
                            _Placement.PIDConnectPointLocation(oSymbolObj, 2, dConnpos_x, dConnpos_y)
3311
                            '   _Placement.PIDPlaceSymbol(sSubSymbol, dConnpos_x, dConnpos_y, dAngle, TargetItem:=oSymbolObj.AsLMRepresentation)
3312
                            _Placement.PIDPlaceSymbol(sSubSymbol, dConnpos_x, dConnpos_y,, dAngle)
3313
                        Else
3314
                            _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
3315
                        End If
3316
                        SetListBoxItems(ListBox_Result, "Place Fitting..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
3317
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() And sClass.ToUpper() = _SYMBOL_ACTUATORS.ToUpper() Then
3318
                        _iFittingcnt = _iFittingcnt + 1
3319
                        Dim sDuplicatePath As String() = sSystemPath.Split(",")
3320
                        Dim sMainSymbol As String = ""
3321
                        Dim sSubSymbol As String = ""
3322
                        For Each sPath In sDuplicatePath
3323
                            If sMainSymbol = "" Then
3324
                                sMainSymbol = sPath.Replace(vbLf, "")
3325
                            Else
3326
                                sSubSymbol = sPath.Replace(vbLf, "")
3327
                            End If
3328
                        Next
3329
                        Dim oSymbolObj As LMSymbol = _Placement.PIDPlaceSymbol(sMainSymbol, dX, dY, , dAngle)
3330
                        Dim dSymbolpos_x As Double = oSymbolObj.XCoordinate
3331
                        Dim dSymbolpos_y As Double = oSymbolObj.YCoordinate
3332
                        _Placement.PIDPlaceSymbol(sSubSymbol, dSymbolpos_x, dSymbolpos_y, , dAngle, TargetItem:=oSymbolObj.AsLMAItem)
3333
                    Else
3334
                        _iFittingcnt = _iFittingcnt + 1
3335
                        _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
3336
                        SetListBoxItems(ListBox_Result, "Place Fitting..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
3337
                    End If
3338
                    oSymbolRow(_XML_SYMBOL_DRAWING_TF) = "TRUE"
3339
                End If
3340
                _Itemcnt = _Itemcnt + 1
3341
                Dim dCalcProgressValue As Double = (_Itemcnt / _allItem) * 100
3342
                SetProgressbar(ProgressBar_Status, dCalcProgressValue)
3343
                Label_Progress.Text = Math.Round(dCalcProgressValue, 0) & "%"
3344
            End If
3345
        Catch ex As Exception
3346
            Return False
3347
        End Try
3348
    End Function
3349

    
3350
    Private Function CheckOPCConnectionLine(ByVal oOpcRow As DataRow, ByVal oLine_Dt As DataTable) As String
3351
        'Dim sLineUid As String = ""
3352
        'Try
3353

    
3354
        '    For Each oLinerow In oLine_Dt.Rows
3355

    
3356
        '        Dim oOpcConn_x1 As Double = oOpcRow(_Modeling_Connection1_X)
3357
        '        Dim oOpcConn_y1 As Double = oOpcRow(_Modeling_Connection1_Y)
3358
        '        Dim oOpcConn_x2 As Double = oOpcRow(_Modeling_Connection2_X)
3359
        '        Dim oOpcConn_y2 As Double = oOpcRow(_Modeling_Connection2_Y)
3360
        '        Dim oAngle As Double = oOpcRow(_Modeling_Angle)
3361
        '        Dim dOriginalStart_x As Double = 0.0
3362
        '        Dim dOriginalStart_y As Double = 0.0
3363
        '        Dim dOriginalEnd_x As Double = 0.0
3364
        '        Dim dOriginalEnd_y As Double = 0.0
3365
        '        Dim dStart_x As Double = 0.0
3366
        '        Dim dStart_y As Double = 0.0
3367
        '        Dim dEnd_x As Double = 0.0
3368
        '        Dim dEnd_y As Double = 0.0
3369
        '        Dim sStartpoint As String = oLinerow(_XML_LINE_STARTPOINT).ToString()
3370
        '        Dim sEndpoint As String = oLinerow(_XML_LINE_ENDPOINT).ToString()
3371
        '        Dim sPipeUid As String = oLinerow(_XML_LINE_UID).ToString()
3372

    
3373
        '        ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
3374
        '        dStart_x = dOriginalStart_x
3375
        '        dStart_y = dOriginalStart_y
3376

    
3377
        '        ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
3378
        '        dEnd_x = dOriginalEnd_x
3379
        '        dEnd_y = dOriginalEnd_y
3380

    
3381

    
3382
        '        If Math.Abs(oOpcConn_x1 - oOpcConn_x2) > Math.Abs(oOpcConn_y1 - oOpcConn_y2) Then
3383
        '            '가로 OPC
3384
        '            Dim dCalcY As Double = (oOpcConn_y1 + oOpcConn_y2) / 2
3385
        '            If (dStart_x >= oOpcConn_x2 And dStart_x <= oOpcConn_x1 And
3386
        '                   dStart_y < dCalcY + 100 And dStart_y > dCalcY - 100) Or
3387
        '                   (dStart_x >= oOpcConn_x1 And dStart_x <= oOpcConn_x2 And
3388
        '                  dStart_y < dCalcY + 100 And dStart_y > dCalcY - 100) Then
3389
        '                'OPC기준 Start점 End 점중 가까운곳을 시작점으로 지정
3390

    
3391
        '                If Math.Abs(dStart_x - oOpcConn_x1) > Math.Abs(dStart_x - oOpcConn_x2) Then
3392
        '                    dStart_x = oOpcConn_x2
3393
        '                    oOpcRow(_Modeling_ConnType) = "2"
3394
        '                Else
3395
        '                    dStart_x = oOpcConn_x1
3396
        '                    oOpcRow(_Modeling_ConnType) = "1"
3397
        '                End If
3398
        '                sLineUid = oLinerow(_XML_LINE_UID).ToString()
3399
        '                oLinerow(_XML_LINE_STARTPOINT) = dStart_x & "," & dStart_y
3400

    
3401
        '                If dStart_y <> dEnd_y Then
3402
        '                    dEnd_y = dStart_y
3403
        '                    oLinerow(_XML_LINE_ENDPOINT) = dEnd_x & "," & dEnd_y
3404
        '                End If
3405
        '            ElseIf (dEnd_x >= oOpcConn_x2 And dEnd_x <= oOpcConn_x1 And
3406
        '                   dEnd_y < dCalcY + 100 And dEnd_y > dCalcY - 100) Or
3407
        '                    (dEnd_x >= oOpcConn_x1 And dEnd_x <= oOpcConn_x2 And
3408
        '                      dEnd_y < dCalcY + 100 And dEnd_y > dCalcY - 100) Then
3409
        '                    'OPC기준 Start점 End 점중 가까운곳을 시작점으로 지정
3410
        '                    sLineUid = oLinerow(_XML_LINE_UID).ToString()
3411
        '                If Math.Abs(dEnd_x - oOpcConn_x1) > Math.Abs(dEnd_x - oOpcConn_x2) Then
3412
        '                    dEnd_x = oOpcConn_x2
3413
        '                Else
3414
        '                    dEnd_x = oOpcConn_x1
3415
        '                End If
3416
        '                sLineUid = oLinerow(_XML_LINE_UID).ToString()
3417
        '                oLinerow(_XML_LINE_ENDPOINT) = dEnd_x & "," & dEnd_y
3418

    
3419
        '                If dStart_y <> dEnd_y Then
3420
        '                    dStart_y = dEnd_y
3421
        '                    oLinerow(_XML_LINE_STARTPOINT) = dStart_x & "," & dStart_y
3422
        '                End If
3423
        '            End If
3424
        '        Else
3425
        '            '세로 OPC
3426
        '            Dim dCalcX As Double = (oOpcConn_x1 + oOpcConn_x2) / 2
3427
        '            If (dStart_y >= oOpcConn_y2 And dStart_y <= oOpcConn_y1 And
3428
        '                   dStart_x < dCalcX + 100 And dStart_x > dCalcX - 100) Or
3429
        '                   (dStart_y >= oOpcConn_y1 And dStart_y <= oOpcConn_y2 And
3430
        '                  dStart_x < dCalcX + 100 And dStart_x > dCalcX - 100) Then
3431
        '                'OPC기준 Start점 End 점중 가까운곳을 시작점으로 지정
3432
        '                If Math.Abs(dStart_y - oOpcConn_y1) > Math.Abs(dStart_y - oOpcConn_y2) Then
3433
        '                    dStart_y = oOpcConn_y2
3434
        '                    oOpcRow(_Modeling_ConnType) = "2"
3435
        '                Else
3436
        '                    dStart_y = oOpcConn_y1
3437
        '                    oOpcRow(_Modeling_ConnType) = "1"
3438
        '                End If
3439
        '                sLineUid = oLinerow(_XML_LINE_UID).ToString()
3440
        '                oLinerow(_XML_LINE_STARTPOINT) = dStart_x & "," & dStart_y
3441

    
3442
        '                If dStart_x <> dEnd_x Then
3443
        '                    dEnd_x = dStart_x
3444
        '                    oLinerow(_XML_LINE_ENDPOINT) = dEnd_x & "," & dEnd_y
3445
        '                End If
3446
        '            ElseIf (dEnd_y >= oOpcConn_y2 And dEnd_y <= oOpcConn_y1 And
3447
        '               dEnd_x < dCalcX + 100 And dEnd_x > dCalcX - 100) Or
3448
        '                (dEnd_y >= oOpcConn_y1 And dEnd_y <= oOpcConn_y2 And
3449
        '                  dEnd_x < dCalcX + 100 And dEnd_x > dCalcX - 100) Then
3450
        '                'OPC기준 Start점 End 점중 가까운곳을 시작점으로 지정
3451
        '                If Math.Abs(dEnd_y - oOpcConn_y1) > Math.Abs(dEnd_y - oOpcConn_y2) Then
3452
        '                    dEnd_y = oOpcConn_y2
3453
        '                Else
3454
        '                    dEnd_y = oOpcConn_y1
3455
        '                End If
3456
        '                sLineUid = oLinerow(_XML_LINE_UID).ToString()
3457
        '                oLinerow(_XML_LINE_ENDPOINT) = dEnd_x & "," & dEnd_y
3458
        '                If dStart_x <> dEnd_x Then
3459
        '                    dStart_x = dEnd_x
3460
        '                    oLinerow(_XML_LINE_STARTPOINT) = dStart_x & "," & dStart_y
3461
        '                End If
3462
        '            End If
3463

    
3464

    
3465

    
3466
        '        End If
3467

    
3468

    
3469
        '    Next
3470

    
3471

    
3472
        'Catch ex As Exception
3473
        '    Return sLineUid
3474
        'End Try
3475
        'Return sLineUid
3476

    
3477
    End Function
3478

    
3479
    Private Sub PlazeConnectionLine(ByVal oLine_Dt As DataTable, ByVal sLineUid As String, ByVal oRow As DataRow)
3480
        'Try
3481
        '    Dim oOPCLineRow As DataRow() = oLine_Dt.Select("[" & _XML_LINE_UID & "] = '" & sLineUid & "'")
3482
        '    If oOPCLineRow.Length = 1 Then
3483
        '        Dim dOriginalStart_x As Double = 0.0
3484
        '        Dim dOriginalStart_y As Double = 0.0
3485
        '        Dim dOriginalEnd_x As Double = 0.0
3486
        '        Dim dOriginalEnd_y As Double = 0.0
3487
        '        Dim oOpcConnType As String = oRow(_Modeling_ConnType)
3488
        '        Dim dStart_x As Double = 0.0
3489
        '        Dim dStart_y As Double = 0.0
3490
        '        Dim dEnd_x As Double = 0.0
3491
        '        Dim dEnd_y As Double = 0.0
3492
        '        Dim sStartpoint As String = oOPCLineRow(0)(_XML_LINE_STARTPOINT).ToString()
3493
        '        Dim sEndpoint As String = oOPCLineRow(0)(_XML_LINE_ENDPOINT).ToString()
3494
        '        Dim sPipeUid As String = oOPCLineRow(0)(_XML_LINE_UID).ToString()
3495

    
3496
        '        ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
3497
        '        dStart_x = dOriginalStart_x
3498
        '        dStart_y = dOriginalStart_y
3499

    
3500
        '        ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
3501
        '        dEnd_x = dOriginalEnd_x
3502
        '        dEnd_y = dOriginalEnd_y
3503

    
3504
        '        Dim objInputs As PlaceRunInputs
3505
        '        objInputs = New PlaceRunInputs
3506
        '        If oOpcConnType = "1" Then
3507

    
3508

    
3509
        '        ElseIf oOpcConnType = "2" Then
3510

    
3511

    
3512
        '        End If
3513

    
3514

    
3515

    
3516

    
3517

    
3518
        '    End If
3519
        'Catch ex As Exception
3520

    
3521
        'End Try
3522

    
3523
    End Sub
3524
    Private Sub PipeLine_Fitting_Modeling()
3525
        For Each oDrwing As TreeNode In Tree_Result.Nodes
3526
            For Each oDwgNode As TreeNode In oDrwing.Nodes
3527

    
3528
                Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
3529
                Dim CDrawing As Drawing = GetDrawing(sDwgName)
3530
                If CDrawing IsNot Nothing Then
3531
                    Dim iAllLineNoCount As Integer = Tree_Result.Nodes.Count ' GetCheckNodeCount(oLinenoNode)
3532
                    Dim iLineNoCount As Integer = 0 ' GetCheckNodeCount(oLinenoNode)
3533
                    For Each oNode As TreeNode In oDwgNode.Nodes
3534
                        Dim iItemcnt As Integer = 0
3535
                        Dim sNodeUid As String = oNode.Name
3536
                        Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
3537

    
3538
                        Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
3539
                        If CLineNo IsNot Nothing Then
3540

    
3541
                            Dim oLine_Dt As DataTable = CLineNo.Dt_Line
3542
                            Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
3543
                            Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
3544
                            Dim oDrawLinenoLabel As Boolean = False
3545

    
3546
                            Dim oOpcRows() As DataRow = _ResultModeling_DT.Select("[" & _Modeling_LineNoUid & "] = '" & sNodeUid & "' and " &
3547
                                                    "[" & _Modeling_Type & "] = '" & _SYMBOL_OPC & "'")
3548
                            Dim bPlaceOpcLine As Boolean = False
3549
                            'For Each oOpcrow In oOpcRows
3550
                            '    'OPC 와 접하는 Line구하기
3551
                            '    Dim sLineUid As String = CheckOPCConnectionLine(oOpcrow, oLine_Dt)
3552

    
3553

    
3554
                            '    For Each oLinerow In oLine_Dt.Rows
3555
                            '            Dim dOriginalStart_x As Double = 0.0
3556
                            '            Dim dOriginalStart_y As Double = 0.0
3557
                            '            Dim dOriginalEnd_x As Double = 0.0
3558
                            '            Dim dOriginalEnd_y As Double = 0.0
3559
                            '            Dim dStart_x As Double = 0.0
3560
                            '            Dim dStart_y As Double = 0.0
3561
                            '            Dim dEnd_x As Double = 0.0
3562
                            '            Dim dEnd_y As Double = 0.0
3563
                            '            Dim sStartpoint As String = oLinerow(_XML_LINE_STARTPOINT).ToString()
3564
                            '            Dim sEndpoint As String = oLinerow(_XML_LINE_ENDPOINT).ToString()
3565
                            '            Dim sPipeUid As String = oLinerow(_XML_LINE_UID).ToString()
3566

    
3567
                            '            Dim oAddPiperunRow As DataRow = oPipeRun_Dt.NewRow()
3568
                            '            ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
3569
                            '            dStart_x = dOriginalStart_x
3570
                            '            dStart_y = dOriginalStart_y
3571
                            '            ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
3572
                            '            dEnd_x = dOriginalEnd_x
3573
                            '        dEnd_y = dOriginalEnd_y
3574
                            '        Dim objItem As LMAItem
3575
                            '        Dim sType As String = oPipeRow(0)(_XML_LINE_TYPE).ToString()
3576
                            '        Dim sSystempath As String = "\Piping\Routing\Process Lines\Primary Piping.sym" ' oPipeRow(0)(_XML_LINE_SYSTEMPATH).ToString()
3577
                            '        If sType.ToUpper() = "ELECTRIC" Then
3578
                            '            sSystempath = "\Instrumentation\Signal Line\Electric.sym"
3579
                            '        ElseIf sType.ToUpper() = "CONNECT TO PROCESS" Then
3580
                            '            sSystempath = "\Instrumentation\Signal Line\Connect to Process.sym"
3581
                            '        Else
3582
                            '        End If
3583

    
3584
                            '        objItem = _Placement.PIDCreateItem(PipeRunLocation)
3585
                            '        objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
3586

    
3587

    
3588

    
3589
                            '    Next
3590

    
3591
                            'Next
3592

    
3593

    
3594
                            For Each oLineNode As TreeNode In oNode.Nodes
3595
                                iItemcnt = iItemcnt + 1
3596
                                Dim sLineUid As String = oLineNode.Name
3597
                                If oLineNode.Checked Then
3598
                                    Dim sUid As String = oLineNode.Name
3599
                                    If oLine_Dt.Select("[" & _XML_LINE_UID & "]= '" & sUid & "'").Length = 1 Then
3600
                                        DrawLine(sUid, sNodeUid, oLine_Dt, oAttribute_Dt, oPipeRun_Dt)
3601
                                    End If
3602
                                    oDrawLinenoLabel = True
3603
                                End If
3604
                                If oNode.Nodes.Count - 1 = iItemcnt And oDrawLinenoLabel Then
3605
                                    Try
3606
                                        DrawLineNo(oPipeRun_Dt, CLineNo)
3607
                                    Catch ex As Exception
3608
                                    End Try
3609
                                End If
3610
                            Next
3611
                            For Each oSymbolNode As TreeNode In oNode.Nodes
3612
                                If oSymbolNode.Checked Then
3613
                                    Dim sUid As String = oSymbolNode.Name
3614
                                    If oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "]= '" & sUid & "' And [" & _XML_SYMBOL_DRAWING_TF & "] = 'False'").Length = 1 Then
3615
                                        DrawSymbol(sUid, oSymbol_Dt, oAttribute_Dt, CLineNo.Dt_Line)
3616
                                    End If
3617
                                End If
3618
                            Next
3619
                            iLineNoCount = iLineNoCount + 1
3620
                        End If
3621

    
3622

    
3623
                        Dim CTrimLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
3624
                        If CTrimLineNo IsNot Nothing Then
3625
                            Dim oLine_Dt As DataTable = CTrimLineNo.Dt_Line
3626
                            Dim oSymbol_Dt As DataTable = CTrimLineNo.Dt_Symbol
3627
                            Dim oAttribute_Dt As DataTable = CTrimLineNo.Dt_Attribute
3628
                            Dim oDrawLinenoLabel As Boolean = False
3629

    
3630
                            For Each oLineNode As TreeNode In oNode.Nodes
3631
                                iItemcnt = iItemcnt + 1
3632
                                Dim sLineUid As String = oLineNode.Name
3633
                                If oLineNode.Checked Then
3634
                                    Dim sUid As String = oLineNode.Name
3635
                                    If oLine_Dt.Select("[" & _XML_LINE_UID & "]= '" & sUid & "'").Length = 1 Then
3636
                                        DrawLine(sUid, sNodeUid, oLine_Dt, oAttribute_Dt, oPipeRun_Dt)
3637
                                    End If
3638
                                    oDrawLinenoLabel = True
3639
                                End If
3640
                            Next
3641
                            For Each oSymbolNode As TreeNode In oNode.Nodes
3642
                                If oSymbolNode.Checked Then
3643
                                    Dim sUid As String = oSymbolNode.Name
3644
                                    If oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "]= '" & sUid & "' And [" & _XML_SYMBOL_DRAWING_TF & "] = 'False'").Length = 1 Then
3645
                                        DrawSymbol(sUid, oSymbol_Dt, oAttribute_Dt, CTrimLineNo.Dt_Line)
3646
                                    End If
3647
                                End If
3648
                            Next
3649
                            iLineNoCount = iLineNoCount + 1
3650
                        End If
3651

    
3652

    
3653
                        'Else
3654
                        '    Dim oDrawLinenoLabel As Boolean = False
3655
                        '    For Each oLineNode As TreeNode In oNode.Nodes
3656
                        '        Dim CLineNo As Line_no = GetOnlyPipeLineNo(CDrawing, oLineNode.Name)
3657
                        '        Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
3658
                        '        Dim oLine_Dt As DataTable = CLineNo.Dt_Line
3659
                        '        Dim sLineUid As String = oLineNode.Name
3660
                        '        If oLineNode.Checked Then
3661
                        '            Dim sUid As String = oLineNode.Name
3662
                        '            DrawLine(sUid, sNodeUid, oLine_Dt, oAttribute_Dt, oPipeRun_Dt)
3663
                        '        End If
3664
                        '    Next
3665
                        'End If
3666

    
3667

    
3668

    
3669
                    Next
3670
                End If
3671
            Next
3672
        Next
3673
    End Sub
3674

    
3675
    Private Function AutoModeling() As Boolean
3676
        Try
3677
            _CompleteConvert = False
3678
            Label_Progress.Text = "0%"
3679
            SetListBoxItems(ListBox_Result, " Auto converting 시작....")
3680
            Dim oDwg_Dt As DataTable = LoadAllDrawing()
3681
            _allItem = GetAllCheckNodeCount()
3682
            '1.Equipment
3683
            '2.Piping OPC
3684
            '3.OPC 시작되는 Line
3685
            InitAutoRouting()
3686
            EquipmentModeling(oDwg_Dt)
3687
            PipingModeling()
3688

    
3689
            '   PipeLine_Fitting_Modeling()
3690

    
3691
            SetProgressbar(ProgressBar_Status, 100)
3692
            Label_Progress.Text = "100%"
3693
            SetListBoxItems(ListBox_Result, " Auto converting 완료")
3694
            _CompleteConvert = True
3695
            Return True
3696
        Catch ex As Exception
3697
            Return False
3698
        End Try
3699
    End Function
3700

    
3701

    
3702

    
3703
    Private Sub ThreadConvert()
3704
        If _DrawingsList IsNot Nothing Then
3705
            If _DrawingsList.Count > 0 Then
3706
                AutoModeling()
3707
            End If
3708
        End If
3709
    End Sub
3710

    
3711
    Private Sub ThreadOPCRemove()
3712
        While _CompleteConvert = False
3713
            Dim oFindOPC As New FindOpc
3714
            oFindOPC.RemoveOPCDlg()
3715
        End While
3716

    
3717
    End Sub
3718

    
3719

    
3720
    Private Function OpenDrawing(ByVal oDt As DataTable, ByVal sDwgName As String) As String
3721
        Dim oRows As DataRow() = oDt.Select("[Name] = '" & sDwgName & "'")
3722
        Dim oPath As String = ""
3723
        If oRows.Length > 0 Then
3724
            oPath = oRows(0).Item("Path").ToString()
3725
        End If
3726
        Return oPath
3727
    End Function
3728

    
3729
    Private Sub LoadXmlToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LoadXmlToolStripMenuItem.Click
3730
        If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
3731
            LoadDB()
3732
            LoadXmlItem(FolderBrowserDialog1.SelectedPath)
3733
        End If
3734
    End Sub
3735
    Private Sub LoadXmlItem(ByVal sFolderPath As String)
3736
        _DrawingsList = New List(Of Drawing)
3737
        Dim sfileEntries As String() = Directory.GetFiles(sFolderPath)
3738
        If Tree_Result.Nodes.Count > 0 Then
3739
            Tree_Result.Nodes(0).Nodes.Clear()
3740
            For Each sfileName In sfileEntries
3741
                Dim sExtension As String = Path.GetExtension(sfileName)
3742
                If sExtension = ".xml" Then
3743
                    Dim sDwgName As String = Path.GetFileNameWithoutExtension(sfileName)
3744
                    Dim sDwgPath As String = sfileName
3745
                    Dim oNode As TreeNode = Tree_Result.Nodes(0).Nodes.Add(sDwgPath, sDwgName, 15)
3746
                    Dim oDwg As Drawing = AddSymbolItem(sDwgPath, oNode)
3747

    
3748
                    _DrawingsList.Add(oDwg)
3749
                End If
3750
            Next
3751
            Tree_Result.Nodes(0).Expand()
3752
        End If
3753
    End Sub
3754

    
3755
    Private Sub GenerateRelation(ByRef oDwg_Ds As Drawing)
3756
        Dim oLineLists As List(Of Line_no) = oDwg_Ds.Line_nos
3757
        Dim oEqpLists As List(Of Eqp_no) = oDwg_Ds.Eqp_nos
3758
        Dim oTrimLineLists As List(Of Line_no) = oDwg_Ds.TrimLine_nos
3759
        Dim oRelation As New GenerateRelation()
3760
        For Each oLinelist In oLineLists
3761

    
3762
            oRelation.CalcLineConnectionItem_Equal(oLinelist.Dt_Line, oLineLists)
3763

    
3764
            oRelation.CalcLineConnectionItem_NonEqual(oLinelist.Dt_Line, oLineLists)
3765

    
3766

    
3767

    
3768
            oRelation.CalcSymbolConnectionItem_Equal(oLinelist.Dt_Symbol, oLineLists)
3769

    
3770
            oRelation.CalcSymbolConnectionItem_NonEqual(oLinelist.Dt_Symbol, oLineLists)
3771

    
3772
            'For Each oLineRow In oLinelist.Dt_Line.Rows
3773
            '    Dim sLineUid As String = oLineRow(_XML_LINE_UID)
3774
            '    Dim dLineStart_x As Double = 0.0
3775
            '    Dim dLineStart_y As Double = 0.0
3776
            '    Dim dLineEnd_x As Double = 0.0
3777
            '    Dim dLineEnd_y As Double = 0.0
3778

    
3779
            '    Dim sStartpoint As String = oLineRow(_XML_LINE_STARTPOINT).ToString()
3780
            '    Dim sEndpoint As String = oLineRow(_XML_LINE_ENDPOINT).ToString()
3781

    
3782
            '    ConvertPointBystring(sStartpoint, dLineStart_x, dLineStart_y)
3783
            '    ConvertPointBystring(sEndpoint, dLineEnd_x, dLineEnd_y)
3784

    
3785
            '    Dim sConn1_Uid As String = ""
3786
            '    Dim sConn2_Uid As String = ""
3787
            '    For Each oConnLineRow In oLinelist.Dt_Line.Rows
3788
            '        Dim sConnLineUid As String = oLineRow(_XML_LINE_UID)
3789
            '        If sLineUid <> sConnLineUid Then
3790
            '            If sConn1_Uid <> "" And sConn2_Uid <> "" Then
3791
            '                Exit For
3792
            '            End If
3793
            '            Dim dConnLineStart_x As Double = 0.0
3794
            '            Dim dConnLineStart_y As Double = 0.0
3795
            '            Dim dConnLineEnd_x As Double = 0.0
3796
            '            Dim dConnLineEnd_y As Double = 0.0
3797
            '            Dim sConnStartpoint As String = oConnLineRow(_XML_LINE_STARTPOINT).ToString()
3798
            '            Dim sConnEndpoint As String = oConnLineRow(_XML_LINE_ENDPOINT).ToString()
3799
            '            ConvertPointBystring(sConnStartpoint, dConnLineStart_x, dConnLineStart_y)
3800
            '            ConvertPointBystring(sConnEndpoint, dConnLineEnd_x, dConnLineEnd_y)
3801

    
3802
            '            If CheckDuplicatePoint(dLineStart_x, dLineStart_y, dLineEnd_x, dLineEnd_y,
3803
            '                                   dConnLineStart_x, dConnLineStart_y, dConnLineEnd_x, dConnLineEnd_y) Then
3804
            '                If dLineStart_x = dConnLineStart_x And dLineStart_y = dConnLineStart_y Then
3805
            '                    sConn1_Uid = sConnLineUid
3806
            '                ElseIf dLineStart_x = dConnLineEnd_x And dLineStart_y = dConnLineEnd_y Then
3807
            '                    sConn1_Uid = sConnLineUid
3808
            '                ElseIf dLineEnd_x = dConnLineStart_x And dLineEnd_y = dConnLineStart_y Then
3809
            '                    sConn2_Uid = sConnLineUid
3810
            '                ElseIf dLineEnd_x = dConnLineEnd_x And dLineEnd_y = dConnLineEnd_y Then
3811
            '                    sConn2_Uid = sConnLineUid
3812
            '                End If
3813
            '            End If
3814
            '        End If
3815

    
3816
            '    Next
3817
            '    For Each oConnSymbolRow In oLinelist.Dt_Symbol.Rows
3818
            '        Dim sSymbolUid As String = oConnSymbolRow(_XML_SYMBOL_UID)
3819
            '        Dim sSymbolName As String = oConnSymbolRow(_XML_SYMBOL_NAME)
3820
            '        Dim sSymbolConnPoint As String = oConnSymbolRow(_XML_SYMBOL_CONNECTIONPOINT)
3821
            '        Dim sConnSplit As String() = sSymbolConnPoint.Split("/")
3822
            '        If sSymbolConnPoint <> "" Then
3823
            '            Dim dSymbolConn1_x As Double = 0.0
3824
            '            Dim dSymbolConn1_y As Double = 0.0
3825
            '            Dim dSymbolConn2_x As Double = 0.0
3826
            '            Dim dSymbolConn2_y As Double = 0.0
3827
            '            Dim dSymbolConn3_x As Double = 0.0
3828
            '            Dim dSymbolConn3_y As Double = 0.0
3829
            '            Dim dSymbolConn4_x As Double = 0.0
3830
            '            Dim dSymbolConn4_y As Double = 0.0
3831

    
3832
            '            Dim sConn1Point As String = ""
3833
            '            Dim sConn2Point As String = ""
3834
            '            Dim sConn3Point As String = ""
3835
            '            Dim sConn4Point As String = ""
3836

    
3837
            '            sConn1Point = sConnSplit(0)
3838

    
3839
            '            If sConnSplit.Length > 1 Then
3840
            '                sConn2Point = sConnSplit(1)
3841
            '                If sConnSplit.Length > 2 Then
3842
            '                    sConn3Point = sConnSplit(2)
3843
            '                    If sConnSplit.Length > 3 Then
3844
            '                        sConn4Point = sConnSplit(3)
3845
            '                    End If
3846
            '                End If
3847
            '            End If
3848

    
3849
            '            ConvertPointBystring(sConn1Point, dSymbolConn1_x, dSymbolConn1_y)
3850
            '            If sConn2Point <> "" Then
3851
            '                ConvertPointBystring(sConn2Point, dSymbolConn2_x, dSymbolConn2_y)
3852
            '            End If
3853
            '            If sConn3Point <> "" Then
3854
            '                ConvertPointBystring(sConn3Point, dSymbolConn3_x, dSymbolConn3_y)
3855
            '            End If
3856
            '            If sConn4Point <> "" Then
3857
            '                ConvertPointBystring(sConn4Point, dSymbolConn4_x, dSymbolConn4_y)
3858
            '            End If
3859

    
3860
            '            If dLineStart_x = dSymbolConn1_x And dLineStart_y = dSymbolConn1_y Then
3861
            '                sConn1_Uid = sSymbolUid
3862
            '            ElseIf dLineStart_x = dSymbolConn2_x And dLineStart_y = dSymbolConn2_y Then
3863
            '                sConn1_Uid = sSymbolUid
3864
            '            ElseIf dLineStart_x = dSymbolConn3_x And dLineStart_y = dSymbolConn3_y Then
3865
            '                sConn1_Uid = sSymbolUid
3866
            '            ElseIf dLineStart_x = dSymbolConn4_x And dLineStart_y = dSymbolConn4_y Then
3867
            '                sConn1_Uid = sSymbolUid
3868
            '            End If
3869

    
3870
            '            If dLineEnd_x = dSymbolConn1_x And dLineEnd_y = dSymbolConn1_y Then
3871
            '                sConn2_Uid = sSymbolUid
3872
            '            ElseIf dLineEnd_x = dSymbolConn2_x And dLineEnd_y = dSymbolConn2_y Then
3873
            '                sConn2_Uid = sSymbolUid
3874
            '            ElseIf dLineEnd_x = dSymbolConn3_x And dLineEnd_y = dSymbolConn3_y Then
3875
            '                sConn2_Uid = sSymbolUid
3876
            '            ElseIf dLineEnd_x = dSymbolConn4_x And dLineEnd_y = dSymbolConn4_y Then
3877
            '                sConn2_Uid = sSymbolUid
3878
            '            End If
3879
            '        Else
3880
            '            Dim dConnSymbolStart_x As Double = 0.0
3881
            '            Dim dConnSymbolStart_y As Double = 0.0
3882
            '            Dim sConnStartpoint As String = oConnSymbolRow(_XML_LINE_STARTPOINT).ToString()
3883
            '            ConvertPointBystring(sConnStartpoint, dConnSymbolStart_x, dConnSymbolStart_y)
3884

    
3885

    
3886
            '        End If
3887

    
3888

    
3889

    
3890

    
3891
            '    Next
3892
            '연결된 Connection point 가 없을때
3893
            '1/100만큼  Line Length 길이의 오차범위를 줘서 다시계산
3894

    
3895
            '1/10만큼 Symbol Size 만큼의 오차범위를 줘서 다시계산
3896

    
3897

    
3898

    
3899

    
3900
            'Next
3901

    
3902
        Next
3903

    
3904

    
3905

    
3906
    End Sub
3907

    
3908

    
3909
    ''' <summary>
3910
    '''  XML Tree 구조 생성 
3911
    ''' </summary>
3912
    ''' <param name="sDwgPath"></param>
3913
    Private Function AddSymbolItem(ByVal sDwgPath As String, ByVal oParentNode As TreeNode) As Drawing
3914
        Dim oDwg_Ds As Drawing = LoadSymbolInXml(sDwgPath)
3915

    
3916
        GenerateRelation(oDwg_Ds)
3917

    
3918
        If oDwg_Ds IsNot Nothing Then
3919
            Dim oLineLists As List(Of Line_no) = oDwg_Ds.Line_nos
3920

    
3921
            Dim oEqpLists As List(Of Eqp_no) = oDwg_Ds.Eqp_nos
3922

    
3923
            Dim oTrimLineLists As List(Of Line_no) = oDwg_Ds.TrimLine_nos
3924

    
3925
            Dim oPipe As Boolean = False
3926
            Dim oFitting As Boolean = False
3927
            Dim oOnlyPipesNode As TreeNode
3928
            Dim oOnlyFittingsNode As TreeNode
3929
            'PipeLine 구분
3930

    
3931
            For Each oLinelist In oLineLists
3932
                Dim sLineNoUid As String = oLinelist.Uid
3933
                Dim sLineNo As String = oLinelist.Text
3934
                Dim oLineNoNode As TreeNode = oParentNode.Nodes.Add(sLineNoUid, sLineNo)
3935
                For Each oLineRow In oLinelist.Dt_Line.Rows
3936
                    Dim sLineUid As String = oLineRow(_XML_LINE_UID)
3937
                    Dim oPipeNode As TreeNode = oLineNoNode.Nodes.Add(sLineUid, "Pipe")
3938
                    oPipeNode.Tag = sLineNoUid
3939
                Next
3940
                For Each oSymbolRow In oLinelist.Dt_Symbol.Rows
3941
                    Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID)
3942
                    Dim sSymbolName As String = oSymbolRow(_XML_SYMBOL_NAME)
3943
                    Dim oSymbolNode As TreeNode = oLineNoNode.Nodes.Add(sSymbolUid, sSymbolName)
3944
                    oSymbolNode.Tag = sLineNoUid
3945
                Next
3946
            Next
3947

    
3948
            For Each oEqplist In oEqpLists
3949
                Dim sEqpUid As String = oEqplist.Uid
3950
                Dim sEqpNo As String = "EQUIPMENT"
3951
                Dim oEqpNode As TreeNode = oParentNode.Nodes.Add(sEqpUid, sEqpNo)
3952

    
3953

    
3954
                For Each oSymbolRow In oEqplist.Dt_Equipment.Rows
3955
                    Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID)
3956
                    Dim sSymbolName As String = oSymbolRow(_XML_SYMBOL_NAME)
3957
                    Dim oSymbolNode As TreeNode = oEqpNode.Nodes.Add(sSymbolUid, sSymbolName)
3958
                    oSymbolNode.Tag = sEqpUid
3959
                Next
3960
            Next
3961
            Dim sTrimLine As String = "TrimLineNos"
3962
            Dim iTrimLinecnt As Integer = 1
3963
            For Each oTrimLinelist In oTrimLineLists
3964
                Dim sLineNoUid As String = oTrimLinelist.Uid
3965
                Dim sLineNo As String = sTrimLine & "_" & iTrimLinecnt
3966
                Dim oLineNoNode As TreeNode = oParentNode.Nodes.Add(sLineNoUid, sLineNo)
3967
                For Each oLineRow In oTrimLinelist.Dt_Line.Rows
3968
                    Dim sLineUid As String = oLineRow(_XML_LINE_UID)
3969
                    Dim oPipeNode As TreeNode = oLineNoNode.Nodes.Add(sLineUid, "Pipe")
3970
                    oPipeNode.Tag = sLineNoUid
3971
                Next
3972
                For Each oSymbolRow In oTrimLinelist.Dt_Symbol.Rows
3973
                    Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID)
3974
                    Dim sSymbolName As String = oSymbolRow(_XML_SYMBOL_NAME)
3975
                    Dim oSymbolNode As TreeNode = oLineNoNode.Nodes.Add(sSymbolUid, sSymbolName)
3976
                    oSymbolNode.Tag = sLineNoUid
3977
                Next
3978
                iTrimLinecnt = iTrimLinecnt + 1
3979
            Next
3980

    
3981
        End If
3982

    
3983
        Return oDwg_Ds
3984
    End Function
3985
    Private Sub Tree_Result_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles Tree_Result.AfterCheck
3986
        If e.Node.Checked = True Then
3987
            For Each oNode As TreeNode In e.Node.Nodes
3988
                oNode.Checked = True
3989
            Next
3990
        Else
3991
            For Each oNode As TreeNode In e.Node.Nodes
3992
                oNode.Checked = False
3993
            Next
3994
        End If
3995
    End Sub
3996

    
3997
    Private Sub Btn_Setting_Click(sender As Object, e As EventArgs) Handles Btn_Setting.Click
3998
        Dim oSettings As Settings = New Settings()
3999
        oSettings.ShowDialog()
4000
    End Sub
4001

    
4002
    Private Sub Btn_TestNozzle_Click(sender As Object, e As EventArgs) Handles Btn_TestNozzle.Click
4003

    
4004
        Dim sVessel_ID As String = "841D5E640AE5421B9A017DDC2E87FF11"
4005
        Dim objVessel As LMVessel
4006
        objVessel = _Placement.PIDDataSource.GetVessel(sVessel_ID)
4007
        Dim oVesselLocation As LMLocations = objVessel.Locations
4008
        Dim symVessel As LMSymbol = _Placement.PIDDataSource.GetSymbol(objVessel.Representations.Nth(1).Id)
4009
        Dim XCoordinate As String = symVessel.Attributes("XCoordinate").Value
4010
        Dim YCoordinate As String = symVessel.Attributes("YCoordinate").Value
4011
        symVessel.Attributes("XCoordinate").Value = XCoordinate + 0.01
4012
        symVessel.Attributes("YCoordinate").Value = YCoordinate + 0.01
4013
        symVessel.Commit()
4014
        Dim sValve_ID As String = "DB7B0CA8A2664A6BA7A9615764BA62B0"
4015
        Dim objValve As LMSymbol
4016
        Dim objValves As LMPipingComp = _Placement.PIDDataSource.GetPipingComp(sValve_ID)
4017

    
4018
        objValve = _Placement.PIDDataSource.GetSymbol(objValves.Representations.Nth(1).Id)
4019
        objValve.Commit()
4020
        Dim dVesselX As Double = XCoordinate
4021
        Dim dVesselY As Double = YCoordinate
4022
        Dim X1 As Double, Y1 As Double, X2 As Double, Y2 As Double
4023

    
4024
        _Placement.PIDConnectPointLocation(objValve, 1, X1, Y1)
4025

    
4026
        _Placement.PIDConnectPointLocation(objValve, 2, X2, Y2)
4027

    
4028
        Dim nozzlename As String = "\Equipment Components\Nozzles\Flanged Nozzle.sym"
4029
        Dim dCalc_x As Double = 0
4030
        Dim dCalc_y As Double = 0
4031

    
4032
        If dVesselX - X2 > 0 Then
4033
            dCalc_x = dVesselX - (dVesselX - X2)
4034
        Else
4035
            dCalc_x = dVesselX + (X2 - dVesselX)
4036
        End If
4037
        If dVesselY - Y2 > 0 Then
4038
            dCalc_y = dVesselY - (dVesselY - Y2)
4039
        Else
4040
            dCalc_y = dVesselY + (Y2 - dVesselY)
4041
        End If
4042

    
4043
        Dim objNozzle As LMSymbol = _Placement.PIDPlaceSymbol(nozzlename, dCalc_x, dCalc_y,
4044
            TargetItem:=symVessel.AsLMRepresentation)
4045

    
4046
        Dim blnSuccess As Boolean = _Placement.PIDConnectPointLocation(objNozzle, 1, X1, Y1)
4047
        blnSuccess = _Placement.PIDConnectPointLocation(objNozzle, 2, X1, Y1)
4048

    
4049
        objValve = _Placement.PIDPlaceSymbol(objValve.FileName, X1, Y1, ExistingItem:=objValve.AsLMAItem,
4050
          TargetItem:=objNozzle.AsLMRepresentation)
4051

    
4052

    
4053

    
4054
    End Sub
4055

    
4056
    Private Sub Btn_SymbolLibrary_Click(sender As Object, e As EventArgs) Handles Btn_SymbolLibrary.Click
4057
        Dim oMapping As New Mapping(_PIDSymbol_DB)
4058
        oMapping.Show()
4059
    End Sub
4060

    
4061
    Private Sub Btn_Stop_Click(sender As Object, e As EventArgs) Handles Btn_Stop.Click
4062
        Try
4063
            SetListBoxItems(ListBox_Result, " Auto converting 중지....")
4064
            _Main_trd.Abort()
4065
            _Opc_trd.Abort()
4066
        Catch ex As Exception
4067

    
4068
        End Try
4069
    End Sub
4070
End Class
4071

    
4072

    
4073
Public Class DrawingInfo
4074
    Public mDrawingName As String
4075
    Public mSpID As String
4076
    Public mPath As String
4077
End Class
4078

    
4079

    
4080

    
4081

    
4082

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