Salome HOME
Define Selection validator interface.
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 8 Jul 2014 12:36:31 +0000 (16:36 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 8 Jul 2014 12:36:31 +0000 (16:36 +0400)
12 files changed:
src/Model/Model_Validator.cpp
src/Model/Model_Validator.h
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI_FeatureValidator.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_Validator.h
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_IModule.h
src/ModuleBase/ModuleBase_ViewSelectionValidator.h [new file with mode: 0644]
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index fe7110924634b04434eedb72f2e73e0f4de07ddb..3f6e1c6caabbeb90b5bccd67bcdaedba39b7ea1d 100644 (file)
@@ -77,7 +77,7 @@ const ModelAPI_Validator* Model_ValidatorsFactory::validator(const string& theFe
   return NULL; // not found
 }
 
-bool Model_ValidatorsFactory::validate(
+/*bool Model_ValidatorsFactory::validate(
   const boost::shared_ptr<ModelAPI_Feature>& theFeature, const string& theAttrID ) const
 {
   map<string, map<string, pair<ModelAPI_Validator*, list<string> > > >::const_iterator
@@ -87,7 +87,7 @@ bool Model_ValidatorsFactory::validate(
     anAttr = aFeature->second.find(theAttrID);
   if (anAttr == aFeature->second.cend()) return true; // attribute is not found
   return anAttr->second.first->validate(theFeature, theAttrID, anAttr->second.second);
-}
+}*/
 
 Model_ValidatorsFactory::Model_ValidatorsFactory() : ModelAPI_ValidatorsFactory()
 {
index 9d04e290167ff128c9134a8cb9122f1f966d55c9..a917911d91c5dce5218c927a4167a21b6ebd0041 100644 (file)
@@ -46,8 +46,8 @@ public:
 
   /// Returns the result of "validate" method for attribute of validator.
   /// If validator is not exists, returns true: everything is valid by default.
-  MODEL_EXPORT virtual bool validate(
-    const boost::shared_ptr<ModelAPI_Feature>& theFeature, const std::string& theAttrID) const;
+  //MODEL_EXPORT virtual bool validate(
+  //  const boost::shared_ptr<ModelAPI_Feature>& theFeature, const std::string& theAttrID) const;
 
 protected:
   /// Get instance from PluginManager
index 5a13d37a656f9463992df4272f652b15d046ad69..8b834dd72561b7790f3bde8fa3a7048c8c786983 100644 (file)
@@ -19,6 +19,7 @@ SET(PROJECT_HEADERS
     ModelAPI_AttributeBoolean.h
     ModelAPI_Events.h
     ModelAPI_Validator.h
+    ModelAPI_FeatureValidator.h
 )
 
 SET(PROJECT_SOURCES
diff --git a/src/ModelAPI/ModelAPI_FeatureValidator.h b/src/ModelAPI/ModelAPI_FeatureValidator.h
new file mode 100644 (file)
index 0000000..2023a66
--- /dev/null
@@ -0,0 +1,22 @@
+// File:        ModelAPI_FeatureValidator.h
+// Created:     8 Jul 2014
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef ModelAPI_FeatureValidator_H
+#define ModelAPI_FeatureValidator_H
+
+#include "ModelAPI.h"
+#include "ModelAPI_Validator.h"
+
+class MODELAPI_EXPORT ModelAPI_FeatureValidator: public ModelAPI_Validator
+{
+public:
+  /// Returns true if feature and/or attributes are valid
+  /// \param theFeature the validated feature
+  /// \param theAttr the validated attribute ID, empty string of feature is validated
+  /// \param theArguments list of string, feature attribute names: dependent attributes
+  virtual bool validate(const boost::shared_ptr<ModelAPI_Feature>& theFeature,
+    const std::string theAttr, std::list<std::string> theArguments) const = 0;
+};
+
+#endif
index 4a0243cd009627cb30dce073b43d3a3e47bd0403..4c807763ac2f2cd104415b062846b1fc8e23444f 100644 (file)
@@ -25,12 +25,15 @@ class ModelAPI_Feature;
 class MODELAPI_EXPORT ModelAPI_Validator
 {
 public:
+  // Make virtual destructor in order to make the class polymorphic
+  virtual ~ModelAPI_Validator() {};
+
   /// Returns true if feature and/or attributes are valid
   /// \param theFeature the validated feature
   /// \param theAttr the validated attribute ID, empty string of feature is validated
   /// \param theArguments list of string, feature attribute names: dependent attributes
-  virtual bool validate(const boost::shared_ptr<ModelAPI_Feature>& theFeature,
-    const std::string theAttr, std::list<std::string> theArguments) const = 0;
+  //virtual bool validate(const boost::shared_ptr<ModelAPI_Feature>& theFeature,
+  //  const std::string theAttr, std::list<std::string> theArguments) const = 0;
 };
 
 typedef boost::shared_ptr<ModelAPI_Validator> ValidatorPtr;
@@ -66,8 +69,8 @@ public:
 
   /// Returns the result of "validate" method for attribute of validator.
   /// If validator is not exists, returns true: everything is valid by default.
-  virtual bool validate(
-    const boost::shared_ptr<ModelAPI_Feature>& theFeature, const std::string& theAttrID) const = 0;
+  //virtual bool validate(
+  //  const boost::shared_ptr<ModelAPI_Feature>& theFeature, const std::string& theAttrID) const = 0;
 
 protected:
   /// Get instance from PluginManager
index 6b3847b293b466d43282a28cd566ba386c616a31..4f34faab863a27a95492ae39e1705b2fa8207e76 100644 (file)
@@ -22,6 +22,7 @@ SET(PROJECT_HEADERS
        ModuleBase_WidgetValue.h
        ModuleBase_WidgetValueFeature.h
        ModuleBase_Definitions.h
+       ModuleBase_ViewSelectionValidator.h
 )
 
 SET(PROJECT_SOURCES
index b5245c37ce15a400416b35ffc78ea1f59e36213b..ae652617e9f8a4f5ae7d39576d6fc0bd3f37f1ea 100644 (file)
@@ -26,7 +26,7 @@ public:
   virtual void launchOperation(const QString& theCmdId) = 0;
 
   /// Called when it is necessary to update a command state (enable or disable it)
-  virtual bool isFeatureEnabled(const QString& theCmdId) const = 0;
+  //virtual bool isFeatureEnabled(const QString& theCmdId) const = 0;
 
   /// Creates custom widgets for property panel
   virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent, 
diff --git a/src/ModuleBase/ModuleBase_ViewSelectionValidator.h b/src/ModuleBase/ModuleBase_ViewSelectionValidator.h
new file mode 100644 (file)
index 0000000..9dcc910
--- /dev/null
@@ -0,0 +1,18 @@
+// File:        ModuleBase_ViewSelectionValidator.h
+// Created:     8 Jul 2014
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef ModuleBase_ViewSelectionValidator_H
+#define ModuleBase_ViewSelectionValidator_H
+
+#include "ModuleBase.h"
+
+#include <ModelAPI_Validator.h>
+
+class MODULEBASE_EXPORT ModuleBase_ViewSelectionValidator: public ModelAPI_Validator
+{
+public:
+  virtual bool isValid(const Handle(AIS_InteractiveContext)& theContext) const = 0;
+};
+
+#endif
index 9af38c4dc7c9bb8e69a7483522b804c715c22e00..8d40a07f7dc53673d683511b40f71d088e87066d 100644 (file)
@@ -522,7 +522,7 @@ void PartSet_Module::onStorePoint2D(FeaturePtr theFeature, const std::string& th
                                 aPoint->x(), aPoint->y());
 }
 
-bool PartSet_Module::isFeatureEnabled(const QString& theCmdId) const
+/*bool PartSet_Module::isFeatureEnabled(const QString& theCmdId) const
 {
   XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr();
   XGUI_ActionsMgr* aActMgr = myWorkshop->actionsMgr();
@@ -540,7 +540,7 @@ bool PartSet_Module::isFeatureEnabled(const QString& theCmdId) const
   }
   QStringList aList = aActMgr->nestedCommands(aOperation->id());
   return aList.contains(theCmdId);
-}
+}*/
 
 QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent, 
                          Config_WidgetAPI* theWidgetApi, QList<ModuleBase_ModelWidget*>& theModelWidgets)
index 7dbbc587be49f10a7b7a50e2da9199e74b261972..627d088b15bf30c63627d5b317449d3a1191d41b 100644 (file)
@@ -49,7 +49,7 @@ public:
   virtual void launchOperation(const QString& theCmdId);
 
   /// Called when it is necessary to update a command state (enable or disable it)
-  virtual bool isFeatureEnabled(const QString& theCmdId) const;
+  //virtual bool isFeatureEnabled(const QString& theCmdId) const;
 
   /// Displays or erase the current operation preview, if it has it.
   /// \param theFeature the feature instance to be displayed
index 7be906691ae361f33510a648ed18b9c56a9d6a45..c6b5f55bdba54bdae36878bed97f64a6cbe8613a 100644 (file)
 #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_ViewSelectionValidator.h>
+
 #include <Config_Common.h>
 #include <Config_FeatureMessage.h>
 #include <Config_PointerMessage.h>
@@ -85,7 +89,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 +99,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);
 
@@ -712,7 +717,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 +731,7 @@ void XGUI_Workshop::updateModuleCommands()
       }
     }
   }
