From b41cff0a399dc4d129b61e5e52f6b08e8681e5eb Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 26 May 2015 18:01:09 +0300 Subject: [PATCH] Use activation only for objects which are not result of a current operation --- src/ModuleBase/ModuleBase_IModule.cpp | 6 ++++ src/ModuleBase/ModuleBase_IModule.h | 5 ++++ src/XGUI/XGUI_Displayer.cpp | 41 +++++++++++++++------------ src/XGUI/XGUI_Displayer.h | 3 +- src/XGUI/XGUI_ModuleConnector.cpp | 16 +++++++++-- src/XGUI/XGUI_ModuleConnector.h | 2 ++ src/XGUI/XGUI_Workshop.cpp | 16 ++++++----- 7 files changed, 61 insertions(+), 28 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index 1f759feb5..28f25fd29 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -148,3 +148,9 @@ void ModuleBase_IModule::editFeature(FeaturePtr theFeature) anOperation->setFeature(theFeature); sendOperation(anOperation); } + +bool ModuleBase_IModule::canActivateSelection(const ObjectPtr& theObject) const +{ + ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); + return !(aOperation && (!aOperation->isEditOperation()) && aOperation->hasObject(theObject)); +} \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 1b3081dd9..6ae486f6c 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -117,6 +117,11 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// \param theObject a model object virtual bool canDisplayObject(const ObjectPtr& theObject) const; + /// 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 + virtual bool canActivateSelection(const ObjectPtr& theObject) const; + /// Reacts to the delete action in module /// \returns true if the action is processed virtual bool deleteObjects() { return false; }; diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index fd7e77079..1fef7d318 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -331,7 +331,7 @@ void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theMode } } -void XGUI_Displayer::activateObjects(const QIntList& theModes) +void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList) { #ifdef DEBUG_ACTIVATE qDebug(QString("activate all features: theModes: %2, myActiveSelectionModes: %3"). @@ -356,15 +356,24 @@ void XGUI_Displayer::activateObjects(const QIntList& theModes) //aContext->UseDisplayedObjects(); //myUseExternalObjects = true; + Handle(AIS_InteractiveObject) anAISIO; AIS_ListOfInteractive aPrsList; - ::displayedObjects(aContext, aPrsList); + if (theObjList.isEmpty()) + ::displayedObjects(aContext, aPrsList); + else { + foreach(ObjectPtr aObj, theObjList) { + if (myResult2AISObjectMap.contains(aObj)) + aPrsList.Append(myResult2AISObjectMap[aObj]->impl()); + } + } Handle(AIS_Trihedron) aTrihedron; AIS_ListIteratorOfListOfInteractive aLIt(aPrsList); - Handle(AIS_InteractiveObject) anAISIO; for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){ anAISIO = aLIt.Value(); - activate(anAISIO, myActiveSelectionModes); + aTrihedron = Handle(AIS_Trihedron)::DownCast(anAISIO); + if (aTrihedron.IsNull()) + activate(anAISIO, myActiveSelectionModes); } } @@ -833,26 +842,22 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, if (aTColModes.IsEmpty()) aContext->Load(theIO, -1, true); - Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO); - //Deactivate trihedron which can be activated in local selector - if (aTrihedron.IsNull()) { //aContext->Load(anAISIO, -1, true); // In order to clear active modes list - if (theModes.size() == 0) { - //aContext->Load(anAISIO, 0, true); - aContext->Activate(theIO); + if (theModes.size() == 0) { + //aContext->Load(anAISIO, 0, true); + aContext->Activate(theIO); #ifdef DEBUG_ACTIVATE - qDebug("activate in all modes"); + qDebug("activate in all modes"); #endif - } else { - foreach(int aMode, theModes) { - //aContext->Load(anAISIO, aMode, true); - if (!aModesActivatedForIO.contains(aMode)) { - aContext->Activate(theIO, aMode); + } else { + foreach(int aMode, theModes) { + //aContext->Load(anAISIO, aMode, true); + if (!aModesActivatedForIO.contains(aMode)) { + aContext->Activate(theIO, aMode); #ifdef DEBUG_ACTIVATE - qDebug(QString("activate: %1").arg(aMode).toStdString().c_str()); + qDebug(QString("activate: %1").arg(aMode).toStdString().c_str()); #endif - } } } } diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index cf35c0083..29cf7482a 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -169,7 +169,8 @@ class XGUI_EXPORT XGUI_Displayer: public QObject /// Activates in local context displayed outside of the context. /// \param theModes - modes on which it has to be activated (can be empty) - void activateObjects(const QIntList& theModes); + /// \param theObjList - list of objects which has to be activated. Can be empty. In this case all displayed objects will be used. + void activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList = QObjectPtrList()); /// Activates in local context displayed outside of the context. void deactivateObjects(); diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index 1405ba5d6..e92c772c6 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -61,6 +61,18 @@ ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const } +QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjList) const +{ + QObjectPtrList aActiveOPbjects; + ModuleBase_IModule* aModule = myWorkshop->module(); + // Activate objects only which can be activated + foreach (ObjectPtr aObj, theObjList) { + if (aModule->canActivateSelection(aObj)) + aActiveOPbjects.append(aObj); + } + return aActiveOPbjects; +} + void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes) { XGUI_Displayer* aDisp = myWorkshop->displayer(); @@ -75,7 +87,7 @@ void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes) else aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType)); } - aDisp->activateObjects(aModes); + aDisp->activateObjects(aModes, activeObjects(aDisp->displayedObjects())); //TODO: We have to open Local context because at neutral point filters don't work (bug 25340) //aDisp->addSelectionFilter(myDocumentShapeFilter); } @@ -93,7 +105,7 @@ void XGUI_ModuleConnector::deactivateSubShapesSelection() // the OCC6.9.0 release. Moreother, it is possible that ClearOutdatedSelection will be called inside // Deactivate method of AIS_InteractiveContext. In this case, we need not call it. module()->activeSelectionModes(aModes); - aDisp->activateObjects(aModes); + aDisp->activateObjects(aModes, activeObjects(aDisp->displayedObjects())); // The document limitation selection has to be only during operation //aDisp->removeSelectionFilter(myDocumentShapeFilter); //aDisp->closeLocalContexts(false); diff --git a/src/XGUI/XGUI_ModuleConnector.h b/src/XGUI/XGUI_ModuleConnector.h index d2348e101..23398a0f9 100644 --- a/src/XGUI/XGUI_ModuleConnector.h +++ b/src/XGUI/XGUI_ModuleConnector.h @@ -69,6 +69,8 @@ Q_OBJECT XGUI_Workshop* workshop() const { return myWorkshop; } private: + QObjectPtrList activeObjects(const QObjectPtrList& theObjList) const; + /// Reference to workshop XGUI_Workshop* myWorkshop; diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index dfa21b5da..646a41bfa 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -468,17 +468,19 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptrredisplay(aObj, false); - if (myOperationMgr->hasOperation()) { - ModuleBase_Operation* aOperation = myOperationMgr->currentOperation(); - if (!aOperation->isEditOperation() && - aOperation->hasObject(aObj) && myDisplayer->isActive(aObj)) + //if (myOperationMgr->hasOperation()) { + // ModuleBase_Operation* aOperation = myOperationMgr->currentOperation(); + // if (!aOperation->isEditOperation() && + // aOperation->hasObject(aObj) && myDisplayer->isActive(aObj)) + if (!myModule->canActivateSelection(aObj)) { + if (myDisplayer->isActive(aObj)) myDisplayer->deactivate(aObj); } } else { // display object if the current operation has it if (displayObject(aObj)) { - ModuleBase_Operation* aOperation = myOperationMgr->currentOperation(); - if (aOperation && aOperation->hasObject(aObj)) { - ModuleBase_Operation* aOperation = myOperationMgr->currentOperation(); + //ModuleBase_Operation* aOperation = myOperationMgr->currentOperation(); + //if (aOperation && aOperation->hasObject(aObj)) { + if (!myModule->canActivateSelection(aObj)) { #ifdef DEBUG_FEATURE_REDISPLAY QString anObjInfo = ModuleBase_Tools::objectInfo((aObj)); qDebug(QString(" display object = %1").arg(anObjInfo).toStdString().c_str()); -- 2.39.2