Salome HOME
Issue #1037 : implementation of cashing of values for method isInList
authormpv <mpv@opencascade.com>
Thu, 28 Apr 2016 10:46:50 +0000 (13:46 +0300)
committermpv <mpv@opencascade.com>
Thu, 28 Apr 2016 10:46:50 +0000 (13:46 +0300)
src/ExchangePlugin/ExchangePlugin_Validators.cpp
src/Model/Model_AttributeSelectionList.cpp
src/Model/Model_AttributeSelectionList.h
src/ModelAPI/ModelAPI_AttributeSelectionList.h

index e0579464007a69089e5e9578d58dfcb40bb747bb..e08b9854aa48929e6f2c7cf7b659f335d3c88973 100644 (file)
@@ -24,7 +24,7 @@ bool ExchangePlugin_FormatValidator::parseFormats(const std::list<std::string>&
   bool result = true;
   for (; it != theArguments.end(); ++it) {
     std::string anArg = *it;
-    int aSepPos = anArg.find(":");
+    size_t aSepPos = anArg.find(":");
     if (aSepPos == std::string::npos) {
       result = false;
       continue;
index 56f82cc6a142b9eed07722d3be44db8067d644a7..86581b348b2581502e97fc2faff7d85c6bfffdcb 100644 (file)
 #include <TDF_ChildIterator.hxx>
 #include <TDF_RelocationTable.hxx>
 #include <TopAbs_ShapeEnum.hxx>
-
 #include <TopoDS.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Edge.hxx>
 #include <BRep_Tool.hxx>
+#include <TNaming_Builder.hxx>
+#include <TNaming_Iterator.hxx>
 
 using namespace std;
 
@@ -85,9 +86,6 @@ void Model_AttributeSelectionList::removeLast()
   }
 }
 
-#include <TNaming_Builder.hxx>
-#include <TNaming_Iterator.hxx>
-
 // copies named shapes: we need the implementation of this 
 static void CopyNS(const Handle(TNaming_NamedShape)& theFrom,
   const Handle(TDF_Attribute)& theTo)
@@ -189,6 +187,25 @@ bool Model_AttributeSelectionList::isInList(const ResultPtr& theContext,
                                             const std::shared_ptr<GeomAPI_Shape>& theSubShape,
                                             const bool theTemporarily)
 {
+  if (myCash.size()) { // the cashing is active
+    std::map<ResultPtr, std::list<const std::shared_ptr<GeomAPI_Shape> > >::iterator aContext =
+      myCash.find(theContext);
+    if (aContext != myCash.end()) {
+      // iterate shapes because "isEqual" method must be called for each shape
+      std::list<const std::shared_ptr<GeomAPI_Shape> >::iterator aShapes = aContext->second.begin();
+      for(; aShapes != aContext->second.end(); aShapes++) {
+        if (!theSubShape.get()) {
+          if (!aShapes->get())
+            return true;
+        } else {
+          if (theSubShape->isEqual(*aShapes))
+            return true;
+        }
+      }
+    }
+    return false;
+  }
+  // no-cash method
   for(int anIndex = size() - 1; anIndex >= 0; anIndex--) {
     AttributeSelectionPtr anAttr = value(anIndex);
     if (anAttr.get()) {
@@ -275,3 +292,15 @@ Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
     theLabel.FindAttribute(TDataStd_Comment::GetID(), mySelectionType);
   }
 }
+
+void Model_AttributeSelectionList::cashValues(const bool theEnabled) {
+  myCash.clear(); // empty list as indicator that cash is not used
+  if (theEnabled) {
+    for(int anIndex = size() - 1; anIndex >= 0; anIndex--) {
+      AttributeSelectionPtr anAttr = value(anIndex);
+      if (anAttr.get()) {
+        myCash[anAttr->context()].push_back(anAttr->value());
+      }
+    }
+  }
+}
index d28798dda638f5dac20896b926f8428cd937dc91..2df86e31d053de6cd23e9a2233534bd3a6ba34b3 100644 (file)
@@ -13,6 +13,7 @@
 #include <TDataStd_Integer.hxx>
 #include <TDataStd_Comment.hxx>
 #include <vector>
+#include <map>
 
 /**\class Model_AttributeSelectionList
  * \ingroup DataModel
 class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList
 {
   Handle(TDataStd_Integer) mySize;  ///< Contains size of this list
-  Handle(TDataStd_Comment) mySelectionType;  ///< Contains current type name (same as selection attribute)
+  /// Contains current type name (same as selection attribute)
+  Handle(TDataStd_Comment) mySelectionType;
   std::shared_ptr<Model_AttributeSelection> myTmpAttr; ///< temporary attribute (the last one)
+  /// the cashed shapes to optimize isInList method: from context to set of shapes in this context
+  std::map<ResultPtr, std::list<const std::shared_ptr<GeomAPI_Shape> > > myCash;
 public:
   /// Adds the new reference to the end of the list
   /// \param theContext object where the sub-shape was selected
@@ -74,6 +78,11 @@ public:
   /// Returns true if attribute was  initialized by some value
   MODEL_EXPORT virtual bool isInitialized();
 
+  /// Starts or stops cashing of the values in the attribute (the cash may become invalid
+  /// on modification of the attribute or sub-elements, so the cash must be enabled only
+  /// during non-modification operations with this attribute)
+  MODEL_EXPORT virtual void cashValues(const bool theEnabled);
+
 protected:
   /// Objects are created for features automatically
   MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
index b5d1ff4669b98b612d4d0a259e4b96fcc17d35a7..9f0b0a69aafb844d031a48b2e9b1a214a22a7b22 100644 (file)
@@ -64,6 +64,11 @@ class ModelAPI_AttributeSelectionList : public ModelAPI_Attribute
   /// Returns all attributes
   virtual void clear() = 0;
 
+  /// Starts or stops cashing of the values in the attribute (the cash may become invalid
+  /// on modification of the attribute or sub-elements, so the cash must be enabled only
+  /// during non-modification operations with this attribute)
+  virtual void cashValues(const bool theEnabled) = 0;
+
   /// Returns the type of this class of attributes
   static std::string typeId()
   {