프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / Main.vb @ 8a2f59cb

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

1 4f359afa Gyusu
Imports System.IO
2
Imports System.Data.SqlClient
3
Imports System.Data.SQLite
4
Imports Plaice
5
Imports Llama
6 b08338e3 Gyusu
Imports ComUtil.MessageLog.CEventLog
7 e282643f Gyusu
8
Imports System.Threading
9
10 4f359afa Gyusu
Public Class Main
11 54b98e09 Gyusu
    'Dim _Mapping_DB As DataTable = New DataTable()
12
    Dim _Mapping_DB As DataSet = New DataSet()
13 171ac39d Gyusu
    Dim _Attribute_DB As DataTable = New DataTable()
14 39d43554 Gyusu
    Dim _PIDSymbol_DB As DataTable = New DataTable()
15 e4000111 Gyusu
    Dim _ResultModeling_DT As DataTable = New DataTable()
16 76f465d0 Gyusu
    Dim _AllLine_DT As New DataTable()
17
    Dim _AllSymbol_DT As New DataTable()
18 79326880 Gyusu
    Dim _ModelingLine_Dt As New DataTable()
19 e38f99a7 Gyusu
    Dim _ModelingSymbol_Dt As New DataTable()
20 4f359afa Gyusu
    Dim _Placement As New Placement
21 e4000111 Gyusu
    Dim _DWG_X = 0.875 '0.695 '1 '
22
    Dim _DWG_Y = 0.617 '0.585 '0.8 '
23 c2c36314 Gyusu
    'Dim _DWG_X = 0.842 '0.695 '1 '
24
    'Dim _DWG_Y = 0.614 '0.585 '0.8 '
25 7e561f5b gaqhf
    Public _IMG_X = 0
26
    Public _IMG_Y = 0
27 171ac39d Gyusu
    Dim _Unit As String
28 31d47a80 Gyusu
    'Drawing 전역변수
29
    Dim _objPIDADrawing As Object
30 e282643f Gyusu
    '현재선택한 폴더경로
31
    Dim _selectFolderPath As String
32
    Private _Main_trd As Thread
33 54b98e09 Gyusu
    Private _Opc_trd As Thread
34
    Private _CompleteConvert As Boolean = False
35 171ac39d Gyusu
    Private _DrawingsList As List(Of Drawing)
36 9e1e7135 Gyusu
    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 e4000111 Gyusu
    Private _iPipintOpccnt As Integer
44 41e4023e Gyusu
    Private _allItem As Integer
45
    Private _Itemcnt As Integer
46 b08338e3 Gyusu
    Dim _Gembox As New CGembox()
47 1bfcc921 Gyusu
48 1406fef4 gaqhf
    Dim PipeRunPoint As Dictionary(Of String, List(Of PointdInfo)) = New Dictionary(Of String, List(Of PointdInfo))
49
50 4f359afa Gyusu
    Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
51 54b98e09 Gyusu
        LoadDB()
52
    End Sub
53 1bfcc921 Gyusu
    ''' <summary>
54
    ''' brief
55
    ''' </summary>
56 272662f9 Gyusu
57 54b98e09 Gyusu
    Private Sub LoadDB()
58 e282643f Gyusu
        If My.Settings.DBPath <> "" And My.Settings.Plant_Hierarchy <> "" Then
59
            Dim sDBPath As String = My.Settings.DBPath
60 54b98e09 Gyusu
61
            _Gembox.isLoadFile(My.Settings.SymbolLibrary)
62
            _Mapping_DB = _Gembox.LoadFileFunc()
63 171ac39d Gyusu
            _Attribute_DB = Load_DB(sDBPath, _DB_TABLE_ATTRIBUTE)
64 39d43554 Gyusu
            _PIDSymbol_DB = Load_DB(sDBPath, _DB_TABLE_SYMBOLNAME)
65 e4000111 Gyusu
            _ResultModeling_DT = ModelingResult_Dt()
66 e282643f Gyusu
        Else
67
            MessageBox.Show("설정값을 먼저 확인해주세요")
68
        End If
69
    End Sub
70 41e4023e Gyusu
71 171ac39d Gyusu
    Private Function GetDataFromMappingDB(ByVal sSymbolName As String, ByVal sColumn As String) As String
72
        Dim sValue As String = ""
73 54b98e09 Gyusu
        For Each oDt As DataTable In _Mapping_DB.Tables
74
            If oDt.Rows.Count > 0 Then
75
                Dim oSelectRow() As DataRow = oDt.Select("[img_symbolname] = '" + sSymbolName + "'")
76
                If oSelectRow.Length = 1 Then
77
                    If sColumn = _DB_COLUMN_MAPPING_SPPID_SYMBOLNAME Then
78
                        sValue = oSelectRow(0).Item("SYM FILE NAME").ToString()
79
                    ElseIf sColumn = _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH Then
80
                        sValue = "\" & oSelectRow(0).Item("SYMBOL PATH").ToString() & "\" & oSelectRow(0).Item("SYM FILE NAME").ToString()
81
                    ElseIf sColumn = _DB_COLUMN_MAPPING_SPPID_COMPTPYE Then
82
                        sValue = oSelectRow(0).Item("ITEM TYPE").ToString()
83
                    ElseIf sColumn = _DB_COLUMN_MAPPING_SPPID_CLASS Then
84
                        sValue = oSelectRow(0).Item("CLASS").ToString()
85
                    Else
86
                        sValue = oSelectRow(0).Item("SYMBOL PATH").ToString() & "\" & oSelectRow(0).Item("SYM FILE NAME").ToString()
87
                    End If
88
                End If
89 e282643f Gyusu
            End If
90 54b98e09 Gyusu
        Next
91 171ac39d Gyusu
        Return sValue
92 4f359afa Gyusu
    End Function
93
94 171ac39d Gyusu
    Private Function GetAttributeMapping(ByVal sAttributeName As String, ByVal sColumn As String) As String
95
        Dim sSPPIDAttribute As String = ""
96
        If _Attribute_DB.Rows.Count > 0 Then
97
            Dim oSelectRow() As DataRow = _Attribute_DB.Select("[pid_attribute] = '" + sAttributeName + "'")
98
            If oSelectRow.Length = 1 Then
99
                sSPPIDAttribute = oSelectRow(0).Item(sColumn).ToString()
100
            End If
101
        End If
102
        Return sSPPIDAttribute
103
    End Function
104 e282643f Gyusu
105 e6ef24be gaqhf
106
107 171ac39d Gyusu
    Private Function LoadSymbolInXml(ByVal sXmlPath As String) As Drawing
108 54b98e09 Gyusu
        Try
109
            ''  _TempSymbolDt = Symbol_Dt()
110
            Dim CDrawing As Drawing = New Drawing()
111 f291ddcb Gyusu
            '     Dim oDt As DataTable = LoadSymbol_DT()
112 54b98e09 Gyusu
            Dim oElement As XElement = XElement.Load(sXmlPath)
113
            If oElement IsNot Nothing Then
114
                CDrawing.DwgName = oElement.Element(_XML_DWGNAME).Value
115
                CDrawing.Size = oElement.Element(_XML_DWGSIZE).Value
116
                SplitLocation(CDrawing.Size, _IMG_X, _IMG_Y)
117 e6ef24be gaqhf
                '' 이것이 무엇인지 확인 필요
118
                'CDrawing.Unit = oElement.Element(_XML_UNIT).Value
119
120
                CDrawing.LINES = LoadLines(oElement)
121
                CDrawing.SYMBOLS = LoadSymbols(oElement)
122
                CDrawing.LINENUMBERS = LoadLineNumbers(oElement)
123
                CDrawing.TRIMLINES = LoadTrimLines(oElement)
124
125
126
                'Dim oLineno_list As New List(Of Line_no)
127
                'Dim oEqp_list As New List(Of Eqp_no)
128
                'Dim oTrim_Lineno_list As New List(Of Line_no)
129
                'oLineno_list = LoadLineNo(oElement, _XML_CATEGORY_LINENO)
130
                'For Each oEqpNo As Object In oElement.Elements(_XML_CATEGORY_EQUIPMENT)
131
                '    Dim CEqp_no As Eqp_no = New Eqp_no()
132
                '    Dim oSymbol_Dt As DataTable = Symbol_Dt()
133
                '    Dim oAttribute_Dt As DataTable = Attribute_Dt()
134
                '    Dim sUid As String = ""
135
                '    For Each oSymbol As Object In oEqpNo.Elements(_XML_CATEGORY_SYMBOL)
136
                '        Try
137
                '            Dim oAddrow As DataRow = oSymbol_Dt.NewRow()
138
                '            Dim oEleObj As XElement
139
                '            Dim sParentName As String
140
                '            Dim sName As String
141
                '            Dim sLocation As String
142
                '            Dim sSize As String
143
                '            Dim sAngle As String
144
                '            Dim sOriginalPoint As String = ""
145
                '            Dim sConnectionPoint As String = ""
146
                '            Dim sConnectionUids As String = ""
147
                '            Dim sConnArray As String()
148
                '            Dim sSizeArray As String()
149
                '            Dim sLocationArray As String()
150
                '            Dim sChild As String = ""
151
                '            Dim dCenterPos_x As Double = 0.0
152
                '            Dim dCenterPos_y As Double = 0.0
153
                '            Dim dDwgCenterPos_x As Double = 0.0
154
                '            Dim dDwgCenterPos_y As Double = 0.0
155
                '            Dim dConn1Pos_x As Double = 0.0
156
                '            Dim dConn1Pos_y As Double = 0.0
157
                '            Dim dConn2Pos_x As Double = 0.0
158
                '            Dim dConn2Pos_y As Double = 0.0
159
                '            Dim dConn3Pos_x As Double = 0.0
160
                '            Dim dConn3Pos_y As Double = 0.0
161
                '            Dim dConn4Pos_x As Double = 0.0
162
                '            Dim dConn4Pos_y As Double = 0.0
163
                '            Dim dDwg_Conn1Pos_x As Double = 0.0
164
                '            Dim dDwg_Conn1Pos_y As Double = 0.0
165
                '            Dim dDwg_Conn2Pos_x As Double = 0.0
166
                '            Dim dDwg_Conn2Pos_y As Double = 0.0
167
                '            Dim dDwg_Conn3Pos_x As Double = 0.0
168
                '            Dim dDwg_Conn3Pos_y As Double = 0.0
169
                '            Dim dDwg_Conn4Pos_x As Double = 0.0
170
                '            Dim dDwg_Conn4Pos_y As Double = 0.0
171
                '            Dim sOwnerUid As String = ""
172
                '            oEleObj = oSymbol.Element(_XML_SYMBOL_UID)
173
                '            sUid = oEleObj.Value
174
                '            oEleObj = oSymbol.Element(_XML_SYMBOL_PARENT)
175
                '            sParentName = oEleObj.Value
176
                '            oEleObj = oSymbol.Element(_XML_SYMBOL_NAME)
177
                '            sName = oEleObj.Value
178
                '            oEleObj = oSymbol.Element(_XML_SYMBOL_LOCATION)
179
                '            sLocation = oEleObj.Value
180
                '            oEleObj = oSymbol.Element(_XML_SYMBOL_SIZE)
181
                '            sSize = oEleObj.Value
182
                '            oEleObj = oSymbol.Element(_XML_SYMBOL_ANGLE)
183
                '            sAngle = oEleObj.Value
184
                '            oEleObj = oSymbol.Element(_XML_SYMBOL_CONNECTIONPOINT)
185
                '            sConnectionPoint = oEleObj.Value
186
                '            oEleObj = oSymbol.Element(_XML_SYMBOL_CHILD)
187
                '            sChild = oEleObj.Value
188
189
                '            If sName = "NOZZLE" Then
190
                '                oEleObj = oSymbol.Element(_XML_SYMBOL_OWNER)
191
                '                sOwnerUid = oEleObj.Value
192
                '            End If
193
                '            Try
194
                '                oEleObj = oSymbol.Element(_XML_SYMBOL_ORIGINALPOINT)
195
                '                sOriginalPoint = oEleObj.Value
196
                '            Catch ex As Exception
197 b08338e3 Gyusu
198 e6ef24be gaqhf
                '            End Try
199
                '            oAddrow(_XML_SYMBOL_OWNER) = sOwnerUid
200
                '            oAddrow(_XML_SYMBOL_Conn1_Uid) = ""
201
                '            oAddrow(_XML_SYMBOL_Conn2_Uid) = ""
202
                '            oAddrow(_XML_SYMBOL_Conn3_Uid) = ""
203
                '            oAddrow(_XML_SYMBOL_Conn4_Uid) = ""
204
                '            ConvertPointBystring(sOriginalPoint, dCenterPos_x, dCenterPos_y)
205
                '            dDwgCenterPos_x = dCenterPos_x
206
                '            dDwgCenterPos_y = dCenterPos_y
207
                '            ConvertPointByImage(dDwgCenterPos_x, dDwgCenterPos_y, _IMG_X, _IMG_Y)
208
                '            oAddrow(_XML_SYMBOL_CENTERPOINT_X) = dCenterPos_x
209
                '            oAddrow(_XML_SYMBOL_CENTERPOINT_Y) = dCenterPos_y
210
                '            oAddrow(_XML_SYMBOL_DWG_CENTERPOINT_X) = dDwgCenterPos_x
211
                '            oAddrow(_XML_SYMBOL_DWG_CENTERPOINT_Y) = dDwgCenterPos_y
212
                '            sConnArray = sConnectionPoint.Split("/")
213
                '            sSizeArray = sSize.Split(",")
214
                '            sLocationArray = sLocation.Split(",")
215
                '            If sConnArray.Length > 4 Then
216
                '                MessageBox.Show(sConnArray.Length)
217
                '            End If
218
                '            For i = 0 To sConnArray.Length - 1
219
                '                If i = 0 Then
220
                '                    oAddrow(_XML_SYMBOL_Conn1_Point) = sConnArray(i)
221
                '                    ConvertPointBystring(sConnArray(i), dConn1Pos_x, dConn1Pos_y)
222
                '                    dDwg_Conn1Pos_x = dConn1Pos_x
223
                '                    dDwg_Conn1Pos_y = dConn1Pos_y
224
                '                    ConvertPointByImage(dDwg_Conn1Pos_x, dDwg_Conn1Pos_y, _IMG_X, _IMG_Y)
225
                '                    oAddrow(_XML_SYMBOL_CONN1_POINT_X) = dConn1Pos_x
226
                '                    oAddrow(_XML_SYMBOL_CONN1_POINT_Y) = dConn1Pos_y
227
                '                    oAddrow(_XML_SYMBOL_DWG_CONN1_POINT_X) = dDwg_Conn1Pos_x
228
                '                    oAddrow(_XML_SYMBOL_DWG_CONN1_POINT_Y) = dDwg_Conn1Pos_y
229
                '                ElseIf i = 1 Then
230
                '                    oAddrow(_XML_SYMBOL_Conn2_Point) = sConnArray(i)
231
                '                    ConvertPointBystring(sConnArray(i), dConn2Pos_x, dConn2Pos_y)
232
                '                    dDwg_Conn2Pos_x = dConn2Pos_x
233
                '                    dDwg_Conn2Pos_y = dConn2Pos_y
234
                '                    ConvertPointByImage(dDwg_Conn2Pos_x, dDwg_Conn2Pos_y, _IMG_X, _IMG_Y)
235
                '                    oAddrow(_XML_SYMBOL_CONN2_POINT_X) = dConn2Pos_x
236
                '                    oAddrow(_XML_SYMBOL_CONN2_POINT_Y) = dConn2Pos_y
237
                '                    oAddrow(_XML_SYMBOL_DWG_CONN2_POINT_X) = dDwg_Conn2Pos_x
238
                '                    oAddrow(_XML_SYMBOL_DWG_CONN2_POINT_Y) = dDwg_Conn2Pos_y
239
                '                ElseIf i = 2 Then
240
                '                    oAddrow(_XML_SYMBOL_Conn3_Point) = sConnArray(i)
241
                '                    ConvertPointBystring(sConnArray(i), dConn3Pos_x, dConn3Pos_y)
242
                '                    dDwg_Conn3Pos_x = dConn3Pos_x
243
                '                    dDwg_Conn3Pos_y = dConn3Pos_y
244
                '                    ConvertPointByImage(dDwg_Conn3Pos_x, dDwg_Conn3Pos_y, _IMG_X, _IMG_Y)
245
                '                    oAddrow(_XML_SYMBOL_CONN3_POINT_X) = dConn3Pos_x
246
                '                    oAddrow(_XML_SYMBOL_CONN3_POINT_Y) = dConn3Pos_y
247
                '                    oAddrow(_XML_SYMBOL_DWG_CONN3_POINT_X) = dDwg_Conn3Pos_x
248
                '                    oAddrow(_XML_SYMBOL_DWG_CONN3_POINT_Y) = dDwg_Conn3Pos_y
249
                '                ElseIf i = 3 Then
250
                '                    oAddrow(_XML_SYMBOL_Conn4_Point) = sConnArray(i)
251
                '                    ConvertPointBystring(sConnArray(i), dConn4Pos_x, dConn4Pos_y)
252
                '                    dDwg_Conn4Pos_x = dConn4Pos_x
253
                '                    dDwg_Conn4Pos_y = dConn4Pos_y
254
                '                    ConvertPointByImage(dDwg_Conn4Pos_x, dDwg_Conn4Pos_y, _IMG_X, _IMG_Y)
255
                '                    oAddrow(_XML_SYMBOL_CONN4_POINT_X) = dConn4Pos_x
256
                '                    oAddrow(_XML_SYMBOL_CONN4_POINT_Y) = dConn4Pos_y
257
                '                    oAddrow(_XML_SYMBOL_DWG_CONN4_POINT_X) = dDwg_Conn4Pos_x
258
                '                    oAddrow(_XML_SYMBOL_DWG_CONN4_POINT_Y) = dDwg_Conn4Pos_y
259
                '                End If
260
                '            Next
261
262
                '            Dim sXLength As String = ""
263
                '            Dim sYLength As String = ""
264
                '            Dim dMin_x As Double = 0
265
                '            Dim dMax_x As Double = 0
266
                '            Dim dMin_y As Double = 0
267
                '            Dim dMax_y As Double = 0
268
269
                '            For i = 0 To sSizeArray.Length - 1
270
                '                If i = 0 Then
271
                '                    sXLength = sSizeArray(i)
272
                '                ElseIf i = 1 Then
273
                '                    sYLength = sSizeArray(i)
274
                '                End If
275
                '            Next
276
277
                '            For i = 0 To sLocationArray.Length - 1
278
                '                If i = 0 Then
279
                '                    dMin_x = sLocationArray(i)
280
                '                    dMax_x = dMin_x + sXLength
281
                '                ElseIf i = 1 Then
282
                '                    'Y축은 반전
283
                '                    dMax_y = sLocationArray(i)
284
                '                    dMin_y = dMax_y + sYLength
285
                '                End If
286
                '            Next
287
                '            ConvertPointByImage(dMin_x, dMin_y, _IMG_X, _IMG_Y)
288
                '            ConvertPointByImage(dMax_x, dMax_y, _IMG_X, _IMG_Y)
289
                '            oAddrow(_XML_SYMBOL_MIN_X) = dMin_x
290
                '            oAddrow(_XML_SYMBOL_MAX_X) = dMax_x
291
                '            oAddrow(_XML_SYMBOL_MIN_Y) = dMin_y
292
                '            oAddrow(_XML_SYMBOL_MAX_Y) = dMax_y
293
                '            oAddrow(_XML_SYMBOL_UID) = sUid
294
                '            oAddrow(_XML_SYMBOL_NAME) = IO.Path.GetFileNameWithoutExtension(GetDataFromMappingDB(sParentName, _DB_COLUMN_MAPPING_SPPID_SYMBOLNAME))
295
                '            oAddrow(_XML_SYMBOL_LOCATION) = sLocation
296
                '            oAddrow(_XML_SYMBOL_SIZE) = sSize
297
                '            oAddrow(_XML_SYMBOL_ANGLE) = sAngle
298
                '            oAddrow(_XML_SYMBOL_SYSTEMPATH) = GetDataFromMappingDB(sParentName, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
299
                '            oAddrow(_XML_SYMBOL_TYPE) = GetDataFromMappingDB(sParentName, _DB_COLUMN_MAPPING_SPPID_COMPTPYE)
300
                '            oAddrow(_XML_SYMBOL_CLASS) = GetDataFromMappingDB(sParentName, _DB_COLUMN_MAPPING_SPPID_CLASS)
301
                '            oAddrow(_XML_SYMBOL_ORIGINALPOINT) = sOriginalPoint
302
                '            oAddrow(_XML_SYMBOL_CONNECTIONPOINT) = sConnectionPoint
303
                '            oAddrow(_XML_SYMBOL_DRAWING_TF) = "FALSE"
304
                '            oAddrow(_XML_SYMBOL_CHILD) = sChild
305
                '            '   _AllSymbol_DT.Rows.Add(oAddrow)
306
                '            oSymbol_Dt.Rows.Add(oAddrow)
307
                '        Catch ex As Exception
308
                '        End Try
309
                '    Next
310
                '    CEqp_no.Uid = sUid
311
                '    CEqp_no.Dt_Equipment = oSymbol_Dt
312
                '    CEqp_no.Dt_Attribute = oAttribute_Dt
313
                '    oEqp_list.Add(CEqp_no)
314
                'Next
315
                'oTrim_Lineno_list = LoadLineNo(oElement, _XML_CATEGORY_TRIM_LINENO)
316
                'CDrawing.Line_nos = oLineno_list
317
                'CDrawing.Eqp_nos = oEqp_list
318
                'CDrawing.TrimLine_nos = oTrim_Lineno_list
319 b08338e3 Gyusu
320 54b98e09 Gyusu
            End If
321
            Return CDrawing
322
        Catch ex As Exception
323
            Return Nothing
324
        End Try
325
326 4f359afa Gyusu
    End Function
327
328 76f465d0 Gyusu
    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
329
330
        Dim sReturnUid As String = ""
331
        Try
332
            Dim oFindLineRow As DataRow() = oLine_Dt.Select(
333
            "[" & _XML_LINE_DWG_STARTPOINT_X & "] >= '" & dPos_x - 0.001 & "' And " &
334
            "[" & _XML_LINE_DWG_STARTPOINT_X & "] <= '" & dPos_x + 0.001 & "' And " &
335
            "[" & _XML_LINE_DWG_STARTPOINT_Y & "] >= '" & dPos_y - 0.001 & "' And " &
336
            "[" & _XML_LINE_DWG_STARTPOINT_Y & "] <= '" & dPos_y + 0.001 & "' And " &
337
            "[" & _XML_LINE_UID & "] <> '" & sUid & "' And " &
338
            "[" & _XML_LINE_Conn1_Uid & "] = ''")
339
            If oFindLineRow.Length = 0 Then
340
                oFindLineRow = oLine_Dt.Select(
341
                "[" & _XML_LINE_DWG_ENDPOINT_X & "] >= '" & dPos_x - 0.001 & "' And " &
342
                "[" & _XML_LINE_DWG_ENDPOINT_X & "] <= '" & dPos_x + 0.001 & "' And " &
343
                "[" & _XML_LINE_DWG_ENDPOINT_Y & "] >= '" & dPos_y - 0.001 & "' And " &
344
                "[" & _XML_LINE_DWG_ENDPOINT_Y & "] <= '" & dPos_y + 0.001 & "' And " &
345
                "[" & _XML_LINE_UID & "] <> '" & sUid & "' And " &
346
                "[" & _XML_LINE_Conn2_Uid & "] = ''")
347
                If oFindLineRow.Length = 0 Then
348
                    oFindLineRow = oSymbol_Dt.Select(
349
              "[" & _XML_SYMBOL_DWG_CONN1_POINT_X & "] >= '" & dPos_x - 0.001 & "' And " &
350
              "[" & _XML_SYMBOL_DWG_CONN1_POINT_X & "] <= '" & dPos_x + 0.001 & "' And " &
351
              "[" & _XML_SYMBOL_DWG_CONN1_POINT_Y & "] >= '" & dPos_y - 0.001 & "' And " &
352
              "[" & _XML_SYMBOL_DWG_CONN1_POINT_Y & "] <= '" & dPos_y + 0.001 & "' And " &
353
              "[" & _XML_SYMBOL_UID & "] <> '" & sUid & "' And " &
354
              "[" & _XML_SYMBOL_Conn1_Uid & "] = ''")
355
                    If oFindLineRow.Length = 0 Then
356
                        oFindLineRow = oSymbol_Dt.Select(
357
                   "[" & _XML_SYMBOL_DWG_CONN2_POINT_X & "] >= '" & dPos_x - 0.001 & "' And " &
358
                   "[" & _XML_SYMBOL_DWG_CONN2_POINT_X & "] <= '" & dPos_x + 0.001 & "' And " &
359
                   "[" & _XML_SYMBOL_DWG_CONN2_POINT_Y & "] >= '" & dPos_y - 0.001 & "' And " &
360
                   "[" & _XML_SYMBOL_DWG_CONN2_POINT_Y & "] <= '" & dPos_y + 0.001 & "' And " &
361
                   "[" & _XML_SYMBOL_UID & "] <> '" & sUid & "' And " &
362
                   "[" & _XML_SYMBOL_Conn2_Uid & "] = ''")
363
                        If oFindLineRow.Length = 0 Then
364
                        Else
365
                            oFindLineRow(0)(_XML_SYMBOL_Conn2_Uid) = sUid
366
                            sReturnUid = oFindLineRow(0)(_XML_SYMBOL_UID).ToString()
367
                        End If
368
                    Else
369
                        oFindLineRow(0)(_XML_SYMBOL_Conn1_Uid) = sUid
370
                        sReturnUid = oFindLineRow(0)(_XML_SYMBOL_UID).ToString()
371
                    End If
372
                Else
373
                    oFindLineRow(0)(_XML_LINE_Conn2_Uid) = sUid
374
                    sReturnUid = oFindLineRow(0)(_XML_LINE_UID).ToString()
375
                End If
376
            Else
377
                oFindLineRow(0)(_XML_LINE_Conn1_Uid) = sUid
378
                sReturnUid = oFindLineRow(0)(_XML_LINE_UID).ToString()
379
            End If
380
        Catch ex As Exception
381
382
        End Try
383
384
        Return sReturnUid
385
    End Function
386
387
388
    Private Function SetConnectionInfo(ByRef oLine_Dt As DataTable, ByRef oSymbol_Dt As DataTable)
389
        Try
390
            For Each oLineInfo In oLine_Dt.Rows
391
                Dim sLineUid As String = oLineInfo(_XML_LINE_UID).ToString()
392
                Dim dStartPos_x As Double = oLineInfo(_XML_LINE_DWG_STARTPOINT_X)
393
                Dim dStartPos_y As Double = oLineInfo(_XML_LINE_DWG_STARTPOINT_Y)
394
                Dim dEndPos_x As Double = oLineInfo(_XML_LINE_DWG_ENDPOINT_X)
395
                Dim dEndPos_y As Double = oLineInfo(_XML_LINE_DWG_ENDPOINT_Y)
396
                Dim sConn1Uid As String = ""
397
                Dim sConn2Uid As String = ""
398
                sConn1Uid = FindConnection(oLine_Dt, oSymbol_Dt, sLineUid, dStartPos_x, dStartPos_y)
399
                If sConn1Uid <> "" Then
400
                    oLineInfo(_XML_LINE_Conn1_Uid) = sConn1Uid
401
                End If
402
                sConn2Uid = FindConnection(oLine_Dt, oSymbol_Dt, sLineUid, dEndPos_x, dEndPos_y)
403
                If sConn2Uid <> "" Then
404
                    oLineInfo(_XML_LINE_Conn2_Uid) = sConn2Uid
405
                End If
406
            Next
407
            For Each oSymbolInfo In oSymbol_Dt.Rows
408
                Dim sSymbolUid As String = oSymbolInfo(_XML_SYMBOL_UID).ToString()
409
                Dim dConn1Pos_x As Double = oSymbolInfo(_XML_SYMBOL_DWG_CONN1_POINT_X)
410
                Dim dConn1Pos_y As Double = oSymbolInfo(_XML_SYMBOL_DWG_CONN1_POINT_Y)
411
                Dim sConn1Uid As String = ""
412
                Dim sConn2Uid As String = ""
413
                sConn1Uid = FindConnection(oLine_Dt, oSymbol_Dt, sSymbolUid, dConn1Pos_x, dConn1Pos_y)
414
                If sConn1Uid <> "" Then
415
                    oSymbolInfo(_XML_SYMBOL_Conn1_Uid) = sConn1Uid
416
                End If
417
                Try
418
                    Dim dConn2Pos_x As Double = oSymbolInfo(_XML_SYMBOL_DWG_CONN2_POINT_X)
419
                    Dim dConn2Pos_y As Double = oSymbolInfo(_XML_SYMBOL_DWG_CONN2_POINT_Y)
420
                    sConn2Uid = FindConnection(oLine_Dt, oSymbol_Dt, sSymbolUid, dConn2Pos_x, dConn2Pos_y)
421
                    If sConn2Uid <> "" Then
422
                        oSymbolInfo(_XML_SYMBOL_Conn2_Uid) = sConn2Uid
423
                    End If
424
                Catch ex As Exception
425
                End Try
426
            Next
427
        Catch ex As Exception
428
        End Try
429
    End Function
430
431 76f5e1a8 Gyusu
    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
432
        Dim bValidLine As Boolean = True
433 76f465d0 Gyusu
        If Math.Abs(dStart_x - dEnd_x) > Math.Abs(dStart_y - dEnd_y) Then
434
            If dStart_x > dEnd_x Then
435
                sDirection = "X"
436
                sFlowdirection = "Left_x"
437
                If Math.Abs(dStart_y - dEnd_y) < 5 Then
438
                    dEnd_y = dStart_y
439
                End If
440
            Else
441
                sDirection = "X"
442
                sFlowdirection = "Right_x"
443
                If Math.Abs(dStart_y - dEnd_y) < 5 Then
444
                    dEnd_y = dStart_y
445
                End If
446
            End If
447 79326880 Gyusu
            If Math.Abs(dStart_x - dEnd_x) <= 15 Then
448 76f5e1a8 Gyusu
                bValidLine = False
449
            End If
450 76f465d0 Gyusu
        Else
451
            If dStart_y > dEnd_y Then
452
                sDirection = "Y"
453
                sFlowdirection = "Down_y"
454
                If Math.Abs(dStart_x - dEnd_x) < 5 Then
455
                    dEnd_x = dStart_x
456
                End If
457
458
            Else
459
                sDirection = "Y"
460
                sFlowdirection = "Up_y"
461
                If Math.Abs(dStart_x - dEnd_x) < 5 Then
462
                    dEnd_x = dStart_x
463
                End If
464
            End If
465 79326880 Gyusu
            If Math.Abs(dStart_y - dEnd_y) <= 20 Then
466 76f5e1a8 Gyusu
                bValidLine = False
467
            End If
468 76f465d0 Gyusu
        End If
469 76f5e1a8 Gyusu
        Return bValidLine
470 76f465d0 Gyusu
    End Function
471 4f359afa Gyusu
472 e6ef24be gaqhf
    Private Function LoadLines(ByVal oElement As XElement) As List(Of Line)
473
        Dim result As List(Of Line) = New List(Of Line)
474
475
        Dim lineInfos As XElement = oElement.Element(_XML_LINEINFOS)
476
477
        For Each oLine As XElement In lineInfos.Elements(_XML_LINEINFOS_LINE)
478
            Dim _line As Line = New Line()
479
            Try
480
                _line.UID = oLine.Element(_XML_LINEINFOS_LINE_UID).Value
481
                _line.STARTPOINT = oLine.Element(_XML_LINEINFOS_LINE_STARTPOINT).Value
482
                _line.ENDPOINT = oLine.Element(_XML_LINEINFOS_LINE_ENDPOINT).Value
483
                _line.TYPE = oLine.Element(_XML_LINEINFOS_LINE_TYPE).Value
484
                _line.AREA = oLine.Element(_XML_LINEINFOS_LINE_AREA).Value
485
                _line.CONNECTORS = GetConnector(oLine)
486
                result.Add(_line)
487
            Catch ex As Exception
488
489
            End Try
490
        Next
491
492
        Return result
493
    End Function
494
495
    Private Function LoadSymbols(ByVal oElement As XElement) As List(Of Symbol)
496
        Dim result As List(Of Symbol) = New List(Of Symbol)
497
498
        Dim symbols As XElement = oElement.Element(_XML_SYMBOLS)
499
500
        For Each oSymbol As XElement In symbols.Elements(_XML_SYMBOLS_SYMBOL)
501
            Dim _symbol As Symbol = New Symbol()
502
            Try
503
                _symbol.UID = oSymbol.Element(_XML_SYMBOLS_SYMBOL_UID).Value
504
                _symbol.NAME = oSymbol.Element(_XML_SYMBOLS_SYMBOL_NAME).Value
505
                _symbol.TYPE = oSymbol.Element(_XML_SYMBOLS_SYMBOL_TYPE).Value
506
                _symbol.ORIGINALPOINT = oSymbol.Element(_XML_SYMBOLS_SYMBOL_ORIGINALPOINT).Value
507
                _symbol.CONNECTORS = GetConnector(oSymbol)
508
                _symbol.LOCATION = oSymbol.Element(_XML_SYMBOLS_SYMBOL_LOCATION).Value
509
                _symbol.SIZE = oSymbol.Element(_XML_SYMBOLS_SYMBOL_SIZE).Value
510
                _symbol.ANGLE = oSymbol.Element(_XML_SYMBOLS_SYMBOL_ANGLE).Value
511
                _symbol.PARENT = oSymbol.Element(_XML_SYMBOLS_SYMBOL_PARENT).Value
512
                _symbol.CHILD = oSymbol.Element(_XML_SYMBOLS_SYMBOL_CHILD).Value
513
                _symbol.HASINSTRUMENTLABEL = oSymbol.Element(_XML_SYMBOLS_SYMBOL_HASINSTRUMENTLABEL).Value
514
                _symbol.AREA = oSymbol.Element(_XML_SYMBOLS_SYMBOL_AREA).Value
515
                _symbol.CURRENTPOINTMODEINDEX = oSymbol.Element(_XML_SYMBOLS_SYMBOL_CURRENTPOINTMODEINDEX).Value
516
517
                result.Add(_symbol)
518
            Catch ex As Exception
519
520
            End Try
521
        Next
522
523
        Return result
524
    End Function
525
526
    Private Function LoadLineNumbers(ByVal oElement As XElement) As List(Of LineNumber)
527
        Dim result As List(Of LineNumber) = New List(Of LineNumber)
528
529
        Dim lineNos As XElement = oElement.Element(_XML_LINENOS)
530
531
        For Each oLineNo As XElement In lineNos.Elements(_XML_LINENOS_LINENO)
532
            Dim _lineNo As LineNumber = New LineNumber()
533
            Try
534
                _lineNo.UID = oLineNo.Element(_XML_LINEINFOS_LINE_UID).Value
535
536
                _lineNo.SYMBOLRUNITEMS = GetSymbolRunItems(oLineNo)
537
                _lineNo.LINERUNITEMS = GetLineRunItems(oLineNo)
538
539
                result.Add(_lineNo)
540
            Catch ex As Exception
541
542
            End Try
543
        Next
544
545
        Return result
546
    End Function
547
548
    Private Function LoadTrimLines(ByVal oElement As XElement) As List(Of LineNumber)
549
        Dim result As List(Of LineNumber) = New List(Of LineNumber)
550
551
        Dim trimNos As XElement = oElement.Element(_XML_TRIMLINENOS)
552
553
        For Each oTrimLine As XElement In trimNos.Elements(_XML_TRIMLINENOS_TRIM_LINE_NO)
554
            Dim _lineNo As LineNumber = New LineNumber()
555
            Try
556
                _lineNo.UID = oTrimLine.Element(_XML_LINEINFOS_LINE_UID).Value
557
558
                _lineNo.SYMBOLRUNITEMS = GetSymbolRunItems(oTrimLine)
559
                _lineNo.LINERUNITEMS = GetLineRunItems(oTrimLine)
560
561
                result.Add(_lineNo)
562
            Catch ex As Exception
563
564
            End Try
565
        Next
566
567
        Return result
568
    End Function
569
570
    Private Function GetSymbolRunItems(ByVal oElement As XElement) As List(Of String)
571
        Dim result As List(Of String) = New List(Of String)
572
573
        Dim oRun As XElement = oElement.Element(_XML_RUN)
574
575
        For Each oSymbol As XElement In oRun.Elements(_XML_RUN_SYMBOL)
576
            result.Add(oSymbol.Element(_XML_SYMBOLS_SYMBOL_UID))
577
        Next
578
579
        Return result
580
    End Function
581
582
    Private Function GetLineRunItems(ByVal oElement As XElement) As List(Of String)
583
        Dim result As List(Of String) = New List(Of String)
584
585
        Dim oRun As XElement = oElement.Element(_XML_RUN)
586
587
        For Each oLine As XElement In oRun.Elements(_XML_RUN_LINE)
588
            result.Add(oLine.Element(_XML_LINEINFOS_LINE_UID))
589
        Next
590
591
        Return result
592
    End Function
593
594
595
596
    Private Function GetConnector(ByVal oElement As XElement) As List(Of Connector)
597
        Dim result As List(Of Connector) = New List(Of Connector)
598
        Dim oElementConnectors As XElement = oElement.Element(_XML_CONNECTORS)
599
        For Each oConnector As XElement In oElementConnectors.Elements(_XML_CONNECTORS_CONNECTOR)
600
            Dim _connector As Connector = New Connector()
601
            Try
602
                _connector.CONNECTEDITEM = oConnector.Element(_XML_CONNECTORS_CONNECTOR_CONNECTEDITEM).Value
603
                _connector.CONNECTPOINT = oConnector.Element(_XML_CONNECTORS_CONNECTOR_CONNECTPOINT).Value
604
                _connector.SCENECONNECTPOINT = oConnector.Element(_XML_CONNECTORS_CONNECTOR_SCENECONNECTPOINT).Value
605
                result.Add(_connector)
606
            Catch ex As Exception
607
            End Try
608
        Next
609
610
        Return result
611
    End Function
612
613 3acffcee Gyusu
    Private Function LoadLineNo(ByVal oElement As XElement, ByVal sLineType As String) As List(Of Line_no)
614
615
        Dim oLineno_list As New List(Of Line_no)
616
        For Each oLineNo As Object In oElement.Elements(sLineType)
617
            Dim CLineNo As Line_no = New Line_no()
618
            Try
619
                CLineNo.Uid = oLineNo.Element(_XML_LINENO_UID).Value
620
                CLineNo.Text = oLineNo.Element(_XML_LINENO_TEXT).Value
621
                CLineNo.Location = oLineNo.Element(_XML_LINENO_LOCATION).Value
622
                CLineNo.Angle = oLineNo.Element(_XML_LINENO_ANGLE).Value
623
                CLineNo.SystemPath = "\Piping\Labels - Piping Segments\Kemya Line Number.sym" 'GetDataFromMappingDB(_XML_CATEGORY_LINENO, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
624
            Catch ex As Exception
625
            End Try
626
            Dim oLine_Dt As DataTable = Line_Dt()
627
            Dim oSymbol_Dt As DataTable = Symbol_Dt()
628
            Dim oAttribute_Dt As DataTable = Attribute_Dt()
629 76f465d0 Gyusu
            Dim iRunCnt As Integer = 0
630 3acffcee Gyusu
            For Each oRun As Object In oLineNo.Elements(_XML_CATEGORY_RUN)
631 76f465d0 Gyusu
                iRunCnt = iRunCnt + 1
632
                Dim sRunName As String = CLineNo.Text & "_" & iRunCnt
633
                For Each oMERGEDLine As Object In oRun.Elements(_XML_CATEGORY_MERGEDLINE)
634
                    For Each oLine As Object In oMERGEDLine.Elements(_XML_CATEGORY_LINE)
635
                        Try
636
                            Dim oAddrow As DataRow = oLine_Dt.NewRow()
637
                            Dim oEleObj As XElement
638
                            Dim sUid As String
639
                            Dim sStartpoint As String
640
                            Dim sEndpoint As String
641
                            Dim sType As String
642
                            Dim sConnectionUids As String = ""
643
                            Dim dStartPos_x As Double = 0.0
644
                            Dim dStartPos_y As Double = 0.0
645
                            Dim dEndPos_x As Double = 0.0
646
                            Dim dEndPos_y As Double = 0.0
647
                            Dim dDWG_StartPos_x As Double = 0.0
648
                            Dim dDWG_StartPos_y As Double = 0.0
649
                            Dim dDWG_EndPos_x As Double = 0.0
650
                            Dim dDWG_EndPos_y As Double = 0.0
651
                            oEleObj = oLine.Element(_XML_LINE_UID)
652
                            sUid = oEleObj.Value
653 b08338e3 Gyusu
654 76f465d0 Gyusu
                            If oLine_Dt.Select(_XML_LINE_UID & "='" & sUid & "'").Length = 0 Then
655
                                oEleObj = oLine.Element(_XML_LINE_STARTPOINT)
656
                                sStartpoint = oEleObj.Value
657
                                oEleObj = oLine.Element(_XML_LINE_ENDPOINT)
658
                                sEndpoint = oEleObj.Value
659
                                oEleObj = oLine.Element(_XML_LINE_TYPE)
660
                                sType = oEleObj.Value
661 f291ddcb Gyusu
662 76f465d0 Gyusu
                                oAddrow(_XML_LINE_Conn1_Uid) = ""
663
                                oAddrow(_XML_LINE_Conn2_Uid) = ""
664
                                oAddrow(_XML_LINE_UID) = sUid
665
                                oAddrow(_XML_LINE_RUNNAME) = sRunName
666
                                oAddrow(_XML_LINE_LINENOUID) = CLineNo.Uid
667
                                oAddrow(_XML_LINENO_TEXT) = CLineNo.Text
668
                                oAddrow(_XML_LINE_STARTPOINT) = sStartpoint
669
                                oAddrow(_XML_LINE_ENDPOINT) = sEndpoint
670 f291ddcb Gyusu
                                If sUid = "0bda520b-9c01-4dc1-9ddd-73adb5f7a871" Then
671
                                    MsgBox("")
672
                                End If
673 76f465d0 Gyusu
                                ConvertPointBystring(sStartpoint, dStartPos_x, dStartPos_y)
674
                                ConvertPointBystring(sEndpoint, dEndPos_x, dEndPos_y)
675
                                Dim sDirection As String = ""
676 76f5e1a8 Gyusu
                                Dim sFlowDirection As String = ""
677
                                Dim bValidLine As Boolean = GetFlowDirection(dStartPos_x, dStartPos_y, dEndPos_x, dEndPos_y, sDirection, sFlowDirection)
678
                                oAddrow(_XML_LINE_FlowDirection) = sFlowDirection
679 76f465d0 Gyusu
                                oAddrow(_XML_LINE_Direction) = sDirection
680 76f5e1a8 Gyusu
                                oAddrow(_XML_LINE_ValieLine) = bValidLine
681 76f465d0 Gyusu
                                dDWG_StartPos_x = dStartPos_x
682
                                dDWG_StartPos_y = dStartPos_y
683
                                ConvertPointByImage(dDWG_StartPos_x, dDWG_StartPos_y, _IMG_X, _IMG_Y)
684
                                dDWG_EndPos_x = dEndPos_x
685
                                dDWG_EndPos_y = dEndPos_y
686
                                ConvertPointByImage(dDWG_EndPos_x, dDWG_EndPos_y, _IMG_X, _IMG_Y)
687
688
                                oAddrow(_XML_LINE_STARTPOINT_X) = dStartPos_x
689
                                oAddrow(_XML_LINE_STARTPOINT_Y) = dStartPos_y
690
                                oAddrow(_XML_LINE_ENDPOINT_X) = dEndPos_x
691
                                oAddrow(_XML_LINE_ENDPOINT_Y) = dEndPos_y
692
693
                                oAddrow(_XML_LINE_DWG_STARTPOINT_X) = dDWG_StartPos_x
694
                                oAddrow(_XML_LINE_DWG_STARTPOINT_Y) = dDWG_StartPos_y
695
                                oAddrow(_XML_LINE_DWG_ENDPOINT_X) = dDWG_EndPos_x
696
                                oAddrow(_XML_LINE_DWG_ENDPOINT_Y) = dDWG_EndPos_y
697
698
                                oAddrow(_XML_LINE_SYSTEMPATH) = GetDataFromMappingDB(_XML_CATEGORY_LINE, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
699
                                If oAddrow(_XML_LINE_SYSTEMPATH) = "" Then
700
                                    MessageBox.Show("")
701 b08338e3 Gyusu
                                End If
702 76f465d0 Gyusu
                                oAddrow(_XML_LINE_DRAWING_TF) = "FALSE"
703
                                oAddrow(_XML_LINE_TYPE) = sType
704
                                '  _AllLine_DT.Rows.Add(oAddrow)
705
                                oLine_Dt.Rows.Add(oAddrow)
706
                            Else
707 b08338e3 Gyusu
                            End If
708 76f465d0 Gyusu
                        Catch ex As Exception
709
                        End Try
710
                    Next
711 3acffcee Gyusu
                Next
712
713
                For Each oSymbol As Object In oRun.Elements(_XML_CATEGORY_SYMBOL)
714
                    Try
715 76f465d0 Gyusu
716 3acffcee Gyusu
                        Dim oAddrow As DataRow = oSymbol_Dt.NewRow()
717
                        Dim oEleObj As XElement
718
                        Dim sUid As String
719
                        Dim sName As String
720
                        Dim sLocation As String
721
                        Dim sSize As String
722
                        Dim sAngle As String
723
                        Dim sOriginalPoint As String = ""
724 bb2a0c79 Gyusu
                        Dim sConnectionPoint As String = ""
725 b08338e3 Gyusu
                        Dim sConnectionUids As String = ""
726
                        Dim sConnArray As String()
727 e38f99a7 Gyusu
                        Dim sSizeArray As String()
728
                        Dim sLocationArray As String()
729 9c86a823 Gyusu
                        Dim sChild As String = ""
730 76f465d0 Gyusu
                        Dim dCenterPos_x As Double = 0.0
731
                        Dim dCenterPos_y As Double = 0.0
732
                        Dim dDwgCenterPos_x As Double = 0.0
733
                        Dim dDwgCenterPos_y As Double = 0.0
734
735
                        Dim dConn1Pos_x As Double = 0.0
736
                        Dim dConn1Pos_y As Double = 0.0
737
                        Dim dConn2Pos_x As Double = 0.0
738
                        Dim dConn2Pos_y As Double = 0.0
739
                        Dim dConn3Pos_x As Double = 0.0
740
                        Dim dConn3Pos_y As Double = 0.0
741
                        Dim dConn4Pos_x As Double = 0.0
742
                        Dim dConn4Pos_y As Double = 0.0
743
744
                        Dim dDwg_Conn1Pos_x As Double = 0.0
745
                        Dim dDwg_Conn1Pos_y As Double = 0.0
746
                        Dim dDwg_Conn2Pos_x As Double = 0.0
747
                        Dim dDwg_Conn2Pos_y As Double = 0.0
748
                        Dim dDwg_Conn3Pos_x As Double = 0.0
749
                        Dim dDwg_Conn3Pos_y As Double = 0.0
750
                        Dim dDwg_Conn4Pos_x As Double = 0.0
751
                        Dim dDwg_Conn4Pos_y As Double = 0.0
752
753 3acffcee Gyusu
                        oEleObj = oSymbol.Element(_XML_SYMBOL_UID)
754
                        sUid = oEleObj.Value
755
                        oEleObj = oSymbol.Element(_XML_SYMBOL_PARENT)
756
                        sName = oEleObj.Value
757
                        oEleObj = oSymbol.Element(_XML_SYMBOL_LOCATION)
758
                        sLocation = oEleObj.Value
759
                        oEleObj = oSymbol.Element(_XML_SYMBOL_SIZE)
760
                        sSize = oEleObj.Value
761
                        oEleObj = oSymbol.Element(_XML_SYMBOL_ANGLE)
762
                        sAngle = oEleObj.Value
763 bb2a0c79 Gyusu
                        oEleObj = oSymbol.Element(_XML_SYMBOL_CONNECTIONPOINT)
764
                        sConnectionPoint = oEleObj.Value
765 9c86a823 Gyusu
                        oEleObj = oSymbol.Element(_XML_SYMBOL_CHILD)
766
                        sChild = oEleObj.Value
767 3acffcee Gyusu
                        Try
768
                            oEleObj = oSymbol.Element(_XML_SYMBOL_ORIGINALPOINT)
769
                            sOriginalPoint = oEleObj.Value
770
                        Catch ex As Exception
771
772
                        End Try
773 76f465d0 Gyusu
                        'oEleObj = oSymbol.Element(_XML_LINE_CONNS)
774
                        'sConnectionUids = oEleObj.Value
775
                        'sConnArray = sConnectionUids.Split(",")
776
                        'If sConnArray.Length > 4 Then
777
                        '    MessageBox.Show(sConnArray.Length)
778
                        'End If
779
                        'For i = 0 To sConnArray.Length - 1
780
                        '    If i = 0 Then
781
                        '        oAddrow(_XML_SYMBOL_Conn1_Uid) = sConnArray(i)
782
                        '    ElseIf i = 1 Then
783
                        '        oAddrow(_XML_SYMBOL_Conn2_Uid) = sConnArray(i)
784
                        '    ElseIf i = 2 Then
785
                        '        oAddrow(_XML_SYMBOL_Conn3_Uid) = sConnArray(i)
786
                        '    ElseIf i = 3 Then
787
                        '        oAddrow(_XML_SYMBOL_Conn4_Uid) = sConnArray(i)
788
                        '    End If
789
                        'Next
790
                        oAddrow(_XML_SYMBOL_Conn1_Uid) = ""
791
                        oAddrow(_XML_SYMBOL_Conn2_Uid) = ""
792
                        oAddrow(_XML_SYMBOL_Conn3_Uid) = ""
793
                        oAddrow(_XML_SYMBOL_Conn4_Uid) = ""
794
                        ConvertPointBystring(sOriginalPoint, dCenterPos_x, dCenterPos_y)
795
                        dDwgCenterPos_x = dCenterPos_x
796
                        dDwgCenterPos_y = dCenterPos_y
797
                        ConvertPointByImage(dDwgCenterPos_x, dDwgCenterPos_y, _IMG_X, _IMG_Y)
798
799
                        oAddrow(_XML_SYMBOL_CENTERPOINT_X) = dCenterPos_x
800
                        oAddrow(_XML_SYMBOL_CENTERPOINT_Y) = dCenterPos_y
801
                        oAddrow(_XML_SYMBOL_DWG_CENTERPOINT_X) = dDwgCenterPos_x
802
                        oAddrow(_XML_SYMBOL_DWG_CENTERPOINT_Y) = dDwgCenterPos_y
803
                        sConnArray = sConnectionPoint.Split("/")
804 e38f99a7 Gyusu
                        sSizeArray = sSize.Split(",")
805
                        sLocationArray = sLocation.Split(",")
806 b08338e3 Gyusu
                        If sConnArray.Length > 4 Then
807
                            MessageBox.Show(sConnArray.Length)
808
                        End If
809
                        For i = 0 To sConnArray.Length - 1
810
                            If i = 0 Then
811 76f465d0 Gyusu
                                oAddrow(_XML_SYMBOL_Conn1_Point) = sConnArray(i)
812
                                ConvertPointBystring(sConnArray(i), dConn1Pos_x, dConn1Pos_y)
813
                                dDwg_Conn1Pos_x = dConn1Pos_x
814
                                dDwg_Conn1Pos_y = dConn1Pos_y
815
                                ConvertPointByImage(dDwg_Conn1Pos_x, dDwg_Conn1Pos_y, _IMG_X, _IMG_Y)
816
817
                                oAddrow(_XML_SYMBOL_CONN1_POINT_X) = dConn1Pos_x
818
                                oAddrow(_XML_SYMBOL_CONN1_POINT_Y) = dConn1Pos_y
819
                                oAddrow(_XML_SYMBOL_DWG_CONN1_POINT_X) = dDwg_Conn1Pos_x
820
                                oAddrow(_XML_SYMBOL_DWG_CONN1_POINT_Y) = dDwg_Conn1Pos_y
821 b08338e3 Gyusu
                            ElseIf i = 1 Then
822 76f465d0 Gyusu
                                oAddrow(_XML_SYMBOL_Conn2_Point) = sConnArray(i)
823
                                ConvertPointBystring(sConnArray(i), dConn2Pos_x, dConn2Pos_y)
824
                                dDwg_Conn2Pos_x = dConn2Pos_x
825
                                dDwg_Conn2Pos_y = dConn2Pos_y
826
                                ConvertPointByImage(dDwg_Conn2Pos_x, dDwg_Conn2Pos_y, _IMG_X, _IMG_Y)
827
                                oAddrow(_XML_SYMBOL_CONN2_POINT_X) = dConn2Pos_x
828
                                oAddrow(_XML_SYMBOL_CONN2_POINT_Y) = dConn2Pos_y
829
                                oAddrow(_XML_SYMBOL_DWG_CONN2_POINT_X) = dDwg_Conn2Pos_x
830
                                oAddrow(_XML_SYMBOL_DWG_CONN2_POINT_Y) = dDwg_Conn2Pos_y
831 b08338e3 Gyusu
                            ElseIf i = 2 Then
832 76f465d0 Gyusu
                                oAddrow(_XML_SYMBOL_Conn3_Point) = sConnArray(i)
833
                                ConvertPointBystring(sConnArray(i), dConn3Pos_x, dConn3Pos_y)
834
                                dDwg_Conn3Pos_x = dConn3Pos_x
835
                                dDwg_Conn3Pos_y = dConn3Pos_y
836
                                ConvertPointByImage(dDwg_Conn3Pos_x, dDwg_Conn3Pos_y, _IMG_X, _IMG_Y)
837
                                oAddrow(_XML_SYMBOL_CONN3_POINT_X) = dConn3Pos_x
838
                                oAddrow(_XML_SYMBOL_CONN3_POINT_Y) = dConn3Pos_y
839
                                oAddrow(_XML_SYMBOL_DWG_CONN3_POINT_X) = dDwg_Conn3Pos_x
840
                                oAddrow(_XML_SYMBOL_DWG_CONN3_POINT_Y) = dDwg_Conn3Pos_y
841 b08338e3 Gyusu
                            ElseIf i = 3 Then
842 76f465d0 Gyusu
                                oAddrow(_XML_SYMBOL_Conn4_Point) = sConnArray(i)
843
                                ConvertPointBystring(sConnArray(i), dConn4Pos_x, dConn4Pos_y)
844
                                dDwg_Conn4Pos_x = dConn4Pos_x
845
                                dDwg_Conn4Pos_y = dConn4Pos_y
846
                                ConvertPointByImage(dDwg_Conn4Pos_x, dDwg_Conn4Pos_y, _IMG_X, _IMG_Y)
847
                                oAddrow(_XML_SYMBOL_CONN4_POINT_X) = dConn4Pos_x
848
                                oAddrow(_XML_SYMBOL_CONN4_POINT_Y) = dConn4Pos_y
849
                                oAddrow(_XML_SYMBOL_DWG_CONN4_POINT_X) = dDwg_Conn4Pos_x
850
                                oAddrow(_XML_SYMBOL_DWG_CONN4_POINT_Y) = dDwg_Conn4Pos_y
851 b08338e3 Gyusu
                            End If
852
                        Next
853
854 e38f99a7 Gyusu
                        Dim sXLength As String = ""
855
                        Dim sYLength As String = ""
856
857
                        Dim dMin_x As Double = 0
858
                        Dim dMax_x As Double = 0
859
                        Dim dMin_y As Double = 0
860
                        Dim dMax_y As Double = 0
861
862
                        For i = 0 To sSizeArray.Length - 1
863
                            If i = 0 Then
864
                                sXLength = sSizeArray(i)
865
                            ElseIf i = 1 Then
866
                                sYLength = sSizeArray(i)
867
                            End If
868
                        Next
869
870
                        For i = 0 To sLocationArray.Length - 1
871
                            If i = 0 Then
872
                                dMin_x = sLocationArray(i)
873
                                dMax_x = dMin_x + sXLength
874
                            ElseIf i = 1 Then
875
                                'Y축은 반전
876
                                dMax_y = sLocationArray(i)
877
                                dMin_y = dMax_y + sYLength
878
                            End If
879
                        Next
880
                        ConvertPointByImage(dMin_x, dMin_y, _IMG_X, _IMG_Y)
881
                        ConvertPointByImage(dMax_x, dMax_y, _IMG_X, _IMG_Y)
882
883
                        oAddrow(_XML_SYMBOL_MIN_X) = dMin_x
884
                        oAddrow(_XML_SYMBOL_MAX_X) = dMax_x
885
                        oAddrow(_XML_SYMBOL_MIN_Y) = dMin_y
886
                        oAddrow(_XML_SYMBOL_MAX_Y) = dMax_y
887 3acffcee Gyusu
                        oAddrow(_XML_SYMBOL_UID) = sUid
888 b08338e3 Gyusu
                        oAddrow(_XML_LINE_LINENOUID) = CLineNo.Uid
889 76f465d0 Gyusu
                        oAddrow(_XML_SYMBOL_RUNNAME) = sRunName
890 b08338e3 Gyusu
                        oAddrow(_XML_LINENO_TEXT) = CLineNo.Text
891 3acffcee Gyusu
                        oAddrow(_XML_SYMBOL_NAME) = IO.Path.GetFileNameWithoutExtension(GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYMBOLNAME))
892
                        oAddrow(_XML_SYMBOL_LOCATION) = sLocation
893
                        oAddrow(_XML_SYMBOL_SIZE) = sSize
894
                        oAddrow(_XML_SYMBOL_ANGLE) = sAngle
895
                        oAddrow(_XML_SYMBOL_SYSTEMPATH) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
896
                        oAddrow(_XML_SYMBOL_TYPE) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_COMPTPYE)
897
                        oAddrow(_XML_SYMBOL_CLASS) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_CLASS)
898
                        oAddrow(_XML_SYMBOL_ORIGINALPOINT) = sOriginalPoint
899 76f465d0 Gyusu
900 bb2a0c79 Gyusu
                        oAddrow(_XML_SYMBOL_CONNECTIONPOINT) = sConnectionPoint
901 e4000111 Gyusu
                        oAddrow(_XML_SYMBOL_DRAWING_TF) = "FALSE"
902 9c86a823 Gyusu
                        oAddrow(_XML_SYMBOL_CHILD) = sChild
903 76f465d0 Gyusu
                        '   _AllSymbol_DT.Rows.Add(oAddrow)
904 3acffcee Gyusu
                        oSymbol_Dt.Rows.Add(oAddrow)
905
                    Catch ex As Exception
906
                    End Try
907
                Next
908
909
                For Each oAtrribute As Object In oRun.Elements(_XML_CATEGORY_ATTRIBUTE)
910
                    Try
911
                        Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
912
                        Dim oEleObj As XElement
913
                        Dim sUid As String
914
                        Dim sName As String
915
                        Dim sValue As String
916
                        oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
917
                        sUid = oEleObj.Value
918
                        oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
919
                        sName = oEleObj.Value
920
                        oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
921
                        sValue = oEleObj.Value
922
                        oAddrow(_XML_ATTRIBUTE_UID) = sUid
923
                        oAddrow(_XML_ATTRIBUTE_NAME) = sName
924
                        oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
925
                        oAttribute_Dt.Rows.Add(oAddrow)
926
                    Catch ex As Exception
927
                    End Try
928
                Next
929
            Next
930
            'Line No Attribute
931
            For Each oAtrribute As Object In oLineNo.Elements(_XML_CATEGORY_ATTRIBUTE)
932
                Try
933
                    Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
934
                    Dim oEleObj As XElement
935
                    Dim sUid As String = ""
936
                    Dim sName As String
937
                    Dim sValue As String
938
939
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
940
                    sUid = oEleObj.Value
941
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
942
                    sName = oEleObj.Value
943
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
944
                    sValue = oEleObj.Value
945
                    oAddrow(_XML_ATTRIBUTE_UID) = sUid
946
                    oAddrow(_XML_ATTRIBUTE_NAME) = sName
947
                    oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
948
                    oAttribute_Dt.Rows.Add(oAddrow)
949
                Catch ex As Exception
950
                End Try
951
            Next
952 76f465d0 Gyusu
            SetConnectionInfo(oLine_Dt, oSymbol_Dt)
953
            _AllLine_DT.Merge(oLine_Dt)
954
            _AllSymbol_DT.Merge(oSymbol_Dt)
955 3acffcee Gyusu
            CLineNo.Dt_Line = oLine_Dt
956
            CLineNo.Dt_Symbol = oSymbol_Dt
957
            CLineNo.Dt_Attribute = oAttribute_Dt
958
            oLineno_list.Add(CLineNo)
959
        Next
960
        Return oLineno_list
961
    End Function
962
963 7e561f5b gaqhf
    Public Sub ConvertPointByImage(ByRef dX As Double, ByRef dY As Double, ByVal dDwgX As Double, ByVal dDwgY As Double)
964 4f359afa Gyusu
965
        Dim calcx As Double = 0
966
        Dim calcy As Double = 0
967
        calcx = (dX * _DWG_X) / dDwgX 'Math.Round((dX * _DWG_X) / dDwgX, 2)
968 76f465d0 Gyusu
        'calcx = Math.Round(calcx, 4, MidpointRounding.)
969
        calcx = Math.Truncate(calcx * 1000) / 1000
970 171ac39d Gyusu
        calcy = _DWG_Y - ((dY * _DWG_Y) / dDwgY) '_DWG_Y - Math.Round((dY * _DWG_Y) / dDwgY, 2)
971 76f465d0 Gyusu
        '   calcy = Math.Round(calcy, 4)
972
        calcy = Math.Truncate(calcy * 1000) / 1000
973 4f359afa Gyusu
        dX = calcx
974
        dY = calcy
975
    End Sub
976 e1cde8f2 Gyusu
    '@brief Convert To SPPID
977
    '@author : Gyusu Park
978
    '@date : 2018-04-10
979
    '@history:
980 171ac39d Gyusu
    Private Sub SplitLocation(ByVal sLocation As String, ByRef dX As Double, ByRef dY As Double)
981
982
        Dim opointstr As String() = Split(sLocation, ",")
983
        If (opointstr.Length > 1) Then
984
            If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
985
                dX = opointstr(0)
986
                dY = opointstr(1)
987
            End If
988
        End If
989
990
    End Sub
991
992
    Private Function Load_DB(ByVal sDBPath As String, ByVal sTableName As String) As DataTable
993 4f359afa Gyusu
994
        Try
995 171ac39d Gyusu
            Dim oDt As New DataTable
996 4f359afa Gyusu
            Dim sConnectionstring As String = "Data Source=" & sDBPath & ";Version=3;Synchronous=Off;UTF8Encoding=True;"
997
            Dim conn As SQLiteConnection = New SQLiteConnection(sConnectionstring)
998
            conn.Open()
999 171ac39d Gyusu
            Dim sQuery As String = "Select * from " & sTableName
1000 4f359afa Gyusu
            Dim cmd As SQLiteCommand = conn.CreateCommand()
1001
            Dim adapter As SQLiteDataAdapter = New SQLiteDataAdapter(sQuery, conn)
1002
            Dim oDataSet As DataSet = New DataSet()
1003
            adapter.Fill(oDataSet)
1004 171ac39d Gyusu
            oDt = oDataSet.Tables(0)
1005
            Return oDt
1006 4f359afa Gyusu
        Catch ex As Exception
1007 171ac39d Gyusu
            Return Nothing
1008 4f359afa Gyusu
        End Try
1009 171ac39d Gyusu
    End Function
1010 4f359afa Gyusu
1011 31d47a80 Gyusu
    Private Function LoadAllDrawing() As DataTable
1012 e1cde8f2 Gyusu
        SetListBoxItems(ListBox_Result, "도면정보 로드중....")
1013 b08338e3 Gyusu
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "도면정보 로드중....")
1014 31d47a80 Gyusu
        Dim oDt As DataTable = Drawing_Dt()
1015 e282643f Gyusu
        Dim sHierarchy As String = My.Settings.Plant_Hierarchy
1016
        Dim files() As String
1017
        files = Directory.GetFiles(sHierarchy, "*.pid", SearchOption.AllDirectories)
1018
        For Each FileName As String In files
1019
            Dim sName As String = FileName
1020 31d47a80 Gyusu
            Dim oAddRow As DataRow = oDt.NewRow()
1021 e282643f Gyusu
            oAddRow("Name") = Path.GetFileNameWithoutExtension(sName)
1022
            oAddRow("Path") = FileName
1023 31d47a80 Gyusu
            oDt.Rows.Add(oAddRow)
1024
        Next
1025
        Return oDt
1026
    End Function
1027
1028 272662f9 Gyusu
    Dim _XMLList As ListView = New ListView()
1029 e282643f Gyusu
1030 171ac39d Gyusu
    Private Function CheckOpenDrawing() As Boolean
1031
        Try
1032
1033
            Dim lobjDatasource As Object
1034
            _Placement = CreateObject("Plaice.Placement", "")
1035
            lobjDatasource = _Placement.PIDDataSource
1036
            Return True
1037
        Catch ex As Exception
1038
            Return False
1039
        End Try
1040
1041
    End Function
1042
1043
1044
    Private Sub Btn_Convert_Click(sender As Object, e As EventArgs) Handles Btn_Convert.Click
1045
        Main_Tab.SelectedIndex = 1
1046
        ListBox_Result.Items.Clear()
1047
        Me.ProgressBar_Status.Visible = True
1048
        ProgressBar_Status.Maximum = 100
1049
        ProgressBar_Status.Value = 0
1050 b08338e3 Gyusu
        InitItemCount()
1051 54b98e09 Gyusu
        _Main_trd = New Thread(AddressOf ThreadConvert)
1052 171ac39d Gyusu
        _Main_trd.IsBackground = True
1053
        _Main_trd.Start()
1054 54b98e09 Gyusu
        FineOPCForm()
1055
    End Sub
1056 171ac39d Gyusu
1057 54b98e09 Gyusu
    Private Sub FineOPCForm()
1058
        _Opc_trd = New Thread(AddressOf ThreadOPCRemove)
1059
        _Opc_trd.IsBackground = True
1060
        _Opc_trd.Start()
1061 171ac39d Gyusu
    End Sub
1062 54b98e09 Gyusu
1063 31d47a80 Gyusu
1064 b08338e3 Gyusu
    Dim _objPIDAutoApp As Object
1065 e282643f Gyusu
1066 b08338e3 Gyusu
    Private Function OpenSPPID(ByVal oDwg_Dt As DataTable, ByVal sDwgName As String) As Boolean
1067
        Dim bCheckOpen As Boolean = False
1068
        '   Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgPath)
1069
        SetListBoxItems(ListBox_Result, sDwgName & " 도면 Open....")
1070
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, sDwgName & " 도면 Open....")
1071
        _objPIDAutoApp = CreateObject("PIDAutomation.Application")
1072 e1cde8f2 Gyusu
1073 b08338e3 Gyusu
        Dim sPath As String = OpenDrawing(oDwg_Dt, sDwgName)
1074
        If sPath <> "" Then
1075
            Process.Start(sPath)
1076
        Else
1077
            Return bCheckOpen
1078
        End If
1079 171ac39d Gyusu
1080 1bfcc921 Gyusu
        Dim bCheckOpenDrawing As Boolean = False
1081
        While (True)
1082
            bCheckOpenDrawing = CheckOpenDrawing()
1083
            If bCheckOpenDrawing = True Then
1084
                bCheckOpen = True
1085
                Exit While
1086
            Else
1087
                Thread.Sleep(2000)
1088
            End If
1089
        End While
1090 171ac39d Gyusu
1091
1092 1bfcc921 Gyusu
        Return bCheckOpen
1093 171ac39d Gyusu
    End Function
1094
1095
    Private Function GetDrawing(ByVal sDwgName As String) As Drawing
1096
        For Each CDrawing In _DrawingsList
1097 559daf6d Gyusu
            If CDrawing.DwgName.ToUpper() = sDwgName.ToUpper() Then
1098 171ac39d Gyusu
                Return CDrawing
1099
            End If
1100
        Next
1101
        Return Nothing
1102
    End Function
1103
1104
    Private Function GetLineNo(ByVal CDrawing As Drawing, ByVal sLineNoUid As String) As Line_no
1105
        For Each CLineNo In CDrawing.Line_nos
1106
            If CLineNo.Uid = sLineNoUid Then
1107
                Return CLineNo
1108
            End If
1109
        Next
1110
        Return Nothing
1111
    End Function
1112
1113 3acffcee Gyusu
    Private Function GetTrimLineNo(ByVal CDrawing As Drawing, ByVal sLineNoUid As String) As Line_no
1114
        For Each CLineNo In CDrawing.TrimLine_nos
1115
            If CLineNo.Uid = sLineNoUid Then
1116
                Return CLineNo
1117
            End If
1118
        Next
1119
        Return Nothing
1120
    End Function
1121
1122
1123 bb2a0c79 Gyusu
1124
    Private Function GetPipeFromConnection(ByVal CDrawing As Drawing, ByVal sSymbolUid As String, ByRef sConnTypeNo As String) As DataTable
1125 6a6d8ab4 Gyusu
        For Each CLineNo In CDrawing.Line_nos
1126
            Dim odt As DataTable = CLineNo.Dt_Line
1127
            If odt.Rows.Count > 0 Then
1128 bb2a0c79 Gyusu
                If odt.Rows(0)(_XML_LINE_Conn1_Uid).ToString = sSymbolUid Then
1129
                    sConnTypeNo = "1"
1130
                    Return odt
1131
                ElseIf odt.Rows(0)(_XML_LINE_Conn2_Uid).ToString() = sSymbolUid Then
1132
                    sConnTypeNo = "2"
1133
                    Return odt
1134 6a6d8ab4 Gyusu
                End If
1135
            End If
1136
        Next
1137 bb2a0c79 Gyusu
        Return New DataTable
1138 6a6d8ab4 Gyusu
    End Function
1139
1140 bb2a0c79 Gyusu
    Private Function GetSymbolFromConnection(ByVal CDrawing As Drawing, ByVal sSymbolUid As String, ByRef sConnTypeNo As String) As DataTable
1141
        For Each CLineNo In CDrawing.Line_nos
1142
            Dim odt As DataTable = CLineNo.Dt_Symbol
1143
            If odt.Rows.Count > 0 Then
1144
                If odt.Rows(0)(_XML_SYMBOL_Conn1_Uid).ToString = sSymbolUid Then
1145
                    sConnTypeNo = "1"
1146
                    Return odt
1147
                ElseIf odt.Rows(0)(_XML_SYMBOL_Conn2_Uid).ToString() = sSymbolUid Then
1148
                    sConnTypeNo = "2"
1149
                    Return odt
1150
                ElseIf odt.Rows(0)(_XML_SYMBOL_Conn3_Uid).ToString() = sSymbolUid Then
1151
                    sConnTypeNo = "3"
1152
                    Return odt
1153
                ElseIf odt.Rows(0)(_XML_SYMBOL_Conn4_Uid).ToString() = sSymbolUid Then
1154
                    sConnTypeNo = "4"
1155
                    Return odt
1156
                End If
1157
            End If
1158
        Next
1159
        Return New DataTable
1160
    End Function
1161 6a6d8ab4 Gyusu
1162
    Private Function GetEqpNo(ByVal CDrawing As Drawing, ByVal sEqpUid As String) As Eqp_no
1163
        For Each CEqpNo In CDrawing.Eqp_nos
1164
            If CEqpNo.Uid = sEqpUid Then
1165
                Return CEqpNo
1166
            End If
1167
        Next
1168
        Return Nothing
1169
    End Function
1170 7e561f5b gaqhf
    Public Function ConvertPointBystring(ByVal sPoint As String, ByRef dX As Double, ByRef dY As Double) As Boolean
1171 171ac39d Gyusu
        Try
1172
            Dim opointstr As String() = Split(sPoint, ",")
1173
            If (opointstr.Length > 1) Then
1174
                If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
1175
                    dX = opointstr(0)
1176
                    dY = opointstr(1)
1177 9e1e7135 Gyusu
1178 171ac39d Gyusu
                Else
1179
                    dX = 0
1180
                    dY = 0
1181
                    Return False
1182
                End If
1183
            End If
1184 e1cde8f2 Gyusu
            Return True
1185
        Catch ex As Exception
1186
            Return False
1187
        End Try
1188 171ac39d Gyusu
    End Function
1189
1190 54b98e09 Gyusu
1191
    Dim _DrawLine_Dt As DataTable = DrawLind_Dt()
1192
1193 e1cde8f2 Gyusu
1194 41e4023e Gyusu
    Private Sub AddModelingLine(ByVal dStart_x As Double, ByVal dStart_y As Double, ByVal dEnd_x As Double, ByVal dEnd_y As Double, ByVal sUid As String)
1195 54b98e09 Gyusu
        Dim oAddRow = _DrawLine_Dt.NewRow()
1196 41e4023e Gyusu
        oAddRow(_XML_LINE_UID) = sUid
1197 54b98e09 Gyusu
        oAddRow(_XML_LINE_STARTPOINT_X) = dStart_x
1198
        oAddRow(_XML_LINE_STARTPOINT_Y) = dStart_y
1199
        oAddRow(_XML_LINE_ENDPOINT_X) = dEnd_x
1200
        oAddRow(_XML_LINE_ENDPOINT_Y) = dEnd_y
1201
        _DrawLine_Dt.Rows.Add(oAddRow)
1202
    End Sub
1203
1204 b08338e3 Gyusu
    Private Sub PlaceEquipment(ByVal sUid As String, ByVal oSymbol_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal sEqpName As String)
1205 41e4023e Gyusu
        Try
1206
            Dim oSymbolRow() As DataRow = oSymbol_Dt.Select(_XML_SYMBOL_UID & " = '" + sUid + "'")
1207
            Dim oAttributeRow() As DataRow
1208
            If oAttribute_Dt.Rows.Count > 0 Then
1209
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
1210
            End If
1211
            If oSymbolRow.Length > 0 Then
1212
                Dim oDatasource As Object = _Placement.PIDDataSource
1213 f291ddcb Gyusu
                Dim sSymbolName As String = oSymbolRow(0)(_XML_SYMBOL_NAME).ToString()
1214 41e4023e Gyusu
                Dim sSymbolCompType As String = oSymbolRow(0)(_XML_SYMBOL_TYPE).ToString()
1215
                Dim sSystemPath As String = oSymbolRow(0)(_XML_SYMBOL_SYSTEMPATH).ToString()
1216
                Dim sClass As String = oSymbolRow(0)(_XML_SYMBOL_CLASS).ToString()
1217
                Dim sLocation As String = oSymbolRow(0)(_XML_SYMBOL_LOCATION).ToString()
1218
                Dim sOriginalPoint As String = oSymbolRow(0)(_XML_SYMBOL_ORIGINALPOINT).ToString()
1219
                Dim dAngle As Double = 0.0
1220
                If IsNumeric(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString()) Then
1221
                    dAngle = Double.Parse(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString())
1222
                End If
1223
                Dim dLocationX As Double = 0.0
1224
                Dim dLocationY As Double = 0.0
1225 f291ddcb Gyusu
                ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY)
1226
                Dim dX As Double = dLocationX
1227
                Dim dY As Double = dLocationY
1228
                ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1229
                Dim oReturnSymbol As LMSymbol = Nothing
1230
                If sSymbolCompType.ToUpper() = "NOZZLE" Then
1231
                    Dim sOwnerUid As String = oSymbolRow(0)(_XML_SYMBOL_OWNER).ToString()
1232
                    Dim oFineRow() As DataRow = _ModelingSymbol_Dt.Select("Uid = '" & sOwnerUid & "'")
1233
                    If oFineRow.Length = 1 Then
1234
                        Dim sEqpModelID As String = oFineRow(0)(_XML_SYMBOL_SPID).ToString()
1235
1236
                        Dim objVessel As LMVessel
1237
                        objVessel = _Placement.PIDDataSource.GetVessel(sEqpModelID)
1238
                        Dim oVesselLocation As LMLocations = objVessel.Locations
1239
                        Dim oEqpSymbol As LMSymbol = _Placement.PIDDataSource.GetSymbol(objVessel.Representations.Nth(1).Id)
1240
1241
                        Dim objNozzle As LMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY,
1242
                                                    TargetItem:=oEqpSymbol.AsLMRepresentation)
1243
                        SetListBoxItems(ListBox_Result, "Place Nozzle.." & sUid & " (" & dLocationX & "," & dLocationY & ")..." & _iEquipmentcnt & " count ")
1244
                        _iNozzlecnt = _iNozzlecnt + 1
1245
                        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Nozzle : " & sUid)
1246
                        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Nozzle Name : " & sSymbolName)
1247
                        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
1248
                        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "OriginalPoint : " & dLocationX & "," & dLocationY)
1249
                        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Nozzle Count : " & _iNozzlecnt)
1250
                    End If
1251
                Else
1252
                    oReturnSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1253 b08338e3 Gyusu
                    SetListBoxItems(ListBox_Result, "Place Equipment.." & sUid & " (" & dLocationX & "," & dLocationY & ")..." & _iEquipmentcnt & " count ")
1254
                    _iEquipmentcnt = _iEquipmentcnt + 1
1255
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Equipment : " & sUid)
1256 f291ddcb Gyusu
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Equipment Name : " & sSymbolName)
1257 b08338e3 Gyusu
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
1258
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "OriginalPoint : " & dLocationX & "," & dLocationY)
1259
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Equipment Count : " & _iEquipmentcnt)
1260 41e4023e Gyusu
                End If
1261 f291ddcb Gyusu
                '모델링 된 Symbol 데이터 테이블 저장
1262
                Dim oAddRow As DataRow = _ModelingSymbol_Dt.NewRow
1263
                oAddRow(_XML_SYMBOL_UID) = sUid
1264
                oAddRow(_XML_SYMBOL_SPID) = oReturnSymbol.ModelItemID
1265
                oAddRow(_XML_SYMBOL_LMSYMBOL) = oReturnSymbol
1266
                oAddRow(_XML_SYMBOL_DRAWING_TF) = "TRUE"
1267
                oAddRow(_XML_SYMBOL_CENTERPOINT_X) = dLocationX
1268
                oAddRow(_XML_SYMBOL_CENTERPOINT_Y) = dLocationY
1269
                _ModelingSymbol_Dt.Rows.Add(oAddRow)
1270 41e4023e Gyusu
            End If
1271
        Catch ex As Exception
1272
        End Try
1273
    End Sub
1274 54b98e09 Gyusu
1275 b08338e3 Gyusu
    Private Function PlacePipingOPC(ByVal sUid As String, ByVal oOPCRow As DataRow, ByVal oAttribute_Dt As DataTable, ByVal sLineNoText As String) As LMSymbol
1276 e4000111 Gyusu
        Try
1277
            Dim oAttributeRow() As DataRow
1278
            If oAttribute_Dt.Rows.Count > 0 Then
1279
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
1280
            End If
1281
            Dim oDatasource As Object = _Placement.PIDDataSource
1282
            Dim sSymbolCompType As String = oOPCRow(_XML_SYMBOL_TYPE).ToString()
1283
            Dim sSystemPath As String = oOPCRow(_XML_SYMBOL_SYSTEMPATH).ToString()
1284
            Dim sClass As String = oOPCRow(_XML_SYMBOL_CLASS).ToString()
1285
            Dim sLocation As String = oOPCRow(_XML_SYMBOL_LOCATION).ToString()
1286
            Dim sOriginalPoint As String = oOPCRow(_XML_SYMBOL_ORIGINALPOINT).ToString()
1287
            Dim dAngle As Double = 0.0
1288
            If IsNumeric(oOPCRow(_XML_SYMBOL_ANGLE).ToString()) Then
1289
                dAngle = Double.Parse(oOPCRow(_XML_SYMBOL_ANGLE).ToString())
1290
            End If
1291
1292
            Dim dLocationX As Double = 0.0
1293
            Dim dLocationY As Double = 0.0
1294
            Dim dX As Double = 0.0
1295
            Dim dY As Double = 0.0
1296 bb2a0c79 Gyusu
            Dim oLMSymbol As LMSymbol = Nothing
1297 e4000111 Gyusu
            If ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY) Then
1298
                dX = dLocationX
1299
                dY = dLocationY
1300
                ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1301
                _iPipintOpccnt = _iPipintOpccnt + 1
1302 bb2a0c79 Gyusu
                oLMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1303 e4000111 Gyusu
                '모델링된 형상은 Drawing True 로 처리
1304 bb2a0c79 Gyusu
                oOPCRow(_XML_SYMBOL_DRAWING_TF) = "TRUE"
1305 b08338e3 Gyusu
                SetListBoxItems(ListBox_Result, "Place Piping OPC.." & sUid & " (" & dLocationX & "," & dLocationY & ")..." & _iPipintOpccnt & " count ")
1306
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Piping OPC : " & sUid & "")
1307
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "LineNo : " & sLineNoText)
1308
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection1 : " & oOPCRow(_XML_SYMBOL_Conn1_Uid).ToString())
1309
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection2 : " & oOPCRow(_XML_SYMBOL_Conn2_Uid).ToString())
1310
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
1311
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "OriginalPoint : " & dLocationX & "," & dLocationY)
1312
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "OPC Count : " & _iPipintOpccnt)
1313 e4000111 Gyusu
1314
                Dim dConn_X1 As Double, dConn_Y1 As Double, dConn_X2 As Double, dConn_Y2 As Double
1315
                _Placement.PIDConnectPointLocation(oLMSymbol, 1, dConn_X1, dConn_Y1)
1316
                _Placement.PIDConnectPointLocation(oLMSymbol, 2, dConn_X2, dConn_Y2)
1317
1318 bb2a0c79 Gyusu
                'Dim oAddrow As DataRow = _ResultModeling_DT.NewRow()
1319
                'oAddrow(_Modeling_Uid) = sUid
1320
                'oAddrow(_Modeling_Location_X) = dLocationX
1321
                'oAddrow(_Modeling_Location_Y) = dLocationY
1322
                'oAddrow(_Modeling_LineNoUid) = sLineUid
1323
                'oAddrow(_Modeling_Type) = sSymbolCompType
1324
                'oAddrow(_Modeling_Connection1_X) = dConn_X1
1325
                'oAddrow(_Modeling_Connection1_Y) = dConn_Y1
1326
                'oAddrow(_Modeling_Connection2_X) = dConn_X2
1327
                'oAddrow(_Modeling_Connection2_X) = dConn_Y2
1328
                'oAddrow(_Modeling_LMSymbol) = oLMSymbol
1329
1330
                '_ResultModeling_DT.Rows.Add(oAddrow)
1331 e4000111 Gyusu
            End If
1332
            _Itemcnt = _Itemcnt + 1
1333
            Dim dCalcProgressValue As Double = (_Itemcnt / _allItem) * 100
1334
            SetProgressbar(ProgressBar_Status, dCalcProgressValue)
1335
            Label_Progress.Text = Math.Round(dCalcProgressValue, 0) & "%"
1336 bb2a0c79 Gyusu
            Return oLMSymbol
1337 e4000111 Gyusu
        Catch ex As Exception
1338
1339
        End Try
1340 bb2a0c79 Gyusu
        Return Nothing
1341 e4000111 Gyusu
1342 bb2a0c79 Gyusu
    End Function
1343 e4000111 Gyusu
1344 76f465d0 Gyusu
    Private Sub AddProgress()
1345
        _Itemcnt = _Itemcnt + 1
1346
        Dim dCalcProgressValue As Double = (_Itemcnt / _allItem) * 100
1347
        SetProgressbar(ProgressBar_Status, dCalcProgressValue)
1348
        Label_Progress.Text = Math.Round(dCalcProgressValue, 0) & "%"
1349
    End Sub
1350 e4000111 Gyusu
    Private Function DrawSymbol(ByVal sUid As String, ByVal oSymbol_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal oLine_Dt As DataTable) As Boolean
1351 171ac39d Gyusu
        Try
1352 e282643f Gyusu
1353 171ac39d Gyusu
            Dim oSymbolRow() As DataRow = oSymbol_Dt.Select(_XML_SYMBOL_UID & " = '" + sUid + "'")
1354 1bfcc921 Gyusu
            Dim oAttributeRow() As DataRow
1355 6a6d8ab4 Gyusu
            If oAttribute_Dt.Rows.Count > 0 Then
1356 460d6abd Gyusu
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
1357 6a6d8ab4 Gyusu
            End If
1358
1359 171ac39d Gyusu
            If oSymbolRow.Length > 0 Then
1360
                Dim oDatasource As Object = _Placement.PIDDataSource
1361
                Dim sSymbolCompType As String = oSymbolRow(0)(_XML_SYMBOL_TYPE).ToString()
1362
                Dim sSystemPath As String = oSymbolRow(0)(_XML_SYMBOL_SYSTEMPATH).ToString()
1363 54b98e09 Gyusu
                Dim sClass As String = oSymbolRow(0)(_XML_SYMBOL_CLASS).ToString()
1364 171ac39d Gyusu
                Dim sLocation As String = oSymbolRow(0)(_XML_SYMBOL_LOCATION).ToString()
1365 9e1e7135 Gyusu
                Dim sOriginalPoint As String = oSymbolRow(0)(_XML_SYMBOL_ORIGINALPOINT).ToString()
1366 171ac39d Gyusu
                Dim dAngle As Double = 0.0
1367
                If IsNumeric(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString()) Then
1368
                    dAngle = Double.Parse(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString())
1369
                End If
1370
1371
                Dim objSymbol As LMSymbol
1372 9e1e7135 Gyusu
                Dim dLocationX As Double = 0.0
1373
                Dim dLocationY As Double = 0.0
1374 171ac39d Gyusu
                Dim dX As Double = 0.0
1375
                Dim dY As Double = 0.0
1376
1377 9e1e7135 Gyusu
                If ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY) Then
1378
                    dX = dLocationX
1379
                    dY = dLocationY
1380 54b98e09 Gyusu
                    If sSymbolCompType = "" Or sSymbolCompType = "Piping OPC's" Then
1381
                        FindConnectionLine(oLine_Dt, dX, dY)
1382
                    End If
1383
1384 9e1e7135 Gyusu
                    ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1385 e4000111 Gyusu
                    Dim oInstrument As LMInstrument
1386 54b98e09 Gyusu
                    If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
1387 9e1e7135 Gyusu
                        _iInstrumentcnt = _iInstrumentcnt + 1
1388 171ac39d Gyusu
                        objSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1389 6a6d8ab4 Gyusu
                        SetListBoxItems(ListBox_Result, "Place Instrument..(" & dLocationX & "," & dLocationY & ")..." & _iInstrumentcnt & " count ")
1390 171ac39d Gyusu
                        oInstrument = oDatasource.GetInstrument(objSymbol.ModelItemID)
1391 6a6d8ab4 Gyusu
                        Try
1392
                            If oAttributeRow.Length > 0 Then
1393
                                For Each oAttribute In oAttributeRow
1394 54b98e09 Gyusu
                                    Try
1395
                                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
1396
                                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
1397
                                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
1398
                                        oInstrument.Attributes(sSPPIDAttribute).Value = sPIDValue
1399
                                    Catch ex As Exception
1400
1401
                                    End Try
1402
1403 6a6d8ab4 Gyusu
                                Next
1404
                                oInstrument.Commit()
1405
                            End If
1406
                        Catch ex As Exception
1407
                        End Try
1408 54b98e09 Gyusu
                    ElseIf sSymbolCompType.ToUpper() = _DB_FITTINGS.ToUpper() Then
1409 9e1e7135 Gyusu
                        _iValvecnt = _iValvecnt + 1
1410 171ac39d Gyusu
                        _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1411 6a6d8ab4 Gyusu
                        SetListBoxItems(ListBox_Result, "Place Valve..(" & dLocationX & "," & dLocationY & ")..." & _iValvecnt & " count ")
1412 171ac39d Gyusu
1413 54b98e09 Gyusu
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_FITTINGS.ToUpper() Then
1414 9e1e7135 Gyusu
                        _iFittingcnt = _iFittingcnt + 1
1415 d039e347 Gyusu
                        If sSystemPath.Contains(",") Then
1416
1417
                            Dim sDuplicatePath As String() = sSystemPath.Split(",")
1418
                            Dim sMainSymbol As String = ""
1419
                            Dim sSubSymbol As String = ""
1420
                            For Each sPath In sDuplicatePath
1421
                                If sMainSymbol = "" Then
1422
                                    sMainSymbol = sPath.Replace(vbLf, "")
1423
                                Else
1424
                                    sSubSymbol = sPath.Replace(vbLf, "")
1425
                                End If
1426
                            Next
1427
                            Dim oSymbolObj As LMSymbol = _Placement.PIDPlaceSymbol(sMainSymbol, dX, dY, , dAngle)
1428
                            Dim dConnpos_x As Double = 0.0
1429
                            Dim dConnpos_y As Double = 0.0
1430
                            _Placement.PIDConnectPointLocation(oSymbolObj, 2, dConnpos_x, dConnpos_y)
1431
                            '   _Placement.PIDPlaceSymbol(sSubSymbol, dConnpos_x, dConnpos_y, dAngle, TargetItem:=oSymbolObj.AsLMRepresentation)
1432
                            _Placement.PIDPlaceSymbol(sSubSymbol, dConnpos_x, dConnpos_y,, dAngle)
1433
1434
                        Else
1435
                            _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1436
                        End If
1437
1438
1439 6a6d8ab4 Gyusu
                        SetListBoxItems(ListBox_Result, "Place Fitting..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1440 54b98e09 Gyusu
                    ElseIf sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() And sClass.ToUpper() = _SYMBOL_ACTUATORS.ToUpper() Then
1441 d039e347 Gyusu
                        _iFittingcnt = _iFittingcnt + 1
1442
                        Dim sDuplicatePath As String() = sSystemPath.Split(",")
1443
                        Dim sMainSymbol As String = ""
1444
                        Dim sSubSymbol As String = ""
1445
                        For Each sPath In sDuplicatePath
1446
                            If sMainSymbol = "" Then
1447
                                sMainSymbol = sPath.Replace(vbLf, "")
1448
                            Else
1449
                                sSubSymbol = sPath.Replace(vbLf, "")
1450
                            End If
1451
                        Next
1452
                        Dim oSymbolObj As LMSymbol = _Placement.PIDPlaceSymbol(sMainSymbol, dX, dY, , dAngle)
1453
                        Dim dSymbolpos_x As Double = oSymbolObj.XCoordinate
1454
                        Dim dSymbolpos_y As Double = oSymbolObj.YCoordinate
1455
                        _Placement.PIDPlaceSymbol(sSubSymbol, dSymbolpos_x, dSymbolpos_y, , dAngle, TargetItem:=oSymbolObj.AsLMAItem)
1456
1457 171ac39d Gyusu
                    Else
1458 9e1e7135 Gyusu
                        _iFittingcnt = _iFittingcnt + 1
1459 171ac39d Gyusu
                        _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1460 6a6d8ab4 Gyusu
                        SetListBoxItems(ListBox_Result, "Place Fitting..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
1461 171ac39d Gyusu
                    End If
1462 e4000111 Gyusu
1463
                End If
1464 41e4023e Gyusu
                _Itemcnt = _Itemcnt + 1
1465
                Dim dCalcProgressValue As Double = (_Itemcnt / _allItem) * 100
1466
                SetProgressbar(ProgressBar_Status, dCalcProgressValue)
1467
                Label_Progress.Text = Math.Round(dCalcProgressValue, 0) & "%"
1468
            End If
1469 171ac39d Gyusu
1470 54b98e09 Gyusu
        Catch ex As Exception
1471
            Return False
1472
        End Try
1473
    End Function
1474
1475
1476
    Private Sub FindConnectionLine(ByVal oLine_Dt As DataTable, ByRef dx As Double, ByRef dy As Double)
1477
1478
        Try
1479
            For Each oRow In oLine_Dt.Rows
1480
                Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1481
                Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1482
                Dim d기준s_x As Double = 0
1483
                Dim d기준s_y As Double = 0
1484
                Dim d기준e_x As Double = 0
1485
                Dim d기준e_y As Double = 0
1486
                ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1487
                ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1488
                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
1489
                    dx = d기준s_x
1490
                    dy = d기준s_y
1491
                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
1492
                    dx = d기준e_x
1493
                    dy = d기준e_y
1494
                End If
1495
            Next
1496
        Catch ex As Exception
1497
        End Try
1498
    End Sub
1499
1500
1501
    Dim _라인보정기준값 As Integer = 10
1502
1503
    Private Function 라인보정(ByRef oLine_Dt As DataTable, ByVal sUid As String, ByRef dsx As Double, ByRef dsy As Double,
1504
                                      ByRef dex As Double, ByRef dey As Double)
1505
        Try
1506
            Dim bCheck라인 As Boolean = False
1507
            '일치하는 Line 찾기
1508
            For Each oRow In oLine_Dt.Rows
1509
                Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1510
                Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1511
                Dim sBUid As String = oRow(_XML_LINE_UID).ToString()
1512
                If sBUid <> sUid Then
1513
                    Dim d기준s_x As Double = 0
1514
                    Dim d기준s_y As Double = 0
1515
                    Dim d기준e_x As Double = 0
1516
                    Dim d기준e_y As Double = 0
1517
                    ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1518
                    ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1519
1520
                    If (dsx = d기준s_x And dsy = d기준s_y) Or (dsx = d기준e_x And dsy = d기준e_y) Or
1521
                       (dex = d기준s_x And dey = d기준s_y) Or (dex = d기준e_x And dey = d기준e_y) Then
1522
                        bCheck라인 = True
1523
                    End If
1524
                End If
1525
            Next
1526
1527
            If bCheck라인 = False Then
1528
                For Each oRow In oLine_Dt.Rows
1529
                    Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1530
                    Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1531
                    Dim sBUid As String = oRow(_XML_LINE_UID).ToString()
1532
                    If sBUid <> sUid Then
1533
                        Dim d기준s_x As Double = 0
1534
                        Dim d기준s_y As Double = 0
1535
                        Dim d기준e_x As Double = 0
1536
                        Dim d기준e_y As Double = 0
1537
                        ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1538
                        ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1539
                        If ((dsx - _라인보정기준값 <= d기준s_x And dsx + _라인보정기준값 >= d기준s_x) And (dsy - _라인보정기준값 <= d기준s_y And dsy + _라인보정기준값 >= d기준s_y)) Then
1540
                            oRow(_XML_LINE_STARTPOINT) = dsx & "," & dsy
1541
                            bCheck라인 = True
1542
                            Exit For
1543
                        ElseIf ((dsx - _라인보정기준값 <= d기준e_x And dsx + _라인보정기준값 >= d기준e_x) And (dsy - _라인보정기준값 <= d기준e_y And dsy + _라인보정기준값 >= d기준e_y)) Then
1544
                            oRow(_XML_LINE_ENDPOINT) = dsx & "," & dsy
1545
                            bCheck라인 = True
1546
                            Exit For
1547
                        ElseIf ((dex - _라인보정기준값 <= d기준s_x And dex + _라인보정기준값 >= d기준s_x) And (dey - _라인보정기준값 <= d기준s_y And dey + _라인보정기준값 >= d기준s_y)) Then
1548
                            oRow(_XML_LINE_STARTPOINT) = dex & "," & dey
1549
                            bCheck라인 = True
1550
                            Exit For
1551
                        ElseIf ((dex - _라인보정기준값 <= d기준e_x And dex + _라인보정기준값 >= d기준e_x) And (dey - _라인보정기준값 <= d기준e_y And dey + _라인보정기준값 >= d기준e_y)) Then
1552
                            oRow(_XML_LINE_ENDPOINT) = dex & "," & dey
1553
                            bCheck라인 = True
1554
                            Exit For
1555
                        End If
1556
1557
                    End If
1558
                Next
1559 171ac39d Gyusu
            End If
1560
1561 54b98e09 Gyusu
            Return bCheck라인
1562 171ac39d Gyusu
        Catch ex As Exception
1563
            Return False
1564
        End Try
1565 54b98e09 Gyusu
1566
1567 171ac39d Gyusu
    End Function
1568
1569 460d6abd Gyusu
    Private Function FindOverlapLine(ByVal oLine_Dt As DataTable, ByVal sUid As String, ByRef dsx As Double, ByRef dsy As Double,
1570
                                      ByRef dex As Double, ByRef dey As Double)
1571
        Try
1572
            Dim bCheckOverlap As Boolean = False
1573
            For Each oRow In oLine_Dt.Rows
1574
                Dim sStartpoint As String = oRow(_XML_LINE_STARTPOINT).ToString()
1575
                Dim sEndpoint As String = oRow(_XML_LINE_ENDPOINT).ToString()
1576
                Dim sBUid As String = oRow(_XML_LINE_UID).ToString()
1577
                If sBUid <> sUid Then
1578
                    Dim d기준s_x As Double = 0
1579
                    Dim d기준s_y As Double = 0
1580
                    Dim d기준e_x As Double = 0
1581
                    Dim d기준e_y As Double = 0
1582
                    ConvertPointBystring(sStartpoint, d기준s_x, d기준s_y)
1583
                    ConvertPointBystring(sEndpoint, d기준e_x, d기준e_y)
1584 54b98e09 Gyusu
                    If (d기준s_x <= dsx And d기준e_x >= dex And
1585
                        d기준s_y <= dsy And d기준e_y >= dey) Then
1586 460d6abd Gyusu
                        '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1587
                        If dsy - d기준s_y > d기준e_y - dey Then
1588
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1589
                            If dResultCalc < 10 Then
1590
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1591
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1592
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1593
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1594
                                If dCalcStartY = 0 Then
1595
                                    dey = d기준e_y
1596
                                Else
1597
                                    dey = dCalcStartY
1598
                                End If
1599
                            End If
1600
                        Else
1601 abb01e6c Gyusu
                            '  Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1602
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1603 460d6abd Gyusu
                            If dResultCalc < 10 Then
1604
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1605
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1606
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1607
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1608
                                If dCalcStartY = 0 Then
1609
                                    dsy = d기준s_y
1610
                                Else
1611
                                    dsy = dCalcStartY
1612
                                End If
1613
                            End If
1614
                        End If
1615
                        bCheckOverlap = True
1616
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
1617
                            d기준s_y <= dey And d기준e_y >= dsy Then
1618
                        '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1619
                        If dey - d기준s_y > d기준e_y - dsy Then
1620
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1621
                            If dResultCalc < 10 Then
1622
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1623
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1624
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1625
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1626
                                If dCalcStartY = 0 Then
1627 abb01e6c Gyusu
                                    dsy = d기준e_y
1628 460d6abd Gyusu
                                Else
1629 abb01e6c Gyusu
                                    dsy = dCalcStartY
1630 460d6abd Gyusu
                                End If
1631
1632
                            End If
1633
                            '겹쳐서 오버되는 길이가 오버되지 않는 길이의 10%미만일때 겹치는 y축좌표를 겹치는점까지 설정
1634
                        Else
1635 abb01e6c Gyusu
                            '  Dim dResultCalc As Double = (Math.Abs((dsy - d기준s_y)) / Math.Abs((d기준e_y - dey))) * 100
1636
                            Dim dResultCalc As Double = ((d기준e_y - dey) / (dsy - d기준s_y)) * 100
1637 460d6abd Gyusu
                            If dResultCalc < 10 Then
1638
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1639
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1640
                                Dim dCalcStartX As Double = Math.Abs(dsx - d기준s_x)
1641
                                Dim dCalcStartY As Double = (dCalcY * dCalcStartX) / dCalcX
1642
                                If dCalcStartY = 0 Then
1643 abb01e6c Gyusu
                                    dey = d기준e_y
1644 460d6abd Gyusu
                                Else
1645 abb01e6c Gyusu
                                    dey = dCalcStartY
1646 460d6abd Gyusu
                                End If
1647
                            End If
1648
                        End If
1649
                        bCheckOverlap = True
1650
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
1651
                            d기준s_y <= dey And d기준e_y >= dsy Then
1652
1653
                        If dsx - d기준s_x > d기준e_x - dex Then
1654
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1655
                            If dResultCalc < 10 Then
1656
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1657
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1658
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1659
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1660
                                If dCalcStartX = 0 Then
1661
                                    dex = d기준e_x
1662
                                Else
1663
                                    dex = dCalcStartX
1664
                                End If
1665
                            End If
1666
                        Else
1667 abb01e6c Gyusu
                            '  Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1668
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1669 460d6abd Gyusu
                            If dResultCalc < 10 Then
1670
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1671
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1672
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1673
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1674
                                If dCalcStartX = 0 Then
1675
                                    dsx = d기준s_x
1676
                                Else
1677
                                    dsx = dCalcStartX
1678
                                End If
1679
                            End If
1680
                        End If
1681
                        bCheckOverlap = True
1682
                    ElseIf (d기준s_x <= dsx And d기준e_x >= dex) And
1683
                            d기준s_y <= dey And d기준e_y >= dsy Then
1684
1685
                        If dex - d기준s_x > d기준e_x - dsx Then
1686
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1687
                            If dResultCalc < 10 Then
1688
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1689
                                Dim dCalcY As Double = Math.Abs(d기준s_y - d기준e_y)
1690
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1691
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1692
                                If dCalcStartX = 0 Then
1693 abb01e6c Gyusu
                                    dsx = d기준e_x
1694 460d6abd Gyusu
                                Else
1695 abb01e6c Gyusu
                                    dsx = dCalcStartX
1696 460d6abd Gyusu
                                End If
1697
                            End If
1698
                        Else
1699 abb01e6c Gyusu
                            ' Dim dResultCalc As Double = ((dsy - d기준s_y) / (d기준e_y - dey)) * 100
1700
                            Dim dResultCalc As Double = ((d기준e_x - dex) / (dsx - d기준s_x)) * 100
1701 460d6abd Gyusu
                            If dResultCalc < 10 Then
1702
                                Dim dCalcX As Double = Math.Abs(d기준e_x - d기준s_x)
1703
                                Dim dCalcY As Double = Math.Abs(d기준e_y - d기준s_y)
1704
                                Dim dCalcStartY As Double = Math.Abs(dsy - d기준s_y)
1705
                                Dim dCalcStartX As Double = (dCalcX * dCalcStartY) / dCalcY
1706
                                If dCalcStartX = 0 Then
1707 abb01e6c Gyusu
                                    dex = d기준s_x
1708 460d6abd Gyusu
                                Else
1709 abb01e6c Gyusu
                                    dex = dCalcStartX
1710 460d6abd Gyusu
                                End If
1711
                            End If
1712
1713
                        End If
1714
                        bCheckOverlap = True
1715
                    End If
1716
                End If
1717
            Next
1718 3acffcee Gyusu
1719 460d6abd Gyusu
            Return bCheckOverlap
1720
        Catch ex As Exception
1721
            Return False
1722
        End Try
1723
    End Function
1724
1725
    Private Sub CalcSperateLine(ByRef dStartX As Double, ByRef dStartY As Double,
1726
                                      ByRef dEndX As Double, ByRef dEndY As Double)
1727
        Try
1728 54b98e09 Gyusu
            Dim dRange As Double = 1 'Line 전체 길이의 10%씩 늘이기
1729 460d6abd Gyusu
            If Math.Abs(dStartX - dEndX) > Math.Abs(dStartY - dEndY) Then
1730 54b98e09 Gyusu
                Dim dCalc_x As Double = Math.Abs(dStartX - dEndX) * 0.1
1731 460d6abd Gyusu
                If dStartX > dEndX Then
1732
                    dStartX = dStartX + dCalc_x
1733
                    dEndX = dEndX - dCalc_x
1734
                Else
1735
                    dEndX = dEndX + dCalc_x
1736
                    dStartX = dStartX - dCalc_x
1737
                End If
1738
            Else
1739 54b98e09 Gyusu
                Dim dCalc_y As Double = Math.Abs(dStartY - dEndY) * 0.1
1740 460d6abd Gyusu
                If dStartY > dEndY Then
1741
                    dStartY = dStartY + dCalc_y
1742
                    dEndY = dEndY - dCalc_y
1743
                Else
1744
                    dEndY = dEndY + dCalc_y
1745
                    dStartY = dStartY - dCalc_y
1746
                End If
1747
            End If
1748
1749
        Catch ex As Exception
1750
1751
        End Try
1752
1753
1754
    End Sub
1755
1756 3acffcee Gyusu
    Private Function DrawLineNo(ByVal oPipeRun_Dt As DataTable, ByVal CLine_No As Line_no) As Boolean
1757 171ac39d Gyusu
        Try
1758
            Dim oDatasource As Object = _Placement.PIDDataSource
1759
            Dim sLocation = CLine_No.Location
1760 9e1e7135 Gyusu
            Dim dLocationx As Double = 0.0
1761
            Dim dLocationy As Double = 0.0
1762 171ac39d Gyusu
            Dim dX As Double = 0.0
1763
            Dim dY As Double = 0.0
1764 9e1e7135 Gyusu
            If ConvertPointBystring(sLocation, dLocationx, dLocationy) Then
1765
                dX = dLocationx
1766
                dY = dLocationy
1767 3acffcee Gyusu
                For Each oRow In oPipeRun_Dt.Rows
1768
                    Dim dStartx As Double = Double.Parse(oRow("startx").ToString())
1769
                    Dim dStarty As Double = Double.Parse(oRow("starty").ToString())
1770
                    Dim dEndx As Double = Double.Parse(oRow("endx").ToString())
1771
                    Dim dEndy As Double = Double.Parse(oRow("endy").ToString())
1772
                    Dim dStartSum As Double = Math.Abs(dStartx - dLocationx) + Math.Abs(dStarty - dLocationy)
1773
                    Dim dEndSum As Double = Math.Abs(dEndx - dLocationx) + Math.Abs(dEndy - dLocationy)
1774
                    If dStartSum > dEndSum Then
1775
                        oRow("value") = dEndSum
1776
                    Else
1777
                        oRow("value") = dStartSum
1778 171ac39d Gyusu
                    End If
1779
                Next
1780 3acffcee Gyusu
                Dim dataView As New DataView(oPipeRun_Dt)
1781
                dataView.Sort = " value asc"
1782
                Dim oDt As DataTable = dataView.ToTable()
1783
                If oDt.Rows.Count > 0 Then
1784
                    Try
1785
                        Dim oPiperun As LMPipeRun = CType(oDt.Rows(0)("Piperun"), LMPipeRun)
1786
                        ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1787
                        Dim dLineNoLocation(2) As Double
1788
                        dLineNoLocation(1) = dX
1789
                        dLineNoLocation(2) = dY
1790
                        'Label
1791
                        Dim sSystemPath As String = CLine_No.SystemPath
1792
                        Dim dAngle As Double = CLine_No.Angle
1793
                        Dim labelpersist As LMLabelPersist
1794
                        For Each representation In oPiperun.Representations
1795
                            If representation.RepresentationType = "Connector" Then
1796
                                labelpersist = _Placement.PIDPlaceLabel(sSystemPath,
1797
                                dLineNoLocation,, dAngle, LabeledItem:=representation)
1798
                                _iPipeLineNocnt = _iPipeLineNocnt + 1
1799 b08338e3 Gyusu
                                SetListBoxItems(ListBox_Result, "Place PipeLineNo Label.." & CLine_No.Uid & " (" & dLocationx & "," & dLocationy & ")..." & _iPipeLineNocnt & " count ")
1800
                                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Pipe : " & CLine_No.Uid & "")
1801
                                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "LineNo : " & CLine_No.Text)
1802
                                'ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
1803
                                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Origina lPoint : " & dLocationx & "," & dLocationy)
1804
                                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "PipeLineNo Count : " & _iPipeLineNocnt)
1805 3acffcee Gyusu
                            End If
1806
                        Next
1807
                    Catch ex As Exception
1808
                    End Try
1809
                End If
1810 171ac39d Gyusu
                Return True
1811
            Else
1812
                Return False
1813
            End If
1814
        Catch ex As Exception
1815
            Return False
1816
        End Try
1817
    End Function
1818
1819 9e1e7135 Gyusu
1820
    Private Sub InitItemCount()
1821
        _iPipeLineNocnt = 0
1822 b08338e3 Gyusu
        _iPipecnt = 1
1823
        _iFittingcnt = 1
1824 9e1e7135 Gyusu
        _iValvecnt = 0
1825
        _iInstrumentcnt = 0
1826
        _iEquipmentcnt = 0
1827 3acffcee Gyusu
        _iNozzlecnt = 1
1828 e4000111 Gyusu
        _iPipintOpccnt = 0
1829 9e1e7135 Gyusu
    End Sub
1830 171ac39d Gyusu
1831 41e4023e Gyusu
    Private Function GetAllCheckNodeCount() As Integer
1832
        _allItem = 0
1833
        For i = 0 To Tree_Result.Nodes.Count - 1
1834
            For j = 0 To Tree_Result.Nodes(i).Nodes.Count - 1
1835
                For k = 0 To Tree_Result.Nodes(i).Nodes(j).Nodes.Count - 1
1836
                    For l = 0 To Tree_Result.Nodes(i).Nodes(j).Nodes(k).Nodes.Count - 1
1837
                        If Tree_Result.Nodes(i).Nodes(j).Nodes(k).Nodes(l).Checked = True Then
1838
                            _allItem = _allItem + 1
1839
                        End If
1840
                    Next
1841
                Next
1842
            Next
1843
        Next
1844
        Return _allItem
1845
    End Function
1846 54b98e09 Gyusu
1847
1848 e4000111 Gyusu
    ''' <summary>
1849
    ''' Equipment 모델링
1850
    ''' </summary>
1851
    Private Sub EquipmentModeling(ByVal oDwg_Dt As DataTable)
1852
        For Each oDrwing As TreeNode In Tree_Result.Nodes
1853
            For Each oDwgNode As TreeNode In oDrwing.Nodes
1854
                Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
1855
                Dim CDrawing As Drawing = GetDrawing(sDwgName)
1856
                If CDrawing IsNot Nothing Then
1857
                    If OpenSPPID(oDwg_Dt, oDwgNode.Text) Then
1858 b08338e3 Gyusu
1859 e4000111 Gyusu
                        For Each oNode As TreeNode In oDwgNode.Nodes
1860
                            Dim iItemcnt As Integer = 0
1861
                            Dim sNodeUid As String = oNode.Name
1862
                            Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
1863
                            '1.Equipment
1864
                            '2.Piping OPC
1865
                            '3.OPC 시작되는 Line
1866
                            'Equipment 생성
1867
                            Dim CEqpNo As Eqp_no = GetEqpNo(CDrawing, sNodeUid)
1868
                            If CEqpNo IsNot Nothing Then
1869
                                Dim oSymbol_Dt As DataTable = CEqpNo.Dt_Equipment
1870
                                Dim oAttribute_Dt As DataTable = CEqpNo.Dt_Attribute
1871
                                For Each oSymbolNode As TreeNode In oNode.Nodes
1872
                                    If oSymbolNode.Checked Then
1873
                                        Dim sUid As String = oSymbolNode.Name
1874 b08338e3 Gyusu
                                        PlaceEquipment(sUid, oSymbol_Dt, oAttribute_Dt, CEqpNo.Text)
1875 e4000111 Gyusu
                                    End If
1876
                                Next
1877
                            End If
1878
                        Next
1879
                    End If
1880
                End If
1881
            Next
1882
        Next
1883
    End Sub
1884
1885 bb2a0c79 Gyusu
    Private Sub ManualCheckNode(ByRef oDt As DataTable)
1886
        For Each oDrwing As TreeNode In Tree_Result.Nodes
1887
            For Each oDwgNode As TreeNode In oDrwing.Nodes
1888
                For Each oNode As TreeNode In oDwgNode.Nodes
1889
                    For Each oSymbolNode As TreeNode In oNode.Nodes
1890
                        Dim sUid As String = oSymbolNode.Name
1891 76f465d0 Gyusu
                        'Dim oSelectRows() As DataRow = oDt.Select("[" & _XML_SYMBOL_UID & "] = '" & sUid &
1892 3b7a4470 Gyusu
                        '                                      "' And [" & _XML_SYMBOL_DRAWING_TF & "] = 'False'")
1893
                        If oSymbolNode.Checked Then
1894
                            Dim oSelectRows() As DataRow = oDt.Select("[" & _XML_SYMBOL_UID & "] = '" & sUid & "'")
1895
                            If oSelectRows.Length = 1 Then
1896
                                oSelectRows(0)(_XML_SYMBOL_DRAWING_TF) = "FALSE"
1897
                                If oSymbolNode.Checked Then
1898
                                    oSelectRows(0)(_XML_SYMBOL_Check) = "TRUE"
1899
                                Else
1900
                                    oSelectRows(0)(_XML_SYMBOL_Check) = "FALSE"
1901
                                End If
1902 bb2a0c79 Gyusu
                            End If
1903
                        End If
1904
                    Next
1905
                Next
1906
            Next
1907
        Next
1908
1909
    End Sub
1910 b08338e3 Gyusu
1911 f9b63682 Gyusu
    Private Function FinalSymbolModeling(ByVal oCurrentSymbolRow As DataRow, ByVal oLine_Dt As DataTable, ByVal oSymbol_Dt As DataTable,
1912
                                  ByVal oAttribute_Dt As DataTable) As String
1913
        Dim sReturnUid As String = ""
1914
        Dim sOriginalPoint As String = ""
1915
        Dim dOriginal_x As Double = 0.0
1916
        Dim dOriginal_y As Double = 0.0
1917
        Dim dConn1_x As Double = 0.0
1918
        Dim dConn1_y As Double = 0.0
1919
        Dim dConn2_x As Double = 0.0
1920
        Dim dConn2_y As Double = 0.0
1921
        Dim dConn3_x As Double = 0.0
1922
        Dim dConn3_y As Double = 0.0
1923
        Dim dConn4_x As Double = 0.0
1924
        Dim dConn4_y As Double = 0.0
1925
        Dim sUid As String = oCurrentSymbolRow(_XML_SYMBOL_UID)
1926
        Dim sSystemPath As String = oCurrentSymbolRow(_XML_SYMBOL_SYSTEMPATH).ToString()
1927
        Dim dAngle As Double = oCurrentSymbolRow(_XML_SYMBOL_ANGLE)
1928
        Dim sLineNoText As String = oCurrentSymbolRow(_XML_LINENO_TEXT)
1929
        Dim sLineNoUid As String = oCurrentSymbolRow(_XML_LINE_LINENOUID).ToString()
1930
        sOriginalPoint = oCurrentSymbolRow(_XML_SYMBOL_ORIGINALPOINT).ToString()
1931 76f465d0 Gyusu
        Dim sSymbolCompType As String = oCurrentSymbolRow(_XML_SYMBOL_TYPE).ToString()
1932 f9b63682 Gyusu
        ConvertPointBystring(sOriginalPoint, dOriginal_x, dOriginal_y)
1933
        ConvertPointByImage(dOriginal_x, dOriginal_y, _IMG_X, _IMG_Y)
1934 9c86a823 Gyusu
        Dim sChildItem As String = oCurrentSymbolRow(_XML_SYMBOL_CHILD)
1935 f9b63682 Gyusu
        'Connection 정보 체크, 모델링 되어 있는지 유무
1936
        '양 커넥션의 모델링 유무를 체크한다.
1937
        Dim sConn1Uid As String = oCurrentSymbolRow(_XML_SYMBOL_Conn1_Uid).ToString()
1938
        Dim sConn2Uid As String = oCurrentSymbolRow(_XML_SYMBOL_Conn2_Uid).ToString()
1939
        Dim sConn3Uid As String = oCurrentSymbolRow(_XML_SYMBOL_Conn3_Uid).ToString()
1940
        Dim sConn4Uid As String = oCurrentSymbolRow(_XML_SYMBOL_Conn4_Uid).ToString()
1941
        Dim sConn1Type As String = ""
1942
        Dim sConn2Type As String = ""
1943
        Dim sConn3Type As String = ""
1944
        Dim sConn4Type As String = ""
1945
        Dim oConn1Rows() As DataRow = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "] = '" & sConn1Uid & "'")
1946
        If oConn1Rows.Length = 0 Then
1947
            oConn1Rows = oLine_Dt.Select("[" & _XML_LINE_UID & "] = '" & sConn1Uid & "'")
1948
            If oConn1Rows.Length = 1 Then
1949
                sConn1Type = "Line"
1950 b08338e3 Gyusu
            End If
1951 f9b63682 Gyusu
        Else
1952
            sConn1Type = "Symbol"
1953
        End If
1954 b08338e3 Gyusu
1955 f9b63682 Gyusu
        Dim oConn2Rows() As DataRow = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "] = '" & sConn2Uid & "'")
1956
        If oConn2Rows.Length = 0 Then
1957
            oConn2Rows = oLine_Dt.Select("[" & _XML_LINE_UID & "] = '" & sConn2Uid & "'")
1958
            If oConn2Rows.Length = 1 Then
1959
                sConn2Type = "Line"
1960 b08338e3 Gyusu
            End If
1961 f9b63682 Gyusu
        Else
1962
            sConn2Type = "Symbol"
1963
        End If
1964 b08338e3 Gyusu
1965 f9b63682 Gyusu
        Dim oConn3Rows() As DataRow = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "] = '" & sConn3Uid & "'")
1966
        If oConn3Rows.Length = 0 Then
1967
            oConn3Rows = oLine_Dt.Select("[" & _XML_LINE_UID & "] = '" & sConn3Uid & "'")
1968
            If oConn3Rows.Length = 1 Then
1969
                sConn3Type = "Line"
1970 b08338e3 Gyusu
            End If
1971 f9b63682 Gyusu
        Else
1972
            sConn3Type = "Symbol"
1973
        End If
1974 b08338e3 Gyusu
1975 f9b63682 Gyusu
        Dim oConn4Rows() As DataRow = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "] = '" & sConn4Uid & "'")
1976
        If oConn4Rows.Length = 0 Then
1977
            oConn4Rows = oLine_Dt.Select("[" & _XML_LINE_UID & "] = '" & sConn4Uid & "'")
1978
            If oConn4Rows.Length = 1 Then
1979
                sConn4Type = "Line"
1980 b08338e3 Gyusu
            End If
1981 f9b63682 Gyusu
        Else
1982
            sConn4Type = "Symbol"
1983
        End If
1984 b08338e3 Gyusu
1985 f9b63682 Gyusu
        Dim oStartLMConnector As LMConnector = Nothing
1986
        Dim oEndLMConnector As LMConnector = Nothing
1987
        Dim objInputs As PlaceRunInputs
1988
        objInputs = New PlaceRunInputs
1989
        Dim iModelingType As Integer = 0
1990 76f465d0 Gyusu
        If sConn1Type <> "" Then
1991
            ConvertPoint(oCurrentSymbolRow(_XML_SYMBOL_Conn1_Point).ToString(), dConn1_x, dConn1_y)
1992 f9b63682 Gyusu
        End If
1993 76f465d0 Gyusu
        If sConn2Type <> "" Then
1994
            ConvertPoint(oCurrentSymbolRow(_XML_SYMBOL_Conn2_Point).ToString(), dConn2_x, dConn2_y)
1995 f9b63682 Gyusu
        End If
1996 76f465d0 Gyusu
        If sConn3Type <> "" Then
1997
            ConvertPoint(oCurrentSymbolRow(_XML_SYMBOL_Conn3_Point).ToString(), dConn3_x, dConn3_y)
1998 f9b63682 Gyusu
        End If
1999 76f465d0 Gyusu
        If sConn4Type <> "" Then
2000
            ConvertPoint(oCurrentSymbolRow(_XML_SYMBOL_Conn4_Point).ToString(), dConn4_x, dConn4_y)
2001 f9b63682 Gyusu
        End If
2002 b08338e3 Gyusu
2003 f9b63682 Gyusu
        Dim sFirstUid As String = ""
2004
        Dim sSecondUid As String = ""
2005
        Dim oLMSymbol As LMSymbol = Nothing
2006 76f465d0 Gyusu
        Dim dPreConn_x As Double = 0
2007
        Dim dPreConn_y As Double = 0
2008 b82166d4 Gyusu
        Dim sStartConnectionUid As String = ""
2009
        Dim sEndConnectionUid As String = ""
2010 f9b63682 Gyusu
        If sConn1Type <> "" And sConn2Type <> "" Then
2011 76f465d0 Gyusu
            If sConn1Type = "Line" Then
2012 b82166d4 Gyusu
                CheckConnectionLine(dConn1_x, dConn1_y, oStartLMConnector, sStartConnectionUid)
2013 76f465d0 Gyusu
            Else
2014
                CheckConnectionSymbolToSymbol(oConn1Rows, dConn1_x, dConn1_y, oStartLMConnector)
2015
            End If
2016
2017
            If sConn2Type = "Line" Then
2018 b82166d4 Gyusu
                CheckConnectionLine(dConn2_x, dConn2_y, oEndLMConnector, sEndConnectionUid)
2019 76f465d0 Gyusu
            Else
2020
                CheckConnectionSymbolToSymbol(oConn2Rows, dConn2_x, dConn2_y, oEndLMConnector)
2021
            End If
2022
2023 f9b63682 Gyusu
            sFirstUid = CheckExistModeling(oConn1Rows(0))
2024
            sSecondUid = CheckExistModeling(oConn2Rows(0))
2025 79326880 Gyusu
            Dim oCurrentLMConnector As LMConnector = Nothing
2026 1bfcc921 Gyusu
2027 f9b63682 Gyusu
        ElseIf sConn1Type <> "" And sConn2Type = "" Then
2028 76f465d0 Gyusu
            If sConn1Type = "Line" Then
2029 b82166d4 Gyusu
                CheckConnectionLine(dConn1_x, dConn1_y, oStartLMConnector, sStartConnectionUid)
2030 76f465d0 Gyusu
            Else
2031
                CheckConnectionSymbolToSymbol(oConn1Rows, dConn1_x, dConn1_y, oStartLMConnector)
2032 79326880 Gyusu
                dOriginal_x = dConn1_x
2033
                dOriginal_y = dConn1_y
2034 76f465d0 Gyusu
            End If
2035
2036 f9b63682 Gyusu
            sFirstUid = CheckExistModeling(oConn1Rows(0))
2037 79326880 Gyusu
2038 f9b63682 Gyusu
        ElseIf sConn1Type = "" And sConn2Type <> "" Then
2039 76f465d0 Gyusu
2040
            If sConn1Type = "Line" Then
2041 b82166d4 Gyusu
                CheckConnectionLine(dConn2_x, dConn2_y, oEndLMConnector, sEndConnectionUid)
2042 76f465d0 Gyusu
            Else
2043
                CheckConnectionSymbolToSymbol(oConn2Rows, dConn2_x, dConn2_y, oEndLMConnector)
2044 79326880 Gyusu
                dOriginal_x = dConn2_x
2045
                dOriginal_y = dConn2_y
2046 76f465d0 Gyusu
            End If
2047 f9b63682 Gyusu
            sSecondUid = CheckExistModeling(oConn2Rows(0))
2048 79326880 Gyusu
2049 f9b63682 Gyusu
        ElseIf sConn3Type <> "" And sConn4Type <> "" Then
2050 76f465d0 Gyusu
            If sConn1Type = "Line" Then
2051 b82166d4 Gyusu
                CheckConnectionLine(dConn3_x, dConn3_y, oStartLMConnector, sStartConnectionUid)
2052 76f465d0 Gyusu
            Else
2053
                CheckConnectionSymbolToSymbol(oConn3Rows, dConn3_x, dConn3_y, oStartLMConnector)
2054
            End If
2055
2056
            If sConn2Type = "Line" Then
2057 b82166d4 Gyusu
                CheckConnectionLine(dConn4_x, dConn4_y, oEndLMConnector, sEndConnectionUid)
2058 76f465d0 Gyusu
            Else
2059
                CheckConnectionSymbolToSymbol(oConn4Rows, dConn4_x, dConn4_y, oEndLMConnector)
2060
            End If
2061
2062 f9b63682 Gyusu
            sFirstUid = CheckExistModeling(oConn3Rows(0))
2063
            sSecondUid = CheckExistModeling(oConn4Rows(0))
2064 76f465d0 Gyusu
2065 f9b63682 Gyusu
        ElseIf sConn3Type <> "" And sConn4Type = "" Then
2066 76f465d0 Gyusu
            If sConn1Type = "Line" Then
2067 b82166d4 Gyusu
                CheckConnectionLine(dConn3_x, dConn3_y, oStartLMConnector, sStartConnectionUid)
2068 76f465d0 Gyusu
            Else
2069
                CheckConnectionSymbolToSymbol(oConn3Rows, dConn3_x, dConn3_y, oStartLMConnector)
2070 79326880 Gyusu
                dOriginal_x = dConn3_x
2071
                dOriginal_y = dConn3_y
2072 76f465d0 Gyusu
            End If
2073
2074 f9b63682 Gyusu
            sFirstUid = CheckExistModeling(oConn3Rows(0))
2075 79326880 Gyusu
2076 f9b63682 Gyusu
        ElseIf sConn3Type = "" And sConn4Type <> "" Then
2077 76f465d0 Gyusu
            If sConn2Type = "Line" Then
2078 b82166d4 Gyusu
                CheckConnectionLine(dConn4_x, dConn4_y, oEndLMConnector, sEndConnectionUid)
2079 76f465d0 Gyusu
            Else
2080
                CheckConnectionSymbolToSymbol(oConn4Rows, dConn4_x, dConn4_y, oEndLMConnector)
2081 79326880 Gyusu
                dOriginal_x = dConn4_x
2082
                dOriginal_y = dConn4_y
2083 76f465d0 Gyusu
            End If
2084
2085 f9b63682 Gyusu
            sSecondUid = CheckExistModeling(oConn4Rows(0))
2086 79326880 Gyusu
2087 f9b63682 Gyusu
        Else
2088 1bfcc921 Gyusu
2089 f9b63682 Gyusu
        End If
2090 b08338e3 Gyusu
2091 f9b63682 Gyusu
        If sFirstUid <> "" And sSecondUid <> "" Then
2092
            sReturnUid = sSecondUid
2093
        ElseIf sFirstUid <> "" And sSecondUid = "" Then
2094
            sReturnUid = sFirstUid
2095
        ElseIf sFirstUid <> "" And sSecondUid = "" Then
2096
            sReturnUid = sFirstUid
2097 76f465d0 Gyusu
        ElseIf sSecondUid <> "" And sFirstUid = "" Then
2098
            sReturnUid = sSecondUid
2099
        ElseIf sSecondUid <> "" And sFirstUid = "" Then
2100
            sReturnUid = sSecondUid
2101 f9b63682 Gyusu
        Else
2102
            sReturnUid = ""
2103
        End If
2104 b08338e3 Gyusu
2105 76f465d0 Gyusu
        If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
2106 f9b63682 Gyusu
            oLMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dOriginal_x, dOriginal_y,, dAngle)
2107 76f465d0 Gyusu
            oCurrentSymbolRow(_XML_SYMBOL_LMSYMBOL) = oLMSymbol
2108
        Else
2109
            If oStartLMConnector IsNot Nothing And oEndLMConnector IsNot Nothing Then
2110
                oLMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dOriginal_x, dOriginal_y,, dAngle)
2111
                oCurrentSymbolRow(_XML_SYMBOL_LMSYMBOL) = oLMSymbol
2112
            ElseIf oStartLMConnector IsNot Nothing And oEndLMConnector Is Nothing Then
2113
                oLMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dOriginal_x, dOriginal_y,, dAngle,,
2114
                            TargetItem:=oStartLMConnector.AsLMAItem)
2115
                oCurrentSymbolRow(_XML_SYMBOL_LMSYMBOL) = oLMSymbol
2116
            ElseIf oStartLMConnector Is Nothing And oEndLMConnector IsNot Nothing Then
2117
                oLMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dOriginal_x, dOriginal_y,, dAngle,,
2118
                TargetItem:=oEndLMConnector.AsLMAItem)
2119
                oCurrentSymbolRow(_XML_SYMBOL_LMSYMBOL) = oLMSymbol
2120
            Else
2121
                oLMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dOriginal_x, dOriginal_y,, dAngle)
2122
                oCurrentSymbolRow(_XML_SYMBOL_LMSYMBOL) = oLMSymbol
2123
            End If
2124 9c86a823 Gyusu
        End If
2125
2126 f291ddcb Gyusu
        '모델링 된 Symbol 데이터 테이블 저장
2127 e38f99a7 Gyusu
        Dim oAddRow As DataRow = _ModelingSymbol_Dt.NewRow
2128
        oAddRow(_XML_SYMBOL_SPID) = oLMSymbol.ModelItemID
2129
        oAddRow(_XML_SYMBOL_LMSYMBOL) = oLMSymbol
2130
        oAddRow(_XML_SYMBOL_DRAWING_TF) = "TRUE"
2131
        oAddRow(_XML_SYMBOL_CENTERPOINT_X) = dOriginal_x
2132
        oAddRow(_XML_SYMBOL_CENTERPOINT_Y) = dOriginal_y
2133
        oAddRow(_XML_SYMBOL_MIN_X) = oCurrentSymbolRow(_XML_SYMBOL_MIN_X)
2134
        oAddRow(_XML_SYMBOL_MAX_X) = oCurrentSymbolRow(_XML_SYMBOL_MAX_X)
2135
        oAddRow(_XML_SYMBOL_MIN_Y) = oCurrentSymbolRow(_XML_SYMBOL_MIN_Y)
2136
        oAddRow(_XML_SYMBOL_MAX_Y) = oCurrentSymbolRow(_XML_SYMBOL_MAX_Y)
2137
        _ModelingSymbol_Dt.Rows.Add(oAddRow)
2138
2139 9c86a823 Gyusu
        If sChildItem <> "" Then
2140
            Dim sConn1_Systempath As String = ""
2141
            Dim sConn2_Systempath As String = ""
2142
            Dim sConn1_Angle As Double = 0
2143
            Dim sConn2_Angle As Double = 0
2144
2145
            For Each sDirection In sChildItem.Split("/")
2146
                Dim iType As Integer = 0
2147
                For Each sType In sDirection.Split(",")
2148
                    If sConn1_Systempath = "" Then
2149 79326880 Gyusu
2150 9c86a823 Gyusu
                        If iType = 0 Then
2151
                            sConn1_Angle = GetChildSymbolDirection(sType)
2152
                            iType = iType + 1
2153
                        Else
2154
                            Dim sStartpoint As String = oCurrentSymbolRow(_XML_SYMBOL_Conn1_Point).ToString()
2155
                            ConvertPointBystring(sStartpoint, dConn1_x, dConn1_y)
2156
                            ConvertPointByImage(dConn1_x, dConn1_y, _IMG_X, _IMG_Y)
2157
                            sConn1_Systempath = GetDataFromMappingDB(sType, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
2158 79326880 Gyusu
                            Dim dChildConn1_x As Double = 0
2159
                            Dim dChildConn1_y As Double = 0
2160 9c86a823 Gyusu
2161 79326880 Gyusu
                            If oLMSymbol IsNot Nothing Then
2162
                                _Placement.PIDConnectPointLocation(oLMSymbol, 1, dChildConn1_x, dChildConn1_y)
2163
                                _Placement.PIDPlaceSymbol(sConn1_Systempath, dChildConn1_x, dChildConn1_y,, sConn1_Angle,,
2164
                                 TargetItem:=oLMSymbol.AsLMAItem)
2165 9c86a823 Gyusu
                            Else
2166 79326880 Gyusu
                                _Placement.PIDPlaceSymbol(sConn1_Systempath, dConn1_x, dConn1_y,, sConn1_Angle,,)
2167 9c86a823 Gyusu
                            End If
2168
                        End If
2169 79326880 Gyusu
2170 9c86a823 Gyusu
                    Else
2171
                        If iType = 0 Then
2172
                            sConn2_Angle = GetChildSymbolDirection(sType)
2173
                            iType = iType + 1
2174
                        Else
2175
                            Dim sEndPoint As String = oCurrentSymbolRow(_XML_SYMBOL_Conn2_Point).ToString()
2176
                            ConvertPointBystring(sEndPoint, dConn2_x, dConn2_y)
2177
                            ConvertPointByImage(dConn2_x, dConn2_y, _IMG_X, _IMG_Y)
2178
                            sConn2_Systempath = GetDataFromMappingDB(sType, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
2179
2180 79326880 Gyusu
                            Dim dChildConn2_x As Double = 0
2181
                            Dim dChildConn2_y As Double = 0
2182
2183
                            If oLMSymbol IsNot Nothing Then
2184
                                _Placement.PIDConnectPointLocation(oLMSymbol, 2, dChildConn2_x, dChildConn2_y)
2185
                                _Placement.PIDPlaceSymbol(sConn1_Systempath, dChildConn2_x, dChildConn2_y,, sConn2_Angle,,
2186
                                        TargetItem:=oLMSymbol.AsLMAItem)
2187 9c86a823 Gyusu
                            Else
2188 79326880 Gyusu
                                _Placement.PIDPlaceSymbol(sConn2_Systempath, dChildConn2_x, dChildConn2_y,, sConn2_Angle,,)
2189 9c86a823 Gyusu
                            End If
2190
2191
                        End If
2192
                    End If
2193
                Next
2194
            Next
2195 b08338e3 Gyusu
        End If
2196 9c86a823 Gyusu
2197 76f465d0 Gyusu
        AddProgress()
2198 b08338e3 Gyusu
2199 f9b63682 Gyusu
        SetListBoxItems(ListBox_Result, "Place Fitting.." & sUid & " (" & dOriginal_x & "," & dOriginal_y & ")..." & _iFittingcnt & " count ")
2200
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Fitting : " & sUid)
2201
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "LineNo : " & sLineNoText)
2202
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "ModelingType : " & iModelingType)
2203
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Conn1_Point : " & dConn1_x & "," & dConn1_y)
2204
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Conn2_Point : " & dConn2_x & "," & dConn2_y)
2205
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Conn3_Point : " & dConn3_x & "," & dConn3_y)
2206
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Conn4_Point : " & dConn4_x & "," & dConn4_y)
2207
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection1 : " & oCurrentSymbolRow(_XML_SYMBOL_Conn1_Uid).ToString())
2208
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection2 : " & oCurrentSymbolRow(_XML_SYMBOL_Conn2_Uid).ToString())
2209
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection3 : " & oCurrentSymbolRow(_XML_SYMBOL_Conn3_Uid).ToString())
2210
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection4 : " & oCurrentSymbolRow(_XML_SYMBOL_Conn4_Uid).ToString())
2211
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
2212
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "OriginalPoint : " & dOriginal_x & "," & dOriginal_y)
2213
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Fitting Count : " & _iFittingcnt)
2214
        _iFittingcnt = _iFittingcnt + 1
2215
        oCurrentSymbolRow(_XML_SYMBOL_DRAWING_TF) = "TRUE"
2216 e38f99a7 Gyusu
2217 76f465d0 Gyusu
        Dim oAttributeRow() As DataRow
2218
        oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
2219
        If oAttribute_Dt.Rows.Count > 0 Then
2220 f9b63682 Gyusu
2221 76f465d0 Gyusu
            If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
2222
                Dim oInstrument As LMInstrument
2223
                oInstrument = _Placement.PIDDataSource.GetInstrument(oLMSymbol.ModelItemID)
2224
                Try
2225
                    If oAttributeRow.Length > 0 Then
2226
                        For Each oAttribute In oAttributeRow
2227
                            Try
2228
                                Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
2229
                                Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
2230
                                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
2231
                                oInstrument.Attributes(sSPPIDAttribute).Value = sPIDValue
2232
                            Catch ex As Exception
2233
                            End Try
2234
                        Next
2235
                        oInstrument.Commit()
2236
                    End If
2237
                Catch ex As Exception
2238
                End Try
2239
            Else
2240 f9b63682 Gyusu
                Try
2241 76f465d0 Gyusu
                    If oAttributeRow.Length > 0 And oLMSymbol IsNot Nothing Then
2242
                        For Each oAttribute In oAttributeRow
2243
                            Try
2244
                                Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
2245
                                Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
2246
                                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
2247
                                oLMSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
2248
2249
                            Catch ex As Exception
2250
                            End Try
2251
                        Next
2252
                        oLMSymbol.Commit()
2253 f9b63682 Gyusu
                    End If
2254
                Catch ex As Exception
2255
                End Try
2256 76f465d0 Gyusu
            End If
2257 f9b63682 Gyusu
        End If
2258 b08338e3 Gyusu
2259 f9b63682 Gyusu
        Return sReturnUid
2260
    End Function
2261 9c86a823 Gyusu
    Private Function GetChildSymbolDirection(ByVal sDirection As String) As Double
2262
        Dim sReturnDirection As String = ""
2263
        If sDirection.ToUpper() = "RIGHT" Then
2264
            Return 3.14
2265
        ElseIf sDirection.ToUpper() = "LEFT" Then
2266
            Return 0
2267
        ElseIf sDirection.ToUpper = "DOWN" Then
2268
            Return 1.57
2269
        ElseIf sDirection.ToUpper() = "UP" Then
2270
            Return 4.71
2271
        Else
2272
            Return 0
2273
        End If
2274
    End Function
2275
2276 f9b63682 Gyusu
    Private Function CheckExistModeling(ByVal oRow As DataRow) As String
2277
        If oRow(_XML_LINE_DRAWING_TF).ToString() = "FALSE" And oRow(_XML_LINE_Check).ToString() = "TRUE" Then
2278
            Return oRow(_XML_LINE_UID).ToString()
2279
        End If
2280
        Return String.Empty
2281
    End Function
2282 b08338e3 Gyusu
2283
2284 f9b63682 Gyusu
    Private Sub ConvertPoint(ByVal sOriginalPoint As String, ByRef dConn1_x As Double, ByRef dConn1_y As Double)
2285
        ConvertPointBystring(sOriginalPoint, dConn1_x, dConn1_y)
2286
        ConvertPointByImage(dConn1_x, dConn1_y, _IMG_X, _IMG_Y)
2287
    End Sub
2288 b08338e3 Gyusu
2289 f9b63682 Gyusu
    Private Function FinalLineModeling(ByVal oCurrentLineRow As DataRow,
2290
                              ByVal oLine_Dt As DataTable, ByVal oSymbol_Dt As DataTable,
2291
                                  ByVal oAttribute_Dt As DataTable) As String
2292
        Dim sReturnUid As String = ""
2293 76f465d0 Gyusu
        Try
2294 1bfcc921 Gyusu
            Dim bCheckBranchItem As Boolean = False
2295 76f465d0 Gyusu
            Dim dCenterPos_x As Double = 0.0
2296
            Dim dCenterPos_y As Double = 0.0
2297
            Dim objItem As LMAItem
2298
            Dim sUid As String = oCurrentLineRow(_XML_LINE_UID).ToString()
2299
            Dim sLineType As String = oCurrentLineRow(_XML_LINE_TYPE).ToString()
2300
            Dim sSystemPath As String = GetPipeType(sLineType)
2301
            Dim sLineNoText As String = oCurrentLineRow(_XML_LINENO_TEXT).ToString()
2302
            Dim sLineNoUid As String = oCurrentLineRow(_XML_LINE_LINENOUID).ToString()
2303
            Dim dStart_Dwg_x As Double = oCurrentLineRow(_XML_LINE_DWG_STARTPOINT_X)
2304
            Dim dStart_Dwg_y As Double = oCurrentLineRow(_XML_LINE_DWG_STARTPOINT_Y)
2305
            Dim dEnd_Dwg_x As Double = oCurrentLineRow(_XML_LINE_DWG_ENDPOINT_X)
2306
            Dim dEnd_Dwg_y As Double = oCurrentLineRow(_XML_LINE_DWG_ENDPOINT_Y)
2307
            Dim sPreFlowDirection As String = ""
2308
            Dim sFlowDirection As String = oCurrentLineRow(_XML_LINE_FlowDirection)
2309
            Dim sPreConn1Direction As String = ""
2310
            Dim sPreConn2Direction As String = ""
2311
            Dim sDirection As String = oCurrentLineRow(_XML_LINE_Direction)
2312
            dCenterPos_x = Math.Abs(dStart_Dwg_x + dEnd_Dwg_x) / 2
2313
            dCenterPos_y = Math.Abs(dStart_Dwg_y + dEnd_Dwg_y) / 2
2314
            Dim oPidDataSource As LMADataSource = Nothing
2315
            Try
2316
                oPidDataSource = _Placement.PIDDataSource
2317
            Catch ex As Exception
2318
                CheckOpenDrawing()
2319
                oPidDataSource = _Placement.PIDDataSource
2320
            End Try
2321
            'Connection 정보 체크, 모델링 되어 있는지 유무
2322
            '양 커넥션의 모델링 유무를 체크한다.
2323
            Dim sConn1Uid As String = oCurrentLineRow(_XML_LINE_Conn1_Uid).ToString()
2324
            Dim sConn2Uid As String = oCurrentLineRow(_XML_LINE_Conn2_Uid).ToString()
2325
            Dim sConn1Type As String = ""
2326
            Dim sConn2Type As String = ""
2327
            Dim oConn1Rows() As DataRow = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "] = '" & sConn1Uid & "'")
2328
            If oConn1Rows.Length = 0 Then
2329
                oConn1Rows = oLine_Dt.Select("[" & _XML_LINE_UID & "] = '" & sConn1Uid & "'")
2330
                If oConn1Rows.Length = 1 Then
2331
                    sConn1Type = "Line"
2332
                End If
2333
            Else
2334 79326880 Gyusu
                Dim oOriginalPoint As String = oConn1Rows(0)(_XML_SYMBOL_ORIGINALPOINT)
2335
                ConvertPointBystring(oOriginalPoint, dStart_Dwg_x, dStart_Dwg_y)
2336
                ConvertPointByImage(dStart_Dwg_x, dStart_Dwg_y, _IMG_X, _IMG_Y)
2337
                oCurrentLineRow(_XML_LINE_DWG_STARTPOINT_X) = dStart_Dwg_x
2338
                oCurrentLineRow(_XML_LINE_DWG_STARTPOINT_Y) = dStart_Dwg_y
2339 76f465d0 Gyusu
                sConn1Type = "Symbol"
2340
            End If
2341
            Dim oConn2Rows() As DataRow = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "] = '" & sConn2Uid & "'")
2342
            If oConn2Rows.Length = 0 Then
2343
                oConn2Rows = oLine_Dt.Select("[" & _XML_LINE_UID & "] = '" & sConn2Uid & "'")
2344
                If oConn2Rows.Length = 1 Then
2345
                    sConn2Type = "Line"
2346
                End If
2347
            Else
2348 79326880 Gyusu
                Dim oOriginalPoint As String = oConn2Rows(0)(_XML_SYMBOL_ORIGINALPOINT)
2349
                ConvertPointBystring(oOriginalPoint, dEnd_Dwg_x, dEnd_Dwg_y)
2350
                ConvertPointByImage(dEnd_Dwg_x, dEnd_Dwg_y, _IMG_X, _IMG_Y)
2351
                oCurrentLineRow(_XML_LINE_DWG_ENDPOINT_X) = dEnd_Dwg_x
2352
                oCurrentLineRow(_XML_LINE_DWG_ENDPOINT_Y) = dEnd_Dwg_y
2353 76f465d0 Gyusu
                sConn2Type = "Symbol"
2354
            End If
2355
            Dim sConn1LineNo As String = ""
2356
            Dim sConn2LineNo As String = ""
2357 3b7a4470 Gyusu
            Dim oLMConnector As LMConnector = Nothing
2358 76f465d0 Gyusu
            Dim oStartLMConnector As LMConnector = Nothing
2359
            Dim oEndLMConnector As LMConnector = Nothing
2360
            Dim oLMSymbol1 As LMSymbol = Nothing
2361
            Dim oLMSymbol2 As LMSymbol = Nothing
2362
            Dim objInputs As PlaceRunInputs
2363
            objInputs = New PlaceRunInputs
2364
            Dim iModelingType As Integer = 0
2365
            If sConn1Type = "Line" And sConn2Type = "Line" Then
2366
                iModelingType = 1
2367
            ElseIf sConn1Type = "Line" And sConn2Type = "Symbol" Then
2368
                iModelingType = 1
2369
            ElseIf sConn1Type = "Symbol" And sConn2Type = "Line" Then
2370
                iModelingType = 1
2371
            ElseIf sConn1Type = "Symbol" And sConn2Type = "Symbol" Then
2372
                iModelingType = 1
2373
            ElseIf sConn1Type = "Line" And sConn2Type = "" Then
2374
                iModelingType = 2
2375
            ElseIf sConn1Type = "Symbol" And sConn2Type = "" Then
2376
                iModelingType = 2
2377
            ElseIf sConn1Type = "" And sConn2Type = "Line" Then
2378
                iModelingType = 3
2379
            ElseIf sConn1Type = "" And sConn2Type = "Symbol" Then
2380
                iModelingType = 3
2381
            Else
2382
                iModelingType = 4
2383
            End If
2384
            Dim dPreConnX As Double = 0
2385
            Dim dPreConnY As Double = 0
2386 b82166d4 Gyusu
            Dim sStartConnectionUid As String = ""
2387
            Dim sEndConnectionUid As String = ""
2388 1bfcc921 Gyusu
            Dim bAlreadyCheckBranchLine As Boolean = False
2389
            '브런치라인이 먼저있는상태에서 메인라인을 그릴경우..해당되는 브런치라인 수 만큼 라인을 따로 생성 
2390
            If CheckAlreadyBranchLine(sSystemPath, dStart_Dwg_x, dStart_Dwg_y, dEnd_Dwg_x, dEnd_Dwg_y) = False Then
2391 3b7a4470 Gyusu
2392 1bfcc921 Gyusu
                CheckConnectionLine(dStart_Dwg_x, dStart_Dwg_y, oStartLMConnector, sStartConnectionUid)
2393 3b7a4470 Gyusu
                If oStartLMConnector Is Nothing Then
2394 1bfcc921 Gyusu
                    bCheckBranchItem = UpdateCheckBranchLine(dStart_Dwg_x, dStart_Dwg_y, oStartLMConnector, sStartConnectionUid)
2395
                    If oStartLMConnector Is Nothing Then
2396
                        oLMSymbol1 = CheckConnectionSymbolToLine(oConn1Rows, dStart_Dwg_x, dStart_Dwg_y, dCenterPos_x, dCenterPos_y, oStartLMConnector)
2397
                        If oLMSymbol1 IsNot Nothing Then
2398
                            sConn1Type = "Symbol"
2399
                        Else
2400
                            sConn1Type = ""
2401
                        End If
2402 76f465d0 Gyusu
                    Else
2403 1bfcc921 Gyusu
                        sConn1Type = "Line"
2404 3b7a4470 Gyusu
                    End If
2405
                Else
2406
                    sConn1Type = "Line"
2407 76f465d0 Gyusu
                End If
2408 1bfcc921 Gyusu
                CheckConnectionLine(dEnd_Dwg_x, dEnd_Dwg_y, oEndLMConnector, sEndConnectionUid)
2409 3b7a4470 Gyusu
                If oEndLMConnector Is Nothing Then
2410 1bfcc921 Gyusu
                    bCheckBranchItem = UpdateCheckBranchLine(dEnd_Dwg_x, dEnd_Dwg_y, oEndLMConnector, sEndConnectionUid)
2411
                    If oEndLMConnector Is Nothing Then
2412
                        oLMSymbol2 = CheckConnectionSymbolToLine(oConn2Rows, dEnd_Dwg_x, dEnd_Dwg_y, dCenterPos_x, dCenterPos_y, oEndLMConnector)
2413
                        If oLMSymbol2 IsNot Nothing Then
2414
                            sConn2Type = "Symbol"
2415
                        End If
2416
                    Else
2417
                        sConn2Type = "Line"
2418 3b7a4470 Gyusu
                    End If
2419
                Else
2420
                    sConn2Type = "Line"
2421 76f465d0 Gyusu
                End If
2422 1bfcc921 Gyusu
                Dim sFirstUid As String = ""
2423
                Dim sSecondUid As String = ""
2424
                Try
2425
                    If oStartLMConnector Is Nothing And oEndLMConnector Is Nothing Then
2426
                        If oLMSymbol1 Is Nothing Then
2427
                            objInputs.AddPoint(dStart_Dwg_x, dStart_Dwg_y)
2428
                        Else
2429
                            objInputs.AddSymbolTarget(oLMSymbol1, dStart_Dwg_x, dStart_Dwg_y)
2430
                        End If
2431 79326880 Gyusu
2432 1bfcc921 Gyusu
                        If oLMSymbol2 Is Nothing Then
2433
                            objInputs.AddPoint(dEnd_Dwg_x, dEnd_Dwg_y)
2434
                        Else
2435
                            objInputs.AddSymbolTarget(oLMSymbol2, dEnd_Dwg_x, dEnd_Dwg_y)
2436
                        End If
2437 79326880 Gyusu
2438 1bfcc921 Gyusu
                    ElseIf oStartLMConnector IsNot Nothing And oEndLMConnector Is Nothing Then
2439
                        If sConn1Type = "Line" Then
2440
                            objInputs.AddConnectorTarget(oStartLMConnector, dStart_Dwg_x, dStart_Dwg_y)
2441
                        Else
2442
                            objInputs.AddSymbolTarget(oLMSymbol1, dStart_Dwg_x, dStart_Dwg_y)
2443
                        End If
2444
                        If oLMSymbol2 Is Nothing Then
2445
                            objInputs.AddPoint(dEnd_Dwg_x, dEnd_Dwg_y)
2446
                        Else
2447
                            objInputs.AddSymbolTarget(oLMSymbol2, dEnd_Dwg_x, dEnd_Dwg_y)
2448
                        End If
2449 3b7a4470 Gyusu
2450 1bfcc921 Gyusu
                    ElseIf oStartLMConnector Is Nothing And oEndLMConnector IsNot Nothing Then
2451
                        If sConn2Type = "Line" Then
2452
                            objInputs.AddConnectorTarget(oEndLMConnector, dEnd_Dwg_x, dEnd_Dwg_y)
2453
                        Else
2454
                            objInputs.AddSymbolTarget(oLMSymbol2, dEnd_Dwg_x, dEnd_Dwg_y)
2455
                        End If
2456
                        If oLMSymbol1 Is Nothing Then
2457
                            objInputs.AddPoint(dStart_Dwg_x, dStart_Dwg_y)
2458
                        Else
2459
                            objInputs.AddSymbolTarget(oLMSymbol1, dStart_Dwg_x, dStart_Dwg_y)
2460
                        End If
2461 b08338e3 Gyusu
2462 1bfcc921 Gyusu
                    Else
2463
                        If sConn1Type = "Line" Then
2464
                            objInputs.AddConnectorTarget(oStartLMConnector, dStart_Dwg_x, dStart_Dwg_y)
2465
                        Else
2466
                            objInputs.AddSymbolTarget(oLMSymbol1, dStart_Dwg_x, dStart_Dwg_y)
2467
                        End If
2468
                        If sConn2Type = "Line" Then
2469
                            objInputs.AddConnectorTarget(oEndLMConnector, dEnd_Dwg_x, dEnd_Dwg_y)
2470
                        Else
2471
                            objInputs.AddSymbolTarget(oLMSymbol2, dEnd_Dwg_x, dEnd_Dwg_y)
2472
                        End If
2473 b08338e3 Gyusu
2474 1bfcc921 Gyusu
                    End If
2475
                    If sConn1Type <> "" And sConn2Type <> "" Then
2476
                        If oConn1Rows.Count > 0 Then
2477
                            sFirstUid = CheckExistModeling(oConn1Rows(0))
2478
                        End If
2479
                        If oConn2Rows.Count > 0 Then
2480
                            sSecondUid = CheckExistModeling(oConn2Rows(0))
2481
                        End If
2482 79326880 Gyusu
2483 1bfcc921 Gyusu
                    ElseIf sConn1Type <> "" And sConn2Type = "" Then
2484
                        If oConn1Rows.Count > 0 Then
2485
                            sFirstUid = CheckExistModeling(oConn1Rows(0))
2486
                        End If
2487 79326880 Gyusu
2488 1bfcc921 Gyusu
                    ElseIf sConn1Type = "" And sConn2Type <> "" Then
2489
                        If oConn2Rows.Count > 0 Then
2490
                            sSecondUid = CheckExistModeling(oConn2Rows(0))
2491
                        End If
2492 79326880 Gyusu
2493 e38f99a7 Gyusu
                    End If
2494
2495 1bfcc921 Gyusu
                    If sFirstUid <> "" And sSecondUid <> "" Then
2496
                        sReturnUid = sSecondUid
2497
                    ElseIf sFirstUid = "" And sSecondUid <> "" Then
2498
                        sReturnUid = sSecondUid
2499
                    ElseIf sFirstUid <> "" And sSecondUid = "" Then
2500
                        sReturnUid = sFirstUid
2501 e38f99a7 Gyusu
                    Else
2502 1bfcc921 Gyusu
                        sReturnUid = ""
2503 e38f99a7 Gyusu
                    End If
2504 1bfcc921 Gyusu
                    _iPipecnt = _iPipecnt + 1
2505
2506
                    '배관 모델링
2507
                    Dim oCurrentConnector As LMConnector = LineModeling(objInputs, sSystemPath)
2508
2509
                    If oCurrentConnector IsNot Nothing Then
2510
                        oCurrentLineRow(_XML_LINE_LMCONNECTOR) = oCurrentConnector
2511
                        oCurrentLineRow(_XML_LINE_DRAWING_TF) = "TRUE"
2512
                        '로그 출력
2513
                        AddLog(sUid, sSystemPath, dStart_Dwg_x, dStart_Dwg_y, dEnd_Dwg_x, dEnd_Dwg_y, sLineNoText, sConn1Uid, sConn2Uid)
2514
                        Dim oPipeRun As LMPipeRun = oPidDataSource.GetPipeRun(oCurrentConnector.ModelItemID)
2515
                        '배관 속성 입력
2516
                        AddAttribute(oPipeRun, oAttribute_Dt, sLineNoUid)
2517
2518
                        Dim sID_1 As String = ""
2519
                        Dim sID_2 As String = ""
2520
                        Dim oAddConnector As LMConnector = Nothing
2521
                        If oStartLMConnector IsNot Nothing Then
2522
                            sID_1 = oStartLMConnector.ModelItemID
2523
                            sID_2 = oCurrentConnector.ModelItemID
2524
                            oAddConnector = oStartLMConnector
2525
                        ElseIf oEndLMConnector IsNot Nothing Then
2526
                            sID_1 = oEndLMConnector.ModelItemID
2527
                            sID_2 = oCurrentConnector.ModelItemID
2528
                            oAddConnector = oEndLMConnector
2529
                        End If
2530
                        If sID_1 <> "" And sID_2 <> "" Then
2531
                            'PipeRun 합치기
2532 dd46ca83 Gyusu
2533 e38f99a7 Gyusu
2534 1bfcc921 Gyusu
                            If bCheckBranchItem Then
2535
                                '모델링 된 PipeLine 데이터 테이블 저장
2536
                                AddModelingDT(sUid, oCurrentConnector.ModelItemID, oCurrentConnector, dStart_Dwg_x, dStart_Dwg_y, dEnd_Dwg_x, dEnd_Dwg_y)
2537
                            Else
2538 dd46ca83 Gyusu
                                JoinPipeRun(sID_1, sID_2)
2539 1bfcc921 Gyusu
                                '모델링 된 PipeLine 데이터 테이블 저장
2540
                                AddModelingDT(sUid, sID_1, oAddConnector, dStart_Dwg_x, dStart_Dwg_y, dEnd_Dwg_x, dEnd_Dwg_y)
2541
                            End If
2542
                        Else
2543
                            '모델링 된 PipeLine 데이터 테이블 저장
2544
                            AddModelingDT(sUid, oCurrentConnector.ModelItemID, oCurrentConnector, dStart_Dwg_x, dStart_Dwg_y, dEnd_Dwg_x, dEnd_Dwg_y)
2545
                        End If
2546 dd46ca83 Gyusu
                        If bCheckBranchItem = False Then
2547 9b5d4527 Gyusu
                            '//2018.09.07 LMControl에 따라서 inconsitency가 달라지는듯 확인
2548
                            If sStartConnectionUid <> "" Then
2549
                                Dim oChangeRow() As DataRow = _ModelingLine_Dt.Select(_XML_LINE_UID & " = '" & sStartConnectionUid & "'")
2550
                                If oChangeRow.Length = 1 Then
2551
                                    oChangeRow(0)(_XML_LINE_SPID) = sID_1
2552
                                    oChangeRow(0)(_XML_LINE_LMCONNECTOR) = oAddConnector
2553
                                End If
2554 1bfcc921 Gyusu
                            End If
2555 9b5d4527 Gyusu
                            If sEndConnectionUid <> "" Then
2556
                                Dim oChangeRow() As DataRow = _ModelingLine_Dt.Select(_XML_LINE_UID & " = '" & sEndConnectionUid & "'")
2557
                                If oChangeRow.Length = 1 Then
2558
                                    oChangeRow(0)(_XML_LINE_SPID) = sID_1
2559
                                    oChangeRow(0)(_XML_LINE_LMCONNECTOR) = oAddConnector
2560
                                End If
2561 1bfcc921 Gyusu
                            End If
2562
                        End If
2563 9b5d4527 Gyusu
2564 e38f99a7 Gyusu
                    Else
2565 1bfcc921 Gyusu
                        sReturnUid = ""
2566 e38f99a7 Gyusu
                    End If
2567 1bfcc921 Gyusu
                Catch ex As Exception
2568
                End Try
2569
            End If
2570
        Catch ex As Exception
2571
        End Try
2572
        Return sReturnUid
2573
        '현재 Uid 모델링
2574
    End Function
2575
    Private Sub AddLog(ByVal sUid As String, ByVal sSystemPath As String,
2576
                             ByVal dStart_Dwg_x As Double, ByVal dStart_Dwg_y As Double, ByVal dEnd_Dwg_x As Double, ByVal dEnd_Dwg_y As Double,
2577
                       ByVal sLineNoText As String, ByVal sConn1Uid As String, ByVal sConn2Uid As String)
2578
        SetListBoxItems(ListBox_Result, "Place Pipe.." & sUid & " (" & dStart_Dwg_x & "," & dStart_Dwg_y & ") - (" & dEnd_Dwg_x & "," & dEnd_Dwg_y & ")..." & _iPipecnt & " count ")
2579
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Pipe : " & sUid)
2580
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "LineNo : " & sLineNoText)
2581
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection1 : " & sConn1Uid)
2582
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection2 : " & sConn2Uid)
2583
        'ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
2584
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "StartPoint : " & dStart_Dwg_x & "," & dStart_Dwg_y)
2585
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "EndPoint : " & dEnd_Dwg_x & "," & dEnd_Dwg_y)
2586
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Pipe Count : " & _iPipecnt)
2587
    End Sub
2588 b08338e3 Gyusu
2589 1bfcc921 Gyusu
    Private Sub AddAttribute(ByVal oPipeRun As LMPipeRun, ByVal oAttribute_Dt As DataTable, ByVal sLineNoUid As String)
2590
        Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
2591
        If oAttributeRow.Length > 0 Then
2592
            For Each oAttribute In oAttributeRow
2593
                Try
2594
                    Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
2595
                    Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
2596
                    If sPIDValue.Contains("'") Then
2597
                        sPIDValue = sPIDValue.Replace("'", """")
2598 e38f99a7 Gyusu
                    End If
2599 1bfcc921 Gyusu
                    Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
2600
                    oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
2601
                Catch ex As Exception
2602
                End Try
2603
            Next
2604
            oPipeRun.Commit()
2605
        End If
2606
    End Sub
2607 b08338e3 Gyusu
2608 1bfcc921 Gyusu
    Private Sub AddModelingDT(ByVal sUid As String, ByVal sModelID As String, ByVal oCurrentConnector As LMConnector,
2609
                              ByVal dStart_Dwg_x As Double, ByVal dStart_Dwg_y As Double,
2610
                              ByVal dEnd_Dwg_x As Double, ByVal dEnd_Dwg_y As Double)
2611
        Dim oAddRow As DataRow = _ModelingLine_Dt.NewRow
2612
        oAddRow(_XML_LINE_UID) = sUid
2613
        oAddRow(_XML_LINE_SPID) = sModelID
2614
        oAddRow(_XML_LINE_LMCONNECTOR) = oCurrentConnector
2615
        oAddRow(_XML_LINE_DRAWING_TF) = "TRUE"
2616
        oAddRow(_XML_LINE_DWG_STARTPOINT_X) = dStart_Dwg_x
2617
        oAddRow(_XML_LINE_DWG_STARTPOINT_Y) = dStart_Dwg_y
2618
        oAddRow(_XML_LINE_DWG_ENDPOINT_X) = dEnd_Dwg_x
2619
        oAddRow(_XML_LINE_DWG_ENDPOINT_Y) = dEnd_Dwg_y
2620
        _ModelingLine_Dt.Rows.Add(oAddRow)
2621
    End Sub
2622 f9b63682 Gyusu
2623 1bfcc921 Gyusu
    Private Function JoinPipeRun(ByVal sID_1 As String, ByVal sID_2 As String) As Boolean
2624
        Try
2625
            Dim objSurvivorItem As LMAItem = Nothing
2626
            Dim oPipeRun1 As LMPipeRun = _Placement.PIDDataSource.GetPipeRun(sID_1)
2627
            Dim oPipeRun2 As LMPipeRun = _Placement.PIDDataSource.GetPipeRun(sID_2)
2628
            _Placement.PIDJoinRuns(oPipeRun1, oPipeRun2)
2629
            Return True
2630
        Catch ex As Exception
2631
            Return False
2632
        End Try
2633
    End Function
2634 73bfb231 Gyusu
2635
2636 1bfcc921 Gyusu
    Private Function LineModeling(ByVal objInputs As PlaceRunInputs, ByVal sSystemPath As String) As LMConnector
2637
        Dim oCurrentConnector As LMConnector = Nothing
2638
        Dim objItem As LMAItem
2639
        objItem = _Placement.PIDCreateItem(sSystemPath)
2640
        Try
2641
            oCurrentConnector = _Placement.PIDPlaceRun(objItem, objInputs)
2642
            AddProgress()
2643
        Catch ex As Exception
2644
        End Try
2645
        Return oCurrentConnector
2646
    End Function
2647 f9b63682 Gyusu
2648 1bfcc921 Gyusu
    Private Sub InstumentLineModeling(ByVal CLineNo As Line_no, ByVal oNode As TreeNode)
2649
        If CLineNo IsNot Nothing Then
2650
            Dim oLine_Dt As DataTable = CLineNo.Dt_Line
2651
            Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
2652
            Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
2653
            Dim oDrawLinenoLabel As Boolean = False
2654
            For Each oSymbolNode As TreeNode In oNode.Nodes
2655
                If oSymbolNode.Checked Then
2656
                    Try
2657
                        Dim sUid As String = oSymbolNode.Name
2658
                        Dim sLineNoUid As String = CLineNo.Uid
2659
                        Dim sReturnUid = sUid
2660
                        '  FinalModeling(sUid, oLine_Dt, oSymbol_Dt, oAttribute_Dt)
2661
                        While True
2662
                            Dim oLineRows As DataRow() = oLine_Dt.Select(_XML_LINE_UID & " = '" & sReturnUid & "' And [" & _XML_SYMBOL_DRAWING_TF & "] = 'False' And [" &
2663
                                               _XML_SYMBOL_Check & "] = 'TRUE' And [" & _XML_LINE_ValieLine & "] = 'True'")
2664
                            If oLineRows.Count > 0 Then
2665
                                Dim sPipeType As String = oLineRows(0)(_XML_LINE_TYPE).ToString()
2666
                                If sPipeType.ToUpper() <> "PRIMARY" Then
2667
                                    sReturnUid = FinalLineModeling(oLineRows(0), oLine_Dt, oSymbol_Dt, oAttribute_Dt)
2668
                                Else
2669
                                    sReturnUid = ""
2670
                                End If
2671
                            Else
2672
                                sReturnUid = ""
2673
                            End If
2674
                            If sReturnUid = "" Then
2675
                                Exit While
2676
                            End If
2677
                        End While
2678
                    Catch ex As Exception
2679
                    End Try
2680 76f465d0 Gyusu
                End If
2681 1bfcc921 Gyusu
            Next
2682
        End If
2683
    End Sub
2684 76f465d0 Gyusu
2685 1bfcc921 Gyusu
    Private Sub PipeLineModeling(ByVal CLineNo As Line_no, ByVal oNode As TreeNode)
2686
        If CLineNo IsNot Nothing Then
2687
            Dim oLine_Dt As DataTable = CLineNo.Dt_Line
2688
            Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
2689
            Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
2690
            Dim oDrawLinenoLabel As Boolean = False
2691
            Try
2692
                ManualCheckNode(oLine_Dt)
2693
                ManualCheckNode(oSymbol_Dt)
2694
            Catch ex As Exception
2695
            End Try
2696
            For Each oSymbolNode As TreeNode In oNode.Nodes
2697
                If oSymbolNode.Checked Then
2698
                    Try
2699
                        Dim sUid As String = oSymbolNode.Name
2700
                        Dim sLineNoUid As String = CLineNo.Uid
2701
                        Dim sReturnUid = sUid
2702
                        '  FinalModeling(sUid, oLine_Dt, oSymbol_Dt, oAttribute_Dt)
2703
                        While True
2704
                            Dim oLineRows As DataRow() = oLine_Dt.Select(_XML_LINE_UID & " = '" & sReturnUid & "' And [" & _XML_SYMBOL_DRAWING_TF & "] = 'False' And [" &
2705
                                               _XML_SYMBOL_Check & "] = 'TRUE' And [" & _XML_LINE_ValieLine & "] = 'True'")
2706
                            If oLineRows.Count > 0 Then
2707
                                Dim sPipeType As String = oLineRows(0)(_XML_LINE_TYPE).ToString()
2708
                                If sPipeType.ToUpper() = "PRIMARY" Then
2709
                                    sReturnUid = FinalLineModeling(oLineRows(0), oLine_Dt, oSymbol_Dt, oAttribute_Dt)
2710
                                Else
2711
                                    sReturnUid = ""
2712 b82166d4 Gyusu
                                End If
2713 76f465d0 Gyusu
2714 1bfcc921 Gyusu
                            Else
2715
                                sReturnUid = ""
2716 b82166d4 Gyusu
                            End If
2717 1bfcc921 Gyusu
                            If sReturnUid = "" Then
2718
                                Exit While
2719
                            End If
2720
                        End While
2721
                    Catch ex As Exception
2722
                    End Try
2723
                End If
2724
            Next
2725
        End If
2726
    End Sub
2727 b82166d4 Gyusu
2728 1bfcc921 Gyusu
    Private Sub InstrumentSymbolModeling(ByVal CLineNo As Line_no, ByVal oNode As TreeNode)
2729
        If CLineNo IsNot Nothing Then
2730
            Dim oLine_Dt As DataTable = CLineNo.Dt_Line
2731
            Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
2732
            Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
2733
            Dim oDrawLinenoLabel As Boolean = False
2734
            Try
2735
                ManualCheckNode(oLine_Dt)
2736
                ManualCheckNode(oSymbol_Dt)
2737
            Catch ex As Exception
2738
            End Try
2739
            For Each oSymbolNode As TreeNode In oNode.Nodes
2740
                If oSymbolNode.Checked Then
2741
                    Try
2742
                        Dim sUid As String = oSymbolNode.Name
2743
                        Dim sLineNoUid As String = CLineNo.Uid
2744
                        Dim sReturnUid = sUid
2745
                        '  FinalModeling(sUid, oLine_Dt, oSymbol_Dt, oAttribute_Dt)
2746
                        Dim oSymbolRows As DataRow() = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "]= '" & sReturnUid & "' And [" & _XML_SYMBOL_DRAWING_TF & "] = 'FALSE' And [" &
2747
                                                                           _XML_SYMBOL_Check & "] = 'TRUE'")
2748
                        If oSymbolRows.Count > 0 Then
2749
                            Dim sSymbolType As String = oSymbolRows(0)(_XML_SYMBOL_TYPE).ToString().ToUpper()
2750
                            If sSymbolType = "INSTRUMENT" Then
2751
                                sReturnUid = FinalSymbolModeling(oSymbolRows(0), oLine_Dt, oSymbol_Dt, oAttribute_Dt)
2752
                            End If
2753
                        Else
2754
                            sReturnUid = ""
2755 b82166d4 Gyusu
                        End If
2756 1bfcc921 Gyusu
                        If sReturnUid = "" Then
2757 b82166d4 Gyusu
                        End If
2758 1bfcc921 Gyusu
                    Catch ex As Exception
2759
                    End Try
2760 76f465d0 Gyusu
                End If
2761 1bfcc921 Gyusu
            Next
2762
        End If
2763
    End Sub
2764 b82166d4 Gyusu
2765 1bfcc921 Gyusu
    Private Sub PipeSymbolModeling(ByVal CLineNo As Line_no, ByVal oNode As TreeNode)
2766
        If CLineNo IsNot Nothing Then
2767
            Dim oLine_Dt As DataTable = CLineNo.Dt_Line
2768
            Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
2769
            Dim oAttribute_Dt As DataTable = CLineNo.Dt_Attribute
2770
            Dim oDrawLinenoLabel As Boolean = False
2771
            Try
2772
                ManualCheckNode(oLine_Dt)
2773
                ManualCheckNode(oSymbol_Dt)
2774 76f465d0 Gyusu
            Catch ex As Exception
2775
            End Try
2776 1bfcc921 Gyusu
            For Each oSymbolNode As TreeNode In oNode.Nodes
2777
                If oSymbolNode.Checked Then
2778
                    Try
2779
                        Dim sUid As String = oSymbolNode.Name
2780
                        Dim sLineNoUid As String = CLineNo.Uid
2781
                        Dim sReturnUid = sUid
2782
                        '  FinalModeling(sUid, oLine_Dt, oSymbol_Dt, oAttribute_Dt)
2783
                        Dim oSymbolRows As DataRow() = oSymbol_Dt.Select("[" & _XML_SYMBOL_UID & "]= '" & sReturnUid & "' And [" & _XML_SYMBOL_DRAWING_TF & "] = 'FALSE' And [" &
2784
                                                                           _XML_SYMBOL_Check & "] = 'TRUE'")
2785
                        If oSymbolRows.Count > 0 Then
2786
                            Dim sSymbolType As String = oSymbolRows(0)(_XML_SYMBOL_TYPE).ToString().ToUpper()
2787
                            If sSymbolType <> "INSTRUMENT" Then
2788
                                sReturnUid = FinalSymbolModeling(oSymbolRows(0), oLine_Dt, oSymbol_Dt, oAttribute_Dt)
2789
                            End If
2790
                        Else
2791
                            sReturnUid = ""
2792
                        End If
2793
                        If sReturnUid = "" Then
2794
                        End If
2795
                    Catch ex As Exception
2796
                    End Try
2797
                End If
2798
            Next
2799
        End If
2800
    End Sub
2801 bb2a0c79 Gyusu
2802
    Private Sub PipingModeling()
2803 e4000111 Gyusu
2804 171ac39d Gyusu
        Try
2805
            For Each oDrwing As TreeNode In Tree_Result.Nodes
2806
                For Each oDwgNode As TreeNode In oDrwing.Nodes
2807
                    Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
2808 54b98e09 Gyusu
                    Dim CDrawing As Drawing = GetDrawing(sDwgName)
2809
                    If CDrawing IsNot Nothing Then
2810 e4000111 Gyusu
                        Dim iAllLineNoCount As Integer = Tree_Result.Nodes.Count ' GetCheckNodeCount(oLinenoNode)
2811
                        Dim iPipingOPC_count As Integer = 0 ' GetCheckNodeCount(oLinenoNode)
2812 1bfcc921 Gyusu
2813
                        'PipeModeling
2814 e4000111 Gyusu
                        For Each oNode As TreeNode In oDwgNode.Nodes
2815
                            Dim iItemcnt As Integer = 0
2816
                            Dim sNodeUid As String = oNode.Name
2817
                            Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
2818
                            Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
2819 1bfcc921 Gyusu
                            PipeLineModeling(CLineNo, oNode)
2820 76f465d0 Gyusu
                            Dim CTrimLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
2821 1bfcc921 Gyusu
                            PipeLineModeling(CTrimLineNo, oNode)
2822 76f465d0 Gyusu
                        Next
2823 3acffcee Gyusu
2824 1bfcc921 Gyusu
                        'Instrument Modeling
2825 76f465d0 Gyusu
                        For Each oNode As TreeNode In oDwgNode.Nodes
2826
                            Dim iItemcnt As Integer = 0
2827
                            Dim sNodeUid As String = oNode.Name
2828
                            Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
2829
                            Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
2830 1bfcc921 Gyusu
                            InstrumentSymbolModeling(CLineNo, oNode)
2831 76f465d0 Gyusu
                            Dim CTrimLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
2832 1bfcc921 Gyusu
                            InstrumentSymbolModeling(CTrimLineNo, oNode)
2833 4e016f5d Gyusu
                        Next
2834
2835 1bfcc921 Gyusu
                        'Instrument Line Modeling
2836 4e016f5d Gyusu
                        For Each oNode As TreeNode In oDwgNode.Nodes
2837
                            Dim iItemcnt As Integer = 0
2838
                            Dim sNodeUid As String = oNode.Name
2839
                            Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
2840
                            Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
2841 1bfcc921 Gyusu
                            InstumentLineModeling(CLineNo, oNode)
2842 4e016f5d Gyusu
                            Dim CTrimLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
2843 1bfcc921 Gyusu
                            InstumentLineModeling(CTrimLineNo, oNode)
2844
                        Next
2845 4e016f5d Gyusu
2846 1bfcc921 Gyusu
                        'Symbol Modeling
2847
                        For Each oNode As TreeNode In oDwgNode.Nodes
2848
                            Dim iItemcnt As Integer = 0
2849
                            Dim sNodeUid As String = oNode.Name
2850
                            Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
2851
                            Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
2852
                            PipeSymbolModeling(CLineNo, oNode)
2853
                            Dim CTrimLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
2854
                            PipeSymbolModeling(CTrimLineNo, oNode)
2855 b08338e3 Gyusu
                        Next
2856
                    End If
2857
                Next
2858
            Next
2859
        Catch ex As Exception
2860
2861
        End Try
2862
    End Sub
2863
2864 7e561f5b gaqhf
    Private Sub GetPrimaryLineInNode(ByVal list As List(Of Line), ByVal node As TreeNode)
2865
2866
        If node.Tag IsNot Nothing Then
2867
            If TypeOf node.Tag Is Line Then
2868
                Dim line As Line = node.Tag
2869
                If line.TYPE = "Primary" And node.Checked Then
2870
                    list.Add(line)
2871
                End If
2872
            End If
2873
        End If
2874
2875
        For Each child As TreeNode In node.Nodes()
2876
            GetPrimaryLineInNode(list, child)
2877
        Next
2878
    End Sub
2879
2880
    Private Function FindBranchLine(ByVal lines As List(Of Line)) As List(Of Line)
2881
        Dim branchLines As List(Of Line) = New List(Of Line)
2882
2883
        For Each line As Line In lines
2884
            For Each conn As Connector In line.CONNECTORS
2885
                If String.IsNullOrEmpty(conn.CONNECTEDITEM) = False Then
2886 1406fef4 gaqhf
                    If IsBranchLine(conn.CONNECTEDITEM, line.UID, lines) Then
2887
                        branchLines.Add(line)
2888 7e561f5b gaqhf
                    End If
2889
                End If
2890
            Next
2891
        Next
2892
2893
        Return branchLines
2894
    End Function
2895
2896 1406fef4 gaqhf
    Private Function IsBranchLine(ByVal connectedUID As String, ByVal UID As String, ByVal lines As List(Of Line)) As Boolean
2897
        Dim connLine = FindLineByUID(lines, connectedUID)
2898
        If connLine IsNot Nothing Then
2899
            If connLine.CONNECTORS(0).CONNECTEDITEM <> UID And connLine.CONNECTORS(1).CONNECTEDITEM <> UID Then
2900
                Return True
2901
            End If
2902
        End If
2903
2904
        Return False
2905
    End Function
2906
2907 7e561f5b gaqhf
    Private Function FindLineByUID(ByVal lines As List(Of Line), ByVal uid As String) As Line
2908
        For Each line As Line In lines
2909
            If line.UID = uid Then
2910
                Return line
2911
            End If
2912
        Next
2913
2914
        Return Nothing
2915
    End Function
2916
2917
2918
    Private Function FindSymbolByUID(ByVal symbols As List(Of Symbol), ByVal uid As String) As Symbol
2919
        For Each symbol As Symbol In symbols
2920
            If symbol.UID = uid Then
2921
                Return symbol
2922
            End If
2923
        Next
2924
2925
        Return Nothing
2926
    End Function
2927
2928
    Private Function IsHorizontal(ByVal line As Line)
2929
        If line.END_X - line.START_X = 0 Then
2930
            Return False
2931
        Else
2932
            Dim angle = Math.Atan(Math.Abs(line.END_Y - line.START_Y) / Math.Abs(line.END_X - line.START_X)) * 180 / Math.PI
2933
            If angle < 10 Then
2934
                Return True
2935
            Else
2936
                Return False
2937
            End If
2938
        End If
2939
    End Function
2940
2941 1406fef4 gaqhf
    Private Function IsHorizontal(ByVal point1 As Pointd, ByVal point2 As Pointd)
2942
        If point1.X - point2.X = 0 Then
2943
            Return False
2944
        Else
2945
            Dim angle = Math.Atan(Math.Abs(point2.Y - point1.Y) / Math.Abs(point2.X - point1.X)) * 180 / Math.PI
2946
            If angle < 10 Then
2947
                Return True
2948
            Else
2949
                Return False
2950
            End If
2951
        End If
2952
    End Function
2953
2954
    Private Sub FindConnectPrimaryLine(ByVal drawing As Drawing, ByVal primaryLines As List(Of Line), ByVal shape As Object, ByRef groupLine As List(Of Line))
2955 7e561f5b gaqhf
2956
        If TypeOf (shape) Is Line Then
2957
            Dim _line As Line = shape
2958
2959
            For Each conn As Connector In _line.CONNECTORS
2960
                Dim symbol As Symbol = FindSymbolByUID(drawing.SYMBOLS, conn.CONNECTEDITEM)
2961
                Dim line As Line = FindLineByUID(primaryLines, conn.CONNECTEDITEM)
2962
2963
                If line IsNot Nothing Then
2964 1406fef4 gaqhf
                    If IsBranchLine(line.UID, _line.UID, primaryLines) = False And line.ENABLE And line.TYPE = "Primary" Then
2965 7e561f5b gaqhf
                        line.ENABLE = False
2966
                        groupLine.Add(line)
2967 1406fef4 gaqhf
                        FindConnectPrimaryLine(drawing, primaryLines, line, groupLine)
2968 7e561f5b gaqhf
                    End If
2969
                ElseIf symbol IsNot Nothing Then
2970
                    If symbol.ENABLE Then
2971
                        symbol.ENABLE = False
2972 1406fef4 gaqhf
                        FindConnectPrimaryLine(drawing, primaryLines, symbol, groupLine)
2973 7e561f5b gaqhf
                    End If
2974
                End If
2975
            Next
2976
2977
        ElseIf TypeOf (shape) Is Symbol Then
2978
            Dim _symbol As Symbol = shape
2979
2980
            For Each conn As Connector In _symbol.CONNECTORS
2981
                Dim symbol As Symbol = FindSymbolByUID(drawing.SYMBOLS, conn.CONNECTEDITEM)
2982
                Dim line As Line = FindLineByUID(primaryLines, conn.CONNECTEDITEM)
2983
2984
                If line IsNot Nothing Then
2985 1406fef4 gaqhf
                    If line.ENABLE And line.TYPE = "Primary" Then
2986 7e561f5b gaqhf
                        line.ENABLE = False
2987
                        groupLine.Add(line)
2988 1406fef4 gaqhf
                        FindConnectPrimaryLine(drawing, primaryLines, line, groupLine)
2989 7e561f5b gaqhf
                        Exit For
2990
                    End If
2991
                ElseIf symbol IsNot Nothing Then
2992
                    If symbol.ENABLE Then
2993
                        symbol.ENABLE = False
2994 1406fef4 gaqhf
                        FindConnectPrimaryLine(drawing, primaryLines, symbol, groupLine)
2995 7e561f5b gaqhf
                    End If
2996
                End If
2997
            Next
2998
2999
        End If
3000
3001
    End Sub
3002
3003 1406fef4 gaqhf
    Private Function GetPrimaryGroup(ByVal drawing As Drawing, ByVal primaryLines As List(Of Line)) As List(Of List(Of Line))
3004 7e561f5b gaqhf
        Dim result As List(Of List(Of Line)) = New List(Of List(Of Line))
3005
3006
        For Each line As Line In primaryLines
3007
            If line.ENABLE And line.TYPE = "Primary" Then
3008 1406fef4 gaqhf
                Dim forwardGroupLine As List(Of Line) = New List(Of Line)
3009
                Dim reverseGroupLine As List(Of Line) = New List(Of Line)
3010
                line.ENABLE = False
3011
3012
                Dim _symbol As Symbol = FindSymbolByUID(drawing.SYMBOLS, line.CONNECTORS(0).CONNECTEDITEM)
3013
                Dim _line As Line = FindLineByUID(primaryLines, line.CONNECTORS(0).CONNECTEDITEM)
3014
3015
                If _line IsNot Nothing Then
3016
                    If IsBranchLine(line.CONNECTORS(0).CONNECTEDITEM, line.UID, primaryLines) = False Then
3017
                        _line.ENABLE = False
3018
                        forwardGroupLine.Add(_line)
3019
                        FindConnectPrimaryLine(drawing, primaryLines, _line, forwardGroupLine)
3020 7e561f5b gaqhf
                    End If
3021 1406fef4 gaqhf
                ElseIf _symbol IsNot Nothing Then
3022
                    _symbol.ENABLE = False
3023
                    FindConnectPrimaryLine(drawing, primaryLines, _symbol, forwardGroupLine)
3024
                End If
3025 7e561f5b gaqhf
3026 1406fef4 gaqhf
                _symbol = FindSymbolByUID(drawing.SYMBOLS, line.CONNECTORS(1).CONNECTEDITEM)
3027
                _line = FindLineByUID(primaryLines, line.CONNECTORS(1).CONNECTEDITEM)
3028
                If _line IsNot Nothing Then
3029
                    If IsBranchLine(line.CONNECTORS(1).CONNECTEDITEM, line.UID, primaryLines) = False Then
3030
                        _line.ENABLE = False
3031
                        reverseGroupLine.Add(_line)
3032
                        FindConnectPrimaryLine(drawing, primaryLines, _line, reverseGroupLine)
3033 7e561f5b gaqhf
                    End If
3034 1406fef4 gaqhf
                ElseIf _symbol IsNot Nothing Then
3035
                    _symbol.ENABLE = False
3036
                    FindConnectPrimaryLine(drawing, primaryLines, _symbol, reverseGroupLine)
3037
                End If
3038 7e561f5b gaqhf
3039 1406fef4 gaqhf
                reverseGroupLine.Reverse()
3040
                reverseGroupLine.Add(line)
3041
                reverseGroupLine.AddRange(forwardGroupLine)
3042
3043
                result.Add(reverseGroupLine)
3044 7e561f5b gaqhf
3045
            End If
3046
        Next
3047
3048
        Return result
3049
    End Function
3050
3051 1406fef4 gaqhf
3052
3053
    Private Function GetTargetLMConnector(ByVal ModelId As String, ByVal point As Pointd) As Tuple(Of LMConnector, Integer)
3054
        Dim lmConnector As LMConnector = Nothing
3055
        Dim ConnPoint1 As PointdInfo = Nothing
3056
        Dim ConnPoint2 As PointdInfo = Nothing
3057
        Dim insertIndex As Integer = 0
3058
3059
        Dim min As Double = 0
3060
        Dim max As Double = 0
3061
        Dim _tempDistance As Double = 0
3062
        Dim distance As Double = Double.MaxValue
3063
3064
        Try
3065
            Dim pointdInfos As List(Of PointdInfo) = PipeRunPoint(ModelId)
3066
3067
            For index = 0 To pointdInfos.Count - 2
3068
                Dim point1 As Pointd = pointdInfos(index).Pointd
3069
                Dim point2 As Pointd = pointdInfos(index + 1).Pointd
3070
3071
                If IsHorizontal(point1, point2) Then
3072
                    min = Math.Min(point1.X, point2.X)
3073
                    max = Math.Max(point1.X, point2.X)
3074
                    _tempDistance = Math.Abs((point1.Y + point2.Y) / 2 - point.Y)
3075
3076
                    If min <= point.X And max >= point.X And _tempDistance < distance Then
3077
                        ConnPoint1 = pointdInfos(index)
3078
                        ConnPoint2 = pointdInfos(index + 1)
3079
                        insertIndex = index + 1
3080
                        distance = _tempDistance
3081
                    End If
3082
3083
                Else
3084
                    min = Math.Min(point1.Y, point2.Y)
3085
                    max = Math.Max(point1.Y, point2.Y)
3086
                    _tempDistance = Math.Abs((point1.X + point2.X) / 2 - point.X)
3087
3088
                    If min <= point.Y And max >= point.Y And _tempDistance < distance Then
3089
                        ConnPoint1 = pointdInfos(index)
3090
                        ConnPoint2 = pointdInfos(index + 1)
3091
                        insertIndex = index + 1
3092
                        distance = _tempDistance
3093
                    End If
3094
                End If
3095
            Next
3096
3097
            If ConnPoint1 IsNot Nothing And ConnPoint2 IsNot Nothing Then
3098
                If ConnPoint1.Type = "RUN" Then
3099
                    lmConnector = GetLMConnectorByPoint(ModelId, ConnPoint1.Pointd)
3100
                ElseIf ConnPoint2.Type = "RUN" Then
3101
                    lmConnector = GetLMConnectorByPoint(ModelId, ConnPoint2.Pointd)
3102
                ElseIf ConnPoint1.Type = "BRANCH" And ConnPoint2.Type = "BRANCH" Then
3103
                    lmConnector = GetLMConnectorBySP_ID(ModelId, ConnPoint1.SP_ID, ConnPoint2.SP_ID)
3104
                Else
3105
                    Debug.WriteLine("Error At GetTargetLMConnector")
3106
                End If
3107
            End If
3108
3109
            If lmConnector Is Nothing Then
3110
                Throw New Exception("")
3111
            End If
3112
3113
            Return New Tuple(Of LMConnector, Integer)(lmConnector, insertIndex)
3114
        Catch ex As Exception
3115
            Debug.WriteLine("Error At GetTargetLMConnector")
3116
            Return Nothing
3117
        End Try
3118
    End Function
3119
3120
    Private Function GetLMConnectorByPoint(ByVal ModelId As String, ByVal point As Pointd) As LMConnector
3121
        Dim objPlacement As Placement = New Placement
3122
        Dim objConnector As LMConnector = Nothing
3123
3124
        Dim distance As Double = Double.MaxValue
3125
        Dim lmPipeRun As LMPipeRun = objPlacement.PIDDataSource.GetPipeRun(ModelId)
3126
        For Each oRep As LMRepresentation In lmPipeRun.Representations
3127
            If oRep.Attributes("RepresentationType").Value = "Connector" And oRep.Attributes("ItemStatus").Value = "Active" Then
3128
                Dim _conn As LMConnector = objPlacement.PIDDataSource.GetConnector(oRep.Id)
3129
                For Each vertex As LMConnectorVertex In _conn.ConnectorVertices
3130
                    Dim _distance As Double = CalcPointToPointdDistance(point, New Pointd(vertex.XCoordinate, vertex.YCoordinate))
3131
3132
                    If _distance < distance Then
3133
                        distance = _distance
3134
                        objConnector = _conn
3135
                    End If
3136
                Next
3137
            End If
3138
        Next
3139
3140
        Return objConnector
3141
    End Function
3142
3143
    Private Function GetLMConnectorBySP_ID(ByVal ModelId As String, ByVal SP_ID1 As String, ByVal SP_ID2 As String) As LMConnector
3144
        Dim objPlacement As Placement = New Placement
3145
        Dim objConnector As LMConnector = Nothing
3146
3147
        Dim distance As Double = Double.MaxValue
3148
        Dim lmPipeRun As LMPipeRun = objPlacement.PIDDataSource.GetPipeRun(ModelId)
3149
        For Each oRep As LMRepresentation In lmPipeRun.Representations
3150
            If oRep.Attributes("RepresentationType").Value = "Connector" And oRep.Attributes("ItemStatus").Value = "Active" Then
3151
                Dim _conn As LMConnector = objPlacement.PIDDataSource.GetConnector(oRep.Id)
3152
3153
                Dim find1 As Boolean = False
3154
                Dim find2 As Boolean = False
3155
3156
                If _conn.ConnectItem1SymbolID IsNot Nothing Then
3157
                    If _conn.ConnectItem1SymbolID.ToString = SP_ID1 Or _conn.ConnectItem1SymbolID.ToString = SP_ID2 Then
3158
                        find1 = True
3159
                    End If
3160
                End If
3161
3162
                If _conn.ConnectItem2SymbolID IsNot Nothing Then
3163
                    If _conn.ConnectItem2SymbolID.ToString = SP_ID1 Or _conn.ConnectItem2SymbolID.ToString = SP_ID2 Then
3164
                        find2 = True
3165
                    End If
3166
                End If
3167
3168
                If find1 And find2 Then
3169
                    Return _conn
3170
                End If
3171
            End If
3172
        Next
3173
3174
        If objConnector Is Nothing Then
3175
            Debug.WriteLine("Error At GetLMConnectorBySP_ID")
3176
        End If
3177
3178
        Return objConnector
3179
    End Function
3180
3181
3182
3183
    Private Function DrawPrimaryGroupLine(ByVal points As List(Of Pointd), ByVal ConnectLine1 As Line, ByVal ConnectLine2 As Line) As LMConnector
3184 7e561f5b gaqhf
        Try
3185
            Dim objPlacement As Placement = New Placement
3186
            Dim objItem As LMAItem
3187
            Dim objConnector As LMConnector
3188 1406fef4 gaqhf
3189
            Dim targetConnector1 As Tuple(Of LMConnector, Integer) = Nothing
3190
            Dim branch1_SP_ID_List As List(Of String) = New List(Of String)
3191
            Dim targetConnector2 As Tuple(Of LMConnector, Integer) = Nothing
3192
            Dim branch2_SP_ID_List As List(Of String) = New List(Of String)
3193
3194
3195
            If ConnectLine1 IsNot Nothing Then
3196
                targetConnector1 = GetTargetLMConnector(ConnectLine1.LMCONNECTOR_MODELID, points(0))
3197
3198
                Dim run As LMPipeRun = objPlacement.PIDDataSource.GetPipeRun(ConnectLine1.LMCONNECTOR_MODELID)
3199
                For Each oRep As LMRepresentation In run.Representations
3200
                    If oRep.Attributes("RepresentationType").Value = "Branch" And oRep.Attributes("ItemStatus").Value = "Active" Then
3201
                        branch1_SP_ID_List.Add(oRep.Id)
3202
                    End If
3203
                Next
3204
            End If
3205
3206
            If ConnectLine2 IsNot Nothing Then
3207
                targetConnector2 = GetTargetLMConnector(ConnectLine2.LMCONNECTOR_MODELID, points(points.Count - 1))
3208
3209
                Dim run As LMPipeRun = objPlacement.PIDDataSource.GetPipeRun(ConnectLine2.LMCONNECTOR_MODELID)
3210
                For Each oRep As LMRepresentation In run.Representations
3211
                    If oRep.Attributes("RepresentationType").Value = "Branch" And oRep.Attributes("ItemStatus").Value = "Active" Then
3212
                        branch2_SP_ID_List.Add(oRep.Id)
3213
                    End If
3214
                Next
3215
            End If
3216
3217 7e561f5b gaqhf
            Dim objInputs As PlaceRunInputs = New PlaceRunInputs
3218
            objItem = objPlacement.PIDCreateItem(GetPipeType("Primary"))
3219
3220 1406fef4 gaqhf
            For index = 0 To points.Count - 1
3221
                If index = 0 And targetConnector1 IsNot Nothing Then
3222
                    objInputs.AddConnectorTarget(targetConnector1.Item1, points(index).X, points(index).Y)
3223
                ElseIf index = points.Count - 1 And targetConnector2 IsNot Nothing Then
3224
                    objInputs.AddConnectorTarget(targetConnector2.Item1, points(index).X, points(index).Y)
3225
                Else
3226
                    objInputs.AddPoint(points(index).X, points(index).Y)
3227
                End If
3228 7e561f5b gaqhf
            Next
3229
            objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
3230
3231 1406fef4 gaqhf
3232
            '' 기존 Points에 Insert해야함
3233
            If ConnectLine1 IsNot Nothing Then
3234
                Dim run As LMPipeRun = objPlacement.PIDDataSource.GetPipeRun(ConnectLine1.LMCONNECTOR_MODELID)
3235
                For Each oRep As LMRepresentation In run.Representations
3236
                    If oRep.Attributes("RepresentationType").Value = "Branch" And oRep.Attributes("ItemStatus").Value = "Active" Then
3237
                        If branch1_SP_ID_List.Contains(oRep.Id) = False Then
3238
                            PipeRunPoint(ConnectLine1.LMCONNECTOR_MODELID).Insert(targetConnector1.Item2, New PointdInfo(points(0), "BRANCH", oRep.Id))
3239
                            Exit For
3240
                        End If
3241
                    End If
3242
                Next
3243
            End If
3244
3245
            If ConnectLine2 IsNot Nothing Then
3246
                Dim run As LMPipeRun = objPlacement.PIDDataSource.GetPipeRun(ConnectLine2.LMCONNECTOR_MODELID)
3247
                For Each oRep As LMRepresentation In run.Representations
3248
                    If oRep.Attributes("RepresentationType").Value = "Branch" And oRep.Attributes("ItemStatus").Value = "Active" Then
3249
                        If branch2_SP_ID_List.Contains(oRep.Id) = False Then
3250
                            PipeRunPoint(ConnectLine2.LMCONNECTOR_MODELID).Insert(targetConnector2.Item2, New PointdInfo(points(points.Count - 1), "BRANCH", oRep.Id))
3251
                            Exit For
3252
                        End If
3253
                    End If
3254
                Next
3255
            End If
3256
3257 7e561f5b gaqhf
            Return objConnector
3258
        Catch ex As Exception
3259 1406fef4 gaqhf
            Debug.WriteLine("Error At DrawPrimaryGroupLine")
3260 7e561f5b gaqhf
            Return Nothing
3261
        End Try
3262
3263
    End Function
3264
3265 cb364170 gaqhf
    Private Function CalcLineToPointdDistance(ByVal point1 As Pointd, ByVal point2 As Pointd, ByVal targetPointd As Pointd) As Double
3266
        If point1.X = point2.X Then
3267
            Return Math.Abs(targetPointd.X - point1.X)
3268
        ElseIf point1.Y = point2.Y Then
3269
            Return Math.Abs(targetPointd.Y - point1.Y)
3270
        Else
3271
            ' y = ax + c
3272
            Dim a As Double = (point2.Y - point1.Y) / (point2.X - point1.X)
3273
            Dim c As Double = point2.Y - a * point2.X
3274
3275
            ' ax + by + c = 0
3276
            Dim b As Double = -1
3277
            Return Math.Abs(a * targetPointd.X + b * targetPointd.Y + c) / Math.Pow(a * a + b * b, 0.5)
3278
        End If
3279
    End Function
3280
3281 1406fef4 gaqhf
    Private Function CalcPointToPointdDistance(ByVal point1 As Pointd, ByVal point2 As Pointd) As Double
3282
3283
        Return Math.Pow(Math.Pow(point1.X - point2.X, 2) + Math.Pow(point1.Y - point2.Y, 2), 0.5)
3284
3285
    End Function
3286
3287 cb364170 gaqhf
    Private Function GetConnectorTarget(ByVal Connector_ModelID As String, ByVal targetPoint As Pointd) As LMConnector
3288
        Dim objPlacement As Placement = New Placement
3289
3290
        Dim lmPipeRun As LMPipeRun = objPlacement.PIDDataSource.GetPipeRun(Connector_ModelID)
3291
3292
        Dim connList As List(Of LMConnector) = New List(Of LMConnector)
3293
        Dim oConnector As LMConnector = Nothing
3294
3295
        For Each oRep As LMRepresentation In lmPipeRun.Representations
3296
            If oRep.Attributes("RepresentationType").Value = "Connector" And oRep.Attributes("ItemStatus").Value = "Active" Then
3297
                connList.Add(objPlacement.PIDDataSource.GetConnector(oRep.Id))
3298
            End If
3299
        Next
3300
3301
        '' 자기 자신의 Line 찾기
3302
        Dim distance As Double = Double.MaxValue
3303
        For Each lmLine As LMConnector In connList
3304
            '' Connector의 포인트 정리
3305
3306
            '' 임시
3307
            oConnector = lmLine
3308
            '_Placement.PIDDataSource.GetPipingPoint()
3309
3310
            Dim pointList As List(Of Pointd) = New List(Of Pointd)
3311
3312
            For index = 1 To Integer.MaxValue
3313
                Dim point As LMConnectorVertex = lmLine.ConnectorVertices.Nth(index)
3314
                If point IsNot Nothing Then
3315
                    Dim _pointd As Pointd = New Pointd()
3316
                    _pointd.X = point.XCoordinate
3317
                    _pointd.Y = point.YCoordinate
3318
                    pointList.Add(_pointd)
3319
                Else
3320
                    Exit For
3321
                End If
3322
            Next
3323
3324
            For index = 0 To pointList.Count - 1
3325
                If pointList.Count > index + 1 Then
3326
                    Dim _tempDistance As Double = CalcLineToPointdDistance(pointList(index), pointList(index + 1), targetPoint)
3327
                    If _tempDistance < distance Then
3328
                        oConnector = lmLine
3329
                        distance = _tempDistance
3330
                    End If
3331
                End If
3332
            Next
3333
        Next
3334
3335
        Return oConnector
3336
    End Function
3337
3338
    Private Function DrawBranchLine(ByVal branchLine As Line, ByVal connLine1 As Line, ByVal connLine2 As Line) As LMConnector
3339
        Try
3340
            Dim objPlacement As Placement = New Placement
3341
            Dim objItem As LMAItem
3342
            Dim objConnector As LMConnector
3343
            Dim objInputs As PlaceRunInputs = New PlaceRunInputs
3344
            objItem = objPlacement.PIDCreateItem(GetPipeType("Primary"))
3345
3346
            If connLine1 IsNot Nothing Then
3347
                If String.IsNullOrEmpty(connLine1.LMCONNECTOR_MODELID) Then
3348
                    Return Nothing
3349
                Else
3350
3351
                    '' Branch Point
3352
                    Dim branchPoint As Pointd = New Pointd()
3353
                    If branchLine.CONNECTORS(0).CONNECTPOINT = branchLine.STARTPOINT Then
3354
                        branchPoint.X = branchLine.START_X
3355
                        branchPoint.Y = branchLine.START_Y
3356
                    ElseIf branchLine.CONNECTORS(0).CONNECTPOINT = branchLine.ENDPOINT Then
3357
                        branchPoint.X = branchLine.END_X
3358
                        branchPoint.Y = branchLine.END_Y
3359
                    Else
3360
                        Return Nothing
3361
                    End If
3362
3363
                    Dim oConnector As LMConnector = GetConnectorTarget(connLine1.LMCONNECTOR_MODELID, branchPoint)
3364
3365
                    If oConnector Is Nothing Then
3366
                        Return Nothing
3367
                    End If
3368
3369
                    objInputs.AddConnectorTarget(oConnector, branchPoint.X, branchPoint.Y)
3370
                End If
3371
            Else
3372
                If branchLine.CONNECTORS(0).CONNECTPOINT = branchLine.STARTPOINT Then
3373
                    objInputs.AddPoint(branchLine.START_X, branchLine.START_Y)
3374
                Else
3375
                    objInputs.AddPoint(branchLine.END_X, branchLine.END_Y)
3376
                End If
3377
            End If
3378
3379
            If connLine2 IsNot Nothing Then
3380
                If String.IsNullOrEmpty(connLine2.LMCONNECTOR_MODELID) Then
3381
                    Return Nothing
3382
                Else
3383
                    '' Branch Point
3384
                    Dim branchPoint As Pointd = New Pointd()
3385
                    If branchLine.CONNECTORS(1).CONNECTPOINT = branchLine.STARTPOINT Then
3386
                        branchPoint.X = branchLine.START_X
3387
                        branchPoint.Y = branchLine.START_Y
3388
                    Else
3389
                        branchPoint.X = branchLine.END_X
3390
                        branchPoint.Y = branchLine.END_Y
3391
                    End If
3392
3393
                    Dim oConnector As LMConnector = GetConnectorTarget(connLine2.LMCONNECTOR_MODELID, branchPoint)
3394
3395
                    If oConnector Is Nothing Then
3396
                        Return Nothing
3397
                    End If
3398
3399
                    objInputs.AddConnectorTarget(oConnector, branchPoint.X, branchPoint.Y)
3400
                End If
3401
            Else
3402
                If branchLine.CONNECTORS(1).CONNECTPOINT = branchLine.STARTPOINT Then
3403
                    objInputs.AddPoint(branchLine.START_X, branchLine.START_Y)
3404
                Else
3405
                    objInputs.AddPoint(branchLine.END_X, branchLine.END_Y)
3406
                End If
3407
            End If
3408
3409
            objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
3410
3411
            Dim _lmPipeRun As LMPipeRun = objPlacement.PIDDataSource.GetPipeRun(objConnector.ModelItemID)
3412
            _lmPipeRun.StreamNo = branchLine.UID
3413
3414
            Return objConnector
3415
        Catch ex As Exception
3416
            SetListBoxItems(ListBox_Result, ex.Message)
3417
            Return Nothing
3418
        End Try
3419
3420
    End Function
3421
3422
3423
    Private Function FindFirstLine(ByVal primaryLineList As List(Of Line), ByVal symbols As List(Of Symbol), ByVal symbol As Symbol, ByVal UID As String) As Line
3424
3425
        For Each conn As Connector In symbol.CONNECTORS
3426
            '' 자기 자신일 경우 제외
3427
            If conn.CONNECTEDITEM = UID Then
3428
                Continue For
3429
            End If
3430
3431
            Dim _symbol As Symbol = FindSymbolByUID(symbols, conn.CONNECTEDITEM)
3432
            Dim _line As Line = FindLineByUID(primaryLineList, conn.CONNECTEDITEM)
3433
3434
            If _line IsNot Nothing Then
3435
                If _line.ENABLE = False Then
3436
                    Return _line
3437
                End If
3438
            ElseIf _symbol IsNot Nothing Then
3439
                Return FindFirstLine(primaryLineList, symbols, _symbol, symbol.UID)
3440
            End If
3441
        Next
3442
3443
        Return Nothing
3444
3445
    End Function
3446
3447
3448
3449 1406fef4 gaqhf
    Private Sub DrawPrimaryLineGroup(ByVal primaryGroup As List(Of List(Of Line)), ByVal primaryLines As List(Of Line))
3450 7e561f5b gaqhf
3451 1406fef4 gaqhf
        Dim loopGroup As List(Of Line) = Nothing
3452 7e561f5b gaqhf
3453 1406fef4 gaqhf
        While primaryGroup.Count > 0
3454
            For Each group As List(Of Line) In primaryGroup
3455
                Dim firstLine As Line = group(0)
3456
                Dim lastLine As Line = group(group.Count - 1)
3457 7e561f5b gaqhf
3458 1406fef4 gaqhf
                Dim line1 As Line = Nothing
3459
                Dim line2 As Line = Nothing
3460 7e561f5b gaqhf
3461 1406fef4 gaqhf
                If group.Count = 1 Then
3462
                    line1 = FindLineByUID(primaryLines, firstLine.CONNECTORS(0).CONNECTEDITEM)
3463
                    line2 = FindLineByUID(primaryLines, firstLine.CONNECTORS(1).CONNECTEDITEM)
3464 7e561f5b gaqhf
3465 1406fef4 gaqhf
                Else
3466
                    '' 붙은 Branch 라인이 있는지 확인함
3467
                    Dim _temp1 As Line = FindLineByUID(primaryLines, firstLine.CONNECTORS(0).CONNECTEDITEM)
3468
                    Dim _temp2 As Line = FindLineByUID(primaryLines, firstLine.CONNECTORS(1).CONNECTEDITEM)
3469
3470
                    If _temp1 IsNot Nothing Then
3471
                        If group.Contains(_temp1) = False Then
3472
                            line1 = _temp1
3473 cb364170 gaqhf
                        End If
3474 1406fef4 gaqhf
                    End If
3475 7e561f5b gaqhf
3476 1406fef4 gaqhf
                    If line1 Is Nothing And _temp2 IsNot Nothing Then
3477
                        If group.Contains(_temp2) = False Then
3478
                            line1 = _temp2
3479
                        End If
3480
                    End If
3481
3482
                    _temp1 = FindLineByUID(primaryLines, lastLine.CONNECTORS(0).CONNECTEDITEM)
3483
                    _temp2 = FindLineByUID(primaryLines, lastLine.CONNECTORS(1).CONNECTEDITEM)
3484
3485
                    If _temp1 IsNot Nothing Then
3486
                        If group.Contains(_temp1) = False Then
3487
                            line2 = _temp1
3488
                        End If
3489
                    End If
3490
3491
                    If line2 Is Nothing And _temp2 IsNot Nothing Then
3492
                        If group.Contains(_temp2) = False Then
3493
                            line2 = _temp2
3494 cb364170 gaqhf
                        End If
3495 1406fef4 gaqhf
                    End If
3496 7e561f5b gaqhf
3497 1406fef4 gaqhf
                End If
3498 7e561f5b gaqhf
3499 1406fef4 gaqhf
                '' line1, line2 가 nothing : 연결된게 없다
3500
                '' line1, line2 가 not nothing : 연결된게 있는데 모델링 된지는 확인해야함
3501
                If line1 IsNot Nothing Then
3502
                    If String.IsNullOrEmpty(line1.LMCONNECTOR_MODELID) Then
3503
                        If loopGroup IsNot Nothing Then
3504
                            If loopGroup.Equals(group) Then
3505
                                SetListBoxItems(ListBox_Result, "Fail to create primary group line [loop]")
3506
                                loopGroup = Nothing
3507
                                primaryGroup.Remove(group)
3508
                            End If
3509 cb364170 gaqhf
                        Else
3510 1406fef4 gaqhf
                            loopGroup = group
3511 cb364170 gaqhf
                        End If
3512 1406fef4 gaqhf
                        Continue For
3513
                    End If
3514
                End If
3515 7e561f5b gaqhf
3516 1406fef4 gaqhf
                If line2 IsNot Nothing Then
3517
                    If String.IsNullOrEmpty(line2.LMCONNECTOR_MODELID) Then
3518
                        If loopGroup IsNot Nothing Then
3519
                            If loopGroup.Equals(group) Then
3520
                                SetListBoxItems(ListBox_Result, "Fail to create primary group line [loop]")
3521
                                loopGroup = Nothing
3522
                                primaryGroup.Remove(group)
3523
                            End If
3524
                        Else
3525
                            loopGroup = group
3526
                        End If
3527
                        Continue For
3528
                    End If
3529
                End If
3530 7e561f5b gaqhf
3531
3532 1406fef4 gaqhf
                '' 만약 2개가 같은 라인바라보면 수정 필요
3533
                If line1 IsNot Nothing And line2 IsNot Nothing Then
3534
                    If line1.LMCONNECTOR_MODELID = line2.LMCONNECTOR_MODELID Then
3535
                        line2 = Nothing
3536
                    End If
3537
                End If
3538 7e561f5b gaqhf
3539 1406fef4 gaqhf
                '' 그림
3540
                Dim points As List(Of Pointd) = GetGroupPoint(group)
3541
                Dim lmConnector As LMConnector = DrawPrimaryGroupLine(points, line1, line2)
3542
                If lmConnector Is Nothing Then
3543
                    SetListBoxItems(ListBox_Result, "Fail to create primary group line")
3544
                    primaryGroup.Remove(group)
3545
                    Continue For
3546
                End If
3547
                For Each line As Line In group
3548
                    line.LMCONNECTOR_MODELID = lmConnector.ModelItemID
3549
                Next
3550 7e561f5b gaqhf
3551
3552 1406fef4 gaqhf
                Dim poinInfotList As List(Of PointdInfo) = New List(Of PointdInfo)
3553
                For index = 0 To points.Count - 1
3554
                    If index = 0 And line1 IsNot Nothing Then
3555
                        poinInfotList.Add(New PointdInfo(points(index), "BRANCH", GetBranch_SP_ID(lmConnector, line1.LMCONNECTOR_MODELID)))
3556
                    ElseIf index = points.Count - 1 And line2 IsNot Nothing Then
3557
                        poinInfotList.Add(New PointdInfo(points(index), "BRANCH", GetBranch_SP_ID(lmConnector, line2.LMCONNECTOR_MODELID)))
3558
                    Else
3559
                        poinInfotList.Add(New PointdInfo(points(index), "RUN"))
3560
                    End If
3561
                Next
3562 7e561f5b gaqhf
3563 1406fef4 gaqhf
                PipeRunPoint.Add(lmConnector.ModelItemID, poinInfotList)
3564 7e561f5b gaqhf
3565 1406fef4 gaqhf
                loopGroup = Nothing
3566
                primaryGroup.Remove(group)
3567
                Exit For
3568
            Next
3569
3570
        End While
3571
    End Sub
3572
3573
    Private Function GetBranch_SP_ID(ByVal lmConnector As LMConnector, ByVal ModelId As String) As String
3574
        Dim objPlacement As Placement = New Placement
3575
3576
        Dim run As LMPipeRun = objPlacement.PIDDataSource.GetPipeRun(ModelId)
3577
3578
        For Each oRep As LMRepresentation In run.Representations
3579
            If oRep.Attributes("RepresentationType").Value = "Branch" And oRep.Attributes("ItemStatus").Value = "Active" Then
3580
                If lmConnector.ConnectItem1SymbolID IsNot Nothing Then
3581
                    If oRep.Id = lmConnector.ConnectItem1SymbolID.ToString Then
3582
                        Return oRep.Id
3583
                    End If
3584
                End If
3585
                If lmConnector.ConnectItem2SymbolID IsNot Nothing Then
3586
                    If oRep.Id = lmConnector.ConnectItem2SymbolID.ToString Then
3587
                        Return oRep.Id
3588 7e561f5b gaqhf
                    End If
3589 1406fef4 gaqhf
                End If
3590
3591
3592
            End If
3593
        Next
3594
3595
        Throw New Exception("why")
3596
    End Function
3597
3598
    Private Sub PrimaryPipeModeling()
3599
        Try
3600
            For Each oDrwing As TreeNode In Tree_Result.Nodes
3601
                For Each oDwgNode As TreeNode In oDrwing.Nodes
3602
                    Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
3603
                    Dim CDrawing As Drawing = GetDrawing(sDwgName)
3604
3605
                    '' Primary Line만 가져옴
3606
                    Dim primaryLineList As List(Of Line) = New List(Of Line)
3607
                    GetPrimaryLineInNode(primaryLineList, oDwgNode)
3608
3609
                    '' Branch Line 가져옴
3610
                    Dim branchLines As List(Of Line) = FindBranchLine(primaryLineList)
3611
3612
                    '' Draw Primary Line Group
3613
                    Dim primaryGroup As List(Of List(Of Line)) = GetPrimaryGroup(CDrawing, primaryLineList)
3614
                    DrawPrimaryLineGroup(primaryGroup, primaryLineList)
3615 7e561f5b gaqhf
                Next
3616
            Next
3617
        Catch ex As Exception
3618
3619
        End Try
3620
3621
    End Sub
3622
3623
    Structure Pointd
3624 1406fef4 gaqhf
        Public Sub New(ByVal X As Double, ByVal Y As Double)
3625
            Me.X = X
3626
            Me.Y = Y
3627
        End Sub
3628 7e561f5b gaqhf
        Public X As Double
3629
        Public Y As Double
3630
    End Structure
3631
3632 1406fef4 gaqhf
    Class PointdInfo
3633
        Public Sub New(ByVal Pointd As Pointd, ByVal Type As String)
3634
            Me.Pointd = Pointd
3635
            Me.Type = Type
3636
        End Sub
3637
3638
        Public Sub New(ByVal Pointd As Pointd, ByVal Type As String, ByVal SP_ID As String)
3639
            Me.Pointd = Pointd
3640
            Me.Type = Type
3641
            Me.SP_ID = SP_ID
3642
        End Sub
3643
3644
        Public Pointd As Pointd
3645
        Public Type As String
3646
        Public SP_ID As String
3647
    End Class
3648
3649 7e561f5b gaqhf
    Private Function GetGroupPoint(ByVal group As List(Of Line)) As List(Of Pointd)
3650
3651
        Dim resultLine As List(Of Tuple(Of Line, Boolean)) = New List(Of Tuple(Of Line, Boolean))
3652
        Dim _lines As List(Of Tuple(Of Line, Boolean)) = New List(Of Tuple(Of Line, Boolean))
3653
        For Each line As Line In group
3654
            Dim tuple As Tuple(Of Line, Boolean) = New Tuple(Of Line, Boolean)(line, IsHorizontal(line))
3655
            _lines.Add(tuple)
3656
        Next
3657
3658
3659
        For Each tuple As Tuple(Of Line, Boolean) In _lines
3660
            If resultLine.Count = 0 Then
3661
                resultLine.Add(tuple)
3662
            Else
3663
                Dim prevTuple As Tuple(Of Line, Boolean) = resultLine(resultLine.Count - 1)
3664
3665
                If prevTuple.Item2 = tuple.Item2 Then
3666
                    resultLine.Remove(prevTuple)
3667
                    resultLine.Add(mergeLine(tuple.Item1, prevTuple.Item1, tuple.Item2))
3668
                Else
3669
                    resultLine.Add(tuple)
3670
                End If
3671
            End If
3672
        Next
3673
3674
        Dim pointList As List(Of Pointd) = New List(Of Pointd)
3675
        For Each tuple As Tuple(Of Line, Boolean) In resultLine
3676
            If pointList.Count = 0 Then
3677
                Dim line As Line = tuple.Item1
3678
3679
                Dim point1 As Pointd
3680
                point1.X = line.START_X
3681
                point1.Y = line.START_Y
3682
3683
                Dim point2 As Pointd
3684
                point2.X = line.END_X
3685
                point2.Y = line.END_Y
3686
3687
                pointList.Add(point1)
3688
                pointList.Add(point2)
3689
            Else
3690
                Dim line As Line = tuple.Item1
3691
                Dim isHorizontal As Boolean = tuple.Item2
3692
3693
3694
                Dim prevPoint1 As Pointd = pointList(pointList.Count - 2)
3695
                Dim prevPoint2 As Pointd = pointList(pointList.Count - 1)
3696
                Dim currPoint1 As Pointd = New Pointd()
3697
                currPoint1.X = line.START_X
3698
                currPoint1.Y = line.START_Y
3699
                Dim currPoint2 As Pointd = New Pointd()
3700
                currPoint2.X = line.END_X
3701
                currPoint2.Y = line.END_Y
3702
3703
                ''제일 작은 조합의 반대편 prevPoint를 넣어야함
3704
                Dim distance = CalcDistance(prevPoint1, currPoint1)
3705
                Dim prev = True
3706
                Dim curr = True
3707
3708
                If distance > CalcDistance(prevPoint1, currPoint2) Then
3709
                    distance = CalcDistance(prevPoint1, currPoint2)
3710
                    curr = False
3711
                End If
3712
3713
                If distance > CalcDistance(prevPoint2, currPoint1) Then
3714
                    distance = CalcDistance(prevPoint2, currPoint1)
3715
                    prev = False
3716
                    curr = True
3717
                End If
3718
3719
                If distance > CalcDistance(prevPoint2, currPoint2) Then
3720
                    distance = CalcDistance(prevPoint2, currPoint2)
3721
                    prev = False
3722
                    curr = False
3723
                End If
3724
3725
                pointList.RemoveAt(pointList.Count - 2)
3726
                pointList.RemoveAt(pointList.Count - 1)
3727
3728
                ' 지금은 수평 / 이전 수직
3729
                If isHorizontal Then
3730
                    If prev Then
3731
                        pointList.Add(prevPoint2)
3732
3733
                        If curr Then
3734
                            Dim newPoint As Pointd = New Pointd()
3735
                            newPoint.X = prevPoint2.X
3736
                            newPoint.Y = currPoint2.Y
3737
                            pointList.Add(newPoint)
3738
3739
                            pointList.Add(currPoint2)
3740
                        Else
3741
                            Dim newPoint As Pointd = New Pointd()
3742
                            newPoint.X = prevPoint2.X
3743
                            newPoint.Y = currPoint1.Y
3744
                            pointList.Add(newPoint)
3745
3746
                            pointList.Add(currPoint1)
3747
                        End If
3748
                    Else
3749
                        pointList.Add(prevPoint1)
3750
3751
                        If curr Then
3752
                            Dim newPoint As Pointd = New Pointd()
3753
                            newPoint.X = prevPoint1.X
3754
                            newPoint.Y = currPoint2.Y
3755
                            pointList.Add(newPoint)
3756
3757
                            pointList.Add(currPoint2)
3758
                        Else
3759
                            Dim newPoint As Pointd = New Pointd()
3760
                            newPoint.X = prevPoint1.X
3761
                            newPoint.Y = currPoint1.Y
3762
                            pointList.Add(newPoint)
3763
3764
                            pointList.Add(currPoint1)
3765
                        End If
3766
                    End If
3767
                    '지금은 수직 / 이전 수평
3768
                Else
3769
                    If prev Then
3770
                        pointList.Add(prevPoint2)
3771
3772
                        If curr Then
3773
                            Dim newPoint As Pointd = New Pointd()
3774
                            newPoint.X = currPoint2.X
3775
                            newPoint.Y = prevPoint2.Y
3776
                            pointList.Add(newPoint)
3777
3778
                            pointList.Add(currPoint2)
3779
                        Else
3780
                            Dim newPoint As Pointd = New Pointd()
3781
                            newPoint.X = currPoint1.X
3782
                            newPoint.Y = prevPoint2.Y
3783
                            pointList.Add(newPoint)
3784
3785
                            pointList.Add(currPoint1)
3786
                        End If
3787
                    Else
3788
                        pointList.Add(prevPoint1)
3789
3790
                        If curr Then
3791
                            Dim newPoint As Pointd = New Pointd()
3792
                            newPoint.X = currPoint2.X
3793
                            newPoint.Y = prevPoint1.Y
3794
                            pointList.Add(newPoint)
3795
3796
                            pointList.Add(currPoint2)
3797
                        Else
3798
                            Dim newPoint As Pointd = New Pointd()
3799
                            newPoint.X = currPoint1.X
3800
                            newPoint.Y = prevPoint1.Y
3801
                            pointList.Add(newPoint)
3802
3803
                            pointList.Add(currPoint1)
3804
                        End If
3805
                    End If
3806
                End If
3807
            End If
3808
        Next
3809
3810
        Return pointList
3811
    End Function
3812
3813
    Private Function CalcDistance(ByVal point1 As Pointd, ByVal point2 As Pointd) As Double
3814
        Return Math.Pow(Math.Sqrt(Math.Abs(point1.X - point2.X)) + Math.Sqrt(Math.Abs(point1.Y - point2.Y)), 0.5)
3815
    End Function
3816
3817
    Private Function mergeLine(line1 As Line, line2 As Line, isHorizontal As Boolean) As Tuple(Of Line, Boolean)
3818
        If isHorizontal Then
3819
            Dim min As Double = Math.Min(line1.START_X, Math.Min(line1.END_X, Math.Min(line2.START_X, line2.END_X)))
3820
            Dim max As Double = Math.Max(line1.START_X, Math.Max(line1.END_X, Math.Max(line2.START_X, line2.END_X)))
3821
3822
            Dim nLine As Line = New Line()
3823
            nLine.START_X = min
3824
            nLine.START_Y = line1.START_Y
3825
            nLine.END_X = max
3826
            nLine.END_Y = line1.START_Y
3827
3828
            Dim tuple As Tuple(Of Line, Boolean) = New Tuple(Of Line, Boolean)(nLine, isHorizontal)
3829
            Return tuple
3830
        Else
3831
            Dim min As Double = Math.Min(line1.START_Y, Math.Min(line1.END_Y, Math.Min(line2.START_Y, line2.END_Y)))
3832
            Dim max As Double = Math.Max(line1.START_Y, Math.Max(line1.END_Y, Math.Max(line2.START_Y, line2.END_Y)))
3833
3834
            Dim nLine As Line = New Line()
3835
            nLine.START_X = line1.START_X
3836
            nLine.START_Y = min
3837
            nLine.END_X = line1.START_X
3838
            nLine.END_Y = max
3839
3840
            Dim tuple As Tuple(Of Line, Boolean) = New Tuple(Of Line, Boolean)(nLine, isHorizontal)
3841
            Return tuple
3842
        End If
3843
3844
    End Function
3845 b08338e3 Gyusu
3846
    Private Sub FindNearPoint(ByVal oOPCSymbol As LMSymbol, ByRef dNear_x As Double, ByRef dNear_y As Double)
3847
        Dim oConnectionPoints_x(4) As Double
3848
        Dim oConnectionPoints_y(4) As Double
3849
3850
        Try
3851
            _Placement.PIDConnectPointLocation(oOPCSymbol, 1, oConnectionPoints_x(0), oConnectionPoints_y(0))
3852
            _Placement.PIDConnectPointLocation(oOPCSymbol, 2, oConnectionPoints_x(1), oConnectionPoints_y(1))
3853
            _Placement.PIDConnectPointLocation(oOPCSymbol, 3, oConnectionPoints_x(2), oConnectionPoints_y(2))
3854
            _Placement.PIDConnectPointLocation(oOPCSymbol, 4, oConnectionPoints_x(3), oConnectionPoints_y(3))
3855
            Dim iNearPoint As Integer = 0
3856
            Dim dGap As Double = 0
3857
            For i = 0 To 3
3858
                If dGap = 0 Then
3859
                    iNearPoint = i
3860
                    dGap = Math.Abs(oConnectionPoints_x(i) - dNear_x) + Math.Abs(oConnectionPoints_y(i) - dNear_y)
3861
                Else
3862
                    If dGap >= Math.Abs(oConnectionPoints_x(i) - dNear_x) + Math.Abs(oConnectionPoints_y(i) - dNear_y) Then
3863
                        iNearPoint = i
3864
                        dGap = Math.Abs(oConnectionPoints_x(i) - dNear_x) + Math.Abs(oConnectionPoints_y(i) - dNear_y)
3865
                    End If
3866
                End If
3867
            Next
3868
            dNear_x = oConnectionPoints_x(iNearPoint)
3869
            dNear_y = oConnectionPoints_y(iNearPoint)
3870
        Catch ex As Exception
3871 e4000111 Gyusu
3872 bb2a0c79 Gyusu
        End Try
3873 e4000111 Gyusu
3874 bb2a0c79 Gyusu
    End Sub
3875
3876 9c86a823 Gyusu
    Private Function GetPipeColor(ByVal sType As String) As Color
3877
        If sType.ToUpper() = "ELECTRIC" Then
3878
            Return Color.DarkOrange
3879
        ElseIf sType.ToUpper() = "CONNECT TO PROCESS" Then
3880 b82166d4 Gyusu
            Return Color.Green
3881 9c86a823 Gyusu
        ElseIf sType.ToUpper() = "SOFTWARE" Then
3882
            Return Color.Blue
3883
        ElseIf sType.ToUpper() = "PNEUMATIC" Then
3884
            Return Color.Gray
3885
        Else
3886
            Return Color.Black
3887
        End If
3888
    End Function
3889
3890 bb2a0c79 Gyusu
    Private Function GetPipeType(ByVal sType As String) As String
3891
        Dim sSystempath As String = "\Piping\Routing\Process Lines\Primary Piping.sym" ' oPipeRow(0)(_XML_LINE_SYSTEMPATH).ToString()
3892
        If sType.ToUpper() = "ELECTRIC" Then
3893
            sSystempath = "\Instrumentation\Signal Line\Electric.sym"
3894
        ElseIf sType.ToUpper() = "CONNECT TO PROCESS" Then
3895
            sSystempath = "\Instrumentation\Signal Line\Connect to Process.sym"
3896 9c86a823 Gyusu
        ElseIf sType.ToUpper() = "SOFTWARE" Then
3897
            sSystempath = "\Instrumentation\Signal Line\Software Link.sym"
3898
        ElseIf sType.ToUpper() = "PNEUMATIC" Then
3899
            sSystempath = "\Instrumentation\Signal Line\Pneumatic.sym"
3900 bb2a0c79 Gyusu
        Else
3901
        End If
3902
        Return sSystempath
3903
    End Function
3904
3905
    Private Sub InitAutoRouting()
3906
        For Each oDrwing As TreeNode In Tree_Result.Nodes
3907
            For Each oDwgNode As TreeNode In oDrwing.Nodes
3908
                Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
3909
                Dim CDrawing As Drawing = GetDrawing(sDwgName)
3910
                If CDrawing IsNot Nothing Then
3911
                    Dim iAllLineNoCount As Integer = Tree_Result.Nodes.Count ' GetCheckNodeCount(oLinenoNode)
3912
                    Dim iPipingOPC_count As Integer = 0 ' GetCheckNodeCount(oLinenoNode)
3913
                    SetListBoxItems(ListBox_Result, "Place " & CDrawing.DwgName & "....")
3914 b08338e3 Gyusu
3915 bb2a0c79 Gyusu
                    For Each oNode As TreeNode In oDwgNode.Nodes
3916
                        Dim iItemcnt As Integer = 0
3917
                        Dim sNodeUid As String = oNode.Name
3918
                        Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
3919
                        Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
3920
                        If CLineNo IsNot Nothing Then
3921
                            Dim oLine_Dt As DataTable = CLineNo.Dt_Line
3922
                            Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
3923
3924
                            For Each oLineRow In oLine_Dt.Rows
3925 76f465d0 Gyusu
                                ' oLineRow(_XML_LINE_UID) = ""
3926
                                oLineRow(_XML_LINE_SPID) = ""
3927
                                oLineRow(_XML_LINE_LMCONNECTOR) = Nothing
3928
                                oLineRow(_XML_LINE_LMCONNECTOR_1) = Nothing
3929
                                oLineRow(_XML_LINE_LMCONNECTOR_2) = Nothing
3930
                                oLineRow(_XML_LINE_DRAWING_TF) = "FALSE"
3931 76f5e1a8 Gyusu
                                oLineRow(_XML_LINE_Check) = "FALSE"
3932 76f465d0 Gyusu
                            Next
3933
                            For Each oSymbolRow In oSymbol_Dt.Rows
3934
                                '   oSymbolRow(_XML_SYMBOL_UID) = ""
3935
                                oSymbolRow(_XML_SYMBOL_SPID) = ""
3936
                                oSymbolRow(_XML_SYMBOL_LMSYMBOL) = Nothing
3937
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_1) = Nothing
3938
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_2) = Nothing
3939
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_3) = Nothing
3940
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_4) = Nothing
3941 76f5e1a8 Gyusu
                                oSymbolRow(_XML_SYMBOL_Check) = "FALSE"
3942 76f465d0 Gyusu
                                oSymbolRow(_XML_SYMBOL_DRAWING_TF) = "FALSE"
3943
3944
                            Next
3945
3946
                        End If
3947
3948
                        Dim CTRIMLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
3949
                        If CTRIMLineNo IsNot Nothing Then
3950
                            Dim oLine_Dt As DataTable = CTRIMLineNo.Dt_Line
3951
                            Dim oSymbol_Dt As DataTable = CTRIMLineNo.Dt_Symbol
3952
3953
                            For Each oLineRow In oLine_Dt.Rows
3954
                                ' oLineRow(_XML_LINE_UID) = ""
3955 bb2a0c79 Gyusu
                                oLineRow(_XML_LINE_SPID) = ""
3956 76f465d0 Gyusu
                                oLineRow(_XML_LINE_LMCONNECTOR) = Nothing
3957
                                oLineRow(_XML_LINE_LMCONNECTOR_1) = Nothing
3958
                                oLineRow(_XML_LINE_LMCONNECTOR_2) = Nothing
3959 bb2a0c79 Gyusu
                                oLineRow(_XML_LINE_DRAWING_TF) = "FALSE"
3960 76f5e1a8 Gyusu
                                oLineRow(_XML_LINE_Check) = "FALSE"
3961 bb2a0c79 Gyusu
                            Next
3962
                            For Each oSymbolRow In oSymbol_Dt.Rows
3963 76f465d0 Gyusu
                                '   oSymbolRow(_XML_SYMBOL_UID) = ""
3964 bb2a0c79 Gyusu
                                oSymbolRow(_XML_SYMBOL_SPID) = ""
3965 76f465d0 Gyusu
                                oSymbolRow(_XML_SYMBOL_LMSYMBOL) = Nothing
3966
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_1) = Nothing
3967
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_2) = Nothing
3968
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_3) = Nothing
3969
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_4) = Nothing
3970 76f5e1a8 Gyusu
                                oSymbolRow(_XML_SYMBOL_Check) = "FALSE"
3971 bb2a0c79 Gyusu
                                oSymbolRow(_XML_SYMBOL_DRAWING_TF) = "FALSE"
3972 76f465d0 Gyusu
3973 bb2a0c79 Gyusu
                            Next
3974
3975
                        End If
3976
                    Next
3977
                End If
3978
            Next
3979
        Next
3980
    End Sub
3981
3982
3983
3984
3985
3986
3987 79326880 Gyusu
    Private Function CheckBranchLine(ByVal dStartX As Double, ByVal dStartY As Double,
3988 bb2a0c79 Gyusu
                                ByRef dEndX As Double, ByRef dEndY As Double, ByRef sBranchType As String, ByRef oLMConnector As LMConnector) As Boolean
3989
3990
        Try
3991 79326880 Gyusu
3992
            For Each oModelrow In _ModelingLine_Dt.Rows
3993
                'Dim sStartPoint As String = oModelrow(_XML_LINE_STARTPOINT)
3994
                'Dim sEndPoint As String = oModelrow(_XML_LINE_ENDPOINT)
3995 bb2a0c79 Gyusu
                Dim dModelStartX As Double
3996
                Dim dModelStartY As Double
3997
                Dim dModelEndX As Double
3998
                Dim dModelEndY As Double
3999 79326880 Gyusu
                dModelStartX = oModelrow(_XML_LINE_DWG_STARTPOINT_X)
4000
                dModelStartY = oModelrow(_XML_LINE_DWG_STARTPOINT_Y)
4001
                dModelEndX = oModelrow(_XML_LINE_DWG_ENDPOINT_X)
4002
                dModelEndY = oModelrow(_XML_LINE_DWG_ENDPOINT_Y)
4003
                'ConvertPointBystring(sStartPoint, dModelStartX, dModelStartY)
4004
                'ConvertPointBystring(sEndPoint, dModelEndX, dModelEndY)
4005
                'ConvertPointByImage(dModelStartX, dModelStartY, _IMG_X, _IMG_Y)
4006
                'ConvertPointByImage(dModelEndX, dModelEndY, _IMG_X, _IMG_Y)
4007 bb2a0c79 Gyusu
                Dim dGap As Double = 0.0002
4008
                Dim d기준x As Double = (dModelStartX + dModelEndX) / 2
4009
                Dim d기준y As Double = (dModelStartY + dModelEndY) / 2
4010
                Try
4011
                    oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4012
                Catch ex As Exception
4013
4014
                End Try
4015
                Dim oRun As LMPipeRun = Nothing
4016
                Try
4017
4018
                    oRun = _Placement.PIDDataSource.GetPipeRun(oLMConnector.ModelItemID)
4019
                    Dim dResultCalc As Double = -1
4020
                    For Each objRep In oRun.Representations
4021
                        If objRep.Attributes("RepresentationType").Value = "Connector" And objRep.Attributes("ItemStatus").Value = "Active" Then
4022
                            Dim objConnector As LMConnector = _Placement.PIDDataSource.GetConnector(objRep.ID)
4023
                            For Each objConnectorVertex In objConnector.ConnectorVertices
4024
                                Dim dConn_X As Double = objConnectorVertex.Attributes("XCoordinate").Value
4025
                                Dim dConn_Y As Double = objConnectorVertex.Attributes("YCoordinate").Value
4026
                                Dim dStartCalc As Double = Math.Abs(dStartX - dConn_X) + Math.Abs(dStartY - dConn_Y)
4027
4028
                                If dResultCalc > dStartCalc Or dResultCalc = -1 Then
4029
                                    dResultCalc = dStartCalc
4030
                                    oLMConnector = objConnector
4031
                                    d기준x = dConn_X
4032
                                    d기준y = dConn_Y
4033
                                End If
4034
                                Dim dEndCalc As Double = Math.Abs(dEndX - dConn_X) + Math.Abs(dEndY - dConn_Y)
4035
                                If dResultCalc > dEndCalc Then
4036
                                    dResultCalc = dEndCalc
4037
                                    oLMConnector = objConnector
4038
                                    d기준x = dConn_X
4039
                                    d기준y = dConn_Y
4040
                                End If
4041
                            Next
4042
                        End If
4043
                    Next
4044
                    '        _Placement.PIDConnectPointLocation(oRun, 1, dModelStartX, dModelEndX)
4045
                    '       _Placement.PIDConnectPointLocation(oRun, 2, dModelEndX, dModelEndY)
4046
                Catch ex As Exception
4047
                End Try
4048
4049
4050
                'Dim sSPID As String = oModelrow(_XML_LINE_SPID).ToString()
4051
                'Dim oPipeRun As LMPipeRun = _Placement.PIDDataSource.Get PipeRun(sSPID)
4052
                'If dModelStartX + dGap > dStartX And dModelStartX - dGap < dStartX And
4053
                '        dModelStartY + dGap > dStartY And dModelStartY - dGap < dStartY Then
4054
                '    dStartX = dModelStartX
4055
                '    dStartY = dModelStartY
4056
                'ElseIf dModelEndX + dGap > dStartX And dModelEndX - dGap < dStartX And
4057
                '        dModelEndY + dGap > dStartY And dModelEndY - dGap < dStartY Then
4058
                '    dStartX = dModelEndX
4059
                '    dStartY = dModelEndY
4060
                'End If
4061
4062
                'Vetical
4063
                If Math.Abs(dModelStartX - dModelEndX) <= Math.Abs(dModelStartY - dModelEndY) Then
4064
                    If Math.Abs(dStartX - dEndX) >= Math.Abs(dStartY - dEndY) Then
4065
                        'Horizontal 
4066
                        ' dGap = 0.0002 'Math.Abs(dStartX - dEndX) / 20
4067
                        '기준선의 Y범위안에 가로선이 포함되어야됨
4068
                        If (dModelStartY + dGap >= dStartY And dModelEndY - dGap <= dStartY) Or
4069
                            (dModelStartY - dGap <= dStartY And dModelEndY + dGap >= dStartY) And
4070
                            (dModelStartY + dGap >= dEndY And dModelEndY - dGap <= dEndY) Or
4071
                            (dModelStartY - dGap <= dEndY And dModelEndY + dGap >= dEndY) Then
4072
                            '기준선보다 왼쪽에 가로선이 있을때
4073
                            If d기준x >= dStartX And d기준x >= dEndX Then
4074
                                If dStartX >= dEndX Then
4075
                                    'dStartX 좌표를 기준으로 Gap만큼 더했을때 기준선보다 큰지 확인
4076
                                    If dStartX + dGap >= d기준x Then
4077
                                        dStartX = d기준x
4078
                                        sBranchType = "1"
4079
                                        Return True
4080
                                    End If
4081
                                Else
4082
                                    'dEndX 좌표를 기준으로 Gap만큼 더했을때 기준선보다 큰지 확인
4083
                                    If dEndX + dGap >= d기준x Then
4084
                                        dEndX = d기준x
4085
                                        sBranchType = "2"
4086
                                        Return True
4087
                                    End If
4088
                                End If
4089
                                '기준선보다 오른쪽에 가로선이 있을때
4090
                            ElseIf d기준x <= dStartX And d기준x <= dEndX Then
4091
                                If dStartX >= dEndX Then
4092
                                    'dEndX 좌표를 기준으로 Gap만큼 뺐을때 기준선보다 작은지 확인
4093
                                    If dEndX - dGap <= d기준x Then
4094
                                        dEndX = d기준x
4095
                                        sBranchType = "2"
4096
                                        Return True
4097
                                    End If
4098
                                Else
4099
                                    'dStartX 좌표를 기준으로 Gap만큼 뺐을때 기준선보다 작은지 확인
4100
                                    If dStartX - dGap <= d기준x Then
4101
                                        dStartX = d기준x
4102
                                        sBranchType = "1"
4103
                                        Return True
4104
                                    End If
4105
                                End If
4106
                            Else
4107
                                '기준선과 세로선이 겹칠때
4108
                                If (d기준x >= dStartX And d기준x <= dEndX) Or
4109
                                        (d기준x <= dStartX And d기준x >= dEndX) Then
4110
                                    If (dModelStartY <= dStartY And dModelEndY >= dEndY) Or
4111
                                        (dModelStartY >= dStartY And dModelEndY <= dEndY) Then
4112
                                        '기준선이 dStartX와 dEndX중 어느쪽에 가까운지 확인
4113
                                        '가로선의 왼쪽점과 기준선이 가까울때는 gap만큼 뺐을때 기준선보다 작은지확인
4114
                                        '가로선의 오른쪽점과 기준선이 가까울때는 gap만큼 더했을때 기준선보다 큰지확인
4115
                                        If Math.Abs(d기준x - dStartX) >= Math.Abs(d기준x - dEndX) Then
4116
                                            'EndX점이 기준선과 더 가까이 있음
4117
                                            If dStartX >= dEndX Then
4118
                                                '가로선의 왼쪽점과 기준선이 가까우므로 gap만큼 뺐을때 기준선보다 작은지확인
4119
                                                If dEndX - dGap <= d기준x Then
4120
                                                    dEndX = d기준x
4121
                                                    sBranchType = "4"
4122
                                                    Return True
4123
                                                End If
4124
                                            Else
4125
                                                '가로선의 오른쪽점과 기준선이 가까우므로 gap만큼 더했을때 기준선보다 큰지확인
4126
                                                If dEndX + dGap >= d기준x Then
4127
                                                    dEndX = d기준x
4128
                                                    sBranchType = "4"
4129
                                                    Return True
4130
                                                End If
4131
4132
                                            End If
4133
                                        Else
4134
                                            'dStartX점이 기준선과 더 가까이 있음
4135
                                            If dStartX >= dEndX Then
4136
                                                '가로선의 오른쪽점과 기준선이 가까우므로 gap만큼 더했을때 기준선보다 큰지확인
4137
                                                If dStartX + dGap >= d기준x Then
4138
                                                    dStartX = d기준x
4139
                                                    sBranchType = "3"
4140
                                                    Return True
4141
                                                End If
4142
4143
                                            Else
4144
                                                '가로선의 왼쪽점과 기준선이 가까우므로 gap만큼 뺐을때 기준선보다 작은지확인
4145
                                                If dStartX - dGap <= d기준x Then
4146
                                                    dStartX = d기준x
4147
                                                    sBranchType = "3"
4148
                                                    Return True
4149
                                                End If
4150
                                            End If
4151
                                        End If
4152
                                    End If
4153
4154
                                End If
4155
                            End If
4156
                        End If
4157
4158
                    End If
4159 79326880 Gyusu
                Else
4160 bb2a0c79 Gyusu
                    'Horizontal
4161
                    If Math.Abs(dModelStartX - dModelEndX) >= Math.Abs(dModelStartY - dModelEndY) Then
4162
                        'Vertical
4163
                        If Math.Abs(dStartX - dEndX) <= Math.Abs(dStartY - dEndY) Then
4164
                            '  dGap = 0.0015 'Math.Abs(dStartY - dEndY) / 80
4165
4166
                            '기준선의 X범위안에 세로선이 포함되어야됨
4167
                            If ((dModelStartX + dGap >= dStartX And dModelEndX - dGap <= dStartX) Or
4168
                            (dModelStartX - dGap <= dStartX And dModelEndX + dGap >= dStartX)) And
4169
                            ((dModelStartX + dGap >= dEndX And dModelEndX - dGap <= dEndX) Or
4170
                            (dModelStartX - dGap <= dEndX And dModelEndX + dGap >= dEndX)) Then
4171
4172
                                '가로선보다 아래에 세로선이 있을때
4173
                                If d기준y >= dStartY And d기준y >= dEndY Then
4174
                                    If dStartY >= dEndY Then
4175
                                        'dStartY 좌표를 기준으로 Gap만큼 더했을때 기준선보다 큰지 확인
4176
                                        If dStartY + dGap >= d기준y Then
4177
                                            dStartY = d기준y
4178
                                            sBranchType = "3"
4179
                                            Return True
4180
                                        End If
4181
                                    Else
4182
                                        'dEndY 좌표를 기준으로 Gap만큼 더했을때 기준선보다 큰지 확인
4183
                                        If dEndY + dGap >= d기준y Then
4184
                                            dEndY = d기준y
4185
4186
                                            If Math.Abs(dEndX - dModelStartX) > Math.Abs(dEndX - dModelEndX) Then
4187
                                                dEndX = dModelEndX
4188
                                            Else
4189
                                                dEndX = dModelStartX
4190
                                            End If
4191
4192
                                            sBranchType = "4"
4193
                                            Return True
4194
                                        End If
4195
                                    End If
4196
                                    '기준선보다 위에 세로선이 있을때
4197
                                ElseIf d기준y <= dStartY And d기준y <= dEndY Then
4198
                                    If dStartY >= dEndY Then
4199
                                        'dEndY 좌표를 기준으로 Gap만큼 뺐을때 기준선보다 작은지 확인
4200
                                        If dEndY - dGap <= d기준y Then
4201
                                            dEndY = d기준y
4202
                                            sBranchType = "4"
4203
                                            Return True
4204
                                        End If
4205
                                    Else
4206
                                        'dStartY 좌표를 기준으로 Gap만큼 뺐을때 기준선보다 작은지 확인
4207
                                        If dStartY - dGap <= d기준y Then
4208
                                            dStartY = d기준y
4209
                                            sBranchType = "3"
4210
                                            Return True
4211
                                        End If
4212
                                    End If
4213
                                Else
4214
                                    '기준선과 세로선이 겹칠때
4215
                                    If (d기준y >= dStartY And d기준y <= dEndY) Or
4216
                                            (d기준y <= dStartY And d기준y >= dEndY) Then
4217
                                        '기준선이 dStartY와 dEndY중 어느쪽에 가까운지 확인
4218
                                        '세로선의 윗점과 기준선이 가까울때는 gap만큼 뺐을때 기준선보다 작은지확인
4219
                                        '세로선의 아래점과 기준선이 가까울때는 gap만큼 더했을때 기준선보다 큰지확인
4220
                                        If (dModelStartX <= dStartX And dModelEndX >= dEndX) Or
4221
                                            (dModelStartX >= dStartX And dModelEndX <= dEndX) Then
4222
                                            If Math.Abs(d기준y - dStartY) >= Math.Abs(d기준y - dEndY) Then
4223
                                                'Endy점이 기준선과 더 가까이 있음
4224
                                                If dStartY >= dEndY Then
4225
                                                    '세로선의 아래점과 기준선이 가까우므로 gap만큼 더했을때 기준선보다 큰지확인
4226
                                                    If dEndY + dGap >= d기준y Then
4227
                                                        dEndY = d기준y
4228
                                                        sBranchType = "4"
4229
                                                        Return True
4230
                                                    End If
4231
                                                Else
4232
                                                    '세로선의 윗점과 기준선이 가까우므로 gap만큼 뺐을때 기준선보다 작은지확인
4233
                                                    If dEndY - dGap <= d기준y Then
4234
                                                        dEndY = d기준y
4235
                                                        sBranchType = "4"
4236
                                                        Return True
4237
                                                    End If
4238
                                                End If
4239
                                            Else
4240
                                                'dStartY점이 기준선과 더 가까이 있음
4241
                                                If dStartY >= dEndY Then
4242
                                                    '세로선의 윗점과 기준선이 가까우므로 gap만큼 뺐을때 기준선보다 작은지확인
4243
                                                    If dStartY - dGap <= d기준y Then
4244
                                                        dStartY = d기준y
4245
                                                        sBranchType = "3"
4246
                                                        Return True
4247
                                                    End If
4248
                                                Else
4249
                                                    '세로선의 아래점과 기준선이 가까우므로 gap만큼 더했을때 기준선보다 큰지확인
4250
                                                    If dStartY + dGap >= d기준y Then
4251
                                                        dStartY = d기준y
4252
                                                        sBranchType = "3"
4253
                                                        Return True
4254
                                                    End If
4255
                                                End If
4256
                                            End If
4257
                                        End If
4258
4259
                                    End If
4260
                                End If
4261
                            End If
4262
                        End If
4263
                    End If
4264
                End If
4265
            Next
4266
        Catch ex As Exception
4267
4268
        End Try
4269
        oLMConnector = Nothing
4270
        Return False
4271
    End Function
4272
4273 76f465d0 Gyusu
    Private Function CheckConnectionSymbolToSymbol(ByVal oModelingLineRows() As DataRow, ByRef dX As Double, ByRef dY As Double,
4274
                                  ByRef oLMConnector As LMConnector) As Boolean
4275
        Dim bConnectionFlag As Boolean = False
4276
        Try
4277
            For Each oModelrow In oModelingLineRows
4278
                Dim d기준x As Double = dX
4279
                Dim d기준y As Double = dY
4280
                Dim dGap As Double = 0.0002
4281
                Dim oRun As LMPipeRun = Nothing
4282
                Try
4283
                    Dim oLMSymbol As LMSymbol = oModelrow(_XML_SYMBOL_LMSYMBOL)
4284
                    Dim dX1 As Double = 0.0
4285
                    Dim dY1 As Double = 0.0
4286
                    Dim dX2 As Double = 0.0
4287
                    Dim dY2 As Double = 0.0
4288
                    For Each oConnector In oLMSymbol.Connect1Connectors
4289
                        oLMConnector = oConnector
4290
                    Next
4291
                    '  oRun = _Placement.PIDDataSource.GetPipeRun(oLMSymbol.Connect1Connectors.Nth(1).ModelItemID)
4292
                    _Placement.PIDConnectPointLocation(oLMSymbol, 1, dX1, dY1)
4293
                    _Placement.PIDConnectPointLocation(oLMSymbol, 2, dX2, dY2)
4294
                    If Math.Abs(dX - dX1) < dGap And Math.Abs(dY - dY1) < dGap Then
4295
                        dX = dX1
4296
                        dY = dY1
4297
                        bConnectionFlag = True
4298
                        Exit For
4299
                    End If
4300
                    If Math.Abs(dX - dX2) < dGap And Math.Abs(dY - dY2) < dGap Then
4301
                        dX = dX2
4302
                        dY = dY2
4303
                        bConnectionFlag = True
4304
                        Exit For
4305
                    End If
4306
4307
                    'For Each oConnector In oLMSymbol.Connect1Connectors
4308
                    '    For Each objConnectorVertex In oConnector.ConnectorVertices
4309
                    '        Dim dConn_X As Double = objConnectorVertex.Attributes("XCoordinate").Value
4310
                    '        Dim dConn_Y As Double = objConnectorVertex.Attributes("YCoordinate").Value
4311
                    '        If Math.Abs(dX - dConn_X) < dGap And Math.Abs(dY - dConn_Y) < dGap Then
4312
                    '            oLMConnector = oConnector
4313
                    '            dX = dConn_X
4314
                    '            dY = dConn_Y
4315
                    '            bConnectionFlag = True
4316
                    '            Exit For
4317
                    '        End If
4318
                    '    Next
4319
                    'Next
4320
4321
                    'For Each oConnector In oLMSymbol.Connect2Connectors
4322
                    '    For Each objConnectorVertex In oConnector.ConnectorVertices
4323
                    '        Dim dConn_X As Double = objConnectorVertex.Attributes("XCoordinate").Value
4324
                    '        Dim dConn_Y As Double = objConnectorVertex.Attributes("YCoordinate").Value
4325
                    '        If Math.Abs(dX - dConn_X) < dGap And Math.Abs(dY - dConn_Y) < dGap Then
4326
                    '            oLMConnector = oConnector
4327
                    '            dX = dConn_X
4328
                    '            dY = dConn_Y
4329
                    '            bConnectionFlag = True
4330
                    '            Exit For
4331
                    '        End If
4332
                    '    Next
4333
                    'Next
4334
4335
4336
                    'If oRun IsNot Nothing Then
4337
                    '    Dim dResultCalc As Double = -1
4338
                    '    For Each objRep In oRun.Representations
4339
                    '        Dim sRepresentationType As String = objRep.Attributes("RepresentationType").Value
4340
                    '        If objRep.Attributes("RepresentationType").Value = "Connector" Or
4341
                    '            objRep.Attributes("RepresentationType").Value = "Symbol" And
4342
                    '             objRep.Attributes("ItemStatus").Value = "Active" Then
4343
                    '            Dim objConnector As LMConnector = _Placement.PIDDataSource.GetConnector(objRep.ID)
4344
                    '            For Each objConnectorVertex In objConnector.ConnectorVertices
4345
                    '                Dim dConn_X As Double = objConnectorVertex.Attributes("XCoordinate").Value
4346
                    '                Dim dConn_Y As Double = objConnectorVertex.Attributes("YCoordinate").Value
4347
                    '                If Math.Abs(dX - dConn_X) < dGap And Math.Abs(dY - dConn_Y) < dGap Then
4348
                    '                    oLMConnector = objConnector
4349
                    '                    d기준x = dConn_X
4350
                    '                    d기준y = dConn_Y
4351
                    '                    bConnectionFlag = True
4352
                    '                    Exit For
4353
                    '                End If
4354
                    '            Next
4355
                    '        End If
4356
                    '    Next
4357
                    'End If
4358
4359
                Catch ex As Exception
4360
                End Try
4361
            Next
4362
4363
        Catch ex As Exception
4364
4365
        End Try
4366
        Return bConnectionFlag
4367
    End Function
4368
4369
    Private Function CheckConnectionSymbolToLine(ByVal oModelingLineRows() As DataRow, ByRef dX As Double, ByRef dY As Double,
4370
ByVal dCenterX As Double, ByVal dCenterY As Double, ByRef oLMConnector As LMConnector) As LMSymbol
4371
        Dim bConnectionFlag As Boolean = False
4372
        Dim oLMSymbol As LMSymbol = Nothing
4373
        Try
4374
4375 e38f99a7 Gyusu
            For Each oModelrow In _ModelingSymbol_Dt.Rows
4376
                Dim dMinx As Double = oModelrow(_XML_SYMBOL_MIN_X)
4377
                Dim dMaxx As Double = oModelrow(_XML_SYMBOL_MAX_X)
4378
                Dim dMiny As Double = oModelrow(_XML_SYMBOL_MIN_Y)
4379
                Dim dMaxy As Double = oModelrow(_XML_SYMBOL_MAX_Y)
4380 76f465d0 Gyusu
                Dim dGap As Double = 0.001
4381 e38f99a7 Gyusu
                If dMinx <= dX And dMaxx >= dX And dMiny <= dY And dMaxy >= dY Then
4382
                    oLMSymbol = oModelrow(_XML_SYMBOL_LMSYMBOL)
4383 76f465d0 Gyusu
                    Dim dX1 As Double = 0.0
4384
                    Dim dY1 As Double = 0.0
4385
                    Dim dX2 As Double = 0.0
4386
                    Dim dY2 As Double = 0.0
4387 e38f99a7 Gyusu
                    Dim dX3 As Double = 0.0
4388
                    Dim dY3 As Double = 0.0
4389
                    Dim dX4 As Double = 0.0
4390
                    Dim dY4 As Double = 0.0
4391
                    Dim dX5 As Double = 0.0
4392
                    Dim dY5 As Double = 0.0
4393
                    Dim dX6 As Double = 0.0
4394
                    Dim dY6 As Double = 0.0
4395
                    Dim dX7 As Double = 0.0
4396
                    Dim dY7 As Double = 0.0
4397
                    Dim dX8 As Double = 0.0
4398
                    Dim dY8 As Double = 0.0
4399 76f465d0 Gyusu
                    _Placement.PIDConnectPointLocation(oLMSymbol, 1, dX1, dY1)
4400
                    _Placement.PIDConnectPointLocation(oLMSymbol, 2, dX2, dY2)
4401 e38f99a7 Gyusu
                    _Placement.PIDConnectPointLocation(oLMSymbol, 3, dX3, dY3)
4402
                    _Placement.PIDConnectPointLocation(oLMSymbol, 4, dX4, dY4)
4403
                    _Placement.PIDConnectPointLocation(oLMSymbol, 5, dX5, dY5)
4404
                    _Placement.PIDConnectPointLocation(oLMSymbol, 6, dX6, dY6)
4405
                    _Placement.PIDConnectPointLocation(oLMSymbol, 7, dX7, dY7)
4406
                    _Placement.PIDConnectPointLocation(oLMSymbol, 8, dX8, dY8)
4407
4408
                    If Math.Abs(dX - dX1) <= dGap And Math.Abs(dY - dY1) <= dGap Then
4409 76f465d0 Gyusu
                        dX = dX1
4410
                        dY = dY1
4411 e38f99a7 Gyusu
                    ElseIf Math.Abs(dX - dX2) <= dGap And Math.Abs(dY - dY2) <= dGap Then
4412 76f465d0 Gyusu
                        dX = dX2
4413
                        dY = dY2
4414 e38f99a7 Gyusu
                    ElseIf Math.Abs(dX - dX3) <= dGap And Math.Abs(dY - dY3) <= dGap Then
4415
                        dX = dX3
4416
                        dY = dY3
4417
                    ElseIf Math.Abs(dX - dX4) <= dGap And Math.Abs(dY - dY4) <= dGap Then
4418
                        dX = dX4
4419
                        dY = dY4
4420
                    ElseIf Math.Abs(dX - dX5) <= dGap And Math.Abs(dY - dY5) <= dGap Then
4421
                        dX = dX5
4422
                        dY = dY5
4423
                    ElseIf Math.Abs(dX - dX6) <= dGap And Math.Abs(dY - dY6) <= dGap Then
4424
                        dX = dX6
4425
                        dY = dY6
4426
                    ElseIf Math.Abs(dX - dX7) <= dGap And Math.Abs(dY - dY7) <= dGap Then
4427
                        dX = dX7
4428
                        dY = dY7
4429
                    ElseIf Math.Abs(dX - dX8) <= dGap And Math.Abs(dY - dY8) <= dGap Then
4430
                        dX = dX8
4431
                        dY = dY8
4432 76f465d0 Gyusu
                    End If
4433
                End If
4434
            Next
4435 b08338e3 Gyusu
4436 e38f99a7 Gyusu
4437
4438
            'For Each oModelrow In oModelingLineRows
4439
            '    Dim d기준x As Double = dCenterX
4440
            '    Dim d기준y As Double = dCenterY
4441
            '    Dim dGap As Double = 0.001
4442
            '    Dim oRun As LMPipeRun = Nothing
4443
            '    Dim dCheckGap As Double = 0
4444
            '    Try
4445
4446
            '        Dim dX1 As Double = 0.0
4447
            '        Dim dY1 As Double = 0.0
4448
            '        Dim dX2 As Double = 0.0
4449
            '        Dim dY2 As Double = 0.0
4450
            '        '  oRun = _Placement.PIDDataSource.GetPipeRun(oLMSymbol.Connect1Connectors.Nth(1).ModelItemID)
4451
            '        oLMSymbol = oModelrow(_XML_SYMBOL_LMSYMBOL)
4452
            '        For Each oConnector In oLMSymbol.Connect1Connectors
4453
            '            oLMConnector = oConnector
4454
            '        Next
4455
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 1, dX1, dY1)
4456
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 2, dX2, dY2)
4457
            '        '  If Math.Abs(dX - dX1) < dGap And Math.Abs(dY - dY1) < dGap And
4458
            '        If Math.Abs(d기준x - dX1) < dCheckGap And Math.Abs(d기준y - dY1) < dCheckGap Or dCheckGap = 0 Then
4459
            '            dX = dX1
4460
            '            dY = dY1
4461
            '            bConnectionFlag = True
4462
            '            dCheckGap = Math.Abs(d기준x - dX1) + Math.Abs(d기준y - dY1)
4463
            '        End If
4464
            '        'If Math.Abs(dX - dX2) < dGap And Math.Abs(dY - dY2) < dGap And
4465
            '        '  Math.Abs(d기준x - dX2) < dCheckGap And Math.Abs(d기준y - dY2 < dCheckGap) Or dCheckGap = 0 Then
4466
            '        If Math.Abs(d기준x - dX2) < dCheckGap And Math.Abs(d기준y - dY2) < dCheckGap Or dCheckGap = 0 Then
4467
            '            dX = dX2
4468
            '            dY = dY2
4469
            '            bConnectionFlag = True
4470
            '        End If
4471
4472
            '    Catch ex As Exception
4473
            '    End Try
4474
            '    If bConnectionFlag Then
4475
            '        oLMSymbol = oModelrow(_XML_SYMBOL_LMSYMBOL)
4476
            '    Else
4477
            '        oLMSymbol = Nothing
4478
            '    End If
4479
            'Next
4480
4481 76f465d0 Gyusu
        Catch ex As Exception
4482 b08338e3 Gyusu
4483 76f465d0 Gyusu
        End Try
4484 b08338e3 Gyusu
4485 76f465d0 Gyusu
        Return oLMSymbol
4486
    End Function
4487 b08338e3 Gyusu
4488 3b7a4470 Gyusu
    ''' <summary>
4489
    ''' 라인과 라인이 만나는점이 브런치점인지 확인, 오차범위내 라인보정
4490
    ''' </summary>
4491
    ''' <param name="oModelingLineRows"></param>
4492
    ''' <param name="dStartX"></param>
4493
    ''' <param name="dStartY"></param>
4494
    ''' <param name="dEndX"></param>
4495
    ''' <param name="dEndY"></param>
4496
    ''' <param name="oLMConnector"></param>
4497
    ''' <returns></returns>
4498
    Private Function CheckBranchLine(ByVal oModelingLineRows As DataRowCollection, ByRef dStartX As Double, ByRef dStartY As Double,
4499
                                     ByRef dEndX As Double, ByRef dEndY As Double, ByRef oLMConnector As LMConnector) As String
4500
        Dim bConnectionFlag As Boolean = False
4501
        Dim sBranchDirection As String = ""
4502
        Try
4503
            For Each oModelrow In oModelingLineRows
4504
                Dim dModelStartX As Double
4505
                Dim dModelStartY As Double
4506
                Dim dModelEndX As Double
4507
                Dim dModelEndY As Double
4508 73bfb231 Gyusu
                Dim dGap As Double = 0.002
4509 3b7a4470 Gyusu
                dModelStartX = oModelrow(_XML_LINE_DWG_STARTPOINT_X)
4510
                dModelStartY = oModelrow(_XML_LINE_DWG_STARTPOINT_Y)
4511
                dModelEndX = oModelrow(_XML_LINE_DWG_ENDPOINT_X)
4512
                dModelEndY = oModelrow(_XML_LINE_DWG_ENDPOINT_Y)
4513
4514
                '기존라인이 X축방향이라면 현재선은 Y축방향이 되어야됨
4515
                If Math.Abs(dModelStartX - dModelEndX) > Math.Abs(dModelStartY - dModelEndY) And
4516
                    Math.Abs(dStartX - dEndX) < Math.Abs(dStartY - dEndY) Then
4517
4518
                    '기본라인의 X축영역안에 현재선이 있어야됨
4519
                    '      If dModelEndY > dModelStartY Then
4520
                    If (dStartX < dModelEndX And dStartX > dModelStartX) Or
4521
                            (dStartX > dModelEndX And dStartX < dModelStartX) Then
4522
                        '[오차범위 수정]
4523
                        '현재선의 Y축방향이 기존라인의 X축방향을 통과하는지 확인
4524
                        If dStartY < dEndY Then
4525
                            If dEndY > dModelStartY And dModelStartY > dStartY Then
4526
                                If dEndY - dModelStartY > dModelStartY - dStartY Then
4527
                                    '위쪽으로 라인이 나와있을때
4528
                                    '현재선 중 작은 Y좌표를 오차범위만큼 더했을때 기존라인의 Y축보다 큰지확인 
4529
                                    'Y축보다 클경우 작은 Y좌표를 기존라인의 Y축에 맞추고 더한 길이만큼 큰 Y좌표에 더한다.
4530 73bfb231 Gyusu
                                    If Math.Abs(dStartY - dModelStartY) <= dGap Then
4531 3b7a4470 Gyusu
                                        Dim dAddPoint As Double = dModelStartY - dStartY
4532
                                        dEndY = dEndY + dAddPoint
4533
                                        dStartY = dModelStartY
4534
                                        sBranchDirection = "START"
4535 73bfb231 Gyusu
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4536
                                        Exit For
4537 3b7a4470 Gyusu
                                    End If
4538
                                Else
4539
                                    '아래쪽으로 라인이 나와있을때
4540
                                    '현재선 중 큰 Y좌표를 오차범위만큼 뺐을때 기존라인의 Y축보다 작은지확인 
4541
                                    'Y축보다 작을경우 큰 Y좌표를 기존라인의 Y축에 맞추고 더한 길이만큼 작은 Y좌표에 뺀다.
4542 73bfb231 Gyusu
                                    If Math.Abs(dEndY - dModelStartY) <= dGap Then
4543 3b7a4470 Gyusu
                                        Dim dAddPoint As Double = dEndY - dModelStartY
4544
                                        dStartY = dStartY - dAddPoint
4545
                                        dEndY = dModelStartY
4546
                                        sBranchDirection = "END"
4547 73bfb231 Gyusu
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4548
                                        Exit For
4549 3b7a4470 Gyusu
                                    End If
4550
                                End If
4551
                            Else
4552
                                '현재선의 Y축방향이 기존라인의 X축방향에 못미치는지 확인
4553
                                If dStartY > dModelStartY Then
4554
                                    '기존라인보다 위쪽에 현재선이 있을때
4555 73bfb231 Gyusu
                                    If Math.Abs(dStartY - dModelStartY) <= dGap Then
4556 3b7a4470 Gyusu
                                        '오차범위만큼 작은 y좌표를 뺐을때 기존라인보다 아래쪽에 있을경우 오차보정
4557
                                        Dim dAddPoint As Double = dStartY - dModelStartY
4558
                                        dEndY = dEndY - dAddPoint
4559
                                        dStartY = dModelStartY
4560
                                        sBranchDirection = "START"
4561 73bfb231 Gyusu
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4562
                                        Exit For
4563 3b7a4470 Gyusu
                                    End If
4564
                                Else
4565
                                    '기존라인보다 아래쪽에 현재선이 있을때
4566 73bfb231 Gyusu
                                    If Math.Abs(dEndY - dModelStartY) <= dGap Then
4567 3b7a4470 Gyusu
                                        '오차범위만큼 큰 y좌표를 더했을때 기존라인보다 위쪽에 있을경우 오차보정
4568
                                        Dim dAddPoint As Double = dModelStartY - dEndY
4569
                                        dEndY = dModelStartY
4570
                                        dStartY = dStartY + dAddPoint
4571
                                        sBranchDirection = "END"
4572 73bfb231 Gyusu
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4573
                                        Exit For
4574 3b7a4470 Gyusu
                                    End If
4575
                                End If
4576
                            End If
4577
                        Else
4578
                            If dEndY < dModelStartY And dModelStartY < dStartY Then
4579
                                If dModelStartY - dEndY < dStartY - dModelStartY Then
4580
                                    '위쪽으로 라인이 나와있을때
4581
                                    '현재선 중 작은 Y좌표를 오차범위만큼 더했을때 기존라인의 Y축보다 큰지확인 
4582
                                    'Y축보다 클경우 작은 Y좌표를 기존라인의 Y축에 맞추고 더한 길이만큼 큰 Y좌표에 더한다.
4583 73bfb231 Gyusu
                                    If Math.Abs(dEndY - dModelStartY) <= dGap Then
4584 3b7a4470 Gyusu
                                        Dim dAddPoint As Double = dModelStartY - dEndY
4585
                                        dStartY = dStartY + dAddPoint
4586
                                        dEndY = dModelStartY
4587
                                        sBranchDirection = "END"
4588 73bfb231 Gyusu
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4589
                                        Exit For
4590 3b7a4470 Gyusu
                                    End If
4591
                                Else
4592
                                    '아래쪽으로 라인이 나와있을때
4593
                                    '현재선 중 큰 Y좌표를 오차범위만큼 뺐을때 기존라인의 Y축보다 작은지확인 
4594
                                    'Y축보다 작을경우 큰 Y좌표를 기존라인의 Y축에 맞추고 더한 길이만큼 작은 Y좌표에 뺀다.
4595 73bfb231 Gyusu
                                    If Math.Abs(dStartY - dModelStartY) <= dGap Then
4596 3b7a4470 Gyusu
                                        Dim dAddPoint As Double = dStartY - dModelStartY
4597
                                        dEndY = dEndY - dAddPoint
4598
                                        dStartY = dModelStartY
4599
                                        sBranchDirection = "START"
4600 73bfb231 Gyusu
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4601
                                        Exit For
4602 3b7a4470 Gyusu
                                    End If
4603
                                End If
4604
                            Else
4605
                                If dEndY > dModelStartY Then
4606
                                    '기존라인보다 우측에 현재선이 있을때
4607 73bfb231 Gyusu
                                    If Math.Abs(dEndY - dModelStartY) <= dGap Then
4608 3b7a4470 Gyusu
                                        '오차범위만큼 작은 x좌표를 뺐을때 기존라인보다 좌측에 있을경우 오차보정
4609
                                        Dim dAddPoint As Double = dEndY - dModelStartY
4610
                                        dStartY = dStartY - dAddPoint
4611
                                        dEndY = dModelStartY
4612
                                        sBranchDirection = "END"
4613 73bfb231 Gyusu
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4614
                                        Exit For
4615 3b7a4470 Gyusu
                                    End If
4616
                                Else
4617
                                    '기존라인보다 좌측에 현재선이 있을때
4618 73bfb231 Gyusu
                                    If Math.Abs(dStartY - dModelStartY) <= dGap Then
4619 3b7a4470 Gyusu
                                        '오차범위만큼 큰 x좌표를 더했을때 기존라인보다 우측에 있을경우 오차보정
4620
                                        Dim dAddPoint As Double = dModelStartY - dStartY
4621
                                        dStartY = dModelStartY
4622
                                        dEndY = dEndY + dAddPoint
4623
                                        sBranchDirection = "START"
4624 73bfb231 Gyusu
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4625
                                        Exit For
4626 3b7a4470 Gyusu
                                    End If
4627
                                End If
4628
                            End If
4629
                        End If
4630
                    End If
4631
                    '기존라인이 Y축방향이라면 현재선은 X축방향이 되어야됨
4632
                ElseIf Math.Abs(dModelStartX - dModelEndX) < Math.Abs(dModelStartY - dModelEndY) And
4633
                Math.Abs(dStartX - dEndX) > Math.Abs(dStartY - dEndY) Then
4634
4635
                    '기본라인의 Y축영역안에 현재선이 있어야됨
4636
                    '      If dModelEndY > dModelStartY Then
4637
                    If (dStartY < dModelEndY And dStartY > dModelStartY) Or
4638
                            (dStartY > dModelEndY And dStartY < dModelStartY) Then
4639
                        '[오차범위 수정]
4640
                        '현재선의 X축방향이 기존라인의 Y축방향을 통과하는지 확인
4641
                        If dStartX < dEndX Then
4642
                            If dEndX > dModelStartX And dModelStartX > dStartX Then
4643
                                If dEndX - dModelStartX > dModelStartX - dStartX Then
4644
                                    '우측으로 라인이 나와있을때
4645
                                    '현재선 중 작은 X좌표를 오차범위만큼 더했을때 기존라인의 X축보다 큰지확인 
4646
                                    'X축보다 클경우 작은 X좌표를 기존라인의 X축에 맞추고 더한 길이만큼 큰 X좌표에 더한다.
4647 73bfb231 Gyusu
                                    If Math.Abs(dStartX - dModelStartX) <= dGap Then
4648 3b7a4470 Gyusu
                                        Dim dAddPoint As Double = dModelStartX - dStartX
4649
                                        dEndX = dEndX + dAddPoint
4650
                                        dStartX = dModelStartX
4651
                                        sBranchDirection = "START"
4652 73bfb231 Gyusu
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4653
                                        Exit For
4654 3b7a4470 Gyusu
                                    End If
4655
                                Else
4656
                                    '좌측으로 라인이 나와있을때
4657
                                    '현재선 중 큰 X좌표를 오차범위만큼 뺐을때 기존라인의 X축보다 작은지확인 
4658
                                    'X축보다 작을경우 큰 X좌표를 기존라인의 X축에 맞추고 뺀 길이만큼 작은 X좌표에 뺀다.
4659 73bfb231 Gyusu
                                    If Math.Abs(dEndX - dModelStartX) <= dGap Then
4660 3b7a4470 Gyusu
                                        Dim dAddPoint As Double = dEndX - dModelStartX
4661
                                        dStartX = dStartX - dAddPoint
4662
                                        dEndX = dModelStartX
4663
                                        sBranchDirection = "END"
4664 73bfb231 Gyusu
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4665
                                        Exit For
4666 3b7a4470 Gyusu
                                    End If
4667
                                End If
4668
                            Else
4669
                                '현재선의 X축방향이 기존라인의 Y축방향에 못미치는지 확인
4670
                                If dStartX > dModelStartX Then
4671
                                    '기존라인보다 우측에 현재선이 있을때
4672 73bfb231 Gyusu
                                    If Math.Abs(dStartX - dModelStartX) <= dGap Then
4673 3b7a4470 Gyusu
                                        '오차범위만큼 작은 x좌표를 뺐을때 기존라인보다 좌측에 있을경우 오차보정
4674
                                        Dim dAddPoint As Double = dStartX - dModelStartX
4675
                                        dEndX = dEndX - dAddPoint
4676
                                        dStartX = dModelStartX
4677
                                        sBranchDirection = "START"
4678 73bfb231 Gyusu
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4679
                                        Exit For
4680 3b7a4470 Gyusu
                                    End If
4681
                                Else
4682
                                    '기존라인보다 좌측에 현재선이 있을때
4683 73bfb231 Gyusu
                                    If Math.Abs(dEndX - dModelStartX) <= dGap Then
4684 3b7a4470 Gyusu
                                        '오차범위만큼 큰 x좌표를 더했을때 기존라인보다 우측에 있을경우 오차보정
4685
                                        Dim dAddPoint As Double = dModelStartX - dEndX
4686
                                        dEndX = dModelStartX
4687
                                        dStartX = dStartX + dAddPoint
4688
                                        sBranchDirection = "END"
4689 73bfb231 Gyusu
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4690
                                        Exit For
4691 3b7a4470 Gyusu
                                    End If
4692
                                End If
4693
                            End If
4694
                        Else
4695
                            If dEndX < dModelStartX And dModelStartX < dStartX Then
4696
                                If dModelStartX - dEndX < dStartX - dModelStartX Then
4697
                                    '우측으로 라인이 나와있을때
4698
                                    '현재선 중 작은 X좌표를 오차범위만큼 더했을때 기존라인의 X축보다 큰지확인 
4699
                                    'X축보다 클경우 작은 X좌표를 기존라인의 X축에 맞추고 더한 길이만큼 큰 X좌에 더한다.
4700 73bfb231 Gyusu
                                    If Math.Abs(dModelStartX - dEndX) <= dGap Then
4701 3b7a4470 Gyusu
                                        Dim dAddPoint As Double = dModelStartX - dEndX
4702
                                        dStartX = dStartX + dAddPoint
4703
                                        dEndX = dModelStartX
4704
                                        sBranchDirection = "END"
4705 73bfb231 Gyusu
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4706
                                        Exit For
4707 3b7a4470 Gyusu
                                    End If
4708
                                Else
4709
                                    '좌측으로 라인이 나와있을때
4710
                                    '현재선 중 큰 X좌표를 오차범위만큼 뺐을때 기존라인의 X축보다 작은지확인 
4711
                                    'X축보다 작을경우 큰 X좌표를 기존라인의 X축에 맞추고 뺀 길이만큼 작은 X좌표에 뺀다.
4712 73bfb231 Gyusu
                                    If Math.Abs(dStartX - dModelStartX) <= dGap Then
4713 3b7a4470 Gyusu
                                        Dim dAddPoint As Double = dStartX - dModelStartX
4714
                                        dEndX = dEndX - dAddPoint
4715
                                        dStartX = dModelStartX
4716
                                        sBranchDirection = "START"
4717 73bfb231 Gyusu
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4718
                                        Exit For
4719 3b7a4470 Gyusu
                                    End If
4720
4721
                                End If
4722
                            Else
4723
                                If dEndX > dModelStartX Then
4724
                                    '기존라인보다 우측에 현재선이 있을때
4725 73bfb231 Gyusu
                                    If Math.Abs(dEndX - dModelStartX) <= dGap Then
4726 3b7a4470 Gyusu
                                        '오차범위만큼 작은 x좌표를 뺐을때 기존라인보다 좌측에 있을경우 오차보정
4727
                                        Dim dAddPoint As Double = dEndX - dModelStartX
4728
                                        dStartX = dStartX - dAddPoint
4729
                                        dEndX = dModelStartX
4730
                                        sBranchDirection = "END"
4731 73bfb231 Gyusu
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4732
                                        Exit For
4733 3b7a4470 Gyusu
                                    End If
4734
                                Else
4735
                                    '기존라인보다 좌측에 현재선이 있을때
4736 73bfb231 Gyusu
                                    If Math.Abs(dStartX - dModelStartX) <= dGap Then
4737 3b7a4470 Gyusu
                                        '오차범위만큼 큰 x좌표를 더했을때 기존라인보다 우측에 있을경우 오차보정
4738
                                        Dim dAddPoint As Double = dModelStartX - dStartX
4739
                                        dStartX = dModelStartX
4740
                                        dEndX = dEndX + dAddPoint
4741
                                        sBranchDirection = "START"
4742 73bfb231 Gyusu
                                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4743
                                        Exit For
4744 3b7a4470 Gyusu
                                    End If
4745
                                End If
4746
                            End If
4747
                        End If
4748
                    End If
4749
                End If
4750
            Next
4751
        Catch ex As Exception
4752
            bConnectionFlag = False
4753
            oLMConnector = Nothing
4754
        End Try
4755
        Return sBranchDirection
4756
4757
    End Function
4758
4759 79326880 Gyusu
    Private Function UpdateCheckBranchLine(ByRef dX As Double, ByRef dY As Double,
4760 1bfcc921 Gyusu
                                  ByRef oLMConnector As LMConnector, ByRef sUid As String) As Boolean
4761 dd46ca83 Gyusu
        Dim oDataSource As LMADataSource = _Placement.PIDDataSource
4762 1bfcc921 Gyusu
        Dim bCheckBranchItem As Boolean = False
4763 79326880 Gyusu
        Dim iGapCheck As Integer = 0
4764
        Try
4765
            For Each oModelrow In _ModelingLine_Dt.Rows
4766
                Dim d기준x As Double = dX
4767
                Dim d기준y As Double = dY
4768
                Dim dGap As Double = 0.001
4769
                Dim oRun As LMPipeRun = Nothing
4770
                Dim dModelStartX As Double
4771
                Dim dModelStartY As Double
4772
                Dim dModelEndX As Double
4773
                Dim dModelEndY As Double
4774
                dModelStartX = oModelrow(_XML_LINE_DWG_STARTPOINT_X)
4775
                dModelStartY = oModelrow(_XML_LINE_DWG_STARTPOINT_Y)
4776
                dModelEndX = oModelrow(_XML_LINE_DWG_ENDPOINT_X)
4777
                dModelEndY = oModelrow(_XML_LINE_DWG_ENDPOINT_Y)
4778
                d기준x = (dModelStartX + dModelEndX) / 2
4779
                d기준y = (dModelStartY + dModelEndY) / 2
4780
4781
                Dim dMax_X As Double = 0.0
4782
                Dim dMax_Y As Double = 0.0
4783
                Dim dMin_X As Double = 0.0
4784
                Dim dMin_Y As Double = 0.0
4785
                If dModelEndX > dModelStartX Then
4786
                    dMax_X = dModelEndX
4787
                    dMin_X = dModelStartX
4788
                Else
4789
                    dMax_X = dModelStartX
4790
                    dMin_X = dModelEndX
4791
                End If
4792
4793
                If dModelEndY > dModelStartY Then
4794
                    dMax_Y = dModelEndY
4795
                    dMin_Y = dModelStartY
4796
                Else
4797
                    dMax_Y = dModelStartY
4798
                    dMin_Y = dModelEndY
4799
                End If
4800
4801
                If dX <= dMax_X + dGap And dX >= dMin_X - dGap And
4802
                  dY <= dMax_Y + dGap And dY >= dMin_Y - dGap Then
4803
                    If Math.Abs(dMax_X - dMin_X) > Math.Abs(dMax_Y - dMin_Y) Then
4804
                        dY = dMax_Y
4805
                    Else
4806
                        dX = dMax_X
4807
                    End If
4808 1bfcc921 Gyusu
4809
                    Try
4810
                        Dim sModelItemID As String = oModelrow(_XML_LINE_SPID).ToString()
4811
                        sUid = oModelrow(_XML_LINE_UID).ToString()
4812 dd46ca83 Gyusu
                        oRun = oDataSource.GetPipeRun(sModelItemID)
4813 1bfcc921 Gyusu
                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4814
                    Catch ex As Exception
4815
                    End Try
4816
                    Try
4817
                        If oRun IsNot Nothing Then
4818
                            Dim dResultCalc As Double = -1
4819 dd46ca83 Gyusu
                            Dim bBranchFlag As Boolean = False
4820
                            Dim dBranchX As Double = 0
4821
                            Dim dBranchY As Double = 0
4822 1bfcc921 Gyusu
                            For Each objRep In oRun.Representations
4823 dd46ca83 Gyusu
                                '  Dim sAttriName As String
4824
                                'For Each objAttr In objRep.Attributes
4825
                                '    sAttriName = objAttr.name
4826
                                'Next
4827
                                'MsgBox(objRep.RepresentationType)
4828 1bfcc921 Gyusu
                                If objRep.RepresentationType = "Connector" Then
4829 dd46ca83 Gyusu
                                    Dim objConnector As LMConnector = oDataSource.GetConnector(objRep.ID)
4830
                                    '     Dim sItemStatus As String = objConnector.Attributes("ItemStatus").Value
4831
                                    '   Dim sModelTypeName As String = objConnector.ModelItemObject.Attributes("ItemTypeName").Value
4832 1bfcc921 Gyusu
4833
                                    'Dim dConn_SX As Double = 0
4834
                                    'Dim dConn_SY As Double = 0
4835
                                    'Dim dConn_EX As Double = 0
4836
                                    'Dim dConn_EY As Double = 0
4837
                                    Dim dConn_X As Double = 0
4838
                                    Dim dConn_Y As Double = 0
4839
                                    For Each objConnectorVertex In objConnector.ConnectorVertices
4840
                                        dConn_X = objConnectorVertex.Attributes("XCoordinate").Value
4841
                                        dConn_Y = objConnectorVertex.Attributes("YCoordinate").Value
4842
                                        'If dConn_SX = 0 Then
4843
                                        '    dConn_SX = objConnectorVertex.Attributes("XCoordinate").Value
4844
                                        '    dConn_SY = objConnectorVertex.Attributes("YCoordinate").Value
4845
                                        'Else
4846
                                        '    dConn_EX = objConnectorVertex.Attributes("XCoordinate").Value
4847
                                        '    dConn_EY = objConnectorVertex.Attributes("YCoordinate").Value
4848
                                        'End If
4849
                                        Dim dCalc As Double = Math.Abs(dConn_X - dX) + Math.Abs(dConn_Y - dY)
4850 dd46ca83 Gyusu
                                        If bBranchFlag = False Then
4851
                                            If dResultCalc = -1 Or dResultCalc > dCalc Then
4852
                                                dResultCalc = dCalc
4853
                                                oLMConnector = objConnector
4854
                                                bCheckBranchItem = True
4855
                                            End If
4856
                                        Else
4857
                                            If (dConn_X >= dX And dBranchX <= dX And dConn_Y >= dY And dBranchY <= dY) Or
4858
                                               (dConn_X <= dX And dBranchX >= dX And dConn_Y <= dY And dBranchY >= dY) Then
4859
                                                If dResultCalc = -1 Or dResultCalc > dCalc Then
4860
                                                    dResultCalc = dCalc
4861
                                                    oLMConnector = objConnector
4862
                                                    bCheckBranchItem = True
4863
                                                End If
4864
                                            End If
4865 1bfcc921 Gyusu
                                        End If
4866
4867 dd46ca83 Gyusu
4868 1bfcc921 Gyusu
                                        'If dConn_EX <> 0 And dConn_EY <> 0 Then
4869
                                        '    If dConn_SX >= dX And dConn_EX <= dX And dConn_SY >= dY And dConn_EY <= dY Then
4870
                                        '        oLMConnector = objConnector
4871
                                        '        Exit For
4872
                                        '    ElseIf dConn_SX <= dX And dConn_EX >= dX And dConn_SY <= dY And dConn_EY >= dY Then
4873
                                        '        oLMConnector = objConnector
4874
                                        '        Exit For
4875
                                        '    Else
4876
                                        '        If dConn_EX > 0 Then
4877
                                        '            dConn_SX = dConn_EX
4878
                                        '            dConn_SY = dConn_EY
4879
                                        '        End If
4880
                                        '    End If
4881
                                        'End If
4882
4883
                                    Next
4884
                                    'If oLMConnector IsNot Nothing Then
4885
                                    '    Exit For
4886
                                    'End If
4887 dd46ca83 Gyusu
                                ElseIf objRep.RepresentationType = "Branch" Then
4888
                                    Dim objConnector As LMSymbol = oDataSource.GetSymbol(objRep.ID)
4889
                                    dBranchX = objConnector.Attributes("XCoordinate").Value
4890
                                    dBranchY = objConnector.Attributes("YCoordinate").Value
4891
                                    bBranchFlag = True
4892 1bfcc921 Gyusu
                                End If
4893
                                'If objRep.Attributes("RepresentationType").Value = "Connector" And objRep.Attributes("ItemStatus").Value = "Active" Then
4894
                                '    Dim objConnector As LMConnector = _Placement.PIDDataSource.GetConnector(objRep.ID)
4895
                                '    For Each objConnectorVertex In objConnector.ConnectorVertices
4896
                                '        Dim dConn_X As Double = objConnectorVertex.Attributes("XCoordinate").Value
4897
                                '        Dim dConn_Y As Double = objConnectorVertex.Attributes("YCoordinate").Value
4898
                                '        If Math.Abs(dX - dConn_X) < dGap And Math.Abs(dY - dConn_Y) < dGap Then
4899
                                '            oLMConnector = objConnector
4900
                                '            dX = dConn_X
4901
                                '            dY = dConn_Y
4902
                                '            bConnectionFlag = True
4903
                                '        End If
4904
                                '    Next
4905
                                'End If
4906
                            Next
4907
                        End If
4908
                    Catch ex As Exception
4909
                    End Try
4910
                    '    oUid = oModelrow(_XML_LINE_UID).ToString()
4911 b82166d4 Gyusu
                    ' Dim oID As String = oModelrow(_XML_LINE_SPID)
4912 1bfcc921 Gyusu
                    '    oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4913 b82166d4 Gyusu
                    '    oID = oLMConnector.ModelItemID
4914
                    '  oLMConnector = _Placement.PIDDataSource.GetConnector(oID)
4915 1bfcc921 Gyusu
                    'If oLMConnector IsNot Nothing Then
4916
                    '    Exit For
4917
                    'End If
4918 79326880 Gyusu
                End If
4919
4920
4921
            Next
4922
        Catch ex As Exception
4923 1bfcc921 Gyusu
            bCheckBranchItem = False
4924 79326880 Gyusu
            oLMConnector = Nothing
4925
        End Try
4926 1bfcc921 Gyusu
        Return bCheckBranchItem
4927 79326880 Gyusu
    End Function
4928
4929 3b7a4470 Gyusu
    ''' <summary>
4930
    ''' 라인과 특정 포인트에 커넥션을 확인하는 메서드
4931
    ''' </summary>
4932
    ''' <param name="oModelingLineRows"></param>
4933
    ''' <param name="dX"></param>
4934
    ''' <param name="dY"></param>
4935
    ''' <param name="oLMConnector"></param>
4936
    ''' <param name="dPreConnX"></param>
4937
    ''' <param name="dPreConnY"></param>
4938
    ''' <returns></returns>
4939
4940 79326880 Gyusu
    Private Function CheckConnectionLine(ByRef dX As Double, ByRef dY As Double,
4941 b82166d4 Gyusu
                                  ByRef oLMConnector As LMConnector, ByRef sUid As String) As Boolean
4942 b08338e3 Gyusu
        Dim bConnectionFlag As Boolean = False
4943 76f465d0 Gyusu
        Dim iGapCheck As Integer = 0
4944 b08338e3 Gyusu
        Try
4945 79326880 Gyusu
            For Each oModelrow In _ModelingLine_Dt.Rows
4946 76f465d0 Gyusu
                Dim d기준x As Double = dX
4947
                Dim d기준y As Double = dY
4948 1bfcc921 Gyusu
                Dim dGap As Double = 0.001
4949 76f465d0 Gyusu
                Dim oRun As LMPipeRun = Nothing
4950 b08338e3 Gyusu
                Dim dModelStartX As Double
4951
                Dim dModelStartY As Double
4952
                Dim dModelEndX As Double
4953
                Dim dModelEndY As Double
4954 76f465d0 Gyusu
                dModelStartX = oModelrow(_XML_LINE_DWG_STARTPOINT_X)
4955
                dModelStartY = oModelrow(_XML_LINE_DWG_STARTPOINT_Y)
4956
                dModelEndX = oModelrow(_XML_LINE_DWG_ENDPOINT_X)
4957
                dModelEndY = oModelrow(_XML_LINE_DWG_ENDPOINT_Y)
4958
                d기준x = (dModelStartX + dModelEndX) / 2
4959
                d기준y = (dModelStartY + dModelEndY) / 2
4960 79326880 Gyusu
4961
                Dim bCheckEqual As Boolean = False
4962
                If dX <= dModelStartX + dGap And dX >= dModelStartX - dGap And
4963
                        dY <= dModelStartY + dGap And dY >= dModelStartY - dGap Then
4964
                    bCheckEqual = True
4965
                ElseIf dX <= dModelEndX + dGap And dX >= dModelEndX - dGap And
4966
                        dY <= dModelEndY + dGap And dY >= dModelEndY - dGap Then
4967
                    bCheckEqual = True
4968
                End If
4969
                If bCheckEqual Then
4970
                    Try
4971
                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
4972 b82166d4 Gyusu
                        sUid = oModelrow(_XML_LINE_UID)
4973 79326880 Gyusu
                        oRun = _Placement.PIDDataSource.GetPipeRun(oLMConnector.ModelItemID)
4974
                    Catch ex As Exception
4975
                    End Try
4976
                    Try
4977
                        If oRun IsNot Nothing Then
4978
                            Dim dResultCalc As Double = -1
4979
                            For Each objRep In oRun.Representations
4980
                                If objRep.Attributes("RepresentationType").Value = "Connector" And objRep.Attributes("ItemStatus").Value = "Active" Then
4981
                                    Dim objConnector As LMConnector = _Placement.PIDDataSource.GetConnector(objRep.ID)
4982
                                    For Each objConnectorVertex In objConnector.ConnectorVertices
4983
                                        Dim dConn_X As Double = objConnectorVertex.Attributes("XCoordinate").Value
4984
                                        Dim dConn_Y As Double = objConnectorVertex.Attributes("YCoordinate").Value
4985
                                        If Math.Abs(dX - dConn_X) < dGap And Math.Abs(dY - dConn_Y) < dGap Then
4986
                                            oLMConnector = objConnector
4987
                                            dX = dConn_X
4988
                                            dY = dConn_Y
4989
                                            bConnectionFlag = True
4990
                                        End If
4991
                                    Next
4992
                                End If
4993
                            Next
4994
                        End If
4995
                    Catch ex As Exception
4996
                    End Try
4997
                Else
4998
                End If
4999 b08338e3 Gyusu
            Next
5000
        Catch ex As Exception
5001 76f465d0 Gyusu
            bConnectionFlag = False
5002
            oLMConnector = Nothing
5003 b08338e3 Gyusu
        End Try
5004
        Return bConnectionFlag
5005
    End Function
5006
5007 1bfcc921 Gyusu
    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
5008
        '현재선의 방향을 보고 상대라인이 직교되는 방향인지 체크
5009
        '오차범위를 줘서 현재선을 통과하는지 체크
5010
        '통과하는 상대라인 갯수를 먼저 구한다음 라인 갯수만큼 라인을 그린다.
5011
        Dim bCheckBranchLine As Boolean = False
5012 dd46ca83 Gyusu
        Dim sCurrentDirection As String = ""
5013
5014
        Dim oModel_Dt As New DataTable()
5015
        oModel_Dt.Columns.Add("X")
5016
        oModel_Dt.Columns.Add("Y")
5017
        oModel_Dt.Columns.Add("Type")
5018
        oModel_Dt.Columns.Add("SPID")
5019
        Dim dGap = 0.001
5020
        If Math.Abs(dStartX - dEndX) > Math.Abs(dStartY - dEndY) Then
5021
            sCurrentDirection = "X"
5022
            If dStartX > dEndX Then
5023
                Dim dTempX As Double = dEndX
5024
                dEndX = dStartX
5025
                dStartX = dTempX
5026
                Dim dTempY As Double = dEndY
5027
                dEndY = dStartY
5028
                dStartY = dTempY
5029
            End If
5030
            '현재선이 X축방향
5031
            Try
5032
                For Each oModelrow In _ModelingLine_Dt.Rows
5033
                    Dim dModelStart_X As Double = oModelrow(_XML_LINE_DWG_STARTPOINT_X)
5034
                    Dim dModelStart_Y As Double = oModelrow(_XML_LINE_DWG_STARTPOINT_Y)
5035
                    Dim dModelEnd_X As Double = oModelrow(_XML_LINE_DWG_ENDPOINT_X)
5036
                    Dim dModelEnd_Y As Double = oModelrow(_XML_LINE_DWG_ENDPOINT_Y)
5037
                    Dim sSPID As String = oModelrow(_XML_LINE_SPID)
5038
                    If dStartX < dModelStart_X And dStartX < dModelEnd_X And
5039
                       dEndX > dModelStart_X And dEndX > dModelEnd_X Then
5040 496a0241 Gyusu
                        Dim dAddX As Double = dStartX
5041 dd46ca83 Gyusu
                        Dim dAddY As Double = dStartY
5042
                        Dim sType As String = ""
5043 496a0241 Gyusu
                        Dim dAddLineX As Double = 0
5044
                        Dim dAddLineY As Double = 0
5045 dd46ca83 Gyusu
                        If dStartY = dModelStart_Y Then
5046 496a0241 Gyusu
                            dAddX = 0
5047
                            '    dAddX = dModelStart_X
5048 dd46ca83 Gyusu
                        ElseIf dStartY = dModelEnd_Y Then
5049 496a0241 Gyusu
                            dAddX = 0
5050
                            '      dAddX = dModelEnd_X
5051 dd46ca83 Gyusu
                        ElseIf dStartY <= dModelStart_Y + dGap And dStartY >= dModelStart_Y - dGap Then
5052
                            dAddX = dModelStart_X
5053 496a0241 Gyusu
                            If dStartY <= dModelStart_Y Then
5054 dd46ca83 Gyusu
                                sType = "AddLine"
5055 496a0241 Gyusu
                                dAddLineX = dModelStart_X
5056
                                dAddLineY = dModelStart_Y
5057 dd46ca83 Gyusu
                            End If
5058
                        ElseIf dStartY <= dModelEnd_Y + dGap And dStartY >= dModelEnd_Y - dGap Then
5059
                            dAddX = dModelEnd_X
5060 496a0241 Gyusu
                            If dStartY <= dModelEnd_Y Then
5061 dd46ca83 Gyusu
                                sType = "AddLine"
5062 496a0241 Gyusu
                                dAddLineX = dModelEnd_X
5063
                                dAddLineY = dModelEnd_Y
5064 dd46ca83 Gyusu
                            End If
5065
                        End If
5066 496a0241 Gyusu
                        If sType = "AddLine" Then
5067
                            Dim objInputs As PlaceRunInputs
5068
                            objInputs = New PlaceRunInputs
5069
                            Dim oLMConnector As LMConnector = Nothing
5070
                            CheckConnectionLine(dAddLineX, dAddLineY, oLMConnector, "")
5071
                            objInputs.AddPoint(dAddLineX, dAddY)
5072
                            objInputs.AddConnectorTarget(oLMConnector, dAddLineX, dAddLineY)
5073
                            Dim AddLMConnector As LMConnector = LineModeling(objInputs, sSystemPath)
5074
                            JoinPipeRun(oLMConnector.ModelItemID, AddLMConnector.ModelItemID)
5075
                            dStartY = dAddY
5076
                        End If
5077
5078 dd46ca83 Gyusu
                        If dAddX <> 0 Then
5079
                            Dim oDatarow As DataRow = oModel_Dt.NewRow()
5080
                            oDatarow("X") = dAddX
5081
                            oDatarow("Y") = dAddY
5082
                            oDatarow("Type") = sType
5083
                            oDatarow("SPID") = sSPID
5084
                            oModel_Dt.Rows.Add(oDatarow)
5085
                        End If
5086
                    End If
5087
                Next
5088
            Catch ex As Exception
5089
            End Try
5090
        Else
5091
            '현재선이 y축방향
5092
            sCurrentDirection = "Y"
5093
            Try
5094
                For Each oModelrow In _ModelingLine_Dt.Rows
5095
                    Dim dModelStart_X As Double = oModelrow(_XML_LINE_DWG_STARTPOINT_X)
5096
                    Dim dModelStart_Y As Double = oModelrow(_XML_LINE_DWG_STARTPOINT_Y)
5097
                    Dim dModelEnd_X As Double = oModelrow(_XML_LINE_DWG_ENDPOINT_X)
5098
                    Dim dModelEnd_Y As Double = oModelrow(_XML_LINE_DWG_ENDPOINT_Y)
5099
                    Dim sSPID As String = oModelrow(_XML_LINE_SPID)
5100
                    If dStartY < dModelStart_Y And dStartY < dModelEnd_Y And
5101
                       dEndY > dModelStart_Y And dEndY > dModelEnd_Y Then
5102
                        Dim dAddX As Double = dStartX
5103 496a0241 Gyusu
                        Dim dAddY As Double = dStartY
5104 dd46ca83 Gyusu
                        Dim sType As String = ""
5105 496a0241 Gyusu
                        Dim dAddLineX As Double = 0
5106
                        Dim dAddLineY As Double = 0
5107 dd46ca83 Gyusu
                        If dStartX = dModelStart_X Then
5108 496a0241 Gyusu
                            dAddY = 0
5109
                            '       dAddY = dModelStart_Y
5110 dd46ca83 Gyusu
                        ElseIf dStartX = dModelEnd_X Then
5111 496a0241 Gyusu
                            dAddY = 0
5112
                            '        dAddY = dModelEnd_Y
5113 dd46ca83 Gyusu
                        ElseIf dStartX <= dModelStart_X + dGap And dStartX >= dModelStart_X - dGap Then
5114 496a0241 Gyusu
                            '         dAddY = dModelStart_Y
5115
                            If dStartX <= dModelStart_X Then
5116
                                dAddLineX = dModelStart_X
5117
                                dAddLineY = dModelStart_Y
5118 dd46ca83 Gyusu
                                sType = "AddLine"
5119
                            End If
5120
                        ElseIf dStartX <= dModelEnd_X + dGap And dStartX >= dModelEnd_X - dGap Then
5121 496a0241 Gyusu
                            '        dAddY = dModelEnd_Y
5122
                            If dStartX <= dModelEnd_X Then
5123
                                dAddLineX = dModelEnd_X
5124
                                dAddLineY = dModelEnd_Y
5125 dd46ca83 Gyusu
                                sType = "AddLine"
5126
                            End If
5127
                        End If
5128 496a0241 Gyusu
                        If sType = "AddLine" Then
5129
                            Dim objInputs As PlaceRunInputs
5130
                            objInputs = New PlaceRunInputs
5131
                            Dim oLMConnector As LMConnector = Nothing
5132
                            CheckConnectionLine(dAddLineX, dAddLineY, oLMConnector, "")
5133
                            objInputs.AddPoint(dAddX, dAddLineY)
5134
                            objInputs.AddConnectorTarget(oLMConnector, dAddLineX, dAddLineY)
5135
                            Dim AddLMConnector As LMConnector = LineModeling(objInputs, sSystemPath)
5136
                            JoinPipeRun(oLMConnector.ModelItemID, AddLMConnector.ModelItemID)
5137
                            dStartX = dAddX
5138
                        End If
5139
5140
                        If dAddY <> 0 Then
5141 dd46ca83 Gyusu
                            Dim oDatarow As DataRow = oModel_Dt.NewRow()
5142
                            oDatarow("X") = dAddX
5143
                            oDatarow("Y") = dAddY
5144
                            oDatarow("Type") = sType
5145
                            oDatarow("SPID") = sSPID
5146
                            oModel_Dt.Rows.Add(oDatarow)
5147
                        End If
5148
                    End If
5149
                Next
5150
            Catch ex As Exception
5151
            End Try
5152
        End If
5153
5154
        '//못미치는 라인은 라인길이를 더한후 나머지 모델링(2018.09.27)
5155
5156
        If oModel_Dt.Rows.Count > 0 Then
5157
            If sCurrentDirection = "X" Then
5158
                'X좌표 정렬
5159
                oModel_Dt.DefaultView.Sort = "X desc"
5160
                oModel_Dt = oModel_Dt.DefaultView.ToTable(True)
5161
            Else
5162
                'Y좌표 정렬
5163
                oModel_Dt.DefaultView.Sort = "Y desc"
5164
                oModel_Dt = oModel_Dt.DefaultView.ToTable(True)
5165
            End If
5166
            Dim oLMConnector As LMConnector = Nothing
5167
            Dim oPreLMConnector As LMConnector = Nothing
5168
            Dim dStartFlag As Boolean = True
5169
            For Each oModelRow In oModel_Dt.Rows
5170
                Dim objInputs As PlaceRunInputs
5171
                objInputs = New PlaceRunInputs
5172
                Dim dX As Double = oModelRow("X")
5173
                Dim dY As Double = oModelRow("Y")
5174
                Dim sType As String = oModelRow("Type")
5175
                Dim sUid As String = ""
5176 496a0241 Gyusu
5177
5178 dd46ca83 Gyusu
                CheckConnectionLine(dX, dY, oLMConnector, sUid)
5179
                If oLMConnector IsNot Nothing Then
5180
                    If dStartFlag Then
5181
                        objInputs.AddPoint(dStartX, dStartY)
5182
                        objInputs.AddConnectorTarget(oLMConnector, dX, dY)
5183
                    Else
5184
                        objInputs.AddConnectorTarget(oPreLMConnector, dStartX, dStartY)
5185
                        objInputs.AddConnectorTarget(oLMConnector, dX, dY)
5186
                    End If
5187
                    oPreLMConnector = LineModeling(objInputs, sSystemPath)
5188
                    '모델링후 StartX를 현재 X로 변경
5189
                    dStartX = dX
5190
                    dStartY = dY
5191
                End If
5192
            Next
5193
            If oPreLMConnector IsNot Nothing Then
5194
                Dim objInputs As PlaceRunInputs
5195
                objInputs = New PlaceRunInputs
5196
                objInputs.AddConnectorTarget(oPreLMConnector, dStartX, dStartY)
5197
                objInputs.AddPoint(dEndX, dEndY)
5198
                LineModeling(objInputs, sSystemPath)
5199
            End If
5200
        End If
5201 1bfcc921 Gyusu
        Return bCheckBranchLine
5202
    End Function
5203
5204
5205 b08338e3 Gyusu
    Private Function CheckLineBranch(ByVal oLine_Dt As DataTable, ByRef dX As Double, ByRef dY As Double,
5206
                                     ByVal sDirection As String, ByRef oLMConnector As LMConnector) As Boolean
5207
5208 496a0241 Gyusu
        Dim oModelingLineRows() As DataRow = oLine_Dt.Select(" Then[" & _XML_LINE_DRAWING_TF & "] = 'TRUE' And " &
5209 b08338e3 Gyusu
                                                                "[" & _XML_LINE_SPID & "] <> ''")
5210
5211
        Dim bConnectionFlag As Boolean = False
5212
        Try
5213
            For Each oModelrow In oModelingLineRows
5214
                Dim sStartPoint As String = oModelrow(_XML_LINE_STARTPOINT)
5215
                Dim sEndPoint As String = oModelrow(_XML_LINE_ENDPOINT)
5216
                Dim dModelStartX As Double
5217
                Dim dModelStartY As Double
5218
                Dim dModelEndX As Double
5219
                Dim dModelEndY As Double
5220
                ConvertPointBystring(sStartPoint, dModelStartX, dModelStartY)
5221
                ConvertPointBystring(sEndPoint, dModelEndX, dModelEndY)
5222
                ConvertPointByImage(dModelStartX, dModelStartY, _IMG_X, _IMG_Y)
5223
                ConvertPointByImage(dModelEndX, dModelEndY, _IMG_X, _IMG_Y)
5224
                Dim dGap As Double = 0.0002
5225
5226
                If Math.Abs(dModelStartX - dModelEndX) <= Math.Abs(dModelStartY - dModelEndY) Then
5227
                    'Vertical
5228
                    If sDirection = "X" Then
5229
                        'x Direction Line
5230
                        If (dModelStartY + dGap >= dY And dModelEndY - dGap <= dY) Or
5231
                        (dModelStartY - dGap <= dY And dModelEndY + dGap >= dY) Then
5232
                            If (dX > dModelStartX And dX < dModelEndX) Or (dX > dModelEndX And dX < dModelStartX) Then
5233
                                If Math.Abs(dX - dModelStartX) > Math.Abs(dX - dModelEndX) Then
5234
                                    dX = dModelEndX
5235
                                Else
5236
                                    dX = dModelStartX
5237
                                End If
5238
                                Try
5239
                                    oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
5240
                                Catch ex As Exception
5241
5242
                                End Try
5243
                                bConnectionFlag = True
5244
                            End If
5245
                        End If
5246
                    End If
5247
                Else
5248
                    'Horizontal 
5249
                    If sDirection = "Y" Then
5250
                        If (dModelStartX + dGap >= dX And dModelEndX - dGap <= dX) Or
5251
                       (dModelStartX - dGap <= dX And dModelEndX + dGap >= dX) Then
5252
                            If (dY > dModelStartY And dY < dModelEndY) Or (dY > dModelEndY And dY < dModelStartY) Then
5253
                                If Math.Abs(dY - dModelStartY) > Math.Abs(dY - dModelEndY) Then
5254
                                    dY = dModelEndY
5255
                                Else
5256
                                    dY = dModelStartY
5257
                                End If
5258
                                Try
5259
                                    oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
5260
                                Catch ex As Exception
5261
                                End Try
5262
                                bConnectionFlag = True
5263
                            End If
5264
                        End If
5265
                    End If
5266
                End If
5267
            Next
5268
        Catch ex As Exception
5269
        End Try
5270
        Return bConnectionFlag
5271
    End Function
5272
    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,
5273
                              ByVal sLineNoUid As String, ByVal sLineUid As String, ByVal sSystemPath As String, ByRef oLMConnector As LMConnector) As Boolean
5274 76f465d0 Gyusu
        'Try
5275
        '    Dim oDatasource As Object = _Placement.PIDDataSource
5276
        '    Dim oPipeRun As LMPipeRun = Nothing
5277
        '    Dim objInputs As PlaceRunInputs
5278
        '    objInputs = New PlaceRunInputs
5279
        '    Dim objItem As LMAItem
5280
        '    '       Dim objConnector As LMConnector
5281
5282
        '    Dim oStartLineRow() As DataRow = oLine_Dt.Select("[" & _XML_LINE_Conn1_Uid & "] = '" & sStartLineUid & "' And " &
5283
        '                                                            "[" & _XML_LINE_DRAWING_TF & "] = 'TRUE' And" &
5284
        '                                                                  "[" & _XML_LINE_SPID & "] <> ''")
5285
        '    If oStartLineRow.Length = 0 Then
5286
        '        oStartLineRow = oLine_Dt.Select("[" & _XML_LINE_Conn2_Uid & "] = '" & sStartLineUid & "' And " &
5287
        '                                                            "[" & _XML_LINE_DRAWING_TF & "] = 'TRUE' And" &
5288
        '                                                                  "[" & _XML_LINE_SPID & "] <> ''")
5289
        '    End If
5290
        '    Dim oEndLineRow() As DataRow = oLine_Dt.Select("[" & _XML_LINE_Conn1_Uid & "] = '" & sEndLineUid & "' And " &
5291
        '                                                            "[" & _XML_LINE_DRAWING_TF & "] = 'TRUE' And" &
5292
        '                                                                  "[" & _XML_LINE_SPID & "] <> ''")
5293
5294
        '    oEndLineRow = oLine_Dt.Select("[" & _XML_LINE_Conn2_Uid & "] = '" & sEndLineUid & "' And " &
5295
        '                                                            "[" & _XML_LINE_DRAWING_TF & "] = 'TRUE' And" &
5296
        '                                                                  "[" & _XML_LINE_SPID & "] <> ''")
5297
        '    Dim sStartConnectionType As String = ""
5298
        '    Dim sEndConnectionType As String = ""
5299
5300
        '    Dim oStartLMConnector As LMConnector = Nothing
5301
        '    Dim oEndLMConnector As LMConnector = Nothing
5302
        '    Dim oDirectionLine As String = ""
5303
5304
        '    If Math.Abs(dStart_x - dEnd_x) > Math.Abs(dStart_y - dEnd_y) Then
5305
        '        oDirectionLine = "X"
5306
        '    Else
5307
        '        oDirectionLine = "Y"
5308
        '    End If
5309 b08338e3 Gyusu
5310 76f465d0 Gyusu
        '    Dim bCheckFlag As Boolean = False
5311 b08338e3 Gyusu
5312 76f465d0 Gyusu
        '    Dim bStartCheckFlag As Boolean = CheckConnectionLine(oStartLineRow, dStart_x, dStart_y, oStartLMConnector)
5313
        '    If bStartCheckFlag = False Then
5314
        '        bStartCheckFlag = CheckConnectionLine(oStartLineRow, dEnd_x, dEnd_y, oStartLMConnector)
5315
        '        bCheckFlag = True
5316
        '    End If
5317
        '    Dim bEndCheckFlag As Boolean = CheckConnectionLine(oEndLineRow, dEnd_x, dEnd_y, oEndLMConnector)
5318 b08338e3 Gyusu
5319 76f465d0 Gyusu
        '    If bEndCheckFlag = False Then
5320 b08338e3 Gyusu
5321 76f465d0 Gyusu
        '        bEndCheckFlag = CheckConnectionLine(oEndLineRow, dStart_x, dStart_y, oEndLMConnector)
5322
        '        bCheckFlag = True
5323
        '    End If
5324 b08338e3 Gyusu
5325 76f465d0 Gyusu
        '    If bStartCheckFlag = True And bEndCheckFlag = False Then
5326
        '        If bCheckFlag Then
5327
        '            objInputs.AddConnectorTarget(oStartLMConnector, dEnd_x, dEnd_y)
5328
        '            objInputs.AddPoint(dStart_x, dStart_y)
5329
        '        Else
5330
        '            objInputs.AddConnectorTarget(oStartLMConnector, dStart_x, dStart_y)
5331
        '            objInputs.AddPoint(dEnd_x, dEnd_y)
5332
        '        End If
5333
5334
        '    ElseIf bStartCheckFlag = False And bEndCheckFlag = True Then
5335
        '        If bCheckFlag Then
5336
5337
        '            objInputs.AddConnectorTarget(oStartLMConnector, dStart_x, dStart_y)
5338
        '            objInputs.AddPoint(dEnd_x, dEnd_y)
5339
        '        Else
5340
        '            objInputs.AddPoint(dStart_x, dStart_y)
5341
        '            objInputs.AddConnectorTarget(oStartLMConnector, dEnd_x, dEnd_y)
5342
        '        End If
5343
5344
        '    ElseIf bStartCheckFlag = True And bEndCheckFlag = True Then
5345
        '        objInputs.AddConnectorTarget(oStartLMConnector, dStart_x, dStart_y)
5346
        '        objInputs.AddConnectorTarget(oEndLMConnector, dEnd_x, dEnd_y)
5347
        '    Else
5348
        '        objInputs.AddPoint(dStart_x, dStart_y)
5349
        '        objInputs.AddPoint(dEnd_x, dEnd_y)
5350
        '    End If
5351
        '    SetListBoxItems(ListBox_Result, "Place Pipe..(" & dStart_x & "," & dStart_y & ") - (" & dEnd_x & "," & dEnd_y & ")..." & _iPipecnt & " count ")
5352
        '    _iPipecnt = _iPipecnt + 1
5353
        '    objItem = _Placement.PIDCreateItem(sSystemPath)
5354
        '    oLMConnector = _Placement.PIDPlaceRun(objItem, objInputs)
5355 b08338e3 Gyusu
5356 76f465d0 Gyusu
        '    Dim oUpdateRow As DataRow() = oLine_Dt.Select(_XML_LINE_UID & " = '" + sLineUid + "'")
5357
        '    If oUpdateRow.Length = 1 Then
5358
        '        oUpdateRow(0)(_XML_LINE_SPID) = oLMConnector.ModelItemID
5359
        '        oUpdateRow(0)(_XML_LINE_LMCONNECTOR) = oLMConnector
5360 b08338e3 Gyusu
5361 76f465d0 Gyusu
        '        oUpdateRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
5362
        '    End If
5363 b08338e3 Gyusu
5364 76f465d0 Gyusu
        '    oPipeRun = oDatasource.GetPipeRun(oLMConnector.ModelItemID)
5365
5366
        '    Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
5367
        '    If oAttributeRow.Length > 0 Then
5368
        '        For Each oAttribute In oAttributeRow
5369
        '            Try
5370
        '                Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
5371
        '                Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
5372
        '                If sPIDValue.Contains("'") Then
5373
        '                    sPIDValue = sPIDValue.Replace("'", """")
5374
        '                End If
5375
        '                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
5376
        '                oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
5377
        '            Catch ex As Exception
5378
        '            End Try
5379
        '        Next
5380
        '        oPipeRun.Commit()
5381
        '    End If
5382
        '    Dim sID_1 As String = ""
5383
        '    Dim sID_2 As String = ""
5384
        '    If oStartLMConnector IsNot Nothing Then
5385
        '        sID_1 = oStartLMConnector.ModelItemID
5386
        '        sID_2 = oLMConnector.ModelItemID
5387
        '    ElseIf oEndLMConnector IsNot Nothing Then
5388
        '        sID_1 = oEndLMConnector.ModelItemID
5389
        '        sID_2 = oLMConnector.ModelItemID
5390
        '    End If
5391
        '    If sID_1 <> "" And sID_2 <> "" Then
5392
        '        Dim objSurvivorItem As LMAItem = Nothing
5393
        '        Dim oPipeRun1 As LMPipeRun = oDatasource.GetPipeRun(sID_1)
5394
        '        Dim oPipeRun2 As LMPipeRun = oDatasource.GetPipeRun(sID_2)
5395
        '        _Placement.PIDJoinRuns(oPipeRun1, oPipeRun2)
5396
        '    End If
5397
        '    Return True
5398
        'Catch ex As Exception
5399
        '    Return False
5400
        'End Try
5401 b08338e3 Gyusu
5402
    End Function
5403
5404
    Private Function LineToLineModeling(ByVal sLineNoUid As String, ByVal oLine_Dt As DataTable,
5405
                                        ByVal oAttribute_Dt As DataTable, ByVal sConnLineUid As String, ByVal sType As String,
5406
                                        ByRef oLMConnector As LMConnector) As String
5407
        Dim sReturnUid As String = ""
5408
        Try
5409
            Dim sLineUid As String = ""
5410
5411
            Dim iConnType As Integer = 0
5412
5413
            Dim sStartpoint As String = ""
5414
            Dim sEndpoint As String = ""
5415 bb2a0c79 Gyusu
            Dim dOriginalStart_x As Double = 0.0
5416
            Dim dOriginalStart_y As Double = 0.0
5417
            Dim dOriginalEnd_x As Double = 0.0
5418
            Dim dOriginalEnd_y As Double = 0.0
5419
5420 b08338e3 Gyusu
            Dim dStart_x As Double = 0
5421
            Dim dStart_y As Double = 0
5422
            Dim dEnd_x As Double = 0
5423
            Dim dEnd_y As Double = 0
5424
            Dim sStartLineUid As String = sConnLineUid
5425
            Dim sEndLineUid As String = ""
5426
            Dim sDirection As String = ""
5427
            Dim sSystemPath As String = GetPipeType(sType)
5428
5429
            Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_UID & " = '" & sConnLineUid & "' And " &
5430
                                                                    "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
5431
                                                                     "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
5432
                                                                     "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
5433
            If oPipeRow.Length > 0 Then
5434 bb2a0c79 Gyusu
                sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
5435
                sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
5436 e4000111 Gyusu
                ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
5437
                ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
5438 b08338e3 Gyusu
                ConvertPointByImage(dOriginalStart_x, dOriginalStart_y, _IMG_X, _IMG_Y)
5439
                ConvertPointByImage(dOriginalEnd_x, dOriginalEnd_y, _IMG_X, _IMG_Y)
5440
                If dStart_x = 0 And dStart_y = 0 Then
5441
                    dStart_x = dOriginalStart_x
5442
                    dStart_y = dOriginalStart_y
5443
                    dEnd_x = dOriginalEnd_x
5444
                    dEnd_y = dOriginalEnd_y
5445
                    If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
5446
                        sDirection = "X"
5447
                    Else
5448
                        sDirection = "Y"
5449
                    End If
5450
                    oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
5451
                    sLineUid = sConnLineUid
5452
                End If
5453
            End If
5454 bb2a0c79 Gyusu
5455 b08338e3 Gyusu
            While True
5456
                sLineUid = ""
5457
                oPipeRow = oLine_Dt.Select(_XML_LINE_Conn1_Uid & " = '" + sConnLineUid + "' And " &
5458 f9b63682 Gyusu
                                            "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
5459
                                            "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
5460
                                            "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
5461 b08338e3 Gyusu
5462
                If oPipeRow.Length = 0 Then
5463
                    oPipeRow = oLine_Dt.Select(_XML_LINE_Conn2_Uid & " = '" + sConnLineUid + "' And " &
5464 f9b63682 Gyusu
                                            "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
5465
                                            "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
5466
                                            "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
5467 bb2a0c79 Gyusu
                Else
5468 b08338e3 Gyusu
                    'sLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
5469
                    'sConnLineUid = sLineUid
5470
                    sLineUid = sConnLineUid
5471
                    sConnLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
5472
                    iConnType = 1
5473
                End If
5474
5475
                If oPipeRow.Length > 0 Then
5476
                    If sLineUid = "" Then
5477
                        'sLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
5478
                        'sConnLineUid = sLineUid
5479
                        sLineUid = sConnLineUid
5480
                        sConnLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
5481
                        iConnType = 2
5482
                    End If
5483
                    If iConnType = 1 Then
5484
5485
                    ElseIf iConnType = 2 Then
5486
5487
                    End If
5488
                    sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
5489
                    sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
5490
                    ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
5491
                    ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
5492
                    ConvertPointByImage(dOriginalStart_x, dOriginalStart_y, _IMG_X, _IMG_Y)
5493
                    ConvertPointByImage(dOriginalEnd_x, dOriginalEnd_y, _IMG_X, _IMG_Y)
5494
5495
                    If dStart_x = 0 And dStart_y = 0 Then
5496
                        dStart_x = dOriginalStart_x
5497
                        dStart_y = dOriginalStart_y
5498
                        dEnd_x = dOriginalEnd_x
5499
                        dEnd_y = dOriginalEnd_y
5500
                        If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
5501
                            sDirection = "X"
5502
                        Else
5503
                            sDirection = "Y"
5504
                        End If
5505
                        sType = oPipeRow(0)(_XML_LINE_TYPE).ToString()
5506
                        sSystemPath = GetPipeType(sType)
5507
                    Else
5508
                        If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
5509
                            If sDirection = "Y" Then
5510
                                '방향이 바꼈음 Y - > X
5511
                                LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
5512
                                sLineNoUid, sLineUid, sSystemPath, oLMConnector)
5513
                                dStart_x = dOriginalStart_x
5514
                                dStart_y = dOriginalStart_y
5515
                                dEnd_x = dOriginalEnd_x
5516
                                dEnd_y = dOriginalEnd_y
5517
                                sStartLineUid = sConnLineUid
5518
                            Else
5519
                                dEnd_x = dOriginalEnd_x
5520
                                dEnd_y = dOriginalEnd_y
5521
                            End If
5522
                            sDirection = "X"
5523
                        Else
5524
                            If sDirection = "X" Then
5525
                                '방향이 바꼈음 X - > Y
5526
                                LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
5527
                                sLineNoUid, sLineUid, sSystemPath, oLMConnector)
5528
                                dStart_x = dOriginalStart_x
5529
                                dStart_y = dOriginalStart_y
5530
                                dEnd_x = dOriginalEnd_x
5531
                                dEnd_y = dOriginalEnd_y
5532
                                sStartLineUid = sConnLineUid
5533
                            Else
5534
5535
                                dEnd_x = dOriginalEnd_x
5536
                                dEnd_y = dOriginalEnd_y
5537
                            End If
5538
                            sDirection = "Y"
5539
                        End If
5540
                    End If
5541
                    '            oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
5542
                Else
5543
                    If dStart_x <> 0 And dStart_y <> 0 And dEnd_x <> 0 And dEnd_y <> 0 Then
5544
                        LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
5545
                         sLineNoUid, sLineUid, sSystemPath, oLMConnector)
5546
                    End If
5547
                    sReturnUid = sConnLineUid
5548
                    Exit While
5549
                End If
5550
            End While
5551
5552
            If sStartLineUid <> "" And sEndLineUid <> "" Then
5553
                LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
5554
                             sLineNoUid, sLineUid, sSystemPath, oLMConnector)
5555
                dStart_x = 0
5556
                dStart_y = 0
5557
                dEnd_x = 0
5558
                dEnd_y = 0
5559
            End If
5560
        Catch ex As Exception
5561
5562
        End Try
5563
5564
        Return sReturnUid
5565
    End Function
5566
5567
5568
    'Private Function LineToLineModeling(ByVal sLineNoUid As String, ByVal oLine_Dt As DataTable,
5569
    '                                    ByVal oAttribute_Dt As DataTable, ByVal sConnLineUid As String, ByVal sType As String) As String
5570
    '    Dim sReturnUid As String = ""
5571
    '    Try
5572
    '        Dim sLineUid As String = ""
5573
5574
    '        Dim iConnType As Integer = 0
5575
5576
    '        Dim sStartpoint As String = ""
5577
    '        Dim sEndpoint As String = ""
5578
    '        Dim dOriginalStart_x As Double = 0.0
5579
    '        Dim dOriginalStart_y As Double = 0.0
5580
    '        Dim dOriginalEnd_x As Double = 0.0
5581
    '        Dim dOriginalEnd_y As Double = 0.0
5582
5583
    '        Dim dStart_x As Double = 0
5584
    '        Dim dStart_y As Double = 0
5585
    '        Dim dEnd_x As Double = 0
5586
    '        Dim dEnd_y As Double = 0
5587
    '        Dim sStartLineUid As String = sConnLineUid
5588
    '        Dim sEndLineUid As String = ""
5589
    '        Dim sDirection As String = ""
5590
    '        Dim sSystemPath As String = GetPipeType(sType)
5591
5592
    '        Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_UID & " = '" & sConnLineUid & "' And " &
5593
    '                                                                "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
5594
    '                                                                 "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
5595
    '                                                                 "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
5596
    '        If oPipeRow.Length > 0 Then
5597
    '            sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
5598
    '            sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
5599
    '            ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
5600
    '            ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
5601
    '            ConvertPointByImage(dOriginalStart_x, dOriginalStart_y, _IMG_X, _IMG_Y)
5602
    '            ConvertPointByImage(dOriginalEnd_x, dOriginalEnd_y, _IMG_X, _IMG_Y)
5603
    '            If dStart_x = 0 And dStart_y = 0 Then
5604
    '                dStart_x = dOriginalStart_x
5605
    '                dStart_y = dOriginalStart_y
5606
    '                dEnd_x = dOriginalEnd_x
5607
    '                dEnd_y = dOriginalEnd_y
5608
    '                If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
5609
    '                    sDirection = "X"
5610
    '                Else
5611
    '                    sDirection = "Y"
5612
    '                End If
5613
    '                oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
5614
    '                sLineUid = sConnLineUid
5615
    '            End If
5616
    '        End If
5617
5618
    '        While True
5619
    '            sLineUid = ""
5620
    '            oPipeRow = oLine_Dt.Select(_XML_LINE_Conn1_Uid & " = '" + sConnLineUid + "' And " &
5621
    '                                                                "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
5622
    '                                                                         "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
5623
    '                                                                         "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
5624
5625
    '            If oPipeRow.Length = 0 Then
5626
    '                oPipeRow = oLine_Dt.Select(_XML_LINE_Conn2_Uid & " = '" + sConnLineUid + "' And " &
5627
    '                                         "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
5628
    '                                       "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
5629
    '                                      "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
5630
    '            Else
5631
    '                'sLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
5632
    '                'sConnLineUid = sLineUid
5633
    '                sLineUid = sConnLineUid
5634
    '                sConnLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
5635
    '                iConnType = 1
5636
    '            End If
5637
5638
    '            If oPipeRow.Length > 0 Then
5639
    '                If sLineUid = "" Then
5640
    '                    'sLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
5641
    '                    'sConnLineUid = sLineUid
5642
    '                    sLineUid = sConnLineUid
5643
    '                    sConnLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
5644
    '                    iConnType = 2
5645
    '                End If
5646
    '                If iConnType = 1 Then
5647
5648
    '                ElseIf iConnType = 2 Then
5649
5650
    '                End If
5651
    '                sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
5652
    '                sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
5653
    '                ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
5654
    '                ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
5655
    '                ConvertPointByImage(dOriginalStart_x, dOriginalStart_y, _IMG_X, _IMG_Y)
5656
    '                ConvertPointByImage(dOriginalEnd_x, dOriginalEnd_y, _IMG_X, _IMG_Y)
5657
5658
5659
5660
    '                If dStart_x = 0 And dStart_y = 0 Then
5661
    '                    dStart_x = dOriginalStart_x
5662
    '                    dStart_y = dOriginalStart_y
5663
    '                    dEnd_x = dOriginalEnd_x
5664
    '                    dEnd_y = dOriginalEnd_y
5665
    '                    If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
5666
    '                        sDirection = "X"
5667
    '                    Else
5668
    '                        sDirection = "Y"
5669
    '                    End If
5670
    '                    sType = oPipeRow(0)(_XML_LINE_TYPE).ToString()
5671
    '                    sSystemPath = GetPipeType(sType)
5672
    '                Else
5673
    '                    If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
5674
    '                        If sDirection = "Y" Then
5675
    '                            '방향이 바꼈음 Y - > X
5676
    '                            LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
5677
    '                            sLineNoUid, sLineUid, sSystemPath)
5678
    '                            dStart_x = dOriginalStart_x
5679
    '                            dStart_y = dOriginalStart_y
5680
    '                            dEnd_x = dOriginalEnd_x
5681
    '                            dEnd_y = dOriginalEnd_y
5682
    '                            sStartLineUid = sConnLineUid
5683
    '                        Else
5684
    '                            dEnd_x = dOriginalEnd_x
5685
    '                            dEnd_y = dOriginalEnd_y
5686
    '                        End If
5687
    '                        sDirection = "X"
5688
    '                    Else
5689
    '                        If sDirection = "X" Then
5690
    '                            '방향이 바꼈음 X - > Y
5691
    '                            LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
5692
    '                            sLineNoUid, sLineUid, sSystemPath)
5693
    '                            dStart_x = dOriginalStart_x
5694
    '                            dStart_y = dOriginalStart_y
5695
    '                            dEnd_x = dOriginalEnd_x
5696
    '                            dEnd_y = dOriginalEnd_y
5697
    '                            sStartLineUid = sConnLineUid
5698
    '                        Else
5699
5700
    '                            dEnd_x = dOriginalEnd_x
5701
    '                            dEnd_y = dOriginalEnd_y
5702
    '                        End If
5703
    '                        sDirection = "Y"
5704
    '                    End If
5705
    '                End If
5706
    '                '            oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
5707
    '            Else
5708
    '                If dStart_x <> 0 And dStart_y <> 0 And dEnd_x <> 0 And dEnd_y <> 0 Then
5709
    '                    LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
5710
    '                     sLineNoUid, sLineUid, sSystemPath)
5711
    '                End If
5712
5713
5714
    '                sReturnUid = sConnLineUid
5715
    '                Exit While
5716
    '            End If
5717
    '        End While
5718
5719
    '        If sStartLineUid <> "" And sEndLineUid <> "" Then
5720
    '            LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
5721
    '                         sLineNoUid, sLineUid, sSystemPath)
5722
    '            dStart_x = 0
5723
    '            dStart_y = 0
5724
    '            dEnd_x = 0
5725
    '            dEnd_y = 0
5726
    '        End If
5727
    '    Catch ex As Exception
5728
5729
    '    End Try
5730
5731
    '    Return sReturnUid
5732
    'End Function
5733
5734
5735
    Private Function SymbolToLine_Modeling(ByVal oLine_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal sLineNoUid As String,
5736
                                       ByVal sSymbolUid As String, ByVal oLMSymbol As LMSymbol) As String
5737
5738
5739
        Dim oDatasource As Object = _Placement.PIDDataSource
5740
        Dim oPipeRun As LMPipeRun = Nothing
5741
        Dim objItem As LMAItem
5742
        Dim objConnector As LMConnector
5743
        Dim objInputs As PlaceRunInputs
5744
        objInputs = New PlaceRunInputs
5745
5746
5747
        Dim sPipeUid As String = ""
5748
        Dim iConnType As Integer = 0
5749
        Dim sStartpoint As String = ""
5750
        Dim sEndpoint As String = ""
5751
        Dim dOriginalStart_x As Double = 0.0
5752
        Dim dOriginalStart_y As Double = 0.0
5753
        Dim dOriginalEnd_x As Double = 0.0
5754
        Dim dOriginalEnd_y As Double = 0.0
5755
        Dim dStart_x As Double = 0.0
5756
        Dim dStart_y As Double = 0.0
5757
        Dim dEnd_x As Double = 0.0
5758
        Dim dEnd_y As Double = 0.0
5759
5760
        Dim sReturnUid As String = ""
5761
        Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_Conn1_Uid & " = '" + sSymbolUid + "' And " &
5762
                                                                        "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
5763
                                                                                  _XML_SYMBOL_Check & "] = 'TRUE'")
5764
        If oPipeRow.Length = 0 Then
5765
            oPipeRow = oLine_Dt.Select(_XML_LINE_Conn2_Uid & " = '" + sSymbolUid + "' And " &
5766
                                     "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
5767
                                    _XML_SYMBOL_Check & "] = 'TRUE'")
5768
        Else
5769
            sPipeUid = oPipeRow(0)(_XML_LINE_UID).ToString()
5770
            iConnType = 1
5771
        End If
5772
5773
        If oPipeRow.Length = 1 Then
5774
            If sPipeUid = "" Then
5775
                sPipeUid = oPipeRow(0)(_XML_LINE_UID).ToString()
5776
                iConnType = 2
5777
            End If
5778
            sReturnUid = oPipeRow(0)(_XML_LINE_UID).ToString()
5779
            sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
5780
            sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
5781
            ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
5782
            dStart_x = dOriginalStart_x
5783
            dStart_y = dOriginalStart_y
5784
            ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
5785
            dEnd_x = dOriginalEnd_x
5786
            dEnd_y = dOriginalEnd_y
5787
            ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
5788
            ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
5789
            'OPC Connection Point가져와서 연결(2018-07-12)
5790
            If iConnType = 1 Then
5791
                FindNearPoint(oLMSymbol, dStart_x, dStart_y)
5792
                objInputs.AddSymbolTarget(oLMSymbol, dStart_x, dStart_y)
5793
                objInputs.AddPoint(dEnd_x, dEnd_y)
5794
            Else
5795
                FindNearPoint(oLMSymbol, dEnd_x, dEnd_y)
5796
                objInputs.AddSymbolTarget(oLMSymbol, dEnd_x, dEnd_y)
5797
                objInputs.AddPoint(dStart_x, dStart_y)
5798
            End If
5799
            oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
5800
5801
            Dim sType As String = oPipeRow(0)(_XML_LINE_TYPE).ToString()
5802
            Dim sSystemPath As String = GetPipeType(sType)
5803
5804
5805
5806
5807
            objItem = _Placement.PIDCreateItem(sSystemPath)
5808
            objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
5809
            oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
5810
            Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
5811
            If oAttributeRow.Length > 0 Then
5812
                For Each oAttribute In oAttributeRow
5813
                    Try
5814
                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
5815
                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
5816
                        If sPIDValue.Contains("'") Then
5817
                            sPIDValue = sPIDValue.Replace("'", """")
5818
                        End If
5819
                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
5820
                        oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
5821
                    Catch ex As Exception
5822
                    End Try
5823
                Next
5824
                oPipeRun.Commit()
5825
            End If
5826
        End If
5827
        Return sReturnUid
5828
    End Function
5829
5830
    Private Function LineToSymbol_Modeling(ByVal oSymbol_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal sLineNoUid As String,
5831
                                       ByVal sLineUid As String, ByVal oLMConnector As LMConnector, ByRef oLMSymbol As LMSymbol) As String
5832
5833
5834
        Dim oDatasource As Object = _Placement.PIDDataSource
5835
        Dim objItem As LMAItem
5836
        Dim objConnector As LMConnector
5837
        Dim objInputs As PlaceRunInputs
5838
        objInputs = New PlaceRunInputs
5839
5840
5841
        Dim sSymbolUid As String = ""
5842
        Dim iConnType As Integer = 0
5843
        Dim dOriginalPoint_x As Double = 0.0
5844
        Dim dORiginalPoint_y As Double = 0.0
5845
        Dim dX As Double = 0.0
5846
        Dim dY As Double = 0.0
5847
        Dim sReturnUid As String = ""
5848
        Dim oSymbolRow() As DataRow = oSymbol_Dt.Select(_XML_SYMBOL_Conn1_Uid & " = '" + sLineUid + "' And " &
5849
                                                                        "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
5850
                                                                                  _XML_SYMBOL_Check & "] = 'TRUE'")
5851
        If oSymbolRow.Length = 0 Then
5852
            oSymbolRow = oSymbol_Dt.Select(_XML_SYMBOL_Conn2_Uid & " = '" + sLineUid + "' And " &
5853
                                                                        "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
5854
                                                                                 _XML_SYMBOL_Check & "] = 'TRUE'")
5855
            If oSymbolRow.Length = 0 Then
5856
                oSymbolRow = oSymbol_Dt.Select(_XML_SYMBOL_Conn2_Uid & " = '" + sLineUid + "' And " &
5857
                                                                 "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
5858
                                                                          _XML_SYMBOL_Check & "] = 'TRUE'")
5859
                If oSymbolRow.Length = 0 Then
5860
                    oSymbolRow = oSymbol_Dt.Select(_XML_SYMBOL_Conn2_Uid & " = '" + sLineUid + "' And " &
5861
                                                   "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
5862
                                                            _XML_SYMBOL_Check & "] = 'TRUE'")
5863
                    If oSymbolRow.Length = 0 Then
5864
5865
                    Else
5866
                        sSymbolUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
5867
                        iConnType = 4
5868
                    End If
5869
                Else
5870
                    sSymbolUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
5871
                    iConnType = 3
5872
                End If
5873
            Else
5874
                sSymbolUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
5875
                iConnType = 2
5876
            End If
5877
5878
        Else
5879
            sSymbolUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
5880
            iConnType = 1
5881
        End If
5882
5883
        If oSymbolRow.Length = 1 Then
5884
            If sSymbolUid = "" Then
5885
                sSymbolUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
5886
                iConnType = 2
5887
            End If
5888
            sReturnUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
5889
            Dim sOriginalPoint As String = oSymbolRow(0)(_XML_SYMBOL_ORIGINALPOINT).ToString()
5890
            ConvertPointBystring(sOriginalPoint, dOriginalPoint_x, dORiginalPoint_y)
5891
            dX = dOriginalPoint_x
5892
            dY = dORiginalPoint_y
5893
            ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
5894
            'OPC Connection Point가져와서 연결(2018-07-12)
5895
5896
            oSymbolRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
5897
5898
            Dim sType As String = oSymbolRow(0)(_XML_LINE_TYPE).ToString()
5899
            Dim sSystemPath As String = GetPipeType(sType)
5900
5901
            oLMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, ExistingItem:=oLMConnector.AsLMAItem,
5902
          TargetItem:=oLMSymbol.AsLMAItem)
5903
5904
            Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
5905
            If oAttributeRow.Length > 0 Then
5906
                For Each oAttribute In oAttributeRow
5907
                    Try
5908
                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
5909
                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
5910
                        If sPIDValue.Contains("'") Then
5911
                            sPIDValue = sPIDValue.Replace("'", """")
5912
                        End If
5913
                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
5914
                        oLMSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
5915
                    Catch ex As Exception
5916
                    End Try
5917
                Next
5918
            End If
5919
        End If
5920
        Return sReturnUid
5921
    End Function
5922
5923
5924
    Private Sub OPCTOLineRouting(ByRef oLine_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal oOPCSymbol As LMSymbol,
5925
                            ByVal sOPCUid As String, ByVal sLineNoUid As String)
5926
        Try
5927
            Dim oDatasource As Object = _Placement.PIDDataSource
5928
            Dim objItem As LMAItem
5929
            Dim objConnector As LMConnector
5930
            Dim objInputs As PlaceRunInputs
5931
            objInputs = New PlaceRunInputs
5932
            Dim dOriginalStart_x As Double = 0.0
5933
            Dim dOriginalStart_y As Double = 0.0
5934
            Dim dOriginalEnd_x As Double = 0.0
5935
            Dim dOriginalEnd_y As Double = 0.0
5936
            Dim dStart_x As Double = 0.0
5937
            Dim dStart_y As Double = 0.0
5938
            Dim dEnd_x As Double = 0.0
5939
            Dim dEnd_y As Double = 0.0
5940
5941
            Dim oPipeRun As LMPipeRun = Nothing
5942
            Dim sStartpoint As String = ""
5943
            Dim sEndpoint As String = ""
5944
            Dim iConnType As Integer = 0
5945
            Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_Conn1_Uid & " = '" + sOPCUid + "' And [" &
5946
                                                                                       _XML_SYMBOL_Check & "] = 'TRUE'")
5947
            Dim sPipeUid As String = ""
5948
            If oPipeRow.Length = 0 Then
5949
                oPipeRow = oLine_Dt.Select(_XML_LINE_Conn2_Uid & " = '" + sOPCUid + "' And [" &
5950
                        _XML_SYMBOL_Check & "] = 'TRUE'")
5951
            Else
5952
                sPipeUid = oPipeRow(0)(_XML_LINE_UID).ToString()
5953
                iConnType = 1
5954
            End If
5955
            Dim oAddUid_List As New List(Of String)
5956
            If oPipeRow.Length = 1 Then
5957
                If sPipeUid = "" Then
5958
                    sPipeUid = oPipeRow(0)(_XML_LINE_UID).ToString()
5959
                    iConnType = 2
5960
                End If
5961
                oAddUid_List.Add(sPipeUid)
5962
                sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
5963
                sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
5964
                ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
5965
                dStart_x = dOriginalStart_x
5966
                dStart_y = dOriginalStart_y
5967
                ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
5968
                dEnd_x = dOriginalEnd_x
5969
                dEnd_y = dOriginalEnd_y
5970
                ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
5971
                ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
5972
5973
                'OPC Connection Point가져와서 연결(2018-07-12)
5974
                If iConnType = 1 Then
5975
                    FindNearPoint(oOPCSymbol, dStart_x, dStart_y)
5976
                    objInputs.AddSymbolTarget(oOPCSymbol, dStart_x, dStart_y)
5977
                    objInputs.AddPoint(dEnd_x, dEnd_y)
5978
                Else
5979
                    FindNearPoint(oOPCSymbol, dEnd_x, dEnd_y)
5980
                    objInputs.AddSymbolTarget(oOPCSymbol, dEnd_x, dEnd_y)
5981 bb2a0c79 Gyusu
                    objInputs.AddPoint(dStart_x, dStart_y)
5982
                End If
5983
                oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
5984
5985
                While True
5986
                    '    objInputs.Clear()
5987
                    Dim oAddPipeRow() As DataRow = oLine_Dt.Select("[" & _XML_LINE_Conn1_Uid & "] = '" + sPipeUid + "' and " &
5988
                                                                 "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And [" &
5989
                                                                                       _XML_SYMBOL_Check & "] = 'TRUE'")
5990
                    If oAddPipeRow.Length = 0 Then
5991
                        oAddPipeRow = oLine_Dt.Select("[" & _XML_LINE_Conn2_Uid & "] = '" + sPipeUid + "' and " &
5992
                                                                 "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And [" &
5993
                                                                                       _XML_SYMBOL_Check & "] = 'TRUE'")
5994
                        sPipeUid = ""
5995
                    Else
5996
                        iConnType = 1
5997
                        sPipeUid = oAddPipeRow(0)(_XML_LINE_UID).ToString()
5998
                    End If
5999
                    If oAddPipeRow.Length = 1 Then
6000
                        If sPipeUid = "" Then
6001
                            sPipeUid = oAddPipeRow(0)(_XML_LINE_UID).ToString()
6002
                            iConnType = 2
6003
                        End If
6004
                        oAddUid_List.Add(sPipeUid)
6005
                        sStartpoint = oAddPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
6006
                        sEndpoint = oAddPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
6007
                        ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
6008
                        dStart_x = dOriginalStart_x
6009
                        dStart_y = dOriginalStart_y
6010
                        ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
6011
                        dEnd_x = dOriginalEnd_x
6012
                        dEnd_y = dOriginalEnd_y
6013
                        ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
6014
                        ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
6015
                        If iConnType = 1 Then
6016
                            objInputs.AddPoint(dEnd_x, dEnd_y)
6017
                            ' objInputs.AddPoint(dStart_x, dStart_y)
6018
                        Else
6019
                            'objInputs.AddConnectorTarget(objConnector, dStart_x, dStart_y)
6020
                            '  objInputs.AddPoint(dStart_x, dStart_y)
6021
                            '  objInputs.AddPoint(dEnd_x, dEnd_y)
6022
                            objInputs.AddPoint(dStart_x, dStart_y)
6023
                        End If
6024 e4000111 Gyusu
6025 bb2a0c79 Gyusu
                        oAddPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
6026
                    Else
6027
                        Exit While
6028
                    End If
6029 e4000111 Gyusu
6030 bb2a0c79 Gyusu
                End While
6031
                Dim sType As String = oPipeRow(0)(_XML_LINE_TYPE).ToString()
6032
                Dim sSystemPath As String = GetPipeType(sType)
6033 e4000111 Gyusu
6034 bb2a0c79 Gyusu
                objItem = _Placement.PIDCreateItem(sSystemPath)
6035
                objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
6036
                For i = 0 To oAddUid_List.Count - 1
6037
                    Dim oUpdateRow As DataRow() = oLine_Dt.Select(_XML_LINE_UID & " = '" + oAddUid_List(i) + "'")
6038
                    If oUpdateRow.Length = 1 Then
6039
                        oUpdateRow(0)(_XML_LINE_SPID) = objConnector.ModelItemID
6040
                        oUpdateRow(0)(_XML_LINE_LMCONNECTOR) = objConnector
6041
                    End If
6042
                Next
6043
6044
6045
                oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
6046
                Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
6047
                If oAttributeRow.Length > 0 Then
6048
                    For Each oAttribute In oAttributeRow
6049
                        Try
6050
                            Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
6051
                            Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
6052
                            If sPIDValue.Contains("'") Then
6053
                                sPIDValue = sPIDValue.Replace("'", """")
6054
                            End If
6055
                            Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
6056
                            oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
6057
                        Catch ex As Exception
6058
                        End Try
6059
                    Next
6060
                    oPipeRun.Commit()
6061
                End If
6062
6063
            End If
6064
6065
        Catch ex As Exception
6066
        End Try
6067
    End Sub
6068
6069
    Private Function AddUidList중복체크(ByVal sUidList As List(Of String), ByVal sAddUid As String) As Boolean
6070 e4000111 Gyusu
6071 bb2a0c79 Gyusu
        For Each sUid In sUidList
6072
            If sUid = sAddUid Then
6073
                Return False
6074
            End If
6075
        Next
6076
        Return True
6077
    End Function
6078
6079 b08338e3 Gyusu
    Private Sub LineRouting(ByRef oLine_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal sLineNoUid As String, ByVal sLineNoText As String)
6080 bb2a0c79 Gyusu
        Try
6081
            Dim oDatasource As Object = _Placement.PIDDataSource
6082
            Dim objItem As LMAItem
6083
            Dim objConnector As LMConnector
6084
            Dim objInputs As PlaceRunInputs
6085
            objInputs = New PlaceRunInputs
6086
            Dim dOriginalStart_x As Double = 0.0
6087
            Dim dOriginalStart_y As Double = 0.0
6088
            Dim dOriginalEnd_x As Double = 0.0
6089
            Dim dOriginalEnd_y As Double = 0.0
6090
            Dim dStart_x As Double = 0.0
6091
            Dim dStart_y As Double = 0.0
6092
            Dim dEnd_x As Double = 0.0
6093
            Dim dEnd_y As Double = 0.0
6094
            Dim oPipeRun As LMPipeRun = Nothing
6095
            Dim sStartpoint As String = ""
6096
            Dim sEndpoint As String = ""
6097
            Dim iConnType As Integer = 0
6098
            Dim pLMConnector As LMConnector = Nothing
6099
            For Each oLinerow In oLine_Dt.Rows
6100
                objInputs.Clear()
6101 b08338e3 Gyusu
                Dim sCheck As String = oLinerow(_XML_LINE_DRAWING_TF).ToString()
6102
                If sCheck = "FALSE" Then
6103
                    Dim sUid As String = oLinerow(_XML_LINE_UID).ToString()
6104
                    sStartpoint = oLinerow(_XML_LINE_STARTPOINT).ToString()
6105
                    sEndpoint = oLinerow(_XML_LINE_ENDPOINT).ToString()
6106
                    ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
6107
                    dStart_x = dOriginalStart_x
6108
                    dStart_y = dOriginalStart_y
6109
                    ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
6110
                    dEnd_x = dOriginalEnd_x
6111
                    dEnd_y = dOriginalEnd_y
6112
                    ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
6113
                    ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
6114 bb2a0c79 Gyusu
6115 b08338e3 Gyusu
                    objInputs.AddPoint(dStart_x, dStart_y)
6116
                    objInputs.AddPoint(dEnd_x, dEnd_y)
6117 bb2a0c79 Gyusu
                    Dim sType As String = oLinerow(_XML_LINE_TYPE).ToString()
6118
                    Dim sSystemPath As String = GetPipeType(sType)
6119
                    objItem = _Placement.PIDCreateItem(sSystemPath)
6120
                    objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
6121 b08338e3 Gyusu
                    SetListBoxItems(ListBox_Result, "Place Pipe.." & sUid & " (" & dOriginalStart_x & "," & dOriginalStart_y & ") - (" & dOriginalEnd_x & "," & dOriginalEnd_y & ")..." & _iPipecnt & " count ")
6122
6123
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Pipe : " & sUid)
6124
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "LineNo : " & sLineNoText)
6125
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection1 : " & oLinerow(_XML_SYMBOL_Conn1_Uid).ToString())
6126
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection2 : " & oLinerow(_XML_SYMBOL_Conn2_Uid).ToString())
6127
                    'ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
6128
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "StartPoint : " & dOriginalStart_x & "," & dOriginalStart_y)
6129
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "EndPoint : " & dOriginalEnd_x & "," & dOriginalEnd_y)
6130
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Pipe Count : " & _iPipecnt)
6131
6132
                    _iPipecnt = _iPipecnt + 1
6133
                    oLinerow(_XML_LINE_SPID) = objConnector.ModelItemID
6134
                    oLinerow(_XML_LINE_LMCONNECTOR) = objConnector
6135
6136
                    oLinerow(_XML_LINE_DRAWING_TF) = "TRUE"
6137 bb2a0c79 Gyusu
                    oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
6138
6139
                    Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
6140
                    If oAttributeRow.Length > 0 Then
6141
                        For Each oAttribute In oAttributeRow
6142
                            Try
6143
                                Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
6144
                                Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
6145
                                If sPIDValue.Contains("'") Then
6146
                                    sPIDValue = sPIDValue.Replace("'", """")
6147
                                End If
6148
                                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
6149
                                oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
6150
                            Catch ex As Exception
6151
                            End Try
6152
                        Next
6153
                        oPipeRun.Commit()
6154
                    End If
6155
                End If
6156
6157
6158
6159
6160
6161 b08338e3 Gyusu
                'Dim sPipeUid As String = oLinerow(_XML_LINE_UID).ToString()
6162
                'Dim sCheckModeling As Boolean = False
6163
                'objInputs.Clear()
6164
                'Dim oAddUid_List As New List(Of String)
6165
                'Try
6166
                '    Dim oAddPipeRow() As DataRow = oLine_Dt.Select("[" & _XML_LINE_Conn1_Uid & "] = '" + sPipeUid + "' and " &
6167
                '                                            "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And [" &
6168
                '                                            _XML_SYMBOL_Check & "] = 'TRUE'")
6169
                '    If oAddPipeRow.Length = 0 Then
6170
                '        oAddPipeRow = oLine_Dt.Select("[" & _XML_LINE_Conn2_Uid & "] = '" + sPipeUid + "' and " &
6171
                '                                        "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And [" &
6172
                '                                        _XML_SYMBOL_Check & "] = 'TRUE'")
6173
                '        sPipeUid = ""
6174
                '    Else
6175
                '        iConnType = 1
6176
                '        sPipeUid = oAddPipeRow(0)(_XML_LINE_UID).ToString()
6177
                '    End If
6178
                '    If oAddPipeRow.Length = 1 Then
6179
                '        sCheckModeling = True
6180
                '        If sPipeUid = "" Then
6181
                '            sPipeUid = oAddPipeRow(0)(_XML_LINE_UID).ToString()
6182
                '            iConnType = 2
6183
                '        End If
6184
                '        If AddUidList중복체크(oAddUid_List, sPipeUid) Then
6185
                '            oAddUid_List.Add(sPipeUid)
6186
                '        End If
6187
                '        sStartpoint = oAddPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
6188
                '        sEndpoint = oAddPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
6189
                '        ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
6190
                '        dStart_x = dOriginalStart_x
6191
                '        dStart_y = dOriginalStart_y
6192
                '        ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
6193
                '        dEnd_x = dOriginalEnd_x
6194
                '        dEnd_y = dOriginalEnd_y
6195
                '        ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
6196
                '        ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
6197
                '        Dim sBranchType As String = ""
6198
                '        If (CheckBranchLine(oLine_Dt, dStart_x, dStart_y, dEnd_x, dEnd_y, sBranchType, pLMConnector)) Then
6199
                '            Try
6200
                '                If pLMConnector Is Nothing Then
6201
                '                    objInputs.AddPoint(dStart_x, dStart_y)
6202
                '                    objInputs.AddPoint(dEnd_x, dEnd_y)
6203
                '                Else
6204
                '                    If sBranchType = "1" Then
6205
                '                        objInputs.AddConnectorTarget(pLMConnector, dStart_x, dStart_y)
6206
                '                        objInputs.AddPoint(dEnd_x, dEnd_y)
6207
                '                    ElseIf sBranchType = "2" Then
6208
                '                        objInputs.AddConnectorTarget(pLMConnector, dEnd_x, dEnd_y)
6209
                '                        objInputs.AddPoint(dStart_x, dStart_y)
6210
                '                    ElseIf sBranchType = "3" Then
6211
                '                        objInputs.AddConnectorTarget(pLMConnector, dStart_x, dStart_y)
6212
                '                        objInputs.AddPoint(dEnd_x, dEnd_y)
6213
                '                    ElseIf sBranchType = "4" Then
6214
                '                        objInputs.AddConnectorTarget(pLMConnector, dEnd_x, dEnd_y)
6215
                '                        objInputs.AddPoint(dStart_x, dStart_y)
6216
                '                    End If
6217
                '                End If
6218
                '            Catch ex As Exception
6219
                '            End Try
6220
                '        Else
6221
                '            objInputs.AddPoint(dStart_x, dStart_y)
6222
                '            objInputs.AddPoint(dEnd_x, dEnd_y)
6223
                '        End If
6224
                '        oAddPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
6225
                '    Else
6226
                '        Dim CheckTF As String = oLinerow(_XML_LINE_DRAWING_TF).ToString()
6227
                '        Dim CheckSelect As String = oLinerow(_XML_LINE_Check).ToString()
6228
                '        If CheckTF = "FALSE" And CheckSelect = "TRUE" Then
6229
                '            sPipeUid = oLinerow(_XML_LINE_UID).ToString()
6230
                '            oAddUid_List.Clear()
6231
                '            oAddUid_List.Add(sPipeUid)
6232
                '            sCheckModeling = True
6233
                '            sStartpoint = oLinerow(_XML_LINE_STARTPOINT).ToString()
6234
                '            sEndpoint = oLinerow(_XML_LINE_ENDPOINT).ToString()
6235
                '            ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
6236
                '            dStart_x = dOriginalStart_x
6237
                '            dStart_y = dOriginalStart_y
6238
                '            ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
6239
                '            dEnd_x = dOriginalEnd_x
6240
                '            dEnd_y = dOriginalEnd_y
6241
                '            ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
6242
                '            ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
6243
                '            Dim sBranchType As String = ""
6244
                '            If (CheckBranchLine(oLine_Dt, dStart_x, dStart_y, dEnd_x, dEnd_y, sBranchType, pLMConnector)) Then
6245
                '                Try
6246
                '                    If sBranchType = "1" Then
6247
                '                        objInputs.AddPoint(dEnd_x, dEnd_y)
6248
                '                        objInputs.AddConnectorTarget(pLMConnector, dStart_x, dStart_y)
6249
                '                    ElseIf sBranchType = "2" Then
6250
                '                        objInputs.AddPoint(dStart_x, dStart_y)
6251
                '                        objInputs.AddConnectorTarget(pLMConnector, dEnd_x, dEnd_y)
6252
                '                    ElseIf sBranchType = "3" Then
6253
                '                        objInputs.AddPoint(dEnd_x, dEnd_y)
6254
                '                        objInputs.AddConnectorTarget(pLMConnector, dStart_x, dStart_y)
6255
                '                    ElseIf sBranchType = "4" Then
6256
                '                        objInputs.AddPoint(dStart_x, dStart_y)
6257
                '                        objInputs.AddConnectorTarget(pLMConnector, dEnd_x, dEnd_y)
6258
                '                    End If
6259
                '                Catch ex As Exception
6260
6261
                '                End Try
6262
                '            Else
6263
                '                objInputs.AddPoint(dStart_x, dStart_y)
6264
                '                objInputs.AddPoint(dEnd_x, dEnd_y)
6265
                '            End If
6266
                '            oLinerow(_XML_LINE_DRAWING_TF) = "TRUE"
6267
                '        End If
6268
                '    End If
6269
                'Catch ex As Exception
6270
                'End Try
6271
                'If sCheckModeling Then
6272
                '    Dim sType As String = oLinerow(_XML_LINE_TYPE).ToString()
6273
                '    Dim sSystemPath As String = GetPipeType(sType)
6274
                '    objItem = _Placement.PIDCreateItem(sSystemPath)
6275
                '    objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
6276
                '    For i = 0 To oAddUid_List.Count - 1
6277
                '        Dim oUpdateRow As DataRow() = oLine_Dt.Select(_XML_LINE_UID & " = '" + oAddUid_List(i) + "'")
6278
                '        If oUpdateRow.Length = 1 Then
6279
                '            oUpdateRow(0)(_XML_LINE_SPID) = objConnector.ModelItemID
6280
                '            oUpdateRow(0)(_XML_LINE_LMCONNECTOR) = objConnector
6281
                '        End If
6282
                '    Next
6283
6284
                '    oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
6285
                '    oAddUid_List.Clear()
6286
6287
                '    Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
6288
                '    If oAttributeRow.Length > 0 Then
6289
                '        For Each oAttribute In oAttributeRow
6290
                '            Try
6291
                '                Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
6292
                '                Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
6293
                '                If sPIDValue.Contains("'") Then
6294
                '                    sPIDValue = sPIDValue.Replace("'", """")
6295
                '                End If
6296
                '                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
6297
                '                oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
6298
                '            Catch ex As Exception
6299
                '            End Try
6300
                '        Next
6301
                '        oPipeRun.Commit()
6302
                '    End If
6303
6304
                '    If pLMConnector IsNot Nothing Then
6305
                '        Dim sID_1 As String = pLMConnector.ModelItemID
6306
                '        Dim sID_2 As String = objConnector.ModelItemID
6307
                '        Dim objSurvivorItem As LMAItem = Nothing
6308
                '        Dim oPipeRun1 As LMPipeRun = oDatasource.GetPipeRun(sID_1)
6309
                '        Dim oPipeRun2 As LMPipeRun = oDatasource.GetPipeRun(sID_2)
6310
                '        _Placement.PIDJoinRuns(oPipeRun1, oPipeRun2)
6311
                '        '     oDatasource.CommitTransaction()
6312
                '        '_Placement.PIDAutoJoin(oPipeRun1.AsLMAItem, AutoJoinEndConstants.autoJoin_End, objSurvivorItem)
6313
                '        'oPipeRun1.Commit()
6314
                '        'oDatasource.CommitTransaction()
6315
                '        'objSurvivorItem = Nothing
6316
                '        '_Placement.PIDAutoJoin(oPipeRun2.AsLMAItem, AutoJoinEndConstants.autoJoin_Start, objSurvivorItem)
6317
                '        'oPipeRun2.Commit()
6318
                '        'oDatasource.CommitTransaction()
6319
                '    End If
6320
                '    sCheckModeling = False
6321
                '  End If
6322
            Next
6323 bb2a0c79 Gyusu
        Catch ex As Exception
6324
        End Try
6325
    End Sub
6326 e4000111 Gyusu
6327 b08338e3 Gyusu
6328
    Private Sub SymbolModeling(ByVal CDrawing As Drawing, ByVal oLine_DT As DataTable, ByVal oSymbolRow As DataRow, ByVal oAttribute_Dt As DataTable,
6329
                               ByVal sLineNoText As String)
6330 bb2a0c79 Gyusu
        Try
6331 b08338e3 Gyusu
6332
            Dim sCheckModeling As String = oSymbolRow(_XML_SYMBOL_DRAWING_TF).ToString()
6333
            If sCheckModeling = "FALSE" Then
6334
                Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID)
6335
                Dim oSymbol As LMSymbol = Nothing
6336
                Dim sSPID As String = oSymbolRow(_XML_SYMBOL_SPID).ToString()
6337
                Dim sSystemPath As String = oSymbolRow(_XML_SYMBOL_SYSTEMPATH).ToString()
6338 bb2a0c79 Gyusu
                Dim oDatasource As Object = _Placement.PIDDataSource
6339
                Dim sSymbolCompType As String = oSymbolRow(_XML_SYMBOL_TYPE).ToString()
6340
                Dim dLocationX As Double = 0.0
6341
                Dim dLocationY As Double = 0.0
6342
                Dim dX As Double = 0.0
6343
                Dim dY As Double = 0.0
6344 b08338e3 Gyusu
                Dim sOriginalPoint As String = oSymbolRow(_XML_SYMBOL_ORIGINALPOINT).ToString()
6345
                ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY)
6346
                dX = dLocationX
6347
                dY = dLocationY
6348
                ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
6349
6350
                Dim dAngle As Double = oSymbolRow(_XML_SYMBOL_ANGLE)
6351
6352
6353
                'Dim oDatarow() As DataRow = oLine_DT.Select("[" & _XML_LINE_Conn1_Uid & "] = '" & sSymbolUid & "'")
6354
                'If oDatarow.Length = 0 Then
6355
                '    oDatarow = oLine_DT.Select("[" & _XML_LINE_Conn2_Uid & "] = '" & sSymbolUid & "'")
6356
                'End If
6357
                'Dim dFix_X As Double = 0.0
6358
                'Dim dFix_Y As Double = 0.0
6359
                'If oDatarow.Length > 0 Then
6360
                '    If dAngle <> 0 Then
6361
                '        sOriginalPoint = oDatarow(0)(_XML_LINE_STARTPOINT).ToString()
6362
                '        ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY)
6363
6364
                '        ConvertPointByImage(dLocationX, dLocationY, _IMG_X, _IMG_Y)
6365
                '        dX = dLocationX
6366
                '    Else
6367
                '        sOriginalPoint = oDatarow(0)(_XML_LINE_STARTPOINT).ToString()
6368
                '        ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY)
6369
                '        ConvertPointByImage(dLocationX, dLocationY, _IMG_X, _IMG_Y)
6370
                '        dY = dLocationY
6371
                '    End If
6372
6373
                'End If
6374
6375
6376
6377
                oSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY,, dAngle)
6378
                SetListBoxItems(ListBox_Result, "Place Fitting.." & sSymbolUid & " (" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
6379
6380
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Fitting : " & sSymbolUid)
6381
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "LineNo : " & sLineNoText)
6382
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection1 : " & oSymbolRow(_XML_SYMBOL_Conn1_Uid).ToString())
6383
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection2 : " & oSymbolRow(_XML_SYMBOL_Conn2_Uid).ToString())
6384
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection3 : " & oSymbolRow(_XML_SYMBOL_Conn3_Uid).ToString())
6385
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection4 : " & oSymbolRow(_XML_SYMBOL_Conn4_Uid).ToString())
6386
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
6387
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "OriginalPoint : " & dLocationX & "," & dLocationY)
6388
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Fitting Count : " & _iFittingcnt)
6389
6390
6391
                _iFittingcnt = _iFittingcnt + 1
6392
                oSymbolRow(_XML_SYMBOL_DRAWING_TF) = "TRUE"
6393
                Dim oAttributeRow() As DataRow
6394
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sSymbolUid + "'")
6395
                If oAttribute_Dt.Rows.Count > 0 Then
6396
6397 bb2a0c79 Gyusu
                    If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
6398 b08338e3 Gyusu
                        Dim oInstrument As LMInstrument
6399
                        oInstrument = oDatasource.GetInstrument(oSymbol.ModelItemID)
6400 bb2a0c79 Gyusu
                        Try
6401
                            If oAttributeRow.Length > 0 Then
6402
                                For Each oAttribute In oAttributeRow
6403
                                    Try
6404
                                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
6405
                                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
6406
                                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
6407
                                        oInstrument.Attributes(sSPPIDAttribute).Value = sPIDValue
6408
                                    Catch ex As Exception
6409
                                    End Try
6410
                                Next
6411
                                oInstrument.Commit()
6412
                            End If
6413
                        Catch ex As Exception
6414
                        End Try
6415
                    Else
6416 b08338e3 Gyusu
                        Try
6417
                            If oAttributeRow.Length > 0 And oSymbol IsNot Nothing Then
6418
                                For Each oAttribute In oAttributeRow
6419
                                    Try
6420
                                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
6421
                                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
6422 e4000111 Gyusu
6423 b08338e3 Gyusu
                                        If sPIDAttribute = "SIZE" Then
6424
6425
                                            'Nominal diamter1,2속성이름뭔지 찾아봐야됨 (2018-07-20)
6426
                                            If sPIDValue.Contains("x") Then
6427
                                                Dim sSplitSize() As String = sPIDValue.Split("x")
6428
                                                If sSplitSize.Count > 1 Then
6429
                                                    'Connection Point와 연결되어 있는 라인을 가져와서 라인프로퍼티를 변경
6430
                                                    Dim oConnector_1 As LMConnector = Nothing
6431
                                                    Dim oConnector_2 As LMConnector = Nothing
6432
                                                    If oSymbol IsNot Nothing Then
6433
                                                        If oSymbol.Connect1Connectors.Count >= 1 Then
6434
                                                            For Each Tconnector In oSymbol.Connect1Connectors
6435
                                                                If Tconnector.ItemStatus = "Active" Then
6436
                                                                    If Tconnector.ModelItemObject.ItemTypeName = "PipeRun" Then
6437
                                                                        oConnector_1 = Tconnector
6438
                                                                    End If
6439
                                                                End If
6440
                                                            Next
6441
                                                        End If
6442
                                                        If oSymbol.Connect1Connectors.Count >= 1 Then
6443
                                                            For Each Tconnector In oSymbol.Connect1Connectors
6444
                                                                If Tconnector.ItemStatus = "Active" Then
6445
                                                                    If Tconnector.ModelItemObject.ItemTypeName = "PipeRun" Then
6446
                                                                        oConnector_2 = Tconnector
6447
                                                                    End If
6448
                                                                End If
6449
                                                            Next
6450
                                                        End If
6451
                                                    End If
6452
                                                    Dim oPipeRun1 As LMPipeRun = oDatasource.GetPipeRun(oConnector_1.ModelItemID)
6453
                                                    Dim oPipeRun2 As LMPipeRun = oDatasource.GetPipeRun(oConnector_2.ModelItemID)
6454
                                                    If dAngle = 3.14 Then
6455
                                                        oPipeRun1.Attributes("NominalDiameter").Value = sSplitSize(1)
6456
                                                        oPipeRun2.Attributes("NominalDiameter").Value = sSplitSize(0)
6457
                                                    Else
6458
                                                        oPipeRun1.Attributes("NominalDiameter").Value = sSplitSize(0)
6459
                                                        oPipeRun2.Attributes("NominalDiameter").Value = sSplitSize(1)
6460
                                                    End If
6461 e4000111 Gyusu
6462
6463 b08338e3 Gyusu
                                                End If
6464 e4000111 Gyusu
6465 b08338e3 Gyusu
                                            Else
6466
                                                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
6467
                                                oSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
6468
                                            End If
6469
                                        Else
6470
                                            Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
6471
                                            oSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
6472
                                        End If
6473 e4000111 Gyusu
6474 b08338e3 Gyusu
                                    Catch ex As Exception
6475
                                    End Try
6476
                                Next
6477
                                oSymbol.Commit()
6478
                            End If
6479
                        Catch ex As Exception
6480
                        End Try
6481
                    End If
6482
                End If
6483 e4000111 Gyusu
6484
6485
6486 b08338e3 Gyusu
            End If
6487 e4000111 Gyusu
6488
6489
6490 b08338e3 Gyusu
            'Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID).ToString()
6491
            'Dim sConnTypeNo As String = ""
6492
            '' Line과 연결되어있는 Symbol인지 확인
6493
            'Dim oLine_Dt As DataTable = GetPipeFromConnection(CDrawing, sSymbolUid, sConnTypeNo)
6494
            ''Symbol과 연결되어 있는 Symbol인지 확인
6495
            'Dim oSymbol_Dt As DataTable = GetSymbolFromConnection(CDrawing, sSymbolUid, sConnTypeNo)
6496
            'Dim oSymbol As LMSymbol = Nothing
6497
            'Dim sSPID As String = oSymbolRow(_XML_SYMBOL_SPID).ToString()
6498
            'Dim sSystemPath As String = oSymbolRow(_XML_SYMBOL_SYSTEMPATH).ToString()
6499
            'Dim oDatasource As Object = _Placement.PIDDataSource
6500
            'Dim sSymbolCompType As String = oSymbolRow(_XML_SYMBOL_TYPE).ToString()
6501 e4000111 Gyusu
6502 b08338e3 Gyusu
            'Dim dAngle As Double = 0.0
6503
            'If IsNumeric(oSymbolRow(_XML_SYMBOL_ANGLE).ToString()) Then
6504
            '    dAngle = Double.Parse(oSymbolRow(_XML_SYMBOL_ANGLE).ToString())
6505
            'End If
6506 e4000111 Gyusu
6507 b08338e3 Gyusu
            'Dim dLocationX As Double = 0.0
6508
            'Dim dLocationY As Double = 0.0
6509
            'Dim dX As Double = 0.0
6510
            'Dim dY As Double = 0.0
6511
            'Dim sOriginalPoint As String = oSymbolRow(_XML_SYMBOL_ORIGINALPOINT).ToString()
6512
            'ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY)
6513
            'dX = dLocationX
6514
            'dY = dLocationY
6515
            'ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
6516
            'Dim bCheckModeling As Boolean = False
6517
6518
            'If oLine_Dt.Rows.Count > 0 Then
6519
6520
            '    If sSPID <> "" Then
6521
            '        Dim dX1 As Double = 0
6522
            '        Dim dX2 As Double = 0
6523
            '        Dim dY1 As Double = 0
6524
            '        Dim dY2 As Double = 0
6525
            '        Dim oLMSymbol As LMSymbol = oDatasource.GetSymbol(sSPID)
6526
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 1, dX1, dY1)
6527
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 2, dX2, dY2)
6528
6529
            '        Dim dCalcPoint As Double = -1
6530
            '        Dim dModeling_X As Double = 0
6531
            '        Dim dModeling_Y As Double = 0
6532
            '        If dX1 <> 0 And dY1 <> 0 Then
6533
            '            dCalcPoint = Math.Abs(dX1 - dX) + Math.Abs(dY1 - dY)
6534
            '            dModeling_X = dX1
6535
            '            dModeling_Y = dY1
6536
            '        End If
6537
            '        If dX2 <> 0 And dY2 <> 0 Then
6538 e4000111 Gyusu
6539 b08338e3 Gyusu
            '            If (Math.Abs(dX2 - dX) + Math.Abs(dY2 - dY) > dCalcPoint) Then
6540
            '                dCalcPoint = Math.Abs(dX2 - dX) + Math.Abs(dY2 - dY)
6541
            '                dModeling_X = dX2
6542
            '                dModeling_Y = dY2
6543
            '            End If
6544
            '        End If
6545 e4000111 Gyusu
6546
6547
6548 b08338e3 Gyusu
            '        If dModeling_X <> 0 And dModeling_Y <> 0 Then
6549
            '            oSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dModeling_X, dModeling_Y,, dAngle, ExistingItem:=oLMSymbol.AsLMAItem,
6550
            '                TargetItem:=oLMSymbol.AsLMRepresentation)
6551
            '            bCheckModeling = True
6552
            '        End If
6553 e4000111 Gyusu
6554
6555 b08338e3 Gyusu
            '    End If
6556
            'End If
6557
            'If oSymbol_Dt.Rows.Count > 0 Then
6558
            '    If sSPID <> "" Then
6559
            '        Dim dX1 As Double = 0
6560
            '        Dim dX2 As Double = 0
6561
            '        Dim dX3 As Double = 0
6562
            '        Dim dX4 As Double = 0
6563
            '        Dim dY1 As Double = 0
6564
            '        Dim dY2 As Double = 0
6565
            '        Dim dY3 As Double = 0
6566
            '        Dim dY4 As Double = 0
6567
            '        Dim oLMSymbol As LMSymbol = oDatasource.GetSymbol(sSPID)
6568
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 1, dX1, dY1)
6569
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 2, dX2, dY2)
6570
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 3, dX3, dY3)
6571
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 4, dX4, dY4)
6572
6573
            '        Dim dCalcPoint As Double = -1
6574
            '        Dim dModeling_X As Double = 0
6575
            '        Dim dModeling_Y As Double = 0
6576
            '        If dX1 <> 0 And dY1 <> 0 Then
6577
            '            dCalcPoint = Math.Abs(dX1 - dX) + Math.Abs(dY1 - dY)
6578
            '            dModeling_X = dX1
6579
            '            dModeling_Y = dY1
6580
            '        End If
6581
            '        If dX2 <> 0 And dY2 <> 0 Then
6582 41e4023e Gyusu
6583 b08338e3 Gyusu
            '            If (Math.Abs(dX2 - dX) + Math.Abs(dY2 - dY) > dCalcPoint) Then
6584
            '                dCalcPoint = Math.Abs(dX2 - dX) + Math.Abs(dY2 - dY)
6585
            '                dModeling_X = dX2
6586
            '                dModeling_Y = dY2
6587
            '            End If
6588
            '        End If
6589
            '        If dX3 <> 0 And dY3 <> 0 Then
6590
            '            If (Math.Abs(dX3 - dX) + Math.Abs(dY3 - dY) > dCalcPoint) Then
6591
            '                dCalcPoint = Math.Abs(dX3 - dX) + Math.Abs(dY3 - dY)
6592
            '                dModeling_X = dX3
6593
            '                dModeling_Y = dY3
6594
            '            End If
6595
            '        End If
6596
            '        If dX4 <> 0 And dY4 <> 0 Then
6597
            '            If (Math.Abs(dX4 - dX) + Math.Abs(dY4 - dY) > dCalcPoint) Then
6598
            '                dCalcPoint = Math.Abs(dX4 - dX) + Math.Abs(dY4 - dY)
6599
            '                dModeling_X = dX4
6600
            '                dModeling_Y = dY4
6601
            '            End If
6602
            '        End If
6603
            '        If dModeling_X <> 0 And dModeling_Y <> 0 Then
6604
            '            oSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dModeling_X, dModeling_Y,, dAngle, ExistingItem:=oLMSymbol.AsLMAItem,
6605
            '                TargetItem:=oLMSymbol.AsLMRepresentation)
6606
            '            bCheckModeling = True
6607
            '        End If
6608 41e4023e Gyusu
6609 e4000111 Gyusu
6610 b08338e3 Gyusu
            '    End If
6611 e4000111 Gyusu
6612 b08338e3 Gyusu
            'End If
6613 e4000111 Gyusu
6614 b08338e3 Gyusu
            'If (oLine_Dt.Rows.Count = 0 And oSymbol_Dt.Rows.Count = 0) Or bCheckModeling = False Then
6615
            '    oSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
6616
            '    SetListBoxItems(ListBox_Result, "Place Fittings..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
6617
            '    _iFittingcnt = _iFittingcnt + 1
6618
            'End If
6619
            'Dim oAttributeRow() As DataRow
6620
            'oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sSymbolUid + "'")
6621
            'If oAttribute_Dt.Rows.Count > 0 Then
6622
6623
            '    If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
6624
            '        Dim oInstrument As LMInstrument
6625
            '        oInstrument = oDatasource.GetInstrument(oSymbol.ModelItemID)
6626
            '        Try
6627
            '            If oAttributeRow.Length > 0 Then
6628
            '                For Each oAttribute In oAttributeRow
6629
            '                    Try
6630
            '                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
6631
            '                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
6632
            '                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
6633
            '                        oInstrument.Attributes(sSPPIDAttribute).Value = sPIDValue
6634
            '                    Catch ex As Exception
6635
            '                    End Try
6636
            '                Next
6637
            '                oInstrument.Commit()
6638
            '            End If
6639
            '        Catch ex As Exception
6640
            '        End Try
6641
            '    Else
6642
            '        Try
6643
            '            If oAttributeRow.Length > 0 And oSymbol IsNot Nothing Then
6644
            '                For Each oAttribute In oAttributeRow
6645
            '                    Try
6646
            '                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
6647
            '                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
6648
6649
            '                        If sPIDAttribute = "SIZE" Then
6650
6651
            '                            'Nominal diamter1,2속성이름뭔지 찾아봐야됨 (2018-07-20)
6652
            '                            If sPIDValue.Contains("x") Then
6653
            '                                Dim sSplitSize() As String = sPIDValue.Split("x")
6654
            '                                If sSplitSize.Count > 1 Then
6655
            '                                    'Connection Point와 연결되어 있는 라인을 가져와서 라인프로퍼티를 변경
6656
            '                                    Dim oConnector_1 As LMConnector = Nothing
6657
            '                                    Dim oConnector_2 As LMConnector = Nothing
6658
            '                                    If oSymbol IsNot Nothing Then
6659
            '                                        If oSymbol.Connect1Connectors.Count >= 1 Then
6660
            '                                            For Each Tconnector In oSymbol.Connect1Connectors
6661
            '                                                If Tconnector.ItemStatus = "Active" Then
6662
            '                                                    If Tconnector.ModelItemObject.ItemTypeName = "PipeRun" Then
6663
            '                                                        oConnector_1 = Tconnector
6664
            '                                                    End If
6665
            '                                                End If
6666
            '                                            Next
6667
            '                                        End If
6668
            '                                        If oSymbol.Connect1Connectors.Count >= 1 Then
6669
            '                                            For Each Tconnector In oSymbol.Connect1Connectors
6670
            '                                                If Tconnector.ItemStatus = "Active" Then
6671
            '                                                    If Tconnector.ModelItemObject.ItemTypeName = "PipeRun" Then
6672
            '                                                        oConnector_2 = Tconnector
6673
            '                                                    End If
6674
            '                                                End If
6675
            '                                            Next
6676
            '                                        End If
6677
            '                                    End If
6678
            '                                    Dim oPipeRun1 As LMPipeRun = oDatasource.GetPipeRun(oConnector_1.ModelItemID)
6679
            '                                    Dim oPipeRun2 As LMPipeRun = oDatasource.GetPipeRun(oConnector_2.ModelItemID)
6680
            '                                    If dAngle = 3.14 Then
6681
            '                                        oPipeRun1.Attributes("NominalDiameter").Value = sSplitSize(1)
6682
            '                                        oPipeRun2.Attributes("NominalDiameter").Value = sSplitSize(0)
6683
            '                                    Else
6684
            '                                        oPipeRun1.Attributes("NominalDiameter").Value = sSplitSize(0)
6685
            '                                        oPipeRun2.Attributes("NominalDiameter").Value = sSplitSize(1)
6686
            '                                    End If
6687
6688
6689
            '                                End If
6690
6691
            '                            Else
6692
            '                                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
6693
            '                                oSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
6694
            '                            End If
6695
            '                        Else
6696
            '                            Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
6697
            '                            oSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
6698
            '                        End If
6699
6700
            '                    Catch ex As Exception
6701
            '                    End Try
6702
            '                Next
6703
            '                oSymbol.Commit()
6704
            '            End If
6705
            '        Catch ex As Exception
6706
            '        End Try
6707
            '    End If
6708
            'End If
6709
        Catch ex As Exception
6710
        End Try
6711
    End Sub
6712 e4000111 Gyusu
6713
6714
6715
    Private Function AutoModeling() As Boolean
6716
        Try
6717 e38f99a7 Gyusu
            '_AllLine_DT = Line_Dt()
6718
            '_AllSymbol_DT = Symbol_Dt()
6719 79326880 Gyusu
            _ModelingLine_Dt = Line_Dt()
6720 e38f99a7 Gyusu
            _ModelingSymbol_Dt = Symbol_Dt()
6721 e4000111 Gyusu
            _CompleteConvert = False
6722
            Label_Progress.Text = "0%"
6723
            SetListBoxItems(ListBox_Result, " Auto converting 시작....")
6724 b08338e3 Gyusu
            ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, " Auto converting 시작....")
6725 e4000111 Gyusu
            Dim oDwg_Dt As DataTable = LoadAllDrawing()
6726 b08338e3 Gyusu
            _Log_File = "AutoConverting_" + DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.ToString("HHmmss")
6727 e4000111 Gyusu
            _allItem = GetAllCheckNodeCount()
6728 76f465d0 Gyusu
            _Itemcnt = 0
6729 e4000111 Gyusu
            '1.Equipment
6730
            '2.Piping OPC
6731
            '3.OPC 시작되는 Line
6732 e6ef24be gaqhf
6733 7e561f5b gaqhf
            'InitAutoRouting()
6734
            'EquipmentModeling(oDwg_Dt)
6735
            'PipingModeling()
6736
6737 1406fef4 gaqhf
            '' 1. Primary Line만 먼저 그림
6738 7e561f5b gaqhf
            PrimaryPipeModeling()
6739 1406fef4 gaqhf
            '' 2. Draw Symbols Prinmary에 붙는 Symbol만 / Reducer 제외
6740
6741
6742
6743
6744
6745
6746 bb2a0c79 Gyusu
6747
            '   PipeLine_Fitting_Modeling()
6748 e4000111 Gyusu
6749 171ac39d Gyusu
            SetProgressbar(ProgressBar_Status, 100)
6750 41e4023e Gyusu
            Label_Progress.Text = "100%"
6751 171ac39d Gyusu
            SetListBoxItems(ListBox_Result, " Auto converting 완료")
6752 b08338e3 Gyusu
            ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, " Auto converting 완료")
6753 54b98e09 Gyusu
            _CompleteConvert = True
6754 171ac39d Gyusu
            Return True
6755
        Catch ex As Exception
6756
            Return False
6757
        End Try
6758
    End Function
6759
6760
6761
6762 54b98e09 Gyusu
    Private Sub ThreadConvert()
6763 559daf6d Gyusu
        If _DrawingsList IsNot Nothing Then
6764
            If _DrawingsList.Count > 0 Then
6765 b82166d4 Gyusu
                'TestBranchLine()
6766 559daf6d Gyusu
                AutoModeling()
6767
            End If
6768 171ac39d Gyusu
        End If
6769 e282643f Gyusu
    End Sub
6770
6771 54b98e09 Gyusu
    Private Sub ThreadOPCRemove()
6772
        While _CompleteConvert = False
6773
            Dim oFindOPC As New FindOpc
6774
            oFindOPC.RemoveOPCDlg()
6775
        End While
6776 e282643f Gyusu
6777 54b98e09 Gyusu
    End Sub
6778 171ac39d Gyusu
6779 e282643f Gyusu
6780
    Private Function OpenDrawing(ByVal oDt As DataTable, ByVal sDwgName As String) As String
6781
        Dim oRows As DataRow() = oDt.Select("[Name] = '" & sDwgName & "'")
6782
        Dim oPath As String = ""
6783
        If oRows.Length > 0 Then
6784
            oPath = oRows(0).Item("Path").ToString()
6785
        End If
6786
        Return oPath
6787
    End Function
6788
6789 272662f9 Gyusu
    Private Sub LoadXmlToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LoadXmlToolStripMenuItem.Click
6790 3b7a4470 Gyusu
6791 171ac39d Gyusu
        If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
6792 54b98e09 Gyusu
            LoadDB()
6793 171ac39d Gyusu
            LoadXmlItem(FolderBrowserDialog1.SelectedPath)
6794
        End If
6795
    End Sub
6796
    Private Sub LoadXmlItem(ByVal sFolderPath As String)
6797
        _DrawingsList = New List(Of Drawing)
6798
        Dim sfileEntries As String() = Directory.GetFiles(sFolderPath)
6799
        If Tree_Result.Nodes.Count > 0 Then
6800
            Tree_Result.Nodes(0).Nodes.Clear()
6801
            For Each sfileName In sfileEntries
6802
                Dim sExtension As String = Path.GetExtension(sfileName)
6803
                If sExtension = ".xml" Then
6804
                    Dim sDwgName As String = Path.GetFileNameWithoutExtension(sfileName)
6805
                    Dim sDwgPath As String = sfileName
6806
                    Dim oNode As TreeNode = Tree_Result.Nodes(0).Nodes.Add(sDwgPath, sDwgName, 15)
6807
                    Dim oDwg As Drawing = AddSymbolItem(sDwgPath, oNode)
6808 bb2a0c79 Gyusu
6809 171ac39d Gyusu
                    _DrawingsList.Add(oDwg)
6810
                End If
6811
            Next
6812
            Tree_Result.Nodes(0).Expand()
6813
        End If
6814
    End Sub
6815 272662f9 Gyusu
6816 e4000111 Gyusu
    Private Sub GenerateRelation(ByRef oDwg_Ds As Drawing)
6817
        Dim oLineLists As List(Of Line_no) = oDwg_Ds.Line_nos
6818
        Dim oEqpLists As List(Of Eqp_no) = oDwg_Ds.Eqp_nos
6819
        Dim oTrimLineLists As List(Of Line_no) = oDwg_Ds.TrimLine_nos
6820
        Dim oRelation As New GenerateRelation()
6821
        For Each oLinelist In oLineLists
6822 bb2a0c79 Gyusu
            oRelation.CalcLineConnectionItem_Equal(oLinelist.Dt_Line, oLineLists)
6823
            oRelation.CalcLineConnectionItem_NonEqual(oLinelist.Dt_Line, oLineLists)
6824
            oRelation.CalcSymbolConnectionItem_Equal(oLinelist.Dt_Symbol, oLineLists)
6825
            oRelation.CalcSymbolConnectionItem_NonEqual(oLinelist.Dt_Symbol, oLineLists)
6826 e4000111 Gyusu
        Next
6827
    End Sub
6828
6829 e6ef24be gaqhf
    Private Sub SetSymbol_LineNumberByUID(ByVal symbols As List(Of Symbol), ByVal lineNumber As LineNumber, ByVal uid As String)
6830
        For Each symbol As Symbol In symbols
6831
            If symbol.UID = uid Then
6832
                symbol.LINENUMBER = lineNumber
6833
                Exit For
6834
            End If
6835
        Next
6836
    End Sub
6837
6838
    Private Sub SetLine_LineNumberByUID(ByVal lines As List(Of Line), ByVal lineNumber As LineNumber, ByVal uid As String)
6839
        For Each line As Line In lines
6840
            If line.UID = uid Then
6841
                line.LINENUMBER = lineNumber
6842
                Exit For
6843
            End If
6844
        Next
6845
    End Sub
6846 e4000111 Gyusu
6847 20c84e05 Gyusu
    ''' <summary>
6848
    '''  XML Tree 구조 생성 
6849
    ''' </summary>
6850
    ''' <param name="sDwgPath"></param>
6851 171ac39d Gyusu
    Private Function AddSymbolItem(ByVal sDwgPath As String, ByVal oParentNode As TreeNode) As Drawing
6852
        Dim oDwg_Ds As Drawing = LoadSymbolInXml(sDwgPath)
6853 e4000111 Gyusu
6854 54b98e09 Gyusu
        If oDwg_Ds IsNot Nothing Then
6855
6856 e6ef24be gaqhf
            Dim oLineNos As List(Of LineNumber) = oDwg_Ds.LINENUMBERS
6857 3acffcee Gyusu
6858 e6ef24be gaqhf
            Dim oTrimLines As List(Of LineNumber) = oDwg_Ds.TRIMLINES
6859 3acffcee Gyusu
6860 e6ef24be gaqhf
            Dim oSymbols As List(Of Symbol) = oDwg_Ds.SYMBOLS
6861 54b98e09 Gyusu
6862 e6ef24be gaqhf
            Dim oLines As List(Of Line) = oDwg_Ds.LINES
6863 9c86a823 Gyusu
6864 e6ef24be gaqhf
            '' TreeView 구성 및 하위 아이템 상위 구성
6865
            ' LIne Number
6866
            For Each lineNo As LineNumber In oLineNos
6867 7e561f5b gaqhf
                Dim node As TreeNode = New TreeNode(lineNo.UID)
6868
                node.Name = lineNo.UID
6869
                node.Tag = lineNo
6870
6871
                oParentNode.Nodes.Add(node)
6872 9c86a823 Gyusu
6873 e6ef24be gaqhf
                For Each uid In lineNo.SYMBOLRUNITEMS
6874
                    SetSymbol_LineNumberByUID(oSymbols, lineNo, uid)
6875 54b98e09 Gyusu
                Next
6876 9c86a823 Gyusu
6877 e6ef24be gaqhf
                For Each uid In lineNo.LINERUNITEMS
6878
                    SetLine_LineNumberByUID(oLines, lineNo, uid)
6879 54b98e09 Gyusu
                Next
6880
            Next
6881 3acffcee Gyusu
6882 e6ef24be gaqhf
            ' Trim Line
6883
            For index = 0 To oTrimLines.Count - 1
6884
                Dim trimLine As LineNumber = oTrimLines(index)
6885 7e561f5b gaqhf
6886
                Dim node As TreeNode = New TreeNode("TrimLine" + index.ToString)
6887
                node.Name = trimLine.UID
6888
                node.Tag = trimLine
6889
6890
                oParentNode.Nodes.Add(node)
6891 d039e347 Gyusu
6892 e6ef24be gaqhf
                For Each uid In trimLine.SYMBOLRUNITEMS
6893
                    SetSymbol_LineNumberByUID(oSymbols, trimLine, uid)
6894
                Next
6895 54b98e09 Gyusu
6896 e6ef24be gaqhf
                For Each uid In trimLine.LINERUNITEMS
6897
                    SetLine_LineNumberByUID(oLines, trimLine, uid)
6898 54b98e09 Gyusu
                Next
6899 171ac39d Gyusu
            Next
6900 e6ef24be gaqhf
            ' symbol
6901
            For Each symbol As Symbol In oSymbols
6902 7e561f5b gaqhf
6903
                Dim node As TreeNode = New TreeNode(symbol.TYPE)
6904
                node.Name = symbol.UID
6905
                node.Tag = symbol
6906
6907 e6ef24be gaqhf
                If symbol.LINENUMBER IsNot Nothing Then
6908
                    Dim nodeIndex As Integer = oParentNode.Nodes.IndexOfKey(symbol.LINENUMBER.UID)
6909 7e561f5b gaqhf
                    oParentNode.Nodes.Item(nodeIndex).Nodes.Add(node)
6910 e6ef24be gaqhf
                Else
6911 7e561f5b gaqhf
                    oParentNode.Nodes.Add(node)
6912 e6ef24be gaqhf
                End If
6913
            Next
6914
            ' line
6915
            For Each line As Line In oLines
6916 7e561f5b gaqhf
6917
                Dim node As TreeNode = New TreeNode(line.TYPE)
6918
                node.Name = line.UID
6919
                node.Tag = line
6920
6921 e6ef24be gaqhf
                If line.LINENUMBER IsNot Nothing Then
6922
                    Dim nodeIndex As Integer = oParentNode.Nodes.IndexOfKey(line.LINENUMBER.UID)
6923 7e561f5b gaqhf
                    oParentNode.Nodes.Item(nodeIndex).Nodes.Add(node)
6924 e6ef24be gaqhf
                Else
6925 7e561f5b gaqhf
                    oParentNode.Nodes.Add(node)
6926 e6ef24be gaqhf
                End If
6927 3acffcee Gyusu
            Next
6928
6929 54b98e09 Gyusu
        End If
6930
6931 171ac39d Gyusu
        Return oDwg_Ds
6932
    End Function
6933 272662f9 Gyusu
    Private Sub Tree_Result_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles Tree_Result.AfterCheck
6934
        If e.Node.Checked = True Then
6935
            For Each oNode As TreeNode In e.Node.Nodes
6936
                oNode.Checked = True
6937
            Next
6938
        Else
6939
            For Each oNode As TreeNode In e.Node.Nodes
6940
                oNode.Checked = False
6941
            Next
6942
        End If
6943
    End Sub
6944 171ac39d Gyusu
6945 559daf6d Gyusu
    Private Sub Btn_Setting_Click(sender As Object, e As EventArgs) Handles Btn_Setting.Click
6946
        Dim oSettings As Settings = New Settings()
6947
        oSettings.ShowDialog()
6948
    End Sub
6949 42c0013c Gyusu
6950 b82166d4 Gyusu
6951
    Private Sub TestBranchLine()
6952
        Dim objPlacement As Placement
6953
        objPlacement = New Placement
6954
        Dim PipeRunLocation As String
6955
        Dim objItem As LMAItem
6956
        Dim objConnector As LMConnector
6957
        Dim objInputs As PlaceRunInputs
6958
        Dim objSymbol As LMSymbol
6959
        Dim ValveLocation As String
6960
        PipeRunLocation = "\Piping\Routing\Process Lines\Primary Piping.sym"
6961
        objInputs = New PlaceRunInputs
6962
        objInputs.AddPoint(0.1, 0.1)
6963
        objInputs.AddPoint(0.2, 0.1)
6964
        objItem = objPlacement.PIDCreateItem(PipeRunLocation)
6965
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
6966
        ValveLocation = "\Piping\Valves\2 Way Common\Ball Valve.sym"
6967
        objSymbol = objPlacement.PIDPlaceSymbol(ValveLocation, 0.15, 0.3, , 1.57)
6968
        objInputs = New PlaceRunInputs
6969
        objInputs.AddConnectorTarget(objConnector, 0.15, 0.1)
6970
        '   objInputs.AddConnectorTarget(objConnector, 0.12, 0.1)
6971
        objInputs.AddPoint(0.15, 0.15)
6972
        objInputs.AddPoint(0.12, 0.15)
6973
        objInputs.AddPoint(0.12, 0.2)
6974
        objInputs.AddPoint(0.15, 0.2)
6975
        objInputs.AddSymbolTarget(objSymbol, 0.15, 0.3)
6976
        objItem = objPlacement.PIDCreateItem(PipeRunLocation)
6977
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
6978
6979
        objInputs = New PlaceRunInputs
6980
        objInputs.AddConnectorTarget(objConnector, 0.17, 0.1)
6981
        objInputs.AddPoint(0.17, 0.15)
6982
        objItem = objPlacement.PIDCreateItem(PipeRunLocation)
6983
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
6984
6985
        objInputs = New PlaceRunInputs
6986
        objInputs.AddConnectorTarget(objConnector, 0.19, 0.1)
6987
        objInputs.AddPoint(0.19, 0.15)
6988
        objItem = objPlacement.PIDCreateItem(PipeRunLocation)
6989
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
6990
6991
        objInputs = New PlaceRunInputs
6992
        objInputs.AddConnectorTarget(objConnector, 0.12, 0.1)
6993
        objInputs.AddPoint(0.12, 0.15)
6994
        objItem = objPlacement.PIDCreateItem(PipeRunLocation)
6995
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
6996
    End Sub
6997
6998 42c0013c Gyusu
    Private Sub Btn_TestNozzle_Click(sender As Object, e As EventArgs) Handles Btn_TestNozzle.Click
6999
7000
        Dim sVessel_ID As String = "841D5E640AE5421B9A017DDC2E87FF11"
7001
        Dim objVessel As LMVessel
7002
        objVessel = _Placement.PIDDataSource.GetVessel(sVessel_ID)
7003
        Dim oVesselLocation As LMLocations = objVessel.Locations
7004
        Dim symVessel As LMSymbol = _Placement.PIDDataSource.GetSymbol(objVessel.Representations.Nth(1).Id)
7005
        Dim XCoordinate As String = symVessel.Attributes("XCoordinate").Value
7006
        Dim YCoordinate As String = symVessel.Attributes("YCoordinate").Value
7007
        symVessel.Attributes("XCoordinate").Value = XCoordinate + 0.01
7008
        symVessel.Attributes("YCoordinate").Value = YCoordinate + 0.01
7009
        symVessel.Commit()
7010
        Dim sValve_ID As String = "DB7B0CA8A2664A6BA7A9615764BA62B0"
7011
        Dim objValve As LMSymbol
7012
        Dim objValves As LMPipingComp = _Placement.PIDDataSource.GetPipingComp(sValve_ID)
7013
        objValve = _Placement.PIDDataSource.GetSymbol(objValves.Representations.Nth(1).Id)
7014
        objValve.Commit()
7015
        Dim dVesselX As Double = XCoordinate
7016
        Dim dVesselY As Double = YCoordinate
7017
        Dim X1 As Double, Y1 As Double, X2 As Double, Y2 As Double
7018
7019
        _Placement.PIDConnectPointLocation(objValve, 1, X1, Y1)
7020
7021
        _Placement.PIDConnectPointLocation(objValve, 2, X2, Y2)
7022
7023
        Dim nozzlename As String = "\Equipment Components\Nozzles\Flanged Nozzle.sym"
7024
        Dim dCalc_x As Double = 0
7025
        Dim dCalc_y As Double = 0
7026
7027
        If dVesselX - X2 > 0 Then
7028
            dCalc_x = dVesselX - (dVesselX - X2)
7029
        Else
7030
            dCalc_x = dVesselX + (X2 - dVesselX)
7031
        End If
7032
        If dVesselY - Y2 > 0 Then
7033
            dCalc_y = dVesselY - (dVesselY - Y2)
7034
        Else
7035
            dCalc_y = dVesselY + (Y2 - dVesselY)
7036
        End If
7037
7038
        Dim objNozzle As LMSymbol = _Placement.PIDPlaceSymbol(nozzlename, dCalc_x, dCalc_y,
7039
            TargetItem:=symVessel.AsLMRepresentation)
7040
7041
        Dim blnSuccess As Boolean = _Placement.PIDConnectPointLocation(objNozzle, 1, X1, Y1)
7042
        blnSuccess = _Placement.PIDConnectPointLocation(objNozzle, 2, X1, Y1)
7043
7044
        objValve = _Placement.PIDPlaceSymbol(objValve.FileName, X1, Y1, ExistingItem:=objValve.AsLMAItem,
7045
          TargetItem:=objNozzle.AsLMRepresentation)
7046
7047
7048
7049
    End Sub
7050 39d43554 Gyusu
7051
    Private Sub Btn_SymbolLibrary_Click(sender As Object, e As EventArgs) Handles Btn_SymbolLibrary.Click
7052
        Dim oMapping As New Mapping(_PIDSymbol_DB)
7053
        oMapping.Show()
7054
    End Sub
7055 41e4023e Gyusu
7056
    Private Sub Btn_Stop_Click(sender As Object, e As EventArgs) Handles Btn_Stop.Click
7057
        Try
7058
            SetListBoxItems(ListBox_Result, " Auto converting 중지....")
7059 b08338e3 Gyusu
            ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, " Auto converting 중지....")
7060 41e4023e Gyusu
            _Main_trd.Abort()
7061
            _Opc_trd.Abort()
7062
        Catch ex As Exception
7063
7064
        End Try
7065
    End Sub
7066 b08338e3 Gyusu
7067
    Private Sub AutoCheckTreeNode(ByVal iType As Integer, ByVal bCheck As Boolean)
7068
7069
        For Each oDrwing As TreeNode In Tree_Result.Nodes
7070
            For Each oDwgNode As TreeNode In oDrwing.Nodes
7071
                Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
7072
                Dim CDrawing As Drawing = GetDrawing(sDwgName)
7073
                If CDrawing IsNot Nothing Then
7074
                    Dim iAllLineNoCount As Integer = Tree_Result.Nodes.Count ' GetCheckNodeCount(oLinenoNode)
7075
                    Dim iPipingOPC_count As Integer = 0 ' GetCheckNodeCount(oLinenoNode)
7076
                    For Each oNode As TreeNode In oDwgNode.Nodes
7077
                        Dim iItemcnt As Integer = 0
7078
                        Dim sNodeUid As String = oNode.Name
7079
                        Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
7080
7081
                        If iType = 0 Then 'Symbol
7082
                            Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
7083
                            If CLineNo IsNot Nothing Then
7084
                                Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
7085
                                For Each oSymbolRow In oSymbol_Dt.Rows
7086
                                    Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID).ToString()
7087
                                    For Each oSymbolNode As TreeNode In oNode.Nodes
7088
                                        Dim sSymbolNodeUid As String = oSymbolNode.Name
7089
                                        If sSymbolNodeUid = sSymbolUid Then
7090
                                            oSymbolNode.Checked = bCheck
7091
                                            Exit For
7092
                                        End If
7093
                                    Next
7094
                                Next
7095
                            End If
7096
                            Dim TrimLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
7097
                            If TrimLineNo IsNot Nothing Then
7098
                                Dim oSymbol_Dt As DataTable = TrimLineNo.Dt_Symbol
7099
                                For Each oSymbolRow In oSymbol_Dt.Rows
7100
                                    Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID).ToString()
7101
                                    For Each oSymbolNode As TreeNode In oNode.Nodes
7102
                                        Dim sSymbolNodeUid As String = oSymbolNode.Name
7103
                                        If sSymbolNodeUid = sSymbolUid Then
7104
                                            oSymbolNode.Checked = bCheck
7105
                                            Exit For
7106
                                        End If
7107
                                    Next
7108
                                Next
7109
                            End If
7110
                        End If
7111
                        If iType = 1 Then 'Line
7112
                            Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
7113
                            If CLineNo IsNot Nothing Then
7114
                                Dim oLine_Dt As DataTable = CLineNo.Dt_Line
7115
                                For Each oLineRow In oLine_Dt.Rows
7116
                                    Dim sLineUid As String = oLineRow(_XML_LINE_UID).ToString()
7117
                                    For Each oLineNode As TreeNode In oNode.Nodes
7118
                                        Dim sLineNodeUid As String = oLineNode.Name
7119
                                        If sLineNodeUid = sLineUid Then
7120
                                            oLineNode.Checked = bCheck
7121
                                            Exit For
7122
                                        End If
7123
                                    Next
7124
                                Next
7125
                            End If
7126
                            Dim TrimLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
7127
                            If TrimLineNo IsNot Nothing Then
7128
                                Dim oLine_Dt As DataTable = TrimLineNo.Dt_Line
7129
                                For Each oLineRow In oLine_Dt.Rows
7130
                                    Dim sLineUid As String = oLineRow(_XML_SYMBOL_UID).ToString()
7131
                                    For Each oLineNode As TreeNode In oNode.Nodes
7132
                                        Dim sLineNodeUid As String = oLineNode.Name
7133
                                        If sLineNodeUid = sLineUid Then
7134
                                            oLineNode.Checked = bCheck
7135
                                            Exit For
7136
                                        End If
7137
                                    Next
7138
                                Next
7139
                            End If
7140
                        End If
7141
                        If iType = 2 Then 'Equipment
7142
                            Dim CEqpNo As Eqp_no = GetEqpNo(CDrawing, sNodeUid)
7143
                            If CEqpNo IsNot Nothing Then
7144
                                Dim oEqp_Dt As DataTable = CEqpNo.Dt_Equipment
7145
                                For Each oEqpRow In oEqp_Dt.Rows
7146
                                    Dim sEqpUid As String = oEqpRow(_XML_LINE_UID).ToString()
7147
                                    For Each oEqpNode As TreeNode In oNode.Nodes
7148
                                        Dim sEqpNodeUid As String = oEqpNode.Name
7149
                                        If sEqpNodeUid = sEqpUid Then
7150
                                            oEqpNode.Checked = bCheck
7151
                                            Exit For
7152
                                        End If
7153
                                    Next
7154
                                Next
7155
                            End If
7156
                        End If
7157
                    Next
7158
                End If
7159
            Next
7160
        Next
7161
7162
7163
    End Sub
7164
7165
7166
7167
    Private Sub Chk_Symbol_CheckedChanged(sender As Object, e As EventArgs) Handles Chk_Symbol.CheckedChanged
7168
        AutoCheckTreeNode(0, Chk_Symbol.Checked)
7169
    End Sub
7170
7171
    Private Sub Chk_Line_CheckedChanged(sender As Object, e As EventArgs) Handles Chk_Line.CheckedChanged
7172
        AutoCheckTreeNode(1, Chk_Line.Checked)
7173
    End Sub
7174
7175
    Private Sub Chk_Equipment_CheckedChanged(sender As Object, e As EventArgs) Handles Chk_Equipment.CheckedChanged
7176
        AutoCheckTreeNode(2, Chk_Equipment.Checked)
7177
    End Sub
7178 e282643f Gyusu
End Class
7179
7180
7181
Public Class DrawingInfo
7182
    Public mDrawingName As String
7183
    Public mSpID As String
7184
    Public mPath As String
7185 4f359afa Gyusu
End Class
7186 e282643f Gyusu
7187
7188
7189
클립보드 이미지 추가 (최대 크기: 500 MB)