Public Member Functions | Private Attributes | List of all members
ClassDiagram Class Reference

#include <diagram.h>

Public Member Functions

 ClassDiagram (ClassDef *root)
 
 ~ClassDiagram ()
 
void writeFigure (FTextStream &t, const char *path, const char *file) const
 
void writeImage (FTextStream &t, const char *path, const char *relPath, const char *file, bool generateMap=TRUE) const
 

Private Attributes

TreeDiagrambase
 
TreeDiagramsuper
 

Detailed Description

Class representing a built-in class diagram.

Definition at line 29 of file diagram.h.

Constructor & Destructor Documentation

ClassDiagram::ClassDiagram ( ClassDef root)

Definition at line 1027 of file diagram.cpp.

1028 {
1029  clearVisitFlags();
1030  base = new TreeDiagram(root,TRUE);
1031  base->computeLayout();
1032  clearVisitFlags();
1033  super = new TreeDiagram(root,FALSE);
1034  super->computeLayout();
1035  DiagramItem *baseItem = base->getFirst()->getFirst();
1036  DiagramItem *superItem = super->getFirst()->getFirst();
1037  int xbase = baseItem->xPos();
1038  int xsuper = superItem->xPos();
1039  if (xbase>xsuper)
1040  {
1041  superItem->move(xbase-xsuper,0);
1042  super->moveChildren(superItem,xbase-xsuper);
1043  }
1044  else if (xbase<xsuper)
1045  {
1046  baseItem->move(xsuper-xbase,0);
1047  base->moveChildren(baseItem,xsuper-xbase);
1048  }
1049 }
void move(int dx, int dy)
Definition: diagram.cpp:52
int xPos() const
Definition: diagram.cpp:53
const bool FALSE
Definition: qglobal.h:370
type * getFirst() const
Definition: qlist.h:95
void computeLayout()
Definition: diagram.cpp:475
TreeDiagram * super
Definition: diagram.h:40
void moveChildren(DiagramItem *root, int dx)
Definition: diagram.cpp:422
const bool TRUE
Definition: qglobal.h:371
void clearVisitFlags()
Definition: diagram.cpp:1017
ClassDiagram::~ClassDiagram ( )

Definition at line 1051 of file diagram.cpp.

1052 {
1053  delete base;
1054  delete super;
1055 }
TreeDiagram * base
Definition: diagram.h:39
TreeDiagram * super
Definition: diagram.h:40

Member Function Documentation

void ClassDiagram::writeFigure ( FTextStream t,
const char *  path,
const char *  file 
) const

Definition at line 1057 of file diagram.cpp.

