Home || SourceForge.net Project Page

mfGraph Library version 0.4.2 (May 20, 2006)

Copyright 2003-2006 Michael Fötsch

Homepage: http://mfgraph.sourceforge.net/

Mail: foetsch@users.sourceforge.net

Table of Contents

Revision History


mfGraph is distributed under the terms of the GNU Lesser General Public License.


To be able to build/run the mfGraph library and the demo applications, you might have to install additional software packages:

Build-Time Requirements:

Run-Time Requirements:

Build Instructions GNU/Linux

In the mfgraph-0.4 directory, run these shell commands:

mkdir build
cd build
make install

The following items will be installed:

To test the installation, try this:

Build Instructions Windows

I tested the Windows build with Microsoft Visual C++ 6.0 and Borland C++Builder 5.

If you need Flex/Bison (see Prerequisites), you can download them from here:

Microsoft Visual C++-Specific

  1. If you want/need to run Flex/Bison/SWIG, add the paths to flex.exe, bison.exe, and swig.exe in "Tools" -> "Options"

    • VC++ 6.0: "Tools" -> "Options" -> "Directories"

    • VS 2005: "Tools" -> "Options" -> "Projects and Solutions" -> "VC++ Directories"

    • See Prerequisites for information on how you can avoid having to run these tools.

  2. If you want to build the Python extension (contrib\windows_pymfg):

    1. Add the path to Python.h in "Tools" -> "Options" (typically C:\Python2x\include)

    2. Add the path to python2x.lib in "Tools" -> "Options" (typically C:\Python2x\libs)

  3. Open the workspace contrib\mfc_demo\mfc_demo.dsw (for VC++ 6.0) or mfc_demo.sln (for VS 2005) and build the project "mfc_demo".

    • This will also build the mfGraph static library in contrib\windows_lib

    • Run the application to test the library
    • /!\ VS 2005: If you are using VS 2005 Express and have no MFC, use the solution contrib\windows_lib\mfgraph_lib.sln instead. Sorry, no test application specifically for VS 2005.

  4. To build the Python extension:
    1. Open the workspace contrib\windows_pymfg\pymfg.dsw (for VC++ 6.0) or pymfg.sln (for VS 2005) and build the project "pymfg"

    2. To install the Python extension DLL, run "setup.py install" on the command prompt

    3. To test, run the Python demos:
      • contrib\pymfg_demo\pymfg_demo.py (requires wxPython!)

      • contrib\wx_graph_editor\wx_graph_editor.py (requires wxPython and the GraphViz package!)

Issues (mostly for package maintainers):

Borland C++Builder-Specific

Before you can build or run the mfGraph UI Sample Application (contrib\bcb_demo), you must

To build the mfGraphUI Sample Application:

  1. Open the project group contrib\bcb_demo\ProjectGroup1.bpg

  2. Build the project "mfgraph_lib"
  3. Build and install the package "mf"; new VCL components will be registered
  4. Build the project "mfgraphui"

To build the Python extension DLL:

  1. Convert the Python import library python23.lib (typically in C:\Python23\libs) to OMF format, e.g.:

    • > cd C:\Python23\libs
      > C:\Program Files\Borland\CBuilder5\bin\coff2omf.exe python23.lib python23_omf.lib
  2. Open the project group contrib\bcb_pymfg\ProjectGroup1.bpg

  3. If Python is not installed in C:\Python23 (for example, because you are using a different version), you will have to modify the paths in the Project Options accordingly

  4. If python23_omf.lib is not in C:\Python23\libs, remove python23_omf.lib from the project and re-add it from its actual location

  5. Build the project "_pymfg"
  6. To install the Python extension DLL, run "setup.py install" on the command prompt.


Programming Examples


(Those parts that make use of class mfg::GraphDrawer are specific to Microsoft Windows.)

This is a simple usage example to demonstrate

