Doxygen
ClassDiagram类 参考

Class representing a built-in class diagram. 更多...

#include <diagram.h>

struct  Private
 

Public 成员函数

 ClassDiagram (const ClassDef *root)
 
 ~ClassDiagram ()
 
void writeFigure (TextStream &t, const QCString &path, const QCString &file) const
 
void writeImage (TextStream &t, const QCString &path, const QCString &relPath, const QCString &file, bool generateMap=true) const
 

Private 属性

std::unique_ptr< Privatep
 

详细描述

Class representing a built-in class diagram.

在文件 diagram.h29 行定义.

构造及析构函数说明

◆ ClassDiagram()

ClassDiagram::ClassDiagram ( const ClassDef root)

在文件 diagram.cpp1023 行定义.

1023  : p(std::make_unique<Private>(root))
1024 {
1025  p->base.computeLayout();
1026  p->super.computeLayout();
1027  DiagramItem *baseItem = p->base.row(0)->item(0);
1028  DiagramItem *superItem = p->super.row(0)->item(0);
1029  uint xbase = baseItem->xPos();
1030  uint xsuper = superItem->xPos();
1031  if (xbase>xsuper)
1032  {
1033  superItem->move((int)(xbase-xsuper),0);
1034  p->super.moveChildren(superItem,(int)(xbase-xsuper));
1035  }
1036  else if (xbase<xsuper)
1037  {
1038  baseItem->move((int)(xsuper-xbase),0);
1039  p->base.moveChildren(baseItem,(int)(xsuper-xbase));
1040  }
1041 }

引用了 DiagramItem::move(), p , 以及 DiagramItem::xPos().

◆ ~ClassDiagram()

ClassDiagram::~ClassDiagram ( )

在文件 diagram.cpp1043 行定义.

1044 {
1045 }

成员函数说明

◆ writeFigure()

void ClassDiagram::writeFigure ( TextStream t,
const QCString path,
const QCString file 
) const

在文件 diagram.cpp1047 行定义.

