프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / Main.vb @ 9133d5d8

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

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

    
8
Imports System.Threading
9

    
10
Public Class Main
11
    'Dim _Mapping_DB As DataTable = New DataTable()
12
    Public _Mapping_DB As DataSet = New DataSet()
13
    Dim _Attribute_DB As DataTable = New DataTable()
14
    Dim _PIDSymbol_DB As DataTable = New DataTable()
15
    Dim _ResultModeling_DT As DataTable = New DataTable()
16
    Dim _AllLine_DT As New DataTable()
17
    Dim _AllSymbol_DT As New DataTable()
18
    Dim _ModelingLine_Dt As New DataTable()
19
    Dim _ModelingSymbol_Dt As New DataTable()
20
    Dim _Placement As New Placement
21
    Dim _DWG_X = 0.875 '0.695 '1 '
22
    Dim _DWG_Y = 0.617 '0.585 '0.8 '
23
    'Dim _DWG_X = 0.842 '0.695 '1 '
24
    'Dim _DWG_Y = 0.614 '0.585 '0.8 '
25
    Public _IMG_X = 0
26
    Public _IMG_Y = 0
27
    Dim _Unit As String
28
    'Drawing 전역변수
29
    Dim _objPIDADrawing As Object
30
    '현재선택한 폴더경로
31
    Dim _selectFolderPath As String
32
    Private _Main_trd As Thread
33
    Private _Opc_trd As Thread
34
    Private _CompleteConvert As Boolean = False
35
    Private _DrawingsList As List(Of Drawing)
36
    Private _iPipeLineNocnt As Integer
37
    Private _iPipecnt As Integer
38
    Private _iFittingcnt As Integer
39
    Private _iValvecnt As Integer
40
    Private _iInstrumentcnt As Integer
41
    Private _iEquipmentcnt As Integer
42
    Private _iNozzlecnt As Integer
43
    Private _iPipintOpccnt As Integer
44
    Private _allItem As Integer
45
    Private _Itemcnt As Integer
46
    Dim _Gembox As New CGembox()
47

    
48
    Dim PipeRunPoint As Dictionary(Of String, List(Of PointdInfo)) = New Dictionary(Of String, List(Of PointdInfo))
49

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

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

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

    
71
    Public Function GetDataFromMappingDB(ByVal sSymbolName As String, ByVal sColumn As String) As String
72
        Dim sValue As String = ""
73

    
74
        'Debug.WriteLine(_Mapping_DB.Tables.Count)
75

    
76
        For Each oDt As DataTable In _Mapping_DB.Tables
77
            If oDt.Rows.Count > 0 Then
78
                Dim oSelectRow() As DataRow = oDt.Select("[Img_symbolname] = '" + sSymbolName + "'")
79
                If oSelectRow.Length = 1 Then
80
                    If sColumn = _DB_COLUMN_MAPPING_SPPID_SYMBOLNAME Then
81
                        sValue = oSelectRow(0).Item("SYM FILE NAME").ToString()
82
                    ElseIf sColumn = _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH Then
83
                        sValue = "\" & oSelectRow(0).Item("SYMBOL PATH").ToString() & "\" & oSelectRow(0).Item("SYM FILE NAME").ToString()
84
                    ElseIf sColumn = _DB_COLUMN_MAPPING_SPPID_COMPTPYE Then
85
                        sValue = oSelectRow(0).Item("ITEM TYPE").ToString()
86
                    ElseIf sColumn = _DB_COLUMN_MAPPING_SPPID_CLASS Then
87
                        sValue = oSelectRow(0).Item("CLASS").ToString()
88
                    Else
89
                        sValue = oSelectRow(0).Item("SYMBOL PATH").ToString() & "\" & oSelectRow(0).Item("SYM FILE NAME").ToString()
90
                    End If
91
                End If
92
            End If
93
        Next
94
        Return sValue
95
    End Function
96

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

    
108

    
109

    
110
    Private Function LoadSymbolInXml(ByVal sXmlPath As String) As Drawing
111
        Try
112
            ''  _TempSymbolDt = Symbol_Dt()
113
            Dim CDrawing As Drawing = New Drawing()
114
            '     Dim oDt As DataTable = LoadSymbol_DT()
115
            Dim oElement As XElement = XElement.Load(sXmlPath)
116
            If oElement IsNot Nothing Then
117
                CDrawing.DwgName = oElement.Element(_XML_DWGNAME).Value
118
                CDrawing.Size = oElement.Element(_XML_DWGSIZE).Value
119
                SplitLocation(CDrawing.Size, _IMG_X, _IMG_Y)
120

    
121
                CDrawing.LINES = LoadLines(oElement)
122
                CDrawing.SYMBOLS = LoadSymbols(oElement)
123
                CDrawing.LINENUMBERS = LoadLineNumbers(oElement)
124
                CDrawing.TRIMLINES = LoadTrimLines(oElement)
125
                CDrawing.TEXTS = LoadTexts(oElement)
126
            End If
127
            Return CDrawing
128
        Catch ex As Exception
129
            Return Nothing
130
        End Try
131

    
132
    End Function
133

    
134
    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
135

    
136
        Dim sReturnUid As String = ""
137
        Try
138
            Dim oFindLineRow As DataRow() = oLine_Dt.Select(
139
            "[" & _XML_LINE_DWG_STARTPOINT_X & "] >= '" & dPos_x - 0.001 & "' And " &
140
            "[" & _XML_LINE_DWG_STARTPOINT_X & "] <= '" & dPos_x + 0.001 & "' And " &
141
            "[" & _XML_LINE_DWG_STARTPOINT_Y & "] >= '" & dPos_y - 0.001 & "' And " &
142
            "[" & _XML_LINE_DWG_STARTPOINT_Y & "] <= '" & dPos_y + 0.001 & "' And " &
143
            "[" & _XML_LINE_UID & "] <> '" & sUid & "' And " &
144
            "[" & _XML_LINE_Conn1_Uid & "] = ''")
145
            If oFindLineRow.Length = 0 Then
146
                oFindLineRow = oLine_Dt.Select(
147
                "[" & _XML_LINE_DWG_ENDPOINT_X & "] >= '" & dPos_x - 0.001 & "' And " &
148
                "[" & _XML_LINE_DWG_ENDPOINT_X & "] <= '" & dPos_x + 0.001 & "' And " &
149
                "[" & _XML_LINE_DWG_ENDPOINT_Y & "] >= '" & dPos_y - 0.001 & "' And " &
150
                "[" & _XML_LINE_DWG_ENDPOINT_Y & "] <= '" & dPos_y + 0.001 & "' And " &
151
                "[" & _XML_LINE_UID & "] <> '" & sUid & "' And " &
152
                "[" & _XML_LINE_Conn2_Uid & "] = ''")
153
                If oFindLineRow.Length = 0 Then
154
                    oFindLineRow = oSymbol_Dt.Select(
155
              "[" & _XML_SYMBOL_DWG_CONN1_POINT_X & "] >= '" & dPos_x - 0.001 & "' And " &
156
              "[" & _XML_SYMBOL_DWG_CONN1_POINT_X & "] <= '" & dPos_x + 0.001 & "' And " &
157
              "[" & _XML_SYMBOL_DWG_CONN1_POINT_Y & "] >= '" & dPos_y - 0.001 & "' And " &
158
              "[" & _XML_SYMBOL_DWG_CONN1_POINT_Y & "] <= '" & dPos_y + 0.001 & "' And " &
159
              "[" & _XML_SYMBOL_UID & "] <> '" & sUid & "' And " &
160
              "[" & _XML_SYMBOL_Conn1_Uid & "] = ''")
161
                    If oFindLineRow.Length = 0 Then
162
                        oFindLineRow = oSymbol_Dt.Select(
163
                   "[" & _XML_SYMBOL_DWG_CONN2_POINT_X & "] >= '" & dPos_x - 0.001 & "' And " &
164
                   "[" & _XML_SYMBOL_DWG_CONN2_POINT_X & "] <= '" & dPos_x + 0.001 & "' And " &
165
                   "[" & _XML_SYMBOL_DWG_CONN2_POINT_Y & "] >= '" & dPos_y - 0.001 & "' And " &
166
                   "[" & _XML_SYMBOL_DWG_CONN2_POINT_Y & "] <= '" & dPos_y + 0.001 & "' And " &
167
                   "[" & _XML_SYMBOL_UID & "] <> '" & sUid & "' And " &
168
                   "[" & _XML_SYMBOL_Conn2_Uid & "] = ''")
169
                        If oFindLineRow.Length = 0 Then
170
                        Else
171
                            oFindLineRow(0)(_XML_SYMBOL_Conn2_Uid) = sUid
172
                            sReturnUid = oFindLineRow(0)(_XML_SYMBOL_UID).ToString()
173
                        End If
174
                    Else
175
                        oFindLineRow(0)(_XML_SYMBOL_Conn1_Uid) = sUid
176
                        sReturnUid = oFindLineRow(0)(_XML_SYMBOL_UID).ToString()
177
                    End If
178
                Else
179
                    oFindLineRow(0)(_XML_LINE_Conn2_Uid) = sUid
180
                    sReturnUid = oFindLineRow(0)(_XML_LINE_UID).ToString()
181
                End If
182
            Else
183
                oFindLineRow(0)(_XML_LINE_Conn1_Uid) = sUid
184
                sReturnUid = oFindLineRow(0)(_XML_LINE_UID).ToString()
185
            End If
186
        Catch ex As Exception
187

    
188
        End Try
189

    
190
        Return sReturnUid
191
    End Function
192

    
193

    
194
    Private Function SetConnectionInfo(ByRef oLine_Dt As DataTable, ByRef oSymbol_Dt As DataTable)
195
        Try
196
            For Each oLineInfo In oLine_Dt.Rows
197
                Dim sLineUid As String = oLineInfo(_XML_LINE_UID).ToString()
198
                Dim dStartPos_x As Double = oLineInfo(_XML_LINE_DWG_STARTPOINT_X)
199
                Dim dStartPos_y As Double = oLineInfo(_XML_LINE_DWG_STARTPOINT_Y)
200
                Dim dEndPos_x As Double = oLineInfo(_XML_LINE_DWG_ENDPOINT_X)
201
                Dim dEndPos_y As Double = oLineInfo(_XML_LINE_DWG_ENDPOINT_Y)
202
                Dim sConn1Uid As String = ""
203
                Dim sConn2Uid As String = ""
204
                sConn1Uid = FindConnection(oLine_Dt, oSymbol_Dt, sLineUid, dStartPos_x, dStartPos_y)
205
                If sConn1Uid <> "" Then
206
                    oLineInfo(_XML_LINE_Conn1_Uid) = sConn1Uid
207
                End If
208
                sConn2Uid = FindConnection(oLine_Dt, oSymbol_Dt, sLineUid, dEndPos_x, dEndPos_y)
209
                If sConn2Uid <> "" Then
210
                    oLineInfo(_XML_LINE_Conn2_Uid) = sConn2Uid
211
                End If
212
            Next
213
            For Each oSymbolInfo In oSymbol_Dt.Rows
214
                Dim sSymbolUid As String = oSymbolInfo(_XML_SYMBOL_UID).ToString()
215
                Dim dConn1Pos_x As Double = oSymbolInfo(_XML_SYMBOL_DWG_CONN1_POINT_X)
216
                Dim dConn1Pos_y As Double = oSymbolInfo(_XML_SYMBOL_DWG_CONN1_POINT_Y)
217
                Dim sConn1Uid As String = ""
218
                Dim sConn2Uid As String = ""
219
                sConn1Uid = FindConnection(oLine_Dt, oSymbol_Dt, sSymbolUid, dConn1Pos_x, dConn1Pos_y)
220
                If sConn1Uid <> "" Then
221
                    oSymbolInfo(_XML_SYMBOL_Conn1_Uid) = sConn1Uid
222
                End If
223
                Try
224
                    Dim dConn2Pos_x As Double = oSymbolInfo(_XML_SYMBOL_DWG_CONN2_POINT_X)
225
                    Dim dConn2Pos_y As Double = oSymbolInfo(_XML_SYMBOL_DWG_CONN2_POINT_Y)
226
                    sConn2Uid = FindConnection(oLine_Dt, oSymbol_Dt, sSymbolUid, dConn2Pos_x, dConn2Pos_y)
227
                    If sConn2Uid <> "" Then
228
                        oSymbolInfo(_XML_SYMBOL_Conn2_Uid) = sConn2Uid
229
                    End If
230
                Catch ex As Exception
231
                End Try
232
            Next
233
        Catch ex As Exception
234
        End Try
235
    End Function
236

    
237
    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
238
        Dim bValidLine As Boolean = True
239
        If Math.Abs(dStart_x - dEnd_x) > Math.Abs(dStart_y - dEnd_y) Then
240
            If dStart_x > dEnd_x Then
241
                sDirection = "X"
242
                sFlowdirection = "Left_x"
243
                If Math.Abs(dStart_y - dEnd_y) < 5 Then
244
                    dEnd_y = dStart_y
245
                End If
246
            Else
247
                sDirection = "X"
248
                sFlowdirection = "Right_x"
249
                If Math.Abs(dStart_y - dEnd_y) < 5 Then
250
                    dEnd_y = dStart_y
251
                End If
252
            End If
253
            If Math.Abs(dStart_x - dEnd_x) <= 15 Then
254
                bValidLine = False
255
            End If
256
        Else
257
            If dStart_y > dEnd_y Then
258
                sDirection = "Y"
259
                sFlowdirection = "Down_y"
260
                If Math.Abs(dStart_x - dEnd_x) < 5 Then
261
                    dEnd_x = dStart_x
262
                End If
263

    
264
            Else
265
                sDirection = "Y"
266
                sFlowdirection = "Up_y"
267
                If Math.Abs(dStart_x - dEnd_x) < 5 Then
268
                    dEnd_x = dStart_x
269
                End If
270
            End If
271
            If Math.Abs(dStart_y - dEnd_y) <= 20 Then
272
                bValidLine = False
273
            End If
274
        End If
275
        Return bValidLine
276
    End Function
277

    
278
    Private Function LoadLines(ByVal oElement As XElement) As List(Of Line)
279
        Dim result As List(Of Line) = New List(Of Line)
280

    
281
        Dim lineInfos As XElement = oElement.Element(_XML_LINEINFOS)
282

    
283
        For Each oLine As XElement In lineInfos.Elements(_XML_LINEINFOS_LINE)
284
            Dim _line As Line = New Line()
285
            Try
286
                _line.UID = oLine.Element(_XML_LINEINFOS_LINE_UID).Value
287
                _line.STARTPOINT = oLine.Element(_XML_LINEINFOS_LINE_STARTPOINT).Value
288
                _line.ENDPOINT = oLine.Element(_XML_LINEINFOS_LINE_ENDPOINT).Value
289
                _line.TYPE = oLine.Element(_XML_LINEINFOS_LINE_TYPE).Value
290
                _line.AREA = oLine.Element(_XML_LINEINFOS_LINE_AREA).Value
291
                _line.CONNECTORS = GetConnector(oLine)
292
                _line.SPPIDMAPPINGNAME = GetPipeType(_line.TYPE)
293

    
294
                _line.AfterSetting()
295

    
296
                result.Add(_line)
297
            Catch ex As Exception
298
                Console.WriteLine(ex.Message)
299
            End Try
300
        Next
301

    
302
        Return result
303
    End Function
304

    
305
    Private Function LoadSymbols(ByVal oElement As XElement) As List(Of Symbol)
306
        Dim result As List(Of Symbol) = New List(Of Symbol)
307

    
308
        Dim symbols As XElement = oElement.Element(_XML_SYMBOLS)
309

    
310
        For Each oSymbol As XElement In symbols.Elements(_XML_SYMBOLS_SYMBOL)
311
            Dim _symbol As Symbol = New Symbol()
312
            Try
313
                _symbol.ANGLE = oSymbol.Element(_XML_SYMBOLS_SYMBOL_ANGLE).Value
314
                _symbol.UID = oSymbol.Element(_XML_SYMBOLS_SYMBOL_UID).Value
315
                _symbol.NAME = oSymbol.Element(_XML_SYMBOLS_SYMBOL_NAME).Value
316
                _symbol.TYPE = oSymbol.Element(_XML_SYMBOLS_SYMBOL_TYPE).Value
317
                _symbol.ORIGINALPOINT = oSymbol.Element(_XML_SYMBOLS_SYMBOL_ORIGINALPOINT).Value
318
                _symbol.CONNECTORS = GetConnector(oSymbol)
319
                _symbol.LOCATION = oSymbol.Element(_XML_SYMBOLS_SYMBOL_LOCATION).Value
320
                _symbol.SIZE = oSymbol.Element(_XML_SYMBOLS_SYMBOL_SIZE).Value
321
                _symbol.PARENT = oSymbol.Element(_XML_SYMBOLS_SYMBOL_PARENT).Value
322
                Dim strChild As String = oSymbol.Element(_XML_SYMBOLS_SYMBOL_CHILD).Value
323
                Dim arrChild As String() = strChild.Split("/")
324
                For Each _child As String In arrChild
325
                    Dim info As String() = _child.Split(",")
