From 2a63ccc7a4ed346d43585e8a0d442b0540f72f03 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 22 Jan 2016 07:56:42 +0300 Subject: [PATCH] Issue #1223 Conflicting constraints not raised An attempt to allow opportunity of hidden sketch features delete. --- src/ModuleBase/ModuleBase_IModule.h | 4 ++ src/PartSet/PartSet_Module.cpp | 5 ++ src/PartSet/PartSet_Module.h | 4 ++ src/PartSet/PartSet_SketcherMgr.cpp | 88 ++++++++++++++++++++++++++++- src/PartSet/PartSet_SketcherMgr.h | 10 ++++ src/XGUI/XGUI_Workshop.cpp | 2 +- src/XGUI/XGUI_WorkshopListener.cpp | 10 ++++ 7 files changed, 119 insertions(+), 4 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 56f7e2bbc..599581024 100755 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -144,6 +144,10 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// \param theObject a model object virtual bool canDisplayObject(const ObjectPtr& theObject) const; + /// Make some functionality after the objects are hidden in viewer + /// \param theObjects a list of hidden objects + virtual void processHiddenObject(const std::list& theObjects) {}; + /// Returns true if selection for the object can be activate. /// By default a result or feature of the current operation can not be activated /// \param theObject a model object diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 3dd75c7b7..dc9c6ac54 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -367,6 +367,11 @@ bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const return mySketchMgr->canDisplayObject(theObject); } +void PartSet_Module::processHiddenObject(const std::list& theObjects) +{ + mySketchMgr->processHiddenObject(theObjects); +} + bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const { bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject); diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 392dfa04e..6c5a5e0b6 100755 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -137,6 +137,10 @@ public: /// \param theObject a model object virtual bool canDisplayObject(const ObjectPtr& theObject) const; + /// Make some functionality after the objects are hidden in viewer + /// \param theObjects a list of hidden objects + virtual void processHiddenObject(const std::list& theObjects); + /// Returns true if selection for the object can be activate. /// For sketch operation allow the selection activation if the operation is edit, for other /// operation uses the default result diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 053ef7238..02b1daf59 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -77,6 +77,7 @@ #include #include #include +#include //#define DEBUG_DO_NOT_BY_ENTER @@ -1160,6 +1161,84 @@ bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const return aCanDisplay; } +void PartSet_SketcherMgr::processHiddenObject(const std::list& theObjects) +{ + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (getCurrentOperation()); + if (aFOperation && myCurrentSketch.get()) { + // find results of the current operation + // these results should not be proposed to be deleted + FeaturePtr anOperationFeature = aFOperation->feature(); + std::list anOperationResultList = anOperationFeature->results(); + std::set anOperationResults; + std::list::const_iterator aRIt = anOperationResultList.begin(), + aRLast = anOperationResultList.end(); + for (; aRIt != aRLast; aRIt++) + anOperationResults.insert(*aRIt); + + std::set anObjectsToBeDeleted; + QStringList anObjectsToBeDeletedNames; + std::list::const_iterator anIt = theObjects.begin(), aLast = theObjects.end(); + for (; anIt != aLast; anIt++) { + ObjectPtr anObject = *anIt; + bool aCanErase = true; + // when the sketch operation is active, results of sketch sub-feature can not be hidden + ResultPtr aResult = std::dynamic_pointer_cast(anObject); + // the result is found between current feature results + if (anOperationResults.find(aResult) != anOperationResults.end()) + continue; + + 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; + } + } + } + if (!aCanErase) { + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) { + anObjectsToBeDeleted.insert(aFeature); + anObjectsToBeDeletedNames.append(aFeature->name().c_str()); + } + } + } + if (!anObjectsToBeDeleted.empty()) { + QString aFeatureNames = anObjectsToBeDeletedNames.join(", "); + QString aMessage = tr("The following features have incorrect presentation and \ +will be hidden: %1. Would you like to delete them?") + .arg(aFeatureNames); + int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"), + aMessage, QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Cancel); + if (anAnswer == QMessageBox::Ok) { + QObjectPtrList anObjects; + std::set::const_iterator anIt = anObjectsToBeDeleted.begin(), + aLast = anObjectsToBeDeleted.end(); + for (; anIt != aLast; anIt++) + anObjects.append(*anIt); + SessionPtr aMgr = ModelAPI_Session::get(); + DocumentPtr aDoc = aMgr->activeDocument(); + bool aIsOp = aMgr->isOperation(); + if (!aIsOp) + aMgr->startOperation(); + workshop()->deleteFeatures(anObjects); + //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED); + //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); + //Events_Loop::loop()->flush(aDeletedEvent); + //Events_Loop::loop()->flush(aRedispEvent); + + if (!aIsOp) + aMgr->finishOperation(); + } + } + } +} + bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const { bool aCanDisplay = myIsMouseOverWindow; @@ -1485,12 +1564,15 @@ void PartSet_SketcherMgr::onShowConstraintsToggle(bool theState, int theType) Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); } -XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const +XGUI_Workshop* PartSet_SketcherMgr::workshop() const { ModuleBase_IWorkshop* anIWorkshop = myModule->workshop(); XGUI_ModuleConnector* aConnector = dynamic_cast(anIWorkshop); - XGUI_Workshop* aWorkshop = aConnector->workshop(); + return aConnector->workshop(); +} - return aWorkshop->operationMgr(); +XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const +{ + return workshop()->operationMgr(); } diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 3b0a868c9..958a7e9a0 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -32,6 +32,8 @@ class ModuleBase_IViewWindow; class ModuleBase_ModelWidget; class ModuleBase_Operation; class XGUI_OperationMgr; +class XGUI_Workshop; + class QMouseEvent; /** @@ -167,6 +169,11 @@ public: /// \param theObject a model object bool canDisplayObject(const ObjectPtr& theObject) const; + /// Check the given objects either there are some results of the current sketch. If so, + /// it suggests to delete them as there are no functionality to show back hidden sketch objects + /// \param theObjects a list of hidden objects + virtual void processHiddenObject(const std::list& theObjects); + /// Returns true if the mouse is over viewer or property panel value is changed /// \return boolean result bool canDisplayCurrentCreatedFeature() const; @@ -316,6 +323,9 @@ private: const bool isToDisplay, const bool isFlushRedisplay = true); private: + /// Returns current workshop + XGUI_Workshop* workshop() const; + /// Returns operation manager XGUI_OperationMgr* operationMgr() const; private: diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 1747b7495..754778afe 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1418,7 +1418,7 @@ bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList, } QString anActionId = "DELETE_CMD"; - removeFeatures(theList, theIgnoredFeatures, anActionId); + return removeFeatures(theList, theIgnoredFeatures, anActionId); } //************************************************************** diff --git a/src/XGUI/XGUI_WorkshopListener.cpp b/src/XGUI/XGUI_WorkshopListener.cpp index c87f0aa3d..c79678fb2 100755 --- a/src/XGUI/XGUI_WorkshopListener.cpp +++ b/src/XGUI/XGUI_WorkshopListener.cpp @@ -283,6 +283,7 @@ void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr aHiddenObjects; for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) { ObjectPtr aObj = (*aIt); @@ -293,6 +294,7 @@ void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr(aObj); aHide = aRes && aRes->isConcealed(); } + #ifdef DEBUG_RESULT_COMPSOLID ResultPtr aRes = std::dynamic_pointer_cast(aObj); if (aRes.get()) { @@ -316,6 +318,9 @@ void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr