프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / Main.vb @ c8203784

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

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

    
8
Imports System.Threading
9

    
10
Public Class Main
11
    'Dim _Mapping_DB As DataTable = New DataTable()
12
    Dim _Mapping_DB As DataSet = New DataSet()
13
    Dim _Attribute_DB As DataTable = New DataTable()
14
    Dim _PIDSymbol_DB As DataTable = New DataTable()
15
    Dim _ResultModeling_DT As DataTable = New DataTable()
16
    Dim _AllLine_DT As New DataTable()
17
    Dim _AllSymbol_DT As New DataTable()
18
    Dim _ModelingLine_Dt As New DataTable()
19
    Dim _ModelingSymbol_Dt As New DataTable()
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
    Dim _Unit As String
28
    'Drawing 전역변수
29
    Dim _objPIDADrawing As Object
30
    '현재선택한 폴더경로
31
    Dim _selectFolderPath As String
32
    Private _Main_trd As Thread
33
    Private _Opc_trd As Thread
34
    Private _CompleteConvert As Boolean = False
35
    Private _DrawingsList As List(Of Drawing)
36
    Private _iPipeLineNocnt As Integer
37
    Private _iPipecnt As Integer
38
    Private _iFittingcnt As Integer
39
    Private _iValvecnt As Integer
40
    Private _iInstrumentcnt As Integer
41
    Private _iEquipmentcnt As Integer
42
    Private _iNozzlecnt As Integer
43
    Private _iPipintOpccnt As Integer
44
    Private _allItem As Integer
45
    Private _Itemcnt As Integer
46
    Dim _Gembox As New CGembox()
47

    
48
    Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
49
        LoadDB()
50
    End Sub
51
    ''' <summary>
52
    ''' brief
53
    ''' </summary>
54

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

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

    
69
    Private Function GetDataFromMappingDB(ByVal sSymbolName As String, ByVal sColumn As String) As String
70
        Dim sValue As String = ""
71
        For Each oDt As DataTable In _Mapping_DB.Tables
72
            If oDt.Rows.Count > 0 Then
73
                Dim oSelectRow() As DataRow = oDt.Select("[img_symbolname] = '" + sSymbolName + "'")
74
                If oSelectRow.Length = 1 Then
75
                    If sColumn = _DB_COLUMN_MAPPING_SPPID_SYMBOLNAME Then
76
                        sValue = oSelectRow(0).Item("SYM FILE NAME").ToString()
77
                    ElseIf sColumn = _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH Then
78
                        sValue = "\" & oSelectRow(0).Item("SYMBOL PATH").ToString() & "\" & oSelectRow(0).Item("SYM FILE NAME").ToString()
79
                    ElseIf sColumn = _DB_COLUMN_MAPPING_SPPID_COMPTPYE Then
80
                        sValue = oSelectRow(0).Item("ITEM TYPE").ToString()
81
                    ElseIf sColumn = _DB_COLUMN_MAPPING_SPPID_CLASS Then
82
                        sValue = oSelectRow(0).Item("CLASS").ToString()
83
                    Else
84
                        sValue = oSelectRow(0).Item("SYMBOL PATH").ToString() & "\" & oSelectRow(0).Item("SYM FILE NAME").ToString()
85
                    End If
86
                End If
87
            End If
88
        Next
89
        Return sValue
90
    End Function
91

    
92
    Private Function GetAttributeMapping(ByVal sAttributeName As String, ByVal sColumn As String) As String
93
        Dim sSPPIDAttribute As String = ""
94
        If _Attribute_DB.Rows.Count > 0 Then
95
            Dim oSelectRow() As DataRow = _Attribute_DB.Select("[pid_attribute] = '" + sAttributeName + "'")
96
            If oSelectRow.Length = 1 Then
97
                sSPPIDAttribute = oSelectRow(0).Item(sColumn).ToString()
98
            End If
99
        End If
100
        Return sSPPIDAttribute
101
    End Function
102

    
103

    
104

    
105
    Private Function LoadSymbolInXml(ByVal sXmlPath As String) As Drawing
106
        Try
107
            ''  _TempSymbolDt = Symbol_Dt()
108
            Dim CDrawing As Drawing = New Drawing()
109
            '     Dim oDt As DataTable = LoadSymbol_DT()
110
            Dim oElement As XElement = XElement.Load(sXmlPath)
111
            If oElement IsNot Nothing Then
112
                CDrawing.DwgName = oElement.Element(_XML_DWGNAME).Value
113
                CDrawing.Size = oElement.Element(_XML_DWGSIZE).Value
114
                SplitLocation(CDrawing.Size, _IMG_X, _IMG_Y)
115
                '' 이것이 무엇인지 확인 필요
116
                'CDrawing.Unit = oElement.Element(_XML_UNIT).Value
117

    
118
                CDrawing.LINES = LoadLines(oElement)
119
                CDrawing.SYMBOLS = LoadSymbols(oElement)
120
                CDrawing.LINENUMBERS = LoadLineNumbers(oElement)
121
                CDrawing.TRIMLINES = LoadTrimLines(oElement)
122

    
123

    
124
                'Dim oLineno_list As New List(Of Line_no)
125
                'Dim oEqp_list As New List(Of Eqp_no)
126
                'Dim oTrim_Lineno_list As New List(Of Line_no)
127
                'oLineno_list = LoadLineNo(oElement, _XML_CATEGORY_LINENO)
128
                'For Each oEqpNo As Object In oElement.Elements(_XML_CATEGORY_EQUIPMENT)
129
                '    Dim CEqp_no As Eqp_no = New Eqp_no()
130
                '    Dim oSymbol_Dt As DataTable = Symbol_Dt()
131
                '    Dim oAttribute_Dt As DataTable = Attribute_Dt()
132
                '    Dim sUid As String = ""
133
                '    For Each oSymbol As Object In oEqpNo.Elements(_XML_CATEGORY_SYMBOL)
134
                '        Try
135
                '            Dim oAddrow As DataRow = oSymbol_Dt.NewRow()
136
                '            Dim oEleObj As XElement
137
                '            Dim sParentName As String
138
                '            Dim sName As String
139
                '            Dim sLocation As String
140
                '            Dim sSize As String
141
                '            Dim sAngle As String
142
                '            Dim sOriginalPoint As String = ""
143
                '            Dim sConnectionPoint As String = ""
144
                '            Dim sConnectionUids As String = ""
145
                '            Dim sConnArray As String()
146
                '            Dim sSizeArray As String()
147
                '            Dim sLocationArray As String()
148
                '            Dim sChild As String = ""
149
                '            Dim dCenterPos_x As Double = 0.0
150
                '            Dim dCenterPos_y As Double = 0.0
151
                '            Dim dDwgCenterPos_x As Double = 0.0
152
                '            Dim dDwgCenterPos_y As Double = 0.0
153
                '            Dim dConn1Pos_x As Double = 0.0
154
                '            Dim dConn1Pos_y As Double = 0.0
155
                '            Dim dConn2Pos_x As Double = 0.0
156
                '            Dim dConn2Pos_y As Double = 0.0
157
                '            Dim dConn3Pos_x As Double = 0.0
158
                '            Dim dConn3Pos_y As Double = 0.0
159
                '            Dim dConn4Pos_x As Double = 0.0
160
                '            Dim dConn4Pos_y As Double = 0.0
161
                '            Dim dDwg_Conn1Pos_x As Double = 0.0
162
                '            Dim dDwg_Conn1Pos_y As Double = 0.0
163
                '            Dim dDwg_Conn2Pos_x As Double = 0.0
164
                '            Dim dDwg_Conn2Pos_y As Double = 0.0
165
                '            Dim dDwg_Conn3Pos_x As Double = 0.0
166
                '            Dim dDwg_Conn3Pos_y As Double = 0.0
167
                '            Dim dDwg_Conn4Pos_x As Double = 0.0
168
                '            Dim dDwg_Conn4Pos_y As Double = 0.0
169
                '            Dim sOwnerUid As String = ""
170
                '            oEleObj = oSymbol.Element(_XML_SYMBOL_UID)
171
                '            sUid = oEleObj.Value
172
                '            oEleObj = oSymbol.Element(_XML_SYMBOL_PARENT)
173
                '            sParentName = oEleObj.Value
174
                '            oEleObj = oSymbol.Element(_XML_SYMBOL_NAME)
175
                '            sName = oEleObj.Value
176
                '            oEleObj = oSymbol.Element(_XML_SYMBOL_LOCATION)
177
                '            sLocation = oEleObj.Value
178
                '            oEleObj = oSymbol.Element(_XML_SYMBOL_SIZE)
179
                '            sSize = oEleObj.Value
180
                '            oEleObj = oSymbol.Element(_XML_SYMBOL_ANGLE)
181
                '            sAngle = oEleObj.Value
182
                '            oEleObj = oSymbol.Element(_XML_SYMBOL_CONNECTIONPOINT)
183
                '            sConnectionPoint = oEleObj.Value
184
                '            oEleObj = oSymbol.Element(_XML_SYMBOL_CHILD)
185
                '            sChild = oEleObj.Value
186

    
187
                '            If sName = "NOZZLE" Then
188
                '                oEleObj = oSymbol.Element(_XML_SYMBOL_OWNER)
189
                '                sOwnerUid = oEleObj.Value
190
                '            End If
191
                '            Try
192
                '                oEleObj = oSymbol.Element(_XML_SYMBOL_ORIGINALPOINT)
193
                '                sOriginalPoint = oEleObj.Value
194
                '            Catch ex As Exception
195

    
196
                '            End Try
197
                '            oAddrow(_XML_SYMBOL_OWNER) = sOwnerUid
198
                '            oAddrow(_XML_SYMBOL_Conn1_Uid) = ""
199
                '            oAddrow(_XML_SYMBOL_Conn2_Uid) = ""
200
                '            oAddrow(_XML_SYMBOL_Conn3_Uid) = ""
201
                '            oAddrow(_XML_SYMBOL_Conn4_Uid) = ""
202
                '            ConvertPointBystring(sOriginalPoint, dCenterPos_x, dCenterPos_y)
203
                '            dDwgCenterPos_x = dCenterPos_x
204
                '            dDwgCenterPos_y = dCenterPos_y
205
                '            ConvertPointByImage(dDwgCenterPos_x, dDwgCenterPos_y, _IMG_X, _IMG_Y)
206
                '            oAddrow(_XML_SYMBOL_CENTERPOINT_X) = dCenterPos_x
207
                '            oAddrow(_XML_SYMBOL_CENTERPOINT_Y) = dCenterPos_y
208
                '            oAddrow(_XML_SYMBOL_DWG_CENTERPOINT_X) = dDwgCenterPos_x
209
                '            oAddrow(_XML_SYMBOL_DWG_CENTERPOINT_Y) = dDwgCenterPos_y
210
                '            sConnArray = sConnectionPoint.Split("/")
211
                '            sSizeArray = sSize.Split(",")
212
                '            sLocationArray = sLocation.Split(",")
213
                '            If sConnArray.Length > 4 Then
214
                '                MessageBox.Show(sConnArray.Length)
215
                '            End If
216
                '            For i = 0 To sConnArray.Length - 1
217
                '                If i = 0 Then
218
                '                    oAddrow(_XML_SYMBOL_Conn1_Point) = sConnArray(i)
219
                '                    ConvertPointBystring(sConnArray(i), dConn1Pos_x, dConn1Pos_y)
220
                '                    dDwg_Conn1Pos_x = dConn1Pos_x
221
                '                    dDwg_Conn1Pos_y = dConn1Pos_y
222
                '                    ConvertPointByImage(dDwg_Conn1Pos_x, dDwg_Conn1Pos_y, _IMG_X, _IMG_Y)
223
                '                    oAddrow(_XML_SYMBOL_CONN1_POINT_X) = dConn1Pos_x
224
                '                    oAddrow(_XML_SYMBOL_CONN1_POINT_Y) = dConn1Pos_y
225
                '                    oAddrow(_XML_SYMBOL_DWG_CONN1_POINT_X) = dDwg_Conn1Pos_x
226
                '                    oAddrow(_XML_SYMBOL_DWG_CONN1_POINT_Y) = dDwg_Conn1Pos_y
227
                '                ElseIf i = 1 Then
228
                '                    oAddrow(_XML_SYMBOL_Conn2_Point) = sConnArray(i)
229
                '                    ConvertPointBystring(sConnArray(i), dConn2Pos_x, dConn2Pos_y)
230
                '                    dDwg_Conn2Pos_x = dConn2Pos_x
231
                '                    dDwg_Conn2Pos_y = dConn2Pos_y
232
                '                    ConvertPointByImage(dDwg_Conn2Pos_x, dDwg_Conn2Pos_y, _IMG_X, _IMG_Y)
233
                '                    oAddrow(_XML_SYMBOL_CONN2_POINT_X) = dConn2Pos_x
234
                '                    oAddrow(_XML_SYMBOL_CONN2_POINT_Y) = dConn2Pos_y
235
                '                    oAddrow(_XML_SYMBOL_DWG_CONN2_POINT_X) = dDwg_Conn2Pos_x
236
                '                    oAddrow(_XML_SYMBOL_DWG_CONN2_POINT_Y) = dDwg_Conn2Pos_y
237
                '                ElseIf i = 2 Then
238
                '                    oAddrow(_XML_SYMBOL_Conn3_Point) = sConnArray(i)
239
                '                    ConvertPointBystring(sConnArray(i), dConn3Pos_x, dConn3Pos_y)
240
                '                    dDwg_Conn3Pos_x = dConn3Pos_x
241
                '                    dDwg_Conn3Pos_y = dConn3Pos_y
242
                '                    ConvertPointByImage(dDwg_Conn3Pos_x, dDwg_Conn3Pos_y, _IMG_X, _IMG_Y)
243
                '                    oAddrow(_XML_SYMBOL_CONN3_POINT_X) = dConn3Pos_x
244
                '                    oAddrow(_XML_SYMBOL_CONN3_POINT_Y) = dConn3Pos_y
245
                '                    oAddrow(_XML_SYMBOL_DWG_CONN3_POINT_X) = dDwg_Conn3Pos_x
246
                '                    oAddrow(_XML_SYMBOL_DWG_CONN3_POINT_Y) = dDwg_Conn3Pos_y
247
                '                ElseIf i = 3 Then
248
                '                    oAddrow(_XML_SYMBOL_Conn4_Point) = sConnArray(i)
249
                '                    ConvertPointBystring(sConnArray(i), dConn4Pos_x, dConn4Pos_y)
250
                '                    dDwg_Conn4Pos_x = dConn4Pos_x
251
                '                    dDwg_Conn4Pos_y = dConn4Pos_y
252
                '                    ConvertPointByImage(dDwg_Conn4Pos_x, dDwg_Conn4Pos_y, _IMG_X, _IMG_Y)
253
                '                    oAddrow(_XML_SYMBOL_CONN4_POINT_X) = dConn4Pos_x
254
                '                    oAddrow(_XML_SYMBOL_CONN4_POINT_Y) = dConn4Pos_y
255
                '                    oAddrow(_XML_SYMBOL_DWG_CONN4_POINT_X) = dDwg_Conn4Pos_x
256
                '                    oAddrow(_XML_SYMBOL_DWG_CONN4_POINT_Y) = dDwg_Conn4Pos_y
257
                '                End If
258
                '            Next
259

    
260
                '            Dim sXLength As String = ""
261
                '            Dim sYLength As String = ""
262
                '            Dim dMin_x As Double = 0
263
                '            Dim dMax_x As Double = 0
264
                '            Dim dMin_y As Double = 0
265
                '            Dim dMax_y As Double = 0
266

    
267
                '            For i = 0 To sSizeArray.Length - 1
268
                '                If i = 0 Then
269
                '                    sXLength = sSizeArray(i)
270
                '                ElseIf i = 1 Then
271
                '                    sYLength = sSizeArray(i)
272
                '                End If
273
                '            Next
274

    
275
                '            For i = 0 To sLocationArray.Length - 1
276
                '                If i = 0 Then
277
                '                    dMin_x = sLocationArray(i)
278
                '                    dMax_x = dMin_x + sXLength
279
                '                ElseIf i = 1 Then
280
                '                    'Y축은 반전
281
                '                    dMax_y = sLocationArray(i)
282
                '                    dMin_y = dMax_y + sYLength
283
                '                End If
284
                '            Next
285
                '            ConvertPointByImage(dMin_x, dMin_y, _IMG_X, _IMG_Y)
286
                '            ConvertPointByImage(dMax_x, dMax_y, _IMG_X, _IMG_Y)
287
                '            oAddrow(_XML_SYMBOL_MIN_X) = dMin_x
288
                '            oAddrow(_XML_SYMBOL_MAX_X) = dMax_x
289
                '            oAddrow(_XML_SYMBOL_MIN_Y) = dMin_y
290
                '            oAddrow(_XML_SYMBOL_MAX_Y) = dMax_y
291
                '            oAddrow(_XML_SYMBOL_UID) = sUid
292
                '            oAddrow(_XML_SYMBOL_NAME) = IO.Path.GetFileNameWithoutExtension(GetDataFromMappingDB(sParentName, _DB_COLUMN_MAPPING_SPPID_SYMBOLNAME))
293
                '            oAddrow(_XML_SYMBOL_LOCATION) = sLocation
294
                '            oAddrow(_XML_SYMBOL_SIZE) = sSize
295
                '            oAddrow(_XML_SYMBOL_ANGLE) = sAngle
296
                '            oAddrow(_XML_SYMBOL_SYSTEMPATH) = GetDataFromMappingDB(sParentName, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
297
                '            oAddrow(_XML_SYMBOL_TYPE) = GetDataFromMappingDB(sParentName, _DB_COLUMN_MAPPING_SPPID_COMPTPYE)
298
                '            oAddrow(_XML_SYMBOL_CLASS) = GetDataFromMappingDB(sParentName, _DB_COLUMN_MAPPING_SPPID_CLASS)
299
                '            oAddrow(_XML_SYMBOL_ORIGINALPOINT) = sOriginalPoint
300
                '            oAddrow(_XML_SYMBOL_CONNECTIONPOINT) = sConnectionPoint
301
                '            oAddrow(_XML_SYMBOL_DRAWING_TF) = "FALSE"
302
                '            oAddrow(_XML_SYMBOL_CHILD) = sChild
303
                '            '   _AllSymbol_DT.Rows.Add(oAddrow)
304
                '            oSymbol_Dt.Rows.Add(oAddrow)
305
                '        Catch ex As Exception
306
                '        End Try
307
                '    Next
308
                '    CEqp_no.Uid = sUid
309
                '    CEqp_no.Dt_Equipment = oSymbol_Dt
310
                '    CEqp_no.Dt_Attribute = oAttribute_Dt
311
                '    oEqp_list.Add(CEqp_no)
312
                'Next
313
                'oTrim_Lineno_list = LoadLineNo(oElement, _XML_CATEGORY_TRIM_LINENO)
314
                'CDrawing.Line_nos = oLineno_list
315
                'CDrawing.Eqp_nos = oEqp_list
316
                'CDrawing.TrimLine_nos = oTrim_Lineno_list
317

    
318
            End If
319
            Return CDrawing
320
        Catch ex As Exception
321
            Return Nothing
322
        End Try
323

    
324
    End Function
325

    
326
    Private Function FindConnection(ByVal oLine_Dt As DataTable, ByVal oSymbol_Dt As DataTable, ByVal sUid As String, ByVal dPos_x As Double, ByVal dPos_y As Double) As String
327

    
328
        Dim sReturnUid As String = ""
329
        Try
330
            Dim oFindLineRow As DataRow() = oLine_Dt.Select(
331
            "[" & _XML_LINE_DWG_STARTPOINT_X & "] >= '" & dPos_x - 0.001 & "' And " &
332
            "[" & _XML_LINE_DWG_STARTPOINT_X & "] <= '" & dPos_x + 0.001 & "' And " &
333
            "[" & _XML_LINE_DWG_STARTPOINT_Y & "] >= '" & dPos_y - 0.001 & "' And " &
334
            "[" & _XML_LINE_DWG_STARTPOINT_Y & "] <= '" & dPos_y + 0.001 & "' And " &
335
            "[" & _XML_LINE_UID & "] <> '" & sUid & "' And " &
336
            "[" & _XML_LINE_Conn1_Uid & "] = ''")
337
            If oFindLineRow.Length = 0 Then
338
                oFindLineRow = oLine_Dt.Select(
339
                "[" & _XML_LINE_DWG_ENDPOINT_X & "] >= '" & dPos_x - 0.001 & "' And " &
340
                "[" & _XML_LINE_DWG_ENDPOINT_X & "] <= '" & dPos_x + 0.001 & "' And " &
341
                "[" & _XML_LINE_DWG_ENDPOINT_Y & "] >= '" & dPos_y - 0.001 & "' And " &
342
                "[" & _XML_LINE_DWG_ENDPOINT_Y & "] <= '" & dPos_y + 0.001 & "' And " &
343
                "[" & _XML_LINE_UID & "] <> '" & sUid & "' And " &
344
                "[" & _XML_LINE_Conn2_Uid & "] = ''")
345
                If oFindLineRow.Length = 0 Then
346
                    oFindLineRow = oSymbol_Dt.Select(
347
              "[" & _XML_SYMBOL_DWG_CONN1_POINT_X & "] >= '" & dPos_x - 0.001 & "' And " &
348
              "[" & _XML_SYMBOL_DWG_CONN1_POINT_X & "] <= '" & dPos_x + 0.001 & "' And " &
349
              "[" & _XML_SYMBOL_DWG_CONN1_POINT_Y & "] >= '" & dPos_y - 0.001 & "' And " &
350
              "[" & _XML_SYMBOL_DWG_CONN1_POINT_Y & "] <= '" & dPos_y + 0.001 & "' And " &
351
              "[" & _XML_SYMBOL_UID & "] <> '" & sUid & "' And " &
352
              "[" & _XML_SYMBOL_Conn1_Uid & "] = ''")
353
                    If oFindLineRow.Length = 0 Then
354
                        oFindLineRow = oSymbol_Dt.Select(
355
                   "[" & _XML_SYMBOL_DWG_CONN2_POINT_X & "] >= '" & dPos_x - 0.001 & "' And " &
356
                   "[" & _XML_SYMBOL_DWG_CONN2_POINT_X & "] <= '" & dPos_x + 0.001 & "' And " &
357
                   "[" & _XML_SYMBOL_DWG_CONN2_POINT_Y & "] >= '" & dPos_y - 0.001 & "' And " &
358
                   "[" & _XML_SYMBOL_DWG_CONN2_POINT_Y & "] <= '" & dPos_y + 0.001 & "' And " &
359
                   "[" & _XML_SYMBOL_UID & "] <> '" & sUid & "' And " &
360
                   "[" & _XML_SYMBOL_Conn2_Uid & "] = ''")
361
                        If oFindLineRow.Length = 0 Then
362
                        Else
363
                            oFindLineRow(0)(_XML_SYMBOL_Conn2_Uid) = sUid
364
                            sReturnUid = oFindLineRow(0)(_XML_SYMBOL_UID).ToString()
365
                        End If
366
                    Else
367
                        oFindLineRow(0)(_XML_SYMBOL_Conn1_Uid) = sUid
368
                        sReturnUid = oFindLineRow(0)(_XML_SYMBOL_UID).ToString()
369
                    End If
370
                Else
371
                    oFindLineRow(0)(_XML_LINE_Conn2_Uid) = sUid
372
                    sReturnUid = oFindLineRow(0)(_XML_LINE_UID).ToString()
373
                End If
374
            Else
375
                oFindLineRow(0)(_XML_LINE_Conn1_Uid) = sUid
376
                sReturnUid = oFindLineRow(0)(_XML_LINE_UID).ToString()
377
            End If
378
        Catch ex As Exception
379

    
380
        End Try
381

    
382
        Return sReturnUid
383
    End Function
384

    
385

    
386
    Private Function SetConnectionInfo(ByRef oLine_Dt As DataTable, ByRef oSymbol_Dt As DataTable)
387
        Try
388
            For Each oLineInfo In oLine_Dt.Rows
389
                Dim sLineUid As String = oLineInfo(_XML_LINE_UID).ToString()
390
                Dim dStartPos_x As Double = oLineInfo(_XML_LINE_DWG_STARTPOINT_X)
391
                Dim dStartPos_y As Double = oLineInfo(_XML_LINE_DWG_STARTPOINT_Y)
392
                Dim dEndPos_x As Double = oLineInfo(_XML_LINE_DWG_ENDPOINT_X)
393
                Dim dEndPos_y As Double = oLineInfo(_XML_LINE_DWG_ENDPOINT_Y)
394
                Dim sConn1Uid As String = ""
395
                Dim sConn2Uid As String = ""
396
                sConn1Uid = FindConnection(oLine_Dt, oSymbol_Dt, sLineUid, dStartPos_x, dStartPos_y)
397
                If sConn1Uid <> "" Then
398
                    oLineInfo(_XML_LINE_Conn1_Uid) = sConn1Uid
399
                End If
400
                sConn2Uid = FindConnection(oLine_Dt, oSymbol_Dt, sLineUid, dEndPos_x, dEndPos_y)
401
                If sConn2Uid <> "" Then
402
                    oLineInfo(_XML_LINE_Conn2_Uid) = sConn2Uid
403
                End If
404
            Next
405
            For Each oSymbolInfo In oSymbol_Dt.Rows
406
                Dim sSymbolUid As String = oSymbolInfo(_XML_SYMBOL_UID).ToString()
407
                Dim dConn1Pos_x As Double = oSymbolInfo(_XML_SYMBOL_DWG_CONN1_POINT_X)
408
                Dim dConn1Pos_y As Double = oSymbolInfo(_XML_SYMBOL_DWG_CONN1_POINT_Y)
409
                Dim sConn1Uid As String = ""
410
                Dim sConn2Uid As String = ""
411
                sConn1Uid = FindConnection(oLine_Dt, oSymbol_Dt, sSymbolUid, dConn1Pos_x, dConn1Pos_y)
412
                If sConn1Uid <> "" Then
413
                    oSymbolInfo(_XML_SYMBOL_Conn1_Uid) = sConn1Uid
414
                End If
415
                Try
416
                    Dim dConn2Pos_x As Double = oSymbolInfo(_XML_SYMBOL_DWG_CONN2_POINT_X)
417
                    Dim dConn2Pos_y As Double = oSymbolInfo(_XML_SYMBOL_DWG_CONN2_POINT_Y)
418
                    sConn2Uid = FindConnection(oLine_Dt, oSymbol_Dt, sSymbolUid, dConn2Pos_x, dConn2Pos_y)
419
                    If sConn2Uid <> "" Then
420
                        oSymbolInfo(_XML_SYMBOL_Conn2_Uid) = sConn2Uid
421
                    End If
422
                Catch ex As Exception
423
                End Try
424
            Next
425
        Catch ex As Exception
426
        End Try
427
    End Function
428

    
429
    Private Function GetFlowDirection(ByRef dStart_x As Double, ByRef dStart_y As Double, ByRef dEnd_x As Double, ByRef dEnd_y As Double, ByRef sDirection As String, ByRef sFlowdirection As String) As Boolean
430
        Dim bValidLine As Boolean = True
431
        If Math.Abs(dStart_x - dEnd_x) > Math.Abs(dStart_y - dEnd_y) Then
432
            If dStart_x > dEnd_x Then
433
                sDirection = "X"
434
                sFlowdirection = "Left_x"
435
                If Math.Abs(dStart_y - dEnd_y) < 5 Then
436
                    dEnd_y = dStart_y
437
                End If
438
            Else
439
                sDirection = "X"
440
                sFlowdirection = "Right_x"
441
                If Math.Abs(dStart_y - dEnd_y) < 5 Then
442
                    dEnd_y = dStart_y
443
                End If
444
            End If
445
            If Math.Abs(dStart_x - dEnd_x) <= 15 Then
446
                bValidLine = False
447
            End If
448
        Else
449
            If dStart_y > dEnd_y Then
450
                sDirection = "Y"
451
                sFlowdirection = "Down_y"
452
                If Math.Abs(dStart_x - dEnd_x) < 5 Then
453
                    dEnd_x = dStart_x
454
                End If
455

    
456
            Else
457
                sDirection = "Y"
458
                sFlowdirection = "Up_y"
459
                If Math.Abs(dStart_x - dEnd_x) < 5 Then
460
                    dEnd_x = dStart_x
461
                End If
462
            End If
463
            If Math.Abs(dStart_y - dEnd_y) <= 20 Then
464
                bValidLine = False
465
            End If
466
        End If
467
        Return bValidLine
468
    End Function
469

    
470
    Private Function LoadLines(ByVal oElement As XElement) As List(Of Line)
471
        Dim result As List(Of Line) = New List(Of Line)
472

    
473
        Dim lineInfos As XElement = oElement.Element(_XML_LINEINFOS)
474

    
475
        For Each oLine As XElement In lineInfos.Elements(_XML_LINEINFOS_LINE)
476
            Dim _line As Line = New Line()
477
            Try
478
                _line.UID = oLine.Element(_XML_LINEINFOS_LINE_UID).Value
479
                _line.STARTPOINT = oLine.Element(_XML_LINEINFOS_LINE_STARTPOINT).Value
480
                _line.ENDPOINT = oLine.Element(_XML_LINEINFOS_LINE_ENDPOINT).Value
481
                _line.TYPE = oLine.Element(_XML_LINEINFOS_LINE_TYPE).Value
482
                _line.AREA = oLine.Element(_XML_LINEINFOS_LINE_AREA).Value
483
                _line.CONNECTORS = GetConnector(oLine)
484
                result.Add(_line)
485
            Catch ex As Exception
486

    
487
            End Try
488
        Next
489

    
490
        Return result
491
    End Function
492

    
493
    Private Function LoadSymbols(ByVal oElement As XElement) As List(Of Symbol)
494
        Dim result As List(Of Symbol) = New List(Of Symbol)
495

    
496
        Dim symbols As XElement = oElement.Element(_XML_SYMBOLS)
497

    
498
        For Each oSymbol As XElement In symbols.Elements(_XML_SYMBOLS_SYMBOL)
499
            Dim _symbol As Symbol = New Symbol()
500
            Try
501
                _symbol.UID = oSymbol.Element(_XML_SYMBOLS_SYMBOL_UID).Value
502
                _symbol.NAME = oSymbol.Element(_XML_SYMBOLS_SYMBOL_NAME).Value
503
                _symbol.TYPE = oSymbol.Element(_XML_SYMBOLS_SYMBOL_TYPE).Value
504
                _symbol.ORIGINALPOINT = oSymbol.Element(_XML_SYMBOLS_SYMBOL_ORIGINALPOINT).Value
505
                _symbol.CONNECTORS = GetConnector(oSymbol)
506
                _symbol.LOCATION = oSymbol.Element(_XML_SYMBOLS_SYMBOL_LOCATION).Value
507
                _symbol.SIZE = oSymbol.Element(_XML_SYMBOLS_SYMBOL_SIZE).Value
508
                _symbol.ANGLE = oSymbol.Element(_XML_SYMBOLS_SYMBOL_ANGLE).Value
509
                _symbol.PARENT = oSymbol.Element(_XML_SYMBOLS_SYMBOL_PARENT).Value
510
                _symbol.CHILD = oSymbol.Element(_XML_SYMBOLS_SYMBOL_CHILD).Value
511
                _symbol.HASINSTRUMENTLABEL = oSymbol.Element(_XML_SYMBOLS_SYMBOL_HASINSTRUMENTLABEL).Value
512
                _symbol.AREA = oSymbol.Element(_XML_SYMBOLS_SYMBOL_AREA).Value
513
                _symbol.CURRENTPOINTMODEINDEX = oSymbol.Element(_XML_SYMBOLS_SYMBOL_CURRENTPOINTMODEINDEX).Value
514

    
515
                result.Add(_symbol)
516
            Catch ex As Exception
517

    
518
            End Try
519
        Next
520

    
521
        Return result
522
    End Function
523

    
524
    Private Function LoadLineNumbers(ByVal oElement As XElement) As List(Of LineNumber)
525
        Dim result As List(Of LineNumber) = New List(Of LineNumber)
526

    
527
        Dim lineNos As XElement = oElement.Element(_XML_LINENOS)
528

    
529
        For Each oLineNo As XElement In lineNos.Elements(_XML_LINENOS_LINENO)
530
            Dim _lineNo As LineNumber = New LineNumber()
531
            Try
532
                _lineNo.UID = oLineNo.Element(_XML_LINEINFOS_LINE_UID).Value
533

    
534
                _lineNo.SYMBOLRUNITEMS = GetSymbolRunItems(oLineNo)
535
                _lineNo.LINERUNITEMS = GetLineRunItems(oLineNo)
536

    
537
                result.Add(_lineNo)
538
            Catch ex As Exception
539

    
540
            End Try
541
        Next
542

    
543
        Return result
544
    End Function
545

    
546
    Private Function LoadTrimLines(ByVal oElement As XElement) As List(Of LineNumber)
547
        Dim result As List(Of LineNumber) = New List(Of LineNumber)
548

    
549
        Dim trimNos As XElement = oElement.Element(_XML_TRIMLINENOS)
550

    
551
        For Each oTrimLine As XElement In trimNos.Elements(_XML_TRIMLINENOS_TRIM_LINE_NO)
552
            Dim _lineNo As LineNumber = New LineNumber()
553
            Try
554
                _lineNo.UID = oTrimLine.Element(_XML_LINEINFOS_LINE_UID).Value
555

    
556
                _lineNo.SYMBOLRUNITEMS = GetSymbolRunItems(oTrimLine)
557
                _lineNo.LINERUNITEMS = GetLineRunItems(oTrimLine)
558

    
559
                result.Add(_lineNo)
560
            Catch ex As Exception
561

    
562
            End Try
563
        Next
564

    
565
        Return result
566
    End Function
567

    
568
    Private Function GetSymbolRunItems(ByVal oElement As XElement) As List(Of String)
569
        Dim result As List(Of String) = New List(Of String)
570

    
571
        Dim oRun As XElement = oElement.Element(_XML_RUN)
572

    
573
        For Each oSymbol As XElement In oRun.Elements(_XML_RUN_SYMBOL)
574
            result.Add(oSymbol.Element(_XML_SYMBOLS_SYMBOL_UID))
575
        Next
576

    
577
        Return result
578
    End Function
579

    
580
    Private Function GetLineRunItems(ByVal oElement As XElement) As List(Of String)
581
        Dim result As List(Of String) = New List(Of String)
582

    
583
        Dim oRun As XElement = oElement.Element(_XML_RUN)
584

    
585
        For Each oLine As XElement In oRun.Elements(_XML_RUN_LINE)
586
            result.Add(oLine.Element(_XML_LINEINFOS_LINE_UID))
587
        Next
588

    
589
        Return result
590
    End Function
591

    
592

    
593

    
594
    Private Function GetConnector(ByVal oElement As XElement) As List(Of Connector)
595
        Dim result As List(Of Connector) = New List(Of Connector)
596
        Dim oElementConnectors As XElement = oElement.Element(_XML_CONNECTORS)
597
        For Each oConnector As XElement In oElementConnectors.Elements(_XML_CONNECTORS_CONNECTOR)
598
            Dim _connector As Connector = New Connector()
599
            Try
600
                _connector.CONNECTEDITEM = oConnector.Element(_XML_CONNECTORS_CONNECTOR_CONNECTEDITEM).Value
601
                _connector.CONNECTPOINT = oConnector.Element(_XML_CONNECTORS_CONNECTOR_CONNECTPOINT).Value
602
                _connector.SCENECONNECTPOINT = oConnector.Element(_XML_CONNECTORS_CONNECTOR_SCENECONNECTPOINT).Value
603
                result.Add(_connector)
604
            Catch ex As Exception
605
            End Try
606
        Next
607

    
608
        Return result
609
    End Function
610

    
611
    Private Function LoadLineNo(ByVal oElement As XElement, ByVal sLineType As String) As List(Of Line_no)
612

    
613
        Dim oLineno_list As New List(Of Line_no)
614
        For Each oLineNo As Object In oElement.Elements(sLineType)
615
            Dim CLineNo As Line_no = New Line_no()
616
            Try
617
                CLineNo.Uid = oLineNo.Element(_XML_LINENO_UID).Value
618
                CLineNo.Text = oLineNo.Element(_XML_LINENO_TEXT).Value
619
                CLineNo.Location = oLineNo.Element(_XML_LINENO_LOCATION).Value
620
                CLineNo.Angle = oLineNo.Element(_XML_LINENO_ANGLE).Value
621
                CLineNo.SystemPath = "\Piping\Labels - Piping Segments\Kemya Line Number.sym" 'GetDataFromMappingDB(_XML_CATEGORY_LINENO, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
622
            Catch ex As Exception
623
            End Try
624
            Dim oLine_Dt As DataTable = Line_Dt()
625
            Dim oSymbol_Dt As DataTable = Symbol_Dt()
626
            Dim oAttribute_Dt As DataTable = Attribute_Dt()
627
            Dim iRunCnt As Integer = 0
628
            For Each oRun As Object In oLineNo.Elements(_XML_CATEGORY_RUN)
629
                iRunCnt = iRunCnt + 1
630
                Dim sRunName As String = CLineNo.Text & "_" & iRunCnt
631
                For Each oMERGEDLine As Object In oRun.Elements(_XML_CATEGORY_MERGEDLINE)
632
                    For Each oLine As Object In oMERGEDLine.Elements(_XML_CATEGORY_LINE)
633
                        Try
634
                            Dim oAddrow As DataRow = oLine_Dt.NewRow()
635
                            Dim oEleObj As XElement
636
                            Dim sUid As String
637
                            Dim sStartpoint As String
638
                            Dim sEndpoint As String
639
                            Dim sType As String
640
                            Dim sConnectionUids As String = ""
641
                            Dim dStartPos_x As Double = 0.0
642
                            Dim dStartPos_y As Double = 0.0
643
                            Dim dEndPos_x As Double = 0.0
644
                            Dim dEndPos_y As Double = 0.0
645
                            Dim dDWG_StartPos_x As Double = 0.0
646
                            Dim dDWG_StartPos_y As Double = 0.0
647
                            Dim dDWG_EndPos_x As Double = 0.0
648
                            Dim dDWG_EndPos_y As Double = 0.0
649
                            oEleObj = oLine.Element(_XML_LINE_UID)
650
                            sUid = oEleObj.Value
651

    
652
                            If oLine_Dt.Select(_XML_LINE_UID & "='" & sUid & "'").Length = 0 Then
653
                                oEleObj = oLine.Element(_XML_LINE_STARTPOINT)
654
                                sStartpoint = oEleObj.Value
655
                                oEleObj = oLine.Element(_XML_LINE_ENDPOINT)
656
                                sEndpoint = oEleObj.Value
657
                                oEleObj = oLine.Element(_XML_LINE_TYPE)
658
                                sType = oEleObj.Value
659

    
660
                                oAddrow(_XML_LINE_Conn1_Uid) = ""
661
                                oAddrow(_XML_LINE_Conn2_Uid) = ""
662
                                oAddrow(_XML_LINE_UID) = sUid
663
                                oAddrow(_XML_LINE_RUNNAME) = sRunName
664
                                oAddrow(_XML_LINE_LINENOUID) = CLineNo.Uid
665
                                oAddrow(_XML_LINENO_TEXT) = CLineNo.Text
666
                                oAddrow(_XML_LINE_STARTPOINT) = sStartpoint
667
                                oAddrow(_XML_LINE_ENDPOINT) = sEndpoint
668
                                If sUid = "0bda520b-9c01-4dc1-9ddd-73adb5f7a871" Then
669
                                    MsgBox("")
670
                                End If
671
                                ConvertPointBystring(sStartpoint, dStartPos_x, dStartPos_y)
672
                                ConvertPointBystring(sEndpoint, dEndPos_x, dEndPos_y)
673
                                Dim sDirection As String = ""
674
                                Dim sFlowDirection As String = ""
675
                                Dim bValidLine As Boolean = GetFlowDirection(dStartPos_x, dStartPos_y, dEndPos_x, dEndPos_y, sDirection, sFlowDirection)
676
                                oAddrow(_XML_LINE_FlowDirection) = sFlowDirection
677
                                oAddrow(_XML_LINE_Direction) = sDirection
678
                                oAddrow(_XML_LINE_ValieLine) = bValidLine
679
                                dDWG_StartPos_x = dStartPos_x
680
                                dDWG_StartPos_y = dStartPos_y
681
                                ConvertPointByImage(dDWG_StartPos_x, dDWG_StartPos_y, _IMG_X, _IMG_Y)
682
                                dDWG_EndPos_x = dEndPos_x
683
                                dDWG_EndPos_y = dEndPos_y
684
                                ConvertPointByImage(dDWG_EndPos_x, dDWG_EndPos_y, _IMG_X, _IMG_Y)
685

    
686
                                oAddrow(_XML_LINE_STARTPOINT_X) = dStartPos_x
687
                                oAddrow(_XML_LINE_STARTPOINT_Y) = dStartPos_y
688
                                oAddrow(_XML_LINE_ENDPOINT_X) = dEndPos_x
689
                                oAddrow(_XML_LINE_ENDPOINT_Y) = dEndPos_y
690

    
691
                                oAddrow(_XML_LINE_DWG_STARTPOINT_X) = dDWG_StartPos_x
692
                                oAddrow(_XML_LINE_DWG_STARTPOINT_Y) = dDWG_StartPos_y
693
                                oAddrow(_XML_LINE_DWG_ENDPOINT_X) = dDWG_EndPos_x
694
                                oAddrow(_XML_LINE_DWG_ENDPOINT_Y) = dDWG_EndPos_y
695

    
696
                                oAddrow(_XML_LINE_SYSTEMPATH) = GetDataFromMappingDB(_XML_CATEGORY_LINE, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
697
                                If oAddrow(_XML_LINE_SYSTEMPATH) = "" Then
698
                                    MessageBox.Show("")
699
                                End If
700
                                oAddrow(_XML_LINE_DRAWING_TF) = "FALSE"
701
                                oAddrow(_XML_LINE_TYPE) = sType
702
                                '  _AllLine_DT.Rows.Add(oAddrow)
703
                                oLine_Dt.Rows.Add(oAddrow)
704
                            Else
705
                            End If
706
                        Catch ex As Exception
707
                        End Try
708
                    Next
709
                Next
710

    
711
                For Each oSymbol As Object In oRun.Elements(_XML_CATEGORY_SYMBOL)
712
                    Try
713

    
714
                        Dim oAddrow As DataRow = oSymbol_Dt.NewRow()
715
                        Dim oEleObj As XElement
716
                        Dim sUid As String
717
                        Dim sName As String
718
                        Dim sLocation As String
719
                        Dim sSize As String
720
                        Dim sAngle As String
721
                        Dim sOriginalPoint As String = ""
722
                        Dim sConnectionPoint As String = ""
723
                        Dim sConnectionUids As String = ""
724
                        Dim sConnArray As String()
725
                        Dim sSizeArray As String()
726
                        Dim sLocationArray As String()
727
                        Dim sChild As String = ""
728
                        Dim dCenterPos_x As Double = 0.0
729
                        Dim dCenterPos_y As Double = 0.0
730
                        Dim dDwgCenterPos_x As Double = 0.0
731
                        Dim dDwgCenterPos_y As Double = 0.0
732

    
733
                        Dim dConn1Pos_x As Double = 0.0
734
                        Dim dConn1Pos_y As Double = 0.0
735
                        Dim dConn2Pos_x As Double = 0.0
736
                        Dim dConn2Pos_y As Double = 0.0
737
                        Dim dConn3Pos_x As Double = 0.0
738
                        Dim dConn3Pos_y As Double = 0.0
739
                        Dim dConn4Pos_x As Double = 0.0
740
                        Dim dConn4Pos_y As Double = 0.0
741

    
742
                        Dim dDwg_Conn1Pos_x As Double = 0.0
743
                        Dim dDwg_Conn1Pos_y As Double = 0.0
744
                        Dim dDwg_Conn2Pos_x As Double = 0.0
745
                        Dim dDwg_Conn2Pos_y As Double = 0.0
746
                        Dim dDwg_Conn3Pos_x As Double = 0.0
747
                        Dim dDwg_Conn3Pos_y As Double = 0.0
748
                        Dim dDwg_Conn4Pos_x As Double = 0.0
749
                        Dim dDwg_Conn4Pos_y As Double = 0.0
750

    
751
                        oEleObj = oSymbol.Element(_XML_SYMBOL_UID)
752
                        sUid = oEleObj.Value
753
                        oEleObj = oSymbol.Element(_XML_SYMBOL_PARENT)
754
                        sName = oEleObj.Value
755
                        oEleObj = oSymbol.Element(_XML_SYMBOL_LOCATION)
756
                        sLocation = oEleObj.Value
757
                        oEleObj = oSymbol.Element(_XML_SYMBOL_SIZE)
758
                        sSize = oEleObj.Value
759
                        oEleObj = oSymbol.Element(_XML_SYMBOL_ANGLE)
760
                        sAngle = oEleObj.Value
761
                        oEleObj = oSymbol.Element(_XML_SYMBOL_CONNECTIONPOINT)
762
                        sConnectionPoint = oEleObj.Value
763
                        oEleObj = oSymbol.Element(_XML_SYMBOL_CHILD)
764
                        sChild = oEleObj.Value
765
                        Try
766
                            oEleObj = oSymbol.Element(_XML_SYMBOL_ORIGINALPOINT)
767
                            sOriginalPoint = oEleObj.Value
768
                        Catch ex As Exception
769

    
770
                        End Try
771
                        'oEleObj = oSymbol.Element(_XML_LINE_CONNS)
772
                        'sConnectionUids = oEleObj.Value
773
                        'sConnArray = sConnectionUids.Split(",")
774
                        'If sConnArray.Length > 4 Then
775
                        '    MessageBox.Show(sConnArray.Length)
776
                        'End If
777
                        'For i = 0 To sConnArray.Length - 1
778
                        '    If i = 0 Then
779
                        '        oAddrow(_XML_SYMBOL_Conn1_Uid) = sConnArray(i)
780
                        '    ElseIf i = 1 Then
781
                        '        oAddrow(_XML_SYMBOL_Conn2_Uid) = sConnArray(i)
782
                        '    ElseIf i = 2 Then
783
                        '        oAddrow(_XML_SYMBOL_Conn3_Uid) = sConnArray(i)
784
                        '    ElseIf i = 3 Then
785
                        '        oAddrow(_XML_SYMBOL_Conn4_Uid) = sConnArray(i)
786
                        '    End If
787
                        'Next
788
                        oAddrow(_XML_SYMBOL_Conn1_Uid) = ""
789
                        oAddrow(_XML_SYMBOL_Conn2_Uid) = ""
790
                        oAddrow(_XML_SYMBOL_Conn3_Uid) = ""
791
                        oAddrow(_XML_SYMBOL_Conn4_Uid) = ""
792
                        ConvertPointBystring(sOriginalPoint, dCenterPos_x, dCenterPos_y)
793
                        dDwgCenterPos_x = dCenterPos_x
794
                        dDwgCenterPos_y = dCenterPos_y
795
                        ConvertPointByImage(dDwgCenterPos_x, dDwgCenterPos_y, _IMG_X, _IMG_Y)
796

    
797
                        oAddrow(_XML_SYMBOL_CENTERPOINT_X) = dCenterPos_x
798
                        oAddrow(_XML_SYMBOL_CENTERPOINT_Y) = dCenterPos_y
799
                        oAddrow(_XML_SYMBOL_DWG_CENTERPOINT_X) = dDwgCenterPos_x
800
                        oAddrow(_XML_SYMBOL_DWG_CENTERPOINT_Y) = dDwgCenterPos_y
801
                        sConnArray = sConnectionPoint.Split("/")
802
                        sSizeArray = sSize.Split(",")
803
                        sLocationArray = sLocation.Split(",")
804
                        If sConnArray.Length > 4 Then
805
                            MessageBox.Show(sConnArray.Length)
806
                        End If
807
                        For i = 0 To sConnArray.Length - 1
808
                            If i = 0 Then
809
                                oAddrow(_XML_SYMBOL_Conn1_Point) = sConnArray(i)
810
                                ConvertPointBystring(sConnArray(i), dConn1Pos_x, dConn1Pos_y)
811
                                dDwg_Conn1Pos_x = dConn1Pos_x
812
                                dDwg_Conn1Pos_y = dConn1Pos_y
813
                                ConvertPointByImage(dDwg_Conn1Pos_x, dDwg_Conn1Pos_y, _IMG_X, _IMG_Y)
814

    
815
                                oAddrow(_XML_SYMBOL_CONN1_POINT_X) = dConn1Pos_x
816
                                oAddrow(_XML_SYMBOL_CONN1_POINT_Y) = dConn1Pos_y
817
                                oAddrow(_XML_SYMBOL_DWG_CONN1_POINT_X) = dDwg_Conn1Pos_x
818
                                oAddrow(_XML_SYMBOL_DWG_CONN1_POINT_Y) = dDwg_Conn1Pos_y
819
                            ElseIf i = 1 Then
820
                                oAddrow(_XML_SYMBOL_Conn2_Point) = sConnArray(i)
821
                                ConvertPointBystring(sConnArray(i), dConn2Pos_x, dConn2Pos_y)
822
                                dDwg_Conn2Pos_x = dConn2Pos_x
823
                                dDwg_Conn2Pos_y = dConn2Pos_y
824
                                ConvertPointByImage(dDwg_Conn2Pos_x, dDwg_Conn2Pos_y, _IMG_X, _IMG_Y)
825
                                oAddrow(_XML_SYMBOL_CONN2_POINT_X) = dConn2Pos_x
826
                                oAddrow(_XML_SYMBOL_CONN2_POINT_Y) = dConn2Pos_y
827
                                oAddrow(_XML_SYMBOL_DWG_CONN2_POINT_X) = dDwg_Conn2Pos_x
828
                                oAddrow(_XML_SYMBOL_DWG_CONN2_POINT_Y) = dDwg_Conn2Pos_y
829
                            ElseIf i = 2 Then
830
                                oAddrow(_XML_SYMBOL_Conn3_Point) = sConnArray(i)
831
                                ConvertPointBystring(sConnArray(i), dConn3Pos_x, dConn3Pos_y)
832
                                dDwg_Conn3Pos_x = dConn3Pos_x
833
                                dDwg_Conn3Pos_y = dConn3Pos_y
834
                                ConvertPointByImage(dDwg_Conn3Pos_x, dDwg_Conn3Pos_y, _IMG_X, _IMG_Y)
835
                                oAddrow(_XML_SYMBOL_CONN3_POINT_X) = dConn3Pos_x
836
                                oAddrow(_XML_SYMBOL_CONN3_POINT_Y) = dConn3Pos_y
837
                                oAddrow(_XML_SYMBOL_DWG_CONN3_POINT_X) = dDwg_Conn3Pos_x
838
                                oAddrow(_XML_SYMBOL_DWG_CONN3_POINT_Y) = dDwg_Conn3Pos_y
839
                            ElseIf i = 3 Then
840
                                oAddrow(_XML_SYMBOL_Conn4_Point) = sConnArray(i)
841
                                ConvertPointBystring(sConnArray(i), dConn4Pos_x, dConn4Pos_y)
842
                                dDwg_Conn4Pos_x = dConn4Pos_x
843
                                dDwg_Conn4Pos_y = dConn4Pos_y
844
                                ConvertPointByImage(dDwg_Conn4Pos_x, dDwg_Conn4Pos_y, _IMG_X, _IMG_Y)
845
                                oAddrow(_XML_SYMBOL_CONN4_POINT_X) = dConn4Pos_x
846
                                oAddrow(_XML_SYMBOL_CONN4_POINT_Y) = dConn4Pos_y
847
                                oAddrow(_XML_SYMBOL_DWG_CONN4_POINT_X) = dDwg_Conn4Pos_x
848
                                oAddrow(_XML_SYMBOL_DWG_CONN4_POINT_Y) = dDwg_Conn4Pos_y
849
                            End If
850
                        Next
851

    
852
                        Dim sXLength As String = ""
853
                        Dim sYLength As String = ""
854

    
855
                        Dim dMin_x As Double = 0
856
                        Dim dMax_x As Double = 0
857
                        Dim dMin_y As Double = 0
858
                        Dim dMax_y As Double = 0
859

    
860
                        For i = 0 To sSizeArray.Length - 1
861
                            If i = 0 Then
862
                                sXLength = sSizeArray(i)
863
                            ElseIf i = 1 Then
864
                                sYLength = sSizeArray(i)
865
                            End If
866
                        Next
867

    
868
                        For i = 0 To sLocationArray.Length - 1
869
                            If i = 0 Then
870
                                dMin_x = sLocationArray(i)
871
                                dMax_x = dMin_x + sXLength
872
                            ElseIf i = 1 Then
873
                                'Y축은 반전
874
                                dMax_y = sLocationArray(i)
875
                                dMin_y = dMax_y + sYLength
876
                            End If
877
                        Next
878
                        ConvertPointByImage(dMin_x, dMin_y, _IMG_X, _IMG_Y)
879
                        ConvertPointByImage(dMax_x, dMax_y, _IMG_X, _IMG_Y)
880

    
881
                        oAddrow(_XML_SYMBOL_MIN_X) = dMin_x
882
                        oAddrow(_XML_SYMBOL_MAX_X) = dMax_x
883
                        oAddrow(_XML_SYMBOL_MIN_Y) = dMin_y
884
                        oAddrow(_XML_SYMBOL_MAX_Y) = dMax_y
885
                        oAddrow(_XML_SYMBOL_UID) = sUid
886
                        oAddrow(_XML_LINE_LINENOUID) = CLineNo.Uid
887
                        oAddrow(_XML_SYMBOL_RUNNAME) = sRunName
888
                        oAddrow(_XML_LINENO_TEXT) = CLineNo.Text
889
                        oAddrow(_XML_SYMBOL_NAME) = IO.Path.GetFileNameWithoutExtension(GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYMBOLNAME))
890
                        oAddrow(_XML_SYMBOL_LOCATION) = sLocation
891
                        oAddrow(_XML_SYMBOL_SIZE) = sSize
892
                        oAddrow(_XML_SYMBOL_ANGLE) = sAngle
893
                        oAddrow(_XML_SYMBOL_SYSTEMPATH) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
894
                        oAddrow(_XML_SYMBOL_TYPE) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_COMPTPYE)
895
                        oAddrow(_XML_SYMBOL_CLASS) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_CLASS)
896
                        oAddrow(_XML_SYMBOL_ORIGINALPOINT) = sOriginalPoint
897

    
898
                        oAddrow(_XML_SYMBOL_CONNECTIONPOINT) = sConnectionPoint
899
                        oAddrow(_XML_SYMBOL_DRAWING_TF) = "FALSE"
900
                        oAddrow(_XML_SYMBOL_CHILD) = sChild
901
                        '   _AllSymbol_DT.Rows.Add(oAddrow)
902
                        oSymbol_Dt.Rows.Add(oAddrow)
903
                    Catch ex As Exception
904
                    End Try
905
                Next
906

    
907
                For Each oAtrribute As Object In oRun.Elements(_XML_CATEGORY_ATTRIBUTE)
908
                    Try
909
                        Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
910
                        Dim oEleObj As XElement
911
                        Dim sUid As String
912
                        Dim sName As String
913
                        Dim sValue As String
914
                        oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
915
                        sUid = oEleObj.Value
916
                        oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
917
                        sName = oEleObj.Value
918
                        oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
919
                        sValue = oEleObj.Value
920
                        oAddrow(_XML_ATTRIBUTE_UID) = sUid
921
                        oAddrow(_XML_ATTRIBUTE_NAME) = sName
922
                        oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
923
                        oAttribute_Dt.Rows.Add(oAddrow)
924
                    Catch ex As Exception
925
                    End Try
926
                Next
927
            Next
928
            'Line No Attribute
929
            For Each oAtrribute As Object In oLineNo.Elements(_XML_CATEGORY_ATTRIBUTE)
930
                Try
931
                    Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
932
                    Dim oEleObj As XElement
933
                    Dim sUid As String = ""
934
                    Dim sName As String
935
                    Dim sValue As String
936

    
937
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
938
                    sUid = oEleObj.Value
939
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
940
                    sName = oEleObj.Value
941
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
942
                    sValue = oEleObj.Value
943
                    oAddrow(_XML_ATTRIBUTE_UID) = sUid
944
                    oAddrow(_XML_ATTRIBUTE_NAME) = sName
945
                    oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
946
                    oAttribute_Dt.Rows.Add(oAddrow)
947
                Catch ex As Exception
948
                End Try
949
            Next
950
            SetConnectionInfo(oLine_Dt, oSymbol_Dt)
951
            _AllLine_DT.Merge(oLine_Dt)
952
            _AllSymbol_DT.Merge(oSymbol_Dt)
953
            CLineNo.Dt_Line = oLine_Dt
954
            CLineNo.Dt_Symbol = oSymbol_Dt
955
            CLineNo.Dt_Attribute = oAttribute_Dt
956
            oLineno_list.Add(CLineNo)
957
        Next
958
        Return oLineno_list
959
    End Function
960

    
961
    Private Sub ConvertPointByImage(ByRef dX As Double, ByRef dY As Double, ByVal dDwgX As Double, ByVal dDwgY As Double)
962

    
963
        Dim calcx As Double = 0
964
        Dim calcy As Double = 0
965
        calcx = (dX * _DWG_X) / dDwgX 'Math.Round((dX * _DWG_X) / dDwgX, 2)
966
        'calcx = Math.Round(calcx, 4, MidpointRounding.)
967
        calcx = Math.Truncate(calcx * 1000) / 1000
968
        calcy = _DWG_Y - ((dY * _DWG_Y) / dDwgY) '_DWG_Y - Math.Round((dY * _DWG_Y) / dDwgY, 2)
969
        '   calcy = Math.Round(calcy, 4)
970
        calcy = Math.Truncate(calcy * 1000) / 1000
971
        dX = calcx
972
        dY = calcy
973
    End Sub
974
    '@brief Convert To SPPID
975
    '@author : Gyusu Park
976
    '@date : 2018-04-10
977
    '@history:
978
    Private Sub SplitLocation(ByVal sLocation As String, ByRef dX As Double, ByRef dY As Double)
979

    
980
        Dim opointstr As String() = Split(sLocation, ",")
981
        If (opointstr.Length > 1) Then
982
            If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
983
                dX = opointstr(0)
984
                dY = opointstr(1)
985
            End If
986
        End If
987

    
988
    End Sub
989

    
990
    Private Function Load_DB(ByVal sDBPath As String, ByVal sTableName As String) As DataTable
991

    
992
        Try
993
            Dim oDt As New DataTable
994
            Dim sConnectionstring As String = "Data Source=" & sDBPath & ";Version=3;Synchronous=Off;UTF8Encoding=True;"
995
            Dim conn As SQLiteConnection = New SQLiteConnection(sConnectionstring)
996
            conn.Open()
997
            Dim sQuery As String = "Select * from " & sTableName
998
            Dim cmd As SQLiteCommand = conn.CreateCommand()
999
            Dim adapter As SQLiteDataAdapter = New SQLiteDataAdapter(sQuery, conn)
1000
            Dim oDataSet As DataSet = New DataSet()
1001
            adapter.Fill(oDataSet)
1002
            oDt = oDataSet.Tables(0)
1003
            Return oDt
1004
        Catch ex As Exception
1005
            Return Nothing
1006
        End Try
1007
    End Function
1008

    
1009
    Private Function LoadAllDrawing() As DataTable
1010
        SetListBoxItems(ListBox_Result, "도면정보 로드중....")
1011
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "도면정보 로드중....")
1012
        Dim oDt As DataTable = Drawing_Dt()
1013
        Dim sHierarchy As String = My.Settings.Plant_Hierarchy
1014
        Dim files() As String
1015
        files = Directory.GetFiles(sHierarchy, "*.pid", SearchOption.AllDirectories)
1016
        For Each FileName As String In files
1017
            Dim sName As String = FileName
1018
            Dim oAddRow As DataRow = oDt.NewRow()
1019
            oAddRow("Name") = Path.GetFileNameWithoutExtension(sName)
1020
            oAddRow("Path") = FileName
1021
            oDt.Rows.Add(oAddRow)
1022
        Next
1023
        Return oDt
1024
    End Function
1025

    
1026
    Dim _XMLList As ListView = New ListView()
1027

    
1028
    Private Function CheckOpenDrawing() As Boolean
1029
        Try
1030

    
1031
            Dim lobjDatasource As Object
1032
            _Placement = CreateObject("Plaice.Placement", "")
1033
            lobjDatasource = _Placement.PIDDataSource
1034
            Return True
1035
        Catch ex As Exception
1036
            Return False
1037
        End Try
1038

    
1039
    End Function
1040

    
1041

    
1042
    Private Sub Btn_Convert_Click(sender As Object, e As EventArgs) Handles Btn_Convert.Click
1043
        Main_Tab.SelectedIndex = 1
1044
        ListBox_Result.Items.Clear()
1045
        Me.ProgressBar_Status.Visible = True
1046
        ProgressBar_Status.Maximum = 100
1047
        ProgressBar_Status.Value = 0
1048
        InitItemCount()
1049
        _Main_trd = New Thread(AddressOf ThreadConvert)
1050
        _Main_trd.IsBackground = True
1051
        _Main_trd.Start()
1052
        FineOPCForm()
1053
    End Sub
1054

    
1055
    Private Sub FineOPCForm()
1056
        _Opc_trd = New Thread(AddressOf ThreadOPCRemove)
1057
        _Opc_trd.IsBackground = True
1058
        _Opc_trd.Start()
1059
    End Sub
1060

    
1061

    
1062
    Dim _objPIDAutoApp As Object
1063

    
1064
    Private Function OpenSPPID(ByVal oDwg_Dt As DataTable, ByVal sDwgName As String) As Boolean
1065
        Dim bCheckOpen As Boolean = False
1066
        '   Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgPath)
1067
        SetListBoxItems(ListBox_Result, sDwgName & " 도면 Open....")
1068
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, sDwgName & " 도면 Open....")
1069
        _objPIDAutoApp = CreateObject("PIDAutomation.Application")
1070

    
1071
        Dim sPath As String = OpenDrawing(oDwg_Dt, sDwgName)
1072
        If sPath <> "" Then
1073
            Process.Start(sPath)
1074
        Else
1075
            Return bCheckOpen
1076
        End If
1077

    
1078
        Dim bCheckOpenDrawing As Boolean = False
1079
        While (True)
1080
            bCheckOpenDrawing = CheckOpenDrawing()
1081
            If bCheckOpenDrawing = True Then
1082
                bCheckOpen = True
1083
                Exit While
1084
            Else
1085
                Thread.Sleep(2000)
1086
            End If
1087
        End While
1088

    
1089

    
1090
        Return bCheckOpen
1091
    End Function
1092

    
1093
    Private Function GetDrawing(ByVal sDwgName As String) As Drawing
1094
        For Each CDrawing In _DrawingsList
1095
            If CDrawing.DwgName.ToUpper() = sDwgName.ToUpper() Then
1096
                Return CDrawing
1097
            End If
1098
        Next
1099
        Return Nothing
1100
    End Function
1101

    
1102
    Private Function GetLineNo(ByVal CDrawing As Drawing, ByVal sLineNoUid As String) As Line_no
1103
        For Each CLineNo In CDrawing.Line_nos
1104
            If CLineNo.Uid = sLineNoUid Then
1105
                Return CLineNo
1106
            End If
1107
        Next
1108
        Return Nothing
1109
    End Function
1110

    
1111
    Private Function GetTrimLineNo(ByVal CDrawing As Drawing, ByVal sLineNoUid As String) As Line_no
1112
        For Each CLineNo In CDrawing.TrimLine_nos
1113
            If CLineNo.Uid = sLineNoUid Then
1114
                Return CLineNo
1115
            End If
1116
        Next
1117
        Return Nothing
1118
    End Function
1119

    
1120

    
1121

    
1122
    Private Function GetPipeFromConnection(ByVal CDrawing As Drawing, ByVal sSymbolUid As String, ByRef sConnTypeNo As String) As DataTable
1123
        For Each CLineNo In CDrawing.Line_nos
1124
            Dim odt As DataTable = CLineNo.Dt_Line
1125
            If odt.Rows.Count > 0 Then
1126
                If odt.Rows(0)(_XML_LINE_Conn1_Uid).ToString = sSymbolUid Then
1127
                    sConnTypeNo = "1"
1128
                    Return odt
1129
                ElseIf odt.Rows(0)(_XML_LINE_Conn2_Uid).ToString() = sSymbolUid Then
1130
                    sConnTypeNo = "2"
1131
                    Return odt
1132
                End If
1133
            End If
1134
        Next
1135
        Return New DataTable
1136
    End Function
1137

    
1138
    Private Function GetSymbolFromConnection(ByVal CDrawing As Drawing, ByVal sSymbolUid As String, ByRef sConnTypeNo As String) As DataTable
1139
        For Each CLineNo In CDrawing.Line_nos
1140
            Dim odt As DataTable = CLineNo.Dt_Symbol
1141
            If odt.Rows.Count > 0 Then
1142
                If odt.Rows(0)(_XML_SYMBOL_Conn1_Uid).ToString = sSymbolUid Then
1143
                    sConnTypeNo = "1"
1144
                    Return odt
1145
                ElseIf odt.Rows(0)(_XML_SYMBOL_Conn2_Uid).ToString() = sSymbolUid Then
1146
                    sConnTypeNo = "2"
1147
                    Return odt
1148
                ElseIf odt.Rows(0)(_XML_SYMBOL_Conn3_Uid).ToString() = sSymbolUid Then
1149
                    sConnTypeNo = "3"
1150
                    Return odt
1151
                ElseIf odt.Rows(0)(_XML_SYMBOL_Conn4_Uid).ToString() = sSymbolUid Then
1152
                    sConnTypeNo = "4"
1153
                    Return odt
1154
                End If
1155
            End If
1156
        Next
1157
        Return New DataTable
1158
    End Function
1159

    
1160
    Private Function GetEqpNo(ByVal CDrawing As Drawing, ByVal sEqpUid As String) As Eqp_no
1161
        For Each CEqpNo In CDrawing.Eqp_nos
1162
            If CEqpNo.Uid = sEqpUid Then
1163
                Return CEqpNo
1164
            End If
1165
        Next
1166
        Return Nothing
1167
    End Function
1168
    Private Function ConvertPointBystring(ByVal sPoint As String, ByRef dX As Double, ByRef dY As Double) As Boolean
1169
        Try
1170
            Dim opointstr As String() = Split(sPoint, ",")
1171
            If (opointstr.Length > 1) Then
1172
                If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
1173
                    dX = opointstr(0)
1174
                    dY = opointstr(1)
1175

    
1176
                Else
1177
                    dX = 0
1178
                    dY = 0
1179
                    Return False
1180
                End If
1181
            End If
1182
            Return True
1183
        Catch ex As Exception
1184
            Return False
1185
        End Try
1186
    End Function
1187

    
1188

    
1189
    Dim _DrawLine_Dt As DataTable = DrawLind_Dt()
1190

    
1191

    
1192
    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)
1193
        Dim oAddRow = _DrawLine_Dt.NewRow()
1194
        oAddRow(_XML_LINE_UID) = sUid
1195
        oAddRow(_XML_LINE_STARTPOINT_X) = dStart_x
1196
        oAddRow(_XML_LINE_STARTPOINT_Y) = dStart_y
1197
        oAddRow(_XML_LINE_ENDPOINT_X) = dEnd_x
1198
        oAddRow(_XML_LINE_ENDPOINT_Y) = dEnd_y
1199
        _DrawLine_Dt.Rows.Add(oAddRow)
1200
    End Sub
1201

    
1202
    Private Sub PlaceEquipment(ByVal sUid As String, ByVal oSymbol_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal sEqpName As String)
1203
        Try
1204
            Dim oSymbolRow() As DataRow = oSymbol_Dt.Select(_XML_SYMBOL_UID & " = '" + sUid + "'")
1205
            Dim oAttributeRow() As DataRow
1206
            If oAttribute_Dt.Rows.Count > 0 Then
1207
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
1208
            End If
1209
            If oSymbolRow.Length > 0 Then
1210
                Dim oDatasource As Object = _Placement.PIDDataSource
1211
                Dim sSymbolName As String = oSymbolRow(0)(_XML_SYMBOL_NAME).ToString()
1212
                Dim sSymbolCompType As String = oSymbolRow(0)(_XML_SYMBOL_TYPE).ToString()
1213
                Dim sSystemPath As String = oSymbolRow(0)(_XML_SYMBOL_SYSTEMPATH).ToString()
1214
                Dim sClass As String = oSymbolRow(0)(_XML_SYMBOL_CLASS).ToString()
1215
                Dim sLocation As String = oSymbolRow(0)(_XML_SYMBOL_LOCATION).ToString()
1216
                Dim sOriginalPoint As String = oSymbolRow(0)(_XML_SYMBOL_ORIGINALPOINT).ToString()
1217
                Dim dAngle As Double = 0.0
1218
                If IsNumeric(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString()) Then
1219
                    dAngle = Double.Parse(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString())
1220
                End If
1221
                Dim dLocationX As Double = 0.0
1222
                Dim dLocationY As Double = 0.0
1223
                ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY)
1224
                Dim dX As Double = dLocationX
1225
                Dim dY As Double = dLocationY
1226
                ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1227
                Dim oReturnSymbol As LMSymbol = Nothing
1228
                If sSymbolCompType.ToUpper() = "NOZZLE" Then
1229
                    Dim sOwnerUid As String = oSymbolRow(0)(_XML_SYMBOL_OWNER).ToString()
1230
                    Dim oFineRow() As DataRow = _ModelingSymbol_Dt.Select("Uid = '" & sOwnerUid & "'")
1231
                    If oFineRow.Length = 1 Then
1232
                        Dim sEqpModelID As String = oFineRow(0)(_XML_SYMBOL_SPID).ToString()
1233

    
1234
                        Dim objVessel As LMVessel
1235
                        objVessel = _Placement.PIDDataSource.GetVessel(sEqpModelID)
1236
                        Dim oVesselLocation As LMLocations = objVessel.Locations
1237
                        Dim oEqpSymbol As LMSymbol = _Placement.PIDDataSource.GetSymbol(objVessel.Representations.Nth(1).Id)
1238

    
1239
                        Dim objNozzle As LMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY,
1240
                                                    TargetItem:=oEqpSymbol.AsLMRepresentation)
1241
                        SetListBoxItems(ListBox_Result, "Place Nozzle.." & sUid & " (" & dLocationX & "," & dLocationY & ")..." & _iEquipmentcnt & " count ")
1242
                        _iNozzlecnt = _iNozzlecnt + 1
1243
                        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Nozzle : " & sUid)
1244
                        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Nozzle Name : " & sSymbolName)
1245
                        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
1246
                        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "OriginalPoint : " & dLocationX & "," & dLocationY)
1247
                        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Nozzle Count : " & _iNozzlecnt)
1248
                    End If
1249
                Else
1250
                    oReturnSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1251
                    SetListBoxItems(ListBox_Result, "Place Equipment.." & sUid & " (" & dLocationX & "," & dLocationY & ")..." & _iEquipmentcnt & " count ")
1252
                    _iEquipmentcnt = _iEquipmentcnt + 1
1253
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Equipment : " & sUid)
1254
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Equipment Name : " & sSymbolName)
1255
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
1256
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "OriginalPoint : " & dLocationX & "," & dLocationY)
1257
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Equipment Count : " & _iEquipmentcnt)
1258
                End If
1259
                '모델링 된 Symbol 데이터 테이블 저장
1260
                Dim oAddRow As DataRow = _ModelingSymbol_Dt.NewRow
1261
                oAddRow(_XML_SYMBOL_UID) = sUid
1262
                oAddRow(_XML_SYMBOL_SPID) = oReturnSymbol.ModelItemID
1263
                oAddRow(_XML_SYMBOL_LMSYMBOL) = oReturnSymbol
1264
                oAddRow(_XML_SYMBOL_DRAWING_TF) = "TRUE"
1265
                oAddRow(_XML_SYMBOL_CENTERPOINT_X) = dLocationX
1266
                oAddRow(_XML_SYMBOL_CENTERPOINT_Y) = dLocationY
1267
                _ModelingSymbol_Dt.Rows.Add(oAddRow)
1268
            End If
1269
        Catch ex As Exception
1270
        End Try
1271
    End Sub
1272

    
1273
    Private Function PlacePipingOPC(ByVal sUid As String, ByVal oOPCRow As DataRow, ByVal oAttribute_Dt As DataTable, ByVal sLineNoText As String) As LMSymbol
1274
        Try
1275
            Dim oAttributeRow() As DataRow
1276
            If oAttribute_Dt.Rows.Count > 0 Then
1277
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
1278
            End If
1279
            Dim oDatasource As Object = _Placement.PIDDataSource
1280
            Dim sSymbolCompType As String = oOPCRow(_XML_SYMBOL_TYPE).ToString()
1281
            Dim sSystemPath As String = oOPCRow(_XML_SYMBOL_SYSTEMPATH).ToString()
1282
            Dim sClass As String = oOPCRow(_XML_SYMBOL_CLASS).ToString()
1283
            Dim sLocation As String = oOPCRow(_XML_SYMBOL_LOCATION).ToString()
1284
            Dim sOriginalPoint As String = oOPCRow(_XML_SYMBOL_ORIGINALPOINT).ToString()
1285
            Dim dAngle As Double = 0.0
1286
            If IsNumeric(oOPCRow(_XML_SYMBOL_ANGLE).ToString()) Then
1287
                dAngle = Double.Parse(oOPCRow(_XML_SYMBOL_ANGLE).ToString())
1288
            End If
1289

    
1290
            Dim dLocationX As Double = 0.0
1291
            Dim dLocationY As Double = 0.0
1292
            Dim dX As Double = 0.0
1293
            Dim dY As Double = 0.0
1294
            Dim oLMSymbol As LMSymbol = Nothing
1295
            If ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY) Then
1296
                dX = dLocationX
1297
                dY = dLocationY
1298
                ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1299
                _iPipintOpccnt = _iPipintOpccnt + 1
1300
                oLMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1301
                '모델링된 형상은 Drawing True 로 처리
1302
                oOPCRow(_XML_SYMBOL_DRAWING_TF) = "TRUE"
1303
                SetListBoxItems(ListBox_Result, "Place Piping OPC.." & sUid & " (" & dLocationX & "," & dLocationY & ")..." & _iPipintOpccnt & " count ")
1304
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Piping OPC : " & sUid & "")
1305
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "LineNo : " & sLineNoText)
1306
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection1 : " & oOPCRow(_XML_SYMBOL_Conn1_Uid).ToString())
1307
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection2 : " & oOPCRow(_XML_SYMBOL_Conn2_Uid).ToString())
1308
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
1309
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "OriginalPoint : " & dLocationX & "," & dLocationY)
1310
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "OPC Count : " & _iPipintOpccnt)
1311

    
1312
                Dim dConn_X1 As Double, dConn_Y1 As Double, dConn_X2 As Double, dConn_Y2 As Double
1313
                _Placement.PIDConnectPointLocation(oLMSymbol, 1, dConn_X1, dConn_Y1)
1314
                _Placement.PIDConnectPointLocation(oLMSymbol, 2, dConn_X2, dConn_Y2)
1315

    
1316
                'Dim oAddrow As DataRow = _ResultModeling_DT.NewRow()
1317
                'oAddrow(_Modeling_Uid) = sUid
1318
                'oAddrow(_Modeling_Location_X) = dLocationX
1319
                'oAddrow(_Modeling_Location_Y) = dLocationY
1320
                'oAddrow(_Modeling_LineNoUid) = sLineUid
1321
                'oAddrow(_Modeling_Type) = sSymbolCompType
1322
                'oAddrow(_Modeling_Connection1_X) = dConn_X1
1323
                'oAddrow(_Modeling_Connection1_Y) = dConn_Y1
1324
                'oAddrow(_Modeling_Connection2_X) = dConn_X2
1325
                'oAddrow(_Modeling_Connection2_X) = dConn_Y2
1326
                'oAddrow(_Modeling_LMSymbol) = oLMSymbol
1327

    
1328
                '_ResultModeling_DT.Rows.Add(oAddrow)
1329
            End If
1330
            _Itemcnt = _Itemcnt + 1
1331
            Dim dCalcProgressValue As Double = (_Itemcnt / _allItem) * 100
1332
            SetProgressbar(ProgressBar_Status, dCalcProgressValue)
1333
            Label_Progress.Text = Math.Round(dCalcProgressValue, 0) & "%"
1334
            Return oLMSymbol
1335
        Catch ex As Exception
1336

    
1337
        End Try
1338
        Return Nothing
1339

    
1340
    End Function
1341

    
1342
    Private Sub AddProgress()
1343
        _Itemcnt = _Itemcnt + 1
1344
        Dim dCalcProgressValue As Double = (_Itemcnt / _allItem) * 100
1345
        SetProgressbar(ProgressBar_Status, dCalcProgressValue)
1346
        Label_Progress.Text = Math.Round(dCalcProgressValue, 0) & "%"
1347
    End Sub
1348
    Private Function DrawSymbol(ByVal sUid As String, ByVal oSymbol_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal oLine_Dt As DataTable) As Boolean
1349
        Try
1350

    
1351
            Dim oSymbolRow() As DataRow = oSymbol_Dt.Select(_XML_SYMBOL_UID & " = '" + sUid + "'")
1352
            Dim oAttributeRow() As DataRow
1353
            If oAttribute_Dt.Rows.Count > 0 Then
1354
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
1355
            End If
1356

    
1357
            If oSymbolRow.Length > 0 Then
1358
                Dim oDatasource As Object = _Placement.PIDDataSource
1359
                Dim sSymbolCompType As String = oSymbolRow(0)(_XML_SYMBOL_TYPE).ToString()
1360
                Dim sSystemPath As String = oSymbolRow(0)(_XML_SYMBOL_SYSTEMPATH).ToString()
1361
                Dim sClass As String = oSymbolRow(0)(_XML_SYMBOL_CLASS).ToString()
1362
                Dim sLocation As String = oSymbolRow(0)(_XML_SYMBOL_LOCATION).ToString()
1363
                Dim sOriginalPoint As String = oSymbolRow(0)(_XML_SYMBOL_ORIGINALPOINT).ToString()
1364
                Dim dAngle As Double = 0.0
1365
                If IsNumeric(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString()) Then
1366
                    dAngle = Double.Parse(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString())
1367
                End If
1368

    
1369
                Dim objSymbol As LMSymbol
1370
                Dim dLocationX As Double = 0.0
1371
                Dim dLocationY As Double = 0.0
1372
                Dim dX As Double = 0.0
1373
                Dim dY As Double = 0.0
1374

    
1375
                If ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY) Then
1376
                    dX = dLocationX
1377
                    dY = dLocationY
1378
                    If sSymbolCompType = "" Or sSymbolCompType = "Piping OPC's" Then
1379
                        FindConnectionLine(oLine_Dt, dX, dY)
1380
                    End If
1381

    
1382
                    ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1383
                    Dim oInstrument As LMInstrument
1384
                    If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
1385
                        _iInstrumentcnt = _iInstrumentcnt + 1
1386
                        objSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1387
                        SetListBoxItems(ListBox_Result, "Place Instrument..(" & dLocationX & "," & dLocationY & ")..." & _iInstrumentcnt & " count ")
1388
                        oInstrument = oDatasource.GetInstrument(objSymbol.ModelItemID)
1389
                        Try
1390
                            If oAttributeRow.Length > 0 Then
1391
                                For Each oAttribute In oAttributeRow
1392
                                    Try
1393
                                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
1394
                                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
1395
                                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
1396
                                        oInstrument.Attributes(sSPPIDAttribute).Value = sPIDValue
1397
                                    Catch ex As Exception
1398

    
1399
                                    End Try
1400

    
1401
                                Next
1402
                                oInstrument.Commit()
1403
                            End If
1404
                        Catch ex As Exception
1405
                        End Try
1406
                    ElseIf sSymbolCompType.ToUpper() = _DB_FITTINGS.ToUpper() Then
1407
                        _iValvecnt = _iValvecnt + 1
1408
                        _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1409
                        SetListBoxItems(ListBox_Result, "Place Valve..(" & dLocationX & "," & dLocationY & ")..." & _iValvecnt & " count ")
1410

    
1411
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_FITTINGS.ToUpper() Then
1412
                        _iFittingcnt = _iFittingcnt + 1
1413
                        If sSystemPath.Contains(",") Then
1414

    
1415
                            Dim sDuplicatePath As String() = sSystemPath.Split(",")
1416
                            Dim sMainSymbol As String = ""
1417
                            Dim sSubSymbol As String = ""
1418
                            For Each sPath In sDuplicatePath
1419
                                If sMainSymbol = "" Then
1420
                                    sMainSymbol = sPath.Replace(vbLf, "")
1421
                                Else
1422
                                    sSubSymbol = sPath.Replace(vbLf, "")
1423
                                End If
1424
                            Next
1425
                            Dim oSymbolObj As LMSymbol = _Placement.PIDPlaceSymbol(sMainSymbol, dX, dY, , dAngle)
1426
                            Dim dConnpos_x As Double = 0.0
1427
                            Dim dConnpos_y As Double = 0.0
1428
                            _Placement.PIDConnectPointLocation(oSymbolObj, 2, dConnpos_x, dConnpos_y)
1429
                            '   _Placement.PIDPlaceSymbol(sSubSymbol, dConnpos_x, dConnpos_y, dAngle, TargetItem:=oSymbolObj.AsLMRepresentation)
1430
                            _Placement.PIDPlaceSymbol(sSubSymbol, dConnpos_x, dConnpos_y,, dAngle)
1431

    
1432
                        Else
1433
                            _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1434
                        End If
1435

    
1436

    
1437
                        SetListBoxItems(ListBox_Result, "Place Fitting..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1438
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() And sClass.ToUpper() = _SYMBOL_ACTUATORS.ToUpper() Then
1439
                        _iFittingcnt = _iFittingcnt + 1
1440
                        Dim sDuplicatePath As String() = sSystemPath.Split(",")
1441
                        Dim sMainSymbol As String = ""
1442
                        Dim sSubSymbol As String = ""
1443
                        For Each sPath In sDuplicatePath
1444
                            If sMainSymbol = "" Then
1445
                                sMainSymbol = sPath.Replace(vbLf, "")
1446
                            Else
1447
                                sSubSymbol = sPath.Replace(vbLf, "")
1448
                            End If
1449
                        Next
1450
                        Dim oSymbolObj As LMSymbol = _Placement.PIDPlaceSymbol(sMainSymbol, dX, dY, , dAngle)
1451
                        Dim dSymbolpos_x As Double = oSymbolObj.XCoordinate
1452
                        Dim dSymbolpos_y As Double = oSymbolObj.YCoordinate
1453
                        _Placement.PIDPlaceSymbol(sSubSymbol, dSymbolpos_x, dSymbolpos_y, , dAngle, TargetItem:=oSymbolObj.AsLMAItem)
1454

    
1455
                    Else
1456
                        _iFittingcnt = _iFittingcnt + 1
1457
                        _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1458
                        SetListBoxItems(ListBox_Result, "Place Fitting..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1459
                    End If
1460

    
1461
                End If
1462
                _Itemcnt = _Itemcnt + 1
1463
                Dim dCalcProgressValue As Double = (_Itemcnt / _allItem) * 100
1464
                SetProgressbar(ProgressBar_Status, dCalcProgressValue)
1465
                Label_Progress.Text = Math.Round(dCalcProgressValue, 0) & "%"
1466
            End If
1467

    
1468
        Catch ex As Exception
1469
            Return False
1470
        End Try
1471
    End Function
1472

    
1473

    
1474
    Private Sub FindConnectionLine(ByVal oLine_Dt As DataTable, ByRef dx As Double, ByRef dy As Double)
1475

    
1476
        Try
1477
            For Each oRow In oLine_Dt.Rows
1478
                Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1479
                Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1480
                Dim d기준s_x As Double = 0
1481
                Dim d기준s_y As Double = 0
1482
                Dim d기준e_x As Double = 0
1483
                Dim d기준e_y As Double = 0
1484
                ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1485
                ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1486
                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
1487
                    dx = d기준s_x
1488
                    dy = d기준s_y
1489
                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
1490
                    dx = d기준e_x
1491
                    dy = d기준e_y
1492
                End If
1493
            Next
1494
        Catch ex As Exception
1495
        End Try
1496
    End Sub
1497

    
1498

    
1499
    Dim _라인보정기준값 As Integer = 10
1500

    
1501
    Private Function 라인보정(ByRef oLine_Dt As DataTable, ByVal sUid As String, ByRef dsx As Double, ByRef dsy As Double,
1502
                                      ByRef dex As Double, ByRef dey As Double)
1503
        Try
1504
            Dim bCheck라인 As Boolean = False
1505
            '일치하는 Line 찾기
1506
            For Each oRow In oLine_Dt.Rows
1507
                Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1508
                Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1509
                Dim sBUid As String = oRow(_XML_LINE_UID).ToString()
1510
                If sBUid <> sUid Then
1511
                    Dim d기준s_x As Double = 0
1512
                    Dim d기준s_y As Double = 0
1513
                    Dim d기준e_x As Double = 0
1514
                    Dim d기준e_y As Double = 0
1515
                    ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1516
                    ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1517

    
1518
                    If (dsx = d기준s_x And dsy = d기준s_y) Or (dsx = d기준e_x And dsy = d기준e_y) Or
1519
                       (dex = d기준s_x And dey = d기준s_y) Or (dex = d기준e_x And dey = d기준e_y) Then
1520
                        bCheck라인 = True
1521
                    End If
1522
                End If
1523
            Next
1524

    
1525
            If bCheck라인 = False Then
1526
                For Each oRow In oLine_Dt.Rows
1527
                    Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1528
                    Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1529
                    Dim sBUid As String = oRow(_XML_LINE_UID).ToString()
1530
                    If sBUid <> sUid Then
1531
                        Dim d기준s_x As Double = 0
1532
                        Dim d기준s_y As Double = 0
1533
                        Dim d기준e_x As Double = 0
1534
                        Dim d기준e_y As Double = 0
1535
                        ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1536
                        ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1537
                        If ((dsx - _라인보정기준값 <= d기준s_x And dsx + _라인보정기준값 >= d기준s_x) And (dsy - _라인보정기준값 <= d기준s_y And dsy + _라인보정기준값 >= d기준s_y)) Then
1538
                            oRow(_XML_LINE_STARTPOINT) = dsx & "," & dsy
1539
                            bCheck라인 = True
1540
                            Exit For
1541
                        ElseIf ((dsx - _라인보정기준값 <= d기준e_x And dsx + _라인보정기준값 >= d기준e_x) And (dsy - _라인보정기준값 <= d기준e_y And dsy + _라인보정기준값 >= d기준e_y)) Then
1542
                            oRow(_XML_LINE_ENDPOINT) = dsx & "," & dsy
1543
                            bCheck라인 = True
1544
                            Exit For
1545
                        ElseIf ((dex - _라인보정기준값 <= d기준s_x And dex + _라인보정기준값 >= d기준s_x) And (dey - _라인보정기준값 <= d기준s_y And dey + _라인보정기준값 >= d기준s_y)) Then
1546
                            oRow(_XML_LINE_STARTPOINT) = dex & "," & dey
1547
                            bCheck라인 = True
1548
                            Exit For
1549
                        ElseIf ((dex - _라인보정기준값 <= d기준e_x And dex + _라인보정기준값 >= d기준e_x) And (dey - _라인보정기준값 <= d기준e_y And dey + _라인보정기준값 >= d기준e_y)) Then
1550
                            oRow(_XML_LINE_ENDPOINT) = dex & "," & dey
1551
                            bCheck라인 = True
1552
                            Exit For
1553
                        End If
1554

    
1555
                    End If
1556
                Next
1557
            End If
1558

    
1559
            Return bCheck라인
1560
        Catch ex As Exception
1561
            Return False
1562
        End Try
1563

    
1564

    
1565
    End Function
1566

    
1567
    Private Function FindOverlapLine(ByVal oLine_Dt As DataTable, ByVal sUid As String, ByRef dsx As Double, ByRef dsy As Double,
1568
                                      ByRef dex As Double, ByRef dey As Double)
1569
        Try
1570
            Dim bCheckOverlap As Boolean = False
1571
            For Each oRow In oLine_Dt.Rows
1572
                Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1573
                Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1574
                Dim sBUid As String = oRow(_XML_LINE_UID).ToString()
1575
                If sBUid <> sUid Then
1576
                    Dim d기준s_x As Double = 0
1577
                    Dim d기준s_y As Double = 0
1578
                    Dim d기준e_x As Double = 0
1579
                    Dim d기준e_y As Double = 0
1580
                    ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1581
                    ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1582
                    If (d기준s_x <= dsx And d기준e_x >= dex And
1583
                        d기준s_y <= dsy And d기준e_y >= dey) Then
1584
                        '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1585
                        If dsy - d기준s_y > d기준e_y - dey Then
1586
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1587
                            If dResultCalc < 10 Then
1588
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1589
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1590
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1591
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1592
                                If dCalcStartY = 0 Then
1593
                                    dey = d기준e_y
1594
                                Else
1595
                                    dey = dCalcStartY
1596
                                End If
1597
                            End If
1598
                        Else
1599
                            '  Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1600
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1601
                            If dResultCalc < 10 Then
1602
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1603
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1604
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1605
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1606
                                If dCalcStartY = 0 Then
1607
                                    dsy = d기준s_y
1608
                                Else
1609
                                    dsy = dCalcStartY
1610
                                End If
1611
                            End If
1612
                        End If
1613
                        bCheckOverlap = True
1614
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
1615
                            d기준s_y <= dey And d기준e_y >= dsy Then
1616
                        '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1617
                        If dey - d기준s_y > d기준e_y - dsy Then
1618
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1619
                            If dResultCalc < 10 Then
1620
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1621
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1622
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1623
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1624
                                If dCalcStartY = 0 Then
1625
                                    dsy = d기준e_y
1626
                                Else
1627
                                    dsy = dCalcStartY
1628
                                End If
1629

    
1630
                            End If
1631
                            '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1632
                        Else
1633
                            '  Dim dResultCalc As Double = (Math.Abs((dsy - d기준s_y)) / Math.Abs((d기준e_y - dey))) * 100
1634
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1635
                            If dResultCalc < 10 Then
1636
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1637
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1638
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1639
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1640
                                If dCalcStartY = 0 Then
1641
                                    dey = d기준e_y
1642
                                Else
1643
                                    dey = dCalcStartY
1644
                                End If
1645
                            End If
1646
                        End If
1647
                        bCheckOverlap = True
1648
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
1649
                            d기준s_y <= dey And d기준e_y >= dsy Then
1650

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

    
1683
                        If dex - d기준s_x > d기준e_x - dsx Then
1684
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1685
                            If dResultCalc < 10 Then
1686
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1687
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1688
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1689
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1690
                                If dCalcStartX = 0 Then
1691
                                    dsx = d기준e_x
1692
                                Else
1693
                                    dsx = dCalcStartX
1694
                                End If
1695
                            End If
1696
                        Else
1697
                            ' Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1698
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1699
                            If dResultCalc < 10 Then
1700
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1701
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1702
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1703
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1704
                                If dCalcStartX = 0 Then
1705
                                    dex = d기준s_x
1706
                                Else
1707
                                    dex = dCalcStartX
1708
                                End If
1709
                            End If
1710

    
1711
                        End If
1712
                        bCheckOverlap = True
1713
                    End If
1714
                End If
1715
            Next
1716

    
1717
            Return bCheckOverlap
1718
        Catch ex As Exception
1719
            Return False
1720
        End Try
1721
    End Function
1722

    
1723
    Private Sub CalcSperateLine(ByRef dStartX As Double, ByRef dStartY As Double,
1724
                                      ByRef dEndX As Double, ByRef dEndY As Double)
1725
        Try
1726
            Dim dRange As Double = 1 'Line 전체 길이의 10%씩 늘이기
1727
            If Math.Abs(dStartX - dEndX) > Math.Abs(dStartY - dEndY) Then
1728
                Dim dCalc_x As Double = Math.Abs(dStartX - dEndX) * 0.1
1729
                If dStartX > dEndX Then
1730
                    dStartX = dStartX + dCalc_x
1731
                    dEndX = dEndX - dCalc_x
1732
                Else
1733
                    dEndX = dEndX + dCalc_x
1734
                    dStartX = dStartX - dCalc_x
1735
                End If
1736
            Else
1737
                Dim dCalc_y As Double = Math.Abs(dStartY - dEndY) * 0.1
1738
                If dStartY > dEndY Then
1739
                    dStartY = dStartY + dCalc_y
1740
                    dEndY = dEndY - dCalc_y
1741
                Else
1742
                    dEndY = dEndY + dCalc_y
1743
                    dStartY = dStartY - dCalc_y
1744
                End If
1745
            End If
1746

    
1747
        Catch ex As Exception
1748

    
1749
        End Try
1750

    
1751

    
1752
    End Sub
1753

    
1754
    Private Function DrawLineNo(ByVal oPipeRun_Dt As DataTable, ByVal CLine_No As Line_no) As Boolean
1755
        Try
1756
            Dim oDatasource As Object = _Placement.PIDDataSource
1757
            Dim sLocation = CLine_No.Location
1758
            Dim dLocationx As Double = 0.0
1759
            Dim dLocationy As Double = 0.0
1760
            Dim dX As Double = 0.0
1761
            Dim dY As Double = 0.0
1762
            If ConvertPointBystring(sLocation, dLocationx, dLocationy) Then
1763
                dX = dLocationx
1764
                dY = dLocationy
1765
                For Each oRow In oPipeRun_Dt.Rows
1766
                    Dim dStartx As Double = Double.Parse(oRow("startx").ToString())
1767
                    Dim dStarty As Double = Double.Parse(oRow("starty").ToString())
1768
                    Dim dEndx As Double = Double.Parse(oRow("endx").ToString())
1769
                    Dim dEndy As Double = Double.Parse(oRow("endy").ToString())
1770
                    Dim dStartSum As Double = Math.Abs(dStartx - dLocationx) + Math.Abs(dStarty - dLocationy)
1771
                    Dim dEndSum As Double = Math.Abs(dEndx - dLocationx) + Math.Abs(dEndy - dLocationy)
1772
                    If dStartSum > dEndSum Then
1773
                        oRow("value") = dEndSum
1774
                    Else
1775
                        oRow("value") = dStartSum
1776
                    End If
1777
                Next
1778
                Dim dataView As New DataView(oPipeRun_Dt)
1779
                dataView.Sort = " value asc"
1780
                Dim oDt As DataTable = dataView.ToTable()
1781
                If oDt.Rows.Count > 0 Then
1782
                    Try
1783
                        Dim oPiperun As LMPipeRun = CType(oDt.Rows(0)("Piperun"), LMPipeRun)
1784
                        ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1785
                        Dim dLineNoLocation(2) As Double
1786
                        dLineNoLocation(1) = dX
1787
                        dLineNoLocation(2) = dY
1788
                        'Label
1789
                        Dim sSystemPath As String = CLine_No.SystemPath
1790
                        Dim dAngle As Double = CLine_No.Angle
1791
                        Dim labelpersist As LMLabelPersist
1792
                        For Each representation In oPiperun.Representations
1793
                            If representation.RepresentationType = "Connector" Then
1794
                                labelpersist = _Placement.PIDPlaceLabel(sSystemPath,
1795
                                dLineNoLocation,, dAngle, LabeledItem:=representation)
1796
                                _iPipeLineNocnt = _iPipeLineNocnt + 1
1797
                                SetListBoxItems(ListBox_Result, "Place PipeLineNo Label.." & CLine_No.Uid & " (" & dLocationx & "," & dLocationy & ")..." & _iPipeLineNocnt & " count ")
1798
                                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Pipe : " & CLine_No.Uid & "")
1799
                                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "LineNo : " & CLine_No.Text)
1800
                                'ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
1801
                                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Origina lPoint : " & dLocationx & "," & dLocationy)
1802
                                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "PipeLineNo Count : " & _iPipeLineNocnt)
1803
                            End If
1804
                        Next
1805
                    Catch ex As Exception
1806
                    End Try
1807
                End If
1808
                Return True
1809
            Else
1810
                Return False
1811
            End If
1812
        Catch ex As Exception
1813
            Return False
1814
        End Try
1815
    End Function
1816

    
1817

    
1818
    Private Sub InitItemCount()
1819
        _iPipeLineNocnt = 0
1820
        _iPipecnt = 1
1821
        _iFittingcnt = 1
1822
        _iValvecnt = 0
1823
        _iInstrumentcnt = 0
1824
        _iEquipmentcnt = 0
1825
        _iNozzlecnt = 1
1826
        _iPipintOpccnt = 0
1827
    End Sub
1828

    
1829
    Private Function GetAllCheckNodeCount() As Integer
1830
        _allItem = 0
1831
        For i = 0 To Tree_Result.Nodes.Count - 1
1832
            For j = 0 To Tree_Result.Nodes(i).Nodes.Count - 1
1833
                For k = 0 To Tree_Result.Nodes(i).Nodes(j).Nodes.Count - 1
1834
                    For l = 0 To Tree_Result.Nodes(i).Nodes(j).Nodes(k).Nodes.Count - 1
1835
                        If Tree_Result.Nodes(i).Nodes(j).Nodes(k).Nodes(l).Checked = True Then
1836
                            _allItem = _allItem + 1
1837
                        End If
1838
                    Next
1839
                Next
1840
            Next
1841
        Next
1842
        Return _allItem
1843
    End Function
1844

    
1845

    
1846
    ''' <summary>
1847
    ''' Equipment 모델링
1848
    ''' </summary>
1849
    Private Sub EquipmentModeling(ByVal oDwg_Dt As DataTable)
1850
        For Each oDrwing As TreeNode In Tree_Result.Nodes
1851
            For Each oDwgNode As TreeNode In oDrwing.Nodes
1852
                Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
1853
                Dim CDrawing As Drawing = GetDrawing(sDwgName)
1854
                If CDrawing IsNot Nothing Then
1855
                    If OpenSPPID(oDwg_Dt, oDwgNode.Text) Then
1856

    
1857
                        For Each oNode As TreeNode In oDwgNode.Nodes
1858
                            Dim iItemcnt As Integer = 0
1859
                            Dim sNodeUid As String = oNode.Name
1860
                            Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
1861
                            '1.Equipment
1862
                            '2.Piping OPC
1863
                            '3.OPC 시작되는 Line
1864
                            'Equipment 생성
1865
                            Dim CEqpNo As Eqp_no = GetEqpNo(CDrawing, sNodeUid)
1866
                            If CEqpNo IsNot Nothing Then
1867
                                Dim oSymbol_Dt As DataTable = CEqpNo.Dt_Equipment
1868
                                Dim oAttribute_Dt As DataTable = CEqpNo.Dt_Attribute
1869
                                For Each oSymbolNode As TreeNode In oNode.Nodes
1870
                                    If oSymbolNode.Checked Then
1871
                                        Dim sUid As String = oSymbolNode.Name
1872
                                        PlaceEquipment(sUid, oSymbol_Dt, oAttribute_Dt, CEqpNo.Text)
1873
                                    End If
1874
                                Next
1875
                            End If
1876
                        Next
1877
                    End If
1878
                End If
1879
            Next
1880
        Next
1881
    End Sub
1882

    
1883
    Private Sub ManualCheckNode(ByRef oDt As DataTable)
1884
        For Each oDrwing As TreeNode In Tree_Result.Nodes
1885
            For Each oDwgNode As TreeNode In oDrwing.Nodes
1886
                For Each oNode As TreeNode In oDwgNode.Nodes
1887
                    For Each oSymbolNode As TreeNode In oNode.Nodes
1888
                        Dim sUid As String = oSymbolNode.Name
1889
                        'Dim oSelectRows() As DataRow = oDt.Select("[" & _XML_SYMBOL_UID & "] = '" & sUid &
1890
                        '                                      "' And [" & _XML_SYMBOL_DRAWING_TF & "] = 'False'")
1891
                        If oSymbolNode.Checked Then
1892
                            Dim oSelectRows() As DataRow = oDt.Select("[" & _XML_SYMBOL_UID & "] = '" & sUid & "'")
1893
                            If oSelectRows.Length = 1 Then
1894
                                oSelectRows(0)(_XML_SYMBOL_DRAWING_TF) = "FALSE"
1895
                                If oSymbolNode.Checked Then
1896
                                    oSelectRows(0)(_XML_SYMBOL_Check) = "TRUE"
1897
                                Else
1898
                                    oSelectRows(0)(_XML_SYMBOL_Check) = "FALSE"
1899
                                End If
1900
                            End If
1901
                        End If
1902
                    Next
1903
                Next
1904
            Next
1905
        Next
1906

    
1907
    End Sub
1908

    
1909
    Private Function FinalSymbolModeling(ByVal oCurrentSymbolRow As DataRow, ByVal oLine_Dt As DataTable, ByVal oSymbol_Dt As DataTable,
1910
                                  ByVal oAttribute_Dt As DataTable) As String
1911
        Dim sReturnUid As String = ""
1912
        Dim sOriginalPoint As String = ""
1913
        Dim dOriginal_x As Double = 0.0
1914
        Dim dOriginal_y As Double = 0.0
1915
        Dim dConn1_x As Double = 0.0
1916
        Dim dConn1_y As Double = 0.0
1917
        Dim dConn2_x As Double = 0.0
1918
        Dim dConn2_y As Double = 0.0
1919
        Dim dConn3_x As Double = 0.0
1920
        Dim dConn3_y As Double = 0.0
1921
        Dim dConn4_x As Double = 0.0
1922
        Dim dConn4_y As Double = 0.0
1923
        Dim sUid As String = oCurrentSymbolRow(_XML_SYMBOL_UID)
1924
        Dim sSystemPath As String = oCurrentSymbolRow(_XML_SYMBOL_SYSTEMPATH).ToString()
1925
        Dim dAngle As Double = oCurrentSymbolRow(_XML_SYMBOL_ANGLE)
1926
        Dim sLineNoText As String = oCurrentSymbolRow(_XML_LINENO_TEXT)
1927
        Dim sLineNoUid As String = oCurrentSymbolRow(_XML_LINE_LINENOUID).ToString()
1928
        sOriginalPoint = oCurrentSymbolRow(_XML_SYMBOL_ORIGINALPOINT).ToString()
1929
        Dim sSymbolCompType As String = oCurrentSymbolRow(_XML_SYMBOL_TYPE).ToString()
1930
        ConvertPointBystring(sOriginalPoint, dOriginal_x, dOriginal_y)
1931
        ConvertPointByImage(dOriginal_x, dOriginal_y, _IMG_X, _IMG_Y)
1932
        Dim sChildItem As String = oCurrentSymbolRow(_XML_SYMBOL_CHILD)
1933
        'Connection 정보 체크, 모델링 되어 있는지 유무
1934
        '양 커넥션의 모델링 유무를 체크한다.
1935
        Dim sConn1Uid As String = oCurrentSymbolRow(_XML_SYMBOL_Conn1_Uid).ToString()
1936
        Dim sConn2Uid As String = oCurrentSymbolRow(_XML_SYMBOL_Conn2_Uid).ToString()
1937
        Dim sConn3Uid As String = oCurrentSymbolRow(_XML_SYMBOL_Conn3_Uid).ToString()
1938
        Dim sConn4Uid As String = oCurrentSymbolRow(_XML_SYMBOL_Conn4_Uid).ToString()
1939
        Dim sConn1Type As String = ""
1940
        Dim sConn2Type As String = ""
1941
        Dim sConn3Type As String = ""
1942
        Dim sConn4Type As String = ""
1943
        Dim oConn1Rows() As DataRow = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "] = '" & sConn1Uid & "'")
1944
        If oConn1Rows.Length = 0 Then
1945
            oConn1Rows = oLine_Dt.Select("[" & _XML_LINE_UID & "] = '" & sConn1Uid & "'")
1946
            If oConn1Rows.Length = 1 Then
1947
                sConn1Type = "Line"
1948
            End If
1949
        Else
1950
            sConn1Type = "Symbol"
1951
        End If
1952

    
1953
        Dim oConn2Rows() As DataRow = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "] = '" & sConn2Uid & "'")
1954
        If oConn2Rows.Length = 0 Then
1955
            oConn2Rows = oLine_Dt.Select("[" & _XML_LINE_UID & "] = '" & sConn2Uid & "'")
1956
            If oConn2Rows.Length = 1 Then
1957
                sConn2Type = "Line"
1958
            End If
1959
        Else
1960
            sConn2Type = "Symbol"
1961
        End If
1962

    
1963
        Dim oConn3Rows() As DataRow = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "] = '" & sConn3Uid & "'")
1964
        If oConn3Rows.Length = 0 Then
1965
            oConn3Rows = oLine_Dt.Select("[" & _XML_LINE_UID & "] = '" & sConn3Uid & "'")
1966
            If oConn3Rows.Length = 1 Then
1967
                sConn3Type = "Line"
1968
            End If
1969
        Else
1970
            sConn3Type = "Symbol"
1971
        End If
1972

    
1973
        Dim oConn4Rows() As DataRow = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "] = '" & sConn4Uid & "'")
1974
        If oConn4Rows.Length = 0 Then
1975
            oConn4Rows = oLine_Dt.Select("[" & _XML_LINE_UID & "] = '" & sConn4Uid & "'")
1976
            If oConn4Rows.Length = 1 Then
1977
                sConn4Type = "Line"
1978
            End If
1979
        Else
1980
            sConn4Type = "Symbol"
1981
        End If
1982

    
1983
        Dim oStartLMConnector As LMConnector = Nothing
1984
        Dim oEndLMConnector As LMConnector = Nothing
1985
        Dim objInputs As PlaceRunInputs
1986
        objInputs = New PlaceRunInputs
1987
        Dim iModelingType As Integer = 0
1988
        If sConn1Type <> "" Then
1989
            ConvertPoint(oCurrentSymbolRow(_XML_SYMBOL_Conn1_Point).ToString(), dConn1_x, dConn1_y)
1990
        End If
1991
        If sConn2Type <> "" Then
1992
            ConvertPoint(oCurrentSymbolRow(_XML_SYMBOL_Conn2_Point).ToString(), dConn2_x, dConn2_y)
1993
        End If
1994
        If sConn3Type <> "" Then
1995
            ConvertPoint(oCurrentSymbolRow(_XML_SYMBOL_Conn3_Point).ToString(), dConn3_x, dConn3_y)
1996
        End If
1997
        If sConn4Type <> "" Then
1998
            ConvertPoint(oCurrentSymbolRow(_XML_SYMBOL_Conn4_Point).ToString(), dConn4_x, dConn4_y)
1999
        End If
2000

    
2001
        Dim sFirstUid As String = ""
2002
        Dim sSecondUid As String = ""
2003
        Dim oLMSymbol As LMSymbol = Nothing
2004
        Dim dPreConn_x As Double = 0
2005
        Dim dPreConn_y As Double = 0
2006
        Dim sStartConnectionUid As String = ""
2007
        Dim sEndConnectionUid As String = ""
2008
        If sConn1Type <> "" And sConn2Type <> "" Then
2009
            If sConn1Type = "Line" Then
2010
                CheckConnectionLine(dConn1_x, dConn1_y, oStartLMConnector, sStartConnectionUid)
2011
            Else
2012
                CheckConnectionSymbolToSymbol(oConn1Rows, dConn1_x, dConn1_y, oStartLMConnector)
2013
            End If
2014

    
2015
            If sConn2Type = "Line" Then
2016
                CheckConnectionLine(dConn2_x, dConn2_y, oEndLMConnector, sEndConnectionUid)
2017
            Else
2018
                CheckConnectionSymbolToSymbol(oConn2Rows, dConn2_x, dConn2_y, oEndLMConnector)
2019
            End If
2020

    
2021
            sFirstUid = CheckExistModeling(oConn1Rows(0))
2022
            sSecondUid = CheckExistModeling(oConn2Rows(0))
2023
            Dim oCurrentLMConnector As LMConnector = Nothing
2024

    
2025
        ElseIf sConn1Type <> "" And sConn2Type = "" Then
2026
            If sConn1Type = "Line" Then
2027
                CheckConnectionLine(dConn1_x, dConn1_y, oStartLMConnector, sStartConnectionUid)
2028
            Else
2029
                CheckConnectionSymbolToSymbol(oConn1Rows, dConn1_x, dConn1_y, oStartLMConnector)
2030
                dOriginal_x = dConn1_x
2031
                dOriginal_y = dConn1_y
2032
            End If
2033

    
2034
            sFirstUid = CheckExistModeling(oConn1Rows(0))
2035

    
2036
        ElseIf sConn1Type = "" And sConn2Type <> "" Then
2037

    
2038
            If sConn1Type = "Line" Then
2039
                CheckConnectionLine(dConn2_x, dConn2_y, oEndLMConnector, sEndConnectionUid)
2040
            Else
2041
                CheckConnectionSymbolToSymbol(oConn2Rows, dConn2_x, dConn2_y, oEndLMConnector)
2042
                dOriginal_x = dConn2_x
2043
                dOriginal_y = dConn2_y
2044
            End If
2045
            sSecondUid = CheckExistModeling(oConn2Rows(0))
2046

    
2047
        ElseIf sConn3Type <> "" And sConn4Type <> "" Then
2048
            If sConn1Type = "Line" Then
2049
                CheckConnectionLine(dConn3_x, dConn3_y, oStartLMConnector, sStartConnectionUid)
2050
            Else
2051
                CheckConnectionSymbolToSymbol(oConn3Rows, dConn3_x, dConn3_y, oStartLMConnector)
2052
            End If
2053

    
2054
            If sConn2Type = "Line" Then
2055
                CheckConnectionLine(dConn4_x, dConn4_y, oEndLMConnector, sEndConnectionUid)
2056
            Else
2057
                CheckConnectionSymbolToSymbol(oConn4Rows, dConn4_x, dConn4_y, oEndLMConnector)
2058
            End If
2059

    
2060
            sFirstUid = CheckExistModeling(oConn3Rows(0))
2061
            sSecondUid = CheckExistModeling(oConn4Rows(0))
2062

    
2063
        ElseIf sConn3Type <> "" And sConn4Type = "" Then
2064
            If sConn1Type = "Line" Then
2065
                CheckConnectionLine(dConn3_x, dConn3_y, oStartLMConnector, sStartConnectionUid)
2066
            Else
2067
                CheckConnectionSymbolToSymbol(oConn3Rows, dConn3_x, dConn3_y, oStartLMConnector)
2068
                dOriginal_x = dConn3_x
2069
                dOriginal_y = dConn3_y
2070
            End If
2071

    
2072
            sFirstUid = CheckExistModeling(oConn3Rows(0))
2073

    
2074
        ElseIf sConn3Type = "" And sConn4Type <> "" Then
2075
            If sConn2Type = "Line" Then
2076
                CheckConnectionLine(dConn4_x, dConn4_y, oEndLMConnector, sEndConnectionUid)
2077
            Else
2078
                CheckConnectionSymbolToSymbol(oConn4Rows, dConn4_x, dConn4_y, oEndLMConnector)
2079
                dOriginal_x = dConn4_x
2080
                dOriginal_y = dConn4_y
2081
            End If
2082

    
2083
            sSecondUid = CheckExistModeling(oConn4Rows(0))
2084

    
2085
        Else
2086

    
2087
        End If
2088

    
2089
        If sFirstUid <> "" And sSecondUid <> "" Then
2090
            sReturnUid = sSecondUid
2091
        ElseIf sFirstUid <> "" And sSecondUid = "" Then
2092
            sReturnUid = sFirstUid
2093
        ElseIf sFirstUid <> "" And sSecondUid = "" Then
2094
            sReturnUid = sFirstUid
2095
        ElseIf sSecondUid <> "" And sFirstUid = "" Then
2096
            sReturnUid = sSecondUid
2097
        ElseIf sSecondUid <> "" And sFirstUid = "" Then
2098
            sReturnUid = sSecondUid
2099
        Else
2100
            sReturnUid = ""
2101
        End If
2102

    
2103
        If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
2104
            oLMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dOriginal_x, dOriginal_y,, dAngle)
2105
            oCurrentSymbolRow(_XML_SYMBOL_LMSYMBOL) = oLMSymbol
2106
        Else
2107
            If oStartLMConnector IsNot Nothing And oEndLMConnector IsNot Nothing Then
2108
                oLMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dOriginal_x, dOriginal_y,, dAngle)
2109
                oCurrentSymbolRow(_XML_SYMBOL_LMSYMBOL) = oLMSymbol
2110
            ElseIf oStartLMConnector IsNot Nothing And oEndLMConnector Is Nothing Then
2111
                oLMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dOriginal_x, dOriginal_y,, dAngle,,
2112
                            TargetItem:=oStartLMConnector.AsLMAItem)
2113
                oCurrentSymbolRow(_XML_SYMBOL_LMSYMBOL) = oLMSymbol
2114
            ElseIf oStartLMConnector Is Nothing And oEndLMConnector IsNot Nothing Then
2115
                oLMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dOriginal_x, dOriginal_y,, dAngle,,
2116
                TargetItem:=oEndLMConnector.AsLMAItem)
2117
                oCurrentSymbolRow(_XML_SYMBOL_LMSYMBOL) = oLMSymbol
2118
            Else
2119
                oLMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dOriginal_x, dOriginal_y,, dAngle)
2120
                oCurrentSymbolRow(_XML_SYMBOL_LMSYMBOL) = oLMSymbol
2121
            End If
2122
        End If
2123

    
2124
        '모델링 된 Symbol 데이터 테이블 저장
2125
        Dim oAddRow As DataRow = _ModelingSymbol_Dt.NewRow
2126
        oAddRow(_XML_SYMBOL_SPID) = oLMSymbol.ModelItemID
2127
        oAddRow(_XML_SYMBOL_LMSYMBOL) = oLMSymbol
2128
        oAddRow(_XML_SYMBOL_DRAWING_TF) = "TRUE"
2129
        oAddRow(_XML_SYMBOL_CENTERPOINT_X) = dOriginal_x
2130
        oAddRow(_XML_SYMBOL_CENTERPOINT_Y) = dOriginal_y
2131
        oAddRow(_XML_SYMBOL_MIN_X) = oCurrentSymbolRow(_XML_SYMBOL_MIN_X)
2132
        oAddRow(_XML_SYMBOL_MAX_X) = oCurrentSymbolRow(_XML_SYMBOL_MAX_X)
2133
        oAddRow(_XML_SYMBOL_MIN_Y) = oCurrentSymbolRow(_XML_SYMBOL_MIN_Y)
2134
        oAddRow(_XML_SYMBOL_MAX_Y) = oCurrentSymbolRow(_XML_SYMBOL_MAX_Y)
2135
        _ModelingSymbol_Dt.Rows.Add(oAddRow)
2136

    
2137
        If sChildItem <> "" Then
2138
            Dim sConn1_Systempath As String = ""
2139
            Dim sConn2_Systempath As String = ""
2140
            Dim sConn1_Angle As Double = 0
2141
            Dim sConn2_Angle As Double = 0
2142

    
2143
            For Each sDirection In sChildItem.Split("/")
2144
                Dim iType As Integer = 0
2145
                For Each sType In sDirection.Split(",")
2146
                    If sConn1_Systempath = "" Then
2147

    
2148
                        If iType = 0 Then
2149
                            sConn1_Angle = GetChildSymbolDirection(sType)
2150
                            iType = iType + 1
2151
                        Else
2152
                            Dim sStartpoint As String = oCurrentSymbolRow(_XML_SYMBOL_Conn1_Point).ToString()
2153
                            ConvertPointBystring(sStartpoint, dConn1_x, dConn1_y)
2154
                            ConvertPointByImage(dConn1_x, dConn1_y, _IMG_X, _IMG_Y)
2155
                            sConn1_Systempath = GetDataFromMappingDB(sType, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
2156
                            Dim dChildConn1_x As Double = 0
2157
                            Dim dChildConn1_y As Double = 0
2158

    
2159
                            If oLMSymbol IsNot Nothing Then
2160
                                _Placement.PIDConnectPointLocation(oLMSymbol, 1, dChildConn1_x, dChildConn1_y)
2161
                                _Placement.PIDPlaceSymbol(sConn1_Systempath, dChildConn1_x, dChildConn1_y,, sConn1_Angle,,
2162
                                 TargetItem:=oLMSymbol.AsLMAItem)
2163
                            Else
2164
                                _Placement.PIDPlaceSymbol(sConn1_Systempath, dConn1_x, dConn1_y,, sConn1_Angle,,)
2165
                            End If
2166
                        End If
2167

    
2168
                    Else
2169
                        If iType = 0 Then
2170
                            sConn2_Angle = GetChildSymbolDirection(sType)
2171
                            iType = iType + 1
2172
                        Else
2173
                            Dim sEndPoint As String = oCurrentSymbolRow(_XML_SYMBOL_Conn2_Point).ToString()
2174
                            ConvertPointBystring(sEndPoint, dConn2_x, dConn2_y)
2175
                            ConvertPointByImage(dConn2_x, dConn2_y, _IMG_X, _IMG_Y)
2176
                            sConn2_Systempath = GetDataFromMappingDB(sType, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
2177

    
2178
                            Dim dChildConn2_x As Double = 0
2179
                            Dim dChildConn2_y As Double = 0
2180

    
2181
                            If oLMSymbol IsNot Nothing Then
2182
                                _Placement.PIDConnectPointLocation(oLMSymbol, 2, dChildConn2_x, dChildConn2_y)
2183
                                _Placement.PIDPlaceSymbol(sConn1_Systempath, dChildConn2_x, dChildConn2_y,, sConn2_Angle,,
2184
                                        TargetItem:=oLMSymbol.AsLMAItem)
2185
                            Else
2186
                                _Placement.PIDPlaceSymbol(sConn2_Systempath, dChildConn2_x, dChildConn2_y,, sConn2_Angle,,)
2187
                            End If
2188

    
2189
                        End If
2190
                    End If
2191
                Next
2192
            Next
2193
        End If
2194

    
2195
        AddProgress()
2196

    
2197
        SetListBoxItems(ListBox_Result, "Place Fitting.." & sUid & " (" & dOriginal_x & "," & dOriginal_y & ")..." & _iFittingcnt & " count ")
2198
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Fitting : " & sUid)
2199
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "LineNo : " & sLineNoText)
2200
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "ModelingType : " & iModelingType)
2201
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Conn1_Point : " & dConn1_x & "," & dConn1_y)
2202
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Conn2_Point : " & dConn2_x & "," & dConn2_y)
2203
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Conn3_Point : " & dConn3_x & "," & dConn3_y)
2204
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Conn4_Point : " & dConn4_x & "," & dConn4_y)
2205
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection1 : " & oCurrentSymbolRow(_XML_SYMBOL_Conn1_Uid).ToString())
2206
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection2 : " & oCurrentSymbolRow(_XML_SYMBOL_Conn2_Uid).ToString())
2207
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection3 : " & oCurrentSymbolRow(_XML_SYMBOL_Conn3_Uid).ToString())
2208
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection4 : " & oCurrentSymbolRow(_XML_SYMBOL_Conn4_Uid).ToString())
2209
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
2210
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "OriginalPoint : " & dOriginal_x & "," & dOriginal_y)
2211
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Fitting Count : " & _iFittingcnt)
2212
        _iFittingcnt = _iFittingcnt + 1
2213
        oCurrentSymbolRow(_XML_SYMBOL_DRAWING_TF) = "TRUE"
2214

    
2215
        Dim oAttributeRow() As DataRow
2216
        oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
2217
        If oAttribute_Dt.Rows.Count > 0 Then
2218

    
2219
            If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
2220
                Dim oInstrument As LMInstrument
2221
                oInstrument = _Placement.PIDDataSource.GetInstrument(oLMSymbol.ModelItemID)
2222
                Try
2223
                    If oAttributeRow.Length > 0 Then
2224
                        For Each oAttribute In oAttributeRow
2225
                            Try
2226
                                Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
2227
                                Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
2228
                                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
2229
                                oInstrument.Attributes(sSPPIDAttribute).Value = sPIDValue
2230
                            Catch ex As Exception
2231
                            End Try
2232
                        Next
2233
                        oInstrument.Commit()
2234
                    End If
2235
                Catch ex As Exception
2236
                End Try
2237
            Else
2238
                Try
2239
                    If oAttributeRow.Length > 0 And oLMSymbol IsNot Nothing Then
2240
                        For Each oAttribute In oAttributeRow
2241
                            Try
2242
                                Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
2243
                                Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
2244
                                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
2245
                                oLMSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
2246

    
2247
                            Catch ex As Exception
2248
                            End Try
2249
                        Next
2250
                        oLMSymbol.Commit()
2251
                    End If
2252
                Catch ex As Exception
2253
                End Try
2254
            End If
2255
        End If
2256

    
2257
        Return sReturnUid
2258
    End Function
2259
    Private Function GetChildSymbolDirection(ByVal sDirection As String) As Double
2260
        Dim sReturnDirection As String = ""
2261
        If sDirection.ToUpper() = "RIGHT" Then
2262
            Return 3.14
2263
        ElseIf sDirection.ToUpper() = "LEFT" Then
2264
            Return 0
2265
        ElseIf sDirection.ToUpper = "DOWN" Then
2266
            Return 1.57
2267
        ElseIf sDirection.ToUpper() = "UP" Then
2268
            Return 4.71
2269
        Else
2270
            Return 0
2271
        End If
2272
    End Function
2273

    
2274
    Private Function CheckExistModeling(ByVal oRow As DataRow) As String
2275
        If oRow(_XML_LINE_DRAWING_TF).ToString() = "FALSE" And oRow(_XML_LINE_Check).ToString() = "TRUE" Then
2276
            Return oRow(_XML_LINE_UID).ToString()
2277
        End If
2278
        Return String.Empty
2279
    End Function
2280

    
2281

    
2282
    Private Sub ConvertPoint(ByVal sOriginalPoint As String, ByRef dConn1_x As Double, ByRef dConn1_y As Double)
2283
        ConvertPointBystring(sOriginalPoint, dConn1_x, dConn1_y)
2284
        ConvertPointByImage(dConn1_x, dConn1_y, _IMG_X, _IMG_Y)
2285
    End Sub
2286

    
2287
    Private Function FinalLineModeling(ByVal oCurrentLineRow As DataRow,
2288
                              ByVal oLine_Dt As DataTable, ByVal oSymbol_Dt As DataTable,
2289
                                  ByVal oAttribute_Dt As DataTable) As String
2290
        Dim sReturnUid As String = ""
2291
        Try
2292
            Dim bCheckBranchItem As Boolean = False
2293
            Dim dCenterPos_x As Double = 0.0
2294
            Dim dCenterPos_y As Double = 0.0
2295
            Dim objItem As LMAItem
2296
            Dim sUid As String = oCurrentLineRow(_XML_LINE_UID).ToString()
2297
            Dim sLineType As String = oCurrentLineRow(_XML_LINE_TYPE).ToString()
2298
            Dim sSystemPath As String = GetPipeType(sLineType)
2299
            Dim sLineNoText As String = oCurrentLineRow(_XML_LINENO_TEXT).ToString()
2300
            Dim sLineNoUid As String = oCurrentLineRow(_XML_LINE_LINENOUID).ToString()
2301
            Dim dStart_Dwg_x As Double = oCurrentLineRow(_XML_LINE_DWG_STARTPOINT_X)
2302
            Dim dStart_Dwg_y As Double = oCurrentLineRow(_XML_LINE_DWG_STARTPOINT_Y)
2303
            Dim dEnd_Dwg_x As Double = oCurrentLineRow(_XML_LINE_DWG_ENDPOINT_X)
2304
            Dim dEnd_Dwg_y As Double = oCurrentLineRow(_XML_LINE_DWG_ENDPOINT_Y)
2305
            Dim sPreFlowDirection As String = ""
2306
            Dim sFlowDirection As String = oCurrentLineRow(_XML_LINE_FlowDirection)
2307
            Dim sPreConn1Direction As String = ""
2308
            Dim sPreConn2Direction As String = ""
2309
            Dim sDirection As String = oCurrentLineRow(_XML_LINE_Direction)
2310
            dCenterPos_x = Math.Abs(dStart_Dwg_x + dEnd_Dwg_x) / 2
2311
            dCenterPos_y = Math.Abs(dStart_Dwg_y + dEnd_Dwg_y) / 2
2312
            Dim oPidDataSource As LMADataSource = Nothing
2313
            Try
2314
                oPidDataSource = _Placement.PIDDataSource
2315
            Catch ex As Exception
2316
                CheckOpenDrawing()
2317
                oPidDataSource = _Placement.PIDDataSource
2318
            End Try
2319
            'Connection 정보 체크, 모델링 되어 있는지 유무
2320
            '양 커넥션의 모델링 유무를 체크한다.
2321
            Dim sConn1Uid As String = oCurrentLineRow(_XML_LINE_Conn1_Uid).ToString()
2322
            Dim sConn2Uid As String = oCurrentLineRow(_XML_LINE_Conn2_Uid).ToString()
2323
            Dim sConn1Type As String = ""
2324
            Dim sConn2Type As String = ""
2325
            Dim oConn1Rows() As DataRow = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "] = '" & sConn1Uid & "'")
2326
            If oConn1Rows.Length = 0 Then
2327
                oConn1Rows = oLine_Dt.Select("[" & _XML_LINE_UID & "] = '" & sConn1Uid & "'")
2328
                If oConn1Rows.Length = 1 Then
2329
                    sConn1Type = "Line"
2330
                End If
2331
            Else
2332
                Dim oOriginalPoint As String = oConn1Rows(0)(_XML_SYMBOL_ORIGINALPOINT)
2333
                ConvertPointBystring(oOriginalPoint, dStart_Dwg_x, dStart_Dwg_y)
2334
                ConvertPointByImage(dStart_Dwg_x, dStart_Dwg_y, _IMG_X, _IMG_Y)
2335
                oCurrentLineRow(_XML_LINE_DWG_STARTPOINT_X) = dStart_Dwg_x
2336
                oCurrentLineRow(_XML_LINE_DWG_STARTPOINT_Y) = dStart_Dwg_y
2337
                sConn1Type = "Symbol"
2338
            End If
2339
            Dim oConn2Rows() As DataRow = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "] = '" & sConn2Uid & "'")
2340
            If oConn2Rows.Length = 0 Then
2341
                oConn2Rows = oLine_Dt.Select("[" & _XML_LINE_UID & "] = '" & sConn2Uid & "'")
2342
                If oConn2Rows.Length = 1 Then
2343
                    sConn2Type = "Line"
2344
                End If
2345
            Else
2346
                Dim oOriginalPoint As String = oConn2Rows(0)(_XML_SYMBOL_ORIGINALPOINT)
2347
                ConvertPointBystring(oOriginalPoint, dEnd_Dwg_x, dEnd_Dwg_y)
2348
                ConvertPointByImage(dEnd_Dwg_x, dEnd_Dwg_y, _IMG_X, _IMG_Y)
2349
                oCurrentLineRow(_XML_LINE_DWG_ENDPOINT_X) = dEnd_Dwg_x
2350
                oCurrentLineRow(_XML_LINE_DWG_ENDPOINT_Y) = dEnd_Dwg_y
2351
                sConn2Type = "Symbol"
2352
            End If
2353
            Dim sConn1LineNo As String = ""
2354
            Dim sConn2LineNo As String = ""
2355
            Dim oLMConnector As LMConnector = Nothing
2356
            Dim oStartLMConnector As LMConnector = Nothing
2357
            Dim oEndLMConnector As LMConnector = Nothing
2358
            Dim oLMSymbol1 As LMSymbol = Nothing
2359
            Dim oLMSymbol2 As LMSymbol = Nothing
2360
            Dim objInputs As PlaceRunInputs
2361
            objInputs = New PlaceRunInputs
2362
            Dim iModelingType As Integer = 0
2363
            If sConn1Type = "Line" And sConn2Type = "Line" Then
2364
                iModelingType = 1
2365
            ElseIf sConn1Type = "Line" And sConn2Type = "Symbol" Then
2366
                iModelingType = 1
2367
            ElseIf sConn1Type = "Symbol" And sConn2Type = "Line" Then
2368
                iModelingType = 1
2369
            ElseIf sConn1Type = "Symbol" And sConn2Type = "Symbol" Then
2370
                iModelingType = 1
2371
            ElseIf sConn1Type = "Line" And sConn2Type = "" Then
2372
                iModelingType = 2
2373
            ElseIf sConn1Type = "Symbol" And sConn2Type = "" Then
2374
                iModelingType = 2
2375
            ElseIf sConn1Type = "" And sConn2Type = "Line" Then
2376
                iModelingType = 3
2377
            ElseIf sConn1Type = "" And sConn2Type = "Symbol" Then
2378
                iModelingType = 3
2379
            Else
2380
                iModelingType = 4
2381
            End If
2382
            Dim dPreConnX As Double = 0
2383
            Dim dPreConnY As Double = 0
2384
            Dim sStartConnectionUid As String = ""
2385
            Dim sEndConnectionUid As String = ""
2386
            Dim bAlreadyCheckBranchLine As Boolean = False
2387
            '브런치라인이 먼저있는상태에서 메인라인을 그릴경우..해당되는 브런치라인 수 만큼 라인을 따로 생성 
2388
            If CheckAlreadyBranchLine(sSystemPath, dStart_Dwg_x, dStart_Dwg_y, dEnd_Dwg_x, dEnd_Dwg_y) = False Then
2389

    
2390
                CheckConnectionLine(dStart_Dwg_x, dStart_Dwg_y, oStartLMConnector, sStartConnectionUid)
2391
                If oStartLMConnector Is Nothing Then
2392
                    bCheckBranchItem = UpdateCheckBranchLine(dStart_Dwg_x, dStart_Dwg_y, oStartLMConnector, sStartConnectionUid)
2393
                    If oStartLMConnector Is Nothing Then
2394
                        oLMSymbol1 = CheckConnectionSymbolToLine(oConn1Rows, dStart_Dwg_x, dStart_Dwg_y, dCenterPos_x, dCenterPos_y, oStartLMConnector)
2395
                        If oLMSymbol1 IsNot Nothing Then
2396
                            sConn1Type = "Symbol"
2397
                        Else
2398
                            sConn1Type = ""
2399
                        End If
2400
                    Else
2401
                        sConn1Type = "Line"
2402
                    End If
2403
                Else
2404
                    sConn1Type = "Line"
2405
                End If
2406
                CheckConnectionLine(dEnd_Dwg_x, dEnd_Dwg_y, oEndLMConnector, sEndConnectionUid)
2407
                If oEndLMConnector Is Nothing Then
2408
                    bCheckBranchItem = UpdateCheckBranchLine(dEnd_Dwg_x, dEnd_Dwg_y, oEndLMConnector, sEndConnectionUid)
2409
                    If oEndLMConnector Is Nothing Then
2410
                        oLMSymbol2 = CheckConnectionSymbolToLine(oConn2Rows, dEnd_Dwg_x, dEnd_Dwg_y, dCenterPos_x, dCenterPos_y, oEndLMConnector)
2411
                        If oLMSymbol2 IsNot Nothing Then
2412
                            sConn2Type = "Symbol"
2413
                        End If
2414
                    Else
2415
                        sConn2Type = "Line"
2416
                    End If
2417
                Else
2418
                    sConn2Type = "Line"
2419
                End If
2420
                Dim sFirstUid As String = ""
2421
                Dim sSecondUid As String = ""
2422
                Try
2423
                    If oStartLMConnector Is Nothing And oEndLMConnector Is Nothing Then
2424
                        If oLMSymbol1 Is Nothing Then
2425
                            objInputs.AddPoint(dStart_Dwg_x, dStart_Dwg_y)
2426
                        Else
2427
                            objInputs.AddSymbolTarget(oLMSymbol1, dStart_Dwg_x, dStart_Dwg_y)
2428
                        End If
2429

    
2430
                        If oLMSymbol2 Is Nothing Then
2431
                            objInputs.AddPoint(dEnd_Dwg_x, dEnd_Dwg_y)
2432
                        Else
2433
                            objInputs.AddSymbolTarget(oLMSymbol2, dEnd_Dwg_x, dEnd_Dwg_y)
2434
                        End If
2435

    
2436
                    ElseIf oStartLMConnector IsNot Nothing And oEndLMConnector Is Nothing Then
2437
                        If sConn1Type = "Line" Then
2438
                            objInputs.AddConnectorTarget(oStartLMConnector, dStart_Dwg_x, dStart_Dwg_y)
2439
                        Else
2440
                            objInputs.AddSymbolTarget(oLMSymbol1, dStart_Dwg_x, dStart_Dwg_y)
2441
                        End If
2442
                        If oLMSymbol2 Is Nothing Then
2443
                            objInputs.AddPoint(dEnd_Dwg_x, dEnd_Dwg_y)
2444
                        Else
2445
                            objInputs.AddSymbolTarget(oLMSymbol2, dEnd_Dwg_x, dEnd_Dwg_y)
2446
                        End If
2447

    
2448
                    ElseIf oStartLMConnector Is Nothing And oEndLMConnector IsNot Nothing Then
2449
                        If sConn2Type = "Line" Then
2450
                            objInputs.AddConnectorTarget(oEndLMConnector, dEnd_Dwg_x, dEnd_Dwg_y)
2451
                        Else
2452
                            objInputs.AddSymbolTarget(oLMSymbol2, dEnd_Dwg_x, dEnd_Dwg_y)
2453
                        End If
2454
                        If oLMSymbol1 Is Nothing Then
2455
                            objInputs.AddPoint(dStart_Dwg_x, dStart_Dwg_y)
2456
                        Else
2457
                            objInputs.AddSymbolTarget(oLMSymbol1, dStart_Dwg_x, dStart_Dwg_y)
2458
                        End If
2459

    
2460
                    Else
2461
                        If sConn1Type = "Line" Then
2462
                            objInputs.AddConnectorTarget(oStartLMConnector, dStart_Dwg_x, dStart_Dwg_y)
2463
                        Else
2464
                            objInputs.AddSymbolTarget(oLMSymbol1, dStart_Dwg_x, dStart_Dwg_y)
2465
                        End If
2466
                        If sConn2Type = "Line" Then
2467
                            objInputs.AddConnectorTarget(oEndLMConnector, dEnd_Dwg_x, dEnd_Dwg_y)
2468
                        Else
2469
                            objInputs.AddSymbolTarget(oLMSymbol2, dEnd_Dwg_x, dEnd_Dwg_y)
2470
                        End If
2471

    
2472
                    End If
2473
                    If sConn1Type <> "" And sConn2Type <> "" Then
2474
                        If oConn1Rows.Count > 0 Then
2475
                            sFirstUid = CheckExistModeling(oConn1Rows(0))
2476
                        End If
2477
                        If oConn2Rows.Count > 0 Then
2478
                            sSecondUid = CheckExistModeling(oConn2Rows(0))
2479
                        End If
2480

    
2481
                    ElseIf sConn1Type <> "" And sConn2Type = "" Then
2482
                        If oConn1Rows.Count > 0 Then
2483
                            sFirstUid = CheckExistModeling(oConn1Rows(0))
2484
                        End If
2485

    
2486
                    ElseIf sConn1Type = "" And sConn2Type <> "" Then
2487
                        If oConn2Rows.Count > 0 Then
2488
                            sSecondUid = CheckExistModeling(oConn2Rows(0))
2489
                        End If
2490

    
2491
                    End If
2492

    
2493
                    If sFirstUid <> "" And sSecondUid <> "" Then
2494
                        sReturnUid = sSecondUid
2495
                    ElseIf sFirstUid = "" And sSecondUid <> "" Then
2496
                        sReturnUid = sSecondUid
2497
                    ElseIf sFirstUid <> "" And sSecondUid = "" Then
2498
                        sReturnUid = sFirstUid
2499
                    Else
2500
                        sReturnUid = ""
2501
                    End If
2502
                    _iPipecnt = _iPipecnt + 1
2503

    
2504
                    '배관 모델링
2505
                    Dim oCurrentConnector As LMConnector = LineModeling(objInputs, sSystemPath)
2506

    
2507
                    If oCurrentConnector IsNot Nothing Then
2508
                        oCurrentLineRow(_XML_LINE_LMCONNECTOR) = oCurrentConnector
2509
                        oCurrentLineRow(_XML_LINE_DRAWING_TF) = "TRUE"
2510
                        '로그 출력
2511
                        AddLog(sUid, sSystemPath, dStart_Dwg_x, dStart_Dwg_y, dEnd_Dwg_x, dEnd_Dwg_y, sLineNoText, sConn1Uid, sConn2Uid)
2512
                        Dim oPipeRun As LMPipeRun = oPidDataSource.GetPipeRun(oCurrentConnector.ModelItemID)
2513
                        '배관 속성 입력
2514
                        AddAttribute(oPipeRun, oAttribute_Dt, sLineNoUid)
2515

    
2516
                        Dim sID_1 As String = ""
2517
                        Dim sID_2 As String = ""
2518
                        Dim oAddConnector As LMConnector = Nothing
2519
                        If oStartLMConnector IsNot Nothing Then
2520
                            sID_1 = oStartLMConnector.ModelItemID
2521
                            sID_2 = oCurrentConnector.ModelItemID
2522
                            oAddConnector = oStartLMConnector
2523
                        ElseIf oEndLMConnector IsNot Nothing Then
2524
                            sID_1 = oEndLMConnector.ModelItemID
2525
                            sID_2 = oCurrentConnector.ModelItemID
2526
                            oAddConnector = oEndLMConnector
2527
                        End If
2528
                        If sID_1 <> "" And sID_2 <> "" Then
2529
                            'PipeRun 합치기
2530

    
2531

    
2532
                            If bCheckBranchItem Then
2533
                                '모델링 된 PipeLine 데이터 테이블 저장
2534
                                AddModelingDT(sUid, oCurrentConnector.ModelItemID, oCurrentConnector, dStart_Dwg_x, dStart_Dwg_y, dEnd_Dwg_x, dEnd_Dwg_y)
2535
                            Else
2536
                                JoinPipeRun(sID_1, sID_2)
2537
                                '모델링 된 PipeLine 데이터 테이블 저장
2538
                                AddModelingDT(sUid, sID_1, oAddConnector, dStart_Dwg_x, dStart_Dwg_y, dEnd_Dwg_x, dEnd_Dwg_y)
2539
                            End If
2540
                        Else
2541
                            '모델링 된 PipeLine 데이터 테이블 저장
2542
                            AddModelingDT(sUid, oCurrentConnector.ModelItemID, oCurrentConnector, dStart_Dwg_x, dStart_Dwg_y, dEnd_Dwg_x, dEnd_Dwg_y)
2543
                        End If
2544
                        If bCheckBranchItem = False Then
2545
                            '//2018.09.07 LMControl에 따라서 inconsitency가 달라지는듯 확인
2546
                            If sStartConnectionUid <> "" Then
2547
                                Dim oChangeRow() As DataRow = _ModelingLine_Dt.Select(_XML_LINE_UID & " = '" & sStartConnectionUid & "'")
2548
                                If oChangeRow.Length = 1 Then
2549
                                    oChangeRow(0)(_XML_LINE_SPID) = sID_1
2550
                                    oChangeRow(0)(_XML_LINE_LMCONNECTOR) = oAddConnector
2551
                                End If
2552
                            End If
2553
                            If sEndConnectionUid <> "" Then
2554
                                Dim oChangeRow() As DataRow = _ModelingLine_Dt.Select(_XML_LINE_UID & " = '" & sEndConnectionUid & "'")
2555
                                If oChangeRow.Length = 1 Then
2556
                                    oChangeRow(0)(_XML_LINE_SPID) = sID_1
2557
                                    oChangeRow(0)(_XML_LINE_LMCONNECTOR) = oAddConnector
2558
                                End If
2559
                            End If
2560
                        End If
2561

    
2562
                    Else
2563
                        sReturnUid = ""
2564
                    End If
2565
                Catch ex As Exception
2566
                End Try
2567
            End If
2568
        Catch ex As Exception
2569
        End Try
2570
        Return sReturnUid
2571
        '현재 Uid 모델링
2572
    End Function
2573
    Private Sub AddLog(ByVal sUid As String, ByVal sSystemPath As String,
2574
                             ByVal dStart_Dwg_x As Double, ByVal dStart_Dwg_y As Double, ByVal dEnd_Dwg_x As Double, ByVal dEnd_Dwg_y As Double,
2575
                       ByVal sLineNoText As String, ByVal sConn1Uid As String, ByVal sConn2Uid As String)
2576
        SetListBoxItems(ListBox_Result, "Place Pipe.." & sUid & " (" & dStart_Dwg_x & "," & dStart_Dwg_y & ") - (" & dEnd_Dwg_x & "," & dEnd_Dwg_y & ")..." & _iPipecnt & " count ")
2577
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Pipe : " & sUid)
2578
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "LineNo : " & sLineNoText)
2579
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection1 : " & sConn1Uid)
2580
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection2 : " & sConn2Uid)
2581
        'ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
2582
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "StartPoint : " & dStart_Dwg_x & "," & dStart_Dwg_y)
2583
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "EndPoint : " & dEnd_Dwg_x & "," & dEnd_Dwg_y)
2584
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Pipe Count : " & _iPipecnt)
2585
    End Sub
2586

    
2587
    Private Sub AddAttribute(ByVal oPipeRun As LMPipeRun, ByVal oAttribute_Dt As DataTable, ByVal sLineNoUid As String)
2588
        Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
2589
        If oAttributeRow.Length > 0 Then
2590
            For Each oAttribute In oAttributeRow
2591
                Try
2592
                    Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
2593
                    Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
2594
                    If sPIDValue.Contains("'") Then
2595
                        sPIDValue = sPIDValue.Replace("'", """")
2596
                    End If
2597
                    Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
2598
                    oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
2599
                Catch ex As Exception
2600
                End Try
2601
            Next
2602
            oPipeRun.Commit()
2603
        End If
2604
    End Sub
2605

    
2606
    Private Sub AddModelingDT(ByVal sUid As String, ByVal sModelID As String, ByVal oCurrentConnector As LMConnector,
2607
                              ByVal dStart_Dwg_x As Double, ByVal dStart_Dwg_y As Double,
2608
                              ByVal dEnd_Dwg_x As Double, ByVal dEnd_Dwg_y As Double)
2609
        Dim oAddRow As DataRow = _ModelingLine_Dt.NewRow
2610
        oAddRow(_XML_LINE_UID) = sUid
2611
        oAddRow(_XML_LINE_SPID) = sModelID
2612
        oAddRow(_XML_LINE_LMCONNECTOR) = oCurrentConnector
2613
        oAddRow(_XML_LINE_DRAWING_TF) = "TRUE"
2614
        oAddRow(_XML_LINE_DWG_STARTPOINT_X) = dStart_Dwg_x
2615
        oAddRow(_XML_LINE_DWG_STARTPOINT_Y) = dStart_Dwg_y
2616
        oAddRow(_XML_LINE_DWG_ENDPOINT_X) = dEnd_Dwg_x
2617
        oAddRow(_XML_LINE_DWG_ENDPOINT_Y) = dEnd_Dwg_y
2618
        _ModelingLine_Dt.Rows.Add(oAddRow)
2619
    End Sub
2620

    
2621
    Private Function JoinPipeRun(ByVal sID_1 As String, ByVal sID_2 As String) As Boolean
2622
        Try
2623
            Dim objSurvivorItem As LMAItem = Nothing
2624
            Dim oPipeRun1 As LMPipeRun = _Placement.PIDDataSource.GetPipeRun(sID_1)
2625
            Dim oPipeRun2 As LMPipeRun = _Placement.PIDDataSource.GetPipeRun(sID_2)
2626
            _Placement.PIDJoinRuns(oPipeRun1, oPipeRun2)
2627
            Return True
2628
        Catch ex As Exception
2629
            Return False
2630
        End Try
2631
    End Function
2632

    
2633

    
2634
    Private Function LineModeling(ByVal objInputs As PlaceRunInputs, ByVal sSystemPath As String) As LMConnector
2635
        Dim oCurrentConnector As LMConnector = Nothing
2636
        Dim objItem As LMAItem
2637
        objItem = _Placement.PIDCreateItem(sSystemPath)
2638
        Try
2639
            oCurrentConnector = _Placement.PIDPlaceRun(objItem, objInputs)
2640
            AddProgress()
2641
        Catch ex As Exception
2642
        End Try
2643
        Return oCurrentConnector
2644
    End Function
2645

    
2646
    Private Sub InstumentLineModeling(ByVal CLineNo As Line_no, ByVal oNode As TreeNode)
2647
        If CLineNo IsNot Nothing Then
2648
            Dim oLine_Dt As DataTable = CLineNo.Dt_Line
2649
            Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
2650
            Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
2651
            Dim oDrawLinenoLabel As Boolean = False
2652
            For Each oSymbolNode As TreeNode In oNode.Nodes
2653
                If oSymbolNode.Checked Then
2654
                    Try
2655
                        Dim sUid As String = oSymbolNode.Name
2656
                        Dim sLineNoUid As String = CLineNo.Uid
2657
                        Dim sReturnUid = sUid
2658
                        '  FinalModeling(sUid, oLine_Dt, oSymbol_Dt, oAttribute_Dt)
2659
                        While True
2660
                            Dim oLineRows As DataRow() = oLine_Dt.Select(_XML_LINE_UID & " = '" & sReturnUid & "' And [" & _XML_SYMBOL_DRAWING_TF & "] = 'False' And [" &
2661
                                               _XML_SYMBOL_Check & "] = 'TRUE' And [" & _XML_LINE_ValieLine & "] = 'True'")
2662
                            If oLineRows.Count > 0 Then
2663
                                Dim sPipeType As String = oLineRows(0)(_XML_LINE_TYPE).ToString()
2664
                                If sPipeType.ToUpper() <> "PRIMARY" Then
2665
                                    sReturnUid = FinalLineModeling(oLineRows(0), oLine_Dt, oSymbol_Dt, oAttribute_Dt)
2666
                                Else
2667
                                    sReturnUid = ""
2668
                                End If
2669
                            Else
2670
                                sReturnUid = ""
2671
                            End If
2672
                            If sReturnUid = "" Then
2673
                                Exit While
2674
                            End If
2675
                        End While
2676
                    Catch ex As Exception
2677
                    End Try
2678
                End If
2679
            Next
2680
        End If
2681
    End Sub
2682

    
2683
    Private Sub PipeLineModeling(ByVal CLineNo As Line_no, ByVal oNode As TreeNode)
2684
        If CLineNo IsNot Nothing Then
2685
            Dim oLine_Dt As DataTable = CLineNo.Dt_Line
2686
            Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
2687
            Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
2688
            Dim oDrawLinenoLabel As Boolean = False
2689
            Try
2690
                ManualCheckNode(oLine_Dt)
2691
                ManualCheckNode(oSymbol_Dt)
2692
            Catch ex As Exception
2693
            End Try
2694
            For Each oSymbolNode As TreeNode In oNode.Nodes
2695
                If oSymbolNode.Checked Then
2696
                    Try
2697
                        Dim sUid As String = oSymbolNode.Name
2698
                        Dim sLineNoUid As String = CLineNo.Uid
2699
                        Dim sReturnUid = sUid
2700
                        '  FinalModeling(sUid, oLine_Dt, oSymbol_Dt, oAttribute_Dt)
2701
                        While True
2702
                            Dim oLineRows As DataRow() = oLine_Dt.Select(_XML_LINE_UID & " = '" & sReturnUid & "' And [" & _XML_SYMBOL_DRAWING_TF & "] = 'False' And [" &
2703
                                               _XML_SYMBOL_Check & "] = 'TRUE' And [" & _XML_LINE_ValieLine & "] = 'True'")
2704
                            If oLineRows.Count > 0 Then
2705
                                Dim sPipeType As String = oLineRows(0)(_XML_LINE_TYPE).ToString()
2706
                                If sPipeType.ToUpper() = "PRIMARY" Then
2707
                                    sReturnUid = FinalLineModeling(oLineRows(0), oLine_Dt, oSymbol_Dt, oAttribute_Dt)
2708
                                Else
2709
                                    sReturnUid = ""
2710
                                End If
2711

    
2712
                            Else
2713
                                sReturnUid = ""
2714
                            End If
2715
                            If sReturnUid = "" Then
2716
                                Exit While
2717
                            End If
2718
                        End While
2719
                    Catch ex As Exception
2720
                    End Try
2721
                End If
2722
            Next
2723
        End If
2724
    End Sub
2725

    
2726
    Private Sub InstrumentSymbolModeling(ByVal CLineNo As Line_no, ByVal oNode As TreeNode)
2727
        If CLineNo IsNot Nothing Then
2728
            Dim oLine_Dt As DataTable = CLineNo.Dt_Line
2729
            Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
2730
            Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
2731
            Dim oDrawLinenoLabel As Boolean = False
2732
            Try
2733
                ManualCheckNode(oLine_Dt)
2734
                ManualCheckNode(oSymbol_Dt)
2735
            Catch ex As Exception
2736
            End Try
2737
            For Each oSymbolNode As TreeNode In oNode.Nodes
2738
                If oSymbolNode.Checked Then
2739
                    Try
2740
                        Dim sUid As String = oSymbolNode.Name
2741
                        Dim sLineNoUid As String = CLineNo.Uid
2742
                        Dim sReturnUid = sUid
2743
                        '  FinalModeling(sUid, oLine_Dt, oSymbol_Dt, oAttribute_Dt)
2744
                        Dim oSymbolRows As DataRow() = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "]= '" & sReturnUid & "' And [" & _XML_SYMBOL_DRAWING_TF & "] = 'FALSE' And [" &
2745
                                                                           _XML_SYMBOL_Check & "] = 'TRUE'")
2746
                        If oSymbolRows.Count > 0 Then
2747
                            Dim sSymbolType As String = oSymbolRows(0)(_XML_SYMBOL_TYPE).ToString().ToUpper()
2748
                            If sSymbolType = "INSTRUMENT" Then
2749
                                sReturnUid = FinalSymbolModeling(oSymbolRows(0), oLine_Dt, oSymbol_Dt, oAttribute_Dt)
2750
                            End If
2751
                        Else
2752
                            sReturnUid = ""
2753
                        End If
2754
                        If sReturnUid = "" Then
2755
                        End If
2756
                    Catch ex As Exception
2757
                    End Try
2758
                End If
2759
            Next
2760
        End If
2761
    End Sub
2762

    
2763
    Private Sub PipeSymbolModeling(ByVal CLineNo As Line_no, ByVal oNode As TreeNode)
2764
        If CLineNo IsNot Nothing Then
2765
            Dim oLine_Dt As DataTable = CLineNo.Dt_Line
2766
            Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
2767
            Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
2768
            Dim oDrawLinenoLabel As Boolean = False
2769
            Try
2770
                ManualCheckNode(oLine_Dt)
2771
                ManualCheckNode(oSymbol_Dt)
2772
            Catch ex As Exception
2773
            End Try
2774
            For Each oSymbolNode As TreeNode In oNode.Nodes
2775
                If oSymbolNode.Checked Then
2776
                    Try
2777
                        Dim sUid As String = oSymbolNode.Name
2778
                        Dim sLineNoUid As String = CLineNo.Uid
2779
                        Dim sReturnUid = sUid
2780
                        '  FinalModeling(sUid, oLine_Dt, oSymbol_Dt, oAttribute_Dt)
2781
                        Dim oSymbolRows As DataRow() = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "]= '" & sReturnUid & "' And [" & _XML_SYMBOL_DRAWING_TF & "] = 'FALSE' And [" &
2782
                                                                           _XML_SYMBOL_Check & "] = 'TRUE'")
2783
                        If oSymbolRows.Count > 0 Then
2784
                            Dim sSymbolType As String = oSymbolRows(0)(_XML_SYMBOL_TYPE).ToString().ToUpper()
2785
                            If sSymbolType <> "INSTRUMENT" Then
2786
                                sReturnUid = FinalSymbolModeling(oSymbolRows(0), oLine_Dt, oSymbol_Dt, oAttribute_Dt)
2787
                            End If
2788
                        Else
2789
                            sReturnUid = ""
2790
                        End If
2791
                        If sReturnUid = "" Then
2792
                        End If
2793
                    Catch ex As Exception
2794
                    End Try
2795
                End If
2796
            Next
2797
        End If
2798
    End Sub
2799

    
2800
    Private Sub PipingModeling()
2801

    
2802
        Try
2803
            For Each oDrwing As TreeNode In Tree_Result.Nodes
2804
                For Each oDwgNode As TreeNode In oDrwing.Nodes
2805
                    Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
2806
                    Dim CDrawing As Drawing = GetDrawing(sDwgName)
2807
                    If CDrawing IsNot Nothing Then
2808
                        Dim iAllLineNoCount As Integer = Tree_Result.Nodes.Count ' GetCheckNodeCount(oLinenoNode)
2809
                        Dim iPipingOPC_count As Integer = 0 ' GetCheckNodeCount(oLinenoNode)
2810

    
2811
                        'PipeModeling
2812
                        For Each oNode As TreeNode In oDwgNode.Nodes
2813
                            Dim iItemcnt As Integer = 0
2814
                            Dim sNodeUid As String = oNode.Name
2815
                            Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
2816
                            Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
2817
                            PipeLineModeling(CLineNo, oNode)
2818
                            Dim CTrimLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
2819
                            PipeLineModeling(CTrimLineNo, oNode)
2820
                        Next
2821

    
2822
                        'Instrument Modeling
2823
                        For Each oNode As TreeNode In oDwgNode.Nodes
2824
                            Dim iItemcnt As Integer = 0
2825
                            Dim sNodeUid As String = oNode.Name
2826
                            Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
2827
                            Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
2828
                            InstrumentSymbolModeling(CLineNo, oNode)
2829
                            Dim CTrimLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
2830
                            InstrumentSymbolModeling(CTrimLineNo, oNode)
2831
                        Next
2832

    
2833
                        'Instrument Line Modeling
2834
                        For Each oNode As TreeNode In oDwgNode.Nodes
2835
                            Dim iItemcnt As Integer = 0
2836
                            Dim sNodeUid As String = oNode.Name
2837
                            Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
2838
                            Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
2839
                            InstumentLineModeling(CLineNo, oNode)
2840
                            Dim CTrimLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
2841
                            InstumentLineModeling(CTrimLineNo, oNode)
2842
                        Next
2843

    
2844
                        'Symbol Modeling
2845
                        For Each oNode As TreeNode In oDwgNode.Nodes
2846
                            Dim iItemcnt As Integer = 0
2847
                            Dim sNodeUid As String = oNode.Name
2848
                            Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
2849
                            Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
2850
                            PipeSymbolModeling(CLineNo, oNode)
2851
                            Dim CTrimLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
2852
                            PipeSymbolModeling(CTrimLineNo, oNode)
2853
                        Next
2854
                    End If
2855
                Next
2856
            Next
2857
        Catch ex As Exception
2858

    
2859
        End Try
2860
    End Sub
2861

    
2862

    
2863
    Private Sub FindNearPoint(ByVal oOPCSymbol As LMSymbol, ByRef dNear_x As Double, ByRef dNear_y As Double)
2864
        Dim oConnectionPoints_x(4) As Double
2865
        Dim oConnectionPoints_y(4) As Double
2866

    
2867
        Try
2868
            _Placement.PIDConnectPointLocation(oOPCSymbol, 1, oConnectionPoints_x(0), oConnectionPoints_y(0))
2869
            _Placement.PIDConnectPointLocation(oOPCSymbol, 2, oConnectionPoints_x(1), oConnectionPoints_y(1))
2870
            _Placement.PIDConnectPointLocation(oOPCSymbol, 3, oConnectionPoints_x(2), oConnectionPoints_y(2))
2871
            _Placement.PIDConnectPointLocation(oOPCSymbol, 4, oConnectionPoints_x(3), oConnectionPoints_y(3))
2872
            Dim iNearPoint As Integer = 0
2873
            Dim dGap As Double = 0
2874
            For i = 0 To 3
2875
                If dGap = 0 Then
2876
                    iNearPoint = i
2877
                    dGap = Math.Abs(oConnectionPoints_x(i) - dNear_x) + Math.Abs(oConnectionPoints_y(i) - dNear_y)
2878
                Else
2879
                    If dGap >= Math.Abs(oConnectionPoints_x(i) - dNear_x) + Math.Abs(oConnectionPoints_y(i) - dNear_y) Then
2880
                        iNearPoint = i
2881
                        dGap = Math.Abs(oConnectionPoints_x(i) - dNear_x) + Math.Abs(oConnectionPoints_y(i) - dNear_y)
2882
                    End If
2883
                End If
2884
            Next
2885
            dNear_x = oConnectionPoints_x(iNearPoint)
2886
            dNear_y = oConnectionPoints_y(iNearPoint)
2887
        Catch ex As Exception
2888

    
2889
        End Try
2890

    
2891
    End Sub
2892

    
2893
    Private Function GetPipeColor(ByVal sType As String) As Color
2894
        If sType.ToUpper() = "ELECTRIC" Then
2895
            Return Color.DarkOrange
2896
        ElseIf sType.ToUpper() = "CONNECT TO PROCESS" Then
2897
            Return Color.Green
2898
        ElseIf sType.ToUpper() = "SOFTWARE" Then
2899
            Return Color.Blue
2900
        ElseIf sType.ToUpper() = "PNEUMATIC" Then
2901
            Return Color.Gray
2902
        Else
2903
            Return Color.Black
2904
        End If
2905
    End Function
2906

    
2907
    Private Function GetPipeType(ByVal sType As String) As String
2908
        Dim sSystempath As String = "\Piping\Routing\Process Lines\Primary Piping.sym" ' oPipeRow(0)(_XML_LINE_SYSTEMPATH).ToString()
2909
        If sType.ToUpper() = "ELECTRIC" Then
2910
            sSystempath = "\Instrumentation\Signal Line\Electric.sym"
2911
        ElseIf sType.ToUpper() = "CONNECT TO PROCESS" Then
2912
            sSystempath = "\Instrumentation\Signal Line\Connect to Process.sym"
2913
        ElseIf sType.ToUpper() = "SOFTWARE" Then
2914
            sSystempath = "\Instrumentation\Signal Line\Software Link.sym"
2915
        ElseIf sType.ToUpper() = "PNEUMATIC" Then
2916
            sSystempath = "\Instrumentation\Signal Line\Pneumatic.sym"
2917
        Else
2918
        End If
2919
        Return sSystempath
2920
    End Function
2921

    
2922
    Private Sub InitAutoRouting()
2923
        For Each oDrwing As TreeNode In Tree_Result.Nodes
2924
            For Each oDwgNode As TreeNode In oDrwing.Nodes
2925
                Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
2926
                Dim CDrawing As Drawing = GetDrawing(sDwgName)
2927
                If CDrawing IsNot Nothing Then
2928
                    Dim iAllLineNoCount As Integer = Tree_Result.Nodes.Count ' GetCheckNodeCount(oLinenoNode)
2929
                    Dim iPipingOPC_count As Integer = 0 ' GetCheckNodeCount(oLinenoNode)
2930
                    SetListBoxItems(ListBox_Result, "Place " & CDrawing.DwgName & "....")
2931

    
2932
                    For Each oNode As TreeNode In oDwgNode.Nodes
2933
                        Dim iItemcnt As Integer = 0
2934
                        Dim sNodeUid As String = oNode.Name
2935
                        Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
2936
                        Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
2937
                        If CLineNo IsNot Nothing Then
2938
                            Dim oLine_Dt As DataTable = CLineNo.Dt_Line
2939
                            Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
2940

    
2941
                            For Each oLineRow In oLine_Dt.Rows
2942
                                ' oLineRow(_XML_LINE_UID) = ""
2943
                                oLineRow(_XML_LINE_SPID) = ""
2944
                                oLineRow(_XML_LINE_LMCONNECTOR) = Nothing
2945
                                oLineRow(_XML_LINE_LMCONNECTOR_1) = Nothing
2946
                                oLineRow(_XML_LINE_LMCONNECTOR_2) = Nothing
2947
                                oLineRow(_XML_LINE_DRAWING_TF) = "FALSE"
2948
                                oLineRow(_XML_LINE_Check) = "FALSE"
2949
                            Next
2950
                            For Each oSymbolRow In oSymbol_Dt.Rows
2951
                                '   oSymbolRow(_XML_SYMBOL_UID) = ""
2952
                                oSymbolRow(_XML_SYMBOL_SPID) = ""
2953
                                oSymbolRow(_XML_SYMBOL_LMSYMBOL) = Nothing
2954
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_1) = Nothing
2955
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_2) = Nothing
2956
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_3) = Nothing
2957
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_4) = Nothing
2958
                                oSymbolRow(_XML_SYMBOL_Check) = "FALSE"
2959
                                oSymbolRow(_XML_SYMBOL_DRAWING_TF) = "FALSE"
2960

    
2961
                            Next
2962

    
2963
                        End If
2964

    
2965
                        Dim CTRIMLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
2966
                        If CTRIMLineNo IsNot Nothing Then
2967
                            Dim oLine_Dt As DataTable = CTRIMLineNo.Dt_Line
2968
                            Dim oSymbol_Dt As DataTable = CTRIMLineNo.Dt_Symbol
2969

    
2970
                            For Each oLineRow In oLine_Dt.Rows
2971
                                ' oLineRow(_XML_LINE_UID) = ""
2972
                                oLineRow(_XML_LINE_SPID) = ""
2973
                                oLineRow(_XML_LINE_LMCONNECTOR) = Nothing
2974
                                oLineRow(_XML_LINE_LMCONNECTOR_1) = Nothing
2975
                                oLineRow(_XML_LINE_LMCONNECTOR_2) = Nothing
2976
                                oLineRow(_XML_LINE_DRAWING_TF) = "FALSE"
2977
                                oLineRow(_XML_LINE_Check) = "FALSE"
2978
                            Next
2979
                            For Each oSymbolRow In oSymbol_Dt.Rows
2980
                                '   oSymbolRow(_XML_SYMBOL_UID) = ""
2981
                                oSymbolRow(_XML_SYMBOL_SPID) = ""
2982
                                oSymbolRow(_XML_SYMBOL_LMSYMBOL) = Nothing
2983
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_1) = Nothing
2984
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_2) = Nothing
2985
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_3) = Nothing
2986
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_4) = Nothing
2987
                                oSymbolRow(_XML_SYMBOL_Check) = "FALSE"
2988
                                oSymbolRow(_XML_SYMBOL_DRAWING_TF) = "FALSE"
2989

    
2990
                            Next
2991

    
2992
                        End If
2993
                    Next
2994
                End If
2995
            Next
2996
        Next
2997
    End Sub
2998

    
2999

    
3000

    
3001

    
3002

    
3003

    
3004
    Private Function CheckBranchLine(ByVal dStartX As Double, ByVal dStartY As Double,
3005
                                ByRef dEndX As Double, ByRef dEndY As Double, ByRef sBranchType As String, ByRef oLMConnector As LMConnector) As Boolean
3006

    
3007
        Try
3008

    
3009
            For Each oModelrow In _ModelingLine_Dt.Rows
3010
                'Dim sStartPoint As String = oModelrow(_XML_LINE_STARTPOINT)
3011
                'Dim sEndPoint As String = oModelrow(_XML_LINE_ENDPOINT)
3012
                Dim dModelStartX As Double
3013
                Dim dModelStartY As Double
3014
                Dim dModelEndX As Double
3015
                Dim dModelEndY As Double
3016
                dModelStartX = oModelrow(_XML_LINE_DWG_STARTPOINT_X)
3017
                dModelStartY = oModelrow(_XML_LINE_DWG_STARTPOINT_Y)
3018
                dModelEndX = oModelrow(_XML_LINE_DWG_ENDPOINT_X)
3019
                dModelEndY = oModelrow(_XML_LINE_DWG_ENDPOINT_Y)
3020
                'ConvertPointBystring(sStartPoint, dModelStartX, dModelStartY)
3021
                'ConvertPointBystring(sEndPoint, dModelEndX, dModelEndY)
3022
                'ConvertPointByImage(dModelStartX, dModelStartY, _IMG_X, _IMG_Y)
3023
                'ConvertPointByImage(dModelEndX, dModelEndY, _IMG_X, _IMG_Y)
3024
                Dim dGap As Double = 0.0002
3025
                Dim d기준x As Double = (dModelStartX + dModelEndX) / 2
3026
                Dim d기준y As Double = (dModelStartY + dModelEndY) / 2
3027
                Try
3028
                    oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3029
                Catch ex As Exception
3030

    
3031
                End Try
3032
                Dim oRun As LMPipeRun = Nothing
3033
                Try
3034

    
3035
                    oRun = _Placement.PIDDataSource.GetPipeRun(oLMConnector.ModelItemID)
3036
                    Dim dResultCalc As Double = -1
3037
                    For Each objRep In oRun.Representations
3038
                        If objRep.Attributes("RepresentationType").Value = "Connector" And objRep.Attributes("ItemStatus").Value = "Active" Then
3039
                            Dim objConnector As LMConnector = _Placement.PIDDataSource.GetConnector(objRep.ID)
3040
                            For Each objConnectorVertex In objConnector.ConnectorVertices
3041
                                Dim dConn_X As Double = objConnectorVertex.Attributes("XCoordinate").Value
3042
                                Dim dConn_Y As Double = objConnectorVertex.Attributes("YCoordinate").Value
3043
                                Dim dStartCalc As Double = Math.Abs(dStartX - dConn_X) + Math.Abs(dStartY - dConn_Y)
3044

    
3045
                                If dResultCalc > dStartCalc Or dResultCalc = -1 Then
3046
                                    dResultCalc = dStartCalc
3047
                                    oLMConnector = objConnector
3048
                                    d기준x = dConn_X
3049
                                    d기준y = dConn_Y
3050
                                End If
3051
                                Dim dEndCalc As Double = Math.Abs(dEndX - dConn_X) + Math.Abs(dEndY - dConn_Y)
3052
                                If dResultCalc > dEndCalc Then
3053
                                    dResultCalc = dEndCalc
3054
                                    oLMConnector = objConnector
3055
                                    d기준x = dConn_X
3056
                                    d기준y = dConn_Y
3057
                                End If
3058
                            Next
3059
                        End If
3060
                    Next
3061
                    '        _Placement.PIDConnectPointLocation(oRun, 1, dModelStartX, dModelEndX)
3062
                    '       _Placement.PIDConnectPointLocation(oRun, 2, dModelEndX, dModelEndY)
3063
                Catch ex As Exception
3064
                End Try
3065

    
3066

    
3067
                'Dim sSPID As String = oModelrow(_XML_LINE_SPID).ToString()
3068
                'Dim oPipeRun As LMPipeRun = _Placement.PIDDataSource.Get PipeRun(sSPID)
3069
                'If dModelStartX + dGap > dStartX And dModelStartX - dGap < dStartX And
3070
                '        dModelStartY + dGap > dStartY And dModelStartY - dGap < dStartY Then
3071
                '    dStartX = dModelStartX
3072
                '    dStartY = dModelStartY
3073
                'ElseIf dModelEndX + dGap > dStartX And dModelEndX - dGap < dStartX And
3074
                '        dModelEndY + dGap > dStartY And dModelEndY - dGap < dStartY Then
3075
                '    dStartX = dModelEndX
3076
                '    dStartY = dModelEndY
3077
                'End If
3078

    
3079
                'Vetical
3080
                If Math.Abs(dModelStartX - dModelEndX) <= Math.Abs(dModelStartY - dModelEndY) Then
3081
                    If Math.Abs(dStartX - dEndX) >= Math.Abs(dStartY - dEndY) Then
3082
                        'Horizontal 
3083
                        ' dGap = 0.0002 'Math.Abs(dStartX - dEndX) / 20
3084
                        '기준선의 Y범위안에 가로선이 포함되어야됨
3085
                        If (dModelStartY + dGap >= dStartY And dModelEndY - dGap <= dStartY) Or
3086
                            (dModelStartY - dGap <= dStartY And dModelEndY + dGap >= dStartY) And
3087
                            (dModelStartY + dGap >= dEndY And dModelEndY - dGap <= dEndY) Or
3088
                            (dModelStartY - dGap <= dEndY And dModelEndY + dGap >= dEndY) Then
3089
                            '기준선보다 왼쪽에 가로선이 있을때
3090
                            If d기준x >= dStartX And d기준x >= dEndX Then
3091
                                If dStartX >= dEndX Then
3092
                                    'dStartX 좌표를 기준으로 Gap만큼 더했을때 기준선보다 큰지 확인
3093
                                    If dStartX + dGap >= d기준x Then
3094
                                        dStartX = d기준x
3095
                                        sBranchType = "1"
3096
                                        Return True
3097
                                    End If
3098
                                Else
3099
                                    'dEndX 좌표를 기준으로 Gap만큼 더했을때 기준선보다 큰지 확인
3100
                                    If dEndX + dGap >= d기준x Then
3101
                                        dEndX = d기준x
3102
                                        sBranchType = "2"
3103
                                        Return True
3104
                                    End If
3105
                                End If
3106
                                '기준선보다 오른쪽에 가로선이 있을때
3107
                            ElseIf d기준x <= dStartX And d기준x <= dEndX Then
3108
                                If dStartX >= dEndX Then
3109
                                    'dEndX 좌표를 기준으로 Gap만큼 뺐을때 기준선보다 작은지 확인
3110
                                    If dEndX - dGap <= d기준x Then
3111
                                        dEndX = d기준x
3112
                                        sBranchType = "2"
3113
                                        Return True
3114
                                    End If
3115
                                Else
3116
                                    'dStartX 좌표를 기준으로 Gap만큼 뺐을때 기준선보다 작은지 확인
3117
                                    If dStartX - dGap <= d기준x Then
3118
                                        dStartX = d기준x
3119
                                        sBranchType = "1"
3120
                                        Return True
3121
                                    End If
3122
                                End If
3123
                            Else
3124
                                '기준선과 세로선이 겹칠때
3125
                                If (d기준x >= dStartX And d기준x <= dEndX) Or
3126
                                        (d기준x <= dStartX And d기준x >= dEndX) Then
3127
                                    If (dModelStartY <= dStartY And dModelEndY >= dEndY) Or
3128
                                        (dModelStartY >= dStartY And dModelEndY <= dEndY) Then
3129
                                        '기준선이 dStartX와 dEndX중 어느쪽에 가까운지 확인
3130
                                        '가로선의 왼쪽점과 기준선이 가까울때는 gap만큼 뺐을때 기준선보다 작은지확인
3131
                                        '가로선의 오른쪽점과 기준선이 가까울때는 gap만큼 더했을때 기준선보다 큰지확인
3132
                                        If Math.Abs(d기준x - dStartX) >= Math.Abs(d기준x - dEndX) Then
3133
                                            'EndX점이 기준선과 더 가까이 있음
3134
                                            If dStartX >= dEndX Then
3135
                                                '가로선의 왼쪽점과 기준선이 가까우므로 gap만큼 뺐을때 기준선보다 작은지확인
3136
                                                If dEndX - dGap <= d기준x Then
3137
                                                    dEndX = d기준x
3138
                                                    sBranchType = "4"
3139
                                                    Return True
3140
                                                End If
3141
                                            Else
3142
                                                '가로선의 오른쪽점과 기준선이 가까우므로 gap만큼 더했을때 기준선보다 큰지확인
3143
                                                If dEndX + dGap >= d기준x Then
3144
                                                    dEndX = d기준x
3145
                                                    sBranchType = "4"
3146
                                                    Return True
3147
                                                End If
3148

    
3149
                                            End If
3150
                                        Else
3151
                                            'dStartX점이 기준선과 더 가까이 있음
3152
                                            If dStartX >= dEndX Then
3153
                                                '가로선의 오른쪽점과 기준선이 가까우므로 gap만큼 더했을때 기준선보다 큰지확인
3154
                                                If dStartX + dGap >= d기준x Then
3155
                                                    dStartX = d기준x
3156
                                                    sBranchType = "3"
3157
                                                    Return True
3158
                                                End If
3159

    
3160
                                            Else
3161
                                                '가로선의 왼쪽점과 기준선이 가까우므로 gap만큼 뺐을때 기준선보다 작은지확인
3162
                                                If dStartX - dGap <= d기준x Then
3163
                                                    dStartX = d기준x
3164
                                                    sBranchType = "3"
3165
                                                    Return True
3166
                                                End If
3167
                                            End If
3168
                                        End If
3169
                                    End If
3170

    
3171
                                End If
3172
                            End If
3173
                        End If
3174

    
3175
                    End If
3176
                Else
3177
                    'Horizontal
3178
                    If Math.Abs(dModelStartX - dModelEndX) >= Math.Abs(dModelStartY - dModelEndY) Then
3179
                        'Vertical
3180
                        If Math.Abs(dStartX - dEndX) <= Math.Abs(dStartY - dEndY) Then
3181
                            '  dGap = 0.0015 'Math.Abs(dStartY - dEndY) / 80
3182

    
3183
                            '기준선의 X범위안에 세로선이 포함되어야됨
3184
                            If ((dModelStartX + dGap >= dStartX And dModelEndX - dGap <= dStartX) Or
3185
                            (dModelStartX - dGap <= dStartX And dModelEndX + dGap >= dStartX)) And
3186
                            ((dModelStartX + dGap >= dEndX And dModelEndX - dGap <= dEndX) Or
3187
                            (dModelStartX - dGap <= dEndX And dModelEndX + dGap >= dEndX)) Then
3188

    
3189
                                '가로선보다 아래에 세로선이 있을때
3190
                                If d기준y >= dStartY And d기준y >= dEndY Then
3191
                                    If dStartY >= dEndY Then
3192
                                        'dStartY 좌표를 기준으로 Gap만큼 더했을때 기준선보다 큰지 확인
3193
                                        If dStartY + dGap >= d기준y Then
3194
                                            dStartY = d기준y
3195
                                            sBranchType = "3"
3196
                                            Return True
3197
                                        End If
3198
                                    Else
3199
                                        'dEndY 좌표를 기준으로 Gap만큼 더했을때 기준선보다 큰지 확인
3200
                                        If dEndY + dGap >= d기준y Then
3201
                                            dEndY = d기준y
3202

    
3203
                                            If Math.Abs(dEndX - dModelStartX) > Math.Abs(dEndX - dModelEndX) Then
3204
                                                dEndX = dModelEndX
3205
                                            Else
3206
                                                dEndX = dModelStartX
3207
                                            End If
3208

    
3209
                                            sBranchType = "4"
3210
                                            Return True
3211
                                        End If
3212
                                    End If
3213
                                    '기준선보다 위에 세로선이 있을때
3214
                                ElseIf d기준y <= dStartY And d기준y <= dEndY Then
3215
                                    If dStartY >= dEndY Then
3216
                                        'dEndY 좌표를 기준으로 Gap만큼 뺐을때 기준선보다 작은지 확인
3217
                                        If dEndY - dGap <= d기준y Then
3218
                                            dEndY = d기준y
3219
                                            sBranchType = "4"
3220
                                            Return True
3221
                                        End If
3222
                                    Else
3223
                                        'dStartY 좌표를 기준으로 Gap만큼 뺐을때 기준선보다 작은지 확인
3224
                                        If dStartY - dGap <= d기준y Then
3225
                                            dStartY = d기준y
3226
                                            sBranchType = "3"
3227
                                            Return True
3228
                                        End If
3229
                                    End If
3230
                                Else
3231
                                    '기준선과 세로선이 겹칠때
3232
                                    If (d기준y >= dStartY And d기준y <= dEndY) Or
3233
                                            (d기준y <= dStartY And d기준y >= dEndY) Then
3234
                                        '기준선이 dStartY와 dEndY중 어느쪽에 가까운지 확인
3235
                                        '세로선의 윗점과 기준선이 가까울때는 gap만큼 뺐을때 기준선보다 작은지확인
3236
                                        '세로선의 아래점과 기준선이 가까울때는 gap만큼 더했을때 기준선보다 큰지확인
3237
                                        If (dModelStartX <= dStartX And dModelEndX >= dEndX) Or
3238
                                            (dModelStartX >= dStartX And dModelEndX <= dEndX) Then
3239
                                            If Math.Abs(d기준y - dStartY) >= Math.Abs(d기준y - dEndY) Then
3240
                                                'Endy점이 기준선과 더 가까이 있음
3241
                                                If dStartY >= dEndY Then
3242
                                                    '세로선의 아래점과 기준선이 가까우므로 gap만큼 더했을때 기준선보다 큰지확인
3243
                                                    If dEndY + dGap >= d기준y Then
3244
                                                        dEndY = d기준y
3245
                                                        sBranchType = "4"
3246
                                                        Return True
3247
                                                    End If
3248
                                                Else
3249
                                                    '세로선의 윗점과 기준선이 가까우므로 gap만큼 뺐을때 기준선보다 작은지확인
3250
                                                    If dEndY - dGap <= d기준y Then
3251
                                                        dEndY = d기준y
3252
                                                        sBranchType = "4"
3253
                                                        Return True
3254
                                                    End If
3255
                                                End If
3256
                                            Else
3257
                                                'dStartY점이 기준선과 더 가까이 있음
3258
                                                If dStartY >= dEndY Then
3259
                                                    '세로선의 윗점과 기준선이 가까우므로 gap만큼 뺐을때 기준선보다 작은지확인
3260
                                                    If dStartY - dGap <= d기준y Then
3261
                                                        dStartY = d기준y
3262
                                                        sBranchType = "3"
3263
                                                        Return True
3264
                                                    End If
3265
                                                Else
3266
                                                    '세로선의 아래점과 기준선이 가까우므로 gap만큼 더했을때 기준선보다 큰지확인
3267
                                                    If dStartY + dGap >= d기준y Then
3268
                                                        dStartY = d기준y
3269
                                                        sBranchType = "3"
3270
                                                        Return True
3271
                                                    End If
3272
                                                End If
3273
                                            End If
3274
                                        End If
3275

    
3276
                                    End If
3277
                                End If
3278
                            End If
3279
                        End If
3280
                    End If
3281
                End If
3282
            Next
3283
        Catch ex As Exception
3284

    
3285
        End Try
3286
        oLMConnector = Nothing
3287
        Return False
3288
    End Function
3289

    
3290
    Private Function CheckConnectionSymbolToSymbol(ByVal oModelingLineRows() As DataRow, ByRef dX As Double, ByRef dY As Double,
3291
                                  ByRef oLMConnector As LMConnector) As Boolean
3292
        Dim bConnectionFlag As Boolean = False
3293
        Try
3294
            For Each oModelrow In oModelingLineRows
3295
                Dim d기준x As Double = dX
3296
                Dim d기준y As Double = dY
3297
                Dim dGap As Double = 0.0002
3298
                Dim oRun As LMPipeRun = Nothing
3299
                Try
3300
                    Dim oLMSymbol As LMSymbol = oModelrow(_XML_SYMBOL_LMSYMBOL)
3301
                    Dim dX1 As Double = 0.0
3302
                    Dim dY1 As Double = 0.0
3303
                    Dim dX2 As Double = 0.0
3304
                    Dim dY2 As Double = 0.0
3305
                    For Each oConnector In oLMSymbol.Connect1Connectors
3306
                        oLMConnector = oConnector
3307
                    Next
3308
                    '  oRun = _Placement.PIDDataSource.GetPipeRun(oLMSymbol.Connect1Connectors.Nth(1).ModelItemID)
3309
                    _Placement.PIDConnectPointLocation(oLMSymbol, 1, dX1, dY1)
3310
                    _Placement.PIDConnectPointLocation(oLMSymbol, 2, dX2, dY2)
3311
                    If Math.Abs(dX - dX1) < dGap And Math.Abs(dY - dY1) < dGap Then
3312
                        dX = dX1
3313
                        dY = dY1
3314
                        bConnectionFlag = True
3315
                        Exit For
3316
                    End If
3317
                    If Math.Abs(dX - dX2) < dGap And Math.Abs(dY - dY2) < dGap Then
3318
                        dX = dX2
3319
                        dY = dY2
3320
                        bConnectionFlag = True
3321
                        Exit For
3322
                    End If
3323

    
3324
                    'For Each oConnector In oLMSymbol.Connect1Connectors
3325
                    '    For Each objConnectorVertex In oConnector.ConnectorVertices
3326
                    '        Dim dConn_X As Double = objConnectorVertex.Attributes("XCoordinate").Value
3327
                    '        Dim dConn_Y As Double = objConnectorVertex.Attributes("YCoordinate").Value
3328
                    '        If Math.Abs(dX - dConn_X) < dGap And Math.Abs(dY - dConn_Y) < dGap Then
3329
                    '            oLMConnector = oConnector
3330
                    '            dX = dConn_X
3331
                    '            dY = dConn_Y
3332
                    '            bConnectionFlag = True
3333
                    '            Exit For
3334
                    '        End If
3335
                    '    Next
3336
                    'Next
3337

    
3338
                    'For Each oConnector In oLMSymbol.Connect2Connectors
3339
                    '    For Each objConnectorVertex In oConnector.ConnectorVertices
3340
                    '        Dim dConn_X As Double = objConnectorVertex.Attributes("XCoordinate").Value
3341
                    '        Dim dConn_Y As Double = objConnectorVertex.Attributes("YCoordinate").Value
3342
                    '        If Math.Abs(dX - dConn_X) < dGap And Math.Abs(dY - dConn_Y) < dGap Then
3343
                    '            oLMConnector = oConnector
3344
                    '            dX = dConn_X
3345
                    '            dY = dConn_Y
3346
                    '            bConnectionFlag = True
3347
                    '            Exit For
3348
                    '        End If
3349
                    '    Next
3350
                    'Next
3351

    
3352

    
3353
                    'If oRun IsNot Nothing Then
3354
                    '    Dim dResultCalc As Double = -1
3355
                    '    For Each objRep In oRun.Representations
3356
                    '        Dim sRepresentationType As String = objRep.Attributes("RepresentationType").Value
3357
                    '        If objRep.Attributes("RepresentationType").Value = "Connector" Or
3358
                    '            objRep.Attributes("RepresentationType").Value = "Symbol" And
3359
                    '             objRep.Attributes("ItemStatus").Value = "Active" Then
3360
                    '            Dim objConnector As LMConnector = _Placement.PIDDataSource.GetConnector(objRep.ID)
3361
                    '            For Each objConnectorVertex In objConnector.ConnectorVertices
3362
                    '                Dim dConn_X As Double = objConnectorVertex.Attributes("XCoordinate").Value
3363
                    '                Dim dConn_Y As Double = objConnectorVertex.Attributes("YCoordinate").Value
3364
                    '                If Math.Abs(dX - dConn_X) < dGap And Math.Abs(dY - dConn_Y) < dGap Then
3365
                    '                    oLMConnector = objConnector
3366
                    '                    d기준x = dConn_X
3367
                    '                    d기준y = dConn_Y
3368
                    '                    bConnectionFlag = True
3369
                    '                    Exit For
3370
                    '                End If
3371
                    '            Next
3372
                    '        End If
3373
                    '    Next
3374
                    'End If
3375

    
3376
                Catch ex As Exception
3377
                End Try
3378
            Next
3379

    
3380
        Catch ex As Exception
3381

    
3382
        End Try
3383
        Return bConnectionFlag
3384
    End Function
3385

    
3386
    Private Function CheckConnectionSymbolToLine(ByVal oModelingLineRows() As DataRow, ByRef dX As Double, ByRef dY As Double,
3387
ByVal dCenterX As Double, ByVal dCenterY As Double, ByRef oLMConnector As LMConnector) As LMSymbol
3388
        Dim bConnectionFlag As Boolean = False
3389
        Dim oLMSymbol As LMSymbol = Nothing
3390
        Try
3391

    
3392
            For Each oModelrow In _ModelingSymbol_Dt.Rows
3393
                Dim dMinx As Double = oModelrow(_XML_SYMBOL_MIN_X)
3394
                Dim dMaxx As Double = oModelrow(_XML_SYMBOL_MAX_X)
3395
                Dim dMiny As Double = oModelrow(_XML_SYMBOL_MIN_Y)
3396
                Dim dMaxy As Double = oModelrow(_XML_SYMBOL_MAX_Y)
3397
                Dim dGap As Double = 0.001
3398
                If dMinx <= dX And dMaxx >= dX And dMiny <= dY And dMaxy >= dY Then
3399
                    oLMSymbol = oModelrow(_XML_SYMBOL_LMSYMBOL)
3400
                    Dim dX1 As Double = 0.0
3401
                    Dim dY1 As Double = 0.0
3402
                    Dim dX2 As Double = 0.0
3403
                    Dim dY2 As Double = 0.0
3404
                    Dim dX3 As Double = 0.0
3405
                    Dim dY3 As Double = 0.0
3406
                    Dim dX4 As Double = 0.0
3407
                    Dim dY4 As Double = 0.0
3408
                    Dim dX5 As Double = 0.0
3409
                    Dim dY5 As Double = 0.0
3410
                    Dim dX6 As Double = 0.0
3411
                    Dim dY6 As Double = 0.0
3412
                    Dim dX7 As Double = 0.0
3413
                    Dim dY7 As Double = 0.0
3414
                    Dim dX8 As Double = 0.0
3415
                    Dim dY8 As Double = 0.0
3416
                    _Placement.PIDConnectPointLocation(oLMSymbol, 1, dX1, dY1)
3417
                    _Placement.PIDConnectPointLocation(oLMSymbol, 2, dX2, dY2)
3418
                    _Placement.PIDConnectPointLocation(oLMSymbol, 3, dX3, dY3)
3419
                    _Placement.PIDConnectPointLocation(oLMSymbol, 4, dX4, dY4)
3420
                    _Placement.PIDConnectPointLocation(oLMSymbol, 5, dX5, dY5)
3421
                    _Placement.PIDConnectPointLocation(oLMSymbol, 6, dX6, dY6)
3422
                    _Placement.PIDConnectPointLocation(oLMSymbol, 7, dX7, dY7)
3423
                    _Placement.PIDConnectPointLocation(oLMSymbol, 8, dX8, dY8)
3424

    
3425
                    If Math.Abs(dX - dX1) <= dGap And Math.Abs(dY - dY1) <= dGap Then
3426
                        dX = dX1
3427
                        dY = dY1
3428
                    ElseIf Math.Abs(dX - dX2) <= dGap And Math.Abs(dY - dY2) <= dGap Then
3429
                        dX = dX2
3430
                        dY = dY2
3431
                    ElseIf Math.Abs(dX - dX3) <= dGap And Math.Abs(dY - dY3) <= dGap Then
3432
                        dX = dX3
3433
                        dY = dY3
3434
                    ElseIf Math.Abs(dX - dX4) <= dGap And Math.Abs(dY - dY4) <= dGap Then
3435
                        dX = dX4
3436
                        dY = dY4
3437
                    ElseIf Math.Abs(dX - dX5) <= dGap And Math.Abs(dY - dY5) <= dGap Then
3438
                        dX = dX5
3439
                        dY = dY5
3440
                    ElseIf Math.Abs(dX - dX6) <= dGap And Math.Abs(dY - dY6) <= dGap Then
3441
                        dX = dX6
3442
                        dY = dY6
3443
                    ElseIf Math.Abs(dX - dX7) <= dGap And Math.Abs(dY - dY7) <= dGap Then
3444
                        dX = dX7
3445
                        dY = dY7
3446
                    ElseIf Math.Abs(dX - dX8) <= dGap And Math.Abs(dY - dY8) <= dGap Then
3447
                        dX = dX8
3448
                        dY = dY8
3449
                    End If
3450
                End If
3451
            Next
3452

    
3453

    
3454

    
3455
            'For Each oModelrow In oModelingLineRows
3456
            '    Dim d기준x As Double = dCenterX
3457
            '    Dim d기준y As Double = dCenterY
3458
            '    Dim dGap As Double = 0.001
3459
            '    Dim oRun As LMPipeRun = Nothing
3460
            '    Dim dCheckGap As Double = 0
3461
            '    Try
3462

    
3463
            '        Dim dX1 As Double = 0.0
3464
            '        Dim dY1 As Double = 0.0
3465
            '        Dim dX2 As Double = 0.0
3466
            '        Dim dY2 As Double = 0.0
3467
            '        '  oRun = _Placement.PIDDataSource.GetPipeRun(oLMSymbol.Connect1Connectors.Nth(1).ModelItemID)
3468
            '        oLMSymbol = oModelrow(_XML_SYMBOL_LMSYMBOL)
3469
            '        For Each oConnector In oLMSymbol.Connect1Connectors
3470
            '            oLMConnector = oConnector
3471
            '        Next
3472
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 1, dX1, dY1)
3473
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 2, dX2, dY2)
3474
            '        '  If Math.Abs(dX - dX1) < dGap And Math.Abs(dY - dY1) < dGap And
3475
            '        If Math.Abs(d기준x - dX1) < dCheckGap And Math.Abs(d기준y - dY1) < dCheckGap Or dCheckGap = 0 Then
3476
            '            dX = dX1
3477
            '            dY = dY1
3478
            '            bConnectionFlag = True
3479
            '            dCheckGap = Math.Abs(d기준x - dX1) + Math.Abs(d기준y - dY1)
3480
            '        End If
3481
            '        'If Math.Abs(dX - dX2) < dGap And Math.Abs(dY - dY2) < dGap And
3482
            '        '  Math.Abs(d기준x - dX2) < dCheckGap And Math.Abs(d기준y - dY2 < dCheckGap) Or dCheckGap = 0 Then
3483
            '        If Math.Abs(d기준x - dX2) < dCheckGap And Math.Abs(d기준y - dY2) < dCheckGap Or dCheckGap = 0 Then
3484
            '            dX = dX2
3485
            '            dY = dY2
3486
            '            bConnectionFlag = True
3487
            '        End If
3488

    
3489
            '    Catch ex As Exception
3490
            '    End Try
3491
            '    If bConnectionFlag Then
3492
            '        oLMSymbol = oModelrow(_XML_SYMBOL_LMSYMBOL)
3493
            '    Else
3494
            '        oLMSymbol = Nothing
3495
            '    End If
3496
            'Next
3497

    
3498
        Catch ex As Exception
3499

    
3500
        End Try
3501

    
3502
        Return oLMSymbol
3503
    End Function
3504

    
3505
    ''' <summary>
3506
    ''' 라인과 라인이 만나는점이 브런치점인지 확인, 오차범위내 라인보정
3507
    ''' </summary>
3508
    ''' <param name="oModelingLineRows"></param>
3509
    ''' <param name="dStartX"></param>
3510
    ''' <param name="dStartY"></param>
3511
    ''' <param name="dEndX"></param>
3512
    ''' <param name="dEndY"></param>
3513
    ''' <param name="oLMConnector"></param>
3514
    ''' <returns></returns>
3515
    Private Function CheckBranchLine(ByVal oModelingLineRows As DataRowCollection, ByRef dStartX As Double, ByRef dStartY As Double,
3516
                                     ByRef dEndX As Double, ByRef dEndY As Double, ByRef oLMConnector As LMConnector) As String
3517
        Dim bConnectionFlag As Boolean = False
3518
        Dim sBranchDirection As String = ""
3519
        Try
3520
            For Each oModelrow In oModelingLineRows
3521
                Dim dModelStartX As Double
3522
                Dim dModelStartY As Double
3523
                Dim dModelEndX As Double
3524
                Dim dModelEndY As Double
3525
                Dim dGap As Double = 0.002
3526
                dModelStartX = oModelrow(_XML_LINE_DWG_STARTPOINT_X)
3527
                dModelStartY = oModelrow(_XML_LINE_DWG_STARTPOINT_Y)
3528
                dModelEndX = oModelrow(_XML_LINE_DWG_ENDPOINT_X)
3529
                dModelEndY = oModelrow(_XML_LINE_DWG_ENDPOINT_Y)
3530

    
3531
                '기존라인이 X축방향이라면 현재선은 Y축방향이 되어야됨
3532
                If Math.Abs(dModelStartX - dModelEndX) > Math.Abs(dModelStartY - dModelEndY) And
3533
                    Math.Abs(dStartX - dEndX) < Math.Abs(dStartY - dEndY) Then
3534

    
3535
                    '기본라인의 X축영역안에 현재선이 있어야됨
3536
                    '      If dModelEndY > dModelStartY Then
3537
                    If (dStartX < dModelEndX And dStartX > dModelStartX) Or
3538
                            (dStartX > dModelEndX And dStartX < dModelStartX) Then
3539
                        '[오차범위 수정]
3540
                        '현재선의 Y축방향이 기존라인의 X축방향을 통과하는지 확인
3541
                        If dStartY < dEndY Then
3542
                            If dEndY > dModelStartY And dModelStartY > dStartY Then
3543
                                If dEndY - dModelStartY > dModelStartY - dStartY Then
3544
                                    '위쪽으로 라인이 나와있을때
3545
                                    '현재선 중 작은 Y좌표를 오차범위만큼 더했을때 기존라인의 Y축보다 큰지확인 
3546
                                    'Y축보다 클경우 작은 Y좌표를 기존라인의 Y축에 맞추고 더한 길이만큼 큰 Y좌표에 더한다.
3547
                                    If Math.Abs(dStartY - dModelStartY) <= dGap Then
3548
                                        Dim dAddPoint As Double = dModelStartY - dStartY
3549
                                        dEndY = dEndY + dAddPoint
3550
                                        dStartY = dModelStartY
3551
                                        sBranchDirection = "START"
3552
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3553
                                        Exit For
3554
                                    End If
3555
                                Else
3556
                                    '아래쪽으로 라인이 나와있을때
3557
                                    '현재선 중 큰 Y좌표를 오차범위만큼 뺐을때 기존라인의 Y축보다 작은지확인 
3558
                                    'Y축보다 작을경우 큰 Y좌표를 기존라인의 Y축에 맞추고 더한 길이만큼 작은 Y좌표에 뺀다.
3559
                                    If Math.Abs(dEndY - dModelStartY) <= dGap Then
3560
                                        Dim dAddPoint As Double = dEndY - dModelStartY
3561
                                        dStartY = dStartY - dAddPoint
3562
                                        dEndY = dModelStartY
3563
                                        sBranchDirection = "END"
3564
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3565
                                        Exit For
3566
                                    End If
3567
                                End If
3568
                            Else
3569
                                '현재선의 Y축방향이 기존라인의 X축방향에 못미치는지 확인
3570
                                If dStartY > dModelStartY Then
3571
                                    '기존라인보다 위쪽에 현재선이 있을때
3572
                                    If Math.Abs(dStartY - dModelStartY) <= dGap Then
3573
                                        '오차범위만큼 작은 y좌표를 뺐을때 기존라인보다 아래쪽에 있을경우 오차보정
3574
                                        Dim dAddPoint As Double = dStartY - dModelStartY
3575
                                        dEndY = dEndY - dAddPoint
3576
                                        dStartY = dModelStartY
3577
                                        sBranchDirection = "START"
3578
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3579
                                        Exit For
3580
                                    End If
3581
                                Else
3582
                                    '기존라인보다 아래쪽에 현재선이 있을때
3583
                                    If Math.Abs(dEndY - dModelStartY) <= dGap Then
3584
                                        '오차범위만큼 큰 y좌표를 더했을때 기존라인보다 위쪽에 있을경우 오차보정
3585
                                        Dim dAddPoint As Double = dModelStartY - dEndY
3586
                                        dEndY = dModelStartY
3587
                                        dStartY = dStartY + dAddPoint
3588
                                        sBranchDirection = "END"
3589
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3590
                                        Exit For
3591
                                    End If
3592
                                End If
3593
                            End If
3594
                        Else
3595
                            If dEndY < dModelStartY And dModelStartY < dStartY Then
3596
                                If dModelStartY - dEndY < dStartY - dModelStartY Then
3597
                                    '위쪽으로 라인이 나와있을때
3598
                                    '현재선 중 작은 Y좌표를 오차범위만큼 더했을때 기존라인의 Y축보다 큰지확인 
3599
                                    'Y축보다 클경우 작은 Y좌표를 기존라인의 Y축에 맞추고 더한 길이만큼 큰 Y좌표에 더한다.
3600
                                    If Math.Abs(dEndY - dModelStartY) <= dGap Then
3601
                                        Dim dAddPoint As Double = dModelStartY - dEndY
3602
                                        dStartY = dStartY + dAddPoint
3603
                                        dEndY = dModelStartY
3604
                                        sBranchDirection = "END"
3605
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3606
                                        Exit For
3607
                                    End If
3608
                                Else
3609
                                    '아래쪽으로 라인이 나와있을때
3610
                                    '현재선 중 큰 Y좌표를 오차범위만큼 뺐을때 기존라인의 Y축보다 작은지확인 
3611
                                    'Y축보다 작을경우 큰 Y좌표를 기존라인의 Y축에 맞추고 더한 길이만큼 작은 Y좌표에 뺀다.
3612
                                    If Math.Abs(dStartY - dModelStartY) <= dGap Then
3613
                                        Dim dAddPoint As Double = dStartY - dModelStartY
3614
                                        dEndY = dEndY - dAddPoint
3615
                                        dStartY = dModelStartY
3616
                                        sBranchDirection = "START"
3617
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3618
                                        Exit For
3619
                                    End If
3620
                                End If
3621
                            Else
3622
                                If dEndY > dModelStartY Then
3623
                                    '기존라인보다 우측에 현재선이 있을때
3624
                                    If Math.Abs(dEndY - dModelStartY) <= dGap Then
3625
                                        '오차범위만큼 작은 x좌표를 뺐을때 기존라인보다 좌측에 있을경우 오차보정
3626
                                        Dim dAddPoint As Double = dEndY - dModelStartY
3627
                                        dStartY = dStartY - dAddPoint
3628
                                        dEndY = dModelStartY
3629
                                        sBranchDirection = "END"
3630
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3631
                                        Exit For
3632
                                    End If
3633
                                Else
3634
                                    '기존라인보다 좌측에 현재선이 있을때
3635
                                    If Math.Abs(dStartY - dModelStartY) <= dGap Then
3636
                                        '오차범위만큼 큰 x좌표를 더했을때 기존라인보다 우측에 있을경우 오차보정
3637
                                        Dim dAddPoint As Double = dModelStartY - dStartY
3638
                                        dStartY = dModelStartY
3639
                                        dEndY = dEndY + dAddPoint
3640
                                        sBranchDirection = "START"
3641
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3642
                                        Exit For
3643
                                    End If
3644
                                End If
3645
                            End If
3646
                        End If
3647
                    End If
3648
                    '기존라인이 Y축방향이라면 현재선은 X축방향이 되어야됨
3649
                ElseIf Math.Abs(dModelStartX - dModelEndX) < Math.Abs(dModelStartY - dModelEndY) And
3650
                Math.Abs(dStartX - dEndX) > Math.Abs(dStartY - dEndY) Then
3651

    
3652
                    '기본라인의 Y축영역안에 현재선이 있어야됨
3653
                    '      If dModelEndY > dModelStartY Then
3654
                    If (dStartY < dModelEndY And dStartY > dModelStartY) Or
3655
                            (dStartY > dModelEndY And dStartY < dModelStartY) Then
3656
                        '[오차범위 수정]
3657
                        '현재선의 X축방향이 기존라인의 Y축방향을 통과하는지 확인
3658
                        If dStartX < dEndX Then
3659
                            If dEndX > dModelStartX And dModelStartX > dStartX Then
3660
                                If dEndX - dModelStartX > dModelStartX - dStartX Then
3661
                                    '우측으로 라인이 나와있을때
3662
                                    '현재선 중 작은 X좌표를 오차범위만큼 더했을때 기존라인의 X축보다 큰지확인 
3663
                                    'X축보다 클경우 작은 X좌표를 기존라인의 X축에 맞추고 더한 길이만큼 큰 X좌표에 더한다.
3664
                                    If Math.Abs(dStartX - dModelStartX) <= dGap Then
3665
                                        Dim dAddPoint As Double = dModelStartX - dStartX
3666
                                        dEndX = dEndX + dAddPoint
3667
                                        dStartX = dModelStartX
3668
                                        sBranchDirection = "START"
3669
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3670
                                        Exit For
3671
                                    End If
3672
                                Else
3673
                                    '좌측으로 라인이 나와있을때
3674
                                    '현재선 중 큰 X좌표를 오차범위만큼 뺐을때 기존라인의 X축보다 작은지확인 
3675
                                    'X축보다 작을경우 큰 X좌표를 기존라인의 X축에 맞추고 뺀 길이만큼 작은 X좌표에 뺀다.
3676
                                    If Math.Abs(dEndX - dModelStartX) <= dGap Then
3677
                                        Dim dAddPoint As Double = dEndX - dModelStartX
3678
                                        dStartX = dStartX - dAddPoint
3679
                                        dEndX = dModelStartX
3680
                                        sBranchDirection = "END"
3681
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3682
                                        Exit For
3683
                                    End If
3684
                                End If
3685
                            Else
3686
                                '현재선의 X축방향이 기존라인의 Y축방향에 못미치는지 확인
3687
                                If dStartX > dModelStartX Then
3688
                                    '기존라인보다 우측에 현재선이 있을때
3689
                                    If Math.Abs(dStartX - dModelStartX) <= dGap Then
3690
                                        '오차범위만큼 작은 x좌표를 뺐을때 기존라인보다 좌측에 있을경우 오차보정
3691
                                        Dim dAddPoint As Double = dStartX - dModelStartX
3692
                                        dEndX = dEndX - dAddPoint
3693
                                        dStartX = dModelStartX
3694
                                        sBranchDirection = "START"
3695
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3696
                                        Exit For
3697
                                    End If
3698
                                Else
3699
                                    '기존라인보다 좌측에 현재선이 있을때
3700
                                    If Math.Abs(dEndX - dModelStartX) <= dGap Then
3701
                                        '오차범위만큼 큰 x좌표를 더했을때 기존라인보다 우측에 있을경우 오차보정
3702
                                        Dim dAddPoint As Double = dModelStartX - dEndX
3703
                                        dEndX = dModelStartX
3704
                                        dStartX = dStartX + dAddPoint
3705
                                        sBranchDirection = "END"
3706
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3707
                                        Exit For
3708
                                    End If
3709
                                End If
3710
                            End If
3711
                        Else
3712
                            If dEndX < dModelStartX And dModelStartX < dStartX Then
3713
                                If dModelStartX - dEndX < dStartX - dModelStartX Then
3714
                                    '우측으로 라인이 나와있을때
3715
                                    '현재선 중 작은 X좌표를 오차범위만큼 더했을때 기존라인의 X축보다 큰지확인 
3716
                                    'X축보다 클경우 작은 X좌표를 기존라인의 X축에 맞추고 더한 길이만큼 큰 X좌에 더한다.
3717
                                    If Math.Abs(dModelStartX - dEndX) <= dGap Then
3718
                                        Dim dAddPoint As Double = dModelStartX - dEndX
3719
                                        dStartX = dStartX + dAddPoint
3720
                                        dEndX = dModelStartX
3721
                                        sBranchDirection = "END"
3722
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3723
                                        Exit For
3724
                                    End If
3725
                                Else
3726
                                    '좌측으로 라인이 나와있을때
3727
                                    '현재선 중 큰 X좌표를 오차범위만큼 뺐을때 기존라인의 X축보다 작은지확인 
3728
                                    'X축보다 작을경우 큰 X좌표를 기존라인의 X축에 맞추고 뺀 길이만큼 작은 X좌표에 뺀다.
3729
                                    If Math.Abs(dStartX - dModelStartX) <= dGap Then
3730
                                        Dim dAddPoint As Double = dStartX - dModelStartX
3731
                                        dEndX = dEndX - dAddPoint
3732
                                        dStartX = dModelStartX
3733
                                        sBranchDirection = "START"
3734
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3735
                                        Exit For
3736
                                    End If
3737

    
3738
                                End If
3739
                            Else
3740
                                If dEndX > dModelStartX Then
3741
                                    '기존라인보다 우측에 현재선이 있을때
3742
                                    If Math.Abs(dEndX - dModelStartX) <= dGap Then
3743
                                        '오차범위만큼 작은 x좌표를 뺐을때 기존라인보다 좌측에 있을경우 오차보정
3744
                                        Dim dAddPoint As Double = dEndX - dModelStartX
3745
                                        dStartX = dStartX - dAddPoint
3746
                                        dEndX = dModelStartX
3747
                                        sBranchDirection = "END"
3748
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3749
                                        Exit For
3750
                                    End If
3751
                                Else
3752
                                    '기존라인보다 좌측에 현재선이 있을때
3753
                                    If Math.Abs(dStartX - dModelStartX) <= dGap Then
3754
                                        '오차범위만큼 큰 x좌표를 더했을때 기존라인보다 우측에 있을경우 오차보정
3755
                                        Dim dAddPoint As Double = dModelStartX - dStartX
3756
                                        dStartX = dModelStartX
3757
                                        dEndX = dEndX + dAddPoint
3758
                                        sBranchDirection = "START"
3759
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3760
                                        Exit For
3761
                                    End If
3762
                                End If
3763
                            End If
3764
                        End If
3765
                    End If
3766
                End If
3767
            Next
3768
        Catch ex As Exception
3769
            bConnectionFlag = False
3770
            oLMConnector = Nothing
3771
        End Try
3772
        Return sBranchDirection
3773

    
3774
    End Function
3775

    
3776
    Private Function UpdateCheckBranchLine(ByRef dX As Double, ByRef dY As Double,
3777
                                  ByRef oLMConnector As LMConnector, ByRef sUid As String) As Boolean
3778
        Dim oDataSource As LMADataSource = _Placement.PIDDataSource
3779
        Dim bCheckBranchItem As Boolean = False
3780
        Dim iGapCheck As Integer = 0
3781
        Try
3782
            For Each oModelrow In _ModelingLine_Dt.Rows
3783
                Dim d기준x As Double = dX
3784
                Dim d기준y As Double = dY
3785
                Dim dGap As Double = 0.001
3786
                Dim oRun As LMPipeRun = Nothing
3787
                Dim dModelStartX As Double
3788
                Dim dModelStartY As Double
3789
                Dim dModelEndX As Double
3790
                Dim dModelEndY As Double
3791
                dModelStartX = oModelrow(_XML_LINE_DWG_STARTPOINT_X)
3792
                dModelStartY = oModelrow(_XML_LINE_DWG_STARTPOINT_Y)
3793
                dModelEndX = oModelrow(_XML_LINE_DWG_ENDPOINT_X)
3794
                dModelEndY = oModelrow(_XML_LINE_DWG_ENDPOINT_Y)
3795
                d기준x = (dModelStartX + dModelEndX) / 2
3796
                d기준y = (dModelStartY + dModelEndY) / 2
3797

    
3798
                Dim dMax_X As Double = 0.0
3799
                Dim dMax_Y As Double = 0.0
3800
                Dim dMin_X As Double = 0.0
3801
                Dim dMin_Y As Double = 0.0
3802
                If dModelEndX > dModelStartX Then
3803
                    dMax_X = dModelEndX
3804
                    dMin_X = dModelStartX
3805
                Else
3806
                    dMax_X = dModelStartX
3807
                    dMin_X = dModelEndX
3808
                End If
3809

    
3810
                If dModelEndY > dModelStartY Then
3811
                    dMax_Y = dModelEndY
3812
                    dMin_Y = dModelStartY
3813
                Else
3814
                    dMax_Y = dModelStartY
3815
                    dMin_Y = dModelEndY
3816
                End If
3817

    
3818
                If dX <= dMax_X + dGap And dX >= dMin_X - dGap And
3819
                  dY <= dMax_Y + dGap And dY >= dMin_Y - dGap Then
3820
                    If Math.Abs(dMax_X - dMin_X) > Math.Abs(dMax_Y - dMin_Y) Then
3821
                        dY = dMax_Y
3822
                    Else
3823
                        dX = dMax_X
3824
                    End If
3825

    
3826
                    Try
3827
                        Dim sModelItemID As String = oModelrow(_XML_LINE_SPID).ToString()
3828
                        sUid = oModelrow(_XML_LINE_UID).ToString()
3829
                        oRun = oDataSource.GetPipeRun(sModelItemID)
3830
                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3831
                    Catch ex As Exception
3832
                    End Try
3833
                    Try
3834
                        If oRun IsNot Nothing Then
3835
                            Dim dResultCalc As Double = -1
3836
                            Dim bBranchFlag As Boolean = False
3837
                            Dim dBranchX As Double = 0
3838
                            Dim dBranchY As Double = 0
3839
                            For Each objRep In oRun.Representations
3840
                                '  Dim sAttriName As String
3841
                                'For Each objAttr In objRep.Attributes
3842
                                '    sAttriName = objAttr.name
3843
                                'Next
3844
                                'MsgBox(objRep.RepresentationType)
3845
                                If objRep.RepresentationType = "Connector" Then
3846
                                    Dim objConnector As LMConnector = oDataSource.GetConnector(objRep.ID)
3847
                                    '     Dim sItemStatus As String = objConnector.Attributes("ItemStatus").Value
3848
                                    '   Dim sModelTypeName As String = objConnector.ModelItemObject.Attributes("ItemTypeName").Value
3849

    
3850
                                    'Dim dConn_SX As Double = 0
3851
                                    'Dim dConn_SY As Double = 0
3852
                                    'Dim dConn_EX As Double = 0
3853
                                    'Dim dConn_EY As Double = 0
3854
                                    Dim dConn_X As Double = 0
3855
                                    Dim dConn_Y As Double = 0
3856
                                    For Each objConnectorVertex In objConnector.ConnectorVertices
3857
                                        dConn_X = objConnectorVertex.Attributes("XCoordinate").Value
3858
                                        dConn_Y = objConnectorVertex.Attributes("YCoordinate").Value
3859
                                        'If dConn_SX = 0 Then
3860
                                        '    dConn_SX = objConnectorVertex.Attributes("XCoordinate").Value
3861
                                        '    dConn_SY = objConnectorVertex.Attributes("YCoordinate").Value
3862
                                        'Else
3863
                                        '    dConn_EX = objConnectorVertex.Attributes("XCoordinate").Value
3864
                                        '    dConn_EY = objConnectorVertex.Attributes("YCoordinate").Value
3865
                                        'End If
3866
                                        Dim dCalc As Double = Math.Abs(dConn_X - dX) + Math.Abs(dConn_Y - dY)
3867
                                        If bBranchFlag = False Then
3868
                                            If dResultCalc = -1 Or dResultCalc > dCalc Then
3869
                                                dResultCalc = dCalc
3870
                                                oLMConnector = objConnector
3871
                                                bCheckBranchItem = True
3872
                                            End If
3873
                                        Else
3874
                                            If (dConn_X >= dX And dBranchX <= dX And dConn_Y >= dY And dBranchY <= dY) Or
3875
                                               (dConn_X <= dX And dBranchX >= dX And dConn_Y <= dY And dBranchY >= dY) Then
3876
                                                If dResultCalc = -1 Or dResultCalc > dCalc Then
3877
                                                    dResultCalc = dCalc
3878
                                                    oLMConnector = objConnector
3879
                                                    bCheckBranchItem = True
3880
                                                End If
3881
                                            End If
3882
                                        End If
3883

    
3884

    
3885
                                        'If dConn_EX <> 0 And dConn_EY <> 0 Then
3886
                                        '    If dConn_SX >= dX And dConn_EX <= dX And dConn_SY >= dY And dConn_EY <= dY Then
3887
                                        '        oLMConnector = objConnector
3888
                                        '        Exit For
3889
                                        '    ElseIf dConn_SX <= dX And dConn_EX >= dX And dConn_SY <= dY And dConn_EY >= dY Then
3890
                                        '        oLMConnector = objConnector
3891
                                        '        Exit For
3892
                                        '    Else
3893
                                        '        If dConn_EX > 0 Then
3894
                                        '            dConn_SX = dConn_EX
3895
                                        '            dConn_SY = dConn_EY
3896
                                        '        End If
3897
                                        '    End If
3898
                                        'End If
3899

    
3900
                                    Next
3901
                                    'If oLMConnector IsNot Nothing Then
3902
                                    '    Exit For
3903
                                    'End If
3904
                                ElseIf objRep.RepresentationType = "Branch" Then
3905
                                    Dim objConnector As LMSymbol = oDataSource.GetSymbol(objRep.ID)
3906
                                    dBranchX = objConnector.Attributes("XCoordinate").Value
3907
                                    dBranchY = objConnector.Attributes("YCoordinate").Value
3908
                                    bBranchFlag = True
3909
                                End If
3910
                                'If objRep.Attributes("RepresentationType").Value = "Connector" And objRep.Attributes("ItemStatus").Value = "Active" Then
3911
                                '    Dim objConnector As LMConnector = _Placement.PIDDataSource.GetConnector(objRep.ID)
3912
                                '    For Each objConnectorVertex In objConnector.ConnectorVertices
3913
                                '        Dim dConn_X As Double = objConnectorVertex.Attributes("XCoordinate").Value
3914
                                '        Dim dConn_Y As Double = objConnectorVertex.Attributes("YCoordinate").Value
3915
                                '        If Math.Abs(dX - dConn_X) < dGap And Math.Abs(dY - dConn_Y) < dGap Then
3916
                                '            oLMConnector = objConnector
3917
                                '            dX = dConn_X
3918
                                '            dY = dConn_Y
3919
                                '            bConnectionFlag = True
3920
                                '        End If
3921
                                '    Next
3922
                                'End If
3923
                            Next
3924
                        End If
3925
                    Catch ex As Exception
3926
                    End Try
3927
                    '    oUid = oModelrow(_XML_LINE_UID).ToString()
3928
                    ' Dim oID As String = oModelrow(_XML_LINE_SPID)
3929
                    '    oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3930
                    '    oID = oLMConnector.ModelItemID
3931
                    '  oLMConnector = _Placement.PIDDataSource.GetConnector(oID)
3932
                    'If oLMConnector IsNot Nothing Then
3933
                    '    Exit For
3934
                    'End If
3935
                End If
3936

    
3937

    
3938
            Next
3939
        Catch ex As Exception
3940
            bCheckBranchItem = False
3941
            oLMConnector = Nothing
3942
        End Try
3943
        Return bCheckBranchItem
3944
    End Function
3945

    
3946
    ''' <summary>
3947
    ''' 라인과 특정 포인트에 커넥션을 확인하는 메서드
3948
    ''' </summary>
3949
    ''' <param name="oModelingLineRows"></param>
3950
    ''' <param name="dX"></param>
3951
    ''' <param name="dY"></param>
3952
    ''' <param name="oLMConnector"></param>
3953
    ''' <param name="dPreConnX"></param>
3954
    ''' <param name="dPreConnY"></param>
3955
    ''' <returns></returns>
3956

    
3957
    Private Function CheckConnectionLine(ByRef dX As Double, ByRef dY As Double,
3958
                                  ByRef oLMConnector As LMConnector, ByRef sUid As String) As Boolean
3959
        Dim bConnectionFlag As Boolean = False
3960
        Dim iGapCheck As Integer = 0
3961
        Try
3962
            For Each oModelrow In _ModelingLine_Dt.Rows
3963
                Dim d기준x As Double = dX
3964
                Dim d기준y As Double = dY
3965
                Dim dGap As Double = 0.001
3966
                Dim oRun As LMPipeRun = Nothing
3967
                Dim dModelStartX As Double
3968
                Dim dModelStartY As Double
3969
                Dim dModelEndX As Double
3970
                Dim dModelEndY As Double
3971
                dModelStartX = oModelrow(_XML_LINE_DWG_STARTPOINT_X)
3972
                dModelStartY = oModelrow(_XML_LINE_DWG_STARTPOINT_Y)
3973
                dModelEndX = oModelrow(_XML_LINE_DWG_ENDPOINT_X)
3974
                dModelEndY = oModelrow(_XML_LINE_DWG_ENDPOINT_Y)
3975
                d기준x = (dModelStartX + dModelEndX) / 2
3976
                d기준y = (dModelStartY + dModelEndY) / 2
3977

    
3978
                Dim bCheckEqual As Boolean = False
3979
                If dX <= dModelStartX + dGap And dX >= dModelStartX - dGap And
3980
                        dY <= dModelStartY + dGap And dY >= dModelStartY - dGap Then
3981
                    bCheckEqual = True
3982
                ElseIf dX <= dModelEndX + dGap And dX >= dModelEndX - dGap And
3983
                        dY <= dModelEndY + dGap And dY >= dModelEndY - dGap Then
3984
                    bCheckEqual = True
3985
                End If
3986
                If bCheckEqual Then
3987
                    Try
3988
                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
3989
                        sUid = oModelrow(_XML_LINE_UID)
3990
                        oRun = _Placement.PIDDataSource.GetPipeRun(oLMConnector.ModelItemID)
3991
                    Catch ex As Exception
3992
                    End Try
3993
                    Try
3994
                        If oRun IsNot Nothing Then
3995
                            Dim dResultCalc As Double = -1
3996
                            For Each objRep In oRun.Representations
3997
                                If objRep.Attributes("RepresentationType").Value = "Connector" And objRep.Attributes("ItemStatus").Value = "Active" Then
3998
                                    Dim objConnector As LMConnector = _Placement.PIDDataSource.GetConnector(objRep.ID)
3999
                                    For Each objConnectorVertex In objConnector.ConnectorVertices
4000
                                        Dim dConn_X As Double = objConnectorVertex.Attributes("XCoordinate").Value
4001
                                        Dim dConn_Y As Double = objConnectorVertex.Attributes("YCoordinate").Value
4002
                                        If Math.Abs(dX - dConn_X) < dGap And Math.Abs(dY - dConn_Y) < dGap Then
4003
                                            oLMConnector = objConnector
4004
                                            dX = dConn_X
4005
                                            dY = dConn_Y
4006
                                            bConnectionFlag = True
4007
                                        End If
4008
                                    Next
4009
                                End If
4010
                            Next
4011
                        End If
4012
                    Catch ex As Exception
4013
                    End Try
4014
                Else
4015
                End If
4016
            Next
4017
        Catch ex As Exception
4018
            bConnectionFlag = False
4019
            oLMConnector = Nothing
4020
        End Try
4021
        Return bConnectionFlag
4022
    End Function
4023

    
4024
    Private Function CheckAlreadyBranchLine(ByVal sSystemPath As String, ByVal dStartX As Double, ByVal dStartY As Double, ByVal dEndX As Double, ByVal dEndY As Double) As Boolean
4025
        '현재선의 방향을 보고 상대라인이 직교되는 방향인지 체크
4026
        '오차범위를 줘서 현재선을 통과하는지 체크
4027
        '통과하는 상대라인 갯수를 먼저 구한다음 라인 갯수만큼 라인을 그린다.
4028
        Dim bCheckBranchLine As Boolean = False
4029
        Dim sCurrentDirection As String = ""
4030

    
4031
        Dim oModel_Dt As New DataTable()
4032
        oModel_Dt.Columns.Add("X")
4033
        oModel_Dt.Columns.Add("Y")
4034
        oModel_Dt.Columns.Add("Type")
4035
        oModel_Dt.Columns.Add("SPID")
4036
        Dim dGap = 0.001
4037
        If Math.Abs(dStartX - dEndX) > Math.Abs(dStartY - dEndY) Then
4038
            sCurrentDirection = "X"
4039
            If dStartX > dEndX Then
4040
                Dim dTempX As Double = dEndX
4041
                dEndX = dStartX
4042
                dStartX = dTempX
4043
                Dim dTempY As Double = dEndY
4044
                dEndY = dStartY
4045
                dStartY = dTempY
4046
            End If
4047
            '현재선이 X축방향
4048
            Try
4049
                For Each oModelrow In _ModelingLine_Dt.Rows
4050
                    Dim dModelStart_X As Double = oModelrow(_XML_LINE_DWG_STARTPOINT_X)
4051
                    Dim dModelStart_Y As Double = oModelrow(_XML_LINE_DWG_STARTPOINT_Y)
4052
                    Dim dModelEnd_X As Double = oModelrow(_XML_LINE_DWG_ENDPOINT_X)
4053
                    Dim dModelEnd_Y As Double = oModelrow(_XML_LINE_DWG_ENDPOINT_Y)
4054
                    Dim sSPID As String = oModelrow(_XML_LINE_SPID)
4055
                    If dStartX < dModelStart_X And dStartX < dModelEnd_X And
4056
                       dEndX > dModelStart_X And dEndX > dModelEnd_X Then
4057
                        Dim dAddX As Double = dStartX
4058
                        Dim dAddY As Double = dStartY
4059
                        Dim sType As String = ""
4060
                        Dim dAddLineX As Double = 0
4061
                        Dim dAddLineY As Double = 0
4062
                        If dStartY = dModelStart_Y Then
4063
                            dAddX = 0
4064
                            '    dAddX = dModelStart_X
4065
                        ElseIf dStartY = dModelEnd_Y Then
4066
                            dAddX = 0
4067
                            '      dAddX = dModelEnd_X
4068
                        ElseIf dStartY <= dModelStart_Y + dGap And dStartY >= dModelStart_Y - dGap Then
4069
                            dAddX = dModelStart_X
4070
                            If dStartY <= dModelStart_Y Then
4071
                                sType = "AddLine"
4072
                                dAddLineX = dModelStart_X
4073
                                dAddLineY = dModelStart_Y
4074
                            End If
4075
                        ElseIf dStartY <= dModelEnd_Y + dGap And dStartY >= dModelEnd_Y - dGap Then
4076
                            dAddX = dModelEnd_X
4077
                            If dStartY <= dModelEnd_Y Then
4078
                                sType = "AddLine"
4079
                                dAddLineX = dModelEnd_X
4080
                                dAddLineY = dModelEnd_Y
4081
                            End If
4082
                        End If
4083
                        If sType = "AddLine" Then
4084
                            Dim objInputs As PlaceRunInputs
4085
                            objInputs = New PlaceRunInputs
4086
                            Dim oLMConnector As LMConnector = Nothing
4087
                            CheckConnectionLine(dAddLineX, dAddLineY, oLMConnector, "")
4088
                            objInputs.AddPoint(dAddLineX, dAddY)
4089
                            objInputs.AddConnectorTarget(oLMConnector, dAddLineX, dAddLineY)
4090
                            Dim AddLMConnector As LMConnector = LineModeling(objInputs, sSystemPath)
4091
                            JoinPipeRun(oLMConnector.ModelItemID, AddLMConnector.ModelItemID)
4092
                            dStartY = dAddY
4093
                        End If
4094

    
4095
                        If dAddX <> 0 Then
4096
                            Dim oDatarow As DataRow = oModel_Dt.NewRow()
4097
                            oDatarow("X") = dAddX
4098
                            oDatarow("Y") = dAddY
4099
                            oDatarow("Type") = sType
4100
                            oDatarow("SPID") = sSPID
4101
                            oModel_Dt.Rows.Add(oDatarow)
4102
                        End If
4103
                    End If
4104
                Next
4105
            Catch ex As Exception
4106
            End Try
4107
        Else
4108
            '현재선이 y축방향
4109
            sCurrentDirection = "Y"
4110
            Try
4111
                For Each oModelrow In _ModelingLine_Dt.Rows
4112
                    Dim dModelStart_X As Double = oModelrow(_XML_LINE_DWG_STARTPOINT_X)
4113
                    Dim dModelStart_Y As Double = oModelrow(_XML_LINE_DWG_STARTPOINT_Y)
4114
                    Dim dModelEnd_X As Double = oModelrow(_XML_LINE_DWG_ENDPOINT_X)
4115
                    Dim dModelEnd_Y As Double = oModelrow(_XML_LINE_DWG_ENDPOINT_Y)
4116
                    Dim sSPID As String = oModelrow(_XML_LINE_SPID)
4117
                    If dStartY < dModelStart_Y And dStartY < dModelEnd_Y And
4118
                       dEndY > dModelStart_Y And dEndY > dModelEnd_Y Then
4119
                        Dim dAddX As Double = dStartX
4120
                        Dim dAddY As Double = dStartY
4121
                        Dim sType As String = ""
4122
                        Dim dAddLineX As Double = 0
4123
                        Dim dAddLineY As Double = 0
4124
                        If dStartX = dModelStart_X Then
4125
                            dAddY = 0
4126
                            '       dAddY = dModelStart_Y
4127
                        ElseIf dStartX = dModelEnd_X Then
4128
                            dAddY = 0
4129
                            '        dAddY = dModelEnd_Y
4130
                        ElseIf dStartX <= dModelStart_X + dGap And dStartX >= dModelStart_X - dGap Then
4131
                            '         dAddY = dModelStart_Y
4132
                            If dStartX <= dModelStart_X Then
4133
                                dAddLineX = dModelStart_X
4134
                                dAddLineY = dModelStart_Y
4135
                                sType = "AddLine"
4136
                            End If
4137
                        ElseIf dStartX <= dModelEnd_X + dGap And dStartX >= dModelEnd_X - dGap Then
4138
                            '        dAddY = dModelEnd_Y
4139
                            If dStartX <= dModelEnd_X Then
4140
                                dAddLineX = dModelEnd_X
4141
                                dAddLineY = dModelEnd_Y
4142
                                sType = "AddLine"
4143
                            End If
4144
                        End If
4145
                        If sType = "AddLine" Then
4146
                            Dim objInputs As PlaceRunInputs
4147
                            objInputs = New PlaceRunInputs
4148
                            Dim oLMConnector As LMConnector = Nothing
4149
                            CheckConnectionLine(dAddLineX, dAddLineY, oLMConnector, "")
4150
                            objInputs.AddPoint(dAddX, dAddLineY)
4151
                            objInputs.AddConnectorTarget(oLMConnector, dAddLineX, dAddLineY)
4152
                            Dim AddLMConnector As LMConnector = LineModeling(objInputs, sSystemPath)
4153
                            JoinPipeRun(oLMConnector.ModelItemID, AddLMConnector.ModelItemID)
4154
                            dStartX = dAddX
4155
                        End If
4156

    
4157
                        If dAddY <> 0 Then
4158
                            Dim oDatarow As DataRow = oModel_Dt.NewRow()
4159
                            oDatarow("X") = dAddX
4160
                            oDatarow("Y") = dAddY
4161
                            oDatarow("Type") = sType
4162
                            oDatarow("SPID") = sSPID
4163
                            oModel_Dt.Rows.Add(oDatarow)
4164
                        End If
4165
                    End If
4166
                Next
4167
            Catch ex As Exception
4168
            End Try
4169
        End If
4170

    
4171
        '//못미치는 라인은 라인길이를 더한후 나머지 모델링(2018.09.27)
4172

    
4173
        If oModel_Dt.Rows.Count > 0 Then
4174
            If sCurrentDirection = "X" Then
4175
                'X좌표 정렬
4176
                oModel_Dt.DefaultView.Sort = "X desc"
4177
                oModel_Dt = oModel_Dt.DefaultView.ToTable(True)
4178
            Else
4179
                'Y좌표 정렬
4180
                oModel_Dt.DefaultView.Sort = "Y desc"
4181
                oModel_Dt = oModel_Dt.DefaultView.ToTable(True)
4182
            End If
4183
            Dim oLMConnector As LMConnector = Nothing
4184
            Dim oPreLMConnector As LMConnector = Nothing
4185
            Dim dStartFlag As Boolean = True
4186
            For Each oModelRow In oModel_Dt.Rows
4187
                Dim objInputs As PlaceRunInputs
4188
                objInputs = New PlaceRunInputs
4189
                Dim dX As Double = oModelRow("X")
4190
                Dim dY As Double = oModelRow("Y")
4191
                Dim sType As String = oModelRow("Type")
4192
                Dim sUid As String = ""
4193

    
4194

    
4195
                CheckConnectionLine(dX, dY, oLMConnector, sUid)
4196
                If oLMConnector IsNot Nothing Then
4197
                    If dStartFlag Then
4198
                        objInputs.AddPoint(dStartX, dStartY)
4199
                        objInputs.AddConnectorTarget(oLMConnector, dX, dY)
4200
                    Else
4201
                        objInputs.AddConnectorTarget(oPreLMConnector, dStartX, dStartY)
4202
                        objInputs.AddConnectorTarget(oLMConnector, dX, dY)
4203
                    End If
4204
                    oPreLMConnector = LineModeling(objInputs, sSystemPath)
4205
                    '모델링후 StartX를 현재 X로 변경
4206
                    dStartX = dX
4207
                    dStartY = dY
4208
                End If
4209
            Next
4210
            If oPreLMConnector IsNot Nothing Then
4211
                Dim objInputs As PlaceRunInputs
4212
                objInputs = New PlaceRunInputs
4213
                objInputs.AddConnectorTarget(oPreLMConnector, dStartX, dStartY)
4214
                objInputs.AddPoint(dEndX, dEndY)
4215
                LineModeling(objInputs, sSystemPath)
4216
            End If
4217
        End If
4218
        Return bCheckBranchLine
4219
    End Function
4220

    
4221

    
4222
    Private Function CheckLineBranch(ByVal oLine_Dt As DataTable, ByRef dX As Double, ByRef dY As Double,
4223
                                     ByVal sDirection As String, ByRef oLMConnector As LMConnector) As Boolean
4224

    
4225
        Dim oModelingLineRows() As DataRow = oLine_Dt.Select(" Then[" & _XML_LINE_DRAWING_TF & "] = 'TRUE' And " &
4226
                                                                "[" & _XML_LINE_SPID & "] <> ''")
4227

    
4228
        Dim bConnectionFlag As Boolean = False
4229
        Try
4230
            For Each oModelrow In oModelingLineRows
4231
                Dim sStartPoint As String = oModelrow(_XML_LINE_STARTPOINT)
4232
                Dim sEndPoint As String = oModelrow(_XML_LINE_ENDPOINT)
4233
                Dim dModelStartX As Double
4234
                Dim dModelStartY As Double
4235
                Dim dModelEndX As Double
4236
                Dim dModelEndY As Double
4237
                ConvertPointBystring(sStartPoint, dModelStartX, dModelStartY)
4238
                ConvertPointBystring(sEndPoint, dModelEndX, dModelEndY)
4239
                ConvertPointByImage(dModelStartX, dModelStartY, _IMG_X, _IMG_Y)
4240
                ConvertPointByImage(dModelEndX, dModelEndY, _IMG_X, _IMG_Y)
4241
                Dim dGap As Double = 0.0002
4242

    
4243
                If Math.Abs(dModelStartX - dModelEndX) <= Math.Abs(dModelStartY - dModelEndY) Then
4244
                    'Vertical
4245
                    If sDirection = "X" Then
4246
                        'x Direction Line
4247
                        If (dModelStartY + dGap >= dY And dModelEndY - dGap <= dY) Or
4248
                        (dModelStartY - dGap <= dY And dModelEndY + dGap >= dY) Then
4249
                            If (dX > dModelStartX And dX < dModelEndX) Or (dX > dModelEndX And dX < dModelStartX) Then
4250
                                If Math.Abs(dX - dModelStartX) > Math.Abs(dX - dModelEndX) Then
4251
                                    dX = dModelEndX
4252
                                Else
4253
                                    dX = dModelStartX
4254
                                End If
4255
                                Try
4256
                                    oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4257
                                Catch ex As Exception
4258

    
4259
                                End Try
4260
                                bConnectionFlag = True
4261
                            End If
4262
                        End If
4263
                    End If
4264
                Else
4265
                    'Horizontal 
4266
                    If sDirection = "Y" Then
4267
                        If (dModelStartX + dGap >= dX And dModelEndX - dGap <= dX) Or
4268
                       (dModelStartX - dGap <= dX And dModelEndX + dGap >= dX) Then
4269
                            If (dY > dModelStartY And dY < dModelEndY) Or (dY > dModelEndY And dY < dModelStartY) Then
4270
                                If Math.Abs(dY - dModelStartY) > Math.Abs(dY - dModelEndY) Then
4271
                                    dY = dModelEndY
4272
                                Else
4273
                                    dY = dModelStartY
4274
                                End If
4275
                                Try
4276
                                    oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4277
                                Catch ex As Exception
4278
                                End Try
4279
                                bConnectionFlag = True
4280
                            End If
4281
                        End If
4282
                    End If
4283
                End If
4284
            Next
4285
        Catch ex As Exception
4286
        End Try
4287
        Return bConnectionFlag
4288
    End Function
4289
    Private Function LineModeling(ByVal oLine_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal sStartLineUid As String, ByVal sEndLineUid As String, ByVal dStart_x As Double, ByVal dStart_y As Double, ByVal dEnd_x As Double, ByVal dEnd_y As Double,
4290
                              ByVal sLineNoUid As String, ByVal sLineUid As String, ByVal sSystemPath As String, ByRef oLMConnector As LMConnector) As Boolean
4291
        'Try
4292
        '    Dim oDatasource As Object = _Placement.PIDDataSource
4293
        '    Dim oPipeRun As LMPipeRun = Nothing
4294
        '    Dim objInputs As PlaceRunInputs
4295
        '    objInputs = New PlaceRunInputs
4296
        '    Dim objItem As LMAItem
4297
        '    '       Dim objConnector As LMConnector
4298

    
4299
        '    Dim oStartLineRow() As DataRow = oLine_Dt.Select("[" & _XML_LINE_Conn1_Uid & "] = '" & sStartLineUid & "' And " &
4300
        '                                                            "[" & _XML_LINE_DRAWING_TF & "] = 'TRUE' And" &
4301
        '                                                                  "[" & _XML_LINE_SPID & "] <> ''")
4302
        '    If oStartLineRow.Length = 0 Then
4303
        '        oStartLineRow = oLine_Dt.Select("[" & _XML_LINE_Conn2_Uid & "] = '" & sStartLineUid & "' And " &
4304
        '                                                            "[" & _XML_LINE_DRAWING_TF & "] = 'TRUE' And" &
4305
        '                                                                  "[" & _XML_LINE_SPID & "] <> ''")
4306
        '    End If
4307
        '    Dim oEndLineRow() As DataRow = oLine_Dt.Select("[" & _XML_LINE_Conn1_Uid & "] = '" & sEndLineUid & "' And " &
4308
        '                                                            "[" & _XML_LINE_DRAWING_TF & "] = 'TRUE' And" &
4309
        '                                                                  "[" & _XML_LINE_SPID & "] <> ''")
4310

    
4311
        '    oEndLineRow = oLine_Dt.Select("[" & _XML_LINE_Conn2_Uid & "] = '" & sEndLineUid & "' And " &
4312
        '                                                            "[" & _XML_LINE_DRAWING_TF & "] = 'TRUE' And" &
4313
        '                                                                  "[" & _XML_LINE_SPID & "] <> ''")
4314
        '    Dim sStartConnectionType As String = ""
4315
        '    Dim sEndConnectionType As String = ""
4316

    
4317
        '    Dim oStartLMConnector As LMConnector = Nothing
4318
        '    Dim oEndLMConnector As LMConnector = Nothing
4319
        '    Dim oDirectionLine As String = ""
4320

    
4321
        '    If Math.Abs(dStart_x - dEnd_x) > Math.Abs(dStart_y - dEnd_y) Then
4322
        '        oDirectionLine = "X"
4323
        '    Else
4324
        '        oDirectionLine = "Y"
4325
        '    End If
4326

    
4327
        '    Dim bCheckFlag As Boolean = False
4328

    
4329
        '    Dim bStartCheckFlag As Boolean = CheckConnectionLine(oStartLineRow, dStart_x, dStart_y, oStartLMConnector)
4330
        '    If bStartCheckFlag = False Then
4331
        '        bStartCheckFlag = CheckConnectionLine(oStartLineRow, dEnd_x, dEnd_y, oStartLMConnector)
4332
        '        bCheckFlag = True
4333
        '    End If
4334
        '    Dim bEndCheckFlag As Boolean = CheckConnectionLine(oEndLineRow, dEnd_x, dEnd_y, oEndLMConnector)
4335

    
4336
        '    If bEndCheckFlag = False Then
4337

    
4338
        '        bEndCheckFlag = CheckConnectionLine(oEndLineRow, dStart_x, dStart_y, oEndLMConnector)
4339
        '        bCheckFlag = True
4340
        '    End If
4341

    
4342
        '    If bStartCheckFlag = True And bEndCheckFlag = False Then
4343
        '        If bCheckFlag Then
4344
        '            objInputs.AddConnectorTarget(oStartLMConnector, dEnd_x, dEnd_y)
4345
        '            objInputs.AddPoint(dStart_x, dStart_y)
4346
        '        Else
4347
        '            objInputs.AddConnectorTarget(oStartLMConnector, dStart_x, dStart_y)
4348
        '            objInputs.AddPoint(dEnd_x, dEnd_y)
4349
        '        End If
4350

    
4351
        '    ElseIf bStartCheckFlag = False And bEndCheckFlag = True Then
4352
        '        If bCheckFlag Then
4353

    
4354
        '            objInputs.AddConnectorTarget(oStartLMConnector, dStart_x, dStart_y)
4355
        '            objInputs.AddPoint(dEnd_x, dEnd_y)
4356
        '        Else
4357
        '            objInputs.AddPoint(dStart_x, dStart_y)
4358
        '            objInputs.AddConnectorTarget(oStartLMConnector, dEnd_x, dEnd_y)
4359
        '        End If
4360

    
4361
        '    ElseIf bStartCheckFlag = True And bEndCheckFlag = True Then
4362
        '        objInputs.AddConnectorTarget(oStartLMConnector, dStart_x, dStart_y)
4363
        '        objInputs.AddConnectorTarget(oEndLMConnector, dEnd_x, dEnd_y)
4364
        '    Else
4365
        '        objInputs.AddPoint(dStart_x, dStart_y)
4366
        '        objInputs.AddPoint(dEnd_x, dEnd_y)
4367
        '    End If
4368
        '    SetListBoxItems(ListBox_Result, "Place Pipe..(" & dStart_x & "," & dStart_y & ") - (" & dEnd_x & "," & dEnd_y & ")..." & _iPipecnt & " count ")
4369
        '    _iPipecnt = _iPipecnt + 1
4370
        '    objItem = _Placement.PIDCreateItem(sSystemPath)
4371
        '    oLMConnector = _Placement.PIDPlaceRun(objItem, objInputs)
4372

    
4373
        '    Dim oUpdateRow As DataRow() = oLine_Dt.Select(_XML_LINE_UID & " = '" + sLineUid + "'")
4374
        '    If oUpdateRow.Length = 1 Then
4375
        '        oUpdateRow(0)(_XML_LINE_SPID) = oLMConnector.ModelItemID
4376
        '        oUpdateRow(0)(_XML_LINE_LMCONNECTOR) = oLMConnector
4377

    
4378
        '        oUpdateRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
4379
        '    End If
4380

    
4381
        '    oPipeRun = oDatasource.GetPipeRun(oLMConnector.ModelItemID)
4382

    
4383
        '    Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
4384
        '    If oAttributeRow.Length > 0 Then
4385
        '        For Each oAttribute In oAttributeRow
4386
        '            Try
4387
        '                Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
4388
        '                Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
4389
        '                If sPIDValue.Contains("'") Then
4390
        '                    sPIDValue = sPIDValue.Replace("'", """")
4391
        '                End If
4392
        '                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
4393
        '                oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
4394
        '            Catch ex As Exception
4395
        '            End Try
4396
        '        Next
4397
        '        oPipeRun.Commit()
4398
        '    End If
4399
        '    Dim sID_1 As String = ""
4400
        '    Dim sID_2 As String = ""
4401
        '    If oStartLMConnector IsNot Nothing Then
4402
        '        sID_1 = oStartLMConnector.ModelItemID
4403
        '        sID_2 = oLMConnector.ModelItemID
4404
        '    ElseIf oEndLMConnector IsNot Nothing Then
4405
        '        sID_1 = oEndLMConnector.ModelItemID
4406
        '        sID_2 = oLMConnector.ModelItemID
4407
        '    End If
4408
        '    If sID_1 <> "" And sID_2 <> "" Then
4409
        '        Dim objSurvivorItem As LMAItem = Nothing
4410
        '        Dim oPipeRun1 As LMPipeRun = oDatasource.GetPipeRun(sID_1)
4411
        '        Dim oPipeRun2 As LMPipeRun = oDatasource.GetPipeRun(sID_2)
4412
        '        _Placement.PIDJoinRuns(oPipeRun1, oPipeRun2)
4413
        '    End If
4414
        '    Return True
4415
        'Catch ex As Exception
4416
        '    Return False
4417
        'End Try
4418

    
4419
    End Function
4420

    
4421
    Private Function LineToLineModeling(ByVal sLineNoUid As String, ByVal oLine_Dt As DataTable,
4422
                                        ByVal oAttribute_Dt As DataTable, ByVal sConnLineUid As String, ByVal sType As String,
4423
                                        ByRef oLMConnector As LMConnector) As String
4424
        Dim sReturnUid As String = ""
4425
        Try
4426
            Dim sLineUid As String = ""
4427

    
4428
            Dim iConnType As Integer = 0
4429

    
4430
            Dim sStartpoint As String = ""
4431
            Dim sEndpoint As String = ""
4432
            Dim dOriginalStart_x As Double = 0.0
4433
            Dim dOriginalStart_y As Double = 0.0
4434
            Dim dOriginalEnd_x As Double = 0.0
4435
            Dim dOriginalEnd_y As Double = 0.0
4436

    
4437
            Dim dStart_x As Double = 0
4438
            Dim dStart_y As Double = 0
4439
            Dim dEnd_x As Double = 0
4440
            Dim dEnd_y As Double = 0
4441
            Dim sStartLineUid As String = sConnLineUid
4442
            Dim sEndLineUid As String = ""
4443
            Dim sDirection As String = ""
4444
            Dim sSystemPath As String = GetPipeType(sType)
4445

    
4446
            Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_UID & " = '" & sConnLineUid & "' And " &
4447
                                                                    "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
4448
                                                                     "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
4449
                                                                     "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
4450
            If oPipeRow.Length > 0 Then
4451
                sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
4452
                sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
4453
                ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
4454
                ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
4455
                ConvertPointByImage(dOriginalStart_x, dOriginalStart_y, _IMG_X, _IMG_Y)
4456
                ConvertPointByImage(dOriginalEnd_x, dOriginalEnd_y, _IMG_X, _IMG_Y)
4457
                If dStart_x = 0 And dStart_y = 0 Then
4458
                    dStart_x = dOriginalStart_x
4459
                    dStart_y = dOriginalStart_y
4460
                    dEnd_x = dOriginalEnd_x
4461
                    dEnd_y = dOriginalEnd_y
4462
                    If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
4463
                        sDirection = "X"
4464
                    Else
4465
                        sDirection = "Y"
4466
                    End If
4467
                    oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
4468
                    sLineUid = sConnLineUid
4469
                End If
4470
            End If
4471

    
4472
            While True
4473
                sLineUid = ""
4474
                oPipeRow = oLine_Dt.Select(_XML_LINE_Conn1_Uid & " = '" + sConnLineUid + "' And " &
4475
                                            "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
4476
                                            "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
4477
                                            "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
4478

    
4479
                If oPipeRow.Length = 0 Then
4480
                    oPipeRow = oLine_Dt.Select(_XML_LINE_Conn2_Uid & " = '" + sConnLineUid + "' And " &
4481
                                            "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
4482
                                            "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
4483
                                            "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
4484
                Else
4485
                    'sLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
4486
                    'sConnLineUid = sLineUid
4487
                    sLineUid = sConnLineUid
4488
                    sConnLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
4489
                    iConnType = 1
4490
                End If
4491

    
4492
                If oPipeRow.Length > 0 Then
4493
                    If sLineUid = "" Then
4494
                        'sLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
4495
                        'sConnLineUid = sLineUid
4496
                        sLineUid = sConnLineUid
4497
                        sConnLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
4498
                        iConnType = 2
4499
                    End If
4500
                    If iConnType = 1 Then
4501

    
4502
                    ElseIf iConnType = 2 Then
4503

    
4504
                    End If
4505
                    sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
4506
                    sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
4507
                    ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
4508
                    ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
4509
                    ConvertPointByImage(dOriginalStart_x, dOriginalStart_y, _IMG_X, _IMG_Y)
4510
                    ConvertPointByImage(dOriginalEnd_x, dOriginalEnd_y, _IMG_X, _IMG_Y)
4511

    
4512
                    If dStart_x = 0 And dStart_y = 0 Then
4513
                        dStart_x = dOriginalStart_x
4514
                        dStart_y = dOriginalStart_y
4515
                        dEnd_x = dOriginalEnd_x
4516
                        dEnd_y = dOriginalEnd_y
4517
                        If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
4518
                            sDirection = "X"
4519
                        Else
4520
                            sDirection = "Y"
4521
                        End If
4522
                        sType = oPipeRow(0)(_XML_LINE_TYPE).ToString()
4523
                        sSystemPath = GetPipeType(sType)
4524
                    Else
4525
                        If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
4526
                            If sDirection = "Y" Then
4527
                                '방향이 바꼈음 Y - > X
4528
                                LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
4529
                                sLineNoUid, sLineUid, sSystemPath, oLMConnector)
4530
                                dStart_x = dOriginalStart_x
4531
                                dStart_y = dOriginalStart_y
4532
                                dEnd_x = dOriginalEnd_x
4533
                                dEnd_y = dOriginalEnd_y
4534
                                sStartLineUid = sConnLineUid
4535
                            Else
4536
                                dEnd_x = dOriginalEnd_x
4537
                                dEnd_y = dOriginalEnd_y
4538
                            End If
4539
                            sDirection = "X"
4540
                        Else
4541
                            If sDirection = "X" Then
4542
                                '방향이 바꼈음 X - > Y
4543
                                LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
4544
                                sLineNoUid, sLineUid, sSystemPath, oLMConnector)
4545
                                dStart_x = dOriginalStart_x
4546
                                dStart_y = dOriginalStart_y
4547
                                dEnd_x = dOriginalEnd_x
4548
                                dEnd_y = dOriginalEnd_y
4549
                                sStartLineUid = sConnLineUid
4550
                            Else
4551

    
4552
                                dEnd_x = dOriginalEnd_x
4553
                                dEnd_y = dOriginalEnd_y
4554
                            End If
4555
                            sDirection = "Y"
4556
                        End If
4557
                    End If
4558
                    '            oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
4559
                Else
4560
                    If dStart_x <> 0 And dStart_y <> 0 And dEnd_x <> 0 And dEnd_y <> 0 Then
4561
                        LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
4562
                         sLineNoUid, sLineUid, sSystemPath, oLMConnector)
4563
                    End If
4564
                    sReturnUid = sConnLineUid
4565
                    Exit While
4566
                End If
4567
            End While
4568

    
4569
            If sStartLineUid <> "" And sEndLineUid <> "" Then
4570
                LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
4571
                             sLineNoUid, sLineUid, sSystemPath, oLMConnector)
4572
                dStart_x = 0
4573
                dStart_y = 0
4574
                dEnd_x = 0
4575
                dEnd_y = 0
4576
            End If
4577
        Catch ex As Exception
4578

    
4579
        End Try
4580

    
4581
        Return sReturnUid
4582
    End Function
4583

    
4584

    
4585
    'Private Function LineToLineModeling(ByVal sLineNoUid As String, ByVal oLine_Dt As DataTable,
4586
    '                                    ByVal oAttribute_Dt As DataTable, ByVal sConnLineUid As String, ByVal sType As String) As String
4587
    '    Dim sReturnUid As String = ""
4588
    '    Try
4589
    '        Dim sLineUid As String = ""
4590

    
4591
    '        Dim iConnType As Integer = 0
4592

    
4593
    '        Dim sStartpoint As String = ""
4594
    '        Dim sEndpoint As String = ""
4595
    '        Dim dOriginalStart_x As Double = 0.0
4596
    '        Dim dOriginalStart_y As Double = 0.0
4597
    '        Dim dOriginalEnd_x As Double = 0.0
4598
    '        Dim dOriginalEnd_y As Double = 0.0
4599

    
4600
    '        Dim dStart_x As Double = 0
4601
    '        Dim dStart_y As Double = 0
4602
    '        Dim dEnd_x As Double = 0
4603
    '        Dim dEnd_y As Double = 0
4604
    '        Dim sStartLineUid As String = sConnLineUid
4605
    '        Dim sEndLineUid As String = ""
4606
    '        Dim sDirection As String = ""
4607
    '        Dim sSystemPath As String = GetPipeType(sType)
4608

    
4609
    '        Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_UID & " = '" & sConnLineUid & "' And " &
4610
    '                                                                "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
4611
    '                                                                 "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
4612
    '                                                                 "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
4613
    '        If oPipeRow.Length > 0 Then
4614
    '            sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
4615
    '            sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
4616
    '            ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
4617
    '            ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
4618
    '            ConvertPointByImage(dOriginalStart_x, dOriginalStart_y, _IMG_X, _IMG_Y)
4619
    '            ConvertPointByImage(dOriginalEnd_x, dOriginalEnd_y, _IMG_X, _IMG_Y)
4620
    '            If dStart_x = 0 And dStart_y = 0 Then
4621
    '                dStart_x = dOriginalStart_x
4622
    '                dStart_y = dOriginalStart_y
4623
    '                dEnd_x = dOriginalEnd_x
4624
    '                dEnd_y = dOriginalEnd_y
4625
    '                If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
4626
    '                    sDirection = "X"
4627
    '                Else
4628
    '                    sDirection = "Y"
4629
    '                End If
4630
    '                oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
4631
    '                sLineUid = sConnLineUid
4632
    '            End If
4633
    '        End If
4634

    
4635
    '        While True
4636
    '            sLineUid = ""
4637
    '            oPipeRow = oLine_Dt.Select(_XML_LINE_Conn1_Uid & " = '" + sConnLineUid + "' And " &
4638
    '                                                                "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
4639
    '                                                                         "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
4640
    '                                                                         "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
4641

    
4642
    '            If oPipeRow.Length = 0 Then
4643
    '                oPipeRow = oLine_Dt.Select(_XML_LINE_Conn2_Uid & " = '" + sConnLineUid + "' And " &
4644
    '                                         "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
4645
    '                                       "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
4646
    '                                      "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
4647
    '            Else
4648
    '                'sLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
4649
    '                'sConnLineUid = sLineUid
4650
    '                sLineUid = sConnLineUid
4651
    '                sConnLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
4652
    '                iConnType = 1
4653
    '            End If
4654

    
4655
    '            If oPipeRow.Length > 0 Then
4656
    '                If sLineUid = "" Then
4657
    '                    'sLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
4658
    '                    'sConnLineUid = sLineUid
4659
    '                    sLineUid = sConnLineUid
4660
    '                    sConnLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
4661
    '                    iConnType = 2
4662
    '                End If
4663
    '                If iConnType = 1 Then
4664

    
4665
    '                ElseIf iConnType = 2 Then
4666

    
4667
    '                End If
4668
    '                sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
4669
    '                sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
4670
    '                ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
4671
    '                ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
4672
    '                ConvertPointByImage(dOriginalStart_x, dOriginalStart_y, _IMG_X, _IMG_Y)
4673
    '                ConvertPointByImage(dOriginalEnd_x, dOriginalEnd_y, _IMG_X, _IMG_Y)
4674

    
4675

    
4676

    
4677
    '                If dStart_x = 0 And dStart_y = 0 Then
4678
    '                    dStart_x = dOriginalStart_x
4679
    '                    dStart_y = dOriginalStart_y
4680
    '                    dEnd_x = dOriginalEnd_x
4681
    '                    dEnd_y = dOriginalEnd_y
4682
    '                    If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
4683
    '                        sDirection = "X"
4684
    '                    Else
4685
    '                        sDirection = "Y"
4686
    '                    End If
4687
    '                    sType = oPipeRow(0)(_XML_LINE_TYPE).ToString()
4688
    '                    sSystemPath = GetPipeType(sType)
4689
    '                Else
4690
    '                    If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
4691
    '                        If sDirection = "Y" Then
4692
    '                            '방향이 바꼈음 Y - > X
4693
    '                            LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
4694
    '                            sLineNoUid, sLineUid, sSystemPath)
4695
    '                            dStart_x = dOriginalStart_x
4696
    '                            dStart_y = dOriginalStart_y
4697
    '                            dEnd_x = dOriginalEnd_x
4698
    '                            dEnd_y = dOriginalEnd_y
4699
    '                            sStartLineUid = sConnLineUid
4700
    '                        Else
4701
    '                            dEnd_x = dOriginalEnd_x
4702
    '                            dEnd_y = dOriginalEnd_y
4703
    '                        End If
4704
    '                        sDirection = "X"
4705
    '                    Else
4706
    '                        If sDirection = "X" Then
4707
    '                            '방향이 바꼈음 X - > Y
4708
    '                            LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
4709
    '                            sLineNoUid, sLineUid, sSystemPath)
4710
    '                            dStart_x = dOriginalStart_x
4711
    '                            dStart_y = dOriginalStart_y
4712
    '                            dEnd_x = dOriginalEnd_x
4713
    '                            dEnd_y = dOriginalEnd_y
4714
    '                            sStartLineUid = sConnLineUid
4715
    '                        Else
4716

    
4717
    '                            dEnd_x = dOriginalEnd_x
4718
    '                            dEnd_y = dOriginalEnd_y
4719
    '                        End If
4720
    '                        sDirection = "Y"
4721
    '                    End If
4722
    '                End If
4723
    '                '            oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
4724
    '            Else
4725
    '                If dStart_x <> 0 And dStart_y <> 0 And dEnd_x <> 0 And dEnd_y <> 0 Then
4726
    '                    LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
4727
    '                     sLineNoUid, sLineUid, sSystemPath)
4728
    '                End If
4729

    
4730

    
4731
    '                sReturnUid = sConnLineUid
4732
    '                Exit While
4733
    '            End If
4734
    '        End While
4735

    
4736
    '        If sStartLineUid <> "" And sEndLineUid <> "" Then
4737
    '            LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
4738
    '                         sLineNoUid, sLineUid, sSystemPath)
4739
    '            dStart_x = 0
4740
    '            dStart_y = 0
4741
    '            dEnd_x = 0
4742
    '            dEnd_y = 0
4743
    '        End If
4744
    '    Catch ex As Exception
4745

    
4746
    '    End Try
4747

    
4748
    '    Return sReturnUid
4749
    'End Function
4750

    
4751

    
4752
    Private Function SymbolToLine_Modeling(ByVal oLine_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal sLineNoUid As String,
4753
                                       ByVal sSymbolUid As String, ByVal oLMSymbol As LMSymbol) As String
4754

    
4755

    
4756
        Dim oDatasource As Object = _Placement.PIDDataSource
4757
        Dim oPipeRun As LMPipeRun = Nothing
4758
        Dim objItem As LMAItem
4759
        Dim objConnector As LMConnector
4760
        Dim objInputs As PlaceRunInputs
4761
        objInputs = New PlaceRunInputs
4762

    
4763

    
4764
        Dim sPipeUid As String = ""
4765
        Dim iConnType As Integer = 0
4766
        Dim sStartpoint As String = ""
4767
        Dim sEndpoint As String = ""
4768
        Dim dOriginalStart_x As Double = 0.0
4769
        Dim dOriginalStart_y As Double = 0.0
4770
        Dim dOriginalEnd_x As Double = 0.0
4771
        Dim dOriginalEnd_y As Double = 0.0
4772
        Dim dStart_x As Double = 0.0
4773
        Dim dStart_y As Double = 0.0
4774
        Dim dEnd_x As Double = 0.0
4775
        Dim dEnd_y As Double = 0.0
4776

    
4777
        Dim sReturnUid As String = ""
4778
        Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_Conn1_Uid & " = '" + sSymbolUid + "' And " &
4779
                                                                        "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
4780
                                                                                  _XML_SYMBOL_Check & "] = 'TRUE'")
4781
        If oPipeRow.Length = 0 Then
4782
            oPipeRow = oLine_Dt.Select(_XML_LINE_Conn2_Uid & " = '" + sSymbolUid + "' And " &
4783
                                     "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
4784
                                    _XML_SYMBOL_Check & "] = 'TRUE'")
4785
        Else
4786
            sPipeUid = oPipeRow(0)(_XML_LINE_UID).ToString()
4787
            iConnType = 1
4788
        End If
4789

    
4790
        If oPipeRow.Length = 1 Then
4791
            If sPipeUid = "" Then
4792
                sPipeUid = oPipeRow(0)(_XML_LINE_UID).ToString()
4793
                iConnType = 2
4794
            End If
4795
            sReturnUid = oPipeRow(0)(_XML_LINE_UID).ToString()
4796
            sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
4797
            sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
4798
            ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
4799
            dStart_x = dOriginalStart_x
4800
            dStart_y = dOriginalStart_y
4801
            ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
4802
            dEnd_x = dOriginalEnd_x
4803
            dEnd_y = dOriginalEnd_y
4804
            ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
4805
            ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
4806
            'OPC Connection Point가져와서 연결(2018-07-12)
4807
            If iConnType = 1 Then
4808
                FindNearPoint(oLMSymbol, dStart_x, dStart_y)
4809
                objInputs.AddSymbolTarget(oLMSymbol, dStart_x, dStart_y)
4810
                objInputs.AddPoint(dEnd_x, dEnd_y)
4811
            Else
4812
                FindNearPoint(oLMSymbol, dEnd_x, dEnd_y)
4813
                objInputs.AddSymbolTarget(oLMSymbol, dEnd_x, dEnd_y)
4814
                objInputs.AddPoint(dStart_x, dStart_y)
4815
            End If
4816
            oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
4817

    
4818
            Dim sType As String = oPipeRow(0)(_XML_LINE_TYPE).ToString()
4819
            Dim sSystemPath As String = GetPipeType(sType)
4820

    
4821

    
4822

    
4823

    
4824
            objItem = _Placement.PIDCreateItem(sSystemPath)
4825
            objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
4826
            oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
4827
            Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
4828
            If oAttributeRow.Length > 0 Then
4829
                For Each oAttribute In oAttributeRow
4830
                    Try
4831
                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
4832
                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
4833
                        If sPIDValue.Contains("'") Then
4834
                            sPIDValue = sPIDValue.Replace("'", """")
4835
                        End If
4836
                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
4837
                        oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
4838
                    Catch ex As Exception
4839
                    End Try
4840
                Next
4841
                oPipeRun.Commit()
4842
            End If
4843
        End If
4844
        Return sReturnUid
4845
    End Function
4846

    
4847
    Private Function LineToSymbol_Modeling(ByVal oSymbol_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal sLineNoUid As String,
4848
                                       ByVal sLineUid As String, ByVal oLMConnector As LMConnector, ByRef oLMSymbol As LMSymbol) As String
4849

    
4850

    
4851
        Dim oDatasource As Object = _Placement.PIDDataSource
4852
        Dim objItem As LMAItem
4853
        Dim objConnector As LMConnector
4854
        Dim objInputs As PlaceRunInputs
4855
        objInputs = New PlaceRunInputs
4856

    
4857

    
4858
        Dim sSymbolUid As String = ""
4859
        Dim iConnType As Integer = 0
4860
        Dim dOriginalPoint_x As Double = 0.0
4861
        Dim dORiginalPoint_y As Double = 0.0
4862
        Dim dX As Double = 0.0
4863
        Dim dY As Double = 0.0
4864
        Dim sReturnUid As String = ""
4865
        Dim oSymbolRow() As DataRow = oSymbol_Dt.Select(_XML_SYMBOL_Conn1_Uid & " = '" + sLineUid + "' And " &
4866
                                                                        "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
4867
                                                                                  _XML_SYMBOL_Check & "] = 'TRUE'")
4868
        If oSymbolRow.Length = 0 Then
4869
            oSymbolRow = oSymbol_Dt.Select(_XML_SYMBOL_Conn2_Uid & " = '" + sLineUid + "' And " &
4870
                                                                        "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
4871
                                                                                 _XML_SYMBOL_Check & "] = 'TRUE'")
4872
            If oSymbolRow.Length = 0 Then
4873
                oSymbolRow = oSymbol_Dt.Select(_XML_SYMBOL_Conn2_Uid & " = '" + sLineUid + "' And " &
4874
                                                                 "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
4875
                                                                          _XML_SYMBOL_Check & "] = 'TRUE'")
4876
                If oSymbolRow.Length = 0 Then
4877
                    oSymbolRow = oSymbol_Dt.Select(_XML_SYMBOL_Conn2_Uid & " = '" + sLineUid + "' And " &
4878
                                                   "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
4879
                                                            _XML_SYMBOL_Check & "] = 'TRUE'")
4880
                    If oSymbolRow.Length = 0 Then
4881

    
4882
                    Else
4883
                        sSymbolUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
4884
                        iConnType = 4
4885
                    End If
4886
                Else
4887
                    sSymbolUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
4888
                    iConnType = 3
4889
                End If
4890
            Else
4891
                sSymbolUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
4892
                iConnType = 2
4893
            End If
4894

    
4895
        Else
4896
            sSymbolUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
4897
            iConnType = 1
4898
        End If
4899

    
4900
        If oSymbolRow.Length = 1 Then
4901
            If sSymbolUid = "" Then
4902
                sSymbolUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
4903
                iConnType = 2
4904
            End If
4905
            sReturnUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
4906
            Dim sOriginalPoint As String = oSymbolRow(0)(_XML_SYMBOL_ORIGINALPOINT).ToString()
4907
            ConvertPointBystring(sOriginalPoint, dOriginalPoint_x, dORiginalPoint_y)
4908
            dX = dOriginalPoint_x
4909
            dY = dORiginalPoint_y
4910
            ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
4911
            'OPC Connection Point가져와서 연결(2018-07-12)
4912

    
4913
            oSymbolRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
4914

    
4915
            Dim sType As String = oSymbolRow(0)(_XML_LINE_TYPE).ToString()
4916
            Dim sSystemPath As String = GetPipeType(sType)
4917

    
4918
            oLMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, ExistingItem:=oLMConnector.AsLMAItem,
4919
          TargetItem:=oLMSymbol.AsLMAItem)
4920

    
4921
            Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
4922
            If oAttributeRow.Length > 0 Then
4923
                For Each oAttribute In oAttributeRow
4924
                    Try
4925
                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
4926
                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
4927
                        If sPIDValue.Contains("'") Then
4928
                            sPIDValue = sPIDValue.Replace("'", """")
4929
                        End If
4930
                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
4931
                        oLMSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
4932
                    Catch ex As Exception
4933
                    End Try
4934
                Next
4935
            End If
4936
        End If
4937
        Return sReturnUid
4938
    End Function
4939

    
4940

    
4941
    Private Sub OPCTOLineRouting(ByRef oLine_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal oOPCSymbol As LMSymbol,
4942
                            ByVal sOPCUid As String, ByVal sLineNoUid As String)
4943
        Try
4944
            Dim oDatasource As Object = _Placement.PIDDataSource
4945
            Dim objItem As LMAItem
4946
            Dim objConnector As LMConnector
4947
            Dim objInputs As PlaceRunInputs
4948
            objInputs = New PlaceRunInputs
4949
            Dim dOriginalStart_x As Double = 0.0
4950
            Dim dOriginalStart_y As Double = 0.0
4951
            Dim dOriginalEnd_x As Double = 0.0
4952
            Dim dOriginalEnd_y As Double = 0.0
4953
            Dim dStart_x As Double = 0.0
4954
            Dim dStart_y As Double = 0.0
4955
            Dim dEnd_x As Double = 0.0
4956
            Dim dEnd_y As Double = 0.0
4957

    
4958
            Dim oPipeRun As LMPipeRun = Nothing
4959
            Dim sStartpoint As String = ""
4960
            Dim sEndpoint As String = ""
4961
            Dim iConnType As Integer = 0
4962
            Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_Conn1_Uid & " = '" + sOPCUid + "' And [" &
4963
                                                                                       _XML_SYMBOL_Check & "] = 'TRUE'")
4964
            Dim sPipeUid As String = ""
4965
            If oPipeRow.Length = 0 Then
4966
                oPipeRow = oLine_Dt.Select(_XML_LINE_Conn2_Uid & " = '" + sOPCUid + "' And [" &
4967
                        _XML_SYMBOL_Check & "] = 'TRUE'")
4968
            Else
4969
                sPipeUid = oPipeRow(0)(_XML_LINE_UID).ToString()
4970
                iConnType = 1
4971
            End If
4972
            Dim oAddUid_List As New List(Of String)
4973
            If oPipeRow.Length = 1 Then
4974
                If sPipeUid = "" Then
4975
                    sPipeUid = oPipeRow(0)(_XML_LINE_UID).ToString()
4976
                    iConnType = 2
4977
                End If
4978
                oAddUid_List.Add(sPipeUid)
4979
                sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
4980
                sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
4981
                ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
4982
                dStart_x = dOriginalStart_x
4983
                dStart_y = dOriginalStart_y
4984
                ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
4985
                dEnd_x = dOriginalEnd_x
4986
                dEnd_y = dOriginalEnd_y
4987
                ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
4988
                ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
4989

    
4990
                'OPC Connection Point가져와서 연결(2018-07-12)
4991
                If iConnType = 1 Then
4992
                    FindNearPoint(oOPCSymbol, dStart_x, dStart_y)
4993
                    objInputs.AddSymbolTarget(oOPCSymbol, dStart_x, dStart_y)
4994
                    objInputs.AddPoint(dEnd_x, dEnd_y)
4995
                Else
4996
                    FindNearPoint(oOPCSymbol, dEnd_x, dEnd_y)
4997
                    objInputs.AddSymbolTarget(oOPCSymbol, dEnd_x, dEnd_y)
4998
                    objInputs.AddPoint(dStart_x, dStart_y)
4999
                End If
5000
                oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
5001

    
5002
                While True
5003
                    '    objInputs.Clear()
5004
                    Dim oAddPipeRow() As DataRow = oLine_Dt.Select("[" & _XML_LINE_Conn1_Uid & "] = '" + sPipeUid + "' and " &
5005
                                                                 "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And [" &
5006
                                                                                       _XML_SYMBOL_Check & "] = 'TRUE'")
5007
                    If oAddPipeRow.Length = 0 Then
5008
                        oAddPipeRow = oLine_Dt.Select("[" & _XML_LINE_Conn2_Uid & "] = '" + sPipeUid + "' and " &
5009
                                                                 "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And [" &
5010
                                                                                       _XML_SYMBOL_Check & "] = 'TRUE'")
5011
                        sPipeUid = ""
5012
                    Else
5013
                        iConnType = 1
5014
                        sPipeUid = oAddPipeRow(0)(_XML_LINE_UID).ToString()
5015
                    End If
5016
                    If oAddPipeRow.Length = 1 Then
5017
                        If sPipeUid = "" Then
5018
                            sPipeUid = oAddPipeRow(0)(_XML_LINE_UID).ToString()
5019
                            iConnType = 2
5020
                        End If
5021
                        oAddUid_List.Add(sPipeUid)
5022
                        sStartpoint = oAddPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
5023
                        sEndpoint = oAddPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
5024
                        ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
5025
                        dStart_x = dOriginalStart_x
5026
                        dStart_y = dOriginalStart_y
5027
                        ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
5028
                        dEnd_x = dOriginalEnd_x
5029
                        dEnd_y = dOriginalEnd_y
5030
                        ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
5031
                        ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
5032
                        If iConnType = 1 Then
5033
                            objInputs.AddPoint(dEnd_x, dEnd_y)
5034
                            ' objInputs.AddPoint(dStart_x, dStart_y)
5035
                        Else
5036
                            'objInputs.AddConnectorTarget(objConnector, dStart_x, dStart_y)
5037
                            '  objInputs.AddPoint(dStart_x, dStart_y)
5038
                            '  objInputs.AddPoint(dEnd_x, dEnd_y)
5039
                            objInputs.AddPoint(dStart_x, dStart_y)
5040
                        End If
5041

    
5042
                        oAddPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
5043
                    Else
5044
                        Exit While
5045
                    End If
5046

    
5047
                End While
5048
                Dim sType As String = oPipeRow(0)(_XML_LINE_TYPE).ToString()
5049
                Dim sSystemPath As String = GetPipeType(sType)
5050

    
5051
                objItem = _Placement.PIDCreateItem(sSystemPath)
5052
                objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
5053
                For i = 0 To oAddUid_List.Count - 1
5054
                    Dim oUpdateRow As DataRow() = oLine_Dt.Select(_XML_LINE_UID & " = '" + oAddUid_List(i) + "'")
5055
                    If oUpdateRow.Length = 1 Then
5056
                        oUpdateRow(0)(_XML_LINE_SPID) = objConnector.ModelItemID
5057
                        oUpdateRow(0)(_XML_LINE_LMCONNECTOR) = objConnector
5058
                    End If
5059
                Next
5060

    
5061

    
5062
                oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
5063
                Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
5064
                If oAttributeRow.Length > 0 Then
5065
                    For Each oAttribute In oAttributeRow
5066
                        Try
5067
                            Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
5068
                            Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
5069
                            If sPIDValue.Contains("'") Then
5070
                                sPIDValue = sPIDValue.Replace("'", """")
5071
                            End If
5072
                            Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
5073
                            oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
5074
                        Catch ex As Exception
5075
                        End Try
5076
                    Next
5077
                    oPipeRun.Commit()
5078
                End If
5079

    
5080
            End If
5081

    
5082
        Catch ex As Exception
5083
        End Try
5084
    End Sub
5085

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

    
5088
        For Each sUid In sUidList
5089
            If sUid = sAddUid Then
5090
                Return False
5091
            End If
5092
        Next
5093
        Return True
5094
    End Function
5095

    
5096
    Private Sub LineRouting(ByRef oLine_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal sLineNoUid As String, ByVal sLineNoText As String)
5097
        Try
5098
            Dim oDatasource As Object = _Placement.PIDDataSource
5099
            Dim objItem As LMAItem
5100
            Dim objConnector As LMConnector
5101
            Dim objInputs As PlaceRunInputs
5102
            objInputs = New PlaceRunInputs
5103
            Dim dOriginalStart_x As Double = 0.0
5104
            Dim dOriginalStart_y As Double = 0.0
5105
            Dim dOriginalEnd_x As Double = 0.0
5106
            Dim dOriginalEnd_y As Double = 0.0
5107
            Dim dStart_x As Double = 0.0
5108
            Dim dStart_y As Double = 0.0
5109
            Dim dEnd_x As Double = 0.0
5110
            Dim dEnd_y As Double = 0.0
5111
            Dim oPipeRun As LMPipeRun = Nothing
5112
            Dim sStartpoint As String = ""
5113
            Dim sEndpoint As String = ""
5114
            Dim iConnType As Integer = 0
5115
            Dim pLMConnector As LMConnector = Nothing
5116
            For Each oLinerow In oLine_Dt.Rows
5117
                objInputs.Clear()
5118
                Dim sCheck As String = oLinerow(_XML_LINE_DRAWING_TF).ToString()
5119
                If sCheck = "FALSE" Then
5120
                    Dim sUid As String = oLinerow(_XML_LINE_UID).ToString()
5121
                    sStartpoint = oLinerow(_XML_LINE_STARTPOINT).ToString()
5122
                    sEndpoint = oLinerow(_XML_LINE_ENDPOINT).ToString()
5123
                    ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
5124
                    dStart_x = dOriginalStart_x
5125
                    dStart_y = dOriginalStart_y
5126
                    ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
5127
                    dEnd_x = dOriginalEnd_x
5128
                    dEnd_y = dOriginalEnd_y
5129
                    ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
5130
                    ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
5131

    
5132
                    objInputs.AddPoint(dStart_x, dStart_y)
5133
                    objInputs.AddPoint(dEnd_x, dEnd_y)
5134
                    Dim sType As String = oLinerow(_XML_LINE_TYPE).ToString()
5135
                    Dim sSystemPath As String = GetPipeType(sType)
5136
                    objItem = _Placement.PIDCreateItem(sSystemPath)
5137
                    objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
5138
                    SetListBoxItems(ListBox_Result, "Place Pipe.." & sUid & " (" & dOriginalStart_x & "," & dOriginalStart_y & ") - (" & dOriginalEnd_x & "," & dOriginalEnd_y & ")..." & _iPipecnt & " count ")
5139

    
5140
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Pipe : " & sUid)
5141
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "LineNo : " & sLineNoText)
5142
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection1 : " & oLinerow(_XML_SYMBOL_Conn1_Uid).ToString())
5143
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection2 : " & oLinerow(_XML_SYMBOL_Conn2_Uid).ToString())
5144
                    'ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
5145
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "StartPoint : " & dOriginalStart_x & "," & dOriginalStart_y)
5146
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "EndPoint : " & dOriginalEnd_x & "," & dOriginalEnd_y)
5147
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Pipe Count : " & _iPipecnt)
5148

    
5149
                    _iPipecnt = _iPipecnt + 1
5150
                    oLinerow(_XML_LINE_SPID) = objConnector.ModelItemID
5151
                    oLinerow(_XML_LINE_LMCONNECTOR) = objConnector
5152

    
5153
                    oLinerow(_XML_LINE_DRAWING_TF) = "TRUE"
5154
                    oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
5155

    
5156
                    Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
5157
                    If oAttributeRow.Length > 0 Then
5158
                        For Each oAttribute In oAttributeRow
5159
                            Try
5160
                                Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
5161
                                Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
5162
                                If sPIDValue.Contains("'") Then
5163
                                    sPIDValue = sPIDValue.Replace("'", """")
5164
                                End If
5165
                                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
5166
                                oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
5167
                            Catch ex As Exception
5168
                            End Try
5169
                        Next
5170
                        oPipeRun.Commit()
5171
                    End If
5172
                End If
5173

    
5174

    
5175

    
5176

    
5177

    
5178
                'Dim sPipeUid As String = oLinerow(_XML_LINE_UID).ToString()
5179
                'Dim sCheckModeling As Boolean = False
5180
                'objInputs.Clear()
5181
                'Dim oAddUid_List As New List(Of String)
5182
                'Try
5183
                '    Dim oAddPipeRow() As DataRow = oLine_Dt.Select("[" & _XML_LINE_Conn1_Uid & "] = '" + sPipeUid + "' and " &
5184
                '                                            "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And [" &
5185
                '                                            _XML_SYMBOL_Check & "] = 'TRUE'")
5186
                '    If oAddPipeRow.Length = 0 Then
5187
                '        oAddPipeRow = oLine_Dt.Select("[" & _XML_LINE_Conn2_Uid & "] = '" + sPipeUid + "' and " &
5188
                '                                        "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And [" &
5189
                '                                        _XML_SYMBOL_Check & "] = 'TRUE'")
5190
                '        sPipeUid = ""
5191
                '    Else
5192
                '        iConnType = 1
5193
                '        sPipeUid = oAddPipeRow(0)(_XML_LINE_UID).ToString()
5194
                '    End If
5195
                '    If oAddPipeRow.Length = 1 Then
5196
                '        sCheckModeling = True
5197
                '        If sPipeUid = "" Then
5198
                '            sPipeUid = oAddPipeRow(0)(_XML_LINE_UID).ToString()
5199
                '            iConnType = 2
5200
                '        End If
5201
                '        If AddUidList중복체크(oAddUid_List, sPipeUid) Then
5202
                '            oAddUid_List.Add(sPipeUid)
5203
                '        End If
5204
                '        sStartpoint = oAddPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
5205
                '        sEndpoint = oAddPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
5206
                '        ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
5207
                '        dStart_x = dOriginalStart_x
5208
                '        dStart_y = dOriginalStart_y
5209
                '        ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
5210
                '        dEnd_x = dOriginalEnd_x
5211
                '        dEnd_y = dOriginalEnd_y
5212
                '        ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
5213
                '        ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
5214
                '        Dim sBranchType As String = ""
5215
                '        If (CheckBranchLine(oLine_Dt, dStart_x, dStart_y, dEnd_x, dEnd_y, sBranchType, pLMConnector)) Then
5216
                '            Try
5217
                '                If pLMConnector Is Nothing Then
5218
                '                    objInputs.AddPoint(dStart_x, dStart_y)
5219
                '                    objInputs.AddPoint(dEnd_x, dEnd_y)
5220
                '                Else
5221
                '                    If sBranchType = "1" Then
5222
                '                        objInputs.AddConnectorTarget(pLMConnector, dStart_x, dStart_y)
5223
                '                        objInputs.AddPoint(dEnd_x, dEnd_y)
5224
                '                    ElseIf sBranchType = "2" Then
5225
                '                        objInputs.AddConnectorTarget(pLMConnector, dEnd_x, dEnd_y)
5226
                '                        objInputs.AddPoint(dStart_x, dStart_y)
5227
                '                    ElseIf sBranchType = "3" Then
5228
                '                        objInputs.AddConnectorTarget(pLMConnector, dStart_x, dStart_y)
5229
                '                        objInputs.AddPoint(dEnd_x, dEnd_y)
5230
                '                    ElseIf sBranchType = "4" Then
5231
                '                        objInputs.AddConnectorTarget(pLMConnector, dEnd_x, dEnd_y)
5232
                '                        objInputs.AddPoint(dStart_x, dStart_y)
5233
                '                    End If
5234
                '                End If
5235
                '            Catch ex As Exception
5236
                '            End Try
5237
                '        Else
5238
                '            objInputs.AddPoint(dStart_x, dStart_y)
5239
                '            objInputs.AddPoint(dEnd_x, dEnd_y)
5240
                '        End If
5241
                '        oAddPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
5242
                '    Else
5243
                '        Dim CheckTF As String = oLinerow(_XML_LINE_DRAWING_TF).ToString()
5244
                '        Dim CheckSelect As String = oLinerow(_XML_LINE_Check).ToString()
5245
                '        If CheckTF = "FALSE" And CheckSelect = "TRUE" Then
5246
                '            sPipeUid = oLinerow(_XML_LINE_UID).ToString()
5247
                '            oAddUid_List.Clear()
5248
                '            oAddUid_List.Add(sPipeUid)
5249
                '            sCheckModeling = True
5250
                '            sStartpoint = oLinerow(_XML_LINE_STARTPOINT).ToString()
5251
                '            sEndpoint = oLinerow(_XML_LINE_ENDPOINT).ToString()
5252
                '            ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
5253
                '            dStart_x = dOriginalStart_x
5254
                '            dStart_y = dOriginalStart_y
5255
                '            ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
5256
                '            dEnd_x = dOriginalEnd_x
5257
                '            dEnd_y = dOriginalEnd_y
5258
                '            ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
5259
                '            ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
5260
                '            Dim sBranchType As String = ""
5261
                '            If (CheckBranchLine(oLine_Dt, dStart_x, dStart_y, dEnd_x, dEnd_y, sBranchType, pLMConnector)) Then
5262
                '                Try
5263
                '                    If sBranchType = "1" Then
5264
                '                        objInputs.AddPoint(dEnd_x, dEnd_y)
5265
                '                        objInputs.AddConnectorTarget(pLMConnector, dStart_x, dStart_y)
5266
                '                    ElseIf sBranchType = "2" Then
5267
                '                        objInputs.AddPoint(dStart_x, dStart_y)
5268
                '                        objInputs.AddConnectorTarget(pLMConnector, dEnd_x, dEnd_y)
5269
                '                    ElseIf sBranchType = "3" Then
5270
                '                        objInputs.AddPoint(dEnd_x, dEnd_y)
5271
                '                        objInputs.AddConnectorTarget(pLMConnector, dStart_x, dStart_y)
5272
                '                    ElseIf sBranchType = "4" Then
5273
                '                        objInputs.AddPoint(dStart_x, dStart_y)
5274
                '                        objInputs.AddConnectorTarget(pLMConnector, dEnd_x, dEnd_y)
5275
                '                    End If
5276
                '                Catch ex As Exception
5277

    
5278
                '                End Try
5279
                '            Else
5280
                '                objInputs.AddPoint(dStart_x, dStart_y)
5281
                '                objInputs.AddPoint(dEnd_x, dEnd_y)
5282
                '            End If
5283
                '            oLinerow(_XML_LINE_DRAWING_TF) = "TRUE"
5284
                '        End If
5285
                '    End If
5286
                'Catch ex As Exception
5287
                'End Try
5288
                'If sCheckModeling Then
5289
                '    Dim sType As String = oLinerow(_XML_LINE_TYPE).ToString()
5290
                '    Dim sSystemPath As String = GetPipeType(sType)
5291
                '    objItem = _Placement.PIDCreateItem(sSystemPath)
5292
                '    objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
5293
                '    For i = 0 To oAddUid_List.Count - 1
5294
                '        Dim oUpdateRow As DataRow() = oLine_Dt.Select(_XML_LINE_UID & " = '" + oAddUid_List(i) + "'")
5295
                '        If oUpdateRow.Length = 1 Then
5296
                '            oUpdateRow(0)(_XML_LINE_SPID) = objConnector.ModelItemID
5297
                '            oUpdateRow(0)(_XML_LINE_LMCONNECTOR) = objConnector
5298
                '        End If
5299
                '    Next
5300

    
5301
                '    oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
5302
                '    oAddUid_List.Clear()
5303

    
5304
                '    Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
5305
                '    If oAttributeRow.Length > 0 Then
5306
                '        For Each oAttribute In oAttributeRow
5307
                '            Try
5308
                '                Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
5309
                '                Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
5310
                '                If sPIDValue.Contains("'") Then
5311
                '                    sPIDValue = sPIDValue.Replace("'", """")
5312
                '                End If
5313
                '                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
5314
                '                oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
5315
                '            Catch ex As Exception
5316
                '            End Try
5317
                '        Next
5318
                '        oPipeRun.Commit()
5319
                '    End If
5320

    
5321
                '    If pLMConnector IsNot Nothing Then
5322
                '        Dim sID_1 As String = pLMConnector.ModelItemID
5323
                '        Dim sID_2 As String = objConnector.ModelItemID
5324
                '        Dim objSurvivorItem As LMAItem = Nothing
5325
                '        Dim oPipeRun1 As LMPipeRun = oDatasource.GetPipeRun(sID_1)
5326
                '        Dim oPipeRun2 As LMPipeRun = oDatasource.GetPipeRun(sID_2)
5327
                '        _Placement.PIDJoinRuns(oPipeRun1, oPipeRun2)
5328
                '        '     oDatasource.CommitTransaction()
5329
                '        '_Placement.PIDAutoJoin(oPipeRun1.AsLMAItem, AutoJoinEndConstants.autoJoin_End, objSurvivorItem)
5330
                '        'oPipeRun1.Commit()
5331
                '        'oDatasource.CommitTransaction()
5332
                '        'objSurvivorItem = Nothing
5333
                '        '_Placement.PIDAutoJoin(oPipeRun2.AsLMAItem, AutoJoinEndConstants.autoJoin_Start, objSurvivorItem)
5334
                '        'oPipeRun2.Commit()
5335
                '        'oDatasource.CommitTransaction()
5336
                '    End If
5337
                '    sCheckModeling = False
5338
                '  End If
5339
            Next
5340
        Catch ex As Exception
5341
        End Try
5342
    End Sub
5343

    
5344

    
5345
    Private Sub SymbolModeling(ByVal CDrawing As Drawing, ByVal oLine_DT As DataTable, ByVal oSymbolRow As DataRow, ByVal oAttribute_Dt As DataTable,
5346
                               ByVal sLineNoText As String)
5347
        Try
5348

    
5349
            Dim sCheckModeling As String = oSymbolRow(_XML_SYMBOL_DRAWING_TF).ToString()
5350
            If sCheckModeling = "FALSE" Then
5351
                Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID)
5352
                Dim oSymbol As LMSymbol = Nothing
5353
                Dim sSPID As String = oSymbolRow(_XML_SYMBOL_SPID).ToString()
5354
                Dim sSystemPath As String = oSymbolRow(_XML_SYMBOL_SYSTEMPATH).ToString()
5355
                Dim oDatasource As Object = _Placement.PIDDataSource
5356
                Dim sSymbolCompType As String = oSymbolRow(_XML_SYMBOL_TYPE).ToString()
5357
                Dim dLocationX As Double = 0.0
5358
                Dim dLocationY As Double = 0.0
5359
                Dim dX As Double = 0.0
5360
                Dim dY As Double = 0.0
5361
                Dim sOriginalPoint As String = oSymbolRow(_XML_SYMBOL_ORIGINALPOINT).ToString()
5362
                ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY)
5363
                dX = dLocationX
5364
                dY = dLocationY
5365
                ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
5366

    
5367
                Dim dAngle As Double = oSymbolRow(_XML_SYMBOL_ANGLE)
5368

    
5369

    
5370
                'Dim oDatarow() As DataRow = oLine_DT.Select("[" & _XML_LINE_Conn1_Uid & "] = '" & sSymbolUid & "'")
5371
                'If oDatarow.Length = 0 Then
5372
                '    oDatarow = oLine_DT.Select("[" & _XML_LINE_Conn2_Uid & "] = '" & sSymbolUid & "'")
5373
                'End If
5374
                'Dim dFix_X As Double = 0.0
5375
                'Dim dFix_Y As Double = 0.0
5376
                'If oDatarow.Length > 0 Then
5377
                '    If dAngle <> 0 Then
5378
                '        sOriginalPoint = oDatarow(0)(_XML_LINE_STARTPOINT).ToString()
5379
                '        ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY)
5380

    
5381
                '        ConvertPointByImage(dLocationX, dLocationY, _IMG_X, _IMG_Y)
5382
                '        dX = dLocationX
5383
                '    Else
5384
                '        sOriginalPoint = oDatarow(0)(_XML_LINE_STARTPOINT).ToString()
5385
                '        ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY)
5386
                '        ConvertPointByImage(dLocationX, dLocationY, _IMG_X, _IMG_Y)
5387
                '        dY = dLocationY
5388
                '    End If
5389

    
5390
                'End If
5391

    
5392

    
5393

    
5394
                oSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY,, dAngle)
5395
                SetListBoxItems(ListBox_Result, "Place Fitting.." & sSymbolUid & " (" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
5396

    
5397
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Fitting : " & sSymbolUid)
5398
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "LineNo : " & sLineNoText)
5399
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection1 : " & oSymbolRow(_XML_SYMBOL_Conn1_Uid).ToString())
5400
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection2 : " & oSymbolRow(_XML_SYMBOL_Conn2_Uid).ToString())
5401
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection3 : " & oSymbolRow(_XML_SYMBOL_Conn3_Uid).ToString())
5402
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection4 : " & oSymbolRow(_XML_SYMBOL_Conn4_Uid).ToString())
5403
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
5404
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "OriginalPoint : " & dLocationX & "," & dLocationY)
5405
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Fitting Count : " & _iFittingcnt)
5406

    
5407

    
5408
                _iFittingcnt = _iFittingcnt + 1
5409
                oSymbolRow(_XML_SYMBOL_DRAWING_TF) = "TRUE"
5410
                Dim oAttributeRow() As DataRow
5411
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sSymbolUid + "'")
5412
                If oAttribute_Dt.Rows.Count > 0 Then
5413

    
5414
                    If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
5415
                        Dim oInstrument As LMInstrument
5416
                        oInstrument = oDatasource.GetInstrument(oSymbol.ModelItemID)
5417
                        Try
5418
                            If oAttributeRow.Length > 0 Then
5419
                                For Each oAttribute In oAttributeRow
5420
                                    Try
5421
                                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
5422
                                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
5423
                                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
5424
                                        oInstrument.Attributes(sSPPIDAttribute).Value = sPIDValue
5425
                                    Catch ex As Exception
5426
                                    End Try
5427
                                Next
5428
                                oInstrument.Commit()
5429
                            End If
5430
                        Catch ex As Exception
5431
                        End Try
5432
                    Else
5433
                        Try
5434
                            If oAttributeRow.Length > 0 And oSymbol IsNot Nothing Then
5435
                                For Each oAttribute In oAttributeRow
5436
                                    Try
5437
                                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
5438
                                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
5439

    
5440
                                        If sPIDAttribute = "SIZE" Then
5441

    
5442
                                            'Nominal diamter1,2속성이름뭔지 찾아봐야됨 (2018-07-20)
5443
                                            If sPIDValue.Contains("x") Then
5444
                                                Dim sSplitSize() As String = sPIDValue.Split("x")
5445
                                                If sSplitSize.Count > 1 Then
5446
                                                    'Connection Point와 연결되어 있는 라인을 가져와서 라인프로퍼티를 변경
5447
                                                    Dim oConnector_1 As LMConnector = Nothing
5448
                                                    Dim oConnector_2 As LMConnector = Nothing
5449
                                                    If oSymbol IsNot Nothing Then
5450
                                                        If oSymbol.Connect1Connectors.Count >= 1 Then
5451
                                                            For Each Tconnector In oSymbol.Connect1Connectors
5452
                                                                If Tconnector.ItemStatus = "Active" Then
5453
                                                                    If Tconnector.ModelItemObject.ItemTypeName = "PipeRun" Then
5454
                                                                        oConnector_1 = Tconnector
5455
                                                                    End If
5456
                                                                End If
5457
                                                            Next
5458
                                                        End If
5459
                                                        If oSymbol.Connect1Connectors.Count >= 1 Then
5460
                                                            For Each Tconnector In oSymbol.Connect1Connectors
5461
                                                                If Tconnector.ItemStatus = "Active" Then
5462
                                                                    If Tconnector.ModelItemObject.ItemTypeName = "PipeRun" Then
5463
                                                                        oConnector_2 = Tconnector
5464
                                                                    End If
5465
                                                                End If
5466
                                                            Next
5467
                                                        End If
5468
                                                    End If
5469
                                                    Dim oPipeRun1 As LMPipeRun = oDatasource.GetPipeRun(oConnector_1.ModelItemID)
5470
                                                    Dim oPipeRun2 As LMPipeRun = oDatasource.GetPipeRun(oConnector_2.ModelItemID)
5471
                                                    If dAngle = 3.14 Then
5472
                                                        oPipeRun1.Attributes("NominalDiameter").Value = sSplitSize(1)
5473
                                                        oPipeRun2.Attributes("NominalDiameter").Value = sSplitSize(0)
5474
                                                    Else
5475
                                                        oPipeRun1.Attributes("NominalDiameter").Value = sSplitSize(0)
5476
                                                        oPipeRun2.Attributes("NominalDiameter").Value = sSplitSize(1)
5477
                                                    End If
5478

    
5479

    
5480
                                                End If
5481

    
5482
                                            Else
5483
                                                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
5484
                                                oSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
5485
                                            End If
5486
                                        Else
5487
                                            Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
5488
                                            oSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
5489
                                        End If
5490

    
5491
                                    Catch ex As Exception
5492
                                    End Try
5493
                                Next
5494
                                oSymbol.Commit()
5495
                            End If
5496
                        Catch ex As Exception
5497
                        End Try
5498
                    End If
5499
                End If
5500

    
5501

    
5502

    
5503
            End If
5504

    
5505

    
5506

    
5507
            'Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID).ToString()
5508
            'Dim sConnTypeNo As String = ""
5509
            '' Line과 연결되어있는 Symbol인지 확인
5510
            'Dim oLine_Dt As DataTable = GetPipeFromConnection(CDrawing, sSymbolUid, sConnTypeNo)
5511
            ''Symbol과 연결되어 있는 Symbol인지 확인
5512
            'Dim oSymbol_Dt As DataTable = GetSymbolFromConnection(CDrawing, sSymbolUid, sConnTypeNo)
5513
            'Dim oSymbol As LMSymbol = Nothing
5514
            'Dim sSPID As String = oSymbolRow(_XML_SYMBOL_SPID).ToString()
5515
            'Dim sSystemPath As String = oSymbolRow(_XML_SYMBOL_SYSTEMPATH).ToString()
5516
            'Dim oDatasource As Object = _Placement.PIDDataSource
5517
            'Dim sSymbolCompType As String = oSymbolRow(_XML_SYMBOL_TYPE).ToString()
5518

    
5519
            'Dim dAngle As Double = 0.0
5520
            'If IsNumeric(oSymbolRow(_XML_SYMBOL_ANGLE).ToString()) Then
5521
            '    dAngle = Double.Parse(oSymbolRow(_XML_SYMBOL_ANGLE).ToString())
5522
            'End If
5523

    
5524
            'Dim dLocationX As Double = 0.0
5525
            'Dim dLocationY As Double = 0.0
5526
            'Dim dX As Double = 0.0
5527
            'Dim dY As Double = 0.0
5528
            'Dim sOriginalPoint As String = oSymbolRow(_XML_SYMBOL_ORIGINALPOINT).ToString()
5529
            'ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY)
5530
            'dX = dLocationX
5531
            'dY = dLocationY
5532
            'ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
5533
            'Dim bCheckModeling As Boolean = False
5534

    
5535
            'If oLine_Dt.Rows.Count > 0 Then
5536

    
5537
            '    If sSPID <> "" Then
5538
            '        Dim dX1 As Double = 0
5539
            '        Dim dX2 As Double = 0
5540
            '        Dim dY1 As Double = 0
5541
            '        Dim dY2 As Double = 0
5542
            '        Dim oLMSymbol As LMSymbol = oDatasource.GetSymbol(sSPID)
5543
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 1, dX1, dY1)
5544
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 2, dX2, dY2)
5545

    
5546
            '        Dim dCalcPoint As Double = -1
5547
            '        Dim dModeling_X As Double = 0
5548
            '        Dim dModeling_Y As Double = 0
5549
            '        If dX1 <> 0 And dY1 <> 0 Then
5550
            '            dCalcPoint = Math.Abs(dX1 - dX) + Math.Abs(dY1 - dY)
5551
            '            dModeling_X = dX1
5552
            '            dModeling_Y = dY1
5553
            '        End If
5554
            '        If dX2 <> 0 And dY2 <> 0 Then
5555

    
5556
            '            If (Math.Abs(dX2 - dX) + Math.Abs(dY2 - dY) > dCalcPoint) Then
5557
            '                dCalcPoint = Math.Abs(dX2 - dX) + Math.Abs(dY2 - dY)
5558
            '                dModeling_X = dX2
5559
            '                dModeling_Y = dY2
5560
            '            End If
5561
            '        End If
5562

    
5563

    
5564

    
5565
            '        If dModeling_X <> 0 And dModeling_Y <> 0 Then
5566
            '            oSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dModeling_X, dModeling_Y,, dAngle, ExistingItem:=oLMSymbol.AsLMAItem,
5567
            '                TargetItem:=oLMSymbol.AsLMRepresentation)
5568
            '            bCheckModeling = True
5569
            '        End If
5570

    
5571

    
5572
            '    End If
5573
            'End If
5574
            'If oSymbol_Dt.Rows.Count > 0 Then
5575
            '    If sSPID <> "" Then
5576
            '        Dim dX1 As Double = 0
5577
            '        Dim dX2 As Double = 0
5578
            '        Dim dX3 As Double = 0
5579
            '        Dim dX4 As Double = 0
5580
            '        Dim dY1 As Double = 0
5581
            '        Dim dY2 As Double = 0
5582
            '        Dim dY3 As Double = 0
5583
            '        Dim dY4 As Double = 0
5584
            '        Dim oLMSymbol As LMSymbol = oDatasource.GetSymbol(sSPID)
5585
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 1, dX1, dY1)
5586
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 2, dX2, dY2)
5587
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 3, dX3, dY3)
5588
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 4, dX4, dY4)
5589

    
5590
            '        Dim dCalcPoint As Double = -1
5591
            '        Dim dModeling_X As Double = 0
5592
            '        Dim dModeling_Y As Double = 0
5593
            '        If dX1 <> 0 And dY1 <> 0 Then
5594
            '            dCalcPoint = Math.Abs(dX1 - dX) + Math.Abs(dY1 - dY)
5595
            '            dModeling_X = dX1
5596
            '            dModeling_Y = dY1
5597
            '        End If
5598
            '        If dX2 <> 0 And dY2 <> 0 Then
5599

    
5600
            '            If (Math.Abs(dX2 - dX) + Math.Abs(dY2 - dY) > dCalcPoint) Then
5601
            '                dCalcPoint = Math.Abs(dX2 - dX) + Math.Abs(dY2 - dY)
5602
            '                dModeling_X = dX2
5603
            '                dModeling_Y = dY2
5604
            '            End If
5605
            '        End If
5606
            '        If dX3 <> 0 And dY3 <> 0 Then
5607
            '            If (Math.Abs(dX3 - dX) + Math.Abs(dY3 - dY) > dCalcPoint) Then
5608
            '                dCalcPoint = Math.Abs(dX3 - dX) + Math.Abs(dY3 - dY)
5609
            '                dModeling_X = dX3
5610
            '                dModeling_Y = dY3
5611
            '            End If
5612
            '        End If
5613
            '        If dX4 <> 0 And dY4 <> 0 Then
5614
            '            If (Math.Abs(dX4 - dX) + Math.Abs(dY4 - dY) > dCalcPoint) Then
5615
            '                dCalcPoint = Math.Abs(dX4 - dX) + Math.Abs(dY4 - dY)
5616
            '                dModeling_X = dX4
5617
            '                dModeling_Y = dY4
5618
            '            End If
5619
            '        End If
5620
            '        If dModeling_X <> 0 And dModeling_Y <> 0 Then
5621
            '            oSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dModeling_X, dModeling_Y,, dAngle, ExistingItem:=oLMSymbol.AsLMAItem,
5622
            '                TargetItem:=oLMSymbol.AsLMRepresentation)
5623
            '            bCheckModeling = True
5624
            '        End If
5625

    
5626

    
5627
            '    End If
5628

    
5629
            'End If
5630

    
5631
            'If (oLine_Dt.Rows.Count = 0 And oSymbol_Dt.Rows.Count = 0) Or bCheckModeling = False Then
5632
            '    oSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
5633
            '    SetListBoxItems(ListBox_Result, "Place Fittings..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
5634
            '    _iFittingcnt = _iFittingcnt + 1
5635
            'End If
5636
            'Dim oAttributeRow() As DataRow
5637
            'oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sSymbolUid + "'")
5638
            'If oAttribute_Dt.Rows.Count > 0 Then
5639

    
5640
            '    If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
5641
            '        Dim oInstrument As LMInstrument
5642
            '        oInstrument = oDatasource.GetInstrument(oSymbol.ModelItemID)
5643
            '        Try
5644
            '            If oAttributeRow.Length > 0 Then
5645
            '                For Each oAttribute In oAttributeRow
5646
            '                    Try
5647
            '                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
5648
            '                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
5649
            '                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
5650
            '                        oInstrument.Attributes(sSPPIDAttribute).Value = sPIDValue
5651
            '                    Catch ex As Exception
5652
            '                    End Try
5653
            '                Next
5654
            '                oInstrument.Commit()
5655
            '            End If
5656
            '        Catch ex As Exception
5657
            '        End Try
5658
            '    Else
5659
            '        Try
5660
            '            If oAttributeRow.Length > 0 And oSymbol IsNot Nothing Then
5661
            '                For Each oAttribute In oAttributeRow
5662
            '                    Try
5663
            '                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
5664
            '                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
5665

    
5666
            '                        If sPIDAttribute = "SIZE" Then
5667

    
5668
            '                            'Nominal diamter1,2속성이름뭔지 찾아봐야됨 (2018-07-20)
5669
            '                            If sPIDValue.Contains("x") Then
5670
            '                                Dim sSplitSize() As String = sPIDValue.Split("x")
5671
            '                                If sSplitSize.Count > 1 Then
5672
            '                                    'Connection Point와 연결되어 있는 라인을 가져와서 라인프로퍼티를 변경
5673
            '                                    Dim oConnector_1 As LMConnector = Nothing
5674
            '                                    Dim oConnector_2 As LMConnector = Nothing
5675
            '                                    If oSymbol IsNot Nothing Then
5676
            '                                        If oSymbol.Connect1Connectors.Count >= 1 Then
5677
            '                                            For Each Tconnector In oSymbol.Connect1Connectors
5678
            '                                                If Tconnector.ItemStatus = "Active" Then
5679
            '                                                    If Tconnector.ModelItemObject.ItemTypeName = "PipeRun" Then
5680
            '                                                        oConnector_1 = Tconnector
5681
            '                                                    End If
5682
            '                                                End If
5683
            '                                            Next
5684
            '                                        End If
5685
            '                                        If oSymbol.Connect1Connectors.Count >= 1 Then
5686
            '                                            For Each Tconnector In oSymbol.Connect1Connectors
5687
            '                                                If Tconnector.ItemStatus = "Active" Then
5688
            '                                                    If Tconnector.ModelItemObject.ItemTypeName = "PipeRun" Then
5689
            '                                                        oConnector_2 = Tconnector
5690
            '                                                    End If
5691
            '                                                End If
5692
            '                                            Next
5693
            '                                        End If
5694
            '                                    End If
5695
            '                                    Dim oPipeRun1 As LMPipeRun = oDatasource.GetPipeRun(oConnector_1.ModelItemID)
5696
            '                                    Dim oPipeRun2 As LMPipeRun = oDatasource.GetPipeRun(oConnector_2.ModelItemID)
5697
            '                                    If dAngle = 3.14 Then
5698
            '                                        oPipeRun1.Attributes("NominalDiameter").Value = sSplitSize(1)
5699
            '                                        oPipeRun2.Attributes("NominalDiameter").Value = sSplitSize(0)
5700
            '                                    Else
5701
            '                                        oPipeRun1.Attributes("NominalDiameter").Value = sSplitSize(0)
5702
            '                                        oPipeRun2.Attributes("NominalDiameter").Value = sSplitSize(1)
5703
            '                                    End If
5704

    
5705

    
5706
            '                                End If
5707

    
5708
            '                            Else
5709
            '                                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
5710
            '                                oSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
5711
            '                            End If
5712
            '                        Else
5713
            '                            Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
5714
            '                            oSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
5715
            '                        End If
5716

    
5717
            '                    Catch ex As Exception
5718
            '                    End Try
5719
            '                Next
5720
            '                oSymbol.Commit()
5721
            '            End If
5722
            '        Catch ex As Exception
5723
            '        End Try
5724
            '    End If
5725
            'End If
5726
        Catch ex As Exception
5727
        End Try
5728
    End Sub
5729

    
5730

    
5731

    
5732
    Private Function AutoModeling() As Boolean
5733
        Try
5734
            '_AllLine_DT = Line_Dt()
5735
            '_AllSymbol_DT = Symbol_Dt()
5736
            _ModelingLine_Dt = Line_Dt()
5737
            _ModelingSymbol_Dt = Symbol_Dt()
5738
            _CompleteConvert = False
5739
            Label_Progress.Text = "0%"
5740
            SetListBoxItems(ListBox_Result, " Auto converting 시작....")
5741
            ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, " Auto converting 시작....")
5742
            Dim oDwg_Dt As DataTable = LoadAllDrawing()
5743
            _Log_File = "AutoConverting_" + DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.ToString("HHmmss")
5744
            _allItem = GetAllCheckNodeCount()
5745
            _Itemcnt = 0
5746
            '1.Equipment
5747
            '2.Piping OPC
5748
            '3.OPC 시작되는 Line
5749

    
5750
            InitAutoRouting()
5751
            EquipmentModeling(oDwg_Dt)
5752
            PipingModeling()
5753

    
5754
            '   PipeLine_Fitting_Modeling()
5755

    
5756
            SetProgressbar(ProgressBar_Status, 100)
5757
            Label_Progress.Text = "100%"
5758
            SetListBoxItems(ListBox_Result, " Auto converting 완료")
5759
            ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, " Auto converting 완료")
5760
            _CompleteConvert = True
5761
            Return True
5762
        Catch ex As Exception
5763
            Return False
5764
        End Try
5765
    End Function
5766

    
5767

    
5768

    
5769
    Private Sub ThreadConvert()
5770
        If _DrawingsList IsNot Nothing Then
5771
            If _DrawingsList.Count > 0 Then
5772
                'TestBranchLine()
5773
                AutoModeling()
5774
            End If
5775
        End If
5776
    End Sub
5777

    
5778
    Private Sub ThreadOPCRemove()
5779
        While _CompleteConvert = False
5780
            Dim oFindOPC As New FindOpc
5781
            oFindOPC.RemoveOPCDlg()
5782
        End While
5783

    
5784
    End Sub
5785

    
5786

    
5787
    Private Function OpenDrawing(ByVal oDt As DataTable, ByVal sDwgName As String) As String
5788
        Dim oRows As DataRow() = oDt.Select("[Name] = '" & sDwgName & "'")
5789
        Dim oPath As String = ""
5790
        If oRows.Length > 0 Then
5791
            oPath = oRows(0).Item("Path").ToString()
5792
        End If
5793
        Return oPath
5794
    End Function
5795

    
5796
    Private Sub LoadXmlToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LoadXmlToolStripMenuItem.Click
5797

    
5798
        If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
5799
            LoadDB()
5800
            LoadXmlItem(FolderBrowserDialog1.SelectedPath)
5801
        End If
5802
    End Sub
5803
    Private Sub LoadXmlItem(ByVal sFolderPath As String)
5804
        _DrawingsList = New List(Of Drawing)
5805
        Dim sfileEntries As String() = Directory.GetFiles(sFolderPath)
5806
        If Tree_Result.Nodes.Count > 0 Then
5807
            Tree_Result.Nodes(0).Nodes.Clear()
5808
            For Each sfileName In sfileEntries
5809
                Dim sExtension As String = Path.GetExtension(sfileName)
5810
                If sExtension = ".xml" Then
5811
                    Dim sDwgName As String = Path.GetFileNameWithoutExtension(sfileName)
5812
                    Dim sDwgPath As String = sfileName
5813
                    Dim oNode As TreeNode = Tree_Result.Nodes(0).Nodes.Add(sDwgPath, sDwgName, 15)
5814
                    Dim oDwg As Drawing = AddSymbolItem(sDwgPath, oNode)
5815

    
5816
                    _DrawingsList.Add(oDwg)
5817
                End If
5818
            Next
5819
            Tree_Result.Nodes(0).Expand()
5820
        End If
5821
    End Sub
5822

    
5823
    Private Sub GenerateRelation(ByRef oDwg_Ds As Drawing)
5824
        Dim oLineLists As List(Of Line_no) = oDwg_Ds.Line_nos
5825
        Dim oEqpLists As List(Of Eqp_no) = oDwg_Ds.Eqp_nos
5826
        Dim oTrimLineLists As List(Of Line_no) = oDwg_Ds.TrimLine_nos
5827
        Dim oRelation As New GenerateRelation()
5828
        For Each oLinelist In oLineLists
5829
            oRelation.CalcLineConnectionItem_Equal(oLinelist.Dt_Line, oLineLists)
5830
            oRelation.CalcLineConnectionItem_NonEqual(oLinelist.Dt_Line, oLineLists)
5831
            oRelation.CalcSymbolConnectionItem_Equal(oLinelist.Dt_Symbol, oLineLists)
5832
            oRelation.CalcSymbolConnectionItem_NonEqual(oLinelist.Dt_Symbol, oLineLists)
5833
        Next
5834
    End Sub
5835

    
5836
    Private Sub SetSymbol_LineNumberByUID(ByVal symbols As List(Of Symbol), ByVal lineNumber As LineNumber, ByVal uid As String)
5837
        For Each symbol As Symbol In symbols
5838
            If symbol.UID = uid Then
5839
                symbol.LINENUMBER = lineNumber
5840
                Exit For
5841
            End If
5842
        Next
5843
    End Sub
5844

    
5845
    Private Sub SetLine_LineNumberByUID(ByVal lines As List(Of Line), ByVal lineNumber As LineNumber, ByVal uid As String)
5846
        For Each line As Line In lines
5847
            If line.UID = uid Then
5848
                line.LINENUMBER = lineNumber
5849
                Exit For
5850
            End If
5851
        Next
5852
    End Sub
5853

    
5854
    ''' <summary>
5855
    '''  XML Tree 구조 생성 
5856
    ''' </summary>
5857
    ''' <param name="sDwgPath"></param>
5858
    Private Function AddSymbolItem(ByVal sDwgPath As String, ByVal oParentNode As TreeNode) As Drawing
5859
        Dim oDwg_Ds As Drawing = LoadSymbolInXml(sDwgPath)
5860

    
5861
        If oDwg_Ds IsNot Nothing Then
5862

    
5863
            Dim oLineNos As List(Of LineNumber) = oDwg_Ds.LINENUMBERS
5864

    
5865
            Dim oTrimLines As List(Of LineNumber) = oDwg_Ds.TRIMLINES
5866

    
5867
            Dim oSymbols As List(Of Symbol) = oDwg_Ds.SYMBOLS
5868

    
5869
            Dim oLines As List(Of Line) = oDwg_Ds.LINES
5870

    
5871
            '' TreeView 구성 및 하위 아이템 상위 구성
5872
            ' LIne Number
5873
            For Each lineNo As LineNumber In oLineNos
5874
                oParentNode.Nodes.Add(lineNo.UID, lineNo.UID)
5875

    
5876
                For Each uid In lineNo.SYMBOLRUNITEMS
5877
                    SetSymbol_LineNumberByUID(oSymbols, lineNo, uid)
5878
                Next
5879

    
5880
                For Each uid In lineNo.LINERUNITEMS
5881
                    SetLine_LineNumberByUID(oLines, lineNo, uid)
5882
                Next
5883
            Next
5884

    
5885
            ' Trim Line
5886
            For index = 0 To oTrimLines.Count - 1
5887
                Dim trimLine As LineNumber = oTrimLines(index)
5888
                oParentNode.Nodes.Add(trimLine.UID, "TrimLine" + index.ToString)
5889

    
5890
                For Each uid In trimLine.SYMBOLRUNITEMS
5891
                    SetSymbol_LineNumberByUID(oSymbols, trimLine, uid)
5892
                Next
5893

    
5894
                For Each uid In trimLine.LINERUNITEMS
5895
                    SetLine_LineNumberByUID(oLines, trimLine, uid)
5896
                Next
5897
            Next
5898
            ' symbol
5899
            For Each symbol As Symbol In oSymbols
5900
                If symbol.LINENUMBER IsNot Nothing Then
5901
                    Dim nodeIndex As Integer = oParentNode.Nodes.IndexOfKey(symbol.LINENUMBER.UID)
5902
                    oParentNode.Nodes.Item(nodeIndex).Nodes.Add(symbol.UID, symbol.TYPE)
5903
                Else
5904
                    oParentNode.Nodes.Add(symbol.UID, symbol.TYPE)
5905
                End If
5906
            Next
5907
            ' line
5908
            For Each line As Line In oLines
5909
                If line.LINENUMBER IsNot Nothing Then
5910
                    Dim nodeIndex As Integer = oParentNode.Nodes.IndexOfKey(line.LINENUMBER.UID)
5911
                    oParentNode.Nodes.Item(nodeIndex).Nodes.Add(line.UID, line.TYPE)
5912
                Else
5913
                    oParentNode.Nodes.Add(line.UID, line.TYPE)
5914
                End If
5915
            Next
5916

    
5917
        End If
5918

    
5919
        Return oDwg_Ds
5920
    End Function
5921
    Private Sub Tree_Result_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles Tree_Result.AfterCheck
5922
        If e.Node.Checked = True Then
5923
            For Each oNode As TreeNode In e.Node.Nodes
5924
                oNode.Checked = True
5925
            Next
5926
        Else
5927
            For Each oNode As TreeNode In e.Node.Nodes
5928
                oNode.Checked = False
5929
            Next
5930
        End If
5931
    End Sub
5932

    
5933
    Private Sub Btn_Setting_Click(sender As Object, e As EventArgs) Handles Btn_Setting.Click
5934
        Dim oSettings As Settings = New Settings()
5935
        oSettings.ShowDialog()
5936
    End Sub
5937

    
5938

    
5939
    Private Sub TestBranchLine()
5940
        Dim objPlacement As Placement
5941
        objPlacement = New Placement
5942
        Dim PipeRunLocation As String
5943
        Dim objItem As LMAItem
5944
        Dim objConnector As LMConnector
5945
        Dim objInputs As PlaceRunInputs
5946
        Dim objSymbol As LMSymbol
5947
        Dim ValveLocation As String
5948
        PipeRunLocation = "\Piping\Routing\Process Lines\Primary Piping.sym"
5949
        objInputs = New PlaceRunInputs
5950
        objInputs.AddPoint(0.1, 0.1)
5951
        objInputs.AddPoint(0.2, 0.1)
5952
        objItem = objPlacement.PIDCreateItem(PipeRunLocation)
5953
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
5954
        ValveLocation = "\Piping\Valves\2 Way Common\Ball Valve.sym"
5955
        objSymbol = objPlacement.PIDPlaceSymbol(ValveLocation, 0.15, 0.3, , 1.57)
5956
        objInputs = New PlaceRunInputs
5957
        objInputs.AddConnectorTarget(objConnector, 0.15, 0.1)
5958
        '   objInputs.AddConnectorTarget(objConnector, 0.12, 0.1)
5959
        objInputs.AddPoint(0.15, 0.15)
5960
        objInputs.AddPoint(0.12, 0.15)
5961
        objInputs.AddPoint(0.12, 0.2)
5962
        objInputs.AddPoint(0.15, 0.2)
5963
        objInputs.AddSymbolTarget(objSymbol, 0.15, 0.3)
5964
        objItem = objPlacement.PIDCreateItem(PipeRunLocation)
5965
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
5966

    
5967
        objInputs = New PlaceRunInputs
5968
        objInputs.AddConnectorTarget(objConnector, 0.17, 0.1)
5969
        objInputs.AddPoint(0.17, 0.15)
5970
        objItem = objPlacement.PIDCreateItem(PipeRunLocation)
5971
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
5972

    
5973
        objInputs = New PlaceRunInputs
5974
        objInputs.AddConnectorTarget(objConnector, 0.19, 0.1)
5975
        objInputs.AddPoint(0.19, 0.15)
5976
        objItem = objPlacement.PIDCreateItem(PipeRunLocation)
5977
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
5978

    
5979
        objInputs = New PlaceRunInputs
5980
        objInputs.AddConnectorTarget(objConnector, 0.12, 0.1)
5981
        objInputs.AddPoint(0.12, 0.15)
5982
        objItem = objPlacement.PIDCreateItem(PipeRunLocation)
5983
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
5984
    End Sub
5985

    
5986
    Private Sub Btn_TestNozzle_Click(sender As Object, e As EventArgs) Handles Btn_TestNozzle.Click
5987

    
5988
        Dim sVessel_ID As String = "841D5E640AE5421B9A017DDC2E87FF11"
5989
        Dim objVessel As LMVessel
5990
        objVessel = _Placement.PIDDataSource.GetVessel(sVessel_ID)
5991
        Dim oVesselLocation As LMLocations = objVessel.Locations
5992
        Dim symVessel As LMSymbol = _Placement.PIDDataSource.GetSymbol(objVessel.Representations.Nth(1).Id)
5993
        Dim XCoordinate As String = symVessel.Attributes("XCoordinate").Value
5994
        Dim YCoordinate As String = symVessel.Attributes("YCoordinate").Value
5995
        symVessel.Attributes("XCoordinate").Value = XCoordinate + 0.01
5996
        symVessel.Attributes("YCoordinate").Value = YCoordinate + 0.01
5997
        symVessel.Commit()
5998
        Dim sValve_ID As String = "DB7B0CA8A2664A6BA7A9615764BA62B0"
5999
        Dim objValve As LMSymbol
6000
        Dim objValves As LMPipingComp = _Placement.PIDDataSource.GetPipingComp(sValve_ID)
6001
        objValve = _Placement.PIDDataSource.GetSymbol(objValves.Representations.Nth(1).Id)
6002
        objValve.Commit()
6003
        Dim dVesselX As Double = XCoordinate
6004
        Dim dVesselY As Double = YCoordinate
6005
        Dim X1 As Double, Y1 As Double, X2 As Double, Y2 As Double
6006

    
6007
        _Placement.PIDConnectPointLocation(objValve, 1, X1, Y1)
6008

    
6009
        _Placement.PIDConnectPointLocation(objValve, 2, X2, Y2)
6010

    
6011
        Dim nozzlename As String = "\Equipment Components\Nozzles\Flanged Nozzle.sym"
6012
        Dim dCalc_x As Double = 0
6013
        Dim dCalc_y As Double = 0
6014

    
6015
        If dVesselX - X2 > 0 Then
6016
            dCalc_x = dVesselX - (dVesselX - X2)
6017
        Else
6018
            dCalc_x = dVesselX + (X2 - dVesselX)
6019
        End If
6020
        If dVesselY - Y2 > 0 Then
6021
            dCalc_y = dVesselY - (dVesselY - Y2)
6022
        Else
6023
            dCalc_y = dVesselY + (Y2 - dVesselY)
6024
        End If
6025

    
6026
        Dim objNozzle As LMSymbol = _Placement.PIDPlaceSymbol(nozzlename, dCalc_x, dCalc_y,
6027
            TargetItem:=symVessel.AsLMRepresentation)
6028

    
6029
        Dim blnSuccess As Boolean = _Placement.PIDConnectPointLocation(objNozzle, 1, X1, Y1)
6030
        blnSuccess = _Placement.PIDConnectPointLocation(objNozzle, 2, X1, Y1)
6031

    
6032
        objValve = _Placement.PIDPlaceSymbol(objValve.FileName, X1, Y1, ExistingItem:=objValve.AsLMAItem,
6033
          TargetItem:=objNozzle.AsLMRepresentation)
6034

    
6035

    
6036

    
6037
    End Sub
6038

    
6039
    Private Sub Btn_SymbolLibrary_Click(sender As Object, e As EventArgs) Handles Btn_SymbolLibrary.Click
6040
        Dim oMapping As New Mapping(_PIDSymbol_DB)
6041
        oMapping.Show()
6042
    End Sub
6043

    
6044
    Private Sub Btn_Stop_Click(sender As Object, e As EventArgs) Handles Btn_Stop.Click
6045
        Try
6046
            SetListBoxItems(ListBox_Result, " Auto converting 중지....")
6047
            ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, " Auto converting 중지....")
6048
            _Main_trd.Abort()
6049
            _Opc_trd.Abort()
6050
        Catch ex As Exception
6051

    
6052
        End Try
6053
    End Sub
6054

    
6055
    Private Sub AutoCheckTreeNode(ByVal iType As Integer, ByVal bCheck As Boolean)
6056

    
6057
        For Each oDrwing As TreeNode In Tree_Result.Nodes
6058
            For Each oDwgNode As TreeNode In oDrwing.Nodes
6059
                Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
6060
                Dim CDrawing As Drawing = GetDrawing(sDwgName)
6061
                If CDrawing IsNot Nothing Then
6062
                    Dim iAllLineNoCount As Integer = Tree_Result.Nodes.Count ' GetCheckNodeCount(oLinenoNode)
6063
                    Dim iPipingOPC_count As Integer = 0 ' GetCheckNodeCount(oLinenoNode)
6064
                    For Each oNode As TreeNode In oDwgNode.Nodes
6065
                        Dim iItemcnt As Integer = 0
6066
                        Dim sNodeUid As String = oNode.Name
6067
                        Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
6068

    
6069
                        If iType = 0 Then 'Symbol
6070
                            Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
6071
                            If CLineNo IsNot Nothing Then
6072
                                Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
6073
                                For Each oSymbolRow In oSymbol_Dt.Rows
6074
                                    Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID).ToString()
6075
                                    For Each oSymbolNode As TreeNode In oNode.Nodes
6076
                                        Dim sSymbolNodeUid As String = oSymbolNode.Name
6077
                                        If sSymbolNodeUid = sSymbolUid Then
6078
                                            oSymbolNode.Checked = bCheck
6079
                                            Exit For
6080
                                        End If
6081
                                    Next
6082
                                Next
6083
                            End If
6084
                            Dim TrimLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
6085
                            If TrimLineNo IsNot Nothing Then
6086
                                Dim oSymbol_Dt As DataTable = TrimLineNo.Dt_Symbol
6087
                                For Each oSymbolRow In oSymbol_Dt.Rows
6088
                                    Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID).ToString()
6089
                                    For Each oSymbolNode As TreeNode In oNode.Nodes
6090
                                        Dim sSymbolNodeUid As String = oSymbolNode.Name
6091
                                        If sSymbolNodeUid = sSymbolUid Then
6092
                                            oSymbolNode.Checked = bCheck
6093
                                            Exit For
6094
                                        End If
6095
                                    Next
6096
                                Next
6097
                            End If
6098
                        End If
6099
                        If iType = 1 Then 'Line
6100
                            Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
6101
                            If CLineNo IsNot Nothing Then
6102
                                Dim oLine_Dt As DataTable = CLineNo.Dt_Line
6103
                                For Each oLineRow In oLine_Dt.Rows
6104
                                    Dim sLineUid As String = oLineRow(_XML_LINE_UID).ToString()
6105
                                    For Each oLineNode As TreeNode In oNode.Nodes
6106
                                        Dim sLineNodeUid As String = oLineNode.Name
6107
                                        If sLineNodeUid = sLineUid Then
6108
                                            oLineNode.Checked = bCheck
6109
                                            Exit For
6110
                                        End If
6111
                                    Next
6112
                                Next
6113
                            End If
6114
                            Dim TrimLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
6115
                            If TrimLineNo IsNot Nothing Then
6116
                                Dim oLine_Dt As DataTable = TrimLineNo.Dt_Line
6117
                                For Each oLineRow In oLine_Dt.Rows
6118
                                    Dim sLineUid As String = oLineRow(_XML_SYMBOL_UID).ToString()
6119
                                    For Each oLineNode As TreeNode In oNode.Nodes
6120
                                        Dim sLineNodeUid As String = oLineNode.Name
6121
                                        If sLineNodeUid = sLineUid Then
6122
                                            oLineNode.Checked = bCheck
6123
                                            Exit For
6124
                                        End If
6125
                                    Next
6126
                                Next
6127
                            End If
6128
                        End If
6129
                        If iType = 2 Then 'Equipment
6130
                            Dim CEqpNo As Eqp_no = GetEqpNo(CDrawing, sNodeUid)
6131
                            If CEqpNo IsNot Nothing Then
6132
                                Dim oEqp_Dt As DataTable = CEqpNo.Dt_Equipment
6133
                                For Each oEqpRow In oEqp_Dt.Rows
6134
                                    Dim sEqpUid As String = oEqpRow(_XML_LINE_UID).ToString()
6135
                                    For Each oEqpNode As TreeNode In oNode.Nodes
6136
                                        Dim sEqpNodeUid As String = oEqpNode.Name
6137
                                        If sEqpNodeUid = sEqpUid Then
6138
                                            oEqpNode.Checked = bCheck
6139
                                            Exit For
6140
                                        End If
6141
                                    Next
6142
                                Next
6143
                            End If
6144
                        End If
6145
                    Next
6146
                End If
6147
            Next
6148
        Next
6149

    
6150

    
6151
    End Sub
6152

    
6153

    
6154

    
6155
    Private Sub Chk_Symbol_CheckedChanged(sender As Object, e As EventArgs) Handles Chk_Symbol.CheckedChanged
6156
        AutoCheckTreeNode(0, Chk_Symbol.Checked)
6157
    End Sub
6158

    
6159
    Private Sub Chk_Line_CheckedChanged(sender As Object, e As EventArgs) Handles Chk_Line.CheckedChanged
6160
        AutoCheckTreeNode(1, Chk_Line.Checked)
6161
    End Sub
6162

    
6163
    Private Sub Chk_Equipment_CheckedChanged(sender As Object, e As EventArgs) Handles Chk_Equipment.CheckedChanged
6164
        AutoCheckTreeNode(2, Chk_Equipment.Checked)
6165
    End Sub
6166
End Class
6167

    
6168

    
6169
Public Class DrawingInfo
6170
    Public mDrawingName As String
6171
    Public mSpID As String
6172
    Public mPath As String
6173
End Class
6174

    
6175

    
6176

    
6177

    
6178

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