00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
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
00158 return false;
00159 }
00160
00161 try {
00162 myEngine->Save(aDoc->id(), theFileName );
00163 return true;
00164 }
00165 catch(...) {
00166
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