Salome HOME
Issue #1037 : performance correction to process preselection, correction of shape...
authornds <nds@opencascade.com>
Fri, 29 Apr 2016 08:58:01 +0000 (11:58 +0300)
committernds <nds@opencascade.com>
Fri, 29 Apr 2016 08:58:01 +0000 (11:58 +0300)
src/ModuleBase/ModuleBase_ISelection.cpp
src/ModuleBase/ModuleBase_ISelection.h
src/ModuleBase/ModuleBase_OperationFeature.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetMultiSelector.h

index 1669c2381cea636b871832c37c1d69505faf146b..1e6a3e3c4b96df0df0229235e684c28907e5c735 100644 (file)
@@ -93,14 +93,35 @@ void ModuleBase_ISelection::filterSelectionOnEqualPoints
   QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theSelected.begin(),
                                               aLast = theSelected.end();
   QList<ModuleBase_ViewerPrsPtr>::const_iterator aSubIt;
+
+  std::set<std::shared_ptr<GeomAPI_Vertex> > aVerticesMap;
   for (; anIt != aLast; anIt++) {
     aSubIt = anIt;
     aSubIt++;
-    for (; aSubIt != aLast; aSubIt++) {
-      if (isEqualVertices(*anIt, *aSubIt)) {
+    ModuleBase_ViewerPrsPtr aPrs = *anIt;
+    std::shared_ptr<GeomAPI_Vertex> aGeomPrsVertex = getPresentationVertex(aPrs);
+    if (aGeomPrsVertex.get()) {
+      const TopoDS_Vertex& aPrsVertex = aGeomPrsVertex->impl<TopoDS_Vertex>();
+      std::set<std::shared_ptr<GeomAPI_Vertex> >::const_iterator anIt = aVerticesMap.begin(),
+                                                                 aLast = aVerticesMap.end();
+      bool aFound = false;
+      for (; anIt != aLast && !aFound; anIt++) {
+        std::shared_ptr<GeomAPI_Vertex> aGeomVertex = *anIt;
+        const TopoDS_Vertex& aVertex = aGeomVertex->impl<TopoDS_Vertex>();
+        gp_Pnt aPoint1 = BRep_Tool::Pnt(aVertex);
+        gp_Pnt aPoint2 = BRep_Tool::Pnt(aPrsVertex);
+
+        std::shared_ptr<GeomAPI_Pnt> aPnt1 = std::shared_ptr<GeomAPI_Pnt>
+                        (new GeomAPI_Pnt(aPoint1.X(), aPoint1.Y(), aPoint1.Z()));
+        std::shared_ptr<GeomAPI_Pnt> aPnt2 = std::shared_ptr<GeomAPI_Pnt>
+                        (new GeomAPI_Pnt(aPoint2.X(), aPoint2.Y(), aPoint2.Z()));
+        aFound = aPnt1->isEqual(aPnt2);
+      }
+      if (aFound) {
         aCandidatesToRemove.append(*aSubIt);
-        break;
+        continue;
       }
+      aVerticesMap.insert(aGeomPrsVertex);
     }
   }
   QList<ModuleBase_ViewerPrsPtr>::const_iterator aRemIt = aCandidatesToRemove.begin(),
@@ -110,34 +131,23 @@ void ModuleBase_ISelection::filterSelectionOnEqualPoints
   }
 }
 
