diff --git a/HLCt/pressure_welded.SLDPRT b/HLCt/pressure_welded.SLDPRT index 06cb614..1355744 100644 Binary files a/HLCt/pressure_welded.SLDPRT and b/HLCt/pressure_welded.SLDPRT differ diff --git a/HLCt/pressure_welded_serrated.SLDPRT b/HLCt/pressure_welded_serrated.SLDPRT index 53ec333..90c24a0 100644 Binary files a/HLCt/pressure_welded_serrated.SLDPRT and b/HLCt/pressure_welded_serrated.SLDPRT differ diff --git a/HLCt/recess_angle.SLDPRT b/HLCt/recess_angle.SLDPRT index 3a446f6..1addea2 100644 Binary files a/HLCt/recess_angle.SLDPRT and b/HLCt/recess_angle.SLDPRT differ diff --git a/HLCt/recess_middle_square.SLDPRT b/HLCt/recess_middle_square.SLDPRT index 117d94d..8f0f185 100644 Binary files a/HLCt/recess_middle_square.SLDPRT and b/HLCt/recess_middle_square.SLDPRT differ diff --git a/HLCt/recess_rectangle.SLDPRT b/HLCt/recess_rectangle.SLDPRT index 6005fed..ad167fe 100644 Binary files a/HLCt/recess_rectangle.SLDPRT and b/HLCt/recess_rectangle.SLDPRT differ diff --git a/HLCt/recess_side_square.SLDPRT b/HLCt/recess_side_square.SLDPRT index fa68598..24c4434 100644 Binary files a/HLCt/recess_side_square.SLDPRT and b/HLCt/recess_side_square.SLDPRT differ diff --git a/HLCt/simplified_floor_grating.SLDPRT b/HLCt/simplified_floor_grating.SLDPRT new file mode 100644 index 0000000..d444b02 Binary files /dev/null and b/HLCt/simplified_floor_grating.SLDPRT differ diff --git a/HLCt/type_a.SLDPRT b/HLCt/type_a.SLDPRT index e1bda21..27ac53e 100644 Binary files a/HLCt/type_a.SLDPRT and b/HLCt/type_a.SLDPRT differ diff --git a/HLCt/type_a_serrated.SLDPRT b/HLCt/type_a_serrated.SLDPRT index 6e771d8..a263e50 100644 Binary files a/HLCt/type_a_serrated.SLDPRT and b/HLCt/type_a_serrated.SLDPRT differ diff --git a/Wardrobe/GUI/Individual.vb b/Wardrobe/GUI/Individual.vb index a996c2a..eb2d041 100644 --- a/Wardrobe/GUI/Individual.vb +++ b/Wardrobe/GUI/Individual.vb @@ -244,7 +244,7 @@ Public Class Individual If AppForm.fillMode Then Grating_Fill.Calculate_Grid() - Multiple_Drawing.Create_Models_For_Drawing() ' Ska flyttas till sist i if satsen + Multiple_Drawing.Build_Grid() ' Ska flyttas till sist i if satsen Multiple_3D.BuildGrid() Else diff --git a/Wardrobe/SolidWorks/Multiple_3D.vb b/Wardrobe/SolidWorks/Multiple_3D.vb index d874901..f9bedbc 100644 --- a/Wardrobe/SolidWorks/Multiple_3D.vb +++ b/Wardrobe/SolidWorks/Multiple_3D.vb @@ -10,9 +10,6 @@ Public Class Multiple_3D Dim pointTable1 As DataTable pointTable1 = Data.grossAreaPoints - - - Dim exportTable As DataTable exportTable = User_Input.Create_ExportTable() diff --git a/Wardrobe/SolidWorks/Multiple_Drawing.vb b/Wardrobe/SolidWorks/Multiple_Drawing.vb index 868f307..e696dba 100644 --- a/Wardrobe/SolidWorks/Multiple_Drawing.vb +++ b/Wardrobe/SolidWorks/Multiple_Drawing.vb @@ -1,773 +1,547 @@ -Imports SldWorks +Imports XCCLibrary +Imports SldWorks Public Class Multiple_Drawing + Private Shared gratingParameters As DataRow + Private Shared designName As String + Public Shared Sub Build_Grid() + Dim exportTable As DataTable + exportTable = User_Input.Create_ExportTable() - Public Shared Sub Create_Models_For_Drawing() - Dim gratingsPointsDS As DataSet = Create_GratingPoints() + XCCBaseClass.newDesign() + ExternalClass.PopulateTamplateXMLGroup() - Dim gratingHeight As Decimal = User_Input.gratingHeight / 1000 + Dim inst_ As Integer + Dim parentID As Integer = 0 + gratingParameters = exportTable.Rows(0) + + For i = 0 To Grating_Fill.gratingDimensions.Rows.Count - 1 + inst_ = ExternalClass.instantiate_parts(parentID, "simplified_floor_grating", "") ' Ange pressure_welded eller type A, Serrated? + ExternalClass.modify_parameter_value("DP_LOADBAR_HEIGHT", inst_, gratingParameters("LOADBAR_HEIGHT")) + ExternalClass.modify_parameter_value("DP_GRATING_WIDTH", inst_, Grating_Fill.gratingDimensions.Rows(i)("WIDTH")) + ExternalClass.modify_parameter_value("DP_GRATING_LENGTH", inst_, Grating_Fill.gratingDimensions.Rows(i)("LENGTH")) + Dim offsetX As Integer = 0 + For j = 1 To Grating_Fill.gratingDimensions.Rows(i)("COLUMN") + offsetX += Grating_Fill.gratingDimensions.Rows(i - j)("LENGTH") + Next + + Dim offsetY As Integer = 0 + For j = 1 To Grating_Fill.gratingDimensions.Rows(i)("ROW") + offsetY += Grating_Fill.gratingDimensions.Rows(i - Grating_Fill.numOfHorizontal * j)("WIDTH") + Next + + ExternalClass.modify_parameter_value("DP_OFFSET_X", inst_, (Grating_Fill.gratingDimensions.Rows(i)("LENGTH") / 2) + offsetX) + ExternalClass.modify_parameter_value("DP_OFFSET_Y", inst_, (Grating_Fill.gratingDimensions.Rows(i)("WIDTH") / 2) + offsetY) + Next + + parentID = Grating_Fill.numOfHorizontal * (Grating_Fill.numOfVertical - 1) + 1 + For Each recessDR As DataRow In Data.recessData.Rows + Inst_Recesses(parentID, gratingParameters, recessDR) + Next + + importClass.copyGroupsByDataSet(ExternalClass.groupds_new) + Dim grNr = groupClass.NewGroupID + Dim designTable = designModel.selectDesign("*") + designName = designTable.rows(0)("designName") + groupClass.InstantiateGroup(designName, grNr, "START") + + Delete_Obsolete() + Recess_Indent() + Suppress_Bodies() + + Save_Assembly() + End Sub + + Private Shared Sub Suppress_Bodies() + Dim swApp As SldWorks.SldWorks + swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks.SldWorks) + + Dim boolstatus As Boolean + Dim AssemblyExtension As SldWorks.ModelDocExtension + + Dim Assembly = swApp.ActiveDoc + Dim modelDoc As IModelDoc2 + modelDoc = Assembly + + Dim SelMgr = Assembly.SelectionManager() + AssemblyExtension = Assembly.Extension + Dim sldata = SelMgr.CreateSelectData + + Dim partDT As New DataTable + partDT = partModel.selectPart("*") + + Dim gratingParts = partDT.Select("parentName = 'START'") + + Dim components = Assembly.GetComponents(True) + + For i = 0 To components.Length - 1 + Dim compName As String = components(i).Name2 + If compName.Split("_")(0) = "RECESS" Then + Assembly.ClearSelection2(True) + boolstatus = AssemblyExtension.SelectByID2(compName & "@" & designName, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0) + Assembly.EditPart + + Dim recessBodies = components(i).GetBodies2(0) + Dim recessBodyList As New List(Of String) + For j = 0 To recessBodies.Length - 1 + Dim bodyName As String = recessBodies(j).Name + If Not bodyName = "Cut-Body" Then + recessBodyList.Add(bodyName) + End If + Next + For j = 0 To recessBodyList.Count - 1 + Assembly.ClearSelection2(True) + boolstatus = AssemblyExtension.SelectByID2(recessBodyList(j) & "@" & compName & "@" & designName, "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0) + modelDoc.EditSuppress2() + Next + Assembly.EditAssembly + End If + Next + End Sub + + Private Shared Sub Save_Assembly() + Dim swApp As SldWorks.SldWorks + swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks.SldWorks) + + Dim status As Boolean + + Dim Assebmly = swApp.ActiveDoc() + status = Assebmly.SaveAs3(Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw_support") & "\gratings_assembly_simplified.SLDASM", 0, 4) + End Sub + + Private Shared Sub Inst_Recesses(parentID As Integer, gratingParameters As DataRow, recessDR As DataRow) + Dim inst_ As Integer + + If recessDR("RECESS TYPE") = "SQUARE" Then + Dim squareL As Integer = recessDR("LENGTH") + gratingParameters("LOADBAR_THICKNESS") + Dim squareW As Integer = recessDR("WIDTH") + gratingParameters("LOADBAR_THICKNESS") + + inst_ = ExternalClass.instantiate_parts(parentID, "recess_rectangle", "") + + ExternalClass.modify_parameter_value("DP_LENGTH", inst_, squareL + gratingParameters("LOADBAR_THICKNESS")) + ExternalClass.modify_parameter_value("DP_WIDTH", inst_, squareW) + ExternalClass.modify_parameter_value("DP_EDGEBAR_HEIGHT", inst_, gratingParameters("LOADBAR_HEIGHT")) + ExternalClass.modify_parameter_value("DP_EDGEBAR_THICKNESS", inst_, gratingParameters("LOADBAR_THICKNESS")) + ExternalClass.modify_parameter_value("DP_BOX_HEIGHT", inst_, gratingParameters("LOADBAR_HEIGHT")) + + + If recessDR("CORNER") = 1 Then + ExternalClass.modify_parameter_value("DP_OFFSET_W", inst_, Data.gratingW - squareW) + ExternalClass.modify_parameter_value("DP_OFFSET_L", inst_, 0) + + 'Position + ExternalClass.modify_parameter_value("DP_V_EDGEBAR_POS", inst_, squareL) + ExternalClass.modify_parameter_value("DP_V_EDGEBAR_BOTTOM", inst_, gratingParameters("LOADBAR_THICKNESS")) + ExternalClass.modify_parameter_value("DP_H_EDGEBAR_POS", inst_, 0) + ElseIf recessDR("CORNER") = 2 Then + ExternalClass.modify_parameter_value("DP_OFFSET_W", inst_, Data.gratingW - squareW) + ExternalClass.modify_parameter_value("DP_OFFSET_L", inst_, Data.gratingL - squareL - gratingParameters("LOADBAR_THICKNESS")) + + 'Position + ExternalClass.modify_parameter_value("DP_V_EDGEBAR_POS", inst_, 0) + ExternalClass.modify_parameter_value("DP_V_EDGEBAR_BOTTOM", inst_, gratingParameters("LOADBAR_THICKNESS")) + ExternalClass.modify_parameter_value("DP_H_EDGEBAR_POS", inst_, 0) + ElseIf recessDR("CORNER") = 3 Then + ExternalClass.modify_parameter_value("DP_OFFSET_W", inst_, 0) + ExternalClass.modify_parameter_value("DP_OFFSET_L", inst_, Data.gratingL - squareL - gratingParameters("LOADBAR_THICKNESS")) + + 'Position + ExternalClass.modify_parameter_value("DP_V_EDGEBAR_POS", inst_, 0) + ExternalClass.modify_parameter_value("DP_V_EDGEBAR_BOTTOM", inst_, 0) + ExternalClass.modify_parameter_value("DP_H_EDGEBAR_POS", inst_, squareW - gratingParameters("LOADBAR_THICKNESS")) + Else + ExternalClass.modify_parameter_value("DP_OFFSET_W", inst_, 0) + ExternalClass.modify_parameter_value("DP_OFFSET_L", inst_, 0) + + 'Position + ExternalClass.modify_parameter_value("DP_V_EDGEBAR_POS", inst_, squareL) + ExternalClass.modify_parameter_value("DP_V_EDGEBAR_BOTTOM", inst_, 0) + ExternalClass.modify_parameter_value("DP_H_EDGEBAR_POS", inst_, squareW - gratingParameters("LOADBAR_THICKNESS")) + End If + + ElseIf recessDR("RECESS TYPE") = "ANGLE" Then + inst_ = ExternalClass.instantiate_parts(parentID, "recess_angle", "") + + ExternalClass.modify_parameter_value("DP_EDGEBAR_HEIGHT", inst_, gratingParameters("LOADBAR_HEIGHT")) + ExternalClass.modify_parameter_value("DP_EDGEBAR_THICKNESS", inst_, gratingParameters("LOADBAR_THICKNESS")) + + If recessDR("CORNER") = 1 Then + ExternalClass.modify_parameter_value("DP_LENGTH", inst_, recessDR("WIDTH")) + ExternalClass.modify_parameter_value("DP_WIDTH", inst_, recessDR("LENGTH")) + ExternalClass.modify_parameter_value("DP_OFFSET_W", inst_, Data.gratingW) + ExternalClass.modify_parameter_value("DP_OFFSET_L", inst_, 0) + ExternalClass.modify_parameter_value("DP_ROTATION", inst_, 90) + + ElseIf recessDR("CORNER") = 2 Then + ExternalClass.modify_parameter_value("DP_LENGTH", inst_, recessDR("LENGTH")) + ExternalClass.modify_parameter_value("DP_WIDTH", inst_, recessDR("WIDTH")) + ExternalClass.modify_parameter_value("DP_OFFSET_W", inst_, Data.gratingW) + ExternalClass.modify_parameter_value("DP_OFFSET_L", inst_, Data.gratingL) + ExternalClass.modify_parameter_value("DP_ROTATION", inst_, 180) + + ElseIf recessDR("CORNER") = 3 Then + ExternalClass.modify_parameter_value("DP_LENGTH", inst_, recessDR("WIDTH")) + ExternalClass.modify_parameter_value("DP_WIDTH", inst_, recessDR("LENGTH")) + ExternalClass.modify_parameter_value("DP_OFFSET_W", inst_, 0) + ExternalClass.modify_parameter_value("DP_OFFSET_L", inst_, Data.gratingL) + ExternalClass.modify_parameter_value("DP_ROTATION", inst_, 270) + + Else + ExternalClass.modify_parameter_value("DP_LENGTH", inst_, recessDR("LENGTH")) + ExternalClass.modify_parameter_value("DP_WIDTH", inst_, recessDR("WIDTH")) + ExternalClass.modify_parameter_value("DP_OFFSET_W", inst_, 0) + ExternalClass.modify_parameter_value("DP_OFFSET_L", inst_, 0) + ExternalClass.modify_parameter_value("DP_ROTATION", inst_, 0) + + End If + + ElseIf recessDR("RECESS TYPE") = "SIDE SQUARE" Then + inst_ = ExternalClass.instantiate_parts(parentID, "recess_side_square", "") + + ExternalClass.modify_parameter_value("DP_EDGEBAR_HEIGHT", inst_, gratingParameters("LOADBAR_HEIGHT")) + ExternalClass.modify_parameter_value("DP_EDGEBAR_THICKNESS", inst_, gratingParameters("LOADBAR_THICKNESS")) + + If recessDR("SIDE") = 1 Then + ExternalClass.modify_parameter_value("DP_LENGTH", inst_, recessDR("WIDTH")) + ExternalClass.modify_parameter_value("DP_WIDTH", inst_, recessDR("LENGTH")) + ExternalClass.modify_parameter_value("DP_OFFSET_W", inst_, Data.gratingW) + ExternalClass.modify_parameter_value("DP_OFFSET_L", inst_, recessDR("OFFSET")) + ExternalClass.modify_parameter_value("DP_ROTATION", inst_, 90) + + ElseIf recessDR("SIDE") = 2 Then + ExternalClass.modify_parameter_value("DP_LENGTH", inst_, recessDR("LENGTH")) + ExternalClass.modify_parameter_value("DP_WIDTH", inst_, recessDR("WIDTH")) + ExternalClass.modify_parameter_value("DP_OFFSET_W", inst_, Data.gratingW - recessDR("OFFSET")) + ExternalClass.modify_parameter_value("DP_OFFSET_L", inst_, Data.gratingL) + ExternalClass.modify_parameter_value("DP_ROTATION", inst_, 180) + + ElseIf recessDR("SIDE") = 3 Then + ExternalClass.modify_parameter_value("DP_LENGTH", inst_, recessDR("WIDTH")) + ExternalClass.modify_parameter_value("DP_WIDTH", inst_, recessDR("LENGTH")) + ExternalClass.modify_parameter_value("DP_OFFSET_W", inst_, 0) + ExternalClass.modify_parameter_value("DP_OFFSET_L", inst_, Data.gratingL - recessDR("OFFSET")) + ExternalClass.modify_parameter_value("DP_ROTATION", inst_, 270) + + Else + ExternalClass.modify_parameter_value("DP_LENGTH", inst_, recessDR("LENGTH")) + ExternalClass.modify_parameter_value("DP_WIDTH", inst_, recessDR("WIDTH")) + ExternalClass.modify_parameter_value("DP_OFFSET_W", inst_, recessDR("OFFSET")) + ExternalClass.modify_parameter_value("DP_OFFSET_L", inst_, 0) + ExternalClass.modify_parameter_value("DP_ROTATION", inst_, 0) + + End If + + ElseIf recessDR("RECESS TYPE") = "MIDDLE SQUARE" Then + inst_ = ExternalClass.instantiate_parts(parentID, "recess_middle_square", "") + + ExternalClass.modify_parameter_value("DP_LENGTH", inst_, recessDR("LENGTH")) + ExternalClass.modify_parameter_value("DP_WIDTH", inst_, recessDR("WIDTH")) + ExternalClass.modify_parameter_value("DP_EDGEBAR_HEIGHT", inst_, gratingParameters("LOADBAR_HEIGHT")) + ExternalClass.modify_parameter_value("DP_EDGEBAR_THICKNESS", inst_, gratingParameters("LOADBAR_THICKNESS")) + ExternalClass.modify_parameter_value("DP_OFFSET_W", inst_, recessDR("OFFSET Y")) + ExternalClass.modify_parameter_value("DP_OFFSET_L", inst_, recessDR("OFFSET X")) + End If + End Sub + + Private Shared Sub Recess_Indent() + Dim swApp As SldWorks.SldWorks + swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks.SldWorks) + + Dim boolstatus As Boolean + Dim AssemblyExtension As SldWorks.ModelDocExtension + + Dim Assembly = swApp.ActiveDoc + Dim modelDoc As IModelDoc2 + modelDoc = Assembly + + Dim SelMgr = Assembly.SelectionManager() + AssemblyExtension = Assembly.Extension + Dim sldata = SelMgr.CreateSelectData + + Dim partDT As New DataTable + partDT = partModel.selectPart("*") + + Dim gratingParts = partDT.Select("parentName = 'START'") + + Dim components = Assembly.GetComponents(True) + + 'Indent + Dim recessParentName As String = partDT.Rows(Grating_Fill.numOfHorizontal * (Grating_Fill.numOfVertical - 1))("partName") + Dim recessParts = partDT.Select("parentName = '" & recessParentName & "'") + For i = 0 To recessParts.Count - 1 + Dim recessPartName As String = recessParts(i)("partName") + If recessPartName.Split("_")(0) = "RECESS" Then + + Dim indexRecess As Integer + For k = 0 To components.Length - 1 + If components(k).Name2 = recessPartName & "-1" Then + indexRecess = k + Exit For + End If + Next + + Dim recessBodies = components(indexRecess).GetBodies2(0) + Dim recessComponent As SldWorks.Component2 = components(indexRecess) + + Dim indexBody As Integer + For l = 0 To recessBodies.Length - 1 + If recessBodies(l).Name = "Cut-Body" Then + indexBody = l + Exit For + End If + Next + + Dim recessFace = recessBodies(indexBody).GetFirstFace + + For j = 0 To Grating_Fill.numOfVertical * Grating_Fill.numOfHorizontal - 1 + Assembly.ClearSelection2(True) + + Dim gratingPartName As String = partDT.Rows(j)("partName") + boolstatus = AssemblyExtension.SelectByID2(gratingPartName & "-1@" & designName, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0) + If boolstatus = True Then + Dim gratingPart = SelMgr.GetSelectedObject6(1, -1) + + Assembly.EditPart + + Dim indexGrating As Integer + For k = 0 To components.Length - 1 + If components(k).Name2 = gratingPartName & "-1" Then + indexGrating = k + Exit For + End If + Next + + Dim gratingComponent As SldWorks.Component2 = components(indexGrating) + + Dim bodiesToCut = Check_Interference(gratingComponent, recessComponent, gratingPartName & "-1") + + For k = 0 To bodiesToCut.Length - 1 + Assembly.ClearSelection2(True) + + sldata.Mark = 1 + Dim bodyName As String = bodiesToCut(k).Name & "@" & gratingPartName & "-1@" & designName + boolstatus = AssemblyExtension.SelectByID2(bodyName, "SOLIDBODY", 0, 0, 0, True, 1, Nothing, 0) + + sldata.Mark = 4 + recessFace.Select4(True, sldata) + + Assembly.FeatureManager.InsertIndent(0.01, 0, False, True, True, False) + Assembly.ClearSelection2(True) + Next + + bodiesToCut = Check_Interference(gratingComponent, recessComponent, gratingPartName & "-1") + + For k = 0 To bodiesToCut.Length - 1 + boolstatus = AssemblyExtension.SelectByID2(bodiesToCut(k).Name & "@" & gratingPartName & "-1@" & designName, "SOLIDBODY", 0, 0, 0, True, 0, Nothing, 0) + Dim myFeature As Object + Dim modelFeat As FeatureManager = modelDoc.FeatureManager + myFeature = modelFeat.InsertDeleteBody2(False) + Next + + Assembly.EditAssembly + End If + Next + Assembly.ClearSelection2(True) + End If + Assembly.EditAssembly + boolstatus = modelDoc.EditRebuild3() + Next + End Sub + + + Private Shared Sub Delete_Obsolete() + Dim listOfObsolete As List(Of Integer) + listOfObsolete = Find_Obsolete() Dim swApp As SldWorks.SldWorks swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks.SldWorks) - Dim Model As ModelDoc2 - Dim RootPoint(2) As Decimal - Dim Normal(2) As Decimal - swApp.UserControl = True - - Dim swSkMgr As SketchManager - Dim longstatus As Integer Dim boolstatus As Boolean - Dim swModelDocExtension As ModelDocExtension - Dim status As Boolean - Dim swFeatureMgr As FeatureManager - Dim swFeature As Feature - Dim iPart As PartDoc - - Dim numOfGratings As Integer = Grating_Fill.numOfVertical * Grating_Fill.numOfHorizontal - - For i = 0 To numOfGratings - 1 - Model = swApp.NewDocument("C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2020\templates\part.prtdot", 0, 0, 0) - - swSkMgr = Model.SketchManager - swSkMgr.InsertSketch(True) - boolstatus = Model.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0) - Model.ClearSelection2(True) - - For Each DR As DataRow In gratingsPointsDS.Tables(i).Rows - Dim skPoint As SketchPoint - Dim pX = DR("X") - Dim pY = DR("Y") - skPoint = swSkMgr.CreatePoint(pX, pY, 0) - Next - - For Each DR1 As DataRow In gratingsPointsDS.Tables(i).Rows - Dim skLine As SketchLine - Dim rowIndex = gratingsPointsDS.Tables(i).Rows.IndexOf(DR1) - Dim DR2 As DataRow - - Try - DR2 = gratingsPointsDS.Tables(i).Rows(rowIndex + 1) - Catch ex As Exception - DR2 = gratingsPointsDS.Tables(i).Rows(0) - End Try - - Dim pX1 = DR1("X") - Dim pY1 = DR1("Y") - Dim pX2 = DR2("X") - Dim pY2 = DR2("Y") - - skLine = swSkMgr.CreateLine(pX1, pY1, 0, pX2, pY2, 0) - Next - - swSkMgr.InsertSketch(True) - - swModelDocExtension = Model.Extension - status = swModelDocExtension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0) - - swFeatureMgr = Model.FeatureManager - swFeature = swFeatureMgr.FeatureExtrusion3(True, False, False, 0, 0, gratingHeight, 0, False, False, False, False, 0, 0, False, False, False, False, True, True, True, 0, 0, False) - - - ' MIddle points if needed - - - Model.ClearSelection2(True) - boolstatus = Model.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0) - Model.FeatureManager.InsertRefPlane(8, gratingHeight, 0, 0, 0, 0) - - iPart = swApp.ActiveDoc - Dim newName As String - newName = Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw_support") & "\simplified_grating_" & i + 1 & ".SLDPRT" - - - ' Title head data - - - longstatus = iPart.SaveAs3(newName, 0, 0) - swApp.CloseDoc(newName) - Next - - ' --- Assembly --- - Dim assembly As IAssemblyDoc + Dim Assembly = swApp.ActiveDoc Dim AssemblyExtension As SldWorks.ModelDocExtension - Model = swApp.NewDocument("C:\ProgramData\SolidWorks\SOLIDWORKS 2020\templates\Assembly.asmdot", 0, 0, 0) - assembly = Model - AssemblyExtension = assembly.Extension + AssemblyExtension = Assembly.Extension - Dim compNames(numOfGratings - 1) As String - Dim coordNames(numOfGratings - 1) As String - Dim transMatrix As Object = Nothing - For i = 0 To numOfGratings - 1 - compNames(i) = Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw_support") & "\simplified_grating_" & i + 1 & ".SLDPRT" - coordNames(i) = "" - Next + Dim partDT As New DataTable + partDT = partModel.selectPart("*") - Dim assemComps As Object - assemComps = assembly.AddComponents3((compNames), (transMatrix), (coordNames)) - - Model.ViewZoomtofit2() - longstatus = Model.SaveAs3(Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw_support") & "\simplified_grating_assembly.SLDASM", 0, 0) - - ' --- Delete Obsolete --- - Dim listOfObsolete As List(Of Integer) - listOfObsolete = Multiple_3D.Find_Obsolete() + Dim gratingParts = partDT.Select("parentName = 'START'") For i = 0 To listOfObsolete.Count - 1 - assembly.ClearSelection2(True) - boolstatus = AssemblyExtension.SelectByID2("simplified_grating_" & listOfObsolete(i) & "-1@simplified_grating_assembly", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0) - assembly.EditDelete + Dim gratingPartName As String = gratingParts(listOfObsolete(i))("partName") - My.Computer.FileSystem.DeleteFile(Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw_support") & "\simplified_grating_" & listOfObsolete(i) & ".SLDPRT") + Assembly.ClearSelection2(True) + boolstatus = AssemblyExtension.SelectByID2(gratingPartName & "-1@" & designName, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0) + Assembly.EditDelete Next - - Dim swErrors As Integer - Dim swWarnings As Integer - boolstatus = assembly.Save3(1, swErrors, swWarnings) End Sub - Private Shared Function Create_GratingPoints() - Dim pointsDS As New DataSet + Public Shared Function Find_Obsolete() + Dim listOfObsolete As New List(Of Integer) - Dim numOfGratings As Integer = Grating_Fill.numOfVertical * Grating_Fill.numOfHorizontal + For i = 0 To Grating_Fill.numOfVertical * Grating_Fill.numOfHorizontal - 1 + Dim gratingDR As DataRow = Grating_Fill.gratingDimensions.Rows(i) + Dim origo(2) As Integer + origo(0) = Data.gratingL / 2 + origo(1) = Data.gratingW / 2 - For i = 0 To numOfGratings - 1 - Dim pointsDT As New DataTable - pointsDT.Columns.Add("NAME", GetType(String)) - pointsDT.Columns.Add("TYPE", GetType(String)) - pointsDT.Columns.Add("X", GetType(Decimal)) - pointsDT.Columns.Add("Y", GetType(Decimal)) - - Dim GAPointsDT As New DataTable - GAPointsDT.Columns.Add("NAME", GetType(String)) - GAPointsDT.Columns.Add("X", GetType(Decimal)) - GAPointsDT.Columns.Add("Y", GetType(Decimal)) - - ' --- Determine grossArea points ---- - Dim pX(3) As Decimal - Dim pY(3) As Decimal - - Dim columnNum As Integer = (i + Grating_Fill.numOfHorizontal) Mod Grating_Fill.numOfHorizontal - If columnNum <> (Grating_Fill.numOfHorizontal - 1) Then - ' Columnn: alla utom sista - pX(0) = Data.grossAreaPoints.Rows(0)("X") + Grating_Fill.minLength * columnNum / 1000 - pX(1) = pX(0) + Grating_Fill.minLength / 1000 - pX(2) = pX(1) - pX(3) = pX(0) - Else - ' Column: sista - pX(0) = Data.grossAreaPoints.Rows(0)("X") + Grating_Fill.minLength * columnNum / 1000 - pX(1) = Data.grossAreaPoints.Rows(1)("X") - pX(2) = pX(1) - pX(3) = pX(0) - End If - - Dim rowNum As Integer = Math.Floor(i / Grating_Fill.numOfHorizontal) - If rowNum < Grating_Fill.numOfVertical - 2 Then - ' Row: alla utom sista och näst sista - pY(0) = Data.grossAreaPoints.Rows(0)("Y") - Grating_Fill.maxSingleWidth * rowNum / 1000 - pY(1) = pY(0) - pY(2) = pY(0) - Grating_Fill.maxSingleWidth / 1000 - pY(3) = pY(2) - ElseIf rowNum < Grating_Fill.numOfVertical - 1 Then - ' Row: Näst sista - pY(0) = Data.grossAreaPoints.Rows(0)("Y") - Grating_Fill.maxSingleWidth * rowNum / 1000 - pY(1) = pY(0) - If Grating_Fill.widthRevNeeded = True Then - pY(2) = pY(0) - Grating_Fill.revWidth / 1000 - Else - pY(2) = pY(0) - Grating_Fill.maxSingleWidth / 1000 - End If - pY(3) = pY(2) - Else - ' Row: Sista - If Grating_Fill.widthRevNeeded = True Then - pY(0) = Data.grossAreaPoints.Rows(0)("Y") - Grating_Fill.maxSingleWidth * (rowNum - 1) / 1000 - Grating_Fill.revWidth / 1000 - Else - pY(0) = Data.grossAreaPoints.Rows(0)("Y") - Grating_Fill.maxSingleWidth * rowNum / 1000 - End If - pY(1) = pY(0) - pY(2) = Data.grossAreaPoints.Rows(3)("Y") - pY(3) = pY(2) - End If - - For j = 0 To 3 - Dim DR As DataRow = pointsDT.NewRow() - DR("NAME") = "GA_" & j + 1 - 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) + Dim GP As New List(Of Integer()) + Dim p1(1), p2(1), p3(1), p4(1) As Integer + p1(0) = -origo(0) + p2(0) = -origo(0) + gratingDR("LENGTH") + For j = 1 To gratingDR("COLUMN") + p1(0) += Grating_Fill.gratingDimensions.Rows(i - j)("LENGTH") + p2(0) += Grating_Fill.gratingDimensions.Rows(i - j)("LENGTH") + Next + p1(1) = origo(1) + p3(1) = origo(1) - gratingDR("WIDTH") + For j = 1 To gratingDR("ROW") + p1(1) -= Grating_Fill.gratingDimensions.Rows(i - Grating_Fill.numOfHorizontal * j)("WIDTH") + p3(1) -= Grating_Fill.gratingDimensions.Rows(i - Grating_Fill.numOfHorizontal * j)("WIDTH") Next - ' --- Add recess points --- - Dim recessPointsDT As New DataTable - recessPointsDT.Columns.Add("NAME", GetType(String)) - recessPointsDT.Columns.Add("TYPE", GetType(String)) - recessPointsDT.Columns.Add("SIDE", GetType(Integer)) - recessPointsDT.Columns.Add("X", GetType(Decimal)) - recessPointsDT.Columns.Add("Y", GetType(Decimal)) + p2(1) = p1(1) + p3(0) = p1(0) + p4(0) = p2(0) + p4(1) = p3(1) - For j = 1 To 4 - For Each DR As DataRow In Data.gratingPoints.Rows - Dim recessDR As DataRow = recessPointsDT.NewRow() - recessDR("NAME") = DR("NAME") - recessDR("SIDE") = j - recessDR("X") = DR("X") - recessDR("Y") = DR("Y") - Dim pointName As String = DR("NAME") - If pointName.Substring(0, 2) = "CA" Then - recessDR("TYPE") = "Corner Angle" - ElseIf pointName.Substring(0, 2) = "CR" Then - recessDR("TYPE") = "Corner Rectangle" - ElseIf pointName.Substring(0, 2) = "CS" Then - recessDR("TYPE") = "Side Rectangle" - Else - Continue For - End If + GP.Add(p1) + GP.Add(p2) + GP.Add(p3) + GP.Add(p4) - If j = 1 Then - If DR("Y") = pointsDT.Rows(0)("Y") Then - If DR("X") >= pointsDT.Rows(0)("X") AndAlso DR("X") <= pointsDT.Rows(1)("X") Then - recessPointsDT.Rows.Add(recessDR) - End If - End If - ElseIf j = 2 Then - If DR("X") = pointsDT.Rows(1)("X") Then - If DR("Y") <= pointsDT.Rows(1)("Y") AndAlso DR("Y") >= pointsDT.Rows(2)("Y") Then - recessPointsDT.Rows.Add(recessDR) - End If - End If - ElseIf j = 3 Then - If DR("Y") = pointsDT.Rows(2)("Y") Then - If DR("X") <= pointsDT.Rows(2)("X") AndAlso DR("X") >= pointsDT.Rows(3)("X") Then - recessPointsDT.Rows.Add(recessDR) - End If - End If - Else - If DR("X") = pointsDT.Rows(3)("X") Then - If DR("Y") >= pointsDT.Rows(3)("Y") AndAlso DR("Y") <= pointsDT.Rows(0)("Y") Then - recessPointsDT.Rows.Add(recessDR) - End If - End If - End If - Next - Next + Dim cornerAngleCounter As Integer = 1 + Dim cornerRectangleCounter As Integer = 1 + Dim numOfSideRectangles As Integer = 0 + Dim numOfMiddleRectangles As Integer = 0 + For j = 0 To Data.recessData.Rows.Count - 1 + If Data.recessData.Rows(j)("RECESS TYPE") = "ANGLE" Then + Dim RP As New List(Of Integer()) + Dim rec1(1), rec2(1), rec3(1) As Integer - ' --- intersecting recesses --- - For Each DR As DataRow In Data.recessData.Rows - If DR("RECESS TYPE") = "ANGLE" Then - Dim recessName As String = DR("NAME") - Dim recessAlreadyOK As Boolean = False - For Each DR2 As DataRow In recessPointsDT.Rows - Dim pointName As String = DR2("NAME") - If pointName.Substring(0, 3) = recessName Then - recessAlreadyOK = True + rec1(0) = Data.grossAreaPoints.Rows(Data.recessData.Rows(j)("CORNER") - 1)("X") * 1000 + rec1(1) = Data.grossAreaPoints.Rows(Data.recessData.Rows(j)("CORNER") - 1)("Y") * 1000 + + Dim rowIndex As Integer + For k = 0 To Data.gratingPoints.Rows.Count - 1 + If Data.gratingPoints.Rows(k)("NAME") = "CA" & cornerAngleCounter & "_" & 1 Then + rowIndex = k + End If + Next + + rec2(0) = Data.gratingPoints.Rows(rowIndex)("X") * 1000 + rec2(1) = Data.gratingPoints.Rows(rowIndex)("Y") * 1000 + + rec3(0) = Data.gratingPoints.Rows(rowIndex + 1)("X") * 1000 + rec3(1) = Data.gratingPoints.Rows(rowIndex + 1)("Y") * 1000 + + RP.Add(rec1) + RP.Add(rec2) + RP.Add(rec3) + + Dim gratingObsolete As Boolean = True + For k = 0 To 3 + Dim pInTriangle As Boolean = Calculate_Triangle_Bool(GP(k), RP(0), RP(1), RP(2)) + If pInTriangle = False Then + gratingObsolete = False Exit For End If Next - If recessAlreadyOK = True Then - Continue For + If gratingObsolete = True Then + listOfObsolete.Add(i) End If - ' Recess points - Dim p0(1) As Decimal - Dim p1(1) As Decimal - Dim p2(1) As Decimal + cornerAngleCounter += 1 - p0(0) = Data.gratingPoints.Select("NAME = '" & recessName & "_1" & "'")(0)("X") - p0(1) = Data.gratingPoints.Select("NAME = '" & recessName & "_1" & "'")(0)("Y") + ElseIf Data.recessData.Rows(j)("RECESS TYPE") = "SQUARE" OrElse Data.recessData.Rows(j)("RECESS TYPE") = "SIDE SQUARE" _ + OrElse Data.recessData.Rows(j)("RECESS TYPE") = "MIDDLE SQUARE" Then + Dim RP As New List(Of Integer()) + Dim rec1(1), rec2(1), rec3(1), rec4(1) As Integer - p1(0) = Data.gratingPoints.Select("NAME = '" & recessName & "_2" & "'")(0)("X") - p1(1) = Data.gratingPoints.Select("NAME = '" & recessName & "_2" & "'")(0)("Y") - - If DR("CORNER") = 1 OrElse DR("CORNER") = 3 Then - p2(0) = p0(0) - p2(1) = p1(1) - Else - p2(0) = p1(0) - p2(1) = p0(1) + Dim rowIndex As Integer + If Data.recessData.Rows(j)("RECESS TYPE") = "SQUARE" Then + For k = 0 To Data.gratingPoints.Rows.Count - 1 + If Data.gratingPoints.Rows(k)("NAME") = "CR" & cornerRectangleCounter & "_" & 1 Then + rowIndex = k + End If + Next + cornerRectangleCounter += 1 + ElseIf Data.recessData.Rows(j)("RECESS TYPE") = "SIDE SQUARE" Then + For k = 0 To Data.gratingPoints.Rows.Count - 1 + If Data.gratingPoints.Rows(k)("NAME") = "CS" & numOfSideRectangles & "_" & 1 Then + rowIndex = k + End If + Next + numOfSideRectangles += 1 End If - Dim pointsInRecess As New Dictionary(Of String, Boolean) - For Each pDR As DataRow In pointsDT.Rows - Dim gp(1) As Decimal - gp(0) = pDR("X") - gp(1) = pDR("Y") + If Data.recessData.Rows(j)("RECESS TYPE") = "SQUARE" OrElse Data.recessData.Rows(j)("RECESS TYPE") = "SIDE SQUARE" Then + rec1(0) = Data.gratingPoints.Rows(rowIndex)("X") * 1000 + rec1(1) = Data.gratingPoints.Rows(rowIndex)("Y") * 1000 - pointsInRecess.Add(pDR("NAME"), Calculate_Triangle_Bool(gp, p0, p1, p2)) - Next + rec2(0) = Data.gratingPoints.Rows(rowIndex + 1)("X") * 1000 + rec2(1) = Data.gratingPoints.Rows(rowIndex + 1)("Y") * 1000 - Dim numOfPInRec As Integer = 0 - For Each bool As Boolean In pointsInRecess.Values - If bool = True Then - numOfPInRec += 1 + rec3(0) = Data.gratingPoints.Rows(rowIndex + 2)("X") * 1000 + rec3(1) = Data.gratingPoints.Rows(rowIndex + 2)("Y") * 1000 + + If Data.recessData.Rows(j)("RECESS TYPE") = "SQUARE" Then + rec4(0) = Data.grossAreaPoints.Rows(Data.recessData.Rows(j)("CORNER") - 1)("X") * 1000 + rec4(1) = Data.grossAreaPoints.Rows(Data.recessData.Rows(j)("CORNER") - 1)("Y") * 1000 + ElseIf Data.recessData.Rows(j)("RECESS TYPE") = "SIDE SQUARE" Then + rec4(0) = Data.gratingPoints.Rows(rowIndex + 3)("X") * 1000 + rec4(1) = Data.gratingPoints.Rows(rowIndex + 3)("Y") * 1000 + + End If + + ElseIf Data.recessData.Rows(j)("RECESS TYPE") = "MIDDLE SQUARE" Then + numOfMiddleRectangles += 1 + + rec1(0) = Data.gratingMiddlePoints.Rows(numOfMiddleRectangles * 4 - 4)("X") * 1000 + rec1(1) = Data.gratingMiddlePoints.Rows(numOfMiddleRectangles * 4 - 4)("Y") * 1000 + + rec2(0) = Data.gratingMiddlePoints.Rows(numOfMiddleRectangles * 4 - 3)("X") * 1000 + rec2(1) = Data.gratingMiddlePoints.Rows(numOfMiddleRectangles * 4 - 3)("Y") * 1000 + + rec3(0) = Data.gratingMiddlePoints.Rows(numOfMiddleRectangles * 4 - 2)("X") * 1000 + rec3(1) = Data.gratingMiddlePoints.Rows(numOfMiddleRectangles * 4 - 2)("Y") * 1000 + + rec4(0) = Data.gratingMiddlePoints.Rows(numOfMiddleRectangles * 4 - 1)("X") * 1000 + rec4(1) = Data.gratingMiddlePoints.Rows(numOfMiddleRectangles * 4 - 1)("Y") * 1000 + End If + + RP.Add(rec1) + RP.Add(rec2) + RP.Add(rec3) + RP.Add(rec4) + + Dim gratingObsolete As Boolean = True + For k = 0 To 3 + Dim pInSquare As Boolean = Calculate_Square_Bool(GP(k), RP(0), RP(1), RP(2), RP(3)) + If pInSquare = False Then + gratingObsolete = False + Exit For End If Next - - If numOfPInRec = 0 OrElse numOfPInRec = 4 Then - Continue For + If gratingObsolete = True Then + listOfObsolete.Add(i) End If - ' - Straight line equation: y = kx + m - Dim k As Decimal = (p1(1) - p0(1)) / (p1(0) - p0(0)) - Dim m As Decimal = p0(1) - (k * p0(0)) - - Dim npDR As DataRow - - Dim x1 As Decimal = (GAPointsDT.Rows(0)("Y") - m) / k - If x1 > GAPointsDT.Rows(0)("X") AndAlso x1 < GAPointsDT.Rows(1)("X") Then - ' lägg till på sida 1 - npDR = pointsDT.NewRow() - npDR("NAME") = recessName & "_1" ' fixa - npDR("TYPE") = "Recess CA" - npDR("X") = x1 - npDR("Y") = GAPointsDT.Rows(0)("Y") - - Dim inIndex As Integer = Get_RowIndex(pointsDT, 1, npDR("X"), npDR("Y"), GAPointsDT) - - pointsDT.Rows.InsertAt(npDR, inIndex + 1) - End If - - Dim y2 As Decimal = k * GAPointsDT.Rows(1)("X") + m - If y2 < GAPointsDT.Rows(1)("Y") AndAlso y2 > GAPointsDT.Rows(2)("Y") Then - ' lägg till på sida 2 - npDR = pointsDT.NewRow() - npDR("NAME") = recessName & "_2" ' fixa - npDR("TYPE") = "Recess CA" - npDR("X") = GAPointsDT.Rows(1)("X") - npDR("Y") = y2 - - Dim inIndex As Integer = Get_RowIndex(pointsDT, 2, npDR("X"), npDR("Y"), GAPointsDT) - - pointsDT.Rows.InsertAt(npDR, inIndex + 1) - End If - - Dim x3 As Decimal = (GAPointsDT.Rows(2)("Y") - m) / k - If x3 < GAPointsDT.Rows(2)("X") AndAlso x3 > GAPointsDT.Rows(3)("X") Then - ' lägg till på sida 3 - npDR = pointsDT.NewRow() - npDR("NAME") = recessName & "_3" ' fixa - npDR("TYPE") = "Recess CA" - npDR("X") = x3 - npDR("Y") = GAPointsDT.Rows(2)("Y") - - Dim inIndex As Integer = Get_RowIndex(pointsDT, 3, npDR("X"), npDR("Y"), GAPointsDT) - - pointsDT.Rows.InsertAt(npDR, inIndex + 1) - End If - - Dim y4 As Decimal = k * GAPointsDT.Rows(3)("X") + m - If y4 > GAPointsDT.Rows(3)("Y") AndAlso y4 < GAPointsDT.Rows(0)("Y") Then - ' lägg till på sida 4 - npDR = pointsDT.NewRow() - npDR("NAME") = recessName & "_4" ' fixa - npDR("TYPE") = "Recess CA" - npDR("X") = GAPointsDT.Rows(3)("X") - npDR("Y") = y4 - - Dim inIndex As Integer = Get_RowIndex(pointsDT, 4, npDR("X"), npDR("Y"), GAPointsDT) - - pointsDT.Rows.InsertAt(npDR, inIndex + 1) - End If - - For Each key As String In pointsInRecess.Keys - If pointsInRecess(key) = True Then - Dim removeIndex As Integer = 0 - For k = 0 To pointsDT.Rows.Count - 1 - If pointsDT.Rows(k)("NAME") = key Then - removeIndex = k - End If - Next - pointsDT.Rows.RemoveAt(removeIndex) - End If - Next End If + Next - - ' --- Point on grating side - recesses --- - For Each DR As DataRow In recessPointsDT.Rows - If DR("TYPE") = "Corner Angle" Then - Dim pointName As String = DR("NAME") - If pointName.Split("_")(1) = 1 Then - 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 + 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 Decimal - Dim pointNumGA As Integer = DR("SIDE") + 2 - If pointNumGA > 4 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, "") - 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) - - Dim temp As String = pointsDT.Rows(index)("NAME") - If temp.Substring(0, 2) = "GA" Then - pointsDT.Rows.RemoveAt(index) - End If - - Dim cornerPoint(1) As Decimal - 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, "GA_" & pointNumGA) - End If - End If - Next - - pointsDT.TableName = "Grating " & i & " - C" & columnNum & " R" & rowNum - pointsDS.Tables.Add(pointsDT) Next - - Return pointsDS + Return listOfObsolete End Function - Private Shared Function Get_RowIndex(pDT As DataTable, side As Integer, pX As Decimal, pY As Decimal, GApDT As DataTable) + Private Shared Function Calculate_Triangle_Bool(gp As Integer(), p0 As Integer(), p1 As Integer(), p2 As Integer()) - Dim rowName As String = "" - Dim newX As Decimal = pX - Dim newY As Decimal = pY - - If side = 1 Then - Dim sidePoints = pDT.Select("Y = '" & pY & "'") - If sidePoints.Length = 0 Then - newX = GApDT.Select("NAME = 'GA_1'")(0)("X") - End If - 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 - ElseIf side = 2 Then - Dim sidePoints = pDT.Select("X = '" & pX & "'") - If sidePoints.Length = 0 Then - newY = GApDT.Select("NAME = 'GA_2'")(0)("Y") - End If - For Each DR2 As DataRow In sidePoints - If DR2("Y") > pY Then - rowName = DR2("NAME") - Else - newY = GApDT.Select("NAME = 'GA_2'")(0)("Y") - Exit For - End If - Next - ElseIf side = 3 Then - Dim sidePoints = pDT.Select("Y = '" & pY & "'") - If sidePoints.Length = 0 Then - newX = GApDT.Select("NAME = 'GA_3'")(0)("X") - End If - For Each DR2 As DataRow In sidePoints - If DR2("X") > pX Then - rowName = DR2("NAME") - Else - newX = GApDT.Select("NAME = 'GA_3'")(0)("X") - Exit For - End If - Next - Else - Dim sidePoints = pDT.Select("X = '" & pX & "'") - If sidePoints.Length = 0 Then - newY = GApDT.Select("NAME = 'GA_4'")(0)("Y") - Else - If sidePoints(0)("NAME") = "GA_1" Then - Dim pointList As New List(Of DataRow) - For i = 1 To sidePoints.Length - 1 - pointList.Add(sidePoints(i)) - Next - pointList.Add(sidePoints(0)) - - For Each DR2 As DataRow In pointList - If DR2("Y") < pY Then - rowName = DR2("NAME") - Else - newY = GApDT.Select("NAME = 'GA_4'")(0)("Y") - Exit For - End If - Next - Else - For Each DR2 As DataRow In sidePoints - If DR2("Y") < pY Then - rowName = DR2("NAME") - Else - newY = GApDT.Select("NAME = 'GA_4'")(0)("Y") - Exit For - End If - Next - End If - End If - End If - - Dim index As Integer = 0 - If rowName = "" Then - Dim newSide As Integer = side - 1 - If newSide = 0 Then - newSide = 4 - End If - index = Get_RowIndex(pDT, newSide, 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 Decimal(), GApDT As DataTable, rDT As DataTable, pNameToRemove As String) - Dim p0(1) As Decimal - Dim p1(1) As Decimal - Dim p2(1) As Decimal - - Dim newDR As DataRow = pDT.NewRow - newDR("TYPE") = "Recess CA" - - Dim side As Integer = 0 - Dim pointName As String = rpDR("NAME") - If pointName.Split("_")(1) = 1 Then - Dim DR = Data.gratingPoints.Select("NAME = '" & pointName.Split("_")(0) & "_2" & "'") - newDR("NAME") = pointName.Split("_")(0) & "_2" - - p0(0) = rpDR("X") - p0(1) = rpDR("Y") - - p2(0) = DR(0)("X") - p2(1) = DR(0)("Y") - - If rpDR("SIDE") + 1 > 4 Then - side = rpDR("SIDE") + 1 - 4 - Else - side = rpDR("SIDE") + 1 - End If - Else - Dim DR = Data.gratingPoints.Select("NAME = '" & pointName.Split("_")(0) & "_1" & "'") - newDR("NAME") = pointName.Split("_")(0) & "_1" - - p0(0) = rpDR("X") - p0(1) = rpDR("Y") - - p2(0) = DR(0)("X") - p2(1) = DR(0)("Y") - - If rpDR("SIDE") - 1 < 1 Then - side = rpDR("SIDE") - 1 + 4 - Else - side = rpDR("SIDE") - 1 - End If - End If - - For Each rDR As DataRow In rDT.Rows - If rDR("NAME") = newDR("NAME") Then - Exit Sub - End If - Next - - If rpDR("SIDE") = 1 OrElse rpDR("SIDE") = 3 Then - p1(0) = p2(0) - p1(1) = p0(1) - ElseIf rpDR("SIDE") = 2 OrElse rpDR("SIDE") = 4 Then - p1(0) = p0(0) - p1(1) = p2(1) - End If - - Dim gpInside As Boolean = Calculate_Triangle_Bool(gp, p0, p1, p2) - - Dim insertIndex As Integer = 0 - If gpInside = False Then - ' If false => new point at side rpDR("SIDE")+1 - If side = 1 Then - Dim c As Decimal = GApDT.Select("NAME = 'GA_1'")(0)("Y") - rpDR("Y") - Dim z As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - rpDR("Y") - Dim x As Decimal = 0 - If pointName.Split("_")(1) = 1 Then - x = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_1'")(0)("X") - newDR("X") = GApDT.Select("NAME = 'GA_1'")(0)("X") + c * x / z ' Triangle likformighet - Else - x = GApDT.Select("NAME = 'GA_2'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - newDR("X") = GApDT.Select("NAME = 'GA_2'")(0)("X") - c * x / z ' Triangle likformighet - End If - newDR("Y") = GApDT.Select("NAME = 'GA_1'")(0)("Y") - ElseIf side = 2 Then - Dim c As Decimal = GApDT.Select("NAME = 'GA_2'")(0)("X") - rpDR("X") - Dim z As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - rpDR("X") - Dim x As Decimal = 0 - If pointName.Split("_")(1) = 1 Then - x = GApDT.Select("NAME = 'GA_2'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - newDR("Y") = GApDT.Select("NAME = 'GA_2'")(0)("Y") - c * x / z ' Triangle likformighet - Else - x = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_3'")(0)("Y") - newDR("Y") = GApDT.Select("NAME = 'GA_3'")(0)("Y") + c * x / z ' Triangle likformighet - End If - newDR("X") = GApDT.Select("NAME = 'GA_2'")(0)("X") - ElseIf side = 3 Then - Dim c As Decimal = rpDR("Y") - GApDT.Select("NAME = 'GA_3'")(0)("Y") - Dim z As Decimal = rpDR("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - Dim x As Decimal = 0 - If pointName.Split("_")(1) = 1 Then - x = GApDT.Select("NAME = 'GA_3'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - newDR("X") = GApDT.Select("NAME = 'GA_3'")(0)("X") - c * x / z ' Triangle likformighet - Else - x = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_4'")(0)("X") - newDR("X") = GApDT.Select("NAME = 'GA_4'")(0)("X") + c * x / z ' Triangle likformighet - End If - newDR("Y") = GApDT.Select("NAME = 'GA_3'")(0)("Y") - Else - Dim c As Decimal = rpDR("X") - GApDT.Select("NAME = 'GA_4'")(0)("X") - Dim z As Decimal = rpDR("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - Dim x As Decimal = 0 - If pointName.Split("_")(1) = 1 Then - x = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_4'")(0)("Y") - newDR("Y") = GApDT.Select("NAME = 'GA_4'")(0)("Y") + c * x / z ' Triangle likformighet - Else - x = GApDT.Select("NAME = 'GA_1'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - newDR("Y") = GApDT.Select("NAME = 'GA_1'")(0)("Y") - c * x / z ' Triangle likformighet - End If - newDR("X") = GApDT.Select("NAME = 'GA_4'")(0)("X") - End If - - newDR("X") = Math.Round(newDR("X"), 3) - newDR("Y") = Math.Round(newDR("Y"), 3) - - 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 temp As String = newDR("NAME") - If temp.Split("_")(1) = 1 Then - If side = 1 Then - side = 4 - Else - side -= 1 - End If - Else - If side = 4 Then - side = 1 - Else - side += 1 - End If - End If - - If side = 1 Then - Dim x As Decimal = rpDR("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - Dim y As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - rpDR("Y") - Dim b As Decimal = 0 - If pointName.Split("_")(1) = 1 Then - b = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_1'")(0)("Y") - newDR("X") = GApDT.Select("NAME = 'GA_1'")(0)("X") + x * b / y - (GApDT.Select("NAME = 'GA_1'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X")) ' Triangle likformighet - Else - b = GApDT.Select("NAME = 'GA_2'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - newDR("X") = GApDT.Select("NAME = 'GA_2'")(0)("X") - x * b / y + (Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_2'")(0)("X")) ' Triangle likformighet - End If - newDR("Y") = GApDT.Select("NAME = 'GA_1'")(0)("Y") - ElseIf side = 2 Then - Dim x As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - rpDR("Y") - Dim y As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - rpDR("X") - Dim b As Decimal = 0 - If pointName.Split("_")(1) = 1 Then - b = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_2'")(0)("X") - newDR("Y") = GApDT.Select("NAME = 'GA_2'")(0)("Y") - x * b / y + (Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_2'")(0)("Y")) - Else - b = GApDT.Select("NAME = 'GA_3'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - newDR("Y") = GApDT.Select("NAME = 'GA_3'")(0)("Y") + x * b / y - (GApDT.Select("NAME = 'GA_3'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y")) - End If - newDR("X") = GApDT.Select("NAME = 'GA_2'")(0)("X") - ElseIf side = 3 Then - Dim x As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - rpDR("X") - Dim y As Decimal = rpDR("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - Dim b As Decimal = 0 - If pointName.Split("_")(1) = 1 Then - b = GApDT.Select("NAME = 'GA_3'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - newDR("X") = GApDT.Select("NAME = 'GA_3'")(0)("X") - x * b / y + (Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_3'")(0)("X")) - Else - b = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_4'")(0)("Y") - newDR("X") = GApDT.Select("NAME = 'GA_4'")(0)("X") + x * b / y - (GApDT.Select("NAME = 'GA_4'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X")) - End If - newDR("Y") = GApDT.Select("NAME = 'GA_3'")(0)("Y") - Else - Dim x As Decimal = rpDR("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - Dim y As Decimal = rpDR("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - Dim b As Decimal = 0 - If pointName.Split("_")(1) = 1 Then - b = GApDT.Select("NAME = 'GA_4'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - newDR("Y") = GApDT.Select("NAME = 'GA_4'")(0)("Y") + x * b / y - (GApDT.Select("NAME = 'GA_4'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y")) - Else - b = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_1'")(0)("X") - newDR("Y") = GApDT.Select("NAME = 'GA_1'")(0)("Y") - x * b / y + (Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_1'")(0)("Y")) - End If - newDR("X") = GApDT.Select("NAME = 'GA_4'")(0)("X") - End If - - insertIndex = Get_RowIndex(pDT, side, newDR("X"), newDR("Y"), GApDT) - - pDT.Rows.InsertAt(newDR, insertIndex + 1) - - Dim removeIndex As Integer = 0 - For k = 0 To pDT.Rows.Count - 1 - If pDT.Rows(k)("NAME") = pNameToRemove Then - removeIndex = k - End If - Next - - pDT.Rows.RemoveAt(removeIndex) - End If - End Sub - - Private Shared Function Calculate_Triangle_Bool(gp As Decimal(), p0 As Decimal(), p1 As Decimal(), p2 As Decimal()) - - Dim s As Decimal = p0(1) * p2(0) - p0(0) * p2(1) + (p2(1) - p0(1)) * gp(0) + (p0(0) - p2(0)) * gp(1) - Dim t As Decimal = p0(0) * p1(1) - p0(1) * p1(0) + (p0(1) - p1(1)) * gp(0) + (p1(0) - p0(0)) * gp(1) + Dim s As Double = p0(1) * p2(0) - p0(0) * p2(1) + (p2(1) - p0(1)) * gp(0) + (p0(0) - p2(0)) * gp(1) + Dim t As Double = p0(0) * p1(1) - p0(1) * p1(0) + (p0(1) - p1(1)) * gp(0) + (p1(0) - p0(0)) * gp(1) If (s < 0 AndAlso t >= 0) OrElse (s >= 0 AndAlso t < 0) Then Return False End If - Dim area As Decimal = -p1(1) * p2(0) + p0(1) * (p2(0) - p1(0)) + p0(0) * (p1(1) - p2(1)) + p1(0) * p2(1) + Dim area As Double = -p1(1) * p2(0) + p0(1) * (p2(0) - p1(0)) + p0(0) * (p1(1) - p2(1)) + p1(0) * p2(1) If area < 0 Then If s <= 0 AndAlso s + t >= area Then @@ -783,4 +557,79 @@ Public Class Multiple_Drawing End If End If End Function + + Private Shared Function Calculate_Square_Bool(gp As Integer(), p0 As Integer(), p1 As Integer(), p2 As Integer(), p3 As Integer()) + Dim squareArea As Double = Math.Abs(p0(0) - p1(0)) * Math.Abs(p1(1) - p2(1)) + If squareArea = 0 Then + squareArea = Math.Abs(p0(1) - p1(1)) * Math.Abs(p1(0) - p2(0)) + End If + + Dim area1 As Double = Math.Abs(gp(0) * p0(1) + gp(1) * p1(0) + p0(0) * p1(1) - p0(1) * p1(0) - gp(1) * p0(0) - gp(0) * p1(1)) / 2 + Dim area2 As Double = Math.Abs(gp(0) * p1(1) + gp(1) * p2(0) + p1(0) * p2(1) - p1(1) * p2(0) - gp(1) * p1(0) - gp(0) * p2(1)) / 2 + Dim area3 As Double = Math.Abs(gp(0) * p2(1) + gp(1) * p3(0) + p2(0) * p3(1) - p2(1) * p3(0) - gp(1) * p2(0) - gp(0) * p3(1)) / 2 + Dim area4 As Double = Math.Abs(gp(0) * p3(1) + gp(1) * p0(0) + p3(0) * p0(1) - p3(1) * p0(0) - gp(1) * p3(0) - gp(0) * p0(1)) / 2 + Dim compArea As Double = area1 + area2 + area3 + area4 + + If compArea > squareArea Then + Return False + Else + Return True + End If + End Function + + Private Shared Function Check_Interference(comp1 As SldWorks.Component2, comp2 As SldWorks.Component2, comp1Name As String) + + Dim swApp As SldWorks.SldWorks + Dim swModel As SldWorks.ModelDoc2 + Dim swAssy As SldWorks.AssemblyDoc + Dim CompArray(1) As SldWorks.Component2 + Dim vCompArray + Dim vIntCompArray + Dim vIntFaceArray + + Dim interfering + + swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks.SldWorks) + swModel = swApp.ActiveDoc + swAssy = swModel + + CompArray(0) = comp1 + CompArray(1) = comp2 + + vCompArray = CompArray + swAssy.ToolsCheckInterference2(2, (vCompArray), interfering, vIntCompArray, vIntFaceArray) + + Dim Bodies(UBound(vIntFaceArray)) As Object + Dim BodyNames(UBound(vIntFaceArray)) As String + Dim CompNames(UBound(vIntFaceArray)) As String + + For i = 0 To UBound(vIntFaceArray) + + Bodies(i) = vIntFaceArray(i).GetBody + BodyNames(i) = Bodies(i).Name + CompNames(i) = vIntCompArray(i).Name2 + + Next + + Dim bodiesToCutList As New List(Of Object) + + If CompNames(0) = comp1Name Then + bodiesToCutList.Add(Bodies(0)) + End If + For i = 1 To CompNames.Length - 1 + If CompNames(i) <> comp1Name Then + Exit For + ElseIf BodyNames(i) <> BodyNames(i - 1) Then + bodiesToCutList.Add(Bodies(i)) + End If + Next + + Dim bodiesToCut() As Object + bodiesToCut = bodiesToCutList.ToArray() + + Return bodiesToCut + + End Function + + End Class diff --git a/Wardrobe/SolidWorks/Multiple_Drawing2.vb b/Wardrobe/SolidWorks/Multiple_Drawing2.vb new file mode 100644 index 0000000..226bc04 --- /dev/null +++ b/Wardrobe/SolidWorks/Multiple_Drawing2.vb @@ -0,0 +1,786 @@ +Imports SldWorks +Public Class Multiple_Drawing2 + + Public Shared Sub Create_Models_For_Drawing() + Dim gratingsPointsDS As DataSet = Create_GratingPoints() + + Dim gratingHeight As Decimal = User_Input.gratingHeight / 1000 + + Dim swApp As SldWorks.SldWorks + swApp = CType(System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application"), SldWorks.SldWorks) + Dim Model As ModelDoc2 + Dim RootPoint(2) As Decimal + Dim Normal(2) As Decimal + swApp.UserControl = True + + Dim swSkMgr As SketchManager + Dim longstatus As Integer + Dim boolstatus As Boolean + Dim swModelDocExtension As ModelDocExtension + Dim status As Boolean + Dim swFeatureMgr As FeatureManager + Dim swFeature As Feature + Dim iPart As PartDoc + + Dim numOfGratings As Integer = Grating_Fill.numOfVertical * Grating_Fill.numOfHorizontal + + For i = 0 To numOfGratings - 1 + Model = swApp.NewDocument("C:\ProgramData\SOLIDWORKS\SOLIDWORKS 2020\templates\part.prtdot", 0, 0, 0) + + swSkMgr = Model.SketchManager + swSkMgr.InsertSketch(True) + boolstatus = Model.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0) + Model.ClearSelection2(True) + + For Each DR As DataRow In gratingsPointsDS.Tables(i).Rows + Dim skPoint As SketchPoint + Dim pX = DR("X") + Dim pY = DR("Y") + skPoint = swSkMgr.CreatePoint(pX, pY, 0) + Next + + For Each DR1 As DataRow In gratingsPointsDS.Tables(i).Rows + Dim skLine As SketchLine + Dim rowIndex = gratingsPointsDS.Tables(i).Rows.IndexOf(DR1) + Dim DR2 As DataRow + + Try + DR2 = gratingsPointsDS.Tables(i).Rows(rowIndex + 1) + Catch ex As Exception + DR2 = gratingsPointsDS.Tables(i).Rows(0) + End Try + + Dim pX1 = DR1("X") + Dim pY1 = DR1("Y") + Dim pX2 = DR2("X") + Dim pY2 = DR2("Y") + + skLine = swSkMgr.CreateLine(pX1, pY1, 0, pX2, pY2, 0) + Next + + swSkMgr.InsertSketch(True) + + swModelDocExtension = Model.Extension + status = swModelDocExtension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0) + + swFeatureMgr = Model.FeatureManager + swFeature = swFeatureMgr.FeatureExtrusion3(True, False, False, 0, 0, gratingHeight, 0, False, False, False, False, 0, 0, False, False, False, False, True, True, True, 0, 0, False) + + + ' MIddle points if needed + + + Model.ClearSelection2(True) + boolstatus = Model.Extension.SelectByID2("Front Plane", "PLANE", 0, 0, 0, False, 0, Nothing, 0) + Model.FeatureManager.InsertRefPlane(8, gratingHeight, 0, 0, 0, 0) + + iPart = swApp.ActiveDoc + Dim newName As String + newName = Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw_support") & "\simplified_grating_" & i + 1 & ".SLDPRT" + + + ' Title head data + + + longstatus = iPart.SaveAs3(newName, 0, 0) + swApp.CloseDoc(newName) + Next + + ' --- Assembly --- + Dim assembly As IAssemblyDoc + Dim AssemblyExtension As SldWorks.ModelDocExtension + Model = swApp.NewDocument("C:\ProgramData\SolidWorks\SOLIDWORKS 2020\templates\Assembly.asmdot", 0, 0, 0) + assembly = Model + AssemblyExtension = assembly.Extension + + Dim compNames(numOfGratings - 1) As String + Dim coordNames(numOfGratings - 1) As String + Dim transMatrix As Object = Nothing + For i = 0 To numOfGratings - 1 + compNames(i) = Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw_support") & "\simplified_grating_" & i + 1 & ".SLDPRT" + coordNames(i) = "" + Next + + Dim assemComps As Object + assemComps = assembly.AddComponents3((compNames), (transMatrix), (coordNames)) + + Model.ViewZoomtofit2() + longstatus = Model.SaveAs3(Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw_support") & "\simplified_grating_assembly.SLDASM", 0, 0) + + ' --- Delete Obsolete --- + Dim listOfObsolete As List(Of Integer) + listOfObsolete = Multiple_3D.Find_Obsolete() + + For i = 0 To listOfObsolete.Count - 1 + assembly.ClearSelection2(True) + boolstatus = AssemblyExtension.SelectByID2("simplified_grating_" & listOfObsolete(i) & "-1@simplified_grating_assembly", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0) + assembly.EditDelete + + My.Computer.FileSystem.DeleteFile(Settings.folderPaths("object_" & Data.objectNum & "_models3D_gratings_sw_support") & "\simplified_grating_" & listOfObsolete(i) & ".SLDPRT") + Next + + Dim swErrors As Integer + Dim swWarnings As Integer + boolstatus = assembly.Save3(1, swErrors, swWarnings) + End Sub + + Private Shared Function Create_GratingPoints() + Dim pointsDS As New DataSet + + Dim numOfGratings As Integer = Grating_Fill.numOfVertical * Grating_Fill.numOfHorizontal + + For i = 0 To numOfGratings - 1 + Dim pointsDT As New DataTable + pointsDT.Columns.Add("NAME", GetType(String)) + pointsDT.Columns.Add("TYPE", GetType(String)) + pointsDT.Columns.Add("X", GetType(Decimal)) + pointsDT.Columns.Add("Y", GetType(Decimal)) + + Dim GAPointsDT As New DataTable + GAPointsDT.Columns.Add("NAME", GetType(String)) + GAPointsDT.Columns.Add("X", GetType(Decimal)) + GAPointsDT.Columns.Add("Y", GetType(Decimal)) + + ' --- Determine grossArea points ---- + Dim pX(3) As Decimal + Dim pY(3) As Decimal + + Dim columnNum As Integer = (i + Grating_Fill.numOfHorizontal) Mod Grating_Fill.numOfHorizontal + If columnNum <> (Grating_Fill.numOfHorizontal - 1) Then + ' Columnn: alla utom sista + pX(0) = Data.grossAreaPoints.Rows(0)("X") + Grating_Fill.minLength * columnNum / 1000 + pX(1) = pX(0) + Grating_Fill.minLength / 1000 + pX(2) = pX(1) + pX(3) = pX(0) + Else + ' Column: sista + pX(0) = Data.grossAreaPoints.Rows(0)("X") + Grating_Fill.minLength * columnNum / 1000 + pX(1) = Data.grossAreaPoints.Rows(1)("X") + pX(2) = pX(1) + pX(3) = pX(0) + End If + + Dim rowNum As Integer = Math.Floor(i / Grating_Fill.numOfHorizontal) + If rowNum < Grating_Fill.numOfVertical - 2 Then + ' Row: alla utom sista och näst sista + pY(0) = Data.grossAreaPoints.Rows(0)("Y") - Grating_Fill.maxSingleWidth * rowNum / 1000 + pY(1) = pY(0) + pY(2) = pY(0) - Grating_Fill.maxSingleWidth / 1000 + pY(3) = pY(2) + ElseIf rowNum < Grating_Fill.numOfVertical - 1 Then + ' Row: Näst sista + pY(0) = Data.grossAreaPoints.Rows(0)("Y") - Grating_Fill.maxSingleWidth * rowNum / 1000 + pY(1) = pY(0) + If Grating_Fill.widthRevNeeded = True Then + pY(2) = pY(0) - Grating_Fill.revWidth / 1000 + Else + pY(2) = pY(0) - Grating_Fill.maxSingleWidth / 1000 + End If + pY(3) = pY(2) + Else + ' Row: Sista + If Grating_Fill.widthRevNeeded = True Then + pY(0) = Data.grossAreaPoints.Rows(0)("Y") - Grating_Fill.maxSingleWidth * (rowNum - 1) / 1000 - Grating_Fill.revWidth / 1000 + Else + pY(0) = Data.grossAreaPoints.Rows(0)("Y") - Grating_Fill.maxSingleWidth * rowNum / 1000 + End If + pY(1) = pY(0) + pY(2) = Data.grossAreaPoints.Rows(3)("Y") + pY(3) = pY(2) + End If + + For j = 0 To 3 + Dim DR As DataRow = pointsDT.NewRow() + DR("NAME") = "GA_" & j + 1 + 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 --- + Dim recessPointsDT As New DataTable + recessPointsDT.Columns.Add("NAME", GetType(String)) + recessPointsDT.Columns.Add("TYPE", GetType(String)) + recessPointsDT.Columns.Add("SIDE", GetType(Integer)) + recessPointsDT.Columns.Add("X", GetType(Decimal)) + recessPointsDT.Columns.Add("Y", GetType(Decimal)) + + For j = 1 To 4 + For Each DR As DataRow In Data.gratingPoints.Rows + Dim recessDR As DataRow = recessPointsDT.NewRow() + recessDR("NAME") = DR("NAME") + recessDR("SIDE") = j + recessDR("X") = DR("X") + recessDR("Y") = DR("Y") + Dim pointName As String = DR("NAME") + If pointName.Substring(0, 2) = "CA" Then + recessDR("TYPE") = "Corner Angle" + ElseIf pointName.Substring(0, 2) = "CR" Then + recessDR("TYPE") = "Corner Rectangle" + ElseIf pointName.Substring(0, 2) = "CS" Then + recessDR("TYPE") = "Side Rectangle" + Else + Continue For + End If + + If j = 1 Then + If DR("Y") = pointsDT.Rows(0)("Y") Then + If DR("X") >= pointsDT.Rows(0)("X") AndAlso DR("X") <= pointsDT.Rows(1)("X") Then + recessPointsDT.Rows.Add(recessDR) + End If + End If + ElseIf j = 2 Then + If DR("X") = pointsDT.Rows(1)("X") Then + If DR("Y") <= pointsDT.Rows(1)("Y") AndAlso DR("Y") >= pointsDT.Rows(2)("Y") Then + recessPointsDT.Rows.Add(recessDR) + End If + End If + ElseIf j = 3 Then + If DR("Y") = pointsDT.Rows(2)("Y") Then + If DR("X") <= pointsDT.Rows(2)("X") AndAlso DR("X") >= pointsDT.Rows(3)("X") Then + recessPointsDT.Rows.Add(recessDR) + End If + End If + Else + If DR("X") = pointsDT.Rows(3)("X") Then + If DR("Y") >= pointsDT.Rows(3)("Y") AndAlso DR("Y") <= pointsDT.Rows(0)("Y") Then + recessPointsDT.Rows.Add(recessDR) + End If + End If + End If + Next + Next + + ' --- intersecting recesses --- + For Each DR As DataRow In Data.recessData.Rows + If DR("RECESS TYPE") = "ANGLE" Then + Dim recessName As String = DR("NAME") + Dim recessAlreadyOK As Boolean = False + For Each DR2 As DataRow In recessPointsDT.Rows + Dim pointName As String = DR2("NAME") + If pointName.Substring(0, 3) = recessName Then + recessAlreadyOK = True + Exit For + End If + Next + If recessAlreadyOK = True Then + Continue For + End If + + ' Recess points + Dim p0(1) As Decimal + Dim p1(1) As Decimal + Dim p2(1) As Decimal + + p0(0) = Data.gratingPoints.Select("NAME = '" & recessName & "_1" & "'")(0)("X") + p0(1) = Data.gratingPoints.Select("NAME = '" & recessName & "_1" & "'")(0)("Y") + + p1(0) = Data.gratingPoints.Select("NAME = '" & recessName & "_2" & "'")(0)("X") + p1(1) = Data.gratingPoints.Select("NAME = '" & recessName & "_2" & "'")(0)("Y") + + If DR("CORNER") = 1 OrElse DR("CORNER") = 3 Then + p2(0) = p0(0) + p2(1) = p1(1) + Else + p2(0) = p1(0) + p2(1) = p0(1) + End If + + Dim pointsInRecess As New Dictionary(Of String, Boolean) + For Each pDR As DataRow In pointsDT.Rows + Dim gp(1) As Decimal + gp(0) = pDR("X") + gp(1) = pDR("Y") + + pointsInRecess.Add(pDR("NAME"), Calculate_Triangle_Bool(gp, p0, p1, p2)) + Next + + Dim numOfPInRec As Integer = 0 + For Each bool As Boolean In pointsInRecess.Values + If bool = True Then + numOfPInRec += 1 + End If + Next + + If numOfPInRec = 0 OrElse numOfPInRec = 4 Then + Continue For + End If + + ' - Straight line equation: y = kx + m + Dim k As Decimal = (p1(1) - p0(1)) / (p1(0) - p0(0)) + Dim m As Decimal = p0(1) - (k * p0(0)) + + Dim npDR As DataRow + + Dim x1 As Decimal = (GAPointsDT.Rows(0)("Y") - m) / k + If x1 > GAPointsDT.Rows(0)("X") AndAlso x1 < GAPointsDT.Rows(1)("X") Then + ' lägg till på sida 1 + npDR = pointsDT.NewRow() + npDR("NAME") = recessName & "_1" ' fixa + npDR("TYPE") = "Recess CA" + npDR("X") = x1 + npDR("Y") = GAPointsDT.Rows(0)("Y") + + Dim inIndex As Integer = Get_RowIndex(pointsDT, 1, npDR("X"), npDR("Y"), GAPointsDT) + + pointsDT.Rows.InsertAt(npDR, inIndex + 1) + End If + + Dim y2 As Decimal = k * GAPointsDT.Rows(1)("X") + m + If y2 < GAPointsDT.Rows(1)("Y") AndAlso y2 > GAPointsDT.Rows(2)("Y") Then + ' lägg till på sida 2 + npDR = pointsDT.NewRow() + npDR("NAME") = recessName & "_2" ' fixa + npDR("TYPE") = "Recess CA" + npDR("X") = GAPointsDT.Rows(1)("X") + npDR("Y") = y2 + + Dim inIndex As Integer = Get_RowIndex(pointsDT, 2, npDR("X"), npDR("Y"), GAPointsDT) + + pointsDT.Rows.InsertAt(npDR, inIndex + 1) + End If + + Dim x3 As Decimal = (GAPointsDT.Rows(2)("Y") - m) / k + If x3 < GAPointsDT.Rows(2)("X") AndAlso x3 > GAPointsDT.Rows(3)("X") Then + ' lägg till på sida 3 + npDR = pointsDT.NewRow() + npDR("NAME") = recessName & "_3" ' fixa + npDR("TYPE") = "Recess CA" + npDR("X") = x3 + npDR("Y") = GAPointsDT.Rows(2)("Y") + + Dim inIndex As Integer = Get_RowIndex(pointsDT, 3, npDR("X"), npDR("Y"), GAPointsDT) + + pointsDT.Rows.InsertAt(npDR, inIndex + 1) + End If + + Dim y4 As Decimal = k * GAPointsDT.Rows(3)("X") + m + If y4 > GAPointsDT.Rows(3)("Y") AndAlso y4 < GAPointsDT.Rows(0)("Y") Then + ' lägg till på sida 4 + npDR = pointsDT.NewRow() + npDR("NAME") = recessName & "_4" ' fixa + npDR("TYPE") = "Recess CA" + npDR("X") = GAPointsDT.Rows(3)("X") + npDR("Y") = y4 + + Dim inIndex As Integer = Get_RowIndex(pointsDT, 4, npDR("X"), npDR("Y"), GAPointsDT) + + pointsDT.Rows.InsertAt(npDR, inIndex + 1) + End If + + For Each key As String In pointsInRecess.Keys + If pointsInRecess(key) = True Then + Dim removeIndex As Integer = 0 + For k = 0 To pointsDT.Rows.Count - 1 + If pointsDT.Rows(k)("NAME") = key Then + removeIndex = k + End If + Next + pointsDT.Rows.RemoveAt(removeIndex) + End If + Next + End If + Next + + + ' --- Point on grating side - recesses --- + For Each DR As DataRow In recessPointsDT.Rows + If DR("TYPE") = "Corner Angle" Then + Dim pointName As String = DR("NAME") + If pointName.Split("_")(1) = 1 Then + 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 + 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 Decimal + Dim pointNumGA As Integer = DR("SIDE") + 2 + If pointNumGA > 4 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, "") + 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) + + Dim temp As String = pointsDT.Rows(index)("NAME") + If temp.Substring(0, 2) = "GA" Then + pointsDT.Rows.RemoveAt(index) + End If + + Dim cornerPoint(1) As Decimal + 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, "GA_" & pointNumGA) + End If + End If + Next + + pointsDT.TableName = "Grating " & i & " - C" & columnNum & " R" & rowNum + pointsDS.Tables.Add(pointsDT) + Next + + Return pointsDS + End Function + + Private Shared Function Get_RowIndex(pDT As DataTable, side As Integer, pX As Decimal, pY As Decimal, GApDT As DataTable) + + Dim rowName As String = "" + Dim newX As Decimal = pX + Dim newY As Decimal = pY + + If side = 1 Then + Dim sidePoints = pDT.Select("Y = '" & pY & "'") + If sidePoints.Length = 0 Then + newX = GApDT.Select("NAME = 'GA_1'")(0)("X") + End If + 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 + ElseIf side = 2 Then + Dim sidePoints = pDT.Select("X = '" & pX & "'") + If sidePoints.Length = 0 Then + newY = GApDT.Select("NAME = 'GA_2'")(0)("Y") + End If + For Each DR2 As DataRow In sidePoints + If DR2("Y") > pY Then + rowName = DR2("NAME") + Else + newY = GApDT.Select("NAME = 'GA_2'")(0)("Y") + Exit For + End If + Next + ElseIf side = 3 Then + Dim sidePoints = pDT.Select("Y = '" & pY & "'") + If sidePoints.Length = 0 Then + newX = GApDT.Select("NAME = 'GA_3'")(0)("X") + End If + For Each DR2 As DataRow In sidePoints + If DR2("X") > pX Then + rowName = DR2("NAME") + Else + newX = GApDT.Select("NAME = 'GA_3'")(0)("X") + Exit For + End If + Next + Else + Dim sidePoints = pDT.Select("X = '" & pX & "'") + If sidePoints.Length = 0 Then + newY = GApDT.Select("NAME = 'GA_4'")(0)("Y") + Else + If sidePoints(0)("NAME") = "GA_1" Then + Dim pointList As New List(Of DataRow) + For i = 1 To sidePoints.Length - 1 + pointList.Add(sidePoints(i)) + Next + pointList.Add(sidePoints(0)) + + For Each DR2 As DataRow In pointList + If DR2("Y") < pY Then + rowName = DR2("NAME") + Else + newY = GApDT.Select("NAME = 'GA_4'")(0)("Y") + Exit For + End If + Next + Else + For Each DR2 As DataRow In sidePoints + If DR2("Y") < pY Then + rowName = DR2("NAME") + Else + newY = GApDT.Select("NAME = 'GA_4'")(0)("Y") + Exit For + End If + Next + End If + End If + End If + + Dim index As Integer = 0 + If rowName = "" Then + Dim newSide As Integer = side - 1 + If newSide = 0 Then + newSide = 4 + End If + index = Get_RowIndex(pDT, newSide, 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 Decimal(), GApDT As DataTable, rDT As DataTable, pNameToRemove As String) + Dim p0(1) As Decimal + Dim p1(1) As Decimal + Dim p2(1) As Decimal + + Dim newDR As DataRow = pDT.NewRow + newDR("TYPE") = "Recess CA" + + Dim side As Integer = 0 + Dim pointName As String = rpDR("NAME") + If pointName.Split("_")(1) = 1 Then + Dim DR = Data.gratingPoints.Select("NAME = '" & pointName.Split("_")(0) & "_2" & "'") + newDR("NAME") = pointName.Split("_")(0) & "_2" + + p0(0) = rpDR("X") + p0(1) = rpDR("Y") + + p2(0) = DR(0)("X") + p2(1) = DR(0)("Y") + + If rpDR("SIDE") + 1 > 4 Then + side = rpDR("SIDE") + 1 - 4 + Else + side = rpDR("SIDE") + 1 + End If + Else + Dim DR = Data.gratingPoints.Select("NAME = '" & pointName.Split("_")(0) & "_1" & "'") + newDR("NAME") = pointName.Split("_")(0) & "_1" + + p0(0) = rpDR("X") + p0(1) = rpDR("Y") + + p2(0) = DR(0)("X") + p2(1) = DR(0)("Y") + + If rpDR("SIDE") - 1 < 1 Then + side = rpDR("SIDE") - 1 + 4 + Else + side = rpDR("SIDE") - 1 + End If + End If + + For Each rDR As DataRow In rDT.Rows + If rDR("NAME") = newDR("NAME") Then + Exit Sub + End If + Next + + If rpDR("SIDE") = 1 OrElse rpDR("SIDE") = 3 Then + p1(0) = p2(0) + p1(1) = p0(1) + ElseIf rpDR("SIDE") = 2 OrElse rpDR("SIDE") = 4 Then + p1(0) = p0(0) + p1(1) = p2(1) + End If + + Dim gpInside As Boolean = Calculate_Triangle_Bool(gp, p0, p1, p2) + + Dim insertIndex As Integer = 0 + If gpInside = False Then + ' If false => new point at side rpDR("SIDE")+1 + If side = 1 Then + Dim c As Decimal = GApDT.Select("NAME = 'GA_1'")(0)("Y") - rpDR("Y") + Dim z As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - rpDR("Y") + Dim x As Decimal = 0 + If pointName.Split("_")(1) = 1 Then + x = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_1'")(0)("X") + newDR("X") = GApDT.Select("NAME = 'GA_1'")(0)("X") + c * x / z ' Triangle likformighet + Else + x = GApDT.Select("NAME = 'GA_2'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") + newDR("X") = GApDT.Select("NAME = 'GA_2'")(0)("X") - c * x / z ' Triangle likformighet + End If + newDR("Y") = GApDT.Select("NAME = 'GA_1'")(0)("Y") + ElseIf side = 2 Then + Dim c As Decimal = GApDT.Select("NAME = 'GA_2'")(0)("X") - rpDR("X") + Dim z As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - rpDR("X") + Dim x As Decimal = 0 + If pointName.Split("_")(1) = 1 Then + x = GApDT.Select("NAME = 'GA_2'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") + newDR("Y") = GApDT.Select("NAME = 'GA_2'")(0)("Y") - c * x / z ' Triangle likformighet + Else + x = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_3'")(0)("Y") + newDR("Y") = GApDT.Select("NAME = 'GA_3'")(0)("Y") + c * x / z ' Triangle likformighet + End If + newDR("X") = GApDT.Select("NAME = 'GA_2'")(0)("X") + ElseIf side = 3 Then + Dim c As Decimal = rpDR("Y") - GApDT.Select("NAME = 'GA_3'")(0)("Y") + Dim z As Decimal = rpDR("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") + Dim x As Decimal = 0 + If pointName.Split("_")(1) = 1 Then + x = GApDT.Select("NAME = 'GA_3'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") + newDR("X") = GApDT.Select("NAME = 'GA_3'")(0)("X") - c * x / z ' Triangle likformighet + Else + x = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_4'")(0)("X") + newDR("X") = GApDT.Select("NAME = 'GA_4'")(0)("X") + c * x / z ' Triangle likformighet + End If + newDR("Y") = GApDT.Select("NAME = 'GA_3'")(0)("Y") + Else + Dim c As Decimal = rpDR("X") - GApDT.Select("NAME = 'GA_4'")(0)("X") + Dim z As Decimal = rpDR("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") + Dim x As Decimal = 0 + If pointName.Split("_")(1) = 1 Then + x = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_4'")(0)("Y") + newDR("Y") = GApDT.Select("NAME = 'GA_4'")(0)("Y") + c * x / z ' Triangle likformighet + Else + x = GApDT.Select("NAME = 'GA_1'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") + newDR("Y") = GApDT.Select("NAME = 'GA_1'")(0)("Y") - c * x / z ' Triangle likformighet + End If + newDR("X") = GApDT.Select("NAME = 'GA_4'")(0)("X") + End If + + newDR("X") = Math.Round(newDR("X"), 3) + newDR("Y") = Math.Round(newDR("Y"), 3) + + 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 temp As String = newDR("NAME") + If temp.Split("_")(1) = 1 Then + If side = 1 Then + side = 4 + Else + side -= 1 + End If + Else + If side = 4 Then + side = 1 + Else + side += 1 + End If + End If + + If side = 1 Then + Dim x As Decimal = rpDR("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") + Dim y As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - rpDR("Y") + Dim b As Decimal = 0 + If pointName.Split("_")(1) = 1 Then + b = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_1'")(0)("Y") + newDR("X") = GApDT.Select("NAME = 'GA_1'")(0)("X") + x * b / y - (GApDT.Select("NAME = 'GA_1'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X")) ' Triangle likformighet + Else + b = GApDT.Select("NAME = 'GA_2'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") + newDR("X") = GApDT.Select("NAME = 'GA_2'")(0)("X") - x * b / y + (Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_2'")(0)("X")) ' Triangle likformighet + End If + newDR("Y") = GApDT.Select("NAME = 'GA_1'")(0)("Y") + ElseIf side = 2 Then + Dim x As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - rpDR("Y") + Dim y As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - rpDR("X") + Dim b As Decimal = 0 + If pointName.Split("_")(1) = 1 Then + b = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_2'")(0)("X") + newDR("Y") = GApDT.Select("NAME = 'GA_2'")(0)("Y") - x * b / y + (Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_2'")(0)("Y")) + Else + b = GApDT.Select("NAME = 'GA_3'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") + newDR("Y") = GApDT.Select("NAME = 'GA_3'")(0)("Y") + x * b / y - (GApDT.Select("NAME = 'GA_3'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y")) + End If + newDR("X") = GApDT.Select("NAME = 'GA_2'")(0)("X") + ElseIf side = 3 Then + Dim x As Decimal = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - rpDR("X") + Dim y As Decimal = rpDR("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") + Dim b As Decimal = 0 + If pointName.Split("_")(1) = 1 Then + b = GApDT.Select("NAME = 'GA_3'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") + newDR("X") = GApDT.Select("NAME = 'GA_3'")(0)("X") - x * b / y + (Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_3'")(0)("X")) + Else + b = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_4'")(0)("Y") + newDR("X") = GApDT.Select("NAME = 'GA_4'")(0)("X") + x * b / y - (GApDT.Select("NAME = 'GA_4'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X")) + End If + newDR("Y") = GApDT.Select("NAME = 'GA_3'")(0)("Y") + Else + Dim x As Decimal = rpDR("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") + Dim y As Decimal = rpDR("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") + Dim b As Decimal = 0 + If pointName.Split("_")(1) = 1 Then + b = GApDT.Select("NAME = 'GA_4'")(0)("X") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") + newDR("Y") = GApDT.Select("NAME = 'GA_4'")(0)("Y") + x * b / y - (GApDT.Select("NAME = 'GA_4'")(0)("Y") - Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y")) + Else + b = Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("X") - GApDT.Select("NAME = 'GA_1'")(0)("X") + newDR("Y") = GApDT.Select("NAME = 'GA_1'")(0)("Y") - x * b / y + (Data.gratingPoints.Select("NAME = '" & newDR("NAME") & "'")(0)("Y") - GApDT.Select("NAME = 'GA_1'")(0)("Y")) + End If + newDR("X") = GApDT.Select("NAME = 'GA_4'")(0)("X") + End If + + insertIndex = Get_RowIndex(pDT, side, newDR("X"), newDR("Y"), GApDT) + + pDT.Rows.InsertAt(newDR, insertIndex + 1) + + Dim removeIndex As Integer = 0 + For k = 0 To pDT.Rows.Count - 1 + If pDT.Rows(k)("NAME") = pNameToRemove Then + removeIndex = k + End If + Next + + pDT.Rows.RemoveAt(removeIndex) + End If + End Sub + + Private Shared Function Calculate_Triangle_Bool(gp As Decimal(), p0 As Decimal(), p1 As Decimal(), p2 As Decimal()) + + Dim s As Decimal = p0(1) * p2(0) - p0(0) * p2(1) + (p2(1) - p0(1)) * gp(0) + (p0(0) - p2(0)) * gp(1) + Dim t As Decimal = p0(0) * p1(1) - p0(1) * p1(0) + (p0(1) - p1(1)) * gp(0) + (p1(0) - p0(0)) * gp(1) + + If (s < 0 AndAlso t >= 0) OrElse (s >= 0 AndAlso t < 0) Then + Return False + End If + + Dim area As Decimal = -p1(1) * p2(0) + p0(1) * (p2(0) - p1(0)) + p0(0) * (p1(1) - p2(1)) + p1(0) * p2(1) + + If area < 0 Then + If s <= 0 AndAlso s + t >= area Then + Return True + Else + Return False + End If + Else + If s >= 0 AndAlso s + t <= area Then + Return True + Else + Return False + End If + End If + End Function +End Class diff --git a/Wardrobe/Wardrobe.vbproj b/Wardrobe/Wardrobe.vbproj index 10332ec..016a1aa 100644 --- a/Wardrobe/Wardrobe.vbproj +++ b/Wardrobe/Wardrobe.vbproj @@ -125,6 +125,7 @@ +