From 52a2aa0728f8694d5774a20bd1eeba8e5e2f8b27 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 29 Apr 2015 22:55:34 +0300 Subject: [PATCH] The selection problem with an object deactivate: Scenario: select a line, start distance constraint operation, activate a point widget, the object is not selected in the viewer, but click 'Esc', the first control is filled by this object. --- src/ModuleBase/ModuleBase_IModule.h | 4 ++++ src/PartSet/PartSet_Module.cpp | 7 +++++++ src/PartSet/PartSet_Module.h | 4 ++++ src/PartSet/PartSet_SketcherMgr.cpp | 19 ++++++++++++------- src/PartSet/PartSet_SketcherMgr.h | 4 ++++ src/XGUI/XGUI_Displayer.cpp | 19 ++++++++++++++++++- src/XGUI/XGUI_Displayer.h | 2 +- src/XGUI/XGUI_ModuleConnector.cpp | 10 ++++++++++ src/XGUI/XGUI_Workshop.cpp | 17 +++++++++++++---- 9 files changed, 73 insertions(+), 13 deletions(-) diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 7ba5cfe1e..65a5c5a5a 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -120,6 +120,10 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// \returns true if the action is processed virtual bool deleteObjects() { return false; }; + /// Returns a list of modes, where the AIS objects should be activated + /// \param theModes a list of modes + virtual void activeSelectionModes(QIntList& theModes) {}; + 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 684d94071..662e3d1bc 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -285,6 +285,13 @@ bool PartSet_Module::addViewerItems(QMenu* theMenu, const QMapaddViewerItems(theMenu, theStdActions); } +void PartSet_Module::activeSelectionModes(QIntList& theModes) +{ + theModes.clear(); + if (mySketchMgr->activeSketch().get()) + PartSet_SketcherMgr::sketchSelectionModes(theModes); +} + bool PartSet_Module::isMouseOverWindow() { return mySketchMgr->isMouseOverWindow(); diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 3120798c6..9ba109a65 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -103,6 +103,10 @@ public: /// \return true if items are added and there is no necessity to provide standard menu virtual bool addViewerItems(QMenu* theMenu, const QMap& theStdActions) const; + /// Returns a list of modes, where the AIS objects should be activated + /// \param theModes a list of modes + virtual void activeSelectionModes(QIntList& theModes); + /// Returns whether the mouse enter the viewer's window /// \return true if items are added and there is no necessity to provide standard menu bool isMouseOverWindow(); diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 5e527a881..7b942563a 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -628,6 +628,16 @@ const QStringList& PartSet_SketcherMgr::constraintsIdList() return aIds; } +void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes) +{ + theModes.clear(); + + theModes.append(SketcherPrs_Tools::Sel_Dimension_Text); + theModes.append(SketcherPrs_Tools::Sel_Dimension_Line); + theModes.append(SketcherPrs_Tools::Sel_Constraint); + theModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX)); + theModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE)); +} bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation) { @@ -1079,13 +1089,8 @@ void PartSet_SketcherMgr::activateObjectsInSketchMode(const bool isActive) XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); QIntList aModes; - if (isActive) { - aModes.append(SketcherPrs_Tools::Sel_Dimension_Text); - aModes.append(SketcherPrs_Tools::Sel_Dimension_Line); - aModes.append(SketcherPrs_Tools::Sel_Constraint); - aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX)); - aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE)); - } + if (isActive) + sketchSelectionModes(aModes); aDisplayer->activateObjects(aModes); } diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index f302a589e..f82f450f5 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -162,6 +162,10 @@ public: /// Returns list of strings which contains id's of constraints operations static const QStringList& constraintsIdList(); + /// Returns a list of modes, where the AIS objects should be activated + /// \param theModes a list of modes + static void sketchSelectionModes(QIntList& theModes); + public slots: /// Process sketch plane selected event void onPlaneSelected(const std::shared_ptr& thePln); diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index dd564aba0..486f23a50 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -47,6 +47,7 @@ const int MOUSE_SENSITIVITY_IN_PIXEL = 10; ///< defines the local context mouse //#define DEBUG_ACTIVATE //#define DEBUG_FEATURE_REDISPLAY //#define DEBUG_SELECTION_FILTERS +//#define DEBUG_USE_CLEAR_OUTDATED_SELECTION // Workaround for bug #25637 void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfInteractive& theList) @@ -272,6 +273,10 @@ void XGUI_Displayer::deactivate(ObjectPtr theObject) AISObjectPtr anObj = myResult2AISObjectMap[theObject]; Handle(AIS_InteractiveObject) anAIS = anObj->impl(); aContext->Deactivate(anAIS); +#ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION + aContext->LocalContext()->ClearOutdatedSelection(anAIS, true); + updateViewer(); +#endif } } @@ -388,6 +393,10 @@ void XGUI_Displayer::deactivateObjects() for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){ anAISIO = aLIt.Value(); aContext->Deactivate(anAISIO); +#ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION + aContext->LocalContext()->ClearOutdatedSelection(anAISIO, true); + updateViewer(); +#endif } } @@ -588,7 +597,7 @@ bool XGUI_Displayer::enableUpdateViewer(const bool isEnabled) return aWasEnabled; } -void XGUI_Displayer::updateViewer() +void XGUI_Displayer::updateViewer() const { Handle(AIS_InteractiveContext) aContext = AISContext(); if (!aContext.IsNull() && myEnableUpdateViewer) @@ -788,6 +797,7 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, aContext->ActivatedModes(theIO, aTColModes); TColStd_ListIteratorOfListOfInteger itr( aTColModes ); QIntList aModesActivatedForIO; + //bool isDeactivated = false; for (; itr.More(); itr.Next() ) { Standard_Integer aMode = itr.Value(); if (!theModes.contains(aMode)) { @@ -795,6 +805,7 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, qDebug(QString("deactivate: %1").arg(aMode).toStdString().c_str()); #endif aContext->Deactivate(theIO, aMode); + //isDeactivated = true; } else { aModesActivatedForIO.append(aMode); @@ -803,6 +814,12 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, #endif } } +#ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION + if (isDeactivated) { + aContext->LocalContext()->ClearOutdatedSelection(theIO, true); + updateViewer(); + } +#endif // loading the interactive object allowing the decomposition if (aTColModes.IsEmpty()) aContext->Load(theIO, -1, true); diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 89f693d52..5ea7f0713 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -126,7 +126,7 @@ class XGUI_EXPORT XGUI_Displayer: public QObject bool enableUpdateViewer(const bool isEnabled); /// Updates the viewer - void updateViewer(); + void updateViewer() const; /// Searches the interactive object by feature /// \param theObject the object or presentable feature diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index d3a057beb..b83edb4c8 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -13,6 +13,8 @@ #include "XGUI_Displayer.h" #include "XGUI_PropertyPanel.h" +#include + #include @@ -83,6 +85,14 @@ void XGUI_ModuleConnector::deactivateSubShapesSelection() XGUI_Displayer* aDisp = myWorkshop->displayer(); // Clear selection modes QIntList aModes; + // TODO: check on OCC6.9.0 + // the module current active modes should not be deactivated in order to save the objects selected + // the deactivate object in the mode of selection leads to the object is deselected in the viewer. + // But, in OCC6.8.0 this deselection does not happened automatically. It is necessary to call + // ClearOutdatedSelection, but this method has an error in the realization, which should be fixed in + // 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); // The document limitation selection has to be only during operation //aDisp->removeSelectionFilter(myDocumentShapeFilter); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index b32a80bbc..387594ec0 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -675,11 +675,20 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation) //myDisplayer->activateObjects(aModes); myModule->operationStopped(theOperation); - if (myOperationMgr->operationsCount() == 0) { + // if the operation is nested, do not deactivate objects + //if (myOperationMgr->operationsCount() == 0) { // Activate selection mode for all objects - QIntList aModes; - myDisplayer->activateObjects(aModes); - } + QIntList aModes; + // TODO: check on OCC_6.9.0 + // the module current active modes should not be deactivated in order to save the objects selected + // the deactivate object in the mode of selection leads to the object is deselected in the viewer. + // But, in OCC_6.8.0 this deselection does not happened automatically. It is necessary to call + // ClearOutdatedSelection, but this method has an error in the realization, which should be fixed in + // the OCC_6.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); + myDisplayer->activateObjects(aModes); + //} } -- 2.39.2