コード例 #1
0
def _make_face(surf, u1=None, u2=None, v1=None, v2=None):
    if u1 is None:
        u1, u2, v1, v2 = surf.Surface().Bounds()

    algo = BRepBuilderAPI_MakeFace(surf.Surface(), u1, u2, v1, v2, 1e-6)
    algo.Build()
    return Shape(algo.Face())
コード例 #2
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()
コード例 #3
0
def makeFace(event=None):
    global myFaceProfile
    myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile)
    if myFaceProfile.IsDone():
        bottomFace = myFaceProfile.Face()
    display.DisplayShape(bottomFace, color='YELLOW', transparency=0.6)
    display.Repaint()
    win.statusBar().showMessage('Make face complete')
コード例 #4
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(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()
コード例 #5
0
ファイル: __init__.py プロジェクト: ocastrup/OCX
 def __init__(self, wire: TopoDS_Wire):
     super().__init__()
     mkface = BRepBuilderAPI_MakeFace(wire)
     if not mkface.IsDone():
         OCCWrapper.OccError('OccFaceFromWire', mkface)
     else:
         self.done = True
         self.face = mkface.Face()
     return
コード例 #6
0
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()
コード例 #7
0
def heightmap_from_image(event=None):
    """ takes the heightmap from a jpeg file
    and apply a texture
    this example requires numpy/matplotlib
    """
    print("opening image")
    heightmap = Image.open('../assets/images/mountain_heightmap.jpg')
    heightmap.show()
    width = heightmap.size[0]
    height = heightmap.size[1]
    # create the gp_Pnt array
    print("image size: ", width, height)
    print("parse image and fill in point array")
    for i in range(1, width):
        for j in range(1, height):
            # all 3 RGB values are equal, just take the first one
            # vertex 1
            height_value = heightmap.getpixel((i - 1, j - 1))[0]
            v1 = gp_Pnt(i, j, float(height_value) / 10)
            # vertex 2
            height_value = heightmap.getpixel((i, j - 1))[0]
            v2 = gp_Pnt(i + 1, j, float(height_value) / 10)
            # vertex 3
            height_value = heightmap.getpixel((i, j))[0]
            v3 = gp_Pnt(i + 1, j + 1, float(height_value) / 10)
            # vertex 4
            height_value = heightmap.getpixel((i - 1, j))[0]
            v4 = gp_Pnt(i, j + 1, float(height_value) / 10)
            # boundaries
            b1 = boundary_curve_from_2_points(v1, v2)
            b2 = boundary_curve_from_2_points(v2, v3)
            b3 = boundary_curve_from_2_points(v3, v4)
            b4 = boundary_curve_from_2_points(v4, v1)
            #
            bConstrainedFilling = GeomFill_ConstrainedFilling(8, 2)
            bConstrainedFilling.Init(b1, b2, b3, b4, False)
            srf1 = bConstrainedFilling.Surface()
            # make a face from this srf
            patch = BRepBuilderAPI_MakeFace()
            bounds = True
            toldegen = 1e-6
            patch.Init(srf1, bounds, toldegen)
            patch.Build()
            display.DisplayShape(patch.Face())
            # then create faces
        print("%s%%" % int(float(i) / width * 100))
        #display.process_events()
    display.FitAll()
    # finally display image
    heightmap.show()
コード例 #8
0
def add_wire_to_face(face, wire, reverse=False):
    '''
    apply a wire to a face
    use reverse to set the orientation of the wire to opposite
    @param face:
    @param wire:
    @param reverse:
    '''
    face = BRepBuilderAPI_MakeFace(face)
    if reverse:
        wire.Reverse()
    face.Add(wire)
    result = face.Face()
    face.Delete()
    return result
コード例 #9
0
 def make_PolyPlane(self, num=6, radi=1.0, shft=0.0, axs=gp_Ax3()):
     lxy = radi - 0.1
     pnts = []
     angl = 360 / num
     for i in range(num):
         thet = np.deg2rad(i * angl) + np.deg2rad(shft)
         x, y = radi * np.sin(thet), radi * np.cos(thet)
         pnts.append(gp_Pnt(x, y, 0))
     pnts.append(pnts[0])
     poly = make_polygon(pnts)
     brep = BRepBuilderAPI_MakeFace(gp_Pln(), poly)
     brep.Add(poly)
     face = brep.Face()
     face.Location(set_loc(gp_Ax3(), axs))
     return face
コード例 #10
0
def _fill(wires):
    if not isinstance(wires, (list, tuple)):
        return Shape(BRepBuilderAPI_MakeFace(wires.Wire_orEdgeToWire()).Face())

    algo = BRepBuilderAPI_MakeFace(wires[0].Wire_orEdgeToWire())

    for i in range(1, len(wires)):
        algo.Add(wires[i].Wire_orEdgeToWire())

    algo.Build()

    fixer = ShapeFix_Face(algo.Face())
    fixer.Perform()
    fixer.FixOrientation()
    return Shape(fixer.Face())
コード例 #11
0
    def make_shape(self):
        # 1 - retrieve the data from the UIUC airfoil data page
        foil_dat_url = 'http://m-selig.ae.illinois.edu/ads/coord_seligFmt/%s.dat' % self.profile
        # explicitly tell to not use ssl verification
        ssl._create_default_https_context = ssl._create_unverified_context
        print("Connecting to m-selig, retrieving foil data")
        f = urllib2.urlopen(foil_dat_url)
        print("Building foil geometry")
        plan = gp_Pln(gp_Pnt(0., 0., 0.), gp_Dir(0., 0.,
                                                 1.))  # Z=0 plan / XY plan
        section_pts_2d = []

        for line in f.readlines()[1:]:  # The first line contains info only
            # 2 - do some cleanup on the data (mostly dealing with spaces)
            data = line.split()
            # 3 - create an array of points
            if len(data) == 2:  # two coordinates for each point
                section_pts_2d.append(
                    gp_Pnt2d(
                        float(data[0]) * self.chord,
                        float(data[1]) * self.chord))

        # 4 - use the array to create a spline describing the airfoil section
        spline_2d = Geom2dAPI_PointsToBSpline(
            point2d_list_to_TColgp_Array1OfPnt2d(section_pts_2d),
            len(section_pts_2d) - 1,  # order min
            len(section_pts_2d))  # order max
        spline = geomapi.To3d(spline_2d.Curve(), plan)

        # 5 - figure out if the trailing edge has a thickness or not,
        # and create a Face
        try:
            #first and last point of spline -> trailing edge
            trailing_edge = make_edge(
                gp_Pnt(section_pts_2d[0].X(), section_pts_2d[0].Y(), 0.0),
                gp_Pnt(section_pts_2d[-1].X(), section_pts_2d[-1].Y(), 0.0))
            face = BRepBuilderAPI_MakeFace(
                make_wire([make_edge(spline), trailing_edge]))
        except AssertionError:
            # the trailing edge segment could not be created, probably because
            # the points are too close
            # No need to build a trailing edge
            face = BRepBuilderAPI_MakeFace(make_wire(make_edge(spline)))

        # 6 - extrude the Face to create a Solid
        return BRepPrimAPI_MakePrism(
            face.Face(), gp_Vec(gp_Pnt(0., 0., 0.),
                                gp_Pnt(0., 0., self.span))).Shape()
コード例 #12
0
 def make_PolySurf(self, num=6, radi=1.0, shft=0.0, axs=gp_Ax3()):
     lxy = radi - 0.1
     pnts = []
     angl = 360 / num
     for i in range(num):
         thet = np.deg2rad(i * angl) + np.deg2rad(shft)
         x, y = radi * np.sin(thet), radi * np.cos(thet)
         pnts.append(gp_Pnt(x, y, 0))
     pnts.append(pnts[0])
     poly = make_polygon(pnts)
     proj = BRepProj_Projection(poly, self.surf, gp_Pnt(0, 0, 10))
     # print(proj.Current())
     brep = BRepBuilderAPI_MakeFace(self.surf, poly)
     # brep.Add(poly)
     face = brep.Face()
     face.Location(set_loc(gp_Ax3(), axs))
     return face
コード例 #13
0
ファイル: CutSurf_fix.py プロジェクト: tnakaicode/GeomSurf
    proj = BRepProj_Projection(poly_1, face, axis.Direction())
    bound_poly_1 = proj.Current()

    axis_2 = axis.Transformed(trsf)
    axis_2.Translate(gp_Pnt(0, 0, 0), gp_Pnt(0, 2, 0))
    poly_2 = obj.make_PolyWire(num=10, axs=axis_2)
    proj = BRepProj_Projection(poly_2, face, axis.Direction())
    bound_poly_2 = proj.Current()

    proj = BRepProj_Projection(poly_0, face, axis.Direction())
    bound_poly = proj.Current()
    print(bound_poly)
    print(surf)
    api = BRepBuilderAPI_MakeFace(surf, 1.0)
    api.Add(bound_poly)
    bound_face = api.Face()
    print(api.IsDone())
    #api = BRepBuilderAPI_MakeFace(bound_face, bound_poly_1)
    #bound_face = api.Face()

    print(face.Location().Transformation())
    obj.display.DisplayShape(face, color="BLUE", transparency=0.9)
    obj.display.DisplayShape(bound_face, color="RED", transparency=0.9)
    obj.display.DisplayShape(poly_0)
    obj.display.DisplayShape(poly_1)
    obj.display.DisplayShape(poly_2)
    obj.display.DisplayShape(bound_poly_0)
    obj.display.DisplayShape(bound_poly_1)
    obj.display.DisplayShape(bound_poly_2)
    obj.display.DisplayShape(bound_poly)
コード例 #14
0
def make_face(*args):
    face = BRepBuilderAPI_MakeFace(*args)
    assert face.IsDone()
    result = face.Face()
    return result
コード例 #15
0
def make_face(*args):
    face = BRepBuilderAPI_MakeFace(*args)
    if not face.IsDone():
        raise AssertionError("Face not done")
    result = face.Face()
    return result
コード例 #16
0
 def __init__(self, pln, umin, umax, vmin, vmax):
     builder = BRepBuilderAPI_MakeFace(pln.gp_pln, umin, umax, vmin, vmax)
     self._f = Face(builder.Face())
コード例 #17
0
# A wire instead of a generic shape now
aMirroredWire = topods.Wire(aMirroredShape)

# Combine the two constituent wires
mkWire = BRepBuilderAPI_MakeWire()
mkWire.Add(aWire.Wire())
mkWire.Add(aMirroredWire)
myWireProfile = mkWire.Wire()

# The face that we'll sweep to make the prism
myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile)

