# HG changeset patch # User ladanyi # Date 1168439866 0 # Node ID 4e8704aae278c560cda252d74e804d13ce23d381 # Parent 48580778851ec8029ea6c928700b7d340f30195c Added support for setting the background form an image file. diff -r 48580778851e -r 4e8704aae278 Makefile.am --- a/Makefile.am Thu Dec 28 15:31:39 2006 +0000 +++ b/Makefile.am Wed Jan 10 14:37:46 2007 +0000 @@ -49,8 +49,8 @@ dijkstrabox.cc \ file_chooser_extra_widget.h \ file_chooser_extra_widget.cc \ - map_window.h \ - map_window.cc + background_chooser_dialog.h \ + background_chooser_dialog.cc glemon_CXXFLAGS = $(GTK_CFLAGS) $(LEMON_CFLAGS) # glemon_LDFLAGS = $(GTK_LIBS) $(LEMON_LIBS) diff -r 48580778851e -r 4e8704aae278 background_chooser_dialog.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/background_chooser_dialog.cc Wed Jan 10 14:37:46 2007 +0000 @@ -0,0 +1,52 @@ +#include "background_chooser_dialog.h" +#include +#include "mapstorage.h" + +BackgroundChooserDialog::BackgroundChooserDialog(MapStorage* ms) : + mapstorage(ms), + btnClear(Gtk::Stock::CLEAR) +{ + set_has_separator(false); + + Gtk::VBox* pVBox = get_vbox(); + + lblBackground.set_text("Background image file"); + lblBackground.set_use_markup(); + lblBackground.set_alignment(Gtk::ALIGN_LEFT); + lblScaling.set_text("Scaling factor"); + lblScaling.set_use_markup(); + lblScaling.set_alignment(Gtk::ALIGN_LEFT); + fcbBackground.set_width_chars(30); + fcbBackground.set_action(Gtk::FILE_CHOOSER_ACTION_OPEN); + if (mapstorage->isBackgroundSet()) + { + fcbBackground.set_filename(mapstorage->getBackgroundFilename()); + } + + fcbBackground.signal_selection_changed().connect( + sigc::mem_fun(*this, &BackgroundChooserDialog::setBackground)); + + btnClear.signal_clicked().connect( + sigc::mem_fun(*this, &BackgroundChooserDialog::clearBackground)); + + pVBox->pack_start(lblBackground, Gtk::PACK_SHRINK); + pVBox->pack_start(box, Gtk::PACK_SHRINK); + box.pack_start(fcbBackground, Gtk::PACK_EXPAND_WIDGET); + box.pack_start(btnClear, Gtk::PACK_SHRINK); + pVBox->pack_start(lblScaling, Gtk::PACK_SHRINK); + pVBox->pack_start(sbScaling, Gtk::PACK_SHRINK); + + add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE); + + show_all_children(); +} + +void BackgroundChooserDialog::clearBackground() +{ + fcbBackground.unselect_all(); +} + +void BackgroundChooserDialog::setBackground() +{ + mapstorage->setBackground(fcbBackground.get_filename()); +} diff -r 48580778851e -r 4e8704aae278 background_chooser_dialog.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/background_chooser_dialog.h Wed Jan 10 14:37:46 2007 +0000 @@ -0,0 +1,27 @@ +#ifndef BACKGROUND_CHOOSER_DIALOG +#define BACKGROUND_CHOOSER_DIALOG + +#include +#include +#include +#include + +class MapStorage; + +class BackgroundChooserDialog : public Gtk::Dialog +{ + private: + MapStorage* mapstorage; + Gtk::Label lblBackground; + Gtk::Label lblScaling; + Gtk::FileChooserButton fcbBackground; + Gtk::SpinButton sbScaling; + Gtk::HBox box; + Gtk::Button btnClear; + void clearBackground(); + void setBackground(); + public: + BackgroundChooserDialog(MapStorage* ms); +}; + +#endif diff -r 48580778851e -r 4e8704aae278 graph_displayer_canvas.cc --- a/graph_displayer_canvas.cc Thu Dec 28 15:31:39 2006 +0000 +++ b/graph_displayer_canvas.cc Wed Jan 10 14:37:46 2007 +0000 @@ -25,7 +25,8 @@ nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0), isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""), edgemap_to_edit(""), autoscale(true), zoomtrack(false), radius_size(20), edge_width(10), - was_redesigned(false), is_drawn(false), mytab(mainw) + was_redesigned(false), is_drawn(false), mytab(mainw), + background_set(false) { //base event handler is move tool actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); @@ -34,6 +35,32 @@ active_node=INVALID; active_edge=INVALID; forming_edge=INVALID; + + setBackground(); +} + +void GraphDisplayerCanvas::setBackground() +{ + if (background_set) + { + delete background; + } + if (mytab.mapstorage.isBackgroundSet()) + { + background_set = true; + refBackground = Gdk::Pixbuf::create_from_file( + mytab.mapstorage.getBackgroundFilename()); + background = new Gnome::Canvas::Pixbuf( + *(root()), + 0.0 - refBackground->get_width() / 2.0, + 0.0 - refBackground->get_height() / 2.0, + refBackground); + background->lower_to_bottom(); + } + else + { + background_set = false; + } } GraphDisplayerCanvas::~GraphDisplayerCanvas() diff -r 48580778851e -r 4e8704aae278 graph_displayer_canvas.h --- a/graph_displayer_canvas.h Thu Dec 28 15:31:39 2006 +0000 +++ b/graph_displayer_canvas.h Wed Jan 10 14:37:46 2007 +0000 @@ -441,6 +441,12 @@ NoteBookTab & mytab; XY calcArrowPos(XY, XY, XY, XY, int); + + bool background_set; + Glib::RefPtr refBackground; + Gnome::Canvas::Pixbuf *background; +public: + void setBackground(); }; #endif //GRAPH_DISPLAYER_CANVAS_H diff -r 48580778851e -r 4e8704aae278 main_win.cc --- a/main_win.cc Thu Dec 28 15:31:39 2006 +0000 +++ b/main_win.cc Wed Jan 10 14:37:46 2007 +0000 @@ -22,6 +22,7 @@ #include "main_win.h" #include "guipixbufs.h" +#include "background_chooser_dialog.h" #include "i18n.h" @@ -113,6 +114,8 @@ sigc::mem_fun(*this, &MainWin::zoomFit)); ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100), sigc::mem_fun(*this, &MainWin::zoom100)); + ag->add( Gtk::Action::create("SetBackground", _("Set Background...")), + sigc::mem_fun(*this, &MainWin::createBackgroundChooser)); ag->add( Gtk::Action::create("ShowMenu", _("_Show")) ); ag->add( Gtk::Action::create("ShowMaps", _("_Maps")), @@ -173,6 +176,7 @@ " " " " " " + " " " " " " " " @@ -580,3 +584,9 @@ { tabs[active_tab]->reDesignGraph(); } + +void MainWin::createBackgroundChooser() +{ + BackgroundChooserDialog dialog(&(tabs[active_tab]->mapstorage)); + dialog.run(); +} diff -r 48580778851e -r 4e8704aae278 main_win.h --- a/main_win.h Thu Dec 28 15:31:39 2006 +0000 +++ b/main_win.h Wed Jan 10 14:37:46 2007 +0000 @@ -261,6 +261,8 @@ virtual void nodeViewChanged(); virtual void reDesignGraph(); + + void createBackgroundChooser(); }; #endif //MAIN_WIN_H diff -r 48580778851e -r 4e8704aae278 map_window.cc --- a/map_window.cc Thu Dec 28 15:31:39 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* -*- C++ -*- - * - * This file is a part of LEMON, a generic C++ optimization library - * - * Copyright (C) 2003-2006 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport - * (Egervary Research Group on Combinatorial Optimization, EGRES). - * - * Permission to use, modify and distribute this software is granted - * provided that this copyright notice appears in all copies. For - * precise terms see the accompanying LICENSE file. - * - * This software is provided "AS IS" with no warranty of any kind, - * express or implied, and with no claim as to its suitability for any - * purpose. - * - */ - -#include "map_window.h" - -MapWindow::MapWindow() -{ - refMapStore = Gtk::ListStore::create(mapColumns); - //refMapStore->signal_row_changed().connect(sigc::mem_fun(*this, &Phy sicalProperties::onChannelChanged)); - twMap.set_model(refMapStore); - twMap.append_column_editable("Name", mapColumns.colName); - //twMap.append_column_editable("Value type", mapColumns.colValue); - //twMap.append_column_editable("Map type", mapColumns.colType); - - swMap.set_size_request(-1, 300); - swMap.add(twMap); - swMap.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); - - swMap.add(twMap); - add(swMap); - - show_all_children(); -} - -MapWindow::~MapWindow() -{ -} diff -r 48580778851e -r 4e8704aae278 map_window.h --- a/map_window.h Thu Dec 28 15:31:39 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* -*- C++ -*- - * - * This file is a part of LEMON, a generic C++ optimization library - * - * Copyright (C) 2003-2006 - * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport - * (Egervary Research Group on Combinatorial Optimization, EGRES). - * - * Permission to use, modify and distribute this software is granted - * provided that this copyright notice appears in all copies. For - * precise terms see the accompanying LICENSE file. - * - * This software is provided "AS IS" with no warranty of any kind, - * express or implied, and with no claim as to its suitability for any - * purpose. - * - */ - -#ifndef MAP_WINDOW -#define MAP_WINDOW - -#include -#include -#include -#include -#include "mapstorage.h" - -class MapWindow : public Gtk::Window -{ - struct MapModelColumns : public Gtk::TreeModel::ColumnRecord - { - MapModelColumns() - { - add(colName); - add(colValue); - add(colType); - } - Gtk::TreeModelColumn colName; - Gtk::TreeModelColumn colValue; - Gtk::TreeModelColumn colType; - }; - private: - MapModelColumns mapColumns; - Glib::RefPtr refMapStore; - Gtk::TreeView twMap; - Gtk::ScrolledWindow swMap; - public: - MapWindow(); - ~MapWindow(); -}; - -#endif diff -r 48580778851e -r 4e8704aae278 mapstorage.cc --- a/mapstorage.cc Thu Dec 28 15:31:39 2006 +0000 +++ b/mapstorage.cc Wed Jan 10 14:37:46 2007 +0000 @@ -17,6 +17,7 @@ */ #include "mapstorage.h" +#include "nbtab.h" #include "gui_writer.h" #include "gui_reader.h" #include @@ -27,7 +28,7 @@ const double a_d=0.05; const double p_d=40000; -MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false), iterations(i_d), attraction(a_d), propulsation(p_d) +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) { nodemap_storage["coordinates_x"] = new Graph::NodeMap(graph); coords.setXMap(*nodemap_storage["coordinates_x"]); @@ -552,3 +553,39 @@ { signal_design_win.emit(attraction, propulsation, iterations); } + +void MapStorage::setBackground(const std::string& file_name) +{ + if (file_name == background_file_name) return; + if (file_name == "") + { + background_file_name = ""; + background_set = false; + } + else + { + background_file_name = file_name; + background_set = true; + } + mytab.gd_canvas->setBackground(); +} + +const std::string& MapStorage::getBackgroundFilename() +{ + return background_file_name; +} + +bool MapStorage::isBackgroundSet() +{ + return background_set; +} + +double MapStorage::getBackgroundScaling() +{ + return background_scaling; +} + +void MapStorage::setBackgroundScaling(double scaling) +{ + background_scaling = scaling; +} diff -r 48580778851e -r 4e8704aae278 mapstorage.h --- a/mapstorage.h Thu Dec 28 15:31:39 2006 +0000 +++ b/mapstorage.h Wed Jan 10 14:37:46 2007 +0000 @@ -25,6 +25,8 @@ #include "xymap.h" #include +class NoteBookTab; + ///class MapStorage handles NodeMaps and EdgeMaps. ///Class MapStorage is responsible for storing @@ -38,10 +40,17 @@ ///\todo too many things are public!! class MapStorage { +private: + std::string background_file_name; + bool background_set; + double background_scaling; + NoteBookTab& mytab; public: - enum value {DOUBLE, STRING}; - enum type {NORMAL, GUI}; - + void setBackground(const std::string& file_name); + const std::string& getBackgroundFilename(); + bool isBackgroundSet(); + double getBackgroundScaling(); + void setBackgroundScaling(double scaling); ///The graph for which the datas are stored. Graph graph; /// the coordinates of the nodes @@ -122,7 +131,7 @@ ///Its all activity is initializing default values ///for different visualization attributes. - MapStorage(); + MapStorage(NoteBookTab& tab); ///Destructor of MapStorage diff -r 48580778851e -r 4e8704aae278 nbtab.cc --- a/nbtab.cc Thu Dec 28 15:31:39 2006 +0000 +++ b/nbtab.cc Wed Jan 10 14:37:46 2007 +0000 @@ -19,7 +19,7 @@ #include #include "file_chooser_extra_widget.h" -NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false) +NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false), mapstorage(*this) { Gtk::ScrolledWindow *pScrolledWindow = manage(new Gtk::ScrolledWindow); gd_canvas=new GraphDisplayerCanvas(*this);