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,
                                    gp_Vec(0., 10., 0.), gp_Vec(0., 0., 0.),
                                    1, True)
    aform.Perform()
    display.DisplayShape(aform.Shape())
    display.FitAll()
示例#2
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, tuple)):
        wire = BRepBuilderAPI_MakeWire()
        for i in args[0]:
            wire.Add(i)
        wire.Build()
        return wire.Wire()
    wire = BRepBuilderAPI_MakeWire(*args)
    assert_isdone(wire, "failed to produce wire")
    return wire.Wire()
示例#4
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)
    wire.Build()
    with assert_isdone(wire, 'failed to produce wire'):
        result = wire.Wire()
        return result
示例#5
0
def extrude_polyline2d(polyline, frame, height):
    pol3d = polyline.to_frame(frame)
    lines = []
    yb_point = Point([frame[0][i] for i in range(3)])
    yb_vec = Vector([frame[1][0][i] for i in range(3)]).unit()
    print '*************'
    print yb_vec
    orig = gp_Pnt(frame[0][0], frame[0][1], frame[0][2])
    vec = gp_Dir(yb_vec[0], yb_vec[1], yb_vec[2])
    plane = gp_Pln(orig, vec)

    for i, p in enumerate(pol3d[:-1]):
        print p
        print 'zob'
        gp0 = gp_Pnt(p[0], p[1], p[2])
        gp1 = gp_Pnt(pol3d[i + 1][0], pol3d[i + 1][1], pol3d[i + 1][2])
        lines.append(BRepBuilderAPI_MakeEdge(gp0, gp1).Edge())

    wire = BRepBuilderAPI_MakeWire(lines[0])

    for l in lines[1:]:
        wire.Add(l)

    face = BRepBuilderAPI_MakeFace(wire.Wire())
    print 'normal'
    print[vec.X(), vec.Y(), vec.Z()]
    extrude = BRepPrimAPI_MakePrism(
        face.Shape(),
        gp_Vec(height * vec.X(), height * vec.Y(), height * vec.Z())).Shape()
    return extrude
示例#6
0
 def display_path(lay, col):
     wire = BRepBuilderAPI_MakeWire()
     for i in range(1, len(lay)):
         if lay[i - 1][0].Distance(lay[i][0]) < 50:
             ray = BRepBuilderAPI_MakeEdge(lay[i - 1][0], lay[i][0]).Edge()
             wire.Add(ray)
     display.DisplayShape(wire.Wire(), color=col, update=False)
