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

dotdefs.cc

Go to the documentation of this file.
00001 /*--------------------------------------------------------------------
00002  *
00003  * (C) Copyright Koninklijke Philips Electronics NV 2006. 
00004  * All rights reserved. This software is licensed under the terms of
00005  * version 2.1 of the GNU Lesser General Public License as published 
00006  * by the Free Software Foundation. For licensing and warranty
00007  * information, see the file COPYING in the main directory.
00008  *
00009  *------------------------------------------------------------------*/
00010 
00011 #include <sys/types.h>
00012 #include "dotdefs.h"
00013 
00014 using std::endl;
00015 using std::string;
00016 
00017 static std::ostream* g_errorStream = &std::cerr;
00018 
00019 inline void dotDefsSetErrorStream(std::ostream&e = std::cerr) {
00020   g_errorStream = &e;
00021 }
00022 
00023 //****************************************************************************
00024 // Default Settings YAPI_DOTTY:
00025 //****************************************************************************
00026 
00027 
00028 // Level of Hierarchy:
00029 int DotDefs::levelInit(10);
00030 
00031 // Colors:
00032 string DotDefs::nodeColorProcessNetwork("white");
00033 string DotDefs::nodeColorProcess("white");
00034 string DotDefs::nodeColorPort("white");
00035 string DotDefs::nodeColorFifo("white");
00036 string DotDefs::fontColorClusterTitle("black");
00037 string DotDefs::fontColorProcessNetwork("black");
00038 string DotDefs::fontColorProcess("black");
00039 string DotDefs::fontColorPort("black");
00040 string DotDefs::fontColorFifo("black");
00041 
00042 // Nodes:
00043 string DotDefs::nodeFifo("false");
00044 string DotDefs::nodeStyle("filled");
00045 string DotDefs::nodeShapeProcessNetwork("record");
00046 string DotDefs::nodeShapeProcess("ellipse");
00047 string DotDefs::nodeShapePort("box");
00048 string DotDefs::nodeShapeFifo("diamond");
00049 string DotDefs::nodeWidthProcessNetwork("0.05");
00050 string DotDefs::nodeHeightProcessNetwork("0.05");
00051 string DotDefs::nodeWidthProcess("0.05");
00052 string DotDefs::nodeHeightProcess("0.05");
00053 string DotDefs::nodeWidthPort("0.05");
00054 string DotDefs::nodeHeightPort("0.05");
00055 string DotDefs::nodeWidthFifo("0.05");
00056 string DotDefs::nodeHeightFifo("0.05");
00057 
00058 // Edges:
00059 string DotDefs::edgeDecorate("false");
00060 int DotDefs::edgeMinLen(2);
00061 int DotDefs::edgeWeight(4);
00062 
00063 // Fonts:
00064 string DotDefs::fontNameClusterTitle("Helvetica");
00065 string DotDefs::fontNameProcessNetwork("Helvetica");
00066 string DotDefs::fontNameProcess("Helvetica");
00067 string DotDefs::fontNamePort("Helvetica");
00068 string DotDefs::fontNameFifo("Helvetica");
00069 
00070 int DotDefs::fontSizeClusterTitle(20);
00071 int DotDefs::fontSizeProcessNetwork(16);
00072 int DotDefs::fontSizeProcess(16);
00073 int DotDefs::fontSizePort(16);
00074 int DotDefs::fontSizeFifo(16);
00075 
00076 // Attributes:
00077 string DotDefs::nodeSep("0.5");
00078 string DotDefs::ratio("fill");
00079 string DotDefs::center("true");
00080 
00081 // PageSetup:
00082 string DotDefs::rankDir("TB");
00083 string DotDefs::size("\"7.5,11\"");
00084 string DotDefs::orientation("portrait");
00085 string DotDefs::margin("\"0.5,0.5\"");
00086 
00087 // Dummy:
00088 string DotDefs::dummy("");
00089 
00090 
00091 //****************************************************************************
00092 // Settings that can be changed by configuration-file dotty.cfg:
00093 //****************************************************************************
00094 
00095 
00096 //****************************************************************************
00097 // Struct:
00098 
00099 struct OptionString
00100 {
00101   const char* s;
00102   void(*f)(string, string*);
00103   string* r;
00104 };
00105 
00106 struct OptionInteger
00107 {
00108   const char* s;
00109   void(*f)(int, int*);
00110   int* r;
00111 };
00112 
00113 
00114 //****************************************************************************
00115 // String:
00116 
00117 
00118 // Colors:
00119 
00120 const int nrColors = 18;
00121 static const char* colors[nrColors] =
00122 {
00123   "white",
00124   "gray",
00125   "black",
00126   "red",
00127   "brown",
00128   "orange",
00129   "yellow",
00130   "green",
00131   "cyan",
00132   "blue",
00133   "magenta",
00134   "pink",
00135   "beige",
00136   "gold",
00137   "violet",
00138   "lavender",
00139   "purple",
00140   "navy"
00141 };
00142 
00143 void setColor(string s, string* c)
00144 {
00145   int i;
00146   for (i=0; i<nrColors; i++) {
00147     if (s == colors[i]) {
00148       *c = s;
00149       return;
00150     }
00151   }
00152   *g_errorStream << "dotty.cfg:  invalid color [" << s 
00153        << "], default used [" << *c << "]" << endl;
00154 }                 
00155 
00156 
00157 // FontNames:
00158 
00159 const int nrFonts = 3;
00160 static const char* fontNames[nrFonts] =
00161 {
00162   "Times-Roman",
00163   "Helvetica",
00164   "Courier"
00165 };
00166 
00167 void setFontName(string s, string* c)
00168 {
00169   int i;
00170   for (i=0; i<nrFonts; i++) {
00171     if (s == fontNames[i]) {
00172       if (s == "Times-Roman") {
00173         *c = "\"Times-Roman\"";
00174         return;
00175       } else {
00176               *c = s;
00177               return;
00178       }
00179     }
00180   }
00181   *g_errorStream << "dotty.cfg:  invalid font name [" << s 
00182        << "], default used [" << *c << "]" << endl;
00183 }     
00184 
00185 
00186 // Ratio:
00187 
00188 const int nrRatios = 3;
00189 static const char* ratios[nrRatios] =
00190 {
00191   "fill",
00192   "compress",
00193   "auto"
00194 };
00195 
00196 void setRatio(string s, string* c)
00197 {
00198   int i;
00199   for (i=0; i<nrRatios; i++) {
00200     if (s == ratios[i]) {
00201       *c = s;
00202       return;
00203     }
00204   }
00205   *g_errorStream << "dotty.cfg:  invalid ratio [" << s 
00206        << "], default used [" << *c << "]" << endl;
00207 }
00208 
00209 
00210 void setPageSize(string s, string* c)
00211 {
00212   if (s == "A4p") {
00213     DotDefs::rankDir = "TB";
00214     DotDefs::size = "\"7.5,11\"";
00215     DotDefs::orientation = "portrait";
00216     DotDefs::margin = "\"0.5,0.5\"";
00217   } else
00218   if (s == "A4l") {
00219     DotDefs::rankDir = "LR";
00220     DotDefs::size = "\"11,7.5\"";
00221     DotDefs::orientation = "landscape";
00222     DotDefs::margin = "\"0.5,0.5\"";
00223       } else
00224   if (s == "A3p") {
00225     DotDefs::rankDir = "TB";
00226     DotDefs::size = "\"9,13\"";
00227     DotDefs::orientation = "portrait";
00228     DotDefs::margin = "\"2.0,2.0\"";
00229       } else
00230   if (s == "A3l") {
00231     DotDefs::rankDir = "LR";
00232     DotDefs::size = "\"14,8.5\"";
00233     DotDefs::orientation = "landscape";
00234     DotDefs::margin = "\"2.0,2.0\"";
00235       } else
00236   if (s == "A2p") {
00237     DotDefs::rankDir = "TB";
00238     DotDefs::size = "\"13,20\"";
00239     DotDefs::orientation = "portrait";
00240     DotDefs::margin = "\"2.0,2.0\"";
00241       } else
00242   if (s == "A2l") {
00243     DotDefs::rankDir = "LR";
00244     DotDefs::size = "\"21,13\"";
00245     DotDefs::orientation = "landscape";
00246     DotDefs::margin = "\"2.0,2.0\"";
00247     } else
00248   if (s == "A1p") {
00249     DotDefs::rankDir = "TB";
00250     DotDefs::size = "\"20,30\"";
00251     DotDefs::orientation = "portrait";
00252     DotDefs::margin = "\"2.0,2.0\"";
00253       } else
00254   if (s == "A1l") {
00255     DotDefs::rankDir = "LR";
00256     DotDefs::size = "\"30,20\"";
00257     DotDefs::orientation = "landscape";
00258     DotDefs::margin = "\"2.0,2.0\"";
00259   } else
00260   if (s == "A0p") {
00261     DotDefs::rankDir = "TB";
00262     DotDefs::size = "\"30,42\"";
00263     DotDefs::orientation = "portrait";
00264     DotDefs::margin = "\"2.0,2.0\"";
00265   } else
00266   if (s == "A0l") {
00267     DotDefs::rankDir = "LR";
00268     DotDefs::size = "\"42,30\"";
00269     DotDefs::orientation = "landscape";
00270     DotDefs::margin = "\"2.0,2.0\"";
00271   } else {
00272     *g_errorStream << "dotty.cfg:  invalid page size [" << s 
00273         << "], default used" << endl;
00274   }
00275 }     
00276 
00277 
00278 // Decorate:
00279 
00280 void setBool(string s, string* c)
00281 {
00282   if (s == "true") {
00283     *c = "true";
00284   } else
00285   if (s == "false") {
00286     *c = "false";
00287   } else {
00288     *g_errorStream << "dotty.cfg:  invalid boolean [" << s 
00289          << "], default used [" << *c << "]" << endl;
00290   }
00291 }     
00292 
00293 
00294 // NodeFifo:
00295 
00296 void setNodeFifo(string s, string* c)
00297 {
00298   if (s == "true") {
00299     *c = "true";
00300     return;
00301   }
00302   if (s == "false") {
00303     *c = "false";
00304     return;
00305   }
00306   *g_errorStream << "Dotty.cfg:  no valid boolean Fifo [" << s 
00307        << "], default used [" << *c << "]" << endl;
00308 } 
00309 
00310 
00311 // OptionString:
00312 
00313 const int nrOptionStrings = 18;
00314 
00315 OptionString optionStrings[nrOptionStrings] = 
00316 {
00317   {"ProcessNetworkColor", setColor, &DotDefs::nodeColorProcessNetwork},
00318   {"ProcessColor", setColor, &DotDefs::nodeColorProcess},
00319   {"PortColor", setColor, &DotDefs::nodeColorPort},
00320   {"FifoColor", setColor, &DotDefs::nodeColorFifo},
00321   {"ProcessNetworkClusterFontColor", setColor, &DotDefs::fontColorClusterTitle},
00322   {"ProcessNetworkFontColor", setColor, &DotDefs::fontColorProcessNetwork},
00323   {"ProcessFontColor", setColor, &DotDefs::fontColorProcess},
00324   {"PortFontColor", setColor, &DotDefs::fontColorPort},
00325   {"FifoFontColor", setColor, &DotDefs::fontColorFifo},
00326   {"ProcessNetworkClusterFontName", setFontName, &DotDefs::fontNameClusterTitle},
00327   {"ProcessNetworkFontName", setFontName, &DotDefs::fontNameProcessNetwork},
00328   {"ProcessFontName", setFontName, &DotDefs::fontNameProcess},
00329   {"PortFontName", setFontName, &DotDefs::fontNamePort},
00330   {"FifoFontName", setFontName, &DotDefs::fontNameFifo},
00331   {"Ratio", setRatio, &DotDefs::ratio},
00332   {"PageSize", setPageSize, &DotDefs::dummy},
00333   {"Decorate", setBool, &DotDefs::edgeDecorate},
00334   {"Fifo", setNodeFifo, &DotDefs::nodeFifo}
00335 };    
00336 
00337 void addOptionString(string p, string q)
00338 {
00339   int i;
00340   for (i=0; i<nrOptionStrings; i++) {
00341     if (p == optionStrings[i].s) {
00342       optionStrings[i].f(q, optionStrings[i].r);
00343       return;
00344     }
00345   }
00346   *g_errorStream << "dotty.cfg:  unknown option: " << p << endl;
00347 }
00348 
00349 
00350 //****************************************************************************
00351 // Integer:
00352 
00353 
00354 // LevelInit:
00355 
00356 void setInt(int n, int* c)
00357 {
00358   *c = n;
00359 }    
00360 
00361 // OptionInteger:
00362 
00363 const int nrIntegers = 6;
00364 OptionInteger optionIntegers[nrIntegers] =
00365 {
00366   {"InitLevel", setInt, &DotDefs::levelInit},
00367   {"ProcessNetworkClusterFontSize", setInt, &DotDefs::fontSizeClusterTitle},
00368   {"ProcessNetworkFontSize", setInt, &DotDefs::fontSizeProcessNetwork},
00369   {"ProcessFontSize", setInt, &DotDefs::fontSizeProcess},
00370   {"PortFontSize", setInt, &DotDefs::fontSizePort},
00371   {"FifoFontSize", setInt, &DotDefs::fontSizeFifo}
00372 };
00373 
00374 void addOptionInteger(string p, int n)
00375 {
00376   int i;
00377   for (i=0; i<nrIntegers; i++) {
00378     if (optionIntegers[i].s == p) {
00379       optionIntegers[i].f(n, optionIntegers[i].r);
00380       return;
00381     }
00382   }
00383   *g_errorStream << "Dotty.cfg:  unknown option: " << p << endl;
00384 }

Generated on Wed Feb 15 14:52:38 2006 for yapi by doxygen 1.3.2