GUI can now export graph to EPS.
authorhegyi
Tue, 27 Feb 2007 17:18:19 +0000
changeset 191af2ed974ab68
parent 190 2cac5b936a2b
child 192 9d7489e8921e
GUI can now export graph to EPS.
Makefile.am
all_include.h
icons/eps.png
main_win.cc
main_win.h
mapstorage.cc
mapstorage.h
nbtab.cc
nbtab.h
     1.1 --- a/Makefile.am	Tue Feb 20 17:45:44 2007 +0000
     1.2 +++ b/Makefile.am	Tue Feb 27 17:18:19 2007 +0000
     1.3 @@ -48,7 +48,9 @@
     1.4  	dijkstrabox.h \
     1.5  	dijkstrabox.cc \
     1.6  	background_chooser_dialog.h \
     1.7 -	background_chooser_dialog.cc
     1.8 +	background_chooser_dialog.cc \
     1.9 +	eps_win.h \
    1.10 +	eps_win.cc
    1.11  
    1.12  glemon_CXXFLAGS = $(GTK_CFLAGS) $(LEMON_CFLAGS)
    1.13  # glemon_LDFLAGS = $(GTK_LIBS) $(LEMON_LIBS)
     2.1 --- a/all_include.h	Tue Feb 20 17:45:44 2007 +0000
     2.2 +++ b/all_include.h	Tue Feb 27 17:18:19 2007 +0000
     2.3 @@ -34,6 +34,7 @@
     2.4  
     2.5  enum {E_WIDTH, E_COLOR, E_TEXT, EDGE_PROPERTY_NUM}; // edge properties;
     2.6  enum {N_RADIUS, N_COLOR, N_TEXT, NODE_PROPERTY_NUM}; // node properties;
     2.7 +enum {N_MAPS, E_MAPS, ARROWS, PAR, EPS_PROPERTY_NUM}; // eps properties;
     2.8  enum {MOVE, CREATE_NODE, CREATE_EDGE, ERASER, MAP_EDIT, TOOL_NUM}; // tools;
     2.9  #define RANGE 3
    2.10  #define WIN_WIDTH 900
     3.1 Binary file icons/eps.png has changed
     4.1 --- a/main_win.cc	Tue Feb 20 17:45:44 2007 +0000
     4.2 +++ b/main_win.cc	Tue Feb 27 17:18:19 2007 +0000
     4.3 @@ -48,6 +48,8 @@
     4.4        2328, gui_icons_editlink);
     4.5    Glib::RefPtr<Gdk::Pixbuf> p_newmap_pixbuf = Gdk::Pixbuf::create_from_inline(
     4.6        2328, gui_icons_newmap);
     4.7 +  Glib::RefPtr<Gdk::Pixbuf> p_eps_pixbuf = Gdk::Pixbuf::create_from_inline(
     4.8 +      2328, gui_icons_eps);
     4.9  
    4.10    Gtk::IconSource move_icon_source;
    4.11    move_icon_source.set_pixbuf(p_move_pixbuf);
    4.12 @@ -85,6 +87,12 @@
    4.13    newmap_icon_set.add_source(newmap_icon_source);
    4.14    p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set);
    4.15  
    4.16 +  Gtk::IconSource eps_icon_source;
    4.17 +  eps_icon_source.set_pixbuf(p_eps_pixbuf);
    4.18 +  Gtk::IconSet eps_icon_set;
    4.19 +  eps_icon_set.add_source(eps_icon_source);
    4.20 +  p_icon_factory->add(Gtk::StockID("gd-eps"), eps_icon_set);
    4.21 +
    4.22    p_icon_factory->add_default();
    4.23    
    4.24    ag=Gtk::ActionGroup::create();
    4.25 @@ -152,6 +160,9 @@
    4.26    ag->add( Gtk::Action::create("DesignGraph", Gtk::Stock::REFRESH),
    4.27        sigc::mem_fun ( *this , &MainWin::reDesignGraph ) );
    4.28  
    4.29 +  ag->add( Gtk::Action::create("Eps", Gtk::StockID("gd-eps")),
    4.30 +      sigc::mem_fun ( *this , &MainWin::exportToEPS ) );
    4.31 +
    4.32    uim=Gtk::UIManager::create();
    4.33    uim->insert_action_group(ag);
    4.34    add_accel_group(uim->get_accel_group());
    4.35 @@ -208,6 +219,7 @@
    4.36        "    <separator />"
    4.37        "    <toolitem action='AddMap' />"
    4.38        "    <toolitem action='DesignGraph' />"
    4.39 +      "    <toolitem action='Eps' />"
    4.40        "  </toolbar>"
    4.41        "</ui>";
    4.42  
    4.43 @@ -610,6 +622,14 @@
    4.44    tabs[active_tab]->reDesignGraph();
    4.45  }
    4.46  
    4.47 +void MainWin::exportToEPS()
    4.48 +{
    4.49 +  if(active_tab!=-1)
    4.50 +    {
    4.51 +      tabs[active_tab]->createExportToEPSWin(tabnames[active_tab]);
    4.52 +    }
    4.53 +}
    4.54 +
    4.55  void MainWin::createBackgroundChooser()
    4.56  {
    4.57    BackgroundChooserDialog dialog(&(tabs[active_tab]->mapstorage));
     5.1 --- a/main_win.h	Tue Feb 20 17:45:44 2007 +0000
     5.2 +++ b/main_win.h	Tue Feb 27 17:18:19 2007 +0000
     5.3 @@ -262,6 +262,8 @@
     5.4  
     5.5    virtual void reDesignGraph();
     5.6  
     5.7 +  virtual void exportToEPS();
     5.8 +
     5.9    void createBackgroundChooser();
    5.10  };
    5.11  
     6.1 --- a/mapstorage.cc	Tue Feb 20 17:45:44 2007 +0000
     6.2 +++ b/mapstorage.cc	Tue Feb 27 17:18:19 2007 +0000
     6.3 @@ -23,8 +23,9 @@
     6.4  #include <limits>
     6.5  #include <cmath>
     6.6  #include <gtkmm.h>
     6.7 +#include<lemon/graph_to_eps.h>
     6.8  
     6.9 -const double i_d=20;
    6.10 +const int i_d=20;
    6.11  const double a_d=0.05;
    6.12  const double p_d=40000;
    6.13  
    6.14 @@ -589,3 +590,74 @@
    6.15  {
    6.16    background_scaling = scaling;
    6.17  }
    6.18 +
    6.19 +void MapStorage::exportGraphToEPS(std::vector<bool> options, std::string filename)
    6.20 +{
    6.21 +  Graph::NodeMap<int> _nodeColors(graph, 0);
    6.22 +  Graph::EdgeMap<int> _edgeColors(graph, 0);
    6.23 +  Graph::NodeMap<double> _nodeSizes(graph, 6.0);
    6.24 +  Graph::EdgeMap<double> _edgeWidths(graph, 1.0);
    6.25 +  bool _drawArrows=options[ARROWS];
    6.26 +  bool _enableParallel=options[PAR];
    6.27 +
    6.28 +  std::string emptyString="";
    6.29 +  Graph::NodeMap<std::string> _nodeTextMap(graph,emptyString);
    6.30 +
    6.31 +  //_nodeTextMap=(Graph::NodeMap<void> *)&emptyStringMap;
    6.32 +
    6.33 +  if(options[N_MAPS])
    6.34 +    {
    6.35 +      if(active_nodemaps[N_RADIUS]!="")
    6.36 +	{
    6.37 +	  _nodeSizes=*(nodemap_storage[active_nodemaps[N_RADIUS]]);
    6.38 +	}
    6.39 +      if(active_nodemaps[N_COLOR]!="")
    6.40 +	{
    6.41 +	  for(NodeIt ni(graph);ni!=INVALID;++ni)
    6.42 +	    {
    6.43 +	      _nodeColors[ni]=(int)((*(nodemap_storage[active_nodemaps[N_COLOR]]))[ni]);
    6.44 +	    }
    6.45 +	}
    6.46 +      if(active_nodemaps[N_TEXT]!="")
    6.47 +	{
    6.48 +	  for(NodeIt ni(graph);ni!=INVALID;++ni)
    6.49 +	    {
    6.50 +	      std::ostringstream o;
    6.51 +	      o << ((*(nodemap_storage[active_nodemaps[N_TEXT]]))[ni]);
    6.52 +	      _nodeTextMap[ni]=o.str();	      
    6.53 +	    }
    6.54 +	}
    6.55 +    }
    6.56 +  if(options[E_MAPS])
    6.57 +    {
    6.58 +      if(active_edgemaps[E_WIDTH]!="")
    6.59 +	{
    6.60 +	  _edgeWidths=*(edgemap_storage[active_edgemaps[E_WIDTH]]);
    6.61 +	}
    6.62 +      if(active_edgemaps[E_COLOR]!="")
    6.63 +	{
    6.64 +	  for(EdgeIt ei(graph);ei!=INVALID;++ei)
    6.65 +	    {
    6.66 +	      _edgeColors[ei]=(int)((*(edgemap_storage[active_edgemaps[E_COLOR]]))[ei]);
    6.67 +	    }
    6.68 +	}
    6.69 +    }
    6.70 +
    6.71 +  Palette palette;
    6.72 +  Palette paletteW(true);
    6.73 +
    6.74 +  graphToEps(graph,filename).
    6.75 +    title("Sample .eps figure (fits to A4)").
    6.76 +    copyright("(C) 2006 LEMON Project").
    6.77 +    absoluteNodeSizes().absoluteEdgeWidths().
    6.78 +    nodeScale(2).nodeSizes(_nodeSizes).
    6.79 +    coords(coords).
    6.80 +    nodeColors(composeMap(paletteW,_nodeColors)).
    6.81 +    edgeColors(composeMap(palette,_edgeColors)).
    6.82 +    edgeWidthScale(0.3).edgeWidths(_edgeWidths).
    6.83 +    nodeTexts(_nodeTextMap).nodeTextSize(7).
    6.84 +    enableParallel(_enableParallel).parEdgeDist(4).
    6.85 +    drawArrows(_drawArrows).arrowWidth(7).arrowLength(7).
    6.86 +    run();
    6.87 +
    6.88 +}
     7.1 --- a/mapstorage.h	Tue Feb 20 17:45:44 2007 +0000
     7.2 +++ b/mapstorage.h	Tue Feb 27 17:18:19 2007 +0000
     7.3 @@ -291,6 +291,8 @@
     7.4    void set_iteration(int);
     7.5  
     7.6    void redesign_data_changed();
     7.7 +
     7.8 +  void exportGraphToEPS(std::vector<bool>, std::string);
     7.9  };
    7.10  
    7.11  #endif //MAPSTORAGE_H
     8.1 --- a/nbtab.cc	Tue Feb 20 17:45:44 2007 +0000
     8.2 +++ b/nbtab.cc	Tue Feb 27 17:18:19 2007 +0000
     8.3 @@ -17,6 +17,7 @@
     8.4   */
     8.5  
     8.6  #include <nbtab.h>
     8.7 +#include <eps_win.h>
     8.8  
     8.9  NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false), mapstorage(*this)
    8.10  {
    8.11 @@ -226,6 +227,17 @@
    8.12      }
    8.13  }
    8.14  
    8.15 +void NoteBookTab::createExportToEPSWin(std::string name)
    8.16 +{
    8.17 +  if(!epswinexists)
    8.18 +    {
    8.19 +      epswin=new EpsWin("Export to EPS - "+name, *this);
    8.20 +      epswin->show();
    8.21 +      epswinexists=true;
    8.22 +    }
    8.23 +}
    8.24 +
    8.25 +
    8.26  void NoteBookTab::createDesignWin(std::string name)
    8.27  {
    8.28    if(!designwinexists)
    8.29 @@ -256,6 +268,12 @@
    8.30    delete mapwin;
    8.31  }
    8.32  
    8.33 +void NoteBookTab::closeEpsWin()
    8.34 +{
    8.35 +  epswinexists=false;
    8.36 +  delete epswin;
    8.37 +}
    8.38 +
    8.39  bool NoteBookTab::closeDesignWin(GdkEventAny * e)
    8.40  {
    8.41    if(e->type==GDK_DELETE)
    8.42 @@ -290,3 +308,8 @@
    8.43  {
    8.44    mapstorage.broadcastActiveMaps();
    8.45  }
    8.46 +
    8.47 +void NoteBookTab::exportGraphToEPS(std::vector<bool> options, std::string filename)
    8.48 +{
    8.49 +  mapstorage.exportGraphToEPS(options, filename);
    8.50 +}
     9.1 --- a/nbtab.h	Tue Feb 20 17:45:44 2007 +0000
     9.2 +++ b/nbtab.h	Tue Feb 27 17:18:19 2007 +0000
     9.3 @@ -23,6 +23,8 @@
     9.4  
     9.5  #include "mapstorage.h"
     9.6  #include "map_win.h"
     9.7 +//#include "eps_win.h"
     9.8 +class EpsWin;
     9.9  #include "design_win.h"
    9.10  #include "graph_displayer_canvas.h"
    9.11  #include <libgnomecanvasmm.h>
    9.12 @@ -97,6 +99,9 @@
    9.13    ///Indicates whether the \ref DesignWin is opened or not. See \ref designwin.
    9.14    bool designwinexists;
    9.15  
    9.16 +  ///Indicates whether the \ref EpsWin is opened or not. See \ref epswin.
    9.17 +  bool epswinexists;
    9.18 +
    9.19    ///Address of the only \ref MapWin that the \ref NoteBookTab can open.
    9.20  
    9.21    ///Only one of this window can be opened at the same time (\ref mapwinexists), 
    9.22 @@ -113,6 +118,13 @@
    9.23    ///more complicated to synchronize them.
    9.24    DesignWin * designwin;
    9.25  
    9.26 +  ///Address of the only \ref EpsWin that the \ref NoteBookTab can open.
    9.27 +
    9.28 +  ///Only one of this window can be opened at the same time (\ref epswinexists), 
    9.29 +  ///because there is no need for more, one per tab is enough.
    9.30 +  ///There won't be benefit of more than one.
    9.31 +  EpsWin * epswin;
    9.32 +
    9.33  public:
    9.34    ///Callback for 'FileNew' action.
    9.35    virtual void newFile();
    9.36 @@ -185,14 +197,29 @@
    9.37    ///\ref mapwin.
    9.38    void createDesignWin(std::string);
    9.39  
    9.40 +  ///Pops up a window, that can dump graph to EPS
    9.41 +
    9.42 +  ///Different parameters can be set here.
    9.43 +  void createExportToEPSWin(std::string);
    9.44 +
    9.45    ///Closes and deregistrates the \ref MapWin of \ref NoteBookTab.
    9.46    
    9.47    ///See also
    9.48    ///\ref mapwin.
    9.49    void closeMapWin();
    9.50  
    9.51 +  ///Closes and deregistrates the \ref DesignWin of \ref NoteBookTab.
    9.52 +  
    9.53 +  ///See also
    9.54 +  ///\ref designwin.
    9.55    bool closeDesignWin(GdkEventAny *);
    9.56  
    9.57 +  ///Closes and deregistrates the \ref EpsWin of \ref NoteBookTab.
    9.58 +  
    9.59 +  ///See also
    9.60 +  ///\ref epswin.
    9.61 +  void closeEpsWin();
    9.62 +
    9.63    ///Sets node representation settings
    9.64    void setView(bool, bool, double, double);
    9.65  
    9.66 @@ -202,6 +229,9 @@
    9.67    ///Let the graph redesign, based on gravity and edge elasticity.
    9.68    void reDesignGraph();
    9.69  
    9.70 +  ///Lets Mapstorage export the graph to EPS
    9.71 +  void exportGraphToEPS(std::vector<bool>, std::string);
    9.72 +
    9.73    ///\ref MapWin calls this function when it updates the maplist in comboboxes.
    9.74    void active_maps_needed();
    9.75