Esempio n. 1
0
    def updateGraphicObjects(self, points, display):

        self.GHPolygon = []

        for i in self.PolygonPoints:
            if i in range(len(points)):
                self.GHPolygon.Add(points[i].Point)
            else:
                print('polygon point %d does not exist' % i)

        self.GHPolygon.Close()
        self.GHFace = BRepBuilderAPI_MakeFace(self.GHPolygon.Wire())
        self.GHShape = BRepBuilderAPI_MakeShape.Shape(self.GHFace)

        #display.DisplayShape(self.GHShape)

        if len(self.Opening) > 0:
            print('processing openings')
            for i in range(len(self.Opening)):
                openingpolygon = BRepBuilderAPI_MakePolygon()
                for j in self.Opening[i]:
                    openingpolygon.Add(points[j].Point)
                openingpolygon.Close()
                openingface = BRepBuilderAPI_MakeFace(openingpolygon.Wire())
                openingshape = BRepBuilderAPI_MakeShape.Shape(openingface)
                cut = BRepAlgoAPI_Cut(self.GHShape, openingshape)
                self.GHShape = cut.Shape()

        #display.DisplayShape(self.GHShape)

        # calculate Area
        Props = GProp_GProps()
        brepgprop.SurfaceProperties(self.GHShape, Props)
        self.Area = Props.Mass()
Esempio n. 2
0
def build_plate(polygon, points):
    ''' 
    build a surface from a constraining polygon(s) and point(s)
    @param polygon:     list of polygons (TopoDS_Shape)
    @param points:      list of points (gp_Pnt) 
    '''
    # plate surface
    bpSrf = GeomPlate_BuildPlateSurface(3, 15, 2)

    # add curve constraints
    for poly in polygon:
        for edg in WireExplorer(poly.Wire()).ordered_edges():
            c = BRepAdaptor_HCurve()
            c.ChangeCurve().Initialize(edg)
            constraint = BRepFill_CurveConstraint(c.GetHandle(), 0)
            bpSrf.Add(constraint.GetHandle())

    # add point constraint
    for pt in points:
        bpSrf.Add(GeomPlate_PointConstraint(pt, 0).GetHandle())
        bpSrf.Perform()

    maxSeg, maxDeg, critOrder = 9, 8, 0
    tol = 1e-4
    dmax = max([tol, 10 * bpSrf.G0Error()])

    srf = bpSrf.Surface()
    plate = GeomPlate_MakeApprox(srf, tol, maxSeg, maxDeg, dmax, critOrder)

    uMin, uMax, vMin, vMax = srf.GetObject().Bounds()

    face = BRepBuilderAPI_MakeFace(plate.Surface(), uMin, uMax, vMin, vMax)
    face.Build()
    return face
Esempio n. 3
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()
Esempio n. 5
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()
Esempio n. 6
0
 def update_shape(self, change):
     wires = [c for c in self.children() if isinstance(c, OccShape)]
     for i, wire in enumerate(wires):
         if i == 0:
             shape = BRepBuilderAPI_MakeFace(wire.shape.Wire())
         else:
             shape.Add(wire.shape.Wire())
     self.shape = shape
Esempio n. 7
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
Esempio n. 8
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()
Esempio n. 9
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()
Esempio n. 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()
Esempio n. 11
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()
Esempio n. 12
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
def brep_feat_rib(event=None):
    mkw = BRepBuilderAPI_MakeWire()

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

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

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

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

    aform = BRepFeat_MakeLinearForm(S.Shape(), W.Wire(), aplane.GetHandle(),
                                    gp_Vec(0., 10., 0.), gp_Vec(0., 0., 0.),
                                    1, True)
    aform.Perform()
    display.DisplayShape(aform.Shape())
    display.FitAll()
 def get_gordon_surface(self):
     if self.gordon_surface is not None:
         return self.gordon_surface
     
     s = tigl3.surface_factories.interpolate_curve_network([self.curve1, self.curve2, self.curve3], [self.te_up, self.le, self.te_lo])
     self.gordon_surface = BRepBuilderAPI_MakeFace(s, 1e-6).Face()
     return self.surface_skin      
