Esempio n. 1
0
	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()
Esempio n. 2
0
	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()
Esempio n. 3
0
def doc_demo_():
    from doc import doc_ctrl
    from OCC import BRepPrimAPI
    quader = BRepPrimAPI.BRepPrimAPI_MakeBox(3, 4, 5).Solid()
    kugel = BRepPrimAPI.BRepPrimAPI_MakeSphere(2).Solid()
    with doc_ctrl.open_command():
        doc_ctrl.add(quader)
        doc_ctrl.set_color(quader, [0, 1, 0])
    with doc_ctrl.open_command():
        doc_ctrl.add(kugel)
        doc_ctrl.set_color(kugel, [1, 0, 0])
Esempio n. 4
0
    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
Esempio n. 5
0
 def execute(self):
     ax = gp.gp_Ax2(gp.gp_Pnt(*self.position),
                     gp.gp_Dir(*self.z_axis),
                     gp.gp_Dir(*self.x_axis))
     m_box = BRepPrimAPI.BRepPrimAPI_MakeBox(ax, *self.dims)
     self.update_naming(m_box)
     return m_box.Shape()
Esempio n. 6
0
def make_ellipsoid(focus1, focus2, major_axis):
    """
    @param focus1: length 3 sequence giving first focus location
    @param focus2: length 3 sequence giving second focus location
    @param path_length: major axis length
    """
    f1 = numpy.asarray(focus1)
    f2 = numpy.asarray(focus2)
    direction = -(f1 - f2)
    centre = (f1 + f2)/2.
    sep = numpy.sqrt((direction**2).sum())
    minor_axis = numpy.sqrt( major_axis**2 - (sep/2.)**2 )
    
    sphere = BRepPrimAPI.BRepPrimAPI_MakeSphere(minor_axis)
    
    scale = gp.gp_GTrsf()
    scale.SetValue(3,3, major_axis/minor_axis)
    
    ellipse = BRepBuilderAPI.BRepBuilderAPI_GTransform(sphere.Shape(), scale)
    
    loc = gp.gp_Ax3()
    loc.SetLocation(gp.gp_Pnt(*centre))
    loc.SetDirection(gp.gp_Dir(*direction))
    
    tr = gp.gp_Trsf()
    tr.SetTransformation(loc, gp.gp_Ax3())
    
    trans = BRepBuilderAPI.BRepBuilderAPI_Transform(ellipse.Shape(), tr)
    shape = toshape(trans)
    return shape
Esempio n. 7
0
def drillWithHoles(shape):
    "returns a shape with a bunch of spheres removed from it"
    box = Bnd.Bnd_Box()
    b = BRepBndLib.BRepBndLib()
    b.Add(shape, box)

    cShape = shape
    (xMin, yMin, zMin, xMax, yMax, zMax) = box.Get()

    d = 0.05 * ((xMax - xMin))
    di = 4.0 * d
    c = 0

    #drill holes in a rectangular grid
    for x in frange6(xMin, xMax, di):
        for y in frange6(yMin, yMax, di):
            for z in frange6(zMin, zMax, di):
                c += 1
                print "Inter %d " % c
                #make a sphere
                center = gp.gp_Pnt(x, y, z)
                hole = BRepPrimAPI.BRepPrimAPI_MakeSphere(center, d).Shape()
                cut = BRepAlgoAPI.BRepAlgoAPI_Cut(cShape, hole)
                cut.SetOperation(3)
                #3 is cut21
                tmp = cut.Shape()
                #store the newly cut shape
                if cut.ErrorStatus() != 0:
                    print "Error %d cutting" % cut.ErrorStatus()
                else:
                    print "Success!"
                    cShape = tmp
    return cShape
