From: nds Date: Thu, 30 Apr 2015 19:05:38 +0000 (+0300) Subject: Preselection realization for multi-selector widget to accept some selection values. X-Git-Tag: V_1.2.0~176 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=01d6bb2a163b2c89e86444bc8b4f1a24a58e4c2a;p=modules%2Fshaper.git Preselection realization for multi-selector widget to accept some selection values. --- diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 8adb5bc76..a6ad2ca97 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -73,8 +73,9 @@ Q_OBJECT /// Set the given wrapped value to the current widget /// This value should be processed in the widget according to the needs - /// \param theValue the wrapped widget value - virtual bool setSelection(ModuleBase_ViewerPrs theValue) + /// \param theValues the wrapped selection values + /// \param thePosition an index in the list of values, the values should be get from the index + virtual bool setSelection(const QList& theValues, int& thePosition) { return false; } diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 1016d90e8..b934df130 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -216,19 +216,15 @@ void ModuleBase_Operation::activateByPreselection() ModuleBase_ModelWidget* aWgt, *aFilledWgt = 0; QList::const_iterator aWIt; - QList::const_iterator aPIt; bool isSet = false; // 1. apply the selection to controls - for (aWIt = aWidgets.constBegin(), aPIt = myPreSelection.constBegin(); - (aWIt != aWidgets.constEnd()) && (aPIt != myPreSelection.constEnd()); - ++aWIt) { + int aCurrentPosition = 0; + for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) { aWgt = (*aWIt); - ModuleBase_ViewerPrs aValue = (*aPIt); if (!aWgt->canSetValue()) continue; - ++aPIt; - if (!aWgt->setSelection(aValue)) { + if (!aWgt->setSelection(myPreSelection, aCurrentPosition/*aValue*/)) { isSet = false; break; } else { diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 57e2ce949..c2e3138a5 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -194,6 +194,35 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/) } } +//******************************************************************** +bool ModuleBase_WidgetMultiSelector::setSelection(const QList& theValues, + int& thePosition) +{ + if (thePosition < 0) + return false; + + QList::const_iterator anIt = theValues.begin(), aLast = theValues.end(); + bool isDone = false; + for (int i = thePosition; i < theValues.size(); i++) { + ModuleBase_ViewerPrs aValue = theValues[i]; + thePosition++; + bool aProcessed = false; + if (isValidSelection(aValue)) { + aProcessed = setSelectionCustom(aValue); + } + // if there is at least one set, the result is true + isDone = isDone || aProcessed; + // when an object, which do not satisfy the validating process, stop set selection + if (!aProcessed) + break; + } + if (isDone) { + updateObject(myFeature); + emit valuesChanged(); + } + return isDone; +} + //******************************************************************** bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) { diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index cc702f6a1..778755c61 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -72,6 +72,12 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge /// The methiod called when widget is deactivated virtual void deactivate(); + /// Set the given wrapped value to the current widget + /// This value should be processed in the widget according to the needs + /// \param theValues the wrapped selection values + /// \param thePosition an index in the list of values, the values should be get from the index + virtual bool setSelection(const QList& theValues, int& thePosition); + /// Fills the attribute with the value of the selected owner /// \param theOwner a selected owner virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs); diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index caadc6be7..a5ec4c5fe 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -29,12 +29,17 @@ ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated() } //******************************************************************** -bool ModuleBase_WidgetValidated::setSelection(ModuleBase_ViewerPrs theValue) +bool ModuleBase_WidgetValidated::setSelection(const QList& theValues, int& thePosition) { + if (thePosition < 0 || thePosition >= theValues.size()) + return false; + ModuleBase_ViewerPrs aValue = theValues[thePosition]; + thePosition++; + bool isDone = false; - if (isValidSelection(theValue)) { - isDone = setSelectionCustom(theValue); + if (isValidSelection(aValue)) { + isDone = setSelectionCustom(aValue); updateObject(myFeature); emit valuesChanged(); } diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.h b/src/ModuleBase/ModuleBase_WidgetValidated.h index 8c05cbb04..95f558029 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.h +++ b/src/ModuleBase/ModuleBase_WidgetValidated.h @@ -48,8 +48,9 @@ class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidg /// This value should be processed in the widget according to the needs /// The method is called by the current operation to process the operation preselection. /// It is redefined to check the value validity and if it is, fill the attribute with by value - /// \param theValue the wrapped widget value - virtual bool setSelection(ModuleBase_ViewerPrs theValue); + /// \param theValues the wrapped selection values + /// \param thePosition an index in the list of values, the values should be get from the index + virtual bool setSelection(const QList& theValues, int& thePosition); protected: /// Creates a backup of the current values of the attribute diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 10f6de95f..b49330a6b 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -120,11 +120,16 @@ PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D() { } -bool PartSet_WidgetPoint2D::setSelection(ModuleBase_ViewerPrs theValue) +bool PartSet_WidgetPoint2D::setSelection(const QList& theValues, int& thePosition) { + if (thePosition < 0 || thePosition >= theValues.size()) + return false; + ModuleBase_ViewerPrs aValue = theValues[thePosition]; + thePosition++; + Handle(V3d_View) aView = myWorkshop->viewer()->activeView(); bool isDone = false; - TopoDS_Shape aShape = theValue.shape(); + TopoDS_Shape aShape = aValue.shape(); double aX, aY; if (getPoint2d(aView, aShape, aX, aY)) { isDone = setPoint(aX, aY); diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index e39011c90..a2fe2aa8d 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -53,7 +53,7 @@ Q_OBJECT /// Set the given wrapped value to the current widget /// This value should be processed in the widget according to the needs /// \param theValue the wrapped widget value - virtual bool setSelection(ModuleBase_ViewerPrs theValue); + virtual bool setSelection(const QList& theValues, int& thePosition); virtual bool restoreValue(); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index ceeeb6bff..c2ca8a4d2 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -85,7 +85,7 @@ PartSet_WidgetSketchLabel::~PartSet_WidgetSketchLabel() erasePreviewPlanes(); } -bool PartSet_WidgetSketchLabel::setSelection(ModuleBase_ViewerPrs theValue) +bool PartSet_WidgetSketchLabel::setSelection(const QList& theValues, int& thePosition) { // do not use the given selection if the plane of the sketch has been already set. // If this check is absent, a selected plane in the viewer can be set in the sketch @@ -93,7 +93,7 @@ bool PartSet_WidgetSketchLabel::setSelection(ModuleBase_ViewerPrs theValue) if (plane().get()) return true; - return ModuleBase_WidgetValidated::setSelection(theValue); + return ModuleBase_WidgetValidated::setSelection(theValues, thePosition); } QList PartSet_WidgetSketchLabel::getControls() const diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index eea79ea6d..6a39f0489 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -52,8 +52,9 @@ Q_OBJECT /// This value should be processed in the widget according to the needs /// The method is called by the current operation to process the operation preselection. /// It is redefined to do nothing if the plane of the sketch has been already set. - /// \param theValue the wrapped widget value - virtual bool setSelection(ModuleBase_ViewerPrs theValue); + /// \param theValues the wrapped selection values + /// \param thePosition an index in the list of values, the values should be get from the index + virtual bool setSelection(const QList& theValues, int& thePosition); virtual bool restoreValue() {