My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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.

References base, clearVisitFlags(), TreeDiagram::computeLayout(), DiagramItem::move(), TreeDiagram::moveChildren(), super, and DiagramItem::xPos().

{
base = new TreeDiagram(root,TRUE);
super = new TreeDiagram(root,FALSE);
DiagramItem *baseItem = base->getFirst()->getFirst();
DiagramItem *superItem = super->getFirst()->getFirst();
int xbase = baseItem->xPos();
int xsuper = superItem->xPos();
if (xbase>xsuper)
{
superItem->move(xbase-xsuper,0);
super->moveChildren(superItem,xbase-xsuper);
}
else if (xbase<xsuper)
{
baseItem->move(xsuper-xbase,0);
base->moveChildren(baseItem,xsuper-xbase);
}
}
ClassDiagram::~ClassDiagram ( )

Definition at line 1051 of file diagram.cpp.

References base, and super.

{
delete base;
delete super;
}

Member Function Documentation

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

Definition at line 1057 of file diagram.cpp.

References base, TreeDiagram::computeExtremes(), TreeDiagram::computeRows(), Config_getBool, TreeDiagram::drawBoxes(), TreeDiagram::drawConnectors(), endl(), err(), gridWidth, DiagramItem::isInList(), DiagramItem::label(), portable_system(), portable_sysTimerStart(), portable_sysTimerStop(), and super.

Referenced by LatexGenerator::endClassDiagram(), and ClassContext::Private::inheritanceDiagram().

