def CreateShape(self): outer = occprim.BRepPrimAPI_MakeCylinder(self.outer_radius,self.length).Shape() inner = occprim.BRepPrimAPI_MakeCylinder(self.inner_radius,self.length).Shape() self.occ_shape = occalgo.BRepAlgoAPI_Cut(outer,inner).Shape() T = gp_Trsf() T.SetTranslation(gp_Vec(0,0,-self.length/2)) self.occ_shape = occbuild.BRepBuilderAPI_Transform(self.occ_shape,T,False).Shape() self.OrientShape()
def CreateShape(self): self.occ_shape = occprim.BRepPrimAPI_MakeCylinder( self.radius, self.length).Shape() T = gp_Trsf() T.SetTranslation(gp_Vec(0, 0, -self.length / 2)) self.occ_shape = occbuild.BRepBuilderAPI_Transform( self.occ_shape, T, False).Shape() self.OrientShape()
def SetCylDirection(self, val): a = (val - 50.) / 10. b = math.sin(a) c = math.cos(a) ax = gp.gp_Ax2(gp.gp_Pnt(0, 0, 0), gp.gp_Dir(b, 0, c)) cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(ax, 25, 50).Shape() self.shape_tool.SetShape(self.cyl_label, cyl) self.shape_tool.UpdateAssembly(self.top_label)
def CreateShape(self): endcap1 = occprim.BRepPrimAPI_MakeSphere(gp_Pnt(0,0,0),self.radius).Shape() endcap2 = occprim.BRepPrimAPI_MakeSphere(gp_Pnt(0,0,self.length),self.radius).Shape() body = occprim.BRepPrimAPI_MakeCylinder(self.radius,self.length).Shape() self.occ_shape = occalgo.BRepAlgoAPI_Fuse(endcap1,body).Shape() self.occ_shape = occalgo.BRepAlgoAPI_Fuse(self.occ_shape,endcap2).Shape() T = gp_Trsf() T.SetTranslation(gp_Vec(0,0,-self.length/2)) self.occ_shape = occbuild.BRepBuilderAPI_Transform(self.occ_shape,T,False).Shape() self.OrientShape()
def make_cylinder_2(start, end, radius): start = numpy.asarray(start) end = numpy.asarray(end) direction = end-start length = numpy.sqrt((direction**2).sum()) cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(radius, length) ax = gp.gp_Ax3(gp.gp_Pnt(*start), gp.gp_Dir(*direction)) trans = gp.gp_Trsf() trans.SetTransformation(ax, gp.gp_Ax3()) t_cyl = BRepBuilderAPI.BRepBuilderAPI_Transform(cyl.Shape(), trans) return toshape(t_cyl)
def make_cylinder(position, direction, radius, length, offset, x_axis): cyl_ax = gp.gp_Ax2(gp.gp_Pnt(offset,0,0), gp.gp_Dir(0,0,1), gp.gp_Dir(1,0,0)) cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(cyl_ax, radius, length) ax = gp.gp_Ax2(gp.gp_Pnt(*position), gp.gp_Dir(*direction), gp.gp_Dir(*x_axis)) ax3 = gp.gp_Ax3() trans = gp.gp_Trsf() trans.SetTransformation(gp.gp_Ax3(ax), ax3) t_cyl = BRepBuilderAPI.BRepBuilderAPI_Transform(cyl.Shape(), trans) print(position, direction, radius, length) return toshape(t_cyl)
def InitDoc(self): h_shape_tool = XCAFDoc.XCAFDoc_DocumentTool().ShapeTool(doc.Main()) l_Colors = XCAFDoc.XCAFDoc_DocumentTool().ColorTool(doc.Main()) shape_tool = h_shape_tool.GetObject() colors = l_Colors.GetObject() self.shape_tool = shape_tool top_label = shape_tool.NewShape( ) #this is the "root" label for the assembly self.top_label = top_label #Add some shapes box = BRepPrimAPI.BRepPrimAPI_MakeBox(10, 20, 30).Shape() box_label = shape_tool.AddShape(box, False) cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(25, 50).Shape() cyl_label = shape_tool.AddShape(cyl, False) #Add components as references to our shape tr = gp.gp_Trsf() tr.SetTranslation(gp.gp_Vec(100, 100, 100)) loc = TopLoc.TopLoc_Location(tr) box_comp1 = shape_tool.AddComponent(top_label, box_label, loc) tr = gp.gp_Trsf() tr.SetTranslation(gp.gp_Vec(-100, -100, -100)) loc = TopLoc.TopLoc_Location(tr) box_comp2 = shape_tool.AddComponent(top_label, box_label, loc) tr = gp.gp_Trsf() tr.SetTranslation(gp.gp_Vec(10, 10, 10)) loc = TopLoc.TopLoc_Location(tr) cyl_comp = shape_tool.AddComponent(top_label, cyl_label, loc) #Add some colors red = Quantity.Quantity_Color(Quantity.Quantity_NOC_RED) green = Quantity.Quantity_Color(Quantity.Quantity_NOC_GREEN) blue = Quantity.Quantity_Color(Quantity.Quantity_NOC_BLUE1) colors.SetColor(cyl_comp, red, XCAFDoc.XCAFDoc_ColorGen) colors.SetColor(box_label, blue, XCAFDoc.XCAFDoc_ColorGen) colors.SetColor(box_comp2, green, XCAFDoc.XCAFDoc_ColorGen) self.box_label = box_label self.cyl_label = cyl_label self.box_comp1 = box_comp1 self.box_comp2 = box_comp2 self.cyl_comp = cyl_comp
def __init__(self): super(TestFrame, self).__init__(None, -1, "test frame", size=(600, 500)) self.canvas = MyCanvas(self) self.viewer = None #self.Show() self.slider1 = wx.Slider(self, -1, 20, 1, 100, style=wx.SL_HORIZONTAL) self.slider1.Bind(wx.EVT_SLIDER, self.OnSlider) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.canvas, 1, wx.EXPAND | wx.ALL, 3) sizer.Add(self.slider1, 0, wx.EXPAND | wx.ALL, 3) self.SetSizer(sizer) self.Fit() self.cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(25, 20).Shape() self.ais_shape = AIS.AIS_Shape(self.cyl)
def make_OAP(EFL, diameter, height, centre, direction, x_axis): FL = EFL/2. #focal length radius = diameter/2. outside = EFL + radius inside = EFL - radius length = (outside**2)/(4.*FL) - FL + height #pbl_shape = make_true_para(FL, 5.0, outside+1) pbl_shape = make_interp_parabola(FL, inside-1, outside+1) ax3 = gp.gp_Ax2(gp.gp_Pnt(EFL,0,-height), #origin gp.gp_Dir(0.,0.,1.), #main direction is X gp.gp_Dir(0.,1.,0.)) #X Direction is Y cyl_solid = BRepPrimAPI.BRepPrimAPI_MakeCylinder(ax3, radius, length) cut = BRepAlgoAPI.BRepAlgoAPI_Cut(cyl_solid.Shape(), pbl_shape) loc= position_shape(toshape(cut), centre, direction, x_axis) #nurbs = BRepBuilderAPI.BRepBuilderAPI_NurbsConvert(loc) return loc #toshape(nurbs)
def FillTestDoc(doc): h_shape_tool = XCAFDoc.XCAFDoc_DocumentTool().shapetool(doc.Main()) h_Colors = XCAFDoc.XCAFDoc_DocumentTool().colortool(doc.Main()) shape_tool = h_shape_tool.GetObject() colors = h_Colors.GetObject() top_label = shape_tool.NewShape( ) #this is the "root" label for the assembly print "top entry", Label(TDF_Label=top_label).entry box = BRepPrimAPI.BRepPrimAPI_MakeBox(10, 20, 30).Shape() box_label = shape_tool.AddShape(box, False) cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(25, 50).Shape() cyl_label = shape_tool.AddShape(cyl, False) # tr = gp.gp_Trsf() tr.SetTranslation(gp.gp_Vec(100, 100, 100)) loc = TopLoc.TopLoc_Location(tr) box_comp1 = shape_tool.AddComponent(top_label, box_label, loc) tr = gp.gp_Trsf() tr.SetTranslation(gp.gp_Vec(200, 200, 200)) loc = TopLoc.TopLoc_Location(tr) box_comp2 = shape_tool.AddComponent(top_label, box_label, loc) tr = gp.gp_Trsf() tr.SetTranslation(gp.gp_Vec(150, 200, 100)) loc = TopLoc.TopLoc_Location(tr) cyl_comp = shape_tool.AddComponent(top_label, cyl_label, loc) red = Quantity.Quantity_Color(Quantity.Quantity_NOC_RED) green = Quantity.Quantity_Color(Quantity.Quantity_NOC_GREEN) colors.SetColor(cyl_comp, red, XCAFDoc.XCAFDoc_ColorGen) colors.SetColor(box_comp2, green, XCAFDoc.XCAFDoc_ColorGen)
def step_export_layers_and_colors(event=None): r""" demo showing how to export step files with layers & colors. adapted from Bryan's names_shape_demo """ # Create the TDocStd document h_doc = TDocStd.Handle_TDocStd_Document() print("Empty Doc?", h_doc.IsNull()) # Create the application app = XCAFApp.GetApplication().GetObject() app.NewDocument(TCollection.TCollection_ExtendedString("MDTV-CAF"), h_doc) # Get root assembly doc = h_doc.GetObject() h_shape_tool = XCAFDoc.XCAFDoc_DocumentTool().ShapeTool(doc.Main()) l_colors = XCAFDoc.XCAFDoc_DocumentTool().ColorTool(doc.Main()) l_layers = XCAFDoc.XCAFDoc_DocumentTool().LayerTool(doc.Main()) shape_tool = h_shape_tool.GetObject() colors = l_colors.GetObject() layers = l_layers.GetObject() top_label = shape_tool.NewShape( ) # this is the "root" label for the assembly print("Is Assembly", shape_tool.IsAssembly(top_label)) # not yet, 'cos it's empty) # Add some shapes box = BRepPrimAPI.BRepPrimAPI_MakeBox(10, 20, 30).Shape() box_label = shape_tool.AddShape(box, False) cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(25, 50).Shape() cyl_label = shape_tool.AddShape(cyl, False) # Add components as references to our shape tr = gp.gp_Trsf() tr.SetTranslation(gp.gp_Vec(100, 100, 100)) loc = TopLoc.TopLoc_Location(tr) box_comp1 = shape_tool.AddComponent(top_label, box_label, loc) tr = gp.gp_Trsf() tr.SetTranslation(gp.gp_Vec(200, 200, 200)) loc = TopLoc.TopLoc_Location(tr) box_comp2 = shape_tool.AddComponent(top_label, box_label, loc) tr = gp.gp_Trsf() tr.SetTranslation(gp.gp_Vec(150, 200, 100)) loc = TopLoc.TopLoc_Location(tr) cyl_comp = shape_tool.AddComponent(top_label, cyl_label, loc) print("Is Assembly", shape_tool.IsAssembly(top_label)) # it is now... # Add some colors red = Quantity.Quantity_Color(Quantity.Quantity_NOC_RED) green = Quantity.Quantity_Color(Quantity.Quantity_NOC_GREEN) colors.SetColor(cyl_comp, red, XCAFDoc.XCAFDoc_ColorGen) colors.SetColor(box_comp2, green, XCAFDoc.XCAFDoc_ColorGen) # Set the box on the 'box' layer, the cylinder on the 'cylinder' layer layers.SetLayer(box_comp1, TCollection_ExtendedString('BOX')) layers.SetLayer(cyl_comp, TCollection_ExtendedString('CYLINDER')) # Set up AIS Presentation stuff (I don't understand this, but it kinda works) aisView = TPrsStd.TPrsStd_AISViewer().New(top_label, display.Context.GetHandle()) aisPres = TPrsStd.TPrsStd_AISPresentation().Set( top_label, XCAFPrs.XCAFPrs_Driver().GetID()) aisPres.GetObject().Display(True) display.FitAll() # write the stuff to STEP, with layers & colors work_session = XSControl_WorkSession() writer = STEPCAFControl_Writer(work_session.GetHandle(), False) writer.Transfer(h_doc, STEPControl_AsIs) pth = '.' print('writing STEP file') status = writer.Write(os.path.join(pth, 'step_layers_colors.step')) print('status:', status)
l_Colors = XCAFDoc.XCAFDoc_DocumentTool().ColorTool(doc.Main()) shape_tool = h_shape_tool.GetObject() colors = l_Colors.GetObject() top_label = shape_tool.NewShape() #this is the "root" label for the assembly print "Is Assembly", shape_tool.IsAssembly(top_label) #not yet, 'cos it's empty # #Add some shapes # box = BRepPrimAPI.BRepPrimAPI_MakeBox(10,20,30).Shape() box_label = shape_tool.AddShape(box, False) cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(25,50).Shape() cyl_label = shape_tool.AddShape(cyl, False) # #Add components as references to our shape # tr = gp.gp_Trsf() tr.SetTranslation(gp.gp_Vec(100,100,100)) loc = TopLoc.TopLoc_Location(tr) box_comp1 = shape_tool.AddComponent(top_label, box_label, loc) tr = gp.gp_Trsf() tr.SetTranslation(gp.gp_Vec(200,200,200)) loc = TopLoc.TopLoc_Location(tr) box_comp2 = shape_tool.AddComponent(top_label, box_label, loc)
def OnSlider(self, event): #print event.GetInt() cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(25, event.GetInt()).Shape() self.ais_shape.Set(cyl) self.context.Redisplay(AIS.AIS_KOI_Shape)
wx.SafeYield() canvas.Init3dViewer() viewer = canvas._3dDisplay print viewer box = BRepPrimAPI.BRepPrimAPI_MakeBox(20, 30, 40) ax = gp_Ax2() ax.Translate(gp_Vec(50, 50, 50)) cyl_len = 40 radius = 10 angle = pi * 1.5 cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(radius, cyl_len) ax = gp_Ax3() ax.SetLocation(gp_Pnt(50, 60, 70)) ax.SetDirection(gp_Dir(gp_Vec(1, 1, 1))) trans = gp_Trsf() trans.SetTransformation(ax) t_cyl = BRepBuilderAPI.BRepBuilderAPI_Transform(cyl.Shape(), trans) viewer.DisplayShape(box.Shape()) viewer.DisplayShape(t_cyl.Shape()) app.MainLoop() ##Building the resulting compund
##professionals having in-depth computer knowledge. Users are therefore ##encouraged to load and test the software's suitability as regards their ##requirements in conditions enabling the security of their systems and/or ##data to be ensured and, more generally, to use and operate it in the ##same conditions as regards security. ## ##The fact that you are presently reading this means that you have had ##knowledge of the CeCILL license and that you accept its terms. import os import math from OCC import BRepPrimAPI # # Make the 1st cylinder # cyl1 = BRepPrimAPI.BRepPrimAPI_MakeCylinder(50, 200) cyl1_shape = cyl1.Shape() # # Make the 2nd cylinder # cyl2 = BRepPrimAPI.BRepPrimAPI_MakeCylinder( OCC.gp_Ax2(OCC.gp_Pnt(200, 200, 0), OCC.gp_Dir(0, 0, 1)), 40, 110, 210 * math.pi / 180) cyl2_shape = cyl2.Shape() # # Export result to IGES file # i = OCC.IGESControl_Controller() i.Init() iges_writer = OCC.IGESControl_Writer() iges_writer.AddShape(cyl1_shape)
def assembly(event=None): # Create the TDocStd document h_doc = TDocStd.Handle_TDocStd_Document() print("Empty Doc?", h_doc.IsNull()) # Create the application app = XCAFApp.GetApplication().GetObject() app.NewDocument(TCollection.TCollection_ExtendedString("MDTV-CAF"), h_doc) # Get root assembly doc = h_doc.GetObject() h_shape_tool = XCAFDoc.XCAFDoc_DocumentTool().ShapeTool(doc.Main()) l_colors = XCAFDoc.XCAFDoc_DocumentTool().ColorTool(doc.Main()) shape_tool = h_shape_tool.GetObject() colors = l_colors.GetObject() top_label = shape_tool.NewShape( ) #this is the "root" label for the assembly print("Is Assembly", shape_tool.IsAssembly(top_label)) # not yet, 'cos it's empty # Add some shapes box = BRepPrimAPI.BRepPrimAPI_MakeBox(10, 20, 30).Shape() box_label = shape_tool.AddShape(box, False) cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(25, 50).Shape() cyl_label = shape_tool.AddShape(cyl, False) # Add components as references to our shape tr = gp.gp_Trsf() tr.SetTranslation(gp.gp_Vec(100, 100, 100)) loc = TopLoc.TopLoc_Location(tr) box_comp1 = shape_tool.AddComponent(top_label, box_label, loc) tr = gp.gp_Trsf() tr.SetTranslation(gp.gp_Vec(200, 200, 200)) loc = TopLoc.TopLoc_Location(tr) box_comp2 = shape_tool.AddComponent(top_label, box_label, loc) tr = gp.gp_Trsf() tr.SetTranslation(gp.gp_Vec(150, 200, 100)) loc = TopLoc.TopLoc_Location(tr) cyl_comp = shape_tool.AddComponent(top_label, cyl_label, loc) print("Is Assembly", shape_tool.IsAssembly(top_label)) # it is now... # Add some colors red = Quantity.Quantity_Color(Quantity.Quantity_NOC_RED) green = Quantity.Quantity_Color(Quantity.Quantity_NOC_GREEN) colors.SetColor(cyl_comp, red, XCAFDoc.XCAFDoc_ColorGen) colors.SetColor(box_comp2, green, XCAFDoc.XCAFDoc_ColorGen) # Set up AIS Presentation stuff (I don't understand this, but it kinda works) ais_view = TPrsStd.TPrsStd_AISViewer().New(top_label, display.Context.GetHandle()) ais_pres = TPrsStd.TPrsStd_AISPresentation().Set( top_label, XCAFPrs.XCAFPrs_Driver().GetID()) ais_pres.GetObject().Display(True) display.FitAll()
outside = EFL + radius length = (outside**2) / (4. * FL) ax2 = gp.gp_Ax2( gp.gp_Pnt(0, 0, 0), #origin gp.gp_Dir(0., 0., 1.), #main direction is X gp.gp_Dir(1., 0., 0.)) #X Direction is Z pbl_shape = BRepPrimAPI.BRepPrimAPI_MakeRevolution(ax2, h_para, 1.0, outside) ax3 = gp.gp_Ax2( gp.gp_Pnt(EFL, 0, 0), #origin gp.gp_Dir(0., 0., 1.), #main direction is X gp.gp_Dir(0., 1., 0.)) #X Direction is Y cyl_solid = BRepPrimAPI.BRepPrimAPI_MakeCylinder(ax3, radius, length) nurb = BRepBuilderAPI.BRepBuilderAPI_NurbsConvert(pbl_shape.Shape()) cut = BRepAlgoAPI.BRepAlgoAPI_Cut(cyl_solid.Shape(), nurb.Shape()) #view(wire.Shape(), cyl_solid.Shape(), pbl_shape.Shape()) #view(cyl_solid.Shape(), pbl_shape.Shape()) view(cut.Shape()) exportList = [nurb.Shape()] step_export = STEPControl.STEPControl_Writer() for shape in exportList: step_export.Transfer(shape, STEPControl.STEPControl_AsIs)