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
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()
{
/// 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
ModelAPI_AttributeBoolean.h
ModelAPI_Events.h
ModelAPI_Validator.h
+ ModelAPI_FeatureValidator.h
)
SET(PROJECT_SOURCES
--- /dev/null
+// 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
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;
/// 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
ModuleBase_WidgetValue.h
ModuleBase_WidgetValueFeature.h
ModuleBase_Definitions.h
+ ModuleBase_ViewSelectionValidator.h
)
SET(PROJECT_SOURCES
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,
--- /dev/null
+// 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
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();
}
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)
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
#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>
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);
this, SLOT(onContextMenuCommand(const QString&, bool)));
myViewerProxy = new XGUI_ViewerProxy(this);
+ connect(myViewerProxy, SIGNAL(selectionChanged()), this, SLOT(updateCommandsOnViewSelection()));
myModuleConnector = new XGUI_ModuleConnector(this);
}
//******************************************************
-void XGUI_Workshop::updateModuleCommands()
+QList<QAction*> XGUI_Workshop::getModuleCommands() const
{
QList<QAction*> aCommands;
if (isSalomeMode()) { // update commands in SALOME mode
}
}
}
- foreach(QAction* aCmd, aCommands) {
- aCmd->setEnabled(myModule->isFeatureEnabled(aCmd->data().toString()));
- }
+ return aCommands;
}
//******************************************************
}
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));
+ }
+ }
+ }
+}
class QDockWidget;
class Model_FeatureUpdatedMessage;
+class QAction;
/**\class XGUI_Workshop
* \ingroup GUI
public slots:
void updateCommandStatus();
- void updateModuleCommands();
+ void updateCommandsOnViewSelection();
void onNew();
void onOpen();
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.