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

#include <dot.h>

Classes

struct  Map
 

Public Member Functions

 DotFilePatcher (const char *patchFile)
 
int addMap (const QCString &mapFile, const QCString &relPath, bool urlOnly, const QCString &context, const QCString &label)
 
int addFigure (const QCString &baseName, const QCString &figureName, bool heightCheck)
 
int addSVGConversion (const QCString &relPath, bool urlOnly, const QCString &context, bool zoomable, int graphId)
 
int addSVGObject (const QCString &baseName, const QCString &figureName, const QCString &relPath)
 
bool run ()
 
QCString file () const
 

Private Attributes

QList< Mapm_maps
 
QCString m_patchFile
 

Detailed Description

Helper class to insert a set of map file into an output file

Definition at line 398 of file dot.h.

Constructor & Destructor Documentation

DotFilePatcher::DotFilePatcher ( const char *  patchFile)

Definition at line 875 of file dot.cpp.

876  : m_patchFile(patchFile)
877 {
878  m_maps.setAutoDelete(TRUE);
879 }
QCString m_patchFile
Definition: dot.h:425
QList< Map > m_maps
Definition: dot.h:424
const bool TRUE
Definition: qglobal.h:371

Member Function Documentation

int DotFilePatcher::addFigure ( const QCString baseName,
const QCString figureName,
bool  heightCheck 
)

Definition at line 902 of file dot.cpp.

904 {
905  int id = m_maps.count();
906  Map *map = new Map;
907  map->mapFile = figureName;
908  map->urlOnly = heightCheck;
909  map->label = baseName;
910  map->zoomable = FALSE;
911  map->graphId = -1;
912  m_maps.append(map);
913  return id;
914 }
const bool FALSE
Definition: qglobal.h:370
QList< Map > m_maps
Definition: dot.h:424
static QCString baseName
Definition: scanner.cpp:10890
#define Map
Definition: vhdlcode.cpp:19862
int DotFilePatcher::addMap ( const QCString mapFile,
const QCString relPath,
bool  urlOnly,
const QCString context,
const QCString label 
)

Definition at line 886 of file dot.cpp.

888 {
889  int id = m_maps.count();
890  Map *map = new Map;
891  map->mapFile = mapFile;
892  map->relPath = relPath;
893  map->urlOnly = urlOnly;
894  map->context = context;
895  map->label = label;
896  map->zoomable = FALSE;
897  map->graphId = -1;
898  m_maps.append(map);
899  return id;
900 }
const bool FALSE
Definition: qglobal.h:370
QList< Map > m_maps
Definition: dot.h:424
#define Map
Definition: vhdlcode.cpp:19862
int DotFilePatcher::addSVGConversion ( const QCString relPath,
bool  urlOnly,
const QCString context,
bool  zoomable,
int  graphId 
)

Definition at line 916 of file dot.cpp.

919 {
920  int id = m_maps.count();
921  Map *map = new Map;
922  map->relPath = relPath;
923  map->urlOnly = urlOnly;
924  map->context = context;
925  map->zoomable = zoomable;
926  map->graphId = graphId;
927  m_maps.append(map);
928  return id;
929 }
QList< Map > m_maps
Definition: dot.h:424
#define Map
Definition: vhdlcode.cpp:19862
int DotFilePatcher::addSVGObject ( const QCString baseName,
const QCString figureName,
const QCString relPath 
)

Definition at line 931 of file dot.cpp.

934 {
935  int id = m_maps.count();
936  Map *map = new Map;
937  map->mapFile = absImgName;
938  map->relPath = relPath;
939  map->label = baseName;
940  map->zoomable = FALSE;
941  map->graphId = -1;
942  m_maps.append(map);
943  return id;
944 }
const bool FALSE
Definition: qglobal.h:370
QList< Map > m_maps
Definition: dot.h:424
static QCString baseName
Definition: scanner.cpp:10890
#define Map
Definition: vhdlcode.cpp:19862
QCString DotFilePatcher::file ( ) const

Definition at line 881 of file dot.cpp.

882 {
883  return m_patchFile;
884 }
QCString m_patchFile
Definition: dot.h:425
bool DotFilePatcher::run ( )

Definition at line 946 of file dot.cpp.

