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

Constructor & Destructor Documentation

DotFilePatcher::DotFilePatcher ( const char *  patchFile)

Definition at line 833 of file dot.cpp.

References m_maps.

: m_patchFile(patchFile)
{
m_maps.setAutoDelete(TRUE);
}

Member Function Documentation

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

Definition at line 860 of file dot.cpp.

References DotFilePatcher::Map::graphId, DotFilePatcher::Map::label, m_maps, DotFilePatcher::Map::mapFile, DotFilePatcher::Map::urlOnly, and DotFilePatcher::Map::zoomable.

Referenced by DotManager::addFigure().

{
int id = m_maps.count();
Map *map = new Map;
map->mapFile = figureName;
map->urlOnly = heightCheck;
map->label = baseName;
map->zoomable = FALSE;
map->graphId = -1;
m_maps.append(map);
return id;
}
int DotFilePatcher::addMap ( const QCString &  mapFile,
const QCString &  relPath,
bool  urlOnly,
const QCString &  context,
const QCString &  label 
)

Definition at line 844 of file dot.cpp.

References DotFilePatcher::Map::context, DotFilePatcher::Map::graphId, DotFilePatcher::Map::label, m_maps, DotFilePatcher::Map::mapFile, DotFilePatcher::Map::relPath, DotFilePatcher::Map::urlOnly, and DotFilePatcher::Map::zoomable.

Referenced by DotManager::addMap().

{
int id = m_maps.count();
Map *map = new Map;
map->mapFile = mapFile;
map->relPath = relPath;
map->urlOnly = urlOnly;
map->context = context;
map->label = label;
map->zoomable = FALSE;
map->graphId = -1;
m_maps.append(map);
return id;
}
int DotFilePatcher::addSVGConversion ( const QCString &  relPath,
bool  urlOnly,
const QCString &  context,
bool  zoomable,
int  graphId 
)

Definition at line 874 of file dot.cpp.

References DotFilePatcher::Map::context, DotFilePatcher::Map::graphId, m_maps, DotFilePatcher::Map::relPath, DotFilePatcher::Map::urlOnly, and DotFilePatcher::Map::zoomable.

Referenced by DotManager::addSVGConversion(), and writeDotImageMapFromFile().

{
int id = m_maps.count();
Map *map = new Map;
map->relPath = relPath;
map->urlOnly = urlOnly;
map->context = context;
map->zoomable = zoomable;
map->graphId = graphId;
m_maps.append(map);
return id;
}
int DotFilePatcher::addSVGObject ( const QCString &  baseName,
const QCString &  figureName,
const QCString &  relPath 
)

Definition at line 889 of file dot.cpp.

References DotFilePatcher::Map::graphId, DotFilePatcher::Map::label, m_maps, DotFilePatcher::Map::mapFile, DotFilePatcher::Map::relPath, and DotFilePatcher::Map::zoomable.

Referenced by DotManager::addSVGObject().

{
int id = m_maps.count();
Map *map = new Map;
map->mapFile = absImgName;
map->relPath = relPath;
map->label = baseName;
map->zoomable = FALSE;
map->graphId = -1;
m_maps.append(map);
return id;
}
QCString DotFilePatcher::file ( ) const

Definition at line 839 of file dot.cpp.

References m_patchFile.

Referenced by DotManager::run().

{
return m_patchFile;
}
bool DotFilePatcher::run ( )

Definition at line 904 of file dot.cpp.

References Config_getBool, DotFilePatcher::Map::context, convertMapFile(), endl(), err(), DotFilePatcher::Map::graphId, DotFilePatcher::Map::label, m_maps, m_patchFile, DotFilePatcher::Map::mapFile, DotFilePatcher::Map::relPath, replaceRef(), stripPath(), substitute(), svgZoomFooter, svgZoomHeader, DotFilePatcher::Map::urlOnly, writeSVGFigureLink(), writeVecGfxFigure(), and DotFilePatcher::Map::zoomable.

