]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue 2229: error when I load a dump python.
authormpv <mpv@opencascade.com>
Wed, 23 Aug 2017 11:08:31 +0000 (14:08 +0300)
committermpv <mpv@opencascade.com>
Wed, 23 Aug 2017 11:08:31 +0000 (14:08 +0300)
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/Test/Test2229.py [new file with mode: 0644]
src/SketchSolver/SketchSolver_Manager.cpp

index 73670e3b34afbf8ba473aaffb5c6636b904bab31..ba06dbe55faa650a1fec3ded65150e0f93f9d63d 100644 (file)
@@ -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 (file)
index 0000000..da8f65a
--- /dev/null
@@ -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<mailto: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()))
index e20ef48c1c23dfda07ff25011b5a695c742cc457..b2a3d49d93341a4415a4242159936af7824e8ff5 100644 (file)
@@ -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<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
-    std::set<ObjectPtr> aFeatures = anUpdateMsg->objects();
 
     isUpdateFlushed = stopSendUpdate();
 
@@ -121,14 +121,31 @@ void SketchSolver_Manager::processEvent(
     bool hasProperFeature = false;
 
     // update sketch features only
-    std::set<ObjectPtr>::iterator aFeatIter;
-    for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) {
-      std::shared_ptr<SketchPlugin_Feature> aFeature =
-          std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
-      if (!aFeature || aFeature->isMacro())
-        continue;
-
-      hasProperFeature = updateFeature(aFeature, isMovedEvt) || hasProperFeature;
+    const std::set<ObjectPtr>& 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<int, std::shared_ptr<SketchPlugin_Feature>> anOrderedFeatures;
+      std::set<ObjectPtr>::iterator aFeatIter;
+      for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) {
+        std::shared_ptr<SketchPlugin_Feature> aFeature =
+            std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
+        if (aFeature && !aFeature->isMacro() && aFeature->data()) {
+          anOrderedFeatures[aFeature->data()->featureId()] = aFeature;
+        }
+      }
+      std::map<int, std::shared_ptr<SketchPlugin_Feature>>::iterator aFeat;
+      for(aFeat = anOrderedFeatures.begin(); aFeat != anOrderedFeatures.end(); aFeat++) {
+        hasProperFeature = updateFeature(aFeat->second, isMovedEvt) || hasProperFeature;
+      }
+    } else { // order is not important
+      std::set<ObjectPtr>::iterator aFeatIter;
+      for (aFeatIter = aFeatures.begin(); aFeatIter != aFeatures.end(); aFeatIter++) {
+        std::shared_ptr<SketchPlugin_Feature> aFeature =
+            std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
+        if (!aFeature || aFeature->isMacro())
+          continue;
+        hasProperFeature = updateFeature(aFeature, isMovedEvt) || hasProperFeature;
+      }
     }
 
     if (isMovedEvt && hasProperFeature)