35#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
60#include <qpushbutton.h>
62#include <qapplication.h>
63#include <qdesktopwidget.h>
66#include <qimagewriter.h>
69#include <qtreewidget.h>
70#include <qapplication.h>
71#include <qmessagebox.h>
72#include <qfiledialog.h>
78#include <qcolordialog.h>
84#include <qsignalmapper.h>
87void G4OpenGLQtViewer::CreateMainWindow (
100 G4Qt* interactorManager = G4Qt::getInstance ();
102 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
114 if (UI == NULL)
return;
123 bool isTabbedView =
false;
126 if (!interactorManager->IsExternalApp()) {
127 isTabbedView = fUiQt->AddTabWidget(fWindow,name,getWinWidth(),getWinHeight());
128 fUISceneTreeComponentsTBWidget = fUiQt->GetSceneTreeComponentsTBWidget();
133#ifdef G4DEBUG_VIS_OGL
135 printf(
"G4OpenGLQtViewer::CreateMainWindow :: UIQt NOt found \n");
141 QWidget *myParent = getParentWidget();
142#ifdef G4DEBUG_VIS_OGL
143 printf(
"G4OpenGLQtViewer::CreateMainWindow :: getParent OK \n");
145 if (myParent != NULL) {
146 glWidget->setParent(myParent);
148 QHBoxLayout *mainLayout =
new QHBoxLayout(fGLWindow);
150 mainLayout->setMargin(0);
151 mainLayout->setSpacing(0);
152 mainLayout->addWidget(fWindow);
153 if (fGLWindow->inherits(
"QMainWindow")) {
154 fGLWindow->setWindowTitle( name);
156 fGLWindow->setLayout(mainLayout);
160 int offset = QApplication::desktop()->height()
161 - QApplication::desktop()->availableGeometry().height();
163 G4int YPos= fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height());
164 if (fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height())< offset) {
167 fGLWindow->resize(getWinWidth(), getWinHeight());
168#ifdef G4DEBUG_VIS_OGL
169 printf(
"G4OpenGLQtViewer::CreateMainWindow :: resizing to %d %d \n",getWinWidth(), getWinHeight());
171 fGLWindow->move(fVP.GetWindowAbsoluteLocationHintX(QApplication::desktop()->width()),YPos);
175 fGLWindow->resize(getWinWidth(), getWinHeight());
187G4OpenGLQtViewer::G4OpenGLQtViewer (
188 G4OpenGLSceneHandler& scene
191 ,G4OpenGLViewer (scene)
193 ,fRecordFrameNumber(0)
197 ,fHoldKeyEvent(false)
198 ,fHoldMoveEvent(false)
199 ,fHoldRotateEvent(false)
203 ,fMovieTempFolderPath(
"")
205 ,fParameterFileName(
"ppmtompeg_encode_parameter_file.par")
206 ,fMovieParametersDialog(NULL)
207 ,fRecordingStep(WAIT)
209 ,fNbMaxFramesPerSec(100)
210 ,fNbMaxAnglePerSec(360)
211 ,fLaunchSpinDelay(100)
212 ,fUISceneTreeComponentsTBWidget(NULL)
215 ,fControlKeyPress(false)
216 ,fShiftKeyPress(false)
218 ,fCheckSceneTreeComponentSignalLock(false)
219 ,fSceneTreeComponentTreeWidget(NULL)
220 ,fOldSceneTreeComponentTreeWidget(NULL)
221 ,fSceneTreeWidget(NULL)
222 ,fPVRootNodeCreate(false)
226 ,fTouchableVolumes(
"Touchables")
227 ,fShortcutsDialog(NULL)
228 ,fSceneTreeDepthSlider(NULL)
230 ,fModelShortNameItem(NULL)
231 ,fMaxPOindexInserted(-1)
233 ,signalMapperMouse(NULL)
234 ,signalMapperSurface(NULL)
238 if (QCoreApplication::instance () == NULL) {
241 G4Qt::getInstance ();
243 fLastPos3 = QPoint(-1,-1);
244 fLastPos2 = QPoint(-1,-1);
245 fLastPos1 = QPoint(-1,-1);
247 initMovieParameters();
249 fLastEventTime =
new QTime();
250 signalMapperMouse =
new QSignalMapper(
this);
251 signalMapperSurface =
new QSignalMapper(
this);
253#ifdef G4DEBUG_VIS_OGL
254 printf(
"G4OpenGLQtViewer::G4OpenGLQtViewer END\n");
259G4OpenGLQtViewer::~G4OpenGLQtViewer (
267 if (fSceneTreeWidget != NULL) {
268 if (fSceneTreeWidget->layout() != NULL) {
269 while ((wItem = fSceneTreeWidget->layout()->takeAt(0)) != 0) {
270 delete wItem->widget();
274 if (fUISceneTreeComponentsTBWidget != NULL) {
275 fUISceneTreeComponentsTBWidget->removeTab(fUISceneTreeComponentsTBWidget->indexOf(fSceneTreeWidget));
278 G4cout <<removeTempFolder().toStdString().c_str() <<
G4endl;
285void G4OpenGLQtViewer::createPopupMenu() {
287 fContextMenu =
new QMenu(
"All");
289 QMenu *mMouseAction = fContextMenu->addMenu(
"&Mouse actions");
291 fMouseRotateAction = mMouseAction->addAction(
"Rotate", signalMapperMouse, SLOT(map()));
292 fMouseMoveAction = mMouseAction->addAction(
"Move", signalMapperMouse, SLOT(map()));
293 fMousePickAction = mMouseAction->addAction(
"Pick", signalMapperMouse, SLOT(map()));
294 fMouseZoomOutAction = mMouseAction->addAction(
"Zoom out", signalMapperMouse, SLOT(map()));
295 fMouseZoomInAction = mMouseAction->addAction(
"Zoom in", signalMapperMouse, SLOT(map()));
296 QAction *shortcutsAction = mMouseAction->addAction(
"Show shortcuts");
298 fMouseRotateAction->setCheckable(
true);
299 fMouseMoveAction->setCheckable(
true);
300 fMousePickAction->setCheckable(
true);
301 fMouseZoomOutAction->setCheckable(
true);
302 fMouseZoomInAction->setCheckable(
true);
303 shortcutsAction->setCheckable(
false);
305 connect(signalMapperMouse, SIGNAL(mapped(
int)),
this, SLOT(toggleMouseAction(
int)));
306 signalMapperMouse->setMapping(fMouseRotateAction,1);
307 signalMapperMouse->setMapping(fMouseMoveAction,2);
308 signalMapperMouse->setMapping(fMousePickAction,3);
309 signalMapperMouse->setMapping(fMouseZoomOutAction,4);
310 signalMapperMouse->setMapping(fMouseZoomInAction,5);
312 QObject::connect(shortcutsAction,
313 SIGNAL(triggered(
bool)),
315 SLOT(showShortcuts()));
318 QMenu *mStyle = fContextMenu->addMenu(
"&Style");
320 QMenu *mRepresentation = mStyle->addMenu(
"&Representation");
321 QMenu *mProjection = mStyle->addMenu(
"&Projection");
322 QAction *polyhedron = mRepresentation->addAction(
"Polyhedron");
323 QAction *nurbs = mRepresentation->addAction(
"NURBS");
325 fProjectionOrtho = mProjection->addAction(
"Orthographic", signalMapperSurface, SLOT(map()));
326 fProjectionPerspective = mProjection->addAction(
"Persepective", signalMapperSurface, SLOT(map()));
330 style = fVP.GetRepStyle();
332 createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(
bool)),1);
334 createRadioAction(polyhedron,nurbs,SLOT(toggleRepresentation(
bool)),2);
336 mRepresentation->clear();
340 if (fVP.GetFieldHalfAngle() == 0) {
341 createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(
bool)),1);
343 createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(
bool)),2);
347 QMenu *mDrawing = mStyle->addMenu(
"&Drawing");
349 fDrawingWireframe = mDrawing->addAction(
"Wireframe", signalMapperSurface, SLOT(map()));
351 fDrawingLineRemoval = mDrawing->addAction(
"Hidden line removal", signalMapperSurface, SLOT(map()));
353 fDrawingSurfaceRemoval = mDrawing->addAction(
"Hidden Surface removal", signalMapperSurface, SLOT(map()));
355 fDrawingLineSurfaceRemoval = mDrawing->addAction(
"Hidden line and surface removal", signalMapperSurface, SLOT(map()));
357 fDrawingWireframe->setCheckable(
true);
358 fDrawingLineRemoval->setCheckable(
true);
359 fDrawingSurfaceRemoval->setCheckable(
true);
360 fDrawingLineSurfaceRemoval->setCheckable(
true);
362 connect(signalMapperSurface, SIGNAL(mapped(
int)),
this, SLOT(toggleSurfaceAction(
int)));
363 signalMapperSurface->setMapping(fDrawingWireframe,1);
364 signalMapperSurface->setMapping(fDrawingLineRemoval,2);
365 signalMapperSurface->setMapping(fDrawingSurfaceRemoval,3);
366 signalMapperSurface->setMapping(fDrawingLineSurfaceRemoval,4);
371 QAction *backgroundColorChooser ;
373 backgroundColorChooser = mStyle->addAction(
"Background color");
374 QObject ::connect(backgroundColorChooser,
377 SLOT(actionChangeBackgroundColor()));
381 QAction *textColorChooser ;
383 textColorChooser = mStyle->addAction(
"Text color");
384 QObject ::connect(textColorChooser,
387 SLOT(actionChangeTextColor()));
391 QAction *defaultColorChooser ;
393 defaultColorChooser = mStyle->addAction(
"Default color");
394 QObject ::connect(defaultColorChooser,
397 SLOT(actionChangeDefaultColor()));
401 QMenu *mActions = fContextMenu->addMenu(
"&Actions");
402 QAction *createEPS = mActions->addAction(
"Save as ...");
403 QObject ::connect(createEPS,
406 SLOT(actionSaveImage()));
409 QAction *movieParameters = mActions->addAction(
"Movie parameters...");
410 QObject ::connect(movieParameters,
413 SLOT(actionMovieParameters()));
419 QMenu *mSpecial = fContextMenu->addMenu(
"S&pecial");
420 QMenu *mTransparency = mSpecial->addMenu(
"Transparency");
421 QAction *transparencyOn = mTransparency->addAction(
"On");
422 QAction *transparencyOff = mTransparency->addAction(
"Off");
424 if (transparency_enabled ==
false) {
425 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(
bool)),2);
426 }
else if (transparency_enabled ==
true) {
427 createRadioAction(transparencyOn,transparencyOff,SLOT(toggleTransparency(
bool)),1);
433 QMenu *mAntialiasing = mSpecial->addMenu(
"Antialiasing");
434 QAction *antialiasingOn = mAntialiasing->addAction(
"On");
435 QAction *antialiasingOff = mAntialiasing->addAction(
"Off");
437 if (antialiasing_enabled ==
false) {
438 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(
bool)),2);
439 }
else if (antialiasing_enabled ==
true) {
440 createRadioAction(antialiasingOn,antialiasingOff,SLOT(toggleAntialiasing(
bool)),1);
442 mAntialiasing->clear();
445 QMenu *mHaloing = mSpecial->addMenu(
"Haloing");
446 QAction *haloingOn = mHaloing->addAction(
"On");
447 QAction *haloingOff = mHaloing->addAction(
"Off");
448 if (haloing_enabled ==
false) {
449 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(
bool)),2);
450 }
else if (haloing_enabled ==
true) {
451 createRadioAction(haloingOn,haloingOff,SLOT(toggleHaloing(
bool)),1);
456 QMenu *mAux = mSpecial->addMenu(
"Auxiliary edges");
457 QAction *auxOn = mAux->addAction(
"On");
458 QAction *auxOff = mAux->addAction(
"Off");
459 if (!fVP.IsAuxEdgeVisible()) {
460 createRadioAction(auxOn,auxOff,SLOT(toggleAux(
bool)),2);
462 createRadioAction(auxOn,auxOff,SLOT(toggleAux(
bool)),1);
466 QMenu *mHiddenMarkers = mSpecial->addMenu(
"Hidden markers");
467 QAction *hiddenMarkersOn = mHiddenMarkers->addAction(
"On");
468 QAction *hiddenMarkersOff = mHiddenMarkers->addAction(
"Off");
469 if (fVP.IsMarkerNotHidden()) {
470 createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(
bool)),2);
472 createRadioAction(hiddenMarkersOn,hiddenMarkersOff,SLOT(toggleHiddenMarkers(
bool)),1);
477 QMenu *mFullScreen = mSpecial->addMenu(
"&Full screen");
478 fFullScreenOn = mFullScreen->addAction(
"On");
479 fFullScreenOff = mFullScreen->addAction(
"Off");
480 createRadioAction(fFullScreenOn,fFullScreenOff,SLOT(toggleFullScreen(
bool)),2);
483 updateToolbarAndMouseContextMenu();
487void G4OpenGLQtViewer::G4manageContextMenuEvent(QContextMenuEvent *e)
490 G4cerr <<
"Visualization window not defined, please choose one before" <<
G4endl;
497 if ( fContextMenu ) {
498 fContextMenu->exec( e->globalPos() );
514void G4OpenGLQtViewer::createRadioAction(QAction *action1,QAction *action2,
const std::string& method,
unsigned int nCheck) {
516 action1->setCheckable(
true);
517 action2->setCheckable(
true);
520 action1->setChecked (
true);
522 action2->setChecked (
true);
524 QObject ::connect(action1, SIGNAL(triggered(
bool)),action2, SLOT(toggle()));
525 QObject ::connect(action2, SIGNAL(triggered(
bool)),action1, SLOT(toggle()));
527 QObject ::connect(action1, SIGNAL(toggled(
bool)),
this, method.c_str());
536void G4OpenGLQtViewer::showShortcuts() {
539 text =
"========= Mouse Shortcuts =========\n";
541 if (fUiQt->IsIconRotateSelected()) {
542 text +=
"Click and move mouse to rotate volume \n";
543 text +=
"ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n";
544 text +=
"CTRL + Click and zoom mouse to zoom in/out \n";
545 text +=
"SHIFT + Click and zoommove camera point of view \n";
546 }
else if (fUiQt->IsIconMoveSelected()) {
547 text +=
"Move camera point of view with mouse \n";
548 }
else if (fUiQt->IsIconPickSelected()) {
549 text +=
"Click and pick \n";
552 text +=
"Click and move mouse to rotate volume \n";
553 text +=
"ALT + Click and move mouse to rotate volume (Toggle View/Theta-Phi Direction) \n";
554 text +=
"CTRL + Click and zoom mouse to zoom in/out \n";
555 text +=
"SHIFT + Click and zoommove camera point of view \n";
557 text +=
"========= Move Shortcuts ========= \n";
558 text +=
"Press left/right arrows to move volume left/right \n";
559 text +=
"Press up/down arrows to move volume up/down \n";
560 text +=
"Press '+'/'-' to move volume toward/forward \n";
562 text +=
"========= Rotation (Theta/Phi) Shortcuts ========= \n";
563 text +=
"Press SHIFT + left/right arrows to rotate volume left/right \n";
564 text +=
"Press SHIFT + up/down arrows to rotate volume up/down \n";
566 text +=
"========= Rotation (View Direction) Shortcuts ========= \n";
567 text +=
"Press ALT + left/right to rotate volume around vertical direction \n";
568 text +=
"Press ALT + up/down to rotate volume around horizontal direction \n";
570 text +=
"========= Zoom View ========= \n";
571 text +=
"Press CTRL + '+'/'-' to zoom into volume \n";
573 text +=
"========= Misc ========= \n";
574 text +=
"Press ALT +/- to slow/speed rotation/move \n";
575 text +=
"Press H to reset view \n";
576 text +=
"Press Esc to exit FullScreen \n";
578 text +=
"========= Video ========= \n";
579 text +=
"In video mode : \n";
580 text +=
" Press SPACE to Start/Pause video recording \n";
581 text +=
" Press RETURN to Stop video recording \n";
586 if ( fShortcutsDialog == NULL) {
587 fShortcutsDialog =
new QDialog();
588 fShortcutsDialogInfos =
new QTextEdit() ;
589 QVBoxLayout *mainLayout =
new QVBoxLayout;
590 mainLayout->addWidget(fShortcutsDialogInfos);
591 fShortcutsDialog->setLayout(mainLayout);
592 fShortcutsDialog->setWindowTitle(tr(
"Shortcuts"));
595 fShortcutsDialogInfos->setPlainText(text.data());
596 fShortcutsDialog->show();
607void G4OpenGLQtViewer::toggleMouseAction(
int aAction) {
610 fUiQt->SetIconRotateSelected();
611 }
else if (aAction == 2) {
612 fUiQt->SetIconMoveSelected();
613 }
else if (aAction == 3) {
614 fUiQt->SetIconPickSelected();
615 }
else if (aAction == 4) {
616 fUiQt->SetIconZoomOutSelected();
617 }
else if (aAction == 5) {
618 fUiQt->SetIconZoomInSelected();
621 updateToolbarAndMouseContextMenu();
635void G4OpenGLQtViewer::toggleSurfaceAction(
int aAction) {
642 }
else if (aAction ==2) {
645 }
else if (aAction ==3) {
648 }
else if (aAction ==4) {
651 fVP.SetDrawingStyle(d_style);
653 updateToolbarAndMouseContextMenu();
668void G4OpenGLQtViewer::toggleRepresentation(
bool check) {
676 fVP.SetRepStyle (style);
678 updateToolbarAndMouseContextMenu();
692void G4OpenGLQtViewer::toggleProjection(
bool check) {
695 fVP.SetOrthogonalProjection ();
697 fVP.SetPerspectiveProjection();
699 updateToolbarAndMouseContextMenu();
708void G4OpenGLQtViewer::toggleTransparency(
bool check) {
711 transparency_enabled =
true;
713 transparency_enabled =
false;
715 SetNeedKernelVisit (
true);
716 updateToolbarAndMouseContextMenu();
724void G4OpenGLQtViewer::toggleAntialiasing(
bool check) {
727 antialiasing_enabled =
false;
728 glDisable (GL_LINE_SMOOTH);
729 glDisable (GL_POLYGON_SMOOTH);
731 antialiasing_enabled =
true;
732 glEnable (GL_LINE_SMOOTH);
733 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
734 glEnable (GL_POLYGON_SMOOTH);
735 glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
738 updateToolbarAndMouseContextMenu();
747void G4OpenGLQtViewer::toggleHaloing(
bool check) {
749 haloing_enabled =
false;
751 haloing_enabled =
true;
754 updateToolbarAndMouseContextMenu();
763void G4OpenGLQtViewer::toggleAux(
bool check) {
765 fVP.SetAuxEdgeVisible(
true);
767 fVP.SetAuxEdgeVisible(
false);
769 SetNeedKernelVisit (
true);
770 updateToolbarAndMouseContextMenu();
778void G4OpenGLQtViewer::toggleHiddenMarkers(
bool check) {
780 fVP.SetMarkerHidden();
782 fVP.SetMarkerNotHidden();
785 updateToolbarAndMouseContextMenu();
792void G4OpenGLQtViewer::toggleFullScreen(
bool check) {
793 if (check != fGLWindow->isFullScreen()) {
794 fGLWindow->setWindowState(fGLWindow->windowState() ^ Qt::WindowFullScreen);
799void G4OpenGLQtViewer::savePPMToTemp() {
800 if (fMovieTempFolderPath ==
"") {
803 QString fileName =
"Test"+QString::number(fRecordFrameNumber)+
".ppm";
804 QString filePath =fMovieTempFolderPath+fileName;
807 image = fWindow->grabFrameBuffer();
810 res = image.save(filePath,0);
813 setRecordingInfos(
"Can't save tmp file "+filePath);
817 setRecordingInfos(
"File "+fileName+
" saved");
818 fRecordFrameNumber++;
823void G4OpenGLQtViewer::actionSaveImage() {
825 QList<QByteArray> formats = QImageWriter::supportedImageFormats ();
826 for (
int i = 0; i < formats.size(); ++i) {
827 filters +=formats.at(i) +
";;";
832 QString* selectedFormat =
new QString();
834 name = QFileDialog::getSaveFileName ( fGLWindow,
838 selectedFormat ).toStdString().c_str();
843 name +=
"." + selectedFormat->toStdString();
844 QString format = selectedFormat->toLower();
845 setPrintFilename(name.c_str(),0);
846 G4OpenGLQtExportDialog* exportDialog=
new G4OpenGLQtExportDialog(fGLWindow,format,fWindow->height(),fWindow->width());
847 if( exportDialog->exec()) {
851 if ((exportDialog->getWidth() !=fWindow->width()) ||
852 (exportDialog->getHeight() !=fWindow->height())) {
853 setPrintSize(exportDialog->getWidth(),exportDialog->getHeight());
854 if ((format != QString(
"eps")) && (format != QString(
"ps"))) {
855 G4cerr <<
"Export->Change Size : This function is not implemented, to export in another size, please resize your frame to what you need" <<
G4endl;
874 image = fWindow->grabFrameBuffer();
876 if (format == QString(
"eps")) {
877 fVectoredPs = exportDialog->getVectorEPS();
879 }
else if (format ==
"ps") {
882 }
else if (format ==
"pdf") {
884 res = printPDF(name,exportDialog->getNbColor(),image);
886 }
else if ((format ==
"tif") ||
887 (format ==
"tiff") ||
889 (format ==
"jpeg") ||
897 res = image.save(QString(name.c_str()),0,exportDialog->getSliderValue());
899 G4cerr <<
"This version of G4UI Could not generate the selected format" <<
G4endl;
901 if ((format == QString(
"eps")) && (format == QString(
"ps"))) {
903 G4cerr <<
"Error while saving file... "<<name.c_str()<<
G4endl;
905 G4cout <<
"File "<<name.c_str()<<
" has been saved " <<
G4endl;
916void G4OpenGLQtViewer::actionChangeBackgroundColor() {
924#if QT_VERSION < 0x040500
926 const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::black).rgba(),&a,fGLWindow));
929 QColorDialog::getColor(Qt::black,
931 " Get background color and transparency",
932 QColorDialog::ShowAlphaChannel);
934 if (color.isValid()) {
939 fVP.SetBackgroundColour(colour);
941 updateToolbarAndMouseContextMenu();
946void G4OpenGLQtViewer::actionChangeTextColor() {
948#if QT_VERSION < 0x040500
950 const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::yellow).rgba(),&a,fGLWindow));
952 const QColor& color =
953 QColorDialog::getColor(Qt::yellow,
955 " Get text color and transparency",
956 QColorDialog::ShowAlphaChannel);
958 if (color.isValid()) {
964 fVP.SetDefaultTextColour(colour);
966 updateToolbarAndMouseContextMenu();
971void G4OpenGLQtViewer::actionChangeDefaultColor() {
973#if QT_VERSION < 0x040500
975 const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::white).rgba(),&a,fGLWindow));
977 const QColor& color =
978 QColorDialog::getColor(Qt::white,
980 " Get default color and transparency",
981 QColorDialog::ShowAlphaChannel);
983 if (color.isValid()) {
989 fVP.SetDefaultColour(colour);
991 updateToolbarAndMouseContextMenu();
997void G4OpenGLQtViewer::actionMovieParameters() {
998 showMovieParametersDialog();
1002void G4OpenGLQtViewer::showMovieParametersDialog() {
1003 if (!fMovieParametersDialog) {
1004 fMovieParametersDialog=
new G4OpenGLQtMovieDialog(
this,fGLWindow);
1005 displayRecordingStatus();
1006 fMovieParametersDialog->checkEncoderSwParameters();
1007 fMovieParametersDialog->checkSaveFileNameParameters();
1008 fMovieParametersDialog->checkTempFolderParameters();
1009 if (getEncoderPath() ==
"") {
1010 setRecordingInfos(
"ppmtompeg is needed to encode in video format. It is available here: http://netpbm.sourceforge.net ");
1013 fMovieParametersDialog->show();
1035void G4OpenGLQtViewer::FinishView()
1047void G4OpenGLQtViewer::G4MousePressEvent(QMouseEvent *evnt)
1049 if ((evnt->buttons() & Qt::LeftButton) && (! (evnt->modifiers() & Qt::ControlModifier ))){
1050 fWindow->setMouseTracking(
true);
1052 fLastPos1 = evnt->pos();
1053 fLastPos2 = fLastPos1;
1054 fLastPos3 = fLastPos2;
1055 fLastEventTime->start();
1056 if (fUiQt != NULL) {
1058 if (fUiQt->IsIconPickSelected()){
1059 fVP.SetPicking(
true);
1060 Pick(evnt->pos().x(),evnt->pos().y());
1061 fVP.SetPicking(
false);
1063 }
else if (fUiQt->IsIconZoomInSelected()) {
1066 float deltaX = ((float)getWinWidth()/2-evnt->pos().x());
1067 float deltaY = ((float)getWinHeight()/2-evnt->pos().y());
1071 if (getWinHeight() <getWinWidth()) {
1074 fVP.IncrementPan(-deltaX*coefTrans,deltaY*coefTrans,0);
1075 fVP.SetZoomFactor(1.5 * fVP.GetZoomFactor());
1079 }
else if (fUiQt->IsIconZoomOutSelected()) {
1081 moveScene(((
float)getWinWidth()/2-evnt->pos().x()),((
float)getWinHeight()/2-evnt->pos().y()),0,
true);
1083 fVP.SetZoomFactor(0.75 * fVP.GetZoomFactor());
1093void G4OpenGLQtViewer::G4MouseReleaseEvent()
1095 fSpinningDelay = fLastEventTime->elapsed();
1096 QPoint delta = (fLastPos3-fLastPos1);
1097 if ((delta.x() == 0) && (delta.y() == 0)) {
1100 if (fSpinningDelay < fLaunchSpinDelay ) {
1103 lastMoveTime.start();
1105 float correctionFactor = 5;
1107 if ( lastMoveTime.elapsed() >= (int)(1000/fNbMaxFramesPerSec)) {
1108 float lTime = 1000/lastMoveTime.elapsed();
1109 if (((((
float)delta.x())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
1110 ((((float)delta.x())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
1111 correctionFactor = (float)delta.x()*(lTime/fNbMaxAnglePerSec);
1112 if (delta.x() <0 ) {
1113 correctionFactor = -correctionFactor;
1116 if (((((
float)delta.y())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
1117 ((((
float)delta.y())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
1118 correctionFactor = (float)delta.y()*(lTime/fNbMaxAnglePerSec);
1119 if (delta.y() <0 ) {
1120 correctionFactor = -correctionFactor;
1131 lastMoveTime.start();
1133 bool rotate =
false;
1136 if (fUiQt != NULL) {
1137 if (fUiQt->IsIconRotateSelected()) {
1139 }
else if (fUiQt->IsIconMoveSelected()) {
1147 rotateQtScene(((
float)delta.x())/correctionFactor,((
float)delta.y())/correctionFactor);
1148 }
else if (fAltKeyPress) {
1149 rotateQtSceneToggle(((
float)delta.x())/correctionFactor,((
float)delta.y())/correctionFactor);
1151#ifdef G4DEBUG_VIS_OGL
1153 fTimeRotation += lastMoveTime.elapsed();
1154 printf(
"G4OpenGLQtViewer %f \n",fTimeRotation/(
float)fNbRotation);
1158 moveScene(-((
float)delta.x())/correctionFactor,-((
float)delta.y())/correctionFactor,0,
true);
1161 ((QApplication*)G4Qt::getInstance ())->processEvents();
1164 fWindow->setMouseTracking(
false);
1169void G4OpenGLQtViewer::G4MouseDoubleClickEvent()
1171 fWindow->setMouseTracking(
true);
1182void G4OpenGLQtViewer::G4MouseMoveEvent(QMouseEvent *evnt)
1185 Qt::MouseButtons mButtons = evnt->buttons();
1187 updateKeyModifierState(evnt->modifiers());
1193 fLastPos3 = fLastPos2;
1194 fLastPos2 = fLastPos1;
1195 fLastPos1 = QPoint(evnt->x(), evnt->y());
1197 int deltaX = fLastPos2.x()-fLastPos1.x();
1198 int deltaY = fLastPos2.y()-fLastPos1.y();
1200 bool rotate =
false;
1202 if (fUiQt != NULL) {
1203 if (fUiQt->IsIconRotateSelected()) {
1205 }
else if (fUiQt->IsIconMoveSelected()) {
1212 if (mButtons & Qt::LeftButton) {
1214 rotateQtScene(((
float)deltaX),((
float)deltaY));
1215 }
else if (fAltKeyPress) {
1216 rotateQtSceneToggle(((
float)deltaX),((
float)deltaY));
1217 }
else if (fShiftKeyPress) {
1218 unsigned int sizeWin;
1219 sizeWin = getWinWidth();
1220 if (getWinHeight() < getWinWidth()) {
1221 sizeWin = getWinHeight();
1225 float factor = ((float)100/(
float)sizeWin) ;
1226 moveScene(-(
float)deltaX*factor,-(
float)deltaY*factor,0,
false);
1227 }
else if (fControlKeyPress) {
1228 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+((
float)deltaY)));
1232 if (mButtons & Qt::LeftButton) {
1233 moveScene(-(
float)deltaX,-(
float)deltaY,0,
true);
1237 fLastEventTime->start();
1248void G4OpenGLQtViewer::moveScene(
float dx,
float dy,
float dz,
bool mouseMove)
1252 fHoldMoveEvent =
true;
1255 GLdouble coefDepth = 0;
1258 if (getWinHeight() <getWinWidth()) {
1262 coefTrans = getSceneNearWidth()*fPan_sens;
1263 coefDepth = getSceneDepth()*fDeltaDepth;
1265 fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth);
1269 ((QApplication*)G4Qt::getInstance ())->processEvents();
1271 fHoldMoveEvent =
false;
1280void G4OpenGLQtViewer::rotateQtScene(
float dx,
float dy)
1282 if (fHoldRotateEvent)
1284 fHoldRotateEvent =
true;
1290 fHoldRotateEvent =
false;
1298void G4OpenGLQtViewer::rotateQtSceneToggle(
float dx,
float dy)
1300 if (fHoldRotateEvent)
1302 fHoldRotateEvent =
true;
1304 rotateSceneToggle(dx,dy);
1308 fHoldRotateEvent =
false;
1319void G4OpenGLQtViewer::rescaleImage(
1344bool G4OpenGLQtViewer::printPDF (
1345 const std::string aFilename
1357 if ((!aImage.isGrayscale ()) &&(aInColor ==1 )) {
1358 aImage = aImage.convertToFormat ( aImage.format(), Qt::MonoOnly);
1362 if (aFilename.substr(aFilename.size()-3) ==
".ps") {
1363#if QT_VERSION > 0x040200
1364 printer.setOutputFormat(QPrinter::PostScriptFormat);
1367#if QT_VERSION > 0x040100
1368 printer.setOutputFormat(QPrinter::PdfFormat);
1371#if QT_VERSION > 0x040100
1372 printer.setOutputFileName(QString(aFilename.c_str()));
1375 QPainter paint(&printer);
1376 paint.drawImage (0,0,aImage);
1382void G4OpenGLQtViewer::G4wheelEvent (QWheelEvent * evnt)
1384 fVP.SetZoomFactor(fVP.GetZoomFactor()+(fVP.GetZoomFactor()*(evnt->delta())/1200));
1389void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * evnt)
1394 fHoldKeyEvent =
true;
1398 updateKeyModifierState(evnt->modifiers());
1399 if ((fNoKeyPress) || (evnt->modifiers() == Qt::KeypadModifier )) {
1400 if (evnt->key() == Qt::Key_Down) {
1401 moveScene(0,1,0,
false);
1403 else if (evnt->key() == Qt::Key_Up) {
1404 moveScene(0,-1,0,
false);
1406 if (evnt->key() == Qt::Key_Left) {
1407 moveScene(-1,0,0,
false);
1409 else if (evnt->key() == Qt::Key_Right) {
1410 moveScene(1,0,0,
false);
1412 if (evnt->key() == Qt::Key_Minus) {
1413 moveScene(0,0,1,
false);
1415 else if (evnt->key() == Qt::Key_Plus) {
1416 moveScene(0,0,-1,
false);
1420 if (evnt->key() == Qt::Key_Escape) {
1421 toggleFullScreen(
false);
1430 if ((evnt->key() == Qt::Key_Return) || (evnt->key() == Qt::Key_Enter)){
1433 if (evnt->key() == Qt::Key_Space){
1438 if (evnt->key() == Qt::Key_H){
1445 if (fShiftKeyPress) {
1446 if (evnt->key() == Qt::Key_Down) {
1447 rotateQtScene(0,-fRot_sens);
1449 else if (evnt->key() == Qt::Key_Up) {
1450 rotateQtScene(0,fRot_sens);
1452 if (evnt->key() == Qt::Key_Left) {
1453 rotateQtScene(fRot_sens,0);
1455 else if (evnt->key() == Qt::Key_Right) {
1456 rotateQtScene(-fRot_sens,0);
1458 if (evnt->key() == Qt::Key_Plus) {
1460 moveScene(0,0,-1,
false);
1465 if ((fAltKeyPress)) {
1466 if (evnt->key() == Qt::Key_Down) {
1467 rotateQtSceneToggle(0,-fRot_sens);
1469 else if (evnt->key() == Qt::Key_Up) {
1470 rotateQtSceneToggle(0,fRot_sens);
1472 if (evnt->key() == Qt::Key_Left) {
1473 rotateQtSceneToggle(fRot_sens,0);
1475 else if (evnt->key() == Qt::Key_Right) {
1476 rotateQtSceneToggle(-fRot_sens,0);
1480 if (evnt->key() == Qt::Key_Plus) {
1481 fRot_sens = fRot_sens/0.7;
1482 G4cout <<
"Auto-rotation set to : " << fRot_sens <<
G4endl;
1484 else if (evnt->key() == Qt::Key_Minus) {
1485 fRot_sens = fRot_sens*0.7;
1486 G4cout <<
"Auto-rotation set to : " << fRot_sens <<
G4endl;
1491 if ((fControlKeyPress)) {
1492 if (evnt->key() == Qt::Key_Plus) {
1493 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom));
1496 else if (evnt->key() == Qt::Key_Minus) {
1497 fVP.SetZoomFactor(fVP.GetZoomFactor()*(1-fDeltaZoom));
1502 fHoldKeyEvent =
false;
1506void G4OpenGLQtViewer::updateKeyModifierState(
const Qt::KeyboardModifiers& modifier) {
1510 fAltKeyPress =
false;
1511 fShiftKeyPress =
false;
1512 fControlKeyPress =
false;
1514 if (modifier & Qt::AltModifier ) {
1515 fAltKeyPress =
true;
1516 fNoKeyPress =
false;
1518 if (modifier & Qt::ShiftModifier ) {
1519 fShiftKeyPress =
true;
1520 fNoKeyPress =
false;
1522 if (modifier & Qt::ControlModifier ) {
1523 fControlKeyPress =
true;
1524 fNoKeyPress =
false;
1531void G4OpenGLQtViewer::stopVideo() {
1534 if (!fMovieParametersDialog) {
1535 showMovieParametersDialog();
1537 setRecordingStatus(STOP);
1539 if (fRecordFrameNumber >0) {
1541 if (!(fMovieParametersDialog->checkEncoderSwParameters())) {
1542 setRecordingStatus(BAD_ENCODER);
1543 }
else if (!(fMovieParametersDialog->checkSaveFileNameParameters())) {
1544 setRecordingStatus(BAD_OUTPUT);
1548 setRecordingInfos(
"No frame to encode.");
1554void G4OpenGLQtViewer::saveVideo() {
1557 if (!fMovieParametersDialog) {
1558 showMovieParametersDialog();
1561 fMovieParametersDialog->checkEncoderSwParameters();
1562 fMovieParametersDialog->checkSaveFileNameParameters();
1564 if (fRecordingStep == STOP) {
1565 setRecordingStatus(SAVE);
1566 generateMpegEncoderParameters();
1574void G4OpenGLQtViewer::startPauseVideo() {
1578 if ( fRecordingStep == WAIT) {
1579 if ( fRecordFrameNumber == 0) {
1580 if (getTempFolderPath() ==
"") {
1581 showMovieParametersDialog();
1582 setRecordingInfos(
"You should specified the temp folder in order to make movie");
1586 QString tmp = removeTempFolder();
1588 setRecordingInfos(tmp);
1591 tmp = createTempFolder();
1593 setRecordingInfos(
"Can't create temp folder."+tmp);
1599 if (fRecordingStep == WAIT) {
1600 setRecordingStatus(
START);
1601 }
else if (fRecordingStep ==
START) {
1602 setRecordingStatus(PAUSE);
1603 }
else if (fRecordingStep == PAUSE) {
1604 setRecordingStatus(CONTINUE);
1605 }
else if (fRecordingStep == CONTINUE) {
1606 setRecordingStatus(PAUSE);
1610void G4OpenGLQtViewer::setRecordingStatus(RECORDING_STEP step) {
1612 fRecordingStep = step;
1613 displayRecordingStatus();
1617void G4OpenGLQtViewer::displayRecordingStatus() {
1619 QString txtStatus =
"";
1620 if (fRecordingStep == WAIT) {
1621 txtStatus =
"Waiting to start...";
1622 fRecordFrameNumber = 0;
1623 }
else if (fRecordingStep ==
START) {
1624 txtStatus =
"Start Recording...";
1625 }
else if (fRecordingStep == PAUSE) {
1626 txtStatus =
"Pause Recording...";
1627 }
else if (fRecordingStep == CONTINUE) {
1628 txtStatus =
"Continue Recording...";
1629 }
else if (fRecordingStep == STOP) {
1630 txtStatus =
"Stop Recording...";
1631 }
else if (fRecordingStep == READY_TO_ENCODE) {
1632 txtStatus =
"Ready to Encode...";
1633 }
else if (fRecordingStep ==
ENCODING) {
1634 txtStatus =
"Encoding...";
1635 }
else if (fRecordingStep == FAILED) {
1636 txtStatus =
"Failed to encode...";
1637 }
else if ((fRecordingStep == BAD_ENCODER)
1638 || (fRecordingStep == BAD_OUTPUT)
1639 || (fRecordingStep == BAD_TMP)) {
1640 txtStatus =
"Correct above errors first";
1641 }
else if (fRecordingStep == SUCCESS) {
1642 txtStatus =
"File encoded successfully";
1646 if (fMovieParametersDialog) {
1647 fMovieParametersDialog->setRecordingStatus(txtStatus);
1651 setRecordingInfos(
"");
1655void G4OpenGLQtViewer::setRecordingInfos(
const QString& txt) {
1656 if (fMovieParametersDialog) {
1657 fMovieParametersDialog->setRecordingInfos(txt);
1665void G4OpenGLQtViewer::initMovieParameters() {
1669 fProcess =
new QProcess();
1671 QObject ::connect(fProcess,SIGNAL(finished (
int)),
1672 this,SLOT(processLookForFinished()));
1673 fProcess->setReadChannelMode(QProcess::MergedChannels);
1674 fProcess->start (
"which ppmtompeg");
1680QString G4OpenGLQtViewer::getEncoderPath() {
1681 return fEncoderPath;
1689QString G4OpenGLQtViewer::setEncoderPath(QString path) {
1691 return "File does not exist";
1694 path = QDir::cleanPath(path);
1695 QFileInfo *f =
new QFileInfo(path);
1697 return "File does not exist";
1698 }
else if (f->isDir()) {
1699 return "This is a directory";
1700 }
else if (!f->isExecutable()) {
1701 return "File exist but is not executable";
1702 }
else if (!f->isFile()) {
1703 return "This is not a file";
1705 fEncoderPath = path;
1707 if (fRecordingStep == BAD_ENCODER) {
1708 setRecordingStatus(STOP);
1714bool G4OpenGLQtViewer::isRecording(){
1715 if ((fRecordingStep ==
START) || (fRecordingStep == CONTINUE)) {
1721bool G4OpenGLQtViewer::isPaused(){
1722 if (fRecordingStep == PAUSE) {
1728bool G4OpenGLQtViewer::isEncoding(){
1735bool G4OpenGLQtViewer::isWaiting(){
1736 if (fRecordingStep == WAIT) {
1742bool G4OpenGLQtViewer::isStopped(){
1743 if (fRecordingStep == STOP) {
1749bool G4OpenGLQtViewer::isFailed(){
1750 if (fRecordingStep == FAILED) {
1756bool G4OpenGLQtViewer::isSuccess(){
1757 if (fRecordingStep == SUCCESS) {
1763bool G4OpenGLQtViewer::isBadEncoder(){
1764 if (fRecordingStep == BAD_ENCODER) {
1769bool G4OpenGLQtViewer::isBadTmp(){
1770 if (fRecordingStep == BAD_TMP) {
1775bool G4OpenGLQtViewer::isBadOutput(){
1776 if (fRecordingStep == BAD_OUTPUT) {
1782void G4OpenGLQtViewer::setBadEncoder(){
1783 fRecordingStep = BAD_ENCODER;
1784 displayRecordingStatus();
1786void G4OpenGLQtViewer::setBadTmp(){
1787 fRecordingStep = BAD_TMP;
1788 displayRecordingStatus();
1790void G4OpenGLQtViewer::setBadOutput(){
1791 fRecordingStep = BAD_OUTPUT;
1792 displayRecordingStatus();
1795void G4OpenGLQtViewer::setWaiting(){
1796 fRecordingStep = WAIT;
1797 displayRecordingStatus();
1801bool G4OpenGLQtViewer::isReadyToEncode(){
1802 if (fRecordingStep == READY_TO_ENCODE) {
1808void G4OpenGLQtViewer::resetRecording() {
1809 setRecordingStatus(WAIT);
1816QString G4OpenGLQtViewer::setTempFolderPath(QString path) {
1819 return "Path does not exist";
1821 path = QDir::cleanPath(path);
1822 QFileInfo *d =
new QFileInfo(path);
1824 return "Path does not exist";
1825 }
else if (!d->isDir()) {
1826 return "This is not a directory";
1827 }
else if (!d->isReadable()) {
1828 return path +
" is read protected";
1829 }
else if (!d->isWritable()) {
1830 return path +
" is write protected";
1833 if (fRecordingStep == BAD_TMP) {
1834 setRecordingStatus(WAIT);
1836 fTempFolderPath = path;
1842QString G4OpenGLQtViewer::getTempFolderPath() {
1843 return fTempFolderPath;
1850QString G4OpenGLQtViewer::setSaveFileName(QString path) {
1853 return "Path does not exist";
1856 QFileInfo *file =
new QFileInfo(path);
1857 QDir dir = file->dir();
1858 path = QDir::cleanPath(path);
1859 if (file->exists()) {
1860 return "File already exist, please choose a new one";
1861 }
else if (!dir.exists()) {
1862 return "Dir does not exist";
1863 }
else if (!dir.isReadable()) {
1864 return path +
" is read protected";
1867 if (fRecordingStep == BAD_OUTPUT) {
1868 setRecordingStatus(STOP);
1870 fSaveFileName = path;
1876QString G4OpenGLQtViewer::getSaveFileName() {
1877 return fSaveFileName ;
1884QString G4OpenGLQtViewer::createTempFolder() {
1885 fMovieTempFolderPath =
"";
1887 QString tmp = setTempFolderPath(fTempFolderPath);
1891 QString sep = QString(QDir::separator());
1892 QString path = sep+
"QtMovie_"+QDateTime::currentDateTime ().toString(
"dd-MM-yyyy_hh-mm-ss")+sep;
1893 QDir *d =
new QDir(QDir::cleanPath(fTempFolderPath));
1895 if (d->exists(path)) {
1896 return "Folder "+path+
" already exists.Please remove it first";
1898 if (d->mkdir(fTempFolderPath+path)) {
1899 fMovieTempFolderPath = fTempFolderPath+path;
1902 return "Can't create "+fTempFolderPath+path;
1907QString G4OpenGLQtViewer::removeTempFolder() {
1909 if (fMovieTempFolderPath ==
"") {
1912 QDir *d =
new QDir(QDir::cleanPath(fMovieTempFolderPath));
1917 d->setFilter( QDir::Files );
1918 QStringList subDirList = d->entryList();
1921 for (QStringList::ConstIterator it = subDirList.begin() ;(it != subDirList.end()) ; it++) {
1922 const QString currentFile = *it;
1923 if (!d->remove(currentFile)) {
1925 QString file = fMovieTempFolderPath+currentFile;
1926 error +=
"Removing file failed : "+file;
1931 if (d->rmdir(fMovieTempFolderPath)) {
1932 fMovieTempFolderPath =
"";
1935 return "Dir "+fMovieTempFolderPath+
" should be empty, but could not remove it";
1939 return "Could not remove "+fMovieTempFolderPath+
" because of the following errors :"+error;
1944bool G4OpenGLQtViewer::hasPendingEvents () {
1945 return ((QApplication*)G4Qt::getInstance ())->hasPendingEvents ();
1948bool G4OpenGLQtViewer::generateMpegEncoderParameters () {
1952 fp = fopen (QString(fMovieTempFolderPath+fParameterFileName).toStdString().c_str(),
"w");
1955 setRecordingInfos(
"Generation of parameter file failed");
1959 fprintf (fp,
"# Pattern affects speed, quality and compression. See the User's Guide\n");
1960 fprintf (fp,
"# for more info.\n");
1962 fprintf (fp,
"PATTERN IBBPBBPBBPBBPBBP\n");
1963 fprintf (fp,
"OUTPUT %s\n",getSaveFileName().toStdString().c_str());
1965 fprintf (fp,
"# You must specify the type of the input files. The choices are:\n");
1966 fprintf (fp,
"# YUV, PPM, JMOVIE, Y, JPEG, PNM\n");
1967 fprintf (fp,
"# (must be upper case)\n");
1969 fprintf (fp,
"BASE_FILE_FORMAT PPM\n");
1972 fprintf (fp,
"# if YUV format (or using parallel version), must provide width and height\n");
1973 fprintf (fp,
"# YUV_SIZE widthxheight\n");
1974 fprintf (fp,
"# this option is ignored if BASE_FILE_FORMAT is not YUV and you're running\n");
1975 fprintf (fp,
"# on just one machine\n");
1977 fprintf (fp,
"YUV_SIZE 352x240\n");
1979 fprintf (fp,
"# If you are using YUV, there are different supported file formats.\n");
1980 fprintf (fp,
"# EYUV or UCB are the same as previous versions of this encoder.\n");
1981 fprintf (fp,
"# (All the Y's, then U's then V's, in 4:2:0 subsampling.)\n");
1982 fprintf (fp,
"# Other formats, such as Abekas, Phillips, or a general format are\n");
1983 fprintf (fp,
"# permissible, the general format is a string of Y's, U's, and V's\n");
1984 fprintf (fp,
"# to specify the file order.\n");
1986 fprintf (fp,
"INPUT_FORMAT UCB\n");
1988 fprintf (fp,
"# the conversion statement\n");
1990 fprintf (fp,
"# Each occurrence of '*' will be replaced by the input file\n");
1992 fprintf (fp,
"# e.g., if you have a bunch of GIF files, then this might be:\n");
1993 fprintf (fp,
"# INPUT_CONVERT giftoppm *\n");
1995 fprintf (fp,
"# e.g., if you have a bunch of files like a.Y a.U a.V, etc., then:\n");
1996 fprintf (fp,
"# INPUT_CONVERT cat *.Y *.U *.V\n");
1998 fprintf (fp,
"# e.g., if you are grabbing from laser disc you might have something like\n");
1999 fprintf (fp,
"# INPUT_CONVERT goto frame *; grabppm\n");
2000 fprintf (fp,
"# 'INPUT_CONVERT *' means the files are already in the base file format\n");
2002 fprintf (fp,
"INPUT_CONVERT * \n");
2004 fprintf (fp,
"# number of frames in a GOP.\n");
2006 fprintf (fp,
"# since each GOP must have at least one I-frame, the encoder will find the\n");
2007 fprintf (fp,
"# the first I-frame after GOP_SIZE frames to start the next GOP\n");
2009 fprintf (fp,
"# later, will add more flexible GOP signalling\n");
2011 fprintf (fp,
"GOP_SIZE 16\n");
2013 fprintf (fp,
"# number of slices in a frame\n");
2015 fprintf (fp,
"# 1 is a good number. another possibility is the number of macroblock rows\n");
2016 fprintf (fp,
"# (which is the height divided by 16)\n");
2018 fprintf (fp,
"SLICES_PER_FRAME 1\n");
2020 fprintf (fp,
"# directory to get all input files from (makes this file easier to read)\n");
2021 fprintf (fp,
"INPUT_DIR %s\n",fMovieTempFolderPath.toStdString().c_str());
2023 fprintf (fp,
"# There are a bunch of ways to specify the input files.\n");
2024 fprintf (fp,
"# from a simple one-per-line listing, to the following \n");
2025 fprintf (fp,
"# way of numbering them. See the manual for more information.\n");
2026 fprintf (fp,
"INPUT\n");
2027 fprintf (fp,
"# '*' is replaced by the numbers 01, 02, 03, 04\n");
2028 fprintf (fp,
"# if I instead do [01-11], it would be 01, 02, ..., 09, 10, 11\n");
2029 fprintf (fp,
"# if I instead do [1-11], it would be 1, 2, 3, ..., 9, 10, 11\n");
2030 fprintf (fp,
"# if I instead do [1-11+3], it would be 1, 4, 7, 10\n");
2031 fprintf (fp,
"# the program assumes none of your input files has a name ending in ']'\n");
2032 fprintf (fp,
"# if you do, too bad!!!\n");
2035 fprintf (fp,
"Test*.ppm [0-%d]\n",fRecordFrameNumber-1);
2036 fprintf (fp,
"# can have more files here if you want...there is no limit on the number\n");
2037 fprintf (fp,
"# of files\n");
2038 fprintf (fp,
"END_INPUT\n");
2042 fprintf (fp,
"# Many of the remaining options have to do with the motion search and qscale\n");
2044 fprintf (fp,
"# FULL or HALF -- must be upper case\n");
2045 fprintf (fp,
"# Should be FULL for computer generated images\n");
2046 fprintf (fp,
"PIXEL FULL\n");
2048 fprintf (fp,
"# means +/- this many pixels for both P and B frame searches\n");
2049 fprintf (fp,
"# specify two numbers if you wish to serc different ranges in the two.\n");
2050 fprintf (fp,
"RANGE 10\n");
2052 fprintf (fp,
"# The two search algorithm parameters below mostly affect speed,\n");
2053 fprintf (fp,
"# with some affect on compression and almost none on quality.\n");
2055 fprintf (fp,
"# this must be one of {EXHAUSTIVE, SUBSAMPLE, LOGARITHMIC}\n");
2056 fprintf (fp,
"PSEARCH_ALG LOGARITHMIC\n");
2058 fprintf (fp,
"# this must be one of {SIMPLE, CROSS2, EXHAUSTIVE}\n");
2060 fprintf (fp,
"# note that EXHAUSTIVE is really, really, really slow\n");
2062 fprintf (fp,
"BSEARCH_ALG SIMPLE\n");
2065 fprintf (fp,
"# these specify the q-scale for I, P, and B frames\n");
2066 fprintf (fp,
"# (values must be between 1 and 31)\n");
2067 fprintf (fp,
"# These are the Qscale values for the entire frame in variable bit-rate\n");
2068 fprintf (fp,
"# mode, and starting points (but not important) for constant bit rate\n");
2071 fprintf (fp,
"# Qscale (Quantization scale) affects quality and compression,\n");
2072 fprintf (fp,
"# but has very little effect on speed.\n");
2074 fprintf (fp,
"IQSCALE 4\n");
2075 fprintf (fp,
"PQSCALE 5\n");
2076 fprintf (fp,
"BQSCALE 12\n");
2078 fprintf (fp,
"# this must be ORIGINAL or DECODED\n");
2079 fprintf (fp,
"REFERENCE_FRAME ORIGINAL\n");
2081 fprintf (fp,
"# for parallel parameters see parallel.param in the exmaples subdirectory\n");
2083 fprintf (fp,
"# if you want constant bit-rate mode, specify it as follows (number is bits/sec):\n");
2084 fprintf (fp,
"#BIT_RATE 1000000\n");
2086 fprintf (fp,
"# To specify the buffer size (327680 is default, measused in bits, for 16bit words)\n");
2087 fprintf (fp,
"BUFFER_SIZE 327680\n");
2089 fprintf (fp,
"# The frame rate is the number of frames/second (legal values:\n");
2090 fprintf (fp,
"# 23.976, 24, 25, 29.97, 30, 50 ,59.94, 60\n");
2091 fprintf (fp,
"FRAME_RATE 30\n");
2093 fprintf (fp,
"# There are many more options, see the users manual for examples....\n");
2094 fprintf (fp,
"# ASPECT_RATIO, USER_DATA, GAMMA, IQTABLE, etc.\n");
2099 setRecordingInfos(
"Parameter file "+fParameterFileName+
" generated in "+fMovieTempFolderPath);
2100 setRecordingStatus(READY_TO_ENCODE);
2104void G4OpenGLQtViewer::encodeVideo()
2106 if ((getEncoderPath() !=
"") && (getSaveFileName() !=
"")) {
2109 fProcess =
new QProcess();
2110#if QT_VERSION > 0x040100
2111 QObject ::connect(fProcess,SIGNAL(finished (
int,QProcess::ExitStatus)),
2112 this,SLOT(processEncodeFinished()));
2113 QObject ::connect(fProcess,SIGNAL(readyReadStandardOutput ()),
2114 this,SLOT(processEncodeStdout()));
2116 QObject ::connect(fProcess,SIGNAL(finished (
int)),
2117 this,SLOT(processEncodeFinished()));
2118 QObject ::connect(fProcess,SIGNAL(readyReadStandardOutput ()),
2119 this,SLOT(processEncodeStdout()));
2121 fProcess->setReadChannelMode(QProcess::MergedChannels);
2122 fProcess->start (fEncoderPath, QStringList(fMovieTempFolderPath+fParameterFileName));
2128void G4OpenGLQtViewer::processEncodeStdout()
2130 QString tmp = fProcess->readAllStandardOutput ().data();
2131 int start = tmp.lastIndexOf(
"ESTIMATED TIME");
2132 tmp = tmp.mid(start,tmp.indexOf(
"\n",start)-start);
2133 setRecordingInfos(tmp);
2137void G4OpenGLQtViewer::processEncodeFinished()
2141 txt = getProcessErrorMsg();
2143 setRecordingStatus(SUCCESS);
2145 setRecordingStatus(FAILED);
2151void G4OpenGLQtViewer::processLookForFinished()
2154 QString txt = getProcessErrorMsg();
2158 fEncoderPath = QString(fProcess->readAllStandardOutput ().data()).trimmed();
2160 if (fEncoderPath.contains(
" ")) {
2162 }
else if (!fEncoderPath.contains(
"ppmtompeg")) {
2165 setEncoderPath(fEncoderPath);
2168 setTempFolderPath(QDir::temp ().absolutePath ());
2172QString G4OpenGLQtViewer::getProcessErrorMsg()
2175 if (fProcess->exitCode() != 0) {
2176 switch (fProcess->error()) {
2177 case QProcess::FailedToStart:
2178 txt =
"The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.\n";
2180 case QProcess::Crashed:
2181 txt =
"The process crashed some time after starting successfully.\n";
2183 case QProcess::Timedout:
2184 txt =
"The last waitFor...() function timed out. The state of QProcess is unchanged, and you can try calling waitFor...() again.\n";
2186 case QProcess::WriteError:
2187 txt =
"An error occurred when attempting to write to the process. For example, the process may not be running, or it may have closed its input channel.\n";
2189 case QProcess::ReadError:
2190 txt =
"An error occurred when attempting to read from the process. For example, the process may not be running.\n";
2192 case QProcess::UnknownError:
2193 txt =
"An unknown error occurred. This is the default return value of error().\n";
2203QWidget *G4OpenGLQtViewer::getParentWidget()
2206 G4Qt* interactorManager = G4Qt::getInstance ();
2213 if (((QApplication*)interactorManager->GetMainInteractor())) {
2215 QWidgetList wl = QApplication::allWidgets();
2216 QWidget *widget = NULL;
2217 for (
int i=0; i < wl.size(); i++) {
2219 if ((found==
false) && (widget->inherits(
"QMainWindow"))) {
2220 fGLWindow =
new QDialog(widget,Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint);
2226#ifdef G4DEBUG_VIS_OGL
2227 printf(
"G4OpenGLQtViewer::CreateMainWindow case Qapp exist, but not found\n");
2229 fGLWindow =
new QDialog();
2232#ifdef G4DEBUG_VIS_OGL
2233 printf(
"G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
2235 fGLWindow =
new QDialog();
2236#ifdef G4DEBUG_VIS_OGL
2237 printf(
"G4OpenGLQtViewer::GetParentWidget fGLWindow\n");
2248void G4OpenGLQtViewer::initSceneTreeComponent(){
2250 fSceneTreeWidget =
new QWidget();
2251 fSceneTreeWidget->setLayout (
new QVBoxLayout());
2253 if (fUISceneTreeComponentsTBWidget != NULL) {
2254 fUISceneTreeComponentsTBWidget->addTab(fSceneTreeWidget,QString(GetName().data()));
2257 QLayout* layoutSceneTreeComponentsTBWidget = fSceneTreeWidget->layout();
2260 fSceneTreeComponentTreeWidget =
new QTreeWidget();
2261 fSceneTreeComponentTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
2262 fSceneTreeComponentTreeWidget->setHeaderLabel (
"Scene tree : "+QString(GetName().data()));
2263 fSceneTreeComponentTreeWidget->setColumnHidden (1,
true);
2264 fSceneTreeComponentTreeWidget->setColumnHidden (2,
true);
2265 fSceneTreeComponentTreeWidget->setColumnHidden (3,
true);
2270 layoutSceneTreeComponentsTBWidget->addWidget(fSceneTreeComponentTreeWidget);
2272 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemChanged(QTreeWidgetItem*,
int)),SLOT(sceneTreeComponentItemChanged(QTreeWidgetItem*,
int)));
2273 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemSelectionChanged ()),SLOT(sceneTreeComponentSelected()));
2274 connect(fSceneTreeComponentTreeWidget,SIGNAL(itemDoubleClicked ( QTreeWidgetItem*,
int)),SLOT(changeColorAndTransparency( QTreeWidgetItem*,
int)));
2278 QLabel *depth =
new QLabel();
2279 depth->setText(
"Depth :");
2281 QWidget* depthWidget =
new QWidget();
2282 QGroupBox *groupBox =
new QGroupBox(tr(
"Touchables slider"),depthWidget);
2283 QHBoxLayout *groupBoxLayout =
new QHBoxLayout(groupBox);
2285 QLabel *zero =
new QLabel();
2286 zero->setText(
"Show all");
2287 QLabel *one =
new QLabel();
2288 one->setText(
"Hide all");
2289 fSceneTreeDepthSlider =
new QSlider ( Qt::Horizontal, groupBox);
2290 fSceneTreeDepthSlider->setMaximum (1000);
2291 fSceneTreeDepthSlider->setMinimum (0);
2292 fSceneTreeDepthSlider->setTickPosition(QSlider::TicksAbove);
2293 groupBoxLayout->addWidget(zero);
2294 groupBoxLayout->addWidget(fSceneTreeDepthSlider);
2295 groupBoxLayout->addWidget(one);
2297 groupBox->setLayout(groupBoxLayout);
2298 layoutSceneTreeComponentsTBWidget->addWidget(groupBox);
2300 connect( fSceneTreeDepthSlider, SIGNAL( valueChanged(
int) ),
this, SLOT( changeDepthInSceneTree(
int) ) );
2303 QWidget *helpWidget =
new QWidget();
2304 QHBoxLayout *helpLayout =
new QHBoxLayout();
2305 QPushButton* select =
new QPushButton(
"select item(s)");
2306 fHelpLine =
new QLineEdit();
2307 helpLayout->addWidget(
new QLabel(
"Search :",helpWidget));
2308 helpLayout->addWidget(fHelpLine);
2309 helpLayout->addWidget(select);
2310 helpWidget->setLayout(helpLayout);
2311 layoutSceneTreeComponentsTBWidget->addWidget(helpWidget);
2313 connect( fHelpLine, SIGNAL( returnPressed () ),
this, SLOT(changeSearchSelection()));
2314 connect( select, SIGNAL( clicked () ),
this, SLOT(changeSearchSelection()));
2317 fTreeItemModels.clear();
2319 fPVRootNodeCreate =
false;
2321 fMaxPOindexInserted = -1;
2327void G4OpenGLQtViewer::setCheckComponent(QTreeWidgetItem* item,
bool check)
2331 item->setCheckState(0,Qt::Checked);
2333 item->setCheckState(0,Qt::Unchecked);
2335 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
2336 int nChildCount = item->childCount();
2337 for (
int i = 0; i < nChildCount; i++) {
2338 setCheckComponent(item->child(i),check);
2344void G4OpenGLQtViewer::DrawText(
const G4Text& g4text)
2346 if (isGl2psWriting()) {
2348 G4OpenGLViewer::DrawText(g4text);
2352 if (!fWindow)
return;
2355 G4double size = fSceneHandler.GetMarkerSize(g4text,sizeType);
2357 QFont font = QFont();
2358 font.setPointSizeF(size);
2363 const char* textCString = textString.c_str();
2366 QFontMetrics* f =
new QFontMetrics (font);
2367 G4double span = f->width(textCString);
2380 ((
position.x()+(2*xmove)/getWinWidth()),
2381 (
position.y()+(2*ymove)/getWinHeight()),
2390void G4OpenGLQtViewer::ResetView () {
2391 G4OpenGLViewer::ResetView();
2401 const QString& modelShortName = getModelShortName(model);
2403 if (modelShortName ==
"") {
2407 if (fSceneTreeComponentTreeWidget == NULL) {
2408 initSceneTreeComponent();
2412 if (fSceneTreeComponentTreeWidget == NULL) {
2416 fSceneTreeComponentTreeWidget->blockSignals(
true);
2420 if (!fPVRootNodeCreate) {
2421 const G4VisAttributes* visAttr = GetApplicableVisAttributes(pPVModel->
GetFullPVPath().at(0).GetPhysicalVolume()->GetLogicalVolume()->GetVisAttributes());
2424 fModelShortNameItem = createTreeWidgetItem(pPVModel->
GetFullPVPath(),
2432 fPVRootNodeCreate =
true;
2435 bool added = parseAndInsertInSceneTree(fModelShortNameItem,pPVModel,0,modelShortName,0,currentPOIndex);
2439 fSceneTreeComponentTreeWidget->blockSignals(
false);
2448QTreeWidgetItem* G4OpenGLQtViewer::createTreeWidgetItem(
2449 const PVPath& fullPath
2450 ,
const QString& name
2453 ,
const QString& logicalName
2454 ,Qt::CheckState state
2455 ,QTreeWidgetItem * parentTreeNode
2460 if (fullPath.size() > fSceneTreeDepth) {
2461 fSceneTreeDepth = fullPath.size();
2463 if (fSceneTreeDepthSlider) {
2464 fSceneTreeDepthSlider->setTickInterval(1000/(fSceneTreeDepth+1));
2467 QTreeWidgetItem * newItem = NULL;
2468 if (parentTreeNode == NULL) {
2469 newItem =
new QTreeWidgetItem(fSceneTreeComponentTreeWidget);
2471 newItem =
new QTreeWidgetItem(parentTreeNode);
2475 newItem->setText(0,name);
2476 newItem->setData(1,Qt::UserRole,copyNb);
2477 newItem->setText(2,QString::number(POIndex));
2478 newItem->setData(0, Qt::UserRole, POIndex);
2479 newItem->setText(3,logicalName);
2480 newItem->setFlags(newItem->flags()|Qt::ItemIsUserCheckable);
2481 newItem->setCheckState(0,state);
2482 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,newItem);
2484 changeQColorForTreeWidgetItem(newItem,QColor((
int)(color.
GetRed()*255),
2490 if ((state == Qt::Unchecked) && (POIndex == -1)) {
2491 newItem->setForeground (0, QBrush( Qt::gray) );
2494 newItem->setToolTip (0,QString(
2495 "This node exists in the geometry but has not been\n")+
2496 "drawn, perhaps because it has been set invisible. It \n"+
2497 "cannot be made visible with a click on the button.\n"+
2498 "To see it, change the visibility, for example, with \n"+
2499 "/vis/geometry/set/visibility " + logicalName +
" 0 true\n"+
2500 "and rebuild the view with /vis/viewer/rebuild.\n"+
2501 "Click here will only show/hide all child components");
2507 state = Qt::Unchecked;
2508 newItem->setCheckState(0,state);
2509 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,newItem);
2512 fTreeItemModels.insert(std::pair <int, PVPath > (POIndex,fullPath) );
2516 changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(newItem);
2533bool G4OpenGLQtViewer::parseAndInsertInSceneTree(
2534 QTreeWidgetItem * parentItem
2536 ,
unsigned int fullPathIndex
2537 ,
const QString& parentRoot
2538 ,
unsigned int currentIndexInTreeSceneHandler
2539 ,
int currentPVPOIndex
2542 if (parentItem == NULL) {
2548 std::ostringstream oss;
2549 oss << fullPath.at(fullPathIndex).GetCopyNo();
2550 std::string currentPVName =
G4String(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetName()+
" ["+oss.str()+
"]").
data();
2552 int currentPVCopyNb = fullPath.at(fullPathIndex).GetCopyNo();
2554 const G4VisAttributes* visAttr = GetApplicableVisAttributes(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetVisAttributes());
2563 QTreeWidgetItem* subItem = NULL;
2564 QList<QTreeWidgetItem *> parentItemList;
2572 if ((currentIndexInTreeSceneHandler == (fullPath.size()-1)) && ((color.
GetAlpha() == 1.))) {
2574 QString lookForString = QString(currentPVName.c_str());
2575 for (
int i = 0;i < parentItem->childCount(); i++ ) {
2576 if (parentItem->child(i)->text(0) == lookForString) {
2577 parentItemList.push_back(parentItem->child(i));
2582 for (
int i = 0; i < parentItemList.size(); ++i) {
2583 const std::string& parentItemName = parentItemList.at(i)->text(0).toStdString();
2584 int parentItemCopyNb = parentItemList.at(i)->data(1,Qt::UserRole).toInt();
2585 int parentItemPOIndex = parentItemList.at(i)->data(0,Qt::UserRole).toInt();
2593 if (((parentRoot == fTouchableVolumes) && (currentPVCopyNb == parentItemCopyNb)
2594 && (currentPVName == parentItemName)) ||
2596 ((parentRoot != fTouchableVolumes) && (currentPVCopyNb == parentItemCopyNb)
2598 && (currentPVName == parentItemName) && (currentPVPOIndex == parentItemPOIndex) )) {
2601 bool sameTransform =
true;
2602 if (parentItemPOIndex >= 0) {
2603 const PVPath& fullPathTmp = fTreeItemModels[parentItemPOIndex];
2604 if (fullPathTmp.size() > 0) {
2605 if (fullPathTmp.at(fullPathTmp.size()-1).GetTransform () == pPVModel->
GetTransformation ()) {
2606 sameTransform =
true;
2608 sameTransform =
false;
2614 if (sameTransform ==
true) {
2621 if (currentIndexInTreeSceneHandler == (fullPath.size()-1)) {
2623 parentItemList.at(i)->setText(2,QString::number(currentPVPOIndex));
2624 parentItemList.at(i)->setData(0, Qt::UserRole,currentPVPOIndex);
2626 fTreeItemModels.insert(std::pair <int, PVPath >(currentPVPOIndex,fullPath) );
2630 parentItemList.at(i)->setFont (0,f);
2633 parentItemList.at(i)->setForeground (0,QBrush());
2636 parentItemList.at(i)->setToolTip (0,
"");
2638 changeQColorForTreeWidgetItem(parentItemList.at(i),QColor((
int)(color.
GetRed()*255),
2645 parentItemList.at(i)->setCheckState(0,Qt::Checked);
2646 updatePositivePoIndexSceneTreeWidgetQuickMap(currentPVPOIndex,parentItemList.at(i));
2650 subItem = parentItemList.at(i);
2654 }
else if (currentIndexInTreeSceneHandler < (fullPath.size()-1)) {
2655 subItem = parentItemList.at(i);
2662 if (currentIndexInTreeSceneHandler == (fullPath.size()-1)) {
2663 createTreeWidgetItem(fullPath,
2664 QString(currentPVName.c_str()),
2667 QString(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetName().data()),
2672 if (currentPVPOIndex > fMaxPOindexInserted) {
2673 fMaxPOindexInserted = currentPVPOIndex;
2679 if (subItem == NULL) {
2681 if (currentIndexInTreeSceneHandler < (fullPath.size()-1)) {
2682 subItem = createTreeWidgetItem(fullPath,
2683 QString(currentPVName.c_str()),
2686 QString(fullPath.at(fullPathIndex).GetPhysicalVolume()->GetLogicalVolume()->GetName().data()),
2693 return parseAndInsertInSceneTree(subItem,pPVModel,fullPathIndex+1,parentRoot,currentIndexInTreeSceneHandler+1,currentPVPOIndex);
2699void G4OpenGLQtViewer::changeOpenCloseVisibleHiddenSelectedColorSceneTreeElement(
2700 QTreeWidgetItem* subItem
2704 QTreeWidgetItem* oldItem = NULL;
2706 QTreeWidgetItem* foundItem = getOldTreeWidgetItem(subItem->data(0,Qt::UserRole).toInt());
2708 if (foundItem != NULL) {
2709 if (isSameSceneTreeElement(foundItem,subItem)) {
2710 oldItem = foundItem;
2713 if (foundItem == NULL) {
2716 std::map <int, QTreeWidgetItem*>::const_iterator i;
2717 i = fOldPositivePoIndexSceneTreeWidgetQuickMap.begin();
2718 while (i != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
2719 if (isSameSceneTreeElement(i->second,subItem)) {
2720 oldItem = i->second;
2721 i = fOldPositivePoIndexSceneTreeWidgetQuickMap.end();
2727 if (oldItem == NULL) {
2729 while (a < fOldNullPoIndexSceneTreeWidgetQuickVector.size()) {
2730 if (isSameSceneTreeElement(fOldNullPoIndexSceneTreeWidgetQuickVector[a],subItem)) {
2731 oldItem = fOldNullPoIndexSceneTreeWidgetQuickVector[a];
2732 a = fOldNullPoIndexSceneTreeWidgetQuickVector.size();
2741 if (oldItem != NULL) {
2742 subItem->setFlags(oldItem->flags());
2743 subItem->setCheckState(0,oldItem->checkState(0));
2744 subItem->setSelected(oldItem->isSelected());
2745 subItem->setExpanded(oldItem->isExpanded ());
2750 std::map <int, QTreeWidgetItem* >::iterator it;
2753 int oldPOIndex = oldItem->data(0,Qt::UserRole).toInt();
2754 it = fOldPositivePoIndexSceneTreeWidgetQuickMap.find(oldPOIndex);
2758 std::map <int, QColor >::iterator itVis;
2759 itVis = fOldVisAttrColorMap.find(oldPOIndex);
2761 QColor oldVisAttrColor;
2762 const QColor& newVisAttrColor = subItem->data(2,Qt::UserRole).value<QColor>();
2764 bool visAttrChange =
false;
2766 if (itVis != fOldVisAttrColorMap.end()) {
2767 oldVisAttrColor = itVis->second;
2768 if (oldVisAttrColor != newVisAttrColor) {
2769 visAttrChange =
true;
2772 visAttrChange =
true;
2775 if (visAttrChange) {
2776 fOldVisAttrColorMap.insert(std::pair <int, QColor > (subItem->data(0,Qt::UserRole).toInt(),newVisAttrColor) );
2780 if (it != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
2781 color = (it->second)->data(2,Qt::UserRole).value<QColor>();
2783 color = oldItem->data(2,Qt::UserRole).value<QColor>();
2785#ifdef G4DEBUG_VIS_OGL
2786 printf(
"====color name:%s\n",color.name().toStdString().c_str());
2788 changeQColorForTreeWidgetItem(subItem,color);
2800bool G4OpenGLQtViewer::isSameSceneTreeElement(
2801 QTreeWidgetItem* parentOldItem
2802 ,QTreeWidgetItem* parentNewItem
2808 int newCpNumber = -1;
2809 int oldCpNumber = -1;
2811 bool firstWhile =
true;
2813 while ((parentOldItem != NULL) && (parentNewItem != NULL)) {
2817 oldPO = parentOldItem->data(0,Qt::UserRole).toInt();
2818 newPO = parentNewItem->data(0,Qt::UserRole).toInt();
2824 const PVPath& oldFullPath = fOldTreeItemModels[oldPO];
2825 const PVPath& newFullPath = fTreeItemModels[newPO];
2826 if ((oldFullPath.size() > 0) &&
2827 (newFullPath.size() > 0)) {
2828 if (oldFullPath.size() != newFullPath.size()) {
2831 if (oldFullPath.at(oldFullPath.size()-1).GetTransform () == newFullPath.at(newFullPath.size()-1).GetTransform ()) {
2832 newCpNumber = newFullPath.at(newFullPath.size()-1).GetCopyNo();
2833 oldCpNumber = oldFullPath.at(oldFullPath.size()-1).GetCopyNo();
2842 if (oldCpNumber == -1) {
2843 oldCpNumber = parentOldItem->data(1,Qt::UserRole).toInt();
2845 if (newCpNumber == -1) {
2846 newCpNumber = parentNewItem->data(1,Qt::UserRole).toInt();
2848 if ((oldCpNumber != newCpNumber) ||
2850 (parentOldItem->text(0) != parentNewItem->text(0)) ) {
2853 }
else if ((parentOldItem->text(0) != parentNewItem->text(0)) ||
2854 (parentOldItem->text(3) != parentNewItem->text(3))) {
2857 parentOldItem = parentOldItem->parent();
2858 parentNewItem = parentNewItem->parent();
2866void G4OpenGLQtViewer::addNonPVSceneTreeElement(
2869 ,
const std::string& modelDescription
2873 QString modelShortName = getModelShortName(model);
2878 const G4Text& g4Text =
dynamic_cast<const G4Text&
>(visible);
2879 color = fSceneHandler.GetTextColour(g4Text);
2881 catch (std::bad_cast) {
2882 color = fSceneHandler.
GetColour(visible);
2884 if (modelShortName ==
"") {
2888 if (fSceneTreeComponentTreeWidget == NULL) {
2889 initSceneTreeComponent();
2893 if (fSceneTreeComponentTreeWidget == NULL) {
2897 fSceneTreeComponentTreeWidget->blockSignals(
true);
2901 QList<QTreeWidgetItem *> resItem;
2902 resItem = fSceneTreeComponentTreeWidget->findItems (modelShortName, Qt::MatchExactly, 0 );
2903 QTreeWidgetItem * currentItem = NULL;
2904 const PVPath tmpFullPath;
2906 if (resItem.empty()) {
2907 currentItem = createTreeWidgetItem(tmpFullPath,
2916 currentItem = resItem.first();
2920 const QList<QTreeWidgetItem *>&
2921 resItems = fSceneTreeComponentTreeWidget->findItems (QString(modelDescription.c_str()), Qt::MatchFixedString| Qt::MatchCaseSensitive|Qt::MatchRecursive, 0 );
2923 bool alreadyPresent =
false;
2924 for (
int i = 0; i < resItems.size(); ++i) {
2925 if (currentPOIndex == resItems.at(i)->data(0,Qt::UserRole).toInt()) {
2926 alreadyPresent =
true;
2929 if (!alreadyPresent) {
2930 createTreeWidgetItem(tmpFullPath,
2931 QString(modelDescription.c_str()),
2939 fSceneTreeComponentTreeWidget->blockSignals(
false);
2947QString G4OpenGLQtViewer::getModelShortName(
const G4String& model) {
2949 QString modelShortName = model.
data();
2950 if (modelShortName.mid(0,modelShortName.indexOf(
" ")) ==
"G4PhysicalVolumeModel") {
2951 modelShortName = fTouchableVolumes;
2953 if (modelShortName.mid(0,2) ==
"G4") {
2954 modelShortName = modelShortName.mid(2);
2956 if (modelShortName.indexOf(
"Model") != -1) {
2957 modelShortName = modelShortName.mid(0,modelShortName.indexOf(
"Model"));
2960 return modelShortName;
2965bool G4OpenGLQtViewer::isTouchableVisible(
int POindex){
2968 if (fSceneTreeComponentTreeWidget == NULL) {
2973 fLastSceneTreeWidgetAskFor++;
2975 QTreeWidgetItem* item = getTreeWidgetItem(POindex);
2978 if ( item->checkState(0) == Qt::Checked) {
2986bool G4OpenGLQtViewer::parseAndCheckVisibility(QTreeWidgetItem * treeNode,
int POindex){
2987 bool isFound =
false;
2988 for (
int i = 0; i < treeNode->childCount() ; ++i) {
2990 if (treeNode->child(i)->data(0,Qt::UserRole).toInt() == POindex) {
2991 if (treeNode->child(i)->checkState(0) == Qt::Checked) {
2995 isFound = parseAndCheckVisibility(treeNode->child(i),POindex);
3004void G4OpenGLQtViewer::sceneTreeComponentItemChanged(QTreeWidgetItem* item,
int) {
3006 if (fCheckSceneTreeComponentSignalLock ==
false) {
3007 fCheckSceneTreeComponentSignalLock =
true;
3009 if (item->checkState(0) == Qt::Checked) {
3012 setCheckComponent(item,checked);
3016 G4int iPO = item->data(0,Qt::UserRole).toInt();
3017 if (iPO >= 0 && fTreeItemModels.find(iPO) != fTreeItemModels.end()) {
3018 const PVPath& fullPath = fTreeItemModels[iPO];
3020 if (fullPath.size()) {
3028 fVP.AddVisAttributesModifier
3039 fCheckSceneTreeComponentSignalLock =
false;
3044void G4OpenGLQtViewer::sceneTreeComponentSelected() {
3062void G4OpenGLQtViewer::changeDepthInSceneTree (
int val){
3065 if (fSceneTreeComponentTreeWidget == NULL) {
3076 double depth = 1 + ((double)val)/1000 * ((double)fSceneTreeDepth+1);
3079 fCheckSceneTreeComponentSignalLock =
true;
3082 G4bool currentAutoRefresh = fVP.IsAutoRefresh();
3083 fVP.SetAutoRefresh(
false);
3085 for (
int b=0;b<fSceneTreeComponentTreeWidget->topLevelItemCount();b++) {
3086 changeDepthOnSceneTreeItem(depth,1.,fSceneTreeComponentTreeWidget->topLevelItem(b));
3090 fVP.SetAutoRefresh(currentAutoRefresh);
3094 fCheckSceneTreeComponentSignalLock =
false;
3099void G4OpenGLQtViewer::changeColorAndTransparency(QTreeWidgetItem* item,
int) {
3104 const QColor& old = QColor(item->data(2,Qt::UserRole).value<QColor>());
3106#if QT_VERSION < 0x040500
3108 const QColor& color = QColor(QColorDialog::getRgba (old.rgba(),&a,fSceneTreeComponentTreeWidget));
3110 const QColor& color = QColorDialog::getColor(old,
3111 fSceneTreeComponentTreeWidget,
3112 " Get color and transparency",
3113 QColorDialog::ShowAlphaChannel);
3116 if (color.isValid()) {
3119 G4int iPO = item->data(0,Qt::UserRole).toInt();
3120 if (iPO >= 0 && fTreeItemModels.find(iPO) != fTreeItemModels.end()) {
3121 const PVPath& fullPath = fTreeItemModels[iPO];
3123 if (fullPath.size()) {
3135 fVP.AddVisAttributesModifier
3147 changeQColorForTreeWidgetItem(item,color);
3152G4Colour G4OpenGLQtViewer::getColorForPoIndex(
int poIndex) {
3154 QTreeWidgetItem* item = getTreeWidgetItem(poIndex);
3158 const QColor& color = item->data(2,Qt::UserRole).value<QColor>();
3170void G4OpenGLQtViewer::changeSearchSelection()
3172 const QString& searchText = fHelpLine->text();
3173 if (fSceneTreeComponentTreeWidget == NULL) {
3178 for (
int a=0; a<fSceneTreeComponentTreeWidget->topLevelItemCount(); a++) {
3179 fSceneTreeComponentTreeWidget->topLevelItem(a)->setExpanded(
false);
3180 fSceneTreeComponentTreeWidget->topLevelItem(a)->setSelected(
false);
3181 clearSceneTreeSelection(fSceneTreeComponentTreeWidget->topLevelItem(a));
3184 QList<QTreeWidgetItem *> itemList = fSceneTreeComponentTreeWidget->findItems (searchText,Qt::MatchContains | Qt::MatchRecursive,0);
3186 for (
int i = 0; i < itemList.size(); ++i) {
3187 QTreeWidgetItem* expandParentItem = itemList.at(i);
3188 while (expandParentItem->parent() != NULL) {
3189 expandParentItem->parent()->setExpanded(
true);
3190 expandParentItem = expandParentItem->parent();
3192 itemList.at(i)->setSelected(
true);
3198void G4OpenGLQtViewer::clearSceneTreeSelection(QTreeWidgetItem* item) {
3199 for (
int a=0; a<item->childCount(); a++) {
3200 item->child(a)->setSelected(
false);
3201 item->child(a)->setExpanded(
false);
3202 clearSceneTreeSelection(item->child(a));
3208bool G4OpenGLQtViewer::isPVVolume(QTreeWidgetItem* item) {
3209 QTreeWidgetItem* sParent = item;
3210 while (sParent->parent() != NULL) {
3211 sParent = sParent->parent();
3213 if (sParent->text(0) != fTouchableVolumes) {
3217 if (item->text(0) == fTouchableVolumes) {
3224void G4OpenGLQtViewer::changeDepthOnSceneTreeItem(
3226 ,
double currentDepth
3227 ,QTreeWidgetItem* item
3229 double transparencyLevel = 0.;
3234 if (isPVVolume(item)) {
3235 if ((lookForDepth-currentDepth) < 0) {
3236 item->setCheckState(0,Qt::Checked);
3237 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3238 transparencyLevel = 1;
3239 }
else if ((lookForDepth-currentDepth) > 1 ){
3240 item->setCheckState(0,Qt::Unchecked);
3241 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3242 transparencyLevel = 0;
3244 item->setCheckState(0,Qt::Checked);
3245 updatePositivePoIndexSceneTreeWidgetQuickMap(item->data(0,Qt::UserRole).toInt(),item);
3246 transparencyLevel = 1-(lookForDepth-currentDepth);
3250 if (item->data(0,Qt::UserRole).toInt() >= 0) {
3251 const G4Colour& color = getColorForPoIndex(item->data(0,Qt::UserRole).toInt());
3263 if (((color.
GetAlpha()-transparencyLevel) > 0.000001) ||
3264 ((color.
GetAlpha()-transparencyLevel) < -0.000001)) {
3265 if ((item->text(3) !=
"")) {
3271 changeQColorForTreeWidgetItem(item,QColor((
int)(color.
GetRed()*255),
3274 (
int)(transparencyLevel*255)));
3279 for (
int b=0;b< item->childCount();b++) {
3280 changeDepthOnSceneTreeItem(lookForDepth,currentDepth+1,item->child(b));
3285void G4OpenGLQtViewer::clearTreeWidget(){
3288 if (fSceneTreeComponentTreeWidget) {
3290 if (fOldSceneTreeComponentTreeWidget == NULL) {
3291 fOldSceneTreeComponentTreeWidget =
new QTreeWidget();
3294 int tmp = fOldSceneTreeComponentTreeWidget->topLevelItemCount();
3296 delete fOldSceneTreeComponentTreeWidget->takeTopLevelItem (0);
3297 tmp = fOldSceneTreeComponentTreeWidget->topLevelItemCount();
3300 if (fSceneTreeComponentTreeWidget->topLevelItemCount () > 0) {
3302 fPVRootNodeCreate =
false;
3305 fOldPositivePoIndexSceneTreeWidgetQuickMap.clear();
3306 fOldNullPoIndexSceneTreeWidgetQuickVector.clear();
3307 fOldTreeItemModels.clear();
3310 for (
int b =0; b <fSceneTreeComponentTreeWidget->topLevelItemCount();b++) {
3319 int poIndex = fSceneTreeComponentTreeWidget->topLevelItem(b)->data(0,Qt::UserRole).toInt();
3320 if (poIndex != -1) {
3321 fOldPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (poIndex,cloneWidgetItem(fSceneTreeComponentTreeWidget->topLevelItem(b))));
3323 fOldNullPoIndexSceneTreeWidgetQuickVector.push_back(cloneWidgetItem(fSceneTreeComponentTreeWidget->topLevelItem(b)));
3327 cloneSceneTree(fSceneTreeComponentTreeWidget->topLevelItem(b));
3331 fOldTreeItemModels.insert(fTreeItemModels.begin(), fTreeItemModels.end());
3334 int tmp2 = fSceneTreeComponentTreeWidget->topLevelItemCount();
3336 delete fSceneTreeComponentTreeWidget->takeTopLevelItem (0);
3337 tmp2 = fSceneTreeComponentTreeWidget->topLevelItemCount();
3339 fPositivePoIndexSceneTreeWidgetQuickMap.clear();
3342 fOldLastSceneTreeWidgetAskFor = fOldPositivePoIndexSceneTreeWidgetQuickMap.begin();
3343 fSceneTreeDepth = 1;
3344 fModelShortNameItem = NULL;
3345 fMaxPOindexInserted = -1;
3358QTreeWidgetItem * G4OpenGLQtViewer::cloneWidgetItem(QTreeWidgetItem* item) {
3360 QTreeWidgetItem* cloneItem =
new QTreeWidgetItem();
3364 cloneItem->setText(0,item->text(0));
3365 cloneItem->setData(1,Qt::UserRole,item->data(1,Qt::UserRole).toInt());
3366 cloneItem->setText(2,item->text(2));
3367 cloneItem->setData(0, Qt::UserRole,item->data(0,Qt::UserRole).toInt());
3368 cloneItem->setText(3,item->text(3));
3369 cloneItem->setFlags(item->flags());
3370 cloneItem->setToolTip(0,item->toolTip(0));
3371 cloneItem->setCheckState(0,item->checkState(0));
3372 cloneItem->setSelected(item->isSelected());
3373 cloneItem->setExpanded(item->isExpanded ());
3375 cloneItem->setData(2,Qt::UserRole,item->data(2,Qt::UserRole).value<QColor>());
3384void G4OpenGLQtViewer::cloneSceneTree(
3385 QTreeWidgetItem* rootItem
3388 for (
int b=0;b< rootItem->childCount();b++) {
3390 QTreeWidgetItem *child = rootItem->child(b);
3393 int poIndex = child->data(0,Qt::UserRole).toInt();
3394 if (poIndex != -1) {
3395 fOldPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (poIndex,cloneWidgetItem(child)));
3397 fOldNullPoIndexSceneTreeWidgetQuickVector.push_back(cloneWidgetItem(child));
3399 cloneSceneTree(child);
3407 void G4OpenGLQtViewer::updatePositivePoIndexSceneTreeWidgetQuickMap(
int POindex,QTreeWidgetItem* item) {
3410 std::map <int, QTreeWidgetItem*>::iterator i;
3411 i = fPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
3413 if (i == fPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3414 fPositivePoIndexSceneTreeWidgetQuickMap.insert(std::pair <int, QTreeWidgetItem*> (POindex,item) );
3415 fLastSceneTreeWidgetAskFor = fPositivePoIndexSceneTreeWidgetQuickMap.end();
3423void G4OpenGLQtViewer::changeQColorForTreeWidgetItem(QTreeWidgetItem* item,
const QColor& qc) {
3425 int POIndex = item->data(0,Qt::UserRole).toInt();
3426 updatePositivePoIndexSceneTreeWidgetQuickMap(POIndex,item );
3428 QPixmap pixmap = QPixmap(QSize(16, 16));
3429 if (item->data(0,Qt::UserRole).toInt() != -1) {
3432 pixmap.fill (QColor(255,255,255,255));
3434 QPainter painter(&pixmap);
3435 painter.setPen(Qt::black);
3436 painter.drawRect(0,0,15,15);
3438 item->setIcon(0,pixmap);
3439 item->setData(2,Qt::UserRole,qc);
3448QTreeWidgetItem* G4OpenGLQtViewer::getTreeWidgetItem(
int POindex){
3451 if (POindex == -1) {
3455 if (fPositivePoIndexSceneTreeWidgetQuickMap.size() == 0){
3459 if (POindex == fLastSceneTreeWidgetAskFor->first) {
3460 if (fLastSceneTreeWidgetAskFor->second != NULL) {
3461 return fLastSceneTreeWidgetAskFor->second;
3466 fLastSceneTreeWidgetAskFor = fPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
3468 if (fLastSceneTreeWidgetAskFor != fPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3469 return fLastSceneTreeWidgetAskFor->second;
3478QTreeWidgetItem* G4OpenGLQtViewer::getOldTreeWidgetItem(
int POindex){
3482 if (POindex == -1) {
3486 if (fOldPositivePoIndexSceneTreeWidgetQuickMap.size() == 0){
3491 fOldLastSceneTreeWidgetAskFor++;
3493 if (POindex == fOldLastSceneTreeWidgetAskFor->first) {
3494 if (fOldLastSceneTreeWidgetAskFor->second != NULL) {
3495 if (fOldLastSceneTreeWidgetAskFor != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3496 return fOldLastSceneTreeWidgetAskFor->second;
3502 fOldLastSceneTreeWidgetAskFor = fOldPositivePoIndexSceneTreeWidgetQuickMap.find(POindex);
3504 if (fOldLastSceneTreeWidgetAskFor != fOldPositivePoIndexSceneTreeWidgetQuickMap.end()) {
3505 return fOldLastSceneTreeWidgetAskFor->second;
3516void G4OpenGLQtViewer::displaySceneTreeComponent() {
3518 if (fUISceneTreeComponentsTBWidget == NULL) {
3521 if (fSceneTreeComponentTreeWidget == NULL) {
3526 fSceneTreeComponentTreeWidget->sortItems (0, Qt::AscendingOrder );
3538void G4OpenGLQtViewer::updateToolbarAndMouseContextMenu(){
3544 d_style = fVP.GetDrawingStyle();
3548 if (fUiQt) fUiQt->SetIconWireframeSelected();
3550 fDrawingWireframe->setChecked(
true);
3551 fDrawingLineRemoval->setChecked(
false);
3552 fDrawingSurfaceRemoval->setChecked(
false);
3553 fDrawingLineSurfaceRemoval->setChecked(
false);
3556 if (fUiQt) fUiQt->SetIconHLRSelected();
3558 fDrawingLineRemoval->setChecked(
true);
3559 fDrawingWireframe->setChecked(
false);
3560 fDrawingSurfaceRemoval->setChecked(
false);
3561 fDrawingLineSurfaceRemoval->setChecked(
false);
3564 if (fUiQt) fUiQt->SetIconSolidSelected();
3566 fDrawingSurfaceRemoval->setChecked(
true);
3567 fDrawingWireframe->setChecked(
false);
3568 fDrawingLineRemoval->setChecked(
false);
3569 fDrawingLineSurfaceRemoval->setChecked(
false);
3572 if (fUiQt) fUiQt->SetIconHLHSRSelected();
3574 fDrawingLineSurfaceRemoval->setChecked(
true);
3575 fDrawingWireframe->setChecked(
false);
3576 fDrawingLineRemoval->setChecked(
false);
3577 fDrawingSurfaceRemoval->setChecked(
false);
3578 fDrawingLineSurfaceRemoval->setChecked(
false);
3584 G4double d_proj = fVP.GetFieldHalfAngle () ;
3586 if (fUiQt) fUiQt->SetIconOrthoSelected();
3588 fProjectionOrtho->setChecked(
true);
3589 fProjectionPerspective->setChecked(
false);
3592 if (fUiQt) fUiQt->SetIconPerspectiveSelected();
3594 fProjectionPerspective->setChecked(
true);
3595 fProjectionOrtho->setChecked(
false);
3601 if (fUiQt && fContextMenu) {
3602 if (fUiQt->IsIconPickSelected()) {
3603 fMousePickAction->setChecked(
true);
3604 fMouseZoomOutAction->setChecked(
false);
3605 fMouseZoomInAction->setChecked(
false);
3606 fMouseRotateAction->setChecked(
false);
3607 fMouseMoveAction->setChecked(
false);
3608 }
else if (fUiQt->IsIconZoomOutSelected()) {
3609 fMouseZoomOutAction->setChecked(
true);
3610 fMousePickAction->setChecked(
false);
3611 fMouseZoomInAction->setChecked(
false);
3612 fMouseRotateAction->setChecked(
false);
3613 fMouseMoveAction->setChecked(
false);
3614 }
else if (fUiQt->IsIconZoomInSelected()) {
3615 fMouseZoomInAction->setChecked(
true);
3616 fMousePickAction->setChecked(
false);
3617 fMouseZoomOutAction->setChecked(
false);
3618 fMouseRotateAction->setChecked(
false);
3619 fMouseMoveAction->setChecked(
false);
3620 }
else if (fUiQt->IsIconRotateSelected()) {
3621 fMouseRotateAction->setChecked(
true);
3622 fMousePickAction->setChecked(
false);
3623 fMouseZoomOutAction->setChecked(
false);
3624 fMouseZoomInAction->setChecked(
false);
3625 fMouseMoveAction->setChecked(
false);
3626 }
else if (fUiQt->IsIconMoveSelected()) {
3627 fMouseMoveAction->setChecked(
true);
3628 fMousePickAction->setChecked(
false);
3629 fMouseZoomOutAction->setChecked(
false);
3630 fMouseZoomInAction->setChecked(
false);
3631 fMouseRotateAction->setChecked(
false);
G4DLLIMPORT std::ostream G4cerr
G4DLLIMPORT std::ostream G4cout
G4double GetAlpha() const
static G4bool GetColour(const G4String &key, G4Colour &result)
G4double GetGreen() const
const std::vector< G4PhysicalVolumeNodeID > & GetFullPVPath() const
const char * data() const
G4double GetYOffset() const
G4double GetXOffset() const
G4UIsession * GetG4UIWindow() const
static G4UImanager * GetUIpointer()
G4Point3D GetPosition() const
const G4Transform3D & GetTransformation() const
void SetVisibility(G4bool)
void SetColour(const G4Colour &)
const G4Colour & GetColour() const
std::vector< PVNodeID > PVPath