From 27c344123e515fd85d7fbcfb6428761f005fcf3a Mon Sep 17 00:00:00 2001 From: Mans Date: Thu, 15 Apr 2021 10:08:08 +0200 Subject: [PATCH] Single grating angle working for multiple --- Wardrobe/SolidWorks/Multiple_Drawing.vb | 161 ++++++++++++++++++------ 1 file changed, 125 insertions(+), 36 deletions(-) diff --git a/Wardrobe/SolidWorks/Multiple_Drawing.vb b/Wardrobe/SolidWorks/Multiple_Drawing.vb index 4e41bd4..50e21d2 100644 --- a/Wardrobe/SolidWorks/Multiple_Drawing.vb +++ b/Wardrobe/SolidWorks/Multiple_Drawing.vb @@ -117,6 +117,11 @@ Public Class Multiple_Drawing pointsDT.Columns.Add("X", GetType(Double)) pointsDT.Columns.Add("Y", GetType(Double)) + Dim GAPointsDT As New DataTable + GAPointsDT.Columns.Add("NAME", GetType(String)) + GAPointsDT.Columns.Add("X", GetType(Double)) + GAPointsDT.Columns.Add("Y", GetType(Double)) + ' --- Determine grossArea points ---- Dim pX(3) As Double Dim pY(3) As Double @@ -171,8 +176,13 @@ Public Class Multiple_Drawing DR("TYPE") = "GA" DR("X") = pX(j) DR("Y") = pY(j) - pointsDT.Rows.Add(DR) + + DR = GAPointsDT.NewRow() + DR("NAME") = "GA_" & j + 1 + DR("X") = pX(j) + DR("Y") = pY(j) + GAPointsDT.Rows.Add(DR) Next ' --- Add recess points --- @@ -239,27 +249,70 @@ Public Class Multiple_Drawing DR3("X") = DR("X") DR3("Y") = DR("Y") - Dim index As Integer = Get_RowIndex(pointsDT, DR("SIDE"), DR("X"), DR("Y")) + Dim index As Integer = Get_RowIndex(pointsDT, DR("SIDE"), DR("X"), DR("Y"), GAPointsDT) pointsDT.Rows.InsertAt(DR3, index + 1) - Try - pointsDT.Rows.RemoveAt(index + 2) - Catch ex As Exception - pointsDT.Rows.RemoveAt(0) - End Try + If pointsDT.Rows.Count > index + 2 Then + Dim temp As String = pointsDT.Rows(index + 2)("NAME") + If temp.Substring(0, 2) = "GA" Then + pointsDT.Rows.RemoveAt(index + 2) + End If + + Else + Dim temp As String = pointsDT.Rows(0)("NAME") + If temp.Substring(0, 2) = "GA" Then + pointsDT.Rows.RemoveAt(0) + End If + + End If 'Check if remove next point aswell (If angle crosses more than one grating) + Dim cornerPoint(1) As Double Dim pointNumGA As Integer = DR("SIDE") + 2 If pointNumGA > 4 Then pointNumGA -= 4 End If - cornerPoint(0) = pointsDT.Select("NAME = 'GA_" & pointNumGA & "'")(0)("X") - cornerPoint(1) = pointsDT.Select("NAME = 'GA_" & pointNumGA & "'")(0)("Y") + cornerPoint(0) = GAPointsDT.Select("NAME = 'GA_" & pointNumGA & "'")(0)("X") + cornerPoint(1) = GAPointsDT.Select("NAME = 'GA_" & pointNumGA & "'")(0)("Y") - Create_SecondAnglePoint(pointsDT, DR, cornerPoint) + Create_SecondAnglePoint(pointsDT, DR, cornerPoint, GAPointsDT, recessPointsDT) Else + Dim DR3 As DataRow = pointsDT.NewRow() + DR3("NAME") = DR("NAME") + DR3("TYPE") = "Recess CA" + DR3("X") = DR("X") + DR3("Y") = DR("Y") + + Dim index As Integer = Get_RowIndex(pointsDT, DR("SIDE"), DR("X"), DR("Y"), GAPointsDT) + pointsDT.Rows.InsertAt(DR3, index + 1) + + 'If pointsDT.Rows.Count > index Then + Dim temp As String = pointsDT.Rows(index)("NAME") + If temp.Substring(0, 2) = "GA" Then + pointsDT.Rows.RemoveAt(index) + End If + + 'Else + ' Dim temp As String = pointsDT.Rows(0)("NAME") + ' If temp.Substring(0, 2) = "GA" Then + ' pointsDT.Rows.RemoveAt(0) + ' End If + + 'End If + + Dim cornerPoint(1) As Double + Dim pointNumGA As Integer = DR("SIDE") - 1 + If pointNumGA < 1 Then + pointNumGA += 4 + End If + + cornerPoint(0) = GAPointsDT.Select("NAME = 'GA_" & pointNumGA & "'")(0)("X") + cornerPoint(1) = GAPointsDT.Select("NAME = 'GA_" & pointNumGA & "'")(0)("Y") + + Create_SecondAnglePoint(pointsDT, DR, cornerPoint, GAPointsDT, recessPointsDT) + End If End If @@ -277,15 +330,19 @@ Public Class Multiple_Drawing Return pointsDS End Function - Private Shared Function Get_RowIndex(pDT As DataTable, side As Integer, pX As Double, pY As Double) + Private Shared Function Get_RowIndex(pDT As DataTable, side As Integer, pX As Double, pY As Double, GApDT As DataTable) Dim rowName As String = "" + Dim newX As Double = pX + Dim newY As Double = pY + If side = 1 Then Dim sidePoints = pDT.Select("Y = '" & pY & "'") For Each DR2 As DataRow In sidePoints If DR2("X") < pX Then rowName = DR2("NAME") Else + newX = GApDT.Select("NAME = 'GA_1'")(0)("X") Exit For End If Next @@ -295,6 +352,7 @@ Public Class Multiple_Drawing If DR2("Y") > pY Then rowName = DR2("NAME") Else + newY = GApDT.Select("NAME = 'GA_2'")(0)("Y") Exit For End If Next @@ -304,6 +362,7 @@ Public Class Multiple_Drawing If DR2("X") > pX Then rowName = DR2("NAME") Else + newX = GApDT.Select("NAME = 'GA_3'")(0)("X") Exit For End If Next @@ -313,23 +372,28 @@ Public Class Multiple_Drawing If DR2("Y") < pY Then rowName = DR2("NAME") Else + newY = GApDT.Select("NAME = 'GA_4'")(0)("Y") Exit For End If Next End If Dim index As Integer = 0 - For j = 0 To pDT.Rows.Count - 1 - If pDT.Rows(j)("NAME") = rowName Then - index = j - Exit For - End If - Next + If rowName = "" Then + index = Get_RowIndex(pDT, side - 1, newX, newY, GApDT) + Else + For j = 0 To pDT.Rows.Count - 1 + If pDT.Rows(j)("NAME") = rowName Then + index = j + Exit For + End If + Next + End If Return index End Function - Private Shared Sub Create_SecondAnglePoint(pDT As DataTable, rpDR As DataRow, gp As Double()) + Private Shared Sub Create_SecondAnglePoint(pDT As DataTable, rpDR As DataRow, gp As Double(), GApDT As DataTable, rDT As DataTable) Dim p0(1) As Double Dim p1(1) As Double Dim p2(1) As Double @@ -361,9 +425,34 @@ Public Class Multiple_Drawing If rpDR("SIDE") = 1 OrElse rpDR("SIDE") = 3 Then p1(0) = p2(0) p1(1) = p0(1) + If rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("X") = GApDT.Select("NAME = 'GA_2'")(0)("X") OrElse + rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("X") = GApDT.Select("NAME = 'GA_4'")(0)("X") Then + If rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") > GApDT.Select("NAME = 'GA_3'")(0)("Y") AndAlso + rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") < GApDT.Select("NAME = 'GA_2'")(0)("Y") Then + + Exit Sub + ElseIf rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") > GApDT.Select("NAME = 'GA_4'")(0)("Y") AndAlso + rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") < GApDT.Select("NAME = 'GA_1'")(0)("Y") Then + + Exit Sub + End If + End If ElseIf rpDR("SIDE") = 2 OrElse rpDR("SIDE") = 4 Then p1(0) = p0(0) p1(1) = p2(1) + + If rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") = GApDT.Select("NAME = 'GA_3'")(0)("Y") OrElse + rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") = GApDT.Select("NAME = 'GA_1'")(0)("Y") Then + If rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("X") < GApDT.Select("NAME = 'GA_3'")(0)("X") AndAlso + rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("X") > GApDT.Select("NAME = 'GA_4'")(0)("X") Then + + Exit Sub + ElseIf rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("X") > GApDT.Select("NAME = 'GA_1'")(0)("X") AndAlso + rDT.Select("NAME = '" & newDR("NAME") & "'")(0)("X") < GApDT.Select("NAME = 'GA_2'")(0)("X") Then + + Exit Sub + End If + End If End If Dim gpInside As Boolean = Calculate_Triangle_Bool(gp, p0, p1, p2) @@ -380,32 +469,32 @@ Public Class Multiple_Drawing ' FIXA: GA punkten tas bort innan vi behöver den här If side = 1 Then - Dim c As Double = pDT.Select("NAME = 'GA_1'")(0)("Y") - rpDR("Y") - Dim x As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - pDT.Select("NAME = 'GA_1'")(0)("X") + Dim c As Double = GApDT.Select("NAME = 'GA_1'")(0)("Y") - rpDR("Y") + Dim x As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_1'")(0)("X") Dim z As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - rpDR("Y") - newDR("X") = pDT.Select("NAME = 'GA_1'")(0)("X") + c * x / z ' Triangle likformighet - newDR("Y") = pDT.Select("NAME = 'GA_1'")(0)("Y") + newDR("X") = GApDT.Select("NAME = 'GA_1'")(0)("X") + c * x / z ' Triangle likformighet + newDR("Y") = GApDT.Select("NAME = 'GA_1'")(0)("Y") ElseIf side = 2 Then - Dim c As Double = pDT.Select("NAME = 'GA_2'")(0)("X") - rpDR("X") - Dim x As Double = pDT.Select("NAME = 'GA_2'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") + Dim c As Double = GApDT.Select("NAME = 'GA_2'")(0)("X") - rpDR("X") + Dim x As Double = GApDT.Select("NAME = 'GA_2'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") Dim z As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - rpDR("X") - newDR("X") = pDT.Select("NAME = 'GA_2'")(0)("X") - newDR("Y") = pDT.Select("NAME = 'GA_2'")(0)("Y") - c * x / z ' Triangle likformighet + newDR("X") = GApDT.Select("NAME = 'GA_2'")(0)("X") + newDR("Y") = GApDT.Select("NAME = 'GA_2'")(0)("Y") - c * x / z ' Triangle likformighet ElseIf side = 3 Then - Dim c As Double = rpDR("Y") - pDT.Select("NAME = 'GA_3'")(0)("Y") - Dim x As Double = pDT.Select("NAME = 'GA_3'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") + Dim c As Double = rpDR("Y") - GApDT.Select("NAME = 'GA_3'")(0)("Y") + Dim x As Double = GApDT.Select("NAME = 'GA_3'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") Dim z As Double = rpDR("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - newDR("X") = pDT.Select("NAME = 'GA_3'")(0)("X") - c * x / z ' Triangle likformighet - newDR("Y") = pDT.Select("NAME = 'GA_3'")(0)("Y") + newDR("X") = GApDT.Select("NAME = 'GA_3'")(0)("X") - c * x / z ' Triangle likformighet + newDR("Y") = GApDT.Select("NAME = 'GA_3'")(0)("Y") Else - Dim c As Double = rpDR("X") - pDT.Select("NAME = 'GA_4'")(0)("X") - Dim x As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - pDT.Select("NAME = 'GA_4'")(0)("Y") + Dim c As Double = rpDR("X") - GApDT.Select("NAME = 'GA_4'")(0)("X") + Dim x As Double = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_4'")(0)("Y") Dim z As Double = rpDR("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - newDR("X") = pDT.Select("NAME = 'GA_4'")(0)("X") - newDR("Y") = pDT.Select("NAME = 'GA_4'")(0)("Y") + c * x / z ' Triangle likformighet + newDR("X") = GApDT.Select("NAME = 'GA_4'")(0)("X") + newDR("Y") = GApDT.Select("NAME = 'GA_4'")(0)("Y") + c * x / z ' Triangle likformighet End If - insertIndex = Get_RowIndex(pDT, side, newDR("X"), newDR("Y")) + 1 + insertIndex = Get_RowIndex(pDT, side, newDR("X"), newDR("Y"), GApDT) + 1 Else ' If true => remove point gp and new point at side rpDR("SIDE")+2 Dim side As Integer = 0 @@ -442,7 +531,7 @@ Public Class Multiple_Drawing ' newDR("Y") = pDT.Select("NAME = 'P4'")(0)("Y") + c * x / z ' Triangle likformighet 'End If - insertIndex = Get_RowIndex(pDT, side, newDR("X"), newDR("Y")) + insertIndex = Get_RowIndex(pDT, side, newDR("X"), newDR("Y"), GApDT) pDT.Rows.RemoveAt(insertIndex) End If