326
                    Dim childMappingName = GetDataFromMappingDB(info(1), _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
327
                    If String.IsNullOrEmpty(childMappingName) = False Then
328
                        _symbol.CHILD.Add(info(0) + "," + childMappingName)
329
                    Else
330
                        Console.WriteLine("Mapping Fail : " + info(1))
331
                    End If
332
                Next
333
                _symbol.HASINSTRUMENTLABEL = oSymbol.Element(_XML_SYMBOLS_SYMBOL_HASINSTRUMENTLABEL).Value
334
                _symbol.AREA = oSymbol.Element(_XML_SYMBOLS_SYMBOL_AREA).Value
335
                _symbol.CURRENTPOINTMODEINDEX = oSymbol.Element(_XML_SYMBOLS_SYMBOL_CURRENTPOINTMODEINDEX).Value
336
                _symbol.SPPIDMAPPINGNAME = GetDataFromMappingDB(_symbol.PARENT, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
337

    
338
                _symbol.AfterSetting()
339

    
340
                result.Add(_symbol)
341
            Catch ex As Exception
342
                Console.WriteLine(ex.Message)
343
            End Try
344
        Next
345

    
346
        Return result
347
    End Function
348

    
349
    Private Function LoadLineNumbers(ByVal oElement As XElement) As List(Of LineNumber)
350
        Dim result As List(Of LineNumber) = New List(Of LineNumber)
351

    
352
        Dim lineNos As XElement = oElement.Element(_XML_LINENOS)
353

    
354
        For Each oLineNo As XElement In lineNos.Elements(_XML_LINENOS_LINENO)
355
            Dim _lineNo As LineNumber = New LineNumber()
356
            Try
357
                _lineNo.UID = oLineNo.Element(_XML_LINEINFOS_LINE_UID).Value
358
                _lineNo.ANGLE = oLineNo.Element("ANGLE").Value
359
                _lineNo.TEXT = oLineNo.Element("TEXT").Value
360
                _lineNo.SYMBOLRUNITEMS = GetSymbolRunItems(oLineNo)
361
                _lineNo.LINERUNITEMS = GetLineRunItems(oLineNo)
362
                If oLineNo.Element("CONNLINE") IsNot Nothing Then
363
                    _lineNo.CONNECTLINE = oLineNo.Element("CONNLINE").Value
364
                End If
365
                _lineNo.LOCATION = oLineNo.Element("LOCATION").Value
366

    
367
                Console.WriteLine("임시 Line Number Labeling and Attribute")
368
                _lineNo.SPPIDMAPPINGNAME = "\Piping\Labels - Piping Segments\Line Number.sym"
369

    
370
                For Each attrElement As XElement In oLineNo.Elements("ATTRIBUTE")
371
                    Dim attr As Attribute = New Attribute()
372
                    attr.UID = attrElement.Attribute("UID").Value
373
                    attr.NAME = attrElement.Attribute("DisplayAttribute").Value.Replace(" ", "")
374
                    If attrElement.Value <> "None" Then
375
                        attr.VALUE = attrElement.Value
376
                    Else
377
                        attr.VALUE = ""
378
                    End If
379
                    _lineNo.ATTRIBUTES.Add(attr)
380
                Next
381

    
382
                _lineNo.AfterSetting()
383

    
384
                result.Add(_lineNo)
385
            Catch ex As Exception
386
                Console.WriteLine(ex.Message)
387
            End Try
388
        Next
389

    
390
        Return result
391
    End Function
392

    
393
    Private Function LoadTrimLines(ByVal oElement As XElement) As List(Of LineNumber)
394
        Dim result As List(Of LineNumber) = New List(Of LineNumber)
395

    
396
        Dim trimNos As XElement = oElement.Element(_XML_TRIMLINENOS)
397

    
398
        For Each oTrimLine As XElement In trimNos.Elements(_XML_TRIMLINENOS_TRIM_LINE_NO)
399
            Dim _lineNo As LineNumber = New LineNumber()
400
            Try
401
                _lineNo.UID = oTrimLine.Element(_XML_LINEINFOS_LINE_UID).Value
402

    
403
                _lineNo.SYMBOLRUNITEMS = GetSymbolRunItems(oTrimLine)
404
                _lineNo.LINERUNITEMS = GetLineRunItems(oTrimLine)
405

    
406
                result.Add(_lineNo)
407
            Catch ex As Exception
408

    
409
            End Try
410
        Next
411

    
412
        Return result
413
    End Function
414

    
415
    Private Function LoadTexts(ByVal oElement As XElement) As List(Of Text)
416
        Dim result As List(Of Text) = New List(Of Text)
417

    
418
        Dim textInfos As XElement = oElement.Element(_XML_TEXTINFOS)
419

    
420
        For Each oText As XElement In textInfos.Elements("ATTRIBUTE")
421
            Dim _text As Text = New Text()
422
            Try
423
                _text.UID = oText.Element("UID").Value
424
                _text.NAME = oText.Element("NAME").Value
425
                _text.LOCATION = oText.Element("LOCATION").Value
426
                _text.TEXT = oText.Element("VALUE").Value
427
                _text.ANGLE = oText.Element("ANGLE").Value
428
                _text.AREA = oText.Element("AREA").Value
429

    
430
                If oText.Element("OWNER") IsNot Nothing Then
431
                    _text.OWNER = oText.Element("OWNER").Value
432
                End If
433

    
434
                Console.WriteLine("임시 Text Labeling")
435
                If _text.NAME = "TEXT" Then
436
                    _text.SPPIDMAPPINGNAME = "\Design\Annotation\Labels\Drawing Notes Label.sym"
437
                ElseIf _text.NAME = "SIZE" Then
438
                    '_text.SPPIDMAPPINGNAME = "\Piping\Labels - Piping Components\Nominal Diameter.sym"
439
                End If
440

    
441

    
442
                _text.AfterSetting()
443

    
444
                result.Add(_text)
445
            Catch ex As Exception
446
                Console.WriteLine(ex.Message)
447
            End Try
448
        Next
449

    
450
        Return result
451
    End Function
452

    
453
    Private Function GetSymbolRunItems(ByVal oElement As XElement) As List(Of String)
454
        Dim result As List(Of String) = New List(Of String)
455
        Dim oRun As XElement = oElement.Element(_XML_RUN)
456
        If oRun IsNot Nothing Then
457
            For Each oSymbol As XElement In oRun.Elements(_XML_RUN_SYMBOL)
458
                result.Add(oSymbol.Element(_XML_SYMBOLS_SYMBOL_UID))
459
            Next
460
        End If
461
        Return result
462
    End Function
463

    
464
    Private Function GetLineRunItems(ByVal oElement As XElement) As List(Of String)
465
        Dim result As List(Of String) = New List(Of String)
466
        Dim oRun As XElement = oElement.Element(_XML_RUN)
467
        If oRun IsNot Nothing Then
468
            For Each oLine As XElement In oRun.Elements(_XML_RUN_LINE)
469
                result.Add(oLine.Element(_XML_LINEINFOS_LINE_UID))
470
            Next
471
        End If
472
        Return result
473
    End Function
474

    
475

    
476

    
477
    Private Function GetConnector(ByVal oElement As XElement) As List(Of Connector)
478
        Dim result As List(Of Connector) = New List(Of Connector)
479
        Dim oElementConnectors As XElement = oElement.Element(_XML_CONNECTORS)
480
        For Each oConnector As XElement In oElementConnectors.Elements(_XML_CONNECTORS_CONNECTOR)
481
            Dim _connector As Connector = New Connector()
482
            Try
483
                _connector.CONNECTEDITEM = oConnector.Element(_XML_CONNECTORS_CONNECTOR_CONNECTEDITEM).Value
484
                _connector.CONNECTPOINT = oConnector.Element(_XML_CONNECTORS_CONNECTOR_CONNECTPOINT).Value
485
                _connector.SCENECONNECTPOINT = oConnector.Element(_XML_CONNECTORS_CONNECTOR_SCENECONNECTPOINT).Value
486
                result.Add(_connector)
487
            Catch ex As Exception
488
            End Try
489
        Next
490

    
491
        Return result
492
    End Function
493

    
494
    Private Function LoadLineNo(ByVal oElement As XElement, ByVal sLineType As String) As List(Of Line_no)
495

    
496
        Dim oLineno_list As New List(Of Line_no)
497
        For Each oLineNo As Object In oElement.Elements(sLineType)
498
            Dim CLineNo As Line_no = New Line_no()
499
            Try
500
                CLineNo.Uid = oLineNo.Element(_XML_LINENO_UID).Value
501
                CLineNo.Text = oLineNo.Element(_XML_LINENO_TEXT).Value
502
                CLineNo.Location = oLineNo.Element(_XML_LINENO_LOCATION).Value
503
                CLineNo.Angle = oLineNo.Element(_XML_LINENO_ANGLE).Value
504
                CLineNo.SystemPath = "\Piping\Labels - Piping Segments\Kemya Line Number.sym" 'GetDataFromMappingDB(_XML_CATEGORY_LINENO, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
505
            Catch ex As Exception
506
            End Try
507
            Dim oLine_Dt As DataTable = Line_Dt()
508
            Dim oSymbol_Dt As DataTable = Symbol_Dt()
509
            Dim oAttribute_Dt As DataTable = Attribute_Dt()
510
            Dim iRunCnt As Integer = 0
511
            For Each oRun As Object In oLineNo.Elements(_XML_CATEGORY_RUN)
512
                iRunCnt = iRunCnt + 1
513
                Dim sRunName As String = CLineNo.Text & "_" & iRunCnt
514
                For Each oMERGEDLine As Object In oRun.Elements(_XML_CATEGORY_MERGEDLINE)
515
                    For Each oLine As Object In oMERGEDLine.Elements(_XML_CATEGORY_LINE)
516
                        Try
517
                            Dim oAddrow As DataRow = oLine_Dt.NewRow()
518
                            Dim oEleObj As XElement
519
                            Dim sUid As String
520
                            Dim sStartpoint As String
521
                            Dim sEndpoint As String
522
                            Dim sType As String
523
                            Dim sConnectionUids As String = ""
524
                            Dim dStartPos_x As Double = 0.0
525
                            Dim dStartPos_y As Double = 0.0
526
                            Dim dEndPos_x As Double = 0.0
527
                            Dim dEndPos_y As Double = 0.0
528
                            Dim dDWG_StartPos_x As Double = 0.0
529
                            Dim dDWG_StartPos_y As Double = 0.0
530
                            Dim dDWG_EndPos_x As Double = 0.0
531
                            Dim dDWG_EndPos_y As Double = 0.0
532
                            oEleObj = oLine.Element(_XML_LINE_UID)
533
                            sUid = oEleObj.Value
534

    
535
                            If oLine_Dt.Select(_XML_LINE_UID & "='" & sUid & "'").Length = 0 Then
536
                                oEleObj = oLine.Element(_XML_LINE_STARTPOINT)
537
                                sStartpoint = oEleObj.Value
538
                                oEleObj = oLine.Element(_XML_LINE_ENDPOINT)
539
                                sEndpoint = oEleObj.Value
540
                                oEleObj = oLine.Element(_XML_LINE_TYPE)
541
                                sType = oEleObj.Value
542

    
543
                                oAddrow(_XML_LINE_Conn1_Uid) = ""
544
                                oAddrow(_XML_LINE_Conn2_Uid) = ""
545
                                oAddrow(_XML_LINE_UID) = sUid
546
                                oAddrow(_XML_LINE_RUNNAME) = sRunName
547
                                oAddrow(_XML_LINE_LINENOUID) = CLineNo.Uid
548
                                oAddrow(_XML_LINENO_TEXT) = CLineNo.Text
549
                                oAddrow(_XML_LINE_STARTPOINT) = sStartpoint
550
                                oAddrow(_XML_LINE_ENDPOINT) = sEndpoint
551
                                If sUid = "0bda520b-9c01-4dc1-9ddd-73adb5f7a871" Then
552
                                    MsgBox("")
553
                                End If
554
                                ConvertPointBystring(sStartpoint, dStartPos_x, dStartPos_y)
555
                                ConvertPointBystring(sEndpoint, dEndPos_x, dEndPos_y)
556
                                Dim sDirection As String = ""
557
                                Dim sFlowDirection As String = ""
558
                                Dim bValidLine As Boolean = GetFlowDirection(dStartPos_x, dStartPos_y, dEndPos_x, dEndPos_y, sDirection, sFlowDirection)
559
                                oAddrow(_XML_LINE_FlowDirection) = sFlowDirection
560
                                oAddrow(_XML_LINE_Direction) = sDirection
561
                                oAddrow(_XML_LINE_ValieLine) = bValidLine
562
                                dDWG_StartPos_x = dStartPos_x
563
                                dDWG_StartPos_y = dStartPos_y
564
                                ConvertPointByImage(dDWG_StartPos_x, dDWG_StartPos_y, _IMG_X, _IMG_Y)
565
                                dDWG_EndPos_x = dEndPos_x
566
                                dDWG_EndPos_y = dEndPos_y
567
                                ConvertPointByImage(dDWG_EndPos_x, dDWG_EndPos_y, _IMG_X, _IMG_Y)
568

    
569
                                oAddrow(_XML_LINE_STARTPOINT_X) = dStartPos_x
570
                                oAddrow(_XML_LINE_STARTPOINT_Y) = dStartPos_y
571
                                oAddrow(_XML_LINE_ENDPOINT_X) = dEndPos_x
572
                                oAddrow(_XML_LINE_ENDPOINT_Y) = dEndPos_y
573

    
574
                                oAddrow(_XML_LINE_DWG_STARTPOINT_X) = dDWG_StartPos_x
575
                                oAddrow(_XML_LINE_DWG_STARTPOINT_Y) = dDWG_StartPos_y
576
                                oAddrow(_XML_LINE_DWG_ENDPOINT_X) = dDWG_EndPos_x
577
                                oAddrow(_XML_LINE_DWG_ENDPOINT_Y) = dDWG_EndPos_y
578

    
579
                                oAddrow(_XML_LINE_SYSTEMPATH) = GetDataFromMappingDB(_XML_CATEGORY_LINE, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
580
                                If oAddrow(_XML_LINE_SYSTEMPATH) = "" Then
581
                                    MessageBox.Show("")
582
                                End If
583
                                oAddrow(_XML_LINE_DRAWING_TF) = "FALSE"
584
                                oAddrow(_XML_LINE_TYPE) = sType
585
                                '  _AllLine_DT.Rows.Add(oAddrow)
586
                                oLine_Dt.Rows.Add(oAddrow)
587
                            Else
588
                            End If
589
                        Catch ex As Exception
590
                        End Try
591
                    Next
592
                Next
593

    
594
                For Each oSymbol As Object In oRun.Elements(_XML_CATEGORY_SYMBOL)
595
                    Try
596

    
597
                        Dim oAddrow As DataRow = oSymbol_Dt.NewRow()
598
                        Dim oEleObj As XElement
599
                        Dim sUid As String
600
                        Dim sName As String
601
                        Dim sLocation As String
602
                        Dim sSize As String
603
                        Dim sAngle As String
604
                        Dim sOriginalPoint As String = ""
605
                        Dim sConnectionPoint As String = ""
606
                        Dim sConnectionUids As String = ""
607
                        Dim sConnArray As String()
608
                        Dim sSizeArray As String()
609
                        Dim sLocationArray As String()
610
                        Dim sChild As String = ""
611
                        Dim dCenterPos_x As Double = 0.0
612
                        Dim dCenterPos_y As Double = 0.0
613
                        Dim dDwgCenterPos_x As Double = 0.0
614
                        Dim dDwgCenterPos_y As Double = 0.0
615

    
616
                        Dim dConn1Pos_x As Double = 0.0
617
                        Dim dConn1Pos_y As Double = 0.0
618
                        Dim dConn2Pos_x As Double = 0.0
619
                        Dim dConn2Pos_y As Double = 0.0
620
                        Dim dConn3Pos_x As Double = 0.0
621
                        Dim dConn3Pos_y As Double = 0.0
622
                        Dim dConn4Pos_x As Double = 0.0
623
                        Dim dConn4Pos_y As Double = 0.0
624

    
625
                        Dim dDwg_Conn1Pos_x As Double = 0.0
626
                        Dim dDwg_Conn1Pos_y As Double = 0.0
627
                        Dim dDwg_Conn2Pos_x As Double = 0.0
628
                        Dim dDwg_Conn2Pos_y As Double = 0.0
629
                        Dim dDwg_Conn3Pos_x As Double = 0.0
630
                        Dim dDwg_Conn3Pos_y As Double = 0.0
631
                        Dim dDwg_Conn4Pos_x As Double = 0.0
632
                        Dim dDwg_Conn4Pos_y As Double = 0.0
633

    
634
                        oEleObj = oSymbol.Element(_XML_SYMBOL_UID)
635
                        sUid = oEleObj.Value
636
                        oEleObj = oSymbol.Element(_XML_SYMBOL_PARENT)
637
                        sName = oEleObj.Value
638
                        oEleObj = oSymbol.Element(_XML_SYMBOL_LOCATION)
639
                        sLocation = oEleObj.Value
640
                        oEleObj = oSymbol.Element(_XML_SYMBOL_SIZE)
641
                        sSize = oEleObj.Value
642
                        oEleObj = oSymbol.Element(_XML_SYMBOL_ANGLE)
643
                        sAngle = oEleObj.Value
644
                        oEleObj = oSymbol.Element(_XML_SYMBOL_CONNECTIONPOINT)
645
                        sConnectionPoint = oEleObj.Value
646
                        oEleObj = oSymbol.Element(_XML_SYMBOL_CHILD)
647
                        sChild = oEleObj.Value
648
                        Try
649
                            oEleObj = oSymbol.Element(_XML_SYMBOL_ORIGINALPOINT)
650
                            sOriginalPoint = oEleObj.Value
651
                        Catch ex As Exception
652

    
653
                        End Try
654
                        'oEleObj = oSymbol.Element(_XML_LINE_CONNS)
655
                        'sConnectionUids = oEleObj.Value
656
                        'sConnArray = sConnectionUids.Split(",")
657
                        'If sConnArray.Length > 4 Then
658
                        '    MessageBox.Show(sConnArray.Length)
659
                        'End If
660
                        'For i = 0 To sConnArray.Length - 1
661
                        '    If i = 0 Then
662
                        '        oAddrow(_XML_SYMBOL_Conn1_Uid) = sConnArray(i)
663
                        '    ElseIf i = 1 Then
664
                        '        oAddrow(_XML_SYMBOL_Conn2_Uid) = sConnArray(i)
665
                        '    ElseIf i = 2 Then
666
                        '        oAddrow(_XML_SYMBOL_Conn3_Uid) = sConnArray(i)
667
                        '    ElseIf i = 3 Then
668
                        '        oAddrow(_XML_SYMBOL_Conn4_Uid) = sConnArray(i)
669
                        '    End If
670
                        'Next
671
                        oAddrow(_XML_SYMBOL_Conn1_Uid) = ""
672
                        oAddrow(_XML_SYMBOL_Conn2_Uid) = ""
673
                        oAddrow(_XML_SYMBOL_Conn3_Uid) = ""
674
                        oAddrow(_XML_SYMBOL_Conn4_Uid) = ""
675
                        ConvertPointBystring(sOriginalPoint, dCenterPos_x, dCenterPos_y)
676
                        dDwgCenterPos_x = dCenterPos_x
677
                        dDwgCenterPos_y = dCenterPos_y
678
                        ConvertPointByImage(dDwgCenterPos_x, dDwgCenterPos_y, _IMG_X, _IMG_Y)
679

    
680
                        oAddrow(_XML_SYMBOL_CENTERPOINT_X) = dCenterPos_x
681
                        oAddrow(_XML_SYMBOL_CENTERPOINT_Y) = dCenterPos_y
682
                        oAddrow(_XML_SYMBOL_DWG_CENTERPOINT_X) = dDwgCenterPos_x
683
                        oAddrow(_XML_SYMBOL_DWG_CENTERPOINT_Y) = dDwgCenterPos_y
684
                        sConnArray = sConnectionPoint.Split("/")
685
                        sSizeArray = sSize.Split(",")
686
                        sLocationArray = sLocation.Split(",")
687
                        If sConnArray.Length > 4 Then
688
                            MessageBox.Show(sConnArray.Length)
689
                        End If
690
                        For i = 0 To sConnArray.Length - 1
691
                            If i = 0 Then
692
                                oAddrow(_XML_SYMBOL_Conn1_Point) = sConnArray(i)
693
                                ConvertPointBystring(sConnArray(i), dConn1Pos_x, dConn1Pos_y)
694
                                dDwg_Conn1Pos_x = dConn1Pos_x
695
                                dDwg_Conn1Pos_y = dConn1Pos_y
696
                                ConvertPointByImage(dDwg_Conn1Pos_x, dDwg_Conn1Pos_y, _IMG_X, _IMG_Y)
697

    
698
                                oAddrow(_XML_SYMBOL_CONN1_POINT_X) = dConn1Pos_x
699
                                oAddrow(_XML_SYMBOL_CONN1_POINT_Y) = dConn1Pos_y
700
                                oAddrow(_XML_SYMBOL_DWG_CONN1_POINT_X) = dDwg_Conn1Pos_x
701
                                oAddrow(_XML_SYMBOL_DWG_CONN1_POINT_Y) = dDwg_Conn1Pos_y
702
                            ElseIf i = 1 Then
703
                                oAddrow(_XML_SYMBOL_Conn2_Point) = sConnArray(i)
704
                                ConvertPointBystring(sConnArray(i), dConn2Pos_x, dConn2Pos_y)
705
                                dDwg_Conn2Pos_x = dConn2Pos_x
706
                                dDwg_Conn2Pos_y = dConn2Pos_y
707
                                ConvertPointByImage(dDwg_Conn2Pos_x, dDwg_Conn2Pos_y, _IMG_X, _IMG_Y)
708
                                oAddrow(_XML_SYMBOL_CONN2_POINT_X) = dConn2Pos_x
709
                                oAddrow(_XML_SYMBOL_CONN2_POINT_Y) = dConn2Pos_y
710
                                oAddrow(_XML_SYMBOL_DWG_CONN2_POINT_X) = dDwg_Conn2Pos_x
711
                                oAddrow(_XML_SYMBOL_DWG_CONN2_POINT_Y) = dDwg_Conn2Pos_y
712
                            ElseIf i = 2 Then
713
                                oAddrow(_XML_SYMBOL_Conn3_Point) = sConnArray(i)
714
                                ConvertPointBystring(sConnArray(i), dConn3Pos_x, dConn3Pos_y)
715
                                dDwg_Conn3Pos_x = dConn3Pos_x
716
                                dDwg_Conn3Pos_y = dConn3Pos_y
717
                                ConvertPointByImage(dDwg_Conn3Pos_x, dDwg_Conn3Pos_y, _IMG_X, _IMG_Y)
718
                                oAddrow(_XML_SYMBOL_CONN3_POINT_X) = dConn3Pos_x
719
                                oAddrow(_XML_SYMBOL_CONN3_POINT_Y) = dConn3Pos_y
720
                                oAddrow(_XML_SYMBOL_DWG_CONN3_POINT_X) = dDwg_Conn3Pos_x
721
                                oAddrow(_XML_SYMBOL_DWG_CONN3_POINT_Y) = dDwg_Conn3Pos_y
722
                            ElseIf i = 3 Then
723
                                oAddrow(_XML_SYMBOL_Conn4_Point) = sConnArray(i)
724
                                ConvertPointBystring(sConnArray(i), dConn4Pos_x, dConn4Pos_y)
725
                                dDwg_Conn4Pos_x = dConn4Pos_x
726
                                dDwg_Conn4Pos_y = dConn4Pos_y
727
                                ConvertPointByImage(dDwg_Conn4Pos_x, dDwg_Conn4Pos_y, _IMG_X, _IMG_Y)
728
                                oAddrow(_XML_SYMBOL_CONN4_POINT_X) = dConn4Pos_x
729
                                oAddrow(_XML_SYMBOL_CONN4_POINT_Y) = dConn4Pos_y
730
                                oAddrow(_XML_SYMBOL_DWG_CONN4_POINT_X) = dDwg_Conn4Pos_x
731
                                oAddrow(_XML_SYMBOL_DWG_CONN4_POINT_Y) = dDwg_Conn4Pos_y
732
                            End If
733
                        Next
734

    
735
                        Dim sXLength As String = ""
736
                        Dim sYLength As String = ""
737

    
738
                        Dim dMin_x As Double = 0
739
                        Dim dMax_x As Double = 0
740
                        Dim dMin_y As Double = 0
741
                        Dim dMax_y As Double = 0
742

    
743
                        For i = 0 To sSizeArray.Length - 1
744
                            If i = 0 Then
745
                                sXLength = sSizeArray(i)
746
                            ElseIf i = 1 Then
747
                                sYLength = sSizeArray(i)
748
                            End If
749
                        Next
750

    
751
                        For i = 0 To sLocationArray.Length - 1
752
                            If i = 0 Then
753
                                dMin_x = sLocationArray(i)
754
                                dMax_x = dMin_x + sXLength
755
                            ElseIf i = 1 Then
756
                                'Y축은 반전
757
                                dMax_y = sLocationArray(i)
758
                                dMin_y = dMax_y + sYLength
759
                            End If
760
                        Next
761
                        ConvertPointByImage(dMin_x, dMin_y, _IMG_X, _IMG_Y)
762
                        ConvertPointByImage(dMax_x, dMax_y, _IMG_X, _IMG_Y)
763

    
764
                        oAddrow(_XML_SYMBOL_MIN_X) = dMin_x
765
                        oAddrow(_XML_SYMBOL_MAX_X) = dMax_x
766
                        oAddrow(_XML_SYMBOL_MIN_Y) = dMin_y
767
                        oAddrow(_XML_SYMBOL_MAX_Y) = dMax_y
768
                        oAddrow(_XML_SYMBOL_UID) = sUid
769
                        oAddrow(_XML_LINE_LINENOUID) = CLineNo.Uid
770
                        oAddrow(_XML_SYMBOL_RUNNAME) = sRunName
771
                        oAddrow(_XML_LINENO_TEXT) = CLineNo.Text
772
                        oAddrow(_XML_SYMBOL_NAME) = IO.Path.GetFileNameWithoutExtension(GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYMBOLNAME))
773
                        oAddrow(_XML_SYMBOL_LOCATION) = sLocation
774
                        oAddrow(_XML_SYMBOL_SIZE) = sSize
775
                        oAddrow(_XML_SYMBOL_ANGLE) = sAngle
776
                        oAddrow(_XML_SYMBOL_SYSTEMPATH) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_SYSTEMPATH)
777
                        oAddrow(_XML_SYMBOL_TYPE) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_COMPTPYE)
778
                        oAddrow(_XML_SYMBOL_CLASS) = GetDataFromMappingDB(sName, _DB_COLUMN_MAPPING_SPPID_CLASS)
779
                        oAddrow(_XML_SYMBOL_ORIGINALPOINT) = sOriginalPoint
780

    
781
                        oAddrow(_XML_SYMBOL_CONNECTIONPOINT) = sConnectionPoint
782
                        oAddrow(_XML_SYMBOL_DRAWING_TF) = "FALSE"
783
                        oAddrow(_XML_SYMBOL_CHILD) = sChild
784
                        '   _AllSymbol_DT.Rows.Add(oAddrow)
785
                        oSymbol_Dt.Rows.Add(oAddrow)
786
                    Catch ex As Exception
787
                    End Try
788
                Next
789

    
790
                For Each oAtrribute As Object In oRun.Elements(_XML_CATEGORY_ATTRIBUTE)
791
                    Try
792
                        Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
793
                        Dim oEleObj As XElement
794
                        Dim sUid As String
795
                        Dim sName As String
796
                        Dim sValue As String
797
                        oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
798
                        sUid = oEleObj.Value
799
                        oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
800
                        sName = oEleObj.Value
801
                        oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
802
                        sValue = oEleObj.Value
803
                        oAddrow(_XML_ATTRIBUTE_UID) = sUid
804
                        oAddrow(_XML_ATTRIBUTE_NAME) = sName
805
                        oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
806
                        oAttribute_Dt.Rows.Add(oAddrow)
807
                    Catch ex As Exception
808
                    End Try
809
                Next
810
            Next
811
            'Line No Attribute
812
            For Each oAtrribute As Object In oLineNo.Elements(_XML_CATEGORY_ATTRIBUTE)
813
                Try
814
                    Dim oAddrow As DataRow = oAttribute_Dt.NewRow()
815
                    Dim oEleObj As XElement
816
                    Dim sUid As String = ""
817
                    Dim sName As String
818
                    Dim sValue As String
819

    
820
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_UID)
821
                    sUid = oEleObj.Value
822
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_NAME)
823
                    sName = oEleObj.Value
824
                    oEleObj = oAtrribute.Element(_XML_ATTRIBUTE_VALUE)
825
                    sValue = oEleObj.Value
826
                    oAddrow(_XML_ATTRIBUTE_UID) = sUid
827
                    oAddrow(_XML_ATTRIBUTE_NAME) = sName
828
                    oAddrow(_XML_ATTRIBUTE_VALUE) = sValue
829
                    oAttribute_Dt.Rows.Add(oAddrow)
830
                Catch ex As Exception
831
                End Try
832
            Next
833
            SetConnectionInfo(oLine_Dt, oSymbol_Dt)
834
            _AllLine_DT.Merge(oLine_Dt)
835
            _AllSymbol_DT.Merge(oSymbol_Dt)
836
            CLineNo.Dt_Line = oLine_Dt
837
            CLineNo.Dt_Symbol = oSymbol_Dt
838
            CLineNo.Dt_Attribute = oAttribute_Dt
839
            oLineno_list.Add(CLineNo)
840
        Next
841
        Return oLineno_list
842
    End Function
843

    
844
    Public Sub ConvertPointByImage(ByRef dX As Double, ByRef dY As Double, ByVal dDwgX As Double, ByVal dDwgY As Double)
845

    
846
        Dim calcx As Double = 0
847
        Dim calcy As Double = 0
848
        calcx = (dX * _DWG_X) / dDwgX 'Math.Round((dX * _DWG_X) / dDwgX, 2)
849
        calcx = Math.Truncate(calcx * 1000) / 1000
850
        calcy = _DWG_Y - ((dY * _DWG_Y) / dDwgY) '_DWG_Y - Math.Round((dY * _DWG_Y) / dDwgY, 2)
851
        calcy = Math.Truncate(calcy * 1000) / 1000
852
        dX = calcx
853
        dY = calcy
854
    End Sub
855
    '@brief Convert To SPPID
856
    '@author : Gyusu Park
857
    '@date : 2018-04-10
858
    '@history:
859
    Private Sub SplitLocation(ByVal sLocation As String, ByRef dX As Double, ByRef dY As Double)
860

    
861
        Dim opointstr As String() = Split(sLocation, ",")
862
        If (opointstr.Length > 1) Then
863
            If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
864
                dX = opointstr(0)
865
                dY = opointstr(1)
866
            End If
867
        End If
868

    
869
    End Sub
870

    
871
    Private Function Load_DB(ByVal sDBPath As String, ByVal sTableName As String) As DataTable
872

    
873
        Try
874
            Dim oDt As New DataTable
875
            Dim sConnectionstring As String = "Data Source=" & sDBPath & ";Version=3;Synchronous=Off;UTF8Encoding=True;"
876
            Dim conn As SQLiteConnection = New SQLiteConnection(sConnectionstring)
877
            conn.Open()
878
            Dim sQuery As String = "Select * from " & sTableName
879
            Dim cmd As SQLiteCommand = conn.CreateCommand()
880
            Dim adapter As SQLiteDataAdapter = New SQLiteDataAdapter(sQuery, conn)
881
            Dim oDataSet As DataSet = New DataSet()
882
            adapter.Fill(oDataSet)
883
            oDt = oDataSet.Tables(0)
884
            Return oDt
885
        Catch ex As Exception
886
            Return Nothing
887
        End Try
888
    End Function
889

    
890
    Private Function LoadAllDrawing() As DataTable
891
        SetListBoxItems(ListBox_Result, "도면정보 로드중....")
892
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "도면정보 로드중....")
893
        Dim oDt As DataTable = Drawing_Dt()
894
        Dim sHierarchy As String = My.Settings.Plant_Hierarchy
895
        Dim files() As String
896
        files = Directory.GetFiles(sHierarchy, "*.pid", SearchOption.AllDirectories)
897
        For Each FileName As String In files
898
            Dim sName As String = FileName
899
            Dim oAddRow As DataRow = oDt.NewRow()
900
            oAddRow("Name") = Path.GetFileNameWithoutExtension(sName)
901
            oAddRow("Path") = FileName
902
            oDt.Rows.Add(oAddRow)
903
        Next
904
        Return oDt
905
    End Function
906

    
907
    Dim _XMLList As ListView = New ListView()
908

    
909
    Private Function CheckOpenDrawing() As Boolean
910
        Try
911

    
912
            Dim lobjDatasource As Object
913
            _Placement = CreateObject("Plaice.Placement", "")
914
            lobjDatasource = _Placement.PIDDataSource
915
            Return True
916
        Catch ex As Exception
917
            Return False
918
        End Try
919

    
920
    End Function
921

    
922

    
923
    Private Sub Btn_Convert_Click(sender As Object, e As EventArgs) Handles Btn_Convert.Click
924
        Main_Tab.SelectedIndex = 1
925
        ListBox_Result.Items.Clear()
926
        Me.ProgressBar_Status.Visible = True
927
        ProgressBar_Status.Maximum = 100
928
        ProgressBar_Status.Value = 0
929

    
930
        _Main_trd = New Thread(AddressOf ThreadConvert)
931
        _Main_trd.IsBackground = True
932
        _Main_trd.Start()
933
        FineOPCForm()
934
    End Sub
935

    
936
    Private Sub FineOPCForm()
937
        _Opc_trd = New Thread(AddressOf ThreadOPCRemove)
938
        _Opc_trd.IsBackground = True
939
        _Opc_trd.Start()
940
    End Sub
941

    
942

    
943
    Dim _objPIDAutoApp As Object
944

    
945
    Private Function OpenSPPID(ByVal oDwg_Dt As DataTable, ByVal sDwgName As String) As Boolean
946
        Dim bCheckOpen As Boolean = False
947
        '   Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgPath)
948
        SetListBoxItems(ListBox_Result, sDwgName & " 도면 Open....")
949
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, sDwgName & " 도면 Open....")
950
        _objPIDAutoApp = CreateObject("PIDAutomation.Application")
951

    
952
        Dim sPath As String = OpenDrawing(oDwg_Dt, sDwgName)
953
        If sPath <> "" Then
954
            Process.Start(sPath)
955
        Else
956
            Return bCheckOpen
957
        End If
958

    
959
        Dim bCheckOpenDrawing As Boolean = False
960
        While (True)
961
            bCheckOpenDrawing = CheckOpenDrawing()
962
            If bCheckOpenDrawing = True Then
963
                bCheckOpen = True
964
                Exit While
965
            Else
966
                Thread.Sleep(2000)
967
            End If
968
        End While
969

    
970

    
971
        Return bCheckOpen
972
    End Function
973

    
974
    Private Function GetDrawing(ByVal sDwgName As String) As Drawing
975
        For Each CDrawing In _DrawingsList
976
            If CDrawing.DwgName.ToUpper() = sDwgName.ToUpper() Then
977
                Return CDrawing
978
            End If
979
        Next
980
        Return Nothing
981
    End Function
982

    
983
    Private Function GetLineNo(ByVal CDrawing As Drawing, ByVal sLineNoUid As String) As Line_no
984
        For Each CLineNo In CDrawing.Line_nos
985
            If CLineNo.Uid = sLineNoUid Then
986
                Return CLineNo
987
            End If
988
        Next
989
        Return Nothing
990
    End Function
991

    
992
    Private Function GetTrimLineNo(ByVal CDrawing As Drawing, ByVal sLineNoUid As String) As Line_no
993
        For Each CLineNo In CDrawing.TrimLine_nos
994
            If CLineNo.Uid = sLineNoUid Then
