From 69f1a8997e23ee363f4087b1da3cb7da8895c808 Mon Sep 17 00:00:00 2001 From: szy Date: Tue, 23 May 2017 15:14:51 +0300 Subject: [PATCH] 0028446: Could not retrieve just kept document with Integer attribute --- src/TDataStd/TDataStd_AsciiString.cxx | 51 ++++++++++++----------- src/TDataStd/TDataStd_Integer.cxx | 48 +++++++++++----------- src/TDataStd/TDataStd_Name.cxx | 55 +++++++++++++------------ src/TDataStd/TDataStd_Real.cxx | 47 +++++++++++----------- tests/caf/basic/A7 | 58 +++++++++++++++++++++++++++ tests/caf/basic/B7 | 57 ++++++++++++++++++++++++++ tests/caf/basic/E7 | 57 ++++++++++++++++++++++++++ tests/caf/basic/N7 | 57 ++++++++++++++++++++++++++ 8 files changed, 334 insertions(+), 96 deletions(-) create mode 100644 tests/caf/basic/A7 create mode 100644 tests/caf/basic/B7 create mode 100644 tests/caf/basic/E7 create mode 100644 tests/caf/basic/N7 diff --git a/src/TDataStd/TDataStd_AsciiString.cxx b/src/TDataStd/TDataStd_AsciiString.cxx index 72374cf1bd..a5f1e792e7 100644 --- a/src/TDataStd/TDataStd_AsciiString.cxx +++ b/src/TDataStd/TDataStd_AsciiString.cxx @@ -28,8 +28,7 @@ IMPLEMENT_STANDARD_RTTIEXT(TDataStd_AsciiString,TDF_Attribute) //function : TDataStd_AsciiString //purpose : //======================================================================= -TDataStd_AsciiString::TDataStd_AsciiString(): - myID (GetID()) +TDataStd_AsciiString::TDataStd_AsciiString() { myString.Clear(); } @@ -55,6 +54,25 @@ const Standard_GUID& TDataStd_AsciiString::ID() const return myID; } +//======================================================================= +//function : SetAttr +//purpose : Implements Set functionality +//======================================================================= +static Handle(TDataStd_AsciiString) SetAttr( + const TDF_Label& label, + const TCollection_AsciiString& theString, + const Standard_GUID& theGuid) +{ + Handle(TDataStd_AsciiString) A; + if (!label.FindAttribute(theGuid, A)) { + A = new TDataStd_AsciiString (); + A->SetID(theGuid); + label.AddAttribute(A); + } + A->Set (theString); + return A; +} + //======================================================================= //function : Set //purpose : @@ -64,15 +82,7 @@ Handle(TDataStd_AsciiString) TDataStd_AsciiString::Set ( const TDF_Label& theLabel, const TCollection_AsciiString& theAsciiString) { - Handle(TDataStd_AsciiString) A; - if (!theLabel.FindAttribute(TDataStd_AsciiString::GetID(), A)) - { - A = new TDataStd_AsciiString; - A->SetID(GetID()); - theLabel.AddAttribute(A); - } - A->Set(theAsciiString); - return A; + return SetAttr(theLabel, theAsciiString, GetID()); } //======================================================================= @@ -80,17 +90,12 @@ Handle(TDataStd_AsciiString) TDataStd_AsciiString::Set ( //purpose : Set user defined attribute //======================================================================= -Handle(TDataStd_AsciiString) TDataStd_AsciiString::Set (const TDF_Label& L, const Standard_GUID& theGuid, - const TCollection_AsciiString& theAsciiString) +Handle(TDataStd_AsciiString) TDataStd_AsciiString::Set ( + const TDF_Label& theLabel, + const Standard_GUID& theGuid, + const TCollection_AsciiString& theAsciiString) { - Handle(TDataStd_AsciiString) A; - if (!L.FindAttribute(theGuid, A)) { - A = new TDataStd_AsciiString (); - A->SetID(theGuid); - L.AddAttribute(A); - } - A->Set (theAsciiString); - return A; + return SetAttr(theLabel, theAsciiString, theGuid); } //======================================================================= //function : Set @@ -143,9 +148,7 @@ void TDataStd_AsciiString::SetID() Handle(TDF_Attribute) TDataStd_AsciiString::NewEmpty () const { - Handle(TDataStd_AsciiString) Att = new TDataStd_AsciiString(); - Att->SetID(myID); - return Att; + return new TDataStd_AsciiString(); } //======================================================================= diff --git a/src/TDataStd/TDataStd_Integer.cxx b/src/TDataStd/TDataStd_Integer.cxx index e15b207c10..5c1077bf7b 100644 --- a/src/TDataStd/TDataStd_Integer.cxx +++ b/src/TDataStd/TDataStd_Integer.cxx @@ -35,6 +35,23 @@ const Standard_GUID& TDataStd_Integer::GetID() return TDataStd_IntegerID; } +//======================================================================= +//function : SetAttr +//purpose : Implements Set functionality +//======================================================================= +static Handle(TDataStd_Integer) SetAttr(const TDF_Label& label, + const Standard_Integer V, + const Standard_GUID& theGuid) +{ + Handle(TDataStd_Integer) A; + if (!label.FindAttribute(theGuid, A)) { + A = new TDataStd_Integer (); + A->SetID(theGuid); + label.AddAttribute(A); + } + A->Set (V); + return A; +} //======================================================================= //function : Set @@ -45,14 +62,7 @@ Handle(TDataStd_Integer) TDataStd_Integer::Set (const TDF_Label& L, const Standard_Integer V) { - Handle(TDataStd_Integer) A; - if (!L.FindAttribute (TDataStd_Integer::GetID(), A)) { - A = new TDataStd_Integer (); - A->SetID(GetID()); - L.AddAttribute(A); - } - A->Set (V); - return A; + return SetAttr(L, V, GetID()); } //======================================================================= @@ -60,17 +70,11 @@ Handle(TDataStd_Integer) TDataStd_Integer::Set (const TDF_Label& L, //purpose : Set user defined attribute //======================================================================= -Handle(TDataStd_Integer) TDataStd_Integer::Set (const TDF_Label& L, const Standard_GUID& theGuid, - const Standard_Integer V) +Handle(TDataStd_Integer) TDataStd_Integer::Set (const TDF_Label& L, + const Standard_GUID& theGuid, + const Standard_Integer V) { - Handle(TDataStd_Integer) A; - if (!L.FindAttribute(theGuid, A)) { - A = new TDataStd_Integer (); - A->SetID(theGuid); - L.AddAttribute(A); - } - A->Set (V); - return A; + return SetAttr(L, V, theGuid); } //======================================================================= //function : TDataStd_Integer @@ -78,7 +82,7 @@ Handle(TDataStd_Integer) TDataStd_Integer::Set (const TDF_Label& L, const Sta //======================================================================= TDataStd_Integer::TDataStd_Integer () - : myValue (-1), myID (GetID()) + : myValue (-1) { } @@ -152,10 +156,8 @@ void TDataStd_Integer::SetID() //======================================================================= Handle(TDF_Attribute) TDataStd_Integer::NewEmpty () const -{ - Handle(TDataStd_Integer) Att = new TDataStd_Integer(); - Att->SetID(myID); - return Att; +{ + return new TDataStd_Integer(); } //======================================================================= diff --git a/src/TDataStd/TDataStd_Name.cxx b/src/TDataStd/TDataStd_Name.cxx index c8b6e6538e..977b42d311 100644 --- a/src/TDataStd/TDataStd_Name.cxx +++ b/src/TDataStd/TDataStd_Name.cxx @@ -40,6 +40,24 @@ const Standard_GUID& TDataStd_Name::GetID () return TDataStd_NameID; } +//======================================================================= +//function : SetAttr +//purpose : Implements Set functionality +//======================================================================= +static Handle(TDataStd_Name) SetAttr(const TDF_Label& label, + const TCollection_ExtendedString& theString, + const Standard_GUID& theGuid) +{ + Handle(TDataStd_Name) N; + if (!label.FindAttribute(theGuid, N)) { + N = new TDataStd_Name (); + N->SetID(theGuid); + label.AddAttribute(N); + } + N->Set (theString); + return N; +} + //======================================================================= //function : Set //purpose : @@ -48,14 +66,7 @@ Handle(TDataStd_Name) TDataStd_Name::Set (const TDF_Label& label, const TCollection_ExtendedString& theString) { - Handle(TDataStd_Name) N; - if (!label.FindAttribute(TDataStd_Name::GetID(), N)) { - N = new TDataStd_Name (); - N->SetID(GetID()); - label.AddAttribute(N); - } - N->Set(theString); - return N; + return SetAttr(label, theString, GetID()); } //======================================================================= @@ -63,25 +74,19 @@ Handle(TDataStd_Name) TDataStd_Name::Set //purpose : Set user defined attribute //======================================================================= -Handle(TDataStd_Name) TDataStd_Name::Set (const TDF_Label& L, const Standard_GUID& theGuid, +Handle(TDataStd_Name) TDataStd_Name::Set (const TDF_Label& label, + const Standard_GUID& theGuid, const TCollection_ExtendedString& theString) { - Handle(TDataStd_Name) N; - if (!L.FindAttribute(theGuid, N)) { - N = new TDataStd_Name (); - N->SetID(theGuid); - L.AddAttribute(N); - } - N->Set (theString); - return N; + return SetAttr(label, theString, theGuid); } //======================================================================= //function : TDataStd_Name //purpose : Empty Constructor //======================================================================= -TDataStd_Name::TDataStd_Name (): myID (GetID()) -{ } +TDataStd_Name::TDataStd_Name () +{} //======================================================================= //function : Set @@ -143,10 +148,8 @@ const Standard_GUID& TDataStd_Name::ID () const { return myID; } //======================================================================= Handle(TDF_Attribute) TDataStd_Name::NewEmpty () const -{ - Handle(TDataStd_Name) Att = new TDataStd_Name(); - Att->SetID(myID); - return Att; +{ + return new TDataStd_Name(); } //======================================================================= @@ -170,9 +173,9 @@ void TDataStd_Name::Restore(const Handle(TDF_Attribute)& with) void TDataStd_Name::Paste (const Handle(TDF_Attribute)& into, const Handle(TDF_RelocationTable)&/* RT*/) const { - Handle(TDataStd_Name) anAtt = Handle(TDataStd_Name)::DownCast (into); - anAtt->Set (myString); - anAtt->SetID(myID); + Handle(TDataStd_Name) anAtt = Handle(TDataStd_Name)::DownCast (into); + anAtt->Set (myString); + anAtt->SetID(myID); } //======================================================================= diff --git a/src/TDataStd/TDataStd_Real.cxx b/src/TDataStd/TDataStd_Real.cxx index f8266fc72a..fe5ab4d982 100644 --- a/src/TDataStd/TDataStd_Real.cxx +++ b/src/TDataStd/TDataStd_Real.cxx @@ -36,6 +36,23 @@ const Standard_GUID& TDataStd_Real::GetID() return TDataStd_RealID; } +//======================================================================= +//function : SetAttr +//purpose : Implements Set functionality +//======================================================================= +static Handle(TDataStd_Real) SetAttr(const TDF_Label& label, + const Standard_Real V, + const Standard_GUID& theGuid) +{ + Handle(TDataStd_Real) A; + if (!label.FindAttribute(theGuid, A)) { + A = new TDataStd_Real (); + A->SetID(theGuid); + label.AddAttribute(A); + } + A->Set (V); + return A; +} //======================================================================= //function : Set @@ -45,14 +62,7 @@ const Standard_GUID& TDataStd_Real::GetID() Handle(TDataStd_Real) TDataStd_Real::Set (const TDF_Label& L, const Standard_Real V) { - Handle(TDataStd_Real) A; - if (!L.FindAttribute(TDataStd_Real::GetID(), A)) { - A = new TDataStd_Real (); - A->SetID(GetID()); - L.AddAttribute(A); - } - A->Set (V); - return A; + return SetAttr(L, V, GetID()); } //======================================================================= @@ -60,17 +70,11 @@ Handle(TDataStd_Real) TDataStd_Real::Set (const TDF_Label& L, //purpose : User defined attribute //======================================================================= -Handle(TDataStd_Real) TDataStd_Real::Set (const TDF_Label& L, const Standard_GUID& theGuid, +Handle(TDataStd_Real) TDataStd_Real::Set (const TDF_Label& L, + const Standard_GUID& theGuid, const Standard_Real V) { - Handle(TDataStd_Real) A; - if (!L.FindAttribute(theGuid, A)) { - A = new TDataStd_Real (); - A->SetID(theGuid); - L.AddAttribute(A); - } - A->Set (V); - return A; + return SetAttr(L, V, theGuid); } //======================================================================= @@ -80,8 +84,7 @@ Handle(TDataStd_Real) TDataStd_Real::Set (const TDF_Label& L, const Standard_ TDataStd_Real::TDataStd_Real () : myValue (RealFirst()), - myDimension (TDataStd_SCALAR), - myID (GetID()) + myDimension (TDataStd_SCALAR) {} @@ -188,10 +191,8 @@ void TDataStd_Real::SetID() //======================================================================= Handle(TDF_Attribute) TDataStd_Real::NewEmpty () const -{ - Handle(TDataStd_Real) Att = new TDataStd_Real(); - Att->SetID(myID); - return Att; +{ + return new TDataStd_Real(); } //======================================================================= diff --git a/tests/caf/basic/A7 b/tests/caf/basic/A7 new file mode 100644 index 0000000000..e822254b37 --- /dev/null +++ b/tests/caf/basic/A7 @@ -0,0 +1,58 @@ +#INTERFACE CAF +# Basic attributes +# +# Testing attribute: User defined (additional GUID) TDataStd_Integer +# +# Testing command: SetInteger +# Testing command: GetInteger +# + +puts "caf001-A6" + +# Add an attribute to a data framework +set aSetAttr1 100 +set aSetAttr2 200 +set aGuid1 "12e94541-6dbc-11d4-b9c8-0060b0ee281b" + +set aLabel 0:2 +SetInteger D ${aLabel} ${aSetAttr1} +SetInteger D ${aLabel} ${aSetAttr2} ${aGuid1} + +# Close/Open the transaction +NewCommand D + +# Save the document +set aFile ${imagedir}/caf001-A7.cbf +file delete ${aFile} +SaveAs D ${aFile} +if { ![file exists ${aFile}] } { + puts "There is not ${aFile} file; SaveAs command: Error" + return +} +#catch {exec chmod 777 ${aFile}} + +# Restore the document +Close D +Open ${aFile} DD + +# Get a value of the attribute #1 +set IsDone [catch {set aGetAttr3 [GetInteger DD ${aLabel}]} aResult] +if { ${IsDone} != 0 || + ${aSetAttr1}!=${aGetAttr3} } { + puts ${aResult} + puts "aSetAttr1=${aSetAttr1} aGetAttr3=${aGetAttr3}" + puts "Get a value of the first TDataStd_Integer attribute from restoring document: Error" + return +} + +# Get a value of the attribute #2 +set IsDone [catch {set aGetAttr4 [GetInteger DD ${aLabel} ${aGuid1}]} aResult] +if { ${IsDone} != 0 || + ${aSetAttr2}!=${aGetAttr4} } { + puts ${aResult} + puts "aSetAttr2=${aSetAttr2} aGetAttr4=${aGetAttr4}" + puts "Get a value of the second TDataStd_Integer attribute from restoring document: Error" + return +} + +puts "Get a value of user defined TDataStd_Integer attributes from restoring document: OK" diff --git a/tests/caf/basic/B7 b/tests/caf/basic/B7 new file mode 100644 index 0000000000..452c2bec21 --- /dev/null +++ b/tests/caf/basic/B7 @@ -0,0 +1,57 @@ +#INTERFACE CAF +# Basic attributes +# +# Testing attribute: User defined (additional GUID) TDataStd_Real +# +# Testing command: SetReal +# Testing command: GetReal +# + +puts "caf001-B6" + +# Add an attribute to a data framework +set aSetAttr1 100.11 +set aSetAttr2 200.11 +set aGuid2 "12e94552-6dbc-11d4-b9c8-0060b0ee281b" +set aLabel 0:2 +SetReal D ${aLabel} ${aSetAttr1} +SetReal D ${aLabel} ${aSetAttr2} ${aGuid2} + +# Close/Open the transaction +NewCommand D + +# Save the document +set aFile ${imagedir}/caf001-B7.cbf +file delete ${aFile} +SaveAs D ${aFile} +if { ![file exists ${aFile}] } { + puts "There is not ${aFile} file; SaveAs command: Error" + return +} +#catch {exec chmod 777 ${aFile}} + +# Restore the document +Close D +Open ${aFile} DD + +# Get a value of the attribute #1 +set IsDone [catch {set aGetAttr3 [GetReal DD ${aLabel}]} aResult] +if { ${IsDone} != 0 || + ${aSetAttr1}!=${aGetAttr3} } { + puts ${aResult} + puts "aSetAttr1=${aSetAttr1} aGetAttr3=${aGetAttr3}" + puts "Get a value of the first TDataStd_Real attribute from restoring document: Error" + return +} + +# Get a value of the attribute #2 +set IsDone [catch {set aGetAttr4 [GetReal DD ${aLabel} ${aGuid2}]} aResult] +if { ${IsDone} != 0 || + ${aSetAttr2}!=${aGetAttr4} } { + puts ${aResult} + puts "aSetAttr2=${aSetAttr2} aGetAttr4=${aGetAttr4}" + puts "Get a value of the second TDataStd_Real attribute from restoring document: Error" + return +} + +puts "Get a value of user defined TDataStd_Integer attributes from restoring document: OK" diff --git a/tests/caf/basic/E7 b/tests/caf/basic/E7 new file mode 100644 index 0000000000..164840aaef --- /dev/null +++ b/tests/caf/basic/E7 @@ -0,0 +1,57 @@ +#INTERFACE CAF +# Basic attributes +# +# Testing attribute: User defined (additional GUID) TDataStd_Name +# +# Testing command: SetName +# Testing command: GetName +# + +puts "caf001-E6" + +# Add an attribute to a data framework +set aSetAttr1 "New Attribute_1" +set aSetAttr2 "New Attribute_2" +set aGuid2 "12e94562-6dbc-11d4-b9c8-0060b0ee281b" +set aLabel 0:2 +SetName D ${aLabel} ${aSetAttr1} +SetName D ${aLabel} ${aSetAttr2} ${aGuid2} + +# Close/Open the transaction +NewCommand D + +# Save the document +set aFile ${imagedir}/caf001-E7.cbf +file delete ${aFile} +SaveAs D ${aFile} +if { ![file exists ${aFile}] } { + puts "There is not ${aFile} file; SaveAs command: Error" + return +} +#catch {exec chmod 777 ${aFile}} + +# Restore the document +Close D +Open ${aFile} DD + +# Get a value of the attribute #1 +set IsDone [catch {set aGetAttr3 [GetName DD ${aLabel}]} aResult] +if { ${IsDone} != 0 || + ${aSetAttr1}!=${aGetAttr3} } { + puts ${aResult} + puts "aSetAttr1=${aSetAttr1} aGetAttr3=${aGetAttr3}" + puts "Get a value of the first TDataStd_Name attribute from restoring document: Error" + return +} + +# Get a value of the attribute #2 +set IsDone [catch {set aGetAttr4 [GetName DD ${aLabel} ${aGuid2}]} aResult] +if { ${IsDone} != 0 || + ${aSetAttr2}!=${aGetAttr4} } { + puts ${aResult} + puts "aSetAttr2=${aSetAttr2} aGetAttr4=${aGetAttr4}" + puts "Get a value of the second TDataStd_Name attribute from restoring document: Error" + return +} + +puts "Get a value of user defined TDataStd_Name attributes from restoring document: OK" diff --git a/tests/caf/basic/N7 b/tests/caf/basic/N7 new file mode 100644 index 0000000000..65c43502ee --- /dev/null +++ b/tests/caf/basic/N7 @@ -0,0 +1,57 @@ +#INTERFACE CAF +# Basic attributes +# +# Testing attribute: User defined (additional GUID) TDataStd_AsciiString +# +# Testing command: SetAsciiString +# Testing command: GetAsciiString +# + +puts "caf001-N6" + +# Add an attribute to a data framework +set aSetAttr1 "New Attribute_1" +set aSetAttr2 "New Attribute_2" +set aGuid2 "12e94572-6dbc-11d4-b9c8-0060b0ee281b" +set aLabel 0:2 +SetAsciiString D ${aLabel} ${aSetAttr1} +SetAsciiString D ${aLabel} ${aSetAttr2} ${aGuid2} + +# Close/Open the transaction +NewCommand D + +# Save the document +set aFile ${imagedir}/caf001-N7.cbf +file delete ${aFile} +SaveAs D ${aFile} +if { ![file exists ${aFile}] } { + puts "There is not ${aFile} file; SaveAs command: Error" + return +} +#catch {exec chmod 777 ${aFile}} + +# Restore the document +Close D +Open ${aFile} DD + +# Get a value of the attribute #1 +set IsDone [catch {set aGetAttr3 [GetAsciiString DD ${aLabel}]} aResult] +if { ${IsDone} != 0 || + ${aSetAttr1}!=${aGetAttr3} } { + puts ${aResult} + puts "aSetAttr1=${aSetAttr1} aGetAttr3=${aGetAttr3}" + puts "Get a value of the first TDataStd_AsciiString attribute from restoring document: Error" + return +} + +# Get a value of the attribute #2 +set IsDone [catch {set aGetAttr4 [GetAsciiString DD ${aLabel} ${aGuid2}]} aResult] +if { ${IsDone} != 0 || + ${aSetAttr2}!=${aGetAttr4} } { + puts ${aResult} + puts "aSetAttr2=${aSetAttr2} aGetAttr4=${aGetAttr4}" + puts "Get a value of the second TDataStd_AsciiString attribute from restoring document: Error" + return +} + +puts "Get a value of user defined TDataStd_AsciiString attributes from restoring document: OK"