프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / Main.vb @ 94092f45

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