Salome HOME
There is a problem with lost selection on an edge. Create a sketch, create two lines...
authornds <natalia.donis@opencascade.com>
Thu, 9 Apr 2015 13:53:57 +0000 (16:53 +0300)
committernds <natalia.donis@opencascade.com>
Thu, 9 Apr 2015 13:53:57 +0000 (16:53 +0300)
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
src/ModuleBase/ModuleBase_Tools.h
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_WidgetSketchLabel.h
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Workshop.cpp

index 06e8fb08dc8befc26ccd7f1dda8c3304313598eb..a2c393658c6b0a5fd972593781b0df6a60dc9325 100644 (file)
@@ -5,6 +5,10 @@
 // Author:      Vitaly Smetannikov
 
 #include "ModuleBase_Tools.h"
+
+#include <ModelAPI_Result.h>
+#include <ModelAPI_Data.h>
+
 #include <QWidget>
 #include <QLayout>
 #include <QPainter>
@@ -105,6 +109,23 @@ void setSpinValue(QDoubleSpinBox* theSpin, double theValue)
   theSpin->blockSignals(isBlocked);
 }
 
+QString objectInfo(const ObjectPtr& theObj)
+{
+  ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
+  FeaturePtr aFeature;// = std::dynamic_pointer_cast<ModelAPI_Feature>(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;
+}
+
 }
 
 
index 1f55bec750a28fb7a9e5b04df2273543c3ff44e6..c54c5441e3ea6e262fd9013dc48d98f576bfa028 100644 (file)
@@ -9,6 +9,8 @@
 
 #include "ModuleBase.h"
 
+#include <ModelAPI_Feature.h>
+
 #include <QPixmap>
 
 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
index 40578fa8ad51a528d185926d14aefe0734784c9a..99c9b3e3813630ca33da0a9a61223e6c9ba63593 100644 (file)
 #include <SketchPlugin_ConstraintFillet.h>
 #include <SketchPlugin_ConstraintMirror.h>
 
+#include <SketcherPrs_Tools.h>
+
 #include <SelectMgr_IndexedMapOfOwner.hxx>
 #include <StdSelect_BRepOwner.hxx>
 
 //#include <AIS_DimensionSelectionMode.hxx>
-//#include <AIS_Shape.hxx>
+#include <AIS_Shape.hxx>
 
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Session.h>
@@ -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<XGUI_ModuleConnector*>(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<XGUI_ModuleConnector*>(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<GeomAPI_Pln>& thePln)
 {
   myPlaneFilter->setPlane(thePln->impl<gp_Pln>());
+
+  // 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<XGUI_ModuleConnector*>(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();
index 01789c136b6e4a46054a215006aadffb5aa58e14..977c666d39d9d9b911985ea84b8d0e514797c767 100644 (file)
@@ -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;
 
index af8e9d56af5061f563fe2ca5a854b61e09b39307..5570182990f55b7a8ff0fab76f7f4f73bf630ebb 100644 (file)
@@ -40,7 +40,7 @@
 #include <Config_PropManager.h>
 
 #include <QLabel>
-#include <QTimer>
+//#include <QTimer>
 #include <QApplication>
 #include <QVBoxLayout>
 #include <QCheckBox>
@@ -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<GeomAPI_Dir> 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)
 {
index 0b26103a47bed65f9be334dd6d73b852dfe33b71..0207199bbdfa78399e60c0d038d1a779cb329793 100644 (file)
@@ -19,7 +19,7 @@
 #include <TopoDS_Shape.hxx>
 
 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;
 };
index 57cb4980184dcd53395de57db0d13164a03e1cc5..368dbb57469080e6f02d66e23a37690cb3388df4 100644 (file)
@@ -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
+        }
       }
     }
   }
index 027248cba7cc970790c1227faadc9975ff867ed2..41c911529b558fc01f1ebe6032f7a178c3fe7b33 100644 (file)
@@ -54,8 +54,9 @@
 #include <ModuleBase_WidgetFactory.h>
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_IViewer.h>
-#include<ModuleBase_FilterFactory.h>
+#include <ModuleBase_FilterFactory.h>
 #include <ModuleBase_PageBase.h>
+#include <ModuleBase_Tools.h>
 
 #include <Config_Common.h>
 #include <Config_FeatureMessage.h>
 //#define DEBUG_FEATURE_CREATED
 //#define DEBUG_FEATURE_REDISPLAY
 
-QString objectInfo(ObjectPtr theObj)
-{
-  ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
-  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(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<QString, QString> XGUI_Workshop::myIcons;
 
 
@@ -541,7 +524,7 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectU
 #ifdef DEBUG_FEATURE_REDISPLAY
   QStringList anInfo;
   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
-    anInfo.append(objectInfo((*aIt)));
+    anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
   }
   QString anInfoStr = anInfo.join(", ");
   qDebug(QString("onFeatureRedisplayMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
@@ -562,7 +545,7 @@ void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectU
       // Redisplay the visible object or the object of the current operation
       bool isVisibleObject = myDisplayer->isVisible(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_ptr<ModelAPI_ObjectUpd
 #ifdef DEBUG_FEATURE_CREATED
   QStringList anInfo;
   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
-    anInfo.append(objectInfo((*aIt)));
+    anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
   }
   QString anInfoStr = anInfo.join(", ");
   qDebug(QString("onFeatureCreatedMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
@@ -679,8 +662,10 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
 
   // Activate objects created by current operation 
   // in order to clean selection modes
-  QIntList aModes;
-  myDisplayer->activateObjects(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);
 }