Пример #1
0
/** Check that given edge is in current sector */
bool NodeNav::isEdgeInSector( GEdge * edge) const
{
    GNode *n = otherEnd( edge);
    /* item corresponding to other (than node_priv) node */
    if ( isNullP( n) || sector() == UNDEF_SECTOR)
        return false;

    NodeItem *item = n->item();
    
    // Both points in current node's coordinates
    QPointF p_center = node_priv->item()->boundingRect().center();
    QPointF s_center = node_priv->item()->mapFromItem( item, item->boundingRect().center());

    qreal angle = QLineF( p_center, s_center).angle();
    
    qreal max_angle = sectorMaxAngle();
    qreal min_angle = sectorMinAngle();

    if ( angle > 270 && sector() == RIGHT_SECTOR)
    {
        max_angle +=360;
    }
    if ( angle < 90 && sector() == RIGHT_SECTOR)
    {
        min_angle -=360;
    }

    if ( angle <= max_angle && angle >= min_angle)
        return true;
    return false;
}
Пример #2
0
/**
 * Change node's style
 */
void GGraph::setNodeStyle( GStyle *style)
{
    if ( sel_nodes.isEmpty())
        return;

    GNode* node = sel_nodes.first();
    node->setStyle( style);
    node->item()->adjustAssociates();
}
Пример #3
0
/** Get edge to the left of given edge */
GEdge *
NodeNav::edgeInDir( GEdge * edge, NavDirection dir) const
{
    /* Applicable only for top and bottom sectors */
    if ( !isDirApplicable( dir, sector()))
    {
        return NULL;
    }
    
    GNode *n = otherEnd( edge);
    /* item corresponding to other (than node_priv) node */
    if ( isNullP( n))
        return NULL;

    NodeItem *item = n->item();
    
    // in current node's coordinates
    QPointF edge_point = node()->item()->mapFromItem( item, item->boundingRect().center());

    GEdge *res = NULL;
    qreal min_delta = 0;
    /** For each edge */   
    for ( Node::EdgeIter e_iter = node()->edgesBegin(),
                         e_end = node()->edgesEnd();
          e_iter != e_end;
          e_iter++ )
    {
        GEdge *e = static_cast<GEdge *>( e_iter.edge());
        if ( isEdgeInSector( e) && areNotEqP( e, edge))
        {
            NodeItem *p_item = static_cast<GNode *>( e_iter.node())->item();
            QPointF point = node()->item()->mapFromItem( p_item, p_item->boundingRect().center());
            if ( isPointInDir( point, edge_point, dir))
            {
                qreal delta = deltaInDir( point, edge_point, dir);
                if ( isNullP( res) 
                     || delta < min_delta) // for selection of closest edge
                {
                    res = e;
                    min_delta = delta;
                }
            }
        }
    }

    return res;
}
Пример #4
0
void
TestParser::parseLine( QString line)
{
    QString n_str("Node ");
    QString e_str("Edge ");
    /** Node recognition */
    QRegExp node_rx("CF ?(Enter)? ?(\\w*) Node (\\d+)");
    
    /** Edge recognition */
    QRegExp edge_rx("CF EDGE (\\d+) \\[(\\d+)->(\\d+)\\]");
    QTextStream stream( stdout);
            
    /** Expression recognition */
    int pos = 0;

    if (  edge_rx.indexIn( line) != -1)
    {
        QString name = e_str.append( edge_rx.cap(1));
        QString pred_name("Node ");
        pred_name.append( edge_rx.cap( 2));
        QString succ_name("Node ");
        succ_name.append( edge_rx.cap( 3));
        
        /** Back edge */
        QRegExp back_rx("Back");
           
        /** Add edge to symtab */
        if ( symtab.find( name) == symtab.end() 
             && symtab.find( pred_name) != symtab.end() 
             && symtab.find( succ_name) != symtab.end())
        {
            SymEdge *edge = new SymEdge( name);
            edge->setPred( pred_name);
            edge->setSucc( succ_name);
            symtab[ name] = edge;

            /** Add edge to graph */
            GNode* pred = static_cast< SymNode *>( symtab[ pred_name])->node();
            GNode* succ = static_cast< SymNode *>( symtab[ succ_name])->node();
            GEdge* e = graph->graph()->newEdge( pred, succ);
#ifdef _DEBUG            
            //stream << name << ": " << pred_name << "->" << succ_name << endl;
#endif      
            if (  back_rx.indexIn( line) != -1 && !e->isSelf())
            {
                GNode* label = e->insertLabelNode( QPointF( 0,0));                
                label->item()->setPlainText( "Back");
            }
        }
    } else if ( node_rx.indexIn( line) != -1 )
    {
		bool good_id = false;
		int ir_id = node_rx.cap(3).toInt( &good_id);
		QString text = QString("Node ").append( node_rx.cap(3));
        QString name = n_str.append( node_rx.cap(3));
        if ( !node_rx.cap( 1).isEmpty())
        {
            text.append("\n").append( node_rx.cap(1));
        }
        if ( !node_rx.cap( 2).isEmpty())
        {
            text.append("\n").append( node_rx.cap(2));
        }
        /** Add node to symtab */
        if ( symtab.find( name ) == symtab.end())
        {
            SymNode* node = new SymNode( name);
            curr_node = static_cast<CFNode *>( graph->graph()->newNode());
            curr_node->setDoc( new QTextDocument());
            node->setNode( curr_node);
            node->node()->item()->setPlainText( text);
		    if ( good_id)
		    {
			    node->node()->setIRId( ir_id);
		    }
            symtab[ name] = node;
#ifdef _DEBUG
            //stream << name << endl;
#endif
        }
    } else
    {
        if ( !isStateNode())
            setStateDefault();
    }
    if ( isStateNode())
    {
        node_text.append( line).append( "\n");
    }
}
Пример #5
0
void 
EdgeItem::keyPressEvent(QKeyEvent *event)
{
    int key = event->key();
    GNode *n = NULL;
    GEdge *e = NULL;
    VEdge vedge( edge());
    NavSector sector = edge()->graph()->nodeNavigationSector();
    GNode *curr_node = edge()->graph()->nodeInFocus();
    NodeNav node_nav( curr_node, sector);
    switch( key)
    {
        case Qt::Key_Up:
            if ( isNotNullP( curr_node) 
                 && ( sector == LEFT_SECTOR || sector == RIGHT_SECTOR))
            {
                e = node_nav.edgeInDir( edge(), NAV_DIR_UP);
            } else
            {
                n = vedge.nodeUp();
            }
            break;
        case Qt::Key_Down:
            if ( isNotNullP( curr_node) 
                 && ( sector == LEFT_SECTOR || sector == RIGHT_SECTOR) )
            {
                e = node_nav.edgeInDir( edge(), NAV_DIR_DOWN);
            } else
            {
                n = vedge.nodeDown();
            }
            break;
        case Qt::Key_Left:
            if ( isNotNullP( curr_node) 
                 && ( sector == TOP_SECTOR || sector == BOTTOM_SECTOR) )
            {
                e = node_nav.edgeInDir( edge(), NAV_DIR_LEFT);
            } else
            {
                n = vedge.nodeLeft();
            }
            break;
        case Qt::Key_Right:
            if ( isNotNullP( curr_node) 
                 && ( sector == TOP_SECTOR || sector == BOTTOM_SECTOR) )
            {
                e = node_nav.edgeInDir( edge(), NAV_DIR_RIGHT);
            } else
            {
                n = vedge.nodeRight();
            }
            break;
        default:
            break;
    }
    if ( isNotNullP( n))
    {
        if ( edge()->graph()->view()->isContext())
        {
            edge()->graph()->emptySelection();
            edge()->graph()->selectNode( n);
            edge()->graph()->view()->findContext();
        }
        edge()->graph()->view()->focusOnNode( n, true);
        
        scene()->clearFocus();
        scene()->clearSelection();
        n->item()->setFocus();
        n->item()->setSelected( true);
    } else if ( isNotNullP( e))
    {
        // Get focus on edge
        scene()->clearFocus();
        scene()->clearSelection();
        e->item()->setFocus();
        e->item()->setSelected( true);
    }
    //QGraphicsItem::keyPressEvent( event);
}