-  foreach(QAction* aCmd, aCommands) {
-    aCmd->setEnabled(myModule->isFeatureEnabled(aCmd->data().toString()));
-  }
+  return aCommands;
 }
 
 //******************************************************
@@ -955,3 +958,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();
+  Handle(AIS_InteractiveContext) aContext = viewer()->AISContext();
+
+  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_ViewSelectionValidator* aSelValidator = 
+        dynamic_cast<const ModuleBase_ViewSelectionValidator*>(aValidator);
+      if (aSelValidator) {
+        aAction->setEnabled(aSelValidator->isValid(aContext));
+      }
+    }
+  }
+}
index 1172bc7dee0479550053ff910a41ffca0ffaaa3c..960c4dd89e5b5e4ab191c7c8f41c18897f510efc 100644 (file)
@@ -38,6 +38,7 @@ class QWidget;
 class QDockWidget;
 
 class Model_FeatureUpdatedMessage;
+class QAction;
 
 /**\class XGUI_Workshop
  * \ingroup GUI
@@ -125,7 +126,7 @@ signals:
 
 public slots:
   void updateCommandStatus();
-  void updateModuleCommands();
+  void updateCommandsOnViewSelection();
 
   void onNew();
   void onOpen();
@@ -155,6 +156,8 @@ protected:
   void onFeatureCreatedMsg(const Model_FeatureUpdatedMessage* theMsg);
   void onFeatureRedisplayMsg(const Model_FeatureUpdatedMessage* theMsg);
 
+  QList<QAction*> getModuleCommands() const;
+
 protected slots:
   /// SLOT, that is called after the operation is started. Update workshop state according to
   /// the started operation, e.g. visualizes the property panel and connect to it.