{
uint baseRows=base->computeRows();
uint superRows=super->computeRows();
uint baseMaxX, baseMaxLabelWidth, superMaxX, superMaxLabelWidth;
base->computeExtremes(&baseMaxLabelWidth,&baseMaxX);
super->computeExtremes(&superMaxLabelWidth,&superMaxX);
uint rows=baseRows+superRows-1;
uint cols=(QMAX(baseMaxX,superMaxX)+gridWidth*2-1)/gridWidth;
// Estimate the image aspect width and height in pixels.
uint estHeight = rows*40;
uint estWidth = cols*(20+QMAX(baseMaxLabelWidth,superMaxLabelWidth));
//printf("Estimated size %d x %d\n",estWidth,estHeight);
const float pageWidth = 14.0f; // estimated page width in cm.
// Somewhat lower to deal with estimation
// errors.
// compute the image height in centimeters based on the estimates
float realHeight = QMIN(rows,12); // real height in cm
float realWidth = realHeight * estWidth/(float)estHeight;
if (realWidth>pageWidth) // assume that the page width is about 15 cm
{
realHeight*=pageWidth/realWidth;
realWidth=pageWidth;
}
//output << "}\n";
output << "\\begin{figure}[H]\n"
"\\begin{center}\n"
"\\leavevmode\n";
output << "\\includegraphics[height=" << realHeight << "cm]{"
<< fileName << "}" << endl;
output << "\\end{center}\n"
"\\end{figure}\n";
//printf("writeFigure rows=%d cols=%d\n",rows,cols);
QCString epsBaseName=(QCString)path+"/"+fileName;
QCString epsName=epsBaseName+".eps";
QFile f1;
f1.setName(epsName.data());
if (!f1.open(IO_WriteOnly))
{
err("Could not open file %s for writing\n",f1.name().data());
exit(1);
}
FTextStream t(&f1);
//printf("writeEPS() rows=%d cols=%d\n",rows,cols);
// generate EPS header and postscript variables and procedures
t << "%!PS-Adobe-2.0 EPSF-2.0\n";
t << "%%Title: ClassName\n";
t << "%%Creator: Doxygen\n";
t << "%%CreationDate: Time\n";
t << "%%For: \n";
t << "%Magnification: 1.00\n";
t << "%%Orientation: Portrait\n";
t << "%%BoundingBox: 0 0 500 " << estHeight*500.0/(float)estWidth << "\n";
t << "%%Pages: 0\n";
t << "%%BeginSetup\n";
t << "%%EndSetup\n";
t << "%%EndComments\n";
t << "\n";
t << "% ----- variables -----\n";
t << "\n";
t << "/boxwidth 0 def\n";
t << "/boxheight 40 def\n";
t << "/fontheight 24 def\n";
t << "/marginwidth 10 def\n";
t << "/distx 20 def\n";
t << "/disty 40 def\n";
t << "/boundaspect " << estWidth/(float)estHeight << " def % aspect ratio of the BoundingBox (width/height)\n";
t << "/boundx 500 def\n";
t << "/boundy boundx boundaspect div def\n";
t << "/xspacing 0 def\n";
t << "/yspacing 0 def\n";
t << "/rows " << rows << " def\n";
t << "/cols " << cols << " def\n";
t << "/scalefactor 0 def\n";
t << "/boxfont /Times-Roman findfont fontheight scalefont def\n";
t << "\n";
t << "% ----- procedures -----\n";
t << "\n";
t << "/dotted { [1 4] 0 setdash } def\n";
t << "/dashed { [5] 0 setdash } def\n";
t << "/solid { [] 0 setdash } def\n";
t << "\n";
t << "/max % result = MAX(arg1,arg2)\n";
t << "{\n";
t << " /a exch def\n";
t << " /b exch def\n";
t << " a b gt {a} {b} ifelse\n";
t << "} def\n";
t << "\n";
t << "/xoffset % result = MAX(0,(scalefactor-(boxwidth*cols+distx*(cols-1)))/2)\n";
t << "{\n";
t << " 0 scalefactor boxwidth cols mul distx cols 1 sub mul add sub 2 div max\n";
t << "} def\n";
t << "\n";
t << "/cw % boxwidth = MAX(boxwidth, stringwidth(arg1))\n";
t << "{\n";
t << " /str exch def\n";
t << " /boxwidth boxwidth str stringwidth pop max def\n";
t << "} def\n";
t << "\n";
t << "/box % draws a box with text `arg1' at grid pos (arg2,arg3)\n";
t << "{ gsave\n";
t << " 2 setlinewidth\n";
t << " newpath\n";
t << " exch xspacing mul xoffset add\n";
t << " exch yspacing mul\n";
t << " moveto\n";
t << " boxwidth 0 rlineto \n";
t << " 0 boxheight rlineto \n";
t << " boxwidth neg 0 rlineto \n";
t << " 0 boxheight neg rlineto \n";
t << " closepath\n";
t << " dup stringwidth pop neg boxwidth add 2 div\n";
t << " boxheight fontheight 2 div sub 2 div\n";
t << " rmoveto show stroke\n";
t << " grestore\n";
t << "} def \n";
t << "\n";
t << "/mark\n";
t << "{ newpath\n";
t << " exch xspacing mul xoffset add boxwidth add\n";
t << " exch yspacing mul\n";
t << " moveto\n";
t << " 0 boxheight 4 div rlineto\n";
t << " boxheight neg 4 div boxheight neg 4 div rlineto\n";
t << " closepath\n";
t << " eofill\n";
t << " stroke\n";
t << "} def\n";
t << "\n";
t << "/arrow\n";
t << "{ newpath\n";
t << " moveto\n";
t << " 3 -8 rlineto\n";
t << " -6 0 rlineto\n";
t << " 3 8 rlineto\n";
t << " closepath\n";
t << " eofill\n";
t << " stroke\n";
t << "} def\n";
t << "\n";
t << "/out % draws an output connector for the block at (arg1,arg2)\n";
t << "{\n";
t << " newpath\n";
t << " exch xspacing mul xoffset add boxwidth 2 div add\n";
t << " exch yspacing mul boxheight add\n";
t << " /y exch def\n";
t << " /x exch def\n";
t << " x y moveto\n";
t << " 0 disty 2 div rlineto \n";
t << " stroke\n";
t << " 1 eq { x y disty 2 div add arrow } if\n";
t << "} def\n";
t << "\n";
t << "/in % draws an input connector for the block at (arg1,arg2)\n";
t << "{\n";
t << " newpath\n";
t << " exch xspacing mul xoffset add boxwidth 2 div add\n";
t << " exch yspacing mul disty 2 div sub\n";
t << " /y exch def\n";
t << " /x exch def\n";
t << " x y moveto\n";
t << " 0 disty 2 div rlineto\n";
t << " stroke\n";
t << " 1 eq { x y disty 2 div add arrow } if\n";
t << "} def\n";
t << "\n";
t << "/hedge\n";
t << "{\n";
t << " exch xspacing mul xoffset add boxwidth 2 div add\n";
t << " exch yspacing mul boxheight 2 div sub\n";
t << " /y exch def\n";
t << " /x exch def\n";
t << " newpath\n";
t << " x y moveto\n";
t << " boxwidth 2 div distx add 0 rlineto\n";
t << " stroke\n";
t << " 1 eq\n";
t << " { newpath x boxwidth 2 div distx add add y moveto\n";
t << " -8 3 rlineto\n";
t << " 0 -6 rlineto\n";
t << " 8 3 rlineto\n";
t << " closepath\n";
t << " eofill\n";
t << " stroke\n";
t << " } if\n";
t << "} def\n";
t << "\n";
t << "/vedge\n";
t << "{\n";
t << " /ye exch def\n";
t << " /ys exch def\n";
t << " /xs exch def\n";
t << " newpath\n";
t << " xs xspacing mul xoffset add boxwidth 2 div add dup\n";
t << " ys yspacing mul boxheight 2 div sub\n";
t << " moveto\n";
t << " ye yspacing mul boxheight 2 div sub\n";
t << " lineto\n";
t << " stroke\n";
t << "} def\n";
t << "\n";
t << "/conn % connections the blocks from col `arg1' to `arg2' of row `arg3'\n";
t << "{\n";
t << " /ys exch def\n";
t << " /xe exch def\n";
t << " /xs exch def\n";
t << " newpath\n";
t << " xs xspacing mul xoffset add boxwidth 2 div add\n";
t << " ys yspacing mul disty 2 div sub\n";
t << " moveto\n";
t << " xspacing xe xs sub mul 0\n";
t << " rlineto\n";
t << " stroke\n";
t << "} def\n";
t << "\n";
t << "% ----- main ------\n";
t << "\n";
t << "boxfont setfont\n";
t << "1 boundaspect scale\n";
bool done=FALSE;
QListIterator<DiagramRow> bit(*base);
for (;(dr=bit.current()) && !done;++bit)
{
QListIterator<DiagramItem> rit(*dr);
for (;(di=rit.current());++rit)
{
done=di->isInList();
t << "(" << di->label() << ") cw\n";
}
}
QListIterator<DiagramRow> sit(*super);
++sit;
done=FALSE;
for (;(dr=sit.current()) && !done;++sit)
{
QListIterator<DiagramItem> rit(*dr);
for (;(di=rit.current());++rit)
{
done=di->isInList();
t << "(" << di->label() << ") cw\n";
}
}
t << "/boxwidth boxwidth marginwidth 2 mul add def\n"
<< "/xspacing boxwidth distx add def\n"
<< "/yspacing boxheight disty add def\n"
<< "/scalefactor \n"
<< " boxwidth cols mul distx cols 1 sub mul add\n"
<< " boxheight rows mul disty rows 1 sub mul add boundaspect mul \n"
<< " max def\n"
<< "boundx scalefactor div boundy scalefactor div scale\n";
t << "\n% ----- classes -----\n\n";
base->drawBoxes(t,0,TRUE,FALSE,baseRows,superRows,0,0);
super->drawBoxes(t,0,FALSE,FALSE,baseRows,superRows,0,0);
t << "\n% ----- relations -----\n\n";
base->drawConnectors(t,0,TRUE,FALSE,baseRows,superRows,0,0);
super->drawConnectors(t,0,FALSE,FALSE,baseRows,superRows,0,0);
f1.close();
if (Config_getBool(USE_PDFLATEX))
{
QCString epstopdfArgs(4096);
epstopdfArgs.sprintf("\"%s.eps\" --outfile=\"%s.pdf\"",
epsBaseName.data(),epsBaseName.data());
//printf("Converting eps using `%s'\n",epstopdfArgs.data());
if (portable_system("epstopdf",epstopdfArgs)!=0)
{
err("Problems running epstopdf. Check your TeX installation!\n");
return;
}
}
}
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.

