Exemple #1
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()
Exemple #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 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()
Exemple #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(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()
Exemple #5
0
 def from_wires(cls, topo: List[TopoDS_Wire], plane: Optional[gp_Pln] = None) -> TopoDS_Face:
     """ create face from compound of edges """
     # if topo.number_of_wires() == 0:
     wire = BRepBuilderAPI_MakeFace()
     for edge in topo:
         wire.Add(edge)
     wire.Build()
     w = wire.Face()
     return w
Exemple #6
0
    def make_shape(self):
        # 1 - retrieve the data from the UIUC airfoil data page
        foil_dat_url = 'http://www.ae.illinois.edu/m-selig/ads/coord_seligFmt/%s.dat' % self.profile
        if py2:
            f = urllib2.urlopen(foil_dat_url)
        else:
            http = urllib3.PoolManager()
            f = http.urlopen('GET', foil_dat_url).data.decode()
            f = io.StringIO(f)

        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)
            line = line.lstrip().rstrip().replace('    ', ' ').replace(
                '   ', ' ').replace('  ', ' ')
            data = line.split(' ')  # data[0] = x coord.    data[1] = y coord.

            # 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()
def brepfeat_prism(event=None):
    box = BRepPrimAPI_MakeBox(400, 250, 300).Shape()
    faces = Topo(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).GetHandle()

    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()
Exemple #8
0
def make_polygon(pyptlist):
    array = []
    for pt in pyptlist:
        array.append(gp_Pnt(pt[0], pt[1], pt[2]))

    poly = BRepBuilderAPI_MakePolygon()
    map(poly.Add, array)
    poly.Build()
    poly.Close()

    wire = poly.Wire()
    occface = BRepBuilderAPI_MakeFace(wire)
    return occface.Face()
Exemple #9
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('images/mountain_heightmap.jpg')
    heightmap.show()
    width = heightmap.size[0]
    height = heightmap.size[1]
    # create the gp_Pnt array
    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()
Exemple #10
0
    def Solid(self):

        mw = BRepBuilderAPI_MakeWire()
        points = []

        x = -self.length / 2.0
        y = -self.width / 2.0
        z = 0.0
        points.append(gp_Pnt(x, y, z))

        x = self.length / 2.0
        points.append(gp_Pnt(x, y, z))

        me = BRepBuilderAPI_MakeEdge(points[0], points[1])
        mw.Add(me.Edge())  # bottom edge

        ax = gp_Ax2(gp_Pnt(x, 0, 0), gp_Dir(0, 0, 1), gp_Dir(0, -1, 0))
        circ = gp_Circ(ax, self.width / 2.0)
        me = BRepBuilderAPI_MakeEdge(circ, 0, pi)
        mw.Add(me.Edge())

        points = []
        y = self.width / 2.0
        points.append(gp_Pnt(x, y, z))

        x = -self.length / 2.0
        points.append(gp_Pnt(x, y, z))
        me = BRepBuilderAPI_MakeEdge(points[0], points[1])
        mw.Add(me.Edge())  # top edge

        ax = gp_Ax2(gp_Pnt(x, 0, 0), gp_Dir(0, 0, 1), gp_Dir(0, 1, 0))
        circ = gp_Circ(ax, self.width / 2.0)
        me = BRepBuilderAPI_MakeEdge(circ, 0, pi)
        mw.Add(me.Edge())

        mf = BRepBuilderAPI_MakeFace(mw.Wire())
        mp = BRepPrimAPI_MakePrism(mf.Face(), gp_Vec(0, 0, self.thickness))

        shape = mp.Shape()

        #v_trans = gp_Vec(self.ax2.Location().XYZ())
        ax = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
        #mainRotationAngle = ax.Angle(self.ax2)

        trsf = gp_Trsf()
        trsf.SetTransformation(gp_Ax3(self.ax2), gp_Ax3(ax))

        mt = BRepBuilderAPI_Transform(shape, trsf)
        return mt.Shape()
