]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
#1330 Multiply selection when Create fillet using Shift button
authornds <nds@opencascade.com>
Fri, 26 Feb 2016 14:21:47 +0000 (17:21 +0300)
committernds <nds@opencascade.com>
Fri, 26 Feb 2016 14:22:12 +0000 (17:22 +0300)
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h
src/ModuleBase/ModuleBase_WidgetSelector.cpp
src/ModuleBase/ModuleBase_WidgetSelector.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/ModuleBase/ModuleBase_WidgetValidated.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp

index 9acca5255469efb03ff16b333712b22663b630ca..2a999aeb25eeddb195561c608db44f49b5017769 100755 (executable)
@@ -271,26 +271,6 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool theValid)
   }
 }
 
-//********************************************************************
-void ModuleBase_WidgetMultiSelector::clearAttribute()
-{
-  DataPtr aData = myFeature->data();
-  AttributePtr anAttribute = aData->attribute(attributeID());
-  std::string aType = anAttribute->attributeType();
-  if (aType == ModelAPI_AttributeSelectionList::typeId()) {
-    AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
-    aSelectionListAttr->clear();
-  }
-  else if (aType == ModelAPI_AttributeRefList::typeId()) {
-    AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
-    aRefListAttr->clear();
-  }
-  else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
-    AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
-    aRefAttrListAttr->clear();
-  }
-}
-
 //********************************************************************
 void ModuleBase_WidgetMultiSelector::setObject(ObjectPtr theSelectedObject,
                                                GeomShapePtr theShape)
@@ -301,20 +281,26 @@ 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);
-    aSelectionListAttr->append(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());
-    aRefListAttr->append(theSelectedObject);
+    //if (!aRefListAttr->isInList(theSelectedObject))
+      aRefListAttr->append(theSelectedObject);
   }
   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
     AttributeRefAttrListPtr aRefAttrListAttr = aData->refattrlist(attributeID());
-
     AttributePtr anAttribute = myWorkshop->module()->findAttribute(theSelectedObject, theShape);
-    if (anAttribute.get())
-      aRefAttrListAttr->append(anAttribute);
-    else
-      aRefAttrListAttr->append(theSelectedObject);
+
+    if (anAttribute.get()) {
+      //if (!aRefAttrListAttr->isInList(anAttribute))
+        aRefAttrListAttr->append(anAttribute);
+    }
+    else {
+      //if (!aRefAttrListAttr->isInList(theSelectedObject))
+        aRefAttrListAttr->append(theSelectedObject);
+    }
   }
 }
 
@@ -344,6 +330,10 @@ bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrs>& t
     // this emit is necessary to call store/restore method an restore type of selection
     //emit valuesChanged();
   //}
+
+  /// remove unused objects from the model attribute
+  removeUnusedAttributeObjects(theValues);
+
   theValues.clear();
   if (!aSkippedValues.empty())
     theValues.append(aSkippedValues);
@@ -681,3 +671,110 @@ void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set<in
     }
   }
 }
