Salome HOME
Issue #1854 Recover feature control update
[modules/shaper.git] / src / ModuleBase / ModuleBase_IModule.cpp
index 942d9ec6584ef3a288b08f1746d3ee1238a7cd8f..a96d676e5fb28ea55f560b954a9d06ecaaedf8d1 100644 (file)
@@ -32,7 +32,7 @@
 #include <QPushButton>
 
 ModuleBase_IModule::ModuleBase_IModule(ModuleBase_IWorkshop* theParent)
-  : QObject(theParent), myWorkshop(theParent) 
+  : QObject(theParent), myWorkshop(theParent)
 {
   connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
 
@@ -71,27 +71,24 @@ void ModuleBase_IModule::launchModal(const QString& theCmdId)
 
 void ModuleBase_IModule::launchOperation(const QString& theCmdId)
 {
+  /// selection should be obtained from workshop before ask if the operation can be started as
+  /// the canStartOperation method performs commit/abort of previous operation.
+  /// Sometimes commit/abort may cause selection clear(Sketch operation) as a result
+  /// it will be lost and is not used for preselection.
+  ModuleBase_ISelection* aSelection = myWorkshop->selection();
+  QList<ModuleBase_ViewerPrsPtr> aPreSelected =
+    aSelection->getSelected(ModuleBase_ISelection::AllControls);
+
   if (!myWorkshop->canStartOperation(theCmdId))
     return;
 
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                              (createOperation(theCmdId.toStdString()));
   if (aFOperation) {
-    ModuleBase_ISelection* aSelection = myWorkshop->selection();
-    // Initialise operation with preliminary selection
-    aFOperation->initSelection(aSelection, myWorkshop->viewer());
-    sendOperation(aFOperation);
-  }
-}
+    aFOperation->initSelection(aPreSelected);
 
-
-void ModuleBase_IModule::sendOperation(ModuleBase_Operation* theOperation)
-{
-  static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
-  std::shared_ptr<Config_PointerMessage> aMessage =
-      std::shared_ptr<Config_PointerMessage>(new Config_PointerMessage(aModuleEvent, this));
-  aMessage->setPointer(theOperation);
-  Events_Loop::loop()->send(aMessage);
+    workshop()->processLaunchOperation(aFOperation);
+  }
 }
 
 Handle(AIS_InteractiveObject) ModuleBase_IModule::createPresentation(const ResultPtr& theResult)
@@ -123,8 +120,8 @@ ModuleBase_Operation* ModuleBase_IModule::getNewOperation(const std::string& the
 }
 
 bool ModuleBase_IModule::customizeObject(ObjectPtr theObject,
-                                         const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
-                                         const bool theUpdateViewer)
+                              const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
+                              const bool theUpdateViewer)
 {
   return false;
 }
@@ -168,7 +165,6 @@ void ModuleBase_IModule::createFeatures()
 
 void ModuleBase_IModule::actionCreated(QAction* theFeature)
 {
-  theFeature->setStatusTip(theFeature->text());
   connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
 }
 
@@ -228,7 +224,7 @@ void ModuleBase_IModule::editFeature(FeaturePtr theFeature)
                                                          (createOperation(aFeatureId));
   if (aFOperation) {
     aFOperation->setFeature(theFeature);
-    sendOperation(aFOperation);
+    workshop()->processLaunchOperation(aFOperation);
   }
 }
 
@@ -239,7 +235,7 @@ bool ModuleBase_IModule::canActivateSelection(const ObjectPtr& theObject) const
   return !aFOperation || !aFOperation->hasObject(theObject);
 }
 
-void ModuleBase_IModule::operationResumed(ModuleBase_Operation* theOperation) 
+void ModuleBase_IModule::operationResumed(ModuleBase_Operation* theOperation)
 {
   emit resumed(theOperation);
 }