关闭

OSG点选事件的基类

1432人阅读 评论(0) 收藏 举报
分类:

由于我的例子中有多处需要用到点选操作,我不想对一段代码到处复制粘贴,所以我写了一基类对点选操作进行管理。
其功能有:
1. 管理点选事件的添加和删除操作
2. 管理点选成功后Qt信号的发送
话不多数,上代码。
handleadapter.h

class HandleAdapter : public QObject
{
    Q_OBJECT

public:
    HandleAdapter(GraphicsView* view, QObject* parent = NULL);
    ~HandleAdapter();

    void benginHandle();
    void endHandle();

private slots:
    // 虚函数的实现,有其子类来
    virtual void slotPicked(osg::Vec3d pos){}
    virtual void slotMoveing(osg::Vec3d pos){}

    virtual void slotPickedXYZ(osg::Vec3d pos){}
    virtual void slotMoveingXYZ(osg::Vec3d pos){}

    virtual void slotRightHandle(){}

public:
    GraphicsView* m_pMap3D;
    osg::Group* m_pLayerGroup;
    PickHandle* m_pEventHandle;
};

功能实现如handleadapter.cpp

HandleAdapter::HandleAdapter(GraphicsView* view, QObject* parent/* = NULL*/)
    : m_pMap3D(view), QObject(parent)
{
    m_pLayerGroup = new osg::Group;
    m_pMap3D->getRoot()->addChild(m_pLayerGroup);

    m_pEventHandle = new PickHandle(m_pMap3D->getSRS());
}

HandleAdapter::~HandleAdapter()
{

}

void HandleAdapter::benginHandle()
{
    m_pMap3D->getOSGViewer()->addEventHandler(m_pEventHandle);
    connect(m_pEventHandle, SIGNAL(signalPicked(osg::Vec3d)), this, SLOT(slotPicked(osg::Vec3d)));
    connect(m_pEventHandle, SIGNAL(signalMoving(osg::Vec3d)), this, SLOT(slotMoveing(osg::Vec3d)));
    connect(m_pEventHandle, SIGNAL(signalRightPicked()), this, SLOT(slotRightHandle()));
    connect(m_pEventHandle, SIGNAL(signalPickedXYZ(osg::Vec3d)), this, SLOT(slotPickedXYZ(osg::Vec3d)));
    connect(m_pEventHandle, SIGNAL(signalMovingXYZ(osg::Vec3d)), this, SLOT(slotMoveingXYZ(osg::Vec3d)));
}

void HandleAdapter::endHandle()
{
    disconnect(m_pEventHandle, SIGNAL(signalPicked(osg::Vec3d)), this, SLOT(slotPicked(osg::Vec3d)));
    disconnect(m_pEventHandle, SIGNAL(signalMoving(osg::Vec3d)), this, SLOT(slotMoveing(osg::Vec3d)));
    disconnect(m_pEventHandle, SIGNAL(signalRightPicked()), this, SLOT(slotRightHandle()));
    disconnect(m_pEventHandle, SIGNAL(signalPickedXYZ(osg::Vec3d)), this, SLOT(slotPickedXYZ(osg::Vec3d)));
    disconnect(m_pEventHandle, SIGNAL(signalMovingXYZ(osg::Vec3d)), this, SLOT(slotMoveingXYZ(osg::Vec3d)));
    m_pMap3D->getOSGViewer()->removeEventHandler(m_pEventHandle);
}

好了,点选操作的基本功能就完善了,下面就可以开始进行功能性操作了。请看下一篇,画线。

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:128715次
    • 积分:1606
    • 等级:
    • 排名:千里之外
    • 原创:44篇
    • 转载:0篇
    • 译文:0篇
    • 评论:101条
    文章分类
    最新评论