From a4de236e09b921bc33a28b6a6e0fc3208a86355b Mon Sep 17 00:00:00 2001 From: dbv Date: Fri, 25 Dec 2015 10:17:20 +0300 Subject: [PATCH] Bug #1170: wrong object names in Main objects field Partition --- src/Model/Model_BodyBuilder.cpp | 24 +++++++++++++++++++++++- src/Model/Model_BodyBuilder.h | 3 ++- src/Model/Model_ResultCompSolid.cpp | 2 +- src/ModelAPI/ModelAPI_BodyBuilder.h | 3 ++- src/ModelAPI/ModelAPI_ResultBody.cpp | 5 +++-- src/ModelAPI/ModelAPI_ResultBody.h | 7 +++++-- 6 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/Model/Model_BodyBuilder.cpp b/src/Model/Model_BodyBuilder.cpp index e8b3479d7..476e22ace 100755 --- a/src/Model/Model_BodyBuilder.cpp +++ b/src/Model/Model_BodyBuilder.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -107,7 +108,8 @@ void Model_BodyBuilder::evolutionToSelection(const bool theFlag) evolutionToSelectionRec(aShapeLab, theFlag); } -void Model_BodyBuilder::store(const std::shared_ptr& theShape) +void Model_BodyBuilder::store(const std::shared_ptr& theShape, + const bool theIsStoreSameShapes) { std::shared_ptr aData = std::dynamic_pointer_cast(data()); if (aData) { @@ -122,6 +124,16 @@ void Model_BodyBuilder::store(const std::shared_ptr& theShape) if (aShape.IsNull()) return; // null shape inside + if(!theIsStoreSameShapes) { + Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aShape, aShapeLab); + if(!aNS.IsNull() && !aNS->IsEmpty()) { + // This shape is already in document, store reference instead of shape; + const TDF_Label aFoundLabel = aNS->Label(); + TDF_Reference::Set(aShapeLab, aFoundLabel); + return; + } + } + aBuilder.Generated(aShape); // register name if(!aBuilder.NamedShape()->IsEmpty()) { @@ -202,6 +214,12 @@ void Model_BodyBuilder::storeModified(const std::shared_ptr& theO TopoDS_Iterator aSubIter(aShapeNew); for(int aTag = theDecomposeSolidsTag; aSubIter.More(); aSubIter.Next()) { + const TopoDS_Shape& aShape = aSubIter.Value(); + Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aShape, aShapeLab); + if(!aNS.IsNull() && !aNS->IsEmpty()) { + // This shape is already in document, don't add it. + continue; + } TNaming_Builder aSubBuilder(aShapeLab.FindChild(aTag++)); aSubBuilder.Generated(aSubIter.Value()); if(!aName.IsEmpty()) { @@ -763,6 +781,10 @@ std::shared_ptr Model_BodyBuilder::shape() std::shared_ptr aData = std::dynamic_pointer_cast(data()); if (aData) { TDF_Label& aShapeLab = aData->shapeLab(); + Handle(TDF_Reference) aRef; + if (aShapeLab.FindAttribute(TDF_Reference::GetID(), aRef)) { + aShapeLab = aRef->Get(); + } Handle(TNaming_NamedShape) aName; if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) { TopoDS_Shape aShape = aName->Get(); diff --git a/src/Model/Model_BodyBuilder.h b/src/Model/Model_BodyBuilder.h index 90092e59e..0941d38b2 100755 --- a/src/Model/Model_BodyBuilder.h +++ b/src/Model/Model_BodyBuilder.h @@ -27,7 +27,8 @@ class Model_BodyBuilder : public ModelAPI_BodyBuilder std::vector myBuilders; public: /// Stores the shape (called by the execution method). - MODEL_EXPORT virtual void store(const std::shared_ptr& theShape); + MODEL_EXPORT virtual void store(const std::shared_ptr& theShape, + const bool theIsStoreSameShapes = true); /// Stores the generated shape (called by the execution method). MODEL_EXPORT virtual void storeGenerated(const std::shared_ptr& theFromShape, diff --git a/src/Model/Model_ResultCompSolid.cpp b/src/Model/Model_ResultCompSolid.cpp index e66ba2d30..8f4523c45 100755 --- a/src/Model/Model_ResultCompSolid.cpp +++ b/src/Model/Model_ResultCompSolid.cpp @@ -183,7 +183,7 @@ void Model_ResultCompSolid::updateSubs(const std::shared_ptr& the aSub = mySubs[aSubIndex]; } if (!aSolidShape->isEqual(aSub->shape())) { - aSub->store(aSolidShape); + aSub->store(aSolidShape, false); aECreator->sendUpdated(aSub, EVENT_DISP); aECreator->sendUpdated(aSub, EVENT_UPD); } diff --git a/src/ModelAPI/ModelAPI_BodyBuilder.h b/src/ModelAPI/ModelAPI_BodyBuilder.h index 424f9857b..629e1fa9a 100755 --- a/src/ModelAPI/ModelAPI_BodyBuilder.h +++ b/src/ModelAPI/ModelAPI_BodyBuilder.h @@ -28,7 +28,8 @@ public: MODELAPI_EXPORT virtual ~ModelAPI_BodyBuilder() {}; /// Stores the shape (called by the execution method). - virtual void store(const std::shared_ptr& theShape) = 0; + virtual void store(const std::shared_ptr& theShape, + const bool theIsStoreSameShapes = true) = 0; /// Stores the generated shape (called by the execution method). virtual void storeGenerated(const std::shared_ptr& theFromShape, diff --git a/src/ModelAPI/ModelAPI_ResultBody.cpp b/src/ModelAPI/ModelAPI_ResultBody.cpp index bcdc0bcb5..6792f18bc 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.cpp +++ b/src/ModelAPI/ModelAPI_ResultBody.cpp @@ -25,9 +25,10 @@ std::string ModelAPI_ResultBody::groupName() return group(); } -void ModelAPI_ResultBody::store(const std::shared_ptr& theShape) +void ModelAPI_ResultBody::store(const std::shared_ptr& theShape, + const bool theIsStoreSameShapes) { - myBuilder->store(theShape); + myBuilder->store(theShape, theIsStoreSameShapes); static Events_Loop* aLoop = Events_Loop::loop(); static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); diff --git a/src/ModelAPI/ModelAPI_ResultBody.h b/src/ModelAPI/ModelAPI_ResultBody.h index a09c80638..ad5846e0f 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.h +++ b/src/ModelAPI/ModelAPI_ResultBody.h @@ -44,8 +44,11 @@ public: return RESULT_BODY_COLOR; } - /// Stores the shape (called by the execution method). - MODELAPI_EXPORT virtual void store(const std::shared_ptr& theShape); + /// \brief Stores the shape (called by the execution method). + /// param[in] theShape shape to store. + /// param[in] theIsStoreSameShapes if false stores reference to the same shape if it is already in document. + MODELAPI_EXPORT virtual void store(const std::shared_ptr& theShape, + const bool theIsStoreSameShapes = true); /// Stores the generated shape (called by the execution method). MODELAPI_EXPORT virtual void storeGenerated(const std::shared_ptr& theFromShape, -- 2.30.2