1049 {
1050  uint baseRows=p->base.computeRows();
1051  uint superRows=p->super.computeRows();
1052  uint baseMaxX, baseMaxLabelWidth, superMaxX, superMaxLabelWidth;
1053  p->base.computeExtremes(&baseMaxLabelWidth,&baseMaxX);
1054  p->super.computeExtremes(&superMaxLabelWidth,&superMaxX);
1055 
1056  uint rows=std::max(1u,baseRows+superRows-1);
1057  uint cols=(std::max(baseMaxX,superMaxX)+gridWidth*2-1)/gridWidth;
1058 
1059  // Estimate the image aspect width and height in pixels.
1060  uint estHeight = rows*40;
1061  uint estWidth = cols*(20+std::max(baseMaxLabelWidth,superMaxLabelWidth));
1062  //printf("Estimated size %d x %d\n",estWidth,estHeight);
1063 
1064  const float pageWidth = 14.0f; // estimated page width in cm.
1065  // Somewhat lower to deal with estimation
1066  // errors.
1067 
1068  // compute the image height in centimeters based on the estimates
1069  float realHeight = static_cast<float>(std::min(rows,12u)); // real height in cm
1070  float realWidth = realHeight * estWidth/static_cast<float>(estHeight);
1071  if (realWidth>pageWidth) // assume that the page width is about 15 cm
1072  {
1073  realHeight*=pageWidth/realWidth;
1074  }
1075 
1076  //output << "}\n";
1077  output << "\\begin{figure}[H]\n"
1078  "\\begin{center}\n"
1079  "\\leavevmode\n";
1080  output << "\\includegraphics[height=" << realHeight << "cm]{"
1081  << fileName << "}\n";
1082  output << "\\end{center}\n"
1083  "\\end{figure}\n";
1084 
1085  //printf("writeFigure rows=%d cols=%d\n",rows,cols);
1086 
1087  QCString epsBaseName=(QCString)path+"/"+fileName;
1088  QCString epsName=epsBaseName+".eps";
1089  std::ofstream f(epsName.str(),std::ofstream::out | std::ofstream::binary);
1090  if (!f.is_open())
1091  {
1092  term("Could not open file %s for writing\n",qPrint(epsName));
1093  }
1094  else
1095  {
1096  TextStream t(&f);
1097 
1098  //printf("writeEPS() rows=%d cols=%d\n",rows,cols);
1099 
1100  // generate EPS header and postscript variables and procedures
1101 
1102  t << "%!PS-Adobe-2.0 EPSF-2.0\n";
1103  t << "%%Title: ClassName\n";
1104  t << "%%Creator: Doxygen\n";
1105  t << "%%CreationDate: Time\n";
1106  t << "%%For: \n";
1107  t << "%Magnification: 1.00\n";
1108  t << "%%Orientation: Portrait\n";
1109  t << "%%BoundingBox: 0 0 500 " << estHeight*500.0f/(float)estWidth << "\n";
1110  t << "%%Pages: 0\n";
1111  t << "%%BeginSetup\n";
1112  t << "%%EndSetup\n";
1113  t << "%%EndComments\n";
1114  t << "\n";
1115  t << "% ----- variables -----\n";
1116  t << "\n";
1117  t << "/boxwidth 0 def\n";
1118  t << "/boxheight 40 def\n";
1119  t << "/fontheight 24 def\n";
1120  t << "/marginwidth 10 def\n";
1121  t << "/distx 20 def\n";
1122  t << "/disty 40 def\n";
1123  t << "/boundaspect " << estWidth/(float)estHeight << " def % aspect ratio of the BoundingBox (width/height)\n";
1124  t << "/boundx 500 def\n";
1125  t << "/boundy boundx boundaspect div def\n";
1126  t << "/xspacing 0 def\n";
1127  t << "/yspacing 0 def\n";
1128  t << "/rows " << rows << " def\n";
1129  t << "/cols " << cols << " def\n";
1130  t << "/scalefactor 0 def\n";
1131  t << "/boxfont /Times-Roman findfont fontheight scalefont def\n";
1132  t << "\n";
1133  t << "% ----- procedures -----\n";
1134  t << "\n";
1135  t << "/dotted { [1 4] 0 setdash } def\n";
1136  t << "/dashed { [5] 0 setdash } def\n";
1137  t << "/solid { [] 0 setdash } def\n";
1138  t << "\n";
1139  t << "/max % result = MAX(arg1,arg2)\n";
1140  t << "{\n";
1141  t << " /a exch def\n";
1142  t << " /b exch def\n";
1143  t << " a b gt {a} {b} ifelse\n";
1144  t << "} def\n";
1145  t << "\n";
1146  t << "/xoffset % result = MAX(0,(scalefactor-(boxwidth*cols+distx*(cols-1)))/2)\n";
1147  t << "{\n";
1148  t << " 0 scalefactor boxwidth cols mul distx cols 1 sub mul add sub 2 div max\n";
1149  t << "} def\n";
1150  t << "\n";
1151  t << "/cw % boxwidth = MAX(boxwidth, stringwidth(arg1))\n";
1152  t << "{\n";
1153  t << " /str exch def\n";
1154  t << " /boxwidth boxwidth str stringwidth pop max def\n";
1155  t << "} def\n";
1156  t << "\n";
1157  t << "/box % draws a box with text 'arg1' at grid pos (arg2,arg3)\n";
1158  t << "{ gsave\n";
1159  t << " 2 setlinewidth\n";
1160  t << " newpath\n";
1161  t << " exch xspacing mul xoffset add\n";
1162  t << " exch yspacing mul\n";
1163  t << " moveto\n";
1164  t << " boxwidth 0 rlineto \n";
1165  t << " 0 boxheight rlineto \n";
1166  t << " boxwidth neg 0 rlineto \n";
1167  t << " 0 boxheight neg rlineto \n";
1168  t << " closepath\n";
1169  t << " dup stringwidth pop neg boxwidth add 2 div\n";
1170  t << " boxheight fontheight 2 div sub 2 div\n";
1171  t << " rmoveto show stroke\n";
1172  t << " grestore\n";
1173  t << "} def \n";
1174  t << "\n";
1175  t << "/mark\n";
1176  t << "{ newpath\n";
1177  t << " exch xspacing mul xoffset add boxwidth add\n";
1178  t << " exch yspacing mul\n";
1179  t << " moveto\n";
1180  t << " 0 boxheight 4 div rlineto\n";
1181  t << " boxheight neg 4 div boxheight neg 4 div rlineto\n";
1182  t << " closepath\n";
1183  t << " eofill\n";
1184  t << " stroke\n";
1185  t << "} def\n";
1186  t << "\n";
1187  t << "/arrow\n";
1188  t << "{ newpath\n";
1189  t << " moveto\n";
1190  t << " 3 -8 rlineto\n";
1191  t << " -6 0 rlineto\n";
1192  t << " 3 8 rlineto\n";
1193  t << " closepath\n";
1194  t << " eofill\n";
1195  t << " stroke\n";
1196  t << "} def\n";
1197  t << "\n";
1198  t << "/out % draws an output connector for the block at (arg1,arg2)\n";
1199  t << "{\n";
1200  t << " newpath\n";
1201  t << " exch xspacing mul xoffset add boxwidth 2 div add\n";
1202  t << " exch yspacing mul boxheight add\n";
1203  t << " /y exch def\n";
1204  t << " /x exch def\n";
1205  t << " x y moveto\n";
1206  t << " 0 disty 2 div rlineto \n";
1207  t << " stroke\n";
1208  t << " 1 eq { x y disty 2 div add arrow } if\n";
1209  t << "} def\n";
1210  t << "\n";
1211  t << "/in % draws an input connector for the block at (arg1,arg2)\n";
1212  t << "{\n";
1213  t << " newpath\n";
1214  t << " exch xspacing mul xoffset add boxwidth 2 div add\n";
1215  t << " exch yspacing mul disty 2 div sub\n";
1216  t << " /y exch def\n";
1217  t << " /x exch def\n";
1218  t << " x y moveto\n";
1219  t << " 0 disty 2 div rlineto\n";
1220  t << " stroke\n";
1221  t << " 1 eq { x y disty 2 div add arrow } if\n";
1222  t << "} def\n";
1223  t << "\n";
1224  t << "/hedge\n";
1225  t << "{\n";
1226  t << " exch xspacing mul xoffset add boxwidth 2 div add\n";
1227  t << " exch yspacing mul boxheight 2 div sub\n";
1228  t << " /y exch def\n";
1229  t << " /x exch def\n";
1230  t << " newpath\n";
1231  t << " x y moveto\n";
1232  t << " boxwidth 2 div distx add 0 rlineto\n";
1233  t << " stroke\n";
1234  t << " 1 eq\n";
1235  t << " { newpath x boxwidth 2 div distx add add y moveto\n";
1236  t << " -8 3 rlineto\n";
1237  t << " 0 -6 rlineto\n";
1238  t << " 8 3 rlineto\n";
1239  t << " closepath\n";
1240  t << " eofill\n";
1241  t << " stroke\n";
1242  t << " } if\n";
1243  t << "} def\n";
1244  t << "\n";
1245  t << "/vedge\n";
1246  t << "{\n";
1247  t << " /ye exch def\n";
1248  t << " /ys exch def\n";
1249  t << " /xs exch def\n";
1250  t << " newpath\n";
1251  t << " xs xspacing mul xoffset add boxwidth 2 div add dup\n";
1252  t << " ys yspacing mul boxheight 2 div sub\n";
1253  t << " moveto\n";
1254  t << " ye yspacing mul boxheight 2 div sub\n";
1255  t << " lineto\n";
1256  t << " stroke\n";
1257  t << "} def\n";
1258  t << "\n";
1259  t << "/conn % connections the blocks from col 'arg1' to 'arg2' of row 'arg3'\n";
1260  t << "{\n";
1261  t << " /ys exch def\n";
1262  t << " /xe exch def\n";
1263  t << " /xs exch def\n";
1264  t << " newpath\n";
1265  t << " xs xspacing mul xoffset add boxwidth 2 div add\n";
1266  t << " ys yspacing mul disty 2 div sub\n";
1267  t << " moveto\n";
1268  t << " xspacing xe xs sub mul 0\n";
1269  t << " rlineto\n";
1270  t << " stroke\n";
1271  t << "} def\n";
1272  t << "\n";
1273  t << "% ----- main ------\n";
1274  t << "\n";
1275  t << "boxfont setfont\n";
1276  t << "1 boundaspect scale\n";
1277 
1278 
1279  for (const auto &dr : p->base)
1280  {
1281  bool done=FALSE;
1282  for (const auto &di : *dr)
1283  {
1284  done=di->isInList();
1285  t << "(" << convertToPSString(di->label()) << ") cw\n";
1286  }
1287  if (done) break;
1288  }
1289 
1290  auto it = p->super.begin();
1291  if (it!=p->super.end()) ++it;
1292  for (;it!=p->super.end();++it)
1293  {
1294  const auto &dr = *it;
1295  bool done=FALSE;
1296  for (const auto &di : *dr)
1297  {
1298  done=di->isInList();
1299  t << "(" << convertToPSString(di->label()) << ") cw\n";
1300  }
1301  if (done) break;
1302  }
1303 
1304  t << "/boxwidth boxwidth marginwidth 2 mul add def\n"
1305  << "/xspacing boxwidth distx add def\n"
1306  << "/yspacing boxheight disty add def\n"
1307  << "/scalefactor \n"
1308  << " boxwidth cols mul distx cols 1 sub mul add\n"
1309  << " boxheight rows mul disty rows 1 sub mul add boundaspect mul \n"
1310  << " max def\n"
1311  << "boundx scalefactor div boundy scalefactor div scale\n";
1312 
1313  t << "\n% ----- classes -----\n\n";
1314  p->base.drawBoxes(t,0,TRUE,FALSE,baseRows,superRows,0,0);
1315  p->super.drawBoxes(t,0,FALSE,FALSE,baseRows,superRows,0,0);
1316 
1317  t << "\n% ----- relations -----\n\n";
1318  p->base.drawConnectors(t,0,TRUE,FALSE,baseRows,superRows,0,0);
1319  p->super.drawConnectors(t,0,FALSE,FALSE,baseRows,superRows,0,0);
1320 
1321  }
1322  f.close();
1323 
1324  if (Config_getBool(USE_PDFLATEX))
1325  {
1326  QCString epstopdfArgs(4096);
1327  epstopdfArgs.sprintf("\"%s.eps\" --outfile=\"%s.pdf\"",
1328  qPrint(epsBaseName),qPrint(epsBaseName));
1329  //printf("Converting eps using '%s'\n",qPrint(epstopdfArgs));
1331  if (Portable::system("epstopdf",epstopdfArgs)!=0)
1332  {
1333  err("Problems running epstopdf. Check your TeX installation!\n");
1335  return;
1336  }
1338  }
1339 }

