Salome HOME
Issue #390 Selection restore problems during edit operation
authornds <natalia.donis@opencascade.com>
Wed, 25 Feb 2015 12:42:02 +0000 (15:42 +0300)
committernds <natalia.donis@opencascade.com>
Wed, 25 Feb 2015 12:42:02 +0000 (15:42 +0300)
24 files changed:
src/ModuleBase/ModuleBase_ModelWidget.cpp
src/ModuleBase/ModuleBase_ModelWidget.h
src/ModuleBase/ModuleBase_WidgetBoolValue.cpp
src/ModuleBase/ModuleBase_WidgetBoolValue.h
src/ModuleBase/ModuleBase_WidgetChoice.cpp
src/ModuleBase/ModuleBase_WidgetChoice.h
src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp
src/ModuleBase/ModuleBase_WidgetDoubleValue.h
src/ModuleBase/ModuleBase_WidgetFileSelector.cpp
src/ModuleBase/ModuleBase_WidgetFileSelector.h
src/ModuleBase/ModuleBase_WidgetLabel.h
src/ModuleBase/ModuleBase_WidgetLineEdit.cpp
src/ModuleBase/ModuleBase_WidgetLineEdit.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h
src/PartSet/PartSet_WidgetPoint2d.cpp
src/PartSet/PartSet_WidgetPoint2d.h
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h
src/PartSet/PartSet_WidgetSketchLabel.h

index 6351c4f785c918f13e0af6c98637ad81598d4023..ea7de61acc3b52dfd5b3e3fbb7dc0482b88af1d1 100644 (file)
@@ -115,6 +115,15 @@ void ModuleBase_ModelWidget::activate()
   activateCustom();
 }
 
+bool ModuleBase_ModelWidget::storeValue()
+{
+  emit beforeValuesChanged();
+  bool isDone = storeValueCustom();
+  emit afterValuesChanged();
+
+  return isDone;
+}
+
 void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) const
 {
   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
index a6830788e9282ea5dd00d629797068200507ab85..3db67b661888ca9cd9abc755228f0b0636aab492 100644 (file)
@@ -137,8 +137,12 @@ Q_OBJECT
   bool isEditingMode() const { return myIsEditing; }
 
 signals:
+  /// The signal about widget values are to be changed
+  void beforeValuesChanged();
   /// The signal about widget values changed
   void valuesChanged();
+  /// The signal about widget values are to be changed
+  void afterValuesChanged();
 
   /// The signal about key release on the control, that corresponds to the attribute
   /// \param theEvent key release event
@@ -153,10 +157,6 @@ signals:
   void focusOutWidget(ModuleBase_ModelWidget* theWidget);
 
  protected:
-  /// Saves the internal parameters to the given feature
-  /// \return True in success
-  virtual bool storeValue() const = 0;
-
   /// \brief Set the attribute name
   /// \param theAttribute the string value with attribute name
   void setAttributeID(const std::string& theAttribute)
@@ -164,6 +164,14 @@ signals:
     myAttributeID = theAttribute;
   }
 
+  /// Saves the internal parameters to the given feature. Emits signals before and after store
+  /// \return True in success
+  bool storeValue();
+
+  /// Saves the internal parameters to the given feature
+  /// \return True in success
+  virtual bool storeValueCustom() const = 0;
+
   /// The methiod called when widget is activated
   virtual void activateCustom() {};
 
index 87e26a78f5c4b03a9a61ad35adc3e99e95929f08..af2e7ee0ef3b79879863c3f61a17f8470133a47d 100644 (file)
@@ -44,7 +44,7 @@ QWidget* ModuleBase_WidgetBoolValue::getControl() const
   return myCheckBox;
 }
 
