Exemple #1
0
 def create_shape(self):
     shape = BRepBuilderAPI_MakePolygon()
     for m in re.finditer(r'(\-?\d+\.?\d*),(\-?\d+\.?\d*)\s+',
                          self.element.attrib.get('points', '')):
         x, y = map(float, m.groups())
         shape.Add(gp_Pnt(x, y, 0))
     return shape.Wire()
Exemple #2
0
 def __init__(self, pnts, close=False):
     builder = BRepBuilderAPI_MakePolygon()
     for p in pnts:
         p = CheckGeom.to_point(p)
         builder.Add(p)
     if close:
         builder.Close()
     self._w = Wire(builder.Wire())
Exemple #3
0
 def create_shape(self):
     d = self.declaration
     t = self.get_transform()
     shape = BRepBuilderAPI_MakePolygon()
     for p in d.points:
         shape.Add(p.proxy.Transformed(t))
     if d.closed:
         shape.Close()
     curve = self.curve = BRepAdaptor_CompCurve(shape.Wire())
     self.shape = curve.Wire()
Exemple #4
0
    def by_points(pnts, close=False):
        """
        Create polygonal wire by connecting points.

        :param collections.Sequence(point_like) pnts: The ordered points.
        :param bool close: Option to close the wire.

        :return: The new wire.
        :rtype: afem.topology.entities.Wire
        """
        builder = BRepBuilderAPI_MakePolygon()
        for p in pnts:
            p = CheckGeom.to_point(p)
            builder.Add(p)
        if close:
            builder.Close()
        return Wire(builder.Wire())
def make_closed_polygon(*args):
    poly = BRepBuilderAPI_MakePolygon()
    for pt in args:
        if isinstance(pt, list) or isinstance(pt, tuple):
            for i in pt:
                poly.Add(i)
        else:
            poly.Add(pt)
    poly.Build()
    poly.Close()
    result = poly.Wire()
    return result
Exemple #6
0
def make_closed_polygon(*args):
    poly = BRepBuilderAPI_MakePolygon()
    for pt in args:
        if isinstance(pt, list) or isinstance(pt, tuple):
            for i in pt:
                poly.Add(i)
        else:
            poly.Add(pt)
    poly.Build()
    poly.Close()
    with assert_isdone(poly, 'failed to produce wire'):
        result = poly.Wire()
        return result
Exemple #7
0
def make_polygon(args, closed=False):
    poly = BRepBuilderAPI_MakePolygon()
    for pt in args:
        # support nested lists
        if isinstance(pt, list) or isinstance(pt, tuple):
            for i in pt:
                poly.Add(i)
        else:
            poly.Add(pt)
    if closed:
        poly.Close()
    poly.Build()

    with assert_isdone(poly, 'failed to produce wire'):
        result = poly.Wire()
        return result
Exemple #8
0
def evolved_shape():
    P = BRepBuilderAPI_MakePolygon()
    P.Add(gp_Pnt(0., 0., 0.))
    P.Add(gp_Pnt(200., 0., 0.))
    P.Add(gp_Pnt(200., 200., 0.))
    P.Add(gp_Pnt(0., 200., 0.))
    P.Add(gp_Pnt(0., 0., 0.))
    wprof = BRepBuilderAPI_MakePolygon(gp_Pnt(0., 0., 0.),
                                       gp_Pnt(-60., -60., -200.))
    S = BRepOffsetAPI_MakeEvolved(P.Wire(), wprof.Wire(), GeomAbs_Arc, True,
                                  False, True, 0.0001)
    S.Build()
    display.DisplayShape(S.Shape(), update=True)
