|
75 | 75 | topods_Solid, |
76 | 76 | ) |
77 | 77 |
|
78 | | -from OCC.Core.TopoDS import TopoDS_Compound, TopoDS_Builder |
| 78 | +from OCC.Core.TopoDS import TopoDS_Compound, TopoDS_Builder, TopoDS_Iterator |
79 | 79 |
|
80 | 80 | from OCC.Core.GC import GC_MakeArcOfCircle, GC_MakeArcOfEllipse # geometry construction |
81 | 81 | from OCC.Core.GCE2d import GCE2d_MakeSegment |
@@ -587,30 +587,59 @@ def transformGeometry(self, tMatrix): |
587 | 587 | def __hash__(self): |
588 | 588 | return self.hashCode() |
589 | 589 |
|
590 | | - def cut(self, toCut): |
| 590 | + def _bool_op(self, args, tools, op): |
| 591 | + """ |
| 592 | + Generic boolean operation |
| 593 | + """ |
| 594 | + |
| 595 | + arg = TopTools_ListOfShape() |
| 596 | + for obj in args: |
| 597 | + arg.Append(obj.wrapped) |
| 598 | + |
| 599 | + tool = TopTools_ListOfShape() |
| 600 | + for obj in tools: |
| 601 | + tool.Append(obj.wrapped) |
| 602 | + |
| 603 | + op.SetArguments(arg) |
| 604 | + op.SetTools(tool) |
| 605 | + |
| 606 | + op.SetRunParallel(True) |
| 607 | + op.Build() |
| 608 | + |
| 609 | + return Shape.cast(op.Shape()) |
| 610 | + |
| 611 | + def cut(self, *toCut): |
591 | 612 | """ |
592 | 613 | Remove a shape from another one |
593 | 614 | """ |
594 | | - return Shape.cast(BRepAlgoAPI_Cut(self.wrapped, toCut.wrapped).Shape()) |
595 | 615 |
|
596 | | - def fuse(self, toFuse): |
| 616 | + cut_op = BRepAlgoAPI_Cut() |
| 617 | + |
| 618 | + return self._bool_op((self,), toCut, cut_op) |
| 619 | + |
| 620 | + def fuse(self, *toFuse): |
597 | 621 | """ |
598 | 622 | Fuse shapes together |
599 | 623 | """ |
600 | 624 |
|
601 | | - fuse_op = BRepAlgoAPI_Fuse(self.wrapped, toFuse.wrapped) |
| 625 | + fuse_op = BRepAlgoAPI_Fuse() |
| 626 | + # fuse_op.SetFuzzyValue(TOLERANCE) |
| 627 | + |
| 628 | + rv = self._bool_op((self,), toFuse, fuse_op) |
| 629 | + |
602 | 630 | fuse_op.RefineEdges() |
603 | 631 | fuse_op.FuseEdges() |
604 | | - # fuse_op.SetFuzzyValue(TOLERANCE) |
605 | | - fuse_op.Build() |
606 | 632 |
|
607 | | - return Shape.cast(fuse_op.Shape()) |
| 633 | + return rv |
608 | 634 |
|
609 | | - def intersect(self, toIntersect): |
| 635 | + def intersect(self, *toIntersect): |
610 | 636 | """ |
611 | 637 | Construct shape intersection |
612 | 638 | """ |
613 | | - return Shape.cast(BRepAlgoAPI_Common(self.wrapped, toIntersect.wrapped).Shape()) |
| 639 | + |
| 640 | + intersect_op = BRepAlgoAPI_Common() |
| 641 | + |
| 642 | + return self._bool_op((self,), toIntersect, intersect_op) |
614 | 643 |
|
615 | 644 | def _repr_html_(self): |
616 | 645 | """ |
@@ -1939,6 +1968,51 @@ def makeText( |
1939 | 1968 |
|
1940 | 1969 | return cls(text_3d.Shape()).transformShape(position.rG) |
1941 | 1970 |
|
| 1971 | + def __iter__(self): |
| 1972 | + """ |
| 1973 | + Iterate over subshapes. |
| 1974 | +
|
| 1975 | + """ |
| 1976 | + |
| 1977 | + it = TopoDS_Iterator(self.wrapped) |
| 1978 | + |
| 1979 | + while it.More(): |
| 1980 | + yield Shape.cast(it.Value()) |
| 1981 | + it.Next() |
| 1982 | + |
| 1983 | + def cut(self, *toCut): |
| 1984 | + """ |
| 1985 | + Remove a shape from another one |
| 1986 | + """ |
| 1987 | + |
| 1988 | + cut_op = BRepAlgoAPI_Cut() |
| 1989 | + |
| 1990 | + return self._bool_op(self, toCut, cut_op) |
| 1991 | + |
| 1992 | + def fuse(self, *toFuse): |
| 1993 | + """ |
| 1994 | + Fuse shapes together |
| 1995 | + """ |
| 1996 | + |
| 1997 | + fuse_op = BRepAlgoAPI_Fuse() |
| 1998 | + # fuse_op.SetFuzzyValue(TOLERANCE) |
| 1999 | + |
| 2000 | + rv = self._bool_op(self, toFuse, fuse_op) |
| 2001 | + |
| 2002 | + # fuse_op.RefineEdges() |
| 2003 | + # fuse_op.FuseEdges() |
| 2004 | + |
| 2005 | + return rv |
| 2006 | + |
| 2007 | + def intersect(self, *toIntersect): |
| 2008 | + """ |
| 2009 | + Construct shape intersection |
| 2010 | + """ |
| 2011 | + |
| 2012 | + intersect_op = BRepAlgoAPI_Common() |
| 2013 | + |
| 2014 | + return self._bool_op(self, toIntersect, intersect_op) |
| 2015 | + |
1942 | 2016 |
|
1943 | 2017 | def sortWiresByBuildOrder(wireList, result={}): |
1944 | 2018 | """Tries to determine how wires should be combined into faces. |
|
0 commit comments