From ace68008dc38022136ba6ed10c7be5e7c8152051 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 28 Aug 2015 21:56:24 +0300 Subject: [PATCH] Issue #851 Show only action should not hide sketch entities when the sketch operation is active. --- src/ModuleBase/ModuleBase_IModule.cpp | 5 +++++ src/ModuleBase/ModuleBase_IModule.h | 4 ++++ src/PartSet/PartSet_Module.cpp | 6 ++++++ src/PartSet/PartSet_Module.h | 5 +++++ src/PartSet/PartSet_SketcherMgr.cpp | 22 ++++++++++++++++++++++ src/PartSet/PartSet_SketcherMgr.h | 5 +++++ src/XGUI/XGUI_Workshop.cpp | 12 ++++++++---- 7 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index 7de4b0ee5..cd4375789 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -115,6 +115,11 @@ void ModuleBase_IModule::actionCreated(QAction* theFeature) connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered())); } +bool ModuleBase_IModule::canEraseObject(const ObjectPtr& theObject) const +{ + return true; +} + bool ModuleBase_IModule::canDisplayObject(const ObjectPtr& theObject) const { return true; diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 79b702e3e..e090d3882 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -130,6 +130,10 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// \return a boolean value virtual bool canCommitOperation() const; + /// Returns whether the object can be erased. The default realization returns true. + /// \param theObject a model object + virtual bool canEraseObject(const ObjectPtr& theObject) const; + /// Returns whether the object can be displayed. The default realization returns true. /// \param theObject a model object virtual bool canDisplayObject(const ObjectPtr& theObject) const; diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index ed2c71c73..c863177fb 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -363,6 +363,12 @@ bool PartSet_Module::canCommitOperation() const return mySketchMgr->canCommitOperation(); } +bool PartSet_Module::canEraseObject(const ObjectPtr& theObject) const +{ + // the sketch manager put the restriction to the objects erase + return mySketchMgr->canEraseObject(theObject); +} + bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const { // the sketch manager put the restriction to the objects display diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 9611ee62e..1fb0d3881 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -110,6 +110,11 @@ public: /// \return a boolean value virtual bool canCommitOperation() const; + /// Returns whether the object can be erased at the bounds of the active operation. + /// The sub-objects of the current operation can not be erased + /// \param theObject a model object + virtual bool canEraseObject(const ObjectPtr& theObject) const; + /// Returns whether the object can be displayed at the bounds of the active operation. /// Display only current operation results for usual operation and ask the sketcher manager /// if it is a sketch operation diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index b7a89b356..f436aa208 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -911,6 +911,28 @@ bool PartSet_SketcherMgr::canCommitOperation() const return aCanCommit; } +bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const +{ + bool aCanErase = true; + // when the sketch operation is active, results of sketch sub-feature can not be hidden + if (myCurrentSketch.get()) { + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if (aResult.get()) { + // Display sketcher objects + for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) { + + FeaturePtr aFeature = myCurrentSketch->subFeature(i); + std::list aResults = aFeature->results(); + std::list::const_iterator anIt; + for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) { + aCanErase = *anIt != aResult; + } + } + } + } + return aCanErase; +} + bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const { bool aCanDisplay = true; diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index e108ff999..cadfd32e5 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -139,6 +139,11 @@ public: /// \return a boolean value bool canCommitOperation() const; + /// Returns whether the object can be erased at the bounds of the active operation. + /// Sketch sub-entities can not be erased during the sketch operation + /// \param theObject a model object + bool canEraseObject(const ObjectPtr& theObject) const; + /// Returns whether the object can be displayed at the bounds of the active operation. /// Display only current operation results for usual operation and ask the sketcher manager /// if it is a sketch operation diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 02c06f646..ab38ca8a1 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -995,8 +995,10 @@ void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked) setDisplayMode(aObjects, XGUI_Displayer::Wireframe); else if (theId == "HIDEALL_CMD") { QObjectPtrList aList = myDisplayer->displayedObjects(); - foreach (ObjectPtr aObj, aList) - aObj->setDisplayed(false); + foreach (ObjectPtr aObj, aList) { + if (module()->canEraseObject(aObj)) + aObj->setDisplayed(false); + } Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); } } @@ -1432,8 +1434,10 @@ void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList) { // Hide all displayed objects QObjectPtrList aList = myDisplayer->displayedObjects(); - foreach (ObjectPtr aObj, aList) - aObj->setDisplayed(false); + foreach (ObjectPtr aObj, aList) { + if (module()->canEraseObject(aObj)) + aObj->setDisplayed(false); + } // Show only objects from the list foreach (ObjectPtr aObj, theList) { -- 2.39.2