Exemple #11
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:
    """
    faceb = BRepBuilderAPI_MakeFace(face)
    if reverse:
        wire.Reverse()
    faceb.Add(wire)
    result = faceb.Face()
    faceb.Delete()
    return result
Exemple #12
0
    def makeFromWires(cls, outerWire, innerWires=[]):
        '''
        Makes a planar face from one or more wires
        '''
        face_builder = BRepBuilderAPI_MakeFace(outerWire.wrapped,
                                               True)  # True is for planar only

        for w in innerWires:
            face_builder.Add(w.wrapped)
        face_builder.Build()
        f = face_builder.Face()

        sf = ShapeFix_Face(f)  # fix wire orientation
        sf.FixOrientation()

        return cls(sf.Face())
Exemple #13
0
def region_as_splinegon(boundary_splines):
    """Represents a region as a splinegon.

    Based on the combined topological-geometrical (intermediate) representation of the regions,
    (done by :func:`skeleton2regions`), this function provides a fully geometrical description
    of a region.

    Parameters
    ----------
    boundary_splines : list
        Each element of the list is a `Handle_Geom_BSplineCurve` object, giving a reference to the
        B-splines bounding the region. The splines must either be ordered (see
        :func:`branches2boundary`) or they must appear in an order such that the n-th spline in
        the list can be connected to one of the first n-1 splines in the list.

    Returns
    -------
    splinegon : TopoDS_Face
        The resulting splinegon (surface). For details on the object, see the OpenCASCADE API:
        https://www.opencascade.com/doc/occt-7.4.0/refman/html/class_topo_d_s___face.html
    boundary : TopoDS_Wire
        The boundary of the splinegon. For details on the resulting object, see the OpenCASCADE API:
        https://www.opencascade.com/doc/occt-7.4.0/refman/html/class_topo_d_s___wire.html

    See Also
    --------
    skeleton2regions
    fit_spline

    Notes
    -----
    The syntax `Handle_classname` in PythonOCC corresponds to wrapping the object of class
    `classname` with a smart pointer. In the C++ interface, it is done by a template:
    `Handle<classname>`.

    """
    # Combine the splines so that they form the boundary (a collection of joining splines)
    boundary = BRepBuilderAPI_MakeWire()
    for spline in boundary_splines:
        edge = BRepBuilderAPI_MakeEdge(spline).Edge()
        boundary.Add(edge)
        _wire_error(boundary.Error())
    # The planar surface (face) is stretched by the wire
    splinegon = BRepBuilderAPI_MakeFace(boundary.Wire())
    _face_error(splinegon.Error())
    return splinegon.Face(), boundary.Wire()
Exemple #14
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")
Exemple #15
0
    def create_cutting_plane_xz(y_pos, bounding_box):
        """Creates a face in the x-z plane at a given y-position.

        :param y_pos: y position
        :type y_pos: float
        :param bounding_box: Surrounding box of the wing
        :type bounding_box: instance of OCC.Bnd.Bnd_Box
        :return: face
        :rtype: instance of OCC.TopoDS.TopoDS_Face or None
        """
        plane = gp_Pln(gp_Pnt(0, y_pos, 0), gp_Dir(0, 1, 0))
        face_builder = BRepBuilderAPI_MakeFace(plane)
        if face_builder.IsDone():
            return face_builder.Face()
        else:
            raise Exception('Could not build face')
        return None
Exemple #16
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')
Exemple #17
0
 def draw3D(self, spaces, displaySize = (1024, 768), update = False):
     """
     draw3D(aecSpaceGroup)
     Accepts an aecSpaceGroup object and renders its list of aecSpaces to the pythonOCC display.
     Returns True on success failure.
     Returns False on failure.
     """
     try:
         if not spaces: return False
         if type(spaces) != list: spaces = spaces.spaces
         if not spaces: return False
         __display, __start_display, __add_menu, __add_function_to_menu = init_display('qt-pyqt5', size = displaySize)            
         for space in spaces:
             points = self.makePoints(space)
             if not points: continue
             pointPairs = self.makePointPairs(points)
             if not pointPairs: continue
             edges = self.makeEdges(pointPairs)
             if not edges: continue
             wire = self.makeWire(edges)
             if not wire.IsDone: continue
             #if not wire: continue
             face = BRepBuilderAPI_MakeFace(wire.Wire())
             if not face: continue
             vector = gp_Vec(0, 0, space.height)
             spaceVolume = BRepPrimAPI_MakePrism(face.Face(), vector).Shape()
             if not spaceVolume: continue
             displayColor = space.color.color_01
             spaceColor = OCC.Quantity.Quantity_Color_Name(
                 displayColor[0],
                 displayColor[1],
                 displayColor[2])
             __display.DisplayShape(
                     spaceVolume, 
                     color = spaceColor,
                     transparency = space.color.alpha_01,
                     update = update)
         __display.FitAll()
         __start_display()
         __display = None
         return True
     except Exception:
         traceback.print_exc()
         return False
Exemple #18
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")
Exemple #19
0
aTrsf = OCC.gp.gp_Trsf()
aTrsf.SetMirror(xAxis)
aBRepTrsf = Transform(aWire.Wire(), aTrsf)
aMirroredShape = aBRepTrsf.Shape()
aMirroredWire = OCC.TopoDS.TopoDS_Shape(aMirroredShape)
aMirroredWire = OCC.TopoDS.topods().Wire(aMirroredWire)

mkWire = MakeWire()
mkWire.Add(aWire.Wire())
mkWire.Add(aMirroredWire)
myWireProfile = mkWire.Wire()

# Body : Prism the Profile
myFaceProfile = MakeFace(myWireProfile)
if myFaceProfile.IsDone():
    bottomFace = myFaceProfile.Face()
aPrismVec = gp_Vec(0, 0, myHeight)
myBody = MakePrism(myFaceProfile.Shape(), aPrismVec)

# Body : Apply Fillets
mkFillet = MakeFillet(myBody.Shape())
aEdgeExplorer = Explorer(myBody.Shape(), OCC.TopAbs.TopAbs_EDGE)
while aEdgeExplorer.More():
    aEdge = OCC.TopoDS.topods_Edge(aEdgeExplorer.Current())
    mkFillet.Add(myThickness / 12, aEdge)
    aEdgeExplorer.Next()
myBody = mkFillet.Shape()

# Body : Add the Neck
neckLocation = OCC.gp.gp_Pnt(0, 0, myHeight)
neckNormal = OCC.gp.gp_DZ()
Exemple #20
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())
    if 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.GetHandle(), BSplineSurf.Surface(),
                                    0, P12d.Distance(P22d)).Edge()
    Edge2 = BRepBuilderAPI_MakeEdge(line2.GetHandle(), BSplineSurf.Surface(),
                                    0, P22d.Distance(P32d)).Edge()
    Edge3 = BRepBuilderAPI_MakeEdge(line3.GetHandle(), 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)
def make_face(*args):
    face = BRepBuilderAPI_MakeFace(*args)
    assert (face.IsDone())
    result = face.Face()
    return result
Exemple #22
0
def make_offset(occ_face, offset_value):
    o_wire = Construct.make_offset(occ_face, offset_value)
    occface = BRepBuilderAPI_MakeFace(o_wire)
    return occface.Face()
Exemple #23
0
def make_face(*args) -> TopoDS_Face:
    face = BRepBuilderAPI_MakeFace(*args)
    with assert_isdone(face, 'failed to produce face'):
        result = face.Face()
        face.Delete()
        return result
Exemple #24
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()
    Proxy(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
def brep_feat_extrusion_protrusion(event=None):
    # Extrusion
    S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape()
    faces = Topo(S).faces()
    F = next(faces)
    surf1 = BRep_Tool_Surface(F)

    Pl1 = Handle_Geom_Plane_DownCast(surf1).GetObject()

    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 = Handle_Geom_Plane_DownCast(surf2).GetObject()
    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.RefineEdges()
    fused.Build()
    print('Boolean operation error status:', fused.ErrorStatus())
    display.DisplayShape(fused.Shape())
    display.FitAll()
# 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

# Create the neck of the bottle
neckLocation = gp_Pnt(0, 0, height)
Exemple #27
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.GetObject()

        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.GetHandle(), 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())
Exemple #28
0
def makeStringerWithContinuousSlot():
    thickness = 5.0
    width = 25.0
    slot_width = 5.0
    slot_depth = thickness / 4.0
    length = 150.0

    points = []

    x = 0
    y = 0
    z = 0

    x = thickness / 2.0
    y = -width / 2.0
    points.append(gp_Pnt(x, y, z))  # bottom right corner

    y = -slot_width / 2.0
    points.append(gp_Pnt(x, y, z))

    x = x - slot_depth
    points.append(gp_Pnt(x, y, z))

    y = slot_width / 2.0
    points.append(gp_Pnt(x, y, z))

    x = x + slot_depth
    points.append(gp_Pnt(x, y, z))

    y = width / 2.0  # top right corner
    points.append(gp_Pnt(x, y, z))

    x = -thickness / 2.0  # top left corner
    points.append(gp_Pnt(x, y, z))

    y = slot_width / 2.0
    points.append(gp_Pnt(x, y, z))

    x = x + slot_depth
    points.append(gp_Pnt(x, y, z))

    y = -slot_width / 2.0
    points.append(gp_Pnt(x, y, z))

    x = x - slot_depth
    points.append(gp_Pnt(x, y, z))

    y = -width / 2.0
    points.append(gp_Pnt(x, y, z))  # bottom left corner

    x = thickness / 2.0
    points.append(gp_Pnt(x, y, z))  # back to the bottom right corner

    mw = BRepBuilderAPI_MakeWire()
    for i in range(len(points) - 1):
        me = BRepBuilderAPI_MakeEdge(points[i], points[i + 1])
        edge = me.Edge()
        mw.Add(edge)

    mf = BRepBuilderAPI_MakeFace(mw.Wire())
    mp = BRepPrimAPI_MakePrism(mf.Face(), gp_Vec(0, 0, length))
    return mp.Shape()