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
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()
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
def _map_shapes_and_ancestors(self, topo_type_a, topo_type_b, topo_entity): ''' using the same method @param topoTypeA: @param topoTypeB: @param topological_entity: ''' topo_set = set() items = [] topo_map = TopTools_IndexedDataMapOfShapeListOfShape() TopExp.MapShapesAndAncestors_(self.shape, topo_type_a, topo_type_b, topo_map) topo_results = topo_map.FindFromKey(topo_entity) if topo_results.IsEmpty(): return [] topology_iterator = TopTools_ListIteratorOfListOfShape(topo_results) factory = self.topo_factory[topo_type_b] while topology_iterator.More(): topo_entity = factory(topology_iterator.Value()) # return the entity if not in set # to assure we're not returning entities several times if topo_entity not in topo_set: if self.ignore_orientation: unique = True for i in topo_set: if i.IsSame(topo_entity): unique = False break if unique: items.append(topo_entity) else: items.append(topo_entity) topo_set.add(topo_entity) topology_iterator.Next() return items
def _number_shapes_ancestors(self, topo_type_a, topo_type_b, topological_entity): """ Get the number of shape ancestors If you want to know how many edges a faces has: _number_shapes_ancestors(self, TopAbs_EDGE, TopAbs_FACE, edg) will return the number of edges a faces has @param topo_type_a: @param topo_type_b: @param topological_entity: """ topo_set = set() _map = TopTools_IndexedDataMapOfShapeListOfShape() TopExp.MapShapesAndAncestors_(self.shape, topo_type_a, topo_type_b, _map) results = _map.FindFromKey(topological_entity) if results.IsEmpty(): return None topology_iterator = TopTools_ListIteratorOfListOfShape(results) while topology_iterator.More(): topo_set.add(topology_iterator.Value()) topology_iterator.Next() return len(topo_set)
def test_FindSubShape(self): """ Test XCAFDoc_ShapeTool:FindSubShape. """ names = [ 'back face', 'front face', 'left face', 'right face', 'bottom face', 'top face' ] labels = TDF_LabelSequence() self._tool.GetShapes(labels) self.assertFalse(labels.IsEmpty()) self.assertEqual(labels.Length(), 1) label = labels.Value(1) named_shape = TNaming_NamedShape() status, named_shape = label.FindAttribute(TNaming_NamedShape.GetID_(), named_shape) self.assertTrue(status) shape = named_shape.Get() self.assertEqual(shape.ShapeType(), TopAbs_ShapeEnum.TopAbs_SOLID) map_ = TopTools_IndexedMapOfShape() TopExp.MapShapes_(shape, TopAbs_ShapeEnum.TopAbs_FACE, map_) for i in range(1, map_.Size() + 1): face = map_.FindKey(i) status, sub_label = self._tool.FindSubShape(label, face) self.assertTrue(status) name = TDataStd_Name() status, name = sub_label.FindAttribute(TDataStd_Name.GetID_(), name) self.assertTrue(status) name = name.Get().ToExtString() self.assertEqual(name, names[i - 1])