|
7 | 7 | List,
|
8 | 8 | Sequence,
|
9 | 9 | Iterator,
|
| 10 | + Dict, |
10 | 11 | Any,
|
11 | 12 | overload,
|
12 | 13 | TypeVar,
|
|
136 | 137 | BRepOffsetAPI_MakeOffset,
|
137 | 138 | )
|
138 | 139 |
|
139 |
| -from OCP.BRepFilletAPI import BRepFilletAPI_MakeChamfer, BRepFilletAPI_MakeFillet |
| 140 | +from OCP.BRepFilletAPI import ( |
| 141 | + BRepFilletAPI_MakeChamfer, |
| 142 | + BRepFilletAPI_MakeFillet, |
| 143 | + BRepFilletAPI_MakeFillet2d, |
| 144 | +) |
140 | 145 |
|
141 | 146 | from OCP.TopTools import TopTools_IndexedDataMapOfShapeListOfShape, TopTools_ListOfShape
|
142 | 147 |
|
@@ -680,6 +685,28 @@ def _entities(self, topo_type: Shapes) -> List[TopoDS_Shape]:
|
680 | 685 |
|
681 | 686 | return list(out.values())
|
682 | 687 |
|
| 688 | + def _entitiesFrom( |
| 689 | + self, child_type: Shapes, parent_type: Shapes |
| 690 | + ) -> Dict["Shape", List["Shape"]]: |
| 691 | + |
| 692 | + res = TopTools_IndexedDataMapOfShapeListOfShape() |
| 693 | + |
| 694 | + TopTools_IndexedDataMapOfShapeListOfShape() |
| 695 | + TopExp.MapShapesAndAncestors_s( |
| 696 | + self.wrapped, |
| 697 | + inverse_shape_LUT[child_type], |
| 698 | + inverse_shape_LUT[parent_type], |
| 699 | + res, |
| 700 | + ) |
| 701 | + |
| 702 | + out: Dict[Shape, List[Shape]] = {} |
| 703 | + for i in range(1, res.Extent() + 1): |
| 704 | + out[Shape.cast(res.FindKey(i))] = [ |
| 705 | + Shape.cast(el) for el in res.FindFromIndex(i) |
| 706 | + ] |
| 707 | + |
| 708 | + return out |
| 709 | + |
683 | 710 | def Vertices(self) -> List["Vertex"]:
|
684 | 711 | """
|
685 | 712 | :returns: All the vertices in this Shape
|
@@ -904,6 +931,9 @@ def moved(self, loc: Location) -> "Shape":
|
904 | 931 | def __hash__(self) -> int:
|
905 | 932 | return self.hashCode()
|
906 | 933 |
|
| 934 | + def __eq__(self, other) -> bool: |
| 935 | + return self.isSame(other) |
| 936 | + |
907 | 937 | def _bool_op(
|
908 | 938 | self,
|
909 | 939 | args: Iterable["Shape"],
|
@@ -1778,6 +1808,24 @@ def offset2D(
|
1778 | 1808 |
|
1779 | 1809 | return rv
|
1780 | 1810 |
|
| 1811 | + def fillet2D(self, radius: float, vertices: Iterable[Vertex]) -> "Wire": |
| 1812 | + """ |
| 1813 | + Apply 2D fillet to a wire |
| 1814 | + """ |
| 1815 | + |
| 1816 | + f = Face.makeFromWires(self) |
| 1817 | + |
| 1818 | + return f.fillet2D(radius, vertices).outerWire() |
| 1819 | + |
| 1820 | + def chamfer2D(self, d: float, vertices: Iterable[Vertex]) -> "Wire": |
| 1821 | + """ |
| 1822 | + Apply 2D chamfer to a wire |
| 1823 | + """ |
| 1824 | + |
| 1825 | + f = Face.makeFromWires(self) |
| 1826 | + |
| 1827 | + return f.chamfer2D(d, vertices).outerWire() |
| 1828 | + |
1781 | 1829 |
|
1782 | 1830 | class Face(Shape):
|
1783 | 1831 | """
|
@@ -1974,6 +2022,43 @@ def makeFromWires(
|
1974 | 2022 |
|
1975 | 2023 | return cls(face).fix()
|
1976 | 2024 |
|
| 2025 | + def fillet2D(self, radius: float, vertices: Iterable[Vertex]) -> "Face": |
| 2026 | + """ |
| 2027 | + Apply 2D fillet to a face |
| 2028 | + """ |
| 2029 | + |
| 2030 | + fillet_builder = BRepFilletAPI_MakeFillet2d(self.wrapped) |
| 2031 | + |
| 2032 | + for v in vertices: |
| 2033 | + fillet_builder.AddFillet(v.wrapped, radius) |
| 2034 | + |
| 2035 | + fillet_builder.Build() |
| 2036 | + |
| 2037 | + return self.__class__(fillet_builder.Shape()) |
| 2038 | + |
| 2039 | + def chamfer2D(self, d: float, vertices: Iterable[Vertex]) -> "Face": |
| 2040 | + """ |
| 2041 | + Apply 2D chamfer to a face |
| 2042 | + """ |
| 2043 | + |
| 2044 | + chamfer_builder = BRepFilletAPI_MakeFillet2d(self.wrapped) |
| 2045 | + edge_map = self._entitiesFrom("Vertex", "Edge") |
| 2046 | + |
| 2047 | + for v in vertices: |
| 2048 | + edges = edge_map[v] |
| 2049 | + if len(edges) < 2: |
| 2050 | + raise ValueError("Cannot chamfer at this location") |
| 2051 | + |
| 2052 | + e1, e2 = edges |
| 2053 | + |
| 2054 | + chamfer_builder.AddChamfer( |
| 2055 | + TopoDS.Edge_s(e1.wrapped), TopoDS.Edge_s(e2.wrapped), d, d |
| 2056 | + ) |
| 2057 | + |
| 2058 | + chamfer_builder.Build() |
| 2059 | + |
| 2060 | + return self.__class__(chamfer_builder.Shape()).fix() |
| 2061 | + |
1977 | 2062 |
|
1978 | 2063 | class Shell(Shape):
|
1979 | 2064 | """
|
|
0 commit comments