def brep_feat_rib(event=None):
    mkw = BRepBuilderAPI_MakeWire()

    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(0., 0., 0.), gp_Pnt(200., 0., 0.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(200., 0., 0.), gp_Pnt(200., 0., 50.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(200., 0., 50.), gp_Pnt(50., 0., 50.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 0., 50.), gp_Pnt(50., 0., 200.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 0., 200.), gp_Pnt(0., 0., 200.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(0., 0., 200.), gp_Pnt(0., 0., 0.)).Edge())

    S = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(mkw.Wire()).Face(),
                              gp_Vec(gp_Pnt(0., 0., 0.),
                                     gp_Pnt(0., 100., 0.)))
    display.EraseAll()
    #    display.DisplayShape(S.Shape())

    W = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 45., 100.),
                                                        gp_Pnt(100., 45., 50.)).Edge())

    aplane = Geom_Plane(0., 1., 0., -45.)

    aform = BRepFeat_MakeLinearForm(S.Shape(), W.Wire(), aplane.GetHandle(),
                                    gp_Vec(0., 10., 0.), gp_Vec(0., 0., 0.),
                                    1, True)
    aform.Perform()
    display.DisplayShape(aform.Shape())
    display.FitAll()
Example #2
0
def makePieSlice(r, theta0, theta1, z_min, z_max):
    p0 = gp_Pnt(0, 0, z_min)
    p1 = gp_Pnt(r * cos(theta0), r * sin(theta0), z_min)
    p2 = gp_Pnt(r * cos(theta1), r * sin(theta1), z_min)
    edges = []
    los = TopTools_ListOfShape()
    me = BRepBuilderAPI_MakeEdge(p0, p1)
    edges.append(me.Edge())
    los.Append(me.Edge())
    ax = gp_Ax2(gp_Pnt(0, 0, z_min), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
    circ = gp_Circ(ax, r)
    me = BRepBuilderAPI_MakeEdge(circ, theta0, theta1)
    edges.append(me.Edge())
    los.Append(me.Edge())
    me = BRepBuilderAPI_MakeEdge(p2, p0)
    edges.append(me.Edge())
    los.Append(me.Edge())
    """
    mw = BRepBuilderAPI_MakeWire()
    for i in edges:
      mw.Add(i)
    """
    mw = BRepBuilderAPI_MakeWire()
    mw.Add(los)

    pln = gp_Pln(gp_Pnt(0, 0, z_min), gp_Dir(0, 0, 1))
    mf = BRepBuilderAPI_MakeFace(pln, mw.Wire())
    face = mf.Face()
    mp = BRepPrimAPI_MakePrism(face, gp_Vec(0, 0, z_max - z_min))
    return mp.Shape()
def pipe_fillet(radius):
    # the points
    p1 = gp_Pnt(0, 0, 0)
    p2 = gp_Pnt(0, 1, 0)
    p3 = gp_Pnt(1, 2, 0)
    p4 = gp_Pnt(2, 2, 0)
    # the edges
    ed1 = BRepBuilderAPI_MakeEdge(p1, p2).Edge()
    ed2 = BRepBuilderAPI_MakeEdge(p2, p3).Edge()
    ed3 = BRepBuilderAPI_MakeEdge(p3, p4).Edge()
    # inbetween
    fillet12 = filletEdges(ed1, ed2)
    fillet23 = filletEdges(ed2, ed3)
    # the wire
    makeWire = BRepBuilderAPI_MakeWire()
    makeWire.Add(ed1)
    makeWire.Add(fillet12)
    makeWire.Add(ed2)
    makeWire.Add(fillet23)
    makeWire.Add(ed3)
    makeWire.Build()
    wire = makeWire.Wire()
    # the pipe
    dir = gp_Dir(0, 1, 0)
    circle = gp_Circ(gp_Ax2(p1, dir), radius)
    profile_edge = BRepBuilderAPI_MakeEdge(circle).Edge()
    profile_wire = BRepBuilderAPI_MakeWire(profile_edge).Wire()
    profile_face = BRepBuilderAPI_MakeFace(profile_wire).Face()
    pipe = BRepOffsetAPI_MakePipe(wire, profile_face).Shape()
    #display.DisplayShape(pipe, update=True)
    return (pipe)
Example #4
0
def make_wirex(*args):
    """ list of Edge """
    # if we get an iterable, than add all edges to wire builder
    wire = BRepBuilderAPI_MakeWire()
    for a in args:
        wire.Add(a)
    wire.Build()

    with assert_isdone(wire, 'failed to produce wire'):
        result = wire.Wire()
        return result
Example #5
0
    def assembleEdges(cls, listOfEdges):
        """
            Attempts to build a wire that consists of the edges in the provided list
            :param cls:
            :param listOfEdges: a list of Edge objects
            :return: a wire with the edges assembled
        """
        wire_builder = BRepBuilderAPI_MakeWire()
        for edge in listOfEdges:
            wire_builder.Add(edge.wrapped)

        return cls(wire_builder.Wire())
Example #6
0
    def combine(cls, listOfWires):
        """
        Attempt to combine a list of wires into a new wire.
        the wires are returned in a list.
        :param cls:
        :param listOfWires:
        :return:
        """

        wire_builder = BRepBuilderAPI_MakeWire()
        for wire in listOfWires:
            wire_builder.Add(wire.wrapped)

        return cls(wire_builder.Wire())
Example #7
0
 def create_shape(self):
     data = self.element.attrib.get('d')
     shapes = []
     path = None
     for cmd, params in self.parse_path(data):
         if cmd == 'M':
             if path is not None:
                 shapes.append(path.Wire())
             path = BRepBuilderAPI_MakeWire()
             last_pnt = gp_Pnt(params[0], params[1], 0)
             start_pnt = last_pnt
         elif cmd in ['L', 'H', 'V']:
             pnt = gp_Pnt(params[0], params[1], 0)
             path.Add(BRepBuilderAPI_MakeEdge(last_pnt, pnt).Edge())
             last_pnt = pnt
         elif cmd == 'Q':
             # Quadratic Bezier
             pts = TColgp_Array1OfPnt(1, 3)
             pts.SetValue(1, last_pnt)
             pts.SetValue(2, gp_Pnt(params[0], params[1], 0))
             last_pnt = gp_Pnt(params[2], params[3], 0)
             pts.SetValue(3, last_pnt)
             curve = Geom_BezierCurve(pts)
             path.Add(BRepBuilderAPI_MakeEdge(curve.GetHandle()).Edge())
         elif cmd == 'C':
             # Cubic Bezier
             pts = TColgp_Array1OfPnt(1, 4)
             pts.SetValue(1, last_pnt)
             pts.SetValue(2, gp_Pnt(params[0], params[1], 0))
             pts.SetValue(3, gp_Pnt(params[2], params[3], 0))
             last_pnt = gp_Pnt(params[4], params[5], 0)
             pts.SetValue(4, last_pnt)
             curve = Geom_BezierCurve(pts)
             path.Add(BRepBuilderAPI_MakeEdge(curve.GetHandle()).Edge())
         elif cmd == 'A':
             # Warning: Play at your own risk!
             x1, y1 = last_pnt.X(), last_pnt.Y()
             rx, ry, phi, large_arc_flag, sweep_flag, x2, y2 = params
             phi = radians(phi)
             pnt = gp_Pnt(x2, y2, 0)
             cx, cy, rx, ry = compute_arc_center(
                 x1, y1, rx, ry, phi, large_arc_flag, sweep_flag, x2, y2)
             z_dir = Z_DIR if sweep_flag else NEG_Z_DIR  # sweep_flag
             c = make_ellipse((cx, cy, 0), rx, ry, phi, z_dir)
             curve = GC_MakeArcOfEllipse(c, last_pnt, pnt, True).Value()
             path.Add(BRepBuilderAPI_MakeEdge(curve).Edge())
             last_pnt = pnt
         elif cmd == 'Z':
             path.Add(BRepBuilderAPI_MakeEdge(last_pnt, start_pnt).Edge())
             shapes.append(path.Wire())
             path = None  # Close path
             last_pnt = start_pnt
     if path is not None:
         shapes.append(path.Wire())
     return shapes
Example #8
0
    def update_shape(self, change):
        d = self.declaration
        shape = BRepBuilderAPI_MakeWire()
        for c in self.children():
            convert = self.shape_to_wire
            if isinstance(c.shape, (list, tuple)):
                #: Assume it's a list of drawn objects...
                for item in c.shape:
                    shape.Add(convert(item))
            else:
                shape.Add(convert(c.shape))

        assert shape.IsDone(), 'Edges must be connected'
        self.shape = shape
Example #9
0
 def makeWire(self, edges):
     """
     Topo_DS_Wire makeWire([Topo_DS_Edge, Topo_DS_Edge,...])
     Returns a pythonOCC Wire object constructed
     from the delivered list of Topo_DS_Edges.
     Returns None on failure.
     """
     try:
         wire = BRepBuilderAPI_MakeWire(edges[0])
         del edges[0] 
         for edge in edges: wire.Add(edge)
         return wire
     except Exception:
         traceback.print_exc()
         return None
def makeWire(edges):
    """ Creating Wire
    
    Note the edges have to be added in an order than default. I chose the keep
    the edge numbering in a sensible format (the format shown in the diffuser
    visualization). However, wire.Add() requires that each edge be connected to
    the current wire. The current order goes around the physical loop starting at
    edge0
    """

    wire = BRepBuilderAPI_MakeWire()
    edgeorder = (0, 1, 6, 2, 3, 4, 5)
    for edgen in edgeorder:
        wire.Add(edges[edgen].Edge())
    if args.v >= 1: print('Wire are created')
    return wire
Example #11
0
def wire_triangle2():
    '''
        isosceles triangle
    output
        w:  TopoDS_Wire
    '''
    ang = random.gauss(2 * pi / 3, pi / 6)
    amin = pi / 3
    amax = 5 * pi / 6
    if ang > amax:
        ang = amax
    if ang < amin:
        ang = amin
    pt1 = gp_Pnt(-1, 0, 0)
    pt2 = gp_Pnt(-1, 0, 0)
    pt2.Rotate(gp_OZ(), ang)
    pt3 = gp_Pnt(-1, 0, 0)
    pt3.Rotate(gp_OZ(), -ang)

    ed1 = BRepBuilderAPI_MakeEdge(GC_MakeSegment(pt1, pt2).Value()).Edge()
    ed2 = BRepBuilderAPI_MakeEdge(GC_MakeSegment(pt2, pt3).Value()).Edge()
    ed3 = BRepBuilderAPI_MakeEdge(GC_MakeSegment(pt3, pt1).Value()).Edge()

    wire = BRepBuilderAPI_MakeWire(ed1, ed2, ed3).Wire()

    return wire
def pipe():
    # the bspline path, must be a wire
    array2 = TColgp_Array1OfPnt(1, 3)
    array2.SetValue(1, gp_Pnt(0, 0, 0))
    array2.SetValue(2, gp_Pnt(0, 1, 2))
    array2.SetValue(3, gp_Pnt(0, 2, 3))
    bspline2 = GeomAPI_PointsToBSpline(array2).Curve()
    path_edge = BRepBuilderAPI_MakeEdge(bspline2).Edge()
    path_wire = BRepBuilderAPI_MakeWire(path_edge).Wire()

    # the bspline profile. Profile mist be a wire
    array = TColgp_Array1OfPnt(1, 5)
    array.SetValue(1, gp_Pnt(0, 0, 0))
    array.SetValue(2, gp_Pnt(1, 2, 0))
    array.SetValue(3, gp_Pnt(2, 3, 0))
    array.SetValue(4, gp_Pnt(4, 3, 0))
    array.SetValue(5, gp_Pnt(5, 5, 0))
    bspline = GeomAPI_PointsToBSpline(array).Curve()
    profile_edge = BRepBuilderAPI_MakeEdge(bspline).Edge()

    # pipe
    pipe = BRepOffsetAPI_MakePipe(path_wire, profile_edge).Shape()

    display.DisplayShape(profile_edge, color='WHITE', update=False)
    display.DisplayShape(path_wire, color='BLUE', update=False)
    display.DisplayShape(pipe, update=True)
Example #13
0
def build(input, output):
    #sample xml for testing
    xml = "<eagle version=\"7\"><drawing><board><plain><wire x1=\"0\" y1=\"0\" x2=\"0\" y2=\"2\" width=\"0.254\" layer=\"20\"/><wire x1=\"0\" y1=\"2\" x2=\"1.5\" y2=\"2\" width=\"0.254\" layer=\"20\"/><wire x1=\"1.5\" y1=\"2\" x2=\"1\" y2=\"0\" width=\"0.254\" layer=\"20\"/><wire x1=\"1\" y1=\"0\" x2=\"0\" y2=\"0\" width=\"0.254\" layer=\"20\"/></plain></board></drawing></eagle>"

    #xmldoc = minidom.parseString( xml )

    xmldoc = minidom.parse(input)

    wires = xmldoc.getElementsByTagName('wire')

    makeWire = BRepBuilderAPI_MakeWire()

    for wire in wires:

        if wire.attributes['layer'].value == '20':
            x1 = float(wire.attributes['x1'].value)
            y1 = float(wire.attributes['y1'].value)

            x2 = float(wire.attributes['x2'].value)
            y2 = float(wire.attributes['y2'].value)

            #print('Building edge from  {}, {} to {}, {}'.format( x1,y1,x2,y2))

            edge = BRepBuilderAPI_MakeEdge( gp_Pnt( x1, y1, 0.0 ), \
                                            gp_Pnt( x2, y2, 0.0 ) \
                                                      )

            makeWire.Add(edge.Edge())

    face = BRepBuilderAPI_MakeFace(makeWire.Wire())

    #vector & height
    vector = gp_Vec(0, 0, .1)

    body = BRepPrimAPI_MakePrism(face.Face(), vector)

    # initialize the STEP exporter
    step_writer = STEPControl_Writer()
    Interface_Static_SetCVal("write.step.schema", "AP203")

    # transfer shapes and write file
    step_writer.Transfer(body.Shape(), STEPControl_AsIs)
    status = step_writer.Write(output)

    if status != IFSelect_RetDone:
        raise AssertionError("load failed")
Example #14
0
    def _generate_tip(self, maxDeg):
        """
        Private method to generate the surface that closing the blade tip.

        :param int maxDeg: Define the maximal U degree of generated surface
        """
        self._import_occ_libs()

        generator = BRepOffsetAPI_ThruSections(False, False, 1e-10)
        generator.SetMaxDegree(maxDeg)
        # npoints_up == npoints_down
        npoints = len(self.blade_coordinates_down[-1][0])
        vertices_1 = TColgp_HArray1OfPnt(1, npoints)
        vertices_2 = TColgp_HArray1OfPnt(1, npoints)
        for j in range(npoints):
            vertices_1.SetValue(
                j + 1,
                gp_Pnt(1000 * self.blade_coordinates_down[-1][0][j],
                       1000 * self.blade_coordinates_down[-1][1][j],
                       1000 * self.blade_coordinates_down[-1][2][j]))

            vertices_2.SetValue(
                j + 1,
                gp_Pnt(1000 * self.blade_coordinates_up[-1][0][j],
                       1000 * self.blade_coordinates_up[-1][1][j],
                       1000 * self.blade_coordinates_up[-1][2][j]))

        # Initializes an algorithm for constructing a constrained
        # BSpline curve passing through the points of the blade last
        # section, with tolerance = 1e-9
        bspline_1 = GeomAPI_Interpolate(vertices_1.GetHandle(), False, 1e-9)
        bspline_1.Perform()

        bspline_2 = GeomAPI_Interpolate(vertices_2.GetHandle(), False, 1e-9)
        bspline_2.Perform()

        edge_1 = BRepBuilderAPI_MakeEdge(bspline_1.Curve()).Edge()
        edge_2 = BRepBuilderAPI_MakeEdge(bspline_2.Curve()).Edge()

        # Add BSpline wire to the generator constructor
        generator.AddWire(BRepBuilderAPI_MakeWire(edge_1).Wire())
        generator.AddWire(BRepBuilderAPI_MakeWire(edge_2).Wire())
        # Returns the shape built by the shape construction algorithm
        generator.Build()
        # Returns the Face generated by each edge of the first section
        self.generated_tip = generator.GeneratedFace(edge_1)
Example #15
0
def make_wire(*args):
    # if we get an iterable, than add all edges to wire builder
    if isinstance(args[0], list) or isinstance(args[0], tuple):
        wire = BRepBuilderAPI_MakeWire()
        for i in args[0]:
            wire.Add(i)
        wire.Build()
        return wire.Wire()
    wire = BRepBuilderAPI_MakeWire(*args)
    return wire.Wire()
def make_wire(*args):
    # if we get an iterable, than add all edges to wire builder
    if isinstance(args[0], list) or isinstance(args[0], tuple):
        wire = BRepBuilderAPI_MakeWire()
        for i in args[0]:
            wire.Add(i)
        wire.Build()
        return wire.Wire()

    wire = BRepBuilderAPI_MakeWire(*args)
    wire.Build()
    with assert_isdone(wire, 'failed to produce wire'):
        result = wire.Wire()
        return result
Example #17
0
def face():

    #The brown face
    circle = gp_Circ(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 80)
    Edge1 = BRepBuilderAPI_MakeEdge(circle, 0, math.pi)
    Edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, -80), gp_Pnt(0, -10, 40))
    Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, -10.00001, 40), gp_Pnt(0, 0, 80))

    ##TopoDS_Wire YellowWire
    MW1 = BRepBuilderAPI_MakeWire(Edge1.Edge(), Edge2.Edge(), Edge3.Edge())

    print MW1.IsDone()
    
    if MW1.IsDone():
        yellow_wire = MW1.Wire()
    brown_face = BRepBuilderAPI_MakeFace(yellow_wire)
	
    display.DisplayColoredShape(brown_face.Face(), 'BLUE')
