+ Thomas Anderson's patch for spacenav

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5242 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
wmayer 2011-12-09 11:29:51 +00:00
parent a5c8113aaa
commit 012e50c524
6 changed files with 123 additions and 56 deletions

View File

@ -205,11 +205,11 @@ void ObjectLabelObserver::slotRelabelObject(const App::DocumentObject& obj, cons
// make sure that there is a name conflict otherwise we don't have to do anything
if (match) {
// remove number from end to avoid lengthy names
size_t lastpos = label.length()-1;
while (label[lastpos] >= 48 && label[lastpos] <= 57)
lastpos--;
label = label.substr(0, lastpos+1);
// remove number from end to avoid lengthy names
size_t lastpos = label.length()-1;
while (label[lastpos] >= 48 && label[lastpos] <= 57)
lastpos--;
label = label.substr(0, lastpos+1);
label = Base::Tools::getUniqueName(label, objectLabels, 3);
this->current = &obj;
const_cast<App::DocumentObject&>(obj).Label.setValue(label);
@ -1437,7 +1437,7 @@ public:
(int)event->type());
}
try {
if (event->type() == Spaceball::ButtonEvent::ButtonEventType)
if (event->type() == Spaceball::ButtonEvent::ButtonEventType || Spaceball::MotionEvent::MotionEventType)
return processSpaceballEvent(receiver, event);
else
return QApplication::notify(receiver, event);

View File

@ -80,15 +80,31 @@ void Gui::GUIApplicationNativeEventAware::initSpaceball(QMainWindow *window)
bool Gui::GUIApplicationNativeEventAware::processSpaceballEvent(QObject *object, QEvent *event)
{
Spaceball::ButtonEvent *ballEvent = dynamic_cast<Spaceball::ButtonEvent *>(event);
if (!ballEvent)
return true;
QApplication::notify(object, ballEvent);
if (!ballEvent->isHandled())
QApplication::notify(object, event);
if (event->type() == Spaceball::MotionEvent::MotionEventType)
{
//make a new event and post to parent.
Spaceball::ButtonEvent *newEvent = new Spaceball::ButtonEvent(*ballEvent);
postEvent(object->parent(), newEvent);
Spaceball::MotionEvent *motionEvent = dynamic_cast<Spaceball::MotionEvent*>(event);
if (!motionEvent)
return true;
if (!motionEvent->isHandled())
{
//make a new event and post to parent.
Spaceball::MotionEvent *newEvent = new Spaceball::MotionEvent(*motionEvent);
postEvent(object->parent(), newEvent);
}
}
if (event->type() == Spaceball::ButtonEvent::ButtonEventType)
{
Spaceball::ButtonEvent *buttonEvent = dynamic_cast<Spaceball::ButtonEvent*>(event);
if (!buttonEvent)
return true;
if (!buttonEvent->isHandled())
{
//make a new event and post to parent.
Spaceball::ButtonEvent *newEvent = new Spaceball::ButtonEvent(*buttonEvent);
postEvent(object->parent(), newEvent);
}
}
return true;
}

View File

@ -104,6 +104,8 @@
#include "ViewProviderExtern.h"
#include "SpaceballEvent.h"
#include "View3DInventor.h"
#include "View3DInventorViewer.h"
#if defined(Q_OS_WIN32)
#define slots
@ -596,6 +598,27 @@ bool MainWindow::event(QEvent *e)
else
return true;
}
else if (e->type() == Spaceball::MotionEvent::MotionEventType) {
Spaceball::MotionEvent *motionEvent = dynamic_cast<Spaceball::MotionEvent *>(e);
if (!motionEvent)
return true;
motionEvent->setHandled(true);
Gui::Document *doc = Application::Instance->activeDocument();
if (!doc)
return true;
View3DInventor *temp = dynamic_cast<View3DInventor *>(doc->getActiveView());
if (!temp)
return true;
View3DInventorViewer *view = temp->getViewer();
if (!view)
return true;
QWidget *viewWidget = view->getGLWidget();
if (viewWidget) {
Spaceball::MotionEvent anotherEvent(*motionEvent);
qApp->sendEvent(viewWidget, &anotherEvent);
}
return true;
}
return QMainWindow::event(e);
}

View File

