]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/PartSet/PartSet_OverconstraintListener.cpp
Salome HOME
Issue #2071 Fatal error when Create box
[modules/shaper.git] / src / PartSet / PartSet_OverconstraintListener.cpp
index 8dd5af2eb002627505ae916c9f95725784f4390f..0e74b06001dd247194d8be3e5d85a91431aedf16 100755 (executable)
@@ -9,6 +9,7 @@
 #include "PartSet_OverconstraintListener.h"
 #include <PartSet_Module.h>
 #include <PartSet_SketcherMgr.h>
+#include <PartSet_SketcherReentrantMgr.h>
 
 #include "XGUI_ModuleConnector.h"
 #include "XGUI_Workshop.h"
@@ -29,7 +30,7 @@
 //#define DEBUG_FEATURE_OVERCONSTRAINT_LISTENER
 
 PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorkshop* theWorkshop)
-: myWorkshop(theWorkshop), myIsFullyConstrained(false), myIsNeedUpdateCustomColor(false)
+: myWorkshop(theWorkshop), myIsFullyConstrained(false)//, myIsNeedUpdateCustomColor(false)
 {
   Events_Loop* aLoop = Events_Loop::loop();
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_FAILED));
@@ -37,6 +38,8 @@ PartSet_OverconstraintListener::PartSet_OverconstraintListener(ModuleBase_IWorks
 
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_UNDER_CONSTRAINED));
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED));
+
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
 }
 
 void PartSet_OverconstraintListener::getCustomColor(const ObjectPtr& theObject,
@@ -111,24 +114,35 @@ void PartSet_OverconstraintListener::processEvent(
     myIsFullyConstrained = anEventID == Events_Loop::eventByName(EVENT_SKETCH_FULLY_CONSTRAINED);
 
     if (aPrevFullyConstrained != myIsFullyConstrained) {
-      myIsNeedUpdateCustomColor = true;
+      //myIsNeedUpdateCustomColor = true;
       std::set<ObjectPtr> aModifiedObjects;
       PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
       CompositeFeaturePtr aSketch = aModule->sketchMgr()->activeSketch();
-      for (int i = 0; i < aSketch->numberOfSubs(); i++) {
-        FeaturePtr aFeature = aSketch->subFeature(i);
-        aModifiedObjects.insert(aFeature); // is necessary to redisplay presentations
-        std::list<ResultPtr> aResults = aFeature->results();
-        for (std::list<ResultPtr>::const_iterator aIt = aResults.begin();
-             aIt != aResults.end(); ++aIt) {
-          aModifiedObjects.insert(*aIt);
+      if (aSketch.get()) {
+        for (int i = 0; i < aSketch->numberOfSubs(); i++) {
+          FeaturePtr aFeature = aSketch->subFeature(i);
+          aModifiedObjects.insert(aFeature); // is necessary to redisplay presentations
+          std::list<ResultPtr> aResults = aFeature->results();
+          for (std::list<ResultPtr>::const_iterator aIt = aResults.begin();
+               aIt != aResults.end(); ++aIt) {
+            aModifiedObjects.insert(*aIt);
+          }
         }
+        redisplayObjects(aModifiedObjects);
       }
-      redisplayObjects(aModifiedObjects);
-      myIsNeedUpdateCustomColor = false;
+      //myIsNeedUpdateCustomColor = false;
+    }
+  }
+  else if (anEventID == Events_Loop::eventByName(EVENT_OBJECT_CREATED)) {
+    PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
+    PartSet_SketcherReentrantMgr* aReentrantMgr = aModule->sketchReentranceMgr();
+    if (aReentrantMgr->isInternalEditActive()) {
+      std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
+            std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+      std::set<ObjectPtr> anObjects = aUpdMsg->objects();
+      aReentrantMgr->appendCreatedObjects(anObjects);
     }
   }
-
 #ifdef DEBUG_FEATURE_OVERCONSTRAINT_LISTENER
   aCurrentInfoStr = getObjectsInfo(myConflictingObjects);
   qDebug(QString("RESULT: current objects count = %1:%2\n")