#include <BOPAlgo_BOP.hxx>
#include <TopTools_ListOfShape.hxx>
+#include <TopoDS_Iterator.hxx>
+#include <TopExp_Explorer.hxx>
//=================================================================================================
GeomAlgoAPI_Boolean::GeomAlgoAPI_Boolean(const GeomShapePtr theObject,
this->setShape(aShape);
this->setDone(true);
}
+
+static bool isHistoryType(TopAbs_ShapeEnum theType) {
+ return theType == TopAbs_VERTEX || theType == TopAbs_EDGE ||
+ theType == TopAbs_FACE || theType == TopAbs_SOLID;
+}
+
+/// searches the corresponding result for theOld
+static void searchResult(const TopoDS_Shape& theOld, const TopoDS_Shape& theResult,
+ BOPAlgo_BOP* theBuilder, TopTools_MapOfShape& theNews)
+{
+ if (theResult.ShapeType() == theOld.ShapeType()) { // check some sub-shape produces a sub-result
+ if (theOld.IsSame(theResult)) {
+ theNews.Add(theResult);
+ return;
+ }
+ // searching for new result by sub-shapes of aSubType type
+ TopAbs_ShapeEnum aSubType = TopAbs_ShapeEnum(int(theOld.ShapeType()) + 1);
+ while(aSubType < TopAbs_VERTEX && !isHistoryType(aSubType))
+ aSubType = TopAbs_ShapeEnum(int(aSubType) + 1);
+ if (aSubType == TopAbs_SHAPE)
+ return;
+ TopTools_MapOfShape aResSubs;
+ for(TopExp_Explorer aResExp(theResult, aSubType); aResExp.More(); aResExp.Next())
+ aResSubs.Add(aResExp.Current());
+ for(TopExp_Explorer anExp(theOld, aSubType); anExp.More(); anExp.Next()) {
+ const TopTools_ListOfShape& aNewSubs = theBuilder->Modified(anExp.Current());
+ // searching for this new sub in theResult
+ for(TopTools_ListIteratorOfListOfShape aNewSub(aNewSubs); aNewSub.More(); aNewSub.Next()) {
+ if (aResSubs.Contains(aNewSub.Value())) {
+ theNews.Add(theResult);
+ return;
+ }
+ }
+ }
+ } else if (theResult.ShapeType() < theOld.ShapeType()) { // recursive search among sub-shapes
+ for(TopoDS_Iterator aSubResults(theResult); aSubResults.More(); aSubResults.Next()) {
+ searchResult(theOld, aSubResults.Value(), theBuilder, theNews);
+ }
+ }
+}
+
+// check the shape is on the higher level of compound or compsolid
+bool isInComp(const TopoDS_Shape& theComp, const TopoDS_Shape& theShape) {
+ if (theComp.ShapeType() == TopAbs_COMPOUND || theComp.ShapeType() == TopAbs_COMPSOLID) {
+ for(TopoDS_Iterator anIter(theComp); anIter.More(); anIter.Next()) {
+ if (isInComp(anIter.Value(), theShape))
+ return true;
+ }
+ } else return theShape.IsSame(theComp);
+ return false;
+}
+
+//=================================================================================================
+/// make arguments of Fuse produce result shapes with "modified" evolution
+void GeomAlgoAPI_Boolean::modified(const GeomShapePtr theOldShape, ListOfShape& theNewShapes)
+{
+ BOPAlgo_BOP* aBuilder = this->implPtr<BOPAlgo_BOP>();
+ if (aBuilder->Operation() == BOPAlgo_FUSE) { // only for fuse and when old is and argument
+ TopoDS_Shape anOld = theOldShape->impl<TopoDS_Shape>();
+ bool isOldComp = anOld.ShapeType() == TopAbs_COMPOUND || anOld.ShapeType() == TopAbs_COMPSOLID;
+ bool aFound = false;
+ TopTools_ListIteratorOfListOfShape anIter(aBuilder->Arguments());
+ for(; !aFound && anIter.More(); anIter.Next())
+ aFound = anOld.IsSame(anIter.Value()) || (!isOldComp && isInComp(anIter.Value(), anOld));
+ for(anIter.Initialize(aBuilder->Tools()); !aFound && anIter.More(); anIter.Next())
+ aFound = anOld.IsSame(anIter.Value()) || (!isOldComp && isInComp(anIter.Value(), anOld));
+ if (aFound) {
+ TopoDS_Shape aResult = aBuilder->Shape();
+ TopTools_MapOfShape aNewsMap;
+ searchResult(anOld, aResult, aBuilder, aNewsMap);
+ if (!aNewsMap.IsEmpty()) {
+ for(TopTools_MapIteratorOfMapOfShape aNewsIter(aNewsMap); aNewsIter.More(); aNewsIter.Next())
+ {
+ GeomShapePtr aShape(new GeomAPI_Shape);
+ aShape->setImpl<TopoDS_Shape>(new TopoDS_Shape(aNewsIter.Value()));
+ theNewShapes.push_back(aShape);
+ }
+ return;
+ }
+ }
+ }
+ GeomAlgoAPI_MakeShape::modified(theOldShape, theNewShapes); // default behavior
+}