Changeset 739 for trunk/geant4
- Timestamp:
- Mar 5, 2008, 3:05:38 PM (17 years ago)
- Location:
- trunk/geant4/visualization/OpenGL
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/geant4/visualization/OpenGL/include/G4OpenGLQtMovieDialog.hh
r737 r739 37 37 #include <qdialog.h> 38 38 39 class QButtonGroup;40 39 class QPushButton; 41 40 class QLabel; … … 73 72 QLabel *fSaveFileStatus; 74 73 QLabel *fGlobalStatus; 74 QPushButton *fButtonEmcode; 75 75 76 76 void checkEncoderParameters(QString); -
trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh
r738 r739 105 105 QDialog* GLWindow; 106 106 bool hasPendingEvents(); 107 void save ForVideo(QString);107 void savePPMToTemp(); 108 108 bool saveVideo(QString); 109 109 bool fRecordFrames; -
trunk/geant4/visualization/OpenGL/src/G4OpenGLQtMovieDialog.cc
r737 r739 230 230 buttonBoxLayout->addWidget(buttonApply); 231 231 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); 236 236 237 237 #if QT_VERSION >= 0x040000 … … 249 249 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( checkAllParameters() ) ); 250 250 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); 251 connect( buttonEncode, SIGNAL( clicked() ), this, SLOT( encode() ) );251 connect( fButtonEncode, SIGNAL( clicked() ), this, SLOT( encode() ) ); 252 252 253 253 // fill -
trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc
r738 r739 72 72 #include <qfiledialog.h> 73 73 #include <qprinter.h> 74 #include <qdatetime.h> 74 75 #include <qpainter.h> 75 76 #include <qgl.h> // include <qglwidget.h> … … 301 302 ,fHoldRotateEvent(false) 302 303 ,fAutoMove(false) 304 ,fEncoderPath("") 305 ,fTempFolderPath("") 306 ,fMovieTempFolderPath("") 307 ,fSaveFileName("") 303 308 ,fMovieParametersDialog(NULL) 304 309 { 310 305 311 initMovieParameters(); 306 createTempFolder();307 removeTempFolder();308 312 309 313 #ifdef GEANT4_QT_DEBUG … … 318 322 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 319 323 { 324 removeTempFolder(); 320 325 #ifdef GEANT4_QT_DEBUG 321 326 printf("G4OpenGLQtViewer::~G4OpenGLQtViewer \n"); … … 1295 1300 1296 1301 1297 void G4OpenGLQtViewer::save ForVideo(QString nomFich) {1298 if ( nomFich == "") {1302 void G4OpenGLQtViewer::savePPMToTemp() { 1303 if (fMovieTempFolderPath == "") { 1299 1304 return; 1300 1305 } 1306 QString nomFich =fMovieTempFolderPath+"/Test"+QString::number(fRecordFrameNumber) 1301 1307 1302 1308 QImage image; … … 1310 1316 res = image.save(nomFich,0); 1311 1317 #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) { 1318 1319 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); 1325 1344 #endif 1326 1345 } … … 1997 2016 1998 2017 fHoldKeyEvent = true; 1999 if (event->key() == Qt::Key_Down) {2000 #ifdef GEANT4_QT_DEBUG2001 printf("G4OpenGLQtViewer::G4keyPressEvent Down\n");2002 #endif2003 } else if (event->key() == Qt::Key_Up) {2004 #ifdef GEANT4_QT_DEBUG2005 printf("G4OpenGLQtViewer::G4keyPressEvent Up\n");2006 #endif2007 } else if (event->key() == Qt::Key_Plus) {2008 #ifdef GEANT4_QT_DEBUG2009 printf("G4OpenGLQtViewer::G4keyPressEvent Plus\n");2010 #endif2011 } else if (event->key() == Qt::Key_Minus) {2012 #ifdef GEANT4_QT_DEBUG2013 printf("G4OpenGLQtViewer::G4keyPressEvent Minus\n");2014 #endif2015 }2016 if (event->modifiers() & Qt::AltModifier ) {2017 #ifdef GEANT4_QT_DEBUG2018 printf("G4OpenGLQtViewer::G4keyPressEvent Alt\n");2019 #endif2020 } else if (event->modifiers() & Qt::ShiftModifier) {2021 #ifdef GEANT4_QT_DEBUG2022 printf("G4OpenGLQtViewer::G4keyPressEvent Shift\n");2023 #endif2024 }2025 2018 2026 2019 #if QT_VERSION < 0x040000 … … 2104 2097 2105 2098 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 } 2109 2116 fRecordFrames = false; 2110 2117 } 2111 2118 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 } 2117 2144 } 2118 2145 fRecordFrames = !fRecordFrames; 2119 2146 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 } 2121 2153 } 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 } 2124 2160 } 2125 2161 … … 2146 2182 } 2147 2183 2148 2149 /** @return encoder path or "" if it does not exist2150 */2151 QString G4OpenGLQtViewer::getEncoderPath() {2152 return fEncoderPath;2153 }2154 2155 2156 /**2157 * set the new encoder path2158 * @return "" if correct. The error otherwise2159 */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 path2177 * @return "" if correct. The error otherwise2178 */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 it2197 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 exist2209 */2210 QString G4OpenGLQtViewer::getTempFolderPath() {2211 return fTempFolderPath;2212 }2213 2214 /**2215 * set the save file name path2216 * @return "" if correct. The error otherwise2217 */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 it2236 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 path2248 */2249 QString G4OpenGLQtViewer::getSaveFileName() {2250 return fSaveFileName ;2251 }2252 2253 /** Create a Qt_temp folder in the temp folder given2254 */2255 bool G4OpenGLQtViewer::createTempFolder() {2256 fMovieTempFolderPath = "";2257 2258 //check2259 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 present2265 if (d->exists(path)) {2266 return false;2267 }2268 if (d.mkdir(path)){2269 #ifdef GEANT4_QT_DEBUG2270 printf("G4OpenGLQtViewer::removeTempFolder. remove file %s\n",fMovieTempFolderPath.toStdString().c_str());2271 #endif2272 fMovieTempFolderPath = path;2273 return true;2274 }2275 return false:2276 }2277 2278 /** Remove the Qt_temp folder in the temp folder2279 */2280 bool G4OpenGLQtViewer::removeTempFolder() {2281 // remove files in Qt_temp folder2282 QDir *d = new QDir(fTempFolderPath+fMovieTempFolderPath);2283 if (!d->exists(path)) {2284 return false; // already remove2285 }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_DEBUG2294 printf("G4OpenGLQtViewer::removeTempFolder. remove file %s\n",currentDir.toStdString().c_str());2295 #endif2296 }2297 if (d.rmdir(fTempFolderPath+fMovieTempFolderPath)) {2298 return true;2299 }2300 return false;2301 }2302 2184 2303 2185 /** Init the movie parameters. Temp dir and encoder path … … 2324 2206 setTempFolderPath(QDir::temp ().absolutePath ()); 2325 2207 } 2208 2209 /** @return encoder path or "" if it does not exist 2210 */ 2211 QString G4OpenGLQtViewer::getEncoderPath() { 2212 return fEncoderPath; 2213 } 2214 2215 2216 /** 2217 * set the new encoder path 2218 * @return "" if correct. The error otherwise 2219 */ 2220 QString 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 */ 2239 QString 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 */ 2270 QString G4OpenGLQtViewer::getTempFolderPath() { 2271 return fTempFolderPath; 2272 } 2273 2274 /** 2275 * set the save file name path 2276 * @return "" if correct. The error otherwise 2277 */ 2278 QString 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 */ 2309 QString G4OpenGLQtViewer::getSaveFileName() { 2310 return fSaveFileName ; 2311 } 2312 2313 /** Create a Qt_temp folder in the temp folder given 2314 */ 2315 bool 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 */ 2337 bool 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 2326 2363 2327 2364 -
trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc
r728 r739 34 34 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER 35 35 36 #define GEANT4_QT_DEBUG36 //#define GEANT4_QT_DEBUG 37 37 38 38 #include "G4OpenGLStoredQtViewer.hh" … … 200 200 201 201 if (fRecordFrames) { 202 save ForVideo(QString("/temp/Test")+QString::number(fRecordFrameNumber));202 savePPMToTemp(); 203 203 fRecordFrameNumber++; 204 204 #ifdef GEANT4_QT_DEBUG
Note: See TracChangeset
for help on using the changeset viewer.