~ubuntu-branches/ubuntu/trusty/yade/trusty

« back to all changes in this revision

Viewing changes to gui/qt4/GLViewerMouse.cpp

  • Committer: Package Import Robot
  • Author(s): Anton Gladky, cf3f8d9
  • Date: 2013-10-30 20:56:33 UTC
  • mfrom: (20.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20131030205633-1f01r7hjce17d723
Tags: 1.05.0-2
[cf3f8d9] Pass -ftrack-macro-expansion=0 only if gcc>=4.8. (Closes: #726009)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*************************************************************************
 
2
*  Copyright (C) 2004 by Olivier Galizzi                                 *
 
3
*  olivier.galizzi@imag.fr                                               *
 
4
*  Copyright (C) 2005 by Janek Kozicki                                   *
 
5
*  cosurgi@berlios.de                                                    *
 
6
*                                                                        *
 
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
*************************************************************************/
 
10
 
 
11
#include"GLViewer.hpp"
 
12
#include"OpenGLManager.hpp"
 
13
 
 
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>
 
23
#include<sstream>
 
24
#include<iomanip>
 
25
#include<boost/algorithm/string/case_conv.hpp>
 
26
#include<yade/lib/serialization/ObjectIO.hpp>
 
27
#include<yade/lib/pyutil/gil.hpp>
 
28
 
 
29
 
 
30
#include<QtGui/qevent.h>
 
31
 
 
32
using namespace boost;
 
33
 
 
34
#ifdef YADE_GL2PS
 
35
        #include<gl2ps.h>
 
36
#endif
 
37
 
 
38
void GLViewer::mouseMovesCamera(){
 
39
        camera()->frame()->setWheelSensitivity(-1.0f);
 
40
 
 
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);
 
47
 
 
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);
 
53
};
 
54
 
 
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);
 
62
}
 
63
 
 
64
 
 
65
void GLViewer::mouseMoveEvent(QMouseEvent *e){
 
66
        last_user_event = boost::posix_time::second_clock::local_time();
 
67
        QGLViewer::mouseMoveEvent(e);
 
68
}
 
69
 
 
70
void GLViewer::mousePressEvent(QMouseEvent *e){
 
71
        last_user_event = boost::posix_time::second_clock::local_time();
 
72
        QGLViewer::mousePressEvent(e);
 
73
}
 
74
 
 
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.
 
77
 *
 
78
 * mostly copied over from ManipulatedFrame::mouseDoubleClickEvent
 
79
 */
 
80
void GLViewer::mouseDoubleClickEvent(QMouseEvent *event){
 
81
        last_user_event = boost::posix_time::second_clock::local_time();
 
82
 
 
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)
 
86
#else
 
87
        if (event->state() == Qt::NoButton)
 
88
#endif
 
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
 
93
        }
 
94
}
 
95
 
 
96
void GLViewer::wheelEvent(QWheelEvent* event){
 
97
        last_user_event = boost::posix_time::second_clock::local_time();
 
98
 
 
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]);
 
109
        updateGL();
 
110
        /* in draw, bound cutting planes will be moved as well */
 
111
}
 
112