From 426a1cf07dfee0bbb58dcd399787a89a4992fa72 Mon Sep 17 00:00:00 2001 From: sbh Date: Wed, 13 Aug 2014 11:09:28 +0400 Subject: [PATCH] Implementation of the Feature Validator --- src/Model/CMakeLists.txt | 2 ++ src/Model/Model_FeatureValidator.cpp | 28 ++++++++++++++++++ src/Model/Model_FeatureValidator.h | 22 +++++++++++++++ src/Model/Model_Validator.cpp | 4 ++- src/ModelAPI/ModelAPI_Attribute.h | 3 ++ src/ModelAPI/ModelAPI_FeatureValidator.h | 5 ++-- src/SketchPlugin/plugin-Sketch.xml | 1 + src/XGUI/XGUI_MainMenu.cpp | 12 -------- src/XGUI/XGUI_MainMenu.h | 7 +++-- src/XGUI/XGUI_MainWindow.cpp | 3 +- src/XGUI/XGUI_MainWindow.h | 4 +-- src/XGUI/XGUI_OperationMgr.cpp | 36 ++++++++++++++++++++++++ src/XGUI/XGUI_OperationMgr.h | 7 +++++ src/XGUI/XGUI_PropertyPanel.cpp | 6 ++++ src/XGUI/XGUI_PropertyPanel.h | 2 ++ src/XGUI/XGUI_Workshop.cpp | 14 +++++---- src/XGUI/XGUI_Workshop.h | 2 ++ 17 files changed, 131 insertions(+), 27 deletions(-) create mode 100644 src/Model/Model_FeatureValidator.cpp create mode 100644 src/Model/Model_FeatureValidator.h diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 45c3db890..d2d6cc78d 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -19,6 +19,7 @@ SET(PROJECT_HEADERS Model_ResultConstruction.h Model_ResultPart.h Model_ResultValidators.h + Model_FeatureValidator.h ) SET(PROJECT_SOURCES @@ -39,6 +40,7 @@ SET(PROJECT_SOURCES Model_ResultConstruction.cpp Model_ResultPart.cpp Model_ResultValidators.cpp + Model_FeatureValidator.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/Model/Model_FeatureValidator.cpp b/src/Model/Model_FeatureValidator.cpp new file mode 100644 index 000000000..5490a3819 --- /dev/null +++ b/src/Model/Model_FeatureValidator.cpp @@ -0,0 +1,28 @@ +// File: Model_FeatureValidator.cpp +// Created: 8 Jul 2014 +// Author: Vitaly SMETANNIKOV + +#include +#include +#include +#include +#include + +#include +#include + +bool Model_FeatureValidator::isValid(const boost::shared_ptr& theFeature + /*, const std::string theAttr*/ + /*, std::list theArguments*/) const +{ + boost::shared_ptr aData = theFeature->data(); + if(!aData->isValid()) + return false; + const std::string kAllTypes = ""; + std::list aLtAttributes = aData->attributes(kAllTypes); + std::list::iterator it = aLtAttributes.begin(); + for( ; it != aLtAttributes.end(); it++) { + if(!(*it)->isInitialized()) return false; + } + return true; +} diff --git a/src/Model/Model_FeatureValidator.h b/src/Model/Model_FeatureValidator.h new file mode 100644 index 000000000..6ba52fd24 --- /dev/null +++ b/src/Model/Model_FeatureValidator.h @@ -0,0 +1,22 @@ +// File: ModelAPI_FeatureValidator.h +// Created: 8 Jul 2014 +// Author: Vitaly SMETANNIKOV + +#ifndef Model_FeatureValidator_H +#define Model_FeatureValidator_H + +#include +#include +#include + +#include + +class Model_FeatureValidator: public ModelAPI_FeatureValidator +{ +public: + /// Returns true if feature and/or attributes are valid + /// \param theFeature the validated feature + MODEL_EXPORT virtual bool isValid(const boost::shared_ptr& theFeature) const; +}; + +#endif diff --git a/src/Model/Model_Validator.cpp b/src/Model/Model_Validator.cpp index 19e9f56dd..bda76e29c 100644 --- a/src/Model/Model_Validator.cpp +++ b/src/Model/Model_Validator.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -94,6 +95,7 @@ Model_ValidatorsFactory::Model_ValidatorsFactory() : ModelAPI_ValidatorsFactory( registerValidator("Model_ResultPointValidator", new Model_ResultPointValidator); registerValidator("Model_ResultLineValidator", new Model_ResultLineValidator); registerValidator("Model_ResultArcValidator", new Model_ResultArcValidator); + registerValidator("Model_FeatureValidator", new Model_FeatureValidator); } @@ -104,4 +106,4 @@ const ModelAPI_Validator* Model_ValidatorsFactory::validator(const std::string& return aIt->second; } return NULL; -} \ No newline at end of file +} diff --git a/src/ModelAPI/ModelAPI_Attribute.h b/src/ModelAPI/ModelAPI_Attribute.h index 5173855f9..580f443db 100644 --- a/src/ModelAPI/ModelAPI_Attribute.h +++ b/src/ModelAPI/ModelAPI_Attribute.h @@ -57,4 +57,7 @@ protected: }; +//! Pointer on attribute object +typedef boost::shared_ptr AttributePtr; + #endif diff --git a/src/ModelAPI/ModelAPI_FeatureValidator.h b/src/ModelAPI/ModelAPI_FeatureValidator.h index 2023a66fc..d2378a0de 100644 --- a/src/ModelAPI/ModelAPI_FeatureValidator.h +++ b/src/ModelAPI/ModelAPI_FeatureValidator.h @@ -8,15 +8,14 @@ #include "ModelAPI.h" #include "ModelAPI_Validator.h" -class MODELAPI_EXPORT ModelAPI_FeatureValidator: public ModelAPI_Validator +class 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& theFeature, - const std::string theAttr, std::list theArguments) const = 0; + virtual bool isValid(const boost::shared_ptr& theFeature) const = 0; }; #endif diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 804f1bb32..b343b57ca 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -11,6 +11,7 @@ + diff --git a/src/XGUI/XGUI_MainMenu.cpp b/src/XGUI/XGUI_MainMenu.cpp index a16076e54..a558cdb36 100644 --- a/src/XGUI/XGUI_MainMenu.cpp +++ b/src/XGUI/XGUI_MainMenu.cpp @@ -115,18 +115,6 @@ QList XGUI_MainMenu::features() const return aList; } -QList XGUI_MainMenu::workbenches() const -{ - QList aList; - for (int aTabIdx = 0; aTabIdx < myMenuTabs->count(); ++aTabIdx) { - XGUI_Workbench* aWb = dynamic_cast(myMenuTabs->widget(aTabIdx)); - if (aWb) { - aList.append(aWb); - } - } - return aList; -} - int XGUI_MainMenu::menuItemSize() const { //TODO(sbh, vsv): get this value from the preferences diff --git a/src/XGUI/XGUI_MainMenu.h b/src/XGUI/XGUI_MainMenu.h index 3be908792..718bd50a7 100644 --- a/src/XGUI/XGUI_MainMenu.h +++ b/src/XGUI/XGUI_MainMenu.h @@ -56,8 +56,6 @@ public: //! Returns list of created commands QList features() const; - QList workbenches() const; - virtual bool eventFilter(QObject *theWatched, QEvent *theEvent); //! Displays given console as a tab in the workbench @@ -65,8 +63,13 @@ public: //! Removes already created tab with python console void removeConsole(); + //! Defines size of menu item. + //! In the future this value should be extracted from the preferences. int menuItemSize() const; + //! Defines number of menu item rows. + //! In the future this value should be extracted from the preferences. int menuItemRowsCount() const; + //! Defines height of the main menu. (Number of rows * row height) int menuHeight() const; private: diff --git a/src/XGUI/XGUI_MainWindow.cpp b/src/XGUI/XGUI_MainWindow.cpp index 28db1de97..3aa696045 100644 --- a/src/XGUI/XGUI_MainWindow.cpp +++ b/src/XGUI/XGUI_MainWindow.cpp @@ -18,8 +18,7 @@ XGUI_MainWindow::XGUI_MainWindow(QWidget* parent) : QMainWindow(parent), - myPythonConsole(0), - myIsConsoleDocked(false) + myPythonConsole(0) { setWindowTitle(tr("New Geom")); createMainMenu(); diff --git a/src/XGUI/XGUI_MainWindow.h b/src/XGUI/XGUI_MainWindow.h index 2126834aa..293163d4a 100644 --- a/src/XGUI/XGUI_MainWindow.h +++ b/src/XGUI/XGUI_MainWindow.h @@ -44,7 +44,9 @@ public: public slots: void showPythonConsole(); void hidePythonConsole(); + //! Python console can be a dock widget void dockPythonConsole(); + //! or can be a tab in the main menu. void undockPythonConsole(); void createSubWindow(); @@ -68,8 +70,6 @@ private: XGUI_Viewer* myViewer; PyConsole_EnhConsole* myPythonConsole; - //! Python console can be a dock widget if true, else as the tab. - bool myIsConsoleDocked; }; class XGUI_EXPORT CloseEventWatcher: public QObject { diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 8a3b36e12..7dca8e3c1 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -5,6 +5,8 @@ #include "XGUI_OperationMgr.h" #include "ModuleBase_Operation.h" +#include +#include #include #include @@ -50,6 +52,7 @@ bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation) this, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*))); theOperation->start(); + validateCurrentOperation(); return true; } @@ -72,6 +75,39 @@ QStringList XGUI_OperationMgr::operationList() return result; } +void XGUI_OperationMgr::validateOperation(ModuleBase_Operation* theOperation) +{ + //Get operation Id and feature to validate + QString anOperationId = theOperation->id(); + FeaturePtr aFeature = theOperation->feature(); + //Get validators for the Id + PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + std::list aValidators; + aFactory->validators(anOperationId.toStdString(), aValidators); + // + std::list::iterator it = aValidators.begin(); + bool isValid = true; + for(; it != aValidators.end(); it++) { + const ModelAPI_FeatureValidator* aFeatureValidator = + dynamic_cast(*it); + if (!aFeatureValidator) continue; + if (!aFeatureValidator->isValid(aFeature)) { + isValid = false; + break; + } + } + emit operationValidated(isValid); +} + +void XGUI_OperationMgr::validateCurrentOperation() +{ + if(!hasOperation()) + return; + ModuleBase_Operation* anOperation = currentOperation(); + validateOperation(currentOperation()); +} + bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent) { if (theEvent->type() == QEvent::KeyRelease) { diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index f6632c161..11a670088 100644 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -54,6 +54,9 @@ public: virtual bool eventFilter(QObject *theObject, QEvent *theEvent); +public slots: + void validateCurrentOperation(); + signals: /// Signal about an operation is started. It is emitted after the start() of operation is done. void operationStarted(); @@ -62,6 +65,8 @@ signals: void operationStopped(ModuleBase_Operation* theOperation); /// Signal about an operation is resumed. It is emitted after the resume() of operation is done. void operationResumed(); + /// Signal is emitted after the validate methods calls. + void operationValidated(bool); /// Signal about the necessety of the next widget activating /// \param theWidget the model widget void activateNextWidget(ModuleBase_ModelWidget* theWidget); @@ -84,6 +89,8 @@ protected: /// Returns true if the operation can be aborted bool canAbortOperation(); + void validateOperation(ModuleBase_Operation* theOperation); + protected slots: /// Slot that commits the current operation. void onCommitOperation(); diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index 5b26e4e6a..b686fcebf 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -167,3 +167,9 @@ void XGUI_PropertyPanel::onActivateNextWidget(ModuleBase_ModelWidget* theWidget) } emit widgetActivated(aNextWidget); } + +void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled) +{ + QPushButton* anOkBtn = findChild(XGUI::PROP_PANEL_OK); + anOkBtn->setEnabled(isEnabled); +} diff --git a/src/XGUI/XGUI_PropertyPanel.h b/src/XGUI/XGUI_PropertyPanel.h index 228531053..7b55b2c0f 100644 --- a/src/XGUI/XGUI_PropertyPanel.h +++ b/src/XGUI/XGUI_PropertyPanel.h @@ -39,6 +39,8 @@ public slots: /// slot to activate the next widget in the property panel /// \param theWidget a widget. The next widget should be activated void onActivateNextWidget(ModuleBase_ModelWidget* theWidget); + // Enables / disables "ok" ("accept") button + void setAcceptEnabled(bool); signals: /// The signal about key release on the control, that corresponds to the attribute diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index b25db3e10..c02b05350 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -321,6 +321,7 @@ void XGUI_Workshop::onFeatureUpdatedMsg(const ModelAPI_ObjectUpdatedMessage* the } } } + myOperationMgr->validateCurrentOperation(); } //****************************************************** @@ -384,7 +385,7 @@ void XGUI_Workshop::onObjectDeletedMsg(const ModelAPI_ObjectDeletedMessage* theM { //std::set aFeatures = theMsg->objects(); } - + //****************************************************** void XGUI_Workshop::onOperationStarted() { @@ -395,7 +396,8 @@ void XGUI_Workshop::onOperationStarted() showPropertyPanel(); QString aXmlRepr = aOperation->getDescription()->xmlRepresentation(); - ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(), myModuleConnector); + ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(), + myModuleConnector); myPropertyPanel->cleanContent(); aFactory.createWidget(myPropertyPanel->contentWidget()); @@ -794,9 +796,8 @@ QList XGUI_Workshop::getModuleCommands() const aCommands = salomeConnector()->commandList(); } else { XGUI_MainMenu* aMenuBar = myMainWindow->menuObject(); - foreach (XGUI_Workbench* aWb, aMenuBar->workbenches()) { - foreach(XGUI_Command* aCmd, aWb->features()) - aCommands.append(aCmd); + foreach(XGUI_Command* aCmd, aMenuBar->features()) { + aCommands.append(aCmd); } } return aCommands; @@ -846,6 +847,9 @@ void XGUI_Workshop::createDockWidgets() myOperationMgr, SLOT(onWidgetActivated(ModuleBase_ModelWidget*))); connect(myOperationMgr, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), myPropertyPanel, SLOT(onActivateNextWidget(ModuleBase_ModelWidget*))); + connect(myOperationMgr, SIGNAL(operationValidated(bool)), + myPropertyPanel, SLOT(setAcceptEnabled(bool))); + } //****************************************************** diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index be2d9a032..f80b8cf7d 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -161,6 +161,8 @@ protected: void onFeatureRedisplayMsg(const ModelAPI_ObjectUpdatedMessage* theMsg); void onObjectDeletedMsg(const ModelAPI_ObjectDeletedMessage* theMsg); + void validateOperation(const QString& theOperationId); + QList getModuleCommands() const; void displayAllResults(); -- 2.30.2