Added support for setting the background form an image file.
1.1 --- a/Makefile.am Thu Dec 28 15:31:39 2006 +0000
1.2 +++ b/Makefile.am Wed Jan 10 14:37:46 2007 +0000
1.3 @@ -49,8 +49,8 @@
1.4 dijkstrabox.cc \
1.5 file_chooser_extra_widget.h \
1.6 file_chooser_extra_widget.cc \
1.7 - map_window.h \
1.8 - map_window.cc
1.9 + background_chooser_dialog.h \
1.10 + background_chooser_dialog.cc
1.11
1.12 glemon_CXXFLAGS = $(GTK_CFLAGS) $(LEMON_CFLAGS)
1.13 # glemon_LDFLAGS = $(GTK_LIBS) $(LEMON_LIBS)
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/background_chooser_dialog.cc Wed Jan 10 14:37:46 2007 +0000
2.3 @@ -0,0 +1,52 @@
2.4 +#include "background_chooser_dialog.h"
2.5 +#include <gtkmm/stock.h>
2.6 +#include "mapstorage.h"
2.7 +
2.8 +BackgroundChooserDialog::BackgroundChooserDialog(MapStorage* ms) :
2.9 + mapstorage(ms),
2.10 + btnClear(Gtk::Stock::CLEAR)
2.11 +{
2.12 + set_has_separator(false);
2.13 +
2.14 + Gtk::VBox* pVBox = get_vbox();
2.15 +
2.16 + lblBackground.set_text("<b>Background image file</b>");
2.17 + lblBackground.set_use_markup();
2.18 + lblBackground.set_alignment(Gtk::ALIGN_LEFT);
2.19 + lblScaling.set_text("<b>Scaling factor</b>");
2.20 + lblScaling.set_use_markup();
2.21 + lblScaling.set_alignment(Gtk::ALIGN_LEFT);
2.22 + fcbBackground.set_width_chars(30);
2.23 + fcbBackground.set_action(Gtk::FILE_CHOOSER_ACTION_OPEN);
2.24 + if (mapstorage->isBackgroundSet())
2.25 + {
2.26 + fcbBackground.set_filename(mapstorage->getBackgroundFilename());
2.27 + }
2.28 +
2.29 + fcbBackground.signal_selection_changed().connect(
2.30 + sigc::mem_fun(*this, &BackgroundChooserDialog::setBackground));
2.31 +
2.32 + btnClear.signal_clicked().connect(
2.33 + sigc::mem_fun(*this, &BackgroundChooserDialog::clearBackground));
2.34 +
2.35 + pVBox->pack_start(lblBackground, Gtk::PACK_SHRINK);
2.36 + pVBox->pack_start(box, Gtk::PACK_SHRINK);
2.37 + box.pack_start(fcbBackground, Gtk::PACK_EXPAND_WIDGET);
2.38 + box.pack_start(btnClear, Gtk::PACK_SHRINK);
2.39 + pVBox->pack_start(lblScaling, Gtk::PACK_SHRINK);
2.40 + pVBox->pack_start(sbScaling, Gtk::PACK_SHRINK);
2.41 +
2.42 + add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);
2.43 +
2.44 + show_all_children();
2.45 +}
2.46 +
2.47 +void BackgroundChooserDialog::clearBackground()
2.48 +{
2.49 + fcbBackground.unselect_all();
2.50 +}
2.51 +
2.52 +void BackgroundChooserDialog::setBackground()
2.53 +{
2.54 + mapstorage->setBackground(fcbBackground.get_filename());
2.55 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/background_chooser_dialog.h Wed Jan 10 14:37:46 2007 +0000
3.3 @@ -0,0 +1,27 @@
3.4 +#ifndef BACKGROUND_CHOOSER_DIALOG
3.5 +#define BACKGROUND_CHOOSER_DIALOG
3.6 +
3.7 +#include <gtkmm/dialog.h>
3.8 +#include <gtkmm/label.h>
3.9 +#include <gtkmm/filechooserbutton.h>
3.10 +#include <gtkmm/spinbutton.h>
3.11 +
3.12 +class MapStorage;
3.13 +
3.14 +class BackgroundChooserDialog : public Gtk::Dialog
3.15 +{
3.16 + private:
3.17 + MapStorage* mapstorage;
3.18 + Gtk::Label lblBackground;
3.19 + Gtk::Label lblScaling;
3.20 + Gtk::FileChooserButton fcbBackground;
3.21 + Gtk::SpinButton sbScaling;
3.22 + Gtk::HBox box;
3.23 + Gtk::Button btnClear;
3.24 + void clearBackground();
3.25 + void setBackground();
3.26 + public:
3.27 + BackgroundChooserDialog(MapStorage* ms);
3.28 +};
3.29 +
3.30 +#endif
4.1 --- a/graph_displayer_canvas.cc Thu Dec 28 15:31:39 2006 +0000
4.2 +++ b/graph_displayer_canvas.cc Wed Jan 10 14:37:46 2007 +0000
4.3 @@ -25,7 +25,8 @@
4.4 nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0),
4.5 isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
4.6 edgemap_to_edit(""), autoscale(true), zoomtrack(false), radius_size(20), edge_width(10),
4.7 - was_redesigned(false), is_drawn(false), mytab(mainw)
4.8 + was_redesigned(false), is_drawn(false), mytab(mainw),
4.9 + background_set(false)
4.10 {
4.11 //base event handler is move tool
4.12 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
4.13 @@ -34,6 +35,32 @@
4.14 active_node=INVALID;
4.15 active_edge=INVALID;
4.16 forming_edge=INVALID;
4.17 +
4.18 + setBackground();
4.19 +}
4.20 +
4.21 +void GraphDisplayerCanvas::setBackground()
4.22 +{
4.23 + if (background_set)
4.24 + {
4.25 + delete background;
4.26 + }
4.27 + if (mytab.mapstorage.isBackgroundSet())
4.28 + {
4.29 + background_set = true;
4.30 + refBackground = Gdk::Pixbuf::create_from_file(
4.31 + mytab.mapstorage.getBackgroundFilename());
4.32 + background = new Gnome::Canvas::Pixbuf(
4.33 + *(root()),
4.34 + 0.0 - refBackground->get_width() / 2.0,
4.35 + 0.0 - refBackground->get_height() / 2.0,
4.36 + refBackground);
4.37 + background->lower_to_bottom();
4.38 + }
4.39 + else
4.40 + {
4.41 + background_set = false;
4.42 + }
4.43 }
4.44
4.45 GraphDisplayerCanvas::~GraphDisplayerCanvas()
5.1 --- a/graph_displayer_canvas.h Thu Dec 28 15:31:39 2006 +0000
5.2 +++ b/graph_displayer_canvas.h Wed Jan 10 14:37:46 2007 +0000
5.3 @@ -441,6 +441,12 @@
5.4 NoteBookTab & mytab;
5.5
5.6 XY calcArrowPos(XY, XY, XY, XY, int);
5.7 +
5.8 + bool background_set;
5.9 + Glib::RefPtr<Gdk::Pixbuf> refBackground;
5.10 + Gnome::Canvas::Pixbuf *background;
5.11 +public:
5.12 + void setBackground();
5.13 };
5.14
5.15 #endif //GRAPH_DISPLAYER_CANVAS_H
6.1 --- a/main_win.cc Thu Dec 28 15:31:39 2006 +0000
6.2 +++ b/main_win.cc Wed Jan 10 14:37:46 2007 +0000
6.3 @@ -22,6 +22,7 @@
6.4
6.5 #include "main_win.h"
6.6 #include "guipixbufs.h"
6.7 +#include "background_chooser_dialog.h"
6.8
6.9 #include "i18n.h"
6.10
6.11 @@ -113,6 +114,8 @@
6.12 sigc::mem_fun(*this, &MainWin::zoomFit));
6.13 ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
6.14 sigc::mem_fun(*this, &MainWin::zoom100));
6.15 + ag->add( Gtk::Action::create("SetBackground", _("Set Background...")),
6.16 + sigc::mem_fun(*this, &MainWin::createBackgroundChooser));
6.17
6.18 ag->add( Gtk::Action::create("ShowMenu", _("_Show")) );
6.19 ag->add( Gtk::Action::create("ShowMaps", _("_Maps")),
6.20 @@ -173,6 +176,7 @@
6.21 " <menuitem action='ViewZoomOut' />"
6.22 " <menuitem action='ViewZoom100' />"
6.23 " <menuitem action='ViewZoomFit' />"
6.24 + " <menuitem action='SetBackground' />"
6.25 " </menu>"
6.26 " <menu action='ShowMenu'>"
6.27 " <menuitem action='ShowMaps'/>"
6.28 @@ -580,3 +584,9 @@
6.29 {
6.30 tabs[active_tab]->reDesignGraph();
6.31 }
6.32 +
6.33 +void MainWin::createBackgroundChooser()
6.34 +{
6.35 + BackgroundChooserDialog dialog(&(tabs[active_tab]->mapstorage));
6.36 + dialog.run();
6.37 +}
7.1 --- a/main_win.h Thu Dec 28 15:31:39 2006 +0000
7.2 +++ b/main_win.h Wed Jan 10 14:37:46 2007 +0000
7.3 @@ -261,6 +261,8 @@
7.4 virtual void nodeViewChanged();
7.5
7.6 virtual void reDesignGraph();
7.7 +
7.8 + void createBackgroundChooser();
7.9 };
7.10
7.11 #endif //MAIN_WIN_H
8.1 --- a/map_window.cc Thu Dec 28 15:31:39 2006 +0000
8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
8.3 @@ -1,42 +0,0 @@
8.4 -/* -*- C++ -*-
8.5 - *
8.6 - * This file is a part of LEMON, a generic C++ optimization library
8.7 - *
8.8 - * Copyright (C) 2003-2006
8.9 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
8.10 - * (Egervary Research Group on Combinatorial Optimization, EGRES).
8.11 - *
8.12 - * Permission to use, modify and distribute this software is granted
8.13 - * provided that this copyright notice appears in all copies. For
8.14 - * precise terms see the accompanying LICENSE file.
8.15 - *
8.16 - * This software is provided "AS IS" with no warranty of any kind,
8.17 - * express or implied, and with no claim as to its suitability for any
8.18 - * purpose.
8.19 - *
8.20 - */
8.21 -
8.22 -#include "map_window.h"
8.23 -
8.24 -MapWindow::MapWindow()
8.25 -{
8.26 - refMapStore = Gtk::ListStore::create(mapColumns);
8.27 - //refMapStore->signal_row_changed().connect(sigc::mem_fun(*this, &Phy sicalProperties::onChannelChanged));
8.28 - twMap.set_model(refMapStore);
8.29 - twMap.append_column_editable("Name", mapColumns.colName);
8.30 - //twMap.append_column_editable("Value type", mapColumns.colValue);
8.31 - //twMap.append_column_editable("Map type", mapColumns.colType);
8.32 -
8.33 - swMap.set_size_request(-1, 300);
8.34 - swMap.add(twMap);
8.35 - swMap.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
8.36 -
8.37 - swMap.add(twMap);
8.38 - add(swMap);
8.39 -
8.40 - show_all_children();
8.41 -}
8.42 -
8.43 -MapWindow::~MapWindow()
8.44 -{
8.45 -}
9.1 --- a/map_window.h Thu Dec 28 15:31:39 2006 +0000
9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
9.3 @@ -1,52 +0,0 @@
9.4 -/* -*- C++ -*-
9.5 - *
9.6 - * This file is a part of LEMON, a generic C++ optimization library
9.7 - *
9.8 - * Copyright (C) 2003-2006
9.9 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
9.10 - * (Egervary Research Group on Combinatorial Optimization, EGRES).
9.11 - *
9.12 - * Permission to use, modify and distribute this software is granted
9.13 - * provided that this copyright notice appears in all copies. For
9.14 - * precise terms see the accompanying LICENSE file.
9.15 - *
9.16 - * This software is provided "AS IS" with no warranty of any kind,
9.17 - * express or implied, and with no claim as to its suitability for any
9.18 - * purpose.
9.19 - *
9.20 - */
9.21 -
9.22 -#ifndef MAP_WINDOW
9.23 -#define MAP_WINDOW
9.24 -
9.25 -#include <gtkmm/window.h>
9.26 -#include <gtkmm/liststore.h>
9.27 -#include <gtkmm/treeview.h>
9.28 -#include <gtkmm/scrolledwindow.h>
9.29 -#include "mapstorage.h"
9.30 -
9.31 -class MapWindow : public Gtk::Window
9.32 -{
9.33 - struct MapModelColumns : public Gtk::TreeModel::ColumnRecord
9.34 - {
9.35 - MapModelColumns()
9.36 - {
9.37 - add(colName);
9.38 - add(colValue);
9.39 - add(colType);
9.40 - }
9.41 - Gtk::TreeModelColumn<Glib::ustring> colName;
9.42 - Gtk::TreeModelColumn<MapStorage::value> colValue;
9.43 - Gtk::TreeModelColumn<MapStorage::type> colType;
9.44 - };
9.45 - private:
9.46 - MapModelColumns mapColumns;
9.47 - Glib::RefPtr<Gtk::ListStore> refMapStore;
9.48 - Gtk::TreeView twMap;
9.49 - Gtk::ScrolledWindow swMap;
9.50 - public:
9.51 - MapWindow();
9.52 - ~MapWindow();
9.53 -};
9.54 -
9.55 -#endif
10.1 --- a/mapstorage.cc Thu Dec 28 15:31:39 2006 +0000
10.2 +++ b/mapstorage.cc Wed Jan 10 14:37:46 2007 +0000
10.3 @@ -17,6 +17,7 @@
10.4 */
10.5
10.6 #include "mapstorage.h"
10.7 +#include "nbtab.h"
10.8 #include "gui_writer.h"
10.9 #include "gui_reader.h"
10.10 #include <limits>
10.11 @@ -27,7 +28,7 @@
10.12 const double a_d=0.05;
10.13 const double p_d=40000;
10.14
10.15 -MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false), iterations(i_d), attraction(a_d), propulsation(p_d)
10.16 +MapStorage::MapStorage(NoteBookTab& tab) : mytab(tab), modified(false), file_name(""), arrow_pos_read_ok(false), iterations(i_d), attraction(a_d), propulsation(p_d), background_set(false)
10.17 {
10.18 nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
10.19 coords.setXMap(*nodemap_storage["coordinates_x"]);
10.20 @@ -552,3 +553,39 @@
10.21 {
10.22 signal_design_win.emit(attraction, propulsation, iterations);
10.23 }
10.24 +
10.25 +void MapStorage::setBackground(const std::string& file_name)
10.26 +{
10.27 + if (file_name == background_file_name) return;
10.28 + if (file_name == "")
10.29 + {
10.30 + background_file_name = "";
10.31 + background_set = false;
10.32 + }
10.33 + else
10.34 + {
10.35 + background_file_name = file_name;
10.36 + background_set = true;
10.37 + }
10.38 + mytab.gd_canvas->setBackground();
10.39 +}
10.40 +
10.41 +const std::string& MapStorage::getBackgroundFilename()
10.42 +{
10.43 + return background_file_name;
10.44 +}
10.45 +
10.46 +bool MapStorage::isBackgroundSet()
10.47 +{
10.48 + return background_set;
10.49 +}
10.50 +
10.51 +double MapStorage::getBackgroundScaling()
10.52 +{
10.53 + return background_scaling;
10.54 +}
10.55 +
10.56 +void MapStorage::setBackgroundScaling(double scaling)
10.57 +{
10.58 + background_scaling = scaling;
10.59 +}
11.1 --- a/mapstorage.h Thu Dec 28 15:31:39 2006 +0000
11.2 +++ b/mapstorage.h Wed Jan 10 14:37:46 2007 +0000
11.3 @@ -25,6 +25,8 @@
11.4 #include "xymap.h"
11.5 #include <libgnomecanvasmm.h>
11.6
11.7 +class NoteBookTab;
11.8 +
11.9 ///class MapStorage handles NodeMaps and EdgeMaps.
11.10
11.11 ///Class MapStorage is responsible for storing
11.12 @@ -38,10 +40,17 @@
11.13 ///\todo too many things are public!!
11.14 class MapStorage
11.15 {
11.16 +private:
11.17 + std::string background_file_name;
11.18 + bool background_set;
11.19 + double background_scaling;
11.20 + NoteBookTab& mytab;
11.21 public:
11.22 - enum value {DOUBLE, STRING};
11.23 - enum type {NORMAL, GUI};
11.24 -
11.25 + void setBackground(const std::string& file_name);
11.26 + const std::string& getBackgroundFilename();
11.27 + bool isBackgroundSet();
11.28 + double getBackgroundScaling();
11.29 + void setBackgroundScaling(double scaling);
11.30 ///The graph for which the datas are stored.
11.31 Graph graph;
11.32 /// the coordinates of the nodes
11.33 @@ -122,7 +131,7 @@
11.34
11.35 ///Its all activity is initializing default values
11.36 ///for different visualization attributes.
11.37 - MapStorage();
11.38 + MapStorage(NoteBookTab& tab);
11.39
11.40 ///Destructor of MapStorage
11.41
12.1 --- a/nbtab.cc Thu Dec 28 15:31:39 2006 +0000
12.2 +++ b/nbtab.cc Wed Jan 10 14:37:46 2007 +0000
12.3 @@ -19,7 +19,7 @@
12.4 #include <nbtab.h>
12.5 #include "file_chooser_extra_widget.h"
12.6
12.7 -NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false)
12.8 +NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false), mapstorage(*this)
12.9 {
12.10 Gtk::ScrolledWindow *pScrolledWindow = manage(new Gtk::ScrolledWindow);
12.11 gd_canvas=new GraphDisplayerCanvas(*this);