# We want to sweep the face along the Z axis to the height
aPrismVec = gp_Vec(0, 0, height)
myBody_step1 = BRepPrimAPI_MakePrism(myFaceProfile.Face(), aPrismVec)

# Add fillets to all edges through the explorer
mkFillet = BRepFilletAPI_MakeFillet(myBody_step1.Shape())
anEdgeExplorer = TopExp_Explorer(myBody_step1.Shape(), TopAbs_EDGE)

while anEdgeExplorer.More():
    anEdge = topods.Edge(anEdgeExplorer.Current())
    mkFillet.Add(thickness / 12.0, anEdge)

    anEdgeExplorer.Next()

# Create the neck of the bottle
neckLocation = gp_Pnt(0, 0, height)
neckAxis = gp_DZ()
neckAx2 = gp_Ax2(neckLocation, neckAxis)
コード例 #18
0
def cut_out(base):
    outer = gp_Circ2d(gp_OX2d(), top_radius - 1.75 * roller_diameter)
    inner = gp_Circ2d(gp_OX2d(), center_radius + 0.75 * roller_diameter)

    geom_outer = GCE2d_MakeCircle(outer).Value()
    geom_inner = GCE2d_MakeCircle(inner).Value()
    geom_inner.Reverse()

    base_angle = (2. * M_PI) / mounting_hole_count
    hole_angle = atan(hole_radius / mounting_radius)
    correction_angle = 3 * hole_angle

    left = gp_Lin2d(gp_Origin2d(), gp_DX2d())
    right = gp_Lin2d(gp_Origin2d(), gp_DX2d())
    left.Rotate(gp_Origin2d(), correction_angle)
    right.Rotate(gp_Origin2d(), base_angle - correction_angle)

    geom_left = GCE2d_MakeLine(left).Value()
    geom_right = GCE2d_MakeLine(right).Value()

    inter_1 = Geom2dAPI_InterCurveCurve(geom_outer, geom_left)
    inter_2 = Geom2dAPI_InterCurveCurve(geom_outer, geom_right)
    inter_3 = Geom2dAPI_InterCurveCurve(geom_inner, geom_right)
    inter_4 = Geom2dAPI_InterCurveCurve(geom_inner, geom_left)

    if inter_1.Point(1).X() > 0:
        p1 = inter_1.Point(1)
    else:
        p1 = inter_1.Point(2)

    if inter_2.Point(1).X() > 0:
        p2 = inter_2.Point(1)
    else:
        p2 = inter_2.Point(2)

    if inter_3.Point(1).X() > 0:
        p3 = inter_3.Point(1)
    else:
        p3 = inter_3.Point(2)

    if inter_4.Point(1).X() > 0:
        p4 = inter_4.Point(1)
    else:
        p4 = inter_4.Point(2)

    trimmed_outer = GCE2d_MakeArcOfCircle(outer, p1, p2).Value()
    trimmed_inner = GCE2d_MakeArcOfCircle(inner, p4, p3).Value()

    plane = gp_Pln(gp_Origin(), gp_DZ())

    arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_outer, plane)).Edge()

    lin1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p2.X(), p2.Y(), 0),
                                   gp_Pnt(p3.X(), p3.Y(), 0)).Edge()

    arc2 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_inner, plane)).Edge()

    lin2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p4.X(), p4.Y(), 0),
                                   gp_Pnt(p1.X(), p1.Y(), 0)).Edge()

    cutout_wire = BRepBuilderAPI_MakeWire(arc1)
    cutout_wire.Add(lin1)
    cutout_wire.Add(arc2)
    cutout_wire.Add(lin2)

    # Turn the wire into a face
    cutout_face = BRepBuilderAPI_MakeFace(cutout_wire.Wire())
    filleted_face = BRepFilletAPI_MakeFillet2d(cutout_face.Face())

    explorer = BRepTools_WireExplorer(cutout_wire.Wire())
    while explorer.More():
        vertex = explorer.CurrentVertex()
        filleted_face.AddFillet(vertex, roller_radius)
        explorer.Next()

    cutout = BRepPrimAPI_MakePrism(filleted_face.Shape(),
                                   gp_Vec(0.0, 0.0, thickness)).Shape()

    result = base
    rotate = gp_Trsf()
    for i in range(0, mounting_hole_count):
        rotate.SetRotation(gp_OZ(), i * 2. * M_PI / mounting_hole_count)
        rotated_cutout = BRepBuilderAPI_Transform(cutout, rotate, True)

        result = BRepAlgoAPI_Cut(result,
                                 rotated_cutout.Shape()).Shape()

    return result
