From 0ddb9fb989b2ae36d0ef4652a0b68d049e0be01d Mon Sep 17 00:00:00 2001 From: dbv Date: Fri, 26 Oct 2018 16:47:54 +0300 Subject: [PATCH] Fixed storing names (generated and primitives) for sub-results. --- src/Model/Model_BodyBuilder.cpp | 29 ++++++++++++++++++++-- src/Model/Model_ResultBody.cpp | 43 +++++++++++++++++++++++++++++---- src/Model/Model_ResultBody.h | 16 ++++++++++-- 3 files changed, 79 insertions(+), 9 deletions(-) diff --git a/src/Model/Model_BodyBuilder.cpp b/src/Model/Model_BodyBuilder.cpp index fbfd692a8..30fb12584 100755 --- a/src/Model/Model_BodyBuilder.cpp +++ b/src/Model/Model_BodyBuilder.cpp @@ -311,6 +311,13 @@ void Model_BodyBuilder::buildName(const int theTag, const std::string& theName) void Model_BodyBuilder::generated(const GeomShapePtr& theNewShape, const std::string& theName) { + GeomShapePtr aResultShape = shape(); + + bool aNewShapeIsNotInResultShape = !aResultShape->isSubShape(theNewShape, false); + if (aNewShapeIsNotInResultShape) { + return; + } + TopoDS_Shape aShape = theNewShape->impl(); builder(myFreePrimitiveTag)->Generated(aShape); if (!theName.empty()) { @@ -565,7 +572,9 @@ void Model_BodyBuilder::loadGeneratedShapes(const GeomMakeShapePtr& theAlgo, const GeomAPI_Shape::ShapeType theShapeTypeToExplore, const std::string& theName) { + GeomShapePtr aResultShape = shape(); TopTools_MapOfShape anAlreadyProcessedShapes; + std::shared_ptr aData = std::dynamic_pointer_cast(data()); for (GeomAPI_ShapeExplorer anOldShapeExp(theOldShape, theShapeTypeToExplore); anOldShapeExp.more(); anOldShapeExp.next()) @@ -573,8 +582,16 @@ void Model_BodyBuilder::loadGeneratedShapes(const GeomMakeShapePtr& theAlgo, GeomShapePtr anOldSubShape = anOldShapeExp.current(); const TopoDS_Shape& anOldSubShape_ = anOldSubShape->impl(); - // There is no sense to write history if shape already processed. - if (!anAlreadyProcessedShapes.Add(anOldSubShape_)) continue; + // There is no sense to write history if shape already processed + // or old shape does not exist in the document. + bool anOldSubShapeAlreadyProcessed = !anAlreadyProcessedShapes.Add(anOldSubShape_); + bool anOldSubShapeNotInTree = TNaming_Tool::NamedShape(anOldSubShape_, aData->shapeLab()) + .IsNull(); + if (anOldSubShapeAlreadyProcessed + || anOldSubShapeNotInTree) + { + continue; + } // Get new shapes. ListOfShape aNewShapes; @@ -589,6 +606,14 @@ void Model_BodyBuilder::loadGeneratedShapes(const GeomMakeShapePtr& theAlgo, GeomShapePtr aNewShape = *aNewShapesIt; const TopoDS_Shape& aNewShape_ = aNewShape->impl(); + bool aNewShapeIsSameAsOldShape = anOldSubShape->isSame(aNewShape); + bool aNewShapeIsNotInResultShape = !aResultShape->isSubShape(aNewShape, false); + if (aNewShapeIsSameAsOldShape + || aNewShapeIsNotInResultShape) + { + continue; + } + TopAbs_ShapeEnum aNewShapeType = aNewShape_.ShapeType(); if (aNewShapeType == TopAbs_WIRE || aNewShapeType == TopAbs_SHELL) { // TODO: This is a workaround. New shape should be only edge or face. diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index 384bbd61a..cfc9ff6e3 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -52,11 +52,44 @@ Model_ResultBody::~Model_ResultBody() delete myBuilder; } -void Model_ResultBody::loadModifiedShapes( - const std::shared_ptr& theAlgo, - const GeomShapePtr& theOldShape, - const GeomAPI_Shape::ShapeType theShapeTypeToExplore, - const std::string& theName) +void Model_ResultBody::generated(const GeomShapePtr& theNewShape, + const std::string& theName) +{ + 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); + } + } else { // do for this directly + myBuilder->generated(theNewShape, theName); + } +} + +void Model_ResultBody::loadGeneratedShapes(const std::shared_ptr& theAlgo, + const GeomShapePtr& theOldShape, + const GeomAPI_Shape::ShapeType theShapeTypeToExplore, + const std::string& theName) +{ + if (mySubs.size()) { // consists of subs + for (std::vector::const_iterator aSubIter = mySubs.cbegin(); + aSubIter != mySubs.cend(); + ++aSubIter) + { + const ResultBodyPtr& aSub = *aSubIter; + aSub->loadGeneratedShapes(theAlgo, theOldShape, theShapeTypeToExplore, theName); + } + } else { // do for this directly + myBuilder->loadGeneratedShapes(theAlgo, theOldShape, theShapeTypeToExplore, theName); + } +} + +void Model_ResultBody::loadModifiedShapes(const std::shared_ptr& theAlgo, + const GeomShapePtr& theOldShape, + const GeomAPI_Shape::ShapeType theShapeTypeToExplore, + const std::string& theName) { if (/*theSplitInSubs &&*/ mySubs.size()) { // consists of subs // optimization of getting of new shapes for specific sub-result diff --git a/src/Model/Model_ResultBody.h b/src/Model/Model_ResultBody.h index eda74f541..bca729d8f 100644 --- a/src/Model/Model_ResultBody.h +++ b/src/Model/Model_ResultBody.h @@ -49,12 +49,24 @@ public: /// Removes the stored builders MODEL_EXPORT virtual ~Model_ResultBody(); - /// load and orient modified shapes for sub-objects + /// 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); + + /// load generated shapes + MODELAPI_EXPORT + virtual void loadGeneratedShapes(const std::shared_ptr& theAlgo, + const GeomShapePtr& theOldShape, + const GeomAPI_Shape::ShapeType theShapeTypeToExplore, + const std::string& theName = "") override; + + /// load modified shapes for sub-objects MODEL_EXPORT virtual void loadModifiedShapes(const std::shared_ptr& theAlgo, const GeomShapePtr& theOldShape, const GeomAPI_Shape::ShapeType theShapeTypeToExplore, - const std::string& theName) override; + const std::string& theName = "") override; /// Returns the number of sub-elements -- 2.39.2