예제 #1
0
// Graph layout stuff
void MainWindow::applyRandomLayout()
{
    RandomNumberGenerator rng(QDateTime::currentMSecsSinceEpoch());

    // Define the topology to work in
    QRectF rc(m_graphView->visibleRegion().boundingRect());
    rc.adjust(-10.0f, -10.0f, -10.0f, -10.0f);
    rc.moveTo(-rc.width() / 2.0f, -rc.height() / 2.0f);
    Topology top(rng, rc.left(), rc.top(), rc.right(), rc.bottom());

    // Apply the layout
    boost::random_graph_layout(m_graph,
        get(&NodeProperties::pos, m_graph), top);

    // Forward the calculated values into the graphics objects
    std::pair<DigraphVertexIterator, DigraphVertexIterator> iterators =
        boost::vertices(m_graph);
    DigraphVertexIterator it = iterators.first;
    for (; it != iterators.second; ++it) {
        TopologicalPoint pt   = m_graph[*it].pos;
        NodeItem*        node = m_graph[*it].item;

        node->setPos(pt[0], pt[1]);
    }
}
예제 #2
0
void NodeMove::redo() {
	NodeItem *item = scene->findItem(node_id);
	item->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
	item->setPos(_new);
	scene->updateConnections(item);
	item->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
	//scene->update();
}
예제 #3
0
void DeleteNode::undo() {
	Node *node = scene->node_reg->createNode(node_class);
	scene->model->addNode(node_id, node);

	NodeItem *nitem = new NodeItem(node);

	nitem->restoreParameters(parameters);
	SimulationParameters sp = scene->simulation->getSimulationParameters();
	node->init(sp.start + seconds(sp.dt), sp.stop, sp.dt);
	nitem->updatePorts();
	nitem->setPos(pos);
	scene->add(nitem);
	//scene->update();
}
예제 #4
0
void RxDev::on_pushButton_managerNodelet_clicked()
{
    NodeItem * newNode;
    newNode = new NodeItem("","nodelet",QStringList(),QStringList(),QStringList(),QStringList());
    newNode->setType("nodelet");
    newNode->setArgs("manager");
    newNode->setLocation(findSpace(QPoint(0,55)));
    newNode->setColor(Qt::yellow);
    newNode->setPos(findSpace(QPoint(0,55)));

    if (newNode->getNodeData()==true){
        scene->addItem(newNode);
    }
}
예제 #5
0
/*!\brief reimplementation of the dropEvent
 *
 * Creates a node item if a node is dropped in the view.
 * The neccessary nodeinformation is fetched during the mousepressaction for the drag event
 * in RxDev::selectionHandle_availableNodes.
 */
