Salome HOME
Issue #1037 Time performance on a big model: do not perform validating for objects...
authornds <nds@opencascade.com>
Thu, 28 Apr 2016 11:58:58 +0000 (14:58 +0300)
committernds <nds@opencascade.com>
Thu, 28 Apr 2016 11:59:23 +0000 (14:59 +0300)
src/ModuleBase/ModuleBase_Tools.cpp
src/ModuleBase/ModuleBase_Tools.h
src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp
src/ModuleBase/ModuleBase_WidgetSelector.cpp
src/ModuleBase/ModuleBase_WidgetSelectorStore.cpp

index 412b5e1094f7ba66b342d2c98413daae0cff2458..3211a935a2c596e6a2998519435143525bef774f 100755 (executable)
@@ -436,9 +436,80 @@ std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop, const FeatureP
   return anAttributeId;
 }
 
+bool hasObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
+               const std::shared_ptr<GeomAPI_Shape>& theShape,
+               ModuleBase_IWorkshop* theWorkshop,
+               const bool theTemporarily)
+{
+  bool aHasObject = false;
+  if (!theAttribute.get())
+    return aHasObject;
+
+  std::string aType = theAttribute->attributeType();
+  if (aType == ModelAPI_AttributeReference::typeId()) {
+    AttributeReferencePtr aRef = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+    ObjectPtr aObject = aRef->value();
+    aHasObject = aObject && aObject->isSame(theObject);
+    //if (!(aObject && aObject->isSame(theObject))) {
+    //  aRef->setValue(theObject);
+    //}
+  } else if (aType == ModelAPI_AttributeRefAttr::typeId()) {
+    AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+
+    AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
+    if (anAttribute.get()) {
+      //aRefAttr->setAttr(anAttribute);
+    }
+    else {
+      ObjectPtr aObject = aRefAttr->object();
+      aHasObject = aObject && aObject->isSame(theObject);
+      //if (!(aObject && aObject->isSame(theObject))) {
+      //  aRefAttr->setObject(theObject);
+      //}
+    }
+  } else if (aType == ModelAPI_AttributeSelection::typeId()) {
+    /*AttributeSelectionPtr aSelectAttr =
+                             std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+    if (aSelectAttr.get() != NULL) {
+      aSelectAttr->setValue(aResult, theShape, theTemporarily);
+    }*/
+  }
+  if (aType == ModelAPI_AttributeSelectionList::typeId()) {
+    AttributeSelectionListPtr aSelectionListAttr =
+                         std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+    aHasObject = aSelectionListAttr->isInList(aResult, theShape, theTemporarily);
+    //if (!theCheckIfAttributeHasObject || !aSelectionListAttr->isInList(aResult, theShape, theTemporarily))
+    //  aSelectionListAttr->append(aResult, theShape, theTemporarily);
+  }
+  else if (aType == ModelAPI_AttributeRefList::typeId()) {
+    AttributeRefListPtr aRefListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
+    aHasObject = aRefListAttr->isInList(theObject);
+    //if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject))
+    //  aRefListAttr->append(theObject);
+  }
+  else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
+    AttributeRefAttrListPtr aRefAttrListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttrList>(theAttribute);
+    AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
+
+    if (anAttribute.get()) {
+      aHasObject = aRefAttrListAttr->isInList(anAttribute);
+      //if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(anAttribute))
+      //  aRefAttrListAttr->append(anAttribute);
+    }
+    else {
+      aHasObject = aRefAttrListAttr->isInList(theObject);
+      //if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(theObject))
+      //  aRefAttrListAttr->append(theObject);
+    }
+  }
+  return aHasObject;
+}
+
 void setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
                const GeomShapePtr& theShape, ModuleBase_IWorkshop* theWorkshop,
-               const bool theTemporarily)
+               const bool theTemporarily, const bool theCheckIfAttributeHasObject)
 {
   if (!theAttribute.get())
     return;
@@ -474,12 +545,12 @@ void setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
     AttributeSelectionListPtr aSelectionListAttr =
                          std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-    if (!aSelectionListAttr->isInList(aResult, theShape, theTemporarily))
+    if (!theCheckIfAttributeHasObject || !aSelectionListAttr->isInList(aResult, theShape, theTemporarily))
       aSelectionListAttr->append(aResult, theShape, theTemporarily);
   }
   else if (aType == ModelAPI_AttributeRefList::typeId()) {
     AttributeRefListPtr aRefListAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
-    if (!aRefListAttr->isInList(theObject))
+    if (!theCheckIfAttributeHasObject || !aRefListAttr->isInList(theObject))
       aRefListAttr->append(theObject);
   }
   else if (aType == ModelAPI_AttributeRefAttrList::typeId()) {
@@ -487,11 +558,11 @@ void setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
     AttributePtr anAttribute = theWorkshop->module()->findAttribute(theObject, theShape);
 
     if (anAttribute.get()) {
-      if (!aRefAttrListAttr->isInList(anAttribute))
+      if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(anAttribute))
         aRefAttrListAttr->append(anAttribute);
     }
     else {
-      if (!aRefAttrListAttr->isInList(theObject))
+      if (!theCheckIfAttributeHasObject || !aRefAttrListAttr->isInList(theObject))
         aRefAttrListAttr->append(theObject);
     }
   }