Example #18
0
def boundary_curve_from_2_points(p1, p2):
    # first create an edge
    e0 = BRepBuilderAPI_MakeEdge(p1, p2).Edge()
    w0 = BRepBuilderAPI_MakeWire(e0).Wire()
    # boundary for filling
    adap = BRepAdaptor_CompCurve(w0)
    p0_h = BRepAdaptor_HCompCurve(adap)
    boundary = GeomFill_SimpleBound(p0_h.GetHandle(), 1e-6, 1e-6)
    return boundary.GetHandle()
Example #19
0
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(Topo(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.DisplayColoredShape(FP, 'YELLOW')
    display.FitAll()
Example #20
0
def process_face(face):
    '''traverses a face for wires
    returns a list of wires'''
    wires = []
    explorer = TopExp_Explorer(face, TopAbs_EDGE)
    while explorer.More():
        edge = TopoDS().Edge(explorer.Current())
        wire = BRepBuilderAPI_MakeWire(edge).Wire()
        wires.append(wire)
        explorer.Next()
    return wires
def gen_boxSolidAsTable(width=1000, depth=1000, height=1215):
    pntList = [
        gp_Pnt(width / 2., depth / 2., 0),
        gp_Pnt(-width / 2., depth / 2., 0),
        gp_Pnt(-width / 2., -depth / 2., 0),
        gp_Pnt(width / 2., -depth / 2., 0)
    ]
    edgList = []
    for i in range(0, len(pntList) - 1):
        edgList.append(BRepBuilderAPI_MakeEdge(pntList[i], pntList[i + 1]))
    edgList.append(BRepBuilderAPI_MakeEdge(pntList[3], pntList[0]))

    wire = BRepBuilderAPI_MakeWire()
    for i in edgList:
        wire.Add(i.Edge())
    wireProfile = wire.Wire()
    faceProfile = BRepBuilderAPI_MakeFace(wireProfile).Shape()
    aPrismVec = gp_Vec(0, 0, height)

    return BRepPrimAPI_MakePrism(faceProfile, aPrismVec).Shape()
Example #22
0
def revolved_cut(base):
    # Define 7 points
    face_points = TColgp_Array1OfPnt(1, 7)
    face_inner_radius = 0.6

    pts = [
        gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05),
        gp_Pnt(face_inner_radius - 0.10, 0.0, -0.025),
        gp_Pnt(face_inner_radius - 0.10, 0.0, 0.025),
        gp_Pnt(face_inner_radius + 0.10, 0.0, 0.025),
        gp_Pnt(face_inner_radius + 0.10, 0.0, -0.025),
        gp_Pnt(face_inner_radius + 0.05, 0.0, -0.05),
        gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05),
    ]

    for n, i in enumerate(pts):
        face_points.SetValue(n + 1, i)

    # Use these points to create edges and add these edges to a wire
    hexwire = BRepBuilderAPI_MakeWire()

    for i in range(1, 7):
        hexedge = BRepBuilderAPI_MakeEdge(face_points.Value(i),
                                          face_points.Value(i + 1)).Edge()
        hexwire.Add(hexedge)

    # Turn the wire into a 6 sided face
    hexface = BRepBuilderAPI_MakeFace(hexwire.Wire()).Face()

    # Revolve the face around an axis
    revolve_axis = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
    revolved_shape = BRepPrimAPI_MakeRevol(hexface, revolve_axis).Shape()

    # Move the generated shape
    move = gp_Trsf()
    move.SetTranslation(gp_Pnt(0, 0, 0), gp_Pnt(0, 0, sin(0.5)))
    moved_shape = BRepBuilderAPI_Transform(revolved_shape, move, False).Shape()

    # Remove the revolved shape
    cut = BRepAlgoAPI_Cut(base, moved_shape).Shape()
    return cut
