bool PickHandler::handleKeyDown( const osgGA::GUIEventAdapter& ea, GUIActionAdapter& aa) { if(ea.getKey() == osgGA::GUIEventAdapter::KEY_Control_R || ea.getKey() == osgGA::GUIEventAdapter::KEY_Control_L) { isCtrlPressed = true; } else if(ea.getKey() == osgGA::GUIEventAdapter::KEY_Shift_L || ea.getKey() == osgGA::GUIEventAdapter::KEY_Shift_R) { isShiftPressed = true; } else if(ea.getKey() == osgGA::GUIEventAdapter::KEY_Alt_L || ea.getKey() == osgGA::GUIEventAdapter::KEY_Alt_R) { isAltPressed = true; } else if(ea.getKey() == 'q') { Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph(); Util::ElementSelector::randomElementSelector(currentGraph->getNodes(), currentGraph->getEdges(), appConf->getValue("Viewer.PickHandler.AutopickedNodes").toInt(), this); } else if(ea.getKey() == 'w') { Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph(); Util::ElementSelector::weightedElementSelector(currentGraph->getNodes(), appConf->getValue("Viewer.PickHandler.AutopickedNodes").toInt(), this); } return false; }
bool CoreWindow::removeClick() { Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph(); QLinkedList<osg::ref_ptr<Data::Edge> > * selectedEdges = viewerWidget->getPickHandler()->getSelectedEdges(); while (selectedEdges->size () > 0) { osg::ref_ptr<Data::Edge> existingEdge1 = (* (selectedEdges->constBegin())); currentGraph->removeEdge(existingEdge1); selectedEdges->removeFirst (); } currentGraph = Manager::GraphManager::getInstance()->getActiveGraph(); QLinkedList<osg::ref_ptr<Data::Node> > * selectedNodes = viewerWidget->getPickHandler()->getSelectedNodes(); while (selectedNodes->size () > 0) { osg::ref_ptr<Data::Node> existingNode1 = (* (selectedNodes->constBegin())); if (existingNode1->isRemovableByUser()) currentGraph->removeNode(existingNode1); selectedNodes->removeFirst (); } int NodesCount=currentGraph->getNodes()->size(); cout<<NodesCount; if (isPlaying) layout->play(); return true; }
bool PickHandler::doNodePick(osg::NodePath nodePath) { Data::Node * n = dynamic_cast<Data::Node *>(nodePath[nodePath.size() - 1]); if (n != NULL) { if (isAltPressed && pickMode == PickMode::NONE && !isShiftPressed) { cameraManipulator->setCenter(n->targetPosition()); } else if (isAltPressed && pickMode == PickMode::NONE && isShiftPressed) { if (appConf->getValue("Viewer.PickHandler.SelectInterestPoints").toInt() == 1) { Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph(); Util::ElementSelector::weightedElementSelector(currentGraph->getNodes(), appConf->getValue("Viewer.PickHandler.AutopickedNodes").toInt(), this); } bool wasEmpty = false; if (pickedNodes.isEmpty()) { pickedNodes.append(n); wasEmpty = true; } if (appConf->getValue("Viewer.Display.CameraPositions").toInt() == 1) { n->setColor(osg::Vec4(0, 1, 0, 1)); } cameraManipulator->setNewPosition(n->getCurrentPosition(), getSelectionCenter(false), getSelectedNodes()->toStdList(), getSelectedEdges()->toStdList()); if (wasEmpty) pickedNodes.removeFirst(); } else if (pickMode != PickMode::NONE) { if (!pickedNodes.contains(n)) { pickedNodes.append(n); n->setSelected(true); } if (isCtrlPressed) unselectPickedNodes(n); return true; } } return false; }
bool PickHandler::doEdgePick(osg::NodePath nodePath, unsigned int primitiveIndex) { osg::Geode * geode = dynamic_cast<osg::Geode *>(nodePath[nodePath.size() - 1]); if (geode != 0) { osg::Drawable * d = geode->getDrawable(0); osg::Geometry * geometry = d->asGeometry(); if (geometry != NULL) { // zmena (plesko): ak vyber zachytil avatara, nastal segmentation fault, // lebo sa vyberal neexistujuci primitiveSet Data::Edge * e; if (geometry->getNumPrimitiveSets() > primitiveIndex) { e = dynamic_cast<Data::Edge *>(geometry->getPrimitiveSet(primitiveIndex)); } else { return false; } // koniec zmeny if (e != NULL) { if (isAltPressed && pickMode == PickMode::NONE && !isShiftPressed) { osg::ref_ptr<osg::Vec3Array> coords = e->getCooridnates(); cameraManipulator->setCenter(DataHelper::getMassCenter(coords)); cameraManipulator->setDistance(Util::ApplicationConfig::get()->getValue("Viewer.PickHandler.PickedEdgeDistance").toFloat()); } else if (isAltPressed && pickMode == PickMode::NONE && isShiftPressed) { if (appConf->getValue("Viewer.PickHandler.SelectInterestPoints").toInt() == 1) { Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph(); Util::ElementSelector::weightedElementSelector(currentGraph->getNodes(), appConf->getValue("Viewer.PickHandler.AutopickedNodes").toInt(), this); } bool wasEmpty = false; if (pickedEdges.isEmpty()) { pickedEdges.append(e); wasEmpty = true; } osg::Vec3f edgeCenter = (e->getSrcNode()->getCurrentPosition() + e->getDstNode()->getCurrentPosition()) / 2; cameraManipulator->setNewPosition(edgeCenter, getSelectionCenter(false), getSelectedNodes()->toStdList(), getSelectedEdges()->toStdList()); if (wasEmpty) pickedEdges.removeFirst(); } else if (pickMode != PickMode::NONE) { if (!pickedEdges.contains(e)) { pickedEdges.append(e); e->setSelected(true); } if (isCtrlPressed) unselectPickedEdges(e); return true; } return true; } } } return false; }
bool PickHandler::handleKeyDown( const osgGA::GUIEventAdapter& ea, GUIActionAdapter& aa) { if(ea.getKey() == osgGA::GUIEventAdapter::KEY_Control_R || ea.getKey() == osgGA::GUIEventAdapter::KEY_Control_L) { isCtrlPressed = true; } else if(ea.getKey() == osgGA::GUIEventAdapter::KEY_Shift_L || ea.getKey() == osgGA::GUIEventAdapter::KEY_Shift_R) { isShiftPressed = true; } else if(ea.getKey() == osgGA::GUIEventAdapter::KEY_Alt_L || ea.getKey() == osgGA::GUIEventAdapter::KEY_Alt_R) { isAltPressed = true; } else if(ea.getKey() == 'q') { Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph(); Util::ElementSelector::randomElementSelector(currentGraph->getNodes(), currentGraph->getEdges(), appConf->getValue("Viewer.PickHandler.AutopickedNodes").toInt(), this); } else if(ea.getKey() == 'w') { Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph(); Util::ElementSelector::weightedElementSelector(currentGraph->getNodes(), appConf->getValue("Viewer.PickHandler.AutopickedNodes").toInt(), this); } // FULLSCREEN else if(ea.getKey() == 'l' || ea.getKey() == 'L') { bool hideToolbars = appConf->getValue("Viewer.Fullscreen").toInt(); if( AppCore::Core::getInstance()->getCoreWindow()->isFullScreen()){ AppCore::Core::getInstance()->getCoreWindow()->menuBar()->show(); AppCore::Core::getInstance()->getCoreWindow()->statusBar()->show(); AppCore::Core::getInstance()->getCoreWindow()->showNormal(); if(hideToolbars){ QList<QToolBar *> toolbars = AppCore::Core::getInstance()->getCoreWindow()->findChildren<QToolBar *>(); QListIterator<QToolBar *> i(toolbars); while (i.hasNext()){ i.next()->show(); } } } else { AppCore::Core::getInstance()->getCoreWindow()->menuBar()->hide(); AppCore::Core::getInstance()->getCoreWindow()->statusBar()->hide(); AppCore::Core::getInstance()->getCoreWindow()->showFullScreen(); if(hideToolbars){ QList<QToolBar *> toolbars = AppCore::Core::getInstance()->getCoreWindow()->findChildren<QToolBar *>(); QListIterator<QToolBar *> i(toolbars); while (i.hasNext()){ i.next()->hide(); } } } } // toolbars only else if(ea.getKey() == 't' || ea.getKey() == 'T') { static bool toolbars = true; if( toolbars ){ toolbars = !toolbars; QList<QToolBar *> toolbars = AppCore::Core::getInstance()->getCoreWindow()->findChildren<QToolBar *>(); QListIterator<QToolBar *> i(toolbars); while (i.hasNext()){ i.next()->show(); } } else { toolbars = !toolbars; QList<QToolBar *> toolbars = AppCore::Core::getInstance()->getCoreWindow()->findChildren<QToolBar *>(); QListIterator<QToolBar *> i(toolbars); while (i.hasNext()){ i.next()->hide(); } } } return false; }