Exemple #9
0
    def create_shape(self):
        d = self.declaration
        t = self.get_transform()
        w, h = d.width, d.height
        if d.rx or d.ry:
            rx, ry = d.rx, d.ry
            if not ry:
                ry = rx
            elif not rx:
                rx = ry

            # Clamp to the valid range
            rx = min(w / 2, rx)
            ry = min(h / 2, ry)

            # Bottom
            p1 = gp_Pnt(0 + rx, 0, 0)
            p2 = gp_Pnt(0 + w - rx, 0, 0)

            # Right
            p3 = gp_Pnt(w, ry, 0)
            p4 = gp_Pnt(w, h - ry, 0)

            # Top
            p5 = gp_Pnt(w - rx, h, 0)
            p6 = gp_Pnt(rx, h, 0)

            # Left
            p7 = gp_Pnt(0, h - ry, 0)
            p8 = gp_Pnt(0, ry, 0)

            shape = BRepBuilderAPI_MakeWire()

            e = d.tolerance

            # Bottom
            if not p1.IsEqual(p2, e):
                shape.Add(BRepBuilderAPI_MakeEdge(p1, p2).Edge())

            # Arc bottom right
            c = make_ellipse((w - rx, ry, 0), rx, ry)
            shape.Add(
                BRepBuilderAPI_MakeEdge(
                    GC_MakeArcOfEllipse(c, p2, p3, False).Value()).Edge())

            # Right
            if not p3.IsEqual(p4, e):
                shape.Add(BRepBuilderAPI_MakeEdge(p3, p4).Edge())

            # Arc top right
            c.SetLocation(gp_Pnt(w - rx, h - ry, 0))
            shape.Add(
                BRepBuilderAPI_MakeEdge(
                    GC_MakeArcOfEllipse(c, p4, p5, False).Value()).Edge())

            # Top
            if not p5.IsEqual(p6, e):
                shape.Add(BRepBuilderAPI_MakeEdge(p5, p6).Edge())

            # Arc top left
            c.SetLocation(gp_Pnt(rx, h - ry, 0))
            shape.Add(
                BRepBuilderAPI_MakeEdge(
                    GC_MakeArcOfEllipse(c, p6, p7, False).Value()).Edge())

            # Left
            if not p7.IsEqual(p8, e):
                shape.Add(BRepBuilderAPI_MakeEdge(p7, p8).Edge())

            # Arc bottom left
            c.SetLocation(gp_Pnt(rx, ry, 0))
            shape.Add(
                BRepBuilderAPI_MakeEdge(
                    GC_MakeArcOfEllipse(c, p8, p1, False).Value()).Edge())

            shape = shape.Wire()
            shape.Closed(True)
        else:
            shape = BRepBuilderAPI_MakePolygon(gp_Pnt(0, 0,
                                                      0), gp_Pnt(w, 0, 0),
                                               gp_Pnt(w, h, 0),
                                               gp_Pnt(0, h, 0), True).Wire()
        wire = TopoDS.Wire_(BRepBuilderAPI_Transform(shape, t, False).Shape())
        self.curve = BRepAdaptor_CompCurve(wire)
        self.shape = wire
Exemple #10
0
    def create_shape(self):
        attrs = self.element.attrib
        x = parse_unit(attrs.get('x', 0))
        y = parse_unit(attrs.get('y', 0))
        w = parse_unit(attrs.get('width', 0))
        h = parse_unit(attrs.get('height', 0))
        rx = parse_unit(attrs.get('rx', 0))
        ry = parse_unit(attrs.get('ry', 0))
        if rx == ry == 0:
            shape = BRepBuilderAPI_MakePolygon(
                gp_Pnt(x, y, 0), gp_Pnt(x+w, y, 0),
                gp_Pnt(x+w, y+h, 0), gp_Pnt(x, y+h, 0),
                True
            )
            return shape.Wire()
        elif rx == 0:
            rx = ry
        elif ry == 0:
            ry = rx

        # Build the rect
        shape = BRepBuilderAPI_MakeWire()

        # Bottom
        p1 = gp_Pnt(x+rx, y, 0)
        p2 = gp_Pnt(x+w-rx, y, 0)

        # Right
        p3 = gp_Pnt(x+w, y+ry, 0)
        p4 = gp_Pnt(x+w, y+h-ry, 0)

        # Top
        p5 = gp_Pnt(x+w-rx, y+h, 0)
        p6 = gp_Pnt(x+rx, y+h, 0)

        # Left
        p7 = gp_Pnt(x, y+h-ry, 0)
        p8 = gp_Pnt(x, y+ry, 0)

        # Bottom
        shape.Add(BRepBuilderAPI_MakeEdge(p1, p2).Edge())

        # Arc bottom right
        c = make_ellipse((x+w-rx, y+ry, 0), rx, ry)
        shape.Add(BRepBuilderAPI_MakeEdge(
            GC_MakeArcOfEllipse(c, p2, p3, False).Value()).Edge())

        # Right
        shape.Add(BRepBuilderAPI_MakeEdge(p3, p4).Edge())

        # Arc top right
        c.SetLocation(gp_Pnt(x+w-rx, y+h-ry, 0))
        shape.Add(BRepBuilderAPI_MakeEdge(
            GC_MakeArcOfEllipse(c, p4, p5, False).Value()).Edge())

        # Top
        shape.Add(BRepBuilderAPI_MakeEdge(p5, p6).Edge())

        # Arc top left
        c.SetLocation(gp_Pnt(x+rx, y+h-ry, 0))
        shape.Add(BRepBuilderAPI_MakeEdge(
            GC_MakeArcOfEllipse(c, p6, p7, False).Value()).Edge())

        # Left
        shape.Add(BRepBuilderAPI_MakeEdge(p7, p8).Edge())

        # Arc bottom left
        c.SetLocation(gp_Pnt(x+rx, y+ry, 0))
        shape.Add(BRepBuilderAPI_MakeEdge(
            GC_MakeArcOfEllipse(c, p8, p1, False).Value()).Edge())

        wire = shape.Wire()
        wire.Closed(True)
        return wire
