SNAP Library 6.0, Developer Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
gviz.cpp
Go to the documentation of this file.
1 // GraphViz
3 namespace TSnap {
4 namespace TSnapDetail {
5 void GVizDoLayout(const TStr& GraphInFNm, TStr OutFNm, const TGVizLayout& Layout) {
6  TStr LayoutExe = TSnap::TSnapDetail::GVizGetLayoutStr(Layout), Ext = OutFNm.GetFExt(), GvPath;
7  #if defined(GLib_WIN)
8  GvPath = "C:\\Prog\\GraphViz\\bin\\";
9  #else
10  GvPath = "/usr/bin/";
11  //OutFNm = OutFNm.GetFMid() + Ext;
12  #endif
13  IAssert(Ext==".ps" || Ext==".gif" || Ext==".png");
14  const TStr ExeCmd = TStr::Fmt("%s -T%s %s -o %s", LayoutExe.CStr(),
15  Ext.CStr()+1, GraphInFNm.CStr(), OutFNm.CStr());
16 
17  if (system(ExeCmd.CStr())==0) { return; }
18  #if defined(GLib_WIN)
19  if (system(TStr::Fmt(".\\%s", ExeCmd.CStr()).CStr())==0) { return; }
20  #else
21  if (system(TStr::Fmt("./%s", ExeCmd.CStr()).CStr())==0) { return; }
22  #endif
23  if (system(TStr::Fmt("%s%s", GvPath.CStr(), ExeCmd.CStr()).CStr())==0) { return; }
24  fprintf(stderr, "[%s:%d] Cannot find GraphViz (%s). Set the PATH.\n", __FILE__, __LINE__, ExeCmd.CStr());
25  //#if defined(GLib_WIN)
26  //if (ShowPlot) system(TStr::Fmt("start %s", OutFNm.CStr()).CStr());
27  //#endif
28 }
29 
31  switch(Layout) {
32  case gvlDot : return "dot";
33  case gvlNeato : return "neato";
34  case gvlTwopi : return "twopi";
35  case gvlCirco: return "circo";
36  case gvlSfdp: return "sfdp";
37  default: Fail;
38  }
39  return TStr::GetNullStr();
40 }
41 
42 } // namespace TSnapDetail
43 } // namespace TSnap
44 
#define IAssert(Cond)
Definition: bd.h:262
Definition: gviz.h:3
Main namespace for all the Snap global entities.
Definition: alg.h:1
#define Fail
Definition: bd.h:238
TStr GetFExt() const
Definition: dt.cpp:1421
Definition: gviz.h:3
void GVizDoLayout(const TStr &GraphInFNm, TStr OutFNm, const TGVizLayout &Layout)
Runs GraphViz layout engine over a graph saved in the file GraphInFNm with output saved to OutFNm...
Definition: gviz.cpp:5
Definition: gviz.h:3
Definition: gviz.h:3
Definition: gviz.h:3
static TStr GetNullStr()
Definition: dt.cpp:1626
Definition: dt.h:412
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
enum TGVizLayout_ TGVizLayout
GraphViz Layout Engines.
char * CStr()
Definition: dt.h:479
TStr GVizGetLayoutStr(const TGVizLayout &Layout)
Generates the GraphViz command string based on the selected Layout engine.
Definition: gviz.cpp:30