From 2f86be51c890074b44f82d3ee46e98e9a565f246 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 17 Jun 2015 14:15:41 +0300 Subject: [PATCH] Preselection using in operations: setSelection of widget returns a modified list of selected presentations. This is especially useful for multi-selection control, which should process all possible selected presentations and give back non-used. --- .../ConstructionPlugin_Axis.cpp | 4 +++ src/ConstructionPlugin/axis_widget.xml | 2 ++ .../GeomValidators_ConstructionComposite.cpp | 9 +++++- src/ModuleBase/ModuleBase_ModelWidget.cpp | 4 +-- src/ModuleBase/ModuleBase_ModelWidget.h | 19 ++++++------ src/ModuleBase/ModuleBase_Operation.cpp | 10 ++++-- .../ModuleBase_WidgetMultiSelector.cpp | 31 ++++++++++--------- .../ModuleBase_WidgetMultiSelector.h | 3 +- src/ModuleBase/ModuleBase_WidgetToolbox.h | 5 +++ src/ModuleBase/ModuleBase_WidgetValidated.cpp | 16 +++++----- src/ModuleBase/ModuleBase_WidgetValidated.h | 5 +-- src/PartSet/PartSet_WidgetPoint2d.cpp | 8 ++--- src/PartSet/PartSet_WidgetPoint2d.h | 4 +-- src/PartSet/PartSet_WidgetSketchLabel.cpp | 4 +-- src/PartSet/PartSet_WidgetSketchLabel.h | 3 +- 15 files changed, 73 insertions(+), 54 deletions(-) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index 280da1e7f..e97fba83e 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -44,7 +44,11 @@ void ConstructionPlugin_Axis::createAxisByTwoPoints() AttributeSelectionPtr aRef2 = data()->selection(ConstructionPlugin_Axis::POINT_SECOND()); if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) { GeomShapePtr aShape1 = aRef1->value(); + if (!aShape1.get()) + aShape1 = aRef1->context()->shape(); GeomShapePtr aShape2 = aRef2->value(); + if (!aShape2.get()) + aShape2 = aRef2->context()->shape(); if (aShape1->isVertex() && aShape2->isVertex() && (!aShape1->isEqual(aShape2))) { std::shared_ptr aStart = GeomAlgoAPI_PointBuilder::point(aShape1); std::shared_ptr anEnd = GeomAlgoAPI_PointBuilder::point(aShape2); diff --git a/src/ConstructionPlugin/axis_widget.xml b/src/ConstructionPlugin/axis_widget.xml index 97796f302..86afa3473 100644 --- a/src/ConstructionPlugin/axis_widget.xml +++ b/src/ConstructionPlugin/axis_widget.xml @@ -9,6 +9,7 @@ tooltip="Select a first point" shape_types="vertex"> + + diff --git a/src/GeomValidators/GeomValidators_ConstructionComposite.cpp b/src/GeomValidators/GeomValidators_ConstructionComposite.cpp index fea231992..16fd4a2e9 100644 --- a/src/GeomValidators/GeomValidators_ConstructionComposite.cpp +++ b/src/GeomValidators/GeomValidators_ConstructionComposite.cpp @@ -26,7 +26,14 @@ bool GeomValidators_ConstructionComposite::isValid(const AttributePtr& theAttrib // It is a GeomAPI_Vertex shape for the point. The shape of the parameter is // GeomAPI_Shape. It is important to use the realization of the isEqual method from // GeomAPI_Vertex class - aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape); + if (aShape.get()) { + aValid = aShapePtr.get() != NULL && aShapePtr->isEqual(aShape); + } + else { + // an empty shape is used in attribute selection if the shape of the result is equal to + // the selected shape, so according to the upper condifition, the result is true + aValid = true; + } } if (!aValid) { ResultConstructionPtr aConstr = diff --git a/src/ModuleBase/ModuleBase_ModelWidget.cpp b/src/ModuleBase/ModuleBase_ModelWidget.cpp index b22c1f3b1..f3818ed52 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.cpp +++ b/src/ModuleBase/ModuleBase_ModelWidget.cpp @@ -139,14 +139,14 @@ bool ModuleBase_ModelWidget::storeValue() return isDone; } -void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) const +void ModuleBase_ModelWidget::updateObject(ObjectPtr theObj) { Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent); } -void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj) const +void ModuleBase_ModelWidget::moveObject(ObjectPtr theObj) { static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED); ModelAPI_EventCreator::get()->sendUpdated(theObj, anEvent); diff --git a/src/ModuleBase/ModuleBase_ModelWidget.h b/src/ModuleBase/ModuleBase_ModelWidget.h index 615fdb152..ce5eb8067 100644 --- a/src/ModuleBase/ModuleBase_ModelWidget.h +++ b/src/ModuleBase/ModuleBase_ModelWidget.h @@ -81,8 +81,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 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 setSelection(QList& theValues) { return false; } @@ -145,6 +144,14 @@ Q_OBJECT /// \return Current Editing mode bool isEditingMode() const { return myIsEditing; } + /// Sends Update and Redisplay for the given object + /// \param theObj is updating object + static void updateObject(ObjectPtr theObj); + + /// Sends Move event for the given object + /// \param theObj is object for moving + static void moveObject(ObjectPtr theObj); + signals: /// The signal about widget values are to be changed void beforeValuesChanged(); @@ -187,14 +194,6 @@ signals: /// The methiod called when widget is activated virtual void activateCustom() {}; - /// Sends Update and Redisplay for the given object - /// \param theObj is updating object - void updateObject(ObjectPtr theObj) const; - - /// Sends Move event for the given object - /// \param theObj is object for moving - void moveObject(ObjectPtr theObj) const; - protected slots: /// Processing of values changed in model widget by store the current value to the feature void onWidgetValuesChanged(); diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 492637ba5..3f9e149ed 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -277,18 +277,17 @@ void ModuleBase_Operation::activateByPreselection() myPropertyPanel->activateNextWidget(NULL); return; } - + ModuleBase_ModelWidget* aWgt, *aFilledWgt = 0; QList::const_iterator aWIt; bool isSet = false; // 1. apply the selection to controls - int aCurrentPosition = 0; for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) { aWgt = (*aWIt); if (!aWgt->canSetValue()) continue; - if (!aWgt->setSelection(myPreSelection, aCurrentPosition/*aValue*/)) { + if (!aWgt->setSelection(myPreSelection)) { isSet = false; break; } else { @@ -296,6 +295,11 @@ void ModuleBase_Operation::activateByPreselection() aFilledWgt = aWgt; } } + // in order to redisplay object in the viewer, the update/redisplay signals should be flushed + // it is better to perform it not in setSelection of each widget, but do it here, + // after the preselection is processed + ModuleBase_ModelWidget::updateObject(myFeature); + // 2. ignore not obligatory widgets /*for (; aWIt != aWidgets.constEnd(); ++aWIt) { aWgt = (*aWIt); diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 6f413e634..2720e55cf 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -262,33 +262,34 @@ bool ModuleBase_WidgetMultiSelector::acceptSubShape(const TopoDS_Shape& theShape } //******************************************************************** -bool ModuleBase_WidgetMultiSelector::setSelection(const QList& theValues, - int& thePosition) +bool ModuleBase_WidgetMultiSelector::setSelection(QList& theValues) { - if (thePosition < 0) - return false; + QList aSkippedValues; 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]; + for (; anIt != aLast; anIt++) { + ModuleBase_ViewerPrs aValue = *anIt; bool aProcessed = false; if (isValidSelection(aValue)) { aProcessed = setSelectionCustom(aValue); } + else + aSkippedValues.append(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; - else - thePosition++; } - if (isDone) { - updateObject(myFeature); + // updateObject - to update/redisplay feature + // it is commented in order to perfom it outside the method + //if (isDone) { + //updateObject(myFeature); // this emit is necessary to call store/restore method an restore type of selection - emit valuesChanged(); - } + //emit valuesChanged(); + //} + theValues.clear(); + if (!aSkippedValues.empty()) + theValues.append(aSkippedValues); + return isDone; } diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index c6c6a5c3b..9d569d2c4 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -78,8 +78,7 @@ class MODULEBASE_EXPORT ModuleBase_WidgetMultiSelector : public ModuleBase_Widge /// 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); + virtual bool setSelection(QList& theValues); /// Checks the widget validity. By default, it returns true. /// \param theValue a selected presentation in the view diff --git a/src/ModuleBase/ModuleBase_WidgetToolbox.h b/src/ModuleBase/ModuleBase_WidgetToolbox.h index 639e90f14..b315e5d3a 100644 --- a/src/ModuleBase/ModuleBase_WidgetToolbox.h +++ b/src/ModuleBase/ModuleBase_WidgetToolbox.h @@ -22,6 +22,11 @@ class MODULEBASE_EXPORT ModuleBase_WidgetToolbox : public ModuleBase_PagedContai ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId); virtual ~ModuleBase_WidgetToolbox(); + + /// Defines if it is supported to set the value in this widget + /// It returns false because this is an info widget + virtual bool canSetValue() const { return false; }; + /// Overrides ModuleBase_PagedContainer int addPage(ModuleBase_PageBase* theWidget, const QString& theName, const QString& theCaseId); diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index b329e36c9..1225e1282 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -29,19 +29,21 @@ ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated() } //******************************************************************** -bool ModuleBase_WidgetValidated::setSelection(const QList& theValues, int& thePosition) +bool ModuleBase_WidgetValidated::setSelection(QList& theValues) { - if (thePosition < 0 || thePosition >= theValues.size()) + if (theValues.empty()) return false; - ModuleBase_ViewerPrs aValue = theValues[thePosition]; - thePosition++; - + // it removes the processed value from the parameters list + ModuleBase_ViewerPrs aValue = theValues.takeFirst(); bool isDone = false; if (isValidSelection(aValue)) { isDone = setSelectionCustom(aValue); - updateObject(myFeature); - emit valuesChanged(); + // updateObject - to update/redisplay feature + // it is commented in order to perfom it outside the method + //updateObject(myFeature); + // to storeValue() + //emit valuesChanged(); } return isDone; } diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.h b/src/ModuleBase/ModuleBase_WidgetValidated.h index e13fb166f..bacba1887 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.h +++ b/src/ModuleBase/ModuleBase_WidgetValidated.h @@ -50,8 +50,7 @@ class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidg /// 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 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 setSelection(QList& theValues); protected: /// Creates a backup of the current values of the attribute @@ -74,8 +73,6 @@ protected: /// \param theOwner a selected owner virtual bool setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) = 0; - virtual void removePresentations() {}; - /// Checks the current attibute in all attribute validators // \return true if all validators return that the attribute is valid bool isValidAttribute() const; diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index df7aab9dc..964303fcd 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -125,12 +125,12 @@ PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D() { } -bool PartSet_WidgetPoint2D::setSelection(const QList& theValues, int& thePosition) +bool PartSet_WidgetPoint2D::setSelection(QList& theValues) { - if (thePosition < 0 || thePosition >= theValues.size()) + if (theValues.empty()) return false; - ModuleBase_ViewerPrs aValue = theValues[thePosition]; - thePosition++; + + ModuleBase_ViewerPrs aValue = theValues.takeFirst(); Handle(V3d_View) aView = myWorkshop->viewer()->activeView(); bool isDone = false; diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index 75c617ca0..21f9738b4 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -52,8 +52,8 @@ 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(const QList& theValues, int& thePosition); + /// \param theValues the wrapped widget values + virtual bool setSelection(QList& theValues); virtual bool restoreValue(); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index e72f1bff5..9e659086c 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -81,7 +81,7 @@ PartSet_WidgetSketchLabel::~PartSet_WidgetSketchLabel() erasePreviewPlanes(); } -bool PartSet_WidgetSketchLabel::setSelection(const QList& theValues, int& thePosition) +bool PartSet_WidgetSketchLabel::setSelection(QList& theValues) { // 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 @@ -89,7 +89,7 @@ bool PartSet_WidgetSketchLabel::setSelection(const QList& if (plane().get()) return true; - return ModuleBase_WidgetValidated::setSelection(theValues, thePosition); + return ModuleBase_WidgetValidated::setSelection(theValues); } QList PartSet_WidgetSketchLabel::getControls() const diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 0dc7c07f6..4074ad53d 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -52,8 +52,7 @@ Q_OBJECT /// 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 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 setSelection(QList& theValues); virtual bool restoreValue() { -- 2.39.2