Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

vis.H

Go to the documentation of this file.
00001 // vis.H
00002 
00003 /*
00004  * 9/17/97 WAH:  Created.
00005  * 3/5/98 WAH:   Added shape argument to AddNode.
00006  * 3/17/98 WAH:  Added textcolor and vertical and horizontal order
00007  *               arguments to AddNode; added textcolor and label to
00008  *               AddEdge.
00009  */
00010 
00011 #ifndef LEGOUTIL_VISCFG_HEADER
00012 #define LEGOUTIL_VISCFG_HEADER
00013 
00014 #include <stdio.h>
00015 #include "lego.H"
00016 
00017 class dag;
00018 
00019 #define VCG_INDENT (2)
00020 
00021 class vcgWriter
00022 {
00023   FILE *fp;
00024   int indent;
00025 
00026   void WriteIndent (void)
00027   {
00028     for (int i = 0; i < indent; i++)
00029       fputc (' ', fp);    
00030   } // end WriteIndent
00031 public:
00032   vcgWriter (char *fname = NULL)
00033   {
00034     if (fname != NULL)
00035       {
00036         fp = fopen (fname, "w");
00037         if (fp == NULL)
00038           {
00039             LegoNonFatal ("vcgWriter", "Couldn't open %s - writing to stdout.",
00040                           fname);
00041             fp = stdout;
00042           } // end if
00043       } // end if
00044     else
00045       fp = stdout;
00046     indent = 0;
00047     return;
00048   } // end constructor
00049   ~vcgWriter() {if (fp != stdout) fclose (fp);}
00050   int IsValid (void) {return (fp != NULL);}
00051 
00052   void StartGraph (char *title, char *color = NULL, int folding = 0,
00053                    char *shape = NULL, int bw = 2)
00054   {
00055     char buffer[20];
00056 
00057     WriteIndent();
00058     fputs ("graph: {\n", fp);
00059     indent += VCG_INDENT;
00060     WriteIndent();
00061     fputs ("title: \"", fp);
00062     fputs (title, fp);
00063     fputs ("\"\n", fp);
00064     if (indent == VCG_INDENT)
00065       {
00066         WriteIndent();
00067         fputs ("near_edges: no\n", fp);
00068         WriteIndent();
00069         fputs ("display_edge_labels: yes\n", fp);
00070       } // end if
00071     if (color != NULL)
00072       {
00073         WriteIndent();
00074         fputs ("color: ", fp);
00075         fputs (color, fp);
00076         fputs ("\n", fp);
00077       } // end if
00078     if (folding != 0)
00079       {
00080         WriteIndent();
00081         fputs ("folding: 1\n", fp);
00082       } // end if
00083     if (bw != 2)
00084       {
00085         WriteIndent();
00086         fputs ("borderwidth: ", fp);
00087         sprintf (buffer, "%d", bw);
00088         fputs (buffer, fp);
00089         fputs ("\n", fp);
00090       }
00091     if (shape != NULL)
00092       {
00093         WriteIndent();
00094         fputs ("shape: ", fp);
00095         fputs (shape, fp);
00096         fputs ("\n", fp);
00097       } // end if
00098     return;
00099   } // end StartGraph
00100 
00101   void EndGraph (void)
00102   {
00103     indent -= VCG_INDENT;
00104     //    if (indent < 0) indent = 0;
00105     fputs ("}\n", fp);
00106   } // end EndGraph
00107 
00108   void AddNode (char *title, char *color, char *shape = NULL,
00109                 char *textcolor = NULL, int vertorder = -1, int hororder = -1)
00110   {
00111     WriteIndent();
00112     fputs ("node: {\n", fp);
00113     indent += VCG_INDENT;
00114     WriteIndent();
00115     fputs ("title: \"", fp);
00116     fputs (title, fp);
00117     fputs ("\"\n", fp);
00118     WriteIndent();
00119     fputs ("color: ", fp);
00120     fputs (color, fp);
00121     fputs ("\n", fp);
00122     if (shape != NULL)
00123       {
00124         WriteIndent();
00125         fputs ("shape: ", fp);
00126         fputs (shape, fp);
00127         fputs ("\n", fp);
00128       } // end if
00129     if (textcolor != NULL)
00130       {
00131         WriteIndent();
00132         fputs ("textcolor: ", fp);
00133         fputs (textcolor, fp);
00134         fputs ("\n", fp);
00135       } // end if
00136     if (vertorder >= 0)
00137       {
00138         char numbuf[10];
00139 
00140         WriteIndent();
00141         fputs ("vertical_order: ", fp);
00142         sprintf (numbuf, "%d", vertorder);
00143         fputs (numbuf, fp);
00144         fputs ("\n", fp);
00145       } // end if
00146     WriteIndent();
00147     fputs ("horizontal_order: ", fp);
00148     if (hororder >= 0)
00149       {
00150         char numbuf[10];
00151 
00152         sprintf (numbuf, "%d", hororder);
00153         fputs (numbuf, fp);
00154         fputs ("\n", fp);
00155       } // end if
00156     else
00157       fputs ("2\n", fp);
00158 
00159     indent -= VCG_INDENT;
00160     WriteIndent();
00161     fputs ("}\n", fp);
00162   } // end AddNode
00163 
00164   void AddEdge (char *sn, char *tn, char *color = NULL, int backedge = 0,
00165                 char *textcolor = NULL, char *label = NULL)
00166   {
00167     WriteIndent();
00168     if (!backedge)
00169       fputs ("edge: {\n", fp);
00170     else
00171       fputs ("backedge: {\n", fp);
00172     indent += VCG_INDENT;
00173     WriteIndent();
00174     fputs ("sourcename: \"", fp);
00175     fputs (sn, fp);
00176     fputs ("\"\n", fp);
00177     WriteIndent();
00178     fputs ("targetname: \"", fp);
00179     fputs (tn, fp);
00180     fputs ("\"\n", fp);
00181     if (color != NULL)
00182       {
00183         WriteIndent();
00184         fputs ("color: ", fp);
00185         fputs (color, fp);
00186         fputs ("\n", fp);
00187       } // end if
00188     if (textcolor != NULL)
00189       {
00190         WriteIndent();
00191         fputs ("textcolor: ", fp);
00192         fputs (textcolor, fp);
00193         fputs ("\n", fp);
00194       } // end if
00195     if (label != NULL)
00196       {
00197         WriteIndent();
00198         if (textcolor == NULL)
00199           {
00200             fputs ("textcolor: black\n", fp);
00201             WriteIndent();
00202           } // end if
00203         fputs ("label: \"", fp);
00204         fputs (label, fp);
00205         fputs ("\"\n", fp);
00206       } // end if
00207     indent -= VCG_INDENT;
00208     WriteIndent();
00209     fputs ("}\n", fp);
00210   } // end AddEdge
00211 
00212 }; // end class vcgWriter
00213 
00214 //HZ:
00215 void DrawTreeRegCFG (legoRegion *region, char *fname = NULL, int bigname = 0);
00216 
00217 void DrawProcCFG (legoProc *, char * = NULL, int = 0);
00218 void DrawDAG (dag *, char * = NULL);
00219 
00220 
00221 #endif // LEGOUTIL_VISCFG_HEADER

Generated on Mon Jul 21 20:29:19 2003 for TINKER LEGO DOC by doxygen 1.3.2