프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / Main.vb @ 59e764f3

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