]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
#1112 tab key doesn't work on the last field of left panels
authornds <nds@opencascade.com>
Tue, 15 Dec 2015 09:42:11 +0000 (12:42 +0300)
committernds <nds@opencascade.com>
Tue, 15 Dec 2015 09:42:47 +0000 (12:42 +0300)
Improvement: modification of the value in the property panel should make enabled the Apply button in the panel. The value is not applyed to the model yet, but click on Apply leads to the values apply. The button becomes disabled if the result is invalid feature.

src/ModelAPI/ModelAPI_Tools.cpp
src/ModelAPI/ModelAPI_Tools.h
src/ModuleBase/ModuleBase_IModule.cpp
src/ModuleBase/ModuleBase_ModelWidget.cpp
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_OperationFeature.cpp
src/XGUI/XGUI_ErrorMgr.cpp
src/XGUI/XGUI_ErrorMgr.h
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h
src/XGUI/XGUI_WorkshopListener.cpp

index 4fa9775d62a73cacacadc47df946fb5692e9ee33..9023cb2d2d89893c4fb9bf343d2fc6ab248571a1 100755 (executable)
@@ -22,6 +22,29 @@ std::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult)
   return theResult->shape();
 }
 
+std::string getFeatureError(const FeaturePtr& theFeature)
+{
+  std::string anError;
+  if (!theFeature.get() || !theFeature->data()->isValid() || theFeature->isAction())
+    return anError;
+
+  // to be removed later, this error should be got from the feature
+  if (theFeature->data()->execState() == ModelAPI_StateDone ||
+      theFeature->data()->execState() == ModelAPI_StateMustBeUpdated)
+    return anError;
+
+  // set error indication
+  anError = theFeature->error();
+  if (anError.empty()) {
+    bool isDone = ( theFeature->data()->execState() == ModelAPI_StateDone
+                 || theFeature->data()->execState() == ModelAPI_StateMustBeUpdated );
+    if (!isDone)
+      anError = theFeature->data()->execState();
+  }
+
+  return anError;
+}
+
 ObjectPtr objectByName(const DocumentPtr& theDocument, const std::string& theGroup, const std::string& theName)
 {
   for (int anIndex = 0; anIndex < theDocument->size(theGroup); ++anIndex) {
index 9d544cbf8e4afac7941e6ba851f1abf37e308c61..0b3f965b7f19ea7c6360bc147a207d45eb98e733 100755 (executable)
@@ -24,6 +24,12 @@ namespace ModelAPI_Tools {
 /// Returns shape from the given Result object
 MODELAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult);
 
+/*! Returns the feature error generated according to feature error and exec state
+ * \param theFeature a feature
+ * \return error value or empty string
+ */
+MODELAPI_EXPORT std::string getFeatureError(const FeaturePtr& theFeature);
+
 /*!
  * Searches for variable with name \param theName in \param theDocument. 
  * If found, set it value in the \param outValue and returns true.
index c73bf3c1c5081a803b07d15181918d283418eaae..2994da26d18154cd9885e4bf0722e3804c0e3097 100644 (file)
@@ -8,7 +8,7 @@
 #include "ModuleBase_ISelection.h"
 #include "ModuleBase_OperationDescription.h"
 #include "ModuleBase_OperationFeature.h"
-#include <ModuleBase_ModelWidget.h>
+#include "ModuleBase_ModelWidget.h"
 
 #include <Events_Loop.h>
 
@@ -16,6 +16,7 @@
 #include <ModelAPI_Events.h>
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_Session.h>
+#include "ModelAPI_Tools.h"
 
 #include <Config_PointerMessage.h>
 #include <Config_WidgetReader.h>
@@ -82,25 +83,7 @@ const char* toString(ModelAPI_ExecState theExecState)
 
 QString ModuleBase_IModule::getFeatureError(const FeaturePtr& theFeature)
 {
-  QString anError;
-  if (!theFeature.get() || !theFeature->data()->isValid() || theFeature->isAction())
-    return anError;
-
-  // to be removed later, this error should be got from the feature
-  if (theFeature->data()->execState() == ModelAPI_StateDone ||
-      theFeature->data()->execState() == ModelAPI_StateMustBeUpdated)
-    return anError;
-
-  // set error indication
-  anError = QString::fromStdString(theFeature->error());
-  if (anError.isEmpty()) {
-    bool isDone = ( theFeature->data()->execState() == ModelAPI_StateDone
-                 || theFeature->data()->execState() == ModelAPI_StateMustBeUpdated );
-    if (!isDone)
-      anError = toString(theFeature->data()->execState());
-  }
-
-  return anError;
+  return ModelAPI_Tools::getFeatureError(theFeature).c_str();
 }
 
 QString ModuleBase_IModule::getWidgetError(ModuleBase_ModelWidget* theWidget)
index d9c678185b11bd4138c2783094a028e4cf0ae382..504b8ca8f95de6723a3a75d5e2fd075eca1760e0 100644 (file)
@@ -64,10 +64,6 @@ QString ModuleBase_ModelWidget::getValueStateError() const
     if (anAttr.get()) {
       QString anAttributeName = anAttr->id().c_str();
       switch (aState) {
-        case ModuleBase_ModelWidget::ModifiedInPP:
-          anError = "Attribute \"" + anAttributeName +
-                    "\" modification is not applyed. Please click \"Enter\" or \"Tab\".";
-          break;
         case ModuleBase_ModelWidget::ModifiedInViewer:
           anError = "Attribute \"" + anAttributeName +
                     "\" is locked by modification value in the viewer.";
@@ -75,6 +71,9 @@ QString ModuleBase_ModelWidget::getValueStateError() const
         case ModuleBase_ModelWidget::Reset:
           anError = "Attribute \"" + anAttributeName + "\" is not initialized.";
           break;
+        case ModuleBase_ModelWidget::ModifiedInPP: // Apply should be enabled in this mode
+        default:
+          break;
       }
     }
   }
index 25ccc5aa1abcf8d967e09a4791cef9d9fcc22969..8194af412247152cc3cefa67aa078c292d58acce 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <memory>
 
+class ModuleBase_OperationFeature;
 class Config_WidgetAPI;
 class ModuleBase_IWorkshop;
 class QKeyEvent;
@@ -301,6 +302,8 @@ private:
   bool myUseReset;
   /// blocked flag of modification of the value state
   bool myIsValueStateBlocked;
+
+  friend ModuleBase_OperationFeature; // to call storeValue() by commit if value state is ModifiedInPP
 };
 
 #endif
index c8f1224b69d97c89ed9dcd2e6c79b790861d7147..0471bfae79e26b601075e030af60a165015df91b 100755 (executable)
@@ -86,17 +86,9 @@ bool ModuleBase_OperationFeature::isValid() const
     return true; // rename operation
   if (myFeature->isAction())
     return true;
-  //Get validators for the Id
-  SessionPtr aMgr = ModelAPI_Session::get();
-  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-  bool aValid = aFactory->validate(myFeature);
-
-  // the feature exec state should be checked in order to do not apply features, which result can not
-  // be built. E.g. extrusion on sketch, where the "to" is a perpendicular plane to the sketch
-  bool isDone = ( myFeature->data()->execState() == ModelAPI_StateDone
-               || myFeature->data()->execState() == ModelAPI_StateMustBeUpdated );
 
-  return aValid && isDone;
+  std::string anError = ModelAPI_Tools::getFeatureError(myFeature);
+  return anError.empty();
 }
 
 void ModuleBase_OperationFeature::startOperation()
@@ -268,6 +260,13 @@ void ModuleBase_OperationFeature::abort()
 
 bool ModuleBase_OperationFeature::commit()
 {
+  ModuleBase_IPropertyPanel* aPanel = propertyPanel();
+  if (aPanel) {
+    ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
+    if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
+      anActiveWidget->storeValue();
+    }
+  }
   if (canBeCommitted()) {
     emit beforeCommitted();
     // the widgets of property panel should not process any events come from data mode
index afacb5d82e77cb29e1212b3a39dda5e9bdd88961..7156e296fffbb4bb4edfef22b9d78a65dfebad6a 100644 (file)
@@ -55,13 +55,20 @@ void XGUI_ErrorMgr::updateActions(const FeaturePtr& theFeature)
                                       (workshop()->operationMgr()->currentOperation());
   if (aFOperation && aFOperation->feature() == theFeature) {
     QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
-    QString anError = myWorkshop->module()->getFeatureError(theFeature);
-
+    
     ModuleBase_ModelWidget* anActiveWidget = activeWidget();
-    QString aWidgetError = myWorkshop->module()->getWidgetError(anActiveWidget);
-    if (anError.isEmpty())
-      anError = aWidgetError;
-
+    bool isApplyEnabledByActiveWidget = false;
+    if (anActiveWidget)
+      isApplyEnabledByActiveWidget = anActiveWidget->getValueState() ==
+                                     ModuleBase_ModelWidget::ModifiedInPP;
+    QString anError = "";
+    QString aWidgetError = "";
+    if (!isApplyEnabledByActiveWidget) {
+      anError = myWorkshop->module()->getFeatureError(theFeature);
+      aWidgetError = myWorkshop->module()->getWidgetError(anActiveWidget);
+      if (anError.isEmpty())
+        anError = aWidgetError;
+    }
     updateActionState(anOkAction, anError);
     updateToolTip(anActiveWidget, aWidgetError);
   }
@@ -82,6 +89,19 @@ void XGUI_ErrorMgr::updateAcceptAllAction(const FeaturePtr& theFeature)
   }
 }
 
+bool XGUI_ErrorMgr::isApplyEnabled() const
+{
+  bool isEnabled = false;
+  XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
+  ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+                                      (workshop()->operationMgr()->currentOperation());
+  if (aFOperation) {
+    QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
+    isEnabled = anOkAction && anOkAction->isEnabled();
+  }
+  return isEnabled;
+}
+
 void XGUI_ErrorMgr::updateActionState(QAction* theAction, const QString& theError)
 {
   bool anEnabled = theError.isEmpty();
index 7970f6ec00e3a05589afd73fdd7bad3914915a65..03d057c5bbda2deb004c2ed8d2e924935371fcfb 100644 (file)
@@ -44,6 +44,9 @@ public:
   /// \param theFeature a feature
   void updateAcceptAllAction(const FeaturePtr& theFeature);
 
+  /// Returns true if the apply is enabled for the current feature
+  bool isApplyEnabled() const;
+
 protected slots:
   /// Reimplemented from ModuleBase_ErrorMgr::onWidgetChanged().
   virtual void onWidgetChanged();
index 5271d1836bc395f25ddfbf314ccb4864c6742c9c..b8bc93c952ce4f3d3aa9cfbd7efa41b87a8f3502 100644 (file)
@@ -30,7 +30,7 @@
 
 XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
                                      ModuleBase_IWorkshop* theWorkshop)
-: QObject(theParent), myIsApplyEnabled(false), myWorkshop(theWorkshop)
+: QObject(theParent), myWorkshop(theWorkshop)
 {
 }
 
@@ -174,7 +174,7 @@ bool XGUI_OperationMgr::commitAllOperations()
   bool isCompositeCommitted = false;
   while (hasOperation()) {
     ModuleBase_Operation* anOperation = currentOperation();
-    if (isApplyEnabled()) {
+    if (workshop()->errorMgr()->isApplyEnabled()) {
       onCommitOperation();
     } else {
       abortOperation(anOperation);
@@ -199,28 +199,8 @@ void XGUI_OperationMgr::onValidateOperation()
     return;
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                                                           (currentOperation());
-  if(aFOperation && aFOperation->feature().get()) {
-    QString anError = myWorkshop->module()->getFeatureError(aFOperation->feature());
-    if (anError.isEmpty()) {
-      ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
-      if (aPanel) {
-        ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
-        if (anActiveWidget)
-          anError = myWorkshop->module()->getWidgetError(anActiveWidget);
-      }
-    }
-    setApplyEnabled(anError.isEmpty());
-  }
-}
-
-void XGUI_OperationMgr::setApplyEnabled(const bool theEnabled)
-{
-  myIsApplyEnabled = theEnabled;
-  ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
-                                                                          (currentOperation());
-  if (aFOperation) {
+  if(aFOperation && aFOperation->feature().get())
     workshop()->errorMgr()->updateActions(aFOperation->feature());
-  }
 }
 
 void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperation)
@@ -230,40 +210,13 @@ void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperati
     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
     if (aFOperation)
       anErrorMgr->updateAcceptAllAction(aFOperation->feature());
-    //emit nestedStateChanged(theOperation->getDescription()->operationId().toStdString(),
-    //                        theOperation->isValid());
   }
   else {
     foreach(ModuleBase_Operation* anOperation, myOperations) {
       if (anOperation)
         updateApplyOfOperations(anOperation);
-      //emit nestedStateChanged(anOperation->getDescription()->operationId().toStdString(),
-      //                        anOperation->isValid());
-    }
-  }
-}
-
-bool XGUI_OperationMgr::isApplyEnabled() const
-{
-  return myIsApplyEnabled;
-}
-
-bool XGUI_OperationMgr::isParentOperationValid() const
-{
-  bool isValid = false;
-  // the enable state of the parent operation of the nested one is defined by the rules that
-  // firstly there are nested operations and secondly the parent operation is valid
-  ModuleBase_Operation* aPrevOp = 0;
-  Operations::const_iterator anIt = myOperations.end();
-  if (anIt != myOperations.begin()) { // there are items in the operations list
-    --anIt;
-    aPrevOp = *anIt; // the last top operation, the operation which is started
-    if (anIt != myOperations.begin()) { // find the operation where the started operation is nested
-      --anIt;
-      aPrevOp = *anIt;
     }
   }
-  return aPrevOp && aPrevOp->isValid();
 }
 
 bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation)
@@ -344,7 +297,7 @@ bool XGUI_OperationMgr::canStartOperation(const QString& theId)
       else if (canStopOperation(aCurrentOp)) {
         // the started operation is granted in the parrent operation,
         // e.g. current - Line in Sketch, started Circle 
-        if (myIsApplyEnabled && aCurrentOp->isModified())
+        if (workshop()->errorMgr()->isApplyEnabled() && aCurrentOp->isModified())
           aCurrentOp->commit();
         else
           abortOperation(aCurrentOp);
index d6172b8946225cd29f414203d68ac9b4dd266ca0..e7e715128b6e7e07e20876cd28a589875a3ad2f9 100755 (executable)
@@ -98,15 +98,6 @@ Q_OBJECT
   /// \param theOperation an aborted operation
   void abortOperation(ModuleBase_Operation* theOperation);
 
-  /// Returns enable apply state 
-  /// \return theEnabled a boolean value
-  bool isApplyEnabled() const;
-
-  /// Returns valid state of the parent operation. If the current operation is the last one
-  /// it returns the valid state of the operation
-  /// \return boolean value
-  bool isParentOperationValid() const;
-
 public slots:
   /// Slot that commits the current operation.
   void onCommitOperation();
@@ -142,11 +133,6 @@ signals:
   /// Signal is emitted after the key released click.
   void keyEnterReleased();
 
- protected:
-  /// Sets apply state to the value and emit signal about this state is changed
-  /// \param theEnabled the state value
-  void setApplyEnabled(const bool theEnabled);
-
 public: // TEMPORARY, it should be protected and be performed automatically
   /// Emits nestedStateChange for operations with an information about validity of the operation
   /// \param theOperation the sent operation. If it is NULL, all operations in the stack are sent.
@@ -219,9 +205,6 @@ private:
 
   /// Current workshop
   ModuleBase_IWorkshop* myWorkshop;
-
-  /// Lock/Unlock access to Ok button in property panel
-  bool myIsApplyEnabled;
 };
 
 #endif
index 8b658c9975d5fa5734464b6af085aaa48f73e736..5f4e082fc82d8e5924a981d007fd5a2c568e4eb6 100755 (executable)
@@ -74,8 +74,6 @@ XGUI_WorkshopListener::XGUI_WorkshopListener(ModuleBase_IWorkshop* theWorkshop)
     myUpdatePrefs(false)
 {
   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
-  //connect(anOperationMgr, SIGNAL(nestedStateChanged(const std::string&, const bool)),
-  //        this, SLOT(onNestedStateChanged(const std::string&, const bool)));
 }
 
 //******************************************************
@@ -430,30 +428,6 @@ void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_O
   //}
 }
 
-/*void XGUI_WorkshopListener::onNestedStateChanged(const std::string& theFeatureId, const bool theState)
-{
-  XGUI_Workshop* aWorkshop = workshop();
-
-  //one button is used for all features, which can have nested actions, so it is obtained from
-  // the action manager
-  //bool aActionToBeUpdated = aWorkshop->isFeatureOfNested(theFeatureId);
-  if (aWorkshop->isSalomeMode()) {
-    XGUI_SalomeConnector* aSalomeConnector = aWorkshop->salomeConnector();
-    XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
-    if (aSalomeConnector->isFeatureOfNested(anActionsMgr->action(theFeatureId.c_str())))
-      aActionToBeUpdated = true;
-  } else {
-    AppElements_MainMenu* aMenuBar = aWorkshop->mainWindow()->menuObject();
-    AppElements_Command* aCommand = aMenuBar->feature(theFeatureId.c_str());
-    if (aCommand && aCommand->button()->additionalButtonWidget())
-      aActionToBeUpdated = true;
-  }
-  if (aActionToBeUpdated) {
-    QAction* anAcceptAllAction = aWorkshop->actionsMgr()->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
-    anAcceptAllAction->setEnabled(theState);
-  }
-}*/
-
 bool XGUI_WorkshopListener::event(QEvent * theEvent)
 {
   PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);