References IndexList::addImageFile(), base, TreeDiagram::computeExtremes(), TreeDiagram::computeRows(), TreeDiagram::drawBoxes(), TreeDiagram::drawConnectors(), endl(), fontHeight, gridWidth, IMAGE_EXT, Doxygen::indexList, labelHorMargin, labelHorSpacing, labelVertSpacing, and super.

Referenced by RTFGenerator::endClassDiagram(), HtmlGenerator::endClassDiagram(), and ClassContext::Private::inheritanceDiagram().

{
uint baseRows=base->computeRows();
uint superRows=super->computeRows();
uint rows=baseRows+superRows-1;
uint lb,ls,xb,xs;
base->computeExtremes(&lb,&xb);
uint cellWidth = QMAX(lb,ls)+labelHorMargin*2;
uint maxXPos = QMAX(xb,xs);
uint labelVertMargin = 6; //QMAX(6,(cellWidth-fontHeight)/6); // aspect at least 1:3
uint cellHeight = labelVertMargin*2+fontHeight;
uint imageWidth = (maxXPos+gridWidth)*cellWidth/gridWidth+
uint imageHeight = rows*cellHeight+(rows-1)*labelVertSpacing;
Image image(imageWidth,imageHeight);
base->drawBoxes(t,&image,TRUE,TRUE,baseRows,superRows,cellWidth,cellHeight,relPath,generateMap);
super->drawBoxes(t,&image,FALSE,TRUE,baseRows,superRows,cellWidth,cellHeight,relPath,generateMap);
base->drawConnectors(t,&image,TRUE,TRUE,baseRows,superRows,cellWidth,cellHeight);
super->drawConnectors(t,&image,FALSE,TRUE,baseRows,superRows,cellWidth,cellHeight);
#define IMAGE_EXT ".png"
image.save((QCString)path+"/"+fileName+IMAGE_EXT);
Doxygen::indexList->addImageFile(QCString(fileName)+IMAGE_EXT);
if (generateMap) t << "</map>" << endl;
}

Member Data Documentation

TreeDiagram* ClassDiagram::base
private

Definition at line 39 of file diagram.h.

Referenced by ClassDiagram(), writeFigure(), writeImage(), and ~ClassDiagram().

TreeDiagram* ClassDiagram::super
private

Definition at line 40 of file diagram.h.

Referenced by ClassDiagram(), writeFigure(), writeImage(), and ~ClassDiagram().


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