From 4df8e41bd2fdbee3bb669a84abf7b080c386a76f Mon Sep 17 00:00:00 2001 From: asl Date: Fri, 14 Aug 2015 14:33:21 +0300 Subject: [PATCH] Issue #649: selection of the "parent" feature --- src/ModuleBase/ModuleBase_ISelection.h | 2 ++ src/PartSet/PartSet_MenuMgr.cpp | 22 ++++++++++++++++++++++ src/PartSet/PartSet_MenuMgr.h | 2 ++ src/PartSet/PartSet_Module.cpp | 6 ++++++ src/XGUI/XGUI_Selection.cpp | 5 +++++ src/XGUI/XGUI_Selection.h | 2 ++ 6 files changed, 39 insertions(+) diff --git a/src/ModuleBase/ModuleBase_ISelection.h b/src/ModuleBase/ModuleBase_ISelection.h index ffe5e389f..a64335b83 100644 --- a/src/ModuleBase/ModuleBase_ISelection.h +++ b/src/ModuleBase/ModuleBase_ISelection.h @@ -60,6 +60,8 @@ class ModuleBase_ISelection */ virtual QObjectPtrList selectedObjects() const = 0; + virtual void setSelectedObjects( const QObjectPtrList& ) const = 0; + /** * Returns list of currently selected results */ diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index c5ad640cb..9b5919c20 100644 --- a/src/PartSet/PartSet_MenuMgr.cpp +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -88,6 +88,11 @@ void PartSet_MenuMgr::createActions() aAction = new QAction(QIcon(":icons/edit.png"), tr("Edit..."), this); connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onEdit(bool))); myActions["EDIT_CMD"] = aAction; + + aAction = new QAction(QIcon(), tr("Select parent feature"), this); + aAction->setCheckable(false); + connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSelectParentFeature())); + myActions["SELECT_PARENT_CMD"] = aAction; } @@ -483,3 +488,20 @@ void PartSet_MenuMgr::onEdit(bool) if (aFeature.get() != NULL) myModule->editFeature(aFeature); } + +void PartSet_MenuMgr::onSelectParentFeature() +{ + QObjectPtrList aObjects = myModule->workshop()->selection()->selectedObjects(); + if (aObjects.size() != 1) + return; + + SessionPtr aMgr = ModelAPI_Session::get(); + ResultPtr aResult = std::dynamic_pointer_cast( aObjects.first() ); + if( !aResult.get() ) + return; + + FeaturePtr aParentFeature = aResult->document()->feature( aResult ); + QObjectPtrList aSelection; + aSelection.append( aParentFeature ); + myModule->workshop()->selection()->setSelectedObjects( aSelection ); +} diff --git a/src/PartSet/PartSet_MenuMgr.h b/src/PartSet/PartSet_MenuMgr.h index b31493dcd..865bbccdc 100644 --- a/src/PartSet/PartSet_MenuMgr.h +++ b/src/PartSet/PartSet_MenuMgr.h @@ -73,6 +73,8 @@ private slots: /// A slot called on edit of feature void onEdit(bool); + void onSelectParentFeature(); + private: /// Returns true if the current operation is sketch entity create operation /// \param theValue the current auxiliary value diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 96083adb9..8541f8922 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -829,6 +829,12 @@ void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const if (hasParameter || hasFeature) theMenu->addAction(myMenuMgr->action("EDIT_CMD")); } + + ResultPtr aResult = std::dynamic_pointer_cast(aObject); + if( aResult.get() ) + { + theMenu->addAction(myMenuMgr->action("SELECT_PARENT_CMD")); + } } else { // If feature is 0 the it means that selected root object (document) if (aMgr->activeDocument() != aMgr->moduleDocument()) theMenu->addAction(myMenuMgr->action("ACTIVATE_PARTSET_CMD")); diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index cd7379944..27a3f18c2 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -165,6 +165,11 @@ QObjectPtrList XGUI_Selection::selectedObjects() const return myWorkshop->objectBrowser()->selectedObjects(); } +void XGUI_Selection::setSelectedObjects( const QObjectPtrList& theObjects ) const +{ + return myWorkshop->objectBrowser()->setObjectsSelected( theObjects ); +} + QObjectPtrList XGUI_Selection::selectedPresentations() const { QObjectPtrList aSelectedList; diff --git a/src/XGUI/XGUI_Selection.h b/src/XGUI/XGUI_Selection.h index a768c132b..5e4b672bc 100644 --- a/src/XGUI/XGUI_Selection.h +++ b/src/XGUI/XGUI_Selection.h @@ -53,6 +53,8 @@ class XGUI_EXPORT XGUI_Selection : public ModuleBase_ISelection */ virtual QObjectPtrList selectedObjects() const; + virtual void setSelectedObjects( const QObjectPtrList& ) const; + /** * Returns list of currently selected results */ -- 2.39.2