-bool ModuleBase_WidgetBoolValue::storeValue() const
+bool ModuleBase_WidgetBoolValue::storeValueCustom() const
 {
   DataPtr aData = myFeature->data();
   std::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
index 518d9a163698df418347103b689569e117be080d..47d574a14be67627cdf53f8b12f9d18dd0f53676 100644 (file)
@@ -40,7 +40,7 @@ Q_OBJECT
 protected:
   /// Saves the internal parameters to the given feature
   /// \return True in success
-  virtual bool storeValue() const;
+  virtual bool storeValueCustom() const;
 
  private:
    /// The check box
index 7156a0f453e1e1e32911853ff0f82bc1a1117aa5..e77c2d9790cb284b03278ed5dd03194e8b422386 100644 (file)
@@ -46,7 +46,7 @@ ModuleBase_WidgetChoice::~ModuleBase_WidgetChoice()
 {
 }
   
-bool ModuleBase_WidgetChoice::storeValue() const
+bool ModuleBase_WidgetChoice::storeValueCustom() const
 {
   DataPtr aData = myFeature->data();
   std::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
index 18fcb55bdadc55c6550681cd89f2685a5709afc7..fd201bd8696b37febec4c81e9669c07a55bf6e14 100644 (file)
@@ -57,7 +57,7 @@ Q_OBJECT
 protected:
   /// Saves the internal parameters to the given feature
   /// \return True in success
-  virtual bool storeValue() const;
+  virtual bool storeValueCustom() const;
 
 private slots:
   /// Slot called on combo box index change
index 2b5437e46910ab5df783ff68054e89ec6303a9a7..df255b46bf363295b9776e0700851d077d7a98b6 100644 (file)
@@ -111,7 +111,7 @@ void ModuleBase_WidgetDoubleValue::reset()
   }
 }
 
-bool ModuleBase_WidgetDoubleValue::storeValue() const
+bool ModuleBase_WidgetDoubleValue::storeValueCustom() const
 {
   DataPtr aData = myFeature->data();
   AttributeDoublePtr aReal = aData->real(attributeID());
index 957d289a7a50bfc77b1317a147210db697a37ee8..fd447a78050f26c525c4e3029855b383df288e7c 100644 (file)
@@ -63,7 +63,7 @@ Q_OBJECT
 protected:
   /// Saves the internal parameters to the given feature
   /// \return True in success
-  virtual bool storeValue() const;
+  virtual bool storeValueCustom() const;
 
 protected:
    /// Container for thw widget controls
index 80e6d670a9a30baf33c0e629d79dc17e4a3f1295..d857d2d66f444a4e5e69aa183627f022511565cd 100644 (file)
@@ -65,7 +65,7 @@ ModuleBase_WidgetFileSelector::~ModuleBase_WidgetFileSelector()
 {
 }
 
-bool ModuleBase_WidgetFileSelector::storeValue() const
+bool ModuleBase_WidgetFileSelector::storeValueCustom() const
 {
   // A rare case when plugin was not loaded. 
   if(!myFeature)
index 5a628286dde694aa8bc4a3dc1aefa176b95b366b..4f64d215ca7ebdeec9fdfd2192d1f7fd6f4ddb7c 100644 (file)
@@ -66,7 +66,7 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFileSelector : public ModuleBase_ModelW
 protected:
   /// Saves the internal parameters to the given feature
   /// \return True in success
-  virtual bool storeValue() const;
+  virtual bool storeValueCustom() const;
 
  protected:
    /// Returns string containing formats
index fd0112ff19b88c3b24a4ec8cd0d8e3a07daf0050..0f6e00baccfc3b67e57098c6a59a7bd5a49b69e8 100644 (file)
@@ -48,7 +48,7 @@ Q_OBJECT
 protected:
   /// Saves the internal parameters to the given feature
   /// \return True in success
-  virtual bool storeValue() const
+  virtual bool storeValueCustom() const
   {
     return true;
   }
index 91af0aa943e439ddcaa37006ed11809bfbf31ec1..c25c3befade9d54df48ca1e9698bf33015123b75 100644 (file)
@@ -49,7 +49,7 @@ ModuleBase_WidgetLineEdit::~ModuleBase_WidgetLineEdit()
 {
 }
 
-bool ModuleBase_WidgetLineEdit::storeValue() const
+bool ModuleBase_WidgetLineEdit::storeValueCustom() const
 {
   // A rare case when plugin was not loaded. 
   if(!myFeature)
index 657b22be05064ebbd4f867e7909c4d2aab363f60..1789b0e436305ed5a5fe8391e1561515ae74f53d 100644 (file)
@@ -51,7 +51,7 @@ class MODULEBASE_EXPORT ModuleBase_WidgetLineEdit : public ModuleBase_ModelWidge
 protected:
   /// Saves the internal parameters to the given feature
   /// \return True in success
-  virtual bool storeValue() const;
+  virtual bool storeValueCustom() const;
 
 private:
    /// A line edit control
index a11725988706e55c0ce67527a6d1ef867f5afe36..bd9d0d702467c33eada8d0f03137d3989779e370 100644 (file)
@@ -83,7 +83,7 @@ ModuleBase_WidgetMultiSelector::~ModuleBase_WidgetMultiSelector()
 }
 
 //********************************************************************
-bool ModuleBase_WidgetMultiSelector::storeValue() const
+bool ModuleBase_WidgetMultiSelector::storeValueCustom() const
 {
   // A rare case when plugin was not loaded. 
   if(!myFeature)
index 3b092d424c0c7720e5a920743247ca4737e5c6c0..84dc2b7dc70367d92a9210ed6ccf7e7c6e63efc4 100644 (file)
@@ -94,7 +94,7 @@ protected slots:
  protected:
   /// Saves the internal parameters to the given feature
   /// \return True in success
-  virtual bool storeValue() const;
+  virtual bool storeValueCustom() const;
 
   /// Provide filtering of selected shapes
    /// \param theShapesToFilter source list of shapes
index 7031b5c1e2e5e22d0abdbac2fc3bc228cd5dea59..9dc8c506384745b66ef27ccd568af42c1332c7b1 100644 (file)
@@ -129,7 +129,7 @@ ModuleBase_WidgetShapeSelector::~ModuleBase_WidgetShapeSelector()
 }
 
 //********************************************************************
-bool ModuleBase_WidgetShapeSelector::storeValue() const
+bool ModuleBase_WidgetShapeSelector::storeValueCustom() const
 {
   FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(mySelectedObject);
   if (aSelectedFeature == myFeature)  // In order to avoid selection of the same object
@@ -442,6 +442,27 @@ void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate)
   }
 }
 