1059 {
1060  uint baseRows=base->computeRows();
1061  uint superRows=super->computeRows();
1062  uint baseMaxX, baseMaxLabelWidth, superMaxX, superMaxLabelWidth;
1063  base->computeExtremes(&baseMaxLabelWidth,&baseMaxX);
1064  super->computeExtremes(&superMaxLabelWidth,&superMaxX);
1065 
1066  uint rows=baseRows+superRows-1;
1067  uint cols=(QMAX(baseMaxX,superMaxX)+gridWidth*2-1)/gridWidth;
1068 
1069  // Estimate the image aspect width and height in pixels.
1070  uint estHeight = rows*40;
1071  uint estWidth = cols*(20+QMAX(baseMaxLabelWidth,superMaxLabelWidth));
1072  //printf("Estimated size %d x %d\n",estWidth,estHeight);
1073 
1074  const float pageWidth = 14.0f; // estimated page width in cm.
1075  // Somewhat lower to deal with estimation
1076  // errors.
1077 
1078  // compute the image height in centimeters based on the estimates
1079  float realHeight = QMIN(rows,12); // real height in cm
1080  float realWidth = realHeight * estWidth/(float)estHeight;
1081  if (realWidth>pageWidth) // assume that the page width is about 15 cm
1082  {
1083  realHeight*=pageWidth/realWidth;
1084  realWidth=pageWidth;
1085  }
1086 
1087  //output << "}\n";
1088  output << "\\begin{figure}[H]\n"
1089  "\\begin{center}\n"
1090  "\\leavevmode\n";
1091  output << "\\includegraphics[height=" << realHeight << "cm]{"
1092  << fileName << "}" << endl;
1093  output << "\\end{center}\n"
1094  "\\end{figure}\n";
1095 
1096  //printf("writeFigure rows=%d cols=%d\n",rows,cols);
1097 
1098  QCString epsBaseName=(QCString)path+"/"+fileName;
1099  QCString epsName=epsBaseName+".eps";
1100  QFile f1;
1101  f1.setName(epsName.data());
1102  if (!f1.open(IO_WriteOnly))
1103  {
1104  err("Could not open file %s for writing\n",f1.name().data());
1105  exit(1);
1106  }
1107  FTextStream t(&f1);
1108 
1109  //printf("writeEPS() rows=%d cols=%d\n",rows,cols);
1110 
1111  // generate EPS header and postscript variables and procedures
1112 
1113  t << "%!PS-Adobe-2.0 EPSF-2.0\n";
1114  t << "%%Title: ClassName\n";
1115  t << "%%Creator: Doxygen\n";
1116  t << "%%CreationDate: Time\n";
1117  t << "%%For: \n";
1118  t << "%Magnification: 1.00\n";
1119  t << "%%Orientation: Portrait\n";
1120  t << "%%BoundingBox: 0 0 500 " << estHeight*500.0/(float)estWidth << "\n";
1121  t << "%%Pages: 0\n";
1122  t << "%%BeginSetup\n";
1123  t << "%%EndSetup\n";
1124  t << "%%EndComments\n";
1125  t << "\n";
1126  t << "% ----- variables -----\n";
1127  t << "\n";
1128  t << "/boxwidth 0 def\n";
1129  t << "/boxheight 40 def\n";
1130  t << "/fontheight 24 def\n";
1131  t << "/marginwidth 10 def\n";
1132  t << "/distx 20 def\n";
1133  t << "/disty 40 def\n";
1134  t << "/boundaspect " << estWidth/(float)estHeight << " def % aspect ratio of the BoundingBox (width/height)\n";
1135  t << "/boundx 500 def\n";
1136  t << "/boundy boundx boundaspect div def\n";
1137  t << "/xspacing 0 def\n";
1138  t << "/yspacing 0 def\n";
1139  t << "/rows " << rows << " def\n";
1140  t << "/cols " << cols << " def\n";
1141  t << "/scalefactor 0 def\n";
1142  t << "/boxfont /Times-Roman findfont fontheight scalefont def\n";
1143  t << "\n";
1144  t << "% ----- procedures -----\n";
1145  t << "\n";
1146  t << "/dotted { [1 4] 0 setdash } def\n";
1147  t << "/dashed { [5] 0 setdash } def\n";
1148  t << "/solid { [] 0 setdash } def\n";
1149  t << "\n";
1150  t << "/max % result = MAX(arg1,arg2)\n";
1151  t << "{\n";
1152  t << " /a exch def\n";
1153  t << " /b exch def\n";
1154  t << " a b gt {a} {b} ifelse\n";
1155  t << "} def\n";
1156  t << "\n";
1157  t << "/xoffset % result = MAX(0,(scalefactor-(boxwidth*cols+distx*(cols-1)))/2)\n";
1158  t << "{\n";
1159  t << " 0 scalefactor boxwidth cols mul distx cols 1 sub mul add sub 2 div max\n";
1160  t << "} def\n";
1161  t << "\n";
1162  t << "/cw % boxwidth = MAX(boxwidth, stringwidth(arg1))\n";
1163  t << "{\n";
1164  t << " /str exch def\n";
1165  t << " /boxwidth boxwidth str stringwidth pop max def\n";
1166  t << "} def\n";
1167  t << "\n";
1168  t << "/box % draws a box with text `arg1' at grid pos (arg2,arg3)\n";
1169  t << "{ gsave\n";
1170  t << " 2 setlinewidth\n";
1171  t << " newpath\n";
1172  t << " exch xspacing mul xoffset add\n";
1173  t << " exch yspacing mul\n";
1174  t << " moveto\n";
1175  t << " boxwidth 0 rlineto \n";
1176  t << " 0 boxheight rlineto \n";
1177  t << " boxwidth neg 0 rlineto \n";
1178  t << " 0 boxheight neg rlineto \n";
1179  t << " closepath\n";
1180  t << " dup stringwidth pop neg boxwidth add 2 div\n";
1181  t << " boxheight fontheight 2 div sub 2 div\n";
1182  t << " rmoveto show stroke\n";
1183  t << " grestore\n";
1184  t << "} def \n";
1185  t << "\n";
1186  t << "/mark\n";
1187  t << "{ newpath\n";
1188  t << " exch xspacing mul xoffset add boxwidth add\n";
1189  t << " exch yspacing mul\n";
1190  t << " moveto\n";
1191  t << " 0 boxheight 4 div rlineto\n";
1192  t << " boxheight neg 4 div boxheight neg 4 div rlineto\n";
1193  t << " closepath\n";
1194  t << " eofill\n";
1195  t << " stroke\n";
1196  t << "} def\n";
1197  t << "\n";
1198  t << "/arrow\n";
1199  t << "{ newpath\n";
1200  t << " moveto\n";
1201  t << " 3 -8 rlineto\n";
1202  t << " -6 0 rlineto\n";
1203  t << " 3 8 rlineto\n";
1204  t << " closepath\n";
1205  t << " eofill\n";
1206  t << " stroke\n";
1207  t << "} def\n";
1208  t << "\n";
1209  t << "/out % draws an output connector for the block at (arg1,arg2)\n";
1210  t << "{\n";
1211  t << " newpath\n";
1212  t << " exch xspacing mul xoffset add boxwidth 2 div add\n";
1213  t << " exch yspacing mul boxheight add\n";
1214  t << " /y exch def\n";
1215  t << " /x exch def\n";
1216  t << " x y moveto\n";
1217  t << " 0 disty 2 div rlineto \n";
1218  t << " stroke\n";
1219  t << " 1 eq { x y disty 2 div add arrow } if\n";
1220  t << "} def\n";
1221  t << "\n";
1222  t << "/in % draws an input connector for the block at (arg1,arg2)\n";
1223  t << "{\n";
1224  t << " newpath\n";
1225  t << " exch xspacing mul xoffset add boxwidth 2 div add\n";
1226  t << " exch yspacing mul disty 2 div sub\n";
1227  t << " /y exch def\n";
1228  t << " /x exch def\n";
1229  t << " x y moveto\n";
1230  t << " 0 disty 2 div rlineto\n";
1231  t << " stroke\n";
1232  t << " 1 eq { x y disty 2 div add arrow } if\n";
1233  t << "} def\n";
1234  t << "\n";
1235  t << "/hedge\n";
1236  t << "{\n";
1237  t << " exch xspacing mul xoffset add boxwidth 2 div add\n";
1238  t << " exch yspacing mul boxheight 2 div sub\n";
1239  t << " /y exch def\n";
1240  t << " /x exch def\n";
1241  t << " newpath\n";
1242  t << " x y moveto\n";
1243  t << " boxwidth 2 div distx add 0 rlineto\n";
1244  t << " stroke\n";
1245  t << " 1 eq\n";
1246  t << " { newpath x boxwidth 2 div distx add add y moveto\n";
1247  t << " -8 3 rlineto\n";
1248  t << " 0 -6 rlineto\n";
1249  t << " 8 3 rlineto\n";
1250  t << " closepath\n";
1251  t << " eofill\n";
1252  t << " stroke\n";
1253  t << " } if\n";
1254  t << "} def\n";
1255  t << "\n";
1256  t << "/vedge\n";
1257  t << "{\n";
1258  t << " /ye exch def\n";
1259  t << " /ys exch def\n";
1260  t << " /xs exch def\n";
1261  t << " newpath\n";
1262  t << " xs xspacing mul xoffset add boxwidth 2 div add dup\n";
1263  t << " ys yspacing mul boxheight 2 div sub\n";
1264  t << " moveto\n";
1265  t << " ye yspacing mul boxheight 2 div sub\n";
1266  t << " lineto\n";
1267  t << " stroke\n";
1268  t << "} def\n";
1269  t << "\n";
1270  t << "/conn % connections the blocks from col `arg1' to `arg2' of row `arg3'\n";
1271  t << "{\n";
1272  t << " /ys exch def\n";
1273  t << " /xe exch def\n";
1274  t << " /xs exch def\n";
1275  t << " newpath\n";
1276  t << " xs xspacing mul xoffset add boxwidth 2 div add\n";
1277  t << " ys yspacing mul disty 2 div sub\n";
1278  t << " moveto\n";
1279  t << " xspacing xe xs sub mul 0\n";
1280  t << " rlineto\n";
1281  t << " stroke\n";
1282  t << "} def\n";
1283  t << "\n";
1284  t << "% ----- main ------\n";
1285  t << "\n";
1286  t << "boxfont setfont\n";
1287  t << "1 boundaspect scale\n";
1288 
1289 
1290  bool done=FALSE;
1292  DiagramRow *dr;
1293  for (;(dr=bit.current()) && !done;++bit)
1294  {
1295  QListIterator<DiagramItem> rit(*dr);
1296  DiagramItem *di;
1297  for (;(di=rit.current());++rit)
1298  {
1299  done=di->isInList();
1300  t << "(" << di->label() << ") cw\n";
1301  }
1302  }
1304  ++sit;
1305  done=FALSE;
1306  for (;(dr=sit.current()) && !done;++sit)
1307  {
1308  QListIterator<DiagramItem> rit(*dr);
1309  DiagramItem *di;
1310  for (;(di=rit.current());++rit)
1311  {
1312  done=di->isInList();
1313  t << "(" << di->label() << ") cw\n";
1314  }
1315  }
1316 
1317  t << "/boxwidth boxwidth marginwidth 2 mul add def\n"
1318  << "/xspacing boxwidth distx add def\n"
1319  << "/yspacing boxheight disty add def\n"
1320  << "/scalefactor \n"
1321  << " boxwidth cols mul distx cols 1 sub mul add\n"
1322  << " boxheight rows mul disty rows 1 sub mul add boundaspect mul \n"
1323  << " max def\n"
1324  << "boundx scalefactor div boundy scalefactor div scale\n";
1325 
1326  t << "\n% ----- classes -----\n\n";
1327  base->drawBoxes(t,0,TRUE,FALSE,baseRows,superRows,0,0);
1328  super->drawBoxes(t,0,FALSE,FALSE,baseRows,superRows,0,0);
1329 
1330  t << "\n% ----- relations -----\n\n";
1331  base->drawConnectors(t,0,TRUE,FALSE,baseRows,superRows,0,0);
1332  super->drawConnectors(t,0,FALSE,FALSE,baseRows,superRows,0,0);
1333 
1334  f1.close();
1335  if (Config_getBool("USE_PDFLATEX"))
1336  {
1337  QCString epstopdfArgs(4096);
1338  epstopdfArgs.sprintf("\"%s.eps\" --outfile=\"%s.pdf\"",
1339  epsBaseName.data(),epsBaseName.data());
1340  //printf("Converting eps using `%s'\n",epstopdfArgs.data());
1342  if (portable_system("epstopdf",epstopdfArgs)!=0)
1343  {
1344  err("Problems running epstopdf. Check your TeX installation!\n");
1346  return;
1347  }
1349  }
1350 }
void computeExtremes(uint *labelWidth, uint *xpos)
Definition: diagram.cpp:555
void portable_sysTimerStop()
Definition: portable.cpp:415
QString name() const
Definition: qfile.h:121
#define IO_WriteOnly
Definition: qiodevice.h:62
bool isInList() const
Definition: diagram.cpp:62
const bool FALSE
Definition: qglobal.h:370
Simplified and optimized version of QTextStream.
Definition: ftextstream.h:11
void setName(const QString &name)
Definition: qfile.cpp:167
void portable_sysTimerStart()
Definition: portable.cpp:410
#define QMIN(a, b)
Definition: qglobal.h:391
const char * data() const
Definition: qstring.h:542
void drawConnectors(FTextStream &t, Image *image, bool doBase, bool bitmap, uint baseRows, uint superRows, uint cellWidth, uint cellheight)
Definition: diagram.cpp:706
#define QMAX(a, b)
Definition: qglobal.h:390
fileName
Definition: dumpTree.py:9
bool open(int)
Definition: qfile_unix.cpp:134
const char * data() const
Definition: qcstring.h:207
#define Config_getBool(val)
Definition: config.cpp:664
void err(const char *fmt,...)
Definition: message.cpp:226
The QFile class is an I/O device that operates on files.
Definition: qfile.h:50
uint computeRows()
Definition: diagram.cpp:525
void drawBoxes(FTextStream &t, Image *image, bool doBase, bool bitmap, uint baseRows, uint superRows, uint cellWidth, uint cellHeight, QCString relPath="", bool generateMap=TRUE)
Definition: diagram.cpp:576
QCString label() const
Definition: diagram.cpp:306
void close()
Definition: qfile_unix.cpp:614
TreeDiagram * super
Definition: diagram.h:40
const int gridWidth
Definition: diagram.cpp:142
unsigned uint
Definition: qglobal.h:351
const bool TRUE
Definition: qglobal.h:371
QTextStream & endl(QTextStream &s)
int portable_system(const char *command, const char *args, bool commandHasConsole)
Definition: portable.cpp:33
void ClassDiagram::writeImage ( FTextStream t,
const char *  path,
const char *  relPath,
const char *  file,
bool  generateMap = TRUE 
) const

