]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Speed-up of the access from OB to complicated compsolids in the frames of issue ...
authormpv <mpv@opencascade.com>
Fri, 29 Sep 2017 07:40:43 +0000 (10:40 +0300)
committermpv <mpv@opencascade.com>
Fri, 29 Sep 2017 07:40:43 +0000 (10:40 +0300)
src/Model/Model_ResultCompSolid.cpp
src/Model/Model_ResultCompSolid.h
src/ModelAPI/ModelAPI_ResultCompSolid.h
src/ModelAPI/ModelAPI_Tools.cpp
src/ModelAPI/ModelAPI_Tools.h
src/XGUI/XGUI_DataModel.cpp

index 231c0b6ed33290d915c5cfecb54ecccf1c1ed401..c650196d92863db878ad59395ba7b238f860ab73 100755 (executable)
@@ -98,12 +98,13 @@ std::shared_ptr<ModelAPI_ResultBody> Model_ResultCompSolid::subResult(const int
   return mySubs.at(theIndex);
 }
 
-bool Model_ResultCompSolid::isSub(ObjectPtr theObject) const
+bool Model_ResultCompSolid::isSub(ObjectPtr theObject, int& theIndex) const
 {
-  std::vector<std::shared_ptr<ModelAPI_ResultBody> >::const_iterator aSubIter = mySubs.cbegin();
-  for(; aSubIter != mySubs.cend(); aSubIter++)
-    if (*aSubIter == theObject)
-      return true;
+  std::map<ObjectPtr, int>::const_iterator aFound = mySubsMap.find(theObject);
+  if (aFound != mySubsMap.end()) {
+    theIndex = aFound->second;
+    return true;
+  }
   return false;
 }
 
