GeomData_Dir::GeomData_Dir(TDF_Label& theLabel)
{
- myIsInitialized = theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords) == Standard_True;
+ myLab = theLabel;
+ reinit();
+}
+
+void GeomData_Dir::reinit()
+{
+ myIsInitialized = myLab.FindAttribute(TDataStd_RealArray::GetID(), myCoords) == Standard_True;
if (!myIsInitialized) {
// create attribute: not initialized by value yet, just zero
- myCoords = TDataStd_RealArray::Set(theLabel, 0, 2);
+ myCoords = TDataStd_RealArray::Set(myLab, 0, 2);
}
}
*/
class GeomData_Dir : public GeomDataAPI_Dir
{
+ TDF_Label myLab; ///< the main label of the attribute
Handle_TDataStd_RealArray myCoords; ///< X, Y and Z doubles as real array attribute [0; 2]
public:
/// Defines the double value
protected:
/// Initializes attributes
GEOMDATA_EXPORT GeomData_Dir(TDF_Label& theLabel);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
friend class Model_Data;
};
myIsInitialized = false;
}
+void GeomData_Point::reinit()
+{
+ myIsInitialized = true;
+ for (int aComponent = 0; aComponent < NUM_COMPONENTS; ++aComponent) {
+ myExpression[aComponent]->reinit();
+ myIsInitialized = myIsInitialized && myExpression[aComponent]->isInitialized();
+ }
+}
+
void GeomData_Point::setCalculatedValue(const double theX, const double theY, const double theZ)
{
if (!myIsInitialized || x() != theX || y() != theY || z() != theZ) {
protected:
/// Initializes attributes
GEOMDATA_EXPORT GeomData_Point();
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
friend class Model_Data;
};
myIsInitialized = false;
}
+void GeomData_Point2D::reinit()
+{
+ myIsInitialized = true;
+ for (int aComponent = 0; aComponent < NUM_COMPONENTS; ++aComponent) {
+ myExpression[aComponent]->reinit();
+ myIsInitialized = myIsInitialized && myExpression[aComponent]->isInitialized();
+ }
+}
+
void GeomData_Point2D::setCalculatedValue(const double theX, const double theY)
{
if (!myIsInitialized || x() != theX || y() != theY) {
protected:
/// Initializes attributes
GEOMDATA_EXPORT GeomData_Point2D();
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
friend class Model_Data;
};
Model_AttributeBoolean::Model_AttributeBoolean(TDF_Label& theLabel)
{
myLab = theLabel;
+ reinit();
+}
+
+void Model_AttributeBoolean::reinit()
+{
// check the attribute could be already presented in this doc (after load document)
- myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), myBool) == Standard_True;
+ myIsInitialized = myLab.FindAttribute(TDataStd_Integer::GetID(), myBool) == Standard_True;
}
/// Initializes attibutes
Model_AttributeBoolean(TDF_Label& theLabel);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
+
friend class Model_Data;
};
myID = TDataStd_Integer::Set(theLabel, aNewID);
}
}
+
+void Model_AttributeDocRef::reinit()
+{
+ // myLab is unknown, nevertheless, lose of attribute DocRef for live feature seems impossible
+}
/// Initializes attibutes
Model_AttributeDocRef(TDF_Label& theLabel);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
+
friend class Model_Data;
};
#include <ModelAPI_Data.h>
#include <ModelAPI_Events.h>
-#include <ModelAPI_Expression.h>
+#include <Model_Expression.h>
#include <ModelAPI_Object.h>
-Model_AttributeDouble::Model_AttributeDouble()
+Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel)
{
- myIsInitialized = false;
+ TDF_Label anExpressionLab = theLabel.FindChild(1);
+ myExpression.reset(new Model_ExpressionDouble(anExpressionLab));
+ myIsInitialized = myExpression->isInitialized();
+}
+
+void Model_AttributeDouble::reinit()
+{
+ myExpression->reinit();
+ myIsInitialized = myExpression->isInitialized();
}
void Model_AttributeDouble::setCalculatedValue(const double theValue)
protected:
/// Initializes attributes
- Model_AttributeDouble();
+ Model_AttributeDouble(TDF_Label& theLabel);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
friend class Model_Data;
};
Model_AttributeDoubleArray::Model_AttributeDoubleArray(TDF_Label& theLabel)
{
myLab = theLabel;
+ reinit();
+}
+
+void Model_AttributeDoubleArray::reinit()
+{
// check the attribute could be already presented in this doc (after load document)
myIsInitialized =
myLab.FindAttribute(TDataStd_RealArray::GetID(), myArray) == Standard_True;
protected:
/// Initializes attibutes
Model_AttributeDoubleArray(TDF_Label& theLabel);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
private:
/// The OCCT array that keeps all values.
Model_AttributeIntArray::Model_AttributeIntArray(TDF_Label& theLabel)
{
myLab = theLabel;
+ reinit();
+}
+
+void Model_AttributeIntArray::reinit()
+{
// check the attribute could be already presented in this doc (after load document)
myIsInitialized =
myLab.FindAttribute(TDataStd_IntegerArray::GetID(), myArray) == Standard_True;
protected:
/// Initializes attibutes
Model_AttributeIntArray(TDF_Label& theLabel);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
friend class Model_Data;
};
#include <ModelAPI_Data.h>
#include <ModelAPI_Events.h>
-#include <ModelAPI_Expression.h>
+#include <Model_Expression.h>
#include <ModelAPI_Object.h>
-Model_AttributeInteger::Model_AttributeInteger()
+Model_AttributeInteger::Model_AttributeInteger(TDF_Label& theLabel)
{
- myIsInitialized = false;
+ // to the same label to support the backward compatibility
+ myExpression.reset(new Model_ExpressionInteger(theLabel));
+ myIsInitialized = myExpression->isInitialized();
+}
+
+void Model_AttributeInteger::reinit()
+{
+ myExpression->reinit();
+ myIsInitialized = myExpression->isInitialized();
}
void Model_AttributeInteger::setCalculatedValue(const int theValue)
protected:
/// Initializes attributes
- Model_AttributeInteger();
+ Model_AttributeInteger(TDF_Label& theLabel);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
friend class Model_Data;
Model_AttributeRefAttr::Model_AttributeRefAttr(TDF_Label& theLabel)
{
- myIsInitialized = theLabel.FindAttribute(TDataStd_Comment::GetID(), myID) == Standard_True;
+ myLab = theLabel;
+ reinit();
+}
+
+void Model_AttributeRefAttr::reinit()
+{
+ myIsInitialized = myLab.FindAttribute(TDataStd_Comment::GetID(), myID) == Standard_True;
if (!myIsInitialized) {
// create attribute: not initialized by value yet
- myID = TDataStd_Comment::Set(theLabel, "");
- myRef = TDF_Reference::Set(theLabel, theLabel); // not initialized: reference to itself
+ myID = TDataStd_Comment::Set(myLab, "");
+ myRef = TDF_Reference::Set(myLab, myLab); // not initialized: reference to itself
} else {
- theLabel.FindAttribute(TDF_Reference::GetID(), myRef);
+ myLab.FindAttribute(TDF_Reference::GetID(), myRef);
}
}
class Model_AttributeRefAttr : public ModelAPI_AttributeRefAttr
{
Handle_TDF_Reference myRef; ///< reference to the feature label
+ TDF_Label myLab; ///< the main label of this attribute
///< ID of the referenced attribute (empty if this is a reference to a feature)
Handle_TDataStd_Comment myID;
public:
protected:
/// Objects are created for features automatically
MODEL_EXPORT Model_AttributeRefAttr(TDF_Label& theLabel);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
friend class Model_Data;
};
Model_AttributeRefAttrList::Model_AttributeRefAttrList(TDF_Label& theLabel)
{
- myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
+ myLab = theLabel;
+ reinit();
+}
+
+void Model_AttributeRefAttrList::reinit()
+{
+ myIsInitialized = myLab.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
if (!myIsInitialized) {
- myRef = TDataStd_ReferenceList::Set(theLabel);
- myIDs = TDataStd_ExtStringList::Set(theLabel);
+ myRef = TDataStd_ReferenceList::Set(myLab);
+ myIDs = TDataStd_ExtStringList::Set(myLab);
} else {
- theLabel.FindAttribute(TDataStd_ExtStringList::GetID(), myIDs);
+ myLab.FindAttribute(TDataStd_ExtStringList::GetID(), myIDs);
}
}
#include "ModelAPI_AttributeRefAttrList.h"
#include "ModelAPI_Feature.h"
+#include <TDF_Label.hxx>
#include <TDataStd_ReferenceList.hxx>
#include <TDataStd_ExtStringList.hxx>
class Model_AttributeRefAttrList : public ModelAPI_AttributeRefAttrList
{
+ TDF_Label myLab; ///< the main label of this attribute
Handle_TDataStd_ReferenceList myRef; ///< references to the features labels
Handle_TDataStd_ExtStringList myIDs; ///< the referenced attributes IDs (empty for just object)
public:
protected:
/// Objects are created for features automatically
MODEL_EXPORT Model_AttributeRefAttrList(TDF_Label& theLabel);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
friend class Model_Data;
};
Model_AttributeRefList::Model_AttributeRefList(TDF_Label& theLabel)
{
- myIsInitialized = theLabel.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
+ myLab = theLabel;
+ reinit();
+}
+
+void Model_AttributeRefList::reinit()
+{
+ myIsInitialized = myLab.FindAttribute(TDataStd_ReferenceList::GetID(), myRef) == Standard_True;
if (!myIsInitialized) {
- myRef = TDataStd_ReferenceList::Set(theLabel);
+ myRef = TDataStd_ReferenceList::Set(myLab);
}
- if (!theLabel.FindAttribute(TDataStd_ExtStringList::GetID(), myExtDocRef)) {
- myExtDocRef = TDataStd_ExtStringList::Set(theLabel);
+ if (!myLab.FindAttribute(TDataStd_ExtStringList::GetID(), myExtDocRef)) {
+ myExtDocRef = TDataStd_ExtStringList::Set(myLab);
}
}
class Model_AttributeRefList : public ModelAPI_AttributeRefList
{
+ TDF_Label myLab; ///< the main label of this attribute
Handle_TDataStd_ReferenceList myRef; ///< references to the features labels
/// pairs of doc ID and entries if reference is to external object, appends some in this list if
/// something in myRef is empty
protected:
/// Objects are created for features automatically
MODEL_EXPORT Model_AttributeRefList(TDF_Label& theLabel);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
/// Returns the object by iterators (theExtIter is iterated if necessary)
ObjectPtr iteratedObject(TDF_ListIteratorOfLabelList& theLIter,
TDataStd_ListIteratorOfListOfExtendedString& theExtIter,
Model_AttributeReference::Model_AttributeReference(TDF_Label& theLabel)
{
- myIsInitialized = theLabel.FindAttribute(TDF_Reference::GetID(), myRef) == Standard_True;
+ myLab = theLabel;
+ reinit();
+}
+
+void Model_AttributeReference::reinit()
+{
+ myIsInitialized = myLab.FindAttribute(TDF_Reference::GetID(), myRef) == Standard_True;
if (!myIsInitialized) {
- myRef = TDF_Reference::Set(theLabel, theLabel); // not initialized references to itself
+ myRef = TDF_Reference::Set(myLab, myLab); // not initialized references to itself
} else {
if (owner()) {
std::shared_ptr<Model_Document> aDoc =
class Model_AttributeReference : public ModelAPI_AttributeReference
{
+ TDF_Label myLab; ///< the main label of this attribute
Handle_TDF_Reference myRef; ///< references to the feature label
public:
/// Defines the object referenced from this attribute
protected:
/// Objects are created for features automatically
MODEL_EXPORT Model_AttributeReference(TDF_Label& theLabel);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
friend class Model_Data;
friend class Model_AttributeSelection;
protected:
/// Objects are created for features automatically
MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel);
- /// Performs the selection for the body result (TNaming Selection)
+
+ /// Performs the selection for the body result (TNaming Selection)
/// Performs the selection for the body result (TNaming selection)
virtual void selectBody(
Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
{
- myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
+ myLab = theLabel;
+ reinit();
+}
+
+void Model_AttributeSelectionList::reinit()
+{
+ myIsInitialized = myLab.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;
if (!myIsInitialized) {
- mySize = TDataStd_Integer::Set(theLabel, 0);
- mySelectionType = TDataStd_Comment::Set(theLabel, "");
+ mySize = TDataStd_Integer::Set(myLab, 0);
+ mySelectionType = TDataStd_Comment::Set(myLab, "");
} else { // recollect mySubs
- theLabel.FindAttribute(TDataStd_Comment::GetID(), mySelectionType);
+ myLab.FindAttribute(TDataStd_Comment::GetID(), mySelectionType);
}
myIsCashed = false;
}
+
void Model_AttributeSelectionList::cashValues(const bool theEnabled)
{
myIsCashed = theEnabled;
class Model_AttributeSelectionList : public ModelAPI_AttributeSelectionList
{
+ TDF_Label myLab; ///< the main label of this attribute
Handle(TDataStd_Integer) mySize; ///< Contains size of this list
/// Contains current type name (same as selection attribute)
Handle(TDataStd_Comment) mySelectionType;
protected:
/// Objects are created for features automatically
MODEL_EXPORT Model_AttributeSelectionList(TDF_Label& theLabel);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
friend class Model_Data;
};
Model_AttributeString::Model_AttributeString(TDF_Label& theLabel)
{
myLab = theLabel;
+ reinit();
+}
+
+void Model_AttributeString::reinit()
+{
// check the attribute could be already presented in this doc (after load document)
- myIsInitialized = theLabel.FindAttribute(TDataStd_Name::GetID(), myString) == Standard_True;
+ myIsInitialized = myLab.FindAttribute(TDataStd_Name::GetID(), myString) == Standard_True;
}
protected:
/// Initializes attibutes
Model_AttributeString(TDF_Label& theLabel);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
friend class Model_Data;
};
if (theAttrType == ModelAPI_AttributeDocRef::typeId()) {
anAttr = new Model_AttributeDocRef(anAttrLab);
} else if (theAttrType == Model_AttributeInteger::typeId()) {
- Model_AttributeInteger* anAttribute = new Model_AttributeInteger();
- // Expression should use the same label to support backward compatibility
- TDF_Label anExpressionLab = anAttrLab;
- anAttribute->myExpression.reset(new Model_ExpressionInteger(anExpressionLab));
- anAttribute->myIsInitialized = anAttribute->myExpression->isInitialized();
- anAttr = anAttribute;
+ anAttr = new Model_AttributeInteger(anAttrLab);
} else if (theAttrType == ModelAPI_AttributeDouble::typeId()) {
- Model_AttributeDouble* anAttribute = new Model_AttributeDouble();
- TDF_Label anExpressionLab = anAttrLab.FindChild(1);
- anAttribute->myExpression.reset(new Model_ExpressionDouble(anExpressionLab));
- anAttribute->myIsInitialized = anAttribute->myExpression->isInitialized();
- anAttr = anAttribute;
+ anAttr = new Model_AttributeDouble(anAttrLab);
} else if (theAttrType == Model_AttributeBoolean::typeId()) {
anAttr = new Model_AttributeBoolean(anAttrLab);
} else if (theAttrType == Model_AttributeString::typeId()) {
return aResult;
}
+///////////////// Model_ExpressionDouble /////////////
Model_ExpressionDouble::Model_ExpressionDouble(TDF_Label& theLabel)
: Model_Expression(theLabel)
{
- if (!theLabel.FindAttribute(TDataStd_Real::GetID(), myReal)) {
+ myLab = theLabel;
+ reinit();
+}
+
+void Model_ExpressionDouble::reinit()
+{
+ if (!myLab.FindAttribute(TDataStd_Real::GetID(), myReal)) {
myIsInitialized = false;
- // MPV: temporarily to support the previously saved files (to check and resolve bugs), to be removed
- Handle(TDataStd_RealArray) anOldArray;
- if (theLabel.Father().FindAttribute(TDataStd_RealArray::GetID(), anOldArray) == Standard_True) {
- myReal = TDataStd_Real::Set(theLabel, 0.);
- myReal->Set(anOldArray->Value(theLabel.Tag() - 1));
- myIsInitialized = true;
- Handle(TDataStd_ExtStringArray) anOldExp;
- if (theLabel.Father().FindAttribute(TDataStd_ExtStringArray::GetID(), anOldExp) == Standard_True) {
- myText->Set(anOldExp->Value(theLabel.Tag() - 1));
- }
- } else {
- Handle(TDataStd_Real) anOldReal;
- if (theLabel.Father().FindAttribute(TDataStd_Real::GetID(), anOldReal)) {
- myIsInitialized = true;
- myReal = TDataStd_Real::Set(theLabel, 0.);
- myReal->Set(anOldReal->Get());
- Handle(TDataStd_Name) aText;
- if (theLabel.Father().FindAttribute(TDataStd_Name::GetID(), aText)) {
- myText->Set(aText->Get());
- }
- }
- }
- } else
+ } else {
myIsInitialized = true;
+ }
}
void Model_ExpressionDouble::setValue(const double theValue)
return myText->Label().IsAttribute(kInvalidGUID) == Standard_True;
}
-
+///////////////// Model_ExpressionInteger /////////////
Model_ExpressionInteger::Model_ExpressionInteger(TDF_Label& theLabel)
: Model_Expression(theLabel)
{
- if (!theLabel.FindAttribute(TDataStd_Integer::GetID(), myInteger)) {
+ myLab = theLabel;
+ reinit();
+}
+
+void Model_ExpressionInteger::reinit()
+{
+ if (!myLab.FindAttribute(TDataStd_Integer::GetID(), myInteger)) {
myIsInitialized = false;
- } else
+ } else {
myIsInitialized = true;
+ }
}
void Model_ExpressionInteger::setValue(const int theValue)
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;
+ TDF_Label myLab; ///< if attribute is not initialized, store label here
};
protected:
/// Initializes attributes
Model_ExpressionDouble(TDF_Label& theLabel);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
+ friend class Model_AttributeDouble;
friend class Model_Data;
private:
protected:
/// Initializes attributes
Model_ExpressionInteger(TDF_Label& theLabel);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ virtual void reinit();
- friend class Model_Data;
+ friend class Model_AttributeInteger;
private:
Handle_TDataStd_Integer myInteger;
aKeptFeatures.insert(aFeature);
if (anUpdatedMap.Contains(aFeatureLabel)) {
if (!theOpen) { // on abort/undo/redo reinitialize attributes is something is changed
- std::shared_ptr<Model_Data> aD = std::dynamic_pointer_cast<Model_Data>(aFeature->data());
- aD->myAttrs.clear();
- aFeature->initAttributes();
+ std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = aFeature->data()->attributes("");
+ std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
+ for(; anAttr != anAttrs.end(); anAttr++)
+ (*anAttr)->reinit();
}
ModelAPI_EventCreator::get()->sendUpdated(aFeature, anUpdateEvent);
if (aFeature->getKind() == "Parameter") { // if parameters are changed, update the results (issue 937)
{
myID = theID;
}
+
+void ModelAPI_Attribute::reinit() {}
/// Sets the ID of the attribute in Data (called from Data)
MODELAPI_EXPORT virtual void setID(const std::string theID);
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ MODELAPI_EXPORT virtual void reinit();
+
friend class Model_Data;
+ friend class Model_Objects;
};
//! Pointer on attribute object
protected:
/// Objects are created for features automatically
MODELAPI_EXPORT ModelAPI_Expression();
+ /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
+ MODELAPI_EXPORT virtual void reinit() = 0;
bool myIsInitialized; ///< is some value assigned to this attribute
friend class Model_Data;
+ friend class Model_AttributeDouble;
+ friend class Model_AttributeInteger;
+ friend class GeomData_Point;
+ friend class GeomData_Point2D;
};
aSession.startOperation()
aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt"))
aFlyoutPoint.setValue(50.0, 100.0)
-aSession.finishOperation()
aSession.abortOperation()
assert (refattrA.isInitialized())
assert (refattrB.isInitialized())
aSession.startOperation()
aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt"))
aFlyoutPoint.setValue(50.0, 100.0)
-aSession.finishOperation()
aSession.abortOperation()
assert (refattrA.isInitialized())
assert (refattrB.isInitialized())