]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #478 Problem of performance with selection: remove last instead of clearing...
authornds <natalia.donis@opencascade.com>
Wed, 19 Aug 2015 10:52:32 +0000 (13:52 +0300)
committernds <natalia.donis@opencascade.com>
Wed, 19 Aug 2015 10:52:32 +0000 (13:52 +0300)
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/PartSet/PartSet_WidgetMultiSelector.cpp
src/PartSet/PartSet_WidgetMultiSelector.h

index 98f45e37081cd3d54bb193b39feb7f3a44b59c44..362d3d8a35f086054a58e39d25a2a830e90c36bf 100644 (file)
@@ -36,6 +36,8 @@
 #include <memory>
 #include <string>
 
+//#define DEBUG_ATTRIBUTE_SELECTION
+
 //#define DEBUG_SHAPE_VALIDATION_PREVIOUS
 
 class CustomListWidget : public QListWidget
@@ -66,7 +68,7 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen
                                                                const Config_WidgetAPI* theData,
                                                                const std::string& theParentId)
  : ModuleBase_WidgetSelector(theParent, theWorkshop, theData, theParentId),
-   mySelectionType(""), mySelectionCount(0)
+   mySelectionCount(0)
 {
   QGridLayout* aMainLay = new QGridLayout(this);
   ModuleBase_Tools::adjustMargins(aMainLay);
@@ -150,6 +152,8 @@ bool ModuleBase_WidgetMultiSelector::storeValueCustom() const
 //********************************************************************
 bool ModuleBase_WidgetMultiSelector::restoreValueCustom()
 {
+  myIsInValidate = false;
+
   // A rare case when plugin was not loaded. 
   if(!myFeature)
     return false;
@@ -170,6 +174,7 @@ bool ModuleBase_WidgetMultiSelector::restoreValueCustom()
 //********************************************************************
 void ModuleBase_WidgetMultiSelector::storeAttributeValue()
 {
+  myIsInValidate = true;
   DataPtr aData = myFeature->data();
   AttributeSelectionListPtr aSelectionListAttr = 
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
@@ -177,14 +182,17 @@ void ModuleBase_WidgetMultiSelector::storeAttributeValue()
     return;
 
   mySelectionType = aSelectionListAttr->selectionType();
-  mySelectionCount = aSelectionListAttr->size();
 
-  /*mySelection.clear();
+#ifdef DEBUG_ATTRIBUTE_SELECTION
+  mySelection.clear();
   int aSize = aSelectionListAttr->size();
   for (int i = 0; i < aSelectionListAttr->size(); i++) {
     AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i);
     mySelection.append(GeomSelection(aSelectAttr->context(), aSelectAttr->value()));
-  }*/
+  }
+#else
+  mySelectionCount = aSelectionListAttr->size();
+#endif
 }
 
 //********************************************************************
@@ -204,14 +212,16 @@ void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject,
   AttributeSelectionListPtr aSelectionListAttr = 
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
 
+  int aSelCount = aSelectionListAttr->size();
   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
-  aSelectionListAttr->append(aResult, theShape);
+  aSelectionListAttr->append(aResult, theShape/*, myIsInValidate*/);
 }
 
 //********************************************************************
 void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/)
 {
-  //clearAttribute();
+#ifdef DEBUG_ATTRIBUTE_SELECTION
+  clearAttribute();
 
   // Store shape type
   DataPtr aData = myFeature->data();
@@ -220,14 +230,21 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/)
   aSelectionListAttr->setSelectionType(mySelectionType);
 
   // Store selection in the attribute
-  //int aSize = mySelection.size();
-  //foreach (GeomSelection aSelec, mySelection) {
-  //  setObject(aSelec.first, aSelec.second);
-  //}
+  foreach (GeomSelection aSelec, mySelection) {
+    setObject(aSelec.first, aSelec.second);
+  }
+#else
+  // Store shape type
+  DataPtr aData = myFeature->data();
+  AttributeSelectionListPtr aSelectionListAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aData->attribute(attributeID()));
+  aSelectionListAttr->setSelectionType(mySelectionType);
 
-  //int aCountAppened = aSelectionListAttr->size() - mySelectionCount;
-  //for ( int i = 0; i < aCountAppened; i++)
-  //  aSelectionListAttr->removeLast();
+  // restore selection in the attribute
+  int aCountAppened = aSelectionListAttr->size() - mySelectionCount;
+  for ( int i = 0; i < aCountAppened; i++)
+    aSelectionListAttr->removeLast();
+#endif
 }
 
 //********************************************************************
index d44edff7d13712196dd8a87d0760da975a869b69..03e07588280b8c813be2872da1a872a59c3d6dff 100644 (file)
@@ -162,8 +162,9 @@ protected:
   std::string mySelectionType;
 
   /// Variable of GeomSelection
-  //QList<GeomSelection> mySelection;
+  QList<GeomSelection> mySelection;
   int mySelectionCount; // number of elements in the attribute selection list when store
+  bool myIsInValidate; // the widget is in validation mode: store is performed, restore is not
 
   bool myIsUseChoice;
 };
index 0a5eb7f9e0b69e2eab62ea99afdec3e1d7a93dc2..91404aaebde88301819ba5de21ee1980871ec6d4 100644 (file)
@@ -74,17 +74,9 @@ bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_Viewer
   return aValid;
 }
 
-//********************************************************************
-void PartSet_WidgetMultiSelector::storeAttributeValue()
-{
-  myIsInVaildate = true;
-  ModuleBase_WidgetMultiSelector::storeAttributeValue();
-}
-
 //********************************************************************
 void PartSet_WidgetMultiSelector::restoreAttributeValue(const bool theValid)
 {
-  myIsInVaildate = false;
   ModuleBase_WidgetMultiSelector::restoreAttributeValue(theValid);
 
   myExternalObjectMgr->removeExternalValidated(sketch(), myFeature, myWorkshop);
@@ -109,7 +101,7 @@ void PartSet_WidgetMultiSelector::getGeomSelection(const ModuleBase_ViewerPrs& t
         aShape = aResult->shape();
     }
     if (aShape.get() != NULL && !aShape->isNull()) {
-      if (myIsInVaildate)
+      if (myIsInValidate)
         theObject = myExternalObjectMgr->externalObjectValidated(theObject, aShape, sketch());
       else
         theObject = myExternalObjectMgr->externalObject(theObject, aShape, sketch());
index e0479547ed5b09fda35eb3d9ca34c9b03d73dc5c..bc2b97ac356a8fb465d609133c4e3b9031079ff6 100644 (file)
@@ -58,11 +58,6 @@ protected:
   /// \return a boolean value
   virtual bool isValidSelectionCustom(const ModuleBase_ViewerPrs& thePrs);
 
-  /// Creates a backup of the current values of the attribute
-  /// It should be realized in the specific widget because of different
-  /// parameters of the current attribute
-  virtual void storeAttributeValue();
-
   /// Creates a backup of the current values of the attribute
   /// It should be realized in the specific widget because of different
   /// parameters of the current attribute
@@ -81,8 +76,6 @@ protected:
   PartSet_ExternalObjectsMgr* myExternalObjectMgr;
   /// Pointer to a sketch 
   CompositeFeaturePtr mySketch;
-
-  bool myIsInVaildate;
 };
 
 #endif
\ No newline at end of file