Import Geant4 11.0.0.beta source tree
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_Qt_glarea
|
||||
#define tools_Qt_glarea
|
||||
|
||||
#include "../sg/GL_viewer"
|
||||
|
||||
#include <QtOpenGL/qgl.h>
|
||||
#include <QtGui/qevent.h>
|
||||
|
||||
#include <tools/sg/device_interactor>
|
||||
|
||||
namespace tools {
|
||||
namespace Qt {
|
||||
|
||||
class glarea : public QGLWidget {
|
||||
typedef QGLWidget parent;
|
||||
public:
|
||||
virtual void initialieGL() {}
|
||||
virtual void resizeGL(int a_w,int a_h){
|
||||
//::printf("debug : resize : %d %d\n",a_w,a_h);
|
||||
#if QT_VERSION < 0x050000
|
||||
#else
|
||||
m_width = a_w;
|
||||
m_height = a_h;
|
||||
#endif
|
||||
}
|
||||
//virtual void paintGL();
|
||||
virtual void paintGL() {
|
||||
#if QT_VERSION < 0x050000
|
||||
//::printf("debug : tools::Qt::glarea::paintGL %d %d\n",width(),height());
|
||||
m_viewer.set_size(width(),height());
|
||||
#else
|
||||
//::printf("debug : tools::Qt::glarea::paintGL %d %d\n",m_width,m_height);
|
||||
m_viewer.set_size(m_width,m_height);
|
||||
#endif
|
||||
m_viewer.render();
|
||||
}
|
||||
|
||||
virtual void keyPressEvent(QKeyEvent* a_event) {
|
||||
if(!m_interactor) return;
|
||||
tools::sg::key_down_event event(convert(a_event->key()));
|
||||
m_interactor->key_press(event);
|
||||
}
|
||||
virtual void keyReleaseEvent(QKeyEvent* a_event) {
|
||||
if(!m_interactor) return;
|
||||
tools::sg::key_up_event event(convert(a_event->key()));
|
||||
m_interactor->key_release(event);
|
||||
}
|
||||
virtual void mousePressEvent(QMouseEvent* a_event) {
|
||||
if(!m_interactor) return;
|
||||
tools::sg::mouse_down_event event(a_event->x(),a_event->y());
|
||||
m_interactor->mouse_press(event);
|
||||
}
|
||||
virtual void mouseReleaseEvent(QMouseEvent* a_event) {
|
||||
if(!m_interactor) return;
|
||||
tools::sg::mouse_up_event event(a_event->x(),a_event->y());
|
||||
m_interactor->mouse_release(event);
|
||||
}
|
||||
virtual void mouseMoveEvent(QMouseEvent* a_event) {
|
||||
if(!m_interactor) return;
|
||||
tools::sg::mouse_move_event event(a_event->x(),a_event->y(),0,0,false);
|
||||
m_interactor->mouse_move(event);
|
||||
}
|
||||
//virtual void mouseDoubleClickEvent(QMouseEvent* a_event) {
|
||||
// if(!m_interactor) return;
|
||||
// tools::sg::mouse_double_click_event event(a_event->x(),a_event->y());
|
||||
// m_interactor->mouse_double_click(event);
|
||||
//}
|
||||
virtual void wheelEvent(QWheelEvent* a_event) {
|
||||
if(!m_interactor) return;
|
||||
tools::sg::wheel_rotate_event event(a_event->angleDelta().y());
|
||||
m_interactor->wheel_rotate(event);
|
||||
}
|
||||
|
||||
public:
|
||||
glarea(QWidget* a_parent,tools::sg::GL_viewer& a_viewer):parent(a_parent),m_viewer(a_viewer),m_interactor(0){}
|
||||
virtual ~glarea(){}
|
||||
public:
|
||||
void set_device_interactor(tools::sg::device_interactor* a_interactor) {m_interactor = a_interactor;} //we do not have ownership.
|
||||
protected:
|
||||
tools::key_code convert(/*Qt::Key*/int a_key) {return a_key;}
|
||||
protected:
|
||||
tools::sg::GL_viewer& m_viewer;
|
||||
#if QT_VERSION < 0x050000
|
||||
#else
|
||||
protected:
|
||||
int m_width;
|
||||
int m_height;
|
||||
#endif
|
||||
tools::sg::device_interactor* m_interactor;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_Qt_plots_glarea
|
||||
#define tools_Qt_plots_glarea
|
||||
|
||||
#include <QtOpenGL/qgl.h>
|
||||
|
||||
#include "../sg/GL_plots_viewer"
|
||||
|
||||
namespace tools {
|
||||
namespace Qt {
|
||||
|
||||
class plots_glarea : public QGLWidget {
|
||||
typedef QGLWidget parent;
|
||||
public:
|
||||
virtual void initialieGL() {}
|
||||
virtual void resizeGL(int a_w,int a_h){
|
||||
//::printf("debug : resize : %d %d\n",a_w,a_h);
|
||||
#if QT_VERSION < 0x050000
|
||||
#else
|
||||
m_width = a_w;
|
||||
m_height = a_h;
|
||||
#endif
|
||||
}
|
||||
//virtual void paintGL();
|
||||
virtual void paintGL() {
|
||||
#if QT_VERSION < 0x050000
|
||||
//::printf("debug : tools::Qt::plots_glarea::paintGL %d %d\n",width(),height());
|
||||
m_viewer.set_size(width(),height());
|
||||
#else
|
||||
//::printf("debug : tools::Qt::plots_glarea::paintGL %d %d\n",m_width,m_height);
|
||||
m_viewer.set_size(m_width,m_height);
|
||||
#endif
|
||||
m_viewer.render();
|
||||
}
|
||||
|
||||
public:
|
||||
plots_glarea(QWidget* a_parent,tools::sg::GL_plots_viewer& a_viewer):parent(a_parent),m_viewer(a_viewer){}
|
||||
virtual ~plots_glarea(){}
|
||||
protected:
|
||||
tools::sg::GL_plots_viewer& m_viewer;
|
||||
#if QT_VERSION < 0x050000
|
||||
#else
|
||||
protected:
|
||||
int m_width;
|
||||
int m_height;
|
||||
#endif
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_Qt_session
|
||||
#define tools_Qt_session
|
||||
|
||||
// pure Qt code, no GL.
|
||||
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
#include <QtCore/qglobal.h> //For QT_VERSION.
|
||||
#include <QtCore/qnamespace.h>
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
#include <QtGui/qapplication.h>
|
||||
#include <QtGui/qwidget.h>
|
||||
#else
|
||||
#include <QtWidgets/qapplication.h>
|
||||
#include <QtWidgets/qwidget.h>
|
||||
#endif
|
||||
|
||||
namespace tools {
|
||||
namespace Qt {
|
||||
|
||||
class session {
|
||||
public:
|
||||
session(std::ostream& a_out,int& a_argc,char** a_argv)
|
||||
:m_out(a_out)
|
||||
,m_qapp(0)
|
||||
,m_own_qapp(false)
|
||||
{
|
||||
if(qApp) {
|
||||
m_qapp = qApp;
|
||||
m_own_qapp = false;
|
||||
} else {
|
||||
m_qapp = new QApplication(a_argc,a_argv);
|
||||
m_own_qapp = true;
|
||||
}
|
||||
}
|
||||
virtual ~session() {
|
||||
if(m_own_qapp && m_qapp) delete m_qapp;
|
||||
m_qapp = 0;
|
||||
m_own_qapp = false;
|
||||
}
|
||||
protected:
|
||||
session(const session& a_from)
|
||||
:m_out(a_from.m_out)
|
||||
,m_qapp(0)
|
||||
,m_own_qapp(false)
|
||||
{}
|
||||
session& operator=(const session& a_from){
|
||||
if(&a_from==this) return *this;
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
std::ostream& out() const {return m_out;}
|
||||
bool is_valid() const {return m_qapp?true:false;}
|
||||
bool steer() {
|
||||
if(!m_qapp) return false;
|
||||
m_qapp->exec();
|
||||
return true;
|
||||
}
|
||||
bool sync() {
|
||||
if(!m_qapp) return false;
|
||||
//m_qapp->exec();
|
||||
return true;
|
||||
}
|
||||
public:
|
||||
QApplication* qapp() const {return m_qapp;}
|
||||
QWidget* create_window(const char* a_title,int a_x,int a_y,unsigned int a_width,unsigned int a_height) {
|
||||
if(!m_qapp) return 0;
|
||||
#ifdef _MSC_VER
|
||||
if(a_y<=0) a_y = 60;
|
||||
#endif
|
||||
QWidget* top = new QWidget();
|
||||
top->setWindowFlags(::Qt::CustomizeWindowHint
|
||||
| ::Qt::WindowTitleHint
|
||||
| ::Qt::WindowMinMaxButtonsHint
|
||||
// | ::Qt::WindowSystemMenuHint
|
||||
// | ::Qt::WindowFullscreenButtonHint
|
||||
);
|
||||
top->setGeometry(a_x,a_y,a_width,a_height);
|
||||
top->setWindowTitle(s2q(a_title));
|
||||
//top->setAttribute(Qt::WA_DeleteOnClose,false);
|
||||
return top;
|
||||
}
|
||||
void delete_window(QWidget* a_window) const {
|
||||
if(!m_qapp) return;
|
||||
delete a_window;
|
||||
}
|
||||
protected:
|
||||
QString s2q(const std::string& a_s) {
|
||||
#if QT_VERSION < 0x050000
|
||||
return QString::fromAscii(a_s.c_str());
|
||||
#else
|
||||
return QString::fromLatin1(a_s.c_str());
|
||||
#endif
|
||||
}
|
||||
protected:
|
||||
std::ostream& m_out;
|
||||
QApplication* m_qapp;
|
||||
bool m_own_qapp;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
// Copyright (C) 2010, Guy Barrand. All rights reserved.
|
||||
// See the file tools.license for terms.
|
||||
|
||||
#ifndef tools_Qt_sg_viewer
|
||||
#define tools_Qt_sg_viewer
|
||||
|
||||
#include "glarea"
|
||||
|
||||
#include "session"
|
||||
|
||||
#include <QtCore/qglobal.h> //For QT_VERSION.
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
#include <QtGui/qpushbutton.h>
|
||||
#include <QtGui/qboxlayout.h>
|
||||
#else
|
||||
#include <QtWidgets/qpushbutton.h>
|
||||
#include <QtWidgets/qboxlayout.h>
|
||||
#endif
|
||||
|
||||
namespace tools {
|
||||
namespace Qt {
|
||||
|
||||
class sg_viewer : public sg::GL_viewer {
|
||||
typedef sg::GL_viewer parent;
|
||||
public:
|
||||
sg_viewer(session& a_session,
|
||||
int a_x = 0,int a_y = 0,
|
||||
unsigned int a_width = 500,unsigned int a_height = 500,
|
||||
const std::string& a_win_title = "")
|
||||
:parent(a_session.out(),a_width,a_height)
|
||||
,m_session(a_session)
|
||||
,m_shell(0)
|
||||
,m_own_shell(false)
|
||||
,m_glarea(0)
|
||||
{
|
||||
if(!m_session.is_valid()) return; //throw
|
||||
m_shell = m_session.create_window(a_win_title.c_str(),a_x,a_y,a_width,a_height);
|
||||
if(!m_shell) return; //throw
|
||||
m_own_shell = true;
|
||||
|
||||
m_glarea = new Qt::glarea(0,*this);
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout;
|
||||
layout->setContentsMargins(0,0,0,0);
|
||||
layout->addWidget(m_glarea);
|
||||
m_shell->setLayout(layout);
|
||||
}
|
||||
virtual ~sg_viewer() {
|
||||
if(m_shell && m_own_shell) {
|
||||
m_session.delete_window(m_shell);
|
||||
//m_session.sync();
|
||||
}
|
||||
}
|
||||
protected:
|
||||
sg_viewer(const sg_viewer& a_from)
|
||||
:parent(a_from)
|
||||
,m_session(a_from.m_session)
|
||||
,m_shell(0)
|
||||
,m_own_shell(false)
|
||||
,m_glarea(0)
|
||||
{}
|
||||
sg_viewer& operator=(const sg_viewer& a_from){
|
||||
parent::operator=(a_from);
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
bool has_window() const {return m_shell?true:false;} //for SWIG
|
||||
|
||||
bool show() {
|
||||
if(!m_shell) return false;
|
||||
m_shell->show();
|
||||
return true;
|
||||
}
|
||||
|
||||
void win_render() {
|
||||
if(!m_glarea) return;
|
||||
m_glarea->update();
|
||||
}
|
||||
public:
|
||||
QWidget* shell() {return m_shell;}
|
||||
void set_own_shell(bool a_value) {m_own_shell = a_value;}
|
||||
Qt::glarea* glarea() {return m_glarea;}
|
||||
void set_device_interactor(tools::sg::device_interactor* a_interactor) { //we do not have ownership.
|
||||
if(!m_glarea) return;
|
||||
m_glarea->set_device_interactor(a_interactor);
|
||||
}
|
||||
void enable_keyboard_focus() {
|
||||
if(!m_glarea) return;
|
||||
m_glarea->setFocusPolicy(::Qt::StrongFocus);
|
||||
}
|
||||
protected:
|
||||
session& m_session;
|
||||
QWidget* m_shell;
|
||||
bool m_own_shell;
|
||||
Qt::glarea* m_glarea;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user