引用了 Config_getBool, convertToPSString(), err(), FALSE, gridWidth, p, qPrint(), QCString::sprintf(), QCString::str(), Portable::system(), Portable::sysTimerStart(), Portable::sysTimerStop(), term() , 以及 TRUE.

被这些函数引用 LatexGenerator::endClassDiagram() , 以及 ClassContext::Private::inheritanceDiagram().

◆ writeImage()

void ClassDiagram::writeImage ( TextStream t,
const QCString path,
const QCString relPath,
const QCString file,
bool  generateMap = true 
) const

在文件 diagram.cpp1342 行定义.

1345 {
1346  uint baseRows=p->base.computeRows();
1347  uint superRows=p->super.computeRows();
1348  uint rows=baseRows+superRows-1;
1349 
1350  uint lb,ls,xb,xs;
1351  p->base.computeExtremes(&lb,&xb);
1352  p->super.computeExtremes(&ls,&xs);
1353 
1354  uint cellWidth = std::max(lb,ls)+labelHorMargin*2;
1355  uint maxXPos = std::max(xb,xs);
1356  uint labelVertMargin = 6; //std::max(6,(cellWidth-fontHeight)/6); // aspect at least 1:3
1357  uint cellHeight = labelVertMargin*2+fontHeight;
1358  uint imageWidth = (maxXPos+gridWidth)*cellWidth/gridWidth+
1359  (maxXPos*labelHorSpacing)/gridWidth;
1360  uint imageHeight = rows*cellHeight+(rows-1)*labelVertSpacing;
1361 
1362  Image image(imageWidth,imageHeight);
1363 
1364  p->base.drawBoxes(t,&image,TRUE,TRUE,baseRows,superRows,cellWidth,cellHeight,relPath,generateMap);
1365  p->super.drawBoxes(t,&image,FALSE,TRUE,baseRows,superRows,cellWidth,cellHeight,relPath,generateMap);
1366  p->base.drawConnectors(t,&image,TRUE,TRUE,baseRows,superRows,cellWidth,cellHeight);
1367  p->super.drawConnectors(t,&image,FALSE,TRUE,baseRows,superRows,cellWidth,cellHeight);
1368 
1369 #define IMAGE_EXT ".png"
1370  image.save((QCString)path+"/"+fileName+IMAGE_EXT);
1372 }

