From 42dc23ef58cbd0822a88209180f1ad98ac64a676 Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 11 Sep 2017 11:34:55 +0300 Subject: [PATCH] Fast try to fix 2241 due to customized movement of Group to the end, not standard Naming mechanism. Requires additional investigation of stability of this approach (OCCT naming may produce an error when object is modified from several arguments) on recomputation of selection. --- .../FeaturesPlugin_Partition.cpp | 18 ++++++++++++++++- src/FeaturesPlugin/Test/Test2240.py | 2 +- src/Model/Model_BodyBuilder.cpp | 20 ++++++++++--------- src/Model/Model_BodyBuilder.h | 3 ++- src/Model/Model_ResultCompSolid.cpp | 6 ++++-- src/Model/Model_ResultCompSolid.h | 3 ++- src/ModelAPI/ModelAPI_BodyBuilder.h | 3 ++- src/ModelAPI/ModelAPI_ResultBody.cpp | 4 ++-- src/ModelAPI/ModelAPI_ResultBody.h | 3 ++- 9 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp b/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp index afb763fc6..f557e6bc3 100755 --- a/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Partition.cpp @@ -181,7 +181,23 @@ void FeaturesPlugin_Partition::storeResult( int aModTag = aSubTag + 10000; const std::string aModName = "Modified"; - aResultBody->storeModified(aBaseShape, theResultShape, aSubTag); + // issue #2241 : make result of partition modified from all input objects (except planes) + bool aIsModifierStored = false; + for(ListOfShape::const_iterator anIt = theObjects.cbegin(); anIt != theObjects.cend(); ++anIt) { + GeomShapePtr anObjectShape = *anIt; + GeomShapePtr aCandidate = + findBase(anObjectShape, theResultShape, GeomAPI_Shape::VERTEX, theMakeShape); + if(!aCandidate.get()) { + aCandidate = findBase(anObjectShape, theResultShape, GeomAPI_Shape::EDGE, theMakeShape); + } + if (!aCandidate.get()) + aCandidate = findBase(anObjectShape, theResultShape, GeomAPI_Shape::FACE, theMakeShape); + + if(aCandidate.get()) { + aResultBody->storeModified(aCandidate, theResultShape, aSubTag, !aIsModifierStored); + aIsModifierStored = true; + } + } std::shared_ptr aMapOfSubShapes = theMakeShape->mapOfSubShapes(); theObjects.insert(theObjects.end(), thePlanes.begin(), thePlanes.end()); diff --git a/src/FeaturesPlugin/Test/Test2240.py b/src/FeaturesPlugin/Test/Test2240.py index 5317ea29b..2277cebea 100644 --- a/src/FeaturesPlugin/Test/Test2240.py +++ b/src/FeaturesPlugin/Test/Test2240.py @@ -97,13 +97,13 @@ Face_1 = model.addFace(Part_1_doc, [model.selection("WIRE", "Sketch_1/Wire-Sketc Face_2 = model.addFace(Part_1_doc, [model.selection("WIRE", "Sketch_1/Wire-SketchLine_9f-SketchLine_10r-SketchArc_1_2f-SketchArc_2_2r")]) Face_3 = model.addFace(Part_1_doc, [model.selection("EDGE", "Sketch_2/Edge-SketchCircle_1_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_2_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_3_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_4_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_5_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_6_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_7_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_9_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_8_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_10_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_12_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_11_2")]) Face_4 = model.addFace(Part_1_doc, [model.selection("EDGE", "Sketch_2/Edge-SketchCircle_1_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_2_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_3_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_4_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_5_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_7_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_6_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_9_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_8_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_10_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_12_2"), model.selection("EDGE", "Sketch_2/Edge-SketchCircle_11_2"), model.selection("WIRE", "Sketch_1/Wire-SketchLine_1f-SketchLine_3f-SketchLine_4f-SketchLine_5f-SketchLine_6f-SketchLine_7f-SketchLine_9f-SketchLine_10r-SketchArc_2_2f")]) -Partition_1 = model.addPartition(Part_1_doc, [model.selection("FACE", "Face_1_1"), model.selection("FACE", "Face_2_1"), model.selection("FACE", "Face_3_1"), model.selection("FACE", "Face_3_2"), model.selection("FACE", "Face_3_3"), model.selection("FACE", "Face_3_4"), model.selection("FACE", "Face_3_5"), model.selection("FACE", "Face_3_6"), model.selection("FACE", "Face_3_7"), model.selection("FACE", "Face_3_8"), model.selection("FACE", "Face_3_9"), model.selection("FACE", "Face_3_10"), model.selection("FACE", "Face_3_11"), model.selection("FACE", "Face_3_12"), model.selection("FACE", "Face_4_1")]) Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Face_2_1"), model.selection("FACE", "Face_3_7"), model.selection("FACE", "Face_3_5"), model.selection("FACE", "Face_3_3"), model.selection("FACE", "Face_3_4"), model.selection("FACE", "Face_3_1"), model.selection("FACE", "Face_3_2"), model.selection("FACE", "Face_3_6"), model.selection("FACE", "Face_3_11"), model.selection("FACE", "Face_3_10"), model.selection("FACE", "Face_3_8"), model.selection("FACE", "Face_3_9"), model.selection("FACE", "Face_3_12")]) Group_1.result().setName("eau") Group_1.result().setColor(0, 170, 255) Group_2 = model.addGroup(Part_1_doc, [model.selection("FACE", "Face_4_1")]) Group_2.result().setName("acier") Group_2.result().setColor(170, 85, 0) +Partition_1 = model.addPartition(Part_1_doc, [model.selection("FACE", "Face_1_1"), model.selection("FACE", "Face_2_1"), model.selection("FACE", "Face_3_1"), model.selection("FACE", "Face_3_2"), model.selection("FACE", "Face_3_3"), model.selection("FACE", "Face_3_4"), model.selection("FACE", "Face_3_5"), model.selection("FACE", "Face_3_6"), model.selection("FACE", "Face_3_7"), model.selection("FACE", "Face_3_8"), model.selection("FACE", "Face_3_9"), model.selection("FACE", "Face_3_10"), model.selection("FACE", "Face_3_11"), model.selection("FACE", "Face_3_12"), model.selection("FACE", "Face_4_1")]) Sketch_3 = model.addSketch(Part_1_doc, model.selection("FACE", "PartSet/XOY")) SketchLine_11 = Sketch_3.addLine(40, 0, 30, 0) SketchPoint_1 = Sketch_3.addPoint(model.selection("VERTEX", "Partition_1_1_1/Modified_Edge_15_6&Partition_1_1_1/Modified_Edge_15_5")) diff --git a/src/Model/Model_BodyBuilder.cpp b/src/Model/Model_BodyBuilder.cpp index ad63bee3e..3a8ddb11f 100755 --- a/src/Model/Model_BodyBuilder.cpp +++ b/src/Model/Model_BodyBuilder.cpp @@ -203,15 +203,16 @@ void Model_BodyBuilder::storeGenerated(const std::shared_ptr& the } void Model_BodyBuilder::storeModified(const std::shared_ptr& theOldShape, - const std::shared_ptr& theNewShape, const int theDecomposeSolidsTag) + const std::shared_ptr& theNewShape, const int theDecomposeSolidsTag, + const bool theClean) { std::shared_ptr aData = std::dynamic_pointer_cast(data()); if (aData) { - TDF_Label& aShapeLab = aData->shapeLab(); // clean builders - clean(); + if (theClean) + clean(); // store the new shape as primitive - TNaming_Builder aBuilder(aShapeLab); + TNaming_Builder* aBuilder = builder(0); if (!theOldShape || !theNewShape) return; // bad shape TopoDS_Shape aShapeOld = theOldShape->impl(); @@ -220,15 +221,15 @@ void Model_BodyBuilder::storeModified(const std::shared_ptr& theO TopoDS_Shape aShapeNew = theNewShape->impl(); if (aShapeNew.IsNull()) return; // null shape inside - aBuilder.Modify(aShapeOld, aShapeNew); - if(!aBuilder.NamedShape()->IsEmpty()) { + aBuilder->Modify(aShapeOld, aShapeNew); + if(!aBuilder->NamedShape()->IsEmpty()) { Handle(TDataStd_Name) anAttr; - if(aBuilder.NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) { + if(aBuilder->NamedShape()->Label().FindAttribute(TDataStd_Name::GetID(),anAttr)) { std::string aName (TCollection_AsciiString(anAttr->Get()).ToCString()); if(!aName.empty()) { std::shared_ptr aDoc = std::dynamic_pointer_cast(document()); - aDoc->addNamingName(aBuilder.NamedShape()->Label(), aName); + aDoc->addNamingName(aBuilder->NamedShape()->Label(), aName); } } } @@ -275,7 +276,8 @@ TNaming_Builder* Model_BodyBuilder::builder(const int theTag) std::map::iterator aFind = myBuilders.find(theTag); if (aFind == myBuilders.end()) { std::shared_ptr aData = std::dynamic_pointer_cast(data()); - myBuilders[theTag] = new TNaming_Builder(aData->shapeLab().FindChild(theTag)); + TDF_Label aLab = theTag == 0 ? aData->shapeLab() : aData->shapeLab().FindChild(theTag); + myBuilders[theTag] = new TNaming_Builder(aLab); aFind = myBuilders.find(theTag); } return aFind->second; diff --git a/src/Model/Model_BodyBuilder.h b/src/Model/Model_BodyBuilder.h index 983c03a75..b94dc483d 100755 --- a/src/Model/Model_BodyBuilder.h +++ b/src/Model/Model_BodyBuilder.h @@ -55,7 +55,8 @@ public: /// theNewShape is compound of solids, if zero it is not used MODEL_EXPORT virtual void storeModified(const std::shared_ptr& theOldShape, const std::shared_ptr& theNewShape, - const int theDecomposeSolidsTag = 0); + const int theDecomposeSolidsTag = 0, + const bool theClean = true); /// Stores the shape without naming support /// \param theShape shape to store diff --git a/src/Model/Model_ResultCompSolid.cpp b/src/Model/Model_ResultCompSolid.cpp index 0fa8b4fd1..dcda320fc 100755 --- a/src/Model/Model_ResultCompSolid.cpp +++ b/src/Model/Model_ResultCompSolid.cpp @@ -59,9 +59,11 @@ void Model_ResultCompSolid::storeGenerated(const std::shared_ptr& } void Model_ResultCompSolid::storeModified(const std::shared_ptr& theOldShape, - const std::shared_ptr& theNewShape, const int theDecomposeSolidsTag) + const std::shared_ptr& theNewShape, const int theDecomposeSolidsTag, + const bool theClean) { - ModelAPI_ResultCompSolid::storeModified(theOldShape, theNewShape, theDecomposeSolidsTag); + ModelAPI_ResultCompSolid::storeModified(theOldShape, theNewShape, theDecomposeSolidsTag, + theClean); updateSubs(theNewShape); } diff --git a/src/Model/Model_ResultCompSolid.h b/src/Model/Model_ResultCompSolid.h index 7fcf5cc59..0e0f0d020 100755 --- a/src/Model/Model_ResultCompSolid.h +++ b/src/Model/Model_ResultCompSolid.h @@ -55,7 +55,8 @@ public: /// Stores the modified shape. Creates sub-results for compsolid. MODEL_EXPORT virtual void storeModified(const std::shared_ptr& theOldShape, - const std::shared_ptr& theNewShape, const int theDecomposeSolidsTag = 0); + const std::shared_ptr& theNewShape, const int theDecomposeSolidsTag = 0, + const bool theClean = true); /// load and orient modified shapes for sub-objects MODEL_EXPORT virtual void loadAndOrientModifiedShapes (GeomAlgoAPI_MakeShape* theMS, diff --git a/src/ModelAPI/ModelAPI_BodyBuilder.h b/src/ModelAPI/ModelAPI_BodyBuilder.h index 8524cc31d..a2dd16513 100755 --- a/src/ModelAPI/ModelAPI_BodyBuilder.h +++ b/src/ModelAPI/ModelAPI_BodyBuilder.h @@ -52,7 +52,8 @@ public: /// Stores the modified shape (called by the execution method). virtual void storeModified(const std::shared_ptr& theOldShape, const std::shared_ptr& theNewShape, - const int theDecomposeSolidsTag = 0) = 0; + const int theDecomposeSolidsTag = 0, + const bool theClean = true) = 0; /// Stores the shape without naming support virtual void storeWithoutNaming(const std::shared_ptr& theShape) = 0; diff --git a/src/ModelAPI/ModelAPI_ResultBody.cpp b/src/ModelAPI/ModelAPI_ResultBody.cpp index 4025d17b7..11dc5f3ce 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.cpp +++ b/src/ModelAPI/ModelAPI_ResultBody.cpp @@ -66,9 +66,9 @@ void ModelAPI_ResultBody::storeGenerated(const std::shared_ptr& t void ModelAPI_ResultBody::storeModified(const std::shared_ptr& theOldShape, const std::shared_ptr& theNewShape, - const int theDecomposeSolidsTag) + const int theDecomposeSolidsTag, const bool theClean) { - myBuilder->storeModified(theOldShape, theNewShape, theDecomposeSolidsTag); + myBuilder->storeModified(theOldShape, theNewShape, theDecomposeSolidsTag, theClean); myConnect = ConnectionNotComputed; static Events_Loop* aLoop = Events_Loop::loop(); diff --git a/src/ModelAPI/ModelAPI_ResultBody.h b/src/ModelAPI/ModelAPI_ResultBody.h index 98a4b6a29..35b66104f 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.h +++ b/src/ModelAPI/ModelAPI_ResultBody.h @@ -86,7 +86,8 @@ public: /// Stores the modified shape (called by the execution method). MODELAPI_EXPORT virtual void storeModified(const std::shared_ptr& theOldShape, - const std::shared_ptr& theNewShape, const int theDecomposeSolidsTag = 0); + const std::shared_ptr& theNewShape, const int theDecomposeSolidsTag = 0, + const bool theClean = true); /// Stores the shape without naming support MODELAPI_EXPORT virtual void storeWithoutNaming( -- 2.39.2