Definition at line 1353 of file diagram.cpp.

1356 {
1357  uint baseRows=base->computeRows();
1358  uint superRows=super->computeRows();
1359  uint rows=baseRows+superRows-1;
1360 
1361  uint lb,ls,xb,xs;
1362  base->computeExtremes(&lb,&xb);
1363  super->computeExtremes(&ls,&xs);
1364 
1365  uint cellWidth = QMAX(lb,ls)+labelHorMargin*2;
1366  uint maxXPos = QMAX(xb,xs);
1367  uint labelVertMargin = 6; //QMAX(6,(cellWidth-fontHeight)/6); // aspect at least 1:3
1368  uint cellHeight = labelVertMargin*2+fontHeight;
1369  uint imageWidth = (maxXPos+gridWidth)*cellWidth/gridWidth+
1370  (maxXPos*labelHorSpacing)/gridWidth;
1371  uint imageHeight = rows*cellHeight+(rows-1)*labelVertSpacing;
1372 
1373  Image image(imageWidth,imageHeight);
1374 
1375  base->drawBoxes(t,&image,TRUE,TRUE,baseRows,superRows,cellWidth,cellHeight,relPath,generateMap);
1376  super->drawBoxes(t,&image,FALSE,TRUE,baseRows,superRows,cellWidth,cellHeight,relPath,generateMap);
1377  base->drawConnectors(t,&image,TRUE,TRUE,baseRows,superRows,cellWidth,cellHeight);
1378  super->drawConnectors(t,&image,FALSE,TRUE,baseRows,superRows,cellWidth,cellHeight);
1379 
1380 #define IMAGE_EXT ".png"
1381  image.save((QCString)path+"/"+fileName+IMAGE_EXT);
1383 
1384  if (generateMap) t << "</map>" << endl;
1385 }
void computeExtremes(uint *labelWidth, uint *xpos)
Definition: diagram.cpp:555
const bool FALSE
Definition: qglobal.h:370
const uint labelHorMargin
Definition: diagram.cpp:147
#define IMAGE_EXT
void drawConnectors(FTextStream &t, Image *image, bool doBase, bool bitmap, uint baseRows, uint superRows, uint cellWidth, uint cellheight)
Definition: diagram.cpp:706
#define QMAX(a, b)
Definition: qglobal.h:390
fileName
Definition: dumpTree.py:9
const uint labelHorSpacing
Definition: diagram.cpp:145
void addImageFile(const char *name)
Definition: index.h:147
const uint fontHeight
Definition: diagram.cpp:148
uint computeRows()
Definition: diagram.cpp:525
void drawBoxes(FTextStream &t, Image *image, bool doBase, bool bitmap, uint baseRows, uint superRows, uint cellWidth, uint cellHeight, QCString relPath="", bool generateMap=TRUE)
Definition: diagram.cpp:576
Definition: image.h:24
TreeDiagram * super
Definition: diagram.h:40
const int gridWidth
Definition: diagram.cpp:142
unsigned uint
Definition: qglobal.h:351
const bool TRUE
Definition: qglobal.h:371
static IndexList * indexList
Definition: doxygen.h:149
const uint labelVertSpacing
Definition: diagram.cpp:146
QTextStream & endl(QTextStream &s)

Member Data Documentation

TreeDiagram* ClassDiagram::base
private

Definition at line 39 of file diagram.h.

TreeDiagram* ClassDiagram::super
private

Definition at line 40 of file diagram.h.


The documentation for this class was generated from the following files: