From 998909e881f6117ac083d0f4ae607602fce7fc55 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 9 Apr 2015 16:53:57 +0300 Subject: [PATCH] There is a problem with lost selection on an edge. Create a sketch, create two lines, Esc, Select the first line, with SHIFT select the second line - selection of the first line is lost. It seems that the reason is the Deactivate of AIS_IO lost the selection state in OCC for the object and by any redisplay it is deselected. It is decided to minimize number of deactivate call and use the same active mode during edit operation(the line selection) like in the sketch operation. In the case, the scenario do not call deactivate and selection is saved. --- src/ModuleBase/ModuleBase_Tools.cpp | 21 ++++++++++ src/ModuleBase/ModuleBase_Tools.h | 7 ++++ src/PartSet/PartSet_SketcherMgr.cpp | 48 +++++++++++++++++------ src/PartSet/PartSet_SketcherMgr.h | 5 +++ src/PartSet/PartSet_WidgetSketchLabel.cpp | 19 ++++----- src/PartSet/PartSet_WidgetSketchLabel.h | 6 +-- src/XGUI/XGUI_Displayer.cpp | 36 +++++++++++++++-- src/XGUI/XGUI_Workshop.cpp | 33 +++++----------- 8 files changed, 123 insertions(+), 52 deletions(-) diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 06e8fb08d..a2c393658 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -5,6 +5,10 @@ // Author: Vitaly Smetannikov #include "ModuleBase_Tools.h" + +#include +#include + #include #include #include @@ -105,6 +109,23 @@ void setSpinValue(QDoubleSpinBox* theSpin, double theValue) theSpin->blockSignals(isBlocked); } +QString objectInfo(const ObjectPtr& theObj) +{ + ResultPtr aRes = std::dynamic_pointer_cast(theObj); + FeaturePtr aFeature;// = std::dynamic_pointer_cast(theObj); + QString aFeatureStr = "feature"; + if(aRes.get()) { + aFeatureStr.append("(Result)"); + //aFeature = ModelAPI_Feature::feature(aRes); + } + if (aFeature.get()) { + aFeatureStr.append(QString(": %1").arg(aFeature->getKind().c_str()).toStdString().c_str()); + if (aFeature->data().get() && aFeature->data()->isValid()) + aFeatureStr.append(QString("(name=%1)").arg(aFeature->data()->name().c_str()).toStdString().c_str()); + } + return aFeatureStr; +} + } diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 1f55bec75..c54c5441e 100644 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -9,6 +9,8 @@ #include "ModuleBase.h" +#include + #include class QWidget; @@ -57,6 +59,11 @@ MODULEBASE_EXPORT QPixmap lighter(const QString& theIcon, const int theLighterVa /// \param theValue a new value MODULEBASE_EXPORT void setSpinValue(QDoubleSpinBox* theSpin, double theValue); +/// Converts the object to the feature or a result and generate information string +/// \param theObj an object +/// \return a string +MODULEBASE_EXPORT QString objectInfo(const ObjectPtr& theObj); + } #endif diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 40578fa8a..99c9b3e38 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -57,11 +57,13 @@ #include #include +#include + #include #include //#include -//#include +#include #include #include @@ -552,18 +554,9 @@ void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent void PartSet_SketcherMgr::launchEditing() { - // there should be activate the vertex selection mode because the edit can happens by the selected - // point - QIntList aModes; - aModes << TopAbs_VERTEX << TopAbs_EDGE; - // TODO: #391 - to be uncommented - /*aModes.append(AIS_DSM_Text); - aModes.append(AIS_DSM_Line); - aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX)); - aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));*/ - - XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); - aConnector->activateSubShapesSelection(aModes); + // 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(); @@ -700,6 +693,9 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) { myIsMouseOverWindow = false; myIsConstraintsShown = true; + // 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()); XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); @@ -757,6 +753,10 @@ 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) @@ -826,6 +826,11 @@ bool PartSet_SketcherMgr::canDisplayObject(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, @@ -1015,6 +1020,23 @@ void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation, aDisplayer->updateViewer(); } +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) { + 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)); + } + 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 01789c136..977c666d3 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -246,6 +246,11 @@ private: /// \param isToDisplay a flag about the display or erase the feature void visualizeFeature(ModuleBase_Operation* theOperation, const bool isToDisplay); + /// 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: PartSet_Module* myModule; diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index af8e9d56a..557018299 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -40,7 +40,7 @@ #include #include -#include +//#include #include #include #include @@ -61,9 +61,9 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, myLabel->setToolTip(""); myLabel->setIndent(5); - mySelectionTimer = new QTimer(this); - connect(mySelectionTimer, SIGNAL(timeout()), SLOT(setSketchingMode())); - mySelectionTimer->setSingleShot(true); + //mySelectionTimer = new QTimer(this); + //connect(mySelectionTimer, SIGNAL(timeout()), SLOT(setSketchingMode())); + //mySelectionTimer->setSingleShot(true); QVBoxLayout* aLayout = new QVBoxLayout(this); ModuleBase_Tools::zeroMargins(aLayout); @@ -130,7 +130,7 @@ void PartSet_WidgetSketchLabel::onPlaneSelected() //XGUI_Displayer* aDisp = myWorkshop->displayer(); //aDisp->closeLocalContexts(); emit planeSelected(plane()); - setSketchingMode(); + //setSketchingMode(); // Update sketcher actions XGUI_ActionsMgr* anActMgr = myWorkshop->actionsMgr(); @@ -216,7 +216,7 @@ void PartSet_WidgetSketchLabel::activateCustom() // In order to avoid Opening/Closing of context too often // it can be useful for a delay on the property panel filling // it is possible that it is not necessary anymore, but it requires a check - mySelectionTimer->start(20); + //mySelectionTimer->start(20); } else { // We have to select a plane before any operation showPreviewPlanes(); @@ -241,7 +241,7 @@ void PartSet_WidgetSketchLabel::activateCustom() void PartSet_WidgetSketchLabel::deactivate() { // Do not set selection mode if the widget was activated for a small moment - mySelectionTimer->stop(); + //mySelectionTimer->stop(); //XGUI_Displayer* aDisp = myWorkshop->displayer(); //aDisp->closeLocalContexts(); erasePreviewPlanes(); @@ -353,7 +353,7 @@ std::shared_ptr PartSet_WidgetSketchLabel::setSketchPlane(const Top } -void PartSet_WidgetSketchLabel::setSketchingMode() +/*void PartSet_WidgetSketchLabel::setSketchingMode() { XGUI_Displayer* aDisp = myWorkshop->displayer(); // Clear standard selection modes if they are defined @@ -361,6 +361,7 @@ void PartSet_WidgetSketchLabel::setSketchingMode() //aDisp->openLocalContext(); // Get default selection modes + QIntList aModes; aModes.append(SketcherPrs_Tools::Sel_Dimension_Text); aModes.append(SketcherPrs_Tools::Sel_Dimension_Line); @@ -369,7 +370,7 @@ void PartSet_WidgetSketchLabel::setSketchingMode() aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE)); aDisp->activateObjects(aModes); -} +}*/ void PartSet_WidgetSketchLabel::showConstraints(bool theOn) { diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 0b26103a4..0207199bb 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -19,7 +19,7 @@ #include class QLabel; -class QTimer; +//class QTimer; class XGUI_OperationMgr; class XGUI_Workshop; class QCheckBox; @@ -114,7 +114,7 @@ protected: void onPlaneSelected(); /// Set sketch specific mode of selection - void setSketchingMode(); + //void setSketchingMode(); private: /// Create preview of planes for sketch plane selection @@ -147,7 +147,7 @@ protected: AISObjectPtr myXYPlane; bool myPreviewDisplayed; - QTimer* mySelectionTimer; + //QTimer* mySelectionTimer; QCheckBox* myShowConstraints; }; diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 57cb49801..368dbb574 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -753,8 +753,30 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, if (aContext.IsNull() || theIO.IsNull()) return; - aContext->Load(theIO, -1, true); - aContext->Deactivate(theIO); + // deactivate object in all modes, which are not in the list of activation + TColStd_ListOfInteger aTColModes; + aContext->ActivatedModes(theIO, aTColModes); + TColStd_ListIteratorOfListOfInteger itr( aTColModes ); + QIntList aModesActivatedForIO; + 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); + } + else { + aModesActivatedForIO.append(aMode); +#ifdef DEBUG_ACTIVATE + qDebug(QString(" active: %1").arg(aMode).toStdString().c_str()); +#endif + } + } + // loading the interactive object allowing the decomposition + 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()) { @@ -763,10 +785,18 @@ void XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO, if (theModes.size() == 0) { //aContext->Load(anAISIO, 0, true); aContext->Activate(theIO); +#ifdef DEBUG_ACTIVATE + qDebug("activate in all modes"); +#endif } else { foreach(int aMode, theModes) { //aContext->Load(anAISIO, aMode, true); - aContext->Activate(theIO, aMode); + if (!aModesActivatedForIO.contains(aMode)) { + aContext->Activate(theIO, aMode); +#ifdef DEBUG_ACTIVATE + qDebug(QString("activate: %1").arg(aMode).toStdString().c_str()); +#endif + } } } } diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 027248cba..41c911529 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -54,8 +54,9 @@ #include #include #include -#include +#include #include +#include #include #include @@ -95,24 +96,6 @@ //#define DEBUG_FEATURE_CREATED //#define DEBUG_FEATURE_REDISPLAY -QString objectInfo(ObjectPtr theObj) -{ - ResultPtr aRes = std::dynamic_pointer_cast(theObj); - FeaturePtr aFeature = std::dynamic_pointer_cast(theObj); - QString aFeatureStr = "feature"; - if(aRes.get()) { - aFeatureStr.append("(Result)"); - aFeature = ModelAPI_Feature::feature(aRes); - } - if (aFeature.get()) { - aFeatureStr.append(QString(": %1").arg(aFeature->getKind().c_str()).toStdString().c_str()); - if (aFeature->data().get() && aFeature->data()->isValid()) - aFeatureStr.append(QString("(name=%1)").arg(aFeature->data()->name().c_str()).toStdString().c_str()); - } - return aFeatureStr; -} - - QMap XGUI_Workshop::myIcons; @@ -541,7 +524,7 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptrisVisible(aObj); #ifdef DEBUG_FEATURE_REDISPLAY - //QString anObjInfo = objectInfo((aObj)); + //QString anObjInfo = ModuleBase_Tools::objectInfo((aObj)); //qDebug(QString("visible=%1 : display= %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str()); #endif @@ -598,7 +581,7 @@ void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptractivateObjects(aModes); + // 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); } -- 2.39.2