Salome HOME
Merge branch 'Dev_2.1.0' of salome:modules/shaper into Dev_2.1.0
[modules/shaper.git] / src / PartSet / PartSet_SketcherReetntrantMgr.cpp
index 5e45abfee7253fc32f55e81d05e6249d43b70d1c..d491b9a57caa522a11cc426f09870d4c39e8b535 100755 (executable)
 #include <XGUI_OperationMgr.h>
 #include <XGUI_PropertyPanel.h>
 
+#include <QToolButton>
+
 PartSet_SketcherReetntrantMgr::PartSet_SketcherReetntrantMgr(ModuleBase_IWorkshop* theWorkshop)
 : QObject(theWorkshop),
   myWorkshop(theWorkshop),
   myRestartingMode(RM_None),
   myIsFlagsBlocked(false),
-  myIsInternalEditOperation(false)
+  myIsInternalEditOperation(false),
+  myNoMoreWidgetsAttribute("")
 {
 }
 
@@ -176,23 +179,31 @@ void PartSet_SketcherReetntrantMgr::onNoMoreWidgets(const std::string& thePrevio
   if (!isActiveMgr())
     return;
 
+  // we should avoid processing of the signal about no more widgets attributes and 
+  // do this after the restart operaion is finished if it was called
+  // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
+  // if it should be called after restart
+  if (myIsFlagsBlocked) {
+    myNoMoreWidgetsAttribute = thePreviousAttributeID;
+    return;
+  }
+
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                                        (myWorkshop->currentOperation());
   if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
     return;
 
-  bool isStarted = false;
-  bool isSketchSolverError = module()->sketchMgr()->sketchSolverError();
-  if (!isSketchSolverError &&
-      aFOperation && PartSet_SketcherMgr::isNestedSketchOperation(aFOperation)) {
-    if (myRestartingMode != RM_Forbided) {
-      myRestartingMode = RM_LastFeatureUsed;
-      isStarted = startInternalEdit(thePreviousAttributeID);
+  if (aFOperation && PartSet_SketcherMgr::isNestedSketchOperation(aFOperation)) {
+    bool isStarted = false;
+    if (!module()->sketchMgr()->sketchSolverError()) {
+      if (myRestartingMode != RM_Forbided) {
+        myRestartingMode = RM_LastFeatureUsed;
+        isStarted = startInternalEdit(thePreviousAttributeID);
+      }
     }
+    if (!isStarted)
+      aFOperation->commit();
   }
-
-  if (!isStarted)
-    aFOperation->commit();
 }
 
 bool PartSet_SketcherReetntrantMgr::processEnter(const std::string& thePreviousAttributeID)
@@ -202,12 +213,18 @@ bool PartSet_SketcherReetntrantMgr::processEnter(const std::string& thePreviousA
   if (!isActiveMgr())
     return isDone;
 
+  // empty previous attribute means that the Apply/Ok button has focus and the enter
+  // should not lead to start edition mode of the previous operation
+  if (thePreviousAttributeID.empty())
+    return isDone;
+
   ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
                                                        (myWorkshop->currentOperation());
   if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
     return isDone;
 
   bool isSketchSolverError = module()->sketchMgr()->sketchSolverError();
+
   if (!isSketchSolverError) {
     myRestartingMode = RM_EmptyFeatureUsed;
     isDone = startInternalEdit(thePreviousAttributeID);
@@ -309,9 +326,18 @@ bool PartSet_SketcherReetntrantMgr::startInternalEdit(const std::string& thePrev
             aPreviousAttributeWidget = aWidgets[i];
         }
         // If the current widget is a selector, do nothing, it processes the mouse press
-        if (aPreviousAttributeWidget && !aPreviousAttributeWidget->isViewerSelector()) {
-          aPreviousAttributeWidget->focusTo();
-          aPreviousAttributeWidget->selectContent();
+        if (aPreviousAttributeWidget) {
+          if (!aPreviousAttributeWidget->isViewerSelector()) {
+            aPreviousAttributeWidget->focusTo();
+            aPreviousAttributeWidget->selectContent();
+          }
+          else {
+            // if there is no the next widget to be automatically activated, the Ok button in property
+            // panel should accept the focus(example is parallel constraint on sketch lines)
+            QToolButton* anOkBtn = aPanel->findChild<QToolButton*>(PROP_PANEL_OK);
+            if (anOkBtn)
+              anOkBtn->setFocus(Qt::TabFocusReason);
+          }
         }
       }
     }
@@ -340,11 +366,20 @@ void PartSet_SketcherReetntrantMgr::restartOperation()
     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(
                                                                   myWorkshop->currentOperation());
     if (aFOperation) {
+      myNoMoreWidgetsAttribute = "";
       myIsFlagsBlocked = true;
       aFOperation->commit();
       module()->launchOperation(aFOperation->id());
       myIsFlagsBlocked = false;
       resetFlags();
+      // we should avoid processing of the signal about no more widgets attributes and 
+      // do this after the restart operaion is finished if it was called
+      // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
+      // if it should be called after restart
+      if (!myNoMoreWidgetsAttribute.empty()) {
+        onNoMoreWidgets(myNoMoreWidgetsAttribute);
+        myNoMoreWidgetsAttribute = "";
+      }
     }
   }
 }
@@ -374,7 +409,10 @@ void PartSet_SketcherReetntrantMgr::createInternalFeature()
     QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
 
     foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
-      aWidget->setFeature(myInternalFeature, true);
+      bool isStoreValue = !aFOperation->isEditOperation() &&
+                          !aWidget->getDefaultValue().empty() &&
+                          !aWidget->isComputedDefault();
+      aWidget->setFeature(myInternalFeature, isStoreValue);
     }
     ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
                                                                                         (aWidgets);