#include <TDF_Label.hxx>
-class ModelAPI_Expression;
+class ModelAPI_ExpressionDouble;
/**\class GeomData_Point
* \ingroup DataModel
class GeomData_Point : public GeomDataAPI_Point
{
enum { NUM_COMPONENTS = 3 };
- std::shared_ptr<ModelAPI_Expression> myExpression[NUM_COMPONENTS]; ///< Expressions for X, Y and Z
+ std::shared_ptr<ModelAPI_ExpressionDouble> myExpression[NUM_COMPONENTS]; ///< Expressions for X, Y and Z
public:
/// Defines the double value
GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY, const double theZ);
#include <TDF_Label.hxx>
-class ModelAPI_Expression;
+class ModelAPI_ExpressionDouble;
/**\class GeomData_Point2D
* \ingroup DataModel
class GeomData_Point2D : public GeomDataAPI_Point2D
{
enum { NUM_COMPONENTS = 2 };
- std::shared_ptr<ModelAPI_Expression> myExpression[NUM_COMPONENTS]; ///< Expressions for X, Y
+ std::shared_ptr<ModelAPI_ExpressionDouble> myExpression[NUM_COMPONENTS]; ///< Expressions for X, Y
public:
/// Defines the double value
GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY);
#include <ModelAPI_Data.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Expression.h>
-#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
{
{
if (text() != theValue) {
myExpression->setText(theValue);
- // Send it to evaluator to convert into the double and store in the attribute
+ // Send it to evaluator to convert text to double and store in the attribute
ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
owner()->data()->sendAttributeUpdated(this);
}
#include <TDF_Label.hxx>
-class ModelAPI_Expression;
+class ModelAPI_ExpressionDouble;
/**\class Model_AttributeDouble
* \ingroup DataModel
class Model_AttributeDouble : public ModelAPI_AttributeDouble
{
- std::shared_ptr<ModelAPI_Expression> myExpression;
+ std::shared_ptr<ModelAPI_ExpressionDouble> myExpression;
public:
/// Defines the double value
#include <Model_AttributeInteger.h>
-#include <ModelAPI_Attribute.h>
#include <ModelAPI_Data.h>
+#include <ModelAPI_Events.h>
+#include <ModelAPI_Expression.h>
#include <ModelAPI_Object.h>
-#include <Standard_TypeDef.hxx>
-#include <TDataStd_Integer.hxx>
+Model_AttributeInteger::Model_AttributeInteger(TDF_Label& theLabel)
+{
+ myIsInitialized = true;
+}
-void Model_AttributeInteger::setValue(const int theValue)
+void Model_AttributeInteger::setCalculatedValue(const int theValue)
{
- if (!myIsInitialized || myInteger->Get() != theValue) {
- myInteger->Set(theValue);
+ if (!myIsInitialized || value() != theValue) {
+ myExpression->setValue(theValue);
owner()->data()->sendAttributeUpdated(this);
}
}
+void Model_AttributeInteger::setValue(const int theValue)
+{
+ setCalculatedValue(text().empty() ? theValue : value());
+}
+
int Model_AttributeInteger::value()
{
- return myInteger->Get();
+ return myExpression->value();
}
-Model_AttributeInteger::Model_AttributeInteger(TDF_Label& theLabel)
+void Model_AttributeInteger::setText(const std::string& theValue)
{
- // check the attribute could be already presented in this doc (after load document)
- myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), myInteger) == Standard_True;
- if (!myIsInitialized) {
- // create attribute: not initialized by value yet, just zero
- myInteger = TDataStd_Integer::Set(theLabel, 0);
+ if (text() != theValue) {
+ myExpression->setText(theValue);
+ // Send it to evaluator to convert text to integer and store in the attribute
+ ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
+ owner()->data()->sendAttributeUpdated(this);
}
}
+
+std::string Model_AttributeInteger::text()
+{
+ return myExpression->text();
+}
+
+void Model_AttributeInteger::setExpressionInvalid(const bool theFlag)
+{
+ myExpression->setInvalid(theFlag);
+}
+
+bool Model_AttributeInteger::expressionInvalid()
+{
+ return myExpression->isInvalid();
+}
+
+void Model_AttributeInteger::setExpressionError(const std::string& theError)
+{
+ if (expressionError() != theError)
+ myExpression->setError(theError);
+}
+
+std::string Model_AttributeInteger::expressionError()
+{
+ return myExpression->error();
+}
+
+void Model_AttributeInteger::setUsedParameters(const std::set<std::string>& theUsedParameters)
+{
+ myExpression->setUsedParameters(theUsedParameters);
+}
+
+std::set<std::string> Model_AttributeInteger::usedParameters() const
+{
+ return myExpression->usedParameters();
+}
#include <ModelAPI_AttributeInteger.h>
#include <TDF_Label.hxx>
-#include <TDataStd_Integer.hxx>
+
+class ModelAPI_ExpressionInteger;
/**\class Model_AttributeInteger
* \ingroup DataModel
- * \brief Attribute that contains integer (int).
+ * \brief Attribute that contains integer.
*/
class Model_AttributeInteger : public ModelAPI_AttributeInteger
{
- Handle_TDataStd_Integer myInteger;
public:
- /// Defines the int value
+ /// Defines the integer value
MODEL_EXPORT virtual void setValue(const int theValue);
- /// Returns the int value
+ /// Returns the integer value
MODEL_EXPORT virtual int value();
+ /// Defines the calculated value
+ MODEL_EXPORT virtual void setCalculatedValue(const int theValue);
+
+ /// Defines the text value
+ MODEL_EXPORT virtual void setText(const std::string& theText);
+
+ /// Returns the text value
+ MODEL_EXPORT virtual std::string text();
+
+ /// Allows to set expression (text) as invalid (by the parameters listener)
+ MODEL_EXPORT virtual void setExpressionInvalid(const bool theFlag);
+
+ /// Returns true if text is invalid
+ MODEL_EXPORT virtual bool expressionInvalid();
+
+ /// Allows to set expression (text) error (by the parameters listener)
+ MODEL_EXPORT virtual void setExpressionError(const std::string& theError);
+
+ /// Returns an expression error
+ MODEL_EXPORT virtual std::string expressionError();
+
+ /// Defines the used parameters
+ MODEL_EXPORT virtual void setUsedParameters(const std::set<std::string>& theUsedParameters);
+
+ /// Returns the used parameters
+ MODEL_EXPORT virtual std::set<std::string> usedParameters() const;
+
protected:
/// Initializes attributes
Model_AttributeInteger(TDF_Label& theLabel);
friend class Model_Data;
+
+ private:
+ std::shared_ptr<ModelAPI_ExpressionInteger> myExpression;
};
#endif
// Author: Sergey POKHODENKO
#include "Model_AttributeValidator.h"
+
#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeInteger.h>
+
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Point2D.h>
const std::list<std::string>& theArguments,
std::string& theError) const
{
+ if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) {
+ AttributeIntegerPtr anAttribue =
+ std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
+ if (!anAttribue->expressionError().empty()) {
+ theError = anAttribue->expressionError();
+ return false;
+ }
+ } else
if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
AttributeDoublePtr anAttribue =
std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
if (theAttrType == ModelAPI_AttributeDocRef::typeId()) {
anAttr = new Model_AttributeDocRef(anAttrLab);
} else if (theAttrType == Model_AttributeInteger::typeId()) {
- anAttr = new Model_AttributeInteger(anAttrLab);
+ Model_AttributeInteger* anAttribute = new Model_AttributeInteger(anAttrLab);
+ // Expression should use the same label to support backward compatibility
+ TDF_Label anExpressionLab = anAttrLab;
+ anAttribute->myExpression.reset(new Model_ExpressionInteger(anExpressionLab));
+ anAttribute->myIsInitialized = anAttribute->myIsInitialized && anAttribute->myExpression->isInitialized();
+ anAttr = anAttribute;
} else if (theAttrType == ModelAPI_AttributeDouble::typeId()) {
Model_AttributeDouble* anAttribute = new Model_AttributeDouble(anAttrLab);
TDF_Label anExpressionLab = anAttrLab.FindChild(1);
- anAttribute->myExpression.reset(new Model_Expression(anExpressionLab));
- anAttribute->myIsInitialized = anAttribute->myIsInitialized && anAttribute->myExpression->isInitialized();
+ anAttribute->myExpression.reset(new Model_ExpressionDouble(anExpressionLab));
+ anAttribute->myIsInitialized = anAttribute->myIsInitialized && anAttribute->myExpression->isInitialized();
anAttr = anAttribute;
} else if (theAttrType == Model_AttributeBoolean::typeId()) {
anAttr = new Model_AttributeBoolean(anAttrLab);
GeomData_Point* anAttribute = new GeomData_Point(anAttrLab);
for (int aComponent = 0; aComponent < GeomData_Point::NUM_COMPONENTS; ++aComponent) {
TDF_Label anExpressionLab = anAttrLab.FindChild(aComponent + 1);
- anAttribute->myExpression[aComponent].reset(new Model_Expression(anExpressionLab));
+ anAttribute->myExpression[aComponent].reset(new Model_ExpressionDouble(anExpressionLab));
anAttribute->myIsInitialized = anAttribute->myIsInitialized && anAttribute->myExpression[aComponent]->isInitialized();
}
anAttr = anAttribute;
GeomData_Point2D* anAttribute = new GeomData_Point2D(anAttrLab);
for (int aComponent = 0; aComponent < GeomData_Point2D::NUM_COMPONENTS; ++aComponent) {
TDF_Label anExpressionLab = anAttrLab.FindChild(aComponent + 1);
- anAttribute->myExpression[aComponent].reset(new Model_Expression(anExpressionLab));
+ anAttribute->myExpression[aComponent].reset(new Model_ExpressionDouble(anExpressionLab));
anAttribute->myIsInitialized = anAttribute->myIsInitialized && anAttribute->myExpression[aComponent]->isInitialized();
}
anAttr = anAttribute;
for(int a = aRef->size() - 1; a >= 0; a--) {
aReferenced.push_back(aRef->value(a)->context());
}
+ } else if (aType == ModelAPI_AttributeInteger::typeId()) { // integer attribute
+ AttributeIntegerPtr anAttribute =
+ std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(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 == ModelAPI_AttributeDouble::typeId()) { // double attribute
AttributeDoublePtr anAttribute =
std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(anAttr->second);
#include <TDataStd_RealArray.hxx>
#include <TDataStd_ExtStringArray.hxx>
+
+static Standard_GUID kInvalidGUID("caee5ce4-34b1-4b29-abcb-685287d18096");
+
+
Model_Expression::Model_Expression(TDF_Label& theLabel)
{
myIsInitialized = true;
if (!theLabel.FindAttribute(TDataStd_Name::GetID(), myText)) {
myText = TDataStd_Name::Set(theLabel, TCollection_ExtendedString());
- myIsInitialized = false;
+// myIsInitialized = false;
}
if (!theLabel.FindAttribute(TDataStd_Comment::GetID(), myError)) {
myError = TDataStd_Comment::Set(theLabel, TCollection_ExtendedString());
- myIsInitialized = false;
+// myIsInitialized = false;
}
if (!theLabel.FindAttribute(TDataStd_ExtStringList::GetID(), myUsedParameters)) {
myUsedParameters = TDataStd_ExtStringList::Set(theLabel);
- myIsInitialized = false;
+// myIsInitialized = false;
}
+ // All this attributes should not set myIsInitialized = false.
+ // This attributes are optional and may absent in old files. So this is OK.
+ // The reason to set myIsInitialized = false is only absence of
+ // the value attribute.
+}
+
+void Model_Expression::setText(const std::string& theValue)
+{
+ if (text() != theValue)
+ myText->Set(TCollection_ExtendedString(theValue.c_str()));
+
+ setError(text().empty() ? "" : "Not a double value.");
+}
+
+std::string Model_Expression::text() const
+{
+ return TCollection_AsciiString(myText->Get()).ToCString();
+}
+
+void Model_Expression::setError(const std::string& theError)
+{
+ if (error() != theError)
+ myError->Set(TCollection_ExtendedString(theError.c_str()));
+}
+
+std::string Model_Expression::error()
+{
+ return TCollection_AsciiString(myError->Get()).ToCString();
+}
+
+void Model_Expression::setUsedParameters(const std::set<std::string>& theUsedParameters)
+{
+ myUsedParameters->Clear();
+ std::set<std::string>::const_iterator anIt = theUsedParameters.begin();
+ for (; anIt != theUsedParameters.end(); ++anIt)
+ myUsedParameters->Append(TCollection_ExtendedString(anIt->c_str()));
+}
+
+std::set<std::string> Model_Expression::usedParameters() const
+{
+ std::set<std::string> aResult;
+ TDataStd_ListIteratorOfListOfExtendedString aIt;
+ for (aIt.Initialize(myUsedParameters->List()); aIt.More(); aIt.Next())
+ aResult.insert(TCollection_AsciiString(aIt.Value()).ToCString());
+ return aResult;
+}
+
+Model_ExpressionDouble::Model_ExpressionDouble(TDF_Label& theLabel)
+ : Model_Expression(theLabel)
+{
if (!theLabel.FindAttribute(TDataStd_Real::GetID(), myReal)) {
myReal = TDataStd_Real::Set(theLabel, 0.);
myIsInitialized = false;
}
}
}
-
}
}
-void Model_Expression::setValue(const double theValue)
+void Model_ExpressionDouble::setValue(const double theValue)
{
if (value() != theValue)
myReal->Set(theValue);
}
-double Model_Expression::value()
+double Model_ExpressionDouble::value()
{
return myReal->Get();
}
-void Model_Expression::setText(const std::string& theValue)
-{
- if (text() != theValue)
- myText->Set(TCollection_ExtendedString(theValue.c_str()));
-
- setError(text().empty() ? "" : "Not a double value.");
-}
-
-std::string Model_Expression::text() const
-{
- return TCollection_AsciiString(myText->Get()).ToCString();
-}
-
-static Standard_GUID kInvalidGUID("caee5ce4-34b1-4b29-abcb-685287d18096");
-
-void Model_Expression::setInvalid(const bool theFlag)
+void Model_ExpressionDouble::setInvalid(const bool theFlag)
{
if (theFlag) {
TDataStd_UAttribute::Set(myReal->Label(), kInvalidGUID);
}
}
-bool Model_Expression::isInvalid()
+bool Model_ExpressionDouble::isInvalid()
{
return myReal->Label().IsAttribute(kInvalidGUID) == Standard_True;
}
-void Model_Expression::setError(const std::string& theError)
+
+Model_ExpressionInteger::Model_ExpressionInteger(TDF_Label& theLabel)
+ : Model_Expression(theLabel)
{
- if (error() != theError)
- myError->Set(TCollection_ExtendedString(theError.c_str()));
+ if (!theLabel.FindAttribute(TDataStd_Integer::GetID(), myInteger)) {
+ myInteger = TDataStd_Integer::Set(theLabel, 0);
+ myIsInitialized = false;
+ }
}
-std::string Model_Expression::error()
+void Model_ExpressionInteger::setValue(const int theValue)
{
- return TCollection_AsciiString(myError->Get()).ToCString();
+ if (value() != theValue)
+ myInteger->Set(theValue);
}
-void Model_Expression::setUsedParameters(const std::set<std::string>& theUsedParameters)
+int Model_ExpressionInteger::value()
{
- myUsedParameters->Clear();
- std::set<std::string>::const_iterator anIt = theUsedParameters.begin();
- for (; anIt != theUsedParameters.end(); ++anIt)
- myUsedParameters->Append(TCollection_ExtendedString(anIt->c_str()));
+ return myInteger->Get();
}
-std::set<std::string> Model_Expression::usedParameters() const
+void Model_ExpressionInteger::setInvalid(const bool theFlag)
{
- std::set<std::string> aResult;
- TDataStd_ListIteratorOfListOfExtendedString aIt;
- for (aIt.Initialize(myUsedParameters->List()); aIt.More(); aIt.Next())
- aResult.insert(TCollection_AsciiString(aIt.Value()).ToCString());
- return aResult;
+ if (theFlag) {
+ TDataStd_UAttribute::Set(myInteger->Label(), kInvalidGUID);
+ } else {
+ myInteger->Label().ForgetAttribute(kInvalidGUID);
+ }
+}
+
+bool Model_ExpressionInteger::isInvalid()
+{
+ return myInteger->Label().IsAttribute(kInvalidGUID) == Standard_True;
}
#include <TDataStd_Comment.hxx>
#include <TDataStd_ExtStringList.hxx>
+#include <TDataStd_Integer.hxx>
#include <TDataStd_Name.hxx>
#include <TDataStd_Real.hxx>
* \ingroup DataModel
* \brief Implementation of ModelAPI_Expression.
*/
-class Model_Expression : public ModelAPI_Expression
+class Model_Expression : public virtual ModelAPI_Expression
{
- Handle_TDataStd_Real myReal; ///< double is Real attribute
- Handle_TDataStd_Name myText; ///< Text representation of the attribute (may differ for parameters)
- Handle_TDataStd_Comment myError; ///< Error of expression of the text attribute
- Handle_TDataStd_ExtStringList myUsedParameters; ///< Parameters used in expression
public:
- /// Defines the double value
- MODEL_EXPORT virtual void setValue(const double theValue);
-
- /// Returns the double value
- MODEL_EXPORT virtual double value();
-
/// Sets the text of this Expression
MODEL_EXPORT virtual void setText(const std::string& theText);
/// Returns the text of this Expression
MODEL_EXPORT virtual std::string text() const;
- /// Allows to set expression (text) as invalid (by the parameters listener)
- MODEL_EXPORT virtual void setInvalid(const bool theFlag);
-
- /// Returns true if text is invalid
- MODEL_EXPORT virtual bool isInvalid();
-
/// Allows to set expression (text) error (by the parameters listener)
MODEL_EXPORT virtual void setError(const std::string& theError);
/// Initializes attributes
Model_Expression(TDF_Label& theLabel);
+ Handle_TDataStd_Name myText; ///< Text representation of the attribute (may differ for parameters)
+ Handle_TDataStd_Comment myError; ///< Error of expression of the text attribute
+ Handle_TDataStd_ExtStringList myUsedParameters; ///< Parameters used in expression
+
friend class Model_Data;
};
-#endif
+
+/**\class Model_ExpressionDouble
+ * \ingroup DataModel
+ * \brief Implementation of ModelAPI_ExpressionDouble.
+ */
+class Model_ExpressionDouble :
+ public Model_Expression, // implementation inheritance
+ public ModelAPI_ExpressionDouble
+{
+ public:
+ /// Defines the double value
+ MODEL_EXPORT virtual void setValue(const double theValue);
+
+ /// Returns the double value
+ MODEL_EXPORT virtual double value();
+
+ /// Allows to set expression (text) as invalid (by the parameters listener)
+ MODEL_EXPORT virtual void setInvalid(const bool theFlag);
+
+ /// Returns true if text is invalid
+ MODEL_EXPORT virtual bool isInvalid();
+
+ protected:
+ /// Initializes attributes
+ Model_ExpressionDouble(TDF_Label& theLabel);
+
+ friend class Model_Data;
+
+ private:
+ Handle_TDataStd_Real myReal; ///< double is Real attribute
+};
+
+
+/**\class Model_ExpressionInteger
+ * \ingroup DataModel
+ * \brief Implementation of ModelAPI_ExpressionInteger.
+ */
+class Model_ExpressionInteger :
+ public Model_Expression, // implementation inheritance
+ public ModelAPI_ExpressionInteger
+{
+ public:
+ /// Defines the integer value
+ MODEL_EXPORT virtual void setValue(const int theValue);
+
+ /// Returns the integer value
+ MODEL_EXPORT virtual int value();
+
+ /// Allows to set expression (text) as invalid (by the parameters listener)
+ MODEL_EXPORT virtual void setInvalid(const bool theFlag);
+
+ /// Returns true if text is invalid
+ MODEL_EXPORT virtual bool isInvalid();
+
+ protected:
+ /// Initializes attributes
+ Model_ExpressionInteger(TDF_Label& theLabel);
+
+ friend class Model_Data;
+
+ private:
+ Handle_TDataStd_Integer myInteger;
+};
+
+#endif // Model_Expression_H_
if (aState == ModelAPI_StateInvalidArgument) // a chance to be corrected
aState = ModelAPI_StateMustBeUpdated;
// check the parameters state
- // Double
- std::list<AttributePtr> aDoubles =
- theFeature->data()->attributes(ModelAPI_AttributeDouble::typeId());
- std::list<AttributePtr>::iterator aDoubleIter = aDoubles.begin();
- for(; aDoubleIter != aDoubles.end(); aDoubleIter++) {
- AttributeDoublePtr aDouble =
- std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(*aDoubleIter);
- if (aDouble.get() && !aDouble->text().empty()) {
- if (myIsParamUpdated) {
- ModelAPI_AttributeEvalMessage::send(aDouble, this);
+ // Integer
+ {
+ std::list<AttributePtr> anAttrinbutes =
+ theFeature->data()->attributes(ModelAPI_AttributeInteger::typeId());
+ std::list<AttributePtr>::iterator anIter = anAttrinbutes.begin();
+ for(; anIter != anAttrinbutes.end(); anIter++) {
+ AttributeIntegerPtr anAttribute =
+ std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(*anIter);
+ if (anAttribute.get() && !anAttribute->text().empty()) {
+ if (myIsParamUpdated) {
+ ModelAPI_AttributeEvalMessage::send(anAttribute, this);
+ }
+ if (anAttribute->expressionInvalid()) {
+ aState = ModelAPI_StateInvalidArgument;
+ }
}
- if (aDouble->expressionInvalid()) {
- aState = ModelAPI_StateInvalidArgument;
+ }
+ }
+ // Double
+ {
+ std::list<AttributePtr> aDoubles =
+ theFeature->data()->attributes(ModelAPI_AttributeDouble::typeId());
+ std::list<AttributePtr>::iterator aDoubleIter = aDoubles.begin();
+ for(; aDoubleIter != aDoubles.end(); aDoubleIter++) {
+ AttributeDoublePtr aDouble =
+ std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(*aDoubleIter);
+ if (aDouble.get() && !aDouble->text().empty()) {
+ if (myIsParamUpdated) {
+ ModelAPI_AttributeEvalMessage::send(aDouble, this);
+ }
+ if (aDouble->expressionInvalid()) {
+ aState = ModelAPI_StateInvalidArgument;
+ }
}
}
}
#ifndef ModelAPI_AttributeDouble_H_
#define ModelAPI_AttributeDouble_H_
-#include "ModelAPI_Attribute.h"
+#include <ModelAPI_Attribute.h>
#include <set>
-
-class ModelAPI_Expression;
+#include <string>
/**\class ModelAPI_AttributeDouble
* \ingroup DataModel
#ifndef MODELAPI_ATTRIBUTEINTEGER_H_
#define MODELAPI_ATTRIBUTEINTEGER_H_
-#include <ModelAPI.h>
#include <ModelAPI_Attribute.h>
+#include <set>
#include <string>
-
/**\class ModelAPI_AttributeInteger
* \ingroup DataModel
* \brief API for the attribute that contains integer (int).
/// Returns the integer value
MODELAPI_EXPORT virtual int value() = 0;
+ /// Defines the calculated value
+ MODELAPI_EXPORT virtual void setCalculatedValue(const int theValue) = 0;
+
+ /// Defines the text value
+ MODELAPI_EXPORT virtual void setText(const std::string& theText) = 0;
+
+ /// Returns the text value
+ MODELAPI_EXPORT virtual std::string text() = 0;
+
+ /// Allows to set expression (text) as invalid (by the parameters listener)
+ MODELAPI_EXPORT virtual void setExpressionInvalid(const bool theFlag) = 0;
+
+ /// Returns true if text is invalid
+ MODELAPI_EXPORT virtual bool expressionInvalid() = 0;
+
+ /// Allows to set expression (text) error (by the parameters listener)
+ MODELAPI_EXPORT virtual void setExpressionError(const std::string& theError) = 0;
+
+ /// Returns an expression error
+ MODELAPI_EXPORT virtual std::string expressionError() = 0;
+
+ /// Defines the used parameters
+ MODELAPI_EXPORT virtual void setUsedParameters(const std::set<std::string>& theUsedParameters) = 0;
+
+ /// Returns the used parameters
+ MODELAPI_EXPORT virtual std::set<std::string> usedParameters() const = 0;
+
/// Returns the type of this class of attributes
MODELAPI_EXPORT static std::string typeId()
{
{
myIsInitialized = true;
}
+
+ModelAPI_ExpressionDouble::ModelAPI_ExpressionDouble()
+{
+
+}
+
+ModelAPI_ExpressionInteger::ModelAPI_ExpressionInteger()
+{
+
+}
#define ModelAPI_Expression_H_
#include "ModelAPI.h"
+
#include <memory>
#include <set>
#include <string>
*/
class ModelAPI_Expression
{
- protected:
- bool myIsInitialized; ///< is some value assigned to this attribute
-
public:
/// To virtually destroy the fields of successors
MODELAPI_EXPORT virtual ~ModelAPI_Expression();
/// Makes attribute initialized
MODELAPI_EXPORT virtual void setInitialized();
- /// Defines the double value
- MODELAPI_EXPORT virtual void setValue(const double theValue) = 0;
-
- /// Returns the double value
- MODELAPI_EXPORT virtual double value() = 0;
-
/// Sets the text of this Expression
MODELAPI_EXPORT virtual void setText(const std::string& theText) = 0;
/// Objects are created for features automatically
MODELAPI_EXPORT ModelAPI_Expression();
+ bool myIsInitialized; ///< is some value assigned to this attribute
+
friend class Model_Data;
};
-//! Pointer on Expression object
+
+/**\class ModelAPI_ExpressionDouble
+ * \ingroup DataModel
+ * \brief Expression for calculated double values.
+ */
+class ModelAPI_ExpressionDouble : public virtual ModelAPI_Expression
+{
+ public:
+ /// Defines the double value
+ MODELAPI_EXPORT virtual void setValue(const double theValue) = 0;
+
+ /// Returns the double value
+ MODELAPI_EXPORT virtual double value() = 0;
+
+ protected:
+ /// Objects are created for features automatically
+ MODELAPI_EXPORT ModelAPI_ExpressionDouble();
+
+ friend class Model_Data;
+};
+
+
+/**\class ModelAPI_ExpressionInteger
+ * \ingroup DataModel
+ * \brief Expression for calculated integer values.
+ */
+class ModelAPI_ExpressionInteger : public virtual ModelAPI_Expression
+{
+ public:
+ /// Defines the integer value
+ MODELAPI_EXPORT virtual void setValue(const int theValue) = 0;
+
+ /// Returns the integer value
+ MODELAPI_EXPORT virtual int value() = 0;
+
+ protected:
+ /// Objects are created for features automatically
+ MODELAPI_EXPORT ModelAPI_ExpressionInteger();
+
+ friend class Model_Data;
+};
+
+
+//! Smart pointers for objects
typedef std::shared_ptr<ModelAPI_Expression> ExpressionPtr;
+typedef std::shared_ptr<ModelAPI_ExpressionDouble> ExpressionDoublePtr;
+typedef std::shared_ptr<ModelAPI_ExpressionInteger> ExpressionIntegerPtr;
#endif
#include <Events_Error.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_AttributeValidator.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Tools.h>
-#include <ModelAPI_AttributeDouble.h>
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Point2D.h>
std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
std::dynamic_pointer_cast<ModelAPI_AttributeEvalMessage>(theMessage);
+ if (aMessage->attribute()->attributeType() == ModelAPI_AttributeInteger::typeId()) {
+ AttributeIntegerPtr anAttribute =
+ std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(aMessage->attribute());
+ std::string anError;
+ int aValue = (int)evaluate(anAttribute->text(), anError, anAttribute->owner()->document());
+ bool isValid = anError.empty();
+ if (isValid)
+ anAttribute->setCalculatedValue(aValue);
+ anAttribute->setUsedParameters(isValid ? toSet(myInterp->compile(anAttribute->text())) : std::set<std::string>());
+ anAttribute->setExpressionInvalid(!isValid);
+ anAttribute->setExpressionError(anAttribute->text().empty() ? "" : anError);
+ } else
if (aMessage->attribute()->attributeType() == ModelAPI_AttributeDouble::typeId()) {
AttributeDoublePtr anAttribute =
std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aMessage->attribute());
const std::string& theOldName,
const std::string& theNewName)
{
+ if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) {
+ AttributeIntegerPtr anAttribute =
+ std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
+ std::string anExpressionString = anAttribute->text();
+ anExpressionString = renameInPythonExpression(anExpressionString,
+ theOldName, theNewName);
+ anAttribute->setText(anExpressionString);
+ } else
if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
AttributeDoublePtr anAttribute =
std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
"""
if (isinstance(attribute, ModelAPI.ModelAPI_AttributeBoolean) or
isinstance(attribute, ModelAPI.ModelAPI_AttributeDocRef) or
- isinstance(attribute, ModelAPI.ModelAPI_AttributeInteger) or
isinstance(attribute, ModelAPI.ModelAPI_AttributeReference)
):
attribute.setValue(value)
elif isinstance(attribute, ModelAPI.ModelAPI_AttributeString):
attribute.setValue(str(value))
- elif isinstance(attribute, ModelAPI.ModelAPI_AttributeDouble):
+ elif (isinstance(attribute, ModelAPI.ModelAPI_AttributeDouble) or
+ isinstance(attribute, ModelAPI.ModelAPI_AttributeInteger)
+ ):
if isinstance(value, basestring):
attribute.setText(value)
else: