예제 #1
0
파일: entities.py 프로젝트: trelau/AFEM
 def __init__(self, shape):
     if not shape.IsNull():
         if not shape.ShapeType() == Shape.WIRE:
             raise TypeError('Shape is not a TopoDS_Wire.')
         if not isinstance(shape, TopoDS_Wire):
             shape = TopoDS.Wire_(shape)
     super(Wire, self).__init__(shape)
예제 #2
0
 def shape_to_face(self, shape):
     if isinstance(shape, OccShape):
         shape = shape.shape
     shape = Topology.cast_shape(shape)
     if isinstance(shape, (TopoDS_Face, TopoDS_Wire)):
         return shape
     if isinstance(shape, TopoDS_Edge):
         return BRepBuilderAPI_MakeWire(shape).Wire()
     return TopoDS.Wire_(shape)
예제 #3
0
    def get_wires(shape):
        """
        Get wires from a shape.

        :param OCCT.TopoDS.TopoDS_Shape shape: The shape.

        :return: Wires of shape.
        :rtype: list[OCCT.TopoDS.TopoDS_Wire]
        """
        if isinstance(shape, TopoDS_Wire):
            return [shape]

        exp = TopExp_Explorer(shape, TopAbs_WIRE)
        wires = []
        while exp.More():
            wi = exp.Current()
            wire = TopoDS.Wire_(wi)
            wires.append(wire)
            exp.Next()
        return wires
예제 #4
0
파일: Check.py 프로젝트: tnakaicode/pyOCCT
    def to_wire(cls, entity):
        """
        Convert an entity to a wire.

        :param entity: The entity.

        :return: A wire.
        :rtype: OCCT.TopoDS.TopoDS_Wire

        :raise TypeError: If entity cannot be converted to a wire.
        """
        if isinstance(entity, TopoDS_Wire):
            return entity

        if cls.is_shape(entity) and entity.ShapeType() == TopAbs_EDGE:
            return BRepBuilderAPI_MakeWire(entity).Wire()

        if cls.is_shape(entity) and entity.ShapeType() == TopAbs_WIRE:
            return TopoDS.Wire_(entity)

        raise TypeError('Failed to convert entity to a wire.')
예제 #5
0
파일: Check.py 프로젝트: tnakaicode/pyOCCT
    def to_shape(cls, entity):
        """
        Convert the entity to a shape. This method tries to convert the
        entity to its most specific shape type.

        :param entity: The entity.

        :return: A shape.
        :rtype: OCCT.TopoDS.TopoDS_Shape

        :raise TypeError: If entity cannot be converted to a shape.
        """
        if entity is None:
            return None

        # Shapes
        if isinstance(entity, TopoDS_Shape):
            if entity.IsNull():
                raise TypeError('Cannot convert null shape.')
            elif entity.ShapeType() == TopAbs_VERTEX:
                return TopoDS.Vertex_(entity)
            elif entity.ShapeType() == TopAbs_EDGE:
                return TopoDS.Edge_(entity)
            elif entity.ShapeType() == TopAbs_WIRE:
                return TopoDS.Wire_(entity)
            elif entity.ShapeType() == TopAbs_FACE:
                return TopoDS.Face_(entity)
            elif entity.ShapeType() == TopAbs_SHELL:
                return TopoDS.Shell_(entity)
            elif entity.ShapeType() == TopAbs_SOLID:
                return TopoDS.Solid_(entity)
            elif entity.ShapeType() == TopAbs_COMPSOLID:
                return TopoDS.CompSolid_(entity)
            elif entity.ShapeType() == TopAbs_COMPOUND:
                return TopoDS.Compound_(entity)
            else:
                raise TypeError('Failed to convert entity to a shape.')

        raise TypeError('Failed to convert entity to a shape.')
예제 #6
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