示例#7
0
def brep_feat_local_revolution(event=None):
    S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape()
    faces = list(TopologyExplorer(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()
示例#8
0
def main():

    vertices = [gp_Pnt(p[0], p[1], p[2]) for p in mesh['vertices']]
    oFaces = []

    builder = BRep_Builder()
    shell = TopoDS_Shell()
    builder.MakeShell(shell)

    for face in mesh['faces']:
        edges = []
        face.reverse()
        for i in range(len(face)):
            cur = face[i]
            nxt = face[(i + 1) % len(face)]
            segment = GC_MakeSegment(vertices[cur], vertices[nxt])
            edges.append(BRepBuilderAPI_MakeEdge(segment.Value()))

        wire = BRepBuilderAPI_MakeWire()
        for edge in edges:
            wire.Add(edge.Edge())

        oFace = BRepBuilderAPI_MakeFace(wire.Wire())
        builder.Add(shell, oFace.Shape())
    write_stl_file(shell, "./cube_binding.stl")
示例#9
0
def make_revolved_cylinder(pnt, height, revolve_angle, rotation, wall_thick):
    """
    This method demonstrates how to create a revolved shape from a drawn closed edge.
    It currently creates a hollow cylinder

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

    :param pnt:
    :param height:
    :param revolve_angle:
    :param rotation:
    :param wall_thick:
    :type pnt: dict
    :type height: float
    :type revolve_angle: float
    :type rotation: float
    :type wall_thick: float
    """
    from OCC.Core.BRepBuilderAPI import (
        BRepBuilderAPI_MakeEdge,
        BRepBuilderAPI_MakeFace,
        BRepBuilderAPI_MakeWire,
    )
    from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeRevol
    from OCC.Core.gp import gp_Ax1, gp_Dir, gp_Pnt

    face_inner_radius = pnt["X"] + (17.0 - wall_thick / 2) * 1000
    face_outer_radius = pnt["X"] + (17.0 + wall_thick / 2) * 1000

    # point to create an edge from
    edg_points = [
        gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"]),
        gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"] + height),
        gp_Pnt(face_outer_radius, pnt["Y"], pnt["Z"] + height),
        gp_Pnt(face_outer_radius, pnt["Y"], pnt["Z"]),
        gp_Pnt(face_inner_radius, pnt["Y"], pnt["Z"]),
    ]

    # aggregate edges in wire
    hexwire = BRepBuilderAPI_MakeWire()

    for i in range(len(edg_points) - 1):
        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(pnt["X"], pnt["Y"], pnt["Z"]),
                          gp_Dir(0, 0, 1))
    # create revolved shape
    revolved_shape_ = BRepPrimAPI_MakeRevol(hexface, revolve_axis,
                                            np.radians(
                                                float(revolve_angle))).Shape()
    revolved_shape_ = rotate_shp_3_axis(revolved_shape_, revolve_axis,
                                        rotation)

    return revolved_shape_
示例#10
0
文件: occ_utils.py 项目: hducg/CADGen
def face_polygon(pnts):
    wire_maker = BRepBuilderAPI_MakeWire()
    verts = [BRepBuilderAPI_MakeVertex(as_occ(pnt, gp_Pnt)).Vertex() for pnt in pnts]
    for i in range(len(verts)):
        j = (i + 1) % len(verts)
        wire_maker.Add(BRepBuilderAPI_MakeEdge(verts[i], verts[j]).Edge())
        
    return BRepBuilderAPI_MakeFace(wire_maker.Wire()).Face() 
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()
示例#12
0
def __make_wire(lst):
    mk = BRepBuilderAPI_MakeWire()

    for ptr in lst:
        if ptr.Shape().ShapeType() == TopAbs_WIRE:
            mk.Add(ptr.Wire())
        elif ptr.Shape().ShapeType() == TopAbs_EDGE:
            mk.Add(ptr.Edge())

    return mk.Wire()
示例#13
0
def _make_wire(arr):
    mk = BRepBuilderAPI_MakeWire()

    for ptr in arr:
        if (ptr.Shape().ShapeType() == TopAbs_WIRE):
            mk.Add(ptr.Wire())
        elif (ptr.Shape().ShapeType() == TopAbs_EDGE):
            mk.Add(ptr.Edge())

    return Shape(mk.Wire())
示例#14
0
    def __init__(self, *edges):
        # Build
        builder = BRepBuilderAPI_MakeWire()
        for e in edges:
            if e is not None and not e.is_null and e.is_edge:
                builder.Add(e.object)

        self._w = Wire(builder.Wire())
        self._last_e = Edge(builder.Edge())
        self._last_v = Vertex(builder.Vertex())
示例#15
0
def holes_in_face():
    aPlane = gp_Pln()
    print(type(gp_Pln()))
    print(type(gp_XOY()))

    aCircle1 = gp_Circ(gp_XOY(), 1.0)
    aCircle2 = gp_Circ(gp_XOY(), 1.0)
    aCircle3 = gp_Circ(gp_XOY(), 1.0)

    aCircle1.SetLocation(gp_Pnt(3.0, 3.0, 0.0))
    aCircle2.SetLocation(gp_Pnt(7.0, 3.0, 0.0))
    aCircle3.SetLocation(gp_Pnt(3.0, 7.0, 0.0))

    anEdgeMaker1 = BRepBuilderAPI_MakeEdge(aCircle1)
    anEdgeMaker2 = BRepBuilderAPI_MakeEdge(aCircle2)
    anEdgeMaker3 = BRepBuilderAPI_MakeEdge(aCircle3)

    aWireMaker1 = BRepBuilderAPI_MakeWire(anEdgeMaker1.Edge())
    aWireMaker2 = BRepBuilderAPI_MakeWire(anEdgeMaker2.Edge())
    aWireMaker3 = BRepBuilderAPI_MakeWire(anEdgeMaker3.Edge())

    aFaceMaker = BRepBuilderAPI_MakeFace(aPlane, 0.0, 10.0, 0.0, 10.0)

    if aWireMaker1.IsDone():
        aWire1 = aWireMaker1.Wire()
        aWire1.Reverse()  # Makes this a hole in outer profile
        aFaceMaker.Add(aWire1)

    if aWireMaker2.IsDone():
        aWire2 = aWireMaker2.Wire()
        aWire2.Reverse()  # Makes this a hole in outer profile
        aFaceMaker.Add(aWire2)

    if aWireMaker3.IsDone():
        aWire3 = aWireMaker3.Wire()
        aWire3.Reverse()  # Makes this a hole in outer profile
        aFaceMaker.Add(aWire3)

    if not aFaceMaker.IsDone():
        raise AssertionError("shape not Done.")

    return aFaceMaker.Shape()
 def generate_planar_slices(nozz_dia, sur_nozz_dia):
     xmin, ymin, zmin, xmax, ymax, zmax = get_boundingbox(part_shape)
     print(xmax - xmin, ",", ymax - ymin, ",", zmax - zmin)
     wires = []
     slices = []
     contours = []
     for z in numpy.arange(zmin+(nozz_dia/2)+(sur_nozz_dia/2), \
      zmax-(nozz_dia/2)-(sur_nozz_dia/2), nozz_dia):
         plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0., 1.))
         slices.append(Slicing.plane_shape_intersection(plane, part_shape))
     for s in range(0, len(slices)):
         wire = []
         wires.append([])
         while len(slices[s]) != 0:
             for i in range(0, len(slices[s])):
                 if len(wire) == 0:
                     wire.append(slices[s][i])
                     slices[s].remove(slices[s][i])
                     break
                 elif Slicing.do_edges_connect(slices[s][i], wire[-1]):
                     wire.append(slices[s][i])
                     slices[s].remove(slices[s][i])
                     break
             if Slicing.do_edges_connect(wire[0], wire[-1]):
                 if len(wire) > 2:
                     wires[s].append(wire)
                     wire = []
                 elif len(wire) == 2 and Slicing.do_edges_loop(
                         wire[0], wire[-1]):
                     wires[s].append(wire)
                     wire = []
     for k in range(0, len(wires)):
         contours.append([])
         for l in range(0, len(wires[k])):
             make_wire = BRepBuilderAPI_MakeWire()
             for edge in wires[k][l]:
                 make_wire.Add(edge)
             try:
                 made_wire = make_wire.Wire()
                 contours[k].append(made_wire)
             except:
                 print("Skipped a contour!")
                 continue
     contour_faces = []
     for contour in contours:
         if len(contour) == 1:
             contour_faces.append(
                 BRepBuilderAPI_MakeFace(contour[0]).Face())
         else:
             contour_faces.extend(Slicing.get_layer_faces(contour))
     # for l in range(0,len(contour_faces)):
     #   display.DisplayShape(contour_faces[l], color=colour[l%5],\
     #   	transparency=0.95, update=True)
     return contour_faces
