-
Notifications
You must be signed in to change notification settings - Fork 0
/
PanelActionListener.cpp
97 lines (95 loc) · 2.54 KB
/
PanelActionListener.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "PanelActionListener.h"
#include "GraphFitting.h"
extern CGraphFitting *pGf;
CPanelActionListener::CPanelActionListener(void)
{
curLine=-1;
}
CPanelActionListener::~CPanelActionListener(void)
{
}
void CPanelActionListener::Accept(osgViewer::Viewer * _viewer,osg::Switch* _switch,osg::Switch* pGrp)
{
pViewer=_viewer;
pViewer->addEventHandler(this);
pSwitch=_switch;
pDetailGrp=pGrp;
}
bool CPanelActionListener::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa)
{
switch(ea.getEventType())
{
case GUIEventAdapter::KEYDOWN:
KeyDownEvent(ea,aa);
break;
case GUIEventAdapter::PUSH:
//MousePressEvent(ea,aa);
break;
case GUIEventAdapter::DRAG:
//MouseDragEvent(ea,aa);
break;
case GUIEventAdapter::DOUBLECLICK:
MouseClickEvent(ea,aa);
break;
case GUIEventAdapter::MOVE:
//MouseMoveEvent(ea,aa);
break;
//case GUIEventAdapter::FRAME:
//displayEachLine();
//break;
default:
break;
}
return false;
}
void CPanelActionListener::MousePressEvent(const GUIEventAdapter& ea,GUIActionAdapter& aa)
{
}
void CPanelActionListener::MouseMoveEvent(const GUIEventAdapter& ea,GUIActionAdapter& aa)
{
}
void CPanelActionListener::MouseClickEvent(const GUIEventAdapter& ea,GUIActionAdapter& aa)
{
if (ea.getButton()==GUIEventAdapter::LEFT_MOUSE_BUTTON)
{
osgUtil::LineSegmentIntersector::Intersections intersections;
if(pViewer->computeIntersections(ea.getX(),ea.getY(),intersections))
{
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();hitr!=intersections.end();++hitr)
{
osg::Node* node = hitr->nodePath.empty() ? NULL : hitr->nodePath.back();
if(node->getNumDescriptions()>0 && node->getDescription(0)=="3DLINE")//µ¥»÷Á˹ã¸æÅÆ
{
curLine=atoi(node->getName().c_str());
//pSwitch->setSingleChildOn(curLine);
pSwitch->setAllChildrenOff();
pDetailGrp->removeChildren(1,pDetailGrp->getNumChildren());
osg::Node* pLinePoints=pGf->getLine(curLine).create3DLinePoints(curLine);
pDetailGrp->addChild(pLinePoints);
pDetailGrp->setSingleChildOn(1);
//printf("CLICK LINE %s, support points=%d\n",node->getName().c_str(),0);
break;
}
}
}
}
}
void CPanelActionListener::MouseDragEvent(const GUIEventAdapter& ea,GUIActionAdapter& aa)
{
}
void CPanelActionListener::KeyDownEvent(const GUIEventAdapter& ea,GUIActionAdapter& aa)
{
switch(ea.getKey())
{
case 'n':
case 'N':
pSwitch->setAllChildrenOn();
pDetailGrp->setSingleChildOn(0);
break;
case 'm':
case 'M':
pSwitch->setAllChildrenOff();
pDetailGrp->setSingleChildOn(0);
break;
}
}