Salome HOME
Issue #3038: Add tooltip
[modules/shaper.git] / src / Model / Model_Objects.cpp
index d7ecf71879dc3ee3b39e5f34eadef130e13f536b..152aaaeb84ee27a8c4211c1c3d3618dae7221f50 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include <Model_Objects.h>
 #include <Model_ResultGroup.h>
 #include <Model_ResultField.h>
 #include <Model_ResultParameter.h>
+#include <Model_AttributeRefList.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_Tools.h>
+#include <ModelAPI_Filter.h>
+
 
 #include <Events_Loop.h>
 #include <Events_InfoMessage.h>
@@ -770,7 +772,7 @@ void Model_Objects::setUniqueName(FolderPtr theFolder)
   NCollection_DataMap<TDF_Label, ObjectPtr>::Iterator anIt(myFolders);
   while (anIt.More()) {
     if (anIt.Value()->data()->name() == aName) {
-      aName = composeName(ModelAPI_Folder::ID(), aNbFolders);
+      aName = composeName(ModelAPI_Folder::ID(), ++aNbFolders);
       // reinitialize iterator to make sure a new name is unique
       anIt.Initialize(myFolders);
     } else
@@ -798,15 +800,6 @@ void Model_Objects::initData(ObjectPtr theObj, TDF_Label theLab, const int theTa
   theObj->initAttributes();
 }
 
-std::shared_ptr<ModelAPI_Feature> Model_Objects::featureById(const int theId)
-{
-  if (theId > 0) {
-    TDF_Label aLab = featuresLabel().FindChild(theId, Standard_False);
-    return feature(aLab);
-  }
-  return std::shared_ptr<ModelAPI_Feature>(); // not found
-}
-
 void Model_Objects::synchronizeFeatures(
   const TDF_LabelList& theUpdated, const bool theUpdateReferences,
   const bool theExecuteFeatures, const bool theOpen, const bool theFlush)
@@ -883,11 +876,30 @@ void Model_Objects::synchronizeFeatures(
 
       if (anUpdatedMap.Contains(aFeatureLabel)) {
         if (!theOpen) { // on abort/undo/redo reinitialize attributes if something is changed
-          std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
-            anObject->data()->attributes("");
-          std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
-          for(; anAttr != anAttrs.end(); anAttr++)
-            (*anAttr)->reinit();
+          FiltersFeaturePtr aFilter = std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(anObject);
+          if (aFilter.get()) { // for filters attributes may be added/removed on undo/redo
+            std::dynamic_pointer_cast<Model_Data>(aFilter->data())->clearAttributes();
+            aFilter->initAttributes();
+          } else {
+            std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
+              anObject->data()->attributes("");
+            std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+            for(; anAttr != anAttrs.end(); anAttr++)
+              (*anAttr)->reinit();
+            // if feature contains results, re-init them too
+            if (aFeature.get()) {
+              std::list<ResultPtr> aResults;
+              ModelAPI_Tools::allResults(aFeature, aResults);
+              std::list<ResultPtr>::iterator aResIter = aResults.begin();
+              for(; aResIter != aResults.end(); aResIter++) {
+                std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs =
+                  (*aResIter)->data()->attributes("");
+                std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+                for(; anAttr != anAttrs.end(); anAttr++)
+                  (*anAttr)->reinit();
+              }
+            }
+          }
         }
         ModelAPI_EventCreator::get()->sendUpdated(anObject, anUpdateEvent);
         if (aFeature && aFeature->getKind() == "Parameter") {
@@ -1004,6 +1016,12 @@ void Model_Objects::synchronizeBackRefsForObject(const std::set<AttributePtr>& t
   // iterate new list to compare with current
   std::set<AttributePtr>::iterator aNewIter = theNewRefs.begin();
   for(; aNewIter != theNewRefs.end(); aNewIter++) {
+    // for the Model_AttributeRefList erase cash (issue #2819)
+    std::shared_ptr<Model_AttributeRefList> aRefList =
+      std::dynamic_pointer_cast<Model_AttributeRefList>(*aNewIter);
+    if (aRefList)
+      aRefList->eraseHash();
+
     if (aData->refsToMe().find(*aNewIter) == aData->refsToMe().end()) {
       FeaturePtr aRefFeat = std::dynamic_pointer_cast<ModelAPI_Feature>((*aNewIter)->owner());
       if (aRefFeat)
@@ -1830,6 +1848,10 @@ void Model_Objects::updateResults(FeaturePtr theFeature, std::set<FeaturePtr>& t
     }
   }
 
+  // it may be on undo
+  if (!theFeature->data() || !theFeature->data()->isValid() || theFeature->isDisabled())
+    return;
+
   // check the existing results and remove them if there is nothing on the label
   std::list<ResultPtr>::const_iterator aResIter = theFeature->results().cbegin();
   while(aResIter != theFeature->results().cend()) {
@@ -1846,9 +1868,6 @@ void Model_Objects::updateResults(FeaturePtr theFeature, std::set<FeaturePtr>& t
     }
     aResIter++;
   }
-  // it may be on undo
-  if (!theFeature->data() || !theFeature->data()->isValid() || theFeature->isDisabled())
-    return;
   // check that results are presented on all labels
   int aResSize = int(theFeature->results().size());
   TDF_ChildIterator aLabIter(resultLabel(theFeature->data(), 0).Father());
@@ -1880,7 +1899,9 @@ void Model_Objects::updateResults(FeaturePtr theFeature, std::set<FeaturePtr>& t
         } else if (aGroup->Get() == ModelAPI_ResultGroup::group().c_str()) {
           aNewBody = createGroup(theFeature->data(), aResIndex);
         } else if (aGroup->Get() == ModelAPI_ResultField::group().c_str()) {
-          aNewBody = createField(theFeature->data(), aResIndex);
+          ResultFieldPtr aField = createField(theFeature->data(), aResIndex);
+          aField->updateSteps(); // to refresh the internal data
+          aNewBody = aField;
         } else if (aGroup->Get() == ModelAPI_ResultParameter::group().c_str()) {
           theFeature->attributeChanged("expression"); // just produce a value
         } else {