Salome HOME
Eliminate some Visual Studio warnings
[modules/shaper.git] / src / Model / Model_Data.cpp
index 0e8d64bd1a911fbce36e8365379023c621999120..aeb1489c47ac39f298439a7dc4090be4d5a174ed 100644 (file)
 #include <Model_Expression.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
+#include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Tools.h>
+
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Point2D.h>
 
 #include <GeomData_Point.h>
 #include <GeomData_Point2D.h>
@@ -103,7 +108,7 @@ AttributePtr Model_Data::addAttribute(const std::string& theID, const std::strin
     anAttr = new Model_AttributeInteger(anAttrLab);
   } else if (theAttrType == ModelAPI_AttributeDouble::typeId()) {
     Model_AttributeDouble* anAttribute = new Model_AttributeDouble(anAttrLab);
-    TDF_Label anExpressionLab = anAttrLab.FindChild(anAttrLab.NbChildren() + 1);
+    TDF_Label anExpressionLab = anAttrLab.FindChild(1);
     anAttribute->myExpression.reset(new Model_Expression(anExpressionLab));
     anAttribute->myIsInitialized = anAttribute->myIsInitialized && anAttribute->myExpression->isInitialized(); 
     anAttr = anAttribute;
@@ -128,7 +133,7 @@ AttributePtr Model_Data::addAttribute(const std::string& theID, const std::strin
   else if (theAttrType == GeomData_Point::typeId()) {
     GeomData_Point* anAttribute = new GeomData_Point(anAttrLab);
     for (int aComponent = 0; aComponent < GeomData_Point::NUM_COMPONENTS; ++aComponent) {
-      TDF_Label anExpressionLab = anAttrLab.FindChild(anAttrLab.NbChildren() + 1);
+      TDF_Label anExpressionLab = anAttrLab.FindChild(aComponent + 1);
       anAttribute->myExpression[aComponent].reset(new Model_Expression(anExpressionLab));
       anAttribute->myIsInitialized = anAttribute->myIsInitialized && anAttribute->myExpression[aComponent]->isInitialized(); 
     }
@@ -138,7 +143,7 @@ AttributePtr Model_Data::addAttribute(const std::string& theID, const std::strin
   } else if (theAttrType == GeomData_Point2D::typeId()) {
     GeomData_Point2D* anAttribute = new GeomData_Point2D(anAttrLab);
     for (int aComponent = 0; aComponent < GeomData_Point2D::NUM_COMPONENTS; ++aComponent) {
-      TDF_Label anExpressionLab = anAttrLab.FindChild(anAttrLab.NbChildren() + 1);
+      TDF_Label anExpressionLab = anAttrLab.FindChild(aComponent + 1);
       anAttribute->myExpression[aComponent].reset(new Model_Expression(anExpressionLab));
       anAttribute->myIsInitialized = anAttribute->myIsInitialized && anAttribute->myExpression[aComponent]->isInitialized(); 
     }
@@ -397,6 +402,46 @@ void Model_Data::updateConcealmentFlag()
 
 #include <Model_Validator.h>
 
+std::set<std::string> set_union(const std::set<std::string>& theLeft, 
+                                const std::set<std::string>& theRight)
+{
+  std::set<std::string> aResult;
+  aResult.insert(theLeft.begin(), theLeft.end());
+  aResult.insert(theRight.begin(), theRight.end());
+  return aResult;
+}
+
+std::set<std::string> usedParameters(const AttributePointPtr& theAttribute)
+{
+  std::set<std::string> anUsedParameters;
+  for (int aComponent = 0; aComponent < 3; ++aComponent)
+    anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent));
+  return anUsedParameters;
+}
+
+std::set<std::string> usedParameters(const AttributePoint2DPtr& theAttribute)
+{
+  std::set<std::string> anUsedParameters;
+  for (int aComponent = 0; aComponent < 2; ++aComponent)
+    anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent));
+  return anUsedParameters;
+}
+
+std::list<ResultParameterPtr> findVariables(const std::set<std::string>& theParameters, 
+                                            const DocumentPtr& theDocument)
+{
+  std::list<ResultParameterPtr> aResult;
+  std::set<std::string>::const_iterator aParamIt = theParameters.cbegin();
+  for (; aParamIt != theParameters.cend(); ++aParamIt) {
+    const std::string& aName = *aParamIt;
+    double aValue;
+    ResultParameterPtr aParam;
+    if (ModelAPI_Tools::findVariable(aName, aValue, aParam, theDocument))
+      aResult.push_back(aParam);
+  }
+  return aResult;
+}
+
 void Model_Data::referencesToObjects(
   std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs)
 {
@@ -432,6 +477,24 @@ void Model_Data::referencesToObjects(
       for(int a = aRef->size() - 1; a >= 0; a--) {
         aReferenced.push_back(aRef->value(a)->context());
       }
+    } else if (aType == ModelAPI_AttributeDouble::typeId()) { // double attribute
+      AttributeDoublePtr anAttribute =
+          std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anAttr->second);
+      std::set<std::string> anUsedParameters = anAttribute->usedParameters();
+      std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters, aMyFeature->document());
+      aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
+    } else if (aType == GeomDataAPI_Point::typeId()) { // point attribute
+      AttributePointPtr anAttribute =
+        std::dynamic_pointer_cast<GeomDataAPI_Point>(anAttr->second);
+      std::set<std::string> anUsedParameters = usedParameters(anAttribute);
+      std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters, aMyFeature->document());
+      aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
+    } else if (aType == GeomDataAPI_Point2D::typeId()) { // point attribute
+      AttributePoint2DPtr anAttribute =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->second);
+      std::set<std::string> anUsedParameters = usedParameters(anAttribute);
+      std::list<ResultParameterPtr> aParameters = findVariables(anUsedParameters, aMyFeature->document());
+      aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
     } else
       continue; // nothing to do, not reference
 
@@ -520,7 +583,7 @@ std::shared_ptr<ModelAPI_Data> Model_Data::invalidData()
   return kInvalid;
 }
 
-bool Model_Data::isOwner(ModelAPI_Object* theOwner)
+std::shared_ptr<ModelAPI_Object> Model_Data::owner()
 {
-  return theOwner == myObject.get();
+  return myObject;
 }