1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #include "CAF_Application.h"
21 #include "CAF_Tools.h"
22 #include "CAF_Study.h"
24 #include <SUIT_Desktop.h>
25 #include <SUIT_Session.h>
26 #include <SUIT_ViewModel.h>
27 #include <SUIT_Operation.h>
28 #include <SUIT_MessageBox.h>
29 #include <SUIT_ResourceMgr.h>
31 #include <QtxListAction.h>
35 #include <qpopupmenu.h>
36 #include <qstatusbar.h>
37 #include <qapplication.h>
39 #include <Resource_Manager.hxx>
41 #include <TColStd_SequenceOfExtendedString.hxx>
43 extern "C" CAF_EXPORT SUIT_Application* createApplication()
45 return new CAF_Application();
51 CAF_Application::CAF_Application()
57 Constructor with OCAF application
58 \param app - OCAF application
60 CAF_Application::CAF_Application( const Handle( TDocStd_Application )& app )
69 CAF_Application::~CAF_Application()
74 \return application name
76 QString CAF_Application::applicationName() const
78 return QString( "CAFApplication" );
82 \return OCAF application
84 Handle( TDocStd_Application ) CAF_Application::stdApp() const
90 \return file filters for open/save document
92 QString CAF_Application::getFileFilter() const
94 if ( stdApp().IsNull() )
97 TColStd_SequenceOfExtendedString formats;
98 stdApp()->Formats( formats );
101 QMap<QString, QStringList> wildCards;
102 Handle(Resource_Manager) resMgr = new Resource_Manager( stdApp()->ResourcesName() );
103 for ( int i = 1; i <= formats.Length(); i++ )
106 QString extResStr = CAF_Tools::toQString( formats.Value( i ) ) + QString( ".FileExtension" );
107 if ( resMgr->Find( (char*)extResStr.latin1() ) )
108 extension = QString( resMgr->Value( (char*)extResStr.latin1() ) );
111 QString descrResStr = CAF_Tools::toQString( formats.Value( i ) ) + QString( ".Description" );
112 if ( resMgr->Find( (char*)descrResStr.latin1() ) )
113 descr = QString( resMgr->Value( (char*)descrResStr.latin1() ) );
115 if ( !descr.isEmpty() && !extension.isEmpty() )
117 if ( !wildCards.contains( descr ) )
118 wildCards.insert( descr, QStringList() );
119 wildCards[descr].append( QString( "*.%1" ).arg( extension ) );
120 allWC.append( QString( "*.%1" ).arg( extension ) );
124 if ( wildCards.isEmpty() )
125 return QString::null;
128 for ( QMap<QString, QStringList>::ConstIterator it = wildCards.begin(); it != wildCards.end(); ++it )
129 filters.append( QString( "%1 (%2)" ).arg( it.key() ).arg( it.data().join( "; " ) ) );
131 if ( wildCards.count() > 1 )
132 filters.prepend( QString( "%1 (%2)" ).arg( tr( "INF_ALL_DOCUMENTS_FILTER" ) ).arg( allWC.join( "; " ) ) );
134 if ( !filters.isEmpty() )
135 filters.append( tr( "INF_ALL_FILTER" ) );
137 return filters.join( ";;" );
141 Creates actions of application
143 void CAF_Application::createActions()
145 STD_Application::createActions();
147 SUIT_Desktop* desk = desktop();
148 SUIT_ResourceMgr* resMgr = resourceMgr();
150 QtxListAction* editUndo =
151 new QtxListAction( tr( "TOT_APP_EDIT_UNDO" ), resMgr->loadPixmap( "CAF", tr( "ICON_APP_EDIT_UNDO" ) ),
152 tr( "MEN_APP_EDIT_UNDO" ), CTRL+Key_Z, desk );
153 registerAction( EditUndoId, editUndo );
155 QtxListAction* editRedo =
156 new QtxListAction( tr( "TOT_APP_EDIT_REDO" ), resMgr->loadPixmap( "CAF", tr( "ICON_APP_EDIT_REDO" ) ),
157 tr( "MEN_APP_EDIT_REDO" ), CTRL+Key_Y, desk );
158 registerAction( EditRedoId, editRedo );
160 editUndo->setComment( tr( "INF_APP_UNDOACTIONS" ) );
161 editRedo->setComment( tr( "INF_APP_REDOACTIONS" ) );
163 connect( editUndo, SIGNAL( activated( int ) ), this, SLOT( onUndo( int ) ) );
164 connect( editRedo, SIGNAL( activated( int ) ), this, SLOT( onRedo( int ) ) );
167 int editMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 10 );
169 createMenu( EditUndoId, editMenu, 0 );
170 createMenu( EditRedoId, editMenu, 0 );
171 createMenu( separator(), editMenu, -1, 0 );
173 int stdTBar = createTool( tr( "INF_DESK_TOOLBAR_STANDARD" ) );
175 createTool( separator(), stdTBar );
176 createTool( EditUndoId, stdTBar );
177 createTool( EditRedoId, stdTBar );
178 createTool( separator(), stdTBar );
182 Undo operation on the given document. [ virtual protected ]
184 bool CAF_Application::undo( CAF_Study* doc )
186 bool success = false;
189 if ( success = doc->undo() )
196 Redo operation on the given document. [ virtual protected ]
198 bool CAF_Application::redo(CAF_Study* doc)
200 bool success = false;
203 if ( success = doc->redo() )
210 Undo operation on the active document. [ virtual protected slot ]
212 bool CAF_Application::onUndo( int numActions )
215 while ( numActions > 0 )
217 CAF_Study* cafStudy = dynamic_cast<CAF_Study*>( activeStudy() );
220 if ( !undo( cafStudy ) )
228 updateCommandsStatus(); /* enable/disable undo/redo */
233 Redo operation on the active document. [ virtual protected slot ]
235 bool CAF_Application::onRedo( int numActions )
238 while ( numActions > 0 )
240 CAF_Study* cafStudy = dynamic_cast<CAF_Study*>( activeStudy() );
243 if ( !redo( cafStudy ) )
251 updateCommandsStatus(); /* enable/disable undo/redo */
256 Enables / disables the actions according to the application state. [ virtual protected ]
258 void CAF_Application::updateCommandsStatus()
260 STD_Application::updateCommandsStatus();
262 CAF_Study* cafStudy = 0;
263 if ( activeStudy() && activeStudy()->inherits( "CAF_Study" ) )
264 cafStudy = (CAF_Study*)activeStudy();
266 QAction* undo = action( EditUndoId );
267 if ( cafStudy && undo )
268 undo->setProperty( "names", cafStudy->undoNames() );
270 QAction* redo = action( EditRedoId );
271 if ( cafStudy && redo )
272 redo->setProperty( "names", cafStudy->redoNames() );
275 undo->setEnabled( cafStudy && cafStudy->canUndo() );
277 redo->setEnabled( cafStudy && cafStudy->canRedo() );
281 SLOT: called by clicking on Help->About in main menu
283 void CAF_Application::onHelpAbout()
285 SUIT_MessageBox::info1( desktop(), tr( "About" ), tr( "ABOUT_INFO" ), "&OK" );
291 SUIT_Study* CAF_Application::createNewStudy()
293 return new CAF_Study( this );
297 Sets OCAF application
299 void CAF_Application::setStdApp( const Handle(TDocStd_Application)& app )