Esempio n. 8
0
def make_interp_parabola(FL, rmin, rmax, segments=50):
    A = 1./(4*FL)
    x = numpy.linspace(rmin, rmax, segments)
    y = (A * x**2) - FL
    
    points = [(X,0,Z) for X,Z in zip(x,y)]
    points.append((x[0],0,y[-1]))
    
    def pairs(itr):
        a,b = itertools.tee(itr)
        next(b)
        return zip(a,b)
    
    edges = (BRepBuilderAPI.BRepBuilderAPI_MakeEdge(
                    gp.gp_Pnt(*p1), gp.gp_Pnt(*p2))
                    for p1, p2 in pairs(points))
    last_edge = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(
                    gp.gp_Pnt(*points[-1]), 
                    gp.gp_Pnt(*points[0]))
    
    wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
    for e in edges:
        wire.Add(e.Edge())
    wire.Add(last_edge.Edge())
    
    face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire())
    
    ax = gp.gp_Ax1(gp.gp_Pnt(0,0,0),
                   gp.gp_Dir(0,0,1))
    
    revol = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), ax)
    
    return revol.Shape()
Esempio n. 9
0
    def preview(self, input, direction):
        if self.step == 0:
            from OCC import TopExp, TopAbs, BRep
            exp = TopExp.TopExp_Explorer(input, TopAbs.TopAbs_VERTEX)
            v1 = TopoDS.topods_Vertex(exp.Current())
            v1_ = BRep.BRep_Tool.Pnt(TopoDS.TopoDS_Vertex(v1))
            # TODO: 0.3: finish: automatically determine orthogonal direction
            # from
            #   input
            self.previous_data = [input, direction]
            try:
                wire = TopoDS.TopoDS_Wire(input)
                print(dir(wire))
            except:
                pass
            return ()
        elif self.step == 1:
            object, dir_ = self.previous_data[:]

            dirvec = [0, 0, 0]
            dirvec[dir_] = input[dir_]
            if dirvec == [0, 0, 0]:
                raise InvalidInputException
            self.remove = [self.previous_data[0]]
            self._final = [BRepPrimAPI.BRepPrimAPI_MakePrism(
                                object, gp.gp_Vec(*dirvec)).Shape()]
            return self._final
Esempio n. 10
0
 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()
Esempio n. 11
0
 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)
Esempio n. 12
0
    def _makeSlice(self, shapeToSlice, zLevel):

        s = Slice()

        #used to determine if a slice is identical to others.
        s.hatchDir = self.hatchReversed
        s.fillWidth = self.options.filling.fillWidth

        #change if layers are variable thickness
        s.sliceHeight = self.options.layerHeight
        s.zLevel = zLevel

        #make a cutting plane
        p = gp.gp_Pnt(0, 0, zLevel)

        origin = gp.gp_Pnt(0, 0, zLevel - 1)
        csys = gp.gp_Ax3(p, gp.gp().DZ())
        cuttingPlane = gp.gp_Pln(csys)
        bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane)
        face = bff.Face()

        #odd, a halfspace is faster than a box?
        hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face, origin)
        hs.Build()
        halfspace = hs.Solid()

        #make the cut
        bc = BRepAlgoAPI.BRepAlgoAPI_Cut(shapeToSlice, halfspace)
        cutShape = bc.Shape()

        foundFace = False
        for face in Topo(cutShape).faces():
            if self._isAtZLevel(zLevel, face):
                foundFace = True
                log.debug("Face is at zlevel" + str(zLevel))
                s.addFace(face)
                #TestDisplay.display.showShape(face);

                log.debug("Face" + str(face))

        if self.options.useSliceFactoring:
            mySum = s.getCheckSum()
            #print 'Slice Created, Checksum is',mySum;
            for otherSlice in self.slices:
                #print "Slice Checksum=",otherSlice.getCheckSum();
                if mySum == otherSlice.getCheckSum():
                    log.info(
                        "This slice matches another one exactly. using that so we can save time."
                    )
                    return otherSlice.copyToZ(zLevel)

        if not foundFace:
            log.warn("No faces found after slicing at zLevel " + str(zLevel) +
                     " !. Skipping This layer completely")
            return None
        else:
            return s
