2011-08-09 19 views
2

我想添加端口到節點,但顯然我錯過了一些東西。如何將端口添加到Agraph_t中的節點?

aginit(); 
Agraph_t *g = agopen("g", AGFLAG_DIRECTED); 

Agsym_t *symRankdir = agraphattr(g, "rankdir", "LR"); 
Agsym_t *symShape = agnodeattr(g, "shape", "Mrecord"); 
Agsym_t *symLabel = agnodeattr(g, "label", ""); 

Agnode_t *n1 = agnode(g, "n1"); 
n1->attr[1] = "n1|<p1>p1|<p2>p2"; 
Agnode_t *n2 = agnode(g, "n2"); 
n2->attr[1] = "n2|<p1>p1|<p2>p2"; 
Agedge_t *e = agedge(g, n1, n2); 
e->u.tail_port.defined = true; 
e->u.tail_port.name = "p1"; 
e->u.head_port.defined = true; 
e->u.head_port.name = "p2"; 

FILE *fp = fopen(argv[1], "w"); 
agwrite(g, fp); 

輸出:

digraph g { 
    graph [rankdir=LR]; 
    node [shape=Mrecord]; 
    n1 [label="n1|<p1>p1|<p2>p2"]; 
    n2 [label="n2|<p1>p1|<p2>p2"]; 
    n1 -> n2; 
} 

在輸出中的邊緣應n1:p1 -> n2:p2。代碼中需要設置什麼來實現這一點?

回答

1

替換此 -

e->u.tail_port.defined = true; 
e->u.tail_port.name = "p1"; 
e->u.head_port.defined = true; 
e->u.head_port.name = "p2"; 

- 與此 -

#define TAILX    1 
#define HEADX    2 
agxset(e, TAILX, "p1"); 
agxset(e, HEADX, "p2"); 

(我計算出來從注視的Graphviz源代碼 - LIB /圖形/ parser.y和lib/graph/libgraph.h)。

相關問題