示例#1
0
void CoreWindow::setRestriction_Plane ()
{
	Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();

	if (currentGraph != NULL) {
		osg::Vec3 position = viewerWidget->getPickHandler()->getSelectionCenter(true);

		osg::ref_ptr<Data::Node> node1 = currentGraph->addRestrictionNode (QString ("plane_node_1"), position);
		osg::ref_ptr<Data::Node> node2 = currentGraph->addRestrictionNode (QString ("plane_node_2"), position + osg::Vec3f (10, 0, 0));
		osg::ref_ptr<Data::Node> node3 = currentGraph->addRestrictionNode (QString ("plane_node_3"), position + osg::Vec3f (0, 10, 0));

		Layout::RestrictionRemovalHandler_RestrictionNodesRemover::NodesListType restrictionNodes;
		restrictionNodes.push_back (node1);
		restrictionNodes.push_back (node2);
		restrictionNodes.push_back (node3);

		setRestrictionToSelectedNodes (
			QSharedPointer<Layout::ShapeGetter> (
				new Layout::ShapeGetter_Plane_ByThreeNodes (node1, node2, node3)
			),
			currentGraph,
			QSharedPointer<Layout::RestrictionRemovalHandler_RestrictionNodesRemover> (
				new Layout::RestrictionRemovalHandler_RestrictionNodesRemover (
					*currentGraph,
					restrictionNodes
				)
			)
		);
	}
}
示例#2
0
void AddMetaNodeExecutor::execute_client() {

    int count, metaNodeId, id_edge, id_node;
    QString name, edgeName;
    float x, y, z;

    *stream >> metaNodeId >> name;

    Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();
    QMap<qlonglong, osg::ref_ptr<Data::Node> >* nodes = currentGraph -> getNodes();

    *stream >> x >> y >> z;

    osg::ref_ptr<Data::Node> metaNode = currentGraph->addNode(metaNodeId, name, currentGraph->getNodeMetaType(), osg::Vec3(x,y,z));

    *stream >> edgeName;
    *stream >> count;
    for (int i = 0; i < count; i++) {
        *stream >> id_edge >> id_node;
        if (nodes->contains(id_node)) {
            currentGraph->addEdge(id_edge, edgeName, *nodes->find(id_node), metaNode, currentGraph->getEdgeMetaType(), true);
        }
    }

}
示例#3
0
void MoveNodeExecutor::execute_client() {

    int id;
    float x,y,z;

    *stream >> id >> x >> y >> z;

    Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();
    QMap<qlonglong, osg::ref_ptr<Data::Node> >* nodes = currentGraph -> getNodes();
    //qDebug() << "Moving" << id << "to" << x << y << z;
    if (nodes->contains(id)) {
        this->moveNode(*nodes->find(id), osg::Vec3(x,y,z));
    } else {
        QMap<qlonglong, osg::ref_ptr<Data::Node> >* mergeNodes = currentGraph->getMetaNodes();
        if (mergeNodes->contains(id)) {
            this->moveNode(*mergeNodes->find(id), osg::Vec3(x,y,z));
        } else {
            qDebug() << "Nepoznam uzol" << id;
        }
    }

    //TODO: refactor
    // Stupid way to fix restriction shape refreshing
    ((QOSG::CoreWindow *)Client::getInstance()->getCoreWindowReference())->getLayoutThread()->pause();
    ((QOSG::CoreWindow *)Client::getInstance()->getCoreWindowReference())->getLayoutThread()->play();
}
示例#4
0
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;
}
示例#5
0
bool CoreWindow::add_NodeClick()
{	
	Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();
	Data::Type *edgeType = NULL;
	Data::Type *nodeType = NULL;

	if (currentGraph != NULL)
	{
		osg::Vec3 position = viewerWidget->getPickHandler()->getSelectionCenter(true); 

		osg::ref_ptr<Data::Node> node1 = currentGraph->addNode("newNode", currentGraph->getNodeMetaType(), position);	

		if (isPlaying)
			layout->play();
	}
	else
	{
		currentGraph= Manager::GraphManager::getInstance()->createNewGraph("NewGraph");
		osg::Vec3 position = viewerWidget->getPickHandler()->getSelectionCenter(true); 
		Data::MetaType* type = currentGraph->addMetaType(Data::GraphLayout::META_NODE_TYPE);
		osg::ref_ptr<Data::Node> node1 = currentGraph->addNode("newNode", type);	
		if (isPlaying)
			layout->play();
	}
	return true;
}
void SetFixNodeStateExecutor::execute_server() {
    int id;
    bool state;

    *stream >> id >> state;

    Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();
    QMap<qlonglong, osg::ref_ptr<Data::Node> >* nodes = currentGraph -> getNodes();
    if (nodes->contains(id)) {
        this->SetFixNodeState(*nodes->find(id), state);
    } else {
        QMap<qlonglong, osg::ref_ptr<Data::Node> >* mergeNodes = currentGraph->getMetaNodes();
        if (mergeNodes->contains(id)) {
            this->SetFixNodeState(*mergeNodes->find(id),state);
        }
    }

    Server * server = Server::getInstance();
    server->sendFixNodeState(id, state);

    if (((QOSG::CoreWindow *)server->getCoreWindowReference())->playing()) {
        server->getLayoutThread()->play();
    }

}
void SetFixNodeStateExecutor::execute_client() {
    int id;
    bool state;

    *stream >> id >> state;


    Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();
    QMap<qlonglong, osg::ref_ptr<Data::Node> >* nodes = currentGraph -> getNodes();
    Client * client = Client::getInstance();
    if (nodes->contains(id)) {
        Data::Node * node = *nodes->find(id);
        this->SetFixNodeState(node, state);
        if (client->selected_nodes.contains(node)) {
            client->selected_nodes.removeOne(node);
        }
    } else {
        QMap<qlonglong, osg::ref_ptr<Data::Node> >* mergeNodes = currentGraph->getMetaNodes();
        if (mergeNodes->contains(id)) {
            Data::Node * node = *mergeNodes->find(id);
            this->SetFixNodeState(node,state);
            if (client->selected_nodes.contains(node)) {
                client->selected_nodes.removeOne(node);
            }
        }
    }

}
示例#8
0
void CoreWindow::saveLayoutToDB()
{
	Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();

	if(currentGraph != NULL)
	{
		QSqlDatabase * conn = Manager::GraphManager::getInstance()->getDB()->tmpGetConn();
		bool ok;
	
		if(conn != NULL && conn->open()) { 
			QString layout_name = QInputDialog::getText(this, tr("New layout name"), tr("Layout name:"), QLineEdit::Normal, "", &ok);
		
			if (ok && !layout_name.isEmpty())
			{
				Data::GraphLayout* layout = Model::GraphLayoutDAO::addLayout(layout_name, currentGraph, conn);
				currentGraph->selectLayout(layout);

				currentGraph->saveLayoutToDB(conn, currentGraph);
			}
			else
			{
				qDebug() << "[QOSG::CoreWindow::saveLayoutToDB] Input dialog canceled";
			}
		}
		else
		{
			qDebug() << "[QOSG::CoreWindow::saveLayoutToDB] Connection to DB not opened";
		}
	}
	else
	{
		qDebug() << "[QOSG::CoreWindow::saveLayoutToDB] There is no active graph loaded";
	}
}
示例#9
0
void SeparateNodesExecutor::execute_server()
{

	int count, id;

	*stream >>count;

	Data::Graph* currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();
	QMap<qlonglong, osg::ref_ptr<Data::Node> >* nodes = currentGraph -> getMetaNodes();

	QLinkedList<osg::ref_ptr<Data::Node> >* selectedNodes = new QLinkedList<osg::ref_ptr<Data::Node> >();

	for ( int i = 0; i < count; i++ ) {
		*stream >> id;
		if ( nodes->contains( id ) ) {
			selectedNodes->append( *nodes->find( id ) );
		}
	}

	Server* server = Server::getInstance();
	currentGraph->separateNodes( selectedNodes );

	server->sendSeparateNodes( selectedNodes );

	if ( ( ( QOSG::CoreWindow* )server->getCoreWindowReference() )->playing() ) {
		server->getLayoutThread()->play();
	}
	return;

}
示例#10
0
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;
}
示例#11
0
void NewEdgeExecutor::execute_server()
{

	Server* server = Server::getInstance();

	QString name;
	int from, to;
	bool oriented;

	*stream >> name >> from >> to >> oriented;
	//qDebug()<< "[NEW NODE]" << "[" << x << "," << y << "," << z << "]";


	Data::Graph* currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();
	QMap<qlonglong, osg::ref_ptr<Data::Node> >* nodes = currentGraph -> getNodes();

	osg::ref_ptr<Data::Node> node_from = *nodes->find( from );
	osg::ref_ptr<Data::Node> node_to = *nodes->find( to );

	Data::Type* type = currentGraph->addType( Data::GraphLayout::META_EDGE_TYPE );

	osg::ref_ptr<Data::Edge> newEdge = currentGraph->addEdge( "NewEdge",node_from,node_to,type,oriented );

	if ( ( ( QOSG::CoreWindow* )server->getCoreWindowReference() )->playing() ) {
		server->getLayoutThread()->play();
	}

	server->sendNewEdge( newEdge );
}
示例#12
0
void CoreWindow::setRestriction_Sphere ()
{
	Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();

	if (currentGraph != NULL)
	{
		osg::Vec3 position = viewerWidget->getPickHandler()->getSelectionCenter(true);

		osg::ref_ptr<Data::Node> centerNode = currentGraph->addRestrictionNode (QString ("center"), position);
		osg::ref_ptr<Data::Node> surfaceNode = currentGraph->addRestrictionNode (QString ("surface"), position + osg::Vec3f (10, 0, 0));

		Layout::RestrictionRemovalHandler_RestrictionNodesRemover::NodesListType restrictionNodes;
		restrictionNodes.push_back (centerNode);
		restrictionNodes.push_back (surfaceNode);

		setRestrictionToSelectedNodes (
			QSharedPointer<Layout::ShapeGetter> (
				new Layout::ShapeGetter_Sphere_ByTwoNodes (centerNode, surfaceNode)
			),
			currentGraph,
			QSharedPointer<Layout::RestrictionRemovalHandler_RestrictionNodesRemover> (
				new Layout::RestrictionRemovalHandler_RestrictionNodesRemover (
					*currentGraph,
					restrictionNodes
				)
			)
		);
	}
}
示例#13
0
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;
}
示例#14
0
void Vwr::CameraManipulator::initAutomaticMovement(osgViewer::Viewer* viewer)
{
	t1 = t2 = 0;

	osg::Vec3d eye;
	osg::Vec3d center;
	osg::Vec3d up;

	viewer->getCamera()->getViewMatrixAsLookAt(eye, center, up);
	
	this->lastPosition = originalEyePosition = eye;
	this->lastTargetPoint = center;

	float scale = appConf->getValue("Viewer.Display.NodeDistanceScale").toFloat();

	weightPoint = (eye + cameraInterestPoint + cameraTargetPoint)/3;
	targetDistance = alterCameraTargetPoint(viewer);

	cameraPositions = new QVector<osg::Vec3d>();
	cameraPositions->push_back(originalEyePosition);
	cameraPositions->push_back(cameraInterestPoint);
	cameraPositions->push_back(cameraTargetPoint);

	// vahy kontrolnych bodov pre trajektoriu kamery
	w1[0] = 1;
	w1[1] = -0.1;
	w1[2] = 1;

	targetPositions = new QVector<osg::Vec3d>();

	targetPositions->push_back(center);
	targetPositions->push_back(cameraInterestPoint);
	targetPositions->push_back(weightPoint);

	// vahy kontrolnych bodov pre trajektriu pohladu
	w2[0] = 1;
	w2[1] = 0.5f;
	w2[2] = 1;

	// uprava vah aby boli viditelne vsetky body zaujmu
	alterWeights(viewer, selectedCluster);

	// zobrazenie kontornych bodov
	if (appConf->getValue("Viewer.Display.CameraPositions").toInt() == 1)
	{
		Data::Graph * g = Manager::GraphManager::getInstance()->getActiveGraph();

		g->addNode("centerNode", g->getNodeMetaType(), center)->setColor(osg::Vec4(0, 0.5, 1, 0.5));
		g->addNode("startNode", g->getNodeMetaType(), originalEyePosition / scale);
		g->addNode("interestPoint", g->getNodeMetaType(), cameraInterestPoint / scale)->setColor(osg::Vec4(0, 1, 1, 1));
		g->addNode("weigthPoint", g->getNodeMetaType(), weightPoint)->setColor(osg::Vec4(0, 0.5, 1, 1));
	}

	automaticMovementInitialized = true;
}
示例#15
0
void CoreWindow::removeMetaNodes()
{
	QLinkedList<osg::ref_ptr<Data::Node> > * selectedNodes = viewerWidget->getPickHandler()->getSelectedNodes();
	Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();

	QLinkedList<osg::ref_ptr<Data::Node> >::const_iterator i = selectedNodes->constBegin();

	while (i != selectedNodes->constEnd()) 
	{
		if ((*i)->getType()->isMeta())
			currentGraph->removeNode((*i));
		++i;
	}

	if (isPlaying)
		layout->play();
}
示例#16
0
void CoreWindow::removeMetaNodes()
{
	QLinkedList<osg::ref_ptr<Data::Node> > * selectedNodes = viewerWidget->getPickHandler()->getSelectedNodes();
	Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();

	QLinkedList<osg::ref_ptr<Data::Node> >::const_iterator i = selectedNodes->constBegin();

	while (i != selectedNodes->constEnd()) 
	{
		//treba este opravit - zatial kontrolujeme ci to nie je mergedNode len podla mena
		if ((*i)->getType()->isMeta() && (*i)->getName() != "mergedNode")
			currentGraph->removeNode((*i));
		++i;
	}

	if (isPlaying)
		layout->play();
}
示例#17
0
void CoreWindow::separateNodes()
{
	Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();
	
	if (currentGraph != NULL)
	{
		QLinkedList<osg::ref_ptr<Data::Node> > * selectedNodes = viewerWidget->getPickHandler()->getSelectedNodes();

		if(selectedNodes->count() > 0) {
			currentGraph->separateNodes(selectedNodes);
		}
		else {
			qDebug() << "[QOSG::CoreWindow::separateNodes] There are no nodes selected";
		}

		if (isPlaying)
			layout->play();
	}
}
示例#18
0
void CoreWindow::mergeNodes()
{	
	Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();

	if (currentGraph != NULL)
	{
		osg::Vec3 position = viewerWidget->getPickHandler()->getSelectionCenter(true); 
		QLinkedList<osg::ref_ptr<Data::Node> > * selectedNodes = viewerWidget->getPickHandler()->getSelectedNodes();

		if(selectedNodes->count() > 0) {
			currentGraph->mergeNodes(selectedNodes, position);
		}
		else {
			qDebug() << "[QOSG::CoreWindow::mergeNodes] There are no nodes selected";
		}
		
		viewerWidget->getPickHandler()->unselectPickedEdges(0);
		viewerWidget->getPickHandler()->unselectPickedNodes(0);

		if (isPlaying)
			layout->play();
	}
}
示例#19
0
void AddMetaNodeExecutor::execute_server()
{

	int count, id;
	QString name, edgeName;
	float x, y, z;

	*stream >> name;

	Data::Graph* currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();
	QMap<qlonglong, osg::ref_ptr<Data::Node> >* nodes = currentGraph -> getNodes();

	*stream >> x >> y >> z;

	osg::ref_ptr<Data::Node> metaNode = currentGraph->addNode( name, currentGraph->getNodeMetaType(), osg::Vec3( x,y,z ) );

	*stream >> edgeName;
	*stream >> count;
	QLinkedList<osg::ref_ptr<Data::Node> >* selectedNodes = new QLinkedList<osg::ref_ptr<Data::Node> >();

	for ( int i = 0; i < count; i++ ) {
		*stream >> id;
		if ( nodes->contains( id ) ) {
			currentGraph->addEdge( edgeName, *nodes->find( id ), metaNode, currentGraph->getEdgeMetaType(), true );
			selectedNodes->append( *nodes->find( id ) );
		}
	}

	Server* server = Server::getInstance();
	server->sendAddMetaNode( metaNode,selectedNodes,edgeName,osg::Vec3( x,y,z ) );

	if ( ( ( QOSG::CoreWindow* )server->getCoreWindowReference() )->playing() ) {
		server->getLayoutThread()->play();
	}


}
示例#20
0
void CoreWindow::addMetaNode()
{	
	Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();

	if (currentGraph != NULL)
	{
		osg::Vec3 position = viewerWidget->getPickHandler()->getSelectionCenter(true); 

		osg::ref_ptr<Data::Node> metaNode = currentGraph->addNode("metaNode", currentGraph->getNodeMetaType(), position);	
		QLinkedList<osg::ref_ptr<Data::Node> > * selectedNodes = viewerWidget->getPickHandler()->getSelectedNodes();

		QLinkedList<osg::ref_ptr<Data::Node> >::const_iterator i = selectedNodes->constBegin();

		while (i != selectedNodes->constEnd()) 
		{
			Data::Edge * e = currentGraph->addEdge("metaEdge", (*i), metaNode, currentGraph->getEdgeMetaType(), true);
			e->setCamera(viewerWidget->getCamera());
			++i;
		}

		if (isPlaying)
			layout->play();
	}
}
示例#21
0
void RemoveEdgeExecutor::execute_server()
{

	int id;

	*stream >> id;

	Data::Graph* currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();
	QMap<qlonglong, osg::ref_ptr<Data::Edge> >* edges = currentGraph -> getEdges();
	if ( edges->contains( id ) ) {
		Data::Edge* edge = *edges->find( id );
		if ( edge != NULL ) {
			currentGraph->removeEdge( edge );
		}
	}

	Server* server = Server::getInstance();
	server->sendRemoveEdge( id );

	if ( ( ( QOSG::CoreWindow* )server->getCoreWindowReference() )->playing() ) {
		server->getLayoutThread()->play();
	}

}
示例#22
0
bool CoreWindow::add_EdgeClick()
{
	Data::Type *edgeType = NULL;
	Data::Type *nodeType = NULL;
	Data::Graph * currentGraph = Manager::GraphManager::getInstance()->getActiveGraph();
	
	
	QLinkedList<osg::ref_ptr<Data::Node> > * selectedNodes = viewerWidget->getPickHandler()->getSelectedNodes();
	QLinkedList<osg::ref_ptr<Data::Node> >::const_iterator ni = selectedNodes->constBegin();
	
	if (
		selectedNodes==NULL
			) {
				AppCore::Core::getInstance()->messageWindows->showMessageBox("Upozornenie","Žiadny uzol oznaèený",false);
				return false;
			}

	osg::ref_ptr<Data::Node> node1, node2;
	int i=0;
	
	while (ni != selectedNodes->constEnd()) 
	{
		osg::ref_ptr<Data::Node> existingNode = (* ni);
		++ni;i++;
	}
		if (	
			i!=2
			) {
				AppCore::Core::getInstance()->messageWindows->showMessageBox("Upozornenie","Musite vybrat práve 2 vrcholy",false);
				return false;
			}
	ni = selectedNodes->constBegin();
	node2=(* ni);
	++ni;
	node1=(* ni);
	++ni;
	QMap<qlonglong, osg::ref_ptr<Data::Edge> > *mapa = currentGraph->getEdges();
	Data::Type* type = currentGraph->addType(Data::GraphLayout::META_EDGE_TYPE);
	for (QMap<qlonglong, osg::ref_ptr<Data::Edge> >::iterator it = mapa->begin (); it != mapa->end (); ++it) {
			osg::ref_ptr<Data::Edge> existingEdge = it.value ();
			if (
				existingEdge->getSrcNode () ->getName () == node1 ->getName () && 
				existingEdge->getDstNode () ->getName () == node2 ->getName ()
			) {
				AppCore::Core::getInstance()->messageWindows->showMessageBox("Hrana najdená","Medzi vrcholmi nesmie byt hrana",false);
				return false;
			}
			if (
				existingEdge->getSrcNode () ->getName () == node2 ->getName () && 
				existingEdge->getDstNode () ->getName () == node1 ->getName ()
			) {
				AppCore::Core::getInstance()->messageWindows->showMessageBox("Hrana najdená","Medzi vrcholmi nesmie byt hrana",false);
				return false;
			}
		}

	
	currentGraph->addEdge("GUI_edge", node1, node2, type, false);
	if (isPlaying)
			layout->play();
	QString nodename1 = QString(node1->getName());
	QString nodename2 = QString(node2->getName());
	return true;
	//context.getGraph ().addEdge (QString (""), node1[1], node1[2], edgeType, true);

}
示例#23
0
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;
}
示例#24
0
/*!
 * \param ea
 * Adapter udalosti.
 * 
 * 
 * Funkcia vypocita poziciu kamery a zmensi rychlost pohybu.
 * 
 */