Esempio n. 13
0
def make_box(position, direction, x_axis, dx, dy, dz):
    box = BRepPrimAPI.BRepPrimAPI_MakeBox(gp.gp_Pnt(-dx/2., -dy/2., 0.0),
                                          dx, dy, -dz)
    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_box = BRepBuilderAPI.BRepBuilderAPI_Transform(box.Shape(), trans)
    return toshape(t_box)
Esempio n. 14
0
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)
Esempio n. 15
0
 def preview(self, input, direction):
     if self.step == 0:
         self.previous_data = [input]
         return []
     elif self.step == 1:
         object = self.previous_data[0]
         dirvec = vec(0, 0, 0)
         dirvec[direction] = 1
         axis = gp.gp_Ax1(input, dirvec.to_gp_Dir())
         self.remove = [self.previous_data[0]]
         self._final = [BRepPrimAPI.BRepPrimAPI_MakeRevol(
                                             object, axis).Shape()]
         return self._final
Esempio n. 16
0
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)
Esempio n. 17
0
def demo_():
    from math import pi, sin, cos
    from gui import viewer_3d
    from OCC import BRepPrimAPI

    quader = BRepPrimAPI.BRepPrimAPI_MakeBox(3, 4, 5).Solid()
    viewer_3d.display_shape(quader)
    viewer_3d.view_mode = 'shaded'
    viewer_3d.zoom = 1
    N = 40
    for i in range(N):
        phi = i / N * pi + pi / 6
        viewer_3d.eye = [sin(phi), cos(phi), phi / 5]
        viewer_3d.zoom *= 1.05
Esempio n. 18
0
def export_step():
    """
    Exports a TopoDS_Shape to a STEP file.
    """
    test_shape = BRepPrimAPI.BRepPrimAPI_MakeBox(100., 100., 100.).Shape()
    # export to AP203 schema
    ap203_exporter = StepExporter('./models_out/box_203.stp', schema='AP203')
    ap203_exporter.add_shape(test_shape)
    ap203_exporter.write_file()
    # export AP214 schema
    ap214cd_exporter = StepExporter('./models_out/box_214CD.stp',
                                    schema='AP214CD')
    ap214cd_exporter.add_shape(test_shape)
    ap214cd_exporter.write_file()
Esempio n. 19
0
    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 _makeSlice(self, shapeToSlice, zLevel):
        s = Slice()

        #change if layers are variable thickness
        s.sliceHeight = self.sliceHeight
        s.zLevel = zLevel

        #make a cutting plane
        p = gp.gp_Pnt(0, 0, zLevel)

        origin = gp.gp_Pnt(0, 0, zLevel - 1)
        csys = gp.gp_Ax3(p, gp.gp().DZ())
        cuttingPlane = gp.gp_Pln(csys)
        bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane)
        face = bff.Face()

        #odd, a halfspace is faster than a box?
        hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face, origin)
        hs.Build()
        halfspace = hs.Solid()

        #make the cut
        bc = BRepAlgoAPI.BRepAlgoAPI_Cut(shapeToSlice, halfspace)
        cutShape = bc.Shape()

        #search the shape for faces at the specified zlevel
        texp = TopExp.TopExp_Explorer()
        texp.Init(cutShape, TopAbs.TopAbs_FACE)
        foundFace = False
        while (texp.More()):
            face = ts.Face(texp.Current())
            if self._isAtZLevel(zLevel, face):
                foundFace = True
                logging.debug("Face is at zlevel" + str(zLevel))
                s.addFace(face, self.saveSliceFaces)
            texp.Next()

        #free memory
        face.Nullify()
        bc.Destroy()
        texp.Clear()
        texp.Destroy()

        if not foundFace:
            logging.warn("No faces found after slicing at zLevel " +
                         str(zLevel) + " !. Skipping This layer completely")
            return None
        else:
            return s
