SNAP Library, Developer Reference  2012-10-02 12:56:23
SNAP, a general purpose network analysis and graph mining library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
gviz.cpp
Go to the documentation of this file.
00001 
00002 // GraphViz
00003 namespace TSnap {
00004 namespace TSnapDetail {
00005 void GVizDoLayout(const TStr& GraphInFNm, TStr OutFNm, const TGVizLayout& Layout) {
00006   TStr LayoutExe = TSnap::TSnapDetail::GVizGetLayoutStr(Layout), Ext = OutFNm.GetFExt(), GvPath;
00007   #if defined(GLib_WIN)
00008     GvPath = "C:\\Prog\\GraphViz\\bin\\";
00009   #else
00010     GvPath = "/usr/bin/";
00011     Ext = ".ps";
00012     OutFNm = OutFNm.GetFMid() + Ext;
00013   #endif
00014   IAssert(Ext==".ps" || Ext==".gif" || Ext==".png");
00015   const TStr ExeCmd = TStr::Fmt("%s -T%s %s -o %s", LayoutExe.CStr(),
00016     Ext.CStr()+1, GraphInFNm.CStr(), OutFNm.CStr());
00017 
00018   if (system(ExeCmd.CStr())==0) { return; }
00019   #if defined(GLib_WIN)
00020   if (system(TStr::Fmt(".\\%s", ExeCmd.CStr()).CStr())==0) { return; }
00021   #else
00022   if (system(TStr::Fmt("./%s", ExeCmd.CStr()).CStr())==0) { return; }
00023   #endif
00024   if (system(TStr::Fmt("%s%s", GvPath.CStr(), ExeCmd.CStr()).CStr())==0) { return; }
00025   fprintf(stderr, "[%s:%d] Cat not find GraphViz (%s). Set the PATH.\n", __FILE__, __LINE__, ExeCmd.CStr());
00026   //#if defined(GLib_WIN)
00027   //if (ShowPlot) system(TStr::Fmt("start %s", OutFNm.CStr()).CStr());
00028   //#endif
00029 }
00030 
00031 TStr GVizGetLayoutStr(const TGVizLayout& Layout) {
00032   switch(Layout) {
00033     case gvlDot : return "dot";
00034     case gvlNeato : return "neato";
00035     case gvlTwopi : return "twopi";
00036     case gvlCirco: return "circo";
00037     default: Fail;
00038   }
00039   return TStr::GetNullStr();
00040 }
00041 
00042 } // namespace TSnapDetail
00043 } // namespace TSnap
00044