995
                Return CLineNo
996
            End If
997
        Next
998
        Return Nothing
999
    End Function
1000

    
1001

    
1002

    
1003
    Private Function GetPipeFromConnection(ByVal CDrawing As Drawing, ByVal sSymbolUid As String, ByRef sConnTypeNo As String) As DataTable
1004
        For Each CLineNo In CDrawing.Line_nos
1005
            Dim odt As DataTable = CLineNo.Dt_Line
1006
            If odt.Rows.Count > 0 Then
1007
                If odt.Rows(0)(_XML_LINE_Conn1_Uid).ToString = sSymbolUid Then
1008
                    sConnTypeNo = "1"
1009
                    Return odt
1010
                ElseIf odt.Rows(0)(_XML_LINE_Conn2_Uid).ToString() = sSymbolUid Then
1011
                    sConnTypeNo = "2"
1012
                    Return odt
1013
                End If
1014
            End If
1015
        Next
1016
        Return New DataTable
1017
    End Function
1018

    
1019
    Private Function GetSymbolFromConnection(ByVal CDrawing As Drawing, ByVal sSymbolUid As String, ByRef sConnTypeNo As String) As DataTable
1020
        For Each CLineNo In CDrawing.Line_nos
1021
            Dim odt As DataTable = CLineNo.Dt_Symbol
1022
            If odt.Rows.Count > 0 Then
1023
                If odt.Rows(0)(_XML_SYMBOL_Conn1_Uid).ToString = sSymbolUid Then
1024
                    sConnTypeNo = "1"
1025
                    Return odt
1026
                ElseIf odt.Rows(0)(_XML_SYMBOL_Conn2_Uid).ToString() = sSymbolUid Then
1027
                    sConnTypeNo = "2"
1028
                    Return odt
1029
                ElseIf odt.Rows(0)(_XML_SYMBOL_Conn3_Uid).ToString() = sSymbolUid Then
1030
                    sConnTypeNo = "3"
1031
                    Return odt
1032
                ElseIf odt.Rows(0)(_XML_SYMBOL_Conn4_Uid).ToString() = sSymbolUid Then
1033
                    sConnTypeNo = "4"
1034
                    Return odt
1035
                End If
1036
            End If
1037
        Next
1038
        Return New DataTable
1039
    End Function
1040

    
1041
    Private Function GetEqpNo(ByVal CDrawing As Drawing, ByVal sEqpUid As String) As Eqp_no
1042
        For Each CEqpNo In CDrawing.Eqp_nos
1043
            If CEqpNo.Uid = sEqpUid Then
1044
                Return CEqpNo
1045
            End If
1046
        Next
1047
        Return Nothing
1048
    End Function
1049
    Public Function ConvertPointBystring(ByVal sPoint As String, ByRef dX As Double, ByRef dY As Double) As Boolean
1050
        Try
1051
            Dim opointstr As String() = Split(sPoint, ",")
1052
            If (opointstr.Length > 1) Then
1053
                If IsNumeric(opointstr(0)) And IsNumeric(opointstr(1)) Then
1054
                    dX = opointstr(0)
1055
                    dY = opointstr(1)
1056

    
1057
                Else
1058
                    dX = 0
1059
                    dY = 0
1060
                    Return False
1061
                End If
1062
            End If
1063
            Return True
1064
        Catch ex As Exception
1065
            Return False
1066
        End Try
1067
    End Function
1068

    
1069

    
1070
    Dim _DrawLine_Dt As DataTable = DrawLind_Dt()
1071

    
1072

    
1073
    Private Sub PlaceEquipment(ByVal sUid As String, ByVal oSymbol_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal sEqpName As String)
1074
        Try
1075
            Dim oSymbolRow() As DataRow = oSymbol_Dt.Select(_XML_SYMBOL_UID & " = '" + sUid + "'")
1076
            Dim oAttributeRow() As DataRow
1077
            If oAttribute_Dt.Rows.Count > 0 Then
1078
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sUid + "'")
1079
            End If
1080
            If oSymbolRow.Length > 0 Then
1081
                Dim oDatasource As Object = _Placement.PIDDataSource
1082
                Dim sSymbolName As String = oSymbolRow(0)(_XML_SYMBOL_NAME).ToString()
1083
                Dim sSymbolCompType As String = oSymbolRow(0)(_XML_SYMBOL_TYPE).ToString()
1084
                Dim sSystemPath As String = oSymbolRow(0)(_XML_SYMBOL_SYSTEMPATH).ToString()
1085
                Dim sClass As String = oSymbolRow(0)(_XML_SYMBOL_CLASS).ToString()
1086
                Dim sLocation As String = oSymbolRow(0)(_XML_SYMBOL_LOCATION).ToString()
1087
                Dim sOriginalPoint As String = oSymbolRow(0)(_XML_SYMBOL_ORIGINALPOINT).ToString()
1088
                Dim dAngle As Double = 0.0
1089
                If IsNumeric(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString()) Then
1090
                    dAngle = Double.Parse(oSymbolRow(0)(_XML_SYMBOL_ANGLE).ToString())
1091
                End If
1092
                Dim dLocationX As Double = 0.0
1093
                Dim dLocationY As Double = 0.0
1094
                ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY)
1095
                Dim dX As Double = dLocationX
1096
                Dim dY As Double = dLocationY
1097
                ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
1098
                Dim oReturnSymbol As LMSymbol = Nothing
1099
                If sSymbolCompType.ToUpper() = "NOZZLE" Then
1100
                    Dim sOwnerUid As String = oSymbolRow(0)(_XML_SYMBOL_OWNER).ToString()
1101
                    Dim oFineRow() As DataRow = _ModelingSymbol_Dt.Select("Uid = '" & sOwnerUid & "'")
1102
                    If oFineRow.Length = 1 Then
1103
                        Dim sEqpModelID As String = oFineRow(0)(_XML_SYMBOL_SPID).ToString()
1104

    
1105
                        Dim objVessel As LMVessel
1106
                        objVessel = _Placement.PIDDataSource.GetVessel(sEqpModelID)
1107
                        Dim oVesselLocation As LMLocations = objVessel.Locations
1108
                        Dim oEqpSymbol As LMSymbol = _Placement.PIDDataSource.GetSymbol(objVessel.Representations.Nth(1).Id)
1109

    
1110
                        Dim objNozzle As LMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY,
1111
                                                    TargetItem:=oEqpSymbol.AsLMRepresentation)
1112
                        SetListBoxItems(ListBox_Result, "Place Nozzle.." & sUid & " (" & dLocationX & "," & dLocationY & ")..." & _iEquipmentcnt & " count ")
1113
                        _iNozzlecnt = _iNozzlecnt + 1
1114
                        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Nozzle : " & sUid)
1115
                        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Nozzle Name : " & sSymbolName)
1116
                        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
1117
                        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "OriginalPoint : " & dLocationX & "," & dLocationY)
1118
                        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Nozzle Count : " & _iNozzlecnt)
1119
                    End If
1120
                Else
1121
                    oReturnSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
1122
                    SetListBoxItems(ListBox_Result, "Place Equipment.." & sUid & " (" & dLocationX & "," & dLocationY & ")..." & _iEquipmentcnt & " count ")
1123
                    _iEquipmentcnt = _iEquipmentcnt + 1
1124
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Equipment : " & sUid)
1125
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Equipment Name : " & sSymbolName)
1126
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
1127
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "OriginalPoint : " & dLocationX & "," & dLocationY)
1128
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Equipment Count : " & _iEquipmentcnt)
1129
                End If
1130
                '모델링 된 Symbol 데이터 테이블 저장
1131
                Dim oAddRow As DataRow = _ModelingSymbol_Dt.NewRow
1132
                oAddRow(_XML_SYMBOL_UID) = sUid
1133
                oAddRow(_XML_SYMBOL_SPID) = oReturnSymbol.ModelItemID
1134
                oAddRow(_XML_SYMBOL_LMSYMBOL) = oReturnSymbol
1135
                oAddRow(_XML_SYMBOL_DRAWING_TF) = "TRUE"
1136
                oAddRow(_XML_SYMBOL_CENTERPOINT_X) = dLocationX
1137
                oAddRow(_XML_SYMBOL_CENTERPOINT_Y) = dLocationY
1138
                _ModelingSymbol_Dt.Rows.Add(oAddRow)
1139
            End If
1140
        Catch ex As Exception
1141
        End Try
1142
    End Sub
1143

    
1144
    Private Sub AddProgress()
1145
        _Itemcnt = _Itemcnt + 1
1146
        Dim dCalcProgressValue As Double = (_Itemcnt / _allItem) * 100
1147
        SetProgressbar(ProgressBar_Status, dCalcProgressValue)
1148
        Label_Progress.Text = Math.Round(dCalcProgressValue, 0) & "%"
1149
    End Sub
1150

    
1151

    
1152
    Dim _라인보정기준값 As Integer = 10
1153

    
1154

    
1155
    Private Function GetAllCheckNodeCount() As Integer
1156
        _allItem = 0
1157
        For i = 0 To Tree_Result.Nodes.Count - 1
1158
            For j = 0 To Tree_Result.Nodes(i).Nodes.Count - 1
1159
                For k = 0 To Tree_Result.Nodes(i).Nodes(j).Nodes.Count - 1
1160
                    For l = 0 To Tree_Result.Nodes(i).Nodes(j).Nodes(k).Nodes.Count - 1
1161
                        If Tree_Result.Nodes(i).Nodes(j).Nodes(k).Nodes(l).Checked = True Then
1162
                            _allItem = _allItem + 1
1163
                        End If
1164
                    Next
1165
                Next
1166
            Next
1167
        Next
1168
        Return _allItem
1169
    End Function
1170

    
1171

    
1172
    Private Sub ManualCheckNode(ByRef oDt As DataTable)
1173
        For Each oDrwing As TreeNode In Tree_Result.Nodes
1174
            For Each oDwgNode As TreeNode In oDrwing.Nodes
1175
                For Each oNode As TreeNode In oDwgNode.Nodes
1176
                    For Each oSymbolNode As TreeNode In oNode.Nodes
1177
                        Dim sUid As String = oSymbolNode.Name
1178
                        'Dim oSelectRows() As DataRow = oDt.Select("[" & _XML_SYMBOL_UID & "] = '" & sUid &
1179
                        '                                      "' And [" & _XML_SYMBOL_DRAWING_TF & "] = 'False'")
1180
                        If oSymbolNode.Checked Then
1181
                            Dim oSelectRows() As DataRow = oDt.Select("[" & _XML_SYMBOL_UID & "] = '" & sUid & "'")
1182
                            If oSelectRows.Length = 1 Then
1183
                                oSelectRows(0)(_XML_SYMBOL_DRAWING_TF) = "FALSE"
1184
                                If oSymbolNode.Checked Then
1185
                                    oSelectRows(0)(_XML_SYMBOL_Check) = "TRUE"
1186
                                Else
1187
                                    oSelectRows(0)(_XML_SYMBOL_Check) = "FALSE"
1188
                                End If
1189
                            End If
1190
                        End If
1191
                    Next
1192
                Next
1193
            Next
1194
        Next
1195

    
1196
    End Sub
1197

    
1198
    Private Function GetChildSymbolDirection(ByVal sDirection As String) As Double
1199
        Dim sReturnDirection As String = ""
1200
        If sDirection.ToUpper() = "RIGHT" Then
1201
            Return 3.14
1202
        ElseIf sDirection.ToUpper() = "LEFT" Then
1203
            Return 0
1204
        ElseIf sDirection.ToUpper = "DOWN" Then
1205
            Return 1.57
1206
        ElseIf sDirection.ToUpper() = "UP" Then
1207
            Return 4.71
1208
        Else
1209
            Return 0
1210
        End If
1211
    End Function
1212

    
1213
    Private Function CheckExistModeling(ByVal oRow As DataRow) As String
1214
        If oRow(_XML_LINE_DRAWING_TF).ToString() = "FALSE" And oRow(_XML_LINE_Check).ToString() = "TRUE" Then
1215
            Return oRow(_XML_LINE_UID).ToString()
1216
        End If
1217
        Return String.Empty
1218
    End Function
1219

    
1220

    
1221
    Private Sub AddLog(ByVal sUid As String, ByVal sSystemPath As String,
1222
                             ByVal dStart_Dwg_x As Double, ByVal dStart_Dwg_y As Double, ByVal dEnd_Dwg_x As Double, ByVal dEnd_Dwg_y As Double,
1223
                       ByVal sLineNoText As String, ByVal sConn1Uid As String, ByVal sConn2Uid As String)
1224
        SetListBoxItems(ListBox_Result, "Place Pipe.." & sUid & " (" & dStart_Dwg_x & "," & dStart_Dwg_y & ") - (" & dEnd_Dwg_x & "," & dEnd_Dwg_y & ")..." & _iPipecnt & " count ")
1225
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Pipe : " & sUid)
1226
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "LineNo : " & sLineNoText)
1227
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection1 : " & sConn1Uid)
1228
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection2 : " & sConn2Uid)
1229
        'ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
1230
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "StartPoint : " & dStart_Dwg_x & "," & dStart_Dwg_y)
1231
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "EndPoint : " & dEnd_Dwg_x & "," & dEnd_Dwg_y)
1232
        ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Pipe Count : " & _iPipecnt)
1233
    End Sub
1234

    
1235
    Private Sub AddAttribute(ByVal oPipeRun As LMPipeRun, ByVal oAttribute_Dt As DataTable, ByVal sLineNoUid As String)
1236
        Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
1237
        If oAttributeRow.Length > 0 Then
1238
            For Each oAttribute In oAttributeRow
1239
                Try
1240
                    Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
1241
                    Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
1242
                    If sPIDValue.Contains("'") Then
