Salome HOME
Optimization for big sketched (from unit tests)
authormpv <mpv@opencascade.com>
Fri, 4 Sep 2015 07:26:11 +0000 (10:26 +0300)
committermpv <mpv@opencascade.com>
Fri, 4 Sep 2015 07:26:11 +0000 (10:26 +0300)
src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp
src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h
src/Model/Model_AttributeSelection.cpp
src/Model/Model_Update.cpp
src/ModelAPI/ModelAPI_CompositeFeature.h
src/PartSetPlugin/PartSetPlugin_Part.cpp
src/PartSetPlugin/PartSetPlugin_Part.h
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h

index 147efefd8d7359b48c72444f5f70a765c3770e55..04785ca6393c3eebcb6d2bc051700c26bdb9df41 100644 (file)
@@ -50,7 +50,7 @@ int FeaturesPlugin_CompositeBoolean::numberOfSubs(bool forTree) const
 }
 
 //=================================================================================================
-std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_CompositeBoolean::subFeature(const int theIndex, bool forTree) const
+std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_CompositeBoolean::subFeature(const int theIndex, bool forTree)
 {
   if (theIndex == 0)
     return std::dynamic_pointer_cast<ModelAPI_Feature>(data()->reference(SKETCH_OBJECT_ID())->value());
@@ -60,9 +60,12 @@ std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_CompositeBoolean::subFeature(co
 //=================================================================================================
 int FeaturesPlugin_CompositeBoolean::subFeatureId(const int theIndex) const
 {
-  std::shared_ptr<ModelAPI_Feature> aFeature = subFeature(theIndex);
-  if (aFeature.get())
-    return aFeature->data()->featureId();
+  if (theIndex == 0) {
+    FeaturePtr aFeature = 
+      std::dynamic_pointer_cast<ModelAPI_Feature>(data()->reference(SKETCH_OBJECT_ID())->value());
+    if (aFeature.get())
+      return aFeature->data()->featureId();
+  }
   return -1;
 }
 
index d5ce37c380d72f4bc1b2e4caf481e22718a1d6d5..344faafe5615f1dffd44ad5eab460f6634aa361f 100644 (file)
@@ -46,7 +46,7 @@ class FeaturesPlugin_CompositeBoolean : public ModelAPI_CompositeFeature
   FEATURESPLUGIN_EXPORT virtual int numberOfSubs(bool forTree = false) const;
 
   /// \return the sub-feature by zero-base index.
-  FEATURESPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex, bool forTree = false) const;
+  FEATURESPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex, bool forTree = false);
 
   /// \return the sub-feature unique identifier in this composite feature by zero-base index.
   FEATURESPLUGIN_EXPORT virtual int subFeatureId(const int theIndex) const;
index b900b181941109b69a79b1878debe87ebb12eff0..d85df7d3e99c453da2e0aa40f427d3baa3c80e7e 100644 (file)
@@ -300,8 +300,19 @@ TDF_LabelMap& Model_AttributeSelection::scope()
     DocumentPtr aMyDoc = owner()->document();
     std::list<std::shared_ptr<ModelAPI_Feature> > allFeatures = aMyDoc->allFeatures();
     std::list<std::shared_ptr<ModelAPI_Feature> >::iterator aFIter = allFeatures.begin();