947 {
948  //printf("DotFilePatcher::run(): %s\n",m_patchFile.data());
949  static bool interactiveSVG = Config_getBool("INTERACTIVE_SVG");
950  bool isSVGFile = m_patchFile.right(4)==".svg";
951  int graphId = -1;
952  QCString relPath;
953  if (isSVGFile)
954  {
955  Map *map = m_maps.at(0); // there is only one 'map' for a SVG file
956  interactiveSVG = interactiveSVG && map->zoomable;
957  graphId = map->graphId;
958  relPath = map->relPath;
959  //printf("DotFilePatcher::addSVGConversion: file=%s zoomable=%d\n",
960  // m_patchFile.data(),map->zoomable);
961  }
962  QString tmpName = QString::fromUtf8(m_patchFile+".tmp");
964  if (!QDir::current().rename(patchFile,tmpName))
965  {
966  err("Failed to rename file %s to %s!\n",m_patchFile.data(),tmpName.data());
967  return FALSE;
968  }
969  QFile fi(tmpName);
970  QFile fo(patchFile);
971  if (!fi.open(IO_ReadOnly))
972  {
973  err("problem opening file %s for patching!\n",tmpName.data());
974  QDir::current().rename(tmpName,patchFile);
975  return FALSE;
976  }
977  if (!fo.open(IO_WriteOnly))
978  {
979  err("problem opening file %s for patching!\n",m_patchFile.data());
980  QDir::current().rename(tmpName,patchFile);
981  return FALSE;
982  }
983  FTextStream t(&fo);
984  const int maxLineLen=100*1024;
985  int lineNr=1;
986  int width,height;
987  bool insideHeader=FALSE;
988  bool replacedHeader=FALSE;
989  bool foundSize=FALSE;
990  while (!fi.atEnd()) // foreach line
991  {
992  QCString line(maxLineLen);
993  int numBytes = fi.readLine(line.rawData(),maxLineLen);
994  if (numBytes<=0)
995  {
996  break;
997  }
998  line.resize(numBytes+1);
999 
1000  //printf("line=[%s]\n",line.stripWhiteSpace().data());
1001  int i;
1002  ASSERT(numBytes<maxLineLen);
1003  if (isSVGFile)
1004  {
1005  if (interactiveSVG)
1006  {
1007  if (line.find("<svg")!=-1 && !replacedHeader)
1008  {
1009  int count;
1010  count = sscanf(line.data(),"<svg width=\"%dpt\" height=\"%dpt\"",&width,&height);
1011  //printf("width=%d height=%d\n",width,height);
1012  foundSize = count==2 && (width>500 || height>450);
1013  if (foundSize) insideHeader=TRUE;
1014  }
1015  else if (insideHeader && !replacedHeader && line.find("<title>")!=-1)
1016  {
1017  if (foundSize)
1018  {
1019  // insert special replacement header for interactive SVGs
1020  t << "<!--zoomable " << height << " -->\n";
1021  t << svgZoomHeader;
1022  t << "var viewWidth = " << width << ";\n";
1023  t << "var viewHeight = " << height << ";\n";
1024  if (graphId>=0)
1025  {
1026  t << "var sectionId = 'dynsection-" << graphId << "';\n";
1027  }
1028  t << "</script>\n";
1029  t << "<script xlink:href=\"" << relPath << "svgpan.js\"/>\n";
1030  t << "<svg id=\"graph\" class=\"graph\">\n";
1031  t << "<g id=\"viewport\">\n";
1032  }
1033  insideHeader=FALSE;
1034  replacedHeader=TRUE;
1035  }
1036  }
1037  if (!insideHeader || !foundSize) // copy SVG and replace refs,
1038  // unless we are inside the header of the SVG.
1039  // Then we replace it with another header.
1040  {
1041  Map *map = m_maps.at(0); // there is only one 'map' for a SVG file
1042  t << replaceRef(line,map->relPath,map->urlOnly,map->context,"_top");
1043  }
1044  }
1045  else if ((i=line.find("<!-- SVG"))!=-1 || (i=line.find("[!-- SVG"))!=-1)
1046  {
1047  //printf("Found marker at %d\n",i);
1048  int mapId=-1;
1049  t << line.left(i);
1050  int n = sscanf(line.data()+i+1,"!-- SVG %d",&mapId);
1051  if (n==1 && mapId>=0 && mapId<(int)m_maps.count())
1052  {
1053  int e = QMAX(line.find("--]"),line.find("-->"));
1054  Map *map = m_maps.at(mapId);
1055  //printf("DotFilePatcher::writeSVGFigure: file=%s zoomable=%d\n",
1056  // m_patchFile.data(),map->zoomable);
1057  if (!writeSVGFigureLink(t,map->relPath,map->label,map->mapFile))
1058  {
1059  err("Problem extracting size from SVG file %s\n",map->mapFile.data());
1060  }
1061  if (e!=-1) t << line.mid(e+3);
1062  }
1063  else // error invalid map id!
1064  {
1065  err("Found invalid SVG id in file %s!\n",m_patchFile.data());
1066  t << line.mid(i);
1067  }
1068  }
1069  else if ((i=line.find("<!-- MAP"))!=-1)
1070  {
1071  int mapId=-1;
1072  t << line.left(i);
1073  int n = sscanf(line.data()+i,"<!-- MAP %d",&mapId);
1074  if (n==1 && mapId>=0 && mapId<(int)m_maps.count())
1075  {
1076  Map *map = m_maps.at(mapId);
1077  //printf("patching MAP %d in file %s with contents of %s\n",
1078  // mapId,m_patchFile.data(),map->mapFile.data());
1079  t << "<map name=\"" << map->label << "\" id=\"" << map->label << "\">" << endl;
1080  convertMapFile(t,map->mapFile,map->relPath,map->urlOnly,map->context);
1081  t << "</map>" << endl;
1082  }
1083  else // error invalid map id!
1084  {
1085  err("Found invalid MAP id in file %s!\n",m_patchFile.data());
1086  t << line.mid(i);
1087  }
1088  }
1089  else if ((i=line.find("% FIG"))!=-1)
1090  {
1091  int mapId=-1;
1092  int n = sscanf(line.data()+i+2,"FIG %d",&mapId);
1093  //printf("line='%s' n=%d\n",line.data()+i,n);
1094  if (n==1 && mapId>=0 && mapId<(int)m_maps.count())
1095  {
1096  Map *map = m_maps.at(mapId);
1097  //printf("patching FIG %d in file %s with contents of %s\n",
1098  // mapId,m_patchFile.data(),map->mapFile.data());
1099  if (!writeVecGfxFigure(t,map->label,map->mapFile))
1100  {
1101  err("problem writing FIG %d figure!\n",mapId);
1102  return FALSE;
1103  }
1104  }
1105  else // error invalid map id!
1106  {
1107  err("Found invalid bounding FIG %d in file %s!\n",mapId,m_patchFile.data());
1108  t << line;
1109  }
1110  }
1111  else
1112  {
1113  t << line;
1114  }
1115  lineNr++;
1116  }
1117  fi.close();
1118  if (isSVGFile && interactiveSVG && replacedHeader)
1119  {
1120  QCString orgName=m_patchFile.left(m_patchFile.length()-4)+"_org.svg";
1121  t << substitute(svgZoomFooter,"$orgname",stripPath(orgName));
1122  fo.close();
1123  // keep original SVG file so we can refer to it, we do need to replace
1124  // dummy link by real ones
1125  QFile fi(tmpName);
1126  QFile fo(orgName);
1127  if (!fi.open(IO_ReadOnly))
1128  {
1129  err("problem opening file %s for reading!\n",tmpName.data());
1130  return FALSE;
1131  }
1132  if (!fo.open(IO_WriteOnly))
1133  {
1134  err("problem opening file %s for writing!\n",orgName.data());
1135  return FALSE;
1136  }
1137  FTextStream t(&fo);
1138  while (!fi.atEnd()) // foreach line
1139  {
1140  QCString line(maxLineLen);
1141  int numBytes = fi.readLine(line.rawData(),maxLineLen);
1142  if (numBytes<=0)
1143  {
1144  break;
1145  }
1146  line.resize(numBytes+1);
1147  Map *map = m_maps.at(0); // there is only one 'map' for a SVG file
1148  t << replaceRef(line,map->relPath,map->urlOnly,map->context,"_top");
1149  }
1150  fi.close();
1151  fo.close();
1152  }
1153  // remove temporary file
1154  QDir::current().remove(tmpName);
1155  return TRUE;
1156 }
QCString m_patchFile
Definition: dot.h:425
virtual bool remove(const QString &fileName, bool acceptAbsPath=TRUE)
Definition: qdir.cpp:915
uint length() const
Definition: qcstring.h:195
#define IO_WriteOnly
Definition: qiodevice.h:62
const bool FALSE
Definition: qglobal.h:370
static QCString replaceRef(const QCString &buf, const QCString relPath, bool urlOnly, const QCString &context, const QCString &target=QCString())
Definition: dot.cpp:286
static QCString stripPath(const QCString &s)
Definition: tagreader.cpp:1287
QCString left(uint len) const
Definition: qcstring.cpp:213
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QList< Map > m_maps
Definition: dot.h:424
Simplified and optimized version of QTextStream.
Definition: ftextstream.h:11
static const char svgZoomHeader[]
Definition: dot.cpp:59
#define IO_ReadOnly
Definition: qiodevice.h:61
const char * data() const
Definition: qstring.h:542
#define QMAX(a, b)
Definition: qglobal.h:390
const double e
static QDir current()
Definition: qdir.cpp:978
virtual bool rename(const QString &name, const QString &newName, bool acceptAbsPaths=TRUE)
Definition: qdir_unix.cpp:119
QCString right(uint len) const
Definition: qcstring.cpp:231
std::void_t< T > n
static bool writeVecGfxFigure(FTextStream &out, const QCString &baseName, const QCString &figureName)
Definition: dot.cpp:518
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
static QString fromUtf8(const char *, int len=-1)
Definition: qstring.cpp:14523
static bool writeSVGFigureLink(FTextStream &out, const QCString &relPath, const QCString &baseName, const QCString &absImgName)
Definition: dot.cpp:618
void line(double t, double *p, double &x, double &y, double &z)
static const char svgZoomFooter[]
Definition: dot.cpp:103
static bool convertMapFile(FTextStream &t, const char *mapName, const QCString relPath, bool urlOnly=FALSE, const QCString &context=QCString())
Definition: dot.cpp:370
#define Map
Definition: vhdlcode.cpp:19862
const bool TRUE
Definition: qglobal.h:371
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition: util.cpp:5088
QTextStream & endl(QTextStream &s)
#define ASSERT(x)
Definition: qglobal.h:590
def rename(src, dest)

Member Data Documentation

QList<Map> DotFilePatcher::m_maps
private

Definition at line 424 of file dot.h.

QCString DotFilePatcher::m_patchFile
private

Definition at line 425 of file dot.h.


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