Esempio n. 21
0
def make_ellipsoid_mirror(f1, f2, major_axis, 
                          x_bounds, y_bounds, z_bounds,
                          centre, direction, x_axis):
    ellipsoid = make_ellipsoid(f1, f2, major_axis)
    P1 = gp.gp_Pnt(x_bounds[0], y_bounds[0], z_bounds[0])
    P2 = gp.gp_Pnt(x_bounds[1], y_bounds[1], z_bounds[1])
    block = BRepPrimAPI.BRepPrimAPI_MakeBox(P1, P2)
    
    ##comment these out to reinstate the cut
    #t_block = position_shape(toshape(block), centre, direction, x_axis)
    #t_ellipse = position_shape(ellipsoid, centre, direction, x_axis)
    #return make_compound([toshape(block), ellipsoid])
    
    #cut = toshape(BRepAlgoAPI.BRepAlgoAPI_Cut(toshape(block), ellipsoid))
    cut = make_compound([toshape(block), ellipsoid])
    return position_shape(cut, centre, direction, x_axis)
Esempio n. 22
0
def make_true_para(FL, rmin, rmax):
    """
    makes a parabloid, with rotation axis along Z and focus
    at the origin
    """
    ax = gp.gp_Ax2(gp.gp_Pnt(0.,0.,-FL), #origin
                   gp.gp_Dir(1.,0.,0.), #main direction is Z
                   gp.gp_Dir(0.,0.,1.)) #X Direction is X
    para = Geom.Geom_Parabola(ax, FL)
    h_para = Geom.Handle_Geom_Parabola(para)
    
    ax2 = gp.gp_Ax2(gp.gp_Pnt(0,0,0), #origin
                   gp.gp_Dir(0.,0.,1.), #main direction is Z
                   gp.gp_Dir(1.,0.,0.)) #X Direction is X
    
    pbl_shape = BRepPrimAPI.BRepPrimAPI_MakeRevolution(ax2, h_para,
                                                       rmin, rmax)
    return pbl_shape.Shape()
Esempio n. 23
0
def test_step_exporter_overwrite(box_shape):
    r"""Happy path with a subclass of TopoDS_Shape"""
    filename = path_from_file(__file__, "./models_out/box.stp")
    exporter = StepExporter(filename)
    solid = shape_to_topology(box_shape)
    assert isinstance(solid, TopoDS.TopoDS_Solid)
    exporter.add_shape(solid)
    exporter.write_file()
    initial_timestamp = os.path.getmtime(filename)
    assert os.path.isfile(filename)

    # read the written box.stp
    importer = StepImporter(filename)
    topo_compound = Topo(importer.compound)
    assert topo_compound.number_of_faces() == 6
    assert len([i for i in topo_compound.faces()]) == 6
    assert topo_compound.number_of_edges() == 12

    # add a sphere and write again with same exporter
    sphere = BRepPrimAPI.BRepPrimAPI_MakeSphere(10)
    exporter.add_shape(sphere.Shape())
    exporter.write_file()  # this creates a file with a box and a sphere
    intermediate_timestamp = os.path.getmtime(filename)
    assert intermediate_timestamp >= initial_timestamp

    # check that the file contains the box and the sphere
    importer = StepImporter(filename)
    assert len([i for i in Topo(importer.compound).faces()]) == 7  # 6 from box + 1 from sphere
    assert len([i for i in Topo(importer.compound).solids()]) == 2

    # create a new exporter and overwrite with a box only
    filename = path_from_file(__file__, "./models_out/box.stp")
    exporter = StepExporter(filename)
    solid = shape_to_topology(box_shape)
    exporter.add_shape(solid)
    exporter.write_file()
    assert os.path.isfile(filename)
    last_timestamp = os.path.getmtime(filename)
    assert last_timestamp >= intermediate_timestamp

    # check the file only contains a box
    importer = StepImporter(filename)
    assert len([i for i in Topo(importer.compound).faces()]) == 6  # 6 from box
    assert len([i for i in Topo(importer.compound).solids()]) == 1
Esempio n. 24
0
    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)