We would like to render the following graph:

    digraph G {
        a -> x [color=red]
        subgraph {
            b [style=filled fillcolor=green]
        a -> b

Step 1. Create a new application and either add mfgraph_lib.lib or add all CPP files in the mfGraph root directory.

Step 2. Create the graph using the mfg::DrawGraph class as follows:

   1     #include "mfg_draw_graph.h"
   2     #include "mfg_graph_drawer.h"
   3     using namespace mfg;
   4     ...
   5     DrawGraph g;
   6     Node* a = g.CreateNode();
   7     Node* x = g.CreateNode();
   8     Edge* ax = g.CreateEdge(a, x);
   9     ax->Attribs()["color"] = "red";
  10     Subgraph* s = g.CreateSubgraph();
  11     Node* b = g.CreateNode(s);
  12     b->Attribs()["style"] = "filled";
  13     b->Attribs()["fillcolor"] = "green";
  14     Edge* ab = g.CreateEdge(a, b);

Step 3. Write the graph to a DOT file on disk. (We could have written the DOT listing to a file directly, but it's more interesting this way.)

   1     #include <iostream>
   2     ...
   3     std::ofstream dot("temp.dot");
   4     g.PrintAsDot(dot);

Step 4. Have DOT.EXE convert the DOT listing to XDOT format. (This is the format that contains information about the graphic primitives such as ellipses and Bézier curves.)

   1     system("dot -Txdot -otemp.xdot temp.dot");
   2         // requires the GraphViz package

Step 5. Windows only*. Load the XDOT graph from the newly created file and have mfg::GraphDrawer render the graph:

   1     HDC hdc;    // assumed to contain a valid device context
   2     ...
   3     std::ifstream xdot("temp.xdot");
   4     g.LoadFromXdot(xdot);
   5     GraphDrawer::DrawGraph(hdc, &g);

Run the application.


This is a port of the preceding C++ example using the "pymfg" Python extension.

Step 1. Create the graph.

   1     from mfgraph import pymfg
   2     g = pymfg.DrawGraph()
   3     a = g.CreateNode()
   4     x = g.CreateNode()
   5     ax = g.CreateEdge(a, x)
   6     ax.Attribs()["color"] = "red"
   7     s = g.CreateSubgraph()
   8     b = g.CreateNode(s)
   9     b.Attribs()["style"] = "filled"
  10     b.Attribs()["fillcolor"] = "green"
  11     ab = g.CreateEdge(a, b)

Step 2. Write the graph to a DOT file on disk.

   1     dot = file("temp.dot", "w")
   2     dot.write(g.PrintAsDot())
   3     dot.close()

Step 3. Have DOT.EXE convert the DOT listing to XDOT format.

   1     import os
   2     ...
   3     os.system("dot -Txdot -otemp.xdot temp.dot")
   4         # requires the GraphViz package

Step 4. wxPython only. Load the XDOT graph from the newly created file and have mfgraph.graph_window.GraphWindow render the graph:

   1     from mfgraph.graph_window import GraphWindow
   2     import wx
   3     ...
   4     class MyFrame(wx.Frame):
   5         def __init__(self):
   6             wx.Frame.__init__(self, None, -1, "pymfg Example")
   7             graph_window = GraphWindow(self, -1, style=wx.SUNKEN_BORDER)
   8             graph_window.XdotListing = file("temp.xdot").read()
   9             graph_window.SetFocus()
  11     class MyApp(wx.PySimpleApp):
  12         def OnInit(self):
  13             frame = MyFrame()
  14             frame.Show()
  15             self.SetTopWindow(frame)
  16             return True
  18     app = MyApp()
  19     app.MainLoop()

You can click on objects to select them, Ctrl+click to select multiple objects. Press TAB to cycle through the objects. Press Numpad +/- to zoom.

mfGraph Editor (wx_graph_editor.py)

Before you can use the mfGraph Editor, you must

Run the application with "python wx_graph_editor.py" in the directory contrib/wx_graph_editor.

The menu and toolbar commands should be self-explaining. A few hints:

See also Known Issues for wx_graph_editor.py.

Known Issues

See also the Bug List on SF.net.


ReleaseNotes0.4.2 (last edited 2008-10-31 15:44:14 by localhost)

Copyright © 2003-2009 [WWW] Michael Fötsch. Visit [WWW] RealMike's Programming Resources.