#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>
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;
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();
}
} 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();
}
#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)
{
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
return kInvalid;
}
-bool Model_Data::isOwner(ModelAPI_Object* theOwner)
+std::shared_ptr<ModelAPI_Object> Model_Data::owner()
{
- return theOwner == myObject.get();
+ return myObject;
}