+//********************************************************************
+void ModuleBase_WidgetShapeSelector::selectionFilters(SelectMgr_ListOfFilter& theFilters)
+{
+  if (!myObjectTypes.isEmpty()) {
+    myObjTypeFilter = new ModuleBase_ObjectTypesFilter(myWorkshop, myObjectTypes);
+    theFilters.Append(myObjTypeFilter);
+  }
+  // apply filters loaded from the XML definition of the widget
+  ModuleBase_FilterFactory* aFactory = myWorkshop->selectionFilters();
+  SelectMgr_ListOfFilter aFilters;
+  aFactory->filters(parentID(), attributeID(), aFilters);
+  SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
+  for (; aIt.More(); aIt.Next()) {
+    Handle(SelectMgr_Filter) aSelFilter = aIt.Value();
+    if (aSelFilter.IsNull())
+      continue;
+
+    theFilters.Append(aSelFilter);
+  }
+}
+
 //********************************************************************
 void ModuleBase_WidgetShapeSelector::raisePanel() const
 {
index f57f5664b652cca5d96114a082193fa4bea767ab..2e6b2cc9a8cabe809b2f6063e7c678f76dc7d2f3 100644 (file)
@@ -116,7 +116,7 @@ Q_OBJECT
  protected:
   /// Saves the internal parameters to the given feature
   /// \return True in success
-  virtual bool storeValue() const;
+  virtual bool storeValueCustom() const;
 
   /// The methiod called when widget is activated
   virtual void activateCustom();
index 226205b7cccd2907ad3c93434a3f66029fad18a2..3427122e99717b7df556a511a6181add9d9e198b 100644 (file)
@@ -114,7 +114,7 @@ void fillFeature2Attribute(const QList<ModuleBase_ViewerPrs>& theList,
 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
   : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
     myIsPropertyPanelValueChanged(false), myIsMouseOverWindow(false),
-    myIsMouseOverViewProcessed(true)
+    myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true)
 {
   ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
   ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
@@ -186,6 +186,20 @@ void PartSet_SketcherMgr::onLeaveViewPort()
   visualizeFeature(aOperation, canDisplayObject());
 }
 
+void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
+{
+  if (isNestedCreateOperation(getCurrentOperation()))
+    return;
+  storeSelection();
+}
+
+void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
+{
+  if (isNestedCreateOperation(getCurrentOperation()))
+    return;
+  restoreSelection();
+}
+
 void PartSet_SketcherMgr::onValuesChangedInPropertyPanel()
 {
   if (!isNestedCreateOperation(getCurrentOperation()))
@@ -842,10 +856,20 @@ void PartSet_SketcherMgr::connectToPropertyPanel(const bool isToConnect)
   if (aPropertyPanel) {
     const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
     foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
-      if (isToConnect)
+      if (isToConnect) {
+        connect(aWidget, SIGNAL(beforeValuesChanged()),
+                this, SLOT(onBeforeValuesChangedInPropertyPanel()));
         connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
-      else
+        connect(aWidget, SIGNAL(afterValuesChanged()),
+                this, SLOT(onAfterValuesChangedInPropertyPanel()));
+      }
+      else {
+        disconnect(aWidget, SIGNAL(beforeValuesChanged()),
+                   this, SLOT(onBeforeValuesChangedInPropertyPanel()));
         disconnect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onValuesChangedInPropertyPanel()));
+        disconnect(aWidget, SIGNAL(afterValuesChanged()),
+                   this, SLOT(onAfterValuesChangedInPropertyPanel()));
+      }
     }
   }
 }