示例#17
0
文件: __init__.py 项目: ocastrup/OCX
 def __init__(self, edges):
     super().__init__()
     self.wire = None
     mkwire = BRepBuilderAPI_MakeWire()
     if isinstance(edges, TopoDS_Edge):
         mkwire.Add(edges)
         self.done = True
         self.wire = mkwire.Wire()
     elif len(edges) > 0:
         for edge in edges:
             if isinstance(edge, list):
                 for e in edge:
                     mkwire.Add(e)
             else:
                 mkwire.Add(edge)
         if not mkwire.IsDone():
             OCCWrapper.OccError('OccWire', mkwire)
         else:
             self.done = True
             self.wire = mkwire.Wire()
     return
示例#18
0
def face_polyline3d(pol3d):
    from OCC.Core.TopoDS import topods
    lines = []
    for i, p in enumerate(pol3d[:-1]):
        gp0 = gp_Pnt(p[0], p[1], p[2])
        gp1 = gp_Pnt(pol3d[i + 1][0], pol3d[i + 1][1], pol3d[i + 1][2])
        lines.append(BRepBuilderAPI_MakeEdge(gp0, gp1).Edge())
    wire = BRepBuilderAPI_MakeWire(lines[0])
    for l in lines[1:]:
        wire.Add(l)
    face = BRepBuilderAPI_MakeFace(wire.Wire())
    return face
