コード例 #1
0
ファイル: entities.py プロジェクト: trelau/AFEM
 def __init__(self, shape):
     if not shape.IsNull():
         if not shape.ShapeType() == Shape.COMPOUND:
             raise TypeError('Shape is not a TopoDS_Compound.')
         if not isinstance(shape, TopoDS_Compound):
             shape = TopoDS.Compound_(shape)
     super(Compound, self).__init__(shape)
コード例 #2
0
ファイル: Check.py プロジェクト: tnakaicode/pyOCCT
    def to_compound(cls, entity):
        """
        Convert an entity to a compound.

        :param entity: The entity.

        :return: A compound
        :rtype: OCCT.TopoDS.TopoDS_Compound

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

        if cls.is_shape(entity) and entity.ShapeType() == TopAbs_COMPOUND:
            return TopoDS.Compound_(entity)

        if cls.is_shape(entity):
            cp = TopoDS_Compound
            builder = BRep_Builder()
            builder.MakeCompound(cp)
            builder.Add(cp, entity)
            return cp

        raise TypeError('Failed to convert entity to a compound.')
コード例 #3
0
    def get_compounds(shape):
        """
        Get compounds from a shape.

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

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

        exp = TopExp_Explorer(shape, TopAbs_COMPOUND)
        compounds = []
        while exp.More():
            ci = exp.Current()
            compound = TopoDS.Compound_(ci)
            compounds.append(compound)
            exp.Next()
        return compounds
コード例 #4
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.')