diff --git a/HLCt/Parts/START.SLDPRT b/HLCt/Parts/START.SLDPRT index 980d16b..c5c2312 100644 Binary files a/HLCt/Parts/START.SLDPRT and b/HLCt/Parts/START.SLDPRT differ diff --git a/Wardrobe/SolidWorks/Individual_Frame_3D.vb b/Wardrobe/SolidWorks/Individual_Frame_3D.vb index 84b5b8f..0141c5b 100644 --- a/Wardrobe/SolidWorks/Individual_Frame_3D.vb +++ b/Wardrobe/SolidWorks/Individual_Frame_3D.vb @@ -251,29 +251,124 @@ Public Class Individual_Frame_3D While frameLengths.Count > 0 Dim frameCutList As New Dictionary(Of String, Integer) - frameCutList.Add(frameLengths.ElementAt(0).Key, frameLengths.ElementAt(0).Value) 'Fixa så att vi hela tiden tar den längsta och testar mot de andra - frameLengths.Remove(frameLengths.ElementAt(0).Key) + Dim longestFrame As Integer = 0 + Dim longestFrameKey As String = "" + For i = 0 To frameLengths.Count - 1 + If frameLengths.ElementAt(i).Value > longestFrame Then + longestFrame = frameLengths.ElementAt(i).Value + longestFrameKey = frameLengths.ElementAt(i).Key + End If + Next + frameCutList.Add(longestFrameKey, longestFrame) + frameLengths.Remove(longestFrameKey) - For i = 0 To 100 + For i = 0 To 1000 Dim lengthRemaining As Integer = 2000 For j = 0 To frameCutList.Count - 1 lengthRemaining -= frameCutList.ElementAt(j).Value Next Dim restLength As Integer = 2000 - Dim frameID As String = "" + Dim frameID As New List(Of String) For j = 0 To frameLengths.Count - 1 - If lengthRemaining - frameLengths.ElementAt(j).Value > 0 AndAlso lengthRemaining - frameLengths.ElementAt(j).Value < restLength Then + If lengthRemaining - frameLengths.ElementAt(j).Value >= 0 AndAlso lengthRemaining - frameLengths.ElementAt(j).Value < restLength Then restLength = lengthRemaining - frameLengths.ElementAt(j).Value - frameID = frameLengths.ElementAt(j).Key + frameID.Clear() + frameID.Add(frameLengths.ElementAt(j).Key) End If Next - If frameID = "" Then + If frameID.Count = 0 Then Exit For Else - frameCutList.Add(frameID, frameLengths(frameID)) - frameLengths.Remove(frameID) + Dim frameCombDS As New DataSet + For l = 2 To frameLengths.Count + Dim frameCombDT As New DataTable + + Dim numOfValues As Integer = l + Dim numOfComb As Integer = Calculate_Factorial(frameLengths.Count) / (Calculate_Factorial(numOfValues) * Calculate_Factorial(frameLengths.Count - numOfValues)) + + For j = 1 To numOfValues + frameCombDT.Columns.Add("Enum " & j, GetType(Integer)) + Next + For j = 1 To numOfValues + frameCombDT.Columns.Add("ID " & j, GetType(Integer)) + Next + frameCombDT.Columns.Add("Combined Length", GetType(Integer)) + + Dim frameCombDR As DataRow = frameCombDT.NewRow + Dim combLength As Integer = 0 + For j = 1 To numOfValues + frameCombDR("Enum " & j) = j + frameCombDR("ID " & j) = CInt(frameLengths.ElementAt(j - 1).Key.Split(" ")(1)) + combLength += frameLengths.ElementAt(j - 1).Value + Next + frameCombDR("Combined Length") = combLength + frameCombDT.Rows.Add(frameCombDR) + + For j = 1 To numOfComb - 1 + frameCombDR = frameCombDT.NewRow + + If frameCombDT.Rows(j - 1)("Enum " & numOfValues) < frameLengths.Count Then + combLength = 0 + For k = 1 To numOfValues + If k = numOfValues Then + frameCombDR("Enum " & k) = frameCombDT.Rows(j - 1)("Enum " & k) + 1 + frameCombDR("ID " & k) = CInt(frameLengths.ElementAt(frameCombDR("Enum " & k) - 1).Key.Split(" ")(1)) + Else + frameCombDR("Enum " & k) = frameCombDT.Rows(j - 1)("Enum " & k) + frameCombDR("ID " & k) = frameCombDT.Rows(j - 1)("ID " & k) + End If + combLength += frameLengths.ElementAt(frameCombDR("Enum " & k) - 1).Value + Next + frameCombDR("Combined Length") = combLength + + Else + Dim frameEnum As Integer + For k = numOfValues To 1 Step -1 + If frameCombDT.Rows(j - 1)("Enum " & k) < frameLengths.Count - (numOfValues - k) Then + frameEnum = k + End If + Next + + combLength = 0 + For k = 1 To numOfValues + If k = frameEnum Then + frameCombDR("Enum " & k) = frameCombDT.Rows(j - 1)("Enum " & k) + 1 + frameCombDR("ID " & k) = CInt(frameLengths.ElementAt(frameCombDR("Enum " & k) - 1).Key.Split(" ")(1)) + ElseIf k > frameEnum Then + frameCombDR("Enum " & k) = frameCombDR("Enum " & k - 1) + 1 + frameCombDR("ID " & k) = CInt(frameLengths.ElementAt(frameCombDR("Enum " & k) - 1).Key.Split(" ")(1)) + Else + frameCombDR("Enum " & k) = frameCombDT.Rows(j - 1)("Enum " & k) + frameCombDR("ID " & k) = frameCombDT.Rows(j - 1)("ID " & k) + End If + combLength += frameLengths.ElementAt(frameCombDR("Enum " & k) - 1).Value + Next + frameCombDR("Combined Length") = combLength + End If + + frameCombDT.Rows.Add(frameCombDR) + Next + frameCombDS.Tables.Add(frameCombDT) + Next + + For j = 0 To frameCombDS.Tables.Count - 1 + For Each DR As DataRow In frameCombDS.Tables(j).Rows + If lengthRemaining - DR("Combined Length") >= 0 AndAlso lengthRemaining - DR("Combined Length") < restLength Then + restLength = lengthRemaining - DR("Combined Length") + frameID.Clear() + For k = 1 To j + 2 + frameID.Add("Frame " & DR("ID " & k)) + Next + End If + Next + Next + + For j = 0 To frameID.Count - 1 + frameCutList.Add(frameID.ElementAt(j), frameLengths(frameID.ElementAt(j))) + frameLengths.Remove(frameID.ElementAt(j)) + Next End If Next @@ -289,6 +384,22 @@ Public Class Individual_Frame_3D Return cuttingList End Function + Private Shared Function Calculate_Factorial(num As Integer) + Dim result As Integer + If num = 0 Then + result = 1 + Else + result = num + num -= 1 + While num > 1 + result = result * num + num -= 1 + End While + End If + + Return result + End Function + Public Shared Sub Generate_End_Frame_Pieces() Dim swApp As SldWorks.SldWorks swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks.SldWorks)