引用了 IndexList::addImageFile(), FALSE, fontHeight, gridWidth, IMAGE_EXT, Doxygen::indexList, labelHorMargin, labelHorSpacing, labelVertSpacing, p , 以及 TRUE.

被这些函数引用 RTFGenerator::endClassDiagram(), HtmlGenerator::endClassDiagram(), DocbookGenerator::endClassDiagram() , 以及 ClassContext::Private::inheritanceDiagram().

类成员变量说明

◆ p

std::unique_ptr<Private> ClassDiagram::p
private

在文件 diagram.h39 行定义.

被这些函数引用 ClassDiagram(), writeFigure() , 以及 writeImage().


该类的文档由以下文件生成:
DiagramItem::move
void move(int dx, int dy)
Definition: diagram.cpp:49
Doxygen::indexList
static IndexList * indexList
Definition: doxygen.h:114
QCString::str
std::string str() const
Definition: qcstring.h:442
err
void err(const char *fmt,...)
Definition: message.cpp:203
TextStream
Text streaming class that buffers data.
Definition: textstream.h:33
DiagramItem::xPos
uint xPos() const
Definition: diagram.cpp:50
uint
unsigned uint
Definition: qcstring.h:40
Image
Class representing a bitmap image generated by doxygen.
Definition: image.h:26
labelHorMargin
const uint labelHorMargin
Definition: diagram.cpp:144
fontHeight
const uint fontHeight
Definition: diagram.cpp:145
Portable::sysTimerStart
void sysTimerStart()
Definition: portable.cpp:470
IndexList::addImageFile
void addImageFile(const QCString &name)
Definition: index.h:105
labelHorSpacing
const uint labelHorSpacing
Definition: diagram.cpp:142
TRUE
#define TRUE
Definition: qcstring.h:36
Portable::system
int system(const QCString &command, const QCString &args, bool commandHasConsole=true)
Definition: portable.cpp:42
ClassDiagram::p
std::unique_ptr< Private > p
Definition: diagram.h:39
IMAGE_EXT
#define IMAGE_EXT
Config_getBool
#define Config_getBool(name)
Definition: config.h:33
labelVertSpacing
const uint labelVertSpacing
Definition: diagram.cpp:143
term
void term(const char *fmt,...)
Definition: message.cpp:220
qPrint
const char * qPrint(const char *s)
Definition: qcstring.h:589
Portable::sysTimerStop
void sysTimerStop()
Definition: portable.cpp:475
gridWidth
const uint gridWidth
Definition: diagram.cpp:139
convertToPSString
QCString convertToPSString(const QCString &s)
Definition: util.cpp:4142
DiagramItem
Class representing a single node in the built-in class diagram
Definition: diagram.cpp:40
FALSE
#define FALSE
Definition: qcstring.h:33
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108