From 71ca600955b5c93f45e6657fd0d6342596ee1755 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 24 Jun 2016 09:41:36 +0300 Subject: [PATCH] 1. Accept All to be enabled when 1st sketch feature is reentrant(feature in the model is still invalid because commit has not happened) 2. Selection should be cleared only if the operation is stopped but it is not a reentrant operation because on restart the previous selected object is used as a preselection for the new created object. --- src/ModuleBase/ModuleBase_IModule.h | 5 ++++ src/PartSet/PartSet_Module.cpp | 10 +++++++ src/PartSet/PartSet_Module.h | 5 ++++ src/PartSet/PartSet_SketcherMgr.cpp | 30 ++++++++++++++++++- src/PartSet/PartSet_SketcherReetntrantMgr.cpp | 19 ++++++++++-- src/PartSet/PartSet_SketcherReetntrantMgr.h | 7 +++++ src/XGUI/XGUI_ContextMenuMgr.cpp | 2 +- src/XGUI/XGUI_ErrorMgr.cpp | 15 ++++++---- 8 files changed, 84 insertions(+), 9 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 78f48a39f..ad8132e4a 100755 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -266,6 +266,11 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// \param theStdActions - a map of standard actions virtual void updateViewerMenu(const QMap& theStdActions) {} + /// Returns true if the action should be always enabled + /// \param theActionId an action index: Accept or Accept All + /// \return boolean value + virtual bool isActionEnableStateFixed(const int theActionId) const { return false; } + //! Returns the feature error if the current state of the feature in the module is not correct //! If the feature is correct, it returns an empty value //! \return string value diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 1b182cdf3..5b858673c 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -70,6 +70,7 @@ #include #include #include +#include #include #include @@ -503,6 +504,15 @@ void PartSet_Module::updateViewerMenu(const QMap& theStdActio myMenuMgr->updateViewerMenu(theStdActions); } +bool PartSet_Module::isActionEnableStateFixed(const int theActionId) const +{ + bool isEnabledFixed = false; + if (theActionId == XGUI_ActionsMgr::AcceptAll && + mySketchReentrantMgr->isInternalEditStarted()) + isEnabledFixed = true; + return isEnabledFixed; +} + QString PartSet_Module::getFeatureError(const FeaturePtr& theFeature) { QString anError = ModuleBase_IModule::getFeatureError(theFeature); diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index c71187fcb..ada062897 100755 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -277,6 +277,11 @@ public: /// \param theStdActions - a map of standard actions virtual void updateViewerMenu(const QMap& theStdActions); + /// Returns true if the action should be always enabled + /// \param theActionId an action index: Accept or Accept All + /// \return boolean value + virtual bool isActionEnableStateFixed(const int theActionId) const; + //! Returns the feature error if the current state of the feature in the module is not correct //! If the feature is correct, it returns an empty value //! \return string value diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index b95786c36..6059ab187 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -82,10 +82,14 @@ #include #include +#include +#include + #include #include #include #include +#include //#define DEBUG_DO_NOT_BY_ENTER @@ -870,6 +874,28 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) } myCurrentSketch->setDisplayed(false); + // Remove invalid sketch entities + /* + std::set anInvalidFeatures; + ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators(); + for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) { + FeaturePtr aFeature = myCurrentSketch->subFeature(i); + if (aFeature.get()) { + if (!aFactory->validate(aFeature)) + anInvalidFeatures.insert(aFeature); + } + } + std::map > aReferences; + ModelAPI_Tools::findAllReferences(anInvalidFeatures, aReferences, false); + std::set aFeatureRefsToDelete; + if (ModuleBase_Tools::askToDelete(anInvalidFeatures, aReferences, aConnector->desktop(), aFeatureRefsToDelete)) { + if (!aFeatureRefsToDelete.empty()) + anInvalidFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end()); + bool aDone = ModelAPI_Tools::removeFeatures(anInvalidFeatures, false); + } + else + return; + */ // Display sketcher objects for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) { FeaturePtr aFeature = myCurrentSketch->subFeature(i); @@ -996,7 +1022,9 @@ void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation) } /// improvement to deselect automatically all eventual selected objects, when // returning to the neutral point of the Sketcher - workshop()->selector()->clearSelection(); + // if the operation is restarted, the previous selection is used to initialize started operation + if (!myModule->sketchReentranceMgr()->isInternalEditStarted()) + workshop()->selector()->clearSelection(); } void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation) diff --git a/src/PartSet/PartSet_SketcherReetntrantMgr.cpp b/src/PartSet/PartSet_SketcherReetntrantMgr.cpp index eb0432ff4..7f92c9646 100755 --- a/src/PartSet/PartSet_SketcherReetntrantMgr.cpp +++ b/src/PartSet/PartSet_SketcherReetntrantMgr.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -84,6 +85,7 @@ void PartSet_SketcherReetntrantMgr::updateInternalEditActiveState() //workshop()->operationMgr()->updateApplyOfOperations(); beforeStopInternalEdit(); myIsInternalEditOperation = false; + updateAcceptAllAction(); } } } @@ -341,6 +343,11 @@ bool PartSet_SketcherReetntrantMgr::canBeCommittedByPreselection() return !isActiveMgr() || myRestartingMode == RM_None; } +bool PartSet_SketcherReetntrantMgr::isInternalEditStarted() const +{ + return myIsInternalEditOperation; +} + bool PartSet_SketcherReetntrantMgr::isActiveMgr() const { ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation(); @@ -372,11 +379,11 @@ bool PartSet_SketcherReetntrantMgr::startInternalEdit(const std::string& thePrev if (aFOperation && PartSet_SketcherMgr::isNestedSketchOperation(aFOperation)) { aFOperation->setEditOperation(true/*, false*/); - workshop()->operationMgr()->updateApplyOfOperations(); - createInternalFeature(); myIsInternalEditOperation = true; + updateAcceptAllAction(); + isDone = true; connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped())); connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped())); @@ -537,6 +544,7 @@ void PartSet_SketcherReetntrantMgr::resetFlags() { if (!myIsFlagsBlocked) { myIsInternalEditOperation = false; + updateAcceptAllAction(); myRestartingMode = RM_None; } } @@ -578,6 +586,13 @@ bool PartSet_SketcherReetntrantMgr::isTangentArc(ModuleBase_Operation* theOperat return aTangentArc; } +void PartSet_SketcherReetntrantMgr::updateAcceptAllAction() +{ + CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch(); + if (aSketch.get()) + workshop()->errorMgr()->updateAcceptAllAction(aSketch); +} + XGUI_Workshop* PartSet_SketcherReetntrantMgr::workshop() const { XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); diff --git a/src/PartSet/PartSet_SketcherReetntrantMgr.h b/src/PartSet/PartSet_SketcherReetntrantMgr.h index 2c9a8a431..74e8bd92b 100755 --- a/src/PartSet/PartSet_SketcherReetntrantMgr.h +++ b/src/PartSet/PartSet_SketcherReetntrantMgr.h @@ -97,6 +97,10 @@ public: /// Returns false if the reentrant mode of the operation is not empty. bool canBeCommittedByPreselection(); + /// returns true if an internal edit operation is started + /// \return boolean value + bool isInternalEditStarted() const; + private slots: /// SLOT, that is called by a widget activating in the property panel /// If the 'internal' edit operation is started, it activates the first widget selection @@ -152,6 +156,9 @@ private: static bool isTangentArc(ModuleBase_Operation* theOperation); + /// Accept All action is enabled if an internal edit is started. It updates the state of the button + void updateAcceptAllAction(); + /// Returns the workshop XGUI_Workshop* workshop() const; diff --git a/src/XGUI/XGUI_ContextMenuMgr.cpp b/src/XGUI/XGUI_ContextMenuMgr.cpp index 178fc3f9d..d7a7d1579 100644 --- a/src/XGUI/XGUI_ContextMenuMgr.cpp +++ b/src/XGUI/XGUI_ContextMenuMgr.cpp @@ -132,7 +132,7 @@ void XGUI_ContextMenuMgr::createActions() addAction("SELECT_FACE_CMD", aAction); //mySelectActions->addAction(aAction); - aAction = ModuleBase_Tools::createAction(QIcon(":pictures/result.png"), tr("Result"), aDesktop, + aAction = ModuleBase_Tools::createAction(QIcon(":pictures/result.png"), tr("Results"), aDesktop, this, SLOT(onResultSelection(bool))); aAction->setCheckable(true); addAction("SELECT_RESULT_CMD", aAction); diff --git a/src/XGUI/XGUI_ErrorMgr.cpp b/src/XGUI/XGUI_ErrorMgr.cpp index b2a1a87f9..317babf1e 100644 --- a/src/XGUI/XGUI_ErrorMgr.cpp +++ b/src/XGUI/XGUI_ErrorMgr.cpp @@ -94,11 +94,16 @@ void XGUI_ErrorMgr::updateAcceptAllAction(const FeaturePtr& theFeature) if (myAcceptAllToolTip.isEmpty() && myAcceptToolTip.isEmpty()) storeInitialActionValues(); - QString anError = myWorkshop->module()->getFeatureError(theFeature); - if (anError.isEmpty()) { - ModuleBase_ModelWidget* anActiveWidget = activeWidget(); - if (anActiveWidget) - anError = anActiveWidget->getError(); + QString anError = ""; + /// to allow the module have the button always enabled + bool isActionStateEnabled = myWorkshop->module()->isActionEnableStateFixed(XGUI_ActionsMgr::AcceptAll); + if (!isActionStateEnabled) { + anError = myWorkshop->module()->getFeatureError(theFeature); + if (anError.isEmpty()) { + ModuleBase_ModelWidget* anActiveWidget = activeWidget(); + if (anActiveWidget) + anError = anActiveWidget->getError(); + } } XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr(); if (workshop()->isFeatureOfNested(theFeature)) { -- 2.39.2