void ViewProvider::eventCallback(void * ud, SoEventCallback * node) { const SoEvent * ev = node->getEvent(); Gui::View3DInventorViewer* viewer = reinterpret_cast<Gui::View3DInventorViewer*>(node->getUserData()); ViewProvider *self = reinterpret_cast<ViewProvider*>(ud); assert(self); try { // Keyboard events if (ev->getTypeId().isDerivedFrom(SoKeyboardEvent::getClassTypeId())) { SoKeyboardEvent * ke = (SoKeyboardEvent *)ev; const SbBool press = ke->getState() == SoButtonEvent::DOWN ? true : false; switch (ke->getKey()) { case SoKeyboardEvent::ESCAPE: if (self->keyPressed (press, ke->getKey())) { node->setHandled(); } else { Gui::TimerFunction* func = new Gui::TimerFunction(); func->setAutoDelete(true); Gui::Document* doc = Gui::Application::Instance->activeDocument(); func->setFunction(boost::bind(&Document::resetEdit, doc)); QTimer::singleShot(0, func, SLOT(timeout())); } break; default: // call the virtual method if (self->keyPressed (press, ke->getKey())) node->setHandled(); break; } } // switching the mouse buttons else if (ev->getTypeId().isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) { const SoMouseButtonEvent * const event = (const SoMouseButtonEvent *) ev; const int button = event->getButton(); const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false; // call the virtual method if (self->mouseButtonPressed(button,press,ev->getPosition(),viewer)) node->setHandled(); } // Mouse Movement handling else if (ev->getTypeId().isDerivedFrom(SoLocation2Event::getClassTypeId())) { if (self->mouseMove(ev->getPosition(),viewer)) node->setHandled(); } } catch (const Base::Exception& e) { Base::Console().Error("Unhandled exception in ViewProvider::eventCallback: %s\n", e.what()); } catch (const std::exception& e) { Base::Console().Error("Unhandled std exception in ViewProvider::eventCallback: %s\n", e.what()); } catch (...) { Base::Console().Error("Unhandled unknown C++ exception in ViewProvider::eventCallback"); } }
bool ViewProviderCurveNet::handleEvent(const SoEvent * const ev, Gui::View3DInventorViewer &Viewer) { SbVec3f point, norm; // get the position of the mouse const SbVec2s pos(ev->getPosition()); // Keybooard events if (ev->getTypeId().isDerivedFrom(SoKeyboardEvent::getClassTypeId())) { SoKeyboardEvent * ke = (SoKeyboardEvent *)ev; switch (ke->getKey()) { case SoKeyboardEvent::LEFT_ALT: case SoKeyboardEvent::RIGHT_ALT: case SoKeyboardEvent::LEFT_CONTROL: case SoKeyboardEvent::RIGHT_CONTROL: case SoKeyboardEvent::LEFT_SHIFT: case SoKeyboardEvent::RIGHT_SHIFT: break; default: break; } } // switching the mouse buttons if (ev->getTypeId().isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) { const SoMouseButtonEvent * const event = (const SoMouseButtonEvent *) ev; const int button = event->getButton(); const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false; // which button pressed? switch (button) { case SoMouseButtonEvent::BUTTON1: if (press) { Base::Console().Log("ViewProviderCurveNet::handleEvent() press left\n"); bool bIsNode = false; for (std::list<Node>::iterator It = NodeList.begin();It != NodeList.end(); It++) { if (It->pcHighlight->isHighlighted()) { bIsNode = true; PointToMove = *It; break; } } if (bIsNode) { // set the provider in point move mode and remember the point bMovePointMode = true; // PointToMove = *It; ### Error 'It' is out of scope->move inside the loop return true; } else if(Viewer.pickPoint(pos,point,norm)) { Node n; Base::Console().Log("Picked(%f,%f,%f)\n",point[0],point[1],point[2]); SoSeparator *TransRoot = new SoSeparator(); n.pcTransform = new SoTransform(); TransRoot->addChild(n.pcTransform); n.pcTransform->translation.setValue(point); n.pcHighlight = new Gui::SoFCSelection(); SoSphere * sphere = new SoSphere; sphere->radius = (float)pcLineStyle->pointSize.getValue(); n.pcHighlight->addChild(sphere); TransRoot->addChild(n.pcHighlight); VertexRoot->addChild(TransRoot); NodeList.push_back(n); return true; } } else // if(pressd).. { if (bMovePointMode) { bMovePointMode = false; return true; } } break; } } // Mouse Movement handling if (ev->getTypeId().isDerivedFrom(SoLocation2Event::getClassTypeId())) { // const SoLocation2Event * const event = (const SoLocation2Event *) ev; if (bMovePointMode && Viewer.pickPoint(pos,point,norm) ){ PointToMove.pcTransform->translation.setValue(point); return true; } } // event not processed return false; }