Salome HOME
Issue #632: Activate/Deactivate zoom tracking on activation/deactivation of module
[modules/shaper.git] / src / InitializationPlugin / InitializationPlugin_Plugin.cpp
index 8270656852020ed435d8f0856abc319edddf92f2..654b9c446e02cd44506916a8b6e5ac16241166f0 100644 (file)
@@ -32,6 +32,12 @@ void InitializationPlugin_Plugin::processEvent(const std::shared_ptr<Events_Mess
     std::shared_ptr<ModelAPI_DocumentCreatedMessage> aMessage = std::dynamic_pointer_cast<
         ModelAPI_DocumentCreatedMessage>(theMessage);
     DocumentPtr aDoc = aMessage->document();
+
+    /// Issue 431: for the current moment create planes only in the module document,
+    /// Later if it is needed we may create special initial planes in Parts (may be different)
+    if (aDoc != ModelAPI_Session::get()->moduleDocument())
+      return;
+
     std::list<FeaturePtr> aFeatures;
 
     // the viewer update should be blocked in order to avoid the features blinking before they are
@@ -49,17 +55,16 @@ void InitializationPlugin_Plugin::processEvent(const std::shared_ptr<Events_Mess
 
     // hides the created features, the precondition is that the feature's results have been
     // already built, so the createPlane/Points method calls the execute function for the planes
-    static Events_ID HIDE_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE);
     std::list<FeaturePtr >::const_iterator aFIter = aFeatures.begin();
     for (; aFIter != aFeatures.cend(); aFIter++) {
       FeaturePtr aPlane = *aFIter;
       const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aPlane->results();
       std::list<ResultPtr >::const_iterator aRIter = aResults.begin();
       for (; aRIter != aResults.cend(); aRIter++) {
-        ModelAPI_EventCreator::get()->sendUpdated(*aRIter, HIDE_DISP);
+        (*aRIter)->setDisplayed(false);
       }
     }
-    Events_Loop::loop()->flush(HIDE_DISP);
+    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
 
     // the viewer update should be unblocked in order to avoid the features blinking before they are
     // hidden
@@ -97,6 +102,10 @@ FeaturePtr InitializationPlugin_Plugin::createPlane(DocumentPtr theDoc, double t
   // the plane should be executed in order to build the feature result immediatelly
   // the results are to be hidden in the plugin
   aPlane->execute();
+  // this flag is needed here to avoid setting it inside of the next transaction
+  // (may cause crash on redo of the first transaction in OCAF)
+  aPlane->data()->execState(ModelAPI_StateDone);
+  aPlane->firstResult()->data()->execState(ModelAPI_StateDone);
 
   return aPlane;
 }
@@ -113,6 +122,8 @@ FeaturePtr InitializationPlugin_Plugin::createPoint(DocumentPtr theDoc)
   // the point should be executed in order to build the feature result immediatelly
   // the results are to be hidden in the plugin
   aPoint->execute();
+  aPoint->data()->execState(ModelAPI_StateDone);
+  aPoint->firstResult()->data()->execState(ModelAPI_StateDone);
 
   return aPoint;
 }