qoccapplication.cpp

Go to the documentation of this file.
00001 /************************************************************************************
00002 **
00003 ** This file is part of the QtOPENCASCADE Toolkit.
00004 **
00005 ** Copyright (C) 2006, 2007, 2008 QtOCC Team Members
00006 **               Peter Dolbey, Marc Britten, Stephane Routelous
00007 **               Stefan Boeykens, Pawel Dobrolowski, Walter Steffe
00008 **               Álvaro Castro Castilla, Dirk Burski, Fotis Sioutis
00009 **
00010 ** This library is free software; you can redistribute it and/or
00011 ** modify it under the terms of the GNU Lesser General Public
00012 ** License as published by the Free Software Foundation; either
00013 ** version 2.1 of the License, or (at your option) any later version.
00014 **
00015 ** This library is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 ** Lesser General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU Lesser General Public
00021 ** License along with this library; if not, write to the Free Software
00022 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023 **
00024 ***********************************************************************************/
00025 
00026 /*
00027 \class  QoccApplication
00028 \brief  This class provides an application extension for the QtOPENCASCADE Toolkit.
00029 \author Peter C. Dolbey
00030 */
00031 #include <QtCore/QDataStream>
00032 #include <QtCore/QEvent>
00033 #include <QtGui/QCursor>
00034 #include <QtCore/QWaitCondition>
00035 #include <QtCore/QMutex>
00036 #include <QtCore/QThread>
00037 
00038 #include "qoccdocument.h"
00039 #include "qoccinternal.h"
00040 #include "qoccapplication.h"
00041 
00042 
00043 QoccApplication::QoccApplication(int &argc, char **argv, int _internal ) :
00044         QApplication (argc, argv, _internal),
00045         mySplash (NULL),
00046         myNextID (0)
00047 {
00048 
00049 #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
00050         setAttribute(Qt::AA_NativeWindows);
00051 #endif
00052 
00053         // Initialise the GEOM framework
00054         myEngine = new GEOMImpl_Gen();
00055         myEngine->SetUndoLimit(20);
00056         UnitsAPI::SetLocalSystem(UnitsAPI_DEFAULT);
00057 
00058 }
00059 
00060 QoccApplication::~QoccApplication()
00061 {
00062         if ( mySplash ) { delete mySplash; }
00063         if ( myEngine ) { delete myEngine; }
00064 }
00065 
00066 QoccDocument* QoccApplication::createDocument( )
00067 {
00068         Handle_TDocStd_Document aDoc;
00069         QoccDocument*           qDoc = NULL;
00070         
00071         aDoc = myEngine->GetDocument( ++myNextID );
00072         if ( !aDoc.IsNull() )
00073         {
00074                 aDoc->SetUndoLimit(20);
00075                 qDoc = new QoccDocument( aDoc, myNextID );
00076         }
00077         return qDoc;
00078 }
00079 
00080 
00081 void QoccApplication::splashScreen ( const QPixmap &pixmap )
00082 {
00083         QPixmap* p = (QPixmap*) &pixmap;
00084         if ( p->isNull() )
00085         {
00086                 p = new QPixmap( ":/images/images/QoccSplash.png" );
00087         }
00088         mySplash = new QSplashScreen( *p, Qt::WindowStaysOnTopHint );
00089         if ( mySplash )
00090         {
00091                 mySplash->show();
00092                 splashMessage( tr( "Initializing Application..." ), Qt::AlignRight | Qt::AlignTop );
00093         }
00094 }
00095 
00096 void QoccApplication::splashMessage(const QString &message, int alignment, const QColor &color)
00097 {
00098         if ( mySplash )
00099         {
00100                 mySplash->showMessage( message, alignment, color );
00101         }
00102 }
00103 
00104 void QoccApplication::splashFinish ( QWidget* widget, long millisecs )
00105 {
00106         if ( mySplash )
00107         {
00108                 msleep ( millisecs );
00109                 mySplash->finish( widget );
00110                 delete mySplash;
00111                 mySplash = NULL;
00112         }
00113 }
00114 
00115 void QoccApplication::msleep(unsigned long millisecs)
00116 {
00117         QMutex mutex;
00118         QWaitCondition waitCondition;
00119         mutex.lock();
00120         waitCondition.wait( &mutex, millisecs );
00121         mutex.unlock();
00122 }
00123 
00124 void QoccApplication::Undo( QoccDocument* aDoc )
00125 {
00126         myEngine->Undo( aDoc->id() );
00127 }
00128 
00129 void QoccApplication::Redo( QoccDocument* aDoc )
00130 {
00131         myEngine->Redo( aDoc->id() );
00132 }
00133 
00134 bool QoccApplication::SaveDocument( QoccDocument* aDoc )
00135 {
00136         if (!aDoc->getDocument()->IsSaved())
00137         {
00138                 return false;
00139         }
00140         else
00141         {
00142                 myEngine->GetApplication()->Save(aDoc->getDocument());
00143                 return true;
00144         }
00145 }
00146 
00147 bool QoccApplication::SaveDocumentAs( QoccDocument* aDoc, char* theFormat, char* theFileName )
00148 {
00149         if              (theFormat == "cbf")
00150                 aDoc->getDocument()->ChangeStorageFormat("GEOM_BIN");
00151         else if (theFormat == "sta")
00152                 aDoc->getDocument()->ChangeStorageFormat("GEOM_ASCII");
00153         else if (theFormat == "xml")
00154                 aDoc->getDocument()->ChangeStorageFormat("GEOM_XML");
00155         else
00156         {
00157                 //cprompt << "Not valid Save Format Specified" << endl;
00158                 return false;
00159         }
00160 
00161         try {
00162                 myEngine->Save(aDoc->id(), theFileName );
00163                 return true;
00164         }
00165         catch(...) {
00166                 //cprompt << "Error! The file wasn't saved." << endl;
00167                 return false;
00168         }
00169 }
00170 
00171 QoccDocument* QoccApplication::LoadDocument( char* theFileName )
00172 {
00173         Handle_TDocStd_Document aDoc;
00174         QoccDocument*           qDoc = NULL;
00175 
00176         if (myEngine->Load( ++myNextID, theFileName ))
00177         {
00178                 aDoc = myEngine->GetDocument( myNextID );
00179 
00180                 qDoc = new QoccDocument( aDoc, myNextID );
00181 
00182                 if ( !aDoc.IsNull() )
00183                 {
00184                         aDoc->SetUndoLimit(20);
00185                         qDoc->UpdatePresentations(aDoc->Main());
00186                 }
00187                 return qDoc;
00188         }
00189         return NULL;
00190 }
00191 
00192 bool QoccApplication::ResetDocument( QoccDocument* aDoc )
00193 {
00194         Handle_TDocStd_Document aNewDoc;
00195 
00196         myEngine->Close(aDoc->id());
00197 
00198         aNewDoc = myEngine->GetDocument( ++myNextID );
00199 
00200         if ( !aNewDoc.IsNull() )
00201         {
00202                 aNewDoc->SetUndoLimit(20);
00203                 aDoc->SetDocumentAndID(aNewDoc, myNextID);
00204                 return true;
00205         }
00206         return false;
00207 }
00208 

Generated on Sat Feb 23 21:22:15 2008 for QtGEOM by  doxygen 1.4.7