Esempio n. 25
0
def make_spherical_lens2(CT1, CT2, diameter, 
                         curvature1, curvature2, 
                        centre, direction, x_axis):
    cax = gp.gp_Ax2(gp.gp_Pnt(0,0,CT1-curvature1),
                    gp.gp_Dir(0,sign(curvature1),0),
                    gp.gp_Dir(1,0,0))
    circ = Geom.Geom_Circle(cax, abs(curvature1))
    h_circ = Geom.Handle_Geom_Circle(circ)
    
    cax2 = gp.gp_Ax2(gp.gp_Pnt(0,0,CT2-curvature2),
                    gp.gp_Dir(0,-sign(curvature2),0),
                    gp.gp_Dir(1,0,0))
    circ2 = Geom.Geom_Circle(cax2, abs(curvature2))
    h_circ2 = Geom.Handle_Geom_Circle(circ2)
    
    r = diameter/2.
    
    h2 = CT1 - curvature1 + numpy.sqrt(curvature1**2 - r**2)*sign(curvature1)
    h3 = CT2 - curvature2 + numpy.sqrt(curvature2**2 - r**2)*sign(curvature2)
    p1 = gp.gp_Pnt(0,0,CT1)
    p2 = gp.gp_Pnt(r,0,h2)
    p3 = gp.gp_Pnt(r,0,h3)
    p4 = gp.gp_Pnt(0,0,CT2)
    
    e1 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(h_circ, p1, p2)    
    e2 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p2,p3)
    e3 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(h_circ2, p3,p4)
    e4 = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(p4,p1)
    
    wire = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
    for e in (e1,e2,e3,e4):
        print(e)
        wire.Add(e.Edge())
    
    face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire.Wire())
    
    ax = gp.gp_Ax1(gp.gp_Pnt(0,0,0),
                   gp.gp_Dir(0,0,1))
    solid = BRepPrimAPI.BRepPrimAPI_MakeRevol(face.Shape(), ax)
    
    return position_shape(toshape(solid), centre, direction, x_axis)
Esempio n. 26
0
    def preview(self, input, direction):
        veclist = []
        for edge in subshapes(input, TopAbs_EDGE):
            vertices = subshapes(edge, TopAbs_VERTEX)
            vec_ = gp_Pnt_(vertices[0]) - gp_Pnt_(vertices[1])
            veclist.append(vec_)

        prisms = []
        for vec_ in veclist:
            vec_ = vec_ * (1/vec_.length())*100
            v = vec(vec_[1], -vec_[0], 100)

            prism = BRepPrimAPI.BRepPrimAPI_MakePrism(input, 
                        gp.gp_Vec(v[0], v[1], v[2])).Shape()
            prisms.append(prism)

        p = prisms.pop()
        for p_ in prisms:
            p = intersection(p, p_)[0]

        self._final = [p]
        return self._final
Esempio n. 27
0
    def makeSection(self, cuttingPlane, shapeToSection, zLevel):
        """
            Uses halfspaces to make a cut.
        """
        bff = BRepBuilderAPI.BRepBuilderAPI_MakeFace(cuttingPlane)
        face = bff.Face()
        origin = gp.gp_Pnt(0, 0, zLevel - 1)

        #odd, a halfspace is faster than a box?
        hs = BRepPrimAPI.BRepPrimAPI_MakeHalfSpace(face, origin)
        hs.Build()
        halfspace = hs.Solid()

        #make the cut
        bc = BRepAlgoAPI.BRepAlgoAPI_Cut(self.solid.shape, halfspace)
        cutShape = bc.Shape()

        ff = []
        for face in Topo(cutShape).faces():
            if OCCUtil.isFaceAtZLevel(zLevel, face):
                ff.append(face)
        return ff
