#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 <SUIT_Desktop.h>
+#include <SUIT_Session.h>
+#include <SUIT_ViewModel.h>
+#include <SUIT_Operation.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_ResourceMgr.h>
-#include "QtxListAction.h"
+#include <QtxListAction.h>
#include <qtoolbar.h>
#include <qmenubar.h>
#include <qstatusbar.h>
#include <qapplication.h>
+#include <Resource_Manager.hxx>
+
+#include <TColStd_SequenceOfExtendedString.hxx>
+
extern "C" CAF_EXPORT SUIT_Application* createApplication()
{
return new CAF_Application();
{
}
+CAF_Application::CAF_Application( const Handle(TDocStd_Application)& app )
+: STD_Application(),
+myStdApp( app )
+{
+}
+
CAF_Application::~CAF_Application()
{
}
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<QString, QStringList> 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<QString, QStringList>::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();
{
return new CAF_Study( this );
}
+
+void CAF_Application::setStdApp( const Handle(TDocStd_Application)& app )
+{
+ myStdApp = app;
+}
#include <qmap.h>
#include <qptrlist.h>
+#include <TDocStd_Application.hxx>
+
class QtxAction;
class CAF_Study;
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
#include "CAF_Tools.h"
#include "CAF_Operation.h"
+#include "CAF_Application.h"
#include <SUIT_Desktop.h>
#include <SUIT_MessageBox.h>
#include <SUIT_Application.h>
+#include <qdir.h>
+
#include <TDF_Delta.hxx>
#include <TDF_ListIteratorOfDeltaList.hxx>
{
}
-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() )
myStdDoc->OpenCommand();
}
- catch( Standard_Failure ) {
+ catch ( Standard_Failure ) {
res = false;
}
}
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<CAF_Application*>( application() );
+}
#include "SUIT_Study.h"
#include <qobject.h>
-#include <qptrstack.h>
#include <TDocStd_Document.hxx>
+#include <TDocStd_Application.hxx>
+
+class CAF_Application;
#if defined WNT
#pragma warning ( disable: 4251 )
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;
};
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 (*.*)"
delete popup;
}
+#include <qregexp.h>
+
/*!\retval QString - return file name from dialog.*/
QString STD_Application::getFileName( bool open, const QString& initial, const QString& filters,
const QString& caption, QWidget* parent )
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;