Example #23
0
def wire_circle():
    '''
        standard circle on XY plane, centered at origin, with radius 1

    output
        w:     TopoDS_Wire
    '''
    circ = gp_Circ(DRAIN_RCS, 1.0)
    edge = BRepBuilderAPI_MakeEdge(circ, 0., 2 * pi).Edge()
    wire = BRepBuilderAPI_MakeWire(edge).Wire()

    return wire
Example #24
0
def makeEllipticalAnnularSolid(rx_outer, ry_outer, rx_inner, ry_inner, z_min,
                               z_max):

    # Make the outer part of the clamp
    ax = gp_Ax2(gp_Pnt(0, 0, z_min), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
    ge = Geom_Ellipse(ax, rx_outer, ry_outer)
    elip = ge.Elips()
    me = BRepBuilderAPI_MakeEdge(elip, 0, 2 * pi)
    edge = me.Edge()
    mw = BRepBuilderAPI_MakeWire(edge)
    wire = mw.Wire()
    pln = gp_Pln(gp_Pnt(0, 0, z_min), gp_Dir(0, 0, 1))
    mf = BRepBuilderAPI_MakeFace(pln, wire)
    face = mf.Face()
    mp = BRepPrimAPI_MakePrism(face, gp_Vec(0, 0, z_max - z_min))
    body = mp.Shape()

    # Make the cutter for the inner hole body
    ax = gp_Ax2(gp_Pnt(0, 0, z_min - 1), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
    ge = Geom_Ellipse(ax, rx_inner, ry_inner)
    elip = ge.Elips()
    me = BRepBuilderAPI_MakeEdge(elip, 0, 2 * pi)
    edge = me.Edge()
    mw = BRepBuilderAPI_MakeWire(edge)
    wire = mw.Wire()
    pln = gp_Pln(gp_Pnt(0, 0, z_min - 1), gp_Dir(0, 0, 1))
    mf = BRepBuilderAPI_MakeFace(pln, wire)
    face = mf.Face()
    mp = BRepPrimAPI_MakePrism(face, gp_Vec(0, 0, z_max + 1))
    innerHoleCutter = mp.Shape()

    # Cut out the middle
    mc = BRepAlgoAPI_Cut(body, innerHoleCutter)
    return mc.Shape()
def brep_feat_local_revolution(event=None):
    S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape()
    faces = list(Topo(S).faces())
    F1 = faces[2]
    surf = BRep_Tool_Surface(F1)

    D = gp_OX()

    MW1 = BRepBuilderAPI_MakeWire()
    p1 = gp_Pnt2d(100., 100.)
    p2 = gp_Pnt2d(200., 100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge())

    p1 = gp_Pnt2d(200., 100.)
    p2 = gp_Pnt2d(150., 200.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge())

    p1 = gp_Pnt2d(150., 200.)
    p2 = gp_Pnt2d(100., 100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge())

    MKF1 = BRepBuilderAPI_MakeFace()
    MKF1.Init(surf, False, 1e-6)
    MKF1.Add(MW1.Wire())
    FP = MKF1.Face()
    breplib_BuildCurves3d(FP)
    MKrev = BRepFeat_MakeRevol(S, FP, F1, D, 1, True)
    F2 = faces[4]
    MKrev.Perform(F2)
    display.EraseAll()
    display.DisplayShape(MKrev.Shape())
    display.FitAll()
Example #26
0
def revolved_shape():
    """ demonstrate how to create a revolved shape from an edge

    adapted from algotopia.com's opencascade_basic tutorial:
    http://www.algotopia.com/contents/opencascade/opencascade_basic

    """
    face_inner_radius = 0.6
    # point to create an edge from
    edg_points = [
        gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05),
        gp_Pnt(face_inner_radius - 0.10, 0.0, -0.025),
        gp_Pnt(face_inner_radius - 0.10, 0.0, 0.025),
        gp_Pnt(face_inner_radius + 0.10, 0.0, 0.025),
        gp_Pnt(face_inner_radius + 0.10, 0.0, -0.025),
        gp_Pnt(face_inner_radius + 0.05, 0.0, -0.05),
        gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05),
    ]

    # aggregate edges in wire
    hexwire = BRepBuilderAPI_MakeWire()

    for i in range(6):
        hexedge = BRepBuilderAPI_MakeEdge(edg_points[i],
                                          edg_points[i + 1]).Edge()
        hexwire.Add(hexedge)

    hexwire_wire = hexwire.Wire()
    # face from wire
    hexface = BRepBuilderAPI_MakeFace(hexwire_wire).Face()
    revolve_axis = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
    # create revolved shape
    revolved_shape_ = BRepPrimAPI_MakeRevol(hexface, revolve_axis,
                                            math.radians(90.)).Shape()

    # render wire & revolved shape
    display.DisplayShape([revolved_shape_, hexwire_wire])
    display.FitAll()
    start_display()