def get_faceted_L_shape(x, y, z):
    pnt_A = gp_Pnt(x + 0, y + 0, z + 0)
    pnt_B = gp_Pnt(x +20, y + 0, z + 0)
    pnt_C = gp_Pnt(x +20, y +10, z + 0)
    pnt_D = gp_Pnt(x + 0, y +10, z + 0)
    pnt_E = gp_Pnt(x + 0, y + 0, z +20)
    pnt_F = gp_Pnt(x +10, y + 0, z +20)
    pnt_G = gp_Pnt(x +10, y +10, z +20)
    pnt_H = gp_Pnt(x +0, y +10, z +20)
    pnt_I = gp_Pnt(x +10, y + 0, z +10)
    pnt_J = gp_Pnt(x +10, y +10, z +10)
    pnt_K = gp_Pnt(x +20, y + 0, z +10)
    pnt_L = gp_Pnt(x +20, y +10, z +10)

    face_1 = make_face_from_4_points(pnt_A, pnt_B, pnt_C, pnt_D)
    face_2 = make_face_from_4_points(pnt_B, pnt_C, pnt_L, pnt_K)
    face_3 = make_face_from_4_points(pnt_E, pnt_F, pnt_G, pnt_H)
    face_4 = make_face_from_4_points(pnt_A, pnt_E, pnt_H, pnt_D)
    face_5 = make_face_from_4_points(pnt_G, pnt_F, pnt_I, pnt_J)
    face_6 = make_face_from_4_points(pnt_I, pnt_K, pnt_L, pnt_J)

    polygon_1 = BRepBuilderAPI_MakePolygon()
    polygon_1.Add(pnt_A)
    polygon_1.Add(pnt_B)
    polygon_1.Add(pnt_K)
    polygon_1.Add(pnt_I)
    polygon_1.Add(pnt_F)
    polygon_1.Add(pnt_E)
    polygon_1.Close()

    face_7 = BRepBuilderAPI_MakeFace(polygon_1.Wire()).Face()
    polygon_2 = BRepBuilderAPI_MakePolygon()
    polygon_2.Add(pnt_D)
    polygon_2.Add(pnt_H)
    polygon_2.Add(pnt_G)
    polygon_2.Add(pnt_J)
    polygon_2.Add(pnt_L)
    polygon_2.Add(pnt_C)
    polygon_2.Close()
    face_8 = BRepBuilderAPI_MakeFace(polygon_2.Wire()).Face()

    sew = BRepBuilderAPI_Sewing()
    for face in [face_1, face_2, face_3, face_4, face_5, face_6, face_7, face_8]:
        sew.Add(face)
    sew.Perform()

    return sew.SewedShape()
def make_face_from_4_points(pnt1, pnt2, pnt3, pnt4):
    # frist create a closed polygon
    poly = BRepBuilderAPI_MakePolygon(pnt1, pnt2, pnt3, pnt4, True).Wire()
    # then build the face from the closed wire
    return BRepBuilderAPI_MakeFace(poly).Face()