# HG changeset patch # User hegyi # Date 1172596699 0 # Node ID af2ed974ab68e978f7a5df0337d82c005aa868da # Parent 2cac5b936a2b6f0b244b27d246b6bdc4c95d5125 GUI can now export graph to EPS. diff -r 2cac5b936a2b -r af2ed974ab68 Makefile.am --- a/Makefile.am Tue Feb 20 17:45:44 2007 +0000 +++ b/Makefile.am Tue Feb 27 17:18:19 2007 +0000 @@ -48,7 +48,9 @@ dijkstrabox.h \ dijkstrabox.cc \ background_chooser_dialog.h \ - background_chooser_dialog.cc + background_chooser_dialog.cc \ + eps_win.h \ + eps_win.cc glemon_CXXFLAGS = $(GTK_CFLAGS) $(LEMON_CFLAGS) # glemon_LDFLAGS = $(GTK_LIBS) $(LEMON_LIBS) diff -r 2cac5b936a2b -r af2ed974ab68 all_include.h --- a/all_include.h Tue Feb 20 17:45:44 2007 +0000 +++ b/all_include.h Tue Feb 27 17:18:19 2007 +0000 @@ -34,6 +34,7 @@ enum {E_WIDTH, E_COLOR, E_TEXT, EDGE_PROPERTY_NUM}; // edge properties; enum {N_RADIUS, N_COLOR, N_TEXT, NODE_PROPERTY_NUM}; // node properties; +enum {N_MAPS, E_MAPS, ARROWS, PAR, EPS_PROPERTY_NUM}; // eps properties; enum {MOVE, CREATE_NODE, CREATE_EDGE, ERASER, MAP_EDIT, TOOL_NUM}; // tools; #define RANGE 3 #define WIN_WIDTH 900 diff -r 2cac5b936a2b -r af2ed974ab68 icons/eps.png Binary file icons/eps.png has changed diff -r 2cac5b936a2b -r af2ed974ab68 main_win.cc --- a/main_win.cc Tue Feb 20 17:45:44 2007 +0000 +++ b/main_win.cc Tue Feb 27 17:18:19 2007 +0000 @@ -48,6 +48,8 @@ 2328, gui_icons_editlink); Glib::RefPtr p_newmap_pixbuf = Gdk::Pixbuf::create_from_inline( 2328, gui_icons_newmap); + Glib::RefPtr p_eps_pixbuf = Gdk::Pixbuf::create_from_inline( + 2328, gui_icons_eps); Gtk::IconSource move_icon_source; move_icon_source.set_pixbuf(p_move_pixbuf); @@ -85,6 +87,12 @@ newmap_icon_set.add_source(newmap_icon_source); p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set); + Gtk::IconSource eps_icon_source; + eps_icon_source.set_pixbuf(p_eps_pixbuf); + Gtk::IconSet eps_icon_set; + eps_icon_set.add_source(eps_icon_source); + p_icon_factory->add(Gtk::StockID("gd-eps"), eps_icon_set); + p_icon_factory->add_default(); ag=Gtk::ActionGroup::create(); @@ -152,6 +160,9 @@ ag->add( Gtk::Action::create("DesignGraph", Gtk::Stock::REFRESH), sigc::mem_fun ( *this , &MainWin::reDesignGraph ) ); + ag->add( Gtk::Action::create("Eps", Gtk::StockID("gd-eps")), + sigc::mem_fun ( *this , &MainWin::exportToEPS ) ); + uim=Gtk::UIManager::create(); uim->insert_action_group(ag); add_accel_group(uim->get_accel_group()); @@ -208,6 +219,7 @@ " " " " " " + " " " " ""; @@ -610,6 +622,14 @@ tabs[active_tab]->reDesignGraph(); } +void MainWin::exportToEPS() +{ + if(active_tab!=-1) + { + tabs[active_tab]->createExportToEPSWin(tabnames[active_tab]); + } +} + void MainWin::createBackgroundChooser() { BackgroundChooserDialog dialog(&(tabs[active_tab]->mapstorage)); diff -r 2cac5b936a2b -r af2ed974ab68 main_win.h --- a/main_win.h Tue Feb 20 17:45:44 2007 +0000 +++ b/main_win.h Tue Feb 27 17:18:19 2007 +0000 @@ -262,6 +262,8 @@ virtual void reDesignGraph(); + virtual void exportToEPS(); + void createBackgroundChooser(); }; diff -r 2cac5b936a2b -r af2ed974ab68 mapstorage.cc --- a/mapstorage.cc Tue Feb 20 17:45:44 2007 +0000 +++ b/mapstorage.cc Tue Feb 27 17:18:19 2007 +0000 @@ -23,8 +23,9 @@ #include #include #include +#include -const double i_d=20; +const int i_d=20; const double a_d=0.05; const double p_d=40000; @@ -589,3 +590,74 @@ { background_scaling = scaling; } + +void MapStorage::exportGraphToEPS(std::vector options, std::string filename) +{ + Graph::NodeMap _nodeColors(graph, 0); + Graph::EdgeMap _edgeColors(graph, 0); + Graph::NodeMap _nodeSizes(graph, 6.0); + Graph::EdgeMap _edgeWidths(graph, 1.0); + bool _drawArrows=options[ARROWS]; + bool _enableParallel=options[PAR]; + + std::string emptyString=""; + Graph::NodeMap _nodeTextMap(graph,emptyString); + + //_nodeTextMap=(Graph::NodeMap *)&emptyStringMap; + + if(options[N_MAPS]) + { + if(active_nodemaps[N_RADIUS]!="") + { + _nodeSizes=*(nodemap_storage[active_nodemaps[N_RADIUS]]); + } + if(active_nodemaps[N_COLOR]!="") + { + for(NodeIt ni(graph);ni!=INVALID;++ni) + { + _nodeColors[ni]=(int)((*(nodemap_storage[active_nodemaps[N_COLOR]]))[ni]); + } + } + if(active_nodemaps[N_TEXT]!="") + { + for(NodeIt ni(graph);ni!=INVALID;++ni) + { + std::ostringstream o; + o << ((*(nodemap_storage[active_nodemaps[N_TEXT]]))[ni]); + _nodeTextMap[ni]=o.str(); + } + } + } + if(options[E_MAPS]) + { + if(active_edgemaps[E_WIDTH]!="") + { + _edgeWidths=*(edgemap_storage[active_edgemaps[E_WIDTH]]); + } + if(active_edgemaps[E_COLOR]!="") + { + for(EdgeIt ei(graph);ei!=INVALID;++ei) + { + _edgeColors[ei]=(int)((*(edgemap_storage[active_edgemaps[E_COLOR]]))[ei]); + } + } + } + + Palette palette; + Palette paletteW(true); + + graphToEps(graph,filename). + title("Sample .eps figure (fits to A4)"). + copyright("(C) 2006 LEMON Project"). + absoluteNodeSizes().absoluteEdgeWidths(). + nodeScale(2).nodeSizes(_nodeSizes). + coords(coords). + nodeColors(composeMap(paletteW,_nodeColors)). + edgeColors(composeMap(palette,_edgeColors)). + edgeWidthScale(0.3).edgeWidths(_edgeWidths). + nodeTexts(_nodeTextMap).nodeTextSize(7). + enableParallel(_enableParallel).parEdgeDist(4). + drawArrows(_drawArrows).arrowWidth(7).arrowLength(7). + run(); + +} diff -r 2cac5b936a2b -r af2ed974ab68 mapstorage.h --- a/mapstorage.h Tue Feb 20 17:45:44 2007 +0000 +++ b/mapstorage.h Tue Feb 27 17:18:19 2007 +0000 @@ -291,6 +291,8 @@ void set_iteration(int); void redesign_data_changed(); + + void exportGraphToEPS(std::vector, std::string); }; #endif //MAPSTORAGE_H diff -r 2cac5b936a2b -r af2ed974ab68 nbtab.cc --- a/nbtab.cc Tue Feb 20 17:45:44 2007 +0000 +++ b/nbtab.cc Tue Feb 27 17:18:19 2007 +0000 @@ -17,6 +17,7 @@ */ #include +#include NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false), mapstorage(*this) { @@ -226,6 +227,17 @@ } } +void NoteBookTab::createExportToEPSWin(std::string name) +{ + if(!epswinexists) + { + epswin=new EpsWin("Export to EPS - "+name, *this); + epswin->show(); + epswinexists=true; + } +} + + void NoteBookTab::createDesignWin(std::string name) { if(!designwinexists) @@ -256,6 +268,12 @@ delete mapwin; } +void NoteBookTab::closeEpsWin() +{ + epswinexists=false; + delete epswin; +} + bool NoteBookTab::closeDesignWin(GdkEventAny * e) { if(e->type==GDK_DELETE) @@ -290,3 +308,8 @@ { mapstorage.broadcastActiveMaps(); } + +void NoteBookTab::exportGraphToEPS(std::vector options, std::string filename) +{ + mapstorage.exportGraphToEPS(options, filename); +} diff -r 2cac5b936a2b -r af2ed974ab68 nbtab.h --- a/nbtab.h Tue Feb 20 17:45:44 2007 +0000 +++ b/nbtab.h Tue Feb 27 17:18:19 2007 +0000 @@ -23,6 +23,8 @@ #include "mapstorage.h" #include "map_win.h" +//#include "eps_win.h" +class EpsWin; #include "design_win.h" #include "graph_displayer_canvas.h" #include @@ -97,6 +99,9 @@ ///Indicates whether the \ref DesignWin is opened or not. See \ref designwin. bool designwinexists; + ///Indicates whether the \ref EpsWin is opened or not. See \ref epswin. + bool epswinexists; + ///Address of the only \ref MapWin that the \ref NoteBookTab can open. ///Only one of this window can be opened at the same time (\ref mapwinexists), @@ -113,6 +118,13 @@ ///more complicated to synchronize them. DesignWin * designwin; + ///Address of the only \ref EpsWin that the \ref NoteBookTab can open. + + ///Only one of this window can be opened at the same time (\ref epswinexists), + ///because there is no need for more, one per tab is enough. + ///There won't be benefit of more than one. + EpsWin * epswin; + public: ///Callback for 'FileNew' action. virtual void newFile(); @@ -185,14 +197,29 @@ ///\ref mapwin. void createDesignWin(std::string); + ///Pops up a window, that can dump graph to EPS + + ///Different parameters can be set here. + void createExportToEPSWin(std::string); + ///Closes and deregistrates the \ref MapWin of \ref NoteBookTab. ///See also ///\ref mapwin. void closeMapWin(); + ///Closes and deregistrates the \ref DesignWin of \ref NoteBookTab. + + ///See also + ///\ref designwin. bool closeDesignWin(GdkEventAny *); + ///Closes and deregistrates the \ref EpsWin of \ref NoteBookTab. + + ///See also + ///\ref epswin. + void closeEpsWin(); + ///Sets node representation settings void setView(bool, bool, double, double); @@ -202,6 +229,9 @@ ///Let the graph redesign, based on gravity and edge elasticity. void reDesignGraph(); + ///Lets Mapstorage export the graph to EPS + void exportGraphToEPS(std::vector, std::string); + ///\ref MapWin calls this function when it updates the maplist in comboboxes. void active_maps_needed();