Commit b0ea3ff5 authored by Jan Möbius's avatar Jan Möbius

Merged examiner and base viewer ( needs a lot of cleanup!!)

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@4482 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 16174533
......@@ -47,7 +47,7 @@
#include <QtGui>
#include <QMenuBar>
#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/widgets/glWidget/QtExaminerViewer.hh>
#include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh>
/** \brief Interface class for plugins which need access to global Data
*
......@@ -65,7 +65,7 @@ class GlobalAccessInterface {
* This function is called to set a pointer to the global examiner Widget.\n
* @param _examiner_widget Pointer to the Examiner Widget in the Main app
*/
virtual void set_examiner( QtExaminerViewer* /*_examiner_widget*/) = 0;
virtual void set_examiner( QtBaseViewer* /*_examiner_widget*/) = 0;
};
......
......@@ -54,10 +54,10 @@ static BaseObject* objectRoot_;
*
* This pointer is internally used to acces the examiner widget in the main apllication
*/
static std::vector< QtExaminerViewer* > examiner_widgets_;
static std::vector< QtBaseViewer* > examiner_widgets_;
/// TODO : Remove this variable and implement multiView correctly here
static QtExaminerViewer* examiner_widget_;
static QtBaseViewer* examiner_widget_;
static unsigned int activeExaminer_ = 0;
......@@ -73,7 +73,7 @@ void setDataRoot( BaseObject* _root ) {
objectRoot_ = _root;
}
void set_examiner( std::vector< QtExaminerViewer* > _examiner_widgets ) {
void set_examiner( std::vector< QtBaseViewer* > _examiner_widgets ) {
PluginFunctions::examiner_widgets_ = _examiner_widgets;
PluginFunctions::examiner_widget_ = examiner_widgets_[0];
}
......
......@@ -50,7 +50,6 @@
#include <OpenFlipper/common/Types.hh>
// #include <ACG/Math/VectorT.hh>
#include <OpenFlipper/widgets/glWidget/QtExaminerViewer.hh>
#include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh>
#include <ACG/GL/GLState.hh>
......@@ -194,7 +193,7 @@ int visible_count();
//=======================================
/// Set the internal examiner pointer ( DO NOT USE!! )
DLLEXPORT
void set_examiner( std::vector< QtExaminerViewer* > _examiner_widgets );
void set_examiner( std::vector< QtBaseViewer* > _examiner_widgets );
/// Set the active id of the examiner which got the last mouse events
DLLEXPORT
......
......@@ -52,7 +52,7 @@
#include "OpenFlipper/common/Types.hh"
#include <OpenFlipper/widgets/glWidget/QtExaminerViewer.hh>
#include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh>
// QT INCLUDES
#include <qvariant.h>
......
......@@ -131,10 +131,10 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
if ( !OpenFlipper::Options::multiView() ) {
QtExaminerViewer* examinerWidget = new QtExaminerViewer(stackedWidget_,
"Examiner Widget",
statusBar_ ,
&format);
QtBaseViewer* examinerWidget = new QtBaseViewer(stackedWidget_,
"Examiner Widget",
statusBar_ ,
&format);
examiner_widgets_.push_back(examinerWidget);
......@@ -148,7 +148,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
tmp = new QWidget(stackedWidget_);
// Create master examiner widget
QtExaminerViewer* examinerWidget = new QtExaminerViewer(tmp,
QtBaseViewer* examinerWidget = new QtBaseViewer(tmp,
"Examiner Widget",
statusBar_ ,
&format,
......@@ -158,7 +158,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
// Create all other examiners using the same gl context as the others
for ( unsigned int i = 1 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
QtExaminerViewer* newWidget = new QtExaminerViewer(tmp,
QtBaseViewer* newWidget = new QtBaseViewer(tmp,
"Examiner Widget",
statusBar_ ,
&format,
......
......@@ -56,7 +56,7 @@
#include <OpenFlipper/BasePlugin/StatusbarInterface.hh>
#include <OpenFlipper/widgets/glWidget/QtExaminerViewer.hh>
#include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh>
// QT INCLUDES
#include <QMainWindow>
......@@ -346,7 +346,7 @@ public:
public :
/// Examiner Widget
std::vector< QtExaminerViewer* > examiner_widgets_;
std::vector< QtBaseViewer* > examiner_widgets_;
///Spliter between toplevel objects and the textedit at the bottom
QSplitter* splitter_;
......
......@@ -200,6 +200,16 @@ QtBaseViewer::QtBaseViewer( QWidget* _parent,
redrawTime_.start ();
// timer for animation
timer_ = new QTimer( this );
connect( timer_, SIGNAL(timeout()), this, SLOT( slotAnimation()) );
allowRotation_ = true;
//default wheel zoom factors
wZoomFactor_ = 1.0;
wZoomFactorShift_ = 0.2;
}
......@@ -1811,5 +1821,338 @@ void QtBaseViewer::actionPickMenu( QAction * _action )
hidePopupMenus();
}
//-----------------------------------------------------------------------------
void
QtBaseViewer::viewMouseEvent(QMouseEvent* _event)
{
switch (_event->type())
{
case QEvent::MouseButtonPress:
{
// shift key -> set rotation center
if (_event->modifiers() & Qt::ShiftModifier)
{
ACG::Vec3d c;
if (fast_pick(_event->pos(), c))
{
trackball_center_ = c;
trackball_radius_ = std::max(scene_radius_, (c-glState().eye()).norm()*0.9f);
}
}
lastPoint_hitSphere_ = mapToSphere( lastPoint2D_=_event->pos(),
lastPoint3D_ );
isRotating_ = true;
timer_->stop();
break;
}
case QEvent::MouseButtonDblClick:
{
if (allowRotation_)
flyTo(_event->pos(), _event->button()==Qt::MidButton);
break;
}
case QEvent::MouseMove:
{
double factor = 1.0;
if (_event->modifiers() == Qt::ShiftModifier)
factor = wZoomFactorShift_;
// mouse button should be pressed
if (_event->buttons() & (Qt::LeftButton | Qt::MidButton))
{
QPoint newPoint2D = _event->pos();
if ( (newPoint2D.x()<0) || (newPoint2D.x() > (int)glWidth()) ||
(newPoint2D.y()<0) || (newPoint2D.y() > (int)glHeight()) )
return;
double value_x, value_y;
ACG::Vec3d newPoint3D;
bool newPoint_hitSphere = mapToSphere( newPoint2D, newPoint3D );
makeCurrent();
// move in z direction
if ( (_event->buttons() & Qt::LeftButton) &&
(_event->buttons() & Qt::MidButton))
{
switch (projectionMode())
{
case PERSPECTIVE_PROJECTION:
{
value_y = scene_radius_ * ((newPoint2D.y() - lastPoint2D_.y())) * 3.0 / (double) glHeight();
translate( ACG::Vec3d(0.0, 0.0, value_y * factor ) );
updateGL();
break;
}
case ORTHOGRAPHIC_PROJECTION:
{
value_y = ((newPoint2D.y() - lastPoint2D_.y())) * orthoWidth_ / (double) glHeight();
orthoWidth_ -= value_y * factor;
updateProjectionMatrix();
updateGL();
break;
}
}
}
// move in x,y direction
else if (_event->buttons() & Qt::MidButton)
{
value_x = scene_radius_ * ((newPoint2D.x() - lastPoint2D_.x())) * 2.0 / (double) glWidth();
value_y = scene_radius_ * ((newPoint2D.y() - lastPoint2D_.y())) * 2.0 / (double) glHeight();
translate( ACG::Vec3d(value_x * factor , -value_y * factor , 0.0) );
}
// rotate
else if (allowRotation_ && (_event->buttons() & Qt::LeftButton) )
{
ACG::Vec3d axis(1.0,0.0,0.0);
double angle(0.0);
if ( lastPoint_hitSphere_ ) {
if ( ( newPoint_hitSphere = mapToSphere( newPoint2D,
newPoint3D ) ) ) {
axis = lastPoint3D_ % newPoint3D;
double cos_angle = ( lastPoint3D_ | newPoint3D );
if ( fabs(cos_angle) < 1.0 ) {
angle = acos( cos_angle ) * 180.0 / M_PI * factor ;
angle *= 2.0; // inventor rotation
}
}
rotate(axis, angle);
}
lastRotationAxis_ = axis;
lastRotationAngle_ = angle;
}
lastPoint2D_ = newPoint2D;
lastPoint3D_ = newPoint3D;
lastPoint_hitSphere_ = newPoint_hitSphere;
updateGL();
lastMoveTime_.restart();
}
break;
}
case QEvent::MouseButtonRelease:
{
lastPoint_hitSphere_ = false;
// continue rotation ?
if ( isRotating_ &&
(_event->button() == Qt::LeftButton) &&
(!(_event->buttons() & Qt::MidButton)) &&
(lastMoveTime_.elapsed() < 10) &&
animation() )
timer_->start(0);
break;
}
default: // avoid warning
break;
}
// sync views
emit(signalSetView(glstate_->modelview(), glstate_->inverse_modelview()));
}
//-----------------------------------------------------------------------------
void
QtBaseViewer::lightMouseEvent(QMouseEvent* _event)
{
switch (_event->type())
{
case QEvent::MouseButtonPress:
{
lastPoint_hitSphere_ = mapToSphere( lastPoint2D_=_event->pos(),
lastPoint3D_ );
isRotating_ = true;
timer_->stop();
break;
}
case QEvent::MouseMove:
{
// rotate lights
if (_event->buttons() & Qt::LeftButton)
{
QPoint newPoint2D = _event->pos();
if ( (newPoint2D.x()<0) || (newPoint2D.x() > (int)glWidth()) ||
(newPoint2D.y()<0) || (newPoint2D.y() > (int)glHeight()) )
return;
ACG::Vec3d newPoint3D;
bool newPoint_hitSphere = mapToSphere( newPoint2D, newPoint3D );
makeCurrent();
ACG::Vec3d axis(1.0,0.0,0.0);
double angle(0.0);
if ( lastPoint_hitSphere_ )
{
if ( ( newPoint_hitSphere = mapToSphere( newPoint2D, newPoint3D ) ) )
{
axis = lastPoint3D_ % newPoint3D;
double cos_angle = ( lastPoint3D_ | newPoint3D );
if ( fabs(cos_angle) < 1.0 ) {
angle = acos( cos_angle ) * 180.0 / M_PI;
angle *= 2.0;
}
}
rotate_lights(axis, angle);
}
lastPoint2D_ = newPoint2D;
lastPoint3D_ = newPoint3D;
lastPoint_hitSphere_ = newPoint_hitSphere;
updateGL();
}
break;
}
default: // avoid warning
break;
}
}
//-----------------------------------------------------------------------------
double QtBaseViewer::wheelZoomFactor(){
return wZoomFactor_;
}
//-----------------------------------------------------------------------------
double QtBaseViewer::wheelZoomFactorShift(){
return wZoomFactorShift_;
}
//-----------------------------------------------------------------------------
void QtBaseViewer::setWheelZoomFactor(double _factor){
wZoomFactor_ = _factor;
}
//-----------------------------------------------------------------------------
void QtBaseViewer::setWheelZoomFactorShift(double _factor){
wZoomFactorShift_ = _factor;
}
//-----------------------------------------------------------------------------
void QtBaseViewer::viewWheelEvent( QWheelEvent* _event)
{
double factor = wZoomFactor_;
if (_event->modifiers() == Qt::ShiftModifier)
factor = wZoomFactorShift_;
switch (projectionMode())
{
case PERSPECTIVE_PROJECTION:
{
double d = -(double)_event->delta() / 120.0 * 0.2 * factor * trackball_radius_/3;
translate( ACG::Vec3d(0.0, 0.0, d) );
updateGL();
break;
}
case ORTHOGRAPHIC_PROJECTION:
{
double d = (double)_event->delta() / 120.0 * 0.2 * factor * orthoWidth_;
orthoWidth_ += d;
updateProjectionMatrix();
updateGL();
break;
}
}
// sync views
emit(signalSetView(glstate_->modelview(), glstate_->inverse_modelview()));
}
//-----------------------------------------------------------------------------
bool QtBaseViewer::mapToSphere(const QPoint& _v2D, ACG::Vec3d& _v3D) const
{
if ( (_v2D.x() >= 0) && (_v2D.x() < (int)glWidth()) &&
(_v2D.y() >= 0) && (_v2D.y() < (int)glHeight()) )
{
double x = (double)(_v2D.x() - ((double)glWidth() / 2.0)) / (double)glWidth();
double y = (double)(((double)glHeight() / 2.0) - _v2D.y()) / (double)glHeight();
double sinx = sin(M_PI * x * 0.5);
double siny = sin(M_PI * y * 0.5);
double sinx2siny2 = sinx * sinx + siny * siny;
_v3D[0] = sinx;
_v3D[1] = siny;
_v3D[2] = sinx2siny2 < 1.0 ? sqrt(1.0 - sinx2siny2) : 0.0;
return true;
}
else return false;
}
//-----------------------------------------------------------------------------
void QtBaseViewer::slotAnimation()
{
static int msecs=0, count=0;
QTime t;
t.start();
makeCurrent();
rotate( lastRotationAxis_, lastRotationAngle_ );
updateGL();
if (!isUpdateLocked()) {
msecs += t.elapsed();
if (count==10) {
assert(statusbar_!=0);
char s[100];
sprintf( s, "%.3f fps", (10000.0 / (float)msecs) );
statusbar_->showMessage(s,2000);
count = msecs = 0;
}
else
++count;
}
}
//=============================================================================
//=============================================================================
......@@ -564,12 +564,12 @@ protected:
/// specialized viewer: hande mouse events
virtual void viewMouseEvent( QMouseEvent* _event) = 0;
void viewMouseEvent( QMouseEvent* _event);
/// specialized viewer: handle wheel events
virtual void viewWheelEvent(QWheelEvent* _event) = 0;
void viewWheelEvent(QWheelEvent* _event);
/// optional: hande mouse events to rotate light
virtual void lightMouseEvent( QMouseEvent* /* _event */ ) {}
void lightMouseEvent( QMouseEvent* /* _event */ );
protected:
......@@ -811,7 +811,7 @@ private:
*
* @return If the derived class handled the event it has to return true otherwise false
*/
virtual bool viewKeyPressEvent(QKeyEvent* _event) = 0;
virtual bool viewKeyPressEvent(QKeyEvent* /*_event*/) { return false; };
/** @} */
......@@ -1023,6 +1023,64 @@ private:
ACG::SceneGraph::PickTarget pickRendererMode_;
/** @} */
//===========================================================================
/** @name Merge from examiner
* @{ */
//===========================================================================
public:
/// Lock scene rotation
void allowRotation( bool _mode ) { allowRotation_ = _mode; };
/// Factors for zooming with the wheel
public:
double wheelZoomFactor();
double wheelZoomFactorShift();
void setWheelZoomFactor(double _factor);
void setWheelZoomFactorShift(double _factor);
private:
double wZoomFactor_;
double wZoomFactorShift_;
private slots:
void slotAnimation();
protected:
// mouse interaction
QPoint lastPoint2D_;
private:
/// virtual trackball: map 2D screen point to unit sphere
bool mapToSphere(const QPoint& _p, ACG::Vec3d& _result) const;
// mouse interaction
ACG::Vec3d lastPoint3D_;
bool lastPoint_hitSphere_;
bool allowRotation_;
// animation stuff
ACG::Vec3d lastRotationAxis_;
double lastRotationAngle_;
QTime lastMoveTime_;
QTimer* timer_;
/** @} */
};
......
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper 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 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper 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 OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 2979 $
// $Author: moebius $
// $Date: 2008-09-22 16:29:25 +0200 (Mo, 22. Sep 2008) $
//
//=============================================================================
//=============================================================================
//
// CLASS QtExaminerViewer - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include "QtExaminerViewer.hh"
#include <QTimer>
#include <QPushButton>
#include <QClipboard>
#include <QApplication>
#include <QInputDialog>
#include <QStatusBar>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QEvent>
#ifdef max
# undef max
#endif
//== NAMESPACES ===============================================================
//== IMPLEMENTATION ==========================================================
QtExaminerViewer::QtExaminerViewer( QWidget* _parent,
const char* _name,
QStatusBar *_statusBar,
const QGLFormat* _format,
const QtBaseViewer* _share) :
QtBaseViewer(_parent, _name, _statusBar, _format, _share)
{