]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Implementation of the Feature Validator
authorsbh <sergey.belash@opencascade.com>
Wed, 13 Aug 2014 07:09:28 +0000 (11:09 +0400)
committersbh <sergey.belash@opencascade.com>
Wed, 13 Aug 2014 07:09:28 +0000 (11:09 +0400)
17 files changed:
src/Model/CMakeLists.txt
src/Model/Model_FeatureValidator.cpp [new file with mode: 0644]
src/Model/Model_FeatureValidator.h [new file with mode: 0644]
src/Model/Model_Validator.cpp
src/ModelAPI/ModelAPI_Attribute.h
src/ModelAPI/ModelAPI_FeatureValidator.h
src/SketchPlugin/plugin-Sketch.xml
src/XGUI/XGUI_MainMenu.cpp
src/XGUI/XGUI_MainMenu.h
src/XGUI/XGUI_MainWindow.cpp
src/XGUI/XGUI_MainWindow.h
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h
src/XGUI/XGUI_PropertyPanel.cpp
src/XGUI/XGUI_PropertyPanel.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 45c3db89032839e88423b3c387d15ec3f321ad70..d2d6cc78d8d9c0dec995dadcb6ab29d0939c58d0 100644 (file)
@@ -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 (file)
index 0000000..5490a38
--- /dev/null
@@ -0,0 +1,28 @@
+// File:        Model_FeatureValidator.cpp
+// Created:     8 Jul 2014
+// Author:      Vitaly SMETANNIKOV
+
+#include <Model_FeatureValidator.h>
+#include <ModelAPI_Attribute.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
+
+#include <list>
+#include <boost/shared_ptr.hpp>
+
+bool Model_FeatureValidator::isValid(const boost::shared_ptr<ModelAPI_Feature>& theFeature
+                                     /*, const std::string theAttr*/
+                                     /*, std::list<std::string> theArguments*/) const
+{
+  boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+  if(!aData->isValid())
+    return false;
+  const std::string kAllTypes = "";
+  std::list<AttributePtr> aLtAttributes = aData->attributes(kAllTypes);
+  std::list<AttributePtr>::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 (file)
index 0000000..6ba52fd
--- /dev/null
@@ -0,0 +1,22 @@
+// File:        ModelAPI_FeatureValidator.h
+// Created:     8 Jul 2014
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef Model_FeatureValidator_H
+#define Model_FeatureValidator_H
+
+#include <Model.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_FeatureValidator.h>
+
+#include <boost/shared_ptr.hpp>
+
+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<ModelAPI_Feature>& theFeature) const;
+};
+
+#endif
index 19e9f56dda46f684efb290f3237d36526944f6f7..bda76e29cc0695bf4d90acfbd201439bef9bbb71 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <Model_Validator.h>
 #include <Model_ResultValidators.h>
+#include <Model_FeatureValidator.h>
 #include <ModelAPI_Feature.h>
 #include <Events_Error.h>
 
@@ -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
+}
index 5173855f9eafe03a9bc8560238cc7dab61833a34..580f443dbb1e4138eddef31f5615ade924873271 100644 (file)
@@ -57,4 +57,7 @@ protected:
 
 };
 
+//! Pointer on attribute object
+typedef boost::shared_ptr<ModelAPI_Attribute> AttributePtr;
+
 #endif
index 2023a66fc77a88ecd3a6166f17471d5e7209909e..d2378a0dea994f19820a40caa7be441f374aebc3 100644 (file)
@@ -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<ModelAPI_Feature>& theFeature,
-    const std::string theAttr, std::list<std::string> theArguments) const = 0;
+  virtual bool isValid(const boost::shared_ptr<ModelAPI_Feature>& theFeature) const = 0;
 };
 
 #endif
index 804f1bb32609a9d858b818f13d125e28a5a2cf43..b343b57cadbe90f35a4dc40274b037579d317ee7 100644 (file)
@@ -11,6 +11,7 @@
       <feature id="SketchLine" title="Line" tooltip="Create a new line" icon=":icons/line.png">
         <point_selector id="StartPoint" title="Start point" tooltip="Start point of the line" previous_feature_param="EndPoint"/>
         <point_selector id="EndPoint" title="End point" tooltip="End point of the line"/>
+        <validator id="Model_FeatureValidator" />
       </feature>
       <feature id="SketchCircle" title="Circle" tooltip="Create a new circle" icon=":icons/circle.png">
         <point_selector id="CircleCenter" title="Center" tooltip="Center of the circle"/>
