Ejemplo n.º 1
0
 def __init__(self, shape):
     if not shape.IsNull():
         if not shape.ShapeType() == Shape.SOLID:
             raise TypeError('Shape is not a TopoDS_Solid.')
         if not isinstance(shape, TopoDS_Solid):
             shape = TopoDS.Solid_(shape)
     super(Solid, self).__init__(shape)
Ejemplo n.º 2
0
    def to_solid(cls, entity):
        """
        Convert an entity to a solid.

        :param entity: The entity.

        :return: A solid.
        :rtype: OCCT.TopoDS.TopoDS_Solid

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

        if cls.is_shape(entity) and entity.ShapeType() == TopAbs_SOLID:
            return TopoDS.Solid_(entity)

        raise TypeError('Failed to convert entity to a solid.')
Ejemplo n.º 3
0
    def get_solids(shape):
        """
        Get solids from a shape.

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

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

        exp = TopExp_Explorer(shape, TopAbs_SOLID)
        solids = []
        while exp.More():
            si = exp.Current()
            solid = TopoDS.Solid_(si)
            solids.append(solid)
            exp.Next()
        return solids
Ejemplo n.º 4
0
    def __init__(self,
                 shapes,
                 intersect=False,
                 fuzzy_val=None,
                 nondestructive=False):
        super(VolumeMaker, self).__init__(None, None, fuzzy_val,
                                          nondestructive, BOPAlgo_MakerVolume)

        self.set_args(shapes)

        if intersect:
            self._bop.SetIntersect(True)
        else:
            self._bop.SetIntersect(False)

        self.build()

        self._solids = []
        for solid in ExploreShape.get_solids(self.shape):
            self._solids.append(TopoDS.Solid_(solid))
Ejemplo n.º 5
0
    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.')