示例#19
0
 def makeWire(self):
     """Generate a wire from the edges in self.edgeList."""
     wireBldr = BRepBuilderAPI_MakeWire()
     occ_seq = TopTools_ListOfShape()
     for edge in self.edgeList:
         occ_seq.Append(edge)
     wireBldr.Add(occ_seq)
     if wireBldr.IsDone():
         self.wire = wireBldr.Wire()
         status = True
     else:
         status = False
     return status
 def display_path(lay, col, nozz_dia=0):
     wire = BRepBuilderAPI_MakeWire()
     for i in range(1, len(lay)):
         if lay[i - 1][0].Distance(lay[i][0]) < 8 and i < len(lay) - 1:
             ray = BRepBuilderAPI_MakeEdge(lay[i - 1][0], lay[i][0]).Edge()
             wire.Add(ray)
         else:
             display.DisplayShape(wire.Wire(), color=col, update=False)
             wire = BRepBuilderAPI_MakeWire()
         if i < len(lay) - 1:
             display.DisplayShape(ray, color=col, update=False)
         else:
             display.DisplayShape(ray, color=col, update=True)
def brepfeat_prism(event=None):
    box = BRepPrimAPI_MakeBox(400, 250, 300).Shape()
    faces = TopologyExplorer(box).faces()

    for i in range(5):
        face = next(faces)

    srf = BRep_Tool_Surface(face)

    c = gp_Circ2d(gp_Ax2d(gp_Pnt2d(200, 130),
                          gp_Dir2d(1, 0)), 75)

    circle = Geom2d_Circle(c)

    wire = BRepBuilderAPI_MakeWire()
    wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, 0., pi).Edge())
    wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, pi, 2. * pi).Edge())
    wire.Build()

    display.DisplayShape(wire.Wire())

    mkf = BRepBuilderAPI_MakeFace()
    mkf.Init(srf, False, 1e-6)
    mkf.Add(wire.Wire())
    mkf.Build()

    new_face = mkf.Face()
    breplib_BuildCurves3d(new_face)

    display.DisplayShape(new_face)

    prism = BRepFeat_MakeDPrism(box, mkf.Face(), face, 100, True, True)

    prism.Perform(400)
    assert prism.IsDone()
    display.EraseAll()
    display.DisplayShape(prism.Shape())
    display.DisplayColoredShape(wire.Wire(), 'RED')
    display.FitAll()
示例#22
0
def makeWholeWire():
    global myWireProfile
    xAxis = gp_OX()
    # Set up the mirror
    aTrsf = gp_Trsf()
    aTrsf.SetMirror(xAxis)
    # Apply the mirror transform
    aBRepTrsf = BRepBuilderAPI_Transform(aWire, aTrsf)
    # Convert mirrored shape to a wire
    aMirroredShape = aBRepTrsf.Shape()
    aMirroredWire = topods_Wire(aMirroredShape)
    # Combine the two wires
    mkWire = BRepBuilderAPI_MakeWire()
    mkWire.Add(aWire)
    mkWire.Add(aMirroredWire)
    myWireProfile = mkWire.Wire()
    return myWireProfile
示例#23
0
 def make_wire(edges, fillets=None):
     # the wire
     # print("adding wire")
     makeWire = BRepBuilderAPI_MakeWire()
     makeWire.Add(edges[0])
     if fillets is None:
         for edge in edges[1:]:
             makeWire.Add(edge)
     else:
         for fillet, edge in zip(fillets, edges[1:]):
             makeWire.Add(fillet)
             makeWire.Add(edge)
     # print("build wire")
     makeWire.Build()
     # print("make wire")
     wire = makeWire.Wire()
     return wire
