From: nds Date: Thu, 9 Jul 2015 08:14:01 +0000 (+0300) Subject: 1. ExtrusionCut: Apply Sketch button(in tool bar) should be applyed only to the sketc... X-Git-Tag: V_1.3.0~63 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=600312b6ee50f49aaf513e694d3d177386b916d9;p=modules%2Fshaper.git 1. ExtrusionCut: Apply Sketch button(in tool bar) should be applyed only to the sketch. Extrusion should not be committed [XGUI_OperationMgr::commitAllOperations()]. 2. Issue #604 Creation of an unexpected line in the Sketcher a) using canUndo to check whether the sketch can be applyed b) undo/redo -> update the Apply button state also. --- diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index c04cb9c6c..15455fe1b 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -10,6 +10,9 @@ #include "ModuleBase_IWorkshop.h" #include "ModuleBase_IModule.h" +#include "ModelAPI_CompositeFeature.h" +#include "ModelAPI_Session.h" + #include #include #include @@ -141,12 +144,20 @@ bool XGUI_OperationMgr::abortAllOperations() bool XGUI_OperationMgr::commitAllOperations() { + bool isCompositeCommitted = false; while (hasOperation()) { + ModuleBase_Operation* anOperation = currentOperation(); if (isApplyEnabled()) { onCommitOperation(); } else { - currentOperation()->abort(); + anOperation->abort(); } + FeaturePtr aFeature = anOperation->feature(); + CompositeFeaturePtr aComposite = + std::dynamic_pointer_cast(aFeature); + isCompositeCommitted = aComposite.get(); + if (isCompositeCommitted) + break; } return true; } @@ -179,6 +190,24 @@ 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; + 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* anOperation = currentOperation(); @@ -248,20 +277,12 @@ void XGUI_OperationMgr::onOperationStarted() { ModuleBase_Operation* aSenderOperation = dynamic_cast(sender()); - // 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; - 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; - } - } - bool isNestedOk = (myOperations.count() >= 1) && aPrevOp->isValid(); - emit nestedStateChanged(isNestedOk); + bool aParentValid = isParentOperationValid(); + // in order to apply is enabled only if there are modifications in the model + // e.g. sketch can be applyed only if at least one nested element modification is finished + bool aCanUndo = ModelAPI_Session::get()->canUndo(); + emit nestedStateChanged(aParentValid && aCanUndo); + emit operationStarted(aSenderOperation); } @@ -274,7 +295,10 @@ void XGUI_OperationMgr::onOperationAborted() void XGUI_OperationMgr::onOperationCommitted() { ModuleBase_Operation* aSenderOperation = dynamic_cast(sender()); - emit nestedStateChanged(myOperations.count() >= 1); + // in order to apply is enabled only if there are modifications in the model + // e.g. sketch can be applyed only if at least one nested element create is finished + bool aCanUndo = ModelAPI_Session::get()->canUndo(); + emit nestedStateChanged(myOperations.count() >= 1 && aCanUndo); emit operationCommitted(aSenderOperation); } diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index 155d4ef48..80c457b2b 100644 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -95,7 +95,12 @@ Q_OBJECT /// \return theEnabled a boolean value bool isApplyEnabled() const; - public slots: + /// 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(); /// Slot that aborts the current operation. diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 6df726e2d..0f01b6230 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -659,7 +659,19 @@ void XGUI_Workshop::onUndo(int theTimes) for (int i = 0; i < theTimes; ++i) { aMgr->undo(); } - updateCommandStatus(); + updateCompositeActionState(); +} + +//****************************************************** +void XGUI_Workshop::updateCompositeActionState() +{ + // in order to apply is enabled only if there are modifications in the model + // e.g. sketch can be applyed only if at least one nested element create is finished + bool aCanUndo = ModelAPI_Session::get()->canUndo(); + bool aParentValid = operationMgr()->isParentOperationValid(); + + QAction* aAcceptAllAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll); + aAcceptAllAct->setEnabled(aParentValid && aCanUndo); } //****************************************************** diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 93feade45..cb7a51dca 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -279,6 +279,10 @@ signals: /// Rebuild data tree void onRebuild(); + // Update enable state of accept all button. It is enabled if the the parent operation is + // valid and there are modifications in sesstion(undo can be performed). + void updateCompositeActionState(); + /// Open preferences dialog box void onPreferences();