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 |
|
Public Class AutoModeling
|
10 |
|
|
11 |
|
Public Shared CDrawing As Drawing
|
12 |
|
Private PipeRunPoint As Dictionary(Of String, List(Of Pointd))
|
13 |
|
Private sCnt As Integer
|
14 |
|
Friend WithEvents ListBox_Result As ListBox
|
15 |
|
|
16 |
|
Public Sub New(ByVal cDrawing As Drawing, ByVal ListBox_Result As ListBox)
|
17 |
|
AutoModeling.CDrawing = cDrawing
|
18 |
|
Me.PipeRunPoint = New Dictionary(Of String, List(Of Pointd))
|
19 |
|
Me.ListBox_Result = ListBox_Result
|
20 |
|
End Sub
|
21 |
|
|
22 |
|
|
23 |
|
Public Sub StartModeling()
|
24 |
|
Try
|
25 |
|
Dim CGroupList As List(Of ItemGroup) = GetGroupList()
|
26 |
|
DrawItemGroup(CGroupList)
|
27 |
|
DrawTextItem()
|
28 |
|
|
29 |
|
Catch ex As Exception
|
30 |
|
Console.WriteLine(ex.Message)
|
31 |
|
End Try
|
32 |
|
End Sub
|
33 |
|
Private Sub DrawLineNumber(ByVal lineUID As String)
|
34 |
|
Dim lineNumbers As List(Of LineNumber) = CDrawing.LINENUMBERS
|
35 |
|
|
36 |
|
For Each lineNumber As LineNumber In lineNumbers
|
37 |
|
If lineNumber.CONNECTLINE = lineUID Then
|
38 |
|
Dim _targetLine As Line = FindLineByUID(CDrawing.LINES, lineNumber.CONNECTLINE)
|
39 |
|
If _targetLine IsNot Nothing Then
|
40 |
|
lineNumber.TARGETLINE = _targetLine
|
41 |
|
lineNumber.Modeling()
|
42 |
|
lineNumber.SetAttribute()
|
43 |
|
End If
|
44 |
|
End If
|
45 |
|
Next
|
46 |
|
End Sub
|
47 |
|
|
48 |
|
Private Sub DrawTextItem()
|
49 |
|
Dim _texts As List(Of Text) = CDrawing.TEXTS
|
50 |
|
|
51 |
|
For Each _text As Text In _texts
|
52 |
|
If _text.NAME = "TEXT" And String.IsNullOrEmpty(_text.OWNER) Then
|
53 |
|
_text.Modeling()
|
54 |
|
ElseIf _text.NAME = "SIZE" And String.IsNullOrEmpty(_text.OWNER) = False Then
|
55 |
|
_text.Modeling()
|
56 |
|
_text.SetAttribute()
|
57 |
|
End If
|
58 |
|
Next
|
59 |
|
End Sub
|
60 |
|
|
61 |
|
Private Sub IfContainLineNumber(ByVal lineUID As String)
|
62 |
|
Dim lineNumbers As List(Of LineNumber) = CDrawing.LINENUMBERS
|
63 |
|
|
64 |
|
For Each lineNumber As LineNumber In lineNumbers
|
65 |
|
If lineNumber.CONNECTLINE = lineUID Then
|
66 |
|
Dim _targetLine As Line = FindLineByUID(CDrawing.LINES, lineNumber.CONNECTLINE)
|
67 |
|
If _targetLine IsNot Nothing Then
|
68 |
|
lineNumber.TARGETLINE = _targetLine
|
69 |
|
lineNumber.Modeling()
|
70 |
|
lineNumber.SetAttribute()
|
71 |
|
End If
|
72 |
|
|
73 |
|
Exit For
|
74 |
|
End If
|
75 |
|
Next
|
76 |
|
End Sub
|
77 |
|
|
78 |
|
Private Sub IfContainSizeLabel(ByVal lineUID As String)
|
79 |
|
Dim _texts As List(Of Text) = CDrawing.TEXTS
|
80 |
|
For Each _text As Text In _texts
|
81 |
|
If _text.OWNER = lineUID Then
|
82 |
|
_text.SetAttribute()
|
83 |
|
Exit For
|
84 |
|
End If
|
85 |
|
Next
|
86 |
|
End Sub
|
87 |
|
|
88 |
|
Private Sub DrawItemGroup(ByVal CGroupList As List(Of ItemGroup))
|
89 |
|
sCnt = 1
|
90 |
|
For Each itemGroup As ItemGroup In CGroupList
|
91 |
|
DrawGroup_Symbol(itemGroup)
|
92 |
|
Next
|
93 |
|
sCnt = 1
|
94 |
|
While CGroupList.Count > 0
|
95 |
|
For Each itemGroup As ItemGroup In CGroupList
|
96 |
|
If IsCanDraw(itemGroup) Then
|
97 |
|
DrawGroup_Line(itemGroup)
|
98 |
|
'DrawGroup(itemGroup)
|
99 |
|
CGroupList.Remove(itemGroup)
|
100 |
|
Exit For
|
101 |
|
Else
|
102 |
|
Continue For
|
103 |
|
End If
|
104 |
|
Next
|
105 |
|
End While
|
106 |
|
End Sub
|
107 |
|
|
108 |
|
Private Sub DrawGroup(ByVal itemGroup As ItemGroup)
|
109 |
|
|
110 |
|
If DrawGroup_Symbol(itemGroup) Then
|
111 |
|
DrawGroup_Line(itemGroup)
|
112 |
|
Else
|
113 |
|
Return
|
114 |
|
End If
|
115 |
|
End Sub
|
116 |
|
|
117 |
|
Private Function DrawGroup_Symbol(ByVal itemGroup As ItemGroup) As Boolean
|
118 |
|
Dim list As List(Of Object) = itemGroup.Group
|
119 |
|
Dim prevSymbol As Symbol = Nothing
|
120 |
|
Dim prevIndex As Integer = 0
|
121 |
|
|
122 |
|
For index = 0 To list.Count - 1
|
123 |
|
Dim obj As Object = list(index)
|
124 |
|
If TypeOf (obj) Is Symbol Then
|
125 |
|
Dim symbol As Symbol = obj
|
126 |
|
'' PrevSymbol과 현재의 Symbol 비교하여 그리기
|
127 |
|
If prevSymbol IsNot Nothing Then
|
128 |
|
Dim prevSlope As SlopType = SlopType.NONE
|
129 |
|
For lineIndex = prevIndex + 1 To index - 1
|
130 |
|
Dim _line As Line = list(lineIndex)
|
131 |
|
If prevSlope = SlopType.NONE Then
|
132 |
|
prevSlope = _line.SLOPTYPE
|
133 |
|
ElseIf prevSlope <> _line.SLOPTYPE Then
|
134 |
|
prevSlope = SlopType.NONE
|
135 |
|
Exit For
|
136 |
|
End If
|
137 |
|
Next
|
138 |
|
If prevSlope = SlopType.HORIZONTAL Then
|
139 |
|
symbol.LOCATION_Y = prevSymbol.SPPID_ITEM_OBJECT.YCoordinate
|
140 |
|
ElseIf prevSlope = SlopType.VERTICAL Then
|
141 |
|
symbol.LOCATION_X = prevSymbol.SPPID_ITEM_OBJECT.XCoordinate
|
142 |
|
End If
|
143 |
|
End If
|
144 |
|
SetListBoxItems(ListBox_Result, "Create Symbol (" + sCnt.ToString + "/" + CDrawing.SYMBOLS.Count.ToString + ") UID : " + symbol.UID)
|
145 |
|
sCnt += 1
|
146 |
|
symbol.Modeling()
|
147 |
|
If symbol.SPPID_ITEM_OBJECT IsNot Nothing Then
|
148 |
|
prevSymbol = symbol
|
149 |
|
prevIndex = index
|
150 |
|
Else
|
151 |
|
Return False
|
152 |
|
End If
|
153 |
|
End If
|
154 |
|
Next
|
155 |
|
Return True
|
156 |
|
End Function
|
157 |
|
|
158 |
|
Private Function DrawGroup_Line(ByVal itemGroup As ItemGroup) As Boolean
|
159 |
|
Dim list As List(Of Object) = itemGroup.Group
|
160 |
|
Dim _Placement As Placement = New Placement
|
161 |
|
Dim allLine As List(Of Line) = New List(Of Line)
|
162 |
|
Dim lineList As List(Of Line) = New List(Of Line)
|
163 |
|
Dim pipeRuns As LMPipeRuns = New LMPipeRuns
|
164 |
|
|
165 |
|
For index = 0 To list.Count - 1
|
166 |
|
Dim obj As Object = list(index)
|
167 |
|
|
168 |
|
If TypeOf (obj) Is Line Then
|
169 |
|
Dim line As Line = obj
|
170 |
|
lineList.Add(line)
|
171 |
|
allLine.Add(line)
|
172 |
|
SetListBoxItems(ListBox_Result, "Grouping Line (" + sCnt.ToString + "/" + CDrawing.LINES.Count.ToString + ") UID : " + line.UID)
|
173 |
|
sCnt += 1
|
174 |
|
ElseIf lineList.Count > 0 Then
|
175 |
|
SetListBoxItems(ListBox_Result, "DrawLine : " + lineList.Count.ToString)
|
176 |
|
Dim lmConnector As LMConnector = DrawLine(GetLinePoints(lineList), lineList(0).SPPIDMAPPINGNAME)
|
177 |
|
If lmConnector IsNot Nothing Then
|
178 |
|
For Each _line As Line In lineList
|
179 |
|
_line.LMCONNECTOR_MODELID = lmConnector.ModelItemID
|
180 |
|
IfContainLineNumber(_line.UID)
|
181 |
|
IfContainSizeLabel(_line.UID)
|
182 |
|
Next
|
183 |
|
pipeRuns.Add(_Placement.PIDDataSource.GetPipeRun(lmConnector.ModelItemID))
|
184 |
|
End If
|
185 |
|
lineList = New List(Of Line)
|
186 |
|
End If
|
187 |
|
Next
|
188 |
|
|
189 |
|
If lineList.Count > 0 Then
|
190 |
|
SetListBoxItems(ListBox_Result, "DrawLine : " + lineList.Count.ToString)
|
191 |
|
Dim lmConnector As LMConnector = DrawLine(GetLinePoints(lineList), lineList(0).SPPIDMAPPINGNAME)
|
192 |
|
If lmConnector IsNot Nothing Then
|
193 |
|
For Each _line As Line In lineList
|
194 |
|
_line.LMCONNECTOR_MODELID = lmConnector.ModelItemID
|
195 |
|
IfContainLineNumber(_line.UID)
|
196 |
|
IfContainSizeLabel(_line.UID)
|
197 |
|
Next
|
198 |
|
pipeRuns.Add(_Placement.PIDDataSource.GetPipeRun(lmConnector.ModelItemID))
|
199 |
|
End If
|
200 |
|
End If
|
201 |
|
|
202 |
|
''' Pipe Run Join
|
203 |
|
'For Each run As LMPipeRun In pipeRuns
|
204 |
|
' Dim objSurvivorItem As LMAItem
|
205 |
|
' Dim prevUID As String = run.AsLMAItem.Id
|
206 |
|
' _Placement.PIDAutoJoin(run.AsLMAItem, AutoJoinEndConstants.autoJoin_Both, objSurvivorItem)
|
207 |
|
' If objSurvivorItem IsNot Nothing Then
|
208 |
|
' Dim newUID = objSurvivorItem.Id
|
209 |
|
' For Each obj As Object In list
|
210 |
|
' If TypeOf (obj) Is Line Then
|
211 |
|
' Dim line As Line = obj
|
212 |
|
' If line.LMCONNECTOR_MODELID = prevUID Then
|
213 |
|
' line.LMCONNECTOR_MODELID = newUID
|
214 |
|
' End If
|
215 |
|
' End If
|
216 |
|
' Next
|
217 |
|
' End If
|
218 |
|
'Next
|
219 |
|
|
220 |
|
|
221 |
|
''' 일반 조인 확인 중
|
222 |
|
'For index = 0 To testList.Count - 2
|
223 |
|
' If testList(index) = testList(index + 1) Then
|
224 |
|
' Continue For
|
225 |
|
' End If
|
226 |
|
' Dim run1 As LMAItem = _Placement.PIDDataSource.GetPipeRun(testList(index)).AsLMAItem
|
227 |
|
' Dim run2 As LMAItem = _Placement.PIDDataSource.GetPipeRun(testList(index + 1)).AsLMAItem
|
228 |
|
' _Placement.PIDJoinRuns(run2, run1)
|
229 |
|
' testList(index) = run1.Id
|
230 |
|
' Console.WriteLine(run1.Id)
|
231 |
|
' testList(index + 1) = run2.Id
|
232 |
|
' Console.WriteLine(run2.Id)
|
233 |
|
'Next
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
'' Branch를 위해서 만들어진 Points 정리
|
241 |
|
SetGroupPoints(allLine)
|
242 |
|
|
243 |
|
'For Each dic In PipeRunPoint
|
244 |
|
' Dim points As List(Of Pointd) = dic.Value
|
245 |
|
' Debug.WriteLine("-----------------------------" + dic.Key + "-----------------------------")
|
246 |
|
' For Each point In points
|
247 |
|
' Debug.WriteLine(point.X.ToString + "/" + point.Y.ToString + "/" + point.PointInfo)
|
248 |
|
' Next
|
249 |
|
' Debug.WriteLine("----------------------------- end " + "-----------------------------")
|
250 |
|
'Next
|
251 |
|
|
252 |
|
Return True
|
253 |
|
End Function
|
254 |
|
|
255 |
|
Private Sub SetGroupPoints(ByVal lines As List(Of Line))
|
256 |
|
'Dim _temp As List(Of String) = New List(Of String)
|
257 |
|
|
258 |
|
For Each line As Line In lines
|
259 |
|
'' 순서로 들어옴
|
260 |
|
Dim sModelId As String = line.LMCONNECTOR_MODELID
|
261 |
|
If PipeRunPoint.ContainsKey(sModelId) = False Then
|
262 |
|
PipeRunPoint.Add(sModelId, New List(Of Pointd))
|
263 |
|
End If
|
264 |
|
|
265 |
|
Dim pointList As List(Of Pointd) = PipeRunPoint(sModelId)
|
266 |
|
If pointList.Count > 0 Then
|
267 |
|
Dim lastPoint As Pointd = pointList(pointList.Count - 1)
|
268 |
|
|
269 |
|
Dim point1 As Pointd = New Pointd(line.START_X, line.START_Y)
|
270 |
|
point1.ConnectedUID = line.CONNECTORS(0).CONNECTEDITEM
|
271 |
|
point1.PointInfo = GetPointState(line.UID, point1.ConnectedUID)
|
272 |
|
point1.SP_ID = GetSymbolSP_ID(point1.ConnectedUID)
|
273 |
|
point1.Line = line
|
274 |
|
|
275 |
|
Dim point2 As Pointd = New Pointd(line.END_X, line.END_Y)
|
276 |
|
point2.ConnectedUID = line.CONNECTORS(1).CONNECTEDITEM
|
277 |
|
point2.PointInfo = GetPointState(line.UID, point2.ConnectedUID)
|
278 |
|
point2.SP_ID = GetSymbolSP_ID(point2.ConnectedUID)
|
279 |
|
point2.Line = line
|
280 |
|
|
281 |
|
If point1.ConnectedUID = lastPoint.Line.UID Then
|
282 |
|
pointList.Add(point2)
|
283 |
|
ElseIf point2.ConnectedUID = lastPoint.Line.UID Then
|
284 |
|
pointList.Add(point1)
|
285 |
|
ElseIf lastPoint.ConnectedUID = point1.ConnectedUID Then
|
286 |
|
pointList.Add(point1)
|
287 |
|
pointList.Add(point2)
|
288 |
|
ElseIf lastPoint.ConnectedUID = point2.ConnectedUID Then
|
289 |
|
pointList.Add(point2)
|
290 |
|
pointList.Add(point1)
|
291 |
|
Else
|
292 |
|
Throw New Exception("Logic Error")
|
293 |
|
End If
|
294 |
|
|
295 |
|
Else
|
296 |
|
Dim UIDList As List(Of String) = New List(Of String)
|
297 |
|
UIDList.Add(line.UID)
|
298 |
|
If IsStartOrLastPointByModelId(line.CONNECTORS(0).CONNECTEDITEM, line.LMCONNECTOR_MODELID, UIDList) Then
|
299 |
|
Dim point1 As Pointd = New Pointd(line.START_X, line.START_Y)
|
300 |
|
point1.ConnectedUID = line.CONNECTORS(0).CONNECTEDITEM
|
301 |
|
point1.PointInfo = GetPointState(line.UID, point1.ConnectedUID)
|
302 |
|
point1.Line = line
|
303 |
|
point1.SP_ID = GetSymbolSP_ID(point1.ConnectedUID)
|
304 |
|
pointList.Add(point1)
|
305 |
|
|
306 |
|
Dim point2 As Pointd = New Pointd(line.END_X, line.END_Y)
|
307 |
|
point2.ConnectedUID = line.CONNECTORS(1).CONNECTEDITEM
|
308 |
|
point2.PointInfo = GetPointState(line.UID, point2.ConnectedUID)
|
309 |
|
point2.Line = line
|
310 |
|
point2.SP_ID = GetSymbolSP_ID(point2.ConnectedUID)
|
311 |
|
pointList.Add(point2)
|
312 |
|
ElseIf IsStartOrLastPointByModelId(line.CONNECTORS(1).CONNECTEDITEM, line.LMCONNECTOR_MODELID, UIDList) Then
|
313 |
|
Dim point2 As Pointd = New Pointd(line.END_X, line.END_Y)
|
314 |
|
point2.ConnectedUID = line.CONNECTORS(1).CONNECTEDITEM
|
315 |
|
point2.PointInfo = GetPointState(line.UID, point2.ConnectedUID)
|
316 |
|
point2.Line = line
|
317 |
|
point2.SP_ID = GetSymbolSP_ID(point2.ConnectedUID)
|
318 |
|
pointList.Add(point2)
|
319 |
|
|
320 |
|
Dim point1 As Pointd = New Pointd(line.START_X, line.START_Y)
|
321 |
|
point1.ConnectedUID = line.CONNECTORS(0).CONNECTEDITEM
|
322 |
|
point1.PointInfo = GetPointState(line.UID, point1.ConnectedUID)
|
323 |
|
point1.Line = line
|
324 |
|
point1.SP_ID = GetSymbolSP_ID(point1.ConnectedUID)
|
325 |
|
pointList.Add(point1)
|
326 |
|
Else
|
327 |
|
Throw New Exception("Logic Error")
|
328 |
|
End If
|
329 |
|
|
330 |
|
End If
|
331 |
|
Next
|
332 |
|
End Sub
|
333 |
|
|
334 |
|
Private Function GetSymbolSP_ID(ByVal symbolUID As String) As String
|
335 |
|
Dim symbol As Symbol = FindSymbolByUID(CDrawing.SYMBOLS, symbolUID)
|
336 |
|
If symbol IsNot Nothing Then
|
337 |
|
Return symbol.SPPID_ITEM_OBJECT.AsLMRepresentation.Id
|
338 |
|
Else
|
339 |
|
Return ""
|
340 |
|
End If
|
341 |
|
|
342 |
|
End Function
|
343 |
|
|
344 |
|
Private Function GetPointState(ByVal lineUID As String, ByVal connectedItem As String) As String
|
345 |
|
If IsBranchLine(connectedItem, lineUID, CDrawing.LINES) Then
|
346 |
|
Return "BRANCH"
|
347 |
|
ElseIf FindSymbolByUID(CDrawing.SYMBOLS, connectedItem) IsNot Nothing Then
|
348 |
|
Return "SYMBOL"
|
349 |
|
ElseIf FindLineByUID(CDrawing.LINES, connectedItem) IsNot Nothing Then
|
350 |
|
Return "RUN"
|
351 |
|
ElseIf String.IsNullOrEmpty(connectedItem) Then
|
352 |
|
Return "RUN"
|
353 |
|
ElseIf connectedItem = "None" Then
|
354 |
|
Return "Run"
|
355 |
|
Else
|
356 |
|
Throw New Exception("Logic Error")
|
357 |
|
End If
|
358 |
|
End Function
|
359 |
|
|
360 |
|
Private Function FindFirstOrLastLMConnector(ByVal modelId As String) As LMConnector
|
361 |
|
Dim _Placement As Placement = New Placement
|
362 |
|
Dim lmPipeRun As LMPipeRun = _Placement.PIDDataSource.GetPipeRun(modelId)
|
363 |
|
|
364 |
|
For Each oRep As LMRepresentation In lmPipeRun.Representations
|
365 |
|
If oRep.Attributes("RepresentationType").Value = "Connector" And oRep.Attributes("ItemStatus").Value = "Active" Then
|
366 |
|
Dim _conn As LMConnector = _Placement.PIDDataSource.GetConnector(oRep.Id)
|
367 |
|
|
368 |
|
Dim connectedItem As LMSymbol = _conn.ConnectItem1SymbolObject
|
369 |
|
If connectedItem Is Nothing Then
|
370 |
|
Return _conn
|
371 |
|
ElseIf connectedItem.RepresentationType.ToString = "" Then
|
372 |
|
Debug.WriteLine(connectedItem.RepresentationType.ToString)
|
373 |
|
Else
|
374 |
|
Debug.WriteLine(connectedItem.RepresentationType.ToString)
|
375 |
|
End If
|
376 |
|
|
377 |
|
connectedItem = _conn.ConnectItem2SymbolObject
|
378 |
|
If connectedItem Is Nothing Then
|
379 |
|
Return _conn
|
380 |
|
ElseIf connectedItem.RepresentationType.ToString = "" Then
|
381 |
|
Debug.WriteLine(connectedItem.RepresentationType.ToString)
|
382 |
|
Else
|
383 |
|
Debug.WriteLine(connectedItem.RepresentationType.ToString)
|
384 |
|
End If
|
385 |
|
|
386 |
|
End If
|
387 |
|
Next
|
388 |
|
|
389 |
|
Return Nothing
|
390 |
|
End Function
|
391 |
|
|
392 |
|
|
393 |
|
''' <summary>
|
394 |
|
''' Branch, 심볼, 비어있으면 마지막 ConnectorPoint라는 것을 알아냄 - 전체 Model ID가 아닌 부분 Line 기준
|
395 |
|
''' </summary>
|
396 |
|
''' <param name="lineUID"></param>
|
397 |
|
''' <param name="connectedItem"></param>
|
398 |
|
''' <returns></returns>
|
399 |
|
Private Function IsStartOrLastPointForSplitLine(ByVal lineUID As String, ByVal connectedItem As String, Optional ByVal containSymbol As Boolean = True) As Boolean
|
400 |
|
If IsBranchLine(connectedItem, lineUID, CDrawing.LINES) Then
|
401 |
|
Return True
|
402 |
|
ElseIf FindSymbolByUID(CDrawing.SYMBOLS, connectedItem) IsNot Nothing And containSymbol Then
|
403 |
|
Return True
|
404 |
|
ElseIf connectedItem = "None" Then
|
405 |
|
Return True
|
406 |
|
ElseIf String.IsNullOrEmpty(connectedItem) Then
|
407 |
|
Return True
|
408 |
|
End If
|
409 |
|
Return False
|
410 |
|
End Function
|
411 |
|
|
412 |
|
Private Function IsStartOrLastPointByModelId(ByVal connectedItemUID As String, ByVal modelId As String, ByVal UIDList As List(Of String)) As Boolean
|
413 |
|
Dim connectedSymbol As Symbol = FindSymbolByUID(CDrawing.SYMBOLS, connectedItemUID)
|
414 |
|
Dim connectedLine As Line = FindLineByUID(CDrawing.LINES, connectedItemUID)
|
415 |
|
Dim result As Boolean = True
|
416 |
|
|
417 |
|
UIDList.Add(connectedItemUID)
|
418 |
|
|
419 |
|
If connectedSymbol IsNot Nothing Then
|
420 |
|
For Each connector As Connector In connectedSymbol.CONNECTORS
|
421 |
|
If connector.CONNECTEDITEM <> connectedItemUID Then
|
422 |
|
If UIDList.Contains(connector.CONNECTEDITEM) = False Then
|
423 |
|
If IsStartOrLastPointByModelId(connector.CONNECTEDITEM, modelId, UIDList) = False Then
|
424 |
|
result = False
|
425 |
|
End If
|
426 |
|
End If
|
427 |
|
End If
|
428 |
|
Next
|
429 |
|
ElseIf connectedLine IsNot Nothing Then
|
430 |
|
If connectedLine.LMCONNECTOR_MODELID = modelId Then
|
431 |
|
result = False
|
432 |
|
End If
|
433 |
|
End If
|
434 |
|
|
435 |
|
Return result
|
436 |
|
End Function
|
437 |
|
|
438 |
|
Private Function GetLinePoints(ByVal lineList As List(Of Line)) As List(Of Pointd)
|
439 |
|
Try
|
440 |
|
Dim points As List(Of Pointd) = GetGroupPoint(lineList)
|
441 |
|
|
442 |
|
Dim startLine As Line = lineList(0)
|
443 |
|
Dim endLine As Line = lineList(lineList.Count - 1)
|
444 |
|
|
445 |
|
Dim startConnItem1 As String = startLine.CONNECTORS(0).CONNECTEDITEM
|
446 |
|
Dim startConnItem2 As String = startLine.CONNECTORS(1).CONNECTEDITEM
|
447 |
|
Dim endConnItem1 As String = endLine.CONNECTORS(0).CONNECTEDITEM
|
448 |
|
Dim endConnItem2 As String = endLine.CONNECTORS(1).CONNECTEDITEM
|
449 |
|
|
450 |
|
If lineList.Count = 1 Then
|
451 |
|
Dim point As Pointd = points(0)
|
452 |
|
point.ConnectedUID = startConnItem1
|
453 |
|
points(0) = point
|
454 |
|
Dim point2 As Pointd = points(1)
|
455 |
|
point2.ConnectedUID = startConnItem2
|
456 |
|
points(1) = point2
|
457 |
|
Else
|
458 |
|
Dim point As Pointd = points(0)
|
459 |
|
If IsStartOrLastPointForSplitLine(startLine.UID, startConnItem1) Then
|
460 |
|
point.ConnectedUID = startConnItem1
|
461 |
|
points(0) = point
|
462 |
|
ElseIf IsStartOrLastPointForSplitLine(startLine.UID, startConnItem2) Then
|
463 |
|
point.ConnectedUID = startConnItem2
|
464 |
|
points(0) = point
|
465 |
|
Else
|
466 |
|
Throw New Exception("GetLinePoints")
|
467 |
|
End If
|
468 |
|
point = points(points.Count - 1)
|
469 |
|
If IsStartOrLastPointForSplitLine(endLine.UID, endConnItem1) Then
|
470 |
|
point.ConnectedUID = endConnItem1
|
471 |
|
points(points.Count - 1) = point
|
472 |
|
ElseIf IsStartOrLastPointForSplitLine(endLine.UID, endConnItem2) Then
|
473 |
|
point.ConnectedUID = endConnItem2
|
474 |
|
points(points.Count - 1) = point
|
475 |
|
Else
|
476 |
|
Throw New Exception("GetLinePoints")
|
477 |
|
End If
|
478 |
|
|
479 |
|
|
480 |
|
End If
|
481 |
|
|
482 |
|
'' 보정
|
483 |
|
Dim startPoint As Pointd = points(0)
|
484 |
|
Dim connSymbol As Symbol = FindSymbolByUID(CDrawing.SYMBOLS, startPoint.ConnectedUID)
|
485 |
|
If connSymbol IsNot Nothing Then
|
486 |
|
Dim symbolX As Double = connSymbol.SPPID_ITEM_OBJECT.XCoordinate
|
487 |
|
Dim symbolY As Double = connSymbol.SPPID_ITEM_OBJECT.YCoordinate
|
488 |
|
Dim nextPoint As Pointd = points(1)
|
489 |
|
If IsHorizontal(startPoint, nextPoint) Then
|
490 |
|
startPoint.Y = symbolY
|
491 |
|
nextPoint.Y = symbolY
|
492 |
|
Else
|
493 |
|
startPoint.X = symbolX
|
494 |
|
nextPoint.X = symbolX
|
495 |
|
End If
|
496 |
|
|
497 |
|
points(0) = startPoint
|
498 |
|
points(1) = nextPoint
|
499 |
|
End If
|
500 |
|
|
501 |
|
Dim endPoint As Pointd = points(points.Count - 1)
|
502 |
|
connSymbol = FindSymbolByUID(CDrawing.SYMBOLS, endPoint.ConnectedUID)
|
503 |
|
If connSymbol IsNot Nothing Then
|
504 |
|
Dim symbolX As Double = connSymbol.SPPID_ITEM_OBJECT.XCoordinate
|
505 |
|
Dim symbolY As Double = connSymbol.SPPID_ITEM_OBJECT.YCoordinate
|
506 |
|
Dim nextPoint As Pointd = points(points.Count - 2)
|
507 |
|
If IsHorizontal(endPoint, nextPoint) Then
|
508 |
|
endPoint.Y = symbolY
|
509 |
|
nextPoint.Y = symbolY
|
510 |
|
Else
|
511 |
|
endPoint.X = symbolX
|
512 |
|
nextPoint.X = symbolX
|
513 |
|
End If
|
514 |
|
|
515 |
|
points(points.Count - 1) = endPoint
|
516 |
|
points(points.Count - 2) = nextPoint
|
517 |
|
End If
|
518 |
|
|
519 |
|
|
520 |
|
Return points
|
521 |
|
|
522 |
|
Catch ex As Exception
|
523 |
|
Debug.WriteLine(ex.Message)
|
524 |
|
End Try
|
525 |
|
|
526 |
|
End Function
|
527 |
|
|
528 |
|
Class Pointd
|
529 |
|
Public Sub New(ByVal X As Double, ByVal Y As Double)
|
530 |
|
Me.X = X
|
531 |
|
Me.Y = Y
|
532 |
|
End Sub
|
533 |
|
Public X As Double
|
534 |
|
Public Y As Double
|
535 |
|
Public ConnectedUID As String
|
536 |
|
Public PointInfo As String
|
537 |
|
Public Line As Line
|
538 |
|
Public SP_ID As String
|
539 |
|
End Class
|
540 |
|
|
541 |
|
Private Function GetGroupPoint(ByVal group As List(Of Line)) As List(Of Pointd)
|
542 |
|
|
543 |
|
Dim resultLine As List(Of Tuple(Of Line, Boolean)) = New List(Of Tuple(Of Line, Boolean))
|
544 |
|
Dim _lines As List(Of Tuple(Of Line, Boolean)) = New List(Of Tuple(Of Line, Boolean))
|
545 |
|
For Each line As Line In group
|
546 |
|
Dim tuple As Tuple(Of Line, Boolean) = New Tuple(Of Line, Boolean)(line, IsHorizontal(line))
|
547 |
|
_lines.Add(tuple)
|
548 |
|
Next
|
549 |
|
|
550 |
|
For Each tuple As Tuple(Of Line, Boolean) In _lines
|
551 |
|
If resultLine.Count = 0 Then
|
552 |
|
resultLine.Add(tuple)
|
553 |
|
Else
|
554 |
|
Dim prevTuple As Tuple(Of Line, Boolean) = resultLine(resultLine.Count - 1)
|
555 |
|
|
556 |
|
If prevTuple.Item2 = tuple.Item2 Then
|
557 |
|
resultLine.Remove(prevTuple)
|
558 |
|
resultLine.Add(mergeLine(tuple.Item1, prevTuple.Item1, tuple.Item2))
|
559 |
|
Else
|
560 |
|
resultLine.Add(tuple)
|
561 |
|
End If
|
562 |
|
End If
|
563 |
|
Next
|
564 |
|
|
565 |
|
Dim pointList As List(Of Pointd) = New List(Of Pointd)
|
566 |
|
For Each tuple As Tuple(Of Line, Boolean) In resultLine
|
567 |
|
If pointList.Count = 0 Then
|
568 |
|
Dim line As Line = tuple.Item1
|
569 |
|
|
570 |
|
Dim point1 As Pointd = New Pointd(line.START_X, line.START_Y)
|
571 |
|
Dim point2 As Pointd = New Pointd(line.END_X, line.END_Y)
|
572 |
|
|
573 |
|
pointList.Add(point1)
|
574 |
|
pointList.Add(point2)
|
575 |
|
Else
|
576 |
|
Dim line As Line = tuple.Item1
|
577 |
|
Dim isHorizontal As Boolean = tuple.Item2
|
578 |
|
|
579 |
|
Dim prevPoint1 As Pointd = pointList(pointList.Count - 2)
|
580 |
|
Dim prevPoint2 As Pointd = pointList(pointList.Count - 1)
|
581 |
|
Dim currPoint1 As Pointd = New Pointd(line.START_X, line.START_Y)
|
582 |
|
Dim currPoint2 As Pointd = New Pointd(line.END_X, line.END_Y)
|
583 |
|
|
584 |
|
''제일 작은 조합의 반대편 prevPoint를 넣어야함
|
585 |
|
Dim distance = CalcDistance(prevPoint1, currPoint1)
|
586 |
|
Dim prev = True
|
587 |
|
Dim curr = True
|
588 |
|
|
589 |
|
If distance > CalcDistance(prevPoint1, currPoint2) Then
|
590 |
|
distance = CalcDistance(prevPoint1, currPoint2)
|
591 |
|
curr = False
|
592 |
|
End If
|
593 |
|
|
594 |
|
If distance > CalcDistance(prevPoint2, currPoint1) Then
|
595 |
|
distance = CalcDistance(prevPoint2, currPoint1)
|
596 |
|
prev = False
|
597 |
|
curr = True
|
598 |
|
End If
|
599 |
|
|
600 |
|
If distance > CalcDistance(prevPoint2, currPoint2) Then
|
601 |
|
distance = CalcDistance(prevPoint2, currPoint2)
|
602 |
|
prev = False
|
603 |
|
curr = False
|
604 |
|
End If
|
605 |
|
|
606 |
|
pointList.RemoveAt(pointList.Count - 2)
|
607 |
|
pointList.RemoveAt(pointList.Count - 1)
|
608 |
|
|
609 |
|
' 지금은 수평 / 이전 수직
|
610 |
|
If isHorizontal Then
|
611 |
|
If prev Then
|
612 |
|
pointList.Add(prevPoint2)
|
613 |
|
|
614 |
|
If curr Then
|
615 |
|
Dim newPoint As Pointd = New Pointd(prevPoint2.X, currPoint2.Y)
|
616 |
|
pointList.Add(newPoint)
|
617 |
|
|
618 |
|
pointList.Add(currPoint2)
|
619 |
|
Else
|
620 |
|
Dim newPoint As Pointd = New Pointd(prevPoint2.X, currPoint1.Y)
|
621 |
|
pointList.Add(newPoint)
|
622 |
|
|
623 |
|
pointList.Add(currPoint1)
|
624 |
|
End If
|
625 |
|
Else
|
626 |
|
pointList.Add(prevPoint1)
|
627 |
|
|
628 |
|
If curr Then
|
629 |
|
Dim newPoint As Pointd = New Pointd(prevPoint1.X, currPoint2.Y)
|
630 |
|
pointList.Add(newPoint)
|
631 |
|
|
632 |
|
pointList.Add(currPoint2)
|
633 |
|
Else
|
634 |
|
Dim newPoint As Pointd = New Pointd(prevPoint1.X, currPoint1.Y)
|
635 |
|
pointList.Add(newPoint)
|
636 |
|
|
637 |
|
pointList.Add(currPoint1)
|
638 |
|
End If
|
639 |
|
End If
|
640 |
|
'지금은 수직 / 이전 수평
|
641 |
|
Else
|
642 |
|
If prev Then
|
643 |
|
pointList.Add(prevPoint2)
|
644 |
|
|
645 |
|
If curr Then
|
646 |
|
Dim newPoint As Pointd = New Pointd(currPoint2.X, prevPoint2.Y)
|
647 |
|
pointList.Add(newPoint)
|
648 |
|
|
649 |
|
pointList.Add(currPoint2)
|
650 |
|
Else
|
651 |
|
Dim newPoint As Pointd = New Pointd(currPoint1.X, prevPoint2.Y)
|
652 |
|
pointList.Add(newPoint)
|
653 |
|
|
654 |
|
pointList.Add(currPoint1)
|
655 |
|
End If
|
656 |
|
Else
|
657 |
|
pointList.Add(prevPoint1)
|
658 |
|
|
659 |
|
If curr Then
|
660 |
|
Dim newPoint As Pointd = New Pointd(currPoint2.X, prevPoint1.Y)
|
661 |
|
pointList.Add(newPoint)
|
662 |
|
|
663 |
|
pointList.Add(currPoint2)
|
664 |
|
Else
|
665 |
|
Dim newPoint As Pointd = New Pointd(currPoint1.X, prevPoint1.Y)
|
666 |
|
pointList.Add(newPoint)
|
667 |
|
|
668 |
|
pointList.Add(currPoint1)
|
669 |
|
End If
|
670 |
|
End If
|
671 |
|
End If
|
672 |
|
End If
|
673 |
|
Next
|
674 |
|
|
675 |
|
Return pointList
|
676 |
|
End Function
|
677 |
|
|
678 |
|
Private Function IsHorizontal(ByVal point1 As Pointd, ByVal point2 As Pointd) As Boolean
|
679 |
|
If point1.X - point2.X = 0 Then
|
680 |
|
Return False
|
681 |
|
Else
|
682 |
|
Dim angle = Math.Atan(Math.Abs(point2.Y - point1.Y) / Math.Abs(point2.X - point1.X)) * 180 / Math.PI
|
683 |
|
If angle < 10 Then
|
684 |
|
Return True
|
685 |
|
Else
|
686 |
|
Return False
|
687 |
|
End If
|
688 |
|
End If
|
689 |
|
End Function
|
690 |
|
|
691 |
|
Private Function IsHorizontal(ByVal line As Line)
|
692 |
|
If line.END_X - line.START_X = 0 Then
|
693 |
|
Return False
|
694 |
|
Else
|
695 |
|
Dim angle = Math.Atan(Math.Abs(line.END_Y - line.START_Y) / Math.Abs(line.END_X - line.START_X)) * 180 / Math.PI
|
696 |
|
If angle < 10 Then
|
697 |
|
Return True
|
698 |
|
Else
|
699 |
|
Return False
|
700 |
|
End If
|
701 |
|
End If
|
702 |
|
End Function
|
703 |
|
|
704 |
|
Private Function mergeLine(line1 As Line, line2 As Line, isHorizontal As Boolean) As Tuple(Of Line, Boolean)
|
705 |
|
If isHorizontal Then
|
706 |
|
Dim min As Double = Math.Min(line1.START_X, Math.Min(line1.END_X, Math.Min(line2.START_X, line2.END_X)))
|
707 |
|
Dim max As Double = Math.Max(line1.START_X, Math.Max(line1.END_X, Math.Max(line2.START_X, line2.END_X)))
|
708 |
|
|
709 |
|
Dim nLine As Line = New Line()
|
710 |
|
nLine.START_X = min
|
711 |
|
nLine.START_Y = line1.START_Y
|
712 |
|
nLine.END_X = max
|
713 |
|
nLine.END_Y = line1.START_Y
|
714 |
|
|
715 |
|
Dim tuple As Tuple(Of Line, Boolean) = New Tuple(Of Line, Boolean)(nLine, isHorizontal)
|
716 |
|
Return tuple
|
717 |
|
Else
|
718 |
|
Dim min As Double = Math.Min(line1.START_Y, Math.Min(line1.END_Y, Math.Min(line2.START_Y, line2.END_Y)))
|
719 |
|
Dim max As Double = Math.Max(line1.START_Y, Math.Max(line1.END_Y, Math.Max(line2.START_Y, line2.END_Y)))
|
720 |
|
|
721 |
|
Dim nLine As Line = New Line()
|
722 |
|
nLine.START_X = line1.START_X
|
723 |
|
nLine.START_Y = min
|
724 |
|
nLine.END_X = line1.START_X
|
725 |
|
nLine.END_Y = max
|
726 |
|
|
727 |
|
Dim tuple As Tuple(Of Line, Boolean) = New Tuple(Of Line, Boolean)(nLine, isHorizontal)
|
728 |
|
Return tuple
|
729 |
|
End If
|
730 |
|
|
731 |
|
End Function
|
732 |
|
|
733 |
|
Private Function CalcDistance(ByVal point1 As Pointd, ByVal point2 As Pointd) As Double
|
734 |
|
Return Math.Pow(Math.Sqrt(Math.Abs(point1.X - point2.X)) + Math.Sqrt(Math.Abs(point1.Y - point2.Y)), 0.5)
|
735 |
|
End Function
|
736 |
|
|
737 |
|
|
738 |
|
Private Function DrawSymbol(ByVal symbol As Symbol) As LMSymbol
|
739 |
|
Dim _Placement As Placement = New Placement
|
740 |
|
Dim sysPath = symbol.SPPIDMAPPINGNAME
|
741 |
|
Dim _lmSymbol As LMSymbol = Nothing
|
742 |
|
|
743 |
|
If sysPath <> "" Then
|
744 |
|
Dim connectSymbol As LMSymbol = Nothing
|
745 |
|
For Each connector As Connector In symbol.CONNECTORS
|
746 |
|
If String.IsNullOrEmpty(connector.CONNECTEDITEM) = False Or connector.CONNECTEDITEM <> "None" Then
|
747 |
|
Dim _sym As Symbol = FindSymbolByUID(CDrawing.SYMBOLS, connector.CONNECTEDITEM)
|
748 |
|
If _sym IsNot Nothing Then
|
749 |
|
If _sym.SPPID_ITEM_OBJECT IsNot Nothing Then
|
750 |
|
connectSymbol = _sym.SPPID_ITEM_OBJECT
|
751 |
|
Exit For
|
752 |
|
End If
|
753 |
|
End If
|
754 |
|
End If
|
755 |
|
Next
|
756 |
|
If connectSymbol IsNot Nothing Then
|
757 |
|
_lmSymbol = _Placement.PIDPlaceSymbol(sysPath, symbol.LOCATION_X, symbol.LOCATION_Y, Rotation:=symbol.ANGLE, Mirror:=symbol.MIRROR, TargetItem:=connectSymbol)
|
758 |
|
Else
|
759 |
|
_lmSymbol = _Placement.PIDPlaceSymbol(sysPath, symbol.LOCATION_X, symbol.LOCATION_Y, Rotation:=symbol.ANGLE, Mirror:=symbol.MIRROR)
|
760 |
|
End If
|
761 |
|
_lmSymbol.Commit()
|
762 |
|
|
763 |
|
'' Check Child
|
764 |
|
For Each _child As String In symbol.CHILD
|
765 |
|
Dim arrChild As String() = _child.Split(",")
|
766 |
|
Dim arrow As String = arrChild(0)
|
767 |
|
Dim mappingName As String = arrChild(1)
|
768 |
|
|
769 |
|
Dim childAngle = 0
|
770 |
|
If arrow = "UP" Then
|
771 |
|
childAngle = 0
|
772 |
|
ElseIf arrow = "RIGHT" Then
|
773 |
|
childAngle = 90
|
774 |
|
ElseIf arrow = "DOWN" Then
|
775 |
|
childAngle = 180
|
776 |
|
Else
|
777 |
|
childAngle = 270
|
778 |
|
End If
|
779 |
|
|
780 |
|
Dim _childLmSymbol As LMSymbol = _Placement.PIDPlaceSymbol(mappingName, symbol.LOCATION_X, symbol.LOCATION_Y, Rotation:=childAngle, TargetItem:=_lmSymbol)
|
781 |
|
symbol.CHILD_SPPID_ITEM_OBJECT.Add(_childLmSymbol)
|
782 |
|
Next
|
783 |
|
|
784 |
|
Debug.WriteLine(symbol.LOCATION_X.ToString + "," + symbol.LOCATION_Y.ToString + "/" + symbol.UID + "/" + symbol.SIZE)
|
785 |
|
End If
|
786 |
|
|
787 |
|
Return _lmSymbol
|
788 |
|
End Function
|
789 |
|
|
790 |
|
Private Function DrawLine(ByVal points As List(Of Pointd), ByVal PipeSystemPath As String) As LMConnector
|
791 |
|
Dim _Placement As Placement = New Placement
|
792 |
|
Dim objItem As LMAItem = _Placement.PIDCreateItem(PipeSystemPath)
|
793 |
|
Dim _lmConnector As LMConnector = Nothing
|
794 |
|
Dim objInputs As PlaceRunInputs = New PlaceRunInputs
|
795 |
|
Dim branchPoint As Pointd = Nothing
|
796 |
|
Dim branchIndex As Integer = 0
|
797 |
|
Dim branch_SP_ID_List As List(Of String) = New List(Of String)
|
798 |
|
|
799 |
|
Try
|
800 |
|
For index = 0 To points.Count - 1
|
801 |
|
Dim point As Pointd = points(index)
|
802 |
|
If index = 0 Or index = points.Count - 1 Then
|
803 |
|
|
804 |
|
Dim targetSymbol As Symbol = FindSymbolByUID(CDrawing.SYMBOLS, point.ConnectedUID)
|
805 |
|
Dim targetLine As Line = FindLineByUID(CDrawing.LINES, point.ConnectedUID)
|
806 |
|
If targetSymbol IsNot Nothing Then
|
807 |
|
objInputs.AddSymbolTarget(targetSymbol.SPPID_ITEM_OBJECT, point.X, point.Y)
|
808 |
|
ElseIf targetLine IsNot Nothing Then
|
809 |
|
'찾아야함'
|
810 |
|
If String.IsNullOrEmpty(targetLine.LMCONNECTOR_MODELID) Then
|
811 |
|
Console.WriteLine("targetLine.LMCONNECTOR_MODELID")
|
812 |
|
End If
|
813 |
|
Dim resultTuple As Tuple(Of LMConnector, Integer) = GetTargetLMConnector(targetLine.LMCONNECTOR_MODELID, point)
|
814 |
|
If resultTuple IsNot Nothing Then
|
815 |
|
objInputs.AddConnectorTarget(resultTuple.Item1, point.X, point.Y)
|
816 |
|
branchPoint = New Pointd(point.X, point.Y)
|
817 |
|
branchPoint.PointInfo = "BRANCH"
|
818 |
|
branchPoint.Line = targetLine
|
819 |
|
branchIndex = resultTuple.Item2
|
820 |
|
'branchPoint.
|
821 |
|
|
822 |
|
Dim run As LMPipeRun = _Placement.PIDDataSource.GetPipeRun(targetLine.LMCONNECTOR_MODELID)
|
823 |
|
For Each oRep As LMRepresentation In run.Representations
|
824 |
|
If oRep.Attributes("RepresentationType").Value = "Branch" And oRep.Attributes("ItemStatus").Value = "Active" Then
|
825 |
|
branch_SP_ID_List.Add(oRep.Id)
|
826 |
|
End If
|
827 |
|
Next
|
828 |
|
Else
|
829 |
|
Console.WriteLine("target lmconnector error : " + targetLine.UID)
|
830 |
|
objInputs.AddPoint(point.X, point.Y)
|
831 |
|
End If
|
832 |
|
Else
|
833 |
|
objInputs.AddPoint(point.X, point.Y)
|
834 |
|
End If
|
835 |
|
|
836 |
|
Else
|
837 |
|
objInputs.AddPoint(point.X, point.Y)
|
838 |
|
End If
|
839 |
|
Next
|
840 |
|
_lmConnector = _Placement.PIDPlaceRun(objItem, objInputs)
|
841 |
|
_lmConnector.Commit()
|
842 |
|
|
843 |
|
If branchPoint IsNot Nothing Then
|
844 |
|
Dim run As LMPipeRun = _Placement.PIDDataSource.GetPipeRun(branchPoint.Line.LMCONNECTOR_MODELID)
|
845 |
|
For Each oRep As LMRepresentation In run.Representations
|
846 |
|
If oRep.Attributes("RepresentationType").Value = "Branch" And oRep.Attributes("ItemStatus").Value = "Active" Then
|
847 |
|
If branch_SP_ID_List.Contains(oRep.Id) = False Then
|
848 |
|
branchPoint.SP_ID = oRep.Id
|
849 |
|
PipeRunPoint(branchPoint.Line.LMCONNECTOR_MODELID).Insert(branchIndex, branchPoint)
|
850 |
|
Exit For
|
851 |
|
End If
|
852 |
|
End If
|
853 |
|
Next
|
854 |
|
End If
|
855 |
|
Catch ex As Exception
|
856 |
|
Console.WriteLine(ex.Message)
|
857 |
|
|
858 |
|
End Try
|
859 |
|
|
860 |
|
Return _lmConnector
|
861 |
|
End Function
|
862 |
|
|
863 |
|
|
864 |
|
Public Function GetTargetLMConnector(ByVal ModelId As String, ByVal point As Pointd) As Tuple(Of LMConnector, Integer)
|
865 |
|
Dim lmConnector As LMConnector = Nothing
|
866 |
|
Dim ConnPoint1 As Pointd = Nothing
|
867 |
|
Dim ConnPoint2 As Pointd = Nothing
|
868 |
|
Dim insertIndex As Integer = 0
|
869 |
|
|
870 |
|
Dim min As Double = 0
|
871 |
|
Dim max As Double = 0
|
872 |
|
Dim _tempDistance As Double = 0
|
873 |
|
Dim distance As Double = Double.MaxValue
|
874 |
|
|
875 |
|
Try
|
876 |
|
Dim pointdList As List(Of Pointd) = PipeRunPoint(ModelId)
|
877 |
|
|
878 |
|
For index = 0 To pointdList.Count - 2
|
879 |
|
Dim point1 As Pointd = pointdList(index)
|
880 |
|
Dim point2 As Pointd = pointdList(index + 1)
|
881 |
|
|
882 |
|
If IsHorizontal(point1, point2) Then
|
883 |
|
min = Math.Min(point1.X, point2.X)
|
884 |
|
max = Math.Max(point1.X, point2.X)
|
885 |
|
_tempDistance = Math.Abs((point1.Y + point2.Y) / 2 - point.Y)
|
886 |
|
|
887 |
|
If min <= point.X And max >= point.X And _tempDistance < distance Then
|
888 |
|
ConnPoint1 = pointdList(index)
|
889 |
|
ConnPoint2 = pointdList(index + 1)
|
890 |
|
insertIndex = index + 1
|
891 |
|
distance = _tempDistance
|
892 |
|
End If
|
893 |
|
|
894 |
|
Else
|
895 |
|
min = Math.Min(point1.Y, point2.Y)
|
896 |
|
max = Math.Max(point1.Y, point2.Y)
|
897 |
|
_tempDistance = Math.Abs((point1.X + point2.X) / 2 - point.X)
|
898 |
|
|
899 |
|
If min <= point.Y And max >= point.Y And _tempDistance < distance Then
|
900 |
|
ConnPoint1 = pointdList(index)
|
901 |
|
ConnPoint2 = pointdList(index + 1)
|
902 |
|
insertIndex = index + 1
|
903 |
|
distance = _tempDistance
|
904 |
|
End If
|
905 |
|
End If
|
906 |
|
Next
|
907 |
|
|
908 |
|
If ConnPoint1 IsNot Nothing And ConnPoint2 IsNot Nothing Then
|
909 |
|
If ConnPoint1.PointInfo.ToUpper = "RUN" Then
|
910 |
|
lmConnector = GetLMConnectorByPoint(ModelId, ConnPoint1)
|
911 |
|
ElseIf ConnPoint2.PointInfo.ToUpper = "RUN" Then
|
912 |
|
lmConnector = GetLMConnectorByPoint(ModelId, ConnPoint2)
|
913 |
|
Else
|
914 |
|
lmConnector = GetLMConnectorBySP_ID(ModelId, ConnPoint1.SP_ID, ConnPoint2.SP_ID)
|
915 |
|
End If
|
916 |
|
End If
|
917 |
|
|
918 |
|
If lmConnector Is Nothing Then
|
919 |
|
Throw New Exception("Logic Error")
|
920 |
|
End If
|
921 |
|
|
922 |
|
Return New Tuple(Of LMConnector, Integer)(lmConnector, insertIndex)
|
923 |
|
Catch ex As Exception
|
924 |
|
Debug.WriteLine(ex.Message)
|
925 |
|
Return Nothing
|
926 |
|
End Try
|
927 |
|
End Function
|
928 |
|
|
929 |
|
Private Function GetLMConnectorByPoint(ByVal ModelId As String, ByVal point As Pointd) As LMConnector
|
930 |
|
Dim objPlacement As Placement = New Placement
|
931 |
|
Dim objConnector As LMConnector = Nothing
|
932 |
|
|
933 |
|
Dim distance As Double = Double.MaxValue
|
934 |
|
Dim lmPipeRun As LMPipeRun = objPlacement.PIDDataSource.GetPipeRun(ModelId)
|
935 |
|
For Each oRep As LMRepresentation In lmPipeRun.Representations
|
936 |
|
If oRep.Attributes("RepresentationType").Value = "Connector" And oRep.Attributes("ItemStatus").Value = "Active" Then
|
937 |
|
Dim _conn As LMConnector = objPlacement.PIDDataSource.GetConnector(oRep.Id)
|
938 |
|
For Each vertex As LMConnectorVertex In _conn.ConnectorVertices
|
939 |
|
Dim _distance As Double = CalcPointToPointdDistance(point, New Pointd(vertex.XCoordinate, vertex.YCoordinate))
|
940 |
|
|
941 |
|
If _distance < distance Then
|
942 |
|
distance = _distance
|
943 |
|
objConnector = _conn
|
944 |
|
End If
|
945 |
|
Next
|
946 |
|
End If
|
947 |
|
Next
|
948 |
|
|
949 |
|
Return objConnector
|
950 |
|
End Function
|
951 |
|
|
952 |
|
Private Function GetLMConnectorBySP_ID(ByVal ModelId As String, ByVal SP_ID1 As String, ByVal SP_ID2 As String) As LMConnector
|
953 |
|
Dim objPlacement As Placement = New Placement
|
954 |
|
Dim objConnector As LMConnector = Nothing
|
955 |
|
|
956 |
|
Dim distance As Double = Double.MaxValue
|
957 |
|
Dim lmPipeRun As LMPipeRun = objPlacement.PIDDataSource.GetPipeRun(ModelId)
|
958 |
|
For Each oRep As LMRepresentation In lmPipeRun.Representations
|
959 |
|
If oRep.Attributes("RepresentationType").Value = "Connector" And oRep.Attributes("ItemStatus").Value = "Active" Then
|
960 |
|
Dim _conn As LMConnector = objPlacement.PIDDataSource.GetConnector(oRep.Id)
|
961 |
|
|
962 |
|
Dim find1 As Boolean = False
|
963 |
|
Dim find2 As Boolean = False
|
964 |
|
|
965 |
|
If _conn.ConnectItem1SymbolID IsNot Nothing Then
|
966 |
|
If _conn.ConnectItem1SymbolID.ToString = SP_ID1 Or _conn.ConnectItem1SymbolID.ToString = SP_ID2 Then
|
967 |
|
find1 = True
|
968 |
|
End If
|
969 |
|
End If
|
970 |
|
|
971 |
|
If _conn.ConnectItem2SymbolID IsNot Nothing Then
|
972 |
|
If _conn.ConnectItem2SymbolID.ToString = SP_ID1 Or _conn.ConnectItem2SymbolID.ToString = SP_ID2 Then
|
973 |
|
find2 = True
|
974 |
|
End If
|
975 |
|
End If
|
976 |
|
|
977 |
|
If find1 And find2 Then
|
978 |
|
Return _conn
|
979 |
|
End If
|
980 |
|
End If
|
981 |
|
Next
|
982 |
|
|
983 |
|
If objConnector Is Nothing Then
|
984 |
|
Debug.WriteLine("Error At GetLMConnectorBySP_ID")
|
985 |
|
End If
|
986 |
|
|
987 |
|
Return objConnector
|
988 |
|
End Function
|
989 |
|
|
990 |
|
Private Function CalcPointToPointdDistance(ByVal point1 As Pointd, ByVal point2 As Pointd) As Double
|
991 |
|
Return Math.Pow(Math.Pow(point1.X - point2.X, 2) + Math.Pow(point1.Y - point2.Y, 2), 0.5)
|
992 |
|
End Function
|
993 |
|
|
994 |
|
Private Function IsCanDraw(ByVal itemGroup As ItemGroup) As Boolean
|
995 |
|
Dim lineList As List(Of Line) = CDrawing.LINES
|
996 |
|
|
997 |
|
Dim groupSymbols As List(Of Symbol) = New List(Of Symbol)
|
998 |
|
Dim groupLines As List(Of Line) = New List(Of Line)
|
999 |
|
|
1000 |
|
For Each item As Object In itemGroup.Group
|
1001 |
|
If TypeOf (item) Is Line Then
|
1002 |
|
groupLines.Add(item)
|
1003 |
|
Else
|
1004 |
|
groupSymbols.Add(item)
|
1005 |
|
End If
|
1006 |
|
Next
|
1007 |
|
|
1008 |
|
For Each symbol As Symbol In groupSymbols
|
1009 |
|
For Each conn As Connector In symbol.CONNECTORS
|
1010 |
|
Dim _line As Line = FindLineByUID(CDrawing.LINES, conn.CONNECTEDITEM)
|
1011 |
|
Dim _symbol As Symbol = FindSymbolByUID(CDrawing.SYMBOLS, conn.CONNECTEDITEM)
|
1012 |
|
If _line IsNot Nothing Then
|
1013 |
|
If groupLines.Contains(_line) = False And String.IsNullOrEmpty(_line.LMCONNECTOR_MODELID) Then
|
1014 |
|
Return False
|
1015 |
|
End If
|
1016 |
|
ElseIf _symbol IsNot Nothing Then
|
1017 |
|
If groupSymbols.Contains(_symbol) = False And _symbol.SPPID_ITEM_OBJECT Is Nothing Then
|
1018 |
|
Return False
|
1019 |
|
End If
|
1020 |
|
End If
|
1021 |
|
Next
|
1022 |
|
Next
|
1023 |
|
|
1024 |
|
For Each line As Line In groupLines
|
1025 |
|
For Each conn As Connector In line.CONNECTORS
|
1026 |
|
Dim _line As Line = FindLineByUID(CDrawing.LINES, conn.CONNECTEDITEM)
|
1027 |
|
Dim _symbol As Symbol = FindSymbolByUID(CDrawing.SYMBOLS, conn.CONNECTEDITEM)
|
1028 |
|
If _line IsNot Nothing Then
|
1029 |
|
If groupLines.Contains(_line) = False And String.IsNullOrEmpty(_line.LMCONNECTOR_MODELID) Then
|
1030 |
|
Return False
|
1031 |
|
End If
|
1032 |
|
ElseIf _symbol IsNot Nothing Then
|
1033 |
|
If groupSymbols.Contains(_symbol) = False And _symbol.SPPID_ITEM_OBJECT Is Nothing Then
|
1034 |
|
Return False
|
1035 |
|
End If
|
1036 |
|
End If
|
1037 |
|
Next
|
1038 |
|
Next
|
1039 |
|
|
1040 |
|
|
1041 |
|
Return True
|
1042 |
|
End Function
|
1043 |
|
|
1044 |
|
Private Function IsContainGroup(ByVal UID As String, ByVal symbols As List(Of Symbol), ByVal lines As List(Of Line)) As Boolean
|
1045 |
|
Dim line As Line = FindLineByUID(lines, UID)
|
1046 |
|
Dim symbol As Symbol = FindSymbolByUID(symbols, UID)
|
1047 |
|
|
1048 |
|
If line IsNot Nothing Then
|
1049 |
|
Return True
|
1050 |
|
ElseIf symbol IsNot Nothing Then
|
1051 |
|
Return True
|
1052 |
|
Else
|
1053 |
|
Return False
|
1054 |
|
End If
|
1055 |
|
End Function
|
1056 |
|
|
1057 |
|
Private Function GetGroupList() As List(Of ItemGroup)
|
1058 |
|
Dim symbolList As List(Of Symbol) = CDrawing.SYMBOLS
|
1059 |
|
Dim lineList As List(Of Line) = CDrawing.LINES
|
1060 |
|
|
1061 |
|
Dim CGroupList As List(Of ItemGroup) = New List(Of ItemGroup)
|
1062 |
|
|
1063 |
|
'' Line 기준으로 먼저 묶음
|
1064 |
|
For Each line As Line In lineList
|
1065 |
|
If line.GROUPING Then
|
1066 |
|
Dim group As ItemGroup = GetGroupByLine(line)
|
1067 |
|
CGroupList.Add(group)
|
1068 |
|
End If
|
1069 |
|
Next
|
1070 |
|
|
1071 |
|
'' Symbol
|
1072 |
|
For Each symbol As Symbol In symbolList
|
1073 |
|
If symbol.GROUPING Then
|
1074 |
|
Dim group As ItemGroup = New ItemGroup()
|
1075 |
|
group.Add(symbol)
|
1076 |
|
CGroupList.Add(group)
|
1077 |
|
End If
|
1078 |
|
Next
|
1079 |
|
|
1080 |
|
Return CGroupList
|
1081 |
|
End Function
|
1082 |
|
|
1083 |
|
Private Function GetGroupByLine(ByVal line As Line) As ItemGroup
|
1084 |
|
Dim CItemGroup As ItemGroup = New ItemGroup()
|
1085 |
|
|
1086 |
|
Dim symbolList As List(Of Symbol) = CDrawing.SYMBOLS
|
1087 |
|
Dim lineList As List(Of Line) = CDrawing.LINES
|
1088 |
|
|
1089 |
|
Dim forwardItems As List(Of Object) = New List(Of Object)
|
1090 |
|
Dim reverseItems As List(Of Object) = New List(Of Object)
|
1091 |
|
line.GROUPING = False
|
1092 |
|
|
1093 |
|
''dd
|
1094 |
|
Console.WriteLine(line.UID)
|
1095 |
|
|
1096 |
|
Dim _symbol As Symbol = FindSymbolByUID(symbolList, line.CONNECTORS(0).CONNECTEDITEM)
|
1097 |
|
Dim _line As Line = FindLineByUID(lineList, line.CONNECTORS(0).CONNECTEDITEM)
|
1098 |
|
|
1099 |
|
If _line IsNot Nothing Then
|
1100 |
|
If IsBranchLine(line.CONNECTORS(0).CONNECTEDITEM, line.UID, lineList) = False And _line.GROUPING And _line.SPPIDMAPPINGNAME = line.SPPIDMAPPINGNAME Then
|
1101 |
|
_line.GROUPING = False
|
1102 |
|
forwardItems.Add(_line)
|
1103 |
|
FindConnectedItem(_line, forwardItems, line.SPPIDMAPPINGNAME)
|
1104 |
|
End If
|
1105 |
|
ElseIf _symbol IsNot Nothing Then
|
1106 |
|
If _symbol.GROUPING Then
|
1107 |
|
If _symbol.CONNECTORS.Count <= 2 Then
|
1108 |
|
_symbol.GROUPING = False
|
1109 |
|
forwardItems.Add(_symbol)
|
1110 |
|
FindConnectedItem(_symbol, forwardItems, line.SPPIDMAPPINGNAME)
|
1111 |
|
Else
|
1112 |
|
Dim connector As List(Of Connector) = _symbol.CONNECTORS
|
1113 |
|
For index = 0 To connector.Count - 1
|
1114 |
|
If index < 2 Then
|
1115 |
|
If connector(index).CONNECTEDITEM = line.UID Then
|
1116 |
|
_symbol.GROUPING = False
|
1117 |
|
forwardItems.Add(_symbol)
|
1118 |
|
FindConnectedItem(_symbol, forwardItems, line.SPPIDMAPPINGNAME)
|
1119 |
|
Exit For
|
1120 |
|
End If
|
1121 |
|
End If
|
1122 |
|
Next
|
1123 |
|
End If
|
1124 |
|
End If
|
1125 |
|
End If
|
1126 |
|
|
1127 |
|
_symbol = FindSymbolByUID(symbolList, line.CONNECTORS(1).CONNECTEDITEM)
|
1128 |
|
_line = FindLineByUID(lineList, line.CONNECTORS(1).CONNECTEDITEM)
|
1129 |
|
If _line IsNot Nothing Then
|
1130 |
|
If IsBranchLine(line.CONNECTORS(1).CONNECTEDITEM, line.UID, lineList) = False And _line.GROUPING And _line.SPPIDMAPPINGNAME = line.SPPIDMAPPINGNAME Then
|
1131 |
|
_line.GROUPING = False
|
1132 |
|
reverseItems.Add(_line)
|
1133 |
|
FindConnectedItem(_line, reverseItems, line.SPPIDMAPPINGNAME)
|
1134 |
|
End If
|
1135 |
|
ElseIf _symbol IsNot Nothing Then
|
1136 |
|
If _symbol.GROUPING Then
|
1137 |
|
If _symbol.CONNECTORS.Count <= 2 Then
|
1138 |
|
_symbol.GROUPING = False
|
1139 |
|
reverseItems.Add(_symbol)
|
1140 |
|
FindConnectedItem(_symbol, reverseItems, line.SPPIDMAPPINGNAME)
|
1141 |
|
Else
|
1142 |
|
Dim connector As List(Of Connector) = _symbol.CONNECTORS
|
1143 |
|
For index = 0 To connector.Count - 1
|
1144 |
|
If index < 2 Then
|
1145 |
|
If connector(index).CONNECTEDITEM = line.UID Then
|
1146 |
|
_symbol.GROUPING = False
|
1147 |
|
reverseItems.Add(_symbol)
|
1148 |
|
FindConnectedItem(_symbol, reverseItems, line.SPPIDMAPPINGNAME)
|
1149 |
|
Exit For
|
1150 |
|
End If
|
1151 |
|
End If
|
1152 |
|
Next
|
1153 |
|
End If
|
1154 |
|
End If
|
1155 |
|
End If
|
1156 |
|
|
1157 |
|
reverseItems.Reverse()
|
1158 |
|
reverseItems.Add(line)
|
1159 |
|
reverseItems.AddRange(forwardItems)
|
1160 |
|
|
1161 |
|
For Each item As Object In reverseItems
|
1162 |
|
CItemGroup.Add(item)
|
1163 |
|
Next
|
1164 |
|
|
1165 |
|
Return CItemGroup
|
1166 |
|
End Function
|
1167 |
|
|
1168 |
|
Private Sub FindConnectedItem(ByVal shape As Object, ByRef groupItem As List(Of Object), ByVal PIDMAPPINGNAME As String)
|
1169 |
|
Dim symbolList As List(Of Symbol) = CDrawing.SYMBOLS
|
1170 |
|
Dim lineList As List(Of Line) = CDrawing.LINES
|
1171 |
|
|
1172 |
|
If TypeOf (shape) Is Line Then
|
1173 |
|
Dim _line As Line = shape
|
1174 |
|
|
1175 |
|
For Each conn As Connector In _line.CONNECTORS
|
1176 |
|
Dim symbol As Symbol = FindSymbolByUID(symbolList, conn.CONNECTEDITEM)
|
1177 |
|
Dim line As Line = FindLineByUID(lineList, conn.CONNECTEDITEM)
|
1178 |
|
|
1179 |
|
If line IsNot Nothing Then
|
1180 |
|
If IsBranchLine(line.UID, _line.UID, lineList) = False And line.GROUPING And _line.SPPIDMAPPINGNAME = line.SPPIDMAPPINGNAME Then
|
1181 |
|
line.GROUPING = False
|
1182 |
|
groupItem.Add(line)
|
1183 |
|
FindConnectedItem(line, groupItem, PIDMAPPINGNAME)
|
1184 |
|
End If
|
1185 |
|
ElseIf symbol IsNot Nothing Then
|
1186 |
|
If symbol.GROUPING Then
|
1187 |
|
If symbol.CONNECTORS.Count <= 2 Then
|
1188 |
|
symbol.GROUPING = False
|
1189 |
|
groupItem.Add(symbol)
|
1190 |
|
FindConnectedItem(symbol, groupItem, PIDMAPPINGNAME)
|
1191 |
|
Else
|
1192 |
|
Dim connector As List(Of Connector) = symbol.CONNECTORS
|
1193 |
|
For index = 0 To connector.Count - 1
|
1194 |
|
If index < 2 Then
|
1195 |
|
If connector(index).CONNECTEDITEM = _line.UID Then
|
1196 |
|
symbol.GROUPING = False
|
1197 |
|
groupItem.Add(symbol)
|
1198 |
|
FindConnectedItem(symbol, groupItem, PIDMAPPINGNAME)
|
1199 |
|
Exit For
|
1200 |
|
End If
|
1201 |
|
End If
|
1202 |
|
Next
|
1203 |
|
End If
|
1204 |
|
End If
|
1205 |
|
End If
|
1206 |
|
Next
|
1207 |
|
|
1208 |
|
ElseIf TypeOf (shape) Is Symbol Then
|
1209 |
|
Dim _symbol As Symbol = shape
|
1210 |
|
|
1211 |
|
For Each conn As Connector In _symbol.CONNECTORS
|
1212 |
|
Dim symbol As Symbol = FindSymbolByUID(symbolList, conn.CONNECTEDITEM)
|
1213 |
|
Dim line As Line = FindLineByUID(lineList, conn.CONNECTEDITEM)
|
1214 |
|
|
1215 |
|
If line IsNot Nothing Then
|
1216 |
|
If line.GROUPING And PIDMAPPINGNAME = line.SPPIDMAPPINGNAME Then
|
1217 |
|
line.GROUPING = False
|
1218 |
|
groupItem.Add(line)
|
1219 |
|
FindConnectedItem(line, groupItem, PIDMAPPINGNAME)
|
1220 |
|
Exit For
|
1221 |
|
End If
|
1222 |
|
ElseIf symbol IsNot Nothing Then
|
1223 |
|
If symbol.GROUPING Then
|
1224 |
|
If symbol.CONNECTORS.Count <= 2 Then
|
1225 |
|
symbol.GROUPING = False
|
1226 |
|
groupItem.Add(symbol)
|
1227 |
|
FindConnectedItem(symbol, groupItem, PIDMAPPINGNAME)
|
1228 |
|
Else
|
1229 |
|
Dim connector As List(Of Connector) = symbol.CONNECTORS
|
1230 |
|
For index = 0 To connector.Count - 1
|
1231 |
|
If index < 2 Then
|
1232 |
|
If connector(index).CONNECTEDITEM = _symbol.UID Then
|
1233 |
|
symbol.GROUPING = False
|
1234 |
|
groupItem.Add(symbol)
|
1235 |
|
FindConnectedItem(symbol, groupItem, PIDMAPPINGNAME)
|
1236 |
|
Exit For
|
1237 |
|
End If
|
1238 |
|
End If
|
1239 |
|
Next
|
1240 |
|
End If
|
1241 |
|
End If
|
1242 |
|
End If
|
1243 |
|
Next
|
1244 |
|
End If
|
1245 |
|
End Sub
|
1246 |
|
|
1247 |
|
|
1248 |
|
Private Function IsBranchLine(ByVal connectedUID As String, ByVal UID As String, ByVal lines As List(Of Line)) As Boolean
|
1249 |
|
Dim connLine = FindLineByUID(lines, connectedUID)
|
1250 |
|
If connLine IsNot Nothing Then
|
1251 |
|
If connLine.CONNECTORS(0).CONNECTEDITEM <> UID And connLine.CONNECTORS(1).CONNECTEDITEM <> UID Then
|
1252 |
|
Return True
|
1253 |
|
End If
|
1254 |
|
End If
|
1255 |
|
|
1256 |
|
Return False
|
1257 |
|
End Function
|
1258 |
|
|
1259 |
|
|
1260 |
|
Private Function FindLineByUID(ByVal lines As List(Of Line), ByVal uid As String) As Line
|
1261 |
|
For Each line As Line In lines
|
1262 |
|
If line.UID = uid Then
|
1263 |
|
Return line
|
1264 |
|
End If
|
1265 |
|
Next
|
1266 |
|
|
1267 |
|
Return Nothing
|
1268 |
|
End Function
|
1269 |
|
|
1270 |
|
|
1271 |
|
Private Function FindSymbolByUID(ByVal symbols As List(Of Symbol), ByVal uid As String) As Symbol
|
1272 |
|
For Each symbol As Symbol In symbols
|
1273 |
|
If symbol.UID = uid Then
|
1274 |
|
Return symbol
|
1275 |
|
End If
|
1276 |
|
Next
|
1277 |
|
|
1278 |
|
Return Nothing
|
1279 |
|
End Function
|
1280 |
|
|
1281 |
|
Public Class ItemGroup
|
1282 |
|
Private _group As List(Of Object) = New List(Of Object)
|
1283 |
|
|
1284 |
|
Public Property Group As List(Of Object)
|
1285 |
|
Get
|
1286 |
|
Return _group
|
1287 |
|
End Get
|
1288 |
|
Set(value As List(Of Object))
|
1289 |
|
_group = value
|
1290 |
|
End Set
|
1291 |
|
End Property
|
1292 |
|
|
1293 |
|
Public Sub Add(ByVal item As Object)
|
1294 |
|
group.Add(item)
|
1295 |
|
End Sub
|
1296 |
|
End Class
|
1297 |
|
|
1298 |
|
End Class
|