1
/*************************************************************************
2
* Copyright (C) 2004 by Olivier Galizzi *
3
* olivier.galizzi@imag.fr *
4
* Copyright (C) 2005 by Janek Kozicki *
7
* This program is free software; it is licensed under the terms of the *
8
* GNU General Public License v2 or later. See file LICENSE for details. *
9
*************************************************************************/
11
#include"GLViewer.hpp"
12
#include"OpenGLManager.hpp"
14
#include<yade/lib/opengl/OpenGLWrapper.hpp>
15
#include<yade/core/Body.hpp>
16
#include<yade/core/Scene.hpp>
17
#include<yade/core/Interaction.hpp>
18
#include<yade/core/DisplayParameters.hpp>
19
#include<boost/filesystem/operations.hpp>
20
#include<boost/algorithm/string.hpp>
21
#include<boost/version.hpp>
22
#include<boost/python.hpp>
25
#include<boost/algorithm/string/case_conv.hpp>
26
#include<yade/lib/serialization/ObjectIO.hpp>
27
#include<yade/lib/pyutil/gil.hpp>
30
#include<QtGui/qevent.h>
32
using namespace boost;
38
void GLViewer::mouseMovesCamera(){
39
camera()->frame()->setWheelSensitivity(-1.0f);
41
setMouseBinding(Qt::SHIFT + Qt::LeftButton, SELECT);
42
//setMouseBinding(Qt::RightButton, NO_CLICK_ACTION);
43
setMouseBinding(Qt::SHIFT + Qt::LeftButton + Qt::RightButton, FRAME, ZOOM);
44
setMouseBinding(Qt::SHIFT + Qt::MidButton, FRAME, TRANSLATE);
45
setMouseBinding(Qt::SHIFT + Qt::RightButton, FRAME, ROTATE);
46
setWheelBinding(Qt::ShiftModifier , FRAME, ZOOM);
48
setMouseBinding(Qt::LeftButton + Qt::RightButton, CAMERA, ZOOM);
49
setMouseBinding(Qt::MidButton, CAMERA, ZOOM);
50
setMouseBinding(Qt::LeftButton, CAMERA, ROTATE);
51
setMouseBinding(Qt::RightButton, CAMERA, TRANSLATE);
52
setWheelBinding(Qt::NoModifier, CAMERA, ZOOM);
55
void GLViewer::mouseMovesManipulatedFrame(qglviewer::Constraint* c){
56
setMouseBinding(Qt::LeftButton + Qt::RightButton, FRAME, ZOOM);
57
setMouseBinding(Qt::MidButton, FRAME, ZOOM);
58
setMouseBinding(Qt::LeftButton, FRAME, ROTATE);
59
setMouseBinding(Qt::RightButton, FRAME, TRANSLATE);
60
setWheelBinding(Qt::NoModifier , FRAME, ZOOM);
61
manipulatedFrame()->setConstraint(c);
65
void GLViewer::mouseMoveEvent(QMouseEvent *e){
66
last_user_event = boost::posix_time::second_clock::local_time();
67
QGLViewer::mouseMoveEvent(e);
70
void GLViewer::mousePressEvent(QMouseEvent *e){
71
last_user_event = boost::posix_time::second_clock::local_time();
72
QGLViewer::mousePressEvent(e);
75
/* Handle double-click event; if clipping plane is manipulated, align it with the global coordinate system.
76
* Otherwise pass the event to QGLViewer to handle it normally.
78
* mostly copied over from ManipulatedFrame::mouseDoubleClickEvent
80
void GLViewer::mouseDoubleClickEvent(QMouseEvent *event){
81
last_user_event = boost::posix_time::second_clock::local_time();
83
if(manipulatedClipPlane<0) { /* LOG_DEBUG("Double click not on clipping plane"); */ QGLViewer::mouseDoubleClickEvent(event); return; }
84
#if QT_VERSION >= 0x040000
85
if (event->modifiers() == Qt::NoModifier)
87
if (event->state() == Qt::NoButton)
89
switch (event->button()){
90
case Qt::LeftButton: manipulatedFrame()->alignWithFrame(NULL,true); LOG_DEBUG("Aligning cutting plane"); break;
91
// case Qt::RightButton: projectOnLine(camera->position(), camera->viewDirection()); break;
92
default: break; // avoid warning
96
void GLViewer::wheelEvent(QWheelEvent* event){
97
last_user_event = boost::posix_time::second_clock::local_time();
99
if(manipulatedClipPlane<0){ QGLViewer::wheelEvent(event); return; }
100
assert(manipulatedClipPlane<renderer->numClipPlanes);
101
float distStep=1e-3*sceneRadius();
102
//const float wheelSensitivityCoef = 8E-4f;
103
//Vec trans(0.0, 0.0, -event->delta()*wheelSensitivity()*wheelSensitivityCoef*(camera->position()-position()).norm());
104
float dist=event->delta()*manipulatedFrame()->wheelSensitivity()*distStep;
105
Vector3r normal=renderer->clipPlaneSe3[manipulatedClipPlane].orientation*Vector3r(0,0,1);
106
qglviewer::Vec newPos=manipulatedFrame()->position()+qglviewer::Vec(normal[0],normal[1],normal[2])*dist;
107
manipulatedFrame()->setPosition(newPos);
108
renderer->clipPlaneSe3[manipulatedClipPlane].position=Vector3r(newPos[0],newPos[1],newPos[2]);
110
/* in draw, bound cutting planes will be moved as well */