4 #include "CAF_Operation.h"
6 #include <SUIT_Desktop.h>
7 #include <SUIT_MessageBox.h>
8 #include <SUIT_Application.h>
10 #include <TDF_Delta.hxx>
11 #include <TDF_ListIteratorOfDeltaList.hxx>
13 //////////////////////////////////////////////////////////////////////
14 // Construction/Destruction
15 //////////////////////////////////////////////////////////////////////
17 CAF_Study::CAF_Study(SUIT_Application* theApp)
18 : SUIT_Study( theApp ),
23 CAF_Study::CAF_Study(SUIT_Application* theApp, Handle (TDocStd_Document)& aStdDoc)
24 : SUIT_Study( theApp ),
30 CAF_Study::~CAF_Study()
34 bool CAF_Study::startOperation()
36 if ( myStdDoc.IsNull() )
41 if ( myStdDoc->HasOpenCommand() )
42 myStdDoc->AbortCommand();
44 myStdDoc->OpenCommand();
46 catch( Standard_Failure ) {
53 void CAF_Study::abortOperation()
55 if ( myStdDoc.IsNull() )
59 myStdDoc->AbortCommand();
62 catch ( Standard_Failure ) {
66 void CAF_Study::commitOperation()
68 if ( myStdDoc.IsNull() )
72 myStdDoc->CommitCommand();
76 CAF_Operation* cafOp = 0;
77 if ( activeOperation() && activeOperation()->inherits( "CAF_Operation" ) )
78 cafOp = (CAF_Operation*)activeOperation();
80 Handle(TDF_Delta) d = myStdDoc->GetUndos().Last();
81 if ( cafOp && !d.IsNull() )
82 d->SetName( CAF_Tools::toExtString( cafOp->getName() ) );
85 catch ( Standard_Failure ) {
90 Returns whether the document was saved in file. [ public ]
92 bool CAF_Study::isSaved() const
94 if ( myStdDoc.IsNull() )
97 return myStdDoc->IsSaved();
101 Returns whether the document is modified. [ public ]
103 bool CAF_Study::isModified() const
105 return ( myModifiedCnt != 0 );
109 Increments modification count. If 'undoable' is 'true', this modification
110 can be rolled back by 'undoModified' otherwise the document will be marked
111 as 'modiifed' until saved. [ protected ]
113 void CAF_Study::doModified( bool undoable )
115 if ( myStdDoc.IsNull() )
120 /* Assumed that number of available undos / redos is NOT changed dynamically */
122 myModifiedCnt += myStdDoc->GetAvailableUndos();
126 Decrements modification count. [ protected ]
128 void CAF_Study::undoModified()
134 Clears modification count. [ public ]
136 void CAF_Study::clearModified()
142 Undoes the last command. [ public ]
144 bool CAF_Study::undo()
146 if ( myStdDoc.IsNull() )
151 undoModified(); /* decrement modification counter */
153 catch ( Standard_Failure ) {
154 SUIT_MessageBox::error1( application()->desktop(), tr( "ERR_ERROR" ),
155 tr( "ERR_DOC_UNDO" ), tr ( "BUT_OK" ) );
162 Redoes the last undo. [ public ]
164 bool CAF_Study::redo()
166 if ( myStdDoc.IsNull() )
171 doModified(); /* increment modification counter */
173 catch ( Standard_Failure ) {
174 SUIT_MessageBox::error1( application()->desktop(), tr( "ERR_ERROR" ),
175 tr( "ERR_DOC_REDO" ), tr ( "BUT_OK" ) );
182 Check if possible to perform 'undo' command. [ public ]
184 bool CAF_Study::canUndo() const
186 if ( myStdDoc.IsNull() )
189 return myStdDoc->GetAvailableUndos() > 0;
193 Check if possible to perform 'redo' command. [ public ]
195 bool CAF_Study::canRedo() const
197 if ( myStdDoc.IsNull() )
200 return myStdDoc->GetAvailableRedos() > 0;
204 Returns the list of names of 'undo' actions available. [ public ]
206 QStringList CAF_Study::undoNames() const
209 if ( !myStdDoc.IsNull() )
211 for ( TDF_ListIteratorOfDeltaList it( myStdDoc->GetUndos() ); it.More(); it.Next() )
212 names.prepend( CAF_Tools::toQString( it.Value()->Name() ) );
218 Returns the list of names of 'redo' actions available. [ public ]
220 QStringList CAF_Study::redoNames() const
223 if ( !myStdDoc.IsNull() )
225 for ( TDF_ListIteratorOfDeltaList it( myStdDoc->GetRedos() ); it.More(); it.Next() )
226 names.append( CAF_Tools::toQString( it.Value()->Name() ) );