Iterate over siblings, i.e. shapes within shape that share subshapes of kind with the elements of self.
(
self, ctx: Shape, kind: Shapes, level: int | Iterable[int] = 1
)
| 4955 | ) |
| 4956 | |
| 4957 | def siblings( |
| 4958 | self, ctx: Shape, kind: Shapes, level: int | Iterable[int] = 1 |
| 4959 | ) -> Compound: |
| 4960 | """ |
| 4961 | Iterate over siblings, i.e. shapes within shape that share subshapes of kind with the elements of self. |
| 4962 | |
| 4963 | """ |
| 4964 | |
| 4965 | shape_map = TopTools_IndexedDataMapOfShapeListOfShape() |
| 4966 | shapetypes = set(shapetype(ch.wrapped) for ch in self) |
| 4967 | |
| 4968 | for t in shapetypes: |
| 4969 | TopExp.MapShapesAndAncestors_s( |
| 4970 | ctx.wrapped, inverse_shape_LUT[kind], t, shape_map, |
| 4971 | ) |
| 4972 | |
| 4973 | exclude = TopTools_MapOfShape() |
| 4974 | |
| 4975 | def _siblings(shapes: Iterable[Shape], level: int) -> set[Shape]: |
| 4976 | |
| 4977 | rv: set[Shape] = set() |
| 4978 | |
| 4979 | for s in shapes: |
| 4980 | exclude.Add(s.wrapped) |
| 4981 | |
| 4982 | for s in shapes: |
| 4983 | rv.update( |
| 4984 | Shape.cast(el) |
| 4985 | for child in s._entities(kind) |
| 4986 | for el in shape_map.FindFromKey(child) |
| 4987 | if not exclude.Contains(el) |
| 4988 | ) |
| 4989 | |
| 4990 | return rv if level == 1 else _siblings(rv, level - 1) |
| 4991 | |
| 4992 | # simple query |
| 4993 | if isinstance(level, int): |
| 4994 | rv = _siblings(self, level) |
| 4995 | else: |
| 4996 | # collect all the requested levels |
| 4997 | rv = set() |
| 4998 | for lvl in level: |
| 4999 | exclude.Clear() |
| 5000 | rv |= _siblings(self, lvl) |
| 5001 | |
| 5002 | return Compound.makeCompound(rv) |
| 5003 | |
| 5004 | |
| 5005 | def sortWiresByBuildOrder(wireList: list[Wire]) -> list[list[Wire]]: |
nothing calls this directly
no test coverage detected