+
+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();
+  std::set<GeomShapePtr> aShapes;
+  std::set<int> anIndicesToBeRemoved;
+  if (aType == ModelAPI_AttributeSelectionList::typeId()) {
+    // iteration through data model to find not selected elements to remove them
+    AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(attributeID());
+    for (int i = 0; i < aSelectionListAttr->size(); i++) {
+      AttributeSelectionPtr anAttr = aSelectionListAttr->value(i);
+      bool aFound = findInSelection(anAttr->context(), anAttr->value(), aGeomSelection);
+      if (!aFound)
+        anIndicesToBeRemoved.insert(i);
+    }
+    aSelectionListAttr->remove(anIndicesToBeRemoved);
+  }
+  else if (aType == ModelAPI_AttributeRefList::typeId()) {
+    AttributeRefListPtr aRefListAttr = aData->reflist(attributeID());
+    for (int i = 0; i < aRefListAttr->size(); i++) {
+      ObjectPtr anObject = aRefListAttr->object(i);
+      if (anObject.get()) {
+        bool aFound = findInSelection(anObject, GeomShapePtr(), aGeomSelection);
+        if (!aFound)
+          anIndicesToBeRemoved.insert(i);
+      }
+    }
+    aRefListAttr->remove(anIndicesToBeRemoved);
+  }
+  else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
+    /*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;
+            }
+          }
+        }
+      }
+      else {
+        aFound = findInSelection(aRefAttrListAttr->object(i), GeomShapePtr(), aGeomSelection);
+      }
+      if (!aFound)
+        anIndicesToBeRemoved.insert(i);
+    }
+    aRefAttrListAttr->remove(anIndicesToBeRemoved);*/
+  }
+}
+
+std::map<ObjectPtr, std::set<GeomShapePtr> > ModuleBase_WidgetMultiSelector::convertSelection
+                                                     (QList<ModuleBase_ViewerPrs>& theValues)
+{
+  // convert prs list to objects map
+  std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection;
+  std::set<GeomShapePtr> aShapes;
+  QList<ModuleBase_ViewerPrs>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
+  ObjectPtr anObject;
+  GeomShapePtr aShape;
+  GeomShapePtr anEmptyShape(new GeomAPI_Shape());
+  for (; anIt != aLast; anIt++) {
+    ModuleBase_ViewerPrs aPrs = *anIt;
+    getGeomSelection(aPrs, anObject, aShape);
+    aShapes.clear();
+    if (aGeomSelection.find(anObject) != aGeomSelection.end()) // found
+      aShapes = aGeomSelection[anObject];
+    // we need to know if there was an empty shape in selection for the object
+    if (!aShape.get())
+      aShape = anEmptyShape;
+    if (aShape.get() && aShapes.find(aShape) == aShapes.end()) // not found
+      aShapes.insert(aShape);
+    aGeomSelection[anObject] = aShapes;
+  }
+  return aGeomSelection;
+}
+
+bool ModuleBase_WidgetMultiSelector::findInSelection(const ObjectPtr& theObject,
+                              const GeomShapePtr& theShape,
+                              const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection)
+{
+  bool aFound = false;
+  GeomShapePtr anEmptyShape(new GeomAPI_Shape());
+  GeomShapePtr aShape = theShape.get() ? theShape : anEmptyShape;
+  if (theGeomSelection.find(theObject) != theGeomSelection.end()) {// found
+    const std::set<GeomShapePtr>& aShapes = theGeomSelection.at(theObject);
+    std::set<GeomShapePtr>::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
+    for (; anIt != aLast && !aFound; anIt++) {
+      GeomShapePtr aCShape = *anIt;
+      if (aCShape.get())
+        aFound = aCShape->isEqual(aShape);
+    }
+  }
+  return aFound;
+}
index 7156e051789862a0df0d16e916005aa0ccc65be2..bebe4123b98cf30ddf8078088d33803dca11ce3b 100755 (executable)
@@ -116,9 +116,6 @@ protected:
   /// parameters of the current attribute
   virtual void storeAttributeValue();
 
-  /// Clear attribute
-  virtual void clearAttribute();
-
   /// Set the focus on the last item in  the list
   virtual void updateFocus();
 
@@ -168,6 +165,26 @@ protected:
   /// \param theValues the result presentations, filled with object and shape of an attribute item
   void convertIndicesToViewerSelection(std::set<int> theAttributeIds,
                                        QList<ModuleBase_ViewerPrs>& theValues) const;
+
+  /// Iterates throgh the model attribute list and remove elements which do not present in the list
+  /// \param theValues the wrapped selection values
+  virtual void removeUnusedAttributeObjects(QList<ModuleBase_ViewerPrs>& theValues);
+
+  /// Converts viewer presentation selection list to objects and shapes map
+  /// \param theValues the wrapped selection values
+  /// \return selection list
+  std::map<ObjectPtr, std::set<GeomShapePtr> > convertSelection
+                                          (QList<ModuleBase_ViewerPrs>& theValues);
+
+  /// Returns true if the object and shape present in the container
+  /// \param theObject a model object, a set of shapes is searched by it
+  /// \param theShape a shape to be in the set of the object shapes
+  /// \param theGeomSelection a map built on selection
+  /// \return boolean result
+  static bool findInSelection(const ObjectPtr& theObject,
+                            const GeomShapePtr& theShape,
+                            const std::map<ObjectPtr, std::set<GeomShapePtr> >& theGeomSelection);
+
 protected:
   /// List control
   QListWidget* myListControl;