index a16076e54024327846d11e202388ea3930ffdaef..a558cdb36f052c09ef5327f80022683aea9c3e99 100644 (file)
@@ -115,18 +115,6 @@ QList<XGUI_Command*> XGUI_MainMenu::features() const
   return aList;
 }
 
-QList<XGUI_Workbench*> XGUI_MainMenu::workbenches() const
-{
-  QList<XGUI_Workbench*> aList;
-  for (int aTabIdx = 0; aTabIdx < myMenuTabs->count(); ++aTabIdx) {
-    XGUI_Workbench* aWb = dynamic_cast<XGUI_Workbench*>(myMenuTabs->widget(aTabIdx));
-    if (aWb) {
-      aList.append(aWb);
-    }
-  }
-  return aList;
-}
-
 int XGUI_MainMenu::menuItemSize() const
 {
   //TODO(sbh, vsv): get this value from the preferences
index 3be908792422bc615f555073b0c96bc855d37718..718bd50a7b59197df2e47a28e31f5bb86c5a4acd 100644 (file)
@@ -56,8 +56,6 @@ public:
   //! Returns list of created commands
   QList<XGUI_Command*> features() const;
 
-  QList<XGUI_Workbench*> 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:
index 28db1de97dd13948b96f4b5847a386859df9ec6f..3aa696045b5be600507280c70bcc2dd80a1ca208 100644 (file)
@@ -18,8 +18,7 @@
 
 XGUI_MainWindow::XGUI_MainWindow(QWidget* parent)
     : QMainWindow(parent), 
-    myPythonConsole(0),
-    myIsConsoleDocked(false)
+    myPythonConsole(0)
 {
   setWindowTitle(tr("New Geom"));
   createMainMenu();
index 2126834aad458c51900c72926f786ca14619ad54..293163d4a5ca5285d2aeedb3161e817343903943 100644 (file)
@@ -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 {
index 8a3b36e12ca8755668b625de5c2f3df25eb958ca..7dca8e3c18700f6a101581e3ad8fafbe5c104e3c 100644 (file)
@@ -5,6 +5,8 @@
 #include "XGUI_OperationMgr.h"
 
 #include "ModuleBase_Operation.h"
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_FeatureValidator.h>
 
 #include <QMessageBox>
 #include <QApplication>
@@ -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<ModelAPI_Validator*> aValidators;
+  aFactory->validators(anOperationId.toStdString(), aValidators);
+  //
+  std::list<ModelAPI_Validator*>::iterator it = aValidators.begin();
+  bool isValid = true;
+  for(; it != aValidators.end(); it++) {
+    const ModelAPI_FeatureValidator* aFeatureValidator =
+        dynamic_cast<const ModelAPI_FeatureValidator*>(*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) {
index f6632c161631d3b04c8ea152d09c3632d6b71cd5..11a670088d0b7397b0404c89929ff132cba8027d 100644 (file)
@@ -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();
index 5b26e4e6a8f62b7937613382b6bfcceb36a598b0..b686fcebf3c80e4b8d4971e6576552afb47d14c4 100644 (file)
@@ -167,3 +167,9 @@ void XGUI_PropertyPanel::onActivateNextWidget(ModuleBase_ModelWidget* theWidget)
   }
   emit widgetActivated(aNextWidget);
 }
+
+void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled)
+{
+  QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
+  anOkBtn->setEnabled(isEnabled);
+}
index 22853105352ca4edcc3ba6be5495d52105091c04..7b55b2c0f5713feefc9896af887ad6c0cb2c89d3 100644 (file)
@@ -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
index b25db3e105acd9f4adc0fe80195719baa747fc1d..c02b053506a033106a0a168edfa26f78517a5211 100644 (file)
@@ -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<ObjectPtr> 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<QAction*> 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)));
+
 }
 
 //******************************************************
index be2d9a032f7525841ad5f0960b6a2769bf898bc3..f80b8cf7d30e4fe82e656c3aa0ae067b0a5248f3 100644 (file)
@@ -161,6 +161,8 @@ protected:
   void onFeatureRedisplayMsg(const ModelAPI_ObjectUpdatedMessage* theMsg);
   void onObjectDeletedMsg(const ModelAPI_ObjectDeletedMessage* theMsg);
 
+  void validateOperation(const QString& theOperationId);
+
   QList<QAction*> getModuleCommands() const;
 
   void displayAllResults();