def Simulate_Path(): suction_Dia=12 cover_percentage=0.4 step_over=suction_Dia*cover_percentage step_down=suction_Dia*0.5 point_list=Generating_Path_function(step_over,step_down) display.EraseAll() stl_shp1 = read_stl_file('mymodel1.stl') props3 = GProp_GProps() brepgprop_VolumeProperties(stl_shp1, props3) model_mass = props3.Mass() view_box=BRepPrimAPI_MakeBox(gp_Pnt(-30, -30, 0),100, 100, 60) display.DisplayShape(view_box.Shape(),color = "BLACK",transparency = 0.999) display.DisplayShape(stl_shp1) #powder box=material material_box=BRepPrimAPI_MakeBox(gp_Pnt(-18, -18, 0),58, 58, 22) props2 = GProp_GProps() brepgprop_VolumeProperties(material_box.Shape(), props2) mass2 = props2.Mass() first_simulate= simulate(suction_Dia,point_list[0],90,material_box) second_simulate=simulate(suction_Dia,point_list[1],45,first_simulate) props = GProp_GProps() brepgprop_VolumeProperties(second_simulate.Shape(), props) mass = props.Mass() print("remained volume = %",(mass*100/(mass2-model_mass))) display.DisplayShape(second_simulate.Shape(),color = "BLACK",transparency = 0.3)
def big_box(pt1, pt2): gp1 = gp_Pnt(pt1[0], pt1[1], pt1[2]) gp2 = gp_Pnt(pt2[0], pt2[1], pt2[2]) gpm = gp_Pnt(0.5 * (pt1[0] + pt2[0]), 0.5 * (pt1[1] + pt2[1]), 0.5 * (pt1[2] + pt2[2])) box = BRepPrimAPI_MakeBox(gp1, gp2) return box.Shape()
def extrusion(event=None): # Make a box Box = BRepPrimAPI_MakeBox(400., 250., 300.) S = Box.Shape() # Choose the first Face of the box F = next(TopologyExplorer(S).faces()) surf = BRep_Tool_Surface(F) # Make a plane from this face Pl = Handle_Geom_Plane_DownCast(surf) Pln = Pl.GetObject() # Get the normal of this plane. This will be the direction of extrusion. D = Pln.Axis().Direction() # Inverse normal D.Reverse() # Create the 2D planar sketch MW = BRepBuilderAPI_MakeWire() p1 = gp_Pnt2d(200., -100.) p2 = gp_Pnt2d(100., -100.) aline = GCE2d_MakeLine(p1, p2).Value() Edge1 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge1.Edge()) p1 = p2 p2 = gp_Pnt2d(100., -200.) aline = GCE2d_MakeLine(p1, p2).Value() Edge2 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge2.Edge()) p1 = p2 p2 = gp_Pnt2d(200., -200.) aline = GCE2d_MakeLine(p1, p2).Value() Edge3 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge3.Edge()) p1 = p2 p2 = gp_Pnt2d(200., -100.) aline = GCE2d_MakeLine(p1, p2).Value() Edge4 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)) MW.Add(Edge4.Edge()) # Build Face from Wire. NB: a face is required to generate a solid. MKF = BRepBuilderAPI_MakeFace() MKF.Init(surf, False, 1e-6) MKF.Add(MW.Wire()) FP = MKF.Face() breplib_BuildCurves3d(FP) MKP = BRepFeat_MakePrism(S, FP, F, D, False, True) MKP.Perform(200.) # TODO MKP completes, seeing a split operation but no extrusion assert MKP.IsDone() res1 = MKP.Shape() display.EraseAll() display.DisplayColoredShape(res1, 'BLUE') display.FitAll()
def make_box(*args): box = BRepPrimAPI_MakeBox(*args) box.Build() with assert_isdone(box, 'failed to built a cube...'): return box.Shape()
def set_selected(self, ais): ctx = self._get_context() ctx.ClearSelected(False) for obj in ais: ctx.AddOrRemoveSelected(obj, False) self.redraw() if __name__ == "__main__": import sys from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox app = QApplication(sys.argv) viewer = OCCViewer() viewer.show_line() dlg = QDialog() dlg.setFixedHeight(400) dlg.setFixedWidth(600) layout(dlg, (viewer, ), dlg) dlg.show() box = BRepPrimAPI_MakeBox(20, 20, 30) box_ais = AIS_ColoredShape(box.Shape()) viewer.display(box_ais) sys.exit(app.exec_())