示例#24
0
文件: __init__.py 项目: ocastrup/OCX
 def __init__(self, center: numpy.array, normal: numpy.array,
              radius: float):
     super().__init__()
     self.wire = TopoDS_Wire
     gpCenter = OccPoint(center)
     gpVec = OccVector(normal)
     mkcircle = GC_MakeCircle(gpCenter.Value(), gpVec.Value(), radius)
     if not mkcircle.IsDone():
         OCCWrapper.OccError('OccCircle', mkcircle)
     else:
         mkwire = BRepBuilderAPI_MakeWire(mkcircle.Value())
         if not mkwire.IsDone():
             OCCWrapper.OccError('OccCircle', mkwire)
         else:
             self.done = True
             self.w = mkwire.Wire()
     return
示例#25
0
 def makeSqProfile(self, size):
     # points and segments need to be in CW sequence to get W pointing along Z
     p1 = gp_Pnt(-size, size, 0).Transformed(self.Trsf)
     p2 = gp_Pnt(size, size, 0).Transformed(self.Trsf)
     p3 = gp_Pnt(size, -size, 0).Transformed(self.Trsf)
     p4 = gp_Pnt(-size, -size, 0).Transformed(self.Trsf)
     seg1 = GC_MakeSegment(p1, p2).Value()
     seg2 = GC_MakeSegment(p2, p3).Value()
     seg3 = GC_MakeSegment(p3, p4).Value()
     seg4 = GC_MakeSegment(p4, p1).Value()
     e1 = BRepBuilderAPI_MakeEdge(seg1).Edge()
     e2 = BRepBuilderAPI_MakeEdge(seg2).Edge()
     e3 = BRepBuilderAPI_MakeEdge(seg3).Edge()
     e4 = BRepBuilderAPI_MakeEdge(seg4).Edge()
     aWire_mkr = BRepBuilderAPI_MakeWire(e1, e2, e3, e4)
     myWireProfile = aWire_mkr.Wire()
     return myWireProfile  # TopoDS_Wire
示例#26
0
文件: __init__.py 项目: ocastrup/OCX
 def __init__(self, p1: numpy.array, p2: numpy.array, p3: numpy.array):
     # p1, p2, p3: Three points on a circle. Cannot be colinear
     super().__init__()
     self.wire = TopoDS_Wire
     gp1 = OccPoint(p1)
     gp2 = OccPoint(p2)
     gp3 = OccPoint(p3)
     mkcircle = GC_MakeCircle(gp1.Value(), gp3.Value(), gp2.Value())
     if not mkcircle.IsDone():
         OCCWrapper.OccError(type(self), mkcircle)
     else:
         mkwire = BRepBuilderAPI_MakeWire(mkcircle.Value())
         if not mkwire.IsDone():
             OCCWrapper.OccError(type(self), mkwire)
         else:
             self.done = True
             self.wire = mkwire.Wire()
     return
示例#27
0
 def makeSqProfile(self, size):
     # points and segments need to be in CW sequence to get W pointing along Z
     p1 = gp_Pnt2d(-size, size)
     p2 = gp_Pnt2d(size, size)
     p3 = gp_Pnt2d(size, -size)
     p4 = gp_Pnt2d(-size, -size)
     seg1 = GCE2d_MakeSegment(p1, p2)
     seg2 = GCE2d_MakeSegment(p2, p3)
     seg3 = GCE2d_MakeSegment(p3, p4)
     seg4 = GCE2d_MakeSegment(p4, p1)
     e1 = BRepBuilderAPI_MakeEdge(seg1.Value(), self.plane)
     e2 = BRepBuilderAPI_MakeEdge(seg2.Value(), self.plane)
     e3 = BRepBuilderAPI_MakeEdge(seg3.Value(), self.plane)
     e4 = BRepBuilderAPI_MakeEdge(seg4.Value(), self.plane)
     aWire = BRepBuilderAPI_MakeWire(e1.Edge(), e2.Edge(), e3.Edge(),
                                     e4.Edge())
     myWireProfile = aWire.Wire()
     return myWireProfile  # TopoDS_Wire
