COIN-OR::LEMON - Graph Library

Changeset 191:af2ed974ab68 in glemon-0.x


Ignore:
Timestamp:
02/27/07 18:18:19 (13 years ago)
Author:
Hegyi Péter
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@3202
Message:

GUI can now export graph to EPS.

Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    r186 r191  
    4949        dijkstrabox.cc \
    5050        background_chooser_dialog.h \
    51         background_chooser_dialog.cc
     51        background_chooser_dialog.cc \
     52        eps_win.h \
     53        eps_win.cc
    5254
    5355glemon_CXXFLAGS = $(GTK_CFLAGS) $(LEMON_CFLAGS)
  • all_include.h

    r174 r191  
    3535enum {E_WIDTH, E_COLOR, E_TEXT, EDGE_PROPERTY_NUM}; // edge properties;
    3636enum {N_RADIUS, N_COLOR, N_TEXT, NODE_PROPERTY_NUM}; // node properties;
     37enum {N_MAPS, E_MAPS, ARROWS, PAR, EPS_PROPERTY_NUM}; // eps properties;
    3738enum {MOVE, CREATE_NODE, CREATE_EDGE, ERASER, MAP_EDIT, TOOL_NUM}; // tools;
    3839#define RANGE 3
  • main_win.cc

    r190 r191  
    4949  Glib::RefPtr<Gdk::Pixbuf> p_newmap_pixbuf = Gdk::Pixbuf::create_from_inline(
    5050      2328, gui_icons_newmap);
     51  Glib::RefPtr<Gdk::Pixbuf> p_eps_pixbuf = Gdk::Pixbuf::create_from_inline(
     52      2328, gui_icons_eps);
    5153
    5254  Gtk::IconSource move_icon_source;
     
    8587  newmap_icon_set.add_source(newmap_icon_source);
    8688  p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set);
     89
     90  Gtk::IconSource eps_icon_source;
     91  eps_icon_source.set_pixbuf(p_eps_pixbuf);
     92  Gtk::IconSet eps_icon_set;
     93  eps_icon_set.add_source(eps_icon_source);
     94  p_icon_factory->add(Gtk::StockID("gd-eps"), eps_icon_set);
    8795
    8896  p_icon_factory->add_default();
     
    152160  ag->add( Gtk::Action::create("DesignGraph", Gtk::Stock::REFRESH),
    153161      sigc::mem_fun ( *this , &MainWin::reDesignGraph ) );
     162
     163  ag->add( Gtk::Action::create("Eps", Gtk::StockID("gd-eps")),
     164      sigc::mem_fun ( *this , &MainWin::exportToEPS ) );
    154165
    155166  uim=Gtk::UIManager::create();
     
    209220      "    <toolitem action='AddMap' />"
    210221      "    <toolitem action='DesignGraph' />"
     222      "    <toolitem action='Eps' />"
    211223      "  </toolbar>"
    212224      "</ui>";
     
    611623}
    612624
     625void MainWin::exportToEPS()
     626{
     627  if(active_tab!=-1)
     628    {
     629      tabs[active_tab]->createExportToEPSWin(tabnames[active_tab]);
     630    }
     631}
     632
    613633void MainWin::createBackgroundChooser()
    614634{
  • main_win.h

    r190 r191  
    263263  virtual void reDesignGraph();
    264264
     265  virtual void exportToEPS();
     266
    265267  void createBackgroundChooser();
    266268};
  • mapstorage.cc

    r184 r191  
    2424#include <cmath>
    2525#include <gtkmm.h>
    26 
    27 const double i_d=20;
     26#include<lemon/graph_to_eps.h>
     27
     28const int i_d=20;
    2829const double a_d=0.05;
    2930const double p_d=40000;
     
    590591  background_scaling = scaling;
    591592}
     593
     594void MapStorage::exportGraphToEPS(std::vector<bool> options, std::string filename)
     595{
     596  Graph::NodeMap<int> _nodeColors(graph, 0);
     597  Graph::EdgeMap<int> _edgeColors(graph, 0);
     598  Graph::NodeMap<double> _nodeSizes(graph, 6.0);
     599  Graph::EdgeMap<double> _edgeWidths(graph, 1.0);
     600  bool _drawArrows=options[ARROWS];
     601  bool _enableParallel=options[PAR];
     602
     603  std::string emptyString="";
     604  Graph::NodeMap<std::string> _nodeTextMap(graph,emptyString);
     605
     606  //_nodeTextMap=(Graph::NodeMap<void> *)&emptyStringMap;
     607
     608  if(options[N_MAPS])
     609    {
     610      if(active_nodemaps[N_RADIUS]!="")
     611        {
     612          _nodeSizes=*(nodemap_storage[active_nodemaps[N_RADIUS]]);
     613        }
     614      if(active_nodemaps[N_COLOR]!="")
     615        {
     616          for(NodeIt ni(graph);ni!=INVALID;++ni)
     617            {
     618              _nodeColors[ni]=(int)((*(nodemap_storage[active_nodemaps[N_COLOR]]))[ni]);
     619            }
     620        }
     621      if(active_nodemaps[N_TEXT]!="")
     622        {
     623          for(NodeIt ni(graph);ni!=INVALID;++ni)
     624            {
     625              std::ostringstream o;
     626              o << ((*(nodemap_storage[active_nodemaps[N_TEXT]]))[ni]);
     627              _nodeTextMap[ni]=o.str();       
     628            }
     629        }
     630    }
     631  if(options[E_MAPS])
     632    {
     633      if(active_edgemaps[E_WIDTH]!="")
     634        {
     635          _edgeWidths=*(edgemap_storage[active_edgemaps[E_WIDTH]]);
     636        }
     637      if(active_edgemaps[E_COLOR]!="")
     638        {
     639          for(EdgeIt ei(graph);ei!=INVALID;++ei)
     640            {
     641              _edgeColors[ei]=(int)((*(edgemap_storage[active_edgemaps[E_COLOR]]))[ei]);
     642            }
     643        }
     644    }
     645
     646  Palette palette;
     647  Palette paletteW(true);
     648
     649  graphToEps(graph,filename).
     650    title("Sample .eps figure (fits to A4)").
     651    copyright("(C) 2006 LEMON Project").
     652    absoluteNodeSizes().absoluteEdgeWidths().
     653    nodeScale(2).nodeSizes(_nodeSizes).
     654    coords(coords).
     655    nodeColors(composeMap(paletteW,_nodeColors)).
     656    edgeColors(composeMap(palette,_edgeColors)).
     657    edgeWidthScale(0.3).edgeWidths(_edgeWidths).
     658    nodeTexts(_nodeTextMap).nodeTextSize(7).
     659    enableParallel(_enableParallel).parEdgeDist(4).
     660    drawArrows(_drawArrows).arrowWidth(7).arrowLength(7).
     661    run();
     662
     663}
  • mapstorage.h

    r184 r191  
    292292
    293293  void redesign_data_changed();
     294
     295  void exportGraphToEPS(std::vector<bool>, std::string);
    294296};
    295297
  • nbtab.cc

    r186 r191  
    1818
    1919#include <nbtab.h>
     20#include <eps_win.h>
    2021
    2122NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false), mapstorage(*this)
     
    227228}
    228229
     230void NoteBookTab::createExportToEPSWin(std::string name)
     231{
     232  if(!epswinexists)
     233    {
     234      epswin=new EpsWin("Export to EPS - "+name, *this);
     235      epswin->show();
     236      epswinexists=true;
     237    }
     238}
     239
     240
    229241void NoteBookTab::createDesignWin(std::string name)
    230242{
     
    257269}
    258270
     271void NoteBookTab::closeEpsWin()
     272{
     273  epswinexists=false;
     274  delete epswin;
     275}
     276
    259277bool NoteBookTab::closeDesignWin(GdkEventAny * e)
    260278{
     
    291309  mapstorage.broadcastActiveMaps();
    292310}
     311
     312void NoteBookTab::exportGraphToEPS(std::vector<bool> options, std::string filename)
     313{
     314  mapstorage.exportGraphToEPS(options, filename);
     315}
  • nbtab.h

    r177 r191  
    2424#include "mapstorage.h"
    2525#include "map_win.h"
     26//#include "eps_win.h"
     27class EpsWin;
    2628#include "design_win.h"
    2729#include "graph_displayer_canvas.h"
     
    98100  bool designwinexists;
    99101
     102  ///Indicates whether the \ref EpsWin is opened or not. See \ref epswin.
     103  bool epswinexists;
     104
    100105  ///Address of the only \ref MapWin that the \ref NoteBookTab can open.
    101106
     
    113118  ///more complicated to synchronize them.
    114119  DesignWin * designwin;
     120
     121  ///Address of the only \ref EpsWin that the \ref NoteBookTab can open.
     122
     123  ///Only one of this window can be opened at the same time (\ref epswinexists),
     124  ///because there is no need for more, one per tab is enough.
     125  ///There won't be benefit of more than one.
     126  EpsWin * epswin;
    115127
    116128public:
     
    186198  void createDesignWin(std::string);
    187199
     200  ///Pops up a window, that can dump graph to EPS
     201
     202  ///Different parameters can be set here.
     203  void createExportToEPSWin(std::string);
     204
    188205  ///Closes and deregistrates the \ref MapWin of \ref NoteBookTab.
    189206 
     
    192209  void closeMapWin();
    193210
     211  ///Closes and deregistrates the \ref DesignWin of \ref NoteBookTab.
     212 
     213  ///See also
     214  ///\ref designwin.
    194215  bool closeDesignWin(GdkEventAny *);
     216
     217  ///Closes and deregistrates the \ref EpsWin of \ref NoteBookTab.
     218 
     219  ///See also
     220  ///\ref epswin.
     221  void closeEpsWin();
    195222
    196223  ///Sets node representation settings
     
    202229  ///Let the graph redesign, based on gravity and edge elasticity.
    203230  void reDesignGraph();
     231
     232  ///Lets Mapstorage export the graph to EPS
     233  void exportGraphToEPS(std::vector<bool>, std::string);
    204234
    205235  ///\ref MapWin calls this function when it updates the maplist in comboboxes.
Note: See TracChangeset for help on using the changeset viewer.