From 65fb6fac9731831e7197d0841e4444e69eb7d7ce Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 21 Nov 2018 08:31:50 +0300 Subject: [PATCH] Basing on the issue #1757 make extrusion-cut that --- .../FeaturesPlugin_CompositeSketch.cpp | 39 ++++++++++++------- .../FeaturesPlugin_CompositeSketch.h | 5 ++- src/Model/Model_BodyBuilder.cpp | 15 ++++--- src/Model/Model_BodyBuilder.h | 5 ++- src/Model/Model_ResultBody.cpp | 12 ++++-- src/Model/Model_ResultBody.h | 4 +- src/ModelAPI/ModelAPI_BodyBuilder.h | 5 ++- src/ModelAPI/ModelAPI_ResultBody.cpp | 6 +-- src/ModelAPI/ModelAPI_ResultBody.h | 5 ++- src/Selector/Selector_FilterByNeighbors.cpp | 2 +- 10 files changed, 59 insertions(+), 39 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp index 398ff651c..272b43001 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp @@ -39,7 +39,8 @@ #include #include -static void storeSubShape(ResultBodyPtr theResultBody, +static void storeSubShape(const std::shared_ptr theMakeShape, + ResultBodyPtr theResultBody, const GeomShapePtr theShape, const GeomAPI_Shape::ShapeType theType, const std::string& theName); @@ -337,18 +338,20 @@ void FeaturesPlugin_CompositeSketch::storeGenerationHistory(ResultBodyPtr theRes std::list >::iterator aSweep = aSweeps.begin(); for(; aSweep != aSweeps.end(); aSweep++) { // Store from shapes. - storeShapes(theResultBody, aBaseShapeType, (*aSweep)->fromShapes(), "From_"); + storeShapes(theMakeShape, theResultBody, aBaseShapeType, (*aSweep)->fromShapes(), "From_"); // Store to shapes. - storeShapes(theResultBody, aBaseShapeType, (*aSweep)->toShapes(), "To_"); + storeShapes(theMakeShape, theResultBody, aBaseShapeType, (*aSweep)->toShapes(), "To_"); } } //================================================================================================= -void FeaturesPlugin_CompositeSketch::storeShapes(ResultBodyPtr theResultBody, - const GeomAPI_Shape::ShapeType theBaseShapeType, - const ListOfShape& theShapes, - const std::string theName) +void FeaturesPlugin_CompositeSketch::storeShapes( + const std::shared_ptr theMakeShape, + ResultBodyPtr theResultBody, + const GeomAPI_Shape::ShapeType theBaseShapeType, + const ListOfShape& theShapes, + const std::string theName) { GeomAPI_Shape::ShapeType aShapeTypeToExplore = GeomAPI_Shape::FACE; std::string aShapeTypeStr = "Face"; @@ -382,25 +385,31 @@ void FeaturesPlugin_CompositeSketch::storeShapes(ResultBodyPtr theResultBody, if(aShapeTypeToExplore == GeomAPI_Shape::COMPOUND) { std::string aName = theName + (aShape->shapeType() == GeomAPI_Shape::EDGE ? "Edge" : "Face"); - storeSubShape(theResultBody, aShape, aShape->shapeType(), aName); + storeSubShape(theMakeShape, theResultBody, aShape, aShape->shapeType(), aName); } else { std::string aName = theName + aShapeTypeStr; - storeSubShape(theResultBody, aShape, aShapeTypeToExplore, aName); + storeSubShape(theMakeShape, theResultBody, aShape, aShapeTypeToExplore, aName); if (theBaseShapeType == GeomAPI_Shape::WIRE) { // issue 2289: special names also for vertices aName = theName + "Vertex"; - storeSubShape(theResultBody, aShape, GeomAPI_Shape::VERTEX, aName); + storeSubShape(theMakeShape, theResultBody, aShape, GeomAPI_Shape::VERTEX, aName); } } } } -void storeSubShape(ResultBodyPtr theResultBody, - const GeomShapePtr theShape, - const GeomAPI_Shape::ShapeType theType, - const std::string& theName) +void storeSubShape( + const std::shared_ptr theMakeShape, + ResultBodyPtr theResultBody, + const GeomShapePtr theShape, + const GeomAPI_Shape::ShapeType theType, + const std::string& theName) { for(GeomAPI_ShapeExplorer anExp(theShape, theType); anExp.more(); anExp.next()) { GeomShapePtr aSubShape = anExp.current(); - theResultBody->generated(aSubShape, theName); + if (!theResultBody->generated(aSubShape, theName)) { + // store from/to shapes as primitives and then store modification of them by the boolean + theResultBody->generated(aSubShape, theName, false); + theResultBody->loadModifiedShapes(theMakeShape, aSubShape, theType); + } } } diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.h b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.h index 074def66b..e4774bde8 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.h +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.h @@ -96,8 +96,9 @@ protected: const GeomShapePtr theBaseShape, const std::shared_ptr theMakeShape); - /// Used to store from and to shapes. - void storeShapes(ResultBodyPtr theResultBody, + /// Used to store from and to shapes: generated, or in common modified tag + void storeShapes(const std::shared_ptr theMakeShape, + ResultBodyPtr theResultBody, const GeomAPI_Shape::ShapeType theBaseShapeType, const ListOfShape& theShapes, const std::string theName); diff --git a/src/Model/Model_BodyBuilder.cpp b/src/Model/Model_BodyBuilder.cpp index 8446d00cb..9c51617f1 100755 --- a/src/Model/Model_BodyBuilder.cpp +++ b/src/Model/Model_BodyBuilder.cpp @@ -317,14 +317,16 @@ void Model_BodyBuilder::buildName(const int theTag, const std::string& theName) TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(), aName.c_str()); } -void Model_BodyBuilder::generated(const GeomShapePtr& theNewShape, - const std::string& theName) +bool Model_BodyBuilder::generated(const GeomShapePtr& theNewShape, + const std::string& theName, + const bool theCheckIsInResult) { GeomShapePtr aResultShape = shape(); - - bool aNewShapeIsNotInResultShape = !aResultShape->isSubShape(theNewShape, false); - if (aNewShapeIsNotInResultShape) { - return; + if (theCheckIsInResult) { + bool aNewShapeIsNotInResultShape = !aResultShape->isSubShape(theNewShape, false); + if (aNewShapeIsNotInResultShape) { + return false; + } } TopoDS_Shape aShape = theNewShape->impl(); @@ -349,6 +351,7 @@ void Model_BodyBuilder::generated(const GeomShapePtr& theNewShape, buildName(myFreePrimitiveTag, aName); } ++myFreePrimitiveTag; + return true; } void Model_BodyBuilder::generated(const GeomShapePtr& theOldShape, diff --git a/src/Model/Model_BodyBuilder.h b/src/Model/Model_BodyBuilder.h index 78aac0349..440791b69 100755 --- a/src/Model/Model_BodyBuilder.h +++ b/src/Model/Model_BodyBuilder.h @@ -66,8 +66,9 @@ public: /// Records the subshape newShape which was generated during a topological construction. /// As an example, consider the case of a face generated in construction of a box. - MODEL_EXPORT virtual void generated(const GeomShapePtr& theNewShape, - const std::string& theName) override; + /// Returns true if it is stored correctly (the final shape contains this new sub-shape) + MODEL_EXPORT virtual bool generated(const GeomShapePtr& theNewShape, + const std::string& theName, const bool theCheckIsInResult = true) override; /// Records the shape newShape which was generated from the shape oldShape during a topological /// construction. As an example, consider the case of a face generated from an edge in diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index cfc9ff6e3..8b736b339 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -52,20 +52,24 @@ Model_ResultBody::~Model_ResultBody() delete myBuilder; } -void Model_ResultBody::generated(const GeomShapePtr& theNewShape, - const std::string& theName) +bool Model_ResultBody::generated(const GeomShapePtr& theNewShape, + const std::string& theName, const bool theCheckIsInResult) { + bool aResult = false; if (mySubs.size()) { // consists of subs for (std::vector::const_iterator aSubIter = mySubs.cbegin(); aSubIter != mySubs.cend(); ++aSubIter) { const ResultBodyPtr& aSub = *aSubIter; - aSub->generated(theNewShape, theName); + if (aSub->generated(theNewShape, theName, theCheckIsInResult)) + aResult = true; } } else { // do for this directly - myBuilder->generated(theNewShape, theName); + if (myBuilder->generated(theNewShape, theName, theCheckIsInResult)) + aResult = true; } + return aResult; } void Model_ResultBody::loadGeneratedShapes(const std::shared_ptr& theAlgo, diff --git a/src/Model/Model_ResultBody.h b/src/Model/Model_ResultBody.h index 62817a9bf..95cb798c8 100644 --- a/src/Model/Model_ResultBody.h +++ b/src/Model/Model_ResultBody.h @@ -51,8 +51,8 @@ public: /// Records the subshape newShape which was generated during a topological construction. /// As an example, consider the case of a face generated in construction of a box. - MODEL_EXPORT virtual void generated(const GeomShapePtr& theNewShape, - const std::string& theName) override; + MODEL_EXPORT virtual bool generated(const GeomShapePtr& theNewShape, + const std::string& theName, const bool theCheckIsInResult = true) override; /// load generated shapes MODEL_EXPORT diff --git a/src/ModelAPI/ModelAPI_BodyBuilder.h b/src/ModelAPI/ModelAPI_BodyBuilder.h index b44e0d2b9..d551a0104 100755 --- a/src/ModelAPI/ModelAPI_BodyBuilder.h +++ b/src/ModelAPI/ModelAPI_BodyBuilder.h @@ -62,8 +62,9 @@ public: /// Records the subshape newShape which was generated during a topological construction. /// As an example, consider the case of a face generated in construction of a box. - virtual void generated(const GeomShapePtr& theNewShape, - const std::string& theName) = 0; + /// Returns true if it is stored correctly (the final shape contains this new sub-shape) + virtual bool generated(const GeomShapePtr& theNewShape, + const std::string& theName, const bool theCheckIsInResult = true) = 0; /// Records the shape newShape which was generated from the shape oldShape during a topological /// construction. As an example, consider the case of a face generated from an edge in diff --git a/src/ModelAPI/ModelAPI_ResultBody.cpp b/src/ModelAPI/ModelAPI_ResultBody.cpp index 806df516e..96507db57 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.cpp +++ b/src/ModelAPI/ModelAPI_ResultBody.cpp @@ -98,10 +98,10 @@ GeomShapePtr ModelAPI_ResultBody::shape() return myBuilder->shape(); } -void ModelAPI_ResultBody::generated(const GeomShapePtr& theNewShape, - const std::string& theName) +bool ModelAPI_ResultBody::generated(const GeomShapePtr& theNewShape, + const std::string& theName, const bool theCheckIsInResult) { - myBuilder->generated(theNewShape, theName); + return myBuilder->generated(theNewShape, theName, theCheckIsInResult); } void ModelAPI_ResultBody::generated(const GeomShapePtr& theOldShape, diff --git a/src/ModelAPI/ModelAPI_ResultBody.h b/src/ModelAPI/ModelAPI_ResultBody.h index aaf1bbecc..8cb8afdf1 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.h +++ b/src/ModelAPI/ModelAPI_ResultBody.h @@ -115,8 +115,9 @@ public: /// Records the subshape newShape which was generated during a topological construction. /// As an example, consider the case of a face generated in construction of a box. - MODELAPI_EXPORT virtual void generated(const GeomShapePtr& theNewShape, - const std::string& theName); + /// Returns true if it is stored correctly (the final shape contains this new sub-shape) + MODELAPI_EXPORT virtual bool generated(const GeomShapePtr& theNewShape, + const std::string& theName, const bool theCheckIsInResult = true); /// Records the shape newShape which was generated from the shape oldShape during a topological /// construction. As an example, consider the case of a face generated from an edge in diff --git a/src/Selector/Selector_FilterByNeighbors.cpp b/src/Selector/Selector_FilterByNeighbors.cpp index 41049e877..06ae4785f 100644 --- a/src/Selector/Selector_FilterByNeighbors.cpp +++ b/src/Selector/Selector_FilterByNeighbors.cpp @@ -260,7 +260,7 @@ bool Selector_FilterByNeighbors::restore() break; // some empty label left in the end } } - return true; + return myNBLevel.size() == list().size(); } TDF_Label Selector_FilterByNeighbors::restoreByName(std::string theName, -- 2.39.2