Import Geant4 9.4.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-09 16:25:56 +02:00
parent 74cad5e589
commit 89a9605df1
4440 changed files with 379508 additions and 189225 deletions
@@ -24,8 +24,8 @@
// ********************************************************************
//
//
// $Id: G4OpenGLImmediateQtViewer.cc,v 1.17 2009/11/03 11:02:32 lgarnier Exp $
// GEANT4 tag $Name: geant4-09-03 $
// $Id: G4OpenGLImmediateQtViewer.cc,v 1.22 2010/06/23 13:29:23 lgarnier Exp $
// GEANT4 tag $Name: geant4-09-04 $
//
//
// Class G4OpenGLImmediateQtViewer : a class derived from G4OpenGLQtViewer and
@@ -52,7 +52,8 @@ G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
#else
setFocusPolicy(Qt::StrongFocus); // enable keybord events
#endif
fHasToRepaint =false;
fHasToRepaint = false;
fIsRepainting = false;
if (fViewId < 0) return; // In case error in base class instantiation.
}
@@ -96,19 +97,8 @@ void G4OpenGLImmediateQtViewer::initializeGL () {
}
/** To ensure compatibility with DrawView method
*/
void G4OpenGLImmediateQtViewer::DrawView() {
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLImmediateQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
#endif
// That's no the same logic as Stored Viewer, I don't know why...
// see G4OpenGLStoredQtViewer::DrawView for more informations
updateQWidget();
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLImmediateQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
#endif
}
@@ -130,7 +120,7 @@ void G4OpenGLImmediateQtViewer::ComputeView () {
HaloingFirstPass ();
NeedKernelVisit ();
ProcessView ();
glFlush ();
FinishView();
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLImmediateQtViewer::ComputeView First ProcessView ok\n");
#endif
@@ -151,19 +141,6 @@ void G4OpenGLImmediateQtViewer::ComputeView () {
fHasToRepaint = true;
}
void G4OpenGLImmediateQtViewer::FinishView()
{
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLImmediateQtViewer::FinishView() BEGIN\n");
#endif
glFlush ();
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLImmediateQtViewer::FinishView() END\n");
#endif
}
/**
- Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements
*/
@@ -171,24 +148,32 @@ void G4OpenGLImmediateQtViewer::resizeGL(
int aWidth
,int aHeight)
{
ResizeWindow(aWidth,aHeight);
fHasToRepaint = sizeHasChanged();
if ((aWidth > 0) && (aHeight > 0)) {
ResizeWindow(aWidth,aHeight);
fHasToRepaint = sizeHasChanged();
}
}
void G4OpenGLImmediateQtViewer::paintGL()
{
#ifdef G4DEBUG_VIS_OGL
printf("\n\nG4OpenGLImmediateQtViewer::paintGL ??\n");
#endif
if (fIsRepainting) {
// return ;
}
if (!fReadyToPaint) {
fReadyToPaint= true;
return;
}
if ((getWinWidth() == 0) && (getWinHeight() == 0)) {
return;
}
// DO NOT RESIZE IF SIZE HAS NOT CHANGE
if ( !fHasToRepaint) {
#if QT_VERSION < 0x040000
if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
return;
}
#else
// L. Garnier : Trap to get the size with mac OSX 10.6 and Qt 4.6(devel)
// Tested on Qt4.5 on mac, 4.4 on windows, 4.5 on unbuntu
@@ -202,9 +187,14 @@ void G4OpenGLImmediateQtViewer::paintGL()
sh = frameGeometry().height();
}
if ((getWinWidth() == (unsigned int)sw) &&(getWinHeight() == (unsigned int)sh)) {
#endif
return;
} else if ((sw == 0) && (sh == 0)) { // NOT A TOP LEVEL WIDGET
if (((getWinWidth() == (unsigned int)width())) &&(getWinHeight() == (unsigned int) height())) {
return;
}
}
#endif
}
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
@@ -220,6 +210,7 @@ void G4OpenGLImmediateQtViewer::paintGL()
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n\n\n",fReadyToPaint);
#endif
fIsRepainting = false;
}
void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event)
@@ -237,6 +228,12 @@ void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event)
G4wheelEvent(event);
}
void G4OpenGLImmediateQtViewer::showEvent (QShowEvent *)
{
fHasToRepaint = true;
}
/**
* This function was build in order to make a zoom on double clic event.
* It was think to build a rubberband on the zoom area, but never work fine
@@ -262,9 +259,17 @@ void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *e)
G4manageContextMenuEvent(e);
}
void G4OpenGLImmediateQtViewer::paintEvent(QPaintEvent *) {
if ( fHasToRepaint) {
updateGL();
}
}
void G4OpenGLImmediateQtViewer::updateQWidget() {
fHasToRepaint= true;
updateGL();
repaint();
fHasToRepaint= false;
}
@@ -274,6 +279,7 @@ void G4OpenGLImmediateQtViewer::ShowView (
//////////////////////////////////////////////////////////////////////////////
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
{
fHasToRepaint = true;
#if QT_VERSION < 0x040000
setActiveWindow();
#else
@@ -24,8 +24,8 @@
// ********************************************************************
//
//
// $Id: G4OpenGLImmediateSceneHandler.cc,v 1.31 2009/02/04 16:48:41 lgarnier Exp $
// GEANT4 tag $Name: geant4-09-03 $
// $Id: G4OpenGLImmediateSceneHandler.cc,v 1.35 2010/06/03 20:35:19 allison Exp $
// GEANT4 tag $Name: geant4-09-04-beta-01 $
//
//
// Andrew Walkden 10th February 1997
@@ -24,8 +24,8 @@
// ********************************************************************
//
//
// $Id: G4OpenGLQtViewer.cc,v 1.45 2009/10/21 08:14:44 lgarnier Exp $
// GEANT4 tag $Name: geant4-09-03 $
// $Id: G4OpenGLQtViewer.cc,v 1.55 2010/10/08 10:07:31 lgarnier Exp $
// GEANT4 tag $Name: geant4-09-04 $
//
//
// G4OpenGLQtViewer : Class to provide Qt specific
@@ -51,6 +51,7 @@
#include "G4OpenGLQtMovieDialog.hh"
#include "G4UnitsTable.hh"
#include "G4Qt.hh"
#include "G4UIQt.hh"
#include "G4UImanager.hh"
#include "G4UIcommandTree.hh"
#include <qlayout.h>
@@ -77,6 +78,7 @@
#include <qpainter.h>
#include <qgl.h> // include <qglwidget.h>
#include <qdialog.h>
#include <qcolordialog.h>
#include <qevent.h> //include <qcontextmenuevent.h>
@@ -109,42 +111,87 @@ void G4OpenGLQtViewer::CreateMainWindow (
fWindow = glWidget ;
// fWindow->makeCurrent();
QWidget *myParent = getParentWidget();
if (myParent != NULL) {
#if QT_VERSION < 0x040000
glWidget->reparent(myParent,0,QPoint(0,0));
#else
glWidget->setParent(myParent);
#endif
}
//G4Qt* interactorManager = G4Qt::getInstance ();
QHBoxLayout *mainLayout = new QHBoxLayout(fGLWindow);
mainLayout->setMargin(0);
mainLayout->setSpacing(0);
mainLayout->addWidget(fWindow);
#if QT_VERSION < 0x040000
fGLWindow->setCaption(name );
#else
fGLWindow->setLayout(mainLayout);
fGLWindow->setWindowTitle( name);
#endif
ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
// FIXME L.Garnier 9/11/09 Has to be check !!!
// Qt UI with Qt Vis
// Qt UI with X Vis
// X UI with Qt Vis
// X UI with X Vis
// Ne marche pas avec un UIBatch !! (ecran blanc)
//useful for MACOSX, we have to compt the menuBar height
int offset = QApplication::desktop()->height()
- QApplication::desktop()->availableGeometry().height();
// return false if G4UIQt was not launch
G4int YPos= fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height());
if (fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height())< offset) {
YPos = offset;
}
fGLWindow->resize(getWinWidth(), getWinHeight());
fGLWindow->move(fVP.GetWindowAbsoluteLocationHintX(QApplication::desktop()->width()),YPos);
fGLWindow->show();
G4UImanager* UI = G4UImanager::GetUIpointer();
if (UI == NULL) return;
if (! static_cast<G4UIQt*> (UI->GetG4UIWindow())) return;
G4UIQt * uiQt = static_cast<G4UIQt*> (UI->GetG4UIWindow());
if(!fWindow) return;
bool isTabbedView = false;
if ( uiQt) {
isTabbedView = uiQt->AddTabWidget(fWindow,name,getWinWidth(),getWinHeight());
}
#ifdef G4DEBUG_VIS_OGL
else {
printf("G4OpenGLQtViewer::CreateMainWindow :: UIQt NOt found \n");
}
#endif
if (!isTabbedView) { // we have to do a dialog
QWidget *myParent = getParentWidget();
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLQtViewer::CreateMainWindow :: getParent OK \n");
#endif
if (myParent != NULL) {
#if QT_VERSION < 0x040000
glWidget->reparent(myParent,0,QPoint(0,0));
#else
glWidget->setParent(myParent);
#endif
}
QHBoxLayout *mainLayout = new QHBoxLayout(fGLWindow);
mainLayout->setMargin(0);
mainLayout->setSpacing(0);
mainLayout->addWidget(fWindow);
if (fGLWindow->inherits("QMainWindow")) {
#if QT_VERSION < 0x040000
fGLWindow->setCaption(name );
#else
fGLWindow->setWindowTitle( name);
#endif
}
#if QT_VERSION >= 0x040000
fGLWindow->setLayout(mainLayout);
#endif
//useful for MACOSX, we have to compt the menuBar height
int offset = QApplication::desktop()->height()
- QApplication::desktop()->availableGeometry().height();
G4int YPos= fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height());
if (fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height())< offset) {
YPos = offset;
}
fGLWindow->resize(getWinWidth(), getWinHeight());
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLQtViewer::CreateMainWindow :: resizing to %d %d \n",getWinWidth(), getWinHeight());
#endif
fGLWindow->move(fVP.GetWindowAbsoluteLocationHintX(QApplication::desktop()->width()),YPos);
fGLWindow->show();
} else {
fGLWindow = fWindow;
fGLWindow->resize(getWinWidth(), getWinHeight());
}
if(!fWindow) return;
if (!fContextMenu)
createPopupMenu();
@@ -166,10 +213,6 @@ G4OpenGLQtViewer::G4OpenGLQtViewer (
,G4OpenGLViewer (scene)
,fWindow(0)
,fRecordFrameNumber(0)
,fRotationAngleX(0)
,fRotationAngleY(0)
,fDeltaRotationAngleX(0)
,fDeltaRotationAngleY(0)
,fContextMenu(0)
,fMouseAction(STYLE1)
,fDeltaRotation(1)
@@ -189,7 +232,15 @@ G4OpenGLQtViewer::G4OpenGLQtViewer (
,fMovieParametersDialog(NULL)
,fRecordingStep(WAIT)
,fProcess(NULL)
,fNbMaxFramesPerSec(100)
,fNbMaxAnglePerSec(360)
,fLaunchSpinDelay(100)
,fXRot(0)
,fYRot(0)
,fNoKeyPress(true)
,fAltKeyPress(false)
,fControlKeyPress(false)
,fShiftKeyPress(false)
{
// launch Qt if not
@@ -494,37 +545,86 @@ void G4OpenGLQtViewer::createPopupMenu() {
SLOT(actionDrawingLineSurfaceRemoval()));
#endif
// Background Color
QAction *backgroundColorChooser ;
#if QT_VERSION < 0x040000
QPopupMenu *mBackground = new QPopupMenu(mStyle);
mStyle->insertItem("&Background color",mBackground);
QPopupMenu *mBackgroundColor = new QPopupMenu(mStyle);
mStyle->insertItem("&Background color",mBackgroundColor);
#if QT_VERSION < 0x030200
QAction *white = new QAction("&White","&White",CTRL+Key_W,mBackground,0,true);
QAction *black = new QAction("&Black","&Black",CTRL+Key_B,mBackground,0,true);
backgroundColorChooser = new QAction("&Choose ...","&Choose ...",CTRL+Key_C,mBackgroundColor,0,true);
#else
QAction *white = new QAction("&White",CTRL+Key_W,mBackground);
QAction *black = new QAction("&Black",CTRL+Key_B,mBackground);
white->setToggleAction(true);
black->setToggleAction(true);
backgroundColorChooser = new QAction("&Choose ...","&Choose ...",CTRL+Key_C,mBackgroundColor);
#endif
white->addTo(mBackground);
black->addTo(mBackground);
backgroundColorChooser->addTo(mBackgroundColor);
QObject ::connect(backgroundColorChooser,
SIGNAL(activated()),
this,
SLOT(actionChangeBackgroundColor()));
#else
QMenu *mBackground = mStyle->addMenu("&Background color");
QAction *white = mBackground->addAction("White");
QAction *black = mBackground->addAction("Black");
// === Action Menu ===
backgroundColorChooser = mStyle->addAction("Background color");
QObject ::connect(backgroundColorChooser,
SIGNAL(triggered()),
this,
SLOT(actionChangeBackgroundColor()));
#endif
// Text Color
QAction *textColorChooser ;
#if QT_VERSION < 0x040000
QPopupMenu *mTextColor = new QPopupMenu(mStyle);
mStyle->insertItem("&Text color",mTextColor);
#if QT_VERSION < 0x030200
textColorChooser = new QAction("&Choose ...","&Choose ...",CTRL+Key_C,mTextColor,0,true);
#else
textColorChooser = new QAction("&Choose ...","&Choose ...",CTRL+Key_C,mTextColor);
#endif
textColorChooser->addTo(mTextColor);
QObject ::connect(textColorChooser,
SIGNAL(activated()),
this,
SLOT(actionChangeTextColor()));
#else
// === Action Menu ===
textColorChooser = mStyle->addAction("Text color");
QObject ::connect(textColorChooser,
SIGNAL(triggered()),
this,
SLOT(actionChangeTextColor()));
#endif
// Default Color
QAction *defaultColorChooser ;
#if QT_VERSION < 0x040000
QPopupMenu *mDefaultColor = new QPopupMenu(mStyle);
mStyle->insertItem("&Default color",mDefaultColor);
#if QT_VERSION < 0x030200
defaultColorChooser = new QAction("&Choose ...","&Choose ...",CTRL+Key_C,mDefaultColor,0,true);
#else
defaultColorChooser = new QAction("&Choose ...","&Choose ...",CTRL+Key_C,mDefaultColor);
#endif
defaultColorChooser->addTo(mDefaultColor);
QObject ::connect(defaultColorChooser,
SIGNAL(activated()),
this,
SLOT(actionChangeDefaultColor()));
#else
// === Action Menu ===
defaultColorChooser = mStyle->addAction("Default color");
QObject ::connect(defaultColorChooser,
SIGNAL(triggered()),
this,
SLOT(actionChangeDefaultColor()));
#endif
if (background.GetRed() == 1. &&
background.GetGreen() == 1. &&
background.GetBlue() == 1.) {
createRadioAction(white,black,SLOT(toggleBackground(bool)),1);
} else {
createRadioAction(white,black,SLOT(toggleBackground(bool)),2);
}
#if QT_VERSION < 0x040000
@@ -896,45 +996,43 @@ void G4OpenGLQtViewer::toggleMouseAction(mouseActions aAction) {
Show shortcuts for this mouse action
*/
void G4OpenGLQtViewer::showShortcuts() {
G4cout << "========= Mouse Shortcuts =========" << G4endl;
if (fMouseAction == STYLE1) { // rotate
G4cout << "Click and move mouse to rotate volume " << G4endl;
G4cout << "Press left/right arrows to move volume left/right" << G4endl;
G4cout << "Press up/down arrows to move volume up/down" << G4endl;
G4cout << "Press ALT+up/down arrows to move volume toward/forward" << G4endl;
G4cout << "Press SHIFT+left/right arrows to rotate volume left/right" << G4endl;
G4cout << "Press SHIFT+up/down arrows to rotate volume up/down" << G4endl;
G4cout << "Press ALT+/- to slow/speed auto rotation/move" << G4endl;
G4cout << "In video mode : " << G4endl;
G4cout << " Press SPACE to Start/Pause video recording " << G4endl;
G4cout << " Press RETURN to Stop video recording " << G4endl;
G4cout << "ALT + Click and move mouse to rotate volume (View Direction)" << G4endl;
G4cout << "CTRL + Click and zoom mouse to zoom in/out" << G4endl;
G4cout << "SHIFT + Click and zoommove camera point of view" << G4endl;
} else if (fMouseAction == STYLE2) { //move
G4cout << "Move camera point of view with mouse" << G4endl;
G4cout << "Press left/right arrows to move volume left/right" << G4endl;
G4cout << "Press up/down arrows to move volume up/down" << G4endl;
G4cout << "Press ALT+up/down arrows to move volume toward/forward" << G4endl;
G4cout << "Press SHIFT+left/right arrows to rotate volume left/right" << G4endl;
G4cout << "Press SHIFT+up/down arrows to rotate volume up/down" << G4endl;
G4cout << "Press +/- to zoom into volume" << G4endl;
G4cout << "Press ALT+/- to slow/speed auto rotation/move" << G4endl;
G4cout << "In video mode : " << G4endl;
G4cout << " Press SPACE to Start/Pause video recording " << G4endl;
G4cout << " Press RETURN to Stop video recording " << G4endl;
} else if (fMouseAction == STYLE3) { //pick
G4cout << "Click and pick " << G4endl;
} else {
G4cout << "Move camera point of view with mouse" << G4endl;
G4cout << "Press left/right arrows to move volume left/right" << G4endl;
G4cout << "Press up/down arrows to move volume up/down" << G4endl;
G4cout << "Press ALT+up/down arrows to move volume toward/forward" << G4endl;
G4cout << "Press SHIFT+left/right arrows to rotate volume left/right" << G4endl;
G4cout << "Press SHIFT+up/down arrows to rotate volume up/down" << G4endl;
G4cout << "Press +/- to zoom into volume" << G4endl;
G4cout << "Press ALT+/- to slow/speed auto rotation/move" << G4endl;
G4cout << "In video mode : " << G4endl;
G4cout << " Press SPACE to Start/Pause video recording " << G4endl;
G4cout << " Press RETURN to Stop video recording " << G4endl;
}
G4cout << "========= Move Shortcuts =========" << G4endl;
G4cout << "Press left/right arrows to move volume left/right" << G4endl;
G4cout << "Press up/down arrows to move volume up/down" << G4endl;
G4cout << "Press '+'/'-' to move volume toward/forward" << G4endl;
G4cout << G4endl;
G4cout << "========= Rotation (Theta/Phi) Shortcuts =========" << G4endl;
G4cout << "Press SHIFT + left/right arrows to rotate volume left/right" << G4endl;
G4cout << "Press SHIFT + up/down arrows to rotate volume up/down" << G4endl;
G4cout << G4endl;
G4cout << "========= Rotation (View Direction) Shortcuts =========" << G4endl;
G4cout << "Press ALT + left/right to rotate volume around vertical direction" << G4endl;
G4cout << "Press ALT + up/down to rotate volume around horizontal direction" << G4endl;
G4cout << G4endl;
G4cout << "========= Zoom View =========" << G4endl;
G4cout << "Press CTRL + '+'/'-' to zoom into volume" << G4endl;
G4cout << G4endl;
G4cout << "========= Misc =========" << G4endl;
G4cout << "Press ALT +/- to slow/speed rotation/move" << G4endl;
G4cout << "Press H to reset view" << G4endl;
G4cout << "Press Esc to exit FullScreen" << G4endl;
G4cout << G4endl;
G4cout << "========= Video =========" << G4endl;
G4cout << "In video mode : " << G4endl;
G4cout << " Press SPACE to Start/Pause video recording " << G4endl;
G4cout << " Press RETURN to Stop video recording " << G4endl;
G4cout << G4endl;
}
@@ -1045,77 +1143,14 @@ void G4OpenGLQtViewer::toggleRepresentation(bool check) {
void G4OpenGLQtViewer::toggleProjection(bool check) {
if (check == 1) {
fVP.SetFieldHalfAngle (0);
G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection o");
} else {
// look for the default parameter hidden in G4UIcommand parameters
G4UImanager* UI = G4UImanager::GetUIpointer();
if(UI==NULL)
return;
G4UIcommandTree * treeTop = UI->GetTree();
// find command
G4UIcommand* command = treeTop->FindPath("/vis/viewer/set/projection");
if (!command)
return;
// find param
G4UIparameter * angleParam = NULL;
for(G4int i=0; i<command->GetParameterEntries(); i++)
{
if( command->GetParameter(i)->GetParameterName() == "field-half-angle" ) {
angleParam = command->GetParameter(i);
}
}
if (!angleParam)
return;
// find unit
G4UIparameter * unitParam = NULL;
for(G4int i=0; i<command->GetParameterEntries(); i++)
{
if( command->GetParameter(i)->GetParameterName() == "unit" ) {
unitParam = command->GetParameter(i);
}
}
if (!unitParam)
return;
G4double defaultValue = command->ConvertToDouble(angleParam->GetDefaultValue())
* G4UnitDefinition::GetValueOf(unitParam->GetDefaultValue());
if (defaultValue > 89.5 || defaultValue <= 0.0) {
G4cerr << "Field half angle should be 0 < angle <= 89.5 degrees. Check your default Field half angle parameter";
} else {
G4cout << "Perspective view has been set to default value. Field half angle="<<angleParam->GetDefaultValue() <<" " << G4endl;
fVP.SetFieldHalfAngle (defaultValue);
SetView ();
}
G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection p");
}
updateQWidget();
}
/**
SLOT Activate by a click on the background menu
@param check : 1 white, 0 black
*/
void G4OpenGLQtViewer::toggleBackground(bool check) {
// //I need to revisit the kernel if the background colour changes and
// //hidden line removal is enabled, because hlr drawing utilises the
// //background colour in its drawing...
// // (Note added by JA 13/9/2005) Background now handled in view
// // parameters. A kernel visit is triggered on change of background.
if (check == 1) {
((G4ViewParameters&)this->GetViewParameters()).
SetBackgroundColour(G4Colour(1.,1.,1.)); // White
} else {
((G4ViewParameters&)this->GetViewParameters()).
SetBackgroundColour(G4Colour(0.,0.,0.)); // Black
}
updateQWidget();
}
/**
SLOT Activate by a click on the transparency menu
@param check : 1 , 0
@@ -1174,13 +1209,12 @@ void G4OpenGLQtViewer::toggleHaloing(bool check) {
*/
void G4OpenGLQtViewer::toggleAux(bool check) {
if (check) {
fVP.SetAuxEdgeVisible(false);
} else {
fVP.SetAuxEdgeVisible(true);
} else {
fVP.SetAuxEdgeVisible(false);
}
SetNeedKernelVisit (true);
updateQWidget();
}
/**
@@ -1345,6 +1379,59 @@ void G4OpenGLQtViewer::actionSaveImage() {
}
void G4OpenGLQtViewer::actionChangeBackgroundColor() {
// //I need to revisit the kernel if the background colour changes and
// //hidden line removal is enabled, because hlr drawing utilises the
// //background colour in its drawing...
// // (Note added by JA 13/9/2005) Background now handled in view
// // parameters. A kernel visit is triggered on change of background.
QColor color;
color = QColorDialog::getColor(Qt::black, fGLWindow);
if (color.isValid()) {
QString com = "/vis/viewer/set/background ";
QString num;
com += num.setNum(((float)color.red())/256)+" ";
com += num.setNum(((float)color.green())/256)+" ";
com += num.setNum(((float)color.blue())/256)+" ";
G4UImanager::GetUIpointer()->ApplyCommand(com.toStdString().c_str());
updateQWidget();
}
}
void G4OpenGLQtViewer::actionChangeTextColor() {
QColor color;
color = QColorDialog::getColor(Qt::yellow, fGLWindow);
if (color.isValid()) {
QString com = "/vis/viewer/set/defaultTextColour ";
QString num;
com += num.setNum(((float)color.red())/256)+" ";
com += num.setNum(((float)color.green())/256)+" ";
com += num.setNum(((float)color.blue())/256)+" ";
G4UImanager::GetUIpointer()->ApplyCommand(com.toStdString().c_str());
updateQWidget();
}
}
void G4OpenGLQtViewer::actionChangeDefaultColor() {
QColor color;
color = QColorDialog::getColor(Qt::white, fGLWindow);
printf("actionChangeDefaultColor\n");
if (color.isValid()) {
QString com = "/vis/viewer/set/defaultColour ";
QString num;
com += num.setNum(((float)color.red())/256)+" ";
com += num.setNum(((float)color.green())/256)+" ";
com += num.setNum(((float)color.blue())/256)+" ";
G4UImanager::GetUIpointer()->ApplyCommand(com.toStdString().c_str());
updateQWidget();
}
}
void G4OpenGLQtViewer::actionMovieParameters() {
showMovieParametersDialog();
}
@@ -1398,17 +1485,9 @@ void G4OpenGLQtViewer::FinishView()
void G4OpenGLQtViewer::G4MousePressEvent(QMouseEvent *event)
{
#if QT_VERSION < 0x040000
if ((event->button() & Qt::LeftButton)
&& !((event->state() & Qt::ShiftButton)
|| (event->state() & Qt::ControlButton)
|| (event->state() & Qt::AltButton)
|| (event->state() & Qt::MetaButton))) {
if (event->button() & Qt::LeftButton) {
#else
if ((event->buttons() & Qt::LeftButton)
&& !((event->modifiers() & Qt::ShiftModifier)
|| (event->modifiers() & Qt::ControlModifier)
|| (event->modifiers() & Qt::AltModifier)
|| (event->modifiers() & Qt::MetaModifier))) {
if (event->buttons() & Qt::LeftButton) {
#endif
fWindow->setMouseTracking(true);
fAutoMove = false; // stop automove
@@ -1436,18 +1515,45 @@ void G4OpenGLQtViewer::G4MouseReleaseEvent()
QTime lastMoveTime;
lastMoveTime.start();
// try to addapt speed move/rotate looking to drawing speed
int cycles = 4;
float correctionFactor = 5;
while (fAutoMove) {
// if ( lastMoveTime.elapsed() > (fSpinningDelay / (cycles/2))) {
if ( lastMoveTime.elapsed () >= (int)(1000/fNbMaxFramesPerSec)) {
float lTime = 1000/((float)lastMoveTime.elapsed ());
if (((((float)delta.x())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
((((float)delta.x())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
correctionFactor = (float)delta.x()*(lTime/fNbMaxAnglePerSec);
if (delta.x() <0 ) {
correctionFactor = -correctionFactor;
}
}
if (((((float)delta.y())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
((((float)delta.y())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
correctionFactor = (float)delta.y()*(lTime/fNbMaxAnglePerSec);
if (delta.y() <0 ) {
correctionFactor = -correctionFactor;
}
}
// Check Qt Versions for META Keys
// Click and move mouse to rotate volume
// ALT + Click and move mouse to rotate volume (View Direction)
// SHIFT + Click and move camera point of view
// CTRL + Click and zoom mouse to zoom in/out
if (fMouseAction == STYLE1) { // rotate
rotateQtScene(((float)delta.x())/cycles,((float)delta.y())/cycles);
if (fNoKeyPress) {
rotateQtScene(((float)delta.x())/correctionFactor,((float)delta.y())/correctionFactor);
} else if (fAltKeyPress) {
rotateQtSceneInViewDirection(((float)delta.x())/correctionFactor,((float)delta.y())/correctionFactor);
}
} else if (fMouseAction == STYLE2) { // move
moveScene(-((float)delta.x())/cycles,-((float)delta.y())/cycles,0,true);
moveScene(-((float)delta.x())/correctionFactor,-((float)delta.y())/correctionFactor,0,true);
}
lastMoveTime.start();
cycles = 1 ;
}
((QApplication*)G4Qt::getInstance ())->processEvents();
cycles ++ ;
}
}
fWindow->setMouseTracking(false);
@@ -1477,6 +1583,12 @@ void G4OpenGLQtViewer::G4MouseMoveEvent(QMouseEvent *event)
Qt::MouseButtons mButtons = event->buttons();
#endif
#if QT_VERSION < 0x040000
updateKeyModifierState(event->state());
#else
updateKeyModifierState(event->modifiers());
#endif
if (fAutoMove) {
return;
}
@@ -1490,7 +1602,23 @@ void G4OpenGLQtViewer::G4MouseMoveEvent(QMouseEvent *event)
if (fMouseAction == STYLE1) { // rotate
if (mButtons & Qt::LeftButton) {
rotateQtScene(deltaX,deltaY);
if (fNoKeyPress) {
rotateQtScene(((float)deltaX),((float)deltaY));
} else if (fAltKeyPress) {
rotateQtSceneInViewDirection(((float)deltaX),((float)deltaY));
} else if (fShiftKeyPress) {
unsigned int sizeWin;
sizeWin = getWinWidth();
if (getWinHeight() < getWinWidth()) {
sizeWin = getWinHeight();
}
// L.Garnier : 08/2010 100 is the good value, but don't ask me why !
float factor = ((float)100/(float)sizeWin) ;
moveScene(-(float)deltaX*factor,-(float)deltaY*factor,0,false);
} else if (fControlKeyPress) {
fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+((float)deltaY)));
}
}
} else if (fMouseAction == STYLE2) { // move
if (mButtons & Qt::LeftButton) {
@@ -1527,9 +1655,9 @@ void G4OpenGLQtViewer::moveScene(float dx,float dy, float dz,bool mouseMove)
coefDepth = getSceneDepth()*fDeltaDepth;
}
fVP.IncrementPan(-dx*coefTrans,dy*coefTrans,dz*coefDepth);
emit moveX(-dx*coefTrans);
emit moveY(dy*coefTrans);
emit moveZ(dz*coefTrans);
emit moveX(-static_cast<int>(dx*coefTrans));
emit moveY(static_cast<int>(dy*coefTrans));
emit moveZ(static_cast<int>(dz*coefTrans));
updateQWidget();
if (fAutoMove)
@@ -1552,11 +1680,11 @@ void G4OpenGLQtViewer::rotateQtScene(float dx, float dy)
if( dx != 0) {
rotateScene(dx,0,fDeltaRotation);
emit rotateTheta(dx);
emit rotateTheta(static_cast<int>(dx));
}
if( dy != 0) {
rotateScene(0,dy,fDeltaRotation);
emit rotatePhi(dy);
emit rotatePhi(static_cast<int>(dy));
}
updateQWidget();
@@ -1568,6 +1696,29 @@ void G4OpenGLQtViewer::rotateQtScene(float dx, float dy)
@param dy delta mouse y position
*/
void G4OpenGLQtViewer::rotateQtSceneInViewDirection(float dx, float dy)
{
if (fHoldRotateEvent)
return;
fHoldRotateEvent = true;
fXRot +=dx;
fYRot +=dy;
rotateSceneInViewDirection(dx,dy,fDeltaRotation/100);
emit rotateTheta(static_cast<int>(dx));
emit rotatePhi(static_cast<int>(dy));
updateQWidget();
fHoldRotateEvent = false;
}
/**
@param dx delta mouse x position
@param dy delta mouse y position
*/
void G4OpenGLQtViewer::rotateQtCamera(float dx, float dy)
{
if (fHoldRotateEvent)
@@ -1575,13 +1726,41 @@ void G4OpenGLQtViewer::rotateQtCamera(float dx, float dy)
fHoldRotateEvent = true;
rotateScene(dx,dy,fDeltaRotation);
emit rotateTheta(dx);
emit rotatePhi(dy);
emit rotateTheta(static_cast<int>(dx));
emit rotatePhi(static_cast<int>(dy));
updateQWidget();
fHoldRotateEvent = false;
}
/**
@param dx delta mouse x position
@param dy delta mouse y position
*/
void G4OpenGLQtViewer::rotateQtCameraInViewDirection(float dx, float dy)
{
if (fHoldRotateEvent)
return;
fHoldRotateEvent = true;
fVP.SetUpVector(G4Vector3D(0.0, 1.0, 0.0));
fVP.SetViewAndLights (G4Vector3D(0.0, 0.0, 1.0));
fXRot +=dx;
fYRot +=dy;
rotateSceneInViewDirection(fXRot,fYRot,fDeltaRotation/100);
emit rotateTheta(static_cast<int>(dx));
emit rotatePhi(static_cast<int>(dy));
updateQWidget();
fHoldRotateEvent = false;
}
@@ -1638,7 +1817,7 @@ bool G4OpenGLQtViewer::printPDF (
printer.setOutputFormat(QPrinter::PdfFormat);
}
*/
printer.setOutputFileName(aFilename);
printer.setOutputFileName(QString(aFilename.c_str()));
// printer.setFullPage ( true);
QPainter paint(&printer);
paint.drawImage (0,0,aImage );
@@ -1697,103 +1876,21 @@ void G4OpenGLQtViewer::G4wheelEvent (QWheelEvent * event)
}
void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event)
void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event)
{
if (fHoldKeyEvent)
return;
fHoldKeyEvent = true;
#if QT_VERSION < 0x040000
if ((event->key() == Qt::Key_Down) && (event->state() & Qt::AltButton )) { // go backward
#else
if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::AltModifier )) { // go backward
#endif
moveScene(0,0,1,false);
}
#if QT_VERSION < 0x040000
else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::AltButton)) { // go forward
#else
else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::AltModifier)) { // go forward
#endif
moveScene(0,0,-1,false);
}
#if QT_VERSION < 0x040000
if ((event->key() == Qt::Key_Down) && (event->state() & Qt::ShiftButton)) { // rotate phi
#else
if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi
#endif
rotateQtCamera(0,-1);
}
#if QT_VERSION < 0x040000
else if ((event->key() == Qt::Key_Up) && (event->state() & Qt::ShiftButton)) { // rotate phi
#else
else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi
#endif
rotateQtCamera(0,1);
}
#if QT_VERSION < 0x040000
if ((event->key() == Qt::Key_Left) && (event->state() & Qt::ShiftButton)) { // rotate theta
#else
if ((event->key() == Qt::Key_Left) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta
#endif
rotateQtCamera(1,0);
}
#if QT_VERSION < 0x040000
else if ((event->key() == Qt::Key_Right) && (event->state() & Qt::ShiftButton)) { // rotate theta
#else
else if ((event->key() == Qt::Key_Right) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta
#endif
rotateQtCamera(-1,0);
}
#if QT_VERSION < 0x040000
if ((event->state() & Qt::AltButton)) {
#else
if ((event->modifiers() & Qt::AltModifier)) {
#endif
if (event->key() == Qt::Key_Plus) {
fDeltaRotation = fDeltaRotation/0.7;
}
else if (event->key() == Qt::Key_Minus) {
fDeltaRotation = fDeltaRotation*0.7;
}
} else {
if (event->key() == Qt::Key_Plus) {
fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom));
updateQWidget();
}
else if (event->key() == Qt::Key_Minus) {
fVP.SetZoomFactor(fVP.GetZoomFactor()*(1-fDeltaZoom));
updateQWidget();
}
}
if (event->key() == Qt::Key_Escape) { // escaped from full screen
#if QT_VERSION >= 0x030200
toggleFullScreen(false);
#endif
}
// several case here : If return is pressed, in every case -> display the movie parameters dialog
// If one parameter is wrong -> put it in red (only save filenam could be wrong..)
// If encoder not found-> does nothing.Only display a message in status box
// If all ok-> generate parameter file
// If ok -> put encoder button enabled
if ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter)){ // end of video
stopVideo();
}
if (event->key() == Qt::Key_Space){ // start/pause of video
startPauseVideo();
}
// with no modifiers
#if QT_VERSION < 0x040000
if (event->state() == Qt::NoButton) {
updateKeyModifierState(event->state());
if (fNoKeyPress) {
#else
if ((event->modifiers() == Qt::NoModifier) || (event->modifiers() == Qt::KeypadModifier )) {
updateKeyModifierState(event->modifiers());
if ((fNoKeyPress) || (event->modifiers() == Qt::KeypadModifier )) {
#endif
if (event->key() == Qt::Key_Down) { // go down
moveScene(0,1,0,false);
@@ -1807,11 +1904,148 @@ void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event)
else if (event->key() == Qt::Key_Right) { // go right
moveScene(1,0,0,false);
}
if (event->key() == Qt::Key_Minus) { // go backward
moveScene(0,0,1,false);
}
else if (event->key() == Qt::Key_Plus) { // go forward
moveScene(0,0,-1,false);
}
// escaped from full screen
if (event->key() == Qt::Key_Escape) {
#if QT_VERSION >= 0x030200
toggleFullScreen(false);
#endif
}
}
// several case here : If return is pressed, in every case -> display the movie parameters dialog
// If one parameter is wrong -> put it in red (only save filenam could be wrong..)
// If encoder not found-> does nothing.Only display a message in status box
// If all ok-> generate parameter file
// If ok -> put encoder button enabled
if ((event->key() == Qt::Key_Return) || (event->key() == Qt::Key_Enter)){ // end of video
stopVideo();
}
if (event->key() == Qt::Key_Space){ // start/pause of video
startPauseVideo();
}
// H : Return Home view
if (event->key() == Qt::Key_H){ // go Home
fDeltaRotation = 1;
fDeltaSceneTranslation = 0.01;
fDeltaDepth = 0.01;
fDeltaZoom = 0.05;
fDeltaMove = 0.05;
fVP.SetZoomFactor(1.);
fVP.SetUpVector(G4Vector3D (0., 1., 0.));
fVP.SetViewAndLights (G4Vector3D (0., 0., 1.));
updateQWidget();
}
// Shift Modifier
if (fShiftKeyPress) {
if (event->key() == Qt::Key_Down) { // rotate phi
rotateQtScene(0,-fDeltaRotation);
}
else if (event->key() == Qt::Key_Up) { // rotate phi
rotateQtScene(0,fDeltaRotation);
}
if (event->key() == Qt::Key_Left) { // rotate theta
rotateQtScene(fDeltaRotation,0);
}
else if (event->key() == Qt::Key_Right) { // rotate theta
rotateQtScene(-fDeltaRotation,0);
}
// Alt Modifier
}
if ((fAltKeyPress)) {
if (event->key() == Qt::Key_Down) { // rotate phi
rotateQtSceneInViewDirection(0,-fDeltaRotation);
}
else if (event->key() == Qt::Key_Up) { // rotate phi
rotateQtSceneInViewDirection(0,fDeltaRotation);
}
if (event->key() == Qt::Key_Left) { // rotate theta
rotateQtSceneInViewDirection(fDeltaRotation,0);
}
else if (event->key() == Qt::Key_Right) { // rotate theta
rotateQtSceneInViewDirection(-fDeltaRotation,0);
}
// Rotatio +/-
if (event->key() == Qt::Key_Plus) {
fDeltaRotation = fDeltaRotation/0.7;
G4cout << "Auto-rotation set to : " << fDeltaRotation << G4endl;
}
else if (event->key() == Qt::Key_Minus) {
fDeltaRotation = fDeltaRotation*0.7;
G4cout << "Auto-rotation set to : " << fDeltaRotation << G4endl;
}
// Control Modifier OR Command on MAC
}
if ((fControlKeyPress)) {
if (event->key() == Qt::Key_Plus) {
fVP.SetZoomFactor(fVP.GetZoomFactor()*(1+fDeltaZoom));
updateQWidget();
}
else if (event->key() == Qt::Key_Minus) {
fVP.SetZoomFactor(fVP.GetZoomFactor()*(1-fDeltaZoom));
updateQWidget();
}
}
fHoldKeyEvent = false;
}
#if QT_VERSION < 0x040000
void G4OpenGLQtViewer::updateKeyModifierState(Qt::ButtonState modifier) {
#else
void G4OpenGLQtViewer::updateKeyModifierState(Qt::KeyboardModifiers modifier) {
#endif
// Check Qt Versions for META Keys
fNoKeyPress = true;
fAltKeyPress = false;
fShiftKeyPress = false;
fControlKeyPress = false;
#if QT_VERSION < 0x040000
if (modifier & Qt::AltButton ) {
fAltKeyPress = true;
fNoKeyPress = false;
}
if (modifier & Qt::ShiftButton ) {
fShiftKeyPress = true;
fNoKeyPress = false;
}
if (modifier & Qt::ControlButton ) {
fControlKeyPress = true;
fNoKeyPress = false;
}
#else
if (modifier & Qt::AltModifier ) {
fAltKeyPress = true;
fNoKeyPress = false;
}
if (modifier & Qt::ShiftModifier ) {
fShiftKeyPress = true;
fNoKeyPress = false;
}
if (modifier & Qt::ControlModifier ) {
fControlKeyPress = true;
fNoKeyPress = false;
}
#endif
}
/** Stop the video. Check all parameters and enable encoder button if all is ok.
*/
void G4OpenGLQtViewer::stopVideo() {
@@ -2606,7 +2840,8 @@ QWidget *G4OpenGLQtViewer::getParentWidget()
{
// launch Qt if not
G4Qt* interactorManager = G4Qt::getInstance ();
// G4UImanager* UI = G4UImanager::GetUIpointer();
// G4UImanager* UI =
G4UImanager::GetUIpointer();
bool found = false;
@@ -2647,6 +2882,9 @@ QWidget *G4OpenGLQtViewer::getParentWidget()
printf("G4OpenGLQtViewer::CreateMainWindow case Qapp exist\n");
#endif
fGLWindow = new QDialog();
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLQtViewer::GetParentWidget fGLWindow\n");
#endif
}
if (found) {
return fGLWindow;
@@ -24,8 +24,8 @@
// ********************************************************************
//
//
// $Id: G4OpenGLSceneHandler.cc,v 1.56 2009/10/21 15:18:43 allison Exp $
// GEANT4 tag $Name: geant4-09-03 $
// $Id: G4OpenGLSceneHandler.cc,v 1.59 2010/05/30 09:53:05 allison Exp $
// GEANT4 tag $Name: geant4-09-04-beta-01 $
//
//
// Andrew Walkden 27th March 1996
@@ -137,24 +137,24 @@ void G4OpenGLSceneHandler::EndPrimitives2D ()
G4VSceneHandler::EndPrimitives2D ();
}
const G4Polyhedron* G4OpenGLSceneHandler::CreateSectionPolyhedron ()
G4VSolid* G4OpenGLSceneHandler::CreateSectionSolid ()
{
// Clipping done in G4OpenGLViewer::SetView.
return 0;
// return 0;
// But...OpenGL no longer seems to reconstruct clipped edges, so,
// when the BooleanProcessor is up to it, abandon this and use
// generic clipping in G4VSceneHandler::CreateSectionPolyhedron...
// return G4VSceneHandler::CreateSectionPolyhedron();
// generic clipping in G4VSceneHandler::CreateSectionSolid...
return G4VSceneHandler::CreateSectionSolid();
}
const G4Polyhedron* G4OpenGLSceneHandler::CreateCutawayPolyhedron ()
G4VSolid* G4OpenGLSceneHandler::CreateCutawaySolid ()
{
// Cutaway done in G4OpenGLViewer::SetView.
return 0;
// return 0;
// But...if not, when the BooleanProcessor is up to it...
// return G4VSceneHandler::CreateCutawayPolyhedron();
return G4VSceneHandler::CreateCutawaySolid();
}
void G4OpenGLSceneHandler::AddPrimitive (const G4Polyline& line)
@@ -224,20 +224,27 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
break;
case G4Polymarker::circles:
{
std::vector <G4VMarker> circleV;
for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
G4Circle circle (polymarker);
// If not already drawn
circle.SetPosition (polymarker[iPoint]);
G4OpenGLSceneHandler::AddPrimitive (circle);
circleV.push_back(circle);
// G4OpenGLSceneHandler::AddPrimitive (circle);
}
G4OpenGLSceneHandler::AddPrimitives (circleV);
}
break;
case G4Polymarker::squares:
{
std::vector <G4VMarker> squareV;
for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
G4Square square (polymarker);
square.SetPosition (polymarker[iPoint]);
G4OpenGLSceneHandler::AddPrimitive (square);
squareV.push_back(square);
// G4OpenGLSceneHandler::AddPrimitive (square);
}
G4OpenGLSceneHandler::AddPrimitives (squareV);
}
break;
}
@@ -303,35 +310,55 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Square& square) {
AddCircleSquare (square, G4OpenGLBitMapStore::square);
}
void G4OpenGLSceneHandler::AddPrimitives (std::vector <G4VMarker> square) {
glDisable (GL_POINT_SMOOTH);
AddCircleSquareVector (square, G4OpenGLBitMapStore::square);
}
void G4OpenGLSceneHandler::AddCircleSquare
(const G4VMarker& marker,
G4OpenGLBitMapStore::Shape shape) {
std::vector <G4VMarker> circleVector;
circleVector.push_back(marker);
AddCircleSquareVector(circleVector,shape);
}
void G4OpenGLSceneHandler::AddCircleSquareVector
(std::vector <G4VMarker> marker,
G4OpenGLBitMapStore::Shape shape) {
if (marker.size() == 0) {
return;
}
if (!fProcessingPolymarker) { // Polymarker has already loaded atts.
// Loads G4Atts for picking...
if (fpViewer->GetViewParameters().IsPicking()) {
G4AttHolder* holder = new G4AttHolder;
LoadAtts(marker, holder);
LoadAtts(marker[0], holder);
fPickMap[fPickName] = holder;
}
}
// Note: colour treated in sub-class.
if (fpViewer -> GetViewParameters ().IsMarkerNotHidden ())
if (fpViewer -> GetViewParameters ().IsMarkerNotHidden ()) {
glDisable (GL_DEPTH_TEST);
else {glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LESS);}
} else {
glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LESS);
}
glDisable (GL_LIGHTING);
// Get vis attributes - pick up defaults if none.
const G4VisAttributes* pVA =
fpViewer -> GetApplicableVisAttributes (marker.GetVisAttributes ());
fpViewer -> GetApplicableVisAttributes (marker[0].GetVisAttributes ());
G4double lineWidth = GetLineWidth(pVA);
glLineWidth(lineWidth);
G4VMarker::FillStyle style = marker.GetFillStyle();
G4VMarker::FillStyle style = marker[0].GetFillStyle();
G4bool filled = false;
static G4bool hashedWarned = false;
@@ -360,20 +387,27 @@ void G4OpenGLSceneHandler::AddCircleSquare
}
// A few useful quantities...
G4Point3D centre = marker.GetPosition();
MarkerSizeType sizeType;
G4double size = GetMarkerSize(marker, sizeType);
G4double size = GetMarkerSize(marker[0], sizeType);
// Draw...
if (sizeType == world) { // Size specified in world coordinates.
DrawXYPolygon (shape, size, centre, pVA);
for (unsigned int a=0;a<marker.size();a++) {
G4Point3D centre = marker[a].GetPosition();
// A few useful quantities...
DrawXYPolygon (shape, size, centre, pVA);
}
} else { // Size specified in screen (window) coordinates.
glPointSize (size);
// A few useful quantities...
glPointSize (size);
glBegin (GL_POINTS);
glVertex3f(centre.x(),centre.y(),centre.z());
for (unsigned int a=0;a<marker.size();a++) {
G4Point3D centre = marker[a].GetPosition();
glVertex3f(centre.x(),centre.y(),centre.z());
}
glEnd();
//Antialiasing
glEnable (GL_POINT_SMOOTH);
@@ -844,6 +878,10 @@ void G4OpenGLSceneHandler::AddCompound(const G4VHit& hit) {
G4VSceneHandler::AddCompound(hit); // For now.
}
void G4OpenGLSceneHandler::AddCompound(const G4VDigi& digi) {
G4VSceneHandler::AddCompound(digi); // For now.
}
void G4OpenGLSceneHandler::AddCompound(const G4THitsMap<G4double>& hits) {
G4VSceneHandler::AddCompound(hits); // For now.
}
@@ -24,8 +24,8 @@
// ********************************************************************
//
//
// $Id: G4OpenGLStoredQtViewer.cc,v 1.28 2009/11/03 11:02:32 lgarnier Exp $
// GEANT4 tag $Name: geant4-09-03 $
// $Id: G4OpenGLStoredQtViewer.cc,v 1.32 2010/06/23 13:29:23 lgarnier Exp $
// GEANT4 tag $Name: geant4-09-04 $
//
//
// Class G4OpenGLStoredQtViewer : a class derived from G4OpenGLQtViewer and
@@ -52,7 +52,8 @@ G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
#else
setFocusPolicy(Qt::StrongFocus); // enable keybord events
#endif
fHasToRepaint =false;
fHasToRepaint = false;
fIsRepainting = false;
if (fViewId < 0) return; // In case error in base class instantiation.
}
@@ -69,7 +70,7 @@ void G4OpenGLStoredQtViewer::Initialise() {
printf("G4OpenGLStoredQtViewer::Initialise 1\n");
#endif
fReadyToPaint = false;
CreateMainWindow (this,QString(fName));
CreateMainWindow (this,QString(GetName()));
CreateFontLists ();
fReadyToPaint = true;
@@ -102,20 +103,8 @@ void G4OpenGLStoredQtViewer::initializeGL () {
}
void G4OpenGLStoredQtViewer::DrawView () {
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLStoredQtViewer::DrawView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
#endif
// That's no the same logic as Immediate Viewer, I don't know why...
// But if I send updateGL here, we go here :
// updateQWidget -> paintGL -> ComputeView
// whih is not the same as ComputeView Directly
// And we loose the redraw of things !
ComputeView();
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLStoredQtViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
#endif
void G4OpenGLStoredQtViewer::DrawView () {
updateQWidget();
}
void G4OpenGLStoredQtViewer::ComputeView () {
@@ -192,7 +181,7 @@ void G4OpenGLStoredQtViewer::ComputeView () {
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLStoredQtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
#endif
fHasToRepaint =true;
fHasToRepaint = true;
}
@@ -204,13 +193,27 @@ void G4OpenGLStoredQtViewer::resizeGL(
,int aHeight)
{
// Set new size, it will be update when next Repaint()->SetView() called
ResizeWindow(aWidth,aHeight);
fHasToRepaint = sizeHasChanged();
if ((aWidth > 0) && (aHeight > 0)) {
ResizeWindow(aWidth,aHeight);
fHasToRepaint = sizeHasChanged();
}
}
// We have to get several case :
// - Only activate the windows (mouse click for example) -> Do not redraw
// - resize window -> redraw
// - try to avoid recompute everything if we do not rescale picture (side is the same)
void G4OpenGLStoredQtViewer::paintGL()
{
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLStoredQtViewer::paintGL \n");
#endif
if (fIsRepainting) {
// return ;
}
fIsRepainting = true;
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLStoredQtViewer::paintGL ready:%d fHasTo:%d??\n",fReadyToPaint,fHasToRepaint);
#endif
@@ -246,15 +249,22 @@ void G4OpenGLStoredQtViewer::paintGL()
#endif
SetView();
ClearView (); //ok, put the background correct
ComputeView();
fHasToRepaint =false;
fHasToRepaint = false;
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLStoredQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n",fReadyToPaint);
#endif
fIsRepainting = false;
}
void G4OpenGLStoredQtViewer::paintEvent(QPaintEvent *) {
if ( fHasToRepaint) {
updateGL();
}
}
void G4OpenGLStoredQtViewer::mousePressEvent(QMouseEvent *event)
@@ -272,6 +282,11 @@ void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event)
G4wheelEvent(event);
}
void G4OpenGLStoredQtViewer::showEvent (QShowEvent *)
{
fHasToRepaint = true;
}
/**
* This function was build in order to make a zoom on double clic event.
* It was think to build a rubberband on the zoom area, but never work fine
@@ -24,8 +24,8 @@
// ********************************************************************
//
//
// $Id: G4OpenGLStoredSceneHandler.cc,v 1.40 2009/02/04 16:48:41 lgarnier Exp $
// GEANT4 tag $Name: geant4-09-03 $
// $Id: G4OpenGLStoredSceneHandler.cc,v 1.46 2010/11/10 17:11:20 allison Exp $
// GEANT4 tag $Name: geant4-09-04 $
//
//
// Andrew Walkden 10th February 1997
@@ -78,7 +78,6 @@ G4OpenGLStoredSceneHandler::G4OpenGLStoredSceneHandler
(G4VGraphicsSystem& system,
const G4String& name):
G4OpenGLSceneHandler (system, fSceneIdCount++, name),
fMemoryForDisplayLists (true),
fAddPrimitivePreambleNestingDepth (0),
fTopPODL (0)
{}
@@ -105,12 +104,15 @@ void G4OpenGLStoredSceneHandler::AddPrimitivePreamble(const G4Visible& visible)
if (fMemoryForDisplayLists) {
fDisplayListId = glGenLists (1);
if (glGetError() == GL_OUT_OF_MEMORY) { // Could pre-allocate?
if (glGetError() == GL_OUT_OF_MEMORY ||
fDisplayListId > fDisplayListLimit) {
G4cout <<
"********************* WARNING! ********************"
"\nUnable to allocate any more display lists in OpenGL."
"\n Continuing drawing in IMMEDIATE MODE."
"\n***************************************************"
"********************* WARNING! ********************"
"\n* Display list limit reached in OpenGL."
"\n* Continuing drawing WITHOUT STORING. Scene only partially refreshable."
"\n* Current limit: " << fDisplayListLimit <<
". Change with \"/vis/ogl/set/displayListLimit\"."
"\n***************************************************"
<< G4endl;
fMemoryForDisplayLists = false;
}
@@ -333,6 +335,8 @@ void G4OpenGLStoredSceneHandler::EndModeling () {
void G4OpenGLStoredSceneHandler::ClearStore () {
//G4cout << "G4OpenGLStoredSceneHandler::ClearStore" << G4endl;
G4VSceneHandler::ClearStore (); // Sets need kernel visit, etc.
// Delete OpenGL permanent display lists.
@@ -350,10 +354,14 @@ void G4OpenGLStoredSceneHandler::ClearStore () {
for (size_t i = 0; i < fTOList.size (); i++)
glDeleteLists(fTOList[i].fDisplayListId, 1);
fTOList.clear ();
fMemoryForDisplayLists = true;
}
void G4OpenGLStoredSceneHandler::ClearTransientStore () {
//G4cout << "G4OpenGLStoredSceneHandler::ClearTransientStore" << G4endl;
G4VSceneHandler::ClearTransientStore ();
// Delete OpenGL transient display lists and Transient Objects themselves.
@@ -361,6 +369,8 @@ void G4OpenGLStoredSceneHandler::ClearTransientStore () {
glDeleteLists(fTOList[i].fDisplayListId, 1);
fTOList.clear ();
fMemoryForDisplayLists = true;
// Make sure screen corresponds to graphical database...
if (fpViewer) {
fpViewer -> SetView ();
@@ -462,4 +472,8 @@ void G4OpenGLStoredSceneHandler::RequestPrimitives (const G4VSolid& solid)
G4int G4OpenGLStoredSceneHandler::fSceneIdCount = 0;
G4int G4OpenGLStoredSceneHandler::fDisplayListId = 0;
G4bool G4OpenGLStoredSceneHandler::fMemoryForDisplayLists = true;
G4int G4OpenGLStoredSceneHandler::fDisplayListLimit = 50000;
#endif
@@ -24,8 +24,8 @@
// ********************************************************************
//
//
// $Id: G4OpenGLStoredViewer.cc,v 1.26 2009/04/08 16:55:44 lgarnier Exp $
// GEANT4 tag $Name: geant4-09-03 $
// $Id: G4OpenGLStoredViewer.cc,v 1.29 2010/10/06 10:05:52 allison Exp $
// GEANT4 tag $Name: geant4-09-04 $
//
//
// Andrew Walkden 7th February 1997
@@ -87,6 +87,10 @@ G4bool G4OpenGLStoredViewer::CompareForKernelVisit(G4ViewParameters& lastVP) {
(lastVP.IsExplode () != fVP.IsExplode ()) ||
(lastVP.GetNoOfSides () != fVP.GetNoOfSides ()) ||
(lastVP.IsMarkerNotHidden () != fVP.IsMarkerNotHidden ()) ||
(lastVP.GetDefaultVisAttributes()->GetColour() !=
fVP.GetDefaultVisAttributes()->GetColour()) ||
(lastVP.GetDefaultTextVisAttributes()->GetColour() !=
fVP.GetDefaultTextVisAttributes()->GetColour()) ||
(lastVP.GetBackgroundColour ()!= fVP.GetBackgroundColour ())||
(lastVP.IsPicking () != fVP.IsPicking ())
)
@@ -155,7 +159,7 @@ void G4OpenGLStoredViewer::DrawDisplayLists () {
for (size_t i = 0; i < fG4OpenGLStoredSceneHandler.fTOList.size(); ++i) {
#ifdef G4DEBUG_VIS_OGL
printf("-");
// printf("-");
#endif
G4OpenGLStoredSceneHandler::TO& to =
fG4OpenGLStoredSceneHandler.fTOList[i];
@@ -164,12 +168,16 @@ void G4OpenGLStoredViewer::DrawDisplayLists () {
G4OpenGLTransform3D oglt (to.fTransform);
glMultMatrixd (oglt.GetGLMatrix ());
if (fVP.IsPicking()) glLoadName(to.fPickName);
G4Colour& c = to.fColour;
const G4Colour& c = to.fColour;
const G4Colour& bg = fVP.GetBackgroundColour();
G4double bsf = 1.; // Brightness scaling factor.
if (fFadeFactor > 0. && to.fEndTime < fEndTime)
bsf = 1. - fFadeFactor *
((fEndTime - to.fEndTime) / (fEndTime - fStartTime));
glColor3d(bsf * c.GetRed (), bsf * c.GetGreen (), bsf * c.GetBlue ());
glColor3d
(bsf * c.GetRed() + (1. - bsf) * bg.GetRed(),
bsf * c.GetGreen() + (1. - bsf) * bg.GetGreen(),
bsf * c.GetBlue() + (1. - bsf) * bg.GetBlue());
glCallList (to.fDisplayListId);
glPopMatrix();
}
@@ -24,8 +24,8 @@
// ********************************************************************
//
//
// $Id: G4OpenGLStoredXViewer.cc,v 1.25 2009/04/08 16:55:44 lgarnier Exp $
// GEANT4 tag $Name: geant4-09-03 $
// $Id: G4OpenGLStoredXViewer.cc,v 1.27 2010/06/03 08:26:55 allison Exp $
// GEANT4 tag $Name: geant4-09-04-beta-01 $
//
//
// Andrew Walkden 7th February 1997
@@ -24,8 +24,8 @@
// ********************************************************************
//
//
// $Id: G4OpenGLStoredXmViewer.cc,v 1.25 2009/04/08 16:55:44 lgarnier Exp $
// GEANT4 tag $Name: geant4-09-03 $
// $Id: G4OpenGLStoredXmViewer.cc,v 1.26 2010/04/30 13:18:32 lgarnier Exp $
// GEANT4 tag $Name: geant4-09-04-beta-01 $
//
//
// Andrew Walkden 10th February 1997
@@ -57,7 +57,9 @@ G4OpenGLStoredXmViewer (G4OpenGLStoredSceneHandler& sceneHandler,
}
}
G4OpenGLStoredXmViewer::~G4OpenGLStoredXmViewer () {}
G4OpenGLStoredXmViewer::~G4OpenGLStoredXmViewer () {
GetSceneHandler()->RemoveViewerFromList(this);
}
void G4OpenGLStoredXmViewer::Initialise () {
+121 -67
View File
@@ -24,8 +24,8 @@
// ********************************************************************
//
//
// $Id: G4OpenGLViewer.cc,v 1.59 2009/10/20 12:47:45 lgarnier Exp $
// GEANT4 tag $Name: geant4-09-03 $
// $Id: G4OpenGLViewer.cc,v 1.63 2010/10/05 15:45:19 lgarnier Exp $
// GEANT4 tag $Name: geant4-09-04 $
//
//
// Andrew Walkden 27th March 1996
@@ -156,54 +156,26 @@ void G4OpenGLViewer::ResizeWindow(unsigned int aWidth, unsigned int aHeight) {
void G4OpenGLViewer::ResizeGLView()
{
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLViewer::ResizeGLView %d %d\n",fWinSize_x,fWinSize_y);
printf("G4OpenGLViewer::ResizeGLView %d %d &:%d\n",fWinSize_x,fWinSize_y,this);
#endif
// Check size
GLint dims[2];
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, dims);
if (fWinSize_x > (unsigned)dims[0]) {
G4cerr << "Try to resize view greater than max X viewport dimension. Desired size "<<dims[0] <<" is resize to "<< dims[0] << G4endl;
fWinSize_x = dims[0];
}
if (fWinSize_y > (unsigned)dims[1]) {
G4cerr << "Try to resize view greater than max Y viewport dimension. Desired size "<<dims[0] <<" is resize to "<< dims[1] << G4endl;
fWinSize_y = dims[1];
}
GLsizei side = fWinSize_x;
if (fWinSize_y < fWinSize_x) side = fWinSize_y;
// SPECIAL CASE if fWinSize_x is even (69 for example)
// Ex : X: 69 Y: 26
// side = 26
// width / 2 = 21,5
// height / 2 = 0
// Should be fixed to closed : 21 0 for ex
// Then size must by change to :
// X:68 Y: 26
if ((dims[0] !=0 ) && (dims[1] !=0)) {
// SPECIAL CASE
if ((fWinSize_x - side)%2) {
// fWinSize_x --;
side = fWinSize_x;
if (fWinSize_y < fWinSize_x) side = fWinSize_y;
if (fWinSize_x > (unsigned)dims[0]) {
G4cerr << "Try to resize view greater than max X viewport dimension. Desired size "<<dims[0] <<" is resize to "<< dims[0] << G4endl;
fWinSize_x = dims[0];
}
if (fWinSize_y > (unsigned)dims[1]) {
G4cerr << "Try to resize view greater than max Y viewport dimension. Desired size "<<dims[0] <<" is resize to "<< dims[1] << G4endl;
fWinSize_y = dims[1];
}
}
if ((fWinSize_y - side)%2) {
// fWinSize_y --;
glViewport(0, 0, fWinSize_x,fWinSize_y);
side = fWinSize_x;
if (fWinSize_y < fWinSize_x) side = fWinSize_y;
}
GLint X = (fWinSize_x - side) / 2;
GLint Y = (fWinSize_y - side) / 2;
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLViewer::ResizeGLView X:%d Y:%d W:%d H:%d --side%d\n",(fWinSize_x - side) / 2,(fWinSize_y - side) / 2,fWinSize_x,fWinSize_y,side);
#endif
glViewport(X, Y, side, side);
// glViewport(0, 0, fWinSize_x,fWinSize_y);
}
@@ -211,8 +183,6 @@ void G4OpenGLViewer::ResizeGLView()
void G4OpenGLViewer::SetView () {
if (!fSceneHandler.GetScene()) {
G4cerr << "G4OpenGLStoredViewer: Creating a Viewer without a scene is not allowed. \nPlease use /vis/scene/create before /vis/open/.... "
<< G4endl;
return;
}
// Calculates view representation based on extent of object being
@@ -232,6 +202,15 @@ void G4OpenGLViewer::SetView () {
glLightfv (GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse);
G4double ratioX = 1;
G4double ratioY = 1;
if (fWinSize_y > fWinSize_x) {
ratioX = ((G4double)fWinSize_y) / ((G4double)fWinSize_x);
}
if (fWinSize_x > fWinSize_y) {
ratioY = ((G4double)fWinSize_x) / ((G4double)fWinSize_y);
}
// Get radius of scene, etc.
// Note that this procedure properly takes into account zoom, dolly and pan.
const G4Point3D targetPoint
@@ -244,10 +223,10 @@ void G4OpenGLViewer::SetView () {
targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
const GLdouble pnear = fVP.GetNearDistance (cameraDistance, radius);
const GLdouble pfar = fVP.GetFarDistance (cameraDistance, pnear, radius);
const GLdouble right = fVP.GetFrontHalfHeight (pnear, radius);
const GLdouble right = fVP.GetFrontHalfHeight (pnear, radius) * ratioY;
const GLdouble left = -right;
const GLdouble bottom = left;
const GLdouble top = right;
const GLdouble top = fVP.GetFrontHalfHeight (pnear, radius) * ratioX;
const GLdouble bottom = -top;
// FIXME
ResizeGLView();
@@ -291,7 +270,8 @@ void G4OpenGLViewer::SetView () {
// clipping in G4OpenGLSceneHandler::CreateSectionPolyhedron. Also,
// force kernel visit on change of clipping plane in
// G4OpenGLStoredViewer::CompareForKernelVisit.
if (fVP.IsSection () ) { // pair of back to back clip planes.
//if (fVP.IsSection () ) { // pair of back to back clip planes.
if (false) { // pair of back to back clip planes.
const G4Plane3D& s = fVP.GetSectionPlane ();
double sArray[4];
sArray[0] = s.a();
@@ -313,7 +293,8 @@ void G4OpenGLViewer::SetView () {
const G4Planes& cutaways = fVP.GetCutawayPlanes();
size_t nPlanes = cutaways.size();
if (fVP.IsCutaway() &&
//if (fVP.IsCutaway() &&
if (false &&
fVP.GetCutawayMode() == G4ViewParameters::cutawayIntersection &&
nPlanes > 0) {
double a[4];
@@ -404,14 +385,14 @@ void G4OpenGLViewer::Pick(GLdouble x, GLdouble y)
DrawView();
GLint hits = glRenderMode(GL_RENDER);
if (hits < 0)
G4cout << "Too many hits. Zoom in to reduce overlaps." << G4cout;
G4cout << "Too many hits. Zoom in to reduce overlaps." << G4endl;
else if (hits > 0) {
//G4cout << hits << " hit(s)" << G4endl;
GLuint* p = selectBuffer;
for (GLint i = 0; i < hits; ++i) {
GLuint nnames = *p++;
*p++; //OR GLuint zmin = *p++;
*p++; //OR GLuint zmax = *p++;
p++; //OR GLuint zmin = *p++;
p++; //OR GLuint zmax = *p++;
//G4cout << "Hit " << i << ": " << nnames << " names"
// << "\nzmin: " << zmin << ", zmax: " << zmax << G4endl;
for (GLuint j = 0; j < nnames; ++j) {
@@ -498,7 +479,8 @@ void G4OpenGLViewer::printEPS() {
// Change the LC_NUMERIC value in order to have "." separtor and not ","
// This case is only useful for French, Canadien...
char *oldLocale = strdup(setlocale(LC_NUMERIC,NULL));
char* oldLocale = (char*)(malloc(strlen(setlocale(LC_NUMERIC,NULL))+1));
if(oldLocale!=NULL) strcpy(oldLocale,setlocale(LC_NUMERIC,NULL));
setlocale(LC_NUMERIC,"C");
if (fVectoredPs) {
@@ -524,6 +506,9 @@ void G4OpenGLViewer::printEPS() {
fPrintFilenameIndex++;
}
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLViewer::printEPS END\n");
#endif
}
bool G4OpenGLViewer::printVectoredEPS() {
@@ -536,7 +521,7 @@ bool G4OpenGLViewer::printNonVectoredEPS () {
int height = getRealPrintSizeY();
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLViewer::printNonVectoredEPS file:%s Vec:%d X:%d Y:%d col:%d\n",getRealPrintFilename().c_str(),fVectoredPs,width,height,fPrintColour);
printf("G4OpenGLViewer::printNonVectoredEPS file:%s Vec:%d X:%d Y:%d col:%d fWinX:%d fWinY:%d\n",getRealPrintFilename().c_str(),fVectoredPs,width,height,fPrintColour,fWinSize_x,fWinSize_y);
#endif
FILE* fp;
GLubyte* pixels;
@@ -633,9 +618,20 @@ bool G4OpenGLViewer::printGl2PS() {
fWinSize_x = width;
fWinSize_y = height;
// Laurent G. 16/03/10 : Not the good way to do.
// We should draw in a new offscreen context instead of
// resizing and drawing in current window...
// This should be solve when we will do an offscreen method
// to render OpenGL
// See :
// http://developer.apple.com/Mac/library/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_offscreen/opengl_offscreen.html
// http://www.songho.ca/opengl/gl_fbo.html
ResizeGLView();
if (fGL2PSAction->enableFileWriting()) {
// Set the viewport
// fGL2PSAction->setViewport(0, 0, getRealPrintSizeX(),getRealPrintSizeY());
// By default, we choose the line width (trajectories...)
fGL2PSAction->setLineWidth(1);
// By default, we choose the point size (markers...)
@@ -648,6 +644,7 @@ bool G4OpenGLViewer::printGl2PS() {
fWinSize_x = X;
fWinSize_y = Y;
ResizeGLView();
DrawView ();
// Reset for next time (useful is size change)
// fPrintSizeX = 0;
@@ -674,8 +671,12 @@ G4int G4OpenGLViewer::getRealPrintSizeX() {
}
GLint dims[2];
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, dims);
if (fPrintSizeX > dims[0]){
return dims[0];
// L.Garnier 01-2010: Some problems with mac 10.6
if ((dims[0] !=0 ) && (dims[1] !=0)) {
if (fPrintSizeX > dims[0]){
return dims[0];
}
}
if (fPrintSizeX < -1){
return 0;
@@ -689,8 +690,12 @@ G4int G4OpenGLViewer::getRealPrintSizeY() {
}
GLint dims[2];
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, dims);
if (fPrintSizeY > dims[1]){
return dims[1];
// L.Garnier 01-2010: Some problems with mac 10.6
if ((dims[0] !=0 ) && (dims[1] !=0)) {
if (fPrintSizeY > dims[1]){
return dims[1];
}
}
if (fPrintSizeY < -1){
return 0;
@@ -731,6 +736,9 @@ std::string G4OpenGLViewer::getRealPrintFilename() {
GLdouble G4OpenGLViewer::getSceneNearWidth()
{
if (!fSceneHandler.GetScene()) {
return 0;
}
const G4Point3D targetPoint
= fSceneHandler.GetScene()->GetStandardTargetPoint()
+ fVP.GetCurrentTargetPoint ();
@@ -743,6 +751,9 @@ GLdouble G4OpenGLViewer::getSceneNearWidth()
GLdouble G4OpenGLViewer::getSceneFarWidth()
{
if (!fSceneHandler.GetScene()) {
return 0;
}
const G4Point3D targetPoint
= fSceneHandler.GetScene()->GetStandardTargetPoint()
+ fVP.GetCurrentTargetPoint ();
@@ -757,6 +768,9 @@ GLdouble G4OpenGLViewer::getSceneFarWidth()
GLdouble G4OpenGLViewer::getSceneDepth()
{
if (!fSceneHandler.GetScene()) {
return 0;
}
const G4Point3D targetPoint
= fSceneHandler.GetScene()->GetStandardTargetPoint()
+ fVP.GetCurrentTargetPoint ();
@@ -821,15 +835,6 @@ void G4OpenGLViewer::rotateScene(G4double dx, G4double dy,G4double deltaRotation
// to avoid z rotation flipping
// to allow more than 360° rotation
const G4Point3D targetPoint
= fSceneHandler.GetScene()->GetStandardTargetPoint()
+ fVP.GetCurrentTargetPoint ();
G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
if(radius<=0.) radius = 1.;
const G4double cameraDistance = fVP.GetCameraDistance (radius);
const G4Point3D cameraPosition =
targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
if (fVP.GetLightsMoveWithCamera()) {
new_up = (new_vp.cross(yprime)).unit();
if (new_vp.z()*vp.z() <0) {
@@ -861,4 +866,53 @@ void G4OpenGLViewer::rotateScene(G4double dx, G4double dy,G4double deltaRotation
fVP.SetViewAndLights (viewPoint);
}
void G4OpenGLViewer::rotateSceneInViewDirection(G4double dx, G4double dy,G4double deltaRotation)
{
if (!fSceneHandler.GetScene()) {
return;
}
G4Vector3D vp;
G4Vector3D up;
G4Vector3D xprime;
G4Vector3D yprime;
G4Vector3D zprime;
G4Vector3D new_vp;
G4Vector3D new_up;
G4Vector3D a1;
G4Vector3D a2;
G4Vector3D delta;
G4Vector3D viewPoint;
//phi spin stuff here
#ifdef G4DEBUG_VIS_OGL
printf("G4OpenGLViewer::rotateScene dx:%f dy:%f delta:%f\n",dx,dy, deltaRotation);
#endif
vp = fVP.GetViewpointDirection ().unit();
up = fVP.GetUpVector ().unit();
G4Vector3D zPrimeVector = G4Vector3D(up.y()*vp.z()-up.z()*vp.y(),
up.z()*vp.x()-up.x()*vp.z(),
up.x()*vp.y()-up.y()*vp.x());
viewPoint = vp/deltaRotation + (zPrimeVector*dx - up*dy) ;
new_up = G4Vector3D(viewPoint.y()*zPrimeVector.z()-viewPoint.z()*zPrimeVector.y(),
viewPoint.z()*zPrimeVector.x()-viewPoint.x()*zPrimeVector.z(),
viewPoint.x()*zPrimeVector.y()-viewPoint.y()*zPrimeVector.x());
G4Vector3D new_upUnit = new_up.unit();
fVP.SetUpVector(new_upUnit);
fVP.SetViewAndLights (viewPoint);
}
#endif
@@ -24,8 +24,8 @@
// ********************************************************************
//
//
// $Id: G4OpenGLViewerMessenger.cc,v 1.18 2009/05/14 16:38:23 lgarnier Exp $
// GEANT4 tag $Name: geant4-09-03 $
// $Id: G4OpenGLViewerMessenger.cc,v 1.21 2010/11/07 10:31:26 allison Exp $
// GEANT4 tag $Name: geant4-09-04 $
#ifdef G4VIS_BUILD_OPENGL_DRIVER
@@ -40,6 +40,7 @@
#include "G4UIcmdWithADouble.hh"
#include "G4UIcmdWithABool.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWithAnInteger.hh"
#include "G4VisManager.hh"
#include <sstream>
@@ -178,6 +179,14 @@ G4OpenGLViewerMessenger::G4OpenGLViewerMessenger()
parameter->SetDefaultValue(0.);
fpCommandDisplayLightFront->SetParameter(parameter);
fpCommandDisplayListLimit =
new G4UIcmdWithAnInteger("/vis/ogl/set/displayListLimit", this);
fpCommandDisplayListLimit->SetGuidance
("Set/reset display list limit (to avoid memory exhaustion).");
fpCommandDisplayListLimit->SetParameterName("limit", omitable = true);
fpCommandDisplayListLimit->SetDefaultValue(50000);
fpCommandDisplayListLimit->SetRange("limit>=10000");
fpCommandEndTime =
new G4UIcommand("/vis/ogl/set/endTime", this);
fpCommandEndTime->SetGuidance("Set end and range of track time.");
@@ -240,6 +249,7 @@ G4OpenGLViewerMessenger::~G4OpenGLViewerMessenger ()
delete fpCommandStartTime;
delete fpCommandFade;
delete fpCommandEndTime;
delete fpCommandDisplayListLimit;
delete fpCommandDisplayLightFront;
delete fpCommandDisplayHeadTime;
delete fpDirectorySet;
@@ -269,7 +279,9 @@ void G4OpenGLViewerMessenger::SetNewValue
if (!pOGLViewer) {
G4cout <<
"G4OpenGLViewerMessenger::SetNewValue: Current viewer is not of type"
"\n OGL. Use \"/vis/viewer/select\" or \"/vis/open\"."
"\n OGL. (It is \""
<< pViewer->GetName() <<
"\".)\n Use \"/vis/viewer/select\" or \"/vis/open\"."
<< G4endl;
return;
}
@@ -321,8 +333,9 @@ void G4OpenGLViewerMessenger::SetNewValue
{
G4cout <<
"G4OpenGLViewerMessenger::SetNewValue: Current viewer is not of type OGLS."
"\n The time slice viewing feature is only implemented for OGL Stored"
"\n viewers at present. Use \"/vis/viewer/select\" or \"/vis/open OGLS...\"."
"\n (It is \"" << pViewer->GetName() << "\".)"
"\n This feature is only implemented for OGL Stored viewers."
"\n Use \"/vis/viewer/select\" or \"/vis/open OGLS...\"."
<< G4endl;
return;
}
@@ -413,6 +426,52 @@ void G4OpenGLViewerMessenger::SetNewValue
return;
}
G4VSceneHandler* pSceneHandler = pViewer->GetSceneHandler();
if (!pSceneHandler) {
G4cout <<
"G4OpenGLViewerMessenger::SetNewValue: This viewer has no scene handler."
"\n Shouldn't happen - please report circumstances."
"\n (Viewer is \"" << pViewer->GetName() << "\".)"
"\n Try \"/vis/open\", or similar, to get one."
<< G4endl;
return;
}
G4OpenGLSceneHandler* pOGLSceneHandler =
dynamic_cast<G4OpenGLSceneHandler*>(pSceneHandler);
if (!pOGLSceneHandler) {
G4cout <<
"G4OpenGLViewerMessenger::SetNewValue: Current scene handler is not of type"
"\n OGL. (Viewer is \"" << pViewer->GetName() << "\".)"
"\n (Scene handler is \"" << pSceneHandler->GetName() << "\".)"
"\n Use \"/vis/sceneHandler/list\" and \"/vis/sceneHandler/select\""
"\n or \"/vis/open\"."
<< G4endl;
return;
}
G4OpenGLStoredSceneHandler* pOGLSSceneHandler =
dynamic_cast<G4OpenGLStoredSceneHandler*>(pViewer->GetSceneHandler());
if (!pOGLSSceneHandler) {
G4cout <<
"G4OpenGLViewerMessenger::SetNewValue: Current scene handler is not of type"
"\n OGLS (Stored). (Viewer is \"" << pViewer->GetName() << "\".)"
"\n (Scene handler is \"" << pSceneHandler->GetName() << "\".)"
"\n This feature is only implemented for OGL Stored"
"\n scene handlers. Use \"/vis/viewer/select\" or \"/vis/open OGLS...\"."
<< G4endl;
return;
}
if (command == fpCommandDisplayListLimit)
{
G4int displayListLimit =
fpCommandDisplayListLimit->GetNewIntValue(newValue);
pOGLSSceneHandler->SetDisplayListLimit(displayListLimit);
}
}
#endif
@@ -24,8 +24,8 @@
// ********************************************************************
//
//
// $Id: G4OpenGLXViewer.cc,v 1.55 2009/05/13 10:28:00 lgarnier Exp $
// GEANT4 tag $Name: geant4-09-03 $
// $Id: G4OpenGLXViewer.cc,v 1.56 2010/11/10 17:57:16 allison Exp $
// GEANT4 tag $Name: geant4-09-04 $
//
//
// Andrew Walkden 7th February 1997
@@ -49,6 +49,7 @@
#include "G4Point3D.hh"
#include "G4Normal3D.hh"
#include "G4StateManager.hh"
#include "G4VisManager.hh"
#include <X11/Xatom.h>
#include <X11/Xutil.h>
@@ -196,24 +197,28 @@ void G4OpenGLXViewer::CreateGLXContext (XVisualInfo* v) {
}
if (!cmap) {
fViewId = -1; // This flags an error.
G4cerr <<
"G4OpenGLViewer::G4OpenGLViewer failed to allocate a standard colormap."
<< G4endl;
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cerr <<
"G4OpenGLViewer::G4OpenGLViewer failed to allocate a standard colormap."
<< G4endl;
return;
}
G4cout << "Got standard cmap" << G4endl;
if (G4VisManager::GetVerbosity() >= G4VisManager::confirmations)
G4cout << "Got standard cmap" << G4endl;
} else {
cmap = XCreateColormap (dpy,
XRootWindow(dpy, vi -> screen),
vi -> visual,
AllocNone);
G4cout << "Created own cmap" << G4endl;
if (G4VisManager::GetVerbosity() >= G4VisManager::confirmations)
G4cout << "Created own cmap" << G4endl;
}
if (!cmap) {
fViewId = -1; // This flags an error.
G4cerr << "G4OpenGLViewer::G4OpenGLViewer failed to allocate a Colormap."
<< G4endl;
if (G4VisManager::GetVerbosity() >= G4VisManager::errors)
G4cout << "G4OpenGLViewer::G4OpenGLViewer failed to allocate a Colormap."
<< G4endl;
return;
}
@@ -249,7 +254,8 @@ void G4OpenGLXViewer::CreateMainWindow () {
} else if ((!fVP.IsWindowSizeHintX ()) && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) {
size_hints->flags |= PPosition;
}
G4cout << "Window name: " << fName << G4endl;
if (G4VisManager::GetVerbosity() >= G4VisManager::confirmations)
G4cout << "Window name: " << fName << G4endl;
strncpy (charViewName, fName, 100);
char *window_name = charViewName;
char *icon_name = charViewName;