Doxygen
Loading...
Searching...
No Matches
ClassDiagram Class Reference

Class representing a built-in class diagram. More...

#include <src/diagram.h>

Classes

struct  Private

Public Member Functions

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

Private Attributes

std::unique_ptr< Privatep

Detailed Description

Class representing a built-in class diagram.

Definition at line 28 of file diagram.h.

Constructor & Destructor Documentation

◆ ClassDiagram()

ClassDiagram::ClassDiagram ( const ClassDef * root)

Definition at line 1043 of file diagram.cpp.

1043 : p(std::make_unique<Private>(root))
1044{
1045 p->base.computeLayout();
1046 p->super.computeLayout();
1047 DiagramItem *baseItem = p->base.row(0)->item(0);
1048 DiagramItem *superItem = p->super.row(0)->item(0);
1049 uint32_t xbase = baseItem->xPos();
1050 uint32_t xsuper = superItem->xPos();
1051 if (xbase>xsuper)
1052 {
1053 int dist=static_cast<int>(xbase-xsuper);
1054 superItem->move(dist,0);
1055 p->super.moveChildren(superItem,dist);
1056 }
1057 else if (xbase<xsuper)
1058 {
1059 int dist=static_cast<int>(xsuper-xbase);
1060 baseItem->move(dist,0);
1061 p->base.moveChildren(baseItem,dist);
1062 }
1063}
std::unique_ptr< Private > p
Definition diagram.h:40
void move(int dx, int dy)
Definition diagram.cpp:50
uint32_t xPos() const
Definition diagram.cpp:51

References DiagramItem::move(), p, and DiagramItem::xPos().

Referenced by ~ClassDiagram().

◆ ~ClassDiagram()

ClassDiagram::~ClassDiagram ( )
default

References ClassDiagram().

Member Function Documentation

◆ writeFigure()

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

Definition at line 1067 of file diagram.cpp.

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

References Config_getBool, convertToPSString(), err, DString::ExplicitSize, gridWidth, Portable::openOutputStream(), p, qPrint(), Dir::remove(), DString::sprintf(), DString::str(), Portable::system(), and term.

Referenced by LatexGenerator::endClassDiagram().

◆ writeImage()

void ClassDiagram::writeImage ( TextStream & t,
const DString & path,
const DString & relPath,
const DString & file,
bool generateMap,
bool toIndex ) const

Definition at line 1363 of file diagram.cpp.

1366{
1367 uint32_t baseRows=p->base.computeRows();
1368 uint32_t superRows=p->super.computeRows();
1369 uint32_t rows=baseRows+superRows-1;
1370
1371 uint32_t lb=0,ls=0,xb=0,xs=0;
1372 p->base.computeExtremes(&lb,&xb);
1373 p->super.computeExtremes(&ls,&xs);
1374
1375 uint32_t cellWidth = std::max(lb,ls)+labelHorMargin*2;
1376 uint32_t maxXPos = std::max(xb,xs);
1377 uint32_t labelVertMargin = 6; //std::max(6,(cellWidth-fontHeight)/6); // aspect at least 1:3
1378 uint32_t cellHeight = labelVertMargin*2+fontHeight;
1379 uint32_t imageWidth = (maxXPos+gridWidth)*cellWidth/gridWidth+
1380 (maxXPos*labelHorSpacing)/gridWidth;
1381 uint32_t imageHeight = rows*cellHeight+(rows-1)*labelVertSpacing;
1382
1383 Image image(imageWidth,imageHeight);
1384
1385 p->base.drawBoxes(t,&image,true,true,baseRows,superRows,cellWidth,cellHeight,relPath,generateMap);
1386 p->super.drawBoxes(t,&image,false,true,baseRows,superRows,cellWidth,cellHeight,relPath,generateMap);
1387 p->base.drawConnectors(t,&image,true,true,baseRows,superRows,cellWidth,cellHeight);
1388 p->super.drawConnectors(t,&image,false,true,baseRows,superRows,cellWidth,cellHeight);
1389
1390#define IMAGE_EXT ".png"
1391 image.save(DString(path)+"/"+fileName+IMAGE_EXT);
1392 if (toIndex) Doxygen::indexList->addImageFile(DString(fileName)+IMAGE_EXT);
1393}
static IndexList * indexList
Definition doxygen.h:125
void addImageFile(const DString &name)
Definition indexlist.h:124
const uint32_t labelHorMargin
Definition diagram.cpp:144
const uint32_t labelHorSpacing
Definition diagram.cpp:142
const uint32_t fontHeight
Definition diagram.cpp:145
#define IMAGE_EXT
const uint32_t labelVertSpacing
Definition diagram.cpp:143

References IndexList::addImageFile(), fontHeight, gridWidth, IMAGE_EXT, Doxygen::indexList, labelHorMargin, labelHorSpacing, labelVertSpacing, and p.

Referenced by DocbookGenerator::endClassDiagram(), HtmlGenerator::endClassDiagram(), and RTFGenerator::endClassDiagram().

Member Data Documentation

◆ p

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

Definition at line 40 of file diagram.h.

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


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