コード例 #19
0
    def write_face(self, points_face, list_points_edge, topo_face, toledge):
        """
        Method to recreate a Face associated to a geometric surface
        after the modification of Face points. It returns a TopoDS_Face.

        :param points_face: the new face points array.
        :param list_points_edge: new edge points
        :param topo_face: the face to be modified
        :param toledge: tolerance on the surface creation after modification
        :return: TopoDS_Face (Shape)

        :rtype: TopoDS_Shape

        """

        # convert Face to Geom B-spline Surface
        nurbs_converter = BRepBuilderAPI_NurbsConvert(topo_face)
        nurbs_converter.Perform(topo_face)
        nurbs_face = nurbs_converter.Shape()
        topo_nurbsface = topods.Face(nurbs_face)
        h_geomsurface = BRep_Tool.Surface(topo_nurbsface)
        h_bsurface = geomconvert_SurfaceToBSplineSurface(h_geomsurface)
        bsurface = h_bsurface

        nb_u = bsurface.NbUPoles()
        nb_v = bsurface.NbVPoles()
        # check consistency
        if points_face.shape[0] != nb_u * nb_v:
            raise ValueError("Input control points do not have not have the "
                             "same number as the geometric face!")

        # cycle on the face points
        indice_cpt = 0
        for iu in range(1, nb_u + 1):
            for iv in range(1, nb_v + 1):
                cpt = points_face[indice_cpt]
                bsurface.SetPole(iu, iv, gp_Pnt(cpt[0], cpt[1], cpt[2]))
                indice_cpt += 1

        # create modified new face
        new_bspline_tface = BRepBuilderAPI_MakeFace()
        toler = precision_Confusion()
        new_bspline_tface.Init(bsurface, False, toler)

        # cycle on the wires
        face_wires_explorer = TopExp_Explorer(
            topo_nurbsface.Oriented(TopAbs_FORWARD), TopAbs_WIRE)
        ind_edge_total = 0

        while face_wires_explorer.More():
            # get old wire
            twire = topods_Wire(face_wires_explorer.Current())

            # cycle on the edges
            ind_edge = 0
            wire_explorer_edge = TopExp_Explorer(
                twire.Oriented(TopAbs_FORWARD), TopAbs_EDGE)
            # check edges order on the wire
            mode3d = True
            tolerance_edges = toledge

            wire_order = ShapeAnalysis_WireOrder(mode3d, tolerance_edges)
            # an edge list
            deformed_edges = []
            # cycle on the edges
            while wire_explorer_edge.More():
                tedge = topods_Edge(wire_explorer_edge.Current())
                new_bspline_tedge = self.write_edge(
                    list_points_edge[ind_edge_total], tedge)

                deformed_edges.append(new_bspline_tedge)
                analyzer = topexp()
                vfirst = analyzer.FirstVertex(new_bspline_tedge)
                vlast = analyzer.LastVertex(new_bspline_tedge)
                pt1 = BRep_Tool.Pnt(vfirst)
                pt2 = BRep_Tool.Pnt(vlast)

                wire_order.Add(pt1.XYZ(), pt2.XYZ())

                ind_edge += 1
                ind_edge_total += 1
                wire_explorer_edge.Next()

            # grouping the edges in a wire, then in the face
            # check edges order and connectivity within the wire
            wire_order.Perform()
            # new wire to be created
            stol = ShapeFix_ShapeTolerance()
            new_bspline_twire = BRepBuilderAPI_MakeWire()
            for order_i in range(1, wire_order.NbEdges() + 1):
                deformed_edge_i = wire_order.Ordered(order_i)
                if deformed_edge_i > 0:
                    # insert the deformed edge to the new wire
                    new_edge_toadd = deformed_edges[deformed_edge_i - 1]
                    stol.SetTolerance(new_edge_toadd, toledge)
                    new_bspline_twire.Add(new_edge_toadd)
                    if new_bspline_twire.Error() != 0:
                        stol.SetTolerance(new_edge_toadd, toledge * 10.0)
                        new_bspline_twire.Add(new_edge_toadd)
                else:
                    deformed_edge_revers = deformed_edges[
                        np.abs(deformed_edge_i) - 1]
                    stol.SetTolerance(deformed_edge_revers, toledge)
                    new_bspline_twire.Add(deformed_edge_revers)
                    if new_bspline_twire.Error() != 0:
                        stol.SetTolerance(deformed_edge_revers, toledge * 10.0)
                        new_bspline_twire.Add(deformed_edge_revers)
            # add new wire to the Face
            new_bspline_tface.Add(new_bspline_twire.Wire())
            face_wires_explorer.Next()

        return topods.Face(new_bspline_tface.Face())