-bool ModuleBase_ISelection::isEqualVertices(const ModuleBase_ViewerPrsPtr thePrs1,
-                                            const ModuleBase_ViewerPrsPtr thePrs2)
+std::shared_ptr<GeomAPI_Vertex> ModuleBase_ISelection::getPresentationVertex(
+                                                         const ModuleBase_ViewerPrsPtr& thePrs)
 {
-  bool isEqual = false;
-  Handle(StdSelect_BRepOwner) anOwner1 = Handle(StdSelect_BRepOwner)::DownCast(thePrs1->owner());
-  Handle(StdSelect_BRepOwner) anOwner2 = Handle(StdSelect_BRepOwner)::DownCast(thePrs2->owner());
-
-  if (!anOwner1.IsNull() && anOwner1->HasShape() &&
-      !anOwner2.IsNull() && anOwner2->HasShape()) {
-    const TopoDS_Shape& aShape1 = anOwner1->Shape();
-    const TopoDS_Shape& aShape2 = anOwner2->Shape();
-    //TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
-    if (aShape1.ShapeType() == TopAbs_VERTEX &&
-        aShape2.ShapeType() == TopAbs_VERTEX) {
-      const TopoDS_Vertex& aVertex1 = TopoDS::Vertex(aShape1);
-      const TopoDS_Vertex& aVertex2 = TopoDS::Vertex(aShape2);
-      if (!aVertex1.IsNull() && !aVertex2.IsNull())  {
-        gp_Pnt aPoint1 = BRep_Tool::Pnt(aVertex1);
-        gp_Pnt aPoint2 = BRep_Tool::Pnt(aVertex2);
-
-        std::shared_ptr<GeomAPI_Pnt> aPnt1 = std::shared_ptr<GeomAPI_Pnt>
-                        (new GeomAPI_Pnt(aPoint1.X(), aPoint1.Y(), aPoint1.Z()));
-        std::shared_ptr<GeomAPI_Pnt> aPnt2 = std::shared_ptr<GeomAPI_Pnt>
-                        (new GeomAPI_Pnt(aPoint2.X(), aPoint2.Y(), aPoint2.Z()));
-        isEqual = aPnt1->isEqual(aPnt2);
+  std::shared_ptr<GeomAPI_Vertex> aGeomVertex;
+  Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast(thePrs->owner());
+
+  if (!anOwner.IsNull() && anOwner->HasShape()) {
+    const TopoDS_Shape& aShape = anOwner->Shape();
+    if (aShape.ShapeType() == TopAbs_VERTEX) {
+      const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
+      if (!aVertex.IsNull())  {
+        gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
+        aGeomVertex = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aPoint.X(), aPoint.Y(),
+                                                                         aPoint.Z()));
       }
     }
   }
-
-  return isEqual;
+  return aGeomVertex;
 }
+
index 510ec76de97e4678bbf2e4c77e6b2eaa20dcca2b..abc994373c608a13888333c560f4dc9b363c82a6 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <ModelAPI_Result.h>
 #include <GeomAPI_Shape.h>
+#include <GeomAPI_Vertex.h>
 
 #include <QModelIndexList>
 #include <AIS_ListOfInteractive.hxx>
@@ -106,11 +107,11 @@ class ModuleBase_ISelection
   static MODULEBASE_EXPORT void filterSelectionOnEqualPoints
                                               (QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theSelected);
 private:
-  /// Returns true if the presentations have an owner with a vertex and these vertices are equal.
-  /// \param thePrs1 the first viewer selected presentation
-  /// \param thePrs2 the second viewer selected presentation
-  static bool isEqualVertices(const std::shared_ptr<ModuleBase_ViewerPrs> thePrs1,
-                              const std::shared_ptr<ModuleBase_ViewerPrs> thePrs2);
+  /// Find vertex shape build by a Brep owner of the presentation if it exists
+  /// \param thePrs a viewer presentation
+  /// \return GeomAPI wrap of vertex
+  static std::shared_ptr<GeomAPI_Vertex> getPresentationVertex(
+                                               const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
 };
 
 #endif
index 2508ac0c198030e91bc9ae864a2daae3f51ea2e7..e2f2dd6803947e7b8443b81c8c16a11cef5411e6 100755 (executable)
@@ -339,8 +339,6 @@ ModuleBase_ModelWidget* ModuleBase_OperationFeature::activateByPreselection(
   ModuleBase_ModelWidget* aWidget = 0;
   if (myPreSelection.empty())
     return aWidget;
-  // equal vertices should not be used here
-  ModuleBase_ISelection::filterSelectionOnEqualPoints(myPreSelection);
 
   ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel();
   ModuleBase_ModelWidget* aFilledWgt = 0;
@@ -349,6 +347,9 @@ ModuleBase_ModelWidget* ModuleBase_OperationFeature::activateByPreselection(
     QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
     ModuleBase_ModelWidget* aWgt = 0;
     if (!aWidgets.empty()) {
+      // equal vertices should not be used here
+      ModuleBase_ISelection::filterSelectionOnEqualPoints(myPreSelection);
+
       if (!theGreedAttributeId.empty()) {
         // set preselection to greed widget
         for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) {
index fa5d776753a9b714af58a64aa11a29eef526b400..180f0ee8b8fca8a8c4d68e1f740d2f8563f50a43 100755 (executable)
@@ -228,7 +228,7 @@ bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrsPtr>
 
   /// remove unused objects from the model attribute.
   /// It should be performed before new attributes append.
-  removeUnusedAttributeObjects(theValues);
+  bool isDone = removeUnusedAttributeObjects(theValues);
 
   QList<ModuleBase_ViewerPrsPtr> anInvalidValues;
   QList<ModuleBase_ViewerPrsPtr> anAttributeValues;
@@ -248,7 +248,6 @@ bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrsPtr>
   }
   bool aHasInvalidValues = anInvalidValues.size() > 0;
 
-  bool isDone = false;
   for (anIt = theValues.begin(); anIt != aLast; anIt++) {
     ModuleBase_ViewerPrsPtr aValue = *anIt;
     bool aProcessed = false;
@@ -274,6 +273,10 @@ bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrsPtr>
   if (!anInvalidValues.empty())
     theValues.append(anInvalidValues);
 
+  if (isDone) // may be the feature's result is not displayed, but attributes should be
+    myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeArguments,
+                                          true);/// hope that something is redisplayed by object updated
+
   return isDone;
 }
 
@@ -348,6 +351,10 @@ bool ModuleBase_WidgetMultiSelector::processDelete()
 
     restoreValue();
     myWorkshop->setSelected(getAttributeSelection());
+
+    // may be the feature's result is not displayed, but attributes should be
+    myWorkshop->module()->customizeObject(myFeature, ModuleBase_IModule::CustomizeArguments,
+                                          true); /// hope that something is redisplayed by object updated
   }
   return aDone;
 }
@@ -602,9 +609,11 @@ void ModuleBase_WidgetMultiSelector::convertIndicesToViewerSelection(std::set<in
   }
 }
 
