Changeset 4014 for trunk/packages


Ignore:
Timestamp:
Oct 27, 2013 12:18:57 AM (11 years ago)
Author:
ldelgass
Message:

Add mouse events

Location:
trunk/packages/vizservers/geovis
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/geovis/Makefile.in

    r4013 r4014  
    4242                -losgDB \
    4343                -losgViewer \
     44                -losgGA \
    4445                -losg \
    4546                -lOpenThreads
    4647
    47 OSGEARTH_LIB_DIR  =
     48OSGEARTH_LIB_DIR  = 
    4849OSGEARTH_INC_SPEC =
    4950OSGEARTH_LIB_SPEC = \
  • trunk/packages/vizservers/geovis/RenderServer.cpp

    r4009 r4014  
    507507        }
    508508
     509        double x, y, z;
     510        if (g_renderer->getMousePoint(&x, &y, &z)) {
     511            // send coords to client
     512            size_t length;
     513            char mesg[256];
     514
     515            length = snprintf(mesg, sizeof(mesg),
     516                              "nv>dataset coords %g %g %g\n", x, y, z);
     517
     518            queueResponse(mesg, length, Response::VOLATILE);
     519        }
     520
    509521        if (g_inBufPtr->status() == ReadBuffer::ENDFILE)
    510522            break;
  • trunk/packages/vizservers/geovis/Renderer.cpp

    r4013 r4014  
    2424#include <osgEarth/ModelLayer>
    2525#include <osgEarthUtil/EarthManipulator>
     26#include <osgEarthUtil/MouseCoordsTool>
    2627
    2728#include "Renderer.h"
     
    5354    _manipulator = new osgEarth::Util::EarthManipulator;
    5455    _viewer->setCameraManipulator(_manipulator);
     56    _coordsCallback = new MouseCoordsCallback();
    5557    _viewer->getCamera()->setNearFarRatio(0.00002);
    5658    _viewer->getCamera()->setSmallFeatureCullingPixelSize(-1.0f);
    5759    _viewer->setUpViewInWindow(0, 0, _windowWidth, _windowHeight);
    5860    _viewer->realize();
     61    if (_viewer->getEventQueue()->getUseFixedMouseInputRange()) {
     62         osgGA::GUIEventAdapter* ea = _viewer->getEventQueue()->getCurrentEventState();
     63         TRACE("Mouse range: %g %g %g %g", ea->getXmin(), ea->getXmax(), ea->getYmin(), ea->getYmax());
     64    } else {
     65        osgGA::GUIEventAdapter* ea = _viewer->getEventQueue()->getCurrentEventState();
     66         TRACE("Not fixed mouse range: %g %g %g %g", ea->getXmin(), ea->getXmax(), ea->getYmin(), ea->getYmax());
     67    }
    5968    if (_viewer->getViewerStats() != NULL) {
    6069        TRACE("Enabling stats");
     
    8089        _map = mapNode->getMap();
    8190    }
     91    if (_mouseCoordsTool.valid())
     92        _viewer->removeEventHandler(_mouseCoordsTool);
     93    _mouseCoordsTool = new osgEarth::Util::MouseCoordsTool(mapNode);
     94    _mouseCoordsTool->addCallback(_coordsCallback);
     95    _viewer->addEventHandler(_mouseCoordsTool);
    8296    _viewer->setSceneData(_sceneRoot.get());
    8397    _manipulator->setNode(NULL);
     
    194208void Renderer::setCameraOrientation(const double quat[4], bool absolute)
    195209{
     210    _manipulator->setRotation(osg::Quat(quat[1], quat[2], quat[3], quat[0]));
    196211    _needsRedraw = true;
    197212}
     
    254269
    255270    _manipulator->zoom(0, z);
     271    _needsRedraw = true;
     272}
     273
     274void Renderer::mouseDoubleClick(int button, double x, double y)
     275{
     276    _viewer->getEventQueue()->mouseDoubleButtonPress((float)x, (float)y, button);
     277    _needsRedraw = true;
     278}
     279
     280void Renderer::mouseClick(int button, double x, double y)
     281{
     282    _viewer->getEventQueue()->mouseButtonPress((float)x, (float)y, button);
     283    _needsRedraw = true;
     284}
     285
     286void Renderer::mouseDrag(int button, double x, double y)
     287{
     288    _viewer->getEventQueue()->mouseMotion((float)x, (float)y);
     289    _needsRedraw = true;
     290}
     291
     292void Renderer::mouseRelease(int button, double x, double y)
     293{
     294    _viewer->getEventQueue()->mouseButtonRelease((float)x, (float)y, button);
     295    _needsRedraw = true;
     296}
     297
     298void Renderer::mouseMotion(double x, double y)
     299{
     300    _viewer->getEventQueue()->mouseMotion((float)x, (float)y);
     301    _needsRedraw = true;
     302}
     303
     304void Renderer::mouseScroll(int direction)
     305{
     306    _viewer->getEventQueue()->mouseScroll((direction > 0 ? osgGA::GUIEventAdapter::SCROLL_UP : osgGA::GUIEventAdapter::SCROLL_DOWN));
    256307    _needsRedraw = true;
    257308}
  • trunk/packages/vizservers/geovis/Renderer.h

    r4013 r4014  
    2525#include <osgEarth/TileSource>
    2626#include <osgEarth/ModelSource>
     27#include <osgEarth/GeoData>
    2728#include <osgEarthUtil/EarthManipulator>
     29#include <osgEarthUtil/MouseCoordsTool>
    2830
    2931#include "Types.h"
     
    7880};
    7981
     82class MouseCoordsCallback : public osgEarth::Util::MouseCoordsTool::Callback
     83{
     84public:
     85    MouseCoordsCallback() :
     86        osgEarth::Util::MouseCoordsTool::Callback(),
     87        _havePoint(false)
     88    {}
     89
     90    void set(const osgEarth::GeoPoint& p, osg::View* view, osgEarth::MapNode* mapNode)
     91    {
     92        // p.y(), p.x()
     93        _pt = p;
     94        _havePoint = true;
     95    }
     96
     97    void reset(osg::View* view, osgEarth::MapNode* mapNode)
     98    {
     99        // Out of range click
     100        //_havePoint = false;
     101    }
     102
     103    bool report(double *x, double *y, double *z)
     104    {
     105        if (_havePoint) {
     106            *x = _pt.x();
     107            *y = _pt.y();
     108            *z = _pt.z();
     109            _havePoint = false;
     110            return true;
     111        }
     112        return false;
     113    }
     114
     115private:
     116    bool _havePoint;
     117    osgEarth::GeoPoint _pt;
     118};
     119
    80120/**
    81121 * \brief GIS Renderer
     
    143183    void zoomCamera(double z, bool absolute = false);
    144184
     185    // Mouse events
     186
     187    void mouseClick(int button, double x, double y);
     188
     189    void mouseDoubleClick(int button, double x, double y);
     190
     191    void mouseDrag(int button, double x, double y);
     192
     193    void mouseRelease(int button, double x, double y);
     194
     195    void mouseMotion(double x, double y);
     196
     197    void mouseScroll(int direction);
     198
    145199    // Rendering an image
    146200
     
    152206
    153207    osg::Image *getRenderedFrame();
     208
     209    bool getMousePoint(double *x, double *y, double *z)
     210    {
     211        return _coordsCallback->report(x, y, z);
     212    }
    154213
    155214private:
     
    161220
    162221    osg::ref_ptr<osg::Node> _sceneRoot;
     222    osg::ref_ptr<osgEarth::MapNode> _mapNode;
    163223    osg::ref_ptr<osgEarth::Map> _map;
    164224    osg::ref_ptr<osgViewer::Viewer> _viewer;
    165225    osg::ref_ptr<ScreenCaptureCallback> _captureCallback;
     226    osg::ref_ptr<osgEarth::Util::MouseCoordsTool> _mouseCoordsTool;
     227    osg::ref_ptr<MouseCoordsCallback> _coordsCallback;
    166228    osg::ref_ptr<osgEarth::Util::EarthManipulator> _manipulator;
    167229};
  • trunk/packages/vizservers/geovis/RendererCmd.cpp

    r4009 r4014  
    309309    lastCmdStatus = TCL_BREAK;
    310310    return TCL_OK;
     311}
     312
     313static int
     314MouseClickOp(ClientData clientData, Tcl_Interp *interp, int objc,
     315             Tcl_Obj *const *objv)
     316{
     317    int button;
     318    double x, y;
     319
     320    if (Tcl_GetIntFromObj(interp, objv[2], &button) != TCL_OK) {
     321        return TCL_ERROR;
     322    }
     323    if (Tcl_GetDoubleFromObj(interp, objv[3], &x) != TCL_OK ||
     324        Tcl_GetDoubleFromObj(interp, objv[4], &y) != TCL_OK) {
     325        return TCL_ERROR;
     326    }
     327
     328    g_renderer->mouseClick(button, x, y);
     329    return TCL_OK;
     330}
     331
     332static int
     333MouseDoubleClickOp(ClientData clientData, Tcl_Interp *interp, int objc,
     334                   Tcl_Obj *const *objv)
     335{
     336    int button;
     337    double x, y;
     338
     339    if (Tcl_GetIntFromObj(interp, objv[2], &button) != TCL_OK) {
     340        return TCL_ERROR;
     341    }
     342    if (Tcl_GetDoubleFromObj(interp, objv[3], &x) != TCL_OK ||
     343        Tcl_GetDoubleFromObj(interp, objv[4], &y) != TCL_OK) {
     344        return TCL_ERROR;
     345    }
     346
     347    g_renderer->mouseDoubleClick(button, x, y);
     348    return TCL_OK;
     349}
     350
     351static int
     352MouseDragOp(ClientData clientData, Tcl_Interp *interp, int objc,
     353            Tcl_Obj *const *objv)
     354{
     355    int button;
     356    double x, y;
     357
     358    if (Tcl_GetIntFromObj(interp, objv[2], &button) != TCL_OK) {
     359        return TCL_ERROR;
     360    }
     361    if (Tcl_GetDoubleFromObj(interp, objv[3], &x) != TCL_OK ||
     362        Tcl_GetDoubleFromObj(interp, objv[4], &y) != TCL_OK) {
     363        return TCL_ERROR;
     364    }
     365
     366    g_renderer->mouseDrag(button, x, y);
     367    return TCL_OK;
     368}
     369
     370static int
     371MouseMotionOp(ClientData clientData, Tcl_Interp *interp, int objc,
     372              Tcl_Obj *const *objv)
     373{
     374    double x, y;
     375
     376    if (Tcl_GetDoubleFromObj(interp, objv[2], &x) != TCL_OK ||
     377        Tcl_GetDoubleFromObj(interp, objv[3], &y) != TCL_OK) {
     378        return TCL_ERROR;
     379    }
     380
     381    g_renderer->mouseMotion(x, y);
     382    return TCL_OK;
     383}
     384
     385static int
     386MouseReleaseOp(ClientData clientData, Tcl_Interp *interp, int objc,
     387               Tcl_Obj *const *objv)
     388{
     389    int button;
     390    double x, y;
     391
     392    if (Tcl_GetIntFromObj(interp, objv[2], &button) != TCL_OK) {
     393        return TCL_ERROR;
     394    }
     395    if (Tcl_GetDoubleFromObj(interp, objv[3], &x) != TCL_OK ||
     396        Tcl_GetDoubleFromObj(interp, objv[4], &y) != TCL_OK) {
     397        return TCL_ERROR;
     398    }
     399
     400    g_renderer->mouseRelease(button, x, y);
     401    return TCL_OK;
     402}
     403
     404static int
     405MouseScrollOp(ClientData clientData, Tcl_Interp *interp, int objc,
     406              Tcl_Obj *const *objv)
     407{
     408    int direction;
     409
     410    if (Tcl_GetIntFromObj(interp, objv[2], &direction) != TCL_OK) {
     411        return TCL_ERROR;
     412    }
     413
     414    g_renderer->mouseScroll(direction);
     415    return TCL_OK;
     416}
     417
     418static Rappture::CmdSpec mouseOps[] = {
     419    {"click",    1, MouseClickOp,       5, 5, "button x y"},
     420    {"dblclick", 2, MouseDoubleClickOp, 5, 5, "button x y"},
     421    {"drag",     2, MouseDragOp,        5, 5, "button x y"},
     422    {"motion",   1, MouseMotionOp,      4, 4, "x y"},
     423    {"release",  1, MouseReleaseOp,     5, 5, "button x y"},
     424    {"scroll",   1, MouseScrollOp,      3, 3, "direction"},
     425};
     426static int nMouseOps = NumCmdSpecs(mouseOps);
     427
     428static int
     429MouseCmd(ClientData clientData, Tcl_Interp *interp, int objc,
     430         Tcl_Obj *const *objv)
     431{
     432    Tcl_ObjCmdProc *proc;
     433
     434    proc = Rappture::GetOpFromObj(interp, nMouseOps, mouseOps,
     435                                  Rappture::CMDSPEC_ARG1, objc, objv, 0);
     436    if (proc == NULL) {
     437        return TCL_ERROR;
     438    }
     439    return (*proc) (clientData, interp, objc, objv);
    311440}
    312441
     
    536665    Tcl_CreateObjCommand(interp, "clientinfo",     ClientInfoCmd,     clientData, NULL);
    537666    Tcl_CreateObjCommand(interp, "imgflush",       ImageFlushCmd,     clientData, NULL);
     667    Tcl_CreateObjCommand(interp, "mouse",          MouseCmd,          clientData, NULL);
    538668    Tcl_CreateObjCommand(interp, "renderer",       RendererCmd,       clientData, NULL);
    539669    Tcl_CreateObjCommand(interp, "screen",         ScreenCmd,         clientData, NULL);
     
    548678    Tcl_DeleteCommand(interp, "clientinfo");
    549679    Tcl_DeleteCommand(interp, "imgflush");
     680    Tcl_DeleteCommand(interp, "mouse");
    550681    Tcl_DeleteCommand(interp, "renderer");
    551682    Tcl_DeleteCommand(interp, "screen");
Note: See TracChangeset for help on using the changeset viewer.