@@ -213,6 +214,7 @@ void Model_ResultCompSolid::updateSubs(const std::shared_ptr<GeomAPI_Shape>& the
       if (mySubs.size() <= aSubIndex) { // it is needed to create a new sub-result
         aSub = anObjects->createBody(this->data(), aSubIndex);
         mySubs.push_back(aSub);
+        mySubsMap[aSub] = int(mySubs.size() - 1);
       } else { // just update shape of this result
         aSub = mySubs[aSubIndex];
       }
@@ -228,6 +230,7 @@ void Model_ResultCompSolid::updateSubs(const std::shared_ptr<GeomAPI_Shape>& the
     while(mySubs.size() > aSubIndex) {
       ResultBodyPtr anErased = *(mySubs.rbegin());
       anErased->setDisabled(anErased, true);
+      mySubsMap.erase(anErased);
       mySubs.pop_back();
     }
     if (aWasEmpty) { // erase all subs
@@ -241,6 +244,7 @@ void Model_ResultCompSolid::updateSubs(const std::shared_ptr<GeomAPI_Shape>& the
         anErased->setDisabled(anErased, true);
       mySubs.pop_back();
     }
+    mySubsMap.clear();
     // redisplay this because result with and without subs are displayed differently
     aECreator->sendUpdated(data()->owner(), EVENT_DISP);
   }
index 7fcf5cc59bae616da02259d634912179528e381b..c748aeeae3800401f93f8124c0d6d19e8378d285 100755 (executable)
@@ -24,6 +24,7 @@
 #include "Model.h"
 #include <ModelAPI_ResultCompSolid.h>
 #include <vector>
+#include <map>
 
 /**\class Model_ResultCompSolid
 * \ingroup DataModel
@@ -35,6 +36,8 @@ class Model_ResultCompSolid : public ModelAPI_ResultCompSolid
 {
   /// Sub-bodies if this is compsolid: zero base index to subs
   std::vector<std::shared_ptr<ModelAPI_ResultBody> > mySubs;
+  /// Also keep map of result to index in mySubs to facilitate speed of access from OB
+  std::map<ObjectPtr, int> mySubsMap;
   /// Flag that stores the previous state of "concealed": if it is changed,
   /// The event must be generated to redisplay this and all subs.
   bool myLastConcealed;
@@ -74,7 +77,8 @@ public:
     bool forTree = false) const;
 
   /// Returns true if feature or reuslt belong to this composite feature as subs
-  MODEL_EXPORT virtual bool isSub(ObjectPtr theObject) const;
+  /// Returns theIndex - zero based index of sub if found
+  MODEL_EXPORT virtual bool isSub(ObjectPtr theObject, int& theIndex) const;
 
   /// Returns the parameters of color definition in the resources config manager
   MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
index b2558013c8457b824f1015efe7cd2021a6afa226..70abc72d079da83e7de754438e1fadc2b3602daa 100755 (executable)
@@ -45,7 +45,8 @@ public:
                                                          bool forTree = false) const = 0;
 
   /// Returns true if feature or reuslt belong to this composite feature as subs
-  virtual bool isSub(ObjectPtr theObject) const = 0;
+  /// Returns theIndex - zero based index of sub if found
+  virtual bool isSub(ObjectPtr theObject, int& theIndex) const = 0;
 
   /// Set displayed flag to the result and all sub results
   /// \param theDisplay a boolean value
index 9dd0d9d6c7eee1985ad332b2c8a2614e4ca7c4d5..3be42d1f47248161f147105f5eecac93fa1d1534 100755 (executable)
@@ -268,6 +268,7 @@ CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature)
 
 ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub)
 {
+  int anIndex;
   ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theSub);
   if (aBody.get()) {
     FeaturePtr aFeatureOwner = aBody->document()->feature(aBody);
@@ -276,7 +277,7 @@ ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub)
         aFeatureOwner->results().cbegin();
       for(; aResIter != aFeatureOwner->results().cend(); aResIter++) {
         ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aResIter);
-        if (aComp && aComp->isSub(aBody))
+        if (aComp && aComp->isSub(aBody, anIndex))
           return aComp;
       }
     }
@@ -284,6 +285,25 @@ ResultCompSolidPtr compSolidOwner(const ResultPtr& theSub)
   return ResultCompSolidPtr(); // not found
 }
 
+int compSolidIndex(const ResultPtr& theSub)
+{
+  int anIndex = -1;
+  ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theSub);
+  if (aBody.get()) {
+    FeaturePtr aFeatureOwner = aBody->document()->feature(aBody);
+    if (aFeatureOwner.get()) {
+      std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aResIter =
+        aFeatureOwner->results().cbegin();
+      for(; aResIter != aFeatureOwner->results().cend(); aResIter++) {
+        ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aResIter);
+        if (aComp && aComp->isSub(aBody, anIndex))
+          return anIndex;
+      }
+    }
+  }
+  return anIndex; // not found
+}
+
 bool hasSubResults(const ResultPtr& theResult)
 {
   ResultCompSolidPtr aCompSolid = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(theResult);
index ca3a1d1d8fc8eb55df3b1b687d04e8d37c6dcadb..c119924cb88d16a43106dd9a0de15b69879d9de0 100755 (executable)
@@ -107,6 +107,11 @@ MODELAPI_EXPORT std::shared_ptr<ModelAPI_CompositeFeature> compositeOwner(
  */
 MODELAPI_EXPORT std::shared_ptr<ModelAPI_ResultCompSolid> compSolidOwner(
                                             const std::shared_ptr<ModelAPI_Result>& theSub);
+/*!
+ * Returns index of this result in parent (if parent exists, returned by compSolidOwner)
+ * \returns zero-base index, or -1 if not found
+ */
+MODELAPI_EXPORT int compSolidIndex(const std::shared_ptr<ModelAPI_Result>& theSub);
 
 /*!
 * Returns true if the result contains a not empty list of sub results.
index 30cf4e574342ab50ac1d7090115d3cf5c5f71b15..758fb4f2344ad975abc3384bbae9fb8386c26cc8 100644 (file)
@@ -386,12 +386,7 @@ QModelIndex XGUI_DataModel::objectIndex(const ObjectPtr theObject) const
       if (aResult.get()) {
         ResultCompSolidPtr aCompRes = ModelAPI_Tools::compSolidOwner(aResult);
         if (aCompRes.get()) {
-          for (int i = 0; i < aCompRes->numberOfSubs(true); i++) {
-            if (aCompRes->subResult(i, true) == theObject) {
-              aRow = i;
-              break;
-            }
-          }
+          aRow = ModelAPI_Tools::compSolidIndex(aResult);
         }
       }
     }