Ignore:
Timestamp:
Mar 5, 2008, 3:05:38 PM (16 years ago)
Author:
garnier
Message:

debut de merge en cours NE COMPILE PAS

Location:
trunk/geant4/visualization/OpenGL
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/geant4/visualization/OpenGL/include/G4OpenGLQtMovieDialog.hh

    r737 r739  
    3737#include <qdialog.h>
    3838
    39 class QButtonGroup;
    4039class QPushButton;
    4140class QLabel;
     
    7372  QLabel *fSaveFileStatus;
    7473  QLabel *fGlobalStatus;
     74  QPushButton *fButtonEmcode;
    7575
    7676  void checkEncoderParameters(QString);
  • trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh

    r738 r739  
    105105  QDialog* GLWindow;
    106106  bool hasPendingEvents();
    107   void saveForVideo(QString);
     107  void savePPMToTemp();
    108108  bool saveVideo(QString);
    109109  bool fRecordFrames;
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLQtMovieDialog.cc

    r737 r739  
    230230  buttonBoxLayout->addWidget(buttonApply);
    231231
    232   QPushButton * buttonEncode = new QPushButton( tr( "&Encode" ),buttonBox );
    233   buttonEncode->setEnabled(false);
    234   buttonEncode->setAutoDefault( TRUE );
    235   buttonBoxLayout->addWidget(buttonEncode);
     232  fButtonEncode = new QPushButton( tr( "&Encode" ),buttonBox );
     233  fButtonEncode->setEnabled(false);
     234  fButtonEncode->setAutoDefault( TRUE );
     235  buttonBoxLayout->addWidget(fButtonEncode);
    236236
    237237#if QT_VERSION >= 0x040000
     
    249249  connect( buttonApply, SIGNAL( clicked() ), this, SLOT( checkAllParameters() ) );
    250250  connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
    251   connect( buttonEncode, SIGNAL( clicked() ), this, SLOT( encode() ) );
     251  connect( fButtonEncode, SIGNAL( clicked() ), this, SLOT( encode() ) );
    252252
    253253  // fill
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc

    r738 r739  
    7272#include <qfiledialog.h>
    7373#include <qprinter.h>
     74#include <qdatetime.h>
    7475#include <qpainter.h>
    7576#include <qgl.h> // include <qglwidget.h>
     
    301302  ,fHoldRotateEvent(false)
    302303  ,fAutoMove(false)
     304  ,fEncoderPath("")
     305  ,fTempFolderPath("")
     306  ,fMovieTempFolderPath("")
     307  ,fSaveFileName("")
    303308  ,fMovieParametersDialog(NULL)
    304309{
     310
    305311  initMovieParameters();
    306   createTempFolder();
    307   removeTempFolder();
    308312
    309313#ifdef GEANT4_QT_DEBUG
     
    318322//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
    319323{
     324  removeTempFolder();
    320325#ifdef GEANT4_QT_DEBUG
    321326  printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n");
     
    12951300
    12961301
    1297 void G4OpenGLQtViewer::saveForVideo(QString nomFich) {
    1298   if (nomFich == "") {
     1302void G4OpenGLQtViewer::savePPMToTemp() {
     1303  if (fMovieTempFolderPath == "") {
    12991304    return;
    13001305  }
     1306  QString nomFich =fMovieTempFolderPath+"/Test"+QString::number(fRecordFrameNumber)
    13011307
    13021308  QImage image;
     
    13101316  res = image.save(nomFich,0);
    13111317#endif
    1312   if (res == false) {
    1313 #if QT_VERSION < 0x040000
    1314     G4cerr << "Error while saving file... "<<nomFich.ascii()<<"\n" << G4endl;
    1315 #else
    1316     G4cerr << "Error while saving file... "<<nomFich.toStdString().c_str()<<"\n" << G4endl;
    1317 #endif
     1318 if (res == false) {
    13181319    fRecordFrames = false;
    1319   }
    1320 
    1321 #if QT_VERSION < 0x040000
    1322   printf("SaveForVideo ^^^^^^^^^^^^^^^^^^^^^^^^ %s\n",nomFich.ascii());
    1323 #else
    1324   printf("SaveForVideo ^^^^^^^^^^^^^^^^^^^^^^^^ %s\n",nomFich.toStdString().c_str());
     1320    if (fMovieParametersDialog) {
     1321      fMovieParametersDialog->setStatus("Can't save tmp file "+nomFich);
     1322    } else {
     1323#if QT_VERSION < 0x040000
     1324      G4cout << "Can't save tmp file "<<nomFich.ascii()<<"\n" << G4endl;
     1325#else
     1326      G4cout << "Can't save tmp file "<<nomFich.toStdString().c_str()<<"\n" << G4endl;
     1327#endif
     1328    }
     1329    return;
     1330  }
     1331 
     1332  if (fMovieParametersDialog) {
     1333    fMovieParametersDialog->setStatus("File "+nomFich+" saved");
     1334  } else {
     1335#if QT_VERSION < 0x040000
     1336    G4cout << "File "<<nomFich.ascii()<<" saved\n" << G4endl;
     1337#else
     1338    G4cout << "File "<<nomFich.toStdString().c_str()<<" saved\n" << G4endl;
     1339#endif
     1340  }
     1341  fRecordFrameNumber++;
     1342#ifdef GEANT4_QT_DEBUG
     1343  printf("G4OpenGLStoredQtViewer::record frame %d\n",fRecordFrameNumber);
    13251344#endif
    13261345}
     
    19972016
    19982017  fHoldKeyEvent = true;
    1999   if (event->key() == Qt::Key_Down) {
    2000 #ifdef GEANT4_QT_DEBUG
    2001   printf("G4OpenGLQtViewer::G4keyPressEvent Down\n");
    2002 #endif
    2003   } else if (event->key() == Qt::Key_Up) {
    2004 #ifdef GEANT4_QT_DEBUG
    2005   printf("G4OpenGLQtViewer::G4keyPressEvent Up\n");
    2006 #endif
    2007   } else if (event->key() == Qt::Key_Plus) {
    2008 #ifdef GEANT4_QT_DEBUG
    2009   printf("G4OpenGLQtViewer::G4keyPressEvent Plus\n");
    2010 #endif
    2011   } else if (event->key() == Qt::Key_Minus) {
    2012 #ifdef GEANT4_QT_DEBUG
    2013   printf("G4OpenGLQtViewer::G4keyPressEvent Minus\n");
    2014 #endif
    2015   }
    2016   if (event->modifiers() & Qt::AltModifier ) {
    2017 #ifdef GEANT4_QT_DEBUG
    2018   printf("G4OpenGLQtViewer::G4keyPressEvent Alt\n");
    2019 #endif
    2020   } else if (event->modifiers() & Qt::ShiftModifier) {
    2021 #ifdef GEANT4_QT_DEBUG
    2022   printf("G4OpenGLQtViewer::G4keyPressEvent Shift\n");
    2023 #endif
    2024   }
    20252018
    20262019#if QT_VERSION < 0x040000
     
    21042097
    21052098  if ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter)){ // end of video
    2106     G4cout << "Stop Recording \n" << G4endl;
    2107     G4cout << "Saving /temp/output.mpg \n" << G4endl;
    2108     saveVideo("/temp/output.mpg");
     2099   // if encoder parameter is wrong, display parameters dialog and return
     2100    if (!fMovieParametersDialog) {
     2101      showMovieParametersDialog();
     2102    }
     2103    fMovieParametersDialog->setStatus("Stop Recording\n");
     2104    if (getEncoderPath() == "") {
     2105      fMovieParametersDialog->setStatus("No valid encoder found. Frames saved in "+fTempFolder);
     2106    }
     2107    if (generateMpegEncoderParameters()) {     
     2108      ...
     2109      if (
     2110          ...
     2111          if (fMovieParametersDialog) {
     2112            fMovieParametersDialog->setEncodeButtonEnable(true);
     2113          }
     2114      }
     2115    }
    21092116    fRecordFrames = false;
    21102117  }
    21112118  if (event->key() == Qt::Key_Space){ // start/pause of video
    2112 
    2113     // first time, if parameters are wrong, display parameters dialog and return
    2114     if ((fRecordFrames == false) && (getEncoderPath() == NULL)) {
    2115       showMovieParametersDialog();
    2116       return;
     2119   // first time, if temp parameter is wrong, display parameters dialog and return
     2120    if (fRecordFrames == false) {
     2121      if ( fRecordFrameNumber == 0) {
     2122        if (getTempFolderPath() == "") {
     2123          showMovieParametersDialog();
     2124          fMovieParametersDialog->setStatus("You should specified the temp folder in order to make movie");
     2125          fHoldKeyEvent = false;
     2126          return;
     2127        } else  {
     2128          //          printf("record+premier image+temp<>.. \n");
     2129          // remove temp folder if it was create
     2130          if (!removeTempFolder()) {
     2131            fHoldKeyEvent = false;
     2132            return;
     2133          }
     2134
     2135          //          printf("create tmp dir.. \n");
     2136          // create temp dir if not
     2137          QString time = QDir::fromNativeSeparators ("/"+QDateTime::currentDateTime ().toString("dd-MM-yyyy_hh-mm-ss"));
     2138          QDir dir(fTempFolderBasePath);
     2139          if (dir.mkdir(fTempFolderBasePath+time)) {
     2140            fTempFolder = fTempFolderBasePath+time;
     2141          }
     2142        }
     2143      }
    21172144    }
    21182145    fRecordFrames = !fRecordFrames;
    21192146    if (fRecordFrames) {
    2120       G4cout << " Start Recording \n" << G4endl;
     2147
     2148      if (fMovieParametersDialog) {
     2149        fMovieParametersDialog->setStatus("Start Recording\n");
     2150      } else {
     2151        G4cout << " Start Recording \n" << G4endl;
     2152      }
    21212153    } else {
    2122       G4cout << "Pause Recording \n" << G4endl;
    2123     }
     2154      if (fMovieParametersDialog) {
     2155        fMovieParametersDialog->setStatus("Pause Recording\n");
     2156      } else {
     2157        G4cout << "Pause Recording \n" << G4endl;
     2158      }
     2159    }   
    21242160  }
    21252161
     
    21462182}
    21472183 
    2148 
    2149 /** @return encoder path or "" if it does not exist
    2150  */
    2151 QString G4OpenGLQtViewer::getEncoderPath() {
    2152   return fEncoderPath;
    2153 }
    2154  
    2155 
    2156 /**
    2157  * set the new encoder path
    2158  * @return "" if correct. The error otherwise
    2159 */
    2160 QString G4OpenGLQtViewer::setEncoderPath(QString path) {
    2161   if (path == "") {
    2162     return "File does not exist";
    2163   }
    2164   QFile *f = new QFile(path);
    2165   if (!f->exists()) {
    2166     return "File does not exist";
    2167   }
    2168   if (!(f->permissions() & QFile::ExeUser)) {
    2169     return "File exist but is not executable";
    2170   }
    2171   fEncoderPath = path;
    2172   return "";
    2173 }
    2174 
    2175 /**
    2176  * set the temp folder path
    2177  * @return "" if correct. The error otherwise
    2178 */
    2179 QString G4OpenGLQtViewer::setTempFolderPath(QString path) {
    2180 
    2181   if (path == "") {
    2182     return "Path does not exist";
    2183   }
    2184   QDir *d = new QDir(path);
    2185   if (!d->exists(path)) {
    2186     return "Path does not exist";
    2187   }
    2188 
    2189   d->setFilter( QDir::Dirs | QDir::Readable | QDir::Writable );
    2190   QStringList subDirList = d->entryList();
    2191   bool found = false;
    2192 
    2193   for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) {
    2194     const QString currentDir = *it;
    2195    
    2196     if (currentDir == ".") { // we found it
    2197       found = true;
    2198     }
    2199   }
    2200 
    2201   if (!found)
    2202     return "Path exist, but is not write accessible";
    2203  
    2204   fTempFolderPath = path;
    2205   return "";
    2206 }
    2207 
    2208 /** @return the temp folder path or "" if it does not exist
    2209  */
    2210 QString G4OpenGLQtViewer::getTempFolderPath() {
    2211   return fTempFolderPath;
    2212 }
    2213  
    2214 /**
    2215  * set the save file name path
    2216  * @return "" if correct. The error otherwise
    2217 */
    2218 QString G4OpenGLQtViewer::setSaveFileName(QString path) {
    2219 
    2220   if (path == "") {
    2221     return "Path does not exist";
    2222   }
    2223   QDir *d = new QDir(path);
    2224   if (!d->exists(path)) {
    2225     return "Path does not exist";
    2226   }
    2227 
    2228   d->setFilter( QDir::Dirs | QDir::Readable | QDir::Writable );
    2229   QStringList subDirList = d->entryList();
    2230   bool found = false;
    2231 
    2232   for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) {
    2233     const QString currentDir = *it;
    2234    
    2235     if (currentDir == ".") { // we found it
    2236       found = true;
    2237     }
    2238   }
    2239 
    2240   if (!found)
    2241     return "Path exist, but is not write accessible";
    2242  
    2243   fSaveFileName = path;
    2244   return "";
    2245 }
    2246 
    2247 /** @return the save file path
    2248  */
    2249 QString G4OpenGLQtViewer::getSaveFileName() {
    2250   return fSaveFileName ;
    2251 }
    2252 
    2253 /** Create a Qt_temp folder in the temp folder given
    2254 */
    2255 bool G4OpenGLQtViewer::createTempFolder() {
    2256   fMovieTempFolderPath = "";
    2257 
    2258   //check
    2259   if (setTempFolderPath(fTempFolderPath) == "") {
    2260           return false;
    2261   }
    2262   QString path = QString("QtMovie_")+QDateTime::currentDateTime ().toString("dd--MM--yyyy_hh-mm-ss");
    2263   QDir *d = new QDir(fTempFolderPath);
    2264   // check if it is already present
    2265   if (d->exists(path)) {
    2266           return false;
    2267   }
    2268   if (d.mkdir(path)){
    2269 #ifdef GEANT4_QT_DEBUG
    2270     printf("G4OpenGLQtViewer::removeTempFolder. remove file %s\n",fMovieTempFolderPath.toStdString().c_str());
    2271 #endif
    2272         fMovieTempFolderPath = path;
    2273     return true;
    2274   }
    2275   return false:
    2276 }
    2277 
    2278 /** Remove the Qt_temp folder in the temp folder
    2279 */
    2280 bool G4OpenGLQtViewer::removeTempFolder() {
    2281         // remove files in Qt_temp folder
    2282   QDir *d = new QDir(fTempFolderPath+fMovieTempFolderPath);
    2283   if (!d->exists(path)) {
    2284     return false;  // already remove
    2285   }
    2286 
    2287   d->setFilter( QDir::Dirs | QDir::Readable | QDir::Writable );
    2288   QStringList subDirList = d->entryList();
    2289   bool found = false;
    2290 
    2291   for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) {
    2292     const QString currentDir = *it;
    2293 #ifdef GEANT4_QT_DEBUG
    2294     printf("G4OpenGLQtViewer::removeTempFolder. remove file %s\n",currentDir.toStdString().c_str());
    2295 #endif
    2296   }
    2297   if (d.rmdir(fTempFolderPath+fMovieTempFolderPath)) {
    2298     return true;
    2299   }
    2300   return false;
    2301 }
    23022184
    23032185/** Init the movie parameters. Temp dir and encoder path
     
    23242206  setTempFolderPath(QDir::temp ().absolutePath ());
    23252207}
     2208
     2209/** @return encoder path or "" if it does not exist
     2210 */
     2211QString G4OpenGLQtViewer::getEncoderPath() {
     2212  return fEncoderPath;
     2213}
     2214 
     2215
     2216/**
     2217 * set the new encoder path
     2218 * @return "" if correct. The error otherwise
     2219*/
     2220QString G4OpenGLQtViewer::setEncoderPath(QString path) {
     2221  if (path == "") {
     2222    return "File does not exist";
     2223  }
     2224  QFile *f = new QFile(path);
     2225  if (!f->exists()) {
     2226    return "File does not exist";
     2227  }
     2228  if (!(f->permissions() & QFile::ExeUser)) {
     2229    return "File exist but is not executable";
     2230  }
     2231  fEncoderPath = path;
     2232  return "";
     2233}
     2234
     2235/**
     2236 * set the temp folder path
     2237 * @return "" if correct. The error otherwise
     2238*/
     2239QString G4OpenGLQtViewer::setTempFolderPath(QString path) {
     2240
     2241  if (path == "") {
     2242    return "Path does not exist";
     2243  }
     2244  QDir *d = new QDir(path);
     2245  if (!d->exists(path)) {
     2246    return "Path does not exist";
     2247  }
     2248
     2249  d->setFilter( QDir::Dirs | QDir::Readable | QDir::Writable );
     2250  QStringList subDirList = d->entryList();
     2251  bool found = false;
     2252
     2253  for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) {
     2254    const QString currentDir = *it;
     2255   
     2256    if (currentDir == ".") { // we found it
     2257      found = true;
     2258    }
     2259  }
     2260
     2261  if (!found)
     2262    return "Path exist, but is not write accessible";
     2263 
     2264  fTempFolderPath = path;
     2265  return "";
     2266}
     2267
     2268/** @return the temp folder path or "" if it does not exist
     2269 */
     2270QString G4OpenGLQtViewer::getTempFolderPath() {
     2271  return fTempFolderPath;
     2272}
     2273 
     2274/**
     2275 * set the save file name path
     2276 * @return "" if correct. The error otherwise
     2277*/
     2278QString G4OpenGLQtViewer::setSaveFileName(QString path) {
     2279
     2280  if (path == "") {
     2281    return "Path does not exist";
     2282  }
     2283  QDir *d = new QDir(path);
     2284  if (!d->exists(path)) {
     2285    return "Path does not exist";
     2286  }
     2287
     2288  d->setFilter( QDir::Dirs | QDir::Readable | QDir::Writable );
     2289  QStringList subDirList = d->entryList();
     2290  bool found = false;
     2291
     2292  for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) {
     2293    const QString currentDir = *it;
     2294   
     2295    if (currentDir == ".") { // we found it
     2296      found = true;
     2297    }
     2298  }
     2299
     2300  if (!found)
     2301    return "Path exist, but is not write accessible";
     2302 
     2303  fSaveFileName = path;
     2304  return "";
     2305}
     2306
     2307/** @return the save file path
     2308 */
     2309QString G4OpenGLQtViewer::getSaveFileName() {
     2310  return fSaveFileName ;
     2311}
     2312
     2313/** Create a Qt_temp folder in the temp folder given
     2314*/
     2315bool G4OpenGLQtViewer::createTempFolder() {
     2316  fMovieTempFolderPath = "";
     2317
     2318  //check
     2319  if (setTempFolderPath(fTempFolderPath) != "") {
     2320    return false;
     2321  }
     2322  QString path = QString("/QtMovie_")+QDateTime::currentDateTime ().toString("dd-MM-yyyy_hh-mm-ss");
     2323  QDir *d = new QDir(fTempFolderPath);
     2324  // check if it is already present
     2325  if (d->exists(path)) {
     2326          return false;
     2327  }
     2328  if (d->mkdir(fTempFolderPath+path)) {
     2329    fMovieTempFolderPath = fTempFolderPath+path;
     2330    return true;
     2331  }
     2332  return false;
     2333}
     2334
     2335/** Remove the Qt_temp folder in the temp folder
     2336*/
     2337bool G4OpenGLQtViewer::removeTempFolder() {
     2338        // remove files in Qt_temp folder
     2339  QDir *d = new QDir(fMovieTempFolderPath);
     2340  if (!d->exists()) {
     2341    return false;  // already remove
     2342  }
     2343
     2344  d->setFilter(QDir::Readable | QDir::Writable );
     2345  QStringList subDirList = d->entryList();
     2346  int res = true;
     2347
     2348  for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) {
     2349    const QString currentFile = *it;
     2350    if (!d->remove(currentFile)) {
     2351      res = false;
     2352      G4cout << "Try to remove Movie temp directory:"<<fMovieTempFolderPath.toStdString()<<" but failed to remove:"<<fMovieTempFolderPath.toStdString()<<"/"<<currentFile.toStdString() <<"\n" << G4endl;
     2353    }
     2354  }
     2355  if (res) {
     2356    if (d->rmdir(fMovieTempFolderPath)) {
     2357      return true;
     2358    }
     2359  }
     2360  return false;
     2361}
     2362
    23262363
    23272364
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc

    r728 r739  
    3434#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
    3535
    36 #define GEANT4_QT_DEBUG
     36//#define GEANT4_QT_DEBUG
    3737
    3838#include "G4OpenGLStoredQtViewer.hh"
     
    200200
    201201  if (fRecordFrames) {
    202     saveForVideo(QString("/temp/Test")+QString::number(fRecordFrameNumber));
     202    savePPMToTemp();
    203203    fRecordFrameNumber++;
    204204#ifdef GEANT4_QT_DEBUG
Note: See TracChangeset for help on using the changeset viewer.