index fd70f33fbfa0a94618b87a3e5eab12e765231387..a9b38bd8055a11c701f88a01f9cbfd789ad48ddd 100755 (executable)
@@ -187,10 +187,25 @@ MODULEBASE_EXPORT std::string findGreedAttribute(ModuleBase_IWorkshop* theWorksh
 /// \param theWorkshop to find an attribute for the given shape for attribute reference
 /// \param theTemporarily if it is true, do not store and name the added in the data framework
 ///        It is useful for attribute selection
+MODULEBASE_EXPORT bool hasObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
+                                 const std::shared_ptr<GeomAPI_Shape>& theShape,
+                                 ModuleBase_IWorkshop* theWorkshop,
+                                 const bool theTemporarily);
+
+/// Set the object to the attribute depending on the attribute type. If it is a list,
+/// the values are appended if they are not in the list yet.
+/// \param theAttribute an attribute where the object and shape are set
+/// \param theObject an object
+/// \param theShape a shape
+/// \param theWorkshop to find an attribute for the given shape for attribute reference
+/// \param theTemporarily if it is true, do not store and name the added in the data framework
+/// \param theCheckIfAttributeHasObject if it is true, the check isInList is called
+///        It is useful for attribute selection
 MODULEBASE_EXPORT void setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject,
                                  const std::shared_ptr<GeomAPI_Shape>& theShape,
                                  ModuleBase_IWorkshop* theWorkshop,
-                                 const bool theTemporarily = false);
+                                 const bool theTemporarily,
+                                 const bool theCheckIfAttributeHasObject);
 
 /// Returns the shape of the attribute. If the attribute is AttributeRefAttrPtr, the shape is found
 /// using current module of the given workshop.
index ab940f015b42c17335730bcfac6b4b6d2076d704..7a187e57c4e864cfd9cb40cbbaee319a30bd84a9 100755 (executable)
@@ -225,10 +225,18 @@ bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrsPtr>
   removeUnusedAttributeObjects(theValues);
 
   QList<ModuleBase_ViewerPrsPtr> anInvalidValues;
+  QList<ModuleBase_ViewerPrsPtr> anAttributeValues;
   QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = theValues.begin(), aLast = theValues.end();
   for (; anIt != aLast; anIt++) {
     ModuleBase_ViewerPrsPtr aValue = *anIt;
-    bool aProcessed = false;
+    // do not validate and append to attribute selection presentation if it exists in the attribute
+    ObjectPtr anObject;
+    GeomShapePtr aShape;
+    getGeomSelection(aValue, anObject, aShape);
+    if (ModuleBase_Tools::hasObject(attribute(), anObject, aShape, myWorkshop, myIsInValidate)) {
+      anAttributeValues.append(aValue);
+      continue;
+    }
     if (theToValidate && !isValidInFilters(aValue))
       anInvalidValues.append(aValue);
   }
@@ -238,9 +246,10 @@ bool ModuleBase_WidgetMultiSelector::setSelection(QList<ModuleBase_ViewerPrsPtr>
   for (anIt = theValues.begin(); anIt != aLast; anIt++) {
     ModuleBase_ViewerPrsPtr aValue = *anIt;
     bool aProcessed = false;
-    if (aHasInvalidValues && anInvalidValues.contains(aValue))
+    if ((aHasInvalidValues && anInvalidValues.contains(aValue)) ||
+        anAttributeValues.contains(aValue))
       continue;
-    aProcessed = setSelectionCustom(aValue);
+    aProcessed = setSelectionCustom(aValue); /// it is not optimal as hasObject() is already checked
     // if there is at least one set, the result is true
     isDone = isDone || aProcessed;
   }
index b9fe6ef9c9db8f643c71abfe33d7cce5514e4e31..9b044c6024540878c34326422de20258c9d1f1d8 100755 (executable)
@@ -176,7 +176,8 @@ bool ModuleBase_WidgetSelector::setSelectionCustom(const ModuleBase_ViewerPrsPtr
   GeomShapePtr aShape;
   getGeomSelection(thePrs, anObject, aShape);
 
-  ModuleBase_Tools::setObject(attribute(), anObject, aShape, myWorkshop, myIsInValidate);
+  // the last flag is to be depending on hasObject is called before. To be corrected later
+  ModuleBase_Tools::setObject(attribute(), anObject, aShape, myWorkshop, myIsInValidate, true);
   return true;
 }
 
index 2bf5195ca425248bdd51eb0aeead072a96662fb7..08e6893876b50035d1522a1dca7ab904fefba609 100755 (executable)
@@ -85,7 +85,7 @@ void ModuleBase_WidgetSelectorStore::restoreAttributeValue(const AttributePtr& t
       aRefAttrListAttr->removeLast();
   }
   else {
-    ModuleBase_Tools::setObject(theAttribute, myObject, myShape, theWorkshop, true);
+    ModuleBase_Tools::setObject(theAttribute, myObject, myShape, theWorkshop, true, true);
     AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
     if (aRefAttr) {
       if (!myIsObject)