Salome HOME
Fix for the issue #587 and general optimization and debug of parametric update.
[modules/shaper.git] / src / Model / Model_Objects.cpp
index deadfd2a3c8b686c80147f0f0517e5de4135251f..224d9d9dbf9039cf65e175116b66c1ce1eb5cafd 100644 (file)
@@ -339,6 +339,8 @@ ObjectPtr Model_Objects::object(TDF_Label theLabel)
 
 ObjectPtr Model_Objects::object(const std::string& theGroupID, const int theIndex)
 {
+  if (theIndex == -1)
+    return ObjectPtr();
   createHistory(theGroupID);
   return myHistory[theGroupID][theIndex];
 }
@@ -473,7 +475,7 @@ void Model_Objects::synchronizeFeatures(
   static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
   static Events_ID aDeleteEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
   static Events_ID aToHideEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-  aLoop->activateFlushes(false);
+  bool isActive = aLoop->activateFlushes(false);
 
   // update all objects by checking are they on labels or not
   std::set<FeaturePtr> aNewFeatures, aKeptFeatures;
@@ -556,7 +558,7 @@ void Model_Objects::synchronizeFeatures(
   }
 
   anOwner->executeFeatures() = false;
-  aLoop->activateFlushes(true);
+  aLoop->activateFlushes(isActive);
 
   if (theFlush) {
     aLoop->flush(aCreateEvent);
@@ -813,8 +815,10 @@ void Model_Objects::updateResults(FeaturePtr theFeature)
         if (aGroup->Get() == ModelAPI_ResultBody::group().c_str()) {
           aNewBody = createBody(theFeature->data(), aResIndex);
         } else if (aGroup->Get() == ModelAPI_ResultPart::group().c_str()) {
-          //aNewBody = createPart(theFeature->data(), aResIndex); 
-          theFeature->execute(); // create the part result
+          std::shared_ptr<ModelAPI_ResultPart> aNewP = createPart(theFeature->data(), aResIndex); 
+          theFeature->setResult(aNewP, aResIndex);
+          if (!aNewP->partDoc().get())
+            theFeature->execute(); // create the part result: it is better to restore the previous result if it is possible
           break;
         } else if (aGroup->Get() == ModelAPI_ResultConstruction::group().c_str()) {
           theFeature->execute(); // construction shapes are needed for sketch solver
@@ -895,6 +899,38 @@ FeaturePtr Model_Objects::lastFeature()
   return FeaturePtr(); // no features at all
 }
 
+std::list<std::shared_ptr<ModelAPI_Feature> > Model_Objects::allFeatures()
+{
+  std::list<std::shared_ptr<ModelAPI_Feature> > aResult;
+  Handle(TDataStd_ReferenceArray) aRefs;
+  if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
+    for(int a = aRefs->Lower(); a <= aRefs->Upper(); a++) {
+      FeaturePtr aFeature = feature(aRefs->Value(a));
+      if (aFeature.get())
+        aResult.push_back(aFeature);
+    }
+  }
+  return aResult;
+}
+
+int Model_Objects::numInternalFeatures()
+{
+  Handle(TDataStd_ReferenceArray) aRefs;
+  if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
+    return aRefs->Upper() - aRefs->Lower() + 1;
+  }
+  return 0; // invalid
+}
+
+std::shared_ptr<ModelAPI_Feature> Model_Objects::internalFeature(const int theIndex)
+{
+  Handle(TDataStd_ReferenceArray) aRefs;
+  if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
+    return feature(aRefs->Value(aRefs->Lower() + theIndex));
+  }
+  return FeaturePtr(); // invalid
+}
+
 Standard_Integer HashCode(const TDF_Label& theLab, const Standard_Integer theUpper)
 {
   return TDF_LabelMapHasher::HashCode(theLab, theUpper);