void LaunchFileView::dropEvent(QDropEvent *event) {
    NodeItem * newNode;
    newNode = new NodeItem(selectedNodeName,selectedNodePackage,selectedNodeSubscriptions,
                           selectedNodePublications,selectedNodeServices,selectedNodeParameters);
    newNode->setLocation(mapToScene(event->pos()));

    newNode->setPos(mapToScene(event->pos()));

    if (newNode->getNodeData()==true){
        scene()->addItem(newNode);
    }

    selectedBox->setColor(Qt::black);
    selectedBox= newNode;
}
예제 #6
0
void RxDev::on_pushButton_blankNode_clicked()
{
    NodeItem * newNode;
    newNode = new NodeItem("","",QStringList(),QStringList(),QStringList(),QStringList());
    newNode->setType("_blank_node");
    newNode->setLocation(findSpace(QPoint(0,55)));
newNode->setColor(Qt::yellow);
    newNode->setPos(findSpace(QPoint(0,55)));

    if (newNode->getNodeData()==true){
        scene->addItem(newNode);
    }


}
예제 #7
0
파일: SceneViewer.cpp 프로젝트: duglah/KoRE
koregui::NodeItem* koregui::SceneViewer
  ::createNode(kore::SceneNode* sourcenode,
               int x,
               int y) {
  NodeItem* nodeItem = new NodeItem(sourcenode);
  _scene.addItem(nodeItem);

  std::vector<kore::SceneNodePtr> pnode = sourcenode->getChildren();
  int startx = x -(estimateTreeWidth(sourcenode)/2);
  for (unsigned int i = 0; i<pnode.size(); i++) {
    int localwidth = estimateTreeWidth(pnode[i].get());
    NodePathItem* path = new NodePathItem(nodeItem,
                                          createNode(pnode[i].get(),
                                            startx + localwidth/2,
                                            y + nodeItem->getHeight() + 80));
    path->setZValue(-1);
    _scene.addItem(path);
    startx += localwidth;
  }
  nodeItem->setPos(x, y);
  return nodeItem;
}
예제 #8
0
파일: canvas.cpp 프로젝트: Andreas665/qt
void Main::addMesh()
{
    int x0 = 0;
    int y0 = 0;

    if ( !tb ) tb = new QBrush( Qt::red );
    if ( !tp ) tp = new QPen( Qt::black );

    int nodecount = 0;

    int w = int(canvas.width());
    int h = int(canvas.height());

    const int dist = 30;
    int rows = h / dist;
    int cols = w / dist;

#ifndef QT_NO_PROGRESSDIALOG
    Q3ProgressDialog progress( "Creating mesh...", "Abort", rows,
			      this, "progress", TRUE );
#endif

    canvas.update();
    
    Q3MemArray<NodeItem*> lastRow(cols);
    for ( int j = 0; j < rows; j++ ) {
	int n = j%2 ? cols-1 : cols;
	NodeItem *prev = 0;
	for ( int i = 0; i < n; i++ ) {
	    NodeItem *el = new NodeItem;
            canvas.addItem(el);
	    nodecount++;
	    int r = qrand();
	    int xrand = r %20;
	    int yrand = (r/20) %20;
	    el->setPos( xrand + x0 + i*dist + (j%2 ? dist/2 : 0 ),
                        yrand + y0 + j*dist );

	    if ( j > 0 ) {
		if ( i < cols-1 )
		    canvas.addItem(new EdgeItem( lastRow[i], el));
		if ( j%2 )
		    canvas.addItem(new EdgeItem( lastRow[i+1], el));
		else if ( i > 0 )
		    canvas.addItem(new EdgeItem( lastRow[i-1], el));
	    }
	    if ( prev ) {
		canvas.addItem(new EdgeItem( prev, el));
	    }
	    if ( i > 0 ) lastRow[i-1] = prev;
	    prev = el;
	}
	lastRow[n-1]=prev;
#ifndef QT_NO_PROGRESSDIALOG
	progress.setProgress( j );
	if ( progress.wasCancelled() )
	    break;
#endif
    }
#ifndef QT_NO_PROGRESSDIALOG
    progress.setProgress( rows );
#endif
    // qDebug( "%d nodes, %d edges", nodecount, EdgeItem::count() );
}
예제 #9
0
void MainWindow::applySpringLayout()
{
    ConstantValueDoubleMap weights(1.0f);
    RandomNumberGenerator rng(QDateTime::currentMSecsSinceEpoch());

    // Create an undirected copy of the graph
    QMap<GraphVertex, DigraphVertex> mapDtoU;
    QMap<DigraphVertex, GraphVertex> mapUtoD;
    Graph g;

    {
        // Copy the nodes
        std::pair<DigraphVertexIterator, DigraphVertexIterator> digraphVertices
            = boost::vertices(m_graph);
        DigraphVertexIterator vit = digraphVertices.first;
        for (; vit != digraphVertices.second; vit++) {
            // Add the vertex
            GraphVertex v = boost::add_vertex(m_graph[*vit], g);

            // Create the mapping
            mapDtoU[*vit] = v;
            mapUtoD[v]    = *vit;
        }

        // Copy the edges
        std::pair<Digraph::edge_iterator, Digraph::edge_iterator> digraphEdges
            = boost::edges(m_graph);
        Digraph::edge_iterator eit = digraphEdges.first;
        for (; eit != digraphEdges.second; eit++) {
            // Get the nodes in terms of the undirected graph
            DigraphVertex src = boost::source(*eit, m_graph);
            DigraphVertex tgt = boost::target(*eit, m_graph);

            // Add an edge into the undirected graph
            boost::add_edge(mapDtoU[src], mapDtoU[tgt], m_graph[*eit], g);
        }
    }

    // Define the topology to work in
    QRectF rc(m_graphView->visibleRegion().boundingRect());
    float adjH = rc.width()  * 0.1f;
    float adjV = rc.height() * 0.1f;
    rc.adjust(adjH, adjV, -adjH, -adjV);
    rc.moveTo(-rc.width() / 2.0f, -rc.height() / 2.0f);

    Topology top(rng, rc.left(), rc.top(), rc.right(), rc.bottom());

    MaxIterationsLayoutTolerance<double> done(
                boost::num_vertices(m_graph) * m_controlsDock->maxIterations(),
                m_controlsDock->layoutTolerance());

    // Seed with a random layout
    boost::random_graph_layout(g, get(&NodeProperties::pos, g), top);

    // Now apply the force-directed layout
    boost::kamada_kawai_spring_layout(g,
        get(&NodeProperties::pos, g), weights, top,
        boost::side_length(rc.width()), done);

    // Forward the calculated values into the graphics objects
    std::pair<GraphVertexIterator, GraphVertexIterator> iterators =
        boost::vertices(g);
    GraphVertexIterator it = iterators.first;
    for (; it != iterators.second; ++it) {
        TopologicalPoint pt   = g[*it].pos;
        NodeItem*        node = g[*it].item;

        // Set the scene item
        node->setPos(pt[0], pt[1]);

        // Update the digraph
        m_graph[mapUtoD[*it]].pos = pt;
    }
}