Salome HOME
Merge branch 'master' into gni/evolution
[modules/shaper.git] / src / Model / Model_AttributeValidator.cpp
index ab01428148b1f47f90fab019e49e2182233914a0..253e592a9666325b3e3ea49285f7edcfbd7d45c6 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2022  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
@@ -32,7 +32,7 @@
 #include <GeomDataAPI_Point2D.h>
 
 bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute,
-                                       const std::list<std::string>& theArguments,
+                                       const std::list<std::string>& /*theArguments*/,
                                        Events_InfoMessage& theError) const
 {
   if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) {
@@ -101,6 +101,8 @@ bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute,
           std::list<ObjectPtr>::const_iterator aRefIter = aReferencedList.cbegin();
           for(; aRefIter != aReferencedList.cend(); aRefIter++) {
             const ObjectPtr& aReferenced = *aRefIter;
+            if (!aReferenced.get())
+              continue;
             // get all results and feature that is referenced to see all references to them
             FeaturePtr aReferencedFeature;
             if (aReferenced->groupName() == ModelAPI_Feature::group()) {
@@ -112,8 +114,21 @@ bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute,
             if (alreadyProcessed.count(aReferencedFeature))
               continue;
             alreadyProcessed.insert(aReferencedFeature);
+            /* it takes all results, not only concealed
             std::list<ResultPtr> aReferencedResults;
             ModelAPI_Tools::allResults(aReferencedFeature, aReferencedResults);
+            */
+            std::list<ResultPtr> aReferencedResults;
+            ResultBodyPtr aRefBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aReferenced);
+            if (aRefBody.get()) { // take only sub-results of this result or sub-result
+              ResultBodyPtr aRoot = ModelAPI_Tools::bodyOwner(aRefBody, true);
+              if (aRoot.get()) {
+                ModelAPI_Tools::allSubs(aRoot, aReferencedResults, false);
+                aReferencedResults.push_back(aRoot);
+              } else
+                aReferencedResults.push_back(aRefBody);
+            }
+
             std::list<ResultPtr>::iterator aRefRes = aReferencedResults.begin();
             bool aCheckFeature = true; // the last iteration to check the feature
             while(aRefRes != aReferencedResults.end() || aCheckFeature) {
@@ -121,6 +136,9 @@ bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute,
               if (aRefRes == aReferencedResults.end()) {
                 aRefd = aReferencedFeature;
                 aCheckFeature = false;
+                if (!aReferencedFeature->results().empty() &&
+                    aReferencedFeature->firstResult()->groupName() != ModelAPI_ResultBody::group())
+                  break;
               } else {
                 aRefd = *aRefRes;
                 if (aRefd->groupName() != ModelAPI_ResultBody::group())
@@ -136,9 +154,13 @@ bool Model_AttributeValidator::isValid(const AttributePtr& theAttribute,
                   continue;
                 if (ModelAPI_Session::get()->validators()->isConcealed(
                     aRefFeat->getKind(), (*aRR)->id())) {
-                  theError = "Reference to concealed object %1";
-                  theError.arg(aRefd->data()->name());
-                  return false;
+                  // check this feature is later than another referenced to make unit tests working
+                  //because of Test1757 and others: allow to move selection context of this to next
+                  if (aFeat->document()->isLater(aFeat, aRefFeat)) {
+                    theError = "Reference to concealed object %1";
+                    theError.arg(aRefd->data()->name());
+                    return false;
+                  }
                 }
               }
               if (aCheckFeature)