Hello, I’m currently implementing a graphical editor that displays elements connected through ports like shown on the following picture:
I’m currently looking for a way to allow the user to automatically layout the elements in the editor in a “nice” way (in the above picture, the elements were positioned manually).
I experimented a bit with graphviz and it seems that the layout algo would suit my needs. For instance, the following .dot input produces a nice layout for the graph:
[dot][code]graph {
rankdir=“LR”
node [shape=record];
goals [label="Goals | { <po1>output1 } | { <po2>output2 } | { <po3>output3 }"];
fmu2 [label="FMU thermal4 | { <pi1>input1 | <po1>output1 } | { <pi2>input2 | <po2>output2 } | { <pi3>input3 | <po3>output3 } | { <pi4>input4 | <po4>output4 }"]
fmu1 [label="FMU my_model | { <pi1>input1 | <po1>output1 } | { <pi2>input2 | }"];
chip [label="Main Chip | <pi1>Heat GenerationRate"]
pressure [label="Environment Pressure 1 | <pi1>Temperature | <pi2>Turbulence"]
goals:po1 -- fmu1:pi2
goals:po2 -- fmu1:pi1
goals:po3 -- fmu2:pi4
fmu1:po1 -- fmu2:pi2
fmu2:po2 -- chip:pi1
fmu2:po1 -- pressure:pi1
fmu2:po3 -- pressure:pi2
}[/code][/dot]
So, with this in mind I would like to use graphviz as a library in order to create a graph and feed my data to it, call the layout algorithm and read back the element positions in order to rearrange the content of my own editor.
So far I managed to use graphviz as a library on Windows and create a node for each of my element (by calling API methods like agopen and agnode). What I’m currently stuck with is the following:
- Specify ports on the node (like in the dot language above): for now, I simply have a node per element but did not find any way to add ports to the nodes.
- Read back the layout information once the layout algorithm has been invoked. I have no idea where I can find that information back. The Agnode_t struct does not contain any of that information it seems.
EDIT: sorry, I tried to edit the DOT section but can’t make it work, here is how it looks like:
Thanks!