コード例 #1
0
ファイル: entities.py プロジェクト: trelau/AFEM
 def __init__(self, shape):
     if not shape.IsNull():
         if not shape.ShapeType() == Shape.VERTEX:
             raise TypeError('Shape is not a TopoDS_Vertex.')
         if not isinstance(shape, TopoDS_Vertex):
             shape = TopoDS.Vertex_(shape)
     super(Vertex, self).__init__(shape)
コード例 #2
0
    def __init__(self, wire, face=None):
        if face is None:
            explorer = BRepTools_WireExplorer(wire)
        else:
            explorer = BRepTools_WireExplorer(wire, face)

        edges = []
        current_verts = []
        while explorer.More():
            ei = TopoDS.Edge_(explorer.Current())
            vi = TopoDS.Vertex_(explorer.CurrentVertex())
            edges.append(ei)
            current_verts.append(vi)
            explorer.Next()

        # CurrentVertex doesn't get the last vertex. Try to get it.
        ordered_verts = list(current_verts)
        if edges:
            data = ShapeExtend_WireData(wire)
            fix = ShapeFix_WireSegment(data)
            v1 = fix.LastVertex()
            ordered_verts.append(v1)

        self._edges = edges
        self._current_verts = current_verts
        self._ordered_verts = ordered_verts
コード例 #3
0
    def get_vertices(shape, unique=True):
        """
        Get vertices from a shape.

        :param OCCT.TopoDS.TopoDS_Shape shape: The shape.
        :param bool unique: Option to return only unique vertices.

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

        exp = TopExp_Explorer(shape, TopAbs_VERTEX)
        vertices = []
        while exp.More():
            vi = exp.Current()
            vertex = TopoDS.Vertex_(vi)
            if unique:
                is_unique = True
                for v in vertices:
                    if v.IsSame(vertex):
                        is_unique = False
                        break
                if is_unique:
                    vertices.append(vertex)
            else:
                vertices.append(vertex)
            exp.Next()
        return vertices
コード例 #4
0
ファイル: Check.py プロジェクト: tnakaicode/pyOCCT
    def to_vertex(cls, entity):
        """
        Convert an entity to a vertex.

        :param entity: The entity.

        :return: A vertex.
        :rtype: OCCT.TopoDS.TopoDS_Vertex

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

        if isinstance(entity, gp_Pnt):
            return BRepBuilderAPI_MakeVertex(entity).Vertex()

        if cls.is_shape(entity) and entity.ShapeType() == TopAbs_VERTEX:
            return TopoDS.Vertex_(entity)

        raise TypeError('Failed to convert entity to a vertex.')
コード例 #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.')