From: nds Date: Thu, 21 May 2015 07:19:07 +0000 (+0300) Subject: Code improvement: separate restore selection functionality in an additional method X-Git-Tag: V_1.2.0~129 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=280c1af2a22929a7dc6e1b980b8c160ac4d9166d;p=modules%2Fshaper.git Code improvement: separate restore selection functionality in an additional method --- diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 2e01ee941..57c4d06dc 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -107,28 +107,9 @@ void ModuleBase_WidgetMultiSelector::activateCustom() Qt::UniqueConnection); activateShapeSelection(true); - QList aSelected; + // Restore selection in the viewer by the attribute selection list - if(myFeature) { - DataPtr aData = myFeature->data(); - AttributeSelectionListPtr aListAttr = - std::dynamic_pointer_cast(aData->attribute(attributeID())); - if (aListAttr) { - for (int i = 0; i < aListAttr->size(); i++) { - AttributeSelectionPtr anAttr = aListAttr->value(i); - ResultPtr anObject = anAttr->context(); - if (anObject.get()) { - TopoDS_Shape aShape; - std::shared_ptr aShapePtr = anAttr->value(); - if (aShapePtr.get()) { - aShape = aShapePtr->impl(); - } - aSelected.append(ModuleBase_ViewerPrs(anObject, aShape, NULL)); - } - } - } - } - myWorkshop->setSelected(aSelected); + myWorkshop->setSelected(getCurrentSelection()); activateFilters(myWorkshop, true); } @@ -392,6 +373,32 @@ void ModuleBase_WidgetMultiSelector::activateShapeSelection(const bool isActivat } } +QList ModuleBase_WidgetMultiSelector::getCurrentSelection() const +{ + QList aSelected; + // Restore selection in the viewer by the attribute selection list + if(myFeature) { + DataPtr aData = myFeature->data(); + AttributeSelectionListPtr aListAttr = + std::dynamic_pointer_cast(aData->attribute(attributeID())); + if (aListAttr) { + for (int i = 0; i < aListAttr->size(); i++) { + AttributeSelectionPtr anAttr = aListAttr->value(i); + ResultPtr anObject = anAttr->context(); + if (anObject.get()) { + TopoDS_Shape aShape; + std::shared_ptr aShapePtr = anAttr->value(); + if (aShapePtr.get()) { + aShape = aShapePtr->impl(); + } + aSelected.append(ModuleBase_ViewerPrs(anObject, aShape, NULL)); + } + } + } + } + return aSelected; +} + //******************************************************************** void ModuleBase_WidgetMultiSelector::updateSelectionList(AttributeSelectionListPtr theList) { diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index 1a98c238e..fe665938f 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -122,6 +122,11 @@ protected slots: /// \param isActivated a state whether the shape is activated or deactivated in selection void activateShapeSelection(const bool isActivated); + /// Return the attribute values wrapped in a list of viewer presentations + /// \return a list of viewer presentations, which contains an attribute result and + /// a shape. If the attribute do not uses the shape, it is empty + QList getCurrentSelection() const; + protected: /// Update selection list void updateSelectionList(AttributeSelectionListPtr); diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 91cc1f01f..9d80e0f79 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -146,6 +146,26 @@ bool ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, return isChanged; } +//******************************************************************** +QList ModuleBase_WidgetShapeSelector::getCurrentSelection() const +{ + QList aSelected; + if(myFeature) { + DataPtr aData = myFeature->data(); + AttributePtr anAttribute = myFeature->attribute(attributeID()); + + ObjectPtr anObject = GeomValidators_Tools::getObject(anAttribute); + TopoDS_Shape aShape; + std::shared_ptr aShapePtr = getShape(); + if (aShapePtr.get()) { + aShape = aShapePtr->impl(); + } + ModuleBase_ViewerPrs aPrs(anObject, aShape, NULL); + aSelected.append(aPrs); + } + return aSelected; +} + //******************************************************************** void ModuleBase_WidgetShapeSelector::clearAttribute() { @@ -308,22 +328,9 @@ void ModuleBase_WidgetShapeSelector::activateCustom() { connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); activateSelection(true); - // Restore selection in the viewer by the attribute selection list - QList aSelected; - if(myFeature) { - DataPtr aData = myFeature->data(); - AttributePtr anAttribute = myFeature->attribute(attributeID()); - ObjectPtr anObject = GeomValidators_Tools::getObject(anAttribute); - TopoDS_Shape aShape; - std::shared_ptr aShapePtr = getShape(); - if (aShapePtr.get()) { - aShape = aShapePtr->impl(); - } - ModuleBase_ViewerPrs aPrs(anObject, aShape, NULL); - aSelected.append(aPrs); - } - myWorkshop->setSelected(aSelected); + // Restore selection in the viewer by the attribute selection list + myWorkshop->setSelected(getCurrentSelection()); activateFilters(myWorkshop, true); } diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index 86a7b7312..66d766d9f 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -136,6 +136,11 @@ Q_OBJECT /// \return true if it is succeed virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape); + /// Return the attribute values wrapped in a list of viewer presentations + /// \return a list of viewer presentations, which contains an attribute result and + /// a shape. If the attribute do not uses the shape, it is empty + QList getCurrentSelection() const; + //----------- Class members ------------- protected: /// Label of the widget