Example #27
0
def through_sections():
    #ruled
    circle_1 = gp_Circ(gp_Ax2(gp_Pnt(-100., 0., -100.), gp_Dir(0., 0., 1.)),
                       40.)
    wire_1 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_1).Edge()).Wire()
    circle_2 = gp_Circ(gp_Ax2(gp_Pnt(-10., 0., -0.), gp_Dir(0., 0., 1.)), 40.)
    wire_2 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_2).Edge()).Wire()
    circle_3 = gp_Circ(gp_Ax2(gp_Pnt(-75., 0., 100.), gp_Dir(0., 0., 1.)), 40.)
    wire_3 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_3).Edge()).Wire()
    circle_4 = gp_Circ(gp_Ax2(gp_Pnt(0., 0., 200.), gp_Dir(0., 0., 1.)), 40.)
    wire_4 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_4).Edge()).Wire()

    generatorA = BRepOffsetAPI_ThruSections(False, True)
    # the use of the map function fails at producing the ThruSection
    # on py3k. Why ?
    # map(generatorA.AddWire, [wire_1, wire_2, wire_3, wire_4])
    # we have to use a loop
    for wir in [wire_1, wire_2, wire_3, wire_4]:
        generatorA.AddWire(wir)
    generatorA.Build()
    display.DisplayShape(generatorA.Shape())

    #smooth
    circle_1b = gp_Circ(gp_Ax2(gp_Pnt(100., 0., -100.), gp_Dir(0., 0., 1.)),
                        40.)
    wire_1b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_1b).Edge()).Wire()
    circle_2b = gp_Circ(gp_Ax2(gp_Pnt(210., 0., -0.), gp_Dir(0., 0., 1.)), 40.)
    wire_2b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_2b).Edge()).Wire()
    circle_3b = gp_Circ(gp_Ax2(gp_Pnt(275., 0., 100.), gp_Dir(0., 0., 1.)),
                        40.)
    wire_3b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_3b).Edge()).Wire()
    circle_4b = gp_Circ(gp_Ax2(gp_Pnt(200., 0., 200.), gp_Dir(0., 0., 1.)),
                        40.)
    wire_4b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_4b).Edge()).Wire()
    generatorB = BRepOffsetAPI_ThruSections(True, False)
    # same here, the following line fails
    # map(generatorB.AddWire, [wire_1b, wire_2b, wire_3b, wire_4b])
    for wir in [wire_1b, wire_2b, wire_3b, wire_4b]:
        generatorB.AddWire(wir)
    generatorB.Build()
    display.DisplayShape(generatorB.Shape(), update=True)
