From: mpv Date: Mon, 29 Aug 2016 16:28:33 +0000 (+0300) Subject: Added the system of reinitialization of attributes instead of re-creation of them... X-Git-Tag: V_2.5.0~117 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b5eaf6f6971771b1e39f55ba5fc484e2f150ffb8;p=modules%2Fshaper.git Added the system of reinitialization of attributes instead of re-creation of them on undo/redo, etc. This is done because in solvers-connector reference to attributes are stored. So, they become bad on undo/redo/abort. --- diff --git a/src/GeomData/GeomData_Dir.cpp b/src/GeomData/GeomData_Dir.cpp index d5272dda2..477a89c20 100644 --- a/src/GeomData/GeomData_Dir.cpp +++ b/src/GeomData/GeomData_Dir.cpp @@ -58,9 +58,15 @@ std::shared_ptr GeomData_Dir::xyz() 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); } } diff --git a/src/GeomData/GeomData_Dir.h b/src/GeomData/GeomData_Dir.h index debd40055..846dcd343 100644 --- a/src/GeomData/GeomData_Dir.h +++ b/src/GeomData/GeomData_Dir.h @@ -22,6 +22,7 @@ class GeomAPI_XYZ; */ 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 @@ -43,6 +44,8 @@ class GeomData_Dir : public GeomDataAPI_Dir 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; }; diff --git a/src/GeomData/GeomData_Point.cpp b/src/GeomData/GeomData_Point.cpp index f6becd98d..9ceced262 100644 --- a/src/GeomData/GeomData_Point.cpp +++ b/src/GeomData/GeomData_Point.cpp @@ -20,6 +20,15 @@ GeomData_Point::GeomData_Point() 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) { diff --git a/src/GeomData/GeomData_Point.h b/src/GeomData/GeomData_Point.h index 3c08a706f..8936ffef8 100644 --- a/src/GeomData/GeomData_Point.h +++ b/src/GeomData/GeomData_Point.h @@ -74,6 +74,8 @@ class GeomData_Point : public GeomDataAPI_Point 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; }; diff --git a/src/GeomData/GeomData_Point2D.cpp b/src/GeomData/GeomData_Point2D.cpp index 8b6116b63..7c9cb73e3 100644 --- a/src/GeomData/GeomData_Point2D.cpp +++ b/src/GeomData/GeomData_Point2D.cpp @@ -20,6 +20,15 @@ GeomData_Point2D::GeomData_Point2D() 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) { diff --git a/src/GeomData/GeomData_Point2D.h b/src/GeomData/GeomData_Point2D.h index d73b20207..017802d5f 100644 --- a/src/GeomData/GeomData_Point2D.h +++ b/src/GeomData/GeomData_Point2D.h @@ -69,6 +69,8 @@ class GeomData_Point2D : public GeomDataAPI_Point2D 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; }; diff --git a/src/Model/Model_AttributeBoolean.cpp b/src/Model/Model_AttributeBoolean.cpp index f603def2d..d576a8870 100644 --- a/src/Model/Model_AttributeBoolean.cpp +++ b/src/Model/Model_AttributeBoolean.cpp @@ -29,6 +29,11 @@ bool Model_AttributeBoolean::value() 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; } diff --git a/src/Model/Model_AttributeBoolean.h b/src/Model/Model_AttributeBoolean.h index 1ad1f487e..e579649e9 100644 --- a/src/Model/Model_AttributeBoolean.h +++ b/src/Model/Model_AttributeBoolean.h @@ -32,6 +32,9 @@ class Model_AttributeBoolean : public ModelAPI_AttributeBoolean /// 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; }; diff --git a/src/Model/Model_AttributeDocRef.cpp b/src/Model/Model_AttributeDocRef.cpp index 5c3eaf442..a2aef9d7d 100644 --- a/src/Model/Model_AttributeDocRef.cpp +++ b/src/Model/Model_AttributeDocRef.cpp @@ -37,3 +37,8 @@ Model_AttributeDocRef::Model_AttributeDocRef(TDF_Label& theLabel) myID = TDataStd_Integer::Set(theLabel, aNewID); } } + +void Model_AttributeDocRef::reinit() +{ + // myLab is unknown, nevertheless, lose of attribute DocRef for live feature seems impossible +} diff --git a/src/Model/Model_AttributeDocRef.h b/src/Model/Model_AttributeDocRef.h index 04eacc437..d054fca8e 100644 --- a/src/Model/Model_AttributeDocRef.h +++ b/src/Model/Model_AttributeDocRef.h @@ -35,6 +35,9 @@ class Model_AttributeDocRef : public ModelAPI_AttributeDocRef /// 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; }; diff --git a/src/Model/Model_AttributeDouble.cpp b/src/Model/Model_AttributeDouble.cpp index 05a256841..4efa7bedc 100644 --- a/src/Model/Model_AttributeDouble.cpp +++ b/src/Model/Model_AttributeDouble.cpp @@ -8,12 +8,20 @@ #include #include -#include +#include #include -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) diff --git a/src/Model/Model_AttributeDouble.h b/src/Model/Model_AttributeDouble.h index abf394aa6..883b9b545 100644 --- a/src/Model/Model_AttributeDouble.h +++ b/src/Model/Model_AttributeDouble.h @@ -59,7 +59,9 @@ class Model_AttributeDouble : public ModelAPI_AttributeDouble 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; }; diff --git a/src/Model/Model_AttributeDoubleArray.cpp b/src/Model/Model_AttributeDoubleArray.cpp index 3a6b2ad9f..fd1e4dfdc 100644 --- a/src/Model/Model_AttributeDoubleArray.cpp +++ b/src/Model/Model_AttributeDoubleArray.cpp @@ -71,6 +71,11 @@ double Model_AttributeDoubleArray::value(const int theIndex) 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; diff --git a/src/Model/Model_AttributeDoubleArray.h b/src/Model/Model_AttributeDoubleArray.h index 74d960624..192d60629 100644 --- a/src/Model/Model_AttributeDoubleArray.h +++ b/src/Model/Model_AttributeDoubleArray.h @@ -38,6 +38,8 @@ public: 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. diff --git a/src/Model/Model_AttributeIntArray.cpp b/src/Model/Model_AttributeIntArray.cpp index c01107332..c05a9e19c 100644 --- a/src/Model/Model_AttributeIntArray.cpp +++ b/src/Model/Model_AttributeIntArray.cpp @@ -71,6 +71,11 @@ int Model_AttributeIntArray::value(const int theIndex) 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; diff --git a/src/Model/Model_AttributeIntArray.h b/src/Model/Model_AttributeIntArray.h index 82808f537..190d3d5a6 100644 --- a/src/Model/Model_AttributeIntArray.h +++ b/src/Model/Model_AttributeIntArray.h @@ -47,6 +47,8 @@ class Model_AttributeIntArray : public ModelAPI_AttributeIntArray 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; }; diff --git a/src/Model/Model_AttributeInteger.cpp b/src/Model/Model_AttributeInteger.cpp index 38ce002c5..3f61cbd96 100644 --- a/src/Model/Model_AttributeInteger.cpp +++ b/src/Model/Model_AttributeInteger.cpp @@ -8,12 +8,20 @@ #include #include -#include +#include #include -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) diff --git a/src/Model/Model_AttributeInteger.h b/src/Model/Model_AttributeInteger.h index 870db2990..c56ff8af9 100644 --- a/src/Model/Model_AttributeInteger.h +++ b/src/Model/Model_AttributeInteger.h @@ -57,7 +57,9 @@ class Model_AttributeInteger : public ModelAPI_AttributeInteger 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; diff --git a/src/Model/Model_AttributeRefAttr.cpp b/src/Model/Model_AttributeRefAttr.cpp index 0c24fe3e1..6456b68a8 100644 --- a/src/Model/Model_AttributeRefAttr.cpp +++ b/src/Model/Model_AttributeRefAttr.cpp @@ -94,12 +94,18 @@ bool Model_AttributeRefAttr::isInitialized() 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); } } diff --git a/src/Model/Model_AttributeRefAttr.h b/src/Model/Model_AttributeRefAttr.h index 40e3e0ecb..f0e149563 100644 --- a/src/Model/Model_AttributeRefAttr.h +++ b/src/Model/Model_AttributeRefAttr.h @@ -22,6 +22,7 @@ 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: @@ -46,6 +47,8 @@ class Model_AttributeRefAttr : public ModelAPI_AttributeRefAttr 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; }; diff --git a/src/Model/Model_AttributeRefAttrList.cpp b/src/Model/Model_AttributeRefAttrList.cpp index 3cfd46274..e1ffa3b62 100755 --- a/src/Model/Model_AttributeRefAttrList.cpp +++ b/src/Model/Model_AttributeRefAttrList.cpp @@ -308,11 +308,17 @@ void Model_AttributeRefAttrList::remove(const std::set& theIndices) 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); } } diff --git a/src/Model/Model_AttributeRefAttrList.h b/src/Model/Model_AttributeRefAttrList.h index 2e666db26..6d877e3e7 100755 --- a/src/Model/Model_AttributeRefAttrList.h +++ b/src/Model/Model_AttributeRefAttrList.h @@ -11,6 +11,7 @@ #include "ModelAPI_AttributeRefAttrList.h" #include "ModelAPI_Feature.h" +#include #include #include @@ -22,6 +23,7 @@ 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: @@ -71,6 +73,8 @@ class Model_AttributeRefAttrList : public ModelAPI_AttributeRefAttrList 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; }; diff --git a/src/Model/Model_AttributeRefList.cpp b/src/Model/Model_AttributeRefList.cpp index 36d11541c..9d6f25ff3 100644 --- a/src/Model/Model_AttributeRefList.cpp +++ b/src/Model/Model_AttributeRefList.cpp @@ -343,11 +343,17 @@ void Model_AttributeRefList::remove(const std::set& theIndices) 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); } } diff --git a/src/Model/Model_AttributeRefList.h b/src/Model/Model_AttributeRefList.h index b3690b227..5d752156e 100644 --- a/src/Model/Model_AttributeRefList.h +++ b/src/Model/Model_AttributeRefList.h @@ -22,6 +22,7 @@ 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 @@ -73,6 +74,8 @@ class Model_AttributeRefList : public ModelAPI_AttributeRefList 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, diff --git a/src/Model/Model_AttributeReference.cpp b/src/Model/Model_AttributeReference.cpp index b4d5acbee..b17b72f87 100644 --- a/src/Model/Model_AttributeReference.cpp +++ b/src/Model/Model_AttributeReference.cpp @@ -104,9 +104,15 @@ bool Model_AttributeReference::isInitialized() 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 aDoc = diff --git a/src/Model/Model_AttributeReference.h b/src/Model/Model_AttributeReference.h index 7ea779b6c..ea9b721f5 100644 --- a/src/Model/Model_AttributeReference.h +++ b/src/Model/Model_AttributeReference.h @@ -20,6 +20,7 @@ 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 @@ -39,6 +40,8 @@ class Model_AttributeReference : public ModelAPI_AttributeReference 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; diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 2f9250642..d1a426693 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -75,7 +75,8 @@ public: 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( diff --git a/src/Model/Model_AttributeSelectionList.cpp b/src/Model/Model_AttributeSelectionList.cpp index e97a2ee49..856db0447 100644 --- a/src/Model/Model_AttributeSelectionList.cpp +++ b/src/Model/Model_AttributeSelectionList.cpp @@ -288,16 +288,23 @@ bool Model_AttributeSelectionList::isInitialized() 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; diff --git a/src/Model/Model_AttributeSelectionList.h b/src/Model/Model_AttributeSelectionList.h index 3c6317d5a..c3b50a3d7 100644 --- a/src/Model/Model_AttributeSelectionList.h +++ b/src/Model/Model_AttributeSelectionList.h @@ -23,6 +23,7 @@ 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; @@ -88,6 +89,8 @@ public: 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; }; diff --git a/src/Model/Model_AttributeString.cpp b/src/Model/Model_AttributeString.cpp index 773a8bef9..72eb09193 100644 --- a/src/Model/Model_AttributeString.cpp +++ b/src/Model/Model_AttributeString.cpp @@ -37,6 +37,11 @@ std::string Model_AttributeString::value() 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; } diff --git a/src/Model/Model_AttributeString.h b/src/Model/Model_AttributeString.h index ac020f051..0d5e382ae 100644 --- a/src/Model/Model_AttributeString.h +++ b/src/Model/Model_AttributeString.h @@ -34,6 +34,8 @@ class Model_AttributeString : public ModelAPI_AttributeString 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; }; diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 7f86b2116..75c973242 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -126,18 +126,9 @@ AttributePtr Model_Data::addAttribute(const std::string& theID, const std::strin 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()) { diff --git a/src/Model/Model_Expression.cpp b/src/Model/Model_Expression.cpp index 7082bd60c..3a1d62ab2 100644 --- a/src/Model/Model_Expression.cpp +++ b/src/Model/Model_Expression.cpp @@ -75,35 +75,21 @@ std::set Model_Expression::usedParameters() const 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) @@ -137,14 +123,21 @@ bool Model_ExpressionDouble::isInvalid() 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) diff --git a/src/Model/Model_Expression.h b/src/Model/Model_Expression.h index fa2be8f75..2c5b2cd7a 100644 --- a/src/Model/Model_Expression.h +++ b/src/Model/Model_Expression.h @@ -50,8 +50,7 @@ class Model_Expression : public virtual ModelAPI_Expression 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 }; @@ -109,7 +108,10 @@ class Model_ExpressionDouble : 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: @@ -171,8 +173,10 @@ class Model_ExpressionInteger : 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; diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index f1edf57aa..c55a94307 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -664,9 +664,10 @@ void Model_Objects::synchronizeFeatures( aKeptFeatures.insert(aFeature); if (anUpdatedMap.Contains(aFeatureLabel)) { if (!theOpen) { // on abort/undo/redo reinitialize attributes is something is changed - std::shared_ptr aD = std::dynamic_pointer_cast(aFeature->data()); - aD->myAttrs.clear(); - aFeature->initAttributes(); + std::list > anAttrs = aFeature->data()->attributes(""); + std::list >::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) diff --git a/src/ModelAPI/ModelAPI_Attribute.cpp b/src/ModelAPI/ModelAPI_Attribute.cpp index e7553a05d..dd704bd31 100644 --- a/src/ModelAPI/ModelAPI_Attribute.cpp +++ b/src/ModelAPI/ModelAPI_Attribute.cpp @@ -83,3 +83,5 @@ void ModelAPI_Attribute::setID(const std::string theID) { myID = theID; } + +void ModelAPI_Attribute::reinit() {} diff --git a/src/ModelAPI/ModelAPI_Attribute.h b/src/ModelAPI/ModelAPI_Attribute.h index 22231be4b..95fd0544e 100644 --- a/src/ModelAPI/ModelAPI_Attribute.h +++ b/src/ModelAPI/ModelAPI_Attribute.h @@ -79,7 +79,11 @@ class ModelAPI_Attribute /// 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 diff --git a/src/ModelAPI/ModelAPI_Expression.h b/src/ModelAPI/ModelAPI_Expression.h index c583e58c7..dbfdeba69 100644 --- a/src/ModelAPI/ModelAPI_Expression.h +++ b/src/ModelAPI/ModelAPI_Expression.h @@ -56,10 +56,16 @@ class ModelAPI_Expression 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; }; diff --git a/src/SketchPlugin/Test/TestConstraintDistance.py b/src/SketchPlugin/Test/TestConstraintDistance.py index 75f4d3fbb..38761a36d 100644 --- a/src/SketchPlugin/Test/TestConstraintDistance.py +++ b/src/SketchPlugin/Test/TestConstraintDistance.py @@ -109,7 +109,6 @@ aSession.finishOperation() aSession.startOperation() aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt")) aFlyoutPoint.setValue(50.0, 100.0) -aSession.finishOperation() aSession.abortOperation() assert (refattrA.isInitialized()) assert (refattrB.isInitialized()) @@ -163,7 +162,6 @@ aSession.finishOperation() aSession.startOperation() aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt")) aFlyoutPoint.setValue(50.0, 100.0) -aSession.finishOperation() aSession.abortOperation() assert (refattrA.isInitialized()) assert (refattrB.isInitialized())