From: nds Date: Wed, 25 Feb 2015 12:42:02 +0000 (+0300) Subject: Issue #390 Selection restore problems during edit operation X-Git-Tag: V_1.1.0~173 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=47aefba9ed96153cab39ebfc4aa7fecc51942f21;p=modules%2Fshaper.git Issue #390 Selection restore problems during edit operation --- diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index 6351c4f78..ea7de61ac 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -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)); diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index a6830788e..3db67b661 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -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() {}; diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp index 87e26a78f..af2e7ee0e 100644 --- a/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.cpp @@ -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 aBool = aData->boolean(attributeID()); diff --git a/src/ModuleBase/ModuleBase_WidgetBoolValue.h b/src/ModuleBase/ModuleBase_WidgetBoolValue.h index 518d9a163..47d574a14 100644 --- a/src/ModuleBase/ModuleBase_WidgetBoolValue.h +++ b/src/ModuleBase/ModuleBase_WidgetBoolValue.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_WidgetChoice.cpp b/src/ModuleBase/ModuleBase_WidgetChoice.cpp index 7156a0f45..e77c2d979 100644 --- a/src/ModuleBase/ModuleBase_WidgetChoice.cpp +++ b/src/ModuleBase/ModuleBase_WidgetChoice.cpp @@ -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 aIntAttr = aData->integer(attributeID()); diff --git a/src/ModuleBase/ModuleBase_WidgetChoice.h b/src/ModuleBase/ModuleBase_WidgetChoice.h index 18fcb55bd..fd201bd86 100644 --- a/src/ModuleBase/ModuleBase_WidgetChoice.h +++ b/src/ModuleBase/ModuleBase_WidgetChoice.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index 2b5437e46..df255b46b 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -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()); diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h index 957d289a7..fd447a780 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.h +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp index 80e6d670a..d857d2d66 100644 --- a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp @@ -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) diff --git a/src/ModuleBase/ModuleBase_WidgetFileSelector.h b/src/ModuleBase/ModuleBase_WidgetFileSelector.h index 5a628286d..4f64d215c 100644 --- a/src/ModuleBase/ModuleBase_WidgetFileSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetFileSelector.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_WidgetLabel.h b/src/ModuleBase/ModuleBase_WidgetLabel.h index fd0112ff1..0f6e00bac 100644 --- a/src/ModuleBase/ModuleBase_WidgetLabel.h +++ b/src/ModuleBase/ModuleBase_WidgetLabel.h @@ -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; } diff --git a/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp b/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp index 91af0aa94..c25c3befa 100644 --- a/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp +++ b/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp @@ -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) diff --git a/src/ModuleBase/ModuleBase_WidgetLineEdit.h b/src/ModuleBase/ModuleBase_WidgetLineEdit.h index 657b22be0..1789b0e43 100644 --- a/src/ModuleBase/ModuleBase_WidgetLineEdit.h +++ b/src/ModuleBase/ModuleBase_WidgetLineEdit.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index a11725988..bd9d0d702 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -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) diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index 3b092d424..84dc2b7dc 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 7031b5c1e..9dc8c5063 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -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 { diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index f57f5664b..2e6b2cc9a 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -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(); diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 226205b7c..3427122e9 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -114,7 +114,7 @@ void fillFeature2Attribute(const QList& 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& 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(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(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(); +} diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 7feca59fb..69e3dcd70 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -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; }; diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 60b644e08..a6178e876 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -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 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); } diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index de3ab120d..f07c60fc9 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -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(); diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index 2f9bb3e95..76561e4e6 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -16,7 +16,7 @@ #include -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 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 diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 0fa5c18f0..3a8f21a39 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -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; }