#! /usr/bin/perl
# 13/03/2005 Laurent FACQ - REAUMUR - Universite de Bordeaux - facq@u-bordeaux.fr
### This is a first quick&dirty attempt to generate a .sxi openoffice file from a .dot file
### with positions
# neato graph2.neato > gr2.dot
## ./dot2sxi.pl gr2.dot
# ../dot2sxi.pl ../gr2.dot > content.xml ; rm ../test2.sxi ;zip -r ../test2.sxi *
unlink("/tmp/res.sxi");
unlink("/tmp/res");
while ($l=<>)
{
if ($l =~ m/bb="\d/)
{ # bounding box
($bbxmin,$bbymin,$bbxmax,$bbymax)= ($l =~ m/bb="(\d+),(\d+),(\d+),(\d+)"/);
#print "BB : $l - $bbxmin $bbxmax $bbymin $bbymax\n";
}
# if ($l =~ m/label=""/)
# {# pseudo nodes
# ($name)= ($l =~ m/\s+(\S+)\s+/);
# $pnode{$name}
# next;
# } ### TMP Skip pseudo nodes for links/edges
if ($l =~ m/pos="\d/)
{ # node
($name)= ($l =~ m/\s+(\S+)\s+/);
if ($l =~ m/label=""/) { $node{$name}{edge}= 1; }
($x,$y)= ($l =~ m/pos="(\d+),(\d+)"/);
$node{$name}{x}= $x;
$node{$name}{y}= $y;
}
if ($l =~ m/pos="e,\d/)
{ # edge
($from,$to)= ($l =~ m/\s+(\S+)\s+->\s+(\S+)\s+/);
#print STDERR "$from $to\n";
# todo
$edge{$from."--".$to}{from}=$from;
$edge{$from."--".$to}{to}=$to;
}
}
$xsize= 30;
$ysize= 30;
$drawid= 10;
sub nodeposx
{
my ($node)=@_;
return (($node{$node}{x}-$bbxmin)/($bbxmax-$bbxmin))*$xsize;
}
sub nodeposy
{
my ($node)=@_;
return (($node{$node}{y}-$bbymin)/($bbymax-$bbymin))*$ysize;
}
sub textbox
{
my ($id,$text,$x,$y)= @_;
return "
".$text."
";
}
sub textcircle
{
my ($id,$text,$x,$y)= @_;
return "
".$text."
";
}
sub smalltextcircle
{
my ($id,$text,$x,$y)= @_;
return "
".$text."
";
}
sub verysmalltextcircle
{
my ($id,$text,$x,$y)= @_;
return "
".$text."
";
}
#
#taga
#
sub connector
{
my ($from,$to)= @_;
return "
";
}
$head= <<'EOF';
EOF
$middle= <<'EOF';
Hello Bibi World
Nouveau TExte1
EOF
$tail= <<'EOF';
EOF
print $head;
$nodes= "";
foreach $node ( keys %node )
{
$drawid++;
#print " $node ".nodeposx($node).",".nodeposy($node)."\n";
#print textbox($drawid,$node,nodeposx($node),nodeposy($node))."\n";
#print textcircle($drawid,$node,nodeposx($node),nodeposy($node))."\n";
if ($node{$node}{edge})
{
$nodes.= verysmalltextcircle($drawid,"",nodeposx($node),nodeposy($node))."\n";
}
else
{
$nodes.= smalltextcircle($drawid,$node,nodeposx($node),nodeposy($node))."\n";
}
$node{$node}{id}= $drawid;
}
foreach $edge ( keys %edge )
{
$from= $edge{$edge}{from};
$to= $edge{$edge}{to};
#print STDERR "$from $node{$from}{id} -> $to $node{$to}{id} \n";
print connector($from,$to);
}
print $nodes; ### put nodes after connector to have the connector under the nodes :)
print $tail;