index 8aed922a3b728e1e29430149f1c20528c3a0260e..53a7b5da8a35a154a8342778bbe64956c2305cf1 100755 (executable)
@@ -44,8 +44,6 @@ void ModuleBase_WidgetSelector::getGeomSelection(const ModuleBase_ViewerPrs& the
 //********************************************************************
 void ModuleBase_WidgetSelector::onSelectionChanged()
 {
-  clearAttribute();
-
   QList<ModuleBase_ViewerPrs> aSelected = getFilteredSelected();
 
   bool isDone = setSelection(aSelected, true/*false*/);
index 58cb33062030fe26c3bb28a875a1b0df5ecc4c53..e44a2dde367fc8b78dbbed3dbe1383ac8e86af74 100755 (executable)
@@ -63,9 +63,6 @@ Q_OBJECT
   void onSelectionChanged();
 
  protected:
-  /// Set an empty value to attribute
-  virtual void clearAttribute() = 0;
-
   /// Update focus after the attribute value change
   virtual void updateFocus() = 0;
 
index 13f071c21dca6f64278fd3301edd222514030ec3..b68e282b69630d35b31d42bb8790a3f5064adf2e 100644 (file)
@@ -160,13 +160,6 @@ QList<ModuleBase_ViewerPrs> ModuleBase_WidgetShapeSelector::getAttributeSelectio
   return aSelected;
 }
 
-//********************************************************************
-void ModuleBase_WidgetShapeSelector::clearAttribute()
-{
-  // In order to make reselection possible, set empty object and shape should be done
-  setObject(ObjectPtr(), std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape()));
-}
-
 //********************************************************************
 bool ModuleBase_WidgetShapeSelector::restoreValueCustom()
 {
index 2c8a10363e630fcade439ae6b895a0545e62459f..bcc247b0f9a7d37ee43fb5fdd0d4ddf46b6077fa 100644 (file)
@@ -94,9 +94,6 @@ Q_OBJECT
   /// Computes and updates name of selected object in the widget
   virtual void updateSelectionName();
 
-  /// Clear attribute
-  virtual void clearAttribute();
-
   // Update focus after the attribute value change
   virtual void updateFocus();
 
index 89315cd4b829db1413656b9e16f19ba008910b51..995c6671778053fa6fdce03c9d190f06af6a25b5 100644 (file)
@@ -37,8 +37,11 @@ ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated()
 bool ModuleBase_WidgetValidated::setSelection(QList<ModuleBase_ViewerPrs>& theValues,
                                               const bool theToValidate)
 {
-  if (theValues.empty())
+  if (theValues.empty()) {
+    // In order to make reselection possible, set empty object and shape should be done
+    setSelectionCustom(ModuleBase_ViewerPrs());
     return false;
+  }
   // it removes the processed value from the parameters list
   ModuleBase_ViewerPrs aValue = theValues.takeFirst();
   bool isDone = false;
index e3a42ecf1d0bb6cefb5ef6410f333ea722c3a529..0da828c4c60c60f716fe48c5abd8cf9f18c9a8d0 100755 (executable)
@@ -461,11 +461,6 @@ bool SketchPlugin_FilletVertexValidator::isValid(const AttributePtr& theAttribut
                                                  const std::list<std::string>& theArguments,
                                                  std::string& theError) const
 {
-  if(!theAttribute.get() || !theAttribute->isInitialized()) {
-    theError = "Error: List of points is not initialized.";
-    return false;
-  }
-
   std::shared_ptr<SketchPlugin_ConstraintFillet> aFilletFeature = std::dynamic_pointer_cast<SketchPlugin_ConstraintFillet>(theAttribute->owner());
   AttributeRefAttrListPtr aPointsRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
   if(aPointsRefList->size() == 0) {