@ -28,11 +28,27 @@ using namespace Spaceball;
int MotionEvent::MotionEventType = -1;
int ButtonEvent::ButtonEventType = -1;
MotionEvent::MotionEvent() : QInputEvent(static_cast<QEvent::Type>(MotionEventType)),
EventBase::EventBase(QEvent::Type event) : QInputEvent(static_cast<QEvent::Type>(event)), handled(false)
{
}
MotionEvent::MotionEvent() : EventBase(static_cast<QEvent::Type>(MotionEventType)),
xTrans(0), yTrans(0), zTrans(0), xRot(0), yRot(0), zRot(0)
{
}
MotionEvent::MotionEvent(const MotionEvent& in) : EventBase(static_cast<QEvent::Type>(MotionEventType))
{
xTrans = in.xTrans;
yTrans = in.yTrans;
zTrans = in.zTrans;
xRot = in.xRot;
yRot = in.yRot;
zRot = in.zRot;
handled = in.handled;
}
void MotionEvent::translations(int &xTransOut, int &yTransOut, int &zTransOut)
{
xTransOut = xTrans;
@ -62,12 +78,12 @@ void MotionEvent::setRotations(const int &xRotIn, const int &yRotIn, const int &
}
ButtonEvent::ButtonEvent() : QInputEvent(static_cast<QEvent::Type>(ButtonEventType)),
buttonState(BUTTON_NONE), button(0), handled(false)
ButtonEvent::ButtonEvent() : EventBase(static_cast<QEvent::Type>(ButtonEventType)),
buttonState(BUTTON_NONE), button(0)
{
}
ButtonEvent::ButtonEvent(const ButtonEvent& in) : QInputEvent(static_cast<QEvent::Type>(ButtonEventType))
ButtonEvent::ButtonEvent(const ButtonEvent& in) : EventBase(static_cast<QEvent::Type>(ButtonEventType))
{
buttonState = in.buttonState;
button = in.button;

View File

@ -28,10 +28,22 @@ namespace Spaceball
{
enum ButtonStateType {BUTTON_NONE = 0, BUTTON_PRESSED, BUTTON_RELEASED};
class MotionEvent : public QInputEvent
class EventBase : public QInputEvent
{
public:
bool isHandled(){return handled;}
void setHandled(bool sig){handled = sig;}
protected:
EventBase(QEvent::Type event);
bool handled;
};
class MotionEvent : public EventBase
{
public:
MotionEvent();
MotionEvent(const MotionEvent& in);
void translations(int &xTransOut, int &yTransOut, int &zTransOut);
void setTranslations(const int &xTransIn, const int &yTransIn, const int &zTransIn);
int translationX(){return xTrans;}
@ -53,9 +65,10 @@ namespace Spaceball
int xRot;
int yRot;
int zRot;
bool handled;
};
class ButtonEvent : public QInputEvent
class ButtonEvent : public EventBase
{
public:
ButtonEvent();
@ -64,15 +77,12 @@ namespace Spaceball
void setButtonStatus(const ButtonStateType &buttonStatusIn);
int buttonNumber();
void setButtonNumber(const int &buttonNumberIn);
bool isHandled(){return handled;}
void setHandled(bool in){handled = in;}
static int ButtonEventType;
private:
ButtonStateType buttonState;
int button;
bool handled;
};
}
#endif // SPACEBALLEVENT_H

View File

@ -1059,6 +1059,8 @@ void View3DInventorViewer::processEvent(QEvent * event)
return;
}
motionEvent->setHandled(true);
static float translationConstant(-.001f);
float xTrans, yTrans, zTrans;
xTrans = static_cast<float>(motionEvent->translationX());
@ -1379,15 +1381,15 @@ void View3DInventorViewer::viewAll()
}
//navigation->viewAll();
}
void View3DInventorViewer::viewAll(float factor)
{
void View3DInventorViewer::viewAll(float factor)
{
SoCamera * cam = this->getCamera();
if (!cam) return;
if (factor <= 0.0f) return;
if (factor != 1.0f) {
SoSearchAction sa;
if (factor != 1.0f) {
SoSearchAction sa;
sa.setType(SoSkipBoundingGroup::getClassTypeId());
sa.setInterest(SoSearchAction::ALL);
sa.apply(this->getSceneGraph());
@ -1425,11 +1427,11 @@ void View3DInventorViewer::viewAll(float factor)
graph->addChild(cube);
cam->viewAll(graph, this->getViewportRegion());
graph->unref();
}
else {
viewAll();
}
}
}
else {
viewAll();
}
}
void View3DInventorViewer::viewSelection()
{
@ -2053,16 +2055,16 @@ SoPath * View3DInventorViewer::pickFilterCB(void *viewer, const SoPickedPoint *
{
ViewProvider* vp = static_cast<View3DInventorViewer*>(viewer)->getViewProviderByPath(pp->getPath());
if (vp && vp->useNewSelectionModel()) {
std::string e = vp->getElement(pp);
vp->getSelectionShape(e.c_str());
static char buf[513];
snprintf(buf,512,"Hovered: %s (%f,%f,%f)"
,e.c_str()
,pp->getPoint()[0]
,pp->getPoint()[1]
,pp->getPoint()[2]);
getMainWindow()->statusBar()->showMessage(QString::fromAscii(buf),3000);
std::string e = vp->getElement(pp);
vp->getSelectionShape(e.c_str());
static char buf[513];
snprintf(buf,512,"Hovered: %s (%f,%f,%f)"
,e.c_str()
,pp->getPoint()[0]
,pp->getPoint()[1]
,pp->getPoint()[2]);
getMainWindow()->statusBar()->showMessage(QString::fromAscii(buf),3000);
}
return pp->getPath();
}
@ -2094,18 +2096,18 @@ ViewProvider* View3DInventorViewer::getViewProviderByPath(SoPath * path) const
ViewProvider* View3DInventorViewer::getViewProviderByPathFromTail(SoPath * path) const
{
// Make sure I'm the lowest LocHL in the pick path!
for (int i = 0; i < path->getLength(); i++) {
SoNode *node = path->getNodeFromTail(i);
if (node->isOfType(SoSeparator::getClassTypeId())) {
std::map<SoSeparator*,ViewProvider*>::const_iterator it = _ViewProviderMap.find(static_cast<SoSeparator*>(node));
if (it != _ViewProviderMap.end()){
return it->second;
}
}
}
return 0;
// Make sure I'm the lowest LocHL in the pick path!
for (int i = 0; i < path->getLength(); i++) {
SoNode *node = path->getNodeFromTail(i);
if (node->isOfType(SoSeparator::getClassTypeId())) {
std::map<SoSeparator*,ViewProvider*>::const_iterator it = _ViewProviderMap.find(static_cast<SoSeparator*>(node));
if (it != _ViewProviderMap.end()){
return it->second;
}
}
}
return 0;
}
std::vector<ViewProvider*> View3DInventorViewer::getViewProvidersOfType(const Base::Type& typeId) const