void Vwr::CameraManipulator::frame( const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa )
{
	osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>( &aa );

	// ak sme v rezime automatickeho pohybu
	if(movingAutomatically)
	{
		// inicializujeme premenne
		if (!automaticMovementInitialized)
			initAutomaticMovement(viewer);

		// dokym pohlad a pozicia neopisu celu trajektoriu
		if (t1 <= 1 || t2 <= 1)
		{
			// ziskanie novych pozicii na krivke
			if (t1 <= 1)
			{
				cameraPosition = CameraMath::getPointOnNextBezierCurve(t1, cameraPositions, w1);	
				t1 += EYE_MOVEMENT_SPEED;
			}

			if (t2 <= 1)
			{
				targetPoint = CameraMath::getPointOnNextBezierCurve(t2, targetPositions, w2 );
				t2 += TARGET_MOVEMENT_SPEED;
			}


			// aktualne pozicie kamery
			osg::Vec3d eye;
			osg::Vec3d center;
			osg::Vec3d up;

			viewer->getCamera()->getViewMatrixAsLookAt(eye, center, up);

			// prepocitanie koordinatov kamerery s novymi hodnotami
			computePosition(cameraPosition, targetPoint, up);

			// zobrazenie trajektorie kamery
			if (appConf->getValue("Viewer.Display.CameraPath").toInt() == 1)
			{
				QLinkedList<osg::ref_ptr<osg::Node> > * list = coreGraph->getCustomNodeList();
				osg::ref_ptr<osg::Group> group = new osg::Group;
				osg::ref_ptr<osg::Geode> g1 = new osg::Geode;

				g1->addDrawable(CameraMath::createAxis(eye, lastPosition));
				g1->addDrawable(CameraMath::createAxis(targetPoint, lastTargetPoint, osg::Vec4d(1,0,0,1)));

				group->addChild(g1);
				lastPosition = eye;
				lastTargetPoint = targetPoint;
				list->push_back(group);
			}

			// vypis metriky do konzoly
			if (appConf->getValue("Graph.Metrics.ViewMetrics").toInt() == 1)
			{
				computeViewMetrics(viewer, selectedCluster);
			}

		}

		// ukoncenie pohybu
		else
		{
			movingAutomatically = false;

			if (appConf->getValue("Viewer.Display.CameraPositions").toInt() == 1)
			{
				osg::Vec3d eye;
				osg::Vec3d center;
				osg::Vec3d up;

				viewer->getCamera()->getViewMatrixAsLookAt(eye, center, up);

				Data::Graph * g = Manager::GraphManager::getInstance()->getActiveGraph();
				g->addNode("EndNode", g->getNodeMetaType(), eye);
			}

	//		osg::Vec3d eye;
	//		osg::Vec3d center;
	//		osg::Vec3d up;

	//		viewer->getCamera()->getViewMatrixAsLookAt(eye, center, up);
	//			cout << eye.x() << " " << eye.y() << " " << eye.z() << "\n";
		}
	}
	// standardny frame
	else
	{
		computeStandardFrame(ea, aa);
	}
}
示例#25
0
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;
}