コード例 #1
0
ファイル: ViewProvider.cpp プロジェクト: mdjurfeldt/FreeCAD
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");
    }
}
コード例 #2
0
ファイル: winiv.cpp プロジェクト: mvancompernolle/ai_project
void
GlutWindowInventor::OnSpecial(int key, int x, int y)
{
    GlutWindow::OnSpecial(key,x,y);

    SoKeyboardEvent event;
    SoKeyboardEvent::Key k;

    switch (key)
    {

    case GLUT_KEY_F1:   k = SoKeyboardEvent::F1;  break;
    case GLUT_KEY_F2:   k = SoKeyboardEvent::F2;  break;
    case GLUT_KEY_F3:   k = SoKeyboardEvent::F3;  break;
    case GLUT_KEY_F4:   k = SoKeyboardEvent::F4;  break;
    case GLUT_KEY_F5:   k = SoKeyboardEvent::F5;  break;
    case GLUT_KEY_F6:   k = SoKeyboardEvent::F6;  break;
    case GLUT_KEY_F7:   k = SoKeyboardEvent::F7;  break;
    case GLUT_KEY_F8:   k = SoKeyboardEvent::F8;  break;
    case GLUT_KEY_F9:   k = SoKeyboardEvent::F9;  break;
    case GLUT_KEY_F10:  k = SoKeyboardEvent::F10; break;
    case GLUT_KEY_F11:  k = SoKeyboardEvent::F11; break;
    case GLUT_KEY_F12:  k = SoKeyboardEvent::F12; break;

    case GLUT_KEY_LEFT:  k = SoKeyboardEvent::LEFT_ARROW;  break;
    case GLUT_KEY_UP:    k = SoKeyboardEvent::UP_ARROW;    break;
    case GLUT_KEY_RIGHT: k = SoKeyboardEvent::RIGHT_ARROW; break;
    case GLUT_KEY_DOWN:  k = SoKeyboardEvent::DOWN_ARROW;  break;

    case GLUT_KEY_PAGE_UP:   k = SoKeyboardEvent::PAGE_UP;   break;
    case GLUT_KEY_PAGE_DOWN: k = SoKeyboardEvent::PAGE_DOWN; break;
    case GLUT_KEY_HOME:      k = SoKeyboardEvent::HOME;      break;
    case GLUT_KEY_END:       k = SoKeyboardEvent::END;       break;
    case GLUT_KEY_INSERT:    k = SoKeyboardEvent::INSERT;    break;

    default:
        return;
    }

    event.setKey(k);
    event.setPosition(SbVec2s(x,_viewport.height()-y));
    event.setState(SoButtonEvent::DOWN);
    processEvent(&event);
    inventorTick();
}
コード例 #3
0
void QCtkXipSGWidget::keyEvent(QKeyEvent *event)
{

  // Pass the QtKeyEvent to open inventor
  SoKeyboardEvent e;
  SbTime time;
  time.setToTimeOfDay();
  e.setTime(time);

  if (event->modifiers() & Qt::ShiftModifier)
    e.setShiftDown(TRUE);
  if (event->modifiers() & Qt::ControlModifier)
    e.setCtrlDown(TRUE);
  if (event->modifiers() & Qt::AltModifier)
    e.setAltDown(TRUE);

  if(event->type() == QEvent::KeyPress)
    e.setState(SoButtonEvent::DOWN);
  else if(event->type() == QEvent::KeyRelease)
    e.setState(SoButtonEvent::UP);

  if(mQtInventorKeyMap.find((Qt::Key)event->key()) != mQtInventorKeyMap.end())
  {
    e.setKey(mQtInventorKeyMap[(Qt::Key)event->key()]);
  }
  if(mQtInventorKeyMap.find((Qt::Key)event->nativeVirtualKey()) != mQtInventorKeyMap.end())
  {
    e.setKey(mQtInventorKeyMap[(Qt::Key)event->nativeVirtualKey()]);
  }

  event->accept();

  if (mSceneManager->processEvent(&e))
  {
    //repaint();
    update();
  }
}
コード例 #4
0
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;
}
コード例 #5
0
ファイル: winiv.cpp プロジェクト: mvancompernolle/ai_project
void
GlutWindowInventor::OnKeyboard(unsigned char key, int x, int y)
{
    GlutWindow::OnKeyboard(key,x,y);

    // TODO: Check that delete, enter, backspace and insert are handled correctly

    SoKeyboardEvent event;
    SoKeyboardEvent::Key k;

    switch (key)
    {

    case '0':  k = SoKeyboardEvent::NUMBER_0; break;
    case '1':  k = SoKeyboardEvent::NUMBER_1; break;
    case '2':  k = SoKeyboardEvent::NUMBER_2; break;
    case '3':  k = SoKeyboardEvent::NUMBER_3; break;
    case '4':  k = SoKeyboardEvent::NUMBER_4; break;
    case '5':  k = SoKeyboardEvent::NUMBER_5; break;
    case '6':  k = SoKeyboardEvent::NUMBER_6; break;
    case '7':  k = SoKeyboardEvent::NUMBER_7; break;
    case '8':  k = SoKeyboardEvent::NUMBER_8; break;
    case '9':  k = SoKeyboardEvent::NUMBER_9; break;

    case 'a':  case 'A': k = SoKeyboardEvent::A; break;
    case 'b':  case 'B': k = SoKeyboardEvent::B; break;
    case 'c':  case 'C': k = SoKeyboardEvent::C; break;
    case 'd':  case 'D': k = SoKeyboardEvent::D; break;
    case 'e':  case 'E': k = SoKeyboardEvent::E; break;
    case 'f':  case 'F': k = SoKeyboardEvent::F; break;
    case 'g':  case 'G': k = SoKeyboardEvent::G; break;
    case 'h':  case 'H': k = SoKeyboardEvent::H; break;
    case 'i':  case 'I': k = SoKeyboardEvent::I; break;
    case 'j':  case 'J': k = SoKeyboardEvent::J; break;
    case 'k':  case 'K': k = SoKeyboardEvent::K; break;
    case 'l':  case 'L': k = SoKeyboardEvent::L; break;
    case 'm':  case 'M': k = SoKeyboardEvent::M; break;
    case 'n':  case 'N': k = SoKeyboardEvent::N; break;
    case 'o':  case 'O': k = SoKeyboardEvent::O; break;
    case 'p':  case 'P': k = SoKeyboardEvent::P; break;
    case 'q':  case 'Q': k = SoKeyboardEvent::Q; break;
    case 'r':  case 'R': k = SoKeyboardEvent::R; break;
    case 's':  case 'S': k = SoKeyboardEvent::S; break;
    case 't':  case 'T': k = SoKeyboardEvent::T; break;
    case 'u':  case 'U': k = SoKeyboardEvent::U; break;
    case 'v':  case 'V': k = SoKeyboardEvent::V; break;
    case 'w':  case 'W': k = SoKeyboardEvent::W; break;
    case 'x':  case 'X': k = SoKeyboardEvent::X; break;
    case 'y':  case 'Y': k = SoKeyboardEvent::Y; break;
    case 'z':  case 'Z': k = SoKeyboardEvent::Z; break;

    case ' ':  k = SoKeyboardEvent::SPACE;  break;
    case '\n': k = SoKeyboardEvent::RETURN; break;
    case ',':  k = SoKeyboardEvent::COMMA;  break;
    case '-':  k = SoKeyboardEvent::MINUS;  break;
    case '.':  k = SoKeyboardEvent::PERIOD; break;
    case '/':  k = SoKeyboardEvent::SLASH;  break;
    case ';':  k = SoKeyboardEvent::SEMICOLON;  break;
    case '=':  k = SoKeyboardEvent::EQUAL;  break;
    case '(':  k = SoKeyboardEvent::BRACKETLEFT;  break;
    case '\\': k = SoKeyboardEvent::BACKSLASH;    break;
    case ')':  k = SoKeyboardEvent::BRACKETRIGHT; break;

    default:
        return;
    }

    event.setKey(k);
    event.setPosition(SbVec2s(x,_viewport.height()-y));
    event.setState(SoButtonEvent::DOWN);
    processEvent(&event);
    inventorTick();
}