Iterate over siblings, i.e. shapes within ctx shape that share subshapes of type kind with self.
(
self, ctx: Shape, kind: Shapes, level: int | Iterable[int] = 1
)
| 1756 | ) |
| 1757 | |
| 1758 | def siblings( |
| 1759 | self, ctx: Shape, kind: Shapes, level: int | Iterable[int] = 1 |
| 1760 | ) -> Compound: |
| 1761 | """ |
| 1762 | Iterate over siblings, i.e. shapes within ctx shape that share subshapes of type kind with self. |
| 1763 | """ |
| 1764 | |
| 1765 | shape_map = TopTools_IndexedDataMapOfShapeListOfShape() |
| 1766 | TopExp.MapShapesAndAncestors_s( |
| 1767 | ctx.wrapped, inverse_shape_LUT[kind], shapetype(self.wrapped), shape_map, |
| 1768 | ) |
| 1769 | exclude = TopTools_MapOfShape() |
| 1770 | |
| 1771 | def _siblings(shapes: Iterable[Shape], level: int) -> set[Shape]: |
| 1772 | |
| 1773 | rv: set[Shape] = set() |
| 1774 | |
| 1775 | for s in shapes: |
| 1776 | exclude.Add(s.wrapped) |
| 1777 | |
| 1778 | for s in shapes: |
| 1779 | |
| 1780 | rv.update( |
| 1781 | Shape.cast(el) |
| 1782 | for child in s._entities(kind) |
| 1783 | for el in shape_map.FindFromKey(child) |
| 1784 | if not exclude.Contains(el) |
| 1785 | ) |
| 1786 | |
| 1787 | return rv if level == 1 else _siblings(rv, level - 1) |
| 1788 | |
| 1789 | # simple query |
| 1790 | if isinstance(level, int): |
| 1791 | rv = _siblings([self], level) |
| 1792 | else: |
| 1793 | # collect all the requested levels |
| 1794 | rv = set() |
| 1795 | for lvl in level: |
| 1796 | exclude.Clear() |
| 1797 | rv |= _siblings([self], lvl) |
| 1798 | |
| 1799 | return Compound.makeCompound(rv) |
| 1800 | |
| 1801 | def __add__(self, other: Shape) -> Shape: |
| 1802 | """ |
nothing calls this directly
no test coverage detected