@@ -891,3 +915,44 @@ void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
   }
   aDisplayer->updateViewer();
 }
+
+void PartSet_SketcherMgr::storeSelection()
+{
+  //qDebug("  storeSelection");
+  ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
+  // 1. it is necessary to save current selection in order to restore it after the features moving
+  //FeatureToSelectionMap aCurrentSelection;
+  myCurrentSelection.clear();
+  getCurrentSelection(myFeature2AttributeMap, myCurrentSketch, aWorkshop, myCurrentSelection);
+
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
+  XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+  // 3. the flag to disable the update viewer should be set in order to avoid blinking in the 
+  // viewer happens by deselect/select the modified objects. The flag should be restored after
+  // the selection processing. The update viewer should be also called.
+  myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
+}
+
+void PartSet_SketcherMgr::restoreSelection()
+{
+  //qDebug("restoreSelection");
+  ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
+  // 5. it is necessary to save current selection in order to restore it after the features moving
+  FeatureToSelectionMap::const_iterator aSIt = myCurrentSelection.begin(),
+                                        aSLast = myCurrentSelection.end();
+  SelectMgr_IndexedMapOfOwner anOwnersToSelect;
+  for (; aSIt != aSLast; aSIt++) {
+    anOwnersToSelect.Clear();
+    getSelectionOwners(aSIt->first, myCurrentSketch, aWorkshop, myCurrentSelection,
+                        anOwnersToSelect);
+    aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
+  }
+  XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+  // 3. the flag to disable the update viewer should be set in order to avoid blinking in the 
+  // viewer happens by deselect/select the modified objects. The flag should be restored after
+  // the selection processing. The update viewer should be also called.
+  aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
+  //if (myPreviousUpdateViewerEnabled)
+    aDisplayer->updateViewer();
+}
index 7feca59fbb28550cd3b6e9fab6163dcc8467515c..69e3dcd706e60cb13ecd9625eb7e3644871ffc68 100644 (file)
@@ -141,8 +141,12 @@ private slots:
   /// Process the leave mouse of the view port. If the current operation is a create of
   /// a nested sketch feature, it hides the feature in the viewer
   void onLeaveViewPort();
-  /// Listens the value changed signal and display the current operation feature
+  /// Listens to the value changed signal and display the current operation feature
+  void onBeforeValuesChangedInPropertyPanel();
+  /// Listens to the signal about values are to be changed in the property panel
   void onValuesChangedInPropertyPanel();
+  /// Listens to the signal about the modification of the values have been done in the property panel
+  void onAfterValuesChangedInPropertyPanel();
 
   void onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*);
   void onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*);
@@ -230,6 +234,9 @@ private:
   /// \param isToDisplay a flag about the display or erase the feature
   void visualizeFeature(ModuleBase_Operation* theOperation, const bool isToDisplay);
 
+  void storeSelection();
+  void restoreSelection();
+
 private:
   PartSet_Module* myModule;
 
@@ -247,6 +254,8 @@ private:
   FeatureToAttributesMap myFeature2AttributeMap; /// a map of a feature to attributes
 
   Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter;
+  FeatureToSelectionMap myCurrentSelection;
+  bool myPreviousUpdateViewerEnabled;
 };
 
 
index 60b644e08275e0192a206554bc56506a3ea3cdb5..a6178e8760206af6a949f744efd01697a02ab794 100644 (file)
@@ -139,7 +139,7 @@ bool PartSet_WidgetPoint2D::setPoint(double theX, double theY)
   return true;
 }
 
-bool PartSet_WidgetPoint2D::storeValue() const
+bool PartSet_WidgetPoint2D::storeValueCustom() const
 {
   std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
   if (!aData) // can be on abort of sketcher element
@@ -205,6 +205,8 @@ void PartSet_WidgetPoint2D::activateCustom()
 
   QIntList aModes;
   aModes << TopAbs_VERTEX;
+  if (isEditingMode())
+    aModes << TopAbs_EDGE;
   myWorkshop->moduleConnector()->activateSubShapesSelection(aModes);
 }
 
index de3ab120ddc92db4f75006dd9b28c3e59eefc2d2..f07c60fc9f69269f50df10c6dc5907b4b8a998a4 100644 (file)
@@ -113,7 +113,7 @@ protected slots:
 protected:
   /// Saves the internal parameters to the given feature
   /// \return True in success
-  virtual bool storeValue() const;
+  virtual bool storeValueCustom() const;
 
   /// The methiod called when widget is activated
   virtual void activateCustom();
index 2f9bb3e95ee310ef5b436e456599d03fabc224e7..76561e4e6e79b1dc42cda0ec95525736c9ba9e83 100644 (file)
@@ -16,7 +16,7 @@
 #include <SketchPlugin_Feature.h>
 
 
-bool PartSet_WidgetShapeSelector::storeValue() const
+bool PartSet_WidgetShapeSelector::storeValueCustom() const
 {
   if (!mySelectedObject)
     return false;
@@ -59,7 +59,7 @@ bool PartSet_WidgetShapeSelector::storeValue() const
       }
     }
   }
-  return ModuleBase_WidgetShapeSelector::storeValue();
+  return ModuleBase_WidgetShapeSelector::storeValueCustom();
 }
 
 //********************************************************************
@@ -126,7 +126,7 @@ bool PartSet_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<Geom
 }
 
 //*********************************************
-bool PartSet_WidgetConstraintShapeSelector::storeValue() const
+bool PartSet_WidgetConstraintShapeSelector::storeValueCustom() const
 {
   FeaturePtr aFeature = ModelAPI_Feature::feature(mySelectedObject);
   if (aFeature) {
@@ -142,5 +142,5 @@ bool PartSet_WidgetConstraintShapeSelector::storeValue() const
         return false;
     }
   }
-  return ModuleBase_WidgetShapeSelector::storeValue();
+  return ModuleBase_WidgetShapeSelector::storeValueCustom();
 }
index f8e9d75b1d7915cc3d9c2326ed43141222c155a5..e38cdf7984b21e924f8dd7a0a4fea33aace27a69 100644 (file)
@@ -45,7 +45,7 @@ Q_OBJECT
 protected:
   /// Saves the internal parameters to the given feature
   /// \return True in success
-  virtual bool storeValue() const;
+  virtual bool storeValueCustom() const;
 
   /// Check the selected with validators if installed
   virtual bool isValid(ObjectPtr theObj, std::shared_ptr<GeomAPI_Shape> theShape);
@@ -85,7 +85,7 @@ Q_OBJECT
 protected:
   /// Saves the internal parameters to the given feature
   /// \return True in success
-  virtual bool storeValue() const;
+  virtual bool storeValueCustom() const;
 
 private:
   /// Pointer to a sketch 
index 0fa5c18f0372ca342b139a377c9a8ea5a94e4ffc..3a8f21a39fece222945b6eba2f67ff7858806403 100644 (file)
@@ -79,7 +79,7 @@ signals:
 protected:
   /// Saves the internal parameters to the given feature
   /// \return True in success
-  virtual bool storeValue() const
+  virtual bool storeValueCustom() const
   {
     return true;
   }