Esempio n. 28
0
def drillWithHolesFaster(shape):
    "returns a shape with a bunch of spheres removed from it"
    box = Bnd.Bnd_Box()
    b = BRepBndLib.BRepBndLib()
    b.Add(shape, box)

    (xMin, yMin, zMin, xMax, yMax, zMax) = box.Get()

    d = 0.05 * ((xMax - xMin))
    di = 3.0 * d
    vec = gp.gp_Vec(gp.gp_Pnt(0, 0, 0), gp.gp_Pnt(0, 0, d))
    cp = None
    compound = TopoDS.TopoDS_Compound()
    builder = BRep.BRep_Builder()
    builder.MakeCompound(compound)
    #drill holes in a rectangular grid
    for x in frange6(xMin, xMax, di):
        for y in frange6(yMin, yMax, di):
            for z in frange6(zMin, zMax, di):
                #make a sphere
                center = gp.gp_Pnt(x, y, z)
                hole = BRepPrimAPI.BRepPrimAPI_MakeSphere(center, d).Shape()
                #lets see if a square hole is faster!
                #w = squareWire(center,d );
                #hb = BRepPrimAPI.BRepPrimAPI_MakePrism(w,vec,False,True);
                #hb.Build();
                #hole = hb.Shape();
                builder.Add(compound, hole)

    display.DisplayShape(compound)
    q = time.clock()
    cut = BRepAlgoAPI.BRepAlgoAPI_Cut(shape, compound)
    if cut.ErrorStatus() == 0:
        print "Cut Took %0.3f sec." % (time.clock() - q)
        return cut.Shape()
    else:
        print "Error Cutting: %d" % cut.ErrorStatus()
        return shape
Esempio n. 29
0
def test_iges_exporter_overwrite(box_shape):
    r"""Happy path with a subclass of TopoDS_Shape"""
    filename = path_from_file(__file__, "./models_out/box.igs")
    exporter = IgesExporter(filename)
    solid = shape_to_topology(box_shape)
    assert isinstance(solid, TopoDS.TopoDS_Solid)
    exporter.add_shape(solid)
    exporter.write_file()
    assert os.path.isfile(filename)

    # read the written box.igs
    importer = IgesImporter(filename)
    topo_compound = Topo(importer.compound)
    assert topo_compound.number_of_faces() == 6
    assert topo_compound.number_of_edges() == 24

    # add a sphere and write again with same exporter
    sphere = BRepPrimAPI.BRepPrimAPI_MakeSphere(10)
    exporter.add_shape(sphere.Shape())
    exporter.write_file()  # this creates a file with a box and a sphere

    # check that the file contains the box and the sphere
    importer = IgesImporter(filename)
    topo_compound = Topo(importer.compound)
    assert topo_compound.number_of_faces() == 7  # 6 from box + 1 from sphere

    # create a new exporter and overwrite with a box only
    filename = path_from_file(__file__, "./models_out/box.igs")
    exporter = IgesExporter(filename)
    solid = shape_to_topology(box_shape)
    exporter.add_shape(solid)
    exporter.write_file()
    assert os.path.isfile(filename)

    # check the file only contains a box
    importer = IgesImporter(filename)
    topo_compound = Topo(importer.compound)
    assert topo_compound.number_of_faces() == 6  # 6 from box
Esempio n. 30
0
def test_stl_exporter_overwrite(box_shape):
    r"""Happy path with a subclass of TopoDS_Shape"""
    filename = path_from_file(__file__, "./models_out/box.stl")
    exporter = StlExporter(filename)
    solid = shape_to_topology(box_shape)
    assert isinstance(solid, TopoDS.TopoDS_Solid)
    exporter.set_shape(solid)
    exporter.write_file()
    assert os.path.isfile(filename)

    # read the written box.stl
    importer = StlImporter(filename)
    topo = Topo(importer.shape)
    assert topo.number_of_shells() == 1

    # set a sphere and write again with same exporter
    sphere = BRepPrimAPI.BRepPrimAPI_MakeSphere(10)
    exporter.set_shape(sphere.Shape())
    exporter.write_file(
    )  # this creates a file with a sphere only, this is STL specific

    # check that the file contains the sphere only
    importer = StlImporter(filename)
    topo = Topo(importer.shape)
    assert topo.number_of_shells() == 1

    # create a new exporter and overwrite with a box only
    filename = path_from_file(__file__, "./models_out/box.stl")
    exporter = StlExporter(filename)
    solid = shape_to_topology(box_shape)
    exporter.set_shape(solid)
    exporter.write_file()
    assert os.path.isfile(filename)

    # check the file only contains a box
    importer = StlImporter(filename)
    topo = Topo(importer.shape)
    assert topo.number_of_shells() == 1