def pipe_fillet(radius):
    # the points
    p1 = gp_Pnt(0, 0, 0)
    p2 = gp_Pnt(0, 1, 0)
    p3 = gp_Pnt(1, 2, 0)
    p4 = gp_Pnt(2, 2, 0)
    # the edges
    ed1 = BRepBuilderAPI_MakeEdge(p1, p2).Edge()
    ed2 = BRepBuilderAPI_MakeEdge(p2, p3).Edge()
    ed3 = BRepBuilderAPI_MakeEdge(p3, p4).Edge()
    # inbetween
    fillet12 = filletEdges(ed1, ed2)
    fillet23 = filletEdges(ed2, ed3)
    # the wire
    makeWire = BRepBuilderAPI_MakeWire()
    makeWire.Add(ed1)
    makeWire.Add(fillet12)
    makeWire.Add(ed2)
    makeWire.Add(fillet23)
    makeWire.Add(ed3)
    makeWire.Build()
    wire = makeWire.Wire()
    # the pipe
    dir = gp_Dir(0, 1, 0)
    circle = gp_Circ(gp_Ax2(p1, dir), radius)
    profile_edge = BRepBuilderAPI_MakeEdge(circle).Edge()
    profile_wire = BRepBuilderAPI_MakeWire(profile_edge).Wire()
    profile_face = BRepBuilderAPI_MakeFace(profile_wire).Face()
    pipe = BRepOffsetAPI_MakePipe(wire, profile_face).Shape()
    #display.DisplayShape(pipe, update=True)
    return (pipe)
 def get_skinned_surface(self):
     if self.surface_skin is not None:
         return self.surface_skin
     
     s = tigl3.surface_factories.interpolate_curves([self.curve1, self.curve2, self.curve3])
     self.surface_skin = BRepBuilderAPI_MakeFace(s, 1e-6).Face()
     return self.surface_skin
Esempio n. 17
0
def srf_nrml_facing_solid_inward(occ_face, occ_solid):
    #move the face in the direction of the normal
    #first offset the face so that vert will be within the solid
    o_wire = Construct.make_offset(occ_face, 0.0001)
    o_face = BRepBuilderAPI_MakeFace(o_wire).Face()

    wire_list = list(Topology.Topo(o_face).wires())
    occpt_list = []
    for wire in wire_list:
        occpts = Topology.WireExplorer(wire).ordered_vertices()
        occpt_list.extend(occpts)

    pt = BRep_Tool.Pnt(occpt_list[0])  #a point that is on the edge of the face
    normal = face_normal(occ_face)

    gp_direction2move = gp_Vec(normal[0], normal[1], normal[2])
    gp_moved_pt = pt.Translated(gp_direction2move.Multiplied(0.001))
    mv_pt = (gp_moved_pt.X(), gp_moved_pt.Y(), gp_moved_pt.Z())

    in_solid = point_in_solid(occ_solid, mv_pt)

    if in_solid:
        return True
    else:
        return False
Esempio n. 18
0
def wire_frm_loose_edges(occedge_list):
    '''
    the edges need to be able to form a close face. IT does not work with a group of open edges
    need to change name to face from loose edges
    '''
    edges = TopTools_HSequenceOfShape()
    edges_handle = Handle_TopTools_HSequenceOfShape(edges)

    wires = TopTools_HSequenceOfShape()
    wires_handle = Handle_TopTools_HSequenceOfShape(wires)

    # The edges are copied to the sequence
    for edge in occedge_list:
        edges.Append(edge)

    # A wire is formed by connecting the edges
    ShapeAnalysis_FreeBounds.ConnectEdgesToWires(edges_handle, 1e-20, True,
                                                 wires_handle)
    wires = wires_handle.GetObject()

    # From each wire a face is created
    face_list = []
    for i in range(wires.Length()):
        wire_shape = wires.Value(i + 1)
        wire = fetch.shape2shapetype(wire_shape)
        face = BRepBuilderAPI_MakeFace(wire).Face()
        if not face.IsNull():
            face_list.append(face)

    return face_list
