Implement DoubleAttribute, Point and Point2D using ModelAPI_Expression.
// Author: Mikhail PONIKAROV
#include "GeomData_Point.h"
+
#include <GeomAPI_Pnt.h>
-#include <ModelAPI_Feature.h>
+
#include <ModelAPI_Data.h>
#include <ModelAPI_Events.h>
+#include <ModelAPI_Expression.h>
+#include <ModelAPI_Feature.h>
+
+#include <cassert>
-using namespace std;
+GeomData_Point::GeomData_Point(TDF_Label& theLabel)
+{
+ myIsInitialized = true;
+}
void GeomData_Point::setCalculatedValue(const double theX, const double theY, const double theZ)
{
- if (!myIsInitialized || myCoords->Value(0) != theX || myCoords->Value(1) != theY
- || myCoords->Value(2) != theZ) {
- myCoords->SetValue(0, theX);
- myCoords->SetValue(1, theY);
- myCoords->SetValue(2, theZ);
+ if (!myIsInitialized || x() != theX || y() != theY || z() != theZ) {
+ myExpression[0]->setValue(theX);
+ myExpression[1]->setValue(theY);
+ myExpression[2]->setValue(theZ);
owner()->data()->sendAttributeUpdated(this);
}
}
double GeomData_Point::x() const
{
- return myCoords->Value(0);
+ return myExpression[0]->value();
}
double GeomData_Point::y() const
{
- return myCoords->Value(1);
+ return myExpression[1]->value();
}
double GeomData_Point::z() const
{
- return myCoords->Value(2);
+ return myExpression[2]->value();
}
std::shared_ptr<GeomAPI_Pnt> GeomData_Point::pnt()
{
- std::shared_ptr<GeomAPI_Pnt> aResult(
- new GeomAPI_Pnt(myCoords->Value(0), myCoords->Value(1), myCoords->Value(2)));
+ std::shared_ptr<GeomAPI_Pnt> aResult(new GeomAPI_Pnt(x(), y(), z()));
return aResult;
}
const std::string& theY,
const std::string& theZ)
{
- TCollection_ExtendedString aX(theX.c_str());
- TCollection_ExtendedString aY(theY.c_str());
- TCollection_ExtendedString aZ(theZ.c_str());
-
- if (!myIsInitialized ||
- myTextArray->Value(0) != aX ||
- myTextArray->Value(1) != aY ||
- myTextArray->Value(2) != aZ) {
- myTextArray->SetValue(0, aX);
- myTextArray->SetValue(1, aY);
- myTextArray->SetValue(2, aZ);
+ if (!myIsInitialized || textX() != theX || textY() != theY || textZ() != theZ) {
+ myExpression[0]->setText(theX);
+ myExpression[1]->setText(theY);
+ myExpression[2]->setText(theZ);
// Send it to evaluator to convert into the double and store in the attribute
ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
owner()->data()->sendAttributeUpdated(this);
std::string GeomData_Point::textX()
{
- return TCollection_AsciiString(myTextArray->Value(0)).ToCString();;
+ return myExpression[0]->text();
}
std::string GeomData_Point::textY()
{
- return TCollection_AsciiString(myTextArray->Value(1)).ToCString();;
+ return myExpression[1]->text();
}
std::string GeomData_Point::textZ()
{
- return TCollection_AsciiString(myTextArray->Value(2)).ToCString();;
+ return myExpression[2]->text();
}
void GeomData_Point::setExpressionInvalid(int theComponent, bool theFlag)
{
- if (!myIsInitialized || myExpressionInvalidArray->Value(theComponent) != theFlag) {
- myExpressionInvalidArray->SetValue(theComponent, theFlag);
- }
+ assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
+ if (!myIsInitialized || expressionInvalid(theComponent) != theFlag)
+ myExpression[theComponent]->setInvalid(theFlag);
}
bool GeomData_Point::expressionInvalid(int theComponent)
{
- return myExpressionInvalidArray->Value(theComponent);
+ assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
+ return myExpression[theComponent]->isInvalid();
}
-GeomData_Point::GeomData_Point(TDF_Label& theLabel)
+void GeomData_Point::setExpressionError(int theComponent, const std::string& theError)
{
- myIsInitialized = true;
+ assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
+ if (expressionError(theComponent) != theError)
+ myExpression[theComponent]->setError(theError);
+}
- if (theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) != Standard_True) {
- // create attribute: not initialized by value yet, just zero
- myCoords = TDataStd_RealArray::Set(theLabel, 0, 2);
- myIsInitialized = false;
- }
- if (theLabel.FindAttribute(TDataStd_ExtStringArray::GetID(), myTextArray) != Standard_True) {
- // create attribute: not initialized by value yet, just zero
- myTextArray = TDataStd_ExtStringArray::Set(theLabel, 0, 2);
- myIsInitialized = false;
- }
- if (theLabel.FindAttribute(TDataStd_BooleanArray::GetID(), myExpressionInvalidArray) != Standard_True) {
- // create attribute: not initialized by value yet, just zero
- myExpressionInvalidArray = TDataStd_BooleanArray::Set(theLabel, 0, 2);
- myIsInitialized = false;
- }
+std::string GeomData_Point::expressionError(int theComponent)
+{
+ assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
+ return myExpression[theComponent]->error();
+}
+
+void GeomData_Point::setUsedParameters(int theComponent, const std::set<std::string>& theUsedParameters)
+{
+ assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
+ myExpression[theComponent]->setUsedParameters(theUsedParameters);
+}
+
+std::set<std::string> GeomData_Point::usedParameters(int theComponent) const
+{
+ assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
+ return myExpression[theComponent]->usedParameters();
}
#include "GeomData.h"
#include "GeomDataAPI_Point.h"
-#include <TDataStd_RealArray.hxx>
-#include <TDataStd_ExtStringArray.hxx>
-#include <TDataStd_BooleanArray.hxx>
+
#include <TDF_Label.hxx>
+class ModelAPI_Expression;
+
/**\class GeomData_Point
* \ingroup DataModel
* \brief Attribute that contains 3D point.
*/
-
class GeomData_Point : public GeomDataAPI_Point
{
- Handle_TDataStd_RealArray myCoords; ///< X, Y and Z doubles as real array attribute [0; 2]
- Handle_TDataStd_ExtStringArray myTextArray; ///< Text representation of the X, Y and Z attributes [0; 2]
- Handle_TDataStd_BooleanArray myExpressionInvalidArray; ///< Flag of invalid expression of the X, Y and Z attributes [0; 2]
+ enum { NUM_COMPONENTS = 3 };
+ std::shared_ptr<ModelAPI_Expression> 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);
/// Returns true if text is invalid
GEOMDATA_EXPORT virtual bool expressionInvalid(int);
+ /// Allows to set expression (text) error (by the parameters listener)
+ GEOMDATA_EXPORT virtual void setExpressionError(int theComponent, const std::string& theError);
+
+ /// Returns an expression error
+ GEOMDATA_EXPORT virtual std::string expressionError(int theComponent);
+
+ /// Defines the used parameters
+ GEOMDATA_EXPORT virtual void setUsedParameters(int theComponent,
+ const std::set<std::string>& theUsedParameters);
+
+ /// Returns the used parameters
+ GEOMDATA_EXPORT virtual std::set<std::string> usedParameters(int theComponent) const;
+
protected:
/// Initializes attributes
GEOMDATA_EXPORT GeomData_Point(TDF_Label& theLabel);
// Author: Mikhail PONIKAROV
#include "GeomData_Point2D.h"
+
#include <GeomAPI_Pnt2d.h>
-#include <ModelAPI_Feature.h>
+
#include <ModelAPI_Data.h>
#include <ModelAPI_Events.h>
+#include <ModelAPI_Expression.h>
+#include <ModelAPI_Feature.h>
+
+#include <cassert>
-using namespace std;
+GeomData_Point2D::GeomData_Point2D(TDF_Label& theLabel)
+{
+ myIsInitialized = true;
+}
void GeomData_Point2D::setCalculatedValue(const double theX, const double theY)
{
- if (!myIsInitialized || myCoords->Value(0) != theX || myCoords->Value(1) != theY) {
- myCoords->SetValue(0, theX);
- myCoords->SetValue(1, theY);
+ if (!myIsInitialized || x() != theX || y() != theY) {
+ myExpression[0]->setValue(theX);
+ myExpression[1]->setValue(theY);
owner()->data()->sendAttributeUpdated(this);
}
}
double GeomData_Point2D::x() const
{
- return myCoords->Value(0);
+ return myExpression[0]->value();
}
double GeomData_Point2D::y() const
{
- return myCoords->Value(1);
+ return myExpression[1]->value();
}
std::shared_ptr<GeomAPI_Pnt2d> GeomData_Point2D::pnt()
{
- std::shared_ptr<GeomAPI_Pnt2d> aResult(
- new GeomAPI_Pnt2d(myCoords->Value(0), myCoords->Value(1)));
+ std::shared_ptr<GeomAPI_Pnt2d> aResult(new GeomAPI_Pnt2d(x(), y()));
return aResult;
}
void GeomData_Point2D::setText(const std::string& theX,
const std::string& theY)
{
- TCollection_ExtendedString aX(theX.c_str());
- TCollection_ExtendedString aY(theY.c_str());
-
- if (!myIsInitialized ||
- myTextArray->Value(0) != aX ||
- myTextArray->Value(1) != aY) {
- myTextArray->SetValue(0, aX);
- myTextArray->SetValue(1, aY);
+ if (!myIsInitialized || textX() != theX || textY() != theY) {
+ myExpression[0]->setText(theX);
+ myExpression[1]->setText(theY);
// Send it to evaluator to convert into the double and store in the attribute
ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
owner()->data()->sendAttributeUpdated(this);
std::string GeomData_Point2D::textX()
{
- return TCollection_AsciiString(myTextArray->Value(0)).ToCString();;
+ return myExpression[0]->text();
}
std::string GeomData_Point2D::textY()
{
- return TCollection_AsciiString(myTextArray->Value(1)).ToCString();;
+ return myExpression[1]->text();
}
void GeomData_Point2D::setExpressionInvalid(int theComponent, bool theFlag)
{
- if (!myIsInitialized || myExpressionInvalidArray->Value(theComponent) != theFlag) {
- myExpressionInvalidArray->SetValue(theComponent, theFlag);
- }
+ assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
+ if (!myIsInitialized || expressionInvalid(theComponent) != theFlag)
+ myExpression[theComponent]->setInvalid(theFlag);
}
bool GeomData_Point2D::expressionInvalid(int theComponent)
{
- return myExpressionInvalidArray->Value(theComponent);
+ assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
+ return myExpression[theComponent]->isInvalid();
}
-GeomData_Point2D::GeomData_Point2D(TDF_Label& theLabel)
+void GeomData_Point2D::setExpressionError(int theComponent, const std::string& theError)
{
- myIsInitialized = true;
+ assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
+ if (expressionError(theComponent) != theError)
+ myExpression[theComponent]->setError(theError);
+}
- if (theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) != Standard_True) {
- // create attribute: not initialized by value yet, just zero
- myCoords = TDataStd_RealArray::Set(theLabel, 0, 1);
- myIsInitialized = false;
- }
- if (theLabel.FindAttribute(TDataStd_ExtStringArray::GetID(), myTextArray) != Standard_True) {
- // create attribute: not initialized by value yet, just zero
- myTextArray = TDataStd_ExtStringArray::Set(theLabel, 0, 1);
- myIsInitialized = false;
- }
- if (theLabel.FindAttribute(TDataStd_BooleanArray::GetID(), myExpressionInvalidArray) != Standard_True) {
- // create attribute: not initialized by value yet, just zero
- myExpressionInvalidArray = TDataStd_BooleanArray::Set(theLabel, 0, 1);
- myIsInitialized = false;
- }
+std::string GeomData_Point2D::expressionError(int theComponent)
+{
+ assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
+ return myExpression[theComponent]->error();
+}
+
+void GeomData_Point2D::setUsedParameters(int theComponent, const std::set<std::string>& theUsedParameters)
+{
+ assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
+ myExpression[theComponent]->setUsedParameters(theUsedParameters);
+}
+
+std::set<std::string> GeomData_Point2D::usedParameters(int theComponent) const
+{
+ assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
+ return myExpression[theComponent]->usedParameters();
}
#include "GeomData.h"
#include "GeomDataAPI_Point2D.h"
-#include <TDataStd_RealArray.hxx>
-#include <TDataStd_ExtStringArray.hxx>
-#include <TDataStd_BooleanArray.hxx>
+
#include <TDF_Label.hxx>
+class ModelAPI_Expression;
+
/**\class GeomData_Point2D
* \ingroup DataModel
* \brief Attribute that contains 2D point.
class GeomData_Point2D : public GeomDataAPI_Point2D
{
- Handle_TDataStd_RealArray myCoords; ///< X and Y doubles as real array attribute [0; 1]
- Handle_TDataStd_ExtStringArray myTextArray; ///< Text representation of the X, Y and Z attributes [0; 2]
- Handle_TDataStd_BooleanArray myExpressionInvalidArray; ///< Flag of invalid expression of the X, Y and Z attributes [0; 2]
+ enum { NUM_COMPONENTS = 2 };
+ std::shared_ptr<ModelAPI_Expression> myExpression[NUM_COMPONENTS]; ///< Expressions for X, Y
public:
/// Defines the double value
GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY);
/// Returns true if text is invalid
GEOMDATA_EXPORT virtual bool expressionInvalid(int);
+ /// Allows to set expression (text) error (by the parameters listener)
+ GEOMDATA_EXPORT virtual void setExpressionError(int theComponent, const std::string& theError);
+
+ /// Returns an expression error
+ GEOMDATA_EXPORT virtual std::string expressionError(int theComponent);
+
+ /// Defines the used parameters
+ GEOMDATA_EXPORT virtual void setUsedParameters(int theComponent,
+ const std::set<std::string>& theUsedParameters);
+
+ /// Returns the used parameters
+ GEOMDATA_EXPORT virtual std::set<std::string> usedParameters(int theComponent) const;
+
protected:
/// Initializes attributes
GEOMDATA_EXPORT GeomData_Point2D(TDF_Label& theLabel);
#include "GeomDataAPI.h"
#include <ModelAPI_Attribute.h>
+#include <set>
+
class GeomAPI_Pnt;
/**\class GeomDataAPI_Point
/// Returns true if text is invalid
GEOMDATAAPI_EXPORT virtual bool expressionInvalid(int theComponent) = 0;
+ /// Allows to set expression (text) error (by the parameters listener)
+ GEOMDATAAPI_EXPORT virtual void setExpressionError(int theComponent, const std::string& theError) = 0;
+
+ /// Returns an expression error
+ GEOMDATAAPI_EXPORT virtual std::string expressionError(int theComponent) = 0;
+
+ /// Defines the used parameters
+ GEOMDATAAPI_EXPORT virtual void setUsedParameters(int theComponent,
+ const std::set<std::string>& theUsedParameters) = 0;
+
+ /// Returns the used parameters
+ GEOMDATAAPI_EXPORT virtual std::set<std::string> usedParameters(int theComponent) const = 0;
+
/// Returns the type of this class of attributes
static std::string typeId()
{
#include <GeomDataAPI.h>
#include <ModelAPI_Attribute.h>
+#include <set>
+
class GeomAPI_Pnt2d;
/**\class GeomDataAPI_Point2D
/// Returns true if text is invalid
GEOMDATAAPI_EXPORT virtual bool expressionInvalid(int theComponent) = 0;
+ /// Allows to set expression (text) error (by the parameters listener)
+ GEOMDATAAPI_EXPORT virtual void setExpressionError(int theComponent, const std::string& theError) = 0;
+
+ /// Returns an expression error
+ GEOMDATAAPI_EXPORT virtual std::string expressionError(int theComponent) = 0;
+
+ /// Defines the used parameters
+ GEOMDATAAPI_EXPORT virtual void setUsedParameters(int theComponent,
+ const std::set<std::string>& theUsedParameters) = 0;
+
+ /// Returns the used parameters
+ GEOMDATAAPI_EXPORT virtual std::set<std::string> usedParameters(int theComponent) const = 0;
+
/// Appends the delta values to point
GEOMDATAAPI_EXPORT void move(const double theDeltaX, const double theDeltaY);
Model_AttributeSelectionList.h
Model_BodyBuilder.h
Model_Events.h
+ Model_Expression.h
Model_Update.h
Model_Validator.h
Model_ResultBody.h
Model_AttributeSelectionList.cpp
Model_BodyBuilder.cpp
Model_Events.cpp
+ Model_Expression.cpp
Model_Update.cpp
Model_Validator.cpp
Model_ResultBody.cpp
// Author: Mikhail PONIKAROV
#include "Model_AttributeDouble.h"
-#include <ModelAPI_Feature.h>
+
#include <ModelAPI_Data.h>
#include <ModelAPI_Events.h>
+#include <ModelAPI_Expression.h>
+#include <ModelAPI_Feature.h>
-#include <TCollection_AsciiString.hxx>
-#include <TCollection_ExtendedString.hxx>
-#include <TDataStd_UAttribute.hxx>
-
-using namespace std;
+Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
+{
+ myIsInitialized = true;
+}
void Model_AttributeDouble::setCalculatedValue(const double theValue)
{
- if (!myIsInitialized || myReal->Get() != theValue) {
- myReal->Set(theValue);
+ if (!myIsInitialized || value() != theValue) {
+ myExpression->setValue(theValue);
owner()->data()->sendAttributeUpdated(this);
}
}
double Model_AttributeDouble::value()
{
- return myReal->Get();
-}
-
-Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
-{
- // check the attribute could be already presented in this doc (after load document)
- myIsInitialized = theLabel.FindAttribute(TDataStd_Real::GetID(), myReal) == Standard_True;
- if (!myIsInitialized) {
- // create attribute: not initialized by value yet, just zero
- myReal = TDataStd_Real::Set(theLabel, 0.);
- }
- if (!theLabel.FindAttribute(TDataStd_Name::GetID(), myText)) {
- myText = TDataStd_Name::Set(theLabel, TCollection_ExtendedString());
- }
+ return myExpression->value();
}
void Model_AttributeDouble::setText(const std::string& theValue)
{
- TCollection_ExtendedString aValue(theValue.c_str());
- if (myText->Get() != aValue) {
- myText->Set(aValue);
+ if (text() != theValue) {
+ myExpression->setText(theValue);
// Send it to evaluator to convert into the double and store in the attribute
ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this);
owner()->data()->sendAttributeUpdated(this);
}
}
-string Model_AttributeDouble::text()
+std::string Model_AttributeDouble::text()
{
- return TCollection_AsciiString(myText->Get()).ToCString();
+ return myExpression->text();
}
-Standard_GUID kInvalidGUID("caee5ce4-34b1-4b29-abcb-685287d18096");
-
void Model_AttributeDouble::setExpressionInvalid(const bool theFlag)
{
- if (theFlag) {
- TDataStd_UAttribute::Set(myReal->Label(), kInvalidGUID);
- } else {
- myReal->Label().ForgetAttribute(kInvalidGUID);
- }
+ myExpression->setInvalid(theFlag);
}
bool Model_AttributeDouble::expressionInvalid()
{
- return myReal->Label().IsAttribute(kInvalidGUID) == Standard_True;
+ return myExpression->isInvalid();
+}
+
+void Model_AttributeDouble::setExpressionError(const std::string& theError)
+{
+ if (expressionError() != theError)
+ myExpression->setError(theError);
+}
+
+std::string Model_AttributeDouble::expressionError()
+{
+ return myExpression->error();
+}
+
+void Model_AttributeDouble::setUsedParameters(const std::set<std::string>& theUsedParameters)
+{
+ myExpression->setUsedParameters(theUsedParameters);
+}
+
+std::set<std::string> Model_AttributeDouble::usedParameters() const
+{
+ return myExpression->usedParameters();
}
#include "Model.h"
#include "ModelAPI_AttributeDouble.h"
-#include <TDataStd_Real.hxx>
+
#include <TDF_Label.hxx>
-#include <TDataStd_Name.hxx>
+class ModelAPI_Expression;
/**\class Model_AttributeDouble
* \ingroup DataModel
class Model_AttributeDouble : public ModelAPI_AttributeDouble
{
- Handle_TDataStd_Real myReal; ///< double is Real attribute
- Handle_TDataStd_Name myText; ///< Text representation of the attribute (may differ for parametres)
+ std::shared_ptr<ModelAPI_Expression> myExpression;
+
public:
/// Defines the double value
MODEL_EXPORT virtual void setValue(const double theValue);
/// 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 attibutes
+ /// Initializes attributes
Model_AttributeDouble(TDF_Label& theLabel);
friend class Model_Data;
#include <Model_AttributeSelectionList.h>
#include <Model_AttributeIntArray.h>
#include <Model_Events.h>
+#include <Model_Expression.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Result.h>
#include <ModelAPI_Validator.h>
} else if (theAttrType == Model_AttributeInteger::typeId()) {
anAttr = new Model_AttributeInteger(anAttrLab);
} else if (theAttrType == ModelAPI_AttributeDouble::typeId()) {
- anAttr = new Model_AttributeDouble(anAttrLab);
+ Model_AttributeDouble* anAttribute = new Model_AttributeDouble(anAttrLab);
+ anAttribute->myExpression.reset(new Model_Expression(myLab.FindChild(myLab.NbChildren() + 1)));
+ anAttribute->myIsInitialized = anAttribute->myIsInitialized && anAttribute->myExpression->isInitialized();
+ anAttr = anAttribute;
} else if (theAttrType == Model_AttributeBoolean::typeId()) {
anAttr = new Model_AttributeBoolean(anAttrLab);
} else if (theAttrType == Model_AttributeString::typeId()) {
}
// create also GeomData attributes here because only here the OCAF structure is known
else if (theAttrType == GeomData_Point::typeId()) {
- anAttr = new GeomData_Point(anAttrLab);
+ GeomData_Point* anAttribute = new GeomData_Point(anAttrLab);
+ for (int aComponent = 0; aComponent < GeomData_Point::NUM_COMPONENTS; ++aComponent) {
+ anAttribute->myExpression[aComponent].reset(new Model_Expression(myLab.FindChild(myLab.NbChildren() + 1)));
+ anAttribute->myIsInitialized = anAttribute->myIsInitialized && anAttribute->myExpression[aComponent]->isInitialized();
+ }
+ anAttr = anAttribute;
} else if (theAttrType == GeomData_Dir::typeId()) {
anAttr = new GeomData_Dir(anAttrLab);
} else if (theAttrType == GeomData_Point2D::typeId()) {
- anAttr = new GeomData_Point2D(anAttrLab);
+ GeomData_Point2D* anAttribute = new GeomData_Point2D(anAttrLab);
+ for (int aComponent = 0; aComponent < GeomData_Point2D::NUM_COMPONENTS; ++aComponent) {
+ anAttribute->myExpression[aComponent].reset(new Model_Expression(myLab.FindChild(myLab.NbChildren() + 1)));
+ anAttribute->myIsInitialized = anAttribute->myIsInitialized && anAttribute->myExpression[aComponent]->isInitialized();
+ }
+ anAttr = anAttribute;
}
if (anAttr) {
aResult = std::shared_ptr<ModelAPI_Attribute>(anAttr);
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: Model_Expression.cpp
+// Created: 5 Aug 2015
+// Author: Sergey POKHODENKO
+
+#include "Model_Expression.h"
+
+#include <TCollection_AsciiString.hxx>
+#include <TCollection_ExtendedString.hxx>
+#include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
+#include <TDataStd_UAttribute.hxx>
+
+Model_Expression::Model_Expression(TDF_Label& theLabel)
+{
+ myIsInitialized = true;
+ if (!theLabel.FindAttribute(TDataStd_Real::GetID(), myReal)) {
+ myReal = TDataStd_Real::Set(theLabel, 0.);
+ myIsInitialized = false;
+ }
+ if (!theLabel.FindAttribute(TDataStd_Name::GetID(), myText)) {
+ myText = TDataStd_Name::Set(theLabel, TCollection_ExtendedString());
+ myIsInitialized = false;
+ }
+ if (!theLabel.FindAttribute(TDataStd_Comment::GetID(), myError)) {
+ myError = TDataStd_Comment::Set(theLabel, TCollection_ExtendedString());
+ myIsInitialized = false;
+ }
+ if (!theLabel.FindAttribute(TDataStd_ExtStringList::GetID(), myUsedParameters)) {
+ myUsedParameters = TDataStd_ExtStringList::Set(theLabel);
+ myIsInitialized = false;
+ }
+}
+
+void Model_Expression::setValue(const double theValue)
+{
+ if (value() != theValue)
+ myReal->Set(theValue);
+}
+
+double Model_Expression::value()
+{
+ return myReal->Get();
+}
+
+void Model_Expression::setText(const std::string& theValue)
+{
+ if (text() != theValue)
+ myText->Set(TCollection_ExtendedString(theValue.c_str()));
+}
+
+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)
+{
+ if (theFlag) {
+ TDataStd_UAttribute::Set(myReal->Label(), kInvalidGUID);
+ } else {
+ myReal->Label().ForgetAttribute(kInvalidGUID);
+ }
+}
+
+bool Model_Expression::isInvalid()
+{
+ return myReal->Label().IsAttribute(kInvalidGUID) == Standard_True;
+}
+
+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;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: Model_Expression.h
+// Created: 5 Aug 2015
+// Author: Sergey POKHODENKO
+
+#ifndef Model_Expression_H_
+#define Model_Expression_H_
+
+#include "Model.h"
+#include "ModelAPI_Expression.h"
+
+#include <TDataStd_Comment.hxx>
+#include <TDataStd_ExtStringList.hxx>
+#include <TDataStd_Name.hxx>
+#include <TDataStd_Real.hxx>
+
+#include <TDF_Label.hxx>
+
+/**\class Model_Expression
+ * \ingroup DataModel
+ * \brief Implementation of ModelAPI_Expression.
+ */
+class Model_Expression : public 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);
+
+ /// Returns an expression error
+ MODEL_EXPORT virtual std::string error();
+
+ /// Defines the used parameters (by the parameters listener)
+ 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_Expression(TDF_Label& theLabel);
+
+ friend class Model_Data;
+};
+
+#endif
ModelAPI_Data.h
ModelAPI_Document.h
ModelAPI_Events.h
+ ModelAPI_Expression.h
ModelAPI_Feature.h
ModelAPI_FeatureValidator.h
ModelAPI_Object.h
ModelAPI_Data.cpp
ModelAPI_Document.cpp
ModelAPI_Events.cpp
+ ModelAPI_Expression.cpp
ModelAPI_Feature.cpp
ModelAPI_FeatureValidator.cpp
ModelAPI_Object.cpp
/// Returns true if attribute causes the result change
MODELAPI_EXPORT bool isArgument();
- /// Immutable argument can not be changed programaticaly (e.g. by constraint)
+ /// Immutable argument can not be changed programmatically (e.g. by constraint)
/// By default it is false.
/// Returns the previous state of the attribute's immutability.
MODELAPI_EXPORT bool setImmutable(const bool theFlag);
- /// Returns true if can not be changed programaticaly
+ /// Returns true if can not be changed programmatically
MODELAPI_EXPORT bool isImmutable();
/// ID of the attribute in Data
#include "ModelAPI_Attribute.h"
+#include <set>
+
+class ModelAPI_Expression;
+
/**\class ModelAPI_AttributeDouble
* \ingroup DataModel
* \brief Attribute that contains real value with double precision.
/// 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()
{
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModelAPI_Expression.cpp
+// Created: 5 Aug 2015
+// Author: Sergey POKHODENKO
+
+#include "ModelAPI_Expression.h"
+
+ModelAPI_Expression::ModelAPI_Expression()
+{
+
+}
+
+ModelAPI_Expression::~ModelAPI_Expression()
+{
+
+}
+
+bool ModelAPI_Expression::isInitialized()
+{
+ return myIsInitialized;
+}
+
+void ModelAPI_Expression::setInitialized()
+{
+ myIsInitialized = true;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModelAPI_Expression.h
+// Created: 5 Aug 2015
+// Author: Sergey POKHODENKO
+
+#ifndef ModelAPI_Expression_H_
+#define ModelAPI_Expression_H_
+
+#include "ModelAPI.h"
+#include <memory>
+#include <set>
+#include <string>
+
+/**\class ModelAPI_Expression
+ * \ingroup DataModel
+ * \brief Expression for calculated values.
+ */
+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();
+
+ /// Returns true if attribute was initialized by some value
+ MODELAPI_EXPORT virtual bool isInitialized();
+
+ /// 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;
+
+ /// Returns the text of this Expression
+ MODELAPI_EXPORT virtual std::string text() const = 0;
+
+ /// Allows to set expression (text) as invalid (by the parameters listener)
+ MODELAPI_EXPORT virtual void setInvalid(const bool theFlag) = 0;
+
+ /// Returns true if text is invalid
+ MODELAPI_EXPORT virtual bool isInvalid() = 0;
+
+ /// Allows to set expression (text) error (by the parameters listener)
+ MODELAPI_EXPORT virtual void setError(const std::string& theError) = 0;
+
+ /// Returns an expression error
+ MODELAPI_EXPORT virtual std::string error() = 0;
+
+ /// Defines the used parameters (by the parameters listener)
+ 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;
+
+ protected:
+ /// Objects are created for features automatically
+ MODELAPI_EXPORT ModelAPI_Expression();
+
+ friend class Model_Data;
+};
+
+//! Pointer on Expression object
+typedef std::shared_ptr<ModelAPI_Expression> ExpressionPtr;
+
+#endif