From b03c3ccab7c9e38c5547f3b2b67ebf15f77f6a40 Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 23 Aug 2017 14:08:31 +0300 Subject: [PATCH] Issue 2229: error when I load a dump python. --- src/SketchPlugin/CMakeLists.txt | 1 + src/SketchPlugin/Test/Test2229.py | 43 +++++++++++++++++++++++ src/SketchSolver/SketchSolver_Manager.cpp | 37 +++++++++++++------ 3 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 src/SketchPlugin/Test/Test2229.py diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 73670e3b3..ba06dbe55 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -199,5 +199,6 @@ ADD_UNIT_TESTS(TestSketchPointLine.py TestTrimCircleAndArc01.py TestTrimLine01.py TestTrimLine02.py + Test2229.py Test2239.py ) diff --git a/src/SketchPlugin/Test/Test2229.py b/src/SketchPlugin/Test/Test2229.py new file mode 100644 index 000000000..da8f65af2 --- /dev/null +++ b/src/SketchPlugin/Test/Test2229.py @@ -0,0 +1,43 @@ +## Copyright (C) 2014-2017 CEA/DEN, EDF R&D +## +## This library is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## This library is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with this library; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +## +## See http:##www.salome-platform.org/ or +## email : webmaster.salome@opencascade.com +## + +from ModelAPI import * +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +model.addParameter(Part_1_doc, "Wall_R", "6.188") +model.addParameter(Part_1_doc, "Wall_T1", "0.089") +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchPoint_1 = Sketch_1.addPoint(0, 2.424999999999997) +SketchLine_1 = Sketch_1.addLine(model.selection("EDGE", "PartSet/OY")) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchLine_1.result()) +SketchConstraintRigid_1 = Sketch_1.setFixed(SketchPoint_1.coordinates()) +SketchLine_2 = Sketch_1.addLine(6.277, 3.700188311077954, 6.277, -1.894463229482514) +SketchLine_2.setAuxiliary(True) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result()) +SketchConstraintDistance_1 = Sketch_1.setDistance(SketchPoint_1.coordinates(), SketchLine_2.result(), "Wall_R+Wall_T1") +model.end() + +# check that resulting sketch is valid +aFactory = ModelAPI_Session.get().validators() +assert(aFactory.validate(Sketch_1.feature())) diff --git a/src/SketchSolver/SketchSolver_Manager.cpp b/src/SketchSolver/SketchSolver_Manager.cpp index e20ef48c1..b2a3d49d9 100644 --- a/src/SketchSolver/SketchSolver_Manager.cpp +++ b/src/SketchSolver/SketchSolver_Manager.cpp @@ -92,6 +92,7 @@ void SketchSolver_Manager::processEvent( bool isUpdateFlushed = false; bool isMovedEvt = false; + static const Events_ID aCreatedEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED); static const Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); static const Events_ID aSketchPreparedEvent = Events_Loop::eventByName(EVENT_SKETCH_PREPARED); // sketch is prepared for resolve: all the needed events @@ -105,12 +106,11 @@ void SketchSolver_Manager::processEvent( return; myIsComputed = true; - if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED) + if (theMessage->eventID() == aCreatedEvent || theMessage->eventID() == anUpdateEvent || theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_MOVED)) { std::shared_ptr anUpdateMsg = std::dynamic_pointer_cast(theMessage); - std::set aFeatures = anUpdateMsg->objects(); isUpdateFlushed = stopSendUpdate(); @@ -121,14 +121,31 @@ void SketchSolver_Manager::processEvent( bool hasProperFeature = false; // update sketch features only - std::set::iterator aFeatIter; - for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { - std::shared_ptr aFeature = - std::dynamic_pointer_cast(*aFeatIter); - if (!aFeature || aFeature->isMacro()) - continue; - - hasProperFeature = updateFeature(aFeature, isMovedEvt) || hasProperFeature; + const std::set& aFeatures = anUpdateMsg->objects(); + // try to keep order as features were created if there are several created features: #2229 + if (theMessage->eventID() == aCreatedEvent && aFeatures.size() > 1) { + std::map> anOrderedFeatures; + std::set::iterator aFeatIter; + for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { + std::shared_ptr aFeature = + std::dynamic_pointer_cast(*aFeatIter); + if (aFeature && !aFeature->isMacro() && aFeature->data()) { + anOrderedFeatures[aFeature->data()->featureId()] = aFeature; + } + } + std::map>::iterator aFeat; + for(aFeat = anOrderedFeatures.begin(); aFeat != anOrderedFeatures.end(); aFeat++) { + hasProperFeature = updateFeature(aFeat->second, isMovedEvt) || hasProperFeature; + } + } else { // order is not important + std::set::iterator aFeatIter; + for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) { + std::shared_ptr aFeature = + std::dynamic_pointer_cast(*aFeatIter); + if (!aFeature || aFeature->isMacro()) + continue; + hasProperFeature = updateFeature(aFeature, isMovedEvt) || hasProperFeature; + } } if (isMovedEvt && hasProperFeature) -- 2.30.2