+    bool aMePassed = false;
+    std::shared_ptr<ModelAPI_CompositeFeature> aComposite = 
+      std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(owner());
     for(; aFIter != allFeatures.end(); aFIter++) {
-      if (*aFIter == owner()) break; // the left features are created later
+      if (*aFIter == owner()) {  // the left features are created later (except subs of composite)
+        aMePassed = true;
+        continue;
+      }
+      bool isInScope = !aMePassed;
+      if (!isInScope && aComposite.get()) { // try to add sub-elements of composite if this is composite
+        if (aComposite->isSub(*aFIter))
+          isInScope = true;
+      }
       if (aFIter->get() && (*aFIter)->data()->isValid()) {
         TDF_Label aFeatureLab = std::dynamic_pointer_cast<Model_Data>(
           (*aFIter)->data())->label().Father();
index eed45d3041b262b776cccffe54a24bb5d60a96cd..4b4ac45a22a937e84424f373e8627ff58795c573 100644 (file)
@@ -589,7 +589,8 @@ void Model_Update::updateArguments(FeaturePtr theFeature) {
   // composite feature must be executed after sub-features execution
   if (aCompos) {
     // number of subs can be changed in execution: like fillet
-    for(int a = 0; a < aCompos->numberOfSubs(); a++) {
+    int aNumSubs = aCompos->numberOfSubs();
+    for(int a = 0; a < aNumSubs; a++) {
       FeaturePtr aSub = aCompos->subFeature(a);
       if (aSub.get() && aState == ModelAPI_StateDone) {
         if (isOlder(theFeature, aSub)) {
@@ -605,6 +606,8 @@ void Model_Update::updateArguments(FeaturePtr theFeature) {
           }
         }
       }
+      if (a == aNumSubs - 1) // in case number of subs is changed, just recheck before end
+        aNumSubs = aCompos->numberOfSubs();
     }
   }
 
index 0814141b71830ecc0b49527a1ab9b2c45cfefda0..4a86409e2214825cffba19f8263846d9c97dc0b1 100644 (file)
@@ -28,7 +28,7 @@ public:
   virtual int numberOfSubs(bool forTree = false) const = 0;
 
   /// Returns the sub-feature by zero-base index
-  virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex, bool forTree = false) const = 0;
+  virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex, bool forTree = false) = 0;
 
   /// Returns the sub-feature unique identifier in this composite feature by zero-base index
   virtual int subFeatureId(const int theIndex) const = 0;
index 73dae50ef0bc4f3e68bf9865a145a998ef19a1ef..794fcd4fa2a58a459ac81a0cb302d1d87055721f 100644 (file)
@@ -72,7 +72,7 @@ int PartSetPlugin_Part::numberOfSubs(bool forTree) const
   return 0;
 }
 
-std::shared_ptr<ModelAPI_Feature> PartSetPlugin_Part::subFeature(const int theIndex, bool forTree) const
+std::shared_ptr<ModelAPI_Feature> PartSetPlugin_Part::subFeature(const int theIndex, bool forTree)
 {
   ResultPartPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
   if (aResult.get()) {
index 0610a68ab3d73429346a73d176cdee4ba09e08cf..242848300acf36be66efb857f624a8c8d6fc9a62 100644 (file)
@@ -56,7 +56,7 @@ class PartSetPlugin_Part : public ModelAPI_CompositeFeature
   virtual int numberOfSubs(bool forTree = false) const;
 
   /// Returns the sub-feature by zero-base index
-  virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex, bool forTree = false) const;
+  virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex, bool forTree = false);
 
   /// Returns the sub-feature unique identifier in this composite feature by zero-base index
   virtual int subFeatureId(const int theIndex) const;
index ceaf6dd0939570316aa2e6bb1a47cedfe7c62150..7b993c2161e0ad1d3daa39ea59f25188c5490430 100644 (file)
@@ -143,42 +143,36 @@ void SketchPlugin_Sketch::removeFeature(std::shared_ptr<ModelAPI_Feature> theFea
   // to keep the persistent sub-elements indexing, do not remove elements from list,
   // but substitute by nulls
   reflist(SketchPlugin_Sketch::FEATURES_ID())->substitute(theFeature, ObjectPtr());
-  /*
-  list<ObjectPtr> aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
-  list<ObjectPtr>::iterator aSubIt = aSubs.begin(), aLastIt = aSubs.end();
-  bool isRemoved = false;
-  bool aHasEmtpyFeature = false;
-  for(; aSubIt != aLastIt && !isRemoved; aSubIt++) {
-    std::shared_ptr<ModelAPI_Feature> aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*aSubIt);
-    if (aFeature.get() != NULL && aFeature == theFeature) {
-      data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->remove(aFeature);
-      isRemoved = true;
+
+  std::map<int, std::shared_ptr<ModelAPI_Feature> >::iterator aSubIter = mySubs.begin();
+  for(; aSubIter != mySubs.end(); aSubIter++) {
+    if (aSubIter->second == theFeature) {
+      mySubs.erase(aSubIter);
+      break;
     }
-    else if (aFeature.get() == NULL)
-      aHasEmtpyFeature = true;
   }
-  // if the object is not found in the sketch sub-elements, that means that the object is removed already.
-  // Find the first empty element and remove it
-  if (!isRemoved && aHasEmtpyFeature)
-    data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->remove(ObjectPtr());
-  */
 }
 
 int SketchPlugin_Sketch::numberOfSubs(bool forTree) const
 {
   if (forTree)
     return 0;
-  return data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->size(false);
+  return data()->reflist(FEATURES_ID())->size(false);
 }
 
 std::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::subFeature(
-  const int theIndex, bool forTree) const
+  const int theIndex, bool forTree)
 {
   if (forTree)
     return FeaturePtr();
 
+  if (mySubs.find(theIndex) != mySubs.end())
+    return mySubs[theIndex];
+
   ObjectPtr anObj = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->object(theIndex, false);
-  return std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
+  FeaturePtr aRes = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
+  mySubs[theIndex] = aRes;
+  return aRes;
 }
 
 int SketchPlugin_Sketch::subFeatureId(const int theIndex) const
index ab0bcd6ad9f0a31952c8e86ab4dd433edc535d78..aadbe9caf47a04a25e689740bd394a0bd8682a88 100644 (file)
@@ -30,6 +30,8 @@
  */
 class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_ICustomPrs//, public GeomAPI_IPresentable
 {
+  /// Optimization: indexes of sketch sub-elements are persistent, so, no problems in synchronization.
+  std::map<int, std::shared_ptr<ModelAPI_Feature> > mySubs;
  public:
   /// Sketch feature kind
   inline static const std::string& ID()
@@ -177,7 +179,7 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_ICu
 
   /// Returns the sub-feature by zero-base index
   SKETCHPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> 
-    subFeature(const int theIndex, bool forTree = false) const;
+    subFeature(const int theIndex, bool forTree = false);
 
   /// Returns the sub-feature unique identifier in this composite feature by index
   SKETCHPLUGIN_EXPORT virtual int subFeatureId(const int theIndex) const;