コード例 #20
0
def brep_feat_extrusion_protrusion(event=None):
    # Extrusion
    S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape()
    faces = TopologyExplorer(S).faces()
    F = next(faces)
    surf1 = BRep_Tool_Surface(F)

    Pl1 = Geom_Plane.DownCast(surf1)

    D1 = Pl1.Pln().Axis().Direction().Reversed()
    MW = BRepBuilderAPI_MakeWire()
    p1, p2 = gp_Pnt2d(200., -100.), gp_Pnt2d(100., -100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge())

    p1, p2 = gp_Pnt2d(100., -100.), gp_Pnt2d(100., -200.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge())

    p1, p2 = gp_Pnt2d(100., -200.), gp_Pnt2d(200., -200.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge())

    p1, p2 = gp_Pnt2d(200., -200.), gp_Pnt2d(200., -100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW.Add(BRepBuilderAPI_MakeEdge(aline, surf1, 0., p1.Distance(p2)).Edge())

    MKF = BRepBuilderAPI_MakeFace()
    MKF.Init(surf1, False, 1e-6)
    MKF.Add(MW.Wire())
    FP = MKF.Face()
    breplib_BuildCurves3d(FP)

    display.EraseAll()
    MKP = BRepFeat_MakePrism(S, FP, F, D1, 0, True)
    MKP.PerformThruAll()

    res1 = MKP.Shape()
    display.DisplayShape(res1)

    # Protrusion
    next(faces)
    F2 = next(faces)
    surf2 = BRep_Tool_Surface(F2)
    Pl2 = Geom_Plane.DownCast(surf2)
    D2 = Pl2.Pln().Axis().Direction().Reversed()
    MW2 = BRepBuilderAPI_MakeWire()
    p1, p2 = gp_Pnt2d(100., 100.), gp_Pnt2d(200., 100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW2.Add(BRepBuilderAPI_MakeEdge(aline, surf2, 0., p1.Distance(p2)).Edge())

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

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

    MKF2 = BRepBuilderAPI_MakeFace()
    MKF2.Init(surf2, False, 1e-6)
    MKF2.Add(MW2.Wire())
    MKF2.Build()

    FP = MKF2.Face()
    breplib_BuildCurves3d(FP)
    MKP2 = BRepFeat_MakePrism(res1, FP, F2, D2, 0, True)
    MKP2.PerformThruAll()
    display.EraseAll()

    trf = gp_Trsf()
    trf.SetTranslation(gp_Vec(0, 0, 300))
    gtrf = gp_GTrsf()
    gtrf.SetTrsf(trf)
    tr = BRepBuilderAPI_GTransform(MKP2.Shape(), gtrf, True)

    fused = BRepAlgoAPI_Fuse(tr.Shape(), MKP2.Shape())
    fused.Build()

    display.DisplayShape(fused.Shape())
    display.FitAll()
コード例 #21
0
    def __call__(self, obj, dst=None):
        """
        This method performs the deformation on the CAD geometry. If `obj` is a
        TopoDS_Shape, the method returns a TopoDS_Shape containing the deformed
        geometry. If `obj` is a filename, the method deforms the geometry
        contained in the file and writes the deformed shape to `dst` (which has
        to be set).
        
        :param obj: the input geometry.
        :type obj: str or TopoDS_Shape
        :param str dst: if `obj` is a string containing the input filename,
            `dst` refers to the file where the deformed geometry is saved.
        """
        # Manage input
        if isinstance(obj, str):  # if a input filename is passed
            if dst is None:
                raise ValueError(
                    'Source file is provided, but no destination specified')
            shape = self.read_shape(obj)
        elif isinstance(obj, TopoDS_Shape):
            shape = obj
        # Maybe do we need to handle also Compound?
        else:
            raise TypeError

        #create compound to store modified faces
        compound_builder = BRep_Builder()
        compound = TopoDS_Compound()
        compound_builder.MakeCompound(compound)

        # cycle on the faces to get the control points

        # iterator to faces (TopoDS_Shape) contained in the shape
        faces_explorer = TopExp_Explorer(shape, TopAbs_FACE)

        while faces_explorer.More():
            # performing some conversions to get the right
            # format (BSplineSurface)
            # TopoDS_Face obtained from iterator
            face = topods_Face(faces_explorer.Current())
            # performing some conversions to get the right
            # format (BSplineSurface)
            bspline_surface = self._bspline_surface_from_face(face)

            # add the required amount of poles in u and v directions
            self._enrich_surface_knots(bspline_surface)

            # deform the Bspline surface through FFD
            self._deform_bspline_surface(bspline_surface)

            # through moving the control points, we now changed the SURFACE
            # underlying FACE we are processing. we now need to obtain the
            # curves (actually, the WIRES) that define the bounds of the
            # surface and TRIM the surface with them, to obtain the new FACE

            #we now start really looping on the wires
            #we will create a single curve joining all the edges in the wire
            # the curve must be a bspline curve so we need to make conversions
            # through all the way

            # list that will contain the (single) outer wire of the face
            outer_wires = []
            # list that will contain all the inner wires (holes) of the face
            inner_wires = []
            # iterator to loop over TopoDS_Wire in the original (undeformed)
            # face
            wire_explorer = TopExp_Explorer(face, TopAbs_WIRE)
            while wire_explorer.More():
                # wire obtained from the iterator
                wire = topods_Wire(wire_explorer.Current())

                # getting a bpline curve joining all the edges of the wire
                composite_curve = self._bspline_curve_from_wire(wire)

                # adding all the required knots to the Bspline curve
                self._enrich_curve_knots(composite_curve)

                # deforming the Bspline curve through FFD
                self._deform_bspline_curve(composite_curve)

                # the GeomCurve corresponding to the whole edge has now
                # been deformed. Now we must make it become an proper
                # wire

                # list of shapes (needed by the wire generator)
                shapes_list = TopTools_ListOfShape()

                # edge (to be converted to wire) obtained from the modified
                # Bspline curve
                modified_composite_edge = \
                    BRepBuilderAPI_MakeEdge(composite_curve).Edge()
                # modified edge is added to shapes_list
                shapes_list.Append(modified_composite_edge)

                # wire builder
                wire_maker = BRepBuilderAPI_MakeWire()
                wire_maker.Add(shapes_list)
                # deformed wire is finally obtained
                modified_wire = wire_maker.Wire()

                # now, the wire can be outer or inner. we store the outer
                # and (possible) inner ones in different lists
                # this is because we first need to trim the surface
                # using the outer wire, and then we can trim it
                # with the wires corresponding to all the holes.
                # the wire order is important, in the trimming process
                if wire == breptools_OuterWire(face):
                    outer_wires.append(modified_wire)
                else:
                    inner_wires.append(modified_wire)
                wire_explorer.Next()

            # so once we finished looping on all the wires to modify them,
            # we first use the only outer one to trim the surface
            # face builder object
            face_maker = BRepBuilderAPI_MakeFace(bspline_surface,
                                                 outer_wires[0])

            # and then add all other inner wires for the holes
            for inner_wire in inner_wires:
                face_maker.Add(inner_wire)

            # finally, we get our trimmed face with all its holes
            trimmed_modified_face = face_maker.Face()

            # trimmed_modified_face is added to the modified faces compound
            compound_builder.Add(compound, trimmed_modified_face)

            # and move to the next face
            faces_explorer.Next()

        ## END SURFACES #################################################

        if isinstance(dst, str):  # if a input filename is passed
            # save the shape exactly to the filename, aka `dst`
            self.write_shape(dst, compound)
        else:
            return compound
コード例 #22
0
    obj = plotocc(view=False)

    face1 = read_step_file("./stp_surf/gen_surf_001.stp")
    axis1 = gp_Ax3(gp_Pnt(0, 0, 1), gp_Dir(0, 0, 1))
    face1.Location(set_loc(gp_Ax3(), axis1))

    face2 = read_step_file("./stp_surf/gen_surf_030.stp")
    axis2 = gp_Ax3(gp_Pnt(0, 0, 2), gp_Dir(0, 0, 1))
    face2.Location(set_loc(gp_Ax3(), axis2))

    axs = gp_Ax3()
    ax1 = gp_Ax3(gp_Pnt(0, 0, -10), axs.Direction())
    vec = gp_Vec(gp_Pnt(0, 0, -10), gp_Pnt(0, 0, 10))
    face = obj.make_EllipWire(rxy=[50.0, 50.0], axs=ax1, skin=0)
    body = BRepPrimAPI_MakePrism(face, vec).Shape()

    lens = make_lens(body, face1, face2)
    obj.create_tempdir(flag=-1)

    wire1 = obj.make_PolyWire(radi=50, num=6, axs=axis1)
    proj = BRepProj_Projection(wire1, face1, axis1.Direction())
    proj_wire = proj.Current()
    top = Topo(face1)
    for faces in top.faces():
        face1_1 = faces
        print(faces)

    api = BRepBuilderAPI_MakeFace(face1_1)
    api.Add(proj_wire)
    obj.export_stp(api.Face())
コード例 #23
0
    def max_counter(self, facesS_2):
        section_edges = list(Topo(facesS_2).edges())
        # print(len(section_edges))

        if len(section_edges) > 0:

            Wire_c = BRepBuilderAPI_MakeWire()
            prep_list = []
            Wire_c.Add(section_edges[0])
            prep_list.append(section_edges[0])
            ex = TopExp_Explorer(section_edges[0], TopAbs_VERTEX)

            # no need for a loop since we know for a fact that
            # the edge has only one start and one end
            c = ex.Current()
            cv = topods_Vertex(c)
            v0 = BRep_Tool_Pnt(cv)
            ex.Next()
            c = ex.Current()
            cv = topods_Vertex(c)
            v1 = BRep_Tool_Pnt(cv)
            section_edges.pop(0)
            flag = 0
            wires = []

            while len(section_edges) > 0:

                new_list = []

                for edges in section_edges:
                    # Wire_c.Add(edges)
                    ex = TopExp_Explorer(edges, TopAbs_VERTEX)
                    c = ex.Current()
                    cv = topods_Vertex(c)
                    End_1 = BRep_Tool_Pnt(cv)
                    ex.Next()
                    c = ex.Current()
                    cv = topods_Vertex(c)
                    End_2 = BRep_Tool_Pnt(cv)

                    if End_1.X() == v0.X() and End_1.Y() == v0.Y() and End_1.Z(
                    ) == v0.Z():
                        Wire_c.Add(edges)
                        v0 = End_2
                        flag = 0
                    elif End_1.X() == v1.X() and End_1.Y() == v1.Y(
                    ) and End_1.Z() == v1.Z():
                        Wire_c.Add(edges)
                        v1 = End_2
                        flag = 0
                    elif End_2.X() == v0.X() and End_2.Y() == v0.Y(
                    ) and End_2.Z() == v0.Z():
                        Wire_c.Add(edges)
                        v0 = End_1
                        flag = 0
                    elif End_2.X() == v1.X() and End_2.Y() == v1.Y(
                    ) and End_2.Z() == v1.Z():
                        Wire_c.Add(edges)
                        v1 = End_1
                        flag = 0
                    else:
                        new_list.append(edges)

                flag += 1
                section_edges = new_list

                if flag >= 5:
                    # print('number_ostalos', len(section_edges))
                    wires.append(Wire_c.Wire())
                    Wire_c = BRepBuilderAPI_MakeWire()

                    Wire_c.Add(section_edges[0])
                    ex = TopExp_Explorer(section_edges[0], TopAbs_VERTEX)

                    # no need for a loop since we know for a fact that
                    # the edge has only one start and one end
                    c = ex.Current()
                    cv = topods_Vertex(c)
                    v0 = BRep_Tool_Pnt(cv)
                    ex.Next()
                    c = ex.Current()
                    cv = topods_Vertex(c)
                    v1 = BRep_Tool_Pnt(cv)
                    section_edges.pop(0)
                    flag = 0

            wires.append(Wire_c.Wire())

            areas = []
            props = GProp_GProps()

            for wire in wires:
                brown_face = BRepBuilderAPI_MakeFace(wire)
                brown_face = brown_face.Face()
                # props = GProp_GProps()
                brepgprop_SurfaceProperties(brown_face, props)
                areas.append(props.Mass())

            return max(areas)

        else:
            return 0
コード例 #24
0
def glue_solids(event=None):
    display.EraseAll()
    display.Context.RemoveAll(True)
    # Without common edges
    S1 = BRepPrimAPI_MakeBox(gp_Pnt(500., 500., 0.), gp_Pnt(100., 250., 300.)).Shape()
    # S2 = BRepPrimAPI_MakeBox(gp_Pnt(300., 300., 300.), gp_Pnt(600., 600., 600.)).Shape()
    S2 = read_step_file(os.path.join('..', 'part_of_sattelate', 'pribore', 'Camara_WS16.STEP'))
    bbox = Bnd_Box()
    brepbndlib_Add(S2, bbox)
    xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
    print(bbox.Get())
    p0 = gp_Pnt(xmin + (xmax - xmin) / 2, ymin + (ymax - ymin) / 2, zmin+0.01)

    vnorm = gp_Dir(0, 0, 1)
    pln = gp_Pln(p0, vnorm)
    face = BRepBuilderAPI_MakeFace(pln, -(xmax - xmin) / 2 - 1, (xmax - xmin) / 2 + 1, -(ymax - ymin) / 2 - 1,
                                   (ymax - ymin) / 2 + 1).Face()
    # face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10,10).Face()
    '''planeZ = BRepBuilderAPI_MakeFace(
        gp_Pln(gp_Pnt(xmin, ymin, zmin), gp_Pnt(xmax, ymax, zmin), gp_Pnt(xmin, ymax, zmin))).Face()'''
    facesS_2 = BRepAlgoAPI_Section(face, S2).Shape()
    # print(facesS_2)
    display.DisplayShape(face, update=True)
    display.DisplayShape(S2, update=True)
    display.DisplayShape(facesS_2, update=True)

    section_edges = list(Topo(facesS_2).edges())
    print(len(section_edges))

    '''toptool_seq_shape = TopTools_SequenceOfShape()
    for edge in section_edges:
        toptool_seq_shape.Append(edge)'''

    Wire_c = BRepBuilderAPI_MakeWire()
    prep_list = []
    Wire_c.Add(section_edges[0])
    prep_list.append(section_edges[0])
    ex = TopExp_Explorer(section_edges[0], TopAbs_VERTEX)

    # no need for a loop since we know for a fact that
    # the edge has only one start and one end
    c = ex.Current()
    cv = topods_Vertex(c)
    v0 = BRep_Tool_Pnt(cv)
    ex.Next()
    c = ex.Current()
    cv = topods_Vertex(c)
    v1 = BRep_Tool_Pnt(cv)
    section_edges.pop(0)
    flag = 0
    wires = []

    while len(section_edges) > 0:

        new_list = []

        for edges in section_edges:
            #Wire_c.Add(edges)
            ex = TopExp_Explorer(edges, TopAbs_VERTEX)
            c = ex.Current()
            cv = topods_Vertex(c)
            End_1 = BRep_Tool_Pnt(cv)
            ex.Next()
            c = ex.Current()
            cv = topods_Vertex(c)
            End_2 = BRep_Tool_Pnt(cv)

            if End_1.X() == v0.X() and End_1.Y() == v0.Y() and End_1.Z() == v0.Z():
                Wire_c.Add(edges)
                v0 = End_2
                flag = 0
            elif End_1.X() == v1.X() and End_1.Y() == v1.Y() and End_1.Z() == v1.Z():
                Wire_c.Add(edges)
                v1 = End_2
                flag = 0
            elif End_2.X() == v0.X() and End_2.Y() == v0.Y() and End_2.Z() == v0.Z():
                Wire_c.Add(edges)
                v0 = End_1
                flag = 0
            elif End_2.X() == v1.X() and End_2.Y() == v1.Y() and End_2.Z() == v1.Z():
                Wire_c.Add(edges)
                v1 = End_1
                flag = 0
            else:
                new_list.append(edges)

        flag += 1
        section_edges = new_list

        if flag >= 5:
            print('number_ostalos', len(section_edges))
            wires.append(Wire_c.Wire())
            #wir = Wire_c.Wire()
            print('ttttt')
            Wire_c = BRepBuilderAPI_MakeWire()

            Wire_c.Add(section_edges[0])
            ex = TopExp_Explorer(section_edges[0], TopAbs_VERTEX)

            # no need for a loop since we know for a fact that
            # the edge has only one start and one end
            c = ex.Current()
            cv = topods_Vertex(c)
            v0 = BRep_Tool_Pnt(cv)
            ex.Next()
            c = ex.Current()
            cv = topods_Vertex(c)
            v1 = BRep_Tool_Pnt(cv)
            section_edges.pop(0)
            flag = 0

    # wires.append(Wire_c.Wire())
    wires.append(bild_wire(Wire_c))
    props = GProp_GProps()

    yellow_wire = wires[0]
    brown_face = BRepBuilderAPI_MakeFace(yellow_wire)
    brown_face = brown_face.Face()
    brepgprop_SurfaceProperties(brown_face, props)
    face_surf = props.Mass()
    print(face_surf)
    #display.DisplayColoredShape(brown_face.Face(), 'BLUE')


    areas = []
    props = GProp_GProps()

    for wire in wires:
        brown_face = BRepBuilderAPI_MakeFace(wire)
        brown_face = brown_face.Face()
        #props = GProp_GProps()
        brepgprop_SurfaceProperties(brown_face, props)
        areas.append(props.Mass())


    print(areas)


    print(len(wires))
コード例 #25
0
ファイル: workplane.py プロジェクト: ponsingh/cadviewer
 def makeWpBorder(self, size):
     wireProfile = self.makeSqProfile(size)
     myFaceProfile = BRepBuilderAPI_MakeFace(wireProfile)
     if myFaceProfile.IsDone():
         border = myFaceProfile.Face()
     return border  # TopoDS_Face
コード例 #26
0
def make_face(*args):
    face = BRepBuilderAPI_MakeFace(*args)
    assert_isdone(face, "failed to produce face")
    result = face.Face()
    return result
コード例 #27
0
def face():
    p1 = gp_Pnt()
    p2 = gp_Pnt()
    p3 = gp_Pnt()
    p4 = gp_Pnt()
    p5 = gp_Pnt()
    p6 = gp_Pnt()

    # The white Face
    sphere = gp_Sphere(gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 150)
    green_face = BRepBuilderAPI_MakeFace(sphere, 0.1, 0.7, 0.2, 0.9)

    # The red face
    p1.SetCoord(-15, 200, 10)
    p2.SetCoord(5, 204, 0)
    p3.SetCoord(15, 200, 0)
    p4.SetCoord(-15, 20, 15)
    p5.SetCoord(-5, 20, 0)
    p6.SetCoord(15, 20, 35)
    array = TColgp_Array2OfPnt(1, 3, 1, 2)
    array.SetValue(1, 1, p1)
    array.SetValue(2, 1, p2)
    array.SetValue(3, 1, p3)
    array.SetValue(1, 2, p4)
    array.SetValue(2, 2, p5)
    array.SetValue(3, 2, p6)
    curve = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2,
                                           0.001).Surface()
    red_face = BRepBuilderAPI_MakeFace(curve, 1e-6)

    #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, 40), gp_Pnt(0, 0, 80))

    ##TopoDS_Wire YellowWire
    MW1 = BRepBuilderAPI_MakeWire(Edge1.Edge(), Edge2.Edge(), Edge3.Edge())
    assert MW1.IsDone()
    yellow_wire = MW1.Wire()
    brown_face = BRepBuilderAPI_MakeFace(yellow_wire)

    #The pink face
    p1.SetCoord(35, -200, 40)
    p2.SetCoord(50, -204, 30)
    p3.SetCoord(65, -200, 30)
    p4.SetCoord(35, -20, 45)
    p5.SetCoord(45, -20, 30)
    p6.SetCoord(65, -20, 65)
    array2 = TColgp_Array2OfPnt(1, 3, 1, 2)
    array2.SetValue(1, 1, p1)
    array2.SetValue(2, 1, p2)
    array2.SetValue(3, 1, p3)
    array2.SetValue(1, 2, p4)
    array2.SetValue(2, 2, p5)
    array2.SetValue(3, 2, p6)
    BSplineSurf = GeomAPI_PointsToBSplineSurface(array2, 3, 8, GeomAbs_C2,
                                                 0.001)
    aFace = BRepBuilderAPI_MakeFace(BSplineSurf.Surface(), 1e-6).Face()
    ##
    ##//2d lines
    P12d = gp_Pnt2d(0.9, 0.1)
    P22d = gp_Pnt2d(0.2, 0.7)
    P32d = gp_Pnt2d(0.02, 0.1)
    ##
    line1 = Geom2d_Line(P12d, gp_Dir2d((0.2 - 0.9), (0.7 - 0.1)))
    line2 = Geom2d_Line(P22d, gp_Dir2d((0.02 - 0.2), (0.1 - 0.7)))
    line3 = Geom2d_Line(P32d, gp_Dir2d((0.9 - 0.02), (0.1 - 0.1)))
    ##
    ##//Edges are on the BSpline surface
    Edge1 = BRepBuilderAPI_MakeEdge(line1, BSplineSurf.Surface(), 0,
                                    P12d.Distance(P22d)).Edge()
    Edge2 = BRepBuilderAPI_MakeEdge(line2, BSplineSurf.Surface(), 0,
                                    P22d.Distance(P32d)).Edge()
    Edge3 = BRepBuilderAPI_MakeEdge(line3, BSplineSurf.Surface(), 0,
                                    P32d.Distance(P12d)).Edge()
    ##
    Wire1 = BRepBuilderAPI_MakeWire(Edge1, Edge2, Edge3).Wire()
    Wire1.Reverse()
    pink_face = BRepBuilderAPI_MakeFace(aFace, Wire1).Face()
    breplib_BuildCurves3d(pink_face)

    display.DisplayColoredShape(green_face.Face(), 'GREEN')
    display.DisplayColoredShape(red_face.Face(), 'RED')
    display.DisplayColoredShape(pink_face, Quantity_Color(Quantity_NOC_PINK))
    display.DisplayColoredShape(brown_face.Face(), 'BLUE')
    display.DisplayColoredShape(yellow_wire, 'YELLOW', update=True)
コード例 #28
0
            # boundaries
            b1 = boundary_curve_from_2_points(v1, v2)
            b2 = boundary_curve_from_2_points(v2, v3)
            b3 = boundary_curve_from_2_points(v3, v4)
            b4 = boundary_curve_from_2_points(v4, v1)
            #
            bConstrainedFilling = GeomFill_ConstrainedFilling(8, 2)
            bConstrainedFilling.Init(b1, b2, b3, b4, False)
            srf1 = bConstrainedFilling.Surface()
            # make a face from this srf
            patch = BRepBuilderAPI_MakeFace()
            bounds = True
            toldegen = 1e-6
            patch.Init(srf1, bounds, toldegen)
            patch.Build()
            display.DisplayShape(patch.Face())
            # then create faces

            txt = "\r"
            txt += "{:03d} / {:03d}".format(i, width)
            txt += " - "
            txt += "{:03d} / {:03d}".format(j, height)
            sys.stdout.write(txt)
            sys.stdout.flush()

        #print("%s%%" % int(float(i) / width * 100))
        # display.process_events()
    print()
    display.FitAll()
    # finally display image
    start_display()
コード例 #29
0
def startBottle(startOnly=True):  # minus the neck fillet, shelling & threads
    partName = "Bottle-start"
    # The points we'll use to create the profile of the bottle's body
    aPnt1 = gp_Pnt(-width / 2.0, 0, 0)
    aPnt2 = gp_Pnt(-width / 2.0, -thickness / 4.0, 0)
    aPnt3 = gp_Pnt(0, -thickness / 2.0, 0)
    aPnt4 = gp_Pnt(width / 2.0, -thickness / 4.0, 0)
    aPnt5 = gp_Pnt(width / 2.0, 0, 0)

    aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4)
    aSegment1 = GC_MakeSegment(aPnt1, aPnt2)
    aSegment2 = GC_MakeSegment(aPnt4, aPnt5)

    # Could also construct the line edges directly using the points
    # instead of the resulting line.
    aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value())
    aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value())
    aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value())

    # Create a wire out of the edges
    aWire = BRepBuilderAPI_MakeWire(aEdge1.Edge(), aEdge2.Edge(),
                                    aEdge3.Edge())

    # Quick way to specify the X axis
    xAxis = gp_OX()

    # Set up the mirror
    aTrsf = gp_Trsf()
    aTrsf.SetMirror(xAxis)

    # Apply the mirror transformation
    aBRespTrsf = BRepBuilderAPI_Transform(aWire.Wire(), aTrsf)

    # Get the mirrored shape back out of the transformation
    # and convert back to a wire
    aMirroredShape = aBRespTrsf.Shape()

    # A wire instead of a generic shape now
    aMirroredWire = topods.Wire(aMirroredShape)

    # Combine the two constituent wires
    mkWire = BRepBuilderAPI_MakeWire()
    mkWire.Add(aWire.Wire())
    mkWire.Add(aMirroredWire)
    myWireProfile = mkWire.Wire()

    # The face that we'll sweep to make the prism
    myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile)

    # We want to sweep the face along the Z axis to the height
    aPrismVec = gp_Vec(0, 0, height)
    myBody = BRepPrimAPI_MakePrism(myFaceProfile.Face(), aPrismVec)

    # Add fillets to all edges through the explorer
    mkFillet = BRepFilletAPI_MakeFillet(myBody.Shape())
    anEdgeExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_EDGE)

    while anEdgeExplorer.More():
        anEdge = topods.Edge(anEdgeExplorer.Current())
        mkFillet.Add(thickness / 12.0, anEdge)

        anEdgeExplorer.Next()

    myBody = mkFillet.Shape()

    # Create the neck of the bottle
    neckLocation = gp_Pnt(0, 0, height)
    neckAxis = gp_DZ()
    neckAx2 = gp_Ax2(neckLocation, neckAxis)

    myNeckRadius = thickness / 4.0
    myNeckHeight = height / 10.0

    mkCylinder = BRepPrimAPI_MakeCylinder(neckAx2, myNeckRadius, myNeckHeight)
    myBody = BRepAlgoAPI_Fuse(myBody, mkCylinder.Shape())
    if startOnly:  # quit here
        uid = win.getNewPartUID(myBody.Shape(), name=partName)
        win.redraw()
        return

    partName = "Bottle-complete"
    # Our goal is to find the highest Z face and remove it
    faceToRemove = None
    zMax = -1

    # We have to work our way through all the faces to find the highest Z face
    aFaceExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_FACE)
    while aFaceExplorer.More():
        aFace = topods.Face(aFaceExplorer.Current())

        if face_is_plane(aFace):
            aPlane = geom_plane_from_face(aFace)

            # We want the highest Z face, so compare this to the previous faces
            aPnt = aPlane.Location()
            aZ = aPnt.Z()
            if aZ > zMax:
                zMax = aZ
                faceToRemove = aFace

        aFaceExplorer.Next()

    facesToRemove = TopTools_ListOfShape()
    facesToRemove.Append(faceToRemove)

    myBody = BRepOffsetAPI_MakeThickSolid(myBody.Shape(), facesToRemove,
                                          -thickness / 50.0, 0.001)

    # Set up our surfaces for the threading on the neck
    neckAx2_Ax3 = gp_Ax3(neckLocation, gp_DZ())
    aCyl1 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 0.99)
    aCyl2 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 1.05)

    # Set up the curves for the threads on the bottle's neck
    aPnt = gp_Pnt2d(2.0 * math.pi, myNeckHeight / 2.0)
    aDir = gp_Dir2d(2.0 * math.pi, myNeckHeight / 4.0)
    anAx2d = gp_Ax2d(aPnt, aDir)

    aMajor = 2.0 * math.pi
    aMinor = myNeckHeight / 10.0

    anEllipse1 = Geom2d_Ellipse(anAx2d, aMajor, aMinor)
    anEllipse2 = Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4.0)

    anArc1 = Geom2d_TrimmedCurve(anEllipse1, 0, math.pi)
    anArc2 = Geom2d_TrimmedCurve(anEllipse2, 0, math.pi)

    anEllipsePnt1 = anEllipse1.Value(0)
    anEllipsePnt2 = anEllipse1.Value(math.pi)

    aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2)

    # Build edges and wires for threading
    anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(anArc1, aCyl1)
    anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl1)
    anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2, aCyl2)
    anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl2)

    threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1.Edge(),
                                             anEdge2OnSurf1.Edge())
    threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2.Edge(),
                                             anEdge2OnSurf2.Edge())

    # Compute the 3D representations of the edges/wires
    breplib.BuildCurves3d(threadingWire1.Shape())
    breplib.BuildCurves3d(threadingWire2.Shape())

    # Create the surfaces of the threading
    aTool = BRepOffsetAPI_ThruSections(True)
    aTool.AddWire(threadingWire1.Wire())
    aTool.AddWire(threadingWire2.Wire())
    aTool.CheckCompatibility(False)
    myThreading = aTool.Shape()

    # Build the resulting compound
    aRes = TopoDS_Compound()
    aBuilder = BRep_Builder()
    aBuilder.MakeCompound(aRes)
    aBuilder.Add(aRes, myBody.Shape())
    aBuilder.Add(aRes, myThreading)
    uid = win.getNewPartUID(aRes, name=partName)
    win.redraw()
コード例 #30
0
def make_face(*args):
    face = BRepBuilderAPI_MakeFace(*args)
    with assert_isdone(face, 'failed to produce face'):
        result = face.Face()
        face.Delete()
        return result