-void ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
+bool ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
                                                  (QList<ModuleBase_ViewerPrsPtr>& theValues)
 {
+  bool isDone = false;
+
   std::map<ObjectPtr, std::set<GeomShapePtr> > aGeomSelection = convertSelection(theValues);
   DataPtr aData = myFeature->data();
   AttributePtr anAttribute = aData->attribute(attributeID());
@@ -620,6 +629,7 @@ void ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
       if (!aFound)
         anIndicesToBeRemoved.insert(i);
     }
+    isDone = anIndicesToBeRemoved.size() > 0;
     aSelectionListAttr->remove(anIndicesToBeRemoved);
   }
   else if (aType == ModelAPI_AttributeRefList::typeId()) {
@@ -632,6 +642,7 @@ void ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
           anIndicesToBeRemoved.insert(i);
       }
     }
+    isDone = anIndicesToBeRemoved.size() > 0;
     aRefListAttr->remove(anIndicesToBeRemoved);
   }
   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
@@ -660,8 +671,11 @@ void ModuleBase_WidgetMultiSelector::removeUnusedAttributeObjects
       if (!aFound)
         anIndicesToBeRemoved.insert(i);
     }
+    isDone = anIndicesToBeRemoved.size() > 0;
     aRefAttrListAttr->remove(anIndicesToBeRemoved);
   }
+
+  return isDone;
 }
 
 std::map<ObjectPtr, std::set<GeomShapePtr> > ModuleBase_WidgetMultiSelector::convertSelection
index 6a0c9e37cf170fa26aa43d2769fe1379154460b1..1fbc337c90ed6f6b44695a55f40dde88fa4f87e8 100755 (executable)
@@ -148,7 +148,8 @@ protected:
 
   /// 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<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
+  /// \return true if at least one object is removed
+  virtual bool removeUnusedAttributeObjects(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
 
   /// Converts viewer presentation selection list to objects and shapes map
   /// \param theValues the wrapped selection values