def split_edge_with_face(event=None):
    display.EraseAll()
    p0 = gp_Pnt()
    vnorm = gp_Dir(1, 0, 0)
    pln = gp_Pln(p0, vnorm)
    face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face()
    p1 = gp_Pnt(0, 0, 15)
    p2 = gp_Pnt(0, 0, -15)
    edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge()
    # Initialize splitter
    splitter = GEOMAlgo_Splitter()
    # Add the edge as an argument and the face as a tool. This will split
    # the edge with the face.
    splitter.AddArgument(edge)
    splitter.AddTool(face)
    splitter.Perform()

    edges = []
    exp = TopExp_Explorer(splitter.Shape(), TopAbs_EDGE)
    while exp.More():
        edges.append(exp.Current())
        exp.Next()
    print('Number of edges in split shape: ', len(edges))
    display.DisplayShape(edges[0], color='red')
    display.DisplayShape(edges[1], color='green')
    display.DisplayShape(edges[2], color='yellow')
    display.FitAll()
Esempio n. 20
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())
Esempio n. 21
0
def slicer(event=None):
    # Param
    Zmin, Zmax, deltaZ = -100, 100, 5
    # Note: the shape can also come from a shape selected from InteractiveViewer
    if 'display' in dir():
        shape = display.GetSelectedShape()
    else:
        # Create the shape to slice
        shape = BRepPrimAPI_MakeSphere(60.).Shape()
    # Define the direction
    D = gp_Dir(0., 0., 1.)  # the z direction
    # Perform slice
    sections = []
    init_time = time.time()  # for total time computation
    for z in range(Zmin, Zmax, deltaZ):
        # Create Plane defined by a point and the perpendicular direction
        P = gp_Pnt(0, 0, z)
        Pln = gp_Pln(P, D)
        face = BRepBuilderAPI_MakeFace(Pln).Shape()
        # Computes Shape/Plane intersection
        section_shp = BRepAlgoAPI_Section(shape, face)
        if section_shp.IsDone():
            sections.append(section_shp)
    total_time = time.time() - init_time
    print("%.3fs necessary to perform slice." % total_time)

    display.EraseAll()
    display.DisplayShape(shape)
    for section_ in sections:
        display.DisplayShape(section_.Shape())
    display.FitAll()
def makeFacefromWire(wire):
    """ Create face from Wire"""

    face = BRepBuilderAPI_MakeFace(wire.Wire())
    if args.v >= 1: print('Face are created')

    return face
Esempio n. 23
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
Esempio n. 24
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")
Esempio n. 25
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()
Esempio n. 26
0
    def from_wire(cls, topo: Union[Topo, TopoDS_Shape], plane: Optional[gp_Pln] = None) -> TopoDS_Face:
        """ create face from compound of edges """
        # if topo.number_of_wires() == 0:
        from .Construct import assert_isdone

        wire_builder = BRepBuilderAPI_MakeWire()
        if isinstance(topo, TopoDS_Shape):
            top = Topo(topo)
        else:
            top = topo

        for edge in top.edges():
            wire_builder.Add(edge)

        with assert_isdone(wire_builder, 'wire'):
            wire_builder.Build()
            w = wire_builder.Wire()

            if plane is not None:
                bface = BRepBuilderAPI_MakeFace(plane)

            else:
                # todo - this doesnt work ----
                _face = TopoDS_Face()
                bface = BRepBuilderAPI_MakeFace(_face)

            bface.Add(w)
            with assert_isdone(bface, 'face'):
                bface.Build()
                face = bface.Shape()
                return face
Esempio n. 27
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')
Esempio n. 28
0
    def makePlane(cls, length, width, basePnt=(0, 0, 0), dir=(0, 0, 1)):
        basePnt = Vector(basePnt)
        dir = Vector(dir)

        pln_geom = gp_Pln(basePnt.toPnt(), dir.toDir())

        return cls(
            BRepBuilderAPI_MakeFace(pln_geom, -width * 0.5, width * 0.5,
                                    -length * 0.5, length * 0.5).Face())
Esempio n. 29
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
Esempio n. 30
0
 def update_shape(self, change):
     d = self.declaration
     if d.wires:
         wires = d.wires
     else:
         wires = [c for c in self.children() if isinstance(c, OccShape)]
     if not wires:
         raise ValueError("No wires or children available to "
                          "create a face!")
     for i, wire in enumerate(wires):
         if hasattr(wire, 'shape'):
             args = (wire.shape.Wire(), )
         else:
             args = (wire, )
         if i == 0:
             shape = BRepBuilderAPI_MakeFace(*args)
         else:
             shape.Add(*args)
     self.shape = shape