From 1c9cffdb4b0fe0d8d2cfe9e478f6d285fb0643cc Mon Sep 17 00:00:00 2001 From: szy Date: Thu, 10 Oct 2013 13:28:30 +0400 Subject: [PATCH] 0024164: Optimization of OCAF document closing OCAF document closing redesign. added 2 test scripts. removed commented method. added missed Draw commands. --- src/DDataStd/DDataStd_BasicCommands.cxx | 70 +++++++++++++++++++++++++ src/TDocStd/TDocStd_Application.cxx | 1 + src/TDocStd/TDocStd_Document.cdl | 7 ++- src/TDocStd/TDocStd_Document.cxx | 29 +++++----- tests/bugs/caf/bug24164_1 | 52 ++++++++++++++++++ tests/bugs/caf/bug24164_2 | 69 ++++++++++++++++++++++++ 6 files changed, 209 insertions(+), 19 deletions(-) create mode 100644 tests/bugs/caf/bug24164_1 create mode 100644 tests/bugs/caf/bug24164_2 diff --git a/src/DDataStd/DDataStd_BasicCommands.cxx b/src/DDataStd/DDataStd_BasicCommands.cxx index eb4ea8e525..7159e5c4b3 100755 --- a/src/DDataStd/DDataStd_BasicCommands.cxx +++ b/src/DDataStd/DDataStd_BasicCommands.cxx @@ -98,6 +98,7 @@ #include #include #include +#include //======================================================================= //function : DDataStd_SetInteger @@ -2595,6 +2596,67 @@ static Standard_Integer DDataStd_GetNDRealArray (Draw_Interpretor& di, return 1; } +//======================================================================= +//function : SetRefArray (DF, entry , From, To, elmt1, elmt2, ... +//======================================================================= +static Standard_Integer DDataStd_SetRefArray (Draw_Interpretor& di, + Standard_Integer, + const char** arg) +{ + + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) return 1; + TDF_Label label; + DDF::AddLabel(DF, arg[2], label); + + Standard_Integer From = Draw::Atoi(arg[3]), To = Draw::Atoi( arg[4] ), j; + di << "RefArray with bounds from = " << From << " to = " << To << "\n"; + + Handle(TDataStd_ReferenceArray) A = TDataStd_ReferenceArray::Set(label, From, To); + + j = 5; + for(Standard_Integer i = From; i<=To; i++) { + TDF_Label aRefLabel; + DDF::AddLabel(DF, arg[j], aRefLabel); + A->SetValue(i, aRefLabel); + j++; + } + return 0; +} +//======================================================================= +//function : GetRefArray (DF, entry ) +//======================================================================= +static Standard_Integer DDataStd_GetRefArray (Draw_Interpretor& di, + Standard_Integer, + const char** arg) +{ + + Handle(TDF_Data) DF; + if (!DDF::GetDF(arg[1],DF)) return 1; + TDF_Label label; + if( !DDF::FindLabel(DF, arg[2], label) ) { + di << "No label for entry" << "\n"; + return 1; + } + + Handle(TDataStd_ReferenceArray) A; + if ( !label.FindAttribute(TDataStd_ReferenceArray::GetID(), A) ) { + di << "There is no TDataStd_ReferenceArray under label" << "\n"; + return 1; + } + + for(Standard_Integer i = A->Lower(); i<=A->Upper(); i++){ + const TDF_Label& aLabel = A->Value(i); + TCollection_AsciiString entry; + TDF_Tool::Entry(aLabel, entry); + di << entry.ToCString(); + if(iUpper()) + di<<" "; + } + di<<"\n"; + return 0; +} + //======================================================================= //function : BasicCommands //purpose : @@ -2636,6 +2698,10 @@ void DDataStd::BasicCommands (Draw_Interpretor& theCommands) "SetExtStringArray (DF, entry, isDelta, From, To, elmt1, elmt2, ... )", __FILE__, DDataStd_SetExtStringArray, g); + theCommands.Add ("SetRefArray", + "SetRefArray (DF, entry, From, To, lab1, lab2,.. )", + __FILE__, DDataStd_SetRefArray, g); + theCommands.Add ("SetIntPackedMap", "SetIntPackedMap (DF, entry, isDelta, key1, key2, ... )", __FILE__, DDataStd_SetIntPackedMap, g); @@ -2703,6 +2769,10 @@ void DDataStd::BasicCommands (Draw_Interpretor& theCommands) "GetExtStringArray (DF, entry )", __FILE__, DDataStd_GetExtStringArray, g); + theCommands.Add ("GetRefArray", + "GetRefArray (DF, entry )", + __FILE__, DDataStd_GetRefArray, g); + theCommands.Add ("GetIntPackedMap", "GetIntPackedMap (DF, entry )", __FILE__, DDataStd_GetIntPackedMap, g); diff --git a/src/TDocStd/TDocStd_Application.cxx b/src/TDocStd/TDocStd_Application.cxx index ef86bfe0cc..a7505a15d7 100755 --- a/src/TDocStd/TDocStd_Application.cxx +++ b/src/TDocStd/TDocStd_Application.cxx @@ -163,6 +163,7 @@ void TDocStd_Application::Close(const Handle(TDocStd_Document)& aDoc) Handle(TDocStd_Document) emptyDoc; Owner->SetDocument(emptyDoc); } + aDoc->BeforeClose(); CDF_Application::Close(aDoc); } #endif diff --git a/src/TDocStd/TDocStd_Document.cdl b/src/TDocStd/TDocStd_Document.cdl index 938f67cd2a..194a6575e9 100755 --- a/src/TDocStd/TDocStd_Document.cdl +++ b/src/TDocStd/TDocStd_Document.cdl @@ -49,7 +49,7 @@ uses Data from TDF, is - Destroy (me : mutable) is redefined protected; + -- Destroy (me : mutable) is redefined protected; ---Purpose: Will Abort any execution, clear fields ---C++: alias ~ @@ -319,7 +319,10 @@ is ModificationMode (me) returns Boolean from Standard; ---Purpose: returns True if changes allowed only inside transactions ---C++: inline - + + BeforeClose(me : mutable) is virtual; + ---Purpose: Prepares document for closing + fields ---Purpose: storage format diff --git a/src/TDocStd/TDocStd_Document.cxx b/src/TDocStd/TDocStd_Document.cxx index 2c141623c1..0c3f209a9a 100755 --- a/src/TDocStd/TDocStd_Document.cxx +++ b/src/TDocStd/TDocStd_Document.cxx @@ -70,23 +70,6 @@ Handle(TDocStd_Document) TDocStd_Document::Get (const TDF_Label& acces) return TDocStd_Owner::GetDocument(acces.Data()); } -//======================================================================= -//function : Destroy -//purpose : -//======================================================================= -void TDocStd_Document::Destroy() -{ - SetModificationMode(Standard_False); - myData->Root().ForgetAllAttributes(Standard_True); - myUndoTransaction.Abort(); - if(!myUndoFILO.IsEmpty()) - myUndoFILO.Clear(); - ClearUndos(); - myData.Nullify(); - -} - - //======================================================================= //function : TDocStd_Document //purpose : @@ -911,3 +894,15 @@ void TDocStd_Document::RemoveFirstUndo() { myUndos.RemoveFirst(); } +//======================================================================= +//function : BeforeClose +//purpose : +//======================================================================= +void TDocStd_Document::BeforeClose() +{ + SetModificationMode(Standard_False); + AbortTransaction(); + if(myIsNestedTransactionMode) + myUndoFILO.Clear(); + ClearUndos(); +} diff --git a/tests/bugs/caf/bug24164_1 b/tests/bugs/caf/bug24164_1 new file mode 100644 index 0000000000..18a58ba4bb --- /dev/null +++ b/tests/bugs/caf/bug24164_1 @@ -0,0 +1,52 @@ +pload DCAF + +if { [info exists imagedir] == 0 } { + set imagedir . +} +set BugNumber OCC24164 + +#1 open new document +NewDocument D MDTV-Standard +UndoLimit D 10 0 0 +InitLogBook D +AddDriver D Box + +#2 build box +NewCommand D +set B2 [AddObject D] +set F2 [AddFunction D $B2 Box] +BoxDX D $B2 190 +BoxDY D $B2 290 +BoxDZ D $B2 390 +ComputeFun D $F2 +GetShape D $F2:2 Box2 +NewCommand D + +#3 save shape in the document +SaveAs D ${imagedir}/testDoc1.std + +#4 close document +set catch_status 0 +if { [catch {Close D} catch_result] } { + set catch_status 1 +} +if { ${catch_status} != 0 } { + puts "Faulty ${BugNumber}" +} else { + puts "OK ${BugNumber}" +} + +#5 reopen just saved document with the same name +Open ${imagedir}/testDoc1.std D +set catch_status 0 + +#6 close the document +if { [catch {Close D} catch_result] } { + set catch_status 1 +} + +if { ${catch_status} != 0 } { + puts "Faulty ${BugNumber}" +} else { + puts "OK ${BugNumber}" +} \ No newline at end of file diff --git a/tests/bugs/caf/bug24164_2 b/tests/bugs/caf/bug24164_2 new file mode 100644 index 0000000000..c01535d69d --- /dev/null +++ b/tests/bugs/caf/bug24164_2 @@ -0,0 +1,69 @@ +pload DCAF + +set BugNumber OCC24164 +if { [info exists imagedir] == 0 } { + set imagedir . +} + +#1 open new document +NewDocument D MDTV-Standard +UndoLimit D 10 0 0 + +#2 define set of labels +NewCommand D +set Lab1 [Label D 0:1:1] +set Lab2 [Label D 0:1:2] +set Lab3 [Label D 0:1:3] +set Lab4 [Label D 0:1:4] +set Lab5 [Label D 0:1:5] +set Lab6 [Label D 0:1:6] + +#3 set references +SetRefArray D $Lab1 1 2 $Lab2 $Lab1 +SetRefArray D $Lab2 1 2 $Lab3 $Lab4 +SetRefArray D $Lab3 1 1 $Lab1 + +#4 set additional references +NewCommand D +SetRefArray D $Lab4 1 2 $Lab5 $Lab1 +SetRefArray D $Lab5 1 1 $Lab6 +SetRefArray D $Lab6 1 2 $Lab3 $Lab4 + +NewCommand D + +#5 check references +GetRefArray D $Lab1 +GetRefArray D $Lab2 +GetRefArray D $Lab3 +GetRefArray D $Lab4 +GetRefArray D $Lab5 +GetRefArray D $Lab6 + +#6 save the document +SaveAs D ${imagedir}/testDoc2.std + +#7 close the document +set catch_status 0 +if { [catch {Close D} catch_result] } { + set catch_status 1 +} +if { ${catch_status} != 0 } { + puts "Faulty ${BugNumber}" +} else { + puts "OK ${BugNumber}" +} + +#8 reopen just saved document with the same name +Open ${imagedir}/testDoc2.std D + +#9 close the document +if { [catch {Close D} catch_result] } { + set catch_status 1 +} + +if { ${catch_status} != 0 } { + puts "Faulty ${BugNumber}" +} else { + puts "OK ${BugNumber}" +} +