Salome HOME
Refactoring: static constants are replaced by inline functions in:
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
index 7be906691ae361f33510a648ed18b9c56a9d6a45..1044a403aba85a059ed1f3e5c5a9a13a9d38c333 100644 (file)
@@ -10,6 +10,7 @@
 #include "XGUI_Viewer.h"
 #include "ModuleBase_WidgetFactory.h"
 #include "XGUI_SelectionMgr.h"
+#include "XGUI_Selection.h"
 #include "XGUI_ObjectsBrowser.h"
 #include "XGUI_Displayer.h"
 #include "XGUI_OperationMgr.h"
 #include <ModelAPI_Data.h>
 #include <ModelAPI_AttributeDocRef.h>
 #include <ModelAPI_Object.h>
+#include <ModelAPI_Validator.h>
 
 #include <PartSetPlugin_Part.h>
 
 #include <Events_Loop.h>
 #include <Events_Error.h>
+
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_OperationDescription.h>
+#include <ModuleBase_SelectionValidator.h>
+
 #include <Config_Common.h>
 #include <Config_FeatureMessage.h>
 #include <Config_PointerMessage.h>
@@ -85,7 +90,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   myDisplayer = new XGUI_Displayer(this);
 
   mySelector = new XGUI_SelectionMgr(this);
-  connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands()));
+  //connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands()));
 
   myOperationMgr = new XGUI_OperationMgr(this);
   myActionsMgr = new XGUI_ActionsMgr(this);
@@ -95,6 +100,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
           this, SLOT(onContextMenuCommand(const QString&, bool)));
 
   myViewerProxy = new XGUI_ViewerProxy(this);
+  connect(myViewerProxy, SIGNAL(selectionChanged()), this, SLOT(updateCommandsOnViewSelection()));
   
   myModuleConnector = new XGUI_ModuleConnector(this);
 
@@ -290,7 +296,7 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const Model_FeatureUpdatedMessage* the
   bool isDisplayed = false;
   for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
     FeaturePtr aFeature = (*aIt);
-    if (aFeature->getKind() != PARTSET_PART_KIND) {
+    if (aFeature->getKind() != PartSetPlugin_Part::ID()) {
       isDisplayed = myDisplayer->redisplay(aFeature, false);
     }
   }
@@ -308,7 +314,7 @@ void XGUI_Workshop::onFeatureCreatedMsg(const Model_FeatureUpdatedMessage* theMs
   bool isDisplayed = false;
   for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
     FeaturePtr aFeature = (*aIt);
-    if (aFeature->getKind() == PARTSET_PART_KIND) {
+    if (aFeature->getKind() == PartSetPlugin_Part::ID()) {
       aHasPart = true;
       //break;
     } else {
@@ -712,7 +718,7 @@ void XGUI_Workshop::updateCommandStatus()
 }
 
 //******************************************************
-void XGUI_Workshop::updateModuleCommands()
+QList<QAction*> XGUI_Workshop::getModuleCommands() const
 {
   QList<QAction*> aCommands;
   if (isSalomeMode()) { // update commands in SALOME mode
@@ -726,9 +732,7 @@ void XGUI_Workshop::updateModuleCommands()
       }
     }
   }
-  foreach(QAction* aCmd, aCommands) {
-    aCmd->setEnabled(myModule->isFeatureEnabled(aCmd->data().toString()));
-  }
+  return aCommands;
 }
 
 //******************************************************
@@ -854,7 +858,7 @@ XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const
 //**************************************************************
 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
 {
-  QFeatureList aFeatures = mySelector->selectedFeatures();
+  QFeatureList aFeatures = mySelector->selection()->selectedFeatures();
   if ((theId == "ACTIVATE_PART_CMD") && (aFeatures.size() > 0))
     activatePart(aFeatures.first());
   else if (theId == "DEACTIVATE_PART_CMD") 
@@ -899,7 +903,8 @@ void XGUI_Workshop::activateLastPart()
 {
   PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
   DocumentPtr aDoc = aMgr->rootDocument();
-  FeaturePtr aLastPart = aDoc->feature(PARTS_GROUP, aDoc->size(PARTS_GROUP) - 1, true);
+  FeaturePtr aLastPart = aDoc->feature(ModelAPI_Document::PARTS_GROUP(),
+                                       aDoc->size(ModelAPI_Document::PARTS_GROUP()) - 1, true);
   activatePart(aLastPart);
 }
 
@@ -914,7 +919,7 @@ void XGUI_Workshop::deleteFeatures(QFeatureList theList)
     PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
     aMgr->rootDocument()->startOperation();
     foreach (FeaturePtr aFeature, theList) {
-      if (aFeature->getKind() == PARTSET_PART_KIND) {
+      if (aFeature->getKind() == PartSetPlugin_Part::ID()) {
         DocumentPtr aDoc;
         if (!XGUI_Tools::isModelObject(aFeature)) {
           aDoc = aFeature->data()->docRef("PartDocument")->value();
@@ -955,3 +960,24 @@ void XGUI_Workshop::showFeatures(QFeatureList theList, bool isVisible)
   }
   myDisplayer->updateViewer();
 }
+
+//**************************************************************
+void XGUI_Workshop::updateCommandsOnViewSelection()
+{
+  PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+  XGUI_Selection* aSelection = mySelector->selection();
+
+  QList<QAction*> aActions = getModuleCommands();
+  foreach(QAction* aAction, aActions) {
+    QString aId = aAction->data().toString();
+    const ModelAPI_Validator* aValidator = aFactory->validator(aId.toStdString());
+    if (aValidator) {
+      const ModuleBase_SelectionValidator* aSelValidator = 
+        dynamic_cast<const ModuleBase_SelectionValidator*>(aValidator);
+      if (aSelValidator) {
+        aAction->setEnabled(aSelValidator->isValid(aSelection));
+      }
+    }
+  }
+}