Ejemplo n.º 1
0
 def num_faces(self):
     """
     :return: The number of faces in the shape.
     :rtype: int
     """
     map_ = TopTools_IndexedMapOfShape()
     topexp.MapShapes(self.object, Shape.FACE, map_)
     return map_.Extent()
Ejemplo n.º 2
0
def generate_shape_maps(compound):
    face_map = TopTools_IndexedMapOfShape()
    wire_map = TopTools_IndexedMapOfShape()
    edge_map = TopTools_IndexedMapOfShape()
    topexp.MapShapes(compound, TopAbs_FACE, face_map)
    topexp.MapShapes(compound, TopAbs_WIRE, wire_map)
    topexp.MapShapes(compound, TopAbs_EDGE, edge_map)
    return (face_map, wire_map, edge_map)
Ejemplo n.º 3
0
 def _get_shapes(self, type_):
     """
     Get sub-shapes of a specified type from the shape.
     """
     map_ = TopTools_IndexedMapOfShape()
     topexp.MapShapes(self.object, type_, map_)
     shapes = []
     for i in range(1, map_.Size() + 1):
         shapes.append(Shape.wrap(map_.FindKey(i)))
     return shapes
Ejemplo n.º 4
0
    def shared_faces(self, other, as_compound=False):
        """
        Get shared faces between this shape and the other.

        :param afem.topology.entities.Shape other: The other shape.
        :param bool as_compound: Option to return shared shapes as a single
            compound.

        :return: Shared faces.
        :rtype: list(afem.topology.entities.Face) or
            afem.topology.entities.Compound
        """
        this_map = TopTools_IndexedMapOfShape()
        topexp.MapShapes(self.object, Shape.FACE, this_map)
        if this_map.Extent() == 0:
            return []

        other_map = TopTools_IndexedMapOfShape()
        topexp.MapShapes(other.object, Shape.FACE, other_map)
        if other_map.Extent() == 0:
            return []

        faces = []
        for i in range(1, this_map.Size() + 1):
            f1 = this_map.FindKey(i)
            if other_map.Contains(f1):
                faces.append(Shape.wrap(f1))

        if as_compound:
            return Compound.by_shapes(faces)
        return faces
Ejemplo n.º 5
0
    def __init__(self, old_shapes, tool):
        reshape = ShapeBuild_ReShape()

        self._new_shapes = TopTools_DataMapOfShapeShape()
        index_map = TopTools_IndexedMapOfShape()

        for old_shape in old_shapes:
            # Old shapes
            shapes = old_shape.faces
            if not shapes:
                shapes = old_shape.edges
            if not shapes:
                shapes = old_shape.vertices
            if not shapes:
                continue

            # Delete and replace
            for shape in shapes:
                # Deleted
                if tool.is_deleted(shape):
                    reshape.Remove(shape.object)
                    continue

                # Modified considering shapes already used
                mod_shapes = tool.modified(shape)
                replace_shapes = []
                for mod_shape in mod_shapes:
                    if index_map.Contains(mod_shape.object):
                        continue
                    replace_shapes.append(mod_shape)
                    index_map.Add(mod_shape.object)

                if replace_shapes:
                    new_shape = Compound.by_shapes(replace_shapes)
                    reshape.Replace(shape.object, new_shape.object)

            new_shape = Shape.wrap(reshape.Apply(old_shape.object))
            self._new_shapes.Bind(old_shape.object, new_shape.object)