[RavenclawDev 263] [25] Tools/RCTaskViz: 1) Added ps2 (postscript with pdf annotations) to list of acceptable rendering devices.

tk@edam.speech.cs.cmu.edu tk at edam.speech.cs.cmu.edu
Mon Apr 23 17:41:13 EDT 2007


An HTML attachment was scrubbed...
URL: http://mailman.srv.cs.cmu.edu/pipermail/ravenclaw-developers/attachments/20070423/6d535069/attachment.html
-------------- next part --------------
Modified: Tools/RCTaskViz/GraphViz.pm
===================================================================
--- Tools/RCTaskViz/GraphViz.pm	2007-04-19 17:26:04 UTC (rev 24)
+++ Tools/RCTaskViz/GraphViz.pm	2007-04-23 21:41:11 UTC (rev 25)
@@ -968,7 +968,7 @@
     $name = "as_dot";
   }
 
-  if ($name =~ /^as_(ps|hpgl|pcl|mif|pic|gd|gd2|gif|jpeg|png|wbmp|cmapx?|ismap|imap|vrml|vtx|mp|fig|svgz?|dot|canon|plain)$/) {
+  if ($name =~ /^as_(ps|ps2|hpgl|pcl|mif|pic|gd|gd2|gif|jpeg|png|wbmp|cmapx?|ismap|imap|vrml|vtx|mp|fig|svgz?|dot|canon|plain)$/) {
     my $data = $self->_as_generic('-T' . $1, $self->_as_debug, $output);
     return $data;
   }

Modified: Tools/RCTaskViz/RCTaskViz.pl
===================================================================
--- Tools/RCTaskViz/RCTaskViz.pl	2007-04-19 17:26:04 UTC (rev 24)
+++ Tools/RCTaskViz/RCTaskViz.pl	2007-04-23 21:41:11 UTC (rev 25)
@@ -3,23 +3,41 @@
 use English;
 use strict;
 
-use GraphViz;
 use Getopt::Std;
 use File::Spec;
+ at INC = ('.', @INC);
 
+require GraphViz;
+
 my %options=();
-getopts('gl:',\%options);
-die "usage: $0 -g -l <label> {dialog task filename}$/" if !@ARGV;
+getopts('gul:n:w:h:',\%options);
+die "usage: $0 -g -l <label> -n <nets dot file> {dialog task filename}$/" 
+    if !@ARGV;
 my $taskfile = shift;
 open(TASKFILE, $taskfile) || die "could not open taskfile '$taskfile'$/";
 my $label = $options{'l'} || 
     ((File::Spec->splitpath($taskfile))[2])." Task Tree";
-my $g = GraphViz->new(directed => 1, 
-		      layout => 'dot', 
-		      rankdir => 1, 
-		      ratio => 'auto',
-		      label => $label);
-
+my $netsfile = $options{'n'};
+my $width = $options{'w'};
+my $height = $options{'h'};
+my $unflatten = $options{'u'};
+my $g;
+if (!$width || !$height) {
+    $g = GraphViz->new(directed => 1, 
+		       layout => 'dot', 
+		       rankdir => 1, 
+		       ratio => 'auto',
+		       label => $label);
+} else {
+    $g = GraphViz->new(directed => 1, 
+		       layout => 'dot', 
+		       rankdir => 1, 
+		       #ratio => 'auto',
+		       width => $width,
+		       height => $height,
+		       label => $label);
+}
+    
 my $MAX_LABEL = 55;
 my @defaultattr = (shape => 'box', style => 'filled');
 
@@ -33,6 +51,8 @@
 my @ablah;
 my $agency_name;
 
+&process_netsfile if $netsfile;
+
 #process taskfile
 while(<TASKFILE>) {
     if($state) {
@@ -98,7 +118,7 @@
 	if(!grep {$_ eq $child} @{$subref}) {
 	    push @{$subref}, $child;
 	    $g->add_node($child);
-	    $g->add_edge($agency_name => $child);
+	    $g->add_edge($agency_name => $child, to_port => 0);
 	}
     } elsif (/DECLARE_DIALOG_TASK_ROOT\s*\([^,]+,\s*([^,\s]+)/) {
 	#print "got DECLARE DIALOG TASK ROOT$/";
@@ -120,11 +140,26 @@
 	    #print "adding '$1'$/";
 	}
 	if($options{'g'} && $gref) {
-	    if(length($gref) > $MAX_LABEL) {
-		$gref = substr($gref, 0, $MAX_LABEL-3).'...';
+	    $gref =~ s/\"//g;
+	    my @netbind = split ',', $gref;
+	    my %terminals;
+	    for my $net (@netbind) {
+		if ($net =~ /\.([^\.]+)\]/ || $net =~ /\[(.+)\]/) {
+		    my $terminal = "[$1]";
+		    next if $terminal =~ /\[[xy](\d+)\]/ && $1 != 1;
+		    $terminals{$terminal}++;
+		} else {
+		    print STDERR "Can't parse net for '$net'$/";
+		}
 	    }
-	    $g->add_node($agency_name, 
-			 'label'=>$agency_name.': '.$gref);
+	    if ($netsfile) {
+		for my $terminal (keys %terminals) {
+		    $g->add_edge($agency_name, $terminal);
+		}
+	    } else {
+		$g->add_node($agency_name, 
+			     label => [$agency_name, (keys %terminals)]);
+	    }
 	}
     }
 }
@@ -152,17 +187,27 @@
 	     @defaultattr, 
 	     fillcolor => 'chocolate',
 	     cluster => 'Key');
+$g->add_node('Grammar Net',
+	     @defaultattr,
+	     shape => 'ellipse',
+	     fillcolor => 'yellow',
+	     cluster => 'Key');
 
 #render
 #print_agency($root);
 $g->as_canon('taskviz.txt');
-$g->as_png('taskviz.png');
+if (!$width && !$height) {
+    $g->as_png('taskviz.png');
+} else {
+    $g->as_ps2('taskviz.ps');
+}
 
 exit;
 
 sub process_last_agency {
     #print "agency $agency_name, subrefs ". scalar(@{$subref}). "\n" if defined $subref;
     return if !defined $subref;
+    return if !$unflatten;
     my $scale = scalar(@{$subref})/6 + 1;
     if($scale > 1) {
 	for(0..$#{$subref}) {
@@ -192,3 +237,18 @@
 	&print_agency($_, $level+1);
     }
 }
+
+sub process_netsfile {
+    open(NETSFILE, $netsfile) || die "Can't open netsfile '$netsfile':$!$/";
+    while(my $line = <NETSFILE>) {
+	if ($line =~ /\"([^\"]+)\"\s*->\s*\"([^\"]+)/) {
+	    my ($mother, $daughter) = ($1, $2);
+	    $g->add_node($mother, shape => 'ellipse', fillcolor => 'yellow', style => 'filled');
+	    $g->add_node($daughter, shape => 'ellipse', fillcolor => 'yellow', style => 'filled');
+	    $g->add_edge($mother => $daughter, color => 'red');
+	} elsif ($line =~ /\"([^\"]+)\"\s*\[/) {
+	    my $lone = $1;
+	    $g->add_node($lone, shape => 'ellipse', fillcolor => 'yellow', style => 'filled');
+	}
+    }
+}


More information about the Ravenclaw-developers mailing list