]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Code improvement: separate restore selection functionality in an additional method
authornds <natalia.donis@opencascade.com>
Thu, 21 May 2015 07:19:07 +0000 (10:19 +0300)
committernds <natalia.donis@opencascade.com>
Thu, 21 May 2015 07:19:07 +0000 (10:19 +0300)
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h

index 2e01ee941308cf260ed4c6c92f6076fffda8bfd2..57c4d06dc7ac42e4b68bc6df28b8a2ab466b5a6d 100644 (file)
@@ -107,28 +107,9 @@ void ModuleBase_WidgetMultiSelector::activateCustom()
           Qt::UniqueConnection);
 
   activateShapeSelection(true);
-  QList<ModuleBase_ViewerPrs> aSelected;
+
   // Restore selection in the viewer by the attribute selection list
-  if(myFeature) {
-    DataPtr aData = myFeature->data();
-    AttributeSelectionListPtr aListAttr = 
-      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(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<GeomAPI_Shape> aShapePtr = anAttr->value();
-          if (aShapePtr.get()) {
-            aShape = aShapePtr->impl<TopoDS_Shape>();
-          }
-          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_ViewerPrs> ModuleBase_WidgetMultiSelector::getCurrentSelection() const
+{
+  QList<ModuleBase_ViewerPrs> aSelected;
+  // Restore selection in the viewer by the attribute selection list
+  if(myFeature) {
+    DataPtr aData = myFeature->data();
+    AttributeSelectionListPtr aListAttr = 
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(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<GeomAPI_Shape> aShapePtr = anAttr->value();
+          if (aShapePtr.get()) {
+            aShape = aShapePtr->impl<TopoDS_Shape>();
+          }
+          aSelected.append(ModuleBase_ViewerPrs(anObject, aShape, NULL));
+        }
+      }
+    }
+  }
+  return aSelected;
+}
+
 //********************************************************************
 void ModuleBase_WidgetMultiSelector::updateSelectionList(AttributeSelectionListPtr theList)
 {
index 1a98c238e5cb726e130ec62f6647f0d44cd3a162..fe665938f0db5525026eef61f0f9980406b98b17 100644 (file)
@@ -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<ModuleBase_ViewerPrs> getCurrentSelection() const;
+
  protected:
    /// Update selection list
    void updateSelectionList(AttributeSelectionListPtr);
index 91cc1f01f5e0538e493c6b91ef00ed3fe939a348..9d80e0f79ef5250bab380d711dfe4a542fc54cbd 100644 (file)
@@ -146,6 +146,26 @@ bool ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject,
   return isChanged;
 }
 
+//********************************************************************
+QList<ModuleBase_ViewerPrs> ModuleBase_WidgetShapeSelector::getCurrentSelection() const
+{
+  QList<ModuleBase_ViewerPrs> aSelected;
+  if(myFeature) {
+    DataPtr aData = myFeature->data();
+    AttributePtr anAttribute = myFeature->attribute(attributeID());
+
+    ObjectPtr anObject = GeomValidators_Tools::getObject(anAttribute);
+    TopoDS_Shape aShape;
+    std::shared_ptr<GeomAPI_Shape> aShapePtr = getShape();
+    if (aShapePtr.get()) {
+      aShape = aShapePtr->impl<TopoDS_Shape>();
+    }
+    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<ModuleBase_ViewerPrs> aSelected;
-  if(myFeature) {
-    DataPtr aData = myFeature->data();
-    AttributePtr anAttribute = myFeature->attribute(attributeID());
 
-    ObjectPtr anObject = GeomValidators_Tools::getObject(anAttribute);
-    TopoDS_Shape aShape;
-    std::shared_ptr<GeomAPI_Shape> aShapePtr = getShape();
-    if (aShapePtr.get()) {
-      aShape = aShapePtr->impl<TopoDS_Shape>();
-    }
-    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);
 }
index 86a7b7312e0ee1c87b23524d3bb92129d4acec73..66d766d9fba3fac26adffedf9710ef07af23e72a 100644 (file)
@@ -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<ModuleBase_ViewerPrs> getCurrentSelection() const;
+
   //----------- Class members -------------
   protected:
   /// Label of the widget