Example #28
0
def build_test(path):
    #points
    pt1 = gp_Pnt(0, 0, 0)
    pt2 = gp_Pnt(0, 2, 0)
    pt3 = gp_Pnt(1.5, 2, 0)
    pt4 = gp_Pnt(1, 0, 0)

    edge1 = BRepBuilderAPI_MakeEdge(pt1, pt2)
    edge2 = BRepBuilderAPI_MakeEdge(pt2, pt3)
    edge3 = BRepBuilderAPI_MakeEdge(pt3, pt4)
    edge4 = BRepBuilderAPI_MakeEdge(pt4, pt1)

    #make wire with 4 edges
    wire = BRepBuilderAPI_MakeWire(edge1.Edge(), edge2.Edge(), edge3.Edge(),
                                   edge4.Edge())

    #alternate wire. create and then add in
    #makeWire = BRepBuilderAPI_MakeWire()
    #makeWire.add( wire )
    #wireProfile = makeWire.Wire()

    face = BRepBuilderAPI_MakeFace(wire.Wire())

    #vector & height
    vector = gp_Vec(0, 0, .1)

    body = BRepPrimAPI_MakePrism(face.Face(), vector)

    # initialize the STEP exporter
    step_writer = STEPControl_Writer()
    Interface_Static_SetCVal("write.step.schema", "AP203")

    # transfer shapes and write file
    step_writer.Transfer(body.Shape(), STEPControl_AsIs)
    status = step_writer.Write(path)

    if status != IFSelect_RetDone:
        raise AssertionError("load failed")
