Salome HOME
Issue #1351: partition is not done
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetMultiSelector.cpp
index 2a999aeb25eeddb195561c608db44f49b5017769..40518a2ca9dcfc573c8af708a769180f931f51dd 100755 (executable)
@@ -281,12 +281,12 @@ void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject,
   if (aType == ModelAPI_AttributeSelectionList::typeId()) {
     AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theSelectedObject);
-    //if (!aSelectionListAttr->isInList(aResult, theShape, myIsInValidate))
+    if (!aSelectionListAttr->isInList(aResult, theShape, myIsInValidate))
       aSelectionListAttr->append(aResult, theShape, myIsInValidate);
   }
   else if (aType == ModelAPI_AttributeRefList::typeId()) {
     AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
-    //if (!aRefListAttr->isInList(theSelectedObject))
+    if (!aRefListAttr->isInList(theSelectedObject))
       aRefListAttr->append(theSelectedObject);
   }
   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
@@ -294,11 +294,11 @@ void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject,
     AttributePtr anAttribute = myWorkshop->module()->findAttribute(theSelectedObject, theShape);
 
     if (anAttribute.get()) {
-      //if (!aRefAttrListAttr->isInList(anAttribute))
+      if (!aRefAttrListAttr->isInList(anAttribute))
         aRefAttrListAttr->append(anAttribute);
     }
     else {
-      //if (!aRefAttrListAttr->isInList(theSelectedObject))
+      if (!aRefAttrListAttr->isInList(theSelectedObject))
         aRefAttrListAttr->append(theSelectedObject);
     }
   }
@@ -310,6 +310,10 @@ bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& t
 {
   QList<ModuleBase_ViewerPrs> aSkippedValues;
 
+  /// remove unused objects from the model attribute.
+  /// It should be performed before new attributes append.
+  removeUnusedAttributeObjects(theValues);
+
   QList<ModuleBase_ViewerPrs>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
   bool isDone = false;
   for (; anIt != aLast; anIt++) {
@@ -331,9 +335,6 @@ bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& t
     //emit valuesChanged();
   //}
 
-  /// remove unused objects from the model attribute
-  removeUnusedAttributeObjects(theValues);
-
   theValues.clear();
   if (!aSkippedValues.empty())
     theValues.append(aSkippedValues);
@@ -478,12 +479,12 @@ void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum
     aShapeTypeName = myTypeCombo->itemText(idx);
     TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName);
     if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) {
-      activateSelectionAndFilters(false);
+      bool aWasActivated = activateSelectionAndFilters(false);
       bool isBlocked = myTypeCombo->blockSignals(true);
       myTypeCombo->setCurrentIndex(idx);
       myTypeCombo->blockSignals(isBlocked);
-
-      activateSelectionAndFilters(true);
+      if (aWasActivated)
+        activateSelectionAndFilters(true);
       break;
     }
   }
@@ -676,7 +677,6 @@ void ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
                                                  (QList<ModuleBase_ViewerPrs>& theValues)
 {
   std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection = convertSelection(theValues);
-
   DataPtr aData = myFeature->data();
   AttributePtr anAttribute = aData->attribute(attributeID());
   std::string aType = anAttribute->attributeType();
@@ -706,23 +706,24 @@ void ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
     aRefListAttr->remove(anIndicesToBeRemoved);
   }
   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
-    /*AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
+    std::set<AttributePtr> anAttributes;
+    QList<ModuleBase_ViewerPrs>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
+    ObjectPtr anObject;
+    GeomShapePtr aShape;
+    for (; anIt != aLast; anIt++) {
+      ModuleBase_ViewerPrs aPrs = *anIt;
+      getGeomSelection(aPrs, anObject, aShape);
+      AttributePtr anAttr = myWorkshop->module()->findAttribute(anObject, aShape);
+      if (anAttr.get() && anAttributes.find(anAttr) == anAttributes.end())
+        anAttributes.insert(anAttr);
+    }
+
+    AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
     for (int i = 0; i < aRefAttrListAttr->size(); i++) {
       bool aFound = false;
       if (aRefAttrListAttr->isAttribute(i)) {
         AttributePtr anAttribute = aRefAttrListAttr->attribute(i);
-        ObjectPtr anAttrObject = anAttribute->owner();
-        if (aGeomSelection.find(anAttrObject) != aGeomSelection.end()) {
-          std::set<GeomShapePtr> aShapes = aGeomSelection[anAttrObject];
-          std::set<GeomShapePtr>::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
-          for (; anIt != aLast && !aFound; anIt++) {
-            GeomShapePtr aCShape = *anIt;
-            if (aCShape.get()) {
-              AttributePtr aCAttr = myWorkshop->module()->findAttribute(anAttrObject, aCShape);
-              aFound = aCAttr == anAttribute;
-            }
-          }
-        }
+        aFound = anAttributes.find(anAttribute) != anAttributes.end();
       }
       else {
         aFound = findInSelection(aRefAttrListAttr->object(i), GeomShapePtr(), aGeomSelection);
@@ -730,7 +731,7 @@ void ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
       if (!aFound)
         anIndicesToBeRemoved.insert(i);
     }
-    aRefAttrListAttr->remove(anIndicesToBeRemoved);*/
+    aRefAttrListAttr->remove(anIndicesToBeRemoved);
   }
 }