From 8d65f580052e1cac799c7b8174017531492302b2 Mon Sep 17 00:00:00 2001 From: stv Date: Fri, 11 Nov 2005 14:31:25 +0000 Subject: [PATCH] no message --- src/CAF/CAF_Application.cxx | 88 +++++++++++++++++++++++--- src/CAF/CAF_Application.h | 32 +++++++--- src/CAF/CAF_Study.cxx | 106 +++++++++++++++++++++++++++++++- src/CAF/CAF_Study.h | 51 +++++++++------ src/CAF/resources/CAF_msg_en.po | 6 ++ src/STD/STD_Application.cxx | 55 +++++++++-------- 6 files changed, 275 insertions(+), 63 deletions(-) diff --git a/src/CAF/CAF_Application.cxx b/src/CAF/CAF_Application.cxx index db05644cf..495241041 100755 --- a/src/CAF/CAF_Application.cxx +++ b/src/CAF/CAF_Application.cxx @@ -1,15 +1,16 @@ #include "CAF_Application.h" +#include "CAF_Tools.h" #include "CAF_Study.h" -#include "SUIT_Desktop.h" -#include "SUIT_Session.h" -#include "SUIT_ViewModel.h" -#include "SUIT_Operation.h" -#include "SUIT_MessageBox.h" -#include "SUIT_ResourceMgr.h" +#include +#include +#include +#include +#include +#include -#include "QtxListAction.h" +#include #include #include @@ -17,6 +18,10 @@ #include #include +#include + +#include + extern "C" CAF_EXPORT SUIT_Application* createApplication() { return new CAF_Application(); @@ -27,6 +32,12 @@ CAF_Application::CAF_Application() { } +CAF_Application::CAF_Application( const Handle(TDocStd_Application)& app ) +: STD_Application(), +myStdApp( app ) +{ +} + CAF_Application::~CAF_Application() { } @@ -36,6 +47,64 @@ QString CAF_Application::applicationName() const return QString( "CAFApplication" ); } +QString CAF_Application::storageFormat() const +{ + return QString( "MDTV-Standard" ); +} + +Handle(TDocStd_Application) CAF_Application::stdApp() const +{ + return myStdApp; +} + +QString CAF_Application::getFileFilter() const +{ + if ( stdApp().IsNull() ) + return QString::null; + + TColStd_SequenceOfExtendedString formats; + stdApp()->Formats( formats ); + + QStringList allWC; + QMap wildCards; + Handle(Resource_Manager) resMgr = new Resource_Manager( stdApp()->ResourcesName() ); + for ( int i = 1; i <= formats.Length(); i++ ) + { + QString extension; + QString extResStr = CAF_Tools::toQString( formats.Value( i ) ) + QString( ".FileExtension" ); + if ( resMgr->Find( (char*)extResStr.latin1() ) ) + extension = QString( resMgr->Value( (char*)extResStr.latin1() ) ); + + QString descr; + QString descrResStr = CAF_Tools::toQString( formats.Value( i ) ) + QString( ".Description" ); + if ( resMgr->Find( (char*)descrResStr.latin1() ) ) + descr = QString( resMgr->Value( (char*)descrResStr.latin1() ) ); + + if ( !descr.isEmpty() && !extension.isEmpty() ) + { + if ( !wildCards.contains( descr ) ) + wildCards.insert( descr, QStringList() ); + wildCards[descr].append( QString( "*.%1" ).arg( extension ) ); + allWC.append( QString( "*.%1" ).arg( extension ) ); + } + } + + if ( wildCards.isEmpty() ) + return QString::null; + + QStringList filters; + for ( QMap::ConstIterator it = wildCards.begin(); it != wildCards.end(); ++it ) + filters.append( QString( "%1 (%2)" ).arg( it.key() ).arg( it.data().join( "; " ) ) ); + + if ( wildCards.count() > 1 ) + filters.prepend( QString( "%1 (%2)" ).arg( tr( "INF_ALL_DOCUMENTS_FILTER" ) ).arg( allWC.join( "; " ) ) ); + + if ( !filters.isEmpty() ) + filters.append( tr( "INF_ALL_FILTER" ) ); + + return filters.join( ";;" ); +} + void CAF_Application::createActions() { STD_Application::createActions(); @@ -182,3 +251,8 @@ SUIT_Study* CAF_Application::createNewStudy() { return new CAF_Study( this ); } + +void CAF_Application::setStdApp( const Handle(TDocStd_Application)& app ) +{ + myStdApp = app; +} diff --git a/src/CAF/CAF_Application.h b/src/CAF/CAF_Application.h index 8f7300459..9c377a8fa 100755 --- a/src/CAF/CAF_Application.h +++ b/src/CAF/CAF_Application.h @@ -8,6 +8,8 @@ #include #include +#include + class QtxAction; class CAF_Study; @@ -21,28 +23,40 @@ class CAF_EXPORT CAF_Application : public STD_Application public: CAF_Application(); + CAF_Application( const Handle(TDocStd_Application)& ); virtual ~CAF_Application(); - virtual QString applicationName() const; + virtual QString applicationName() const; + + Handle(TDocStd_Application) stdApp() const; + + virtual QString storageFormat() const; + + virtual QString getFileFilter() const; public slots: - virtual void onHelpAbout(); + virtual void onHelpAbout(); protected slots: - virtual bool onUndo( int ); - virtual bool onRedo( int ); + virtual bool onUndo( int ); + virtual bool onRedo( int ); protected: enum { EditUndoId = STD_Application::UserID, EditRedoId, UserID }; protected: - virtual void createActions(); - virtual void updateCommandsStatus(); + virtual void createActions(); + virtual void updateCommandsStatus(); + + virtual SUIT_Study* createNewStudy(); + + bool undo( CAF_Study* doc ); + bool redo( CAF_Study* doc ); - virtual SUIT_Study* createNewStudy(); + virtual void setStdApp( const Handle(TDocStd_Application)& ); - bool undo( CAF_Study* doc ); - bool redo( CAF_Study* doc ); +private: + Handle(TDocStd_Application) myStdApp; }; #if defined WIN32 diff --git a/src/CAF/CAF_Study.cxx b/src/CAF/CAF_Study.cxx index e9262e495..178182ab5 100755 --- a/src/CAF/CAF_Study.cxx +++ b/src/CAF/CAF_Study.cxx @@ -2,11 +2,14 @@ #include "CAF_Tools.h" #include "CAF_Operation.h" +#include "CAF_Application.h" #include #include #include +#include + #include #include @@ -31,16 +34,93 @@ CAF_Study::~CAF_Study() { } -Handle(TDocStd_Document) CAF_Study::stdDocument() const +Handle(TDocStd_Document) CAF_Study::stdDoc() const { return myStdDoc; } -void CAF_Study::setStdDocument( Handle(TDocStd_Document)& aStdDoc ) +void CAF_Study::setStdDoc( Handle(TDocStd_Document)& aStdDoc ) { myStdDoc = aStdDoc; } +void CAF_Study::createDocument() +{ + SUIT_Study::createDocument(); + + CAF_Application* app = cafApplication(); + if ( app && !app->stdApp().IsNull() ) + { + try { + TColStd_SequenceOfExtendedString formats; + app->stdApp()->Formats( formats ); + if ( !formats.IsEmpty() ) + app->stdApp()->NewDocument( formats.First(), myStdDoc ); + } + catch ( Standard_Failure ) { + } + } +} + +void CAF_Study::closeDocument( bool permanent ) +{ + Handle(TDocStd_Application) app = stdApp(); + if ( !app.IsNull() && !stdDoc().IsNull() ) + app->Close( stdDoc() ); + + SUIT_Study::closeDocument( permanent ); +} + +bool CAF_Study::openDocument( const QString& fname ) +{ + Handle(TDocStd_Application) app = stdApp(); + if ( app.IsNull() ) + return false; + + try { + app->Open( CAF_Tools::toExtString( fname ), myStdDoc ); + } + catch ( Standard_Failure ) { + return false; + } + + return SUIT_Study::openDocument( fname ); +} + +bool CAF_Study::saveDocumentAs( const QString& fname ) +{ + Handle(TDocStd_Application) app = stdApp(); + if ( app.IsNull() ) + return false; + + bool save = false; + if ( !stdDoc().IsNull() && stdDoc()->IsSaved() ) + { + QString path = QDir::convertSeparators( CAF_Tools::toQString( stdDoc()->GetPath() ) ); + save = path == QDir::convertSeparators( fname ); + } + + try { + if ( save ) + app->Save( stdDoc() ); + else + { + TCollection_ExtendedString format, path( CAF_Tools::toExtString( fname ) ); + app->Format( path, format ); + + if ( format.Length() ) + stdDoc()->ChangeStorageFormat( format ); + + app->SaveAs( stdDoc(), path ); + } + } + catch ( Standard_Failure ) { + return false; + } + + return SUIT_Study::saveDocumentAs( fname ); +} + bool CAF_Study::startOperation() { if ( myStdDoc.IsNull() ) @@ -53,7 +133,7 @@ bool CAF_Study::startOperation() myStdDoc->OpenCommand(); } - catch( Standard_Failure ) { + catch ( Standard_Failure ) { res = false; } @@ -237,3 +317,23 @@ QStringList CAF_Study::redoNames() const } return names; } + +/*! + Returns the standard OCAF application from owner application. [ protected ] +*/ +Handle(TDocStd_Application) CAF_Study::stdApp() const +{ + Handle(TDocStd_Application) stdApp; + CAF_Application* app = cafApplication(); + if ( app ) + stdApp = app->stdApp(); + return stdApp; +} + +/*! + Returns the application casted to type CAF_Application. [ protected ] +*/ +CAF_Application* CAF_Study::cafApplication() const +{ + return ::qt_cast( application() ); +} diff --git a/src/CAF/CAF_Study.h b/src/CAF/CAF_Study.h index dc1f7fe5f..88ae24cba 100755 --- a/src/CAF/CAF_Study.h +++ b/src/CAF/CAF_Study.h @@ -6,9 +6,11 @@ #include "SUIT_Study.h" #include -#include #include +#include + +class CAF_Application; #if defined WNT #pragma warning ( disable: 4251 ) @@ -23,29 +25,40 @@ public: CAF_Study( SUIT_Application* theApp, Handle(TDocStd_Document)& aStdDoc ); virtual ~CAF_Study(); - virtual bool startOperation(); - virtual void abortOperation(); - virtual void commitOperation(); + virtual void createDocument(); + virtual void closeDocument( bool = true ); + virtual bool openDocument( const QString& ); + + virtual bool saveDocumentAs( const QString& ); + + virtual bool startOperation(); + virtual void abortOperation(); + virtual void commitOperation(); - bool isSaved() const; - bool isModified() const; - void doModified( bool undoable = true); - void undoModified(); - void clearModified(); + bool isSaved() const; + bool isModified() const; + void doModified( bool = true ); + void undoModified(); + void clearModified(); - bool undo(); - bool redo(); - bool canUndo() const; - bool canRedo() const; - QStringList undoNames() const; - QStringList redoNames() const; + bool undo(); + bool redo(); + bool canUndo() const; + bool canRedo() const; + QStringList undoNames() const; + QStringList redoNames() const; - Handle(TDocStd_Document) stdDocument() const; - void setStdDocument( Handle(TDocStd_Document)& ); + Handle(TDocStd_Document) stdDoc() const; protected: - Handle(TDocStd_Document) myStdDoc; - int myModifiedCnt; + Handle(TDocStd_Application) stdApp() const; + CAF_Application* cafApplication() const; + + virtual void setStdDoc( Handle(TDocStd_Document)& ); + +private: + Handle(TDocStd_Document) myStdDoc; + int myModifiedCnt; friend class CAF_Operation; }; diff --git a/src/CAF/resources/CAF_msg_en.po b/src/CAF/resources/CAF_msg_en.po index fc7188c36..59119c241 100755 --- a/src/CAF/resources/CAF_msg_en.po +++ b/src/CAF/resources/CAF_msg_en.po @@ -41,3 +41,9 @@ msgstr " Undoes %1 action(s) " msgid "CAF_Application::INF_APP_REDOACTIONS" msgstr " Redoes %1 action(s) " + +msgid "CAF_Application::INF_ALL_DOCUMENTS_FILTER" +msgstr "All Readable Documents" + +msgid "CAF_Application::INF_ALL_FILTER" +msgstr "All Files (*.*)" diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index 2b5759931..20b8f0837 100755 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -699,6 +699,8 @@ void STD_Application::onConnectPopupRequest( SUIT_PopupClient* client, QContextM delete popup; } +#include + /*!\retval QString - return file name from dialog.*/ QString STD_Application::getFileName( bool open, const QString& initial, const QString& filters, const QString& caption, QWidget* parent ) @@ -719,42 +721,45 @@ QString STD_Application::getFileName( bool open, const QString& initial, const Q while ( !isOk ) { // It is preferrable to use OS-specific file dialog box here !!! - aName = QFileDialog::getSaveFileName( anOldPath, filters, parent, - 0, caption, &aUsedFilter); + aName = QFileDialog::getSaveFileName( anOldPath, filters, parent, 0, caption, &aUsedFilter ); if ( aName.isNull() ) isOk = true; else { - if ( !getFileFilter().isNull() ) // check extension and add if it is necessary + int aEnd = aUsedFilter.findRev( ')' ); + int aStart = aUsedFilter.findRev( '(', aEnd ); + QString wcStr = aUsedFilter.mid( aStart + 1, aEnd - aStart - 1 ); + + int idx = 0; + QStringList extList; + QRegExp rx( "[\b\\*]*\\.([\\w]+)" ); + while ( ( idx = rx.search( wcStr, idx ) ) != -1 ) { - int aStart = aUsedFilter.find( '*' ); - int aEnd = aUsedFilter.find( ')', aStart + 1 ); - QString aExt = aUsedFilter.mid( aStart + 1, aEnd - aStart - 1 ); - if ( aExt.contains( '*' ) == 0 ) // if it is not *.* - { - // Check that there is an extension at the end of the name - QString aNameTail = aName.right( aExt.length() ); - if ( aNameTail != aExt ) - aName += aExt; - } + extList.append( rx.cap( 1 ) ); + idx += rx.matchedLength(); } - if ( QFileInfo( aName ).exists() ) + + if ( !extList.isEmpty() && !extList.contains( QFileInfo( aName ).extension() ) ) + aName += QString( ".%1" ).arg( extList.first() ); + + if ( QFileInfo( aName ).exists() ) { - int aAnswer = SUIT_MessageBox::warn3( desktop(), tr( "TIT_FILE_SAVEAS" ), - tr( "MSG_FILE_EXISTS" ).arg( aName ), - tr( "BUT_YES" ), tr( "BUT_NO" ), tr( "BUT_CANCEL" ), 1, 2, 3, 1 ); - if ( aAnswer == 3 ) { // cancelled + int aAnswer = SUIT_MessageBox::warn3( desktop(), tr( "TIT_FILE_SAVEAS" ), + tr( "MSG_FILE_EXISTS" ).arg( aName ), + tr( "BUT_YES" ), tr( "BUT_NO" ), tr( "BUT_CANCEL" ), 1, 2, 3, 1 ); + if ( aAnswer == 3 ) + { // cancelled aName = QString::null; - isOk = true; + isOk = true; } - else if ( aAnswer == 2 ) // not save to this file - anOldPath = aName; // not to return to the same initial dir at each "while" step - else // overwrite the existing file - isOk = true; + else if ( aAnswer == 2 ) // not save to this file + anOldPath = aName; // not to return to the same initial dir at each "while" step + else // overwrite the existing file + isOk = true; } - else - isOk = true; + else + isOk = true; } } return aName; -- 2.39.2