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();
48 CAF_Application::CAF_Application()
53 CAF_Application::CAF_Application( const Handle(TDocStd_Application)& app )
59 CAF_Application::~CAF_Application()
63 QString CAF_Application::applicationName() const
65 return QString( "CAFApplication" );
68 Handle(TDocStd_Application) CAF_Application::stdApp() const
73 QString CAF_Application::getFileFilter() const
75 if ( stdApp().IsNull() )
78 TColStd_SequenceOfExtendedString formats;
79 stdApp()->Formats( formats );
82 QMap<QString, QStringList> wildCards;
83 Handle(Resource_Manager) resMgr = new Resource_Manager( stdApp()->ResourcesName() );
84 for ( int i = 1; i <= formats.Length(); i++ )
87 QString extResStr = CAF_Tools::toQString( formats.Value( i ) ) + QString( ".FileExtension" );
88 if ( resMgr->Find( (char*)extResStr.latin1() ) )
89 extension = QString( resMgr->Value( (char*)extResStr.latin1() ) );
92 QString descrResStr = CAF_Tools::toQString( formats.Value( i ) ) + QString( ".Description" );
93 if ( resMgr->Find( (char*)descrResStr.latin1() ) )
94 descr = QString( resMgr->Value( (char*)descrResStr.latin1() ) );
96 if ( !descr.isEmpty() && !extension.isEmpty() )
98 if ( !wildCards.contains( descr ) )
99 wildCards.insert( descr, QStringList() );
100 wildCards[descr].append( QString( "*.%1" ).arg( extension ) );
101 allWC.append( QString( "*.%1" ).arg( extension ) );
105 if ( wildCards.isEmpty() )
106 return QString::null;
109 for ( QMap<QString, QStringList>::ConstIterator it = wildCards.begin(); it != wildCards.end(); ++it )
110 filters.append( QString( "%1 (%2)" ).arg( it.key() ).arg( it.data().join( "; " ) ) );
112 if ( wildCards.count() > 1 )
113 filters.prepend( QString( "%1 (%2)" ).arg( tr( "INF_ALL_DOCUMENTS_FILTER" ) ).arg( allWC.join( "; " ) ) );
115 if ( !filters.isEmpty() )
116 filters.append( tr( "INF_ALL_FILTER" ) );
118 return filters.join( ";;" );
121 void CAF_Application::createActions()
123 STD_Application::createActions();
125 SUIT_Desktop* desk = desktop();
126 SUIT_ResourceMgr* resMgr = resourceMgr();
128 QtxListAction* editUndo =
129 new QtxListAction( tr( "TOT_APP_EDIT_UNDO" ), resMgr->loadPixmap( "CAF", tr( "ICON_APP_EDIT_UNDO" ) ),
130 tr( "MEN_APP_EDIT_UNDO" ), CTRL+Key_Z, desk );
131 registerAction( EditUndoId, editUndo );
133 QtxListAction* editRedo =
134 new QtxListAction( tr( "TOT_APP_EDIT_REDO" ), resMgr->loadPixmap( "CAF", tr( "ICON_APP_EDIT_REDO" ) ),
135 tr( "MEN_APP_EDIT_REDO" ), CTRL+Key_Y, desk );
136 registerAction( EditRedoId, editRedo );
138 editUndo->setComment( tr( "INF_APP_UNDOACTIONS" ) );
139 editRedo->setComment( tr( "INF_APP_REDOACTIONS" ) );
141 connect( editUndo, SIGNAL( activated( int ) ), this, SLOT( onUndo( int ) ) );
142 connect( editRedo, SIGNAL( activated( int ) ), this, SLOT( onRedo( int ) ) );
145 int editMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 10 );
147 createMenu( EditUndoId, editMenu, 0 );
148 createMenu( EditRedoId, editMenu, 0 );
149 createMenu( separator(), editMenu, -1, 0 );
151 int stdTBar = createTool( tr( "INF_DESK_TOOLBAR_STANDARD" ) );
153 createTool( separator(), stdTBar );
154 createTool( EditUndoId, stdTBar );
155 createTool( EditRedoId, stdTBar );
156 createTool( separator(), stdTBar );
160 Undo operation on the given document. [ virtual protected ]
162 bool CAF_Application::undo( CAF_Study* doc )
164 bool success = false;
167 if ( success = doc->undo() )
174 Redo operation on the given document. [ virtual protected ]
176 bool CAF_Application::redo(CAF_Study* doc)
178 bool success = false;
181 if ( success = doc->redo() )
188 Undo operation on the active document. [ virtual protected slot ]
190 bool CAF_Application::onUndo( int numActions )
193 while ( numActions > 0 )
195 CAF_Study* cafStudy = dynamic_cast<CAF_Study*>( activeStudy() );
198 if ( !undo( cafStudy ) )
206 updateCommandsStatus(); /* enable/disable undo/redo */
211 Redo operation on the active document. [ virtual protected slot ]
213 bool CAF_Application::onRedo( int numActions )
216 while ( numActions > 0 )
218 CAF_Study* cafStudy = dynamic_cast<CAF_Study*>( activeStudy() );
221 if ( !redo( cafStudy ) )
229 updateCommandsStatus(); /* enable/disable undo/redo */
234 Enables / disables the actions according to the application state. [ virtual protected ]
236 void CAF_Application::updateCommandsStatus()
238 STD_Application::updateCommandsStatus();
240 CAF_Study* cafStudy = 0;
241 if ( activeStudy() && activeStudy()->inherits( "CAF_Study" ) )
242 cafStudy = (CAF_Study*)activeStudy();
244 QAction* undo = action( EditUndoId );
245 if ( cafStudy && undo )
246 undo->setProperty( "names", cafStudy->undoNames() );
248 QAction* redo = action( EditRedoId );
249 if ( cafStudy && redo )
250 redo->setProperty( "names", cafStudy->redoNames() );
253 undo->setEnabled( cafStudy && cafStudy->canUndo() );
255 redo->setEnabled( cafStudy && cafStudy->canRedo() );
258 void CAF_Application::onHelpAbout()
260 SUIT_MessageBox::info1( desktop(), tr( "About" ), tr( "ABOUT_INFO" ), "&OK" );
263 SUIT_Study* CAF_Application::createNewStudy()
265 return new CAF_Study( this );
268 void CAF_Application::setStdApp( const Handle(TDocStd_Application)& app )