示例#28
0
def makeWholeWire(event=None):
    global myWireProfile
    xAxis = gp_OX()
    # Set up the mirror
    aTrsf = gp_Trsf()
    aTrsf.SetMirror(xAxis)
    # Apply the mirror transform
    aBRepTrsf = BRepBuilderAPI_Transform(aWire, aTrsf)
    # Convert mirrored shape to a wire
    aMirroredShape = aBRepTrsf.Shape()
    aMirroredWire = topods_Wire(aMirroredShape)
    # Combine the two wires
    mkWire = BRepBuilderAPI_MakeWire()
    mkWire.Add(aWire)
    mkWire.Add(aMirroredWire)
    myWireProfile = mkWire.Wire()
    display.DisplayColoredShape(myWireProfile, 'BLUE')
    display.Repaint()
    win.statusBar().showMessage('Make whole wire complete')
示例#29
0
def _polysegment(pnts, closed=False) -> Shape:
    if len(pnts) <= 1:
        raise Exception("Need at least two points for polysegment")

    mkWire = BRepBuilderAPI_MakeWire()

    def __make_edge(a, b):
        try:
            return BRepBuilderAPI_MakeEdge(to_Pnt(a), to_Pnt(b)).Edge()
        except:
            raise Exception(f"Cannot make edge segment from points {a}, {b}")

    for i in range(len(pnts) - 1):
        mkWire.Add(__make_edge(pnts[i], pnts[i + 1]))

    if (closed):
        mkWire.Add(__make_edge(pnts[len(pnts) - 1], pnts[0]))

    return Shape(mkWire.Wire())
示例#30
0
    def create_model(self):
        boltCylinderex = BRepPrimAPI_MakeCylinder(
            gp_Ax2(getGpPt(self.p1), getGpDir(-self.shaftDir)), self.r,
            self.cylex_length).Shape()
        boltCylinder1 = BRepPrimAPI_MakeCylinder(
            gp_Ax2(getGpPt(self.p1), getGpDir(self.shaftDir)), self.r,
            self.cyl1_length).Shape()
        boltCylinder2 = BRepPrimAPI_MakeCylinder(
            gp_Ax2(getGpPt(self.p2), getGpDir(self.cyl2_angle)), self.r,
            self.cyl2_ht).Shape()
        boltCylinder3 = BRepPrimAPI_MakeCylinder(
            gp_Ax2(getGpPt(self.p3), getGpDir(self.shaftDir)), self.r,
            self.cyl3_length).Shape()
        boltCylinder4 = BRepPrimAPI_MakeCylinder(
            gp_Ax2(getGpPt(self.p6), getGpDir(-self.shaftDir)), self.r,
            self.cyl5_length).Shape()

        sphere1 = BRepPrimAPI_MakeSphere(getGpPt(self.p2), self.r).Shape()
        sphere2 = BRepPrimAPI_MakeSphere(getGpPt(self.p3), self.r).Shape()

        edg_points = gp_Circ(gp_Ax2(getGpPt(self.p4), getGpDir(self.shaftDir)),
                             self.r)
        hexwire = BRepBuilderAPI_MakeWire()
        hexedge = BRepBuilderAPI_MakeEdge(edg_points).Edge()
        hexwire.Add(hexedge)
        hexwire_wire = hexwire.Wire()
        hexface = BRepBuilderAPI_MakeFace(hexwire_wire).Face()
        revolve_axis = gp_Ax1(getGpPt(self.p5), gp_Dir(0, -1, 0))
        revolved_shape = BRepPrimAPI_MakeRevol(hexface, revolve_axis,
                                               math.radians(180.)).Shape()

        Anchor_BOlt = BRepAlgoAPI_Fuse(boltCylinder1, boltCylinder2).Shape()
        Anchor_BOlt = BRepAlgoAPI_Fuse(boltCylinder3, Anchor_BOlt).Shape()
        Anchor_BOlt = BRepAlgoAPI_Fuse(revolved_shape, Anchor_BOlt).Shape()
        Anchor_BOlt = BRepAlgoAPI_Fuse(boltCylinder4, Anchor_BOlt).Shape()

        Anchor_BOlt = BRepAlgoAPI_Fuse(sphere1, Anchor_BOlt).Shape()
        Anchor_BOlt = BRepAlgoAPI_Fuse(sphere2, Anchor_BOlt).Shape()

        Anchor_BOlt = BRepAlgoAPI_Fuse(boltCylinderex, Anchor_BOlt).Shape()

        return Anchor_BOlt