def __init__(self, shape): if not shape.IsNull(): if not shape.ShapeType() == Shape.COMPSOLID: raise TypeError('Shape is not a TopoDS_CompSolid.') if not isinstance(shape, TopoDS_CompSolid): shape = TopoDS.CompSolid_(shape) super(CompSolid, self).__init__(shape)
def to_compsolid(cls, entity): """ Convert an entity to a compsolid. :param entity: The entity. :return: A compsolid. :rtype: OCCT.TopoDS.TopoDS_CompSolid :raise TypeError: If entity cannot be converted to a compsolid. """ if isinstance(entity, TopoDS_CompSolid): return entity if cls.is_shape(entity) and entity.ShapeType() == TopAbs_COMPSOLID: return TopoDS.CompSolid_(entity) raise TypeError('Failed to convert entity to a compsolid.')
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.')