Referenced by DotManager::run(), and writeDotImageMapFromFile().

{
//printf("DotFilePatcher::run(): %s\n",m_patchFile.data());
static bool interactiveSVG = Config_getBool(INTERACTIVE_SVG);
bool isSVGFile = m_patchFile.right(4)==".svg";
int graphId = -1;
QCString relPath;
if (isSVGFile)
{
Map *map = m_maps.at(0); // there is only one 'map' for a SVG file
interactiveSVG = interactiveSVG && map->zoomable;
graphId = map->graphId;
relPath = map->relPath;
//printf("DotFilePatcher::addSVGConversion: file=%s zoomable=%d\n",
// m_patchFile.data(),map->zoomable);
}
QString tmpName = QString::fromUtf8(m_patchFile+".tmp");
QString patchFile = QString::fromUtf8(m_patchFile);
if (!QDir::current().rename(patchFile,tmpName))
{
err("Failed to rename file %s to %s!\n",m_patchFile.data(),tmpName.data());
return FALSE;
}
QFile fi(tmpName);
QFile fo(patchFile);
if (!fi.open(IO_ReadOnly))
{
err("problem opening file %s for patching!\n",tmpName.data());
QDir::current().rename(tmpName,patchFile);
return FALSE;
}
if (!fo.open(IO_WriteOnly))
{
err("problem opening file %s for patching!\n",m_patchFile.data());
QDir::current().rename(tmpName,patchFile);
return FALSE;
}
FTextStream t(&fo);
const int maxLineLen=100*1024;
int lineNr=1;
int width,height;
bool insideHeader=FALSE;
bool replacedHeader=FALSE;
bool foundSize=FALSE;
while (!fi.atEnd()) // foreach line
{
QCString line(maxLineLen);
int numBytes = fi.readLine(line.rawData(),maxLineLen);
if (numBytes<=0)
{
break;
}
line.resize(numBytes+1);
//printf("line=[%s]\n",line.stripWhiteSpace().data());
int i;
ASSERT(numBytes<maxLineLen);
if (isSVGFile)
{
if (interactiveSVG)
{
if (line.find("<svg")!=-1 && !replacedHeader)
{
int count;
count = sscanf(line.data(),"<svg width=\"%dpt\" height=\"%dpt\"",&width,&height);
//printf("width=%d height=%d\n",width,height);
foundSize = count==2 && (width>500 || height>450);
if (foundSize) insideHeader=TRUE;
}
else if (insideHeader && !replacedHeader && line.find("<title>")!=-1)
{
if (foundSize)
{
// insert special replacement header for interactive SVGs
t << "<!--zoomable " << height << " -->\n";
t << "var viewWidth = " << width << ";\n";
t << "var viewHeight = " << height << ";\n";
if (graphId>=0)
{
t << "var sectionId = 'dynsection-" << graphId << "';\n";
}
t << "</script>\n";
t << "<script xlink:href=\"" << relPath << "svgpan.js\"/>\n";
t << "<svg id=\"graph\" class=\"graph\">\n";
t << "<g id=\"viewport\">\n";
}
insideHeader=FALSE;
replacedHeader=TRUE;
}
}
if (!insideHeader || !foundSize) // copy SVG and replace refs,
// unless we are inside the header of the SVG.
// Then we replace it with another header.
{
Map *map = m_maps.at(0); // there is only one 'map' for a SVG file
t << replaceRef(line,map->relPath,map->urlOnly,map->context,"_top");
}
}
else if ((i=line.find("<!-- SVG"))!=-1 || (i=line.find("[!-- SVG"))!=-1)
{
//printf("Found marker at %d\n",i);
int mapId=-1;
t << line.left(i);
int n = sscanf(line.data()+i+1,"!-- SVG %d",&mapId);
if (n==1 && mapId>=0 && mapId<(int)m_maps.count())
{
int e = QMAX(line.find("--]"),line.find("-->"));
Map *map = m_maps.at(mapId);
//printf("DotFilePatcher::writeSVGFigure: file=%s zoomable=%d\n",
// m_patchFile.data(),map->zoomable);
if (!writeSVGFigureLink(t,map->relPath,map->label,map->mapFile))
{
err("Problem extracting size from SVG file %s\n",map->mapFile.data());
}
if (e!=-1) t << line.mid(e+3);
}
else // error invalid map id!
{
err("Found invalid SVG id in file %s!\n",m_patchFile.data());
t << line.mid(i);
}
}
else if ((i=line.find("<!-- MAP"))!=-1)
{
int mapId=-1;
t << line.left(i);
int n = sscanf(line.data()+i,"<!-- MAP %d",&mapId);
if (n==1 && mapId>=0 && mapId<(int)m_maps.count())
{
Map *map = m_maps.at(mapId);
//printf("patching MAP %d in file %s with contents of %s\n",
// mapId,m_patchFile.data(),map->mapFile.data());
t << "<map name=\"" << map->label << "\" id=\"" << map->label << "\">" << endl;
convertMapFile(t,map->mapFile,map->relPath,map->urlOnly,map->context);
t << "</map>" << endl;
}
else // error invalid map id!
{
err("Found invalid MAP id in file %s!\n",m_patchFile.data());
t << line.mid(i);
}
}
else if ((i=line.find("% FIG"))!=-1)
{
int mapId=-1;
int n = sscanf(line.data()+i+2,"FIG %d",&mapId);
//printf("line='%s' n=%d\n",line.data()+i,n);
if (n==1 && mapId>=0 && mapId<(int)m_maps.count())
{
Map *map = m_maps.at(mapId);
//printf("patching FIG %d in file %s with contents of %s\n",
// mapId,m_patchFile.data(),map->mapFile.data());
if (!writeVecGfxFigure(t,map->label,map->mapFile))
{
err("problem writing FIG %d figure!\n",mapId);
return FALSE;
}
}
else // error invalid map id!
{
err("Found invalid bounding FIG %d in file %s!\n",mapId,m_patchFile.data());
t << line;
}
}
else
{
t << line;
}
lineNr++;
}
fi.close();
if (isSVGFile && interactiveSVG && replacedHeader)
{
QCString orgName=m_patchFile.left(m_patchFile.length()-4)+"_org.svg";
t << substitute(svgZoomFooter,"$orgname",stripPath(orgName));
fo.close();
// keep original SVG file so we can refer to it, we do need to replace
// dummy link by real ones
QFile fi(tmpName);
QFile fo(orgName);
if (!fi.open(IO_ReadOnly))
{
err("problem opening file %s for reading!\n",tmpName.data());
return FALSE;
}
if (!fo.open(IO_WriteOnly))
{
err("problem opening file %s for writing!\n",orgName.data());
return FALSE;
}
FTextStream t(&fo);
while (!fi.atEnd()) // foreach line
{
QCString line(maxLineLen);
int numBytes = fi.readLine(line.rawData(),maxLineLen);
if (numBytes<=0)
{
break;
}
line.resize(numBytes+1);
Map *map = m_maps.at(0); // there is only one 'map' for a SVG file
t << replaceRef(line,map->relPath,map->urlOnly,map->context,"_top");
}
fi.close();
fo.close();
}
// remove temporary file
QDir::current().remove(tmpName);
return TRUE;
}

Member Data Documentation

QList<Map> DotFilePatcher::m_maps
private

Definition at line 432 of file dot.h.

Referenced by addFigure(), addMap(), addSVGConversion(), addSVGObject(), DotFilePatcher(), and run().

QCString DotFilePatcher::m_patchFile
private

Definition at line 433 of file dot.h.

Referenced by file(), and run().


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