Example #29
0
      def makeRect(self,r,h) :

          from OCC.Core.gp import gp_Pnt
          from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeWire
          from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeEdge
          from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeFace

          print("Make Rect")
          wire = BRepBuilderAPI_MakeWire()
          print("Make Points")
          p1 = gp_Pnt(0,0,0)
          p2 = gp_Pnt(r,0,0)
          p3 = gp_Pnt(r,0,h)
          p4 = gp_Pnt(0,0,h)
          print("make Edges")
          wire.Add(BRepBuilderAPI_MakeEdge(p1,p2).Edge())
          wire.Add(BRepBuilderAPI_MakeEdge(p2,p3).Edge())
          wire.Add(BRepBuilderAPI_MakeEdge(p3,p4).Edge())
          wire.Add(BRepBuilderAPI_MakeEdge(p4,p1).Edge())
          print("Make Face")
          face = BRepBuilderAPI_MakeFace(wire.Wire()).Face()
          print("Return Face")
          return face
Example #30
0
    def stitch(self, other):
        """Attempt to stich wires"""

        wire_builder = BRepBuilderAPI_MakeWire()
        wire_builder.Add(topods_Wire(self.wrapped))
        wire_builder.Add(topods_Wire(other.wrapped))
        wire_builder.Build()

        return self.__class__(wire_builder.Wire())