1243
                        sPIDValue = sPIDValue.Replace("'", """")
1244
                    End If
1245
                    Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
1246
                    oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
1247
                Catch ex As Exception
1248
                End Try
1249
            Next
1250
            oPipeRun.Commit()
1251
        End If
1252
    End Sub
1253

    
1254
    Private Sub AddModelingDT(ByVal sUid As String, ByVal sModelID As String, ByVal oCurrentConnector As LMConnector,
1255
                              ByVal dStart_Dwg_x As Double, ByVal dStart_Dwg_y As Double,
1256
                              ByVal dEnd_Dwg_x As Double, ByVal dEnd_Dwg_y As Double)
1257
        Dim oAddRow As DataRow = _ModelingLine_Dt.NewRow
1258
        oAddRow(_XML_LINE_UID) = sUid
1259
        oAddRow(_XML_LINE_SPID) = sModelID
1260
        oAddRow(_XML_LINE_LMCONNECTOR) = oCurrentConnector
1261
        oAddRow(_XML_LINE_DRAWING_TF) = "TRUE"
1262
        oAddRow(_XML_LINE_DWG_STARTPOINT_X) = dStart_Dwg_x
1263
        oAddRow(_XML_LINE_DWG_STARTPOINT_Y) = dStart_Dwg_y
1264
        oAddRow(_XML_LINE_DWG_ENDPOINT_X) = dEnd_Dwg_x
1265
        oAddRow(_XML_LINE_DWG_ENDPOINT_Y) = dEnd_Dwg_y
1266
        _ModelingLine_Dt.Rows.Add(oAddRow)
1267
    End Sub
1268

    
1269
    Private Function JoinPipeRun(ByVal sID_1 As String, ByVal sID_2 As String) As Boolean
1270
        Try
1271
            Dim objSurvivorItem As LMAItem = Nothing
1272
            Dim oPipeRun1 As LMPipeRun = _Placement.PIDDataSource.GetPipeRun(sID_1)
1273
            Dim oPipeRun2 As LMPipeRun = _Placement.PIDDataSource.GetPipeRun(sID_2)
1274
            _Placement.PIDJoinRuns(oPipeRun1, oPipeRun2)
1275
            Return True
1276
        Catch ex As Exception
1277
            Return False
1278
        End Try
1279
    End Function
1280

    
1281

    
1282
    Private Function LineModeling(ByVal objInputs As PlaceRunInputs, ByVal sSystemPath As String) As LMConnector
1283
        Dim oCurrentConnector As LMConnector = Nothing
1284
        Dim objItem As LMAItem
1285
        objItem = _Placement.PIDCreateItem(sSystemPath)
1286
        Try
1287
            oCurrentConnector = _Placement.PIDPlaceRun(objItem, objInputs)
1288
            AddProgress()
1289
        Catch ex As Exception
1290
        End Try
1291
        Return oCurrentConnector
1292
    End Function
1293

    
1294
    Private Sub GetPrimaryLineInNode(ByVal list As List(Of Line), ByVal node As TreeNode)
1295

    
1296
        If node.Tag IsNot Nothing Then
1297
            If TypeOf node.Tag Is Line Then
1298
                Dim line As Line = node.Tag
1299
                If line.TYPE = "Primary" And node.Checked Then
1300
                    list.Add(line)
1301
                End If
1302
            End If
1303
        End If
1304

    
1305
        For Each child As TreeNode In node.Nodes()
1306
            GetPrimaryLineInNode(list, child)
1307
        Next
1308
    End Sub
1309

    
1310
    Private Sub GetSymbolInNode(ByVal list As List(Of Symbol), ByVal node As TreeNode)
1311

    
1312
        If node.Tag IsNot Nothing Then
1313
            If TypeOf node.Tag Is Symbol Then
1314
                Dim symbol As Symbol = node.Tag
1315
                list.Add(symbol)
1316
            End If
1317
        End If
1318

    
1319
        For Each child As TreeNode In node.Nodes()
1320
            GetSymbolInNode(list, child)
1321
        Next
1322
    End Sub
1323

    
1324
    Private Function FindBranchLine(ByVal lines As List(Of Line)) As List(Of Line)
1325
        Dim branchLines As List(Of Line) = New List(Of Line)
1326

    
1327
        For Each line As Line In lines
1328
            For Each conn As Connector In line.CONNECTORS
1329
                If String.IsNullOrEmpty(conn.CONNECTEDITEM) = False Then
1330
                    If IsBranchLine(conn.CONNECTEDITEM, line.UID, lines) Then
1331
                        branchLines.Add(line)
1332
                    End If
1333
                End If
1334
            Next
1335
        Next
1336

    
1337
        Return branchLines
1338
    End Function
1339

    
1340
    Private Function IsBranchLine(ByVal connectedUID As String, ByVal UID As String, ByVal lines As List(Of Line)) As Boolean
1341
        Dim connLine = FindLineByUID(lines, connectedUID)
1342
        If connLine IsNot Nothing Then
1343
            If connLine.CONNECTORS(0).CONNECTEDITEM <> UID And connLine.CONNECTORS(1).CONNECTEDITEM <> UID Then
1344
                Return True
1345
            End If
1346
        End If
1347

    
1348
        Return False
1349
    End Function
1350

    
1351
    Private Function FindLineByUID(ByVal lines As List(Of Line), ByVal uid As String) As Line
1352
        For Each line As Line In lines
1353
            If line.UID = uid Then
1354
                Return line
1355
            End If
1356
        Next
1357

    
1358
        Return Nothing
1359
    End Function
1360

    
1361

    
1362
    Private Function FindSymbolByUID(ByVal symbols As List(Of Symbol), ByVal uid As String) As Symbol
1363
        For Each symbol As Symbol In symbols
1364
            If symbol.UID = uid Then
1365
                Return symbol
1366
            End If
1367
        Next
1368

    
1369
        Return Nothing
1370
    End Function
1371

    
1372
    Private Function IsHorizontal(ByVal line As Line)
1373
        If line.END_X - line.START_X = 0 Then
1374
            Return False
1375
        Else
1376
            Dim angle = Math.Atan(Math.Abs(line.END_Y - line.START_Y) / Math.Abs(line.END_X - line.START_X)) * 180 / Math.PI
1377
            If angle < 10 Then
1378
                Return True
1379
            Else
1380
                Return False
1381
            End If
1382
        End If
1383
    End Function
1384

    
1385
    Private Function IsHorizontal(ByVal point1 As Pointd, ByVal point2 As Pointd)
1386
        If point1.X - point2.X = 0 Then
1387
            Return False
1388
        Else
1389
            Dim angle = Math.Atan(Math.Abs(point2.Y - point1.Y) / Math.Abs(point2.X - point1.X)) * 180 / Math.PI
1390
            If angle < 10 Then
1391
                Return True
1392
            Else
1393
                Return False
1394
            End If
1395
        End If
1396
    End Function
1397

    
1398
    Private Function GetLMConnectorByPoint(ByVal ModelId As String, ByVal point As Pointd) As LMConnector
1399
        Dim objPlacement As Placement = New Placement
1400
        Dim objConnector As LMConnector = Nothing
1401

    
1402
        Dim distance As Double = Double.MaxValue
1403
        Dim lmPipeRun As LMPipeRun = objPlacement.PIDDataSource.GetPipeRun(ModelId)
1404
        For Each oRep As LMRepresentation In lmPipeRun.Representations
1405
            If oRep.Attributes("RepresentationType").Value = "Connector" And oRep.Attributes("ItemStatus").Value = "Active" Then
1406
                Dim _conn As LMConnector = objPlacement.PIDDataSource.GetConnector(oRep.Id)
1407
                For Each vertex As LMConnectorVertex In _conn.ConnectorVertices
1408
                    Dim _distance As Double = CalcPointToPointdDistance(point, New Pointd(vertex.XCoordinate, vertex.YCoordinate))
1409

    
1410
                    If _distance < distance Then
1411
                        distance = _distance
1412
                        objConnector = _conn
1413
                    End If
1414
                Next
1415
            End If
1416
        Next
1417

    
1418
        Return objConnector
1419
    End Function
1420

    
1421
    Private Function GetLMConnectorBySP_ID(ByVal ModelId As String, ByVal SP_ID1 As String, ByVal SP_ID2 As String) As LMConnector
1422
        Dim objPlacement As Placement = New Placement
1423
        Dim objConnector As LMConnector = Nothing
1424

    
1425
        Dim distance As Double = Double.MaxValue
1426
        Dim lmPipeRun As LMPipeRun = objPlacement.PIDDataSource.GetPipeRun(ModelId)
1427
        For Each oRep As LMRepresentation In lmPipeRun.Representations
1428
            If oRep.Attributes("RepresentationType").Value = "Connector" And oRep.Attributes("ItemStatus").Value = "Active" Then
1429
                Dim _conn As LMConnector = objPlacement.PIDDataSource.GetConnector(oRep.Id)
1430

    
1431
                Dim find1 As Boolean = False
1432
                Dim find2 As Boolean = False
1433

    
1434
                If _conn.ConnectItem1SymbolID IsNot Nothing Then
1435
                    If _conn.ConnectItem1SymbolID.ToString = SP_ID1 Or _conn.ConnectItem1SymbolID.ToString = SP_ID2 Then
1436
                        find1 = True
1437
                    End If
1438
                End If
1439

    
1440
                If _conn.ConnectItem2SymbolID IsNot Nothing Then
1441
                    If _conn.ConnectItem2SymbolID.ToString = SP_ID1 Or _conn.ConnectItem2SymbolID.ToString = SP_ID2 Then
1442
                        find2 = True
1443
                    End If
1444
                End If
1445

    
1446
                If find1 And find2 Then
1447
                    Return _conn
1448
                End If
1449
            End If
1450
        Next
1451

    
1452
        If objConnector Is Nothing Then
1453
            Debug.WriteLine("Error At GetLMConnectorBySP_ID")
1454
        End If
1455

    
1456
        Return objConnector
1457
    End Function
1458

    
1459
    Private Function CalcLineToPointdDistance(ByVal point1 As Pointd, ByVal point2 As Pointd, ByVal targetPointd As Pointd) As Double
1460
        If point1.X = point2.X Then
1461
            Return Math.Abs(targetPointd.X - point1.X)
1462
        ElseIf point1.Y = point2.Y Then
1463
            Return Math.Abs(targetPointd.Y - point1.Y)
1464
        Else
1465
            ' y = ax + c
1466
            Dim a As Double = (point2.Y - point1.Y) / (point2.X - point1.X)
1467
            Dim c As Double = point2.Y - a * point2.X
1468

    
1469
            ' ax + by + c = 0
1470
            Dim b As Double = -1
1471
            Return Math.Abs(a * targetPointd.X + b * targetPointd.Y + c) / Math.Pow(a * a + b * b, 0.5)
1472
        End If
1473
    End Function
1474

    
1475
    Private Function CalcPointToPointdDistance(ByVal point1 As Pointd, ByVal point2 As Pointd) As Double
1476

    
1477
        Return Math.Pow(Math.Pow(point1.X - point2.X, 2) + Math.Pow(point1.Y - point2.Y, 2), 0.5)
1478

    
1479
    End Function
1480

    
1481
    Private Function GetConnectorTarget(ByVal Connector_ModelID As String, ByVal targetPoint As Pointd) As LMConnector
1482
        Dim objPlacement As Placement = New Placement
1483

    
1484
        Dim lmPipeRun As LMPipeRun = objPlacement.PIDDataSource.GetPipeRun(Connector_ModelID)
1485

    
1486
        Dim connList As List(Of LMConnector) = New List(Of LMConnector)
1487
        Dim oConnector As LMConnector = Nothing
1488

    
1489
        For Each oRep As LMRepresentation In lmPipeRun.Representations
1490
            If oRep.Attributes("RepresentationType").Value = "Connector" And oRep.Attributes("ItemStatus").Value = "Active" Then
1491
                connList.Add(objPlacement.PIDDataSource.GetConnector(oRep.Id))
1492
            End If
1493
        Next
1494

    
1495
        '' 자기 자신의 Line 찾기
1496
        Dim distance As Double = Double.MaxValue
1497
        For Each lmLine As LMConnector In connList
1498
            '' Connector의 포인트 정리
1499

    
1500
            '' 임시
1501
            oConnector = lmLine
1502
            '_Placement.PIDDataSource.GetPipingPoint()
1503

    
1504
            Dim pointList As List(Of Pointd) = New List(Of Pointd)
1505

    
1506
            For index = 1 To Integer.MaxValue
1507
                Dim point As LMConnectorVertex = lmLine.ConnectorVertices.Nth(index)
1508
                If point IsNot Nothing Then
1509
                    Dim _pointd As Pointd = New Pointd()
1510
                    _pointd.X = point.XCoordinate
1511
                    _pointd.Y = point.YCoordinate
1512
                    pointList.Add(_pointd)
1513
                Else
1514
                    Exit For
1515
                End If
1516
            Next
1517

    
1518
            For index = 0 To pointList.Count - 1
1519
                If pointList.Count > index + 1 Then
1520
                    Dim _tempDistance As Double = CalcLineToPointdDistance(pointList(index), pointList(index + 1), targetPoint)
1521
                    If _tempDistance < distance Then
1522
                        oConnector = lmLine
1523
                        distance = _tempDistance
1524
                    End If
1525
                End If
1526
            Next
1527
        Next
1528

    
1529
        Return oConnector
1530
    End Function
1531

    
1532
    Private Function FindFirstLine(ByVal primaryLineList As List(Of Line), ByVal symbols As List(Of Symbol), ByVal symbol As Symbol, ByVal UID As String) As Line
1533

    
1534
        For Each conn As Connector In symbol.CONNECTORS
1535
            '' 자기 자신일 경우 제외
1536
            If conn.CONNECTEDITEM = UID Then
1537
                Continue For
1538
            End If
1539

    
1540
            Dim _symbol As Symbol = FindSymbolByUID(symbols, conn.CONNECTEDITEM)
1541
            Dim _line As Line = FindLineByUID(primaryLineList, conn.CONNECTEDITEM)
1542

    
1543
            If _line IsNot Nothing Then
1544
                If _line.GROUPING = False Then
1545
                    Return _line
1546
                End If
1547
            ElseIf _symbol IsNot Nothing Then
1548
                Return FindFirstLine(primaryLineList, symbols, _symbol, symbol.UID)
1549
            End If
1550
        Next
1551

    
1552
        Return Nothing
1553

    
1554
    End Function
1555

    
1556
    Structure Pointd
1557
        Public Sub New(ByVal X As Double, ByVal Y As Double)
1558
            Me.X = X
1559
            Me.Y = Y
1560
        End Sub
1561
        Public X As Double
1562
        Public Y As Double
1563
    End Structure
1564

    
1565
    Class PointdInfo
1566
        Public Sub New(ByVal Pointd As Pointd, ByVal Type As String)
1567
            Me.Pointd = Pointd
1568
            Me.Type = Type
1569
        End Sub
1570

    
1571
        Public Sub New(ByVal Pointd As Pointd, ByVal Type As String, ByVal SP_ID As String)
1572
            Me.Pointd = Pointd
1573
            Me.Type = Type
1574
            Me.SP_ID = SP_ID
1575
        End Sub
1576

    
1577
        Public Pointd As Pointd
1578
        Public Type As String
1579
        Public SP_ID As String
1580
    End Class
1581

    
1582
    Private Function CalcDistance(ByVal point1 As Pointd, ByVal point2 As Pointd) As Double
1583
        Return Math.Pow(Math.Sqrt(Math.Abs(point1.X - point2.X)) + Math.Sqrt(Math.Abs(point1.Y - point2.Y)), 0.5)
1584
    End Function
1585

    
1586
    Private Sub FindNearPoint(ByVal oOPCSymbol As LMSymbol, ByRef dNear_x As Double, ByRef dNear_y As Double)
1587
        Dim oConnectionPoints_x(4) As Double
1588
        Dim oConnectionPoints_y(4) As Double
1589

    
1590
        Try
1591
            _Placement.PIDConnectPointLocation(oOPCSymbol, 1, oConnectionPoints_x(0), oConnectionPoints_y(0))
1592
            _Placement.PIDConnectPointLocation(oOPCSymbol, 2, oConnectionPoints_x(1), oConnectionPoints_y(1))
1593
            _Placement.PIDConnectPointLocation(oOPCSymbol, 3, oConnectionPoints_x(2), oConnectionPoints_y(2))
1594
            _Placement.PIDConnectPointLocation(oOPCSymbol, 4, oConnectionPoints_x(3), oConnectionPoints_y(3))
1595
            Dim iNearPoint As Integer = 0
1596
            Dim dGap As Double = 0
1597
            For i = 0 To 3
1598
                If dGap = 0 Then
1599
                    iNearPoint = i
1600
                    dGap = Math.Abs(oConnectionPoints_x(i) - dNear_x) + Math.Abs(oConnectionPoints_y(i) - dNear_y)
1601
                Else
1602
                    If dGap >= Math.Abs(oConnectionPoints_x(i) - dNear_x) + Math.Abs(oConnectionPoints_y(i) - dNear_y) Then
1603
                        iNearPoint = i
1604
                        dGap = Math.Abs(oConnectionPoints_x(i) - dNear_x) + Math.Abs(oConnectionPoints_y(i) - dNear_y)
1605
                    End If
1606
                End If
1607
            Next
1608
            dNear_x = oConnectionPoints_x(iNearPoint)
1609
            dNear_y = oConnectionPoints_y(iNearPoint)
1610
        Catch ex As Exception
1611

    
1612
        End Try
1613

    
1614
    End Sub
1615

    
1616
    Private Function GetPipeType(ByVal sType As String) As String
1617
        Dim sSystempath As String = "\Piping\Routing\Process Lines\Primary Piping.sym" ' oPipeRow(0)(_XML_LINE_SYSTEMPATH).ToString()
1618
        If sType.ToUpper() = "ELECTRIC" Then
1619
            sSystempath = "\Instrumentation\Signal Line\Electric.sym"
1620
        ElseIf sType.ToUpper() = "CONNECT TO PROCESS" Then
1621
            sSystempath = "\Instrumentation\Signal Line\Connect To Process.sym"
1622
        ElseIf sType.ToUpper() = "SOFTWARE" Then
1623
            sSystempath = "\Instrumentation\Signal Line\Software Link.sym"
1624
        ElseIf sType.ToUpper() = "PNEUMATIC" Then
1625
            sSystempath = "\Instrumentation\Signal Line\Pneumatic.sym"
1626
        End If
1627
        Return sSystempath
1628
    End Function
1629

    
1630
    Private Sub InitAutoRouting()
1631
        For Each oDrwing As TreeNode In Tree_Result.Nodes
1632
            For Each oDwgNode As TreeNode In oDrwing.Nodes
1633
                Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
1634
                Dim CDrawing As Drawing = GetDrawing(sDwgName)
1635
                If CDrawing IsNot Nothing Then
1636
                    Dim iAllLineNoCount As Integer = Tree_Result.Nodes.Count ' GetCheckNodeCount(oLinenoNode)
1637
                    Dim iPipingOPC_count As Integer = 0 ' GetCheckNodeCount(oLinenoNode)
1638
                    SetListBoxItems(ListBox_Result, "Place " & CDrawing.DwgName & "....")
1639

    
1640
                    For Each oNode As TreeNode In oDwgNode.Nodes
1641
                        Dim iItemcnt As Integer = 0
1642
                        Dim sNodeUid As String = oNode.Name
1643
                        Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
1644
                        Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
1645
                        If CLineNo IsNot Nothing Then
1646
                            Dim oLine_Dt As DataTable = CLineNo.Dt_Line
1647
                            Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
1648

    
1649
                            For Each oLineRow In oLine_Dt.Rows
1650
                                ' oLineRow(_XML_LINE_UID) = ""
1651
                                oLineRow(_XML_LINE_SPID) = ""
1652
                                oLineRow(_XML_LINE_LMCONNECTOR) = Nothing
1653
                                oLineRow(_XML_LINE_LMCONNECTOR_1) = Nothing
1654
                                oLineRow(_XML_LINE_LMCONNECTOR_2) = Nothing
1655
                                oLineRow(_XML_LINE_DRAWING_TF) = "False"
1656
                                oLineRow(_XML_LINE_Check) = "False"
1657
                            Next
1658
                            For Each oSymbolRow In oSymbol_Dt.Rows
1659
                                '   oSymbolRow(_XML_SYMBOL_UID) = ""
1660
                                oSymbolRow(_XML_SYMBOL_SPID) = ""
1661
                                oSymbolRow(_XML_SYMBOL_LMSYMBOL) = Nothing
1662
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_1) = Nothing
1663
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_2) = Nothing
1664
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_3) = Nothing
1665
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_4) = Nothing
1666
                                oSymbolRow(_XML_SYMBOL_Check) = "False"
1667
                                oSymbolRow(_XML_SYMBOL_DRAWING_TF) = "False"
1668

    
1669
                            Next
1670

    
1671
                        End If
1672

    
1673
                        Dim CTRIMLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
1674
                        If CTRIMLineNo IsNot Nothing Then
1675
                            Dim oLine_Dt As DataTable = CTRIMLineNo.Dt_Line
1676
                            Dim oSymbol_Dt As DataTable = CTRIMLineNo.Dt_Symbol
1677

    
1678
                            For Each oLineRow In oLine_Dt.Rows
1679
                                ' oLineRow(_XML_LINE_UID) = ""
1680
                                oLineRow(_XML_LINE_SPID) = ""
1681
                                oLineRow(_XML_LINE_LMCONNECTOR) = Nothing
1682
                                oLineRow(_XML_LINE_LMCONNECTOR_1) = Nothing
1683
                                oLineRow(_XML_LINE_LMCONNECTOR_2) = Nothing
1684
                                oLineRow(_XML_LINE_DRAWING_TF) = "False"
1685
                                oLineRow(_XML_LINE_Check) = "False"
1686
                            Next
1687
                            For Each oSymbolRow In oSymbol_Dt.Rows
1688
                                '   oSymbolRow(_XML_SYMBOL_UID) = ""
1689
                                oSymbolRow(_XML_SYMBOL_SPID) = ""
1690
                                oSymbolRow(_XML_SYMBOL_LMSYMBOL) = Nothing
1691
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_1) = Nothing
1692
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_2) = Nothing
1693
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_3) = Nothing
1694
                                oSymbolRow(_XML_SYMBOL_LMCONNECTOR_4) = Nothing
1695
                                oSymbolRow(_XML_SYMBOL_Check) = "False"
1696
                                oSymbolRow(_XML_SYMBOL_DRAWING_TF) = "False"
1697

    
1698
                            Next
1699

    
1700
                        End If
1701
                    Next
1702
                End If
1703
            Next
1704
        Next
1705
    End Sub
1706

    
1707

    
1708

    
1709

    
1710

    
1711
    Private Function UpdateCheckBranchLine(ByRef dX As Double, ByRef dY As Double,
1712
                                  ByRef oLMConnector As LMConnector, ByRef sUid As String) As Boolean
1713
        Dim oDataSource As LMADataSource = _Placement.PIDDataSource
1714
        Dim bCheckBranchItem As Boolean = False
1715
        Dim iGapCheck As Integer = 0
1716
        Try
1717
            For Each oModelrow In _ModelingLine_Dt.Rows
1718
                Dim d기준x As Double = dX
1719
                Dim d기준y As Double = dY
1720
                Dim dGap As Double = 0.001
1721
                Dim oRun As LMPipeRun = Nothing
1722
                Dim dModelStartX As Double
1723
                Dim dModelStartY As Double
1724
                Dim dModelEndX As Double
1725
                Dim dModelEndY As Double
1726
                dModelStartX = oModelrow(_XML_LINE_DWG_STARTPOINT_X)
1727
                dModelStartY = oModelrow(_XML_LINE_DWG_STARTPOINT_Y)
1728
                dModelEndX = oModelrow(_XML_LINE_DWG_ENDPOINT_X)
1729
                dModelEndY = oModelrow(_XML_LINE_DWG_ENDPOINT_Y)
1730
                d기준x = (dModelStartX + dModelEndX) / 2
1731
                d기준y = (dModelStartY + dModelEndY) / 2
1732

    
1733
                Dim dMax_X As Double = 0.0
1734
                Dim dMax_Y As Double = 0.0
1735
                Dim dMin_X As Double = 0.0
1736
                Dim dMin_Y As Double = 0.0
1737
                If dModelEndX > dModelStartX Then
1738
                    dMax_X = dModelEndX
1739
                    dMin_X = dModelStartX
1740
                Else
1741
                    dMax_X = dModelStartX
1742
                    dMin_X = dModelEndX
1743
                End If
1744

    
1745
                If dModelEndY > dModelStartY Then
1746
                    dMax_Y = dModelEndY
1747
                    dMin_Y = dModelStartY
1748
                Else
1749
                    dMax_Y = dModelStartY
1750
                    dMin_Y = dModelEndY
1751
                End If
1752

    
1753
                If dX <= dMax_X + dGap And dX >= dMin_X - dGap And
1754
                  dY <= dMax_Y + dGap And dY >= dMin_Y - dGap Then
1755
                    If Math.Abs(dMax_X - dMin_X) > Math.Abs(dMax_Y - dMin_Y) Then
1756
                        dY = dMax_Y
1757
                    Else
1758
                        dX = dMax_X
1759
                    End If
1760

    
1761
                    Try
1762
                        Dim sModelItemID As String = oModelrow(_XML_LINE_SPID).ToString()
1763
                        sUid = oModelrow(_XML_LINE_UID).ToString()
1764
                        oRun = oDataSource.GetPipeRun(sModelItemID)
1765
                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
1766
                    Catch ex As Exception
1767
                    End Try
1768
                    Try
1769
                        If oRun IsNot Nothing Then
1770
                            Dim dResultCalc As Double = -1
1771
                            Dim bBranchFlag As Boolean = False
1772
                            Dim dBranchX As Double = 0
1773
                            Dim dBranchY As Double = 0
1774
                            For Each objRep In oRun.Representations
1775
                                '  Dim sAttriName As String
1776
                                'For Each objAttr In objRep.Attributes
1777
                                '    sAttriName = objAttr.name
1778
                                'Next
1779
                                'MsgBox(objRep.RepresentationType)
1780
                                If objRep.RepresentationType = "Connector" Then
1781
                                    Dim objConnector As LMConnector = oDataSource.GetConnector(objRep.ID)
1782
                                    '     Dim sItemStatus As String = objConnector.Attributes("ItemStatus").Value
1783
                                    '   Dim sModelTypeName As String = objConnector.ModelItemObject.Attributes("ItemTypeName").Value
1784

    
1785
                                    'Dim dConn_SX As Double = 0
1786
                                    'Dim dConn_SY As Double = 0
1787
                                    'Dim dConn_EX As Double = 0
1788
                                    'Dim dConn_EY As Double = 0
1789
                                    Dim dConn_X As Double = 0
1790
                                    Dim dConn_Y As Double = 0
1791
                                    For Each objConnectorVertex In objConnector.ConnectorVertices
1792
                                        dConn_X = objConnectorVertex.Attributes("XCoordinate").Value
1793
                                        dConn_Y = objConnectorVertex.Attributes("YCoordinate").Value
1794
                                        'If dConn_SX = 0 Then
1795
                                        '    dConn_SX = objConnectorVertex.Attributes("XCoordinate").Value
1796
                                        '    dConn_SY = objConnectorVertex.Attributes("YCoordinate").Value
1797
                                        'Else
1798
                                        '    dConn_EX = objConnectorVertex.Attributes("XCoordinate").Value
1799
                                        '    dConn_EY = objConnectorVertex.Attributes("YCoordinate").Value
1800
                                        'End If
1801
                                        Dim dCalc As Double = Math.Abs(dConn_X - dX) + Math.Abs(dConn_Y - dY)
1802
                                        If bBranchFlag = False Then
1803
                                            If dResultCalc = -1 Or dResultCalc > dCalc Then
1804
                                                dResultCalc = dCalc
1805
                                                oLMConnector = objConnector
1806
                                                bCheckBranchItem = True
1807
                                            End If
1808
                                        Else
1809
                                            If (dConn_X >= dX And dBranchX <= dX And dConn_Y >= dY And dBranchY <= dY) Or
1810
                                               (dConn_X <= dX And dBranchX >= dX And dConn_Y <= dY And dBranchY >= dY) Then
1811
                                                If dResultCalc = -1 Or dResultCalc > dCalc Then
1812
                                                    dResultCalc = dCalc
1813
                                                    oLMConnector = objConnector
1814
                                                    bCheckBranchItem = True
1815
                                                End If
1816
                                            End If
1817
                                        End If
1818

    
1819

    
1820
                                        'If dConn_EX <> 0 And dConn_EY <> 0 Then
1821
                                        '    If dConn_SX >= dX And dConn_EX <= dX And dConn_SY >= dY And dConn_EY <= dY Then
1822
                                        '        oLMConnector = objConnector
1823
                                        '        Exit For
1824
                                        '    ElseIf dConn_SX <= dX And dConn_EX >= dX And dConn_SY <= dY And dConn_EY >= dY Then
1825
                                        '        oLMConnector = objConnector
1826
                                        '        Exit For
1827
                                        '    Else
1828
                                        '        If dConn_EX > 0 Then
1829
                                        '            dConn_SX = dConn_EX
1830
                                        '            dConn_SY = dConn_EY
1831
                                        '        End If
1832
                                        '    End If
1833
                                        'End If
1834

    
1835
                                    Next
1836
                                    'If oLMConnector IsNot Nothing Then
1837
                                    '    Exit For
1838
                                    'End If
1839
                                ElseIf objRep.RepresentationType = "Branch" Then
1840
                                    Dim objConnector As LMSymbol = oDataSource.GetSymbol(objRep.ID)
1841
                                    dBranchX = objConnector.Attributes("XCoordinate").Value
1842
                                    dBranchY = objConnector.Attributes("YCoordinate").Value
1843
                                    bBranchFlag = True
1844
                                End If
1845
                                'If objRep.Attributes("RepresentationType").Value = "Connector" And objRep.Attributes("ItemStatus").Value = "Active" Then
1846
                                '    Dim objConnector As LMConnector = _Placement.PIDDataSource.GetConnector(objRep.ID)
1847
                                '    For Each objConnectorVertex In objConnector.ConnectorVertices
1848
                                '        Dim dConn_X As Double = objConnectorVertex.Attributes("XCoordinate").Value
1849
                                '        Dim dConn_Y As Double = objConnectorVertex.Attributes("YCoordinate").Value
1850
                                '        If Math.Abs(dX - dConn_X) < dGap And Math.Abs(dY - dConn_Y) < dGap Then
1851
                                '            oLMConnector = objConnector
1852
                                '            dX = dConn_X
1853
                                '            dY = dConn_Y
1854
                                '            bConnectionFlag = True
1855
                                '        End If
1856
                                '    Next
1857
                                'End If
1858
                            Next
1859
                        End If
1860
                    Catch ex As Exception
1861
                    End Try
1862
                    '    oUid = oModelrow(_XML_LINE_UID).ToString()
1863
                    ' Dim oID As String = oModelrow(_XML_LINE_SPID)
1864
                    '    oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
1865
                    '    oID = oLMConnector.ModelItemID
1866
                    '  oLMConnector = _Placement.PIDDataSource.GetConnector(oID)
1867
                    'If oLMConnector IsNot Nothing Then
1868
                    '    Exit For
1869
                    'End If
1870
                End If
1871

    
1872

    
1873
            Next
1874
        Catch ex As Exception
1875
            bCheckBranchItem = False
1876
            oLMConnector = Nothing
1877
        End Try
1878
        Return bCheckBranchItem
1879
    End Function
1880

    
1881
    ''' <summary>
1882
    ''' 라인과 특정 포인트에 커넥션을 확인하는 메서드
1883
    ''' </summary>
1884
    ''' <param name="oModelingLineRows"></param>
1885
    ''' <param name="dX"></param>
1886
    ''' <param name="dY"></param>
1887
    ''' <param name="oLMConnector"></param>
1888
    ''' <param name="dPreConnX"></param>
1889
    ''' <param name="dPreConnY"></param>
1890
    ''' <returns></returns>
1891

    
1892
    Private Function CheckConnectionLine(ByRef dX As Double, ByRef dY As Double,
1893
                                  ByRef oLMConnector As LMConnector, ByRef sUid As String) As Boolean
1894
        Dim bConnectionFlag As Boolean = False
1895
        Dim iGapCheck As Integer = 0
1896
        Try
1897
            For Each oModelrow In _ModelingLine_Dt.Rows
1898
                Dim d기준x As Double = dX
1899
                Dim d기준y As Double = dY
1900
                Dim dGap As Double = 0.001
1901
                Dim oRun As LMPipeRun = Nothing
1902
                Dim dModelStartX As Double
1903
                Dim dModelStartY As Double
1904
                Dim dModelEndX As Double
1905
                Dim dModelEndY As Double
1906
                dModelStartX = oModelrow(_XML_LINE_DWG_STARTPOINT_X)
1907
                dModelStartY = oModelrow(_XML_LINE_DWG_STARTPOINT_Y)
1908
                dModelEndX = oModelrow(_XML_LINE_DWG_ENDPOINT_X)
1909
                dModelEndY = oModelrow(_XML_LINE_DWG_ENDPOINT_Y)
1910
                d기준x = (dModelStartX + dModelEndX) / 2
1911
                d기준y = (dModelStartY + dModelEndY) / 2
1912

    
1913
                Dim bCheckEqual As Boolean = False
1914
                If dX <= dModelStartX + dGap And dX >= dModelStartX - dGap And
1915
                        dY <= dModelStartY + dGap And dY >= dModelStartY - dGap Then
1916
                    bCheckEqual = True
1917
                ElseIf dX <= dModelEndX + dGap And dX >= dModelEndX - dGap And
1918
                        dY <= dModelEndY + dGap And dY >= dModelEndY - dGap Then
1919
                    bCheckEqual = True
1920
                End If
1921
                If bCheckEqual Then
1922
                    Try
1923
                        oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
1924
                        sUid = oModelrow(_XML_LINE_UID)
1925
                        oRun = _Placement.PIDDataSource.GetPipeRun(oLMConnector.ModelItemID)
1926
                    Catch ex As Exception
1927
                    End Try
1928
                    Try
1929
                        If oRun IsNot Nothing Then
1930
                            Dim dResultCalc As Double = -1
1931
                            For Each objRep In oRun.Representations
1932
                                If objRep.Attributes("RepresentationType").Value = "Connector" And objRep.Attributes("ItemStatus").Value = "Active" Then
1933
                                    Dim objConnector As LMConnector = _Placement.PIDDataSource.GetConnector(objRep.ID)
1934
                                    For Each objConnectorVertex In objConnector.ConnectorVertices
1935
                                        Dim dConn_X As Double = objConnectorVertex.Attributes("XCoordinate").Value
1936
                                        Dim dConn_Y As Double = objConnectorVertex.Attributes("YCoordinate").Value
1937
                                        If Math.Abs(dX - dConn_X) < dGap And Math.Abs(dY - dConn_Y) < dGap Then
1938
                                            oLMConnector = objConnector
1939
                                            dX = dConn_X
1940
                                            dY = dConn_Y
1941
                                            bConnectionFlag = True
1942
                                        End If
1943
                                    Next
1944
                                End If
1945
                            Next
1946
                        End If
1947
                    Catch ex As Exception
1948
                    End Try
1949
                Else
1950
                End If
1951
            Next
1952
        Catch ex As Exception
1953
            bConnectionFlag = False
1954
            oLMConnector = Nothing
1955
        End Try
1956
        Return bConnectionFlag
1957
    End Function
1958

    
1959
    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
1960
        '현재선의 방향을 보고 상대라인이 직교되는 방향인지 체크
1961
        '오차범위를 줘서 현재선을 통과하는지 체크
1962
        '통과하는 상대라인 갯수를 먼저 구한다음 라인 갯수만큼 라인을 그린다.
1963
        Dim bCheckBranchLine As Boolean = False
1964
        Dim sCurrentDirection As String = ""
1965

    
1966
        Dim oModel_Dt As New DataTable()
1967
        oModel_Dt.Columns.Add("X")
1968
        oModel_Dt.Columns.Add("Y")
1969
        oModel_Dt.Columns.Add("Type")
1970
        oModel_Dt.Columns.Add("SPID")
1971
        Dim dGap = 0.001
1972
        If Math.Abs(dStartX - dEndX) > Math.Abs(dStartY - dEndY) Then
1973
            sCurrentDirection = "X"
1974
            If dStartX > dEndX Then
1975
                Dim dTempX As Double = dEndX
1976
                dEndX = dStartX
1977
                dStartX = dTempX
1978
                Dim dTempY As Double = dEndY
1979
                dEndY = dStartY
1980
                dStartY = dTempY
1981
            End If
1982
            '현재선이 X축방향
1983
            Try
1984
                For Each oModelrow In _ModelingLine_Dt.Rows
1985
                    Dim dModelStart_X As Double = oModelrow(_XML_LINE_DWG_STARTPOINT_X)
1986
                    Dim dModelStart_Y As Double = oModelrow(_XML_LINE_DWG_STARTPOINT_Y)
1987
                    Dim dModelEnd_X As Double = oModelrow(_XML_LINE_DWG_ENDPOINT_X)
1988
                    Dim dModelEnd_Y As Double = oModelrow(_XML_LINE_DWG_ENDPOINT_Y)
1989
                    Dim sSPID As String = oModelrow(_XML_LINE_SPID)
1990
                    If dStartX < dModelStart_X And dStartX < dModelEnd_X And
1991
                       dEndX > dModelStart_X And dEndX > dModelEnd_X Then
1992
                        Dim dAddX As Double = dStartX
1993
                        Dim dAddY As Double = dStartY
1994
                        Dim sType As String = ""
1995
                        Dim dAddLineX As Double = 0
1996
                        Dim dAddLineY As Double = 0
1997
                        If dStartY = dModelStart_Y Then
1998
                            dAddX = 0
1999
                            '    dAddX = dModelStart_X
2000
                        ElseIf dStartY = dModelEnd_Y Then
2001
                            dAddX = 0
2002
                            '      dAddX = dModelEnd_X
2003
                        ElseIf dStartY <= dModelStart_Y + dGap And dStartY >= dModelStart_Y - dGap Then
2004
                            dAddX = dModelStart_X
2005
                            If dStartY <= dModelStart_Y Then
2006
                                sType = "AddLine"
2007
                                dAddLineX = dModelStart_X
2008
                                dAddLineY = dModelStart_Y
2009
                            End If
2010
                        ElseIf dStartY <= dModelEnd_Y + dGap And dStartY >= dModelEnd_Y - dGap Then
2011
                            dAddX = dModelEnd_X
2012
                            If dStartY <= dModelEnd_Y Then
2013
                                sType = "AddLine"
2014
                                dAddLineX = dModelEnd_X
2015
                                dAddLineY = dModelEnd_Y
2016
                            End If
2017
                        End If
2018
                        If sType = "AddLine" Then
2019
                            Dim objInputs As PlaceRunInputs
2020
                            objInputs = New PlaceRunInputs
2021
                            Dim oLMConnector As LMConnector = Nothing
2022
                            CheckConnectionLine(dAddLineX, dAddLineY, oLMConnector, "")
2023
                            objInputs.AddPoint(dAddLineX, dAddY)
2024
                            objInputs.AddConnectorTarget(oLMConnector, dAddLineX, dAddLineY)
2025
                            Dim AddLMConnector As LMConnector = LineModeling(objInputs, sSystemPath)
2026
                            JoinPipeRun(oLMConnector.ModelItemID, AddLMConnector.ModelItemID)
2027
                            dStartY = dAddY
2028
                        End If
2029

    
2030
                        If dAddX <> 0 Then
2031
                            Dim oDatarow As DataRow = oModel_Dt.NewRow()
2032
                            oDatarow("X") = dAddX
2033
                            oDatarow("Y") = dAddY
2034
                            oDatarow("Type") = sType
2035
                            oDatarow("SPID") = sSPID
2036
                            oModel_Dt.Rows.Add(oDatarow)
2037
                        End If
2038
                    End If
2039
                Next
2040
            Catch ex As Exception
2041
            End Try
2042
        Else
2043
            '현재선이 y축방향
2044
            sCurrentDirection = "Y"
2045
            Try
2046
                For Each oModelrow In _ModelingLine_Dt.Rows
2047
                    Dim dModelStart_X As Double = oModelrow(_XML_LINE_DWG_STARTPOINT_X)
2048
                    Dim dModelStart_Y As Double = oModelrow(_XML_LINE_DWG_STARTPOINT_Y)
2049
                    Dim dModelEnd_X As Double = oModelrow(_XML_LINE_DWG_ENDPOINT_X)
2050
                    Dim dModelEnd_Y As Double = oModelrow(_XML_LINE_DWG_ENDPOINT_Y)
2051
                    Dim sSPID As String = oModelrow(_XML_LINE_SPID)
2052
                    If dStartY < dModelStart_Y And dStartY < dModelEnd_Y And
2053
                       dEndY > dModelStart_Y And dEndY > dModelEnd_Y Then
2054
                        Dim dAddX As Double = dStartX
2055
                        Dim dAddY As Double = dStartY
2056
                        Dim sType As String = ""
2057
                        Dim dAddLineX As Double = 0
2058
                        Dim dAddLineY As Double = 0
2059
                        If dStartX = dModelStart_X Then
2060
                            dAddY = 0
2061
                            '       dAddY = dModelStart_Y
2062
                        ElseIf dStartX = dModelEnd_X Then
2063
                            dAddY = 0
2064
                            '        dAddY = dModelEnd_Y
2065
                        ElseIf dStartX <= dModelStart_X + dGap And dStartX >= dModelStart_X - dGap Then
2066
                            '         dAddY = dModelStart_Y
2067
                            If dStartX <= dModelStart_X Then
2068
                                dAddLineX = dModelStart_X
2069
                                dAddLineY = dModelStart_Y
2070
                                sType = "AddLine"
2071
                            End If
2072
                        ElseIf dStartX <= dModelEnd_X + dGap And dStartX >= dModelEnd_X - dGap Then
2073
                            '        dAddY = dModelEnd_Y
2074
                            If dStartX <= dModelEnd_X Then
2075
                                dAddLineX = dModelEnd_X
2076
                                dAddLineY = dModelEnd_Y
2077
                                sType = "AddLine"
2078
                            End If
2079
                        End If
2080
                        If sType = "AddLine" Then
2081
                            Dim objInputs As PlaceRunInputs
2082
                            objInputs = New PlaceRunInputs
2083
                            Dim oLMConnector As LMConnector = Nothing
2084
                            CheckConnectionLine(dAddLineX, dAddLineY, oLMConnector, "")
2085
                            objInputs.AddPoint(dAddX, dAddLineY)
2086
                            objInputs.AddConnectorTarget(oLMConnector, dAddLineX, dAddLineY)
2087
                            Dim AddLMConnector As LMConnector = LineModeling(objInputs, sSystemPath)
2088
                            JoinPipeRun(oLMConnector.ModelItemID, AddLMConnector.ModelItemID)
2089
                            dStartX = dAddX
2090
                        End If
2091

    
2092
                        If dAddY <> 0 Then
2093
                            Dim oDatarow As DataRow = oModel_Dt.NewRow()
2094
                            oDatarow("X") = dAddX
2095
                            oDatarow("Y") = dAddY
2096
                            oDatarow("Type") = sType
2097
                            oDatarow("SPID") = sSPID
2098
                            oModel_Dt.Rows.Add(oDatarow)
2099
                        End If
2100
                    End If
2101
                Next
2102
            Catch ex As Exception
2103
            End Try
2104
        End If
2105

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

    
2108
        If oModel_Dt.Rows.Count > 0 Then
2109
            If sCurrentDirection = "X" Then
2110
                'X좌표 정렬
2111
                oModel_Dt.DefaultView.Sort = "X desc"
2112
                oModel_Dt = oModel_Dt.DefaultView.ToTable(True)
2113
            Else
2114
                'Y좌표 정렬
2115
                oModel_Dt.DefaultView.Sort = "Y desc"
2116
                oModel_Dt = oModel_Dt.DefaultView.ToTable(True)
2117
            End If
2118
            Dim oLMConnector As LMConnector = Nothing
2119
            Dim oPreLMConnector As LMConnector = Nothing
2120
            Dim dStartFlag As Boolean = True
2121
            For Each oModelRow In oModel_Dt.Rows
2122
                Dim objInputs As PlaceRunInputs
2123
                objInputs = New PlaceRunInputs
2124
                Dim dX As Double = oModelRow("X")
2125
                Dim dY As Double = oModelRow("Y")
2126
                Dim sType As String = oModelRow("Type")
2127
                Dim sUid As String = ""
2128

    
2129

    
2130
                CheckConnectionLine(dX, dY, oLMConnector, sUid)
2131
                If oLMConnector IsNot Nothing Then
2132
                    If dStartFlag Then
2133
                        objInputs.AddPoint(dStartX, dStartY)
2134
                        objInputs.AddConnectorTarget(oLMConnector, dX, dY)
2135
                    Else
2136
                        objInputs.AddConnectorTarget(oPreLMConnector, dStartX, dStartY)
2137
                        objInputs.AddConnectorTarget(oLMConnector, dX, dY)
2138
                    End If
2139
                    oPreLMConnector = LineModeling(objInputs, sSystemPath)
2140
                    '모델링후 StartX를 현재 X로 변경
2141
                    dStartX = dX
2142
                    dStartY = dY
2143
                End If
2144
            Next
2145
            If oPreLMConnector IsNot Nothing Then
2146
                Dim objInputs As PlaceRunInputs
2147
                objInputs = New PlaceRunInputs
2148
                objInputs.AddConnectorTarget(oPreLMConnector, dStartX, dStartY)
2149
                objInputs.AddPoint(dEndX, dEndY)
2150
                LineModeling(objInputs, sSystemPath)
2151
            End If
2152
        End If
2153
        Return bCheckBranchLine
2154
    End Function
2155

    
2156

    
2157
    Private Function CheckLineBranch(ByVal oLine_Dt As DataTable, ByRef dX As Double, ByRef dY As Double,
2158
                                     ByVal sDirection As String, ByRef oLMConnector As LMConnector) As Boolean
2159

    
2160
        Dim oModelingLineRows() As DataRow = oLine_Dt.Select(" Then[" & _XML_LINE_DRAWING_TF & "] = 'TRUE' And " &
2161
                                                                "[" & _XML_LINE_SPID & "] <> ''")
2162

    
2163
        Dim bConnectionFlag As Boolean = False
2164
        Try
2165
            For Each oModelrow In oModelingLineRows
2166
                Dim sStartPoint As String = oModelrow(_XML_LINE_STARTPOINT)
2167
                Dim sEndPoint As String = oModelrow(_XML_LINE_ENDPOINT)
2168
                Dim dModelStartX As Double
2169
                Dim dModelStartY As Double
2170
                Dim dModelEndX As Double
2171
                Dim dModelEndY As Double
2172
                ConvertPointBystring(sStartPoint, dModelStartX, dModelStartY)
2173
                ConvertPointBystring(sEndPoint, dModelEndX, dModelEndY)
2174
                ConvertPointByImage(dModelStartX, dModelStartY, _IMG_X, _IMG_Y)
2175
                ConvertPointByImage(dModelEndX, dModelEndY, _IMG_X, _IMG_Y)
2176
                Dim dGap As Double = 0.0002
2177

    
2178
                If Math.Abs(dModelStartX - dModelEndX) <= Math.Abs(dModelStartY - dModelEndY) Then
2179
                    'Vertical
2180
                    If sDirection = "X" Then
2181
                        'x Direction Line
2182
                        If (dModelStartY + dGap >= dY And dModelEndY - dGap <= dY) Or
2183
                        (dModelStartY - dGap <= dY And dModelEndY + dGap >= dY) Then
2184
                            If (dX > dModelStartX And dX < dModelEndX) Or (dX > dModelEndX And dX < dModelStartX) Then
2185
                                If Math.Abs(dX - dModelStartX) > Math.Abs(dX - dModelEndX) Then
2186
                                    dX = dModelEndX
2187
                                Else
2188
                                    dX = dModelStartX
2189
                                End If
2190
                                Try
2191
                                    oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
2192
                                Catch ex As Exception
2193

    
2194
                                End Try
2195
                                bConnectionFlag = True
2196
                            End If
2197
                        End If
2198
                    End If
2199
                Else
2200
                    'Horizontal 
2201
                    If sDirection = "Y" Then
2202
                        If (dModelStartX + dGap >= dX And dModelEndX - dGap <= dX) Or
2203
                       (dModelStartX - dGap <= dX And dModelEndX + dGap >= dX) Then
2204
                            If (dY > dModelStartY And dY < dModelEndY) Or (dY > dModelEndY And dY < dModelStartY) Then
2205
                                If Math.Abs(dY - dModelStartY) > Math.Abs(dY - dModelEndY) Then
2206
                                    dY = dModelEndY
2207
                                Else
2208
                                    dY = dModelStartY
2209
                                End If
2210
                                Try
2211
                                    oLMConnector = oModelrow(_XML_LINE_LMCONNECTOR)
2212
                                Catch ex As Exception
2213
                                End Try
2214
                                bConnectionFlag = True
2215
                            End If
2216
                        End If
2217
                    End If
2218
                End If
2219
            Next
2220
        Catch ex As Exception
2221
        End Try
2222
        Return bConnectionFlag
2223
    End Function
2224
    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,
2225
                              ByVal sLineNoUid As String, ByVal sLineUid As String, ByVal sSystemPath As String, ByRef oLMConnector As LMConnector) As Boolean
2226
        'Try
2227
        '    Dim oDatasource As Object = _Placement.PIDDataSource
2228
        '    Dim oPipeRun As LMPipeRun = Nothing
2229
        '    Dim objInputs As PlaceRunInputs
2230
        '    objInputs = New PlaceRunInputs
2231
        '    Dim objItem As LMAItem
2232
        '    '       Dim objConnector As LMConnector
2233

    
2234
        '    Dim oStartLineRow() As DataRow = oLine_Dt.Select("[" & _XML_LINE_Conn1_Uid & "] = '" & sStartLineUid & "' And " &
2235
        '                                                            "[" & _XML_LINE_DRAWING_TF & "] = 'TRUE' And" &
2236
        '                                                                  "[" & _XML_LINE_SPID & "] <> ''")
2237
        '    If oStartLineRow.Length = 0 Then
2238
        '        oStartLineRow = oLine_Dt.Select("[" & _XML_LINE_Conn2_Uid & "] = '" & sStartLineUid & "' And " &
2239
        '                                                            "[" & _XML_LINE_DRAWING_TF & "] = 'TRUE' And" &
2240
        '                                                                  "[" & _XML_LINE_SPID & "] <> ''")
2241
        '    End If
2242
        '    Dim oEndLineRow() As DataRow = oLine_Dt.Select("[" & _XML_LINE_Conn1_Uid & "] = '" & sEndLineUid & "' And " &
2243
        '                                                            "[" & _XML_LINE_DRAWING_TF & "] = 'TRUE' And" &
2244
        '                                                                  "[" & _XML_LINE_SPID & "] <> ''")
2245

    
2246
        '    oEndLineRow = oLine_Dt.Select("[" & _XML_LINE_Conn2_Uid & "] = '" & sEndLineUid & "' And " &
2247
        '                                                            "[" & _XML_LINE_DRAWING_TF & "] = 'TRUE' And" &
2248
        '                                                                  "[" & _XML_LINE_SPID & "] <> ''")
2249
        '    Dim sStartConnectionType As String = ""
2250
        '    Dim sEndConnectionType As String = ""
2251

    
2252
        '    Dim oStartLMConnector As LMConnector = Nothing
2253
        '    Dim oEndLMConnector As LMConnector = Nothing
2254
        '    Dim oDirectionLine As String = ""
2255

    
2256
        '    If Math.Abs(dStart_x - dEnd_x) > Math.Abs(dStart_y - dEnd_y) Then
2257
        '        oDirectionLine = "X"
2258
        '    Else
2259
        '        oDirectionLine = "Y"
2260
        '    End If
2261

    
2262
        '    Dim bCheckFlag As Boolean = False
2263

    
2264
        '    Dim bStartCheckFlag As Boolean = CheckConnectionLine(oStartLineRow, dStart_x, dStart_y, oStartLMConnector)
2265
        '    If bStartCheckFlag = False Then
2266
        '        bStartCheckFlag = CheckConnectionLine(oStartLineRow, dEnd_x, dEnd_y, oStartLMConnector)
2267
        '        bCheckFlag = True
2268
        '    End If
2269
        '    Dim bEndCheckFlag As Boolean = CheckConnectionLine(oEndLineRow, dEnd_x, dEnd_y, oEndLMConnector)
2270

    
2271
        '    If bEndCheckFlag = False Then
2272

    
2273
        '        bEndCheckFlag = CheckConnectionLine(oEndLineRow, dStart_x, dStart_y, oEndLMConnector)
2274
        '        bCheckFlag = True
2275
        '    End If
2276

    
2277
        '    If bStartCheckFlag = True And bEndCheckFlag = False Then
2278
        '        If bCheckFlag Then
2279
        '            objInputs.AddConnectorTarget(oStartLMConnector, dEnd_x, dEnd_y)
2280
        '            objInputs.AddPoint(dStart_x, dStart_y)
2281
        '        Else
2282
        '            objInputs.AddConnectorTarget(oStartLMConnector, dStart_x, dStart_y)
2283
        '            objInputs.AddPoint(dEnd_x, dEnd_y)
2284
        '        End If
2285

    
2286
        '    ElseIf bStartCheckFlag = False And bEndCheckFlag = True Then
2287
        '        If bCheckFlag Then
2288

    
2289
        '            objInputs.AddConnectorTarget(oStartLMConnector, dStart_x, dStart_y)
2290
        '            objInputs.AddPoint(dEnd_x, dEnd_y)
2291
        '        Else
2292
        '            objInputs.AddPoint(dStart_x, dStart_y)
2293
        '            objInputs.AddConnectorTarget(oStartLMConnector, dEnd_x, dEnd_y)
2294
        '        End If
2295

    
2296
        '    ElseIf bStartCheckFlag = True And bEndCheckFlag = True Then
2297
        '        objInputs.AddConnectorTarget(oStartLMConnector, dStart_x, dStart_y)
2298
        '        objInputs.AddConnectorTarget(oEndLMConnector, dEnd_x, dEnd_y)
2299
        '    Else
2300
        '        objInputs.AddPoint(dStart_x, dStart_y)
2301
        '        objInputs.AddPoint(dEnd_x, dEnd_y)
2302
        '    End If
2303
        '    SetListBoxItems(ListBox_Result, "Place Pipe..(" & dStart_x & "," & dStart_y & ") - (" & dEnd_x & "," & dEnd_y & ")..." & _iPipecnt & " count ")
2304
        '    _iPipecnt = _iPipecnt + 1
2305
        '    objItem = _Placement.PIDCreateItem(sSystemPath)
2306
        '    oLMConnector = _Placement.PIDPlaceRun(objItem, objInputs)
2307

    
2308
        '    Dim oUpdateRow As DataRow() = oLine_Dt.Select(_XML_LINE_UID & " = '" + sLineUid + "'")
2309
        '    If oUpdateRow.Length = 1 Then
2310
        '        oUpdateRow(0)(_XML_LINE_SPID) = oLMConnector.ModelItemID
2311
        '        oUpdateRow(0)(_XML_LINE_LMCONNECTOR) = oLMConnector
2312

    
2313
        '        oUpdateRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
2314
        '    End If
2315

    
2316
        '    oPipeRun = oDatasource.GetPipeRun(oLMConnector.ModelItemID)
2317

    
2318
        '    Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
2319
        '    If oAttributeRow.Length > 0 Then
2320
        '        For Each oAttribute In oAttributeRow
2321
        '            Try
2322
        '                Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
2323
        '                Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
2324
        '                If sPIDValue.Contains("'") Then
2325
        '                    sPIDValue = sPIDValue.Replace("'", """")
2326
        '                End If
2327
        '                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
2328
        '                oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
2329
        '            Catch ex As Exception
2330
        '            End Try
2331
        '        Next
2332
        '        oPipeRun.Commit()
2333
        '    End If
2334
        '    Dim sID_1 As String = ""
2335
        '    Dim sID_2 As String = ""
2336
        '    If oStartLMConnector IsNot Nothing Then
2337
        '        sID_1 = oStartLMConnector.ModelItemID
2338
        '        sID_2 = oLMConnector.ModelItemID
2339
        '    ElseIf oEndLMConnector IsNot Nothing Then
2340
        '        sID_1 = oEndLMConnector.ModelItemID
2341
        '        sID_2 = oLMConnector.ModelItemID
2342
        '    End If
2343
        '    If sID_1 <> "" And sID_2 <> "" Then
2344
        '        Dim objSurvivorItem As LMAItem = Nothing
2345
        '        Dim oPipeRun1 As LMPipeRun = oDatasource.GetPipeRun(sID_1)
2346
        '        Dim oPipeRun2 As LMPipeRun = oDatasource.GetPipeRun(sID_2)
2347
        '        _Placement.PIDJoinRuns(oPipeRun1, oPipeRun2)
2348
        '    End If
2349
        '    Return True
2350
        'Catch ex As Exception
2351
        '    Return False
2352
        'End Try
2353

    
2354
    End Function
2355

    
2356
    Private Function LineToLineModeling(ByVal sLineNoUid As String, ByVal oLine_Dt As DataTable,
2357
                                        ByVal oAttribute_Dt As DataTable, ByVal sConnLineUid As String, ByVal sType As String,
2358
                                        ByRef oLMConnector As LMConnector) As String
2359
        Dim sReturnUid As String = ""
2360
        Try
2361
            Dim sLineUid As String = ""
2362

    
2363
            Dim iConnType As Integer = 0
2364

    
2365
            Dim sStartpoint As String = ""
2366
            Dim sEndpoint As String = ""
2367
            Dim dOriginalStart_x As Double = 0.0
2368
            Dim dOriginalStart_y As Double = 0.0
2369
            Dim dOriginalEnd_x As Double = 0.0
2370
            Dim dOriginalEnd_y As Double = 0.0
2371

    
2372
            Dim dStart_x As Double = 0
2373
            Dim dStart_y As Double = 0
2374
            Dim dEnd_x As Double = 0
2375
            Dim dEnd_y As Double = 0
2376
            Dim sStartLineUid As String = sConnLineUid
2377
            Dim sEndLineUid As String = ""
2378
            Dim sDirection As String = ""
2379
            Dim sSystemPath As String = GetPipeType(sType)
2380

    
2381
            Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_UID & " = '" & sConnLineUid & "' And " &
2382
                                                                    "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
2383
                                                                     "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
2384
                                                                     "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
2385
            If oPipeRow.Length > 0 Then
2386
                sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
2387
                sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
2388
                ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
2389
                ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
2390
                ConvertPointByImage(dOriginalStart_x, dOriginalStart_y, _IMG_X, _IMG_Y)
2391
                ConvertPointByImage(dOriginalEnd_x, dOriginalEnd_y, _IMG_X, _IMG_Y)
2392
                If dStart_x = 0 And dStart_y = 0 Then
2393
                    dStart_x = dOriginalStart_x
2394
                    dStart_y = dOriginalStart_y
2395
                    dEnd_x = dOriginalEnd_x
2396
                    dEnd_y = dOriginalEnd_y
2397
                    If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
2398
                        sDirection = "X"
2399
                    Else
2400
                        sDirection = "Y"
2401
                    End If
2402
                    oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
2403
                    sLineUid = sConnLineUid
2404
                End If
2405
            End If
2406

    
2407
            While True
2408
                sLineUid = ""
2409
                oPipeRow = oLine_Dt.Select(_XML_LINE_Conn1_Uid & " = '" + sConnLineUid + "' And " &
2410
                                            "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
2411
                                            "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
2412
                                            "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
2413

    
2414
                If oPipeRow.Length = 0 Then
2415
                    oPipeRow = oLine_Dt.Select(_XML_LINE_Conn2_Uid & " = '" + sConnLineUid + "' And " &
2416
                                            "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
2417
                                            "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
2418
                                            "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
2419
                Else
2420
                    'sLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
2421
                    'sConnLineUid = sLineUid
2422
                    sLineUid = sConnLineUid
2423
                    sConnLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
2424
                    iConnType = 1
2425
                End If
2426

    
2427
                If oPipeRow.Length > 0 Then
2428
                    If sLineUid = "" Then
2429
                        'sLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
2430
                        'sConnLineUid = sLineUid
2431
                        sLineUid = sConnLineUid
2432
                        sConnLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
2433
                        iConnType = 2
2434
                    End If
2435
                    If iConnType = 1 Then
2436

    
2437
                    ElseIf iConnType = 2 Then
2438

    
2439
                    End If
2440
                    sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
2441
                    sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
2442
                    ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
2443
                    ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
2444
                    ConvertPointByImage(dOriginalStart_x, dOriginalStart_y, _IMG_X, _IMG_Y)
2445
                    ConvertPointByImage(dOriginalEnd_x, dOriginalEnd_y, _IMG_X, _IMG_Y)
2446

    
2447
                    If dStart_x = 0 And dStart_y = 0 Then
2448
                        dStart_x = dOriginalStart_x
2449
                        dStart_y = dOriginalStart_y
2450
                        dEnd_x = dOriginalEnd_x
2451
                        dEnd_y = dOriginalEnd_y
2452
                        If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
2453
                            sDirection = "X"
2454
                        Else
2455
                            sDirection = "Y"
2456
                        End If
2457
                        sType = oPipeRow(0)(_XML_LINE_TYPE).ToString()
2458
                        sSystemPath = GetPipeType(sType)
2459
                    Else
2460
                        If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
2461
                            If sDirection = "Y" Then
2462
                                '방향이 바꼈음 Y - > X
2463
                                LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
2464
                                sLineNoUid, sLineUid, sSystemPath, oLMConnector)
2465
                                dStart_x = dOriginalStart_x
2466
                                dStart_y = dOriginalStart_y
2467
                                dEnd_x = dOriginalEnd_x
2468
                                dEnd_y = dOriginalEnd_y
2469
                                sStartLineUid = sConnLineUid
2470
                            Else
2471
                                dEnd_x = dOriginalEnd_x
2472
                                dEnd_y = dOriginalEnd_y
2473
                            End If
2474
                            sDirection = "X"
2475
                        Else
2476
                            If sDirection = "X" Then
2477
                                '방향이 바꼈음 X - > Y
2478
                                LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
2479
                                sLineNoUid, sLineUid, sSystemPath, oLMConnector)
2480
                                dStart_x = dOriginalStart_x
2481
                                dStart_y = dOriginalStart_y
2482
                                dEnd_x = dOriginalEnd_x
2483
                                dEnd_y = dOriginalEnd_y
2484
                                sStartLineUid = sConnLineUid
2485
                            Else
2486

    
2487
                                dEnd_x = dOriginalEnd_x
2488
                                dEnd_y = dOriginalEnd_y
2489
                            End If
2490
                            sDirection = "Y"
2491
                        End If
2492
                    End If
2493
                    '            oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
2494
                Else
2495
                    If dStart_x <> 0 And dStart_y <> 0 And dEnd_x <> 0 And dEnd_y <> 0 Then
2496
                        LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
2497
                         sLineNoUid, sLineUid, sSystemPath, oLMConnector)
