From 31d79837e11c63df254853b589acc2678fe7edd0 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 4 Mar 2015 15:08:32 +0300 Subject: [PATCH] Using the workshop "Delete" action for the sketch operation features --- src/ModuleBase/ModuleBase_IModule.h | 4 ++++ src/PartSet/PartSet_Module.cpp | 28 ++++++++++------------------ src/PartSet/PartSet_Module.h | 5 +---- src/XGUI/XGUI_Workshop.cpp | 5 ++--- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 3c3d33878..8d435b84f 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -111,6 +111,10 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// \param theObject a model object virtual bool canDisplayObject(const ObjectPtr& theObject) const; + /// Reacts to the delete action in module + /// \returns true if the action is processed + virtual bool deleteObjects() { return false; }; + public slots: /// Called on call of command corresponded to a feature void onFeatureTriggered(); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 912fdebf4..999344074 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -95,7 +95,6 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop) XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr(); connect(anOpMgr, SIGNAL(keyEnterReleased()), this, SLOT(onEnterReleased())); - connect(anOpMgr, SIGNAL(keyDeleteReleased()), this, SLOT(onDeleteObjects())); connect(anOpMgr, SIGNAL(operationActivatedByPreselection()), this, SLOT(onOperationActivatedByPreselection())); @@ -299,7 +298,6 @@ void PartSet_Module::addViewerItems(QMenu* theMenu) const XGUI_Workshop* aWorkshop = aConnector->workshop(); QAction* anAction = aWorkshop->contextMenuMgr()->action("DELETE_CMD"); theMenu->addAction(anAction); - //theMenu->addAction(action("DELETE_PARTSET_CMD")); } } bool isConstruction; @@ -403,14 +401,6 @@ void PartSet_Module::onEnterReleased() myRestartingMode = RM_EmptyFeatureUsed; } -void PartSet_Module::onDeleteObjects() -{ - ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); - if (PartSet_SketcherMgr::isSketchOperation(anOperation) || - PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) - deleteObjects(); -} - void PartSet_Module::onOperationActivatedByPreselection() { ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); @@ -492,9 +482,6 @@ void PartSet_Module::createActions() { QAction* anAction; - //anAction = new QAction(QIcon(":pictures/delete.png"), tr("Delete"), this); - //addAction("DELETE_PARTSET_CMD", anAction); - anAction = new QAction(tr("Construction"), this); anAction->setCheckable(true); addAction("CONSTRUCTION_CMD", anAction); @@ -521,20 +508,17 @@ void PartSet_Module::onAction(bool isChecked) QAction* aAction = static_cast(sender()); QString anId = aAction->data().toString(); - //if (anId == "DELETE_PARTSET_CMD") { - // deleteObjects(); - //} if (anId == "CONSTRUCTION_CMD") { mySketchMgr->setConstruction(isChecked); } } -void PartSet_Module::deleteObjects() +bool PartSet_Module::deleteObjects() { ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation); if (!isSketchOp && !PartSet_SketcherMgr::isNestedSketchOperation(anOperation)) - return; + return false; // sketch feature should be skipped, only sub-features can be removed // when sketch operation is active @@ -546,6 +530,12 @@ void PartSet_Module::deleteObjects() ModuleBase_ISelection* aSel = aConnector->selection(); QObjectPtrList aSelectedObj = aSel->selectedPresentations(); + // if there are no selected objects in the viewer, that means that the selection in another + // place cased this method. It is necessary to return the false value to understande in above + // method that delete is not processed + if (aSelectedObj.count() == 0) + return false; + XGUI_Workshop* aWorkshop = aConnector->workshop(); XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr(); if (!isSketchOp && anOpMgr->canStopOperation()) { @@ -628,4 +618,6 @@ void PartSet_Module::deleteObjects() aWorkshop->displayer()->updateViewer(); //myDisplayer->updateViewer(); aMgr->finishOperation(); + + return true; } diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 2bf2f44b0..5a4429857 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -123,9 +123,6 @@ protected slots: /// It commits the operation of it is can be committed void onOperationActivatedByPreselection(); - //! Delete features - void onDeleteObjects(); - protected: /// Register validators for this module virtual void registerValidators(); @@ -158,7 +155,7 @@ protected slots: void addAction(const QString& theId, QAction* theAction); //! Delete features - void deleteObjects(); + virtual bool deleteObjects(); private: QString myLastOperationId; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 99311b558..02fe22ef8 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1288,9 +1288,8 @@ void XGUI_Workshop::activatePart(ResultPartPtr theFeature) //************************************************************** void XGUI_Workshop::deleteObjects(const QObjectPtrList& theList) { - // the active operation should not be aborted if there is an empty list of objects - // it is possible that delete shortcut should be processed in the active operation. - if (theList.empty()) + ModuleBase_IModule* aModule = module(); + if (aModule->deleteObjects()) return; if (!isActiveOperationAborted()) -- 2.39.2