From: nds Date: Tue, 9 Jun 2015 11:36:42 +0000 (+0300) Subject: Minimization of activate/deactivate calls. X-Git-Tag: V_1.3.0~264 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=179d6f9656ac229aa724f98742bf3e0f07f23e0f;p=modules%2Fshaper.git Minimization of activate/deactivate calls. using ClearOutdatedSelection() because there was a porting to OCCT/SALOME --- diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index 28f25fd29..5aba16c4c 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -152,5 +152,5 @@ void ModuleBase_IModule::editFeature(FeaturePtr theFeature) bool ModuleBase_IModule::canActivateSelection(const ObjectPtr& theObject) const { ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); - return !(aOperation && (!aOperation->isEditOperation()) && aOperation->hasObject(theObject)); + return !aOperation || !aOperation->hasObject(theObject); } \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_IWorkshop.h b/src/ModuleBase/ModuleBase_IWorkshop.h index 229b6e2e3..a4f4afc28 100644 --- a/src/ModuleBase/ModuleBase_IWorkshop.h +++ b/src/ModuleBase/ModuleBase_IWorkshop.h @@ -46,6 +46,9 @@ Q_OBJECT /// Types has to be defined according to TopAbs_ShapeEnum virtual void activateSubShapesSelection(const QIntList& theTypes) = 0; + /// Activate objects in the module selection modes(opens local context) + virtual void activateModuleSelectionModes() = 0; + /// Deactivate sub-shapes selection (closes local context) virtual void deactivateSubShapesSelection() = 0; diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index 7bf94af85..ac6f0ef92 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -86,8 +86,7 @@ Q_OBJECT /// The methiod called when widget is deactivated virtual void deactivate(); - public slots: - +protected: /// Activate or deactivate selection void activateSelection(bool toActivate); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 30649eafe..ce0555969 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -298,6 +298,20 @@ bool PartSet_Module::canDisplayObject(const ObjectPtr& theObject) const return mySketchMgr->canDisplayObject(theObject); } +bool PartSet_Module::canActivateSelection(const ObjectPtr& theObject) const +{ + bool aCanActivate = ModuleBase_IModule::canActivateSelection(theObject); + + ModuleBase_Operation* anOperation = myWorkshop->currentOperation(); + bool isSketchOp = PartSet_SketcherMgr::isSketchOperation(anOperation), + isNestedOp = PartSet_SketcherMgr::isNestedSketchOperation(anOperation); + if (isSketchOp || isNestedOp) { + // in active sketch operation it is possible to activate operation object in selection + // in the edit operation, e.g. points of the line can be moved when the line is edited + aCanActivate = aCanActivate || anOperation->isEditOperation(); + } + return aCanActivate; +} bool PartSet_Module::addViewerMenu(QMenu* theMenu, const QMap& theStdActions) const { diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 2d1786d49..e4388e0bb 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -101,6 +101,12 @@ public: /// \param theObject a model object virtual bool canDisplayObject(const ObjectPtr& theObject) const; + /// 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 + /// \param theObject a model object + virtual bool canActivateSelection(const ObjectPtr& theObject) const; + /// Add menu atems for object browser into the given menu /// \param theMenu a popup menu to be shown in the object browser virtual void addObjectBrowserMenu(QMenu* theMenu) const; diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 10092d41e..a4c9cf1c8 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -596,10 +596,6 @@ void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent void PartSet_SketcherMgr::launchEditing() { - // there should be activate the sketch selection mode because the edit can happens - // by any sketch entity or consttant selected - activateObjectsInSketchMode(true); - if (!myCurrentSelection.empty()) { FeaturePtr aFeature = myCurrentSelection.begin().key(); std::shared_ptr aSPFeature = @@ -608,7 +604,6 @@ void PartSet_SketcherMgr::launchEditing() myModule->editFeature(aSPFeature); } } - } @@ -655,8 +650,8 @@ void PartSet_SketcherMgr::sketchSelectionModes(QIntList& theModes) 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)); + theModes.append(TopAbs_VERTEX); + theModes.append(TopAbs_EDGE); } bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation) @@ -728,8 +723,9 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) } Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); // all sketch objects should be activated in the sketch selection modes by edit operation start + // in case of creation operation, there is an active widget, which activates own selection mode if (theOperation->isEditOperation()) - activateObjectsInSketchMode(true); + aConnector->activateModuleSelectionModes(); } void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) @@ -739,10 +735,6 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) #ifdef DEBUG_MOUSE_OVER_WINDOW_FLAGS qDebug(QString("stopSketch: %1").arg(mouseOverWindowFlagsInfo()).toStdString().c_str()); #endif - // the objects activated in the sketch should be deactivated in order to do not have the specific - // sketch selection mode activated on objects in neutral point of the application(no started operation) - activateObjectsInSketchMode(false); - XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); DataPtr aData = myCurrentSketch->data(); @@ -760,8 +752,8 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) if (!aObjData->isValid()) aObj->setDisplayed(false); } - return; } + else { // Hide all sketcher sub-Objects for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) { FeaturePtr aFeature = myCurrentSketch->subFeature(i); @@ -783,6 +775,9 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) myCurrentSketch = CompositeFeaturePtr(); myModule->workshop()->viewer()->removeSelectionFilter(myPlaneFilter); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); + } + // restore the module selection modes, which were changed on startSketch + aConnector->activateModuleSelectionModes(); } void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation) @@ -799,10 +794,6 @@ void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp) connectToPropertyPanel(false); myIsPropertyPanelValueChanged = false; myIsMouseOverViewProcessed = true; - - // the sketch objects selection should be activated in order to select any sketch - // object - activateObjectsInSketchMode(true); } void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation) @@ -924,11 +915,6 @@ bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr& thePln) { myPlaneFilter->setPlane(thePln->impl()); - - // after the plane is selected in the sketch, the sketch selection should be activated - // it can not be performed in the sketch label widget because, we don't need to switch off - // the selection by any label deactivation, but need to switch it off by stop the sketch - activateObjectsInSketchMode(true); } void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature, @@ -1123,18 +1109,6 @@ void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation, Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); } -void PartSet_SketcherMgr::activateObjectsInSketchMode(const bool isActive) -{ - ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); - XGUI_ModuleConnector* aConnector = dynamic_cast(aWorkshop); - XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); - - QIntList aModes; - if (isActive) - sketchSelectionModes(aModes); - aDisplayer->activateObjects(aModes); -} - void PartSet_SketcherMgr::storeSelection(const bool theHighlightedOnly) { ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 2300f5c7b..973924a3e 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -262,12 +262,6 @@ private: /// \param isToDisplay a flag about the display or erase the feature void visualizeFeature(ModuleBase_Operation* theOperation, const bool isToDisplay, const bool isFlushRedisplay = true); - - /// Activates all visualized objects in the following selection modes: Dimension_Text/Line/Constraint, - /// Shape Edge and Vertex. If the active flag is empty, it deactivates all modes - /// \param isActive the flag whether the modes should be activated or deactivated - void activateObjectsInSketchMode(const bool isActive); - private: /// Gives a debug information about internal flags myIsMouseOverWindow and myIsPropertyPanelValueChanged /// \return a string value diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 2ce6f152e..0b4b6b946 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,6 @@ #include #include -//#include #include #include #include @@ -64,10 +64,6 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, myLabel->setToolTip(""); myLabel->setIndent(5); - //mySelectionTimer = new QTimer(this); - //connect(mySelectionTimer, SIGNAL(timeout()), SLOT(setSketchingMode())); - //mySelectionTimer->setSingleShot(true); - QVBoxLayout* aLayout = new QVBoxLayout(this); ModuleBase_Tools::zeroMargins(aLayout); aLayout->addWidget(myLabel); @@ -152,7 +148,10 @@ void PartSet_WidgetSketchLabel::onSelectionChanged() //XGUI_Displayer* aDisp = myWorkshop->displayer(); //aDisp->closeLocalContexts(); emit planeSelected(plane()); - //setSketchingMode(); + // after the plane is selected in the sketch, the sketch selection should be activated + // it can not be performed in the sketch label widget because, we don't need to switch off + // the selection by any label deactivation, but need to switch it off by stop the sketch + activateSelection(true); // 8. Update sketcher actions XGUI_ActionsMgr* anActMgr = myWorkshop->actionsMgr(); @@ -234,8 +233,10 @@ bool PartSet_WidgetSketchLabel::setSelectionCustom(const ModuleBase_ViewerPrs& t void PartSet_WidgetSketchLabel::activateCustom() { std::shared_ptr aPlane = plane(); - if (aPlane.get()) + if (aPlane.get()) { + activateSelection(true); return; + } bool aBodyIsVisualized = false; XGUI_Displayer* aDisp = myWorkshop->displayer(); @@ -253,9 +254,7 @@ void PartSet_WidgetSketchLabel::activateCustom() // We have to select a plane before any operation showPreviewPlanes(); } - QIntList aModes; - aModes << TopAbs_FACE; - aDisp->activateObjects(aModes); + activateSelection(true); myLabel->setText(myText); myLabel->setToolTip(myTooltip); @@ -268,14 +267,29 @@ void PartSet_WidgetSketchLabel::activateCustom() void PartSet_WidgetSketchLabel::deactivate() { - // Do not set selection mode if the widget was activated for a small moment - //mySelectionTimer->stop(); - //XGUI_Displayer* aDisp = myWorkshop->displayer(); - //aDisp->closeLocalContexts(); erasePreviewPlanes(); + activateSelection(false); + activateFilters(myWorkshop->module()->workshop(), false); } +void PartSet_WidgetSketchLabel::activateSelection(bool toActivate) +{ + if (toActivate) { + QIntList aModes; + std::shared_ptr aPlane = plane(); + if (aPlane.get()) { + myWorkshop->moduleConnector()->module()->activeSelectionModes(aModes); + } + else { + aModes << TopAbs_FACE; + } + myWorkshop->moduleConnector()->activateSubShapesSelection(aModes); + } else { + myWorkshop->moduleConnector()->deactivateSubShapesSelection(); + } +} + void PartSet_WidgetSketchLabel::erasePreviewPlanes() { if (myPreviewDisplayed) { @@ -380,26 +394,6 @@ std::shared_ptr PartSet_WidgetSketchLabel::setSketchPlane(const Top return aDir; } - -/*void PartSet_WidgetSketchLabel::setSketchingMode() -{ - XGUI_Displayer* aDisp = myWorkshop->displayer(); - // Clear standard selection modes if they are defined - //aDisp->activateObjects(aModes); - //aDisp->openLocalContext(); - - // Get default selection modes - - QIntList aModes; - 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)); - - aDisp->activateObjects(aModes); -}*/ - void PartSet_WidgetSketchLabel::showConstraints(bool theOn) { myShowConstraints->setChecked(theOn); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 6a39f0489..0dc7c07f6 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -19,7 +19,6 @@ #include class QLabel; -//class QTimer; class XGUI_OperationMgr; class XGUI_Workshop; class QCheckBox; @@ -117,13 +116,14 @@ protected: /// The methiod called when widget is activated virtual void activateCustom(); + protected: + /// Activate or deactivate selection + void activateSelection(bool toActivate); + private slots: /// Slot on change selection void onSelectionChanged(); - /// Set sketch specific mode of selection - //void setSketchingMode(); - private: /// Create preview of planes for sketch plane selection /// \param theOrigin an origin of the plane @@ -155,8 +155,6 @@ protected: AISObjectPtr myXYPlane; bool myPreviewDisplayed; - //QTimer* mySelectionTimer; - QCheckBox* myShowConstraints; }; diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 19da29c51..d76bf6d3f 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -46,11 +46,16 @@ const int MOUSE_SENSITIVITY_IN_PIXEL = 10; ///< defines the local context mouse selection sensitivity +#define DEBUG_CRASH_RESTORE_SELECTION + +//#define DEBUG_ACTIVATE_OBJECTS +//#define DEBUG_DEACTIVATE +//#define DEBUG_ACTIVATE_AIS +//#define DEBUG_DEACTIVATE_AIS + //#define DEBUG_DISPLAY -//#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) @@ -74,6 +79,15 @@ void displayedObjects(const Handle(AIS_InteractiveContext)& theAIS, AIS_ListOfIn } } +QString qIntListInfo(const QIntList& theValues, const QString& theSeparator = QString(", ")) +{ + QStringList anInfo; + QIntList::const_iterator anIt = theValues.begin(), aLast = theValues.end(); + for (; anIt != aLast; anIt++) { + anInfo.append(QString::number(*anIt)); + } + return anInfo.join(theSeparator); +} XGUI_Displayer::XGUI_Displayer(XGUI_Workshop* theWorkshop) : myWorkshop(theWorkshop) @@ -91,10 +105,10 @@ bool XGUI_Displayer::isVisible(ObjectPtr theObject) const return myResult2AISObjectMap.contains(theObject); } -void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer) +void XGUI_Displayer::display(ObjectPtr theObject, bool theUpdateViewer) { if (isVisible(theObject)) { - redisplay(theObject, isUpdateViewer); + redisplay(theObject, theUpdateViewer); } else { AISObjectPtr anAIS; @@ -115,7 +129,7 @@ void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer) } } if (anAIS) - display(theObject, anAIS, isShading, isUpdateViewer); + display(theObject, anAIS, isShading, theUpdateViewer); } } @@ -139,7 +153,7 @@ bool canBeShaded(Handle(AIS_InteractiveObject) theAIS) } void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS, - bool isShading, bool isUpdateViewer) + bool isShading, bool theUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); if (aContext.IsNull()) @@ -158,13 +172,13 @@ void XGUI_Displayer::display(ObjectPtr theObject, AISObjectPtr theAIS, aContext->Display(anAISIO, aDispMode, 0, false, true, AIS_DS_Displayed); emit objectDisplayed(theObject, theAIS); - activate(anAISIO, myActiveSelectionModes); + activate(anAISIO, myActiveSelectionModes, theUpdateViewer); } - if (isUpdateViewer) + if (theUpdateViewer) updateViewer(); } -void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer) +void XGUI_Displayer::erase(ObjectPtr theObject, const bool theUpdateViewer) { if (!isVisible(theObject)) return; @@ -177,13 +191,13 @@ void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer) Handle(AIS_InteractiveObject) anAIS = anObject->impl(); if (!anAIS.IsNull()) { emit beforeObjectErase(theObject, anObject); - aContext->Remove(anAIS, isUpdateViewer); + aContext->Remove(anAIS, theUpdateViewer); } } myResult2AISObjectMap.remove(theObject); } -void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer) +void XGUI_Displayer::redisplay(ObjectPtr theObject, bool theUpdateViewer) { if (!isVisible(theObject)) return; @@ -195,7 +209,7 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer) if (aPrs) { AISObjectPtr aAIS_Obj = aPrs->getAISObject(aAISObj); if (!aAIS_Obj) { - erase(theObject, isUpdateViewer); + erase(theObject, theUpdateViewer); return; } if (aAIS_Obj != aAISObj) { @@ -239,14 +253,21 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer) #ifdef DEBUG_FEATURE_REDISPLAY qDebug(" Redisplay happens"); #endif - if (isUpdateViewer) + if (theUpdateViewer) updateViewer(); } } } -void XGUI_Displayer::deactivate(ObjectPtr theObject) +void XGUI_Displayer::deactivate(ObjectPtr theObject, const bool theUpdateViewer) { +#ifdef DEBUG_DEACTIVATE + QString anInfoStr = ModuleBase_Tools::objectInfo(theObject); + qDebug(QString("deactivate: myActiveSelectionModes[%1]: %2, objects = "). + arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)). + arg(anInfoStr). + toStdString().c_str()); +#endif if (isVisible(theObject)) { Handle(AIS_InteractiveContext) aContext = AISContext(); if (aContext.IsNull()) @@ -254,11 +275,12 @@ 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 + + deactivateAIS(anAIS); + // the selection from the previous activation modes should be cleared manually (#26172) aContext->LocalContext()->ClearOutdatedSelection(anAIS, true); - updateViewer(); -#endif + if (theUpdateViewer) + updateViewer(); } } @@ -284,17 +306,35 @@ void XGUI_Displayer::getModesOfActivation(ObjectPtr theObject, QIntList& theMode } } -void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList) +void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList, + const bool theUpdateViewer) { -#ifdef DEBUG_ACTIVATE - qDebug(QString("activate all features: theModes: %2, myActiveSelectionModes: %3"). - arg(theModes.size()). - arg(myActiveSelectionModes.size()). + // Convert shape types to selection types + QIntList aModes; + foreach(int aType, theModes) { + if (aType > TopAbs_SHAPE) + aModes.append(aType); + else + aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType)); + } + +#ifdef DEBUG_ACTIVATE_OBJECTS + QStringList anInfo; + QObjectPtrList::const_iterator anIt = theObjList.begin(), aLast = theObjList.end(); + for (; anIt != aLast; ++anIt) { + anInfo.append(ModuleBase_Tools::objectInfo((*anIt))); + } + QString anInfoStr = anInfo.join(", "); + + qDebug(QString("activateObjects: aModes[%1] = %2, myActiveSelectionModes[%3] = %4, objects = %5"). + arg(aModes.size()).arg(qIntListInfo(aModes)). + arg(myActiveSelectionModes.size()).arg(qIntListInfo(myActiveSelectionModes)). + arg(anInfoStr). toStdString().c_str()); #endif // In order to avoid doblications of selection modes QIntList aNewModes; - foreach (int aMode, theModes) { + foreach (int aMode, aModes) { if (!aNewModes.contains(aMode)) aNewModes.append(aMode); } @@ -306,21 +346,13 @@ void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrL if (!aContext->HasOpenedContext()) return; - // we need to block the sort of the viewer selector during deactivate/activate because - // it takes a lot of time if there are a many objects are processed. It can be performed - // manualy after the activation is peformed - //Handle(StdSelect_ViewerSelector3d) aSelector = aContext->LocalContext()->MainSelector(); - //bool isUpdateSortPossible = !aSelector.IsNull() && aSelector->IsUpdateSortPossible(); - //if (!aSelector.IsNull()) - // aSelector->SetUpdateSortPossible(false); - //aContext->UseDisplayedObjects(); //myUseExternalObjects = true; Handle(AIS_InteractiveObject) anAISIO; AIS_ListOfInteractive aPrsList; if (theObjList.isEmpty()) - ::displayedObjects(aContext, aPrsList); + return; else { foreach(ObjectPtr aObj, theObjList) { if (myResult2AISObjectMap.contains(aObj)) @@ -331,38 +363,7 @@ void XGUI_Displayer::activateObjects(const QIntList& theModes, const QObjectPtrL AIS_ListIteratorOfListOfInteractive aLIt(aPrsList); for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()){ anAISIO = aLIt.Value(); - activate(anAISIO, myActiveSelectionModes); - } - // restore the sorting flag and perform the sort of selection - //if (!aSelector.IsNull()) { - // aSelector->SetUpdateSortPossible(isUpdateSortPossible); - // aSelector->UpdateSort(); - //} -} - - -void XGUI_Displayer::deactivateObjects() -{ - myActiveSelectionModes.clear(); - Handle(AIS_InteractiveContext) aContext = AISContext(); - // Open local context if there is no one - if (!aContext->HasOpenedContext()) - return; - - //aContext->NotUseDisplayedObjects(); - AIS_ListOfInteractive aPrsList; - ::displayedObjects(aContext, aPrsList); - - AIS_ListIteratorOfListOfInteractive aLIt; - //Handle(AIS_Trihedron) aTrihedron; - Handle(AIS_InteractiveObject) anAISIO; - 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 + activate(anAISIO, myActiveSelectionModes, theUpdateViewer); } } @@ -381,8 +382,7 @@ bool XGUI_Displayer::isActive(ObjectPtr theObject) const aContext->ActivatedModes(anAIS, aModes); return aModes.Extent() > 0; } - -void XGUI_Displayer::setSelected(const QList& theValues, bool isUpdateViewer) +void XGUI_Displayer::setSelected(const QList& theValues, bool theUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); if (aContext.IsNull()) @@ -390,11 +390,13 @@ void XGUI_Displayer::setSelected(const QList& theValues, if (aContext->HasOpenedContext()) { aContext->UnhilightSelected(); aContext->ClearSelected(); - //if (aSelected.size() > 0) { foreach (ModuleBase_ViewerPrs aPrs, theValues) { const TopoDS_Shape& aShape = aPrs.shape(); if (!aShape.IsNull()) { +#ifdef DEBUG_CRASH_RESTORE_SELECTION +#else aContext->AddOrRemoveSelected(aShape, false); +#endif } else { ObjectPtr anObject = aPrs.object(); ResultPtr aResult = std::dynamic_pointer_cast(anObject); @@ -426,7 +428,7 @@ void XGUI_Displayer::setSelected(const QList& theValues, } } } - if (isUpdateViewer) + if (theUpdateViewer) updateViewer(); } @@ -439,7 +441,7 @@ void XGUI_Displayer::clearSelected() } } -void XGUI_Displayer::eraseAll(const bool isUpdateViewer) +void XGUI_Displayer::eraseAll(const bool theUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); if (!aContext.IsNull()) { @@ -452,12 +454,27 @@ void XGUI_Displayer::eraseAll(const bool isUpdateViewer) aContext->Remove(anIO, false); } } - if (isUpdateViewer) + if (theUpdateViewer) updateViewer(); } myResult2AISObjectMap.clear(); } +void XGUI_Displayer::deactivateTrihedron() const +{ + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + + AIS_ListOfInteractive aList; + aContext->DisplayedObjects(aList, true); + AIS_ListIteratorOfListOfInteractive aIt; + for (aIt.Initialize(aList); aIt.More(); aIt.Next()) { + Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(aIt.Value()); + if (!aTrihedron.IsNull()) { + aContext->Deactivate(aTrihedron); + } + } +} + void XGUI_Displayer::openLocalContext() { Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); @@ -480,6 +497,7 @@ void XGUI_Displayer::openLocalContext() //aContext->ClearCurrents(); aContext->OpenLocalContext(); + deactivateTrihedron(); //aContext->NotUseDisplayedObjects(); //myUseExternalObjects = false; @@ -496,7 +514,7 @@ void XGUI_Displayer::openLocalContext() } } -void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer) +void XGUI_Displayer::closeLocalContexts(const bool theUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); if ( (!aContext.IsNull()) && (aContext->HasOpenedContext()) ) { @@ -530,7 +548,7 @@ void XGUI_Displayer::closeLocalContexts(const bool isUpdateViewer) aContext->AddFilter(aFilter); } - if (isUpdateViewer) + if (theUpdateViewer) updateViewer(); //myUseExternalObjects = false; @@ -585,11 +603,40 @@ void XGUI_Displayer::updateViewer() const aContext->UpdateCurrentViewer(); } +void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO, + const int theMode, const bool theUpdateViewer) const +{ + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + aContext->Activate(theIO, theMode, theUpdateViewer); + +#ifdef DEBUG_ACTIVATE_AIS + ObjectPtr anObject = getObject(theIO); + anInfo.append(ModuleBase_Tools::objectInfo((*anIt))); + qDebug(QString("activateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str()); +#endif +} + +void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode) const +{ + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + if (theMode == -1) + aContext->Deactivate(theIO); + else + aContext->Deactivate(theIO, theMode); + +#ifdef DEBUG_DEACTIVATE_AIS + ObjectPtr anObject = getObject(theIO); + anInfo.append(ModuleBase_Tools::objectInfo((*anIt))); + qDebug(QString("deactivateAIS: theMode = %1, object = %2").arg(theMode).arg(anInfo).toStdString().c_str()); +#endif +} + Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const { Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); if ((!aContext.IsNull()) && (!aContext->HasOpenedContext())) { aContext->OpenLocalContext(); + deactivateTrihedron(); } return aContext; } @@ -604,41 +651,39 @@ Handle(SelectMgr_AndFilter) XGUI_Displayer::GetFilter() return myAndFilter; } -void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool isUpdate) +void XGUI_Displayer::displayAIS(AISObjectPtr theAIS, bool theUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); if (aContext.IsNull()) return; Handle(AIS_InteractiveObject) anAISIO = theAIS->impl(); if (!anAISIO.IsNull()) { - aContext->Display(anAISIO, isUpdate); + aContext->Display(anAISIO, theUpdateViewer); if (aContext->HasOpenedContext()) { - //if (myUseExternalObjects) { - if (myActiveSelectionModes.size() == 0) - aContext->Activate(anAISIO); - else { - foreach(int aMode, myActiveSelectionModes) { - aContext->Activate(anAISIO, aMode); - } + if (myActiveSelectionModes.size() == 0) + activateAIS(anAISIO, 0, theUpdateViewer); + else { + foreach(int aMode, myActiveSelectionModes) { + activateAIS(anAISIO, aMode, theUpdateViewer); } - //} + } } } } -void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool isUpdate) +void XGUI_Displayer::eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer) { Handle(AIS_InteractiveContext) aContext = AISContext(); if (aContext.IsNull()) return; Handle(AIS_InteractiveObject) anAISIO = theAIS->impl(); if (!anAISIO.IsNull()) { - aContext->Remove(anAISIO, isUpdate); + aContext->Remove(anAISIO, theUpdateViewer); } } -void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate) +void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer) { if (theMode == NoMode) return; @@ -654,7 +699,7 @@ void XGUI_Displayer::setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bo Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl(); aContext->SetDisplayMode(aAISIO, theMode, false); // Redisplay in order to update new mode because it could be not computed before - if (toUpdate) + if (theUpdateViewer) updateViewer(); } @@ -746,7 +791,8 @@ bool XGUI_Displayer::canBeShaded(ObjectPtr theObject) const } void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, - const QIntList& theModes) const + const QIntList& theModes, + const bool theUpdateViewer) const { Handle(AIS_InteractiveContext) aContext = AISContext(); if (aContext.IsNull() || theIO.IsNull()) @@ -765,32 +811,28 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, aContext->ActivatedModes(theIO, aTColModes); TColStd_ListIteratorOfListOfInteger itr( aTColModes ); QIntList aModesActivatedForIO; - //bool isDeactivated = false; + bool isDeactivated = false; for (; itr.More(); itr.Next() ) { Standard_Integer aMode = itr.Value(); if (!theModes.contains(aMode)) { -#ifdef DEBUG_ACTIVATE - qDebug(QString("deactivate: %1").arg(aMode).toStdString().c_str()); -#endif - aContext->Deactivate(theIO, aMode); - //isDeactivated = true; + deactivateAIS(theIO, aMode); + isDeactivated = true; } else { aModesActivatedForIO.append(aMode); -#ifdef DEBUG_ACTIVATE - qDebug(QString(" active: %1").arg(aMode).toStdString().c_str()); -#endif } } -#ifdef DEBUG_USE_CLEAR_OUTDATED_SELECTION if (isDeactivated) { + // the selection from the previous activation modes should be cleared manually (#26172) aContext->LocalContext()->ClearOutdatedSelection(theIO, true); - updateViewer(); + if (theUpdateViewer) + updateViewer(); } -#endif + // loading the interactive object allowing the decomposition - if (aTColModes.IsEmpty()) + if (aTColModes.IsEmpty()) { aContext->Load(theIO, -1, true); + } // trihedron AIS check should be after the AIS loading. // If it is not loaded, it is steel selectable in the viewer. @@ -800,18 +842,12 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, // In order to clear active modes list if (theModes.size() == 0) { //aContext->Load(anAISIO, 0, true); - aContext->Activate(theIO); - #ifdef DEBUG_ACTIVATE - qDebug("activate in all modes"); - #endif + activateAIS(theIO, 0, theUpdateViewer); } 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()); - #endif + activateAIS(theIO, aMode, theUpdateViewer); } } } @@ -843,7 +879,7 @@ bool XGUI_Displayer::customizeObject(ObjectPtr theObject) } -QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate) +QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer) { if (!isVisible(theObject)) return Qt::black; @@ -852,7 +888,7 @@ QColor XGUI_Displayer::setObjectColor(ObjectPtr theObject, const QColor& theColo int aR, aG, aB; anAISObj->getColor(aR, aG, aB); anAISObj->setColor(theColor.red(), theColor.green(), theColor.blue()); - if (toUpdate) + if (theUpdateViewer) updateViewer(); return QColor(aR, aG, aB); } diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 29cf7482a..910dcc37b 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -63,29 +63,29 @@ class XGUI_EXPORT XGUI_Displayer: public QObject /// Display the feature. Obtain the visualized object from the feature. /// \param theObject an object to display - /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly + /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly /// Returns true if the Feature succesfully displayed - void display(ObjectPtr theObject, bool isUpdateViewer = true); + void display(ObjectPtr theObject, bool theUpdateViewer = true); /// Display the given AIS object. To hide this object use corresponde erase method /// \param theAIS AIOS object to display - /// \param isUpdate the parameter whether the viewer should be update immediatelly - void displayAIS(AISObjectPtr theAIS, bool isUpdate = true); + /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly + void displayAIS(AISObjectPtr theAIS, bool theUpdateViewer = true); /** Redisplay the shape if it was displayed * \param theObject an object instance - * \param isUpdateViewer the parameter whether the viewer should be update immediatelly + * \param theUpdateViewer the parameter whether the viewer should be update immediatelly */ - void redisplay(ObjectPtr theObject, bool isUpdateViewer = true); + void redisplay(ObjectPtr theObject, bool theUpdateViewer = true); /** * Add presentations to current selection. It unhighlight and deselect the current selection. * The shape and result components are processed in the values. If the presentation shape is not * empty, select it, otherwise select the result. * \param theValues a list of presentation to be selected - * \param isUpdateViewer the parameter whether the viewer should be update immediatelly + * \param theUpdateViewer the parameter whether the viewer should be update immediatelly */ - void setSelected(const QList& theValues, bool isUpdateViewer = true); + void setSelected(const QList& theValues, bool theUpdateViewer = true); /// Unselect all objects @@ -93,21 +93,21 @@ class XGUI_EXPORT XGUI_Displayer: public QObject /// Erase the feature and a shape. /// \param theObject an object instance - /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void erase(ObjectPtr theObject, const bool isUpdateViewer = true); + /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly + void erase(ObjectPtr theObject, const bool theUpdateViewer = true); /// Erase the given AIS object displayed by corresponded display method /// \param theAIS instance of AIS object - /// \param isUpdate the parameter whether the viewer should be update immediatelly - void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true); + /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly + void eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer = true); /// Erase all presentations - /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void eraseAll(const bool isUpdateViewer = true); + /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly + void eraseAll(const bool theUpdateViewer = true); /// Deactivates selection of sub-shapes - /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly - void closeLocalContexts(const bool isUpdateViewer = true); + /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly + void closeLocalContexts(const bool theUpdateViewer = true); /// \brief Add selection filter /// \param theFilter a filter instance @@ -130,6 +130,15 @@ class XGUI_EXPORT XGUI_Displayer: public QObject /// Updates the viewer void updateViewer() const; + /// Activate interactive context + /// \param theIO + /// \param theMode + void activateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode, + const bool theUpdateViewer) const; + + /// Activate interactive context. It is necessary to call ClearOutdatedSelection after deactivation + void deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode = -1) const; + /// Searches the interactive object by feature /// \param theObject the object or presentable feature /// \return theIO an interactive object @@ -147,7 +156,7 @@ class XGUI_EXPORT XGUI_Displayer: public QObject /// Deactivates the given object (not allow selection) /// \param theObject object to deactivate - void deactivate(ObjectPtr theObject); + void deactivate(ObjectPtr theObject, const bool theUpdateViewer); /// Activates the given object (it can be selected) /// \param theObject object to activate @@ -169,14 +178,12 @@ 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) - /// \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(); + /// \param theObjList - list of objects which has to be activated. + void activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList, + const bool theUpdateViewer = true); /// Sets display mode for the given object if this object is displayed - void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true); + void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer = true); /// Returns current display mode for the given object. /// If object is not dis played then returns NoMode. @@ -203,9 +210,9 @@ class XGUI_EXPORT XGUI_Displayer: public QObject /// Set color on presentation of an object if it is displayed /// \param theObject an object /// \param theColor a color which has to be set - /// \param toUpdate update viewer flag + /// \param theUpdateViewer update viewer flag /// \return previously defined color on the object - QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate = true); + QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer = true); signals: /// Signal on object display @@ -230,16 +237,20 @@ signals: /// \param theObject an object instance /// \param theAIS AIS presentation /// \param isShading flag to show in shading mode - /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly + /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly /// \return true if the object is succesfully displayed void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading, - bool isUpdateViewer = true); + bool theUpdateViewer = true); private: /// Activates the interactive object in the local context. /// \param theIO an interactive object /// \param theModes - modes on which it has to be activated (can be empty) - void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes) const; + void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes, + const bool theUpdateViewer) const; + + /// Find a trihedron in a list of displayed presentations and deactivate it. + void deactivateTrihedron() const; /// Opens local context. Does nothing if it is already opened. void openLocalContext(); diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index e92c772c6..486b89b85 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -26,13 +26,10 @@ XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop) connect(aSelector, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged())); XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr(); - - //myDocumentShapeFilter = new ModuleBase_ShapeDocumentFilter(this); } XGUI_ModuleConnector::~XGUI_ModuleConnector() { - //myDocumentShapeFilter.Nullify(); } ModuleBase_ISelection* XGUI_ModuleConnector::selection() const @@ -76,39 +73,21 @@ QObjectPtrList XGUI_ModuleConnector::activeObjects(const QObjectPtrList& theObjL void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes) { XGUI_Displayer* aDisp = myWorkshop->displayer(); - // Close context if it was opened in order to clear stsndard selection modes - //aDisp->closeLocalContexts(false); - //aDisp->openLocalContext(); - // Convert shape types to selection types - QIntList aModes; - foreach(int aType, theTypes) { - if (aType > TopAbs_SHAPE) - aModes.append(aType); - else - aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum)aType)); - } - 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); + aDisp->activateObjects(theTypes, activeObjects(aDisp->displayedObjects())); } void XGUI_ModuleConnector::deactivateSubShapesSelection() { - XGUI_Displayer* aDisp = myWorkshop->displayer(); // Clear selection modes + activateModuleSelectionModes(); +} + +void XGUI_ModuleConnector::activateModuleSelectionModes() +{ + XGUI_Displayer* aDisp = myWorkshop->displayer(); 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, activeObjects(aDisp->displayedObjects())); - // The document limitation selection has to be only during operation - //aDisp->removeSelectionFilter(myDocumentShapeFilter); - //aDisp->closeLocalContexts(false); } AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) const diff --git a/src/XGUI/XGUI_ModuleConnector.h b/src/XGUI/XGUI_ModuleConnector.h index 23398a0f9..cd64ffc09 100644 --- a/src/XGUI/XGUI_ModuleConnector.h +++ b/src/XGUI/XGUI_ModuleConnector.h @@ -10,7 +10,6 @@ #include "XGUI.h" #include #include -#include class Handle_AIS_InteractiveContext; class XGUI_Workshop; @@ -37,6 +36,9 @@ Q_OBJECT /// Types has to be dined according to TopAbs_ShapeEnum virtual void activateSubShapesSelection(const QIntList& theTypes); + /// Activate objects in the module selection modes(opens local context) + virtual void activateModuleSelectionModes(); + /// Deactivate sub-shapes selection (closes local context) virtual void deactivateSubShapesSelection(); @@ -73,9 +75,6 @@ private: /// Reference to workshop XGUI_Workshop* myWorkshop; - - /// A filter which provides selection within a current document or whole PartSet - Handle(ModuleBase_ShapeDocumentFilter) myDocumentShapeFilter; }; #endif diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index d945b95e0..2c4e2fdcb 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -470,27 +470,12 @@ 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 (!myModule->canActivateSelection(aObj)) { - if (myDisplayer->isActive(aObj)) - myDisplayer->deactivate(aObj); - } + // Deactivate object of current operation from selection + deactivateActiveObject(aObj, false); } else { // display object if the current operation has it if (displayObject(aObj)) { - //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()); - #endif - // Deactivate object of current operation from selection - if (myDisplayer->isActive(aObj)) - myDisplayer->deactivate(aObj); - } + // Deactivate object of current operation from selection + deactivateActiveObject(aObj, false); } } } @@ -498,6 +483,15 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptrupdateViewer(); } +//****************************************************** +void XGUI_Workshop::deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer) +{ + if (!myModule->canActivateSelection(theObject)) { + if (myDisplayer->isActive(theObject)) + myDisplayer->deactivate(theObject, theUpdateViewer); + } +} + //****************************************************** void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr& theMsg) { @@ -553,6 +547,21 @@ void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation) updateCommandStatus(); myModule->operationStarted(theOperation); + + // the objects of the current operation should be deactivated + QObjectPtrList anObjects; + FeaturePtr aFeature = theOperation->feature(); + anObjects.append(aFeature); + std::list aResults = aFeature->results(); + std::list::const_iterator aIt; + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { + anObjects.append(*aIt); + } + QObjectPtrList::const_iterator anIt = anObjects.begin(), aLast = anObjects.end(); + for (; anIt != aLast; anIt++) + deactivateActiveObject(*anIt, false); + if (anObjects.size() > 0) + myDisplayer->updateViewer(); } //****************************************************** @@ -580,28 +589,25 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation) hidePropertyPanel(); myPropertyPanel->cleanContent(); - // Activate objects created by current operation - // in order to clean selection modes - // the deactivation should be pefromed in the same place, where the mode is activated, - // e.g. activation in the current widget activation, deactivation - in the widget's deactivation - //QIntList aModes; - //myDisplayer->activateObjects(aModes); myModule->operationStopped(theOperation); - // if the operation is nested, do not deactivate objects - //if (myOperationMgr->operationsCount() == 0) { - // Activate selection mode for all objects + // the deactivated objects of the current operation should be activated back. + // They were deactivated on operation start or an object redisplay + QObjectPtrList anObjects; + FeaturePtr aFeature = theOperation->feature(); + if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature)) + anObjects.append(aFeature); + std::list aResults = aFeature->results(); + std::list::const_iterator aIt; + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { + ResultPtr anObject = *aIt; + if (myDisplayer->isVisible(anObject) && !myDisplayer->isActive(anObject)) { + anObjects.append(anObject); + } + } 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); - //} + myDisplayer->activateObjects(aModes, anObjects); } diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 8e5af0de4..ea4190af0 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -314,12 +314,18 @@ signals: /// Process feature update message void onFeatureUpdatedMsg(const std::shared_ptr& ); - ///Process feature created message + /// Process feature created message void onFeatureCreatedMsg(const std::shared_ptr& ); /// Process feature redisplay message void onFeatureRedisplayMsg(const std::shared_ptr& ); + /// Deactivates the object, if it is active and the module returns that the activation + /// of selection for the object is not possible currently(the current operation uses it) + /// \param theObject an object + /// \param theUpdateViewer a boolean flag to update viewer immediately + void deactivateActiveObject(const ObjectPtr& theObject, const bool theUpdateViewer); + /// Display all results //void displayAllResults();