2498
                    End If
2499
                    sReturnUid = sConnLineUid
2500
                    Exit While
2501
                End If
2502
            End While
2503

    
2504
            If sStartLineUid <> "" And sEndLineUid <> "" Then
2505
                LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
2506
                             sLineNoUid, sLineUid, sSystemPath, oLMConnector)
2507
                dStart_x = 0
2508
                dStart_y = 0
2509
                dEnd_x = 0
2510
                dEnd_y = 0
2511
            End If
2512
        Catch ex As Exception
2513

    
2514
        End Try
2515

    
2516
        Return sReturnUid
2517
    End Function
2518

    
2519

    
2520
    'Private Function LineToLineModeling(ByVal sLineNoUid As String, ByVal oLine_Dt As DataTable,
2521
    '                                    ByVal oAttribute_Dt As DataTable, ByVal sConnLineUid As String, ByVal sType As String) As String
2522
    '    Dim sReturnUid As String = ""
2523
    '    Try
2524
    '        Dim sLineUid As String = ""
2525

    
2526
    '        Dim iConnType As Integer = 0
2527

    
2528
    '        Dim sStartpoint As String = ""
2529
    '        Dim sEndpoint As String = ""
2530
    '        Dim dOriginalStart_x As Double = 0.0
2531
    '        Dim dOriginalStart_y As Double = 0.0
2532
    '        Dim dOriginalEnd_x As Double = 0.0
2533
    '        Dim dOriginalEnd_y As Double = 0.0
2534

    
2535
    '        Dim dStart_x As Double = 0
2536
    '        Dim dStart_y As Double = 0
2537
    '        Dim dEnd_x As Double = 0
2538
    '        Dim dEnd_y As Double = 0
2539
    '        Dim sStartLineUid As String = sConnLineUid
2540
    '        Dim sEndLineUid As String = ""
2541
    '        Dim sDirection As String = ""
2542
    '        Dim sSystemPath As String = GetPipeType(sType)
2543

    
2544
    '        Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_UID & " = '" & sConnLineUid & "' And " &
2545
    '                                                                "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
2546
    '                                                                 "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
2547
    '                                                                 "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
2548
    '        If oPipeRow.Length > 0 Then
2549
    '            sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
2550
    '            sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
2551
    '            ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
2552
    '            ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
2553
    '            ConvertPointByImage(dOriginalStart_x, dOriginalStart_y, _IMG_X, _IMG_Y)
2554
    '            ConvertPointByImage(dOriginalEnd_x, dOriginalEnd_y, _IMG_X, _IMG_Y)
2555
    '            If dStart_x = 0 And dStart_y = 0 Then
2556
    '                dStart_x = dOriginalStart_x
2557
    '                dStart_y = dOriginalStart_y
2558
    '                dEnd_x = dOriginalEnd_x
2559
    '                dEnd_y = dOriginalEnd_y
2560
    '                If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
2561
    '                    sDirection = "X"
2562
    '                Else
2563
    '                    sDirection = "Y"
2564
    '                End If
2565
    '                oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
2566
    '                sLineUid = sConnLineUid
2567
    '            End If
2568
    '        End If
2569

    
2570
    '        While True
2571
    '            sLineUid = ""
2572
    '            oPipeRow = oLine_Dt.Select(_XML_LINE_Conn1_Uid & " = '" + sConnLineUid + "' And " &
2573
    '                                                                "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
2574
    '                                                                         "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
2575
    '                                                                         "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
2576

    
2577
    '            If oPipeRow.Length = 0 Then
2578
    '                oPipeRow = oLine_Dt.Select(_XML_LINE_Conn2_Uid & " = '" + sConnLineUid + "' And " &
2579
    '                                         "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And" &
2580
    '                                       "[" & _XML_SYMBOL_Check & "] = 'TRUE' And " &
2581
    '                                      "[" & _XML_SYMBOL_TYPE & "] = '" & sType & "'")
2582
    '            Else
2583
    '                'sLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
2584
    '                'sConnLineUid = sLineUid
2585
    '                sLineUid = sConnLineUid
2586
    '                sConnLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
2587
    '                iConnType = 1
2588
    '            End If
2589

    
2590
    '            If oPipeRow.Length > 0 Then
2591
    '                If sLineUid = "" Then
2592
    '                    'sLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
2593
    '                    'sConnLineUid = sLineUid
2594
    '                    sLineUid = sConnLineUid
2595
    '                    sConnLineUid = oPipeRow(0)(_XML_LINE_UID).ToString()
2596
    '                    iConnType = 2
2597
    '                End If
2598
    '                If iConnType = 1 Then
2599

    
2600
    '                ElseIf iConnType = 2 Then
2601

    
2602
    '                End If
2603
    '                sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
2604
    '                sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
2605
    '                ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
2606
    '                ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
2607
    '                ConvertPointByImage(dOriginalStart_x, dOriginalStart_y, _IMG_X, _IMG_Y)
2608
    '                ConvertPointByImage(dOriginalEnd_x, dOriginalEnd_y, _IMG_X, _IMG_Y)
2609

    
2610

    
2611

    
2612
    '                If dStart_x = 0 And dStart_y = 0 Then
2613
    '                    dStart_x = dOriginalStart_x
2614
    '                    dStart_y = dOriginalStart_y
2615
    '                    dEnd_x = dOriginalEnd_x
2616
    '                    dEnd_y = dOriginalEnd_y
2617
    '                    If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
2618
    '                        sDirection = "X"
2619
    '                    Else
2620
    '                        sDirection = "Y"
2621
    '                    End If
2622
    '                    sType = oPipeRow(0)(_XML_LINE_TYPE).ToString()
2623
    '                    sSystemPath = GetPipeType(sType)
2624
    '                Else
2625
    '                    If Math.Abs(dOriginalStart_x - dOriginalEnd_x) > Math.Abs(dOriginalStart_y - dOriginalEnd_y) Then
2626
    '                        If sDirection = "Y" Then
2627
    '                            '방향이 바꼈음 Y - > X
2628
    '                            LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
2629
    '                            sLineNoUid, sLineUid, sSystemPath)
2630
    '                            dStart_x = dOriginalStart_x
2631
    '                            dStart_y = dOriginalStart_y
2632
    '                            dEnd_x = dOriginalEnd_x
2633
    '                            dEnd_y = dOriginalEnd_y
2634
    '                            sStartLineUid = sConnLineUid
2635
    '                        Else
2636
    '                            dEnd_x = dOriginalEnd_x
2637
    '                            dEnd_y = dOriginalEnd_y
2638
    '                        End If
2639
    '                        sDirection = "X"
2640
    '                    Else
2641
    '                        If sDirection = "X" Then
2642
    '                            '방향이 바꼈음 X - > Y
2643
    '                            LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
2644
    '                            sLineNoUid, sLineUid, sSystemPath)
2645
    '                            dStart_x = dOriginalStart_x
2646
    '                            dStart_y = dOriginalStart_y
2647
    '                            dEnd_x = dOriginalEnd_x
2648
    '                            dEnd_y = dOriginalEnd_y
2649
    '                            sStartLineUid = sConnLineUid
2650
    '                        Else
2651

    
2652
    '                            dEnd_x = dOriginalEnd_x
2653
    '                            dEnd_y = dOriginalEnd_y
2654
    '                        End If
2655
    '                        sDirection = "Y"
2656
    '                    End If
2657
    '                End If
2658
    '                '            oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
2659
    '            Else
2660
    '                If dStart_x <> 0 And dStart_y <> 0 And dEnd_x <> 0 And dEnd_y <> 0 Then
2661
    '                    LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
2662
    '                     sLineNoUid, sLineUid, sSystemPath)
2663
    '                End If
2664

    
2665

    
2666
    '                sReturnUid = sConnLineUid
2667
    '                Exit While
2668
    '            End If
2669
    '        End While
2670

    
2671
    '        If sStartLineUid <> "" And sEndLineUid <> "" Then
2672
    '            LineModeling(oLine_Dt, oAttribute_Dt, sStartLineUid, sEndLineUid, dStart_x, dStart_y, dEnd_x, dEnd_y,
2673
    '                         sLineNoUid, sLineUid, sSystemPath)
2674
    '            dStart_x = 0
2675
    '            dStart_y = 0
2676
    '            dEnd_x = 0
2677
    '            dEnd_y = 0
2678
    '        End If
2679
    '    Catch ex As Exception
2680

    
2681
    '    End Try
2682

    
2683
    '    Return sReturnUid
2684
    'End Function
2685

    
2686

    
2687
    Private Function SymbolToLine_Modeling(ByVal oLine_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal sLineNoUid As String,
2688
                                       ByVal sSymbolUid As String, ByVal oLMSymbol As LMSymbol) As String
2689

    
2690

    
2691
        Dim oDatasource As Object = _Placement.PIDDataSource
2692
        Dim oPipeRun As LMPipeRun = Nothing
2693
        Dim objItem As LMAItem
2694
        Dim objConnector As LMConnector
2695
        Dim objInputs As PlaceRunInputs
2696
        objInputs = New PlaceRunInputs
2697

    
2698

    
2699
        Dim sPipeUid As String = ""
2700
        Dim iConnType As Integer = 0
2701
        Dim sStartpoint As String = ""
2702
        Dim sEndpoint As String = ""
2703
        Dim dOriginalStart_x As Double = 0.0
2704
        Dim dOriginalStart_y As Double = 0.0
2705
        Dim dOriginalEnd_x As Double = 0.0
2706
        Dim dOriginalEnd_y As Double = 0.0
2707
        Dim dStart_x As Double = 0.0
2708
        Dim dStart_y As Double = 0.0
2709
        Dim dEnd_x As Double = 0.0
2710
        Dim dEnd_y As Double = 0.0
2711

    
2712
        Dim sReturnUid As String = ""
2713
        Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_Conn1_Uid & " = '" + sSymbolUid + "' And " &
2714
                                                                        "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
2715
                                                                                  _XML_SYMBOL_Check & "] = 'TRUE'")
2716
        If oPipeRow.Length = 0 Then
2717
            oPipeRow = oLine_Dt.Select(_XML_LINE_Conn2_Uid & " = '" + sSymbolUid + "' And " &
2718
                                     "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
2719
                                    _XML_SYMBOL_Check & "] = 'TRUE'")
2720
        Else
2721
            sPipeUid = oPipeRow(0)(_XML_LINE_UID).ToString()
2722
            iConnType = 1
2723
        End If
2724

    
2725
        If oPipeRow.Length = 1 Then
2726
            If sPipeUid = "" Then
2727
                sPipeUid = oPipeRow(0)(_XML_LINE_UID).ToString()
2728
                iConnType = 2
2729
            End If
2730
            sReturnUid = oPipeRow(0)(_XML_LINE_UID).ToString()
2731
            sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
2732
            sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
2733
            ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
2734
            dStart_x = dOriginalStart_x
2735
            dStart_y = dOriginalStart_y
2736
            ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
2737
            dEnd_x = dOriginalEnd_x
2738
            dEnd_y = dOriginalEnd_y
2739
            ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
2740
            ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
2741
            'OPC Connection Point가져와서 연결(2018-07-12)
2742
            If iConnType = 1 Then
2743
                FindNearPoint(oLMSymbol, dStart_x, dStart_y)
2744
                objInputs.AddSymbolTarget(oLMSymbol, dStart_x, dStart_y)
2745
                objInputs.AddPoint(dEnd_x, dEnd_y)
2746
            Else
2747
                FindNearPoint(oLMSymbol, dEnd_x, dEnd_y)
2748
                objInputs.AddSymbolTarget(oLMSymbol, dEnd_x, dEnd_y)
2749
                objInputs.AddPoint(dStart_x, dStart_y)
2750
            End If
2751
            oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
2752

    
2753
            Dim sType As String = oPipeRow(0)(_XML_LINE_TYPE).ToString()
2754
            Dim sSystemPath As String = GetPipeType(sType)
2755

    
2756

    
2757

    
2758

    
2759
            objItem = _Placement.PIDCreateItem(sSystemPath)
2760
            objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
2761
            oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
2762
            Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
2763
            If oAttributeRow.Length > 0 Then
2764
                For Each oAttribute In oAttributeRow
2765
                    Try
2766
                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
2767
                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
2768
                        If sPIDValue.Contains("'") Then
2769
                            sPIDValue = sPIDValue.Replace("'", """")
2770
                        End If
2771
                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
2772
                        oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
2773
                    Catch ex As Exception
2774
                    End Try
2775
                Next
2776
                oPipeRun.Commit()
2777
            End If
2778
        End If
2779
        Return sReturnUid
2780
    End Function
2781

    
2782
    Private Function LineToSymbol_Modeling(ByVal oSymbol_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal sLineNoUid As String,
2783
                                       ByVal sLineUid As String, ByVal oLMConnector As LMConnector, ByRef oLMSymbol As LMSymbol) As String
2784

    
2785

    
2786
        Dim oDatasource As Object = _Placement.PIDDataSource
2787
        Dim objItem As LMAItem
2788
        Dim objConnector As LMConnector
2789
        Dim objInputs As PlaceRunInputs
2790
        objInputs = New PlaceRunInputs
2791

    
2792

    
2793
        Dim sSymbolUid As String = ""
2794
        Dim iConnType As Integer = 0
2795
        Dim dOriginalPoint_x As Double = 0.0
2796
        Dim dORiginalPoint_y As Double = 0.0
2797
        Dim dX As Double = 0.0
2798
        Dim dY As Double = 0.0
2799
        Dim sReturnUid As String = ""
2800
        Dim oSymbolRow() As DataRow = oSymbol_Dt.Select(_XML_SYMBOL_Conn1_Uid & " = '" + sLineUid + "' And " &
2801
                                                                        "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
2802
                                                                                  _XML_SYMBOL_Check & "] = 'TRUE'")
2803
        If oSymbolRow.Length = 0 Then
2804
            oSymbolRow = oSymbol_Dt.Select(_XML_SYMBOL_Conn2_Uid & " = '" + sLineUid + "' And " &
2805
                                                                        "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
2806
                                                                                 _XML_SYMBOL_Check & "] = 'TRUE'")
2807
            If oSymbolRow.Length = 0 Then
2808
                oSymbolRow = oSymbol_Dt.Select(_XML_SYMBOL_Conn2_Uid & " = '" + sLineUid + "' And " &
2809
                                                                 "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
2810
                                                                          _XML_SYMBOL_Check & "] = 'TRUE'")
2811
                If oSymbolRow.Length = 0 Then
2812
                    oSymbolRow = oSymbol_Dt.Select(_XML_SYMBOL_Conn2_Uid & " = '" + sLineUid + "' And " &
2813
                                                   "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' " &
2814
                                                            _XML_SYMBOL_Check & "] = 'TRUE'")
2815
                    If oSymbolRow.Length = 0 Then
2816

    
2817
                    Else
2818
                        sSymbolUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
2819
                        iConnType = 4
2820
                    End If
2821
                Else
2822
                    sSymbolUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
2823
                    iConnType = 3
2824
                End If
2825
            Else
2826
                sSymbolUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
2827
                iConnType = 2
2828
            End If
2829

    
2830
        Else
2831
            sSymbolUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
2832
            iConnType = 1
2833
        End If
2834

    
2835
        If oSymbolRow.Length = 1 Then
2836
            If sSymbolUid = "" Then
2837
                sSymbolUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
2838
                iConnType = 2
2839
            End If
2840
            sReturnUid = oSymbolRow(0)(_XML_SYMBOL_UID).ToString()
2841
            Dim sOriginalPoint As String = oSymbolRow(0)(_XML_SYMBOL_ORIGINALPOINT).ToString()
2842
            ConvertPointBystring(sOriginalPoint, dOriginalPoint_x, dORiginalPoint_y)
2843
            dX = dOriginalPoint_x
2844
            dY = dORiginalPoint_y
2845
            ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
2846
            'OPC Connection Point가져와서 연결(2018-07-12)
2847

    
2848
            oSymbolRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
2849

    
2850
            Dim sType As String = oSymbolRow(0)(_XML_LINE_TYPE).ToString()
2851
            Dim sSystemPath As String = GetPipeType(sType)
2852

    
2853
            oLMSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, ExistingItem:=oLMConnector.AsLMAItem,
2854
          TargetItem:=oLMSymbol.AsLMAItem)
2855

    
2856
            Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
2857
            If oAttributeRow.Length > 0 Then
2858
                For Each oAttribute In oAttributeRow
2859
                    Try
2860
                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
2861
                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
2862
                        If sPIDValue.Contains("'") Then
2863
                            sPIDValue = sPIDValue.Replace("'", """")
2864
                        End If
2865
                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
2866
                        oLMSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
2867
                    Catch ex As Exception
2868
                    End Try
2869
                Next
2870
            End If
2871
        End If
2872
        Return sReturnUid
2873
    End Function
2874

    
2875

    
2876
    Private Sub OPCTOLineRouting(ByRef oLine_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal oOPCSymbol As LMSymbol,
2877
                            ByVal sOPCUid As String, ByVal sLineNoUid As String)
2878
        Try
2879
            Dim oDatasource As Object = _Placement.PIDDataSource
2880
            Dim objItem As LMAItem
2881
            Dim objConnector As LMConnector
2882
            Dim objInputs As PlaceRunInputs
2883
            objInputs = New PlaceRunInputs
2884
            Dim dOriginalStart_x As Double = 0.0
2885
            Dim dOriginalStart_y As Double = 0.0
2886
            Dim dOriginalEnd_x As Double = 0.0
2887
            Dim dOriginalEnd_y As Double = 0.0
2888
            Dim dStart_x As Double = 0.0
2889
            Dim dStart_y As Double = 0.0
2890
            Dim dEnd_x As Double = 0.0
2891
            Dim dEnd_y As Double = 0.0
2892

    
2893
            Dim oPipeRun As LMPipeRun = Nothing
2894
            Dim sStartpoint As String = ""
2895
            Dim sEndpoint As String = ""
2896
            Dim iConnType As Integer = 0
2897
            Dim oPipeRow() As DataRow = oLine_Dt.Select(_XML_LINE_Conn1_Uid & " = '" + sOPCUid + "' And [" &
2898
                                                                                       _XML_SYMBOL_Check & "] = 'TRUE'")
2899
            Dim sPipeUid As String = ""
2900
            If oPipeRow.Length = 0 Then
2901
                oPipeRow = oLine_Dt.Select(_XML_LINE_Conn2_Uid & " = '" + sOPCUid + "' And [" &
2902
                        _XML_SYMBOL_Check & "] = 'TRUE'")
2903
            Else
2904
                sPipeUid = oPipeRow(0)(_XML_LINE_UID).ToString()
2905
                iConnType = 1
2906
            End If
2907
            Dim oAddUid_List As New List(Of String)
2908
            If oPipeRow.Length = 1 Then
2909
                If sPipeUid = "" Then
2910
                    sPipeUid = oPipeRow(0)(_XML_LINE_UID).ToString()
2911
                    iConnType = 2
2912
                End If
2913
                oAddUid_List.Add(sPipeUid)
2914
                sStartpoint = oPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
2915
                sEndpoint = oPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
2916
                ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
2917
                dStart_x = dOriginalStart_x
2918
                dStart_y = dOriginalStart_y
2919
                ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
2920
                dEnd_x = dOriginalEnd_x
2921
                dEnd_y = dOriginalEnd_y
2922
                ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
2923
                ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
2924

    
2925
                'OPC Connection Point가져와서 연결(2018-07-12)
2926
                If iConnType = 1 Then
2927
                    FindNearPoint(oOPCSymbol, dStart_x, dStart_y)
2928
                    objInputs.AddSymbolTarget(oOPCSymbol, dStart_x, dStart_y)
2929
                    objInputs.AddPoint(dEnd_x, dEnd_y)
2930
                Else
2931
                    FindNearPoint(oOPCSymbol, dEnd_x, dEnd_y)
2932
                    objInputs.AddSymbolTarget(oOPCSymbol, dEnd_x, dEnd_y)
2933
                    objInputs.AddPoint(dStart_x, dStart_y)
2934
                End If
2935
                oPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
2936

    
2937
                While True
2938
                    '    objInputs.Clear()
2939
                    Dim oAddPipeRow() As DataRow = oLine_Dt.Select("[" & _XML_LINE_Conn1_Uid & "] = '" + sPipeUid + "' and " &
2940
                                                                 "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And [" &
2941
                                                                                       _XML_SYMBOL_Check & "] = 'TRUE'")
2942
                    If oAddPipeRow.Length = 0 Then
2943
                        oAddPipeRow = oLine_Dt.Select("[" & _XML_LINE_Conn2_Uid & "] = '" + sPipeUid + "' and " &
2944
                                                                 "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And [" &
2945
                                                                                       _XML_SYMBOL_Check & "] = 'TRUE'")
2946
                        sPipeUid = ""
2947
                    Else
2948
                        iConnType = 1
2949
                        sPipeUid = oAddPipeRow(0)(_XML_LINE_UID).ToString()
2950
                    End If
2951
                    If oAddPipeRow.Length = 1 Then
2952
                        If sPipeUid = "" Then
2953
                            sPipeUid = oAddPipeRow(0)(_XML_LINE_UID).ToString()
2954
                            iConnType = 2
2955
                        End If
2956
                        oAddUid_List.Add(sPipeUid)
2957
                        sStartpoint = oAddPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
2958
                        sEndpoint = oAddPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
2959
                        ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
2960
                        dStart_x = dOriginalStart_x
2961
                        dStart_y = dOriginalStart_y
2962
                        ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
2963
                        dEnd_x = dOriginalEnd_x
2964
                        dEnd_y = dOriginalEnd_y
2965
                        ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
2966
                        ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
2967
                        If iConnType = 1 Then
2968
                            objInputs.AddPoint(dEnd_x, dEnd_y)
2969
                            ' objInputs.AddPoint(dStart_x, dStart_y)
2970
                        Else
2971
                            'objInputs.AddConnectorTarget(objConnector, dStart_x, dStart_y)
2972
                            '  objInputs.AddPoint(dStart_x, dStart_y)
2973
                            '  objInputs.AddPoint(dEnd_x, dEnd_y)
2974
                            objInputs.AddPoint(dStart_x, dStart_y)
2975
                        End If
2976

    
2977
                        oAddPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
2978
                    Else
2979
                        Exit While
2980
                    End If
2981

    
2982
                End While
2983
                Dim sType As String = oPipeRow(0)(_XML_LINE_TYPE).ToString()
2984
                Dim sSystemPath As String = GetPipeType(sType)
2985

    
2986
                objItem = _Placement.PIDCreateItem(sSystemPath)
2987
                objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
2988
                For i = 0 To oAddUid_List.Count - 1
2989
                    Dim oUpdateRow As DataRow() = oLine_Dt.Select(_XML_LINE_UID & " = '" + oAddUid_List(i) + "'")
2990
                    If oUpdateRow.Length = 1 Then
2991
                        oUpdateRow(0)(_XML_LINE_SPID) = objConnector.ModelItemID
2992
                        oUpdateRow(0)(_XML_LINE_LMCONNECTOR) = objConnector
2993
                    End If
2994
                Next
2995

    
2996

    
2997
                oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
2998
                Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
2999
                If oAttributeRow.Length > 0 Then
3000
                    For Each oAttribute In oAttributeRow
3001
                        Try
3002
                            Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
3003
                            Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
3004
                            If sPIDValue.Contains("'") Then
3005
                                sPIDValue = sPIDValue.Replace("'", """")
3006
                            End If
3007
                            Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
3008
                            oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
3009
                        Catch ex As Exception
3010
                        End Try
3011
                    Next
3012
                    oPipeRun.Commit()
3013
                End If
3014

    
3015
            End If
3016

    
3017
        Catch ex As Exception
3018
        End Try
3019
    End Sub
3020

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

    
3023
        For Each sUid In sUidList
3024
            If sUid = sAddUid Then
3025
                Return False
3026
            End If
3027
        Next
3028
        Return True
3029
    End Function
3030

    
3031
    Private Sub LineRouting(ByRef oLine_Dt As DataTable, ByVal oAttribute_Dt As DataTable, ByVal sLineNoUid As String, ByVal sLineNoText As String)
3032
        Try
3033
            Dim oDatasource As Object = _Placement.PIDDataSource
3034
            Dim objItem As LMAItem
3035
            Dim objConnector As LMConnector
3036
            Dim objInputs As PlaceRunInputs
3037
            objInputs = New PlaceRunInputs
3038
            Dim dOriginalStart_x As Double = 0.0
3039
            Dim dOriginalStart_y As Double = 0.0
3040
            Dim dOriginalEnd_x As Double = 0.0
3041
            Dim dOriginalEnd_y As Double = 0.0
3042
            Dim dStart_x As Double = 0.0
3043
            Dim dStart_y As Double = 0.0
3044
            Dim dEnd_x As Double = 0.0
3045
            Dim dEnd_y As Double = 0.0
3046
            Dim oPipeRun As LMPipeRun = Nothing
3047
            Dim sStartpoint As String = ""
3048
            Dim sEndpoint As String = ""
3049
            Dim iConnType As Integer = 0
3050
            Dim pLMConnector As LMConnector = Nothing
3051
            For Each oLinerow In oLine_Dt.Rows
3052
                objInputs.Clear()
3053
                Dim sCheck As String = oLinerow(_XML_LINE_DRAWING_TF).ToString()
3054
                If sCheck = "FALSE" Then
3055
                    Dim sUid As String = oLinerow(_XML_LINE_UID).ToString()
3056
                    sStartpoint = oLinerow(_XML_LINE_STARTPOINT).ToString()
3057
                    sEndpoint = oLinerow(_XML_LINE_ENDPOINT).ToString()
3058
                    ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
3059
                    dStart_x = dOriginalStart_x
3060
                    dStart_y = dOriginalStart_y
3061
                    ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
3062
                    dEnd_x = dOriginalEnd_x
3063
                    dEnd_y = dOriginalEnd_y
3064
                    ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
3065
                    ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
3066

    
3067
                    objInputs.AddPoint(dStart_x, dStart_y)
3068
                    objInputs.AddPoint(dEnd_x, dEnd_y)
3069
                    Dim sType As String = oLinerow(_XML_LINE_TYPE).ToString()
3070
                    Dim sSystemPath As String = GetPipeType(sType)
3071
                    objItem = _Placement.PIDCreateItem(sSystemPath)
3072
                    objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
3073
                    SetListBoxItems(ListBox_Result, "Place Pipe.." & sUid & " (" & dOriginalStart_x & "," & dOriginalStart_y & ") - (" & dOriginalEnd_x & "," & dOriginalEnd_y & ")..." & _iPipecnt & " count ")
3074

    
3075
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Pipe : " & sUid)
3076
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "LineNo : " & sLineNoText)
3077
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection1 : " & oLinerow(_XML_SYMBOL_Conn1_Uid).ToString())
3078
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection2 : " & oLinerow(_XML_SYMBOL_Conn2_Uid).ToString())
3079
                    'ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
3080
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "StartPoint : " & dOriginalStart_x & "," & dOriginalStart_y)
3081
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "EndPoint : " & dOriginalEnd_x & "," & dOriginalEnd_y)
3082
                    ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Pipe Count : " & _iPipecnt)
3083

    
3084
                    _iPipecnt = _iPipecnt + 1
3085
                    oLinerow(_XML_LINE_SPID) = objConnector.ModelItemID
3086
                    oLinerow(_XML_LINE_LMCONNECTOR) = objConnector
3087

    
3088
                    oLinerow(_XML_LINE_DRAWING_TF) = "TRUE"
3089
                    oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
3090

    
3091
                    Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
3092
                    If oAttributeRow.Length > 0 Then
3093
                        For Each oAttribute In oAttributeRow
3094
                            Try
3095
                                Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
3096
                                Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
3097
                                If sPIDValue.Contains("'") Then
3098
                                    sPIDValue = sPIDValue.Replace("'", """")
3099
                                End If
3100
                                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
3101
                                oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
3102
                            Catch ex As Exception
3103
                            End Try
3104
                        Next
3105
                        oPipeRun.Commit()
3106
                    End If
3107
                End If
3108

    
3109

    
3110

    
3111

    
3112

    
3113
                'Dim sPipeUid As String = oLinerow(_XML_LINE_UID).ToString()
3114
                'Dim sCheckModeling As Boolean = False
3115
                'objInputs.Clear()
3116
                'Dim oAddUid_List As New List(Of String)
3117
                'Try
3118
                '    Dim oAddPipeRow() As DataRow = oLine_Dt.Select("[" & _XML_LINE_Conn1_Uid & "] = '" + sPipeUid + "' and " &
3119
                '                                            "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And [" &
3120
                '                                            _XML_SYMBOL_Check & "] = 'TRUE'")
3121
                '    If oAddPipeRow.Length = 0 Then
3122
                '        oAddPipeRow = oLine_Dt.Select("[" & _XML_LINE_Conn2_Uid & "] = '" + sPipeUid + "' and " &
3123
                '                                        "[" & _XML_LINE_DRAWING_TF & "] = 'FALSE' And [" &
3124
                '                                        _XML_SYMBOL_Check & "] = 'TRUE'")
3125
                '        sPipeUid = ""
3126
                '    Else
3127
                '        iConnType = 1
3128
                '        sPipeUid = oAddPipeRow(0)(_XML_LINE_UID).ToString()
3129
                '    End If
3130
                '    If oAddPipeRow.Length = 1 Then
3131
                '        sCheckModeling = True
3132
                '        If sPipeUid = "" Then
3133
                '            sPipeUid = oAddPipeRow(0)(_XML_LINE_UID).ToString()
3134
                '            iConnType = 2
3135
                '        End If
3136
                '        If AddUidList중복체크(oAddUid_List, sPipeUid) Then
3137
                '            oAddUid_List.Add(sPipeUid)
3138
                '        End If
3139
                '        sStartpoint = oAddPipeRow(0)(_XML_LINE_STARTPOINT).ToString()
3140
                '        sEndpoint = oAddPipeRow(0)(_XML_LINE_ENDPOINT).ToString()
3141
                '        ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
3142
                '        dStart_x = dOriginalStart_x
3143
                '        dStart_y = dOriginalStart_y
3144
                '        ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
3145
                '        dEnd_x = dOriginalEnd_x
3146
                '        dEnd_y = dOriginalEnd_y
3147
                '        ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
3148
                '        ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
3149
                '        Dim sBranchType As String = ""
3150
                '        If (CheckBranchLine(oLine_Dt, dStart_x, dStart_y, dEnd_x, dEnd_y, sBranchType, pLMConnector)) Then
3151
                '            Try
3152
                '                If pLMConnector Is Nothing Then
3153
                '                    objInputs.AddPoint(dStart_x, dStart_y)
3154
                '                    objInputs.AddPoint(dEnd_x, dEnd_y)
3155
                '                Else
3156
                '                    If sBranchType = "1" Then
3157
                '                        objInputs.AddConnectorTarget(pLMConnector, dStart_x, dStart_y)
3158
                '                        objInputs.AddPoint(dEnd_x, dEnd_y)
3159
                '                    ElseIf sBranchType = "2" Then
3160
                '                        objInputs.AddConnectorTarget(pLMConnector, dEnd_x, dEnd_y)
3161
                '                        objInputs.AddPoint(dStart_x, dStart_y)
3162
                '                    ElseIf sBranchType = "3" Then
3163
                '                        objInputs.AddConnectorTarget(pLMConnector, dStart_x, dStart_y)
3164
                '                        objInputs.AddPoint(dEnd_x, dEnd_y)
3165
                '                    ElseIf sBranchType = "4" Then
3166
                '                        objInputs.AddConnectorTarget(pLMConnector, dEnd_x, dEnd_y)
3167
                '                        objInputs.AddPoint(dStart_x, dStart_y)
3168
                '                    End If
3169
                '                End If
3170
                '            Catch ex As Exception
3171
                '            End Try
3172
                '        Else
3173
                '            objInputs.AddPoint(dStart_x, dStart_y)
3174
                '            objInputs.AddPoint(dEnd_x, dEnd_y)
3175
                '        End If
3176
                '        oAddPipeRow(0)(_XML_LINE_DRAWING_TF) = "TRUE"
3177
                '    Else
3178
                '        Dim CheckTF As String = oLinerow(_XML_LINE_DRAWING_TF).ToString()
3179
                '        Dim CheckSelect As String = oLinerow(_XML_LINE_Check).ToString()
3180
                '        If CheckTF = "FALSE" And CheckSelect = "TRUE" Then
3181
                '            sPipeUid = oLinerow(_XML_LINE_UID).ToString()
3182
                '            oAddUid_List.Clear()
3183
                '            oAddUid_List.Add(sPipeUid)
3184
                '            sCheckModeling = True
3185
                '            sStartpoint = oLinerow(_XML_LINE_STARTPOINT).ToString()
3186
                '            sEndpoint = oLinerow(_XML_LINE_ENDPOINT).ToString()
3187
                '            ConvertPointBystring(sStartpoint, dOriginalStart_x, dOriginalStart_y)
3188
                '            dStart_x = dOriginalStart_x
3189
                '            dStart_y = dOriginalStart_y
3190
                '            ConvertPointBystring(sEndpoint, dOriginalEnd_x, dOriginalEnd_y)
3191
                '            dEnd_x = dOriginalEnd_x
3192
                '            dEnd_y = dOriginalEnd_y
3193
                '            ConvertPointByImage(dStart_x, dStart_y, _IMG_X, _IMG_Y)
3194
                '            ConvertPointByImage(dEnd_x, dEnd_y, _IMG_X, _IMG_Y)
3195
                '            Dim sBranchType As String = ""
3196
                '            If (CheckBranchLine(oLine_Dt, dStart_x, dStart_y, dEnd_x, dEnd_y, sBranchType, pLMConnector)) Then
3197
                '                Try
3198
                '                    If sBranchType = "1" Then
3199
                '                        objInputs.AddPoint(dEnd_x, dEnd_y)
3200
                '                        objInputs.AddConnectorTarget(pLMConnector, dStart_x, dStart_y)
3201
                '                    ElseIf sBranchType = "2" Then
3202
                '                        objInputs.AddPoint(dStart_x, dStart_y)
3203
                '                        objInputs.AddConnectorTarget(pLMConnector, dEnd_x, dEnd_y)
3204
                '                    ElseIf sBranchType = "3" Then
3205
                '                        objInputs.AddPoint(dEnd_x, dEnd_y)
3206
                '                        objInputs.AddConnectorTarget(pLMConnector, dStart_x, dStart_y)
3207
                '                    ElseIf sBranchType = "4" Then
3208
                '                        objInputs.AddPoint(dStart_x, dStart_y)
3209
                '                        objInputs.AddConnectorTarget(pLMConnector, dEnd_x, dEnd_y)
3210
                '                    End If
3211
                '                Catch ex As Exception
3212

    
3213
                '                End Try
3214
                '            Else
3215
                '                objInputs.AddPoint(dStart_x, dStart_y)
3216
                '                objInputs.AddPoint(dEnd_x, dEnd_y)
3217
                '            End If
3218
                '            oLinerow(_XML_LINE_DRAWING_TF) = "TRUE"
3219
                '        End If
3220
                '    End If
3221
                'Catch ex As Exception
3222
                'End Try
3223
                'If sCheckModeling Then
3224
                '    Dim sType As String = oLinerow(_XML_LINE_TYPE).ToString()
3225
                '    Dim sSystemPath As String = GetPipeType(sType)
3226
                '    objItem = _Placement.PIDCreateItem(sSystemPath)
3227
                '    objConnector = _Placement.PIDPlaceRun(objItem, objInputs)
3228
                '    For i = 0 To oAddUid_List.Count - 1
3229
                '        Dim oUpdateRow As DataRow() = oLine_Dt.Select(_XML_LINE_UID & " = '" + oAddUid_List(i) + "'")
3230
                '        If oUpdateRow.Length = 1 Then
3231
                '            oUpdateRow(0)(_XML_LINE_SPID) = objConnector.ModelItemID
3232
                '            oUpdateRow(0)(_XML_LINE_LMCONNECTOR) = objConnector
3233
                '        End If
3234
                '    Next
3235

    
3236
                '    oPipeRun = oDatasource.GetPipeRun(objConnector.ModelItemID)
3237
                '    oAddUid_List.Clear()
3238

    
3239
                '    Dim oAttributeRow() As DataRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sLineNoUid + "'")
3240
                '    If oAttributeRow.Length > 0 Then
3241
                '        For Each oAttribute In oAttributeRow
3242
                '            Try
3243
                '                Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
3244
                '                Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
3245
                '                If sPIDValue.Contains("'") Then
3246
                '                    sPIDValue = sPIDValue.Replace("'", """")
3247
                '                End If
3248
                '                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
3249
                '                oPipeRun.Attributes(sSPPIDAttribute).Value = sPIDValue
3250
                '            Catch ex As Exception
3251
                '            End Try
3252
                '        Next
3253
                '        oPipeRun.Commit()
3254
                '    End If
3255

    
3256
                '    If pLMConnector IsNot Nothing Then
3257
                '        Dim sID_1 As String = pLMConnector.ModelItemID
3258
                '        Dim sID_2 As String = objConnector.ModelItemID
3259
                '        Dim objSurvivorItem As LMAItem = Nothing
3260
                '        Dim oPipeRun1 As LMPipeRun = oDatasource.GetPipeRun(sID_1)
3261
                '        Dim oPipeRun2 As LMPipeRun = oDatasource.GetPipeRun(sID_2)
3262
                '        _Placement.PIDJoinRuns(oPipeRun1, oPipeRun2)
3263
                '        '     oDatasource.CommitTransaction()
3264
                '        '_Placement.PIDAutoJoin(oPipeRun1.AsLMAItem, AutoJoinEndConstants.autoJoin_End, objSurvivorItem)
3265
                '        'oPipeRun1.Commit()
3266
                '        'oDatasource.CommitTransaction()
3267
                '        'objSurvivorItem = Nothing
3268
                '        '_Placement.PIDAutoJoin(oPipeRun2.AsLMAItem, AutoJoinEndConstants.autoJoin_Start, objSurvivorItem)
3269
                '        'oPipeRun2.Commit()
3270
                '        'oDatasource.CommitTransaction()
3271
                '    End If
3272
                '    sCheckModeling = False
3273
                '  End If
3274
            Next
3275
        Catch ex As Exception
3276
        End Try
3277
    End Sub
3278

    
3279

    
3280
    Private Sub SymbolModeling(ByVal CDrawing As Drawing, ByVal oLine_DT As DataTable, ByVal oSymbolRow As DataRow, ByVal oAttribute_Dt As DataTable,
3281
                               ByVal sLineNoText As String)
3282
        Try
3283

    
3284
            Dim sCheckModeling As String = oSymbolRow(_XML_SYMBOL_DRAWING_TF).ToString()
3285
            If sCheckModeling = "FALSE" Then
3286
                Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID)
3287
                Dim oSymbol As LMSymbol = Nothing
3288
                Dim sSPID As String = oSymbolRow(_XML_SYMBOL_SPID).ToString()
3289
                Dim sSystemPath As String = oSymbolRow(_XML_SYMBOL_SYSTEMPATH).ToString()
3290
                Dim oDatasource As Object = _Placement.PIDDataSource
3291
                Dim sSymbolCompType As String = oSymbolRow(_XML_SYMBOL_TYPE).ToString()
3292
                Dim dLocationX As Double = 0.0
3293
                Dim dLocationY As Double = 0.0
3294
                Dim dX As Double = 0.0
3295
                Dim dY As Double = 0.0
3296
                Dim sOriginalPoint As String = oSymbolRow(_XML_SYMBOL_ORIGINALPOINT).ToString()
3297
                ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY)
3298
                dX = dLocationX
3299
                dY = dLocationY
3300
                ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
3301

    
3302
                Dim dAngle As Double = oSymbolRow(_XML_SYMBOL_ANGLE)
3303

    
3304

    
3305
                'Dim oDatarow() As DataRow = oLine_DT.Select("[" & _XML_LINE_Conn1_Uid & "] = '" & sSymbolUid & "'")
3306
                'If oDatarow.Length = 0 Then
3307
                '    oDatarow = oLine_DT.Select("[" & _XML_LINE_Conn2_Uid & "] = '" & sSymbolUid & "'")
3308
                'End If
3309
                'Dim dFix_X As Double = 0.0
3310
                'Dim dFix_Y As Double = 0.0
3311
                'If oDatarow.Length > 0 Then
3312
                '    If dAngle <> 0 Then
3313
                '        sOriginalPoint = oDatarow(0)(_XML_LINE_STARTPOINT).ToString()
3314
                '        ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY)
3315

    
3316
                '        ConvertPointByImage(dLocationX, dLocationY, _IMG_X, _IMG_Y)
3317
                '        dX = dLocationX
3318
                '    Else
3319
                '        sOriginalPoint = oDatarow(0)(_XML_LINE_STARTPOINT).ToString()
3320
                '        ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY)
3321
                '        ConvertPointByImage(dLocationX, dLocationY, _IMG_X, _IMG_Y)
3322
                '        dY = dLocationY
3323
                '    End If
3324

    
3325
                'End If
3326

    
3327

    
3328

    
3329
                oSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY,, dAngle)
3330
                SetListBoxItems(ListBox_Result, "Place Fitting.." & sSymbolUid & " (" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
3331

    
3332
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Place Fitting : " & sSymbolUid)
3333
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "LineNo : " & sLineNoText)
3334
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection1 : " & oSymbolRow(_XML_SYMBOL_Conn1_Uid).ToString())
3335
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection2 : " & oSymbolRow(_XML_SYMBOL_Conn2_Uid).ToString())
3336
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection3 : " & oSymbolRow(_XML_SYMBOL_Conn3_Uid).ToString())
3337
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Connection4 : " & oSymbolRow(_XML_SYMBOL_Conn4_Uid).ToString())
3338
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Angle : " & dAngle)
3339
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "OriginalPoint : " & dLocationX & "," & dLocationY)
3340
                ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, "Fitting Count : " & _iFittingcnt)
3341

    
3342

    
3343
                _iFittingcnt = _iFittingcnt + 1
3344
                oSymbolRow(_XML_SYMBOL_DRAWING_TF) = "TRUE"
3345
                Dim oAttributeRow() As DataRow
3346
                oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sSymbolUid + "'")
3347
                If oAttribute_Dt.Rows.Count > 0 Then
3348

    
3349
                    If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
3350
                        Dim oInstrument As LMInstrument
3351
                        oInstrument = oDatasource.GetInstrument(oSymbol.ModelItemID)
3352
                        Try
3353
                            If oAttributeRow.Length > 0 Then
3354
                                For Each oAttribute In oAttributeRow
3355
                                    Try
3356
                                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
3357
                                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
3358
                                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
3359
                                        oInstrument.Attributes(sSPPIDAttribute).Value = sPIDValue
3360
                                    Catch ex As Exception
3361
                                    End Try
3362
                                Next
3363
                                oInstrument.Commit()
3364
                            End If
3365
                        Catch ex As Exception
3366
                        End Try
3367
                    Else
3368
                        Try
3369
                            If oAttributeRow.Length > 0 And oSymbol IsNot Nothing Then
3370
                                For Each oAttribute In oAttributeRow
3371
                                    Try
3372
                                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
3373
                                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
3374

    
3375
                                        If sPIDAttribute = "SIZE" Then
3376

    
3377
                                            'Nominal diamter1,2속성이름뭔지 찾아봐야됨 (2018-07-20)
3378
                                            If sPIDValue.Contains("x") Then
3379
                                                Dim sSplitSize() As String = sPIDValue.Split("x")
3380
                                                If sSplitSize.Count > 1 Then
3381
                                                    'Connection Point와 연결되어 있는 라인을 가져와서 라인프로퍼티를 변경
3382
                                                    Dim oConnector_1 As LMConnector = Nothing
3383
                                                    Dim oConnector_2 As LMConnector = Nothing
3384
                                                    If oSymbol IsNot Nothing Then
3385
                                                        If oSymbol.Connect1Connectors.Count >= 1 Then
3386
                                                            For Each Tconnector In oSymbol.Connect1Connectors
3387
                                                                If Tconnector.ItemStatus = "Active" Then
3388
                                                                    If Tconnector.ModelItemObject.ItemTypeName = "PipeRun" Then
3389
                                                                        oConnector_1 = Tconnector
3390
                                                                    End If
3391
                                                                End If
3392
                                                            Next
3393
                                                        End If
3394
                                                        If oSymbol.Connect1Connectors.Count >= 1 Then
3395
                                                            For Each Tconnector In oSymbol.Connect1Connectors
3396
                                                                If Tconnector.ItemStatus = "Active" Then
3397
                                                                    If Tconnector.ModelItemObject.ItemTypeName = "PipeRun" Then
3398
                                                                        oConnector_2 = Tconnector
3399
                                                                    End If
3400
                                                                End If
3401
                                                            Next
3402
                                                        End If
3403
                                                    End If
3404
                                                    Dim oPipeRun1 As LMPipeRun = oDatasource.GetPipeRun(oConnector_1.ModelItemID)
3405
                                                    Dim oPipeRun2 As LMPipeRun = oDatasource.GetPipeRun(oConnector_2.ModelItemID)
3406
                                                    If dAngle = 3.14 Then
3407
                                                        oPipeRun1.Attributes("NominalDiameter").Value = sSplitSize(1)
3408
                                                        oPipeRun2.Attributes("NominalDiameter").Value = sSplitSize(0)
3409
                                                    Else
3410
                                                        oPipeRun1.Attributes("NominalDiameter").Value = sSplitSize(0)
3411
                                                        oPipeRun2.Attributes("NominalDiameter").Value = sSplitSize(1)
3412
                                                    End If
3413

    
3414

    
3415
                                                End If
3416

    
3417
                                            Else
3418
                                                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
3419
                                                oSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
3420
                                            End If
3421
                                        Else
3422
                                            Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
3423
                                            oSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
3424
                                        End If
3425

    
3426
                                    Catch ex As Exception
3427
                                    End Try
3428
                                Next
3429
                                oSymbol.Commit()
3430
                            End If
3431
                        Catch ex As Exception
3432
                        End Try
3433
                    End If
3434
                End If
3435

    
3436

    
3437

    
3438
            End If
3439

    
3440

    
3441

    
3442
            'Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID).ToString()
3443
            'Dim sConnTypeNo As String = ""
3444
            '' Line과 연결되어있는 Symbol인지 확인
3445
            'Dim oLine_Dt As DataTable = GetPipeFromConnection(CDrawing, sSymbolUid, sConnTypeNo)
3446
            ''Symbol과 연결되어 있는 Symbol인지 확인
3447
            'Dim oSymbol_Dt As DataTable = GetSymbolFromConnection(CDrawing, sSymbolUid, sConnTypeNo)
3448
            'Dim oSymbol As LMSymbol = Nothing
3449
            'Dim sSPID As String = oSymbolRow(_XML_SYMBOL_SPID).ToString()
3450
            'Dim sSystemPath As String = oSymbolRow(_XML_SYMBOL_SYSTEMPATH).ToString()
3451
            'Dim oDatasource As Object = _Placement.PIDDataSource
3452
            'Dim sSymbolCompType As String = oSymbolRow(_XML_SYMBOL_TYPE).ToString()
3453

    
3454
            'Dim dAngle As Double = 0.0
3455
            'If IsNumeric(oSymbolRow(_XML_SYMBOL_ANGLE).ToString()) Then
3456
            '    dAngle = Double.Parse(oSymbolRow(_XML_SYMBOL_ANGLE).ToString())
3457
            'End If
3458

    
3459
            'Dim dLocationX As Double = 0.0
3460
            'Dim dLocationY As Double = 0.0
3461
            'Dim dX As Double = 0.0
3462
            'Dim dY As Double = 0.0
3463
            'Dim sOriginalPoint As String = oSymbolRow(_XML_SYMBOL_ORIGINALPOINT).ToString()
3464
            'ConvertPointBystring(sOriginalPoint, dLocationX, dLocationY)
3465
            'dX = dLocationX
3466
            'dY = dLocationY
3467
            'ConvertPointByImage(dX, dY, _IMG_X, _IMG_Y)
3468
            'Dim bCheckModeling As Boolean = False
3469

    
3470
            'If oLine_Dt.Rows.Count > 0 Then
3471

    
3472
            '    If sSPID <> "" Then
3473
            '        Dim dX1 As Double = 0
3474
            '        Dim dX2 As Double = 0
3475
            '        Dim dY1 As Double = 0
3476
            '        Dim dY2 As Double = 0
3477
            '        Dim oLMSymbol As LMSymbol = oDatasource.GetSymbol(sSPID)
3478
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 1, dX1, dY1)
3479
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 2, dX2, dY2)
3480

    
3481
            '        Dim dCalcPoint As Double = -1
3482
            '        Dim dModeling_X As Double = 0
3483
            '        Dim dModeling_Y As Double = 0
3484
            '        If dX1 <> 0 And dY1 <> 0 Then
3485
            '            dCalcPoint = Math.Abs(dX1 - dX) + Math.Abs(dY1 - dY)
3486
            '            dModeling_X = dX1
3487
            '            dModeling_Y = dY1
3488
            '        End If
3489
            '        If dX2 <> 0 And dY2 <> 0 Then
3490

    
3491
            '            If (Math.Abs(dX2 - dX) + Math.Abs(dY2 - dY) > dCalcPoint) Then
3492
            '                dCalcPoint = Math.Abs(dX2 - dX) + Math.Abs(dY2 - dY)
3493
            '                dModeling_X = dX2
3494
            '                dModeling_Y = dY2
3495
            '            End If
3496
            '        End If
3497

    
3498

    
3499

    
3500
            '        If dModeling_X <> 0 And dModeling_Y <> 0 Then
3501
            '            oSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dModeling_X, dModeling_Y,, dAngle, ExistingItem:=oLMSymbol.AsLMAItem,
3502
            '                TargetItem:=oLMSymbol.AsLMRepresentation)
3503
            '            bCheckModeling = True
3504
            '        End If
3505

    
3506

    
3507
            '    End If
3508
            'End If
3509
            'If oSymbol_Dt.Rows.Count > 0 Then
3510
            '    If sSPID <> "" Then
3511
            '        Dim dX1 As Double = 0
3512
            '        Dim dX2 As Double = 0
3513
            '        Dim dX3 As Double = 0
3514
            '        Dim dX4 As Double = 0
3515
            '        Dim dY1 As Double = 0
3516
            '        Dim dY2 As Double = 0
3517
            '        Dim dY3 As Double = 0
3518
            '        Dim dY4 As Double = 0
3519
            '        Dim oLMSymbol As LMSymbol = oDatasource.GetSymbol(sSPID)
3520
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 1, dX1, dY1)
3521
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 2, dX2, dY2)
3522
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 3, dX3, dY3)
3523
            '        _Placement.PIDConnectPointLocation(oLMSymbol, 4, dX4, dY4)
3524

    
3525
            '        Dim dCalcPoint As Double = -1
3526
            '        Dim dModeling_X As Double = 0
3527
            '        Dim dModeling_Y As Double = 0
3528
            '        If dX1 <> 0 And dY1 <> 0 Then
3529
            '            dCalcPoint = Math.Abs(dX1 - dX) + Math.Abs(dY1 - dY)
3530
            '            dModeling_X = dX1
3531
            '            dModeling_Y = dY1
3532
            '        End If
3533
            '        If dX2 <> 0 And dY2 <> 0 Then
3534

    
3535
            '            If (Math.Abs(dX2 - dX) + Math.Abs(dY2 - dY) > dCalcPoint) Then
3536
            '                dCalcPoint = Math.Abs(dX2 - dX) + Math.Abs(dY2 - dY)
3537
            '                dModeling_X = dX2
3538
            '                dModeling_Y = dY2
3539
            '            End If
3540
            '        End If
3541
            '        If dX3 <> 0 And dY3 <> 0 Then
3542
            '            If (Math.Abs(dX3 - dX) + Math.Abs(dY3 - dY) > dCalcPoint) Then
3543
            '                dCalcPoint = Math.Abs(dX3 - dX) + Math.Abs(dY3 - dY)
3544
            '                dModeling_X = dX3
3545
            '                dModeling_Y = dY3
3546
            '            End If
3547
            '        End If
3548
            '        If dX4 <> 0 And dY4 <> 0 Then
3549
            '            If (Math.Abs(dX4 - dX) + Math.Abs(dY4 - dY) > dCalcPoint) Then
3550
            '                dCalcPoint = Math.Abs(dX4 - dX) + Math.Abs(dY4 - dY)
3551
            '                dModeling_X = dX4
3552
            '                dModeling_Y = dY4
3553
            '            End If
3554
            '        End If
3555
            '        If dModeling_X <> 0 And dModeling_Y <> 0 Then
3556
            '            oSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dModeling_X, dModeling_Y,, dAngle, ExistingItem:=oLMSymbol.AsLMAItem,
3557
            '                TargetItem:=oLMSymbol.AsLMRepresentation)
3558
            '            bCheckModeling = True
3559
            '        End If
3560

    
3561

    
3562
            '    End If
3563

    
3564
            'End If
3565

    
3566
            'If (oLine_Dt.Rows.Count = 0 And oSymbol_Dt.Rows.Count = 0) Or bCheckModeling = False Then
3567
            '    oSymbol = _Placement.PIDPlaceSymbol(sSystemPath, dX, dY, , dAngle)
3568
            '    SetListBoxItems(ListBox_Result, "Place Fittings..(" & dLocationX & "," & dLocationY & ")..." & _iFittingcnt & " count ")
3569
            '    _iFittingcnt = _iFittingcnt + 1
3570
            'End If
3571
            'Dim oAttributeRow() As DataRow
3572
            'oAttributeRow = oAttribute_Dt.Select(_XML_ATTRIBUTE_UID & " = '" + sSymbolUid + "'")
3573
            'If oAttribute_Dt.Rows.Count > 0 Then
3574

    
3575
            '    If sSymbolCompType.ToUpper() = _SYMBOL_INSTUMENT.ToUpper() Then
3576
            '        Dim oInstrument As LMInstrument
3577
            '        oInstrument = oDatasource.GetInstrument(oSymbol.ModelItemID)
3578
            '        Try
3579
            '            If oAttributeRow.Length > 0 Then
3580
            '                For Each oAttribute In oAttributeRow
3581
            '                    Try
3582
            '                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
3583
            '                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
3584
            '                        Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
3585
            '                        oInstrument.Attributes(sSPPIDAttribute).Value = sPIDValue
3586
            '                    Catch ex As Exception
3587
            '                    End Try
3588
            '                Next
3589
            '                oInstrument.Commit()
3590
            '            End If
3591
            '        Catch ex As Exception
3592
            '        End Try
3593
            '    Else
3594
            '        Try
3595
            '            If oAttributeRow.Length > 0 And oSymbol IsNot Nothing Then
3596
            '                For Each oAttribute In oAttributeRow
3597
            '                    Try
3598
            '                        Dim sPIDAttribute As String = oAttribute(_XML_ATTRIBUTE_NAME).ToString()
3599
            '                        Dim sPIDValue As String = oAttribute(_XML_ATTRIBUTE_VALUE).ToString()
3600

    
3601
            '                        If sPIDAttribute = "SIZE" Then
3602

    
3603
            '                            'Nominal diamter1,2속성이름뭔지 찾아봐야됨 (2018-07-20)
3604
            '                            If sPIDValue.Contains("x") Then
3605
            '                                Dim sSplitSize() As String = sPIDValue.Split("x")
3606
            '                                If sSplitSize.Count > 1 Then
3607
            '                                    'Connection Point와 연결되어 있는 라인을 가져와서 라인프로퍼티를 변경
3608
            '                                    Dim oConnector_1 As LMConnector = Nothing
3609
            '                                    Dim oConnector_2 As LMConnector = Nothing
3610
            '                                    If oSymbol IsNot Nothing Then
3611
            '                                        If oSymbol.Connect1Connectors.Count >= 1 Then
3612
            '                                            For Each Tconnector In oSymbol.Connect1Connectors
3613
            '                                                If Tconnector.ItemStatus = "Active" Then
3614
            '                                                    If Tconnector.ModelItemObject.ItemTypeName = "PipeRun" Then
3615
            '                                                        oConnector_1 = Tconnector
3616
            '                                                    End If
3617
            '                                                End If
3618
            '                                            Next
3619
            '                                        End If
3620
            '                                        If oSymbol.Connect1Connectors.Count >= 1 Then
3621
            '                                            For Each Tconnector In oSymbol.Connect1Connectors
3622
            '                                                If Tconnector.ItemStatus = "Active" Then
3623
            '                                                    If Tconnector.ModelItemObject.ItemTypeName = "PipeRun" Then
3624
            '                                                        oConnector_2 = Tconnector
3625
            '                                                    End If
3626
            '                                                End If
3627
            '                                            Next
3628
            '                                        End If
3629
            '                                    End If
3630
            '                                    Dim oPipeRun1 As LMPipeRun = oDatasource.GetPipeRun(oConnector_1.ModelItemID)
3631
            '                                    Dim oPipeRun2 As LMPipeRun = oDatasource.GetPipeRun(oConnector_2.ModelItemID)
3632
            '                                    If dAngle = 3.14 Then
3633
            '                                        oPipeRun1.Attributes("NominalDiameter").Value = sSplitSize(1)
3634
            '                                        oPipeRun2.Attributes("NominalDiameter").Value = sSplitSize(0)
3635
            '                                    Else
3636
            '                                        oPipeRun1.Attributes("NominalDiameter").Value = sSplitSize(0)
3637
            '                                        oPipeRun2.Attributes("NominalDiameter").Value = sSplitSize(1)
3638
            '                                    End If
3639

    
3640

    
3641
            '                                End If
3642

    
3643
            '                            Else
3644
            '                                Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
3645
            '                                oSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
3646
            '                            End If
3647
            '                        Else
3648
            '                            Dim sSPPIDAttribute As String = GetAttributeMapping(sPIDAttribute, _DB_COLUMN_ATTRIBUTE_SPPID_ATTRIBUTE)
3649
            '                            oSymbol.Attributes(sSPPIDAttribute).Value = sPIDValue
3650
            '                        End If
3651

    
3652
            '                    Catch ex As Exception
3653
            '                    End Try
3654
            '                Next
3655
            '                oSymbol.Commit()
3656
            '            End If
3657
            '        Catch ex As Exception
3658
            '        End Try
3659
            '    End If
3660
            'End If
3661
        Catch ex As Exception
3662
        End Try
3663
    End Sub
3664

    
3665
    Private Function AutoModeling() As Boolean
3666
        Try
3667
            '_AllLine_DT = Line_Dt()
3668
            '_AllSymbol_DT = Symbol_Dt()
3669
            _ModelingLine_Dt = Line_Dt()
3670
            _ModelingSymbol_Dt = Symbol_Dt()
3671
            _CompleteConvert = False
3672
            Label_Progress.Text = "0%"
3673
            SetListBoxItems(ListBox_Result, " Auto converting 시작....")
3674
            ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, " Auto converting 시작....")
3675
            Dim oDwg_Dt As DataTable = LoadAllDrawing()
3676
            _Log_File = "AutoConverting_" + DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.ToString("HHmmss")
3677
            _allItem = GetAllCheckNodeCount()
3678
            _Itemcnt = 0
3679
            '1.Equipment
3680
            '2.Piping OPC
3681
            '3.OPC 시작되는 Line
3682

    
3683
            'InitAutoRouting()
3684
            'EquipmentModeling(oDwg_Dt)
3685
            'PipingModeling()
3686

    
3687
            '' 1. Primary Line만 먼저 그림
3688
            'PrimaryPipeModeling()
3689
            '' 2. Draw Symbols Prinmary에 붙는 Symbol만 / Reducer 제외
3690
            'PrimarySymbolModeling()
3691

    
3692
            ''
3693
            Dim auto As AutoModeling = New AutoModeling(_DrawingsList(0), ListBox_Result)
3694
            auto.StartModeling()
3695

    
3696

    
3697

    
3698

    
3699
            '   PipeLine_Fitting_Modeling()
3700

    
3701
            SetProgressbar(ProgressBar_Status, 100)
3702
            Label_Progress.Text = "100%"
3703
            SetListBoxItems(ListBox_Result, " Auto converting 완료")
3704
            ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, " Auto converting 완료")
3705
            _CompleteConvert = True
3706
            Return True
3707
        Catch ex As Exception
3708
            Return False
3709
        End Try
3710
    End Function
3711

    
3712
    Private Sub ThreadConvert()
3713
        If _DrawingsList IsNot Nothing Then
3714
            If _DrawingsList.Count > 0 Then
3715
                'TestBranchLine()
3716
                AutoModeling()
3717
            End If
3718
        End If
3719
    End Sub
3720

    
3721
    Private Sub ThreadOPCRemove()
3722
        While _CompleteConvert = False
3723
            Dim oFindOPC As New FindOpc
3724
            oFindOPC.RemoveOPCDlg()
3725
        End While
3726

    
3727
    End Sub
3728

    
3729
    Private Function OpenDrawing(ByVal oDt As DataTable, ByVal sDwgName As String) As String
3730
        Dim oRows As DataRow() = oDt.Select("[Name] = '" & sDwgName & "'")
3731
        Dim oPath As String = ""
3732
        If oRows.Length > 0 Then
3733
            oPath = oRows(0).Item("Path").ToString()
3734
        End If
3735
        Return oPath
3736
    End Function
3737

    
3738
    Private Sub LoadXmlToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LoadXmlToolStripMenuItem.Click
3739

    
3740
        If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
3741
            LoadDB()
3742
            LoadXmlItem(FolderBrowserDialog1.SelectedPath)
3743
        End If
3744
    End Sub
3745
    Private Sub LoadXmlItem(ByVal sFolderPath As String)
3746
        _DrawingsList = New List(Of Drawing)
3747
        Dim sfileEntries As String() = Directory.GetFiles(sFolderPath)
3748
        If Tree_Result.Nodes.Count > 0 Then
3749
            Tree_Result.Nodes(0).Nodes.Clear()
3750
            For Each sfileName In sfileEntries
3751
                Dim sExtension As String = Path.GetExtension(sfileName)
3752
                If sExtension = ".xml" Then
3753
                    Dim sDwgName As String = Path.GetFileNameWithoutExtension(sfileName)
3754
                    Dim sDwgPath As String = sfileName
3755
                    Dim oNode As TreeNode = Tree_Result.Nodes(0).Nodes.Add(sDwgPath, sDwgName, 15)
3756
                    Dim oDwg As Drawing = AddSymbolItem(sDwgPath, oNode)
3757

    
3758
                    _DrawingsList.Add(oDwg)
3759
                End If
3760
            Next
3761
            Tree_Result.Nodes(0).Expand()
3762
        End If
3763
    End Sub
3764

    
3765
    Private Sub GenerateRelation(ByRef oDwg_Ds As Drawing)
3766
        Dim oLineLists As List(Of Line_no) = oDwg_Ds.Line_nos
3767
        Dim oEqpLists As List(Of Eqp_no) = oDwg_Ds.Eqp_nos
3768
        Dim oTrimLineLists As List(Of Line_no) = oDwg_Ds.TrimLine_nos
3769
        Dim oRelation As New GenerateRelation()
3770
        For Each oLinelist In oLineLists
3771
            oRelation.CalcLineConnectionItem_Equal(oLinelist.Dt_Line, oLineLists)
3772
            oRelation.CalcLineConnectionItem_NonEqual(oLinelist.Dt_Line, oLineLists)
3773
            oRelation.CalcSymbolConnectionItem_Equal(oLinelist.Dt_Symbol, oLineLists)
3774
            oRelation.CalcSymbolConnectionItem_NonEqual(oLinelist.Dt_Symbol, oLineLists)
3775
        Next
3776
    End Sub
3777

    
3778
    Private Sub SetSymbol_LineNumberByUID(ByVal symbols As List(Of Symbol), ByVal lineNumber As LineNumber, ByVal uid As String)
3779
        For Each symbol As Symbol In symbols
3780
            If symbol.UID = uid Then
3781
                symbol.LINENUMBER = lineNumber
3782
                Exit For
3783
            End If
3784
        Next
3785
    End Sub
3786

    
3787
    Private Sub SetLine_LineNumberByUID(ByVal lines As List(Of Line), ByVal lineNumber As LineNumber, ByVal uid As String)
3788
        For Each line As Line In lines
3789
            If line.UID = uid Then
3790
                line.LINENUMBER = lineNumber
3791
                Exit For
3792
            End If
3793
        Next
3794
    End Sub
3795

    
3796
    ''' <summary>
3797
    '''  XML Tree 구조 생성 
3798
    ''' </summary>
3799
    ''' <param name="sDwgPath"></param>
3800
    Private Function AddSymbolItem(ByVal sDwgPath As String, ByVal oParentNode As TreeNode) As Drawing
3801
        Dim oDwg_Ds As Drawing = LoadSymbolInXml(sDwgPath)
3802

    
3803
        If oDwg_Ds IsNot Nothing Then
3804

    
3805
            Dim oLineNos As List(Of LineNumber) = oDwg_Ds.LINENUMBERS
3806

    
3807
            Dim oTrimLines As List(Of LineNumber) = oDwg_Ds.TRIMLINES
3808

    
3809
            Dim oSymbols As List(Of Symbol) = oDwg_Ds.SYMBOLS
3810

    
3811
            Dim oLines As List(Of Line) = oDwg_Ds.LINES
3812

    
3813
            '' TreeView 구성 및 하위 아이템 상위 구성
3814
            ' LIne Number
3815
            For Each lineNo As LineNumber In oLineNos
3816
                Dim node As TreeNode = New TreeNode(lineNo.TEXT)
3817
                node.Name = lineNo.UID
3818
                node.Tag = lineNo
3819

    
3820
                oParentNode.Nodes.Add(node)
3821

    
3822
                For Each uid In lineNo.SYMBOLRUNITEMS
3823
                    SetSymbol_LineNumberByUID(oSymbols, lineNo, uid)
3824
                Next
3825

    
3826
                For Each uid In lineNo.LINERUNITEMS
3827
                    SetLine_LineNumberByUID(oLines, lineNo, uid)
3828
                Next
3829
            Next
3830

    
3831
            ' Trim Line
3832
            For index = 0 To oTrimLines.Count - 1
3833
                Dim trimLine As LineNumber = oTrimLines(index)
3834

    
3835
                Dim node As TreeNode = New TreeNode("TrimLine" + index.ToString)
3836
                node.Name = trimLine.UID
3837
                node.Tag = trimLine
3838

    
3839
                oParentNode.Nodes.Add(node)
3840

    
3841
                For Each uid In trimLine.SYMBOLRUNITEMS
3842
                    SetSymbol_LineNumberByUID(oSymbols, trimLine, uid)
3843
                Next
3844

    
3845
                For Each uid In trimLine.LINERUNITEMS
3846
                    SetLine_LineNumberByUID(oLines, trimLine, uid)
3847
                Next
3848
            Next
3849
            ' symbol
3850
            For Each symbol As Symbol In oSymbols
3851

    
3852
                Dim node As TreeNode = New TreeNode(symbol.PARENT)
3853
                node.Name = symbol.UID
3854
                node.Tag = symbol
3855

    
3856
                If symbol.SPPIDMAPPINGNAME = "" Then
3857
                    node.ForeColor = Color.Red
3858
                End If
3859

    
3860
                If symbol.LINENUMBER IsNot Nothing Then
3861
                    Dim nodeIndex As Integer = oParentNode.Nodes.IndexOfKey(symbol.LINENUMBER.UID)
3862
                    oParentNode.Nodes.Item(nodeIndex).Nodes.Add(node)
3863
                Else
3864
                    oParentNode.Nodes.Add(node)
3865
                End If
3866
            Next
3867
            ' line
3868
            For Each line As Line In oLines
3869

    
3870
                Dim node As TreeNode = New TreeNode(line.TYPE)
3871
                node.Name = line.UID
3872
                node.Tag = line
3873

    
3874
                If line.LINENUMBER IsNot Nothing Then
3875
                    Dim nodeIndex As Integer = oParentNode.Nodes.IndexOfKey(line.LINENUMBER.UID)
3876
                    oParentNode.Nodes.Item(nodeIndex).Nodes.Add(node)
3877
                Else
3878
                    oParentNode.Nodes.Add(node)
3879
                End If
3880

    
3881
                For index = 0 To 1
3882
                    If line.CONNECTORS(index).CONNECTEDITEM = line.UID Then
3883
                        Console.WriteLine("")
3884
                    End If
3885
                Next
3886
            Next
3887

    
3888
        End If
3889

    
3890
        Return oDwg_Ds
3891
    End Function
3892
    Private Sub Tree_Result_AfterCheck(sender As Object, e As TreeViewEventArgs) Handles Tree_Result.AfterCheck
3893
        If e.Node.Checked = True Then
3894
            For Each oNode As TreeNode In e.Node.Nodes
3895
                oNode.Checked = True
3896
            Next
3897
        Else
3898
            For Each oNode As TreeNode In e.Node.Nodes
3899
                oNode.Checked = False
3900
            Next
3901
        End If
3902
    End Sub
3903

    
3904
    Private Sub Btn_Setting_Click(sender As Object, e As EventArgs) Handles Btn_Setting.Click
3905
        Dim oSettings As Settings = New Settings()
3906
        oSettings.ShowDialog()
3907
    End Sub
3908

    
3909

    
3910
    Private Sub TestBranchLine()
3911
        Dim objPlacement As Placement
3912
        objPlacement = New Placement
3913
        Dim PipeRunLocation As String
3914
        Dim objItem As LMAItem
3915
        Dim objConnector As LMConnector
3916
        Dim objInputs As PlaceRunInputs
3917
        Dim objSymbol As LMSymbol
3918
        Dim ValveLocation As String
3919
        PipeRunLocation = "\Piping\Routing\Process Lines\Primary Piping.sym"
3920
        objInputs = New PlaceRunInputs
3921
        objInputs.AddPoint(0.1, 0.1)
3922
        objInputs.AddPoint(0.2, 0.1)
3923
        objItem = objPlacement.PIDCreateItem(PipeRunLocation)
3924
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
3925
        ValveLocation = "\Piping\Valves\2 Way Common\Ball Valve.sym"
3926
        objSymbol = objPlacement.PIDPlaceSymbol(ValveLocation, 0.15, 0.3, , 1.57)
3927
        objInputs = New PlaceRunInputs
3928
        objInputs.AddConnectorTarget(objConnector, 0.15, 0.1)
3929
        '   objInputs.AddConnectorTarget(objConnector, 0.12, 0.1)
3930
        objInputs.AddPoint(0.15, 0.15)
3931
        objInputs.AddPoint(0.12, 0.15)
3932
        objInputs.AddPoint(0.12, 0.2)
3933
        objInputs.AddPoint(0.15, 0.2)
3934
        objInputs.AddSymbolTarget(objSymbol, 0.15, 0.3)
3935
        objItem = objPlacement.PIDCreateItem(PipeRunLocation)
3936
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
3937

    
3938
        objInputs = New PlaceRunInputs
3939
        objInputs.AddConnectorTarget(objConnector, 0.17, 0.1)
3940
        objInputs.AddPoint(0.17, 0.15)
3941
        objItem = objPlacement.PIDCreateItem(PipeRunLocation)
3942
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
3943

    
3944
        objInputs = New PlaceRunInputs
3945
        objInputs.AddConnectorTarget(objConnector, 0.19, 0.1)
3946
        objInputs.AddPoint(0.19, 0.15)
3947
        objItem = objPlacement.PIDCreateItem(PipeRunLocation)
3948
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
3949

    
3950
        objInputs = New PlaceRunInputs
3951
        objInputs.AddConnectorTarget(objConnector, 0.12, 0.1)
3952
        objInputs.AddPoint(0.12, 0.15)
3953
        objItem = objPlacement.PIDCreateItem(PipeRunLocation)
3954
        objConnector = objPlacement.PIDPlaceRun(objItem, objInputs)
3955
    End Sub
3956

    
3957
    Private Sub Btn_TestNozzle_Click(sender As Object, e As EventArgs) Handles Btn_TestNozzle.Click
3958

    
3959
        Dim sVessel_ID As String = "841D5E640AE5421B9A017DDC2E87FF11"
3960
        Dim objVessel As LMVessel
3961
        objVessel = _Placement.PIDDataSource.GetVessel(sVessel_ID)
3962
        Dim oVesselLocation As LMLocations = objVessel.Locations
3963
        Dim symVessel As LMSymbol = _Placement.PIDDataSource.GetSymbol(objVessel.Representations.Nth(1).Id)
3964
        Dim XCoordinate As String = symVessel.Attributes("XCoordinate").Value
3965
        Dim YCoordinate As String = symVessel.Attributes("YCoordinate").Value
3966
        symVessel.Attributes("XCoordinate").Value = XCoordinate + 0.01
3967
        symVessel.Attributes("YCoordinate").Value = YCoordinate + 0.01
3968
        symVessel.Commit()
3969
        Dim sValve_ID As String = "DB7B0CA8A2664A6BA7A9615764BA62B0"
3970
        Dim objValve As LMSymbol
3971
        Dim objValves As LMPipingComp = _Placement.PIDDataSource.GetPipingComp(sValve_ID)
3972
        objValve = _Placement.PIDDataSource.GetSymbol(objValves.Representations.Nth(1).Id)
3973
        objValve.Commit()
3974
        Dim dVesselX As Double = XCoordinate
3975
        Dim dVesselY As Double = YCoordinate
3976
        Dim X1 As Double, Y1 As Double, X2 As Double, Y2 As Double
3977

    
3978
        _Placement.PIDConnectPointLocation(objValve, 1, X1, Y1)
3979

    
3980
        _Placement.PIDConnectPointLocation(objValve, 2, X2, Y2)
3981

    
3982
        Dim nozzlename As String = "\Equipment Components\Nozzles\Flanged Nozzle.sym"
3983
        Dim dCalc_x As Double = 0
3984
        Dim dCalc_y As Double = 0
3985

    
3986
        If dVesselX - X2 > 0 Then
3987
            dCalc_x = dVesselX - (dVesselX - X2)
3988
        Else
3989
            dCalc_x = dVesselX + (X2 - dVesselX)
3990
        End If
3991
        If dVesselY - Y2 > 0 Then
3992
            dCalc_y = dVesselY - (dVesselY - Y2)
3993
        Else
3994
            dCalc_y = dVesselY + (Y2 - dVesselY)
3995
        End If
3996

    
3997
        Dim objNozzle As LMSymbol = _Placement.PIDPlaceSymbol(nozzlename, dCalc_x, dCalc_y,
3998
            TargetItem:=symVessel.AsLMRepresentation)
3999

    
4000
        Dim blnSuccess As Boolean = _Placement.PIDConnectPointLocation(objNozzle, 1, X1, Y1)
4001
        blnSuccess = _Placement.PIDConnectPointLocation(objNozzle, 2, X1, Y1)
4002

    
4003
        objValve = _Placement.PIDPlaceSymbol(objValve.FileName, X1, Y1, ExistingItem:=objValve.AsLMAItem,
4004
          TargetItem:=objNozzle.AsLMRepresentation)
4005

    
4006

    
4007

    
4008
    End Sub
4009

    
4010
    Private Sub Btn_SymbolLibrary_Click(sender As Object, e As EventArgs) Handles Btn_SymbolLibrary.Click
4011
        Dim oMapping As New Mapping(_PIDSymbol_DB)
4012
        oMapping.Show()
4013
    End Sub
4014

    
4015
    Private Sub Btn_Stop_Click(sender As Object, e As EventArgs) Handles Btn_Stop.Click
4016
        Try
4017
            SetListBoxItems(ListBox_Result, " Auto converting 중지....")
4018
            ComUtil.MessageLog.CEventLog.Log_Write_Update(_Log_Path, _Log_File, " Auto converting 중지....")
4019
            _Main_trd.Abort()
4020
            _Opc_trd.Abort()
4021
        Catch ex As Exception
4022

    
4023
        End Try
4024
    End Sub
4025

    
4026
    Private Sub AutoCheckTreeNode(ByVal iType As Integer, ByVal bCheck As Boolean)
4027

    
4028
        For Each oDrwing As TreeNode In Tree_Result.Nodes
4029
            For Each oDwgNode As TreeNode In oDrwing.Nodes
4030
                Dim sDwgName As String = Path.GetFileNameWithoutExtension(oDwgNode.Text)
4031
                Dim CDrawing As Drawing = GetDrawing(sDwgName)
4032
                If CDrawing IsNot Nothing Then
4033
                    Dim iAllLineNoCount As Integer = Tree_Result.Nodes.Count ' GetCheckNodeCount(oLinenoNode)
4034
                    Dim iPipingOPC_count As Integer = 0 ' GetCheckNodeCount(oLinenoNode)
4035
                    For Each oNode As TreeNode In oDwgNode.Nodes
4036
                        Dim iItemcnt As Integer = 0
4037
                        Dim sNodeUid As String = oNode.Name
4038
                        Dim oPipeRun_Dt As DataTable = PipeRun_Dt()
4039

    
4040
                        If iType = 0 Then 'Symbol
4041
                            Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
4042
                            If CLineNo IsNot Nothing Then
4043
                                Dim oSymbol_Dt As DataTable = CLineNo.Dt_Symbol
4044
                                For Each oSymbolRow In oSymbol_Dt.Rows
4045
                                    Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID).ToString()
4046
                                    For Each oSymbolNode As TreeNode In oNode.Nodes
4047
                                        Dim sSymbolNodeUid As String = oSymbolNode.Name
4048
                                        If sSymbolNodeUid = sSymbolUid Then
4049
                                            oSymbolNode.Checked = bCheck
4050
                                            Exit For
4051
                                        End If
4052
                                    Next
4053
                                Next
4054
                            End If
4055
                            Dim TrimLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
4056
                            If TrimLineNo IsNot Nothing Then
4057
                                Dim oSymbol_Dt As DataTable = TrimLineNo.Dt_Symbol
4058
                                For Each oSymbolRow In oSymbol_Dt.Rows
4059
                                    Dim sSymbolUid As String = oSymbolRow(_XML_SYMBOL_UID).ToString()
4060
                                    For Each oSymbolNode As TreeNode In oNode.Nodes
4061
                                        Dim sSymbolNodeUid As String = oSymbolNode.Name
4062
                                        If sSymbolNodeUid = sSymbolUid Then
4063
                                            oSymbolNode.Checked = bCheck
4064
                                            Exit For
4065
                                        End If
4066
                                    Next
4067
                                Next
4068
                            End If
4069
                        End If
4070
                        If iType = 1 Then 'Line
4071
                            Dim CLineNo As Line_no = GetLineNo(CDrawing, sNodeUid)
4072
                            If CLineNo IsNot Nothing Then
4073
                                Dim oLine_Dt As DataTable = CLineNo.Dt_Line
4074
                                For Each oLineRow In oLine_Dt.Rows
4075
                                    Dim sLineUid As String = oLineRow(_XML_LINE_UID).ToString()
4076
                                    For Each oLineNode As TreeNode In oNode.Nodes
4077
                                        Dim sLineNodeUid As String = oLineNode.Name
4078
                                        If sLineNodeUid = sLineUid Then
4079
                                            oLineNode.Checked = bCheck
4080
                                            Exit For
4081
                                        End If
4082
                                    Next
4083
                                Next
4084
                            End If
4085
                            Dim TrimLineNo As Line_no = GetTrimLineNo(CDrawing, sNodeUid)
4086
                            If TrimLineNo IsNot Nothing Then
4087
                                Dim oLine_Dt As DataTable = TrimLineNo.Dt_Line
4088
                                For Each oLineRow In oLine_Dt.Rows
4089
                                    Dim sLineUid As String = oLineRow(_XML_SYMBOL_UID).ToString()
4090
                                    For Each oLineNode As TreeNode In oNode.Nodes
4091
                                        Dim sLineNodeUid As String = oLineNode.Name
4092
                                        If sLineNodeUid = sLineUid Then
4093
                                            oLineNode.Checked = bCheck
4094
                                            Exit For
4095
                                        End If
4096
                                    Next
4097
                                Next
4098
                            End If
4099
                        End If
4100
                        If iType = 2 Then 'Equipment
4101
                            Dim CEqpNo As Eqp_no = GetEqpNo(CDrawing, sNodeUid)
4102
                            If CEqpNo IsNot Nothing Then
4103
                                Dim oEqp_Dt As DataTable = CEqpNo.Dt_Equipment
4104
                                For Each oEqpRow In oEqp_Dt.Rows
4105
                                    Dim sEqpUid As String = oEqpRow(_XML_LINE_UID).ToString()
4106
                                    For Each oEqpNode As TreeNode In oNode.Nodes
4107
                                        Dim sEqpNodeUid As String = oEqpNode.Name
4108
                                        If sEqpNodeUid = sEqpUid Then
4109
                                            oEqpNode.Checked = bCheck
4110
                                            Exit For
4111
                                        End If
4112
                                    Next
4113
                                Next
4114
                            End If
4115
                        End If
4116
                    Next
4117
                End If
4118
            Next
4119
        Next
4120

    
4121

    
4122
    End Sub
4123

    
4124

    
4125

    
4126
    Private Sub Chk_Symbol_CheckedChanged(sender As Object, e As EventArgs) Handles Chk_Symbol.CheckedChanged
4127
        AutoCheckTreeNode(0, Chk_Symbol.Checked)
4128
    End Sub
4129

    
4130
    Private Sub Chk_Line_CheckedChanged(sender As Object, e As EventArgs) Handles Chk_Line.CheckedChanged
4131
        AutoCheckTreeNode(1, Chk_Line.Checked)
4132
    End Sub
4133

    
4134
    Private Sub Chk_Equipment_CheckedChanged(sender As Object, e As EventArgs) Handles Chk_Equipment.CheckedChanged
4135
        AutoCheckTreeNode(2, Chk_Equipment.Checked)
4136
    End Sub
4137
End Class
4138

    
4139

    
4140
Public Class DrawingInfo
4141
    Public mDrawingName As String
4142
    Public mSpID As String
4143
    Public mPath As String
4144
End Class
클립보드 이미지 추가 (최대 크기: 500 MB)