Commit 2824f2ae authored by Sylvain Thery's avatar Sylvain Thery

add qtQGLV for qtQGLViewer

parent 6e4b84c4
......@@ -42,9 +42,24 @@ int main(int argc, char **argv)
// final show for redraw
sqt.show();
// and wait for the end
// QGLViewer* ptr = sqt.getQGLWidget();
return app.exec();
}
void MyQT::cb_keyPress(int keycode)
{
switch(keycode)
{
case 'c' :
getQGLWidget()->camera()->centerScene();
updateGL();
break;
default:
break;
}
}
void MyQT::createMap()
{
// creation of a new attribute on vertices of type 3D vector for position.
......@@ -70,6 +85,7 @@ void MyQT::createMap()
float lWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2);
show();
// send BB info to interface for centering on GL screen
setParamObject(lWidthObj, lPosObj.data());
......
......@@ -27,7 +27,8 @@
//#define USE_GMAP
#include "Utils/Qt/qtSimple.h"
//#include "Utils/Qt/qtSimple.h"
#include "Utils/Qt/qtQGLV.h"
#include "Utils/cgognStream.h"
#include "Topology/generic/parameters.h"
......@@ -59,7 +60,7 @@ struct PFP: public PFP_STANDARD
typedef PFP::MAP MAP;
typedef PFP::VEC3 VEC3;
class MyQT : public Utils::QT::SimpleQT
class MyQT : public Utils::QT::SimpleQGLV
{
Q_OBJECT
public:
......@@ -67,6 +68,7 @@ public:
void cb_redraw();
void cb_initGL();
void cb_keyPress(int keycode);
protected:
// declaration of the map
......
......@@ -34,6 +34,7 @@ find_package(ZLIB REQUIRED)
find_package(LibXml2 REQUIRED)
find_package(GLEW REQUIRED)
find_package(SuiteSparse REQUIRED)
find_package(QGLViewer REQUIRED)
IF (DEFINED ASSERTON)
add_definitions(-DCGOGN_ASSERT_BOOL=${ASSERTON})
......@@ -73,7 +74,7 @@ SET (CGoGN_EXT_INCLUDES
${ZLIB_INCLUDE_DIRS}
${LIBXML2_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
${QGLVIEWER_INCLUDE_DIR}
)
# define libs for external libs
......@@ -87,6 +88,7 @@ SET (CGoGN_EXT_LIBS
${Boost_REGEX_LIBRARY}
${Boost_THREAD_LIBRARY}
${SUITESPARSE_LIBRARIES}
${QGLVIEWER_LIBRARIES}
)
#optionnal libs
......@@ -104,9 +106,11 @@ ENDIF (WITH_ZINRI)
IF (WITH_QT)
add_definitions(-DWITH_QT)
find_package(Qt4 REQUIRED)
SET(QT_USE_QTCORE TRUE)
SET(QT_USE_QTOPENGL TRUE)
SET(QT_USE_QTSVG TRUE)
find_package(Qt4 REQUIRED)
SET(QT_USE_QTXML TRUE )
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
SET (CGoGN_EXT_INCLUDES ${CGoGN_EXT_INCLUDES} ${QT_INCLUDE_DIR})
......
......@@ -92,7 +92,9 @@ IF(WITH_QT)
utils_qt_headers
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtgl.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtSimple.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtpopup.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtQGLV_glw.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtQGLV.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtpopup.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qthistodraw.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtcolorschooser.h
)
......
......@@ -90,7 +90,9 @@ IF(WITH_QT)
utils_qt_headers
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtgl.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtSimple.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtpopup.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtQGLV_glw.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtQGLV.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtpopup.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qthistodraw.h
${CGoGN_ROOT_DIR}/include/Utils/Qt/qtcolorschooser.h
)
......
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __QTQGLVIEWER_H
#define __QTQGLVIEWER_H
#include <QApplication>
#include <QDesktopWidget>
#include <QMainWindow>
#include <QWidget>
#include <QtGui>
#include "Utils/Qt/qtQGLV_glw.h"
#include <set>
#include <string>
#include "Geometry/vector_gen.h"
#include "Utils/gl_matrices.h"
namespace CGoGN { namespace Utils { class GLSLShader; } }
namespace CGoGN
{
namespace Utils
{
namespace QT
{
class SimpleQGLV : public QMainWindow
{
Q_OBJECT
public:
SimpleQGLV();
SimpleQGLV(const SimpleQGLV&) ;
virtual ~SimpleQGLV();
void operator=(const SimpleQGLV& v) ;
/**
* set the main widget of the dock
*/
void setDock(QDockWidget *dock);
/**
* set the main widget of the dock
*/
QDockWidget* dockWidget();
/**
* connect a widget/signal with a method of inherited object
* @param sender the widget sending signal
* @param signal use macro SIGNAL(qt_signal)
* @param method use macro SLOT(name_of_method(params))
*/
void setCallBack(const QObject* sender, const char* signal, const char* method);
/**
* set window Title
*/
void windowTitle(const char* windowTitle);
/**
* set dock Title
*/
void dockTitle(const char* dockTitle);
/**
* draw a message in status bar
* @param msg message in C format (if NULL swp show/hidden)
* @param timeoutms number of ms message stay (0 = until next msg)
*/
void statusMsg(const char* msg, int timeoutms = 0);
/**
* add an empty dock to the window
*/
QDockWidget* addEmptyDock();
/**
* change dock visibility
*/
void visibilityDock(bool visible);
/**
* change console visibility
*/
void visibilityConsole(bool visible);
/**
* change dock visibility
*/
void toggleVisibilityDock();
/**
* change console visibility
*/
void toggleVisibilityConsole();
/**
* add an entry to popup menu
* @param label label printed in menu
* @param method qt slot (function name)
*/
void add_menu_entry(const std::string label, const char* method);
/**
* re-initialize popup menu
*/
void init_app_menu();
/**
* set the help message
*/
void setHelpMsg(const std::string& msg);
/**
* set mouse tracking on the GLWidget
* if true : mouseMove events are generated for each mouse move
* if false : mouseMove events are only generated when a button is pressed
*/
void setGLWidgetMouseTracking(bool b);
protected:
// GLWidget* m_glWidget;
QGLView* m_qglWidget;
QDockWidget* m_dock;
QDockWidget* m_dockConsole;
QTextEdit* m_textConsole;
bool m_dockOn;
// mouse & matrix
Utils::GL_Matrices m_mat;
/// ref to projection matrix
glm::mat4& m_projection_matrix;
/// ref to modelview matrix
glm::mat4& m_modelView_matrix;
/// ref to transformation matrix
glm::mat4& m_transfo_matrix;
float m_curquat[4];
float m_lastquat[4];
float m_trans_x;
float m_trans_y;
float m_trans_z;
QMenu* m_fileMenu;
QMenu* m_appMenu;
std::string m_helpString;
std::stack<glm::mat4> m_stack_trf;
void closeEvent(QCloseEvent *event);
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *e);
public:
/**
* set width and pos center of object to draw
*/
void setParamObject(float width, float* pos) { m_qglWidget->setParamObject(width, pos); }
/**
* @brief get pointer on QGLViewer widget for direct access
* @return
*/
QGLViewer* getQGLWidget() { return static_cast<QGLViewer*>(m_qglWidget); }
// void resetCenterOfRotation(float width, float* pos) { m_qglWidget->resetCenterOfRotation(width, pos); }
/**
* make the contex of glWidget current
*/
void makeCurrent() { m_qglWidget->makeCurrent();}
/**
* set focal
*/
// void setFocal(float f) { m_glWidget->setFocal(f); }
/**
* set geometry (override buggy Qt function)
*/
void setGeometry(int x, int y, int w, int h);
/**
* get the mouse position in GL widget
*/
void glMousePosition(int& x, int& y);
/**
* get a ray (2 points) from a pick point in GL area
* @param x mouse position
* @param y mouse position
* @param rayA first computed point of ray
* @param rayA second computed point of ray
* @param radius radius on pixel for clicking precision
* @return the distance in modelview world corresponding to radius pixel in screen
*/
// GLfloat getOrthoScreenRay(int x, int y, Geom::Vec3f& rayA, Geom::Vec3f& rayB, int radius=4) { return m_glWidget->getOrthoScreenRay(x,y,rayA,rayB,radius);}
/**
* transform a pixel distance on screen in distance in world
* @param pixel_width width on pixel on screen
* @param center reference point on world to use (defaut 0,0,0)
*/
// float getWidthInWorld(unsigned int pixel_width, const Geom::Vec3f& center) { return m_glWidget->getWidthInWorld(pixel_width,center);}
const glm::mat4& transfoMatrix() const { return m_transfo_matrix; }
glm::mat4& transfoMatrix() { return m_transfo_matrix; }
/**
* current modelview matrix
*/
const glm::mat4& modelViewMatrix() const { return m_modelView_matrix; }
glm::mat4& modelViewMatrix() { return m_modelView_matrix; }
/**
* current projection matrix
*/
const glm::mat4& projectionMatrix() const { return m_projection_matrix; }
glm::mat4& projectionMatrix() { return m_projection_matrix; }
float* curquat() { return m_curquat; }
float* lastquat() { return m_lastquat; }
float& trans_x() { return m_trans_x; }
float& trans_y() { return m_trans_y; }
float& trans_z() { return m_trans_z; }
// glm::mat4* matricesPtr() { return m_mat.m_matrices;}
Utils::GL_Matrices* matricesPtr() { return &m_mat;}
/**
* shift key pressed ?
*/
bool Shift() const { return m_qglWidget->Shift(); }
/**
* control key pressed ?
*/
bool Control() const { return m_qglWidget->Control(); }
/**
* alt key pressed ?
*/
bool Alt() const { return m_qglWidget->Alt(); }
/**
* height of OpenGL widget (for classic yy = H-y)
*/
int getHeight() const { return m_qglWidget->getHeight(); }
/**
* width of OpenGL widget
*/
int getWidth() const { return m_qglWidget->getWidth(); }
/**
* console QTextEdit ptr
*/
QTextEdit* console() { return m_textConsole; }
/**
* syncronization between SimpleQTs (experimental)
*/
// void synchronize(SimpleQT* sqt);
/**
* Register a shader as running in this Widget.
* Needed for automatic matrices update
*/
void registerShader(GLSLShader* ptr);
/**
* Unregister a shader as running in this Widget.
*/
void unregisterShader(GLSLShader* ptr);
/**
* GL initialization CB (context is ok)
*/
virtual void cb_initGL() {}
/**
* what to you want to draw ? (need to be implemented)
*/
virtual void cb_redraw() = 0;
/**
* Mouse button has been pressed
*/
virtual void cb_mousePress(int button, int x, int y) {}
/**
* Mouse button has been released
*/
virtual void cb_mouseRelease(int button, int x, int y) {}
/**
* Mouse button has been clicked
*/
virtual void cb_mouseClick(int button, int x, int y) {}
/**
* the mouse has been move (with buttons still pressed)
*/
virtual void cb_mouseMove(int buttons, int x, int y) {}
/**
* the mouse has been move (with button still pressed)
*/
virtual void cb_wheelEvent(int delta, int x, int y) {}
/**
* key press CB (context is ok)
*/
virtual void cb_keyPress(int code) {}
/**
* key releaase CB (context is ok)
*/
virtual void cb_keyRelease(int code) {}
/**
* matrices need to be updated (context is ok)
*/
virtual void cb_updateMatrix();
/**
* end of program, some things to clean ?
*/
virtual void cb_exit() {}
/**
* Ask to Qt to update the GL widget.
* Equivalent of glutPostRedisplay()
*/
void updateGL();
/**
* Ask to Qt to update matrices and then the GL widget.
*/
void updateGLMatrices();
/**
* apply rotation to transformation matrix
*/
void transfoRotate(float angle, float x, float y, float z);
/**
* apply translation to transformation matrix
*/
void transfoTranslate(float tx, float ty, float tz);
/**
* apply scale to transformation matrix
*/
void transfoScale(float sx, float sy, float sz);
/**
* push the transfo matrix on stack
*/
void pushTransfoMatrix();
/**
* pop the transfo matrix from stack
*/
bool popTransfoMatrix();
/**
* Open a file selector and return the filename
* @param title title of window
* @param dir base directory
* @param filters file filters (syntax: "label1 (filter1);; label2 (filter2);; ...")
*/
std::string selectFile(const std::string& title = "open file", const std::string& dir = ".", const std::string& filters = "all (*.*)");
/**
* Open a file selector and return the filename (for saving a file)
* @param title title of window
* @param dir base directory
* @param filters file filters (syntax: "label1 (filter1);; label2 (filter2);; ...")
*/
std::string selectFileSave(const std::string& title = "save file", const std::string& dir = ".", const std::string& filters = "all (*.*)");
void snapshot(const QString& filename, const char* format = 0, const int& quality = -1);
public slots:
virtual void cb_New() { std::cerr << "callback not implemented" << std::endl; }
virtual void cb_Open() { std::cerr << "callback not implemented" << std::endl; }
virtual void cb_Save() { std::cerr << "callback not implemented" << std::endl; }
virtual void cb_Quit() { exit(0); }
void cb_about_cgogn();
void cb_about();
void cb_consoleOnOff() { toggleVisibilityConsole(); }
void cb_consoleClear() { m_textConsole->clear(); }
};
} // namespace QT
} // namespace Utils
} // namespace CGoGN
#endif
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#ifndef __QTQGLVIEWER_GLW_H
#define __QTQGLVIEWER_GLW_H
#include <QApplication>
#include <QDesktopWidget>
#include <QMainWindow>
#include <QWidget>
#include <QtGui>
#include <GL/glew.h>
#include <QGLViewer/qglviewer.h>
#include <set>
#include <string>
#include "Geometry/vector_gen.h"
#include "Utils/gl_matrices.h"
namespace CGoGN { namespace Utils { class GLSLShader; } }
namespace CGoGN
{
namespace Utils
{
namespace QT
{
// forward definition
class SimpleQGLV;
class QGLView : public QGLViewer
{
Q_OBJECT
protected:
SimpleQGLV* m_sqgl;
int W;
int H;
int m_state_modifier;
public:
QGLView(SimpleQGLV* ptr, QWidget *parent = 0);
~QGLView();
void setParamObject(float width, float* pos);
void glMousePosition(int& x, int& y);
virtual void init();
virtual void preDraw();
virtual void draw();
virtual void postDraw() {}
virtual void resizeGL(int width, int height);
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void mouseClickEvent(QMouseEvent* event);
// void mouseDoubleClickEvent(QMouseEvent* event);
// void mouseMoveEvent(QMouseEvent* event);
void keyPressEvent(QKeyEvent* event);
void keyReleaseEvent(QKeyEvent* event);
// void wheelEvent(QWheelEvent* event);
bool Shift() { return m_state_modifier & Qt::ShiftModifier; }
bool Control() { return m_state_modifier & Qt::ControlModifier; }
bool Alt() { return m_state_modifier & Qt::AltModifier; }
int getHeight() const { return H; }
int getWidth() const { return W; }
QSize minimumSizeHint() const;
QSize sizeHint() const;
};
} // namespace QT
} // namespace Utils
} // namespace CGoGN
#endif
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps *
* version 0.1 *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg *
* *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your *
* option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
* *
* Web site: http://cgogn.unistra.fr/ *
* Contact information: cgogn@unistra.fr *
* *
*******************************************************************************/
#include "Utils/GLSLShader.h"
#include "Utils/Qt/qtQGLV.h"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/type_precision.hpp"
#include "glm/gtc/type_ptr.hpp"
#include <QtGui/QTextEdit>
#include <QImage>
namespace CGoGN
{
namespace Utils
{
namespace QT
{
SimpleQGLV::SimpleQGLV() :
m_dock(NULL),
m_projection_matrix(m_mat.m_matrices[0]),
m_modelView_matrix(m_mat.m_matrices[1]),
m_transfo_matrix(m_mat.m_matrices[2])
{
m_qglWidget = new QGLView(this);
setCentralWidget(m_qglWidget);
setWindowTitle(tr("CGoGN"));
m_fileMenu = menuBar()->addMenu(tr("&File"));
QAction* action = new QAction(tr("New"), this);
connect(action, SIGNAL(triggered()), this, SLOT(cb_New()));
m_fileMenu->addAction(action);
action = new QAction(tr("Open"), this);
connect(action, SIGNAL(triggered()), this, SLOT(cb_Open()));
m_fileMenu->addAction(action);
action = new QAction(tr("Save"), this);
connect(action, SIGNAL(triggered()), this, SLOT(cb_Save()));
m_fileMenu->addAction(action);
m_fileMenu->addSeparator();
action = new QAction(tr("Quit"), this);
connect(action, SIGNAL(triggered()), this, SLOT(cb_Quit()));
m_fileMenu->addAction(action);
m_appMenu = menuBar()->addMenu(tr("&Application"));
QMenu* m_helpMenu = menuBar()->addMenu(tr("&Help"));
action = new QAction(tr("console on/off"), this);
connect(action, SIGNAL(triggered()), this, SLOT(cb_consoleOnOff()));
m_helpMenu->addAction(action);
action = new QAction(tr("console clear"), this);
connect(action, SIGNAL(triggered()), this, SLOT(cb_consoleClear()));
m_helpMenu->addAction(action);
action = new QAction(tr("About"), this);