# HG changeset patch # User ladanyi # Date 1150879168 0 # Node ID 8e27998e9b1d4e527338a3ecad645cb95a8237d5 # Parent a979fcdda073915cd87a68d146a282cfb2bc5f23 Moved the gui to glemon/trunk. diff -r a979fcdda073 -r 8e27998e9b1d gui/Doxyfile --- a/gui/Doxyfile Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,273 +0,0 @@ -# Doxyfile 1.4.5 - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- -PROJECT_NAME = glemon -PROJECT_NUMBER = 0.1 -OUTPUT_DIRECTORY = -CREATE_SUBDIRS = NO -OUTPUT_LANGUAGE = English -USE_WINDOWS_ENCODING = NO -BRIEF_MEMBER_DESC = YES -REPEAT_BRIEF = YES -ABBREVIATE_BRIEF = "The $name class" \ - "The $name widget" \ - "The $name file" \ - is \ - provides \ - specifies \ - contains \ - represents \ - a \ - an \ - the -ALWAYS_DETAILED_SEC = NO -INLINE_INHERITED_MEMB = NO -FULL_PATH_NAMES = YES -STRIP_FROM_PATH = . -STRIP_FROM_INC_PATH = -SHORT_NAMES = NO -JAVADOC_AUTOBRIEF = NO -MULTILINE_CPP_IS_BRIEF = NO -DETAILS_AT_TOP = NO -INHERIT_DOCS = YES -SEPARATE_MEMBER_PAGES = NO -TAB_SIZE = 8 -ALIASES = -OPTIMIZE_OUTPUT_FOR_C = NO -OPTIMIZE_OUTPUT_JAVA = NO -BUILTIN_STL_SUPPORT = NO -DISTRIBUTE_GROUP_DOC = NO -SUBGROUPING = YES -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- -EXTRACT_ALL = YES -EXTRACT_PRIVATE = YES -EXTRACT_STATIC = YES -EXTRACT_LOCAL_CLASSES = YES -EXTRACT_LOCAL_METHODS = NO -HIDE_UNDOC_MEMBERS = NO -HIDE_UNDOC_CLASSES = NO -HIDE_FRIEND_COMPOUNDS = NO -HIDE_IN_BODY_DOCS = NO -INTERNAL_DOCS = NO -CASE_SENSE_NAMES = YES -HIDE_SCOPE_NAMES = NO -SHOW_INCLUDE_FILES = YES -INLINE_INFO = YES -SORT_MEMBER_DOCS = YES -SORT_BRIEF_DOCS = NO -SORT_BY_SCOPE_NAME = NO -GENERATE_TODOLIST = YES -GENERATE_TESTLIST = YES -GENERATE_BUGLIST = YES -GENERATE_DEPRECATEDLIST= YES -ENABLED_SECTIONS = -MAX_INITIALIZER_LINES = 30 -SHOW_USED_FILES = YES -SHOW_DIRECTORIES = YES -FILE_VERSION_FILTER = -#--------------------------------------------------------------------------- -# configuration options related to warning and progress messages -#--------------------------------------------------------------------------- -QUIET = NO -WARNINGS = YES -WARN_IF_UNDOCUMENTED = YES -WARN_IF_DOC_ERROR = YES -WARN_NO_PARAMDOC = NO -WARN_FORMAT = "$file:$line: $text" -WARN_LOGFILE = -#--------------------------------------------------------------------------- -# configuration options related to the input files -#--------------------------------------------------------------------------- -INPUT = . -FILE_PATTERNS = *.c \ - *.cc \ - *.cxx \ - *.cpp \ - *.c++ \ - *.d \ - *.java \ - *.ii \ - *.ixx \ - *.ipp \ - *.i++ \ - *.inl \ - *.h \ - *.hh \ - *.hxx \ - *.hpp \ - *.h++ \ - *.idl \ - *.odl \ - *.cs \ - *.php \ - *.php3 \ - *.inc \ - *.m \ - *.mm \ - *.dox \ - *.py \ - *.C \ - *.CC \ - *.C++ \ - *.II \ - *.I++ \ - *.H \ - *.HH \ - *.H++ \ - *.CS \ - *.PHP \ - *.PHP3 \ - *.M \ - *.MM \ - *.PY -RECURSIVE = NO -EXCLUDE = -EXCLUDE_SYMLINKS = NO -EXCLUDE_PATTERNS = -EXAMPLE_PATH = -EXAMPLE_PATTERNS = * -EXAMPLE_RECURSIVE = NO -IMAGE_PATH = -INPUT_FILTER = -FILTER_PATTERNS = -FILTER_SOURCE_FILES = NO -#--------------------------------------------------------------------------- -# configuration options related to source browsing -#--------------------------------------------------------------------------- -SOURCE_BROWSER = YES -INLINE_SOURCES = NO -STRIP_CODE_COMMENTS = YES -REFERENCED_BY_RELATION = YES -REFERENCES_RELATION = YES -USE_HTAGS = NO -VERBATIM_HEADERS = YES -#--------------------------------------------------------------------------- -# configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- -ALPHABETICAL_INDEX = NO -COLS_IN_ALPHA_INDEX = 5 -IGNORE_PREFIX = -#--------------------------------------------------------------------------- -# configuration options related to the HTML output -#--------------------------------------------------------------------------- -GENERATE_HTML = YES -HTML_OUTPUT = html -HTML_FILE_EXTENSION = .html -HTML_HEADER = -HTML_FOOTER = -HTML_STYLESHEET = -HTML_ALIGN_MEMBERS = YES -GENERATE_HTMLHELP = NO -CHM_FILE = -HHC_LOCATION = -GENERATE_CHI = NO -BINARY_TOC = NO -TOC_EXPAND = NO -DISABLE_INDEX = NO -ENUM_VALUES_PER_LINE = 4 -GENERATE_TREEVIEW = NO -TREEVIEW_WIDTH = 250 -#--------------------------------------------------------------------------- -# configuration options related to the LaTeX output -#--------------------------------------------------------------------------- -GENERATE_LATEX = NO -LATEX_OUTPUT = latex -LATEX_CMD_NAME = latex -MAKEINDEX_CMD_NAME = makeindex -COMPACT_LATEX = NO -PAPER_TYPE = a4wide -EXTRA_PACKAGES = -LATEX_HEADER = -PDF_HYPERLINKS = NO -USE_PDFLATEX = NO -LATEX_BATCHMODE = NO -LATEX_HIDE_INDICES = NO -#--------------------------------------------------------------------------- -# configuration options related to the RTF output -#--------------------------------------------------------------------------- -GENERATE_RTF = NO -RTF_OUTPUT = rtf -COMPACT_RTF = NO -RTF_HYPERLINKS = NO -RTF_STYLESHEET_FILE = -RTF_EXTENSIONS_FILE = -#--------------------------------------------------------------------------- -# configuration options related to the man page output -#--------------------------------------------------------------------------- -GENERATE_MAN = NO -MAN_OUTPUT = man -MAN_EXTENSION = .3 -MAN_LINKS = NO -#--------------------------------------------------------------------------- -# configuration options related to the XML output -#--------------------------------------------------------------------------- -GENERATE_XML = NO -XML_OUTPUT = xml -XML_SCHEMA = -XML_DTD = -XML_PROGRAMLISTING = YES -#--------------------------------------------------------------------------- -# configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- -GENERATE_AUTOGEN_DEF = NO -#--------------------------------------------------------------------------- -# configuration options related to the Perl module output -#--------------------------------------------------------------------------- -GENERATE_PERLMOD = NO -PERLMOD_LATEX = NO -PERLMOD_PRETTY = YES -PERLMOD_MAKEVAR_PREFIX = -#--------------------------------------------------------------------------- -# Configuration options related to the preprocessor -#--------------------------------------------------------------------------- -ENABLE_PREPROCESSING = YES -MACRO_EXPANSION = NO -EXPAND_ONLY_PREDEF = NO -SEARCH_INCLUDES = YES -INCLUDE_PATH = -INCLUDE_FILE_PATTERNS = -PREDEFINED = -EXPAND_AS_DEFINED = -SKIP_FUNCTION_MACROS = YES -#--------------------------------------------------------------------------- -# Configuration::additions related to external references -#--------------------------------------------------------------------------- -TAGFILES = -GENERATE_TAGFILE = -ALLEXTERNALS = NO -EXTERNAL_GROUPS = YES -PERL_PATH = /usr/bin/perl -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- -CLASS_DIAGRAMS = NO -HIDE_UNDOC_RELATIONS = YES -HAVE_DOT = YES -CLASS_GRAPH = YES -COLLABORATION_GRAPH = YES -GROUP_GRAPHS = YES -UML_LOOK = NO -TEMPLATE_RELATIONS = NO -INCLUDE_GRAPH = YES -INCLUDED_BY_GRAPH = YES -CALL_GRAPH = YES -GRAPHICAL_HIERARCHY = YES -DIRECTORY_GRAPH = YES -DOT_IMAGE_FORMAT = png -DOT_PATH = -DOTFILE_DIRS = -MAX_DOT_GRAPH_WIDTH = 1024 -MAX_DOT_GRAPH_HEIGHT = 1024 -MAX_DOT_GRAPH_DEPTH = 1000 -DOT_TRANSPARENT = NO -DOT_MULTI_TARGETS = NO -GENERATE_LEGEND = YES -DOT_CLEANUP = YES -#--------------------------------------------------------------------------- -# Configuration::additions related to the search engine -#--------------------------------------------------------------------------- -SEARCHENGINE = NO diff -r a979fcdda073 -r 8e27998e9b1d gui/Makefile.am --- a/gui/Makefile.am Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir) -DLOCALEDIR=\""$(datadir)/locale"\" -LDADD = $(top_builddir)/lemon/libemon.la - -bin_PROGRAMS = glemon -BUILT_SOURCES = guipixbufs.h -CLEANFILES = guipixbufs.h - -glemon_SOURCES = \ - all_include.h \ - algobox.cc \ - algobox.h \ - algowin.cc \ - algowin.h \ - gdc-broken_edge.cc \ - graph_displayer_canvas.cc \ - graph_displayer_canvas.h \ - graph_displayer_canvas-edge.cc \ - graph_displayer_canvas-event.cc \ - graph_displayer_canvas-node.cc \ - graph_displayer_canvas-zoom.cc \ - graph-displayer.cc \ - kruskalbox.cc \ - kruskalbox.h \ - main_win.cc \ - main_win.h \ - mapstorage.cc \ - mapstorage.h \ - map_win.cc \ - map_win.h \ - mapselector.cc \ - mapselector.h \ - nbtab.h \ - nbtab.cc \ - new_map_win.cc \ - new_map_win.h \ - xymap.h \ - gui_reader.h \ - gui_reader.cc \ - gui_writer.h \ - gui_writer.cc \ - xml.h \ - guipixbufs.h \ - i18n.h \ - gettext.h - -glemon_CXXFLAGS = $(GTK_CFLAGS) -glemon_LDFLAGS = $(GTK_LIBS) -glemon_LDADD = $(LIBINTL) - -IMAGES = \ - icons/addlink.png \ - icons/addnode.png \ - icons/delete.png \ - icons/editlink.png \ - icons/editnode.png \ - icons/move.png \ - icons/newmap.png - -VARIABLES = \ - gui_icons_addlink $(srcdir)/icons/addlink.png \ - gui_icons_addnode $(srcdir)/icons/addnode.png \ - gui_icons_delete $(srcdir)/icons/delete.png \ - gui_icons_editlink $(srcdir)/icons/editlink.png \ - gui_icons_editnode $(srcdir)/icons/editnode.png \ - gui_icons_move $(srcdir)/icons/move.png \ - gui_icons_newmap $(srcdir)/icons/newmap.png - -guipixbufs.h: $(IMAGES) - gdk-pixbuf-csource \ - --raw --build-list $(VARIABLES) > guipixbufs.h || \ - ( rm -f guipixbufs.h && false ) - -EXTRA_DIST = $(IMAGES) guipixbufs.h diff -r a979fcdda073 -r 8e27998e9b1d gui/algobox.cc --- a/gui/algobox.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,186 +0,0 @@ -#include - -enum {N_DEMO1, N_DEMO2, NODE_INPUT_NUM}; // input IDs for nodes; -enum {E_DEMO1, EDGE_INPUT_NUM}; // input IDs for edges; - -AlgoBox::AlgoBox(std::vector tabnames) -{ - init(tabnames); -} - -void AlgoBox::init(std::vector tabnames) -{ - set_spacing(5); - - update_tablist(tabnames); - - //if active tab is changed, the map names in cbt/s have to be updated - tabcbt.signal_changed().connect(sigc::mem_fun(*this, &AlgoBox::emit_tab_change)); - - pack_start(tabcbt); - build_box(); - - show_all_children(); -}; - -void AlgoBox::update_cbt(std::vector< std::string > stringlist, Gtk::ComboBoxText & cbt) -{ - std::string actname=cbt.get_active_text(); - int prev_act=-1; - - cbt.clear(); - int actptr=0; - - std::vector< std::string >::iterator emsi=stringlist.begin(); - for(;emsi!=stringlist.end();emsi++) - { - if(actname==*emsi) - { - prev_act=actptr; - } - - cbt.append_text(*emsi); - actptr++; - } - - if(prev_act!=-1) - { - cbt.set_active(prev_act); - } - else if(actptr>0) //so there is item in the list - { - //cbt.set_active(0); - } -} - -void AlgoBox::update_tablist( std::vector< std::string > tl ) -{ - update_cbt(tl, tabcbt); - emit_tab_change(); -} - -void AlgoBox::update_maplist(MapStorage * ms) -{ - mapstorage=ms; - std::vector nml; - std::vector eml; - if(mapstorage!=NULL) - { - mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed)); - mapstorage->signal_edge_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::edgemaplist_changed)); - nml=mapstorage->getNodeMapList(); - eml=mapstorage->getEdgeMapList(); - } - for(int i=0;i<(int)nodemapcbts.size();i++) - { - (nodemapcbts[i])->update_list(nml); - //update_cbt(nml, *(nodemapcbts[i])); - } - for(int i=0;i<(int)edgemapcbts.size();i++) - { - (edgemapcbts[i])->update_list(eml); - //update_cbt(eml, *(edgemapcbts[i])); - } -} - -void AlgoBox::nodemaplist_changed(std::string newmap) -{ - for(int i=0;i<(int)nodemapcbts.size();i++) - { - (nodemapcbts[i])->append_text(newmap); - } -} - -void AlgoBox::edgemaplist_changed(std::string newmap) -{ - for(int i=0;i<(int)edgemapcbts.size();i++) - { - (edgemapcbts[i])->append_text(newmap); - } -} - -void AlgoBox::run() -{ - std::cout << "Start algorithm." << std::endl; -} - -void AlgoBox::build_box() -{ - pack_start(*(new Gtk::HSeparator())); - - Gtk::Label * label=new Gtk::Label("Specific part for each algorithm."); - - pack_start(*label); - pack_start(*(new Gtk::HSeparator())); - - label=new Gtk::Label("Maps in chosen tab:"); - - pack_start(*label); - - for(int i=0;i empty_vector; - - MapSelector * msp=new MapSelector(empty_vector,"",inputname,itisedge, false); - - if(itisedge) - { - edgemapcbts.resize(edgemapcbts.size()+1); - edgemapcbts[edgemapcbts.size()-1]=msp; - } - else - { - nodemapcbts.resize(nodemapcbts.size()+1); - nodemapcbts[nodemapcbts.size()-1]=msp; - } - - msp->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal)); - - pack_start(*msp); -} - -sigc::signal AlgoBox::signal_maplist_needed() -{ - return signal_maplist_need; -} - -void AlgoBox::emit_tab_change() -{ - std::string active_tab=tabcbt.get_active_text(); - if(active_tab!="") - { - signal_maplist_need.emit(active_tab); - } - else - { - std::vector empty_vector; - update_maplist(NULL); - } -} - -void AlgoBox::emit_new_map_signal(bool itisedge) -{ - signal_newmapwin_need.emit(tabcbt.get_active_text(), itisedge); -} diff -r a979fcdda073 -r 8e27998e9b1d gui/algobox.h --- a/gui/algobox.h Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,167 +0,0 @@ -// -*- C++ -*- // - -#ifndef ALGOBOX_H -#define ALGOBOX_H - -class AlgoBox; - -#include -#include -#include -#include -#include - -///Ancestor class of algorithm graphical interface classes. - -///It also demonstrates, how should an algorithm graphical interface -///work. Children of this class have the same functions and attributes, -///therefore with all of them can the holder \ref AlgoWin communicate -///in the same way. -/// -///IMPORTANT! In a child class only the following tasks are to do: -/// -///-call \ref init function with correct parameters from correctly parametrized constructor -/// -///-implement \ref build_box function -/// -///-implement \ref run function -/// -///because all other thing is automatically done in \ref init function! - -class AlgoBox : public Gtk::VBox -{ - ///Signal emitted in case of need for list of maps. - - ///If the user has selected different tab to work on - ///new maps are selected as well. These new maps should be - ///provided for \ref AlgoBox. To get these maps, \ref AlgoBox - ///emits this signal. - sigc::signal signal_maplist_need; - - ///Signal emitted in case of need for \ref NewMapWin. - - ///If user wants to create a new for an input, or output - ///it can let \ref NewMapWin popped up from here as well. - ///In that case will be this signal emitted. - sigc::signal signal_newmapwin_need; - -protected: - ///Holder of tabnames. - Gtk::ComboBoxText tabcbt; - - ///Holder of widgets, in which nodemaps can be selected to work on. - std::vector nodemapcbts; - - ///Holder of widgets, in which edgemaps can be selected to work on. - std::vector edgemapcbts; - - ///Maps of selected tabs. - MapStorage * mapstorage; - -public: - ///Empty constructor called by children. - AlgoBox(){}; - - ///Constructor - - ///Calls \ref init function - ///with the provided parameters. \ref init function - ///is needed, because it is virtual, therefore the - ///functions of the proper class will be called when - ///running. - ///\param tablist list of tabs in \ref MainWin - AlgoBox(std::vector tablist); - - ///Initiates \ref AlgoBox. - - ///Creates the graphical interface for the realized algorithm, initiates variables, connects signals. - /// - ///List of tabs in \ref MainWin is required, but no one - ///will be selected automatically. Every other - ///entry field remains empty (unselected), until a \ref NoteBookTab - ///is selected. - /// - ///It also have to bind all the signals to the correct place. - ///This function is virtual, in all type of children of - ///\ref AlgoBox the correct function willbe called. - /// - ///Therefore it is IMPORTANT that only \ref run and \ref build_box - ///has to be implemented in children of \ref AlgoBox, every other - ///thing will automatically work properly by the help of this - ///function that must be called in constructor of child!!! - virtual void init(std::vector); - - ///Signal emitted, when selected tab changes, and new list of maps required. - sigc::signal signal_maplist_needed(); - - ///Emitted if user wants to create a new map for inpuit or output. - sigc::signal signal_newmapwin_needed(){return signal_newmapwin_need;}; - - ///Emits signal that requires list of maps for the recently selected \ref NoteBookTab. - void emit_tab_change(); - - ///Interface, through which \ref AlgoBox can be notified about tab addition, deletion in \ref MainWin - - ///\param tl list - ///of new tab state. - void update_tablist( std::vector< std::string > tl ); - - ///Interface, through which \ref AlgoBox can get the maps of the recently selected \ref NoteBookTab - - ///\param ms the maps - ///of the recently selected \ref NoteBookTab - void update_maplist( MapStorage * ms); - - ///Interface, through which \ref AlgoBox can be notified about nodemap addition. - - ///If new map was added to \ref MapStorage of currently selected \ref NoteBookTab - ///a signal is emitted by it. This signal is connected to this function, so \ref MapSelector s - ///in \ref nodemapcbts can be notified, and those can registrate the new map. (\ref MapSelector::append_text) - void nodemaplist_changed(std::string); - - ///Interface, through which \ref AlgoBox can be notified about edgemap addition. - - ///If new map was added to \ref MapStorage of currently selected \ref NoteBookTab - ///a signal is emitted by it. This signal is connected to this function, so \ref MapSelector s - ///in \ref edgemapcbts can be notified, and those can registrate the new map. (\ref MapSelector::append_text) - void edgemaplist_changed(std::string); - - ///Aid function to provide data for a given entry. - - ///At the moment it is only used for updating info - ///in \ref tabcbt. It clears it first, after that - ///inserts the data got from caller, and if there - ///was previously selected item it switches entry - ///to that. - ///\param tl list of entries (at the moment tabs in \ref MainWin) - ///\param cbt the entry to update (at the moment only \ref tabcbt) - void update_cbt( std::vector< std::string > tl, Gtk::ComboBoxText & cbt); - - ///Runs the ralized algorithm. - - ///Prepare the data for it - ///and after that postprocess it if necessary. - ///This is only a demo here, but in children it - ///runs the algorithm really. - virtual void run(); - - ///Creates the layout of the \ref AlgoBox - - ///Place all the entries - ///required. Run and close button is not - ///its responsibility! - virtual void build_box(); - - ///Emits \ref signal_newmapwin_need if user wants to create new input or output map. - - ///Called in case of pressing \ref MapSelector::newbut. - ///\param itisedge edge or nodemap is required. - virtual void emit_new_map_signal(bool itisedge); - - ///Aid function to make addition of \ref MapSelector easy in \ref build_box. - - ///\param label label to show in \ref MapSelector - ///\param itisedge whether edge or nodemaps stored in \ref MapSelector - void addMapSelector(std::string label, bool itisedge); -}; -#endif //ALGOBOX_H diff -r a979fcdda073 -r 8e27998e9b1d gui/algowin.cc --- a/gui/algowin.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -#include -#include - -sigc::signal AlgoWin::signal_closing() -{ - return signal_closed; -} - -sigc::signal AlgoWin::signal_maplist_needed() -{ - return signal_maplist_need; -} - -bool AlgoWin::closeIfEscapeIsPressed(GdkEventKey* e) -{ - if(e->keyval==GDK_Escape) - { - on_hide(); - } - return true; -} - -AlgoWin::AlgoWin(int algoid, std::vector tabnames) -{ - signal_key_press_event().connect(sigc::mem_fun(*this, &AlgoWin::closeIfEscapeIsPressed)); - - Gtk::VBox * vbox=new Gtk::VBox(); - vbox->set_spacing(5); - - Gtk::Label * label=new Gtk::Label("Select graph:"); - - switch(algoid) - { - case 0: - ab=new AlgoBox(tabnames); - set_title("Algo Win Demo"); - break; - case 1: - ab=new KruskalBox(tabnames); - set_title("Kruskal Algorithm"); - break; - default: - break; - } - ab->signal_maplist_needed().connect(sigc::mem_fun(*this, &AlgoWin::emit_tab_change)); - ab->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoWin::emit_new_map_signal)); - - runbutton=new Gtk::Button("Run"); - runbutton->signal_released().connect(sigc::mem_fun(*ab,&AlgoBox::run)); - runbutton->signal_activate().connect(sigc::mem_fun(*ab,&AlgoBox::run)); - - closebutton=new Gtk::Button("Close"); - closebutton->signal_released().connect(sigc::mem_fun(*this,&AlgoWin::on_hide)); - closebutton->signal_activate().connect(sigc::mem_fun(*this,&AlgoWin::on_hide)); - - Gtk::HBox * hbox=new Gtk::HBox(); - - hbox->pack_start(*runbutton); - hbox->pack_start(*closebutton); - - vbox->pack_start(*label); - vbox->pack_start(*ab); - vbox->pack_start(*hbox); - - add(*vbox); - - show_all_children(); -}; - -void AlgoWin::update_tablist(std::vector tabnames) -{ - ab->update_tablist(tabnames); -} - -void AlgoWin::update_maplist(MapStorage * mapstorage) -{ - ab->update_maplist(mapstorage); -} - -void AlgoWin::on_hide() -{ - signal_closed.emit(this); - Gtk::Window::on_hide(); -} - -void AlgoWin::emit_tab_change(std::string newtab) -{ - signal_maplist_need.emit(this, newtab); -} diff -r a979fcdda073 -r 8e27998e9b1d gui/algowin.h --- a/gui/algowin.h Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,134 +0,0 @@ -// -*- C++ -*- // - -#ifndef ALGOWIN_H -#define ALGOWIN_H - -class AlgoWin; - -#include -//#include -#include -#include -#include - -class MapStorage; - -///Algorithm identifiers. -enum {GENERAL, KRUSKAL, ALGO_NUM}; // algorithm IDs; - -///Window displaying graphical interface for different algorithms. - -///This class displays a graphical interface to set up -///and run different algorithms. Different algorithms need -///different inputs, running methods, etc. Therefore -///class \ref AlgoWin is only a holder of a base class, the so -///called AlgoBox. \ref AlgoBox is the ancestor of other -///classes. These child classes realize interfaces of different -///algorithms, but as their common ancestor is \ref AlgoBox -///the interface of them is the same. \ref AlgoWin communicates -///with these classes through this common interface. But it the -///real object to be placed in \ref AlgoWin depends on the algorithm -///which the \ref AlgoWin actually has to display. It gets the -///id of algorithm to display at initialization, and therefore it is -///able to place in itself the requested child of \ref AlgoBox -/// visualizing the appropriate algorithm. -class AlgoWin : public Gtk::Window -{ -private: - ///Algorithm specific part of \ref AlgoWin - AlgoBox * ab; - - ///Run button. - - ///If pressed, algorithm should run. - ///That is why common ancestor of different - ///algorithm realizer classes have to be. In case of - ///pressing run button a common method can be called. - Gtk::Button * runbutton; - - ///Close button. If pressed, \ref AlgoWin should close. - Gtk::Button * closebutton; - -protected: - ///Signal emitted upon close of window - - ///It is necessary, because \ref MainWin have to - ///score the opened \ref AlgoWin s, to be able to communicate - ///with them: let them know about changement in tabs, maps, etc. - ///If \ref AlgoWin is closed, \ref MainWin has to deregistrate it. - ///Therefore signal contains address of emitter \ref AlgoWin. - sigc::signal signal_closed; - - ///Signal indicating that informatino on certain maplist is required. - - ///It is just a forwarded signal from \ref AlgoBox, benefit of common ancestor - ///algorithm class. User can select the graph (the holder \ref NoteBookTab) on - ///which the algorithm should run. But different graphs (\ref NoteBookTab) have - ///different maps. If selected tab changes this signal is emitted by \ref AlgoBox, - ///caught and reemitted by \ref AlgoWin. - /// - ///Signal contains the address of \ref AlgoWin to let \ref MainWin know - ///where should the information needed forwarded, and the name of - ///\ref NoteBookTab, of which maps are inquired. - sigc::signal signal_maplist_need; - - ///Signal that indicates that a \ref NewMapWin should be popped up. - - ///This is a forwarded signal. If \ref AlgoBox emits a signal - ///to let a \ref NewMapWin pop up, |ref AlgoWin catch and reemit it. - /// - ///Signal contains the name of \ref NoteBookTab, in which the new map - ///should be created and a boolean that indicates whether an edge or a - ///nodemap should be created. - sigc::signal signal_newmapwin_need; - -public: - ///Close window if escape key is pressed. - bool closeIfEscapeIsPressed(GdkEventKey* e); - - ///Returns \ref signal_closed to be bindable somewhere. - sigc::signal signal_closing(); - - ///Returns \ref signal_maplist_need to be bindable somewhere. - sigc::signal signal_maplist_needed(); - - ///Returns \ref signal_newmapwin_need to be bindable somewhere. - sigc::signal signal_newmapwin_needed(){return signal_newmapwin_need;}; - - ///Forwards signal emitted by \ref AlgoBox, in which it indicates changement in selection of tabs. - void emit_tab_change(std::string); - - ///Forwards signal emitted by \ref AlgoBox, in which it indicates need for \ref NewMapWin. - void emit_new_map_signal(std::string tabname, bool itisedge){signal_newmapwin_need.emit(tabname, itisedge);}; - - ///Constructor - - ///It builds the window according to the information provided - ///by the creator. It needs the identifier of the algorithm - ///to visualize, and a list of name of \ref NoteBookTab s that can - ///be found in \ref MainWin. - ///\param algoid identifier of algorithm to show - ///\param tablist list of tabs in \ref MainWin - AlgoWin(int algoid, std::vector tablist); - - ///Forwards list of \ref NoteBookTabs toward \ref AlgoBox - - ///In case of changement in tabs in \ref MainWin - ///\ref MainWin automatically updates tablist in - ///\ref AlgoWin s. - void update_tablist(std::vector tabnames); - - ///Forwards list of requested maps toward \ref AlgoBox - - ///Upon catching the signal in which \ref AlgoBox requests - ///list of maps \ref MainWin responds - ///through this function. - void update_maplist(MapStorage *); - - ///Called when window is closing. - - ///\ref AlgoWin has to be deregistrated in \ref MainWin - ///thereforeit emits signal \ref signal_closed. - void on_hide(); -}; -#endif //ALGOWIN_H diff -r a979fcdda073 -r 8e27998e9b1d gui/all_include.h --- a/gui/all_include.h Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -// -*- C++ -*- // - -#ifndef ALL_INCLUDE_H -#define ALL_INCLUDE_H - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -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 {MOVE, CREATE_NODE, CREATE_EDGE, ERASER, EDGE_MAP_EDIT, NODE_MAP_EDIT, TOOL_NUM}; // tools; -#define RANGE 3 -#define WIN_WIDTH 900 -#define WIN_HEIGHT 600 -#define MIN_EDGE_WIDTH 2 -#define MAX_EDGE_WIDTH 40 -#define MIN_NODE_RADIUS 2 -#define MAX_NODE_RADIUS 80 - -#ifndef MAIN_PART -extern std::vector edge_property_strings; -extern std::vector edge_property_defaults; -extern std::vector node_property_strings; -extern std::vector node_property_defaults; -extern int longest_property_string_length; -#endif //MAIN_PART - -using namespace lemon; - -typedef xy XY; -typedef ListGraph Graph; -typedef Graph::Node Node; -typedef Graph::Edge Edge; -typedef Graph::EdgeIt EdgeIt; -typedef Graph::InEdgeIt InEdgeIt; -typedef Graph::OutEdgeIt OutEdgeIt; -typedef Graph::NodeIt NodeIt; - -const std::string prog_name = "LEMON Graph Editor"; - -#endif // ALL_INCLUDE_H diff -r a979fcdda073 -r 8e27998e9b1d gui/gdc-broken_edge.cc --- a/gui/gdc-broken_edge.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,133 +0,0 @@ -#include "graph_displayer_canvas.h" -#include - -GraphDisplayerCanvas::BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Edge _edge, GraphDisplayerCanvas & gc) : Line(g), edge(_edge), gdc(gc), isbutton(false) -{ - arrow=new Gnome::Canvas::Polygon(g); - *arrow << Gnome::Canvas::Properties::fill_color("red"); - arrow->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::BrokenEdge::edgeFormerEventHandler)); - arrow->lower_to_bottom(); - draw(); -} - -GraphDisplayerCanvas::BrokenEdge::~BrokenEdge() -{ - if(arrow)delete(arrow); -} - -void GraphDisplayerCanvas::BrokenEdge::draw() -{ - MapStorage& ms = gdc.mytab.mapstorage; - - // update the edge - { - Gnome::Canvas::Points points; - Node source = ms.graph.source(edge); - Node target = ms.graph.target(edge); - points.push_back(Gnome::Art::Point(ms.coords[source].x, - ms.coords[source].y)); - points.push_back(Gnome::Art::Point(ms.arrow_pos[edge].x, - ms.arrow_pos[edge].y)); - points.push_back(Gnome::Art::Point(ms.coords[target].x, - ms.coords[target].y)); - property_points().set_value(points); - } - - // update the arrow - { - //calculating coordinates of the direction indicator arrow - XY target(ms.coords[ms.graph.target(edge)]); - XY center(ms.arrow_pos[edge]); - - XY unit_vector_in_dir(target-center); - double length=sqrt( unit_vector_in_dir.normSquare() ); - - // std::cout << target << " - " << center << " = " << unit_vector_in_dir << " / " <property_points().set_value(arrow_points); - } -} - -bool GraphDisplayerCanvas::BrokenEdge::edgeFormerEventHandler(GdkEvent* e) -{ - switch(e->type) - { - case GDK_BUTTON_PRESS: - //we mark the location of the event to be able to calculate parameters of dragging - if(gdc.getActualTool()!=CREATE_NODE) - { - gdc.toggleEdgeActivity(this, true); - clicked_x=e->button.x; - clicked_y=e->button.y; - isbutton=true; - } - break; - case GDK_BUTTON_RELEASE: - if(gdc.getActualTool()!=CREATE_NODE) - { - gdc.toggleEdgeActivity(this, false); - isbutton=false; - } - break; - case GDK_MOTION_NOTIFY: - //we only have to do sg. if the mouse button is pressed - if(isbutton) - { - //new coordinates will be the old values, - //because the item will be moved to the - //new coordinate therefore the new movement - //has to be calculated from here - - double dx=e->motion.x-clicked_x; - double dy=e->motion.y-clicked_y; - - Gnome::Canvas::Points points_new; - - gdc.mytab.mapstorage.arrow_pos.set(edge, gdc.mytab.mapstorage.arrow_pos[edge] + XY(dx, dy)); - - draw(); - gdc.textReposition(gdc.mytab.mapstorage.arrow_pos[edge]); - - clicked_x=e->motion.x; - clicked_y=e->motion.y; - - } - default: break; - } - - return true; -} diff -r a979fcdda073 -r 8e27998e9b1d gui/gettext.h --- a/gui/gettext.h Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* Convenience header for conditional use of GNU . - Copyright (C) 1995-1998, 2000-2002, 2004 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published - by the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. */ - -#ifndef _LIBGETTEXT_H -#define _LIBGETTEXT_H 1 - -/* NLS can be disabled through the configure --disable-nls option. */ -#if ENABLE_NLS - -/* Get declarations of GNU message catalog functions. */ -# include - -#else - -/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which - chokes if dcgettext is defined as a macro. So include it now, to make - later inclusions of a NOP. We don't include - as well because people using "gettext.h" will not include , - and also including would fail on SunOS 4, whereas - is OK. */ -#if defined(__sun) -# include -#endif - -/* Many header files from the libstdc++ coming with g++ 3.3 or newer include - , which chokes if dcgettext is defined as a macro. So include - it now, to make later inclusions of a NOP. */ -#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3) -# include -# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H -# include -# endif -#endif - -/* Disabled NLS. - The casts to 'const char *' serve the purpose of producing warnings - for invalid uses of the value returned from these functions. - On pre-ANSI systems without 'const', the config.h file is supposed to - contain "#define const". */ -# define gettext(Msgid) ((const char *) (Msgid)) -# define dgettext(Domainname, Msgid) ((const char *) (Msgid)) -# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid)) -# define ngettext(Msgid1, Msgid2, N) \ - ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) -# define dngettext(Domainname, Msgid1, Msgid2, N) \ - ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) -# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ - ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) -# define textdomain(Domainname) ((const char *) (Domainname)) -# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname)) -# define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset)) - -#endif - -/* A pseudo function call that serves as a marker for the automated - extraction of messages, but does not call gettext(). The run-time - translation is done at a different place in the code. - The argument, String, should be a literal string. Concatenated strings - and other string expressions won't work. - The macro's expansion is not parenthesized, so that it is suitable as - initializer for static 'char[]' or 'const char[]' variables. */ -#define gettext_noop(String) String - -#endif /* _LIBGETTEXT_H */ diff -r a979fcdda073 -r 8e27998e9b1d gui/graph-displayer.cc --- a/gui/graph-displayer.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "all_include.h" -#include "mapstorage.h" -#include "main_win.h" -#include -#include - -#include - -#define MAIN_PART - -std::vector edge_property_strings; -std::vector edge_property_defaults; -std::vector node_property_strings; -std::vector node_property_defaults; -int longest_property_string_length; - -int main(int argc, char *argv[]) -{ - setlocale(LC_ALL, ""); - bindtextdomain(PACKAGE, LOCALEDIR); - bind_textdomain_codeset(PACKAGE, "UTF-8"); - textdomain(PACKAGE); - - //initializing - - edge_property_strings.resize(EDGE_PROPERTY_NUM); - edge_property_strings[E_WIDTH]="Edge Width"; - edge_property_strings[E_COLOR]="Edge Color"; - edge_property_strings[E_TEXT]="Edge Text"; - - edge_property_defaults.resize(EDGE_PROPERTY_NUM); - edge_property_defaults[E_WIDTH]=10.0; - edge_property_defaults[E_COLOR]=100; - edge_property_defaults[E_TEXT]=0; - - node_property_strings.resize(NODE_PROPERTY_NUM); - node_property_strings[N_RADIUS]="Node Radius"; - node_property_strings[N_COLOR]="Node Color"; - node_property_strings[N_TEXT]="Node Text"; - - node_property_defaults.resize(NODE_PROPERTY_NUM); - node_property_defaults[N_RADIUS]=20.0; - node_property_defaults[N_COLOR]=100; - node_property_defaults[N_TEXT]=0; - - longest_property_string_length=0; - for(int i=0;ilongest_property_string_length) - { - longest_property_string_length=j; - } - } - for(int i=0;ilongest_property_string_length) - { - longest_property_string_length=j; - } - } - - - //initializing GUI - - Gnome::Canvas::init(); - Gtk::Main app(argc, argv); - - MainWin mytab; - -// if ((argc == 2) && (Glib::file_test(argv[1], Glib::FILE_TEST_IS_REGULAR))) -// { -// mytab.readFile(argv[1]); -// } - if(argc>=2) - { - for(int i=1;i - - -int GraphDisplayerCanvas::resetEdgeWidth (Edge edge) -{ - double min, max; - - min=edge_property_defaults[E_WIDTH]; - max=edge_property_defaults[E_WIDTH]; - Graph::EdgeMap actual_map((mytab.mapstorage).graph,edge_property_defaults[E_WIDTH]); - - if(edge==INVALID) - { - for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - double v=fabs(actual_map[i]); - int w; - if(min==max) - { - w=(int)(edge_property_defaults[E_WIDTH]); - } - else - { - w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH)); - } - edgesmap[i]->property_width_units().set_value(w); - } - } - else - { - int w=(int)actual_map[edge]; - if(w>=0) - { - edgesmap[edge]->property_width_units().set_value(w); - } - } - return 0; -} - - -int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge) -{ - Graph::EdgeMap * actual_map; - double min, max; - - min=(mytab.mapstorage).minOfEdgeMap(mapname); - max=(mytab.mapstorage).maxOfEdgeMap(mapname); - actual_map=((mytab.mapstorage).edgemap_storage)[mapname]; - - if(edge==INVALID) - { - for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - double v=fabs((*actual_map)[i]); - int w; - if(min==max) - { - w=(int)(edge_property_defaults[E_WIDTH]); - } - else - { - w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH)); - } - edgesmap[i]->property_width_units().set_value(w); - } - } - else - { - int w=(int)(*actual_map)[edge]; - if(w>=0) - { - edgesmap[edge]->property_width_units().set_value(w); - } - } - return 0; -}; - -int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge) -{ - - //function maps the range of the maximum and - //the minimum of the nodemap to the range of - //green in RGB - Graph::EdgeMap * actual_map; - actual_map=((mytab.mapstorage).edgemap_storage)[mapname]; - - double max, min; - - max=(mytab.mapstorage).maxOfEdgeMap(mapname); - min=(mytab.mapstorage).minOfEdgeMap(mapname); - - if(edge==INVALID) - { - for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - double w=(*actual_map)[i]; - - Gdk::Color color; - if(max!=min) - { - color.set_rgb_p (0, 100*(w-min)/(max-min), 0); - } - else - { - color.set_rgb_p (0, 100, 0); - } - edgesmap[i]->property_fill_color_gdk().set_value(color); - } - } - else - { - Gdk::Color color; - - double w=(*actual_map)[edge]; - - if(max!=min) - { - color.set_rgb_p (0, 100*(w-min)/(max-min), 0); - } - else - { - color.set_rgb_p (0, 100, 0); - } - - edgesmap[edge]->property_fill_color_gdk().set_value(color); - } - return 0; -}; - -int GraphDisplayerCanvas::resetEdgeColor (Edge edge) -{ - - //function maps the range of the maximum and - //the minimum of the nodemap to the range of - //green in RGB - Graph::EdgeMap actual_map((mytab.mapstorage).graph,edge_property_defaults[E_COLOR]); - - double max, min; - - max=edge_property_defaults[E_COLOR]; - min=edge_property_defaults[E_COLOR]; - - if(edge==INVALID) - { - for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - double w=actual_map[i]; - - Gdk::Color color; - if(max!=min) - { - color.set_rgb_p (0, 100*(w-min)/(max-min), 0); - } - else - { - color.set_rgb_p (0, 100, 0); - } - edgesmap[i]->property_fill_color_gdk().set_value(color); - } - } - else - { - Gdk::Color color; - - double w=actual_map[edge]; - - if(max!=min) - { - color.set_rgb_p (0, 100*(w-min)/(max-min), 0); - } - else - { - color.set_rgb_p (0, 100, 0); - } - - edgesmap[edge]->property_fill_color_gdk().set_value(color); - } - return 0; -}; - -int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge) -{ - //the number in the map will be written on the edge - //EXCEPT when the name of the map is Default, because - //in that case empty string will be written, because - //that is the deleter map - - if(edge==INVALID) - { - for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - edgemap_to_edit=mapname; - double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[i]; - - std::ostringstream ostr; - ostr << number; - - edgetextmap[i]->property_text().set_value(ostr.str()); - } - - } - else - { - double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[edge]; - - std::ostringstream ostr; - ostr << number; - - edgetextmap[edge]->property_text().set_value(ostr.str()); - } - - return 0; - -}; - -int GraphDisplayerCanvas::resetEdgeText (Edge edge) -{ - //the number in the map will be written on the edge - //EXCEPT when the name of the map is Default, because - //in that case empty string will be written, because - //that is the deleter map - - if(edge==INVALID) - { - for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - edgemap_to_edit=""; - edgetextmap[i]->property_text().set_value(""); - } - - } - else - { - edgetextmap[edge]->property_text().set_value(""); - } - - return 0; - -}; diff -r a979fcdda073 -r 8e27998e9b1d gui/graph_displayer_canvas-event.cc --- a/gui/graph_displayer_canvas-event.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,862 +0,0 @@ -#include "graph_displayer_canvas.h" -#include - - -bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event) -{ - Gnome::Canvas::CanvasAA::on_expose_event(event); - //usleep(10000); - //rezoom(); - return true; -} - -void GraphDisplayerCanvas::changeEditorialTool(int newtool) -{ - if(actual_tool!=newtool) - { - - actual_handler.disconnect(); - - switch(actual_tool) - { - case CREATE_EDGE: - { - GdkEvent * generated=new GdkEvent(); - generated->type=GDK_BUTTON_RELEASE; - generated->button.button=3; - createEdgeEventHandler(generated); - break; - } - case EDGE_MAP_EDIT: - //has to do the same thing as in the case of NODE_MAP_EDIT - case NODE_MAP_EDIT: - { - break; - } - default: - break; - } - - active_item=NULL; - target_item=NULL; - active_edge=INVALID; - active_node=INVALID; - - - actual_tool=newtool; - - switch(newtool) - { - case MOVE: - actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); - break; - - case CREATE_NODE: - actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false); - break; - - case CREATE_EDGE: - actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false); - break; - - case ERASER: - actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false); - break; - - case EDGE_MAP_EDIT: - grab_focus(); - actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false); - break; - - case NODE_MAP_EDIT: - actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false); - break; - - default: - break; - } - } -} - -int GraphDisplayerCanvas::getActualTool() -{ - return actual_tool; -} - -bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e) -{ - static Gnome::Canvas::Text *coord_text = 0; - switch(e->type) - { - case GDK_BUTTON_PRESS: - //we mark the location of the event to be able to calculate parameters of dragging - window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); - - active_item=(get_item_at(clicked_x, clicked_y)); - active_node=INVALID; - for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - if(nodesmap[i]==active_item) - { - active_node=i; - } - } - switch(e->button.button) - { - case 3: - isbutton=3; - break; - default: - isbutton=1; - break; - } - break; - case GDK_BUTTON_RELEASE: - if (coord_text) - { - delete coord_text; - coord_text = 0; - } - isbutton=0; - active_item=NULL; - active_node=INVALID; - break; - case GDK_MOTION_NOTIFY: - //we only have to do sg. if the mouse button is pressed AND the click was on a node that was found in the set of nodes - if(active_node!=INVALID) - { - (mytab.mapstorage).modified = true; - - //new coordinates will be the old values, - //because the item will be moved to the - //new coordinate therefore the new movement - //has to be calculated from here - - double new_x, new_y; - - window_to_world (e->motion.x, e->motion.y, new_x, new_y); - - double dx=new_x-clicked_x; - double dy=new_y-clicked_y; - - //repositioning node and its text - active_item->move(dx, dy); - nodetextmap[active_node]->move(dx, dy); - - // the new coordinates of the centre of the node - double coord_x = new_x - (clicked_x - (mytab.mapstorage).coords[active_node].x); - double coord_y = new_y - (clicked_y - (mytab.mapstorage).coords[active_node].y); - - // write back the new coordinates to the coords map - (mytab.mapstorage).coords.set(active_node, xy(coord_x, coord_y)); - - clicked_x=new_x; - clicked_y=new_y; - - // reposition the coordinates text - std::ostringstream ostr; - ostr << "(" << - (mytab.mapstorage).coords[active_node].x << ", " << - (mytab.mapstorage).coords[active_node].y << ")"; - double radius = - (nodesmap[active_node]->property_x2().get_value() - - nodesmap[active_node]->property_x1().get_value()) / 2.0; - if (coord_text) - { - coord_text->property_text().set_value(ostr.str()); - coord_text->property_x().set_value((mytab.mapstorage).coords[active_node].x + - radius); - coord_text->property_y().set_value((mytab.mapstorage).coords[active_node].y - - radius); - } - else - { - coord_text = new Gnome::Canvas::Text( - displayed_graph, - (mytab.mapstorage).coords[active_node].x + radius, - (mytab.mapstorage).coords[active_node].y - radius, - ostr.str()); - coord_text->property_fill_color().set_value("black"); - coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST); - } - - //all the edges connected to the moved point has to be redrawn - for(OutEdgeIt ei((mytab.mapstorage).graph,active_node);ei!=INVALID;++ei) - { - XY moved_node_1(coord_x - dx, coord_y - dy); - XY moved_node_2(coord_x, coord_y); - Node target = mytab.mapstorage.graph.target(ei); - XY fix_node(mytab.mapstorage.coords[target].x, - mytab.mapstorage.coords[target].y); - XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]); - - XY arrow_pos; - if(isbutton==3) - arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, false); - else - arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, true); - - mytab.mapstorage.arrow_pos.set(ei, arrow_pos); - edgesmap[ei]->draw(); - - //reposition of edgetext - XY text_pos=mytab.mapstorage.arrow_pos[ei]; - text_pos+=(XY(10,10)); - edgetextmap[ei]->property_x().set_value(text_pos.x); - edgetextmap[ei]->property_y().set_value(text_pos.y); - } - - for(InEdgeIt ei((mytab.mapstorage).graph,active_node);ei!=INVALID;++ei) - { - XY moved_node_1(coord_x - dx, coord_y - dy); - XY moved_node_2(coord_x, coord_y); - Node source = mytab.mapstorage.graph.source(ei); - XY fix_node(mytab.mapstorage.coords[source].x, - mytab.mapstorage.coords[source].y); - XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]); - - XY arrow_pos; - if(isbutton==3) - arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, false); - else - arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, true); - - mytab.mapstorage.arrow_pos.set(ei, arrow_pos); - edgesmap[ei]->draw(); - - //reposition of edgetext - XY text_pos=mytab.mapstorage.arrow_pos[ei]; - text_pos+=(XY(10,10)); - edgetextmap[ei]->property_x().set_value(text_pos.x); - edgetextmap[ei]->property_y().set_value(text_pos.y); - } - } - default: break; - } - - return false; -} - -XY GraphDisplayerCanvas::calcArrowPos(XY moved_node_1, XY moved_node_2, XY fix_node, XY old_arrow_pos, bool move) -{ - if(!move) - { - return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0); - } - else - { - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////// keeps shape-with scalar multiplication - version 2. - ////////////////////////////////////////////////////////////////////////////////////////////////////// - - //old vector from one to the other node - a - xy a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y); - //new vector from one to the other node - b - xy b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y); - - double absa=sqrt(a_v.normSquare()); - double absb=sqrt(b_v.normSquare()); - - if ((absa == 0.0) || (absb == 0.0)) - { - return old_arrow_pos; - } - else - { - //old vector from one node to the breakpoint - c - xy c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y); - - //unit vector with the same direction to a_v - xy a_v_u(a_v.x/absa,a_v.y/absa); - - //normal vector of unit vector with the same direction to a_v - xy a_v_u_n(((-1)*a_v_u.y),a_v_u.x); - - //unit vector with the same direction to b_v - xy b_v_u(b_v.x/absb,b_v.y/absb); - - //normal vector of unit vector with the same direction to b_v - xy b_v_u_n(((-1)*b_v_u.y),b_v_u.x); - - //vector c in a_v_u and a_v_u_n co-ordinate system - xy c_a(c_v*a_v_u,c_v*a_v_u_n); - - //new vector from one node to the breakpoint - d - we have to calculate this one - xy d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n); - - return XY(d_v.x+fix_node.x,d_v.y+fix_node.y); - } - } -} - -bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e) -{ - switch(e->type) - { - //move the new node - case GDK_MOTION_NOTIFY: - { - GdkEvent * generated=new GdkEvent(); - generated->motion.x=e->motion.x; - generated->motion.y=e->motion.y; - generated->type=GDK_MOTION_NOTIFY; - moveEventHandler(generated); - break; - } - - case GDK_BUTTON_RELEASE: - (mytab.mapstorage).modified = true; - - isbutton=1; - - active_node=(mytab.mapstorage).graph.addNode(); - - //initiating values corresponding to new node in maps - - window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); - - // update coordinates - (mytab.mapstorage).coords.set(active_node, xy(clicked_x, clicked_y)); - - // update all other maps - for (std::map*>::const_iterator it = - (mytab.mapstorage).nodemap_storage.begin(); it != - (mytab.mapstorage).nodemap_storage.end(); ++it) - { - if ((it->first != "coordinates_x") && - (it->first != "coordinates_y")) - { - (*(it->second))[active_node] = - (mytab.mapstorage).nodemap_default[it->first]; - } - } - // increment the id map's default value - (mytab.mapstorage).nodemap_default["label"] += 1.0; - - nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, - clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); - active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); - *(nodesmap[active_node]) << - Gnome::Canvas::Properties::fill_color("blue"); - *(nodesmap[active_node]) << - Gnome::Canvas::Properties::outline_color("black"); - active_item->raise_to_top(); - - (nodesmap[active_node])->show(); - - nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph, - clicked_x+node_property_defaults[N_RADIUS]+5, - clicked_y+node_property_defaults[N_RADIUS]+5, ""); - nodetextmap[active_node]->property_fill_color().set_value("darkblue"); - nodetextmap[active_node]->raise_to_top(); - -// mapwin.updateNode(active_node); - propertyUpdate(active_node); - - isbutton=0; - target_item=NULL; - active_item=NULL; - active_node=INVALID; - break; - default: - break; - } - return false; -} - -bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e) -{ - switch(e->type) - { - case GDK_BUTTON_PRESS: - //in edge creation right button has special meaning - if(e->button.button!=3) - { - //there is not yet selected node - if(active_node==INVALID) - { - //we mark the location of the event to be able to calculate parameters of dragging - - window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); - - active_item=(get_item_at(clicked_x, clicked_y)); - active_node=INVALID; - for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - if(nodesmap[i]==active_item) - { - active_node=i; - } - } - //the clicked item is really a node - if(active_node!=INVALID) - { - *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); - isbutton=1; - } - //clicked item was not a node. It could be e.g. edge. - else - { - active_item=NULL; - } - } - //we only have to do sg. if the mouse button - // is pressed already once AND the click was - // on a node that was found in the set of - //nodes, and now we only search for the second - //node - else - { - window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); - target_item=(get_item_at(clicked_x, clicked_y)); - Node target_node=INVALID; - for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - if(nodesmap[i]==target_item) - { - target_node=i; - } - } - //the clicked item is a node, the edge can be drawn - if(target_node!=INVALID) - { - if(target_node!=active_node) - { - (mytab.mapstorage).modified = true; - - *(nodesmap[target_node]) << - Gnome::Canvas::Properties::fill_color("red"); - - //creating new edge - active_edge=(mytab.mapstorage).graph.addEdge(active_node, - target_node); - - // update maps - for (std::map*>::const_iterator it = - (mytab.mapstorage).edgemap_storage.begin(); it != - (mytab.mapstorage).edgemap_storage.end(); ++it) - { - (*(it->second))[active_edge] = - (mytab.mapstorage).edgemap_default[it->first]; - } - // increment the id map's default value - (mytab.mapstorage).edgemap_default["label"] += 1.0; - - //calculating coordinates of new edge - Gnome::Canvas::Points coos; - double x1, x2, y1, y2; - - active_item->get_bounds(x1, y1, x2, y2); - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); - - target_item->get_bounds(x1, y1, x2, y2); - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); - - // set the coordinates of the arrow on the new edge - MapStorage& ms = mytab.mapstorage; - ms.arrow_pos.set(active_edge, - (ms.coords[ms.graph.source(active_edge)] + - ms.coords[ms.graph.target(active_edge)])/ 2.0); - - //drawing new edge - edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge, - *this); - *(edgesmap[active_edge]) << - Gnome::Canvas::Properties::fill_color("green"); - edgesmap[active_edge]->property_width_pixels().set_value(10); - - edgesmap[active_edge]->lower_to_bottom(); - - //initializing edge-text as well, to empty string - XY text_pos=mytab.mapstorage.arrow_pos[active_edge]; - text_pos+=(XY(10,10)); - - edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, - text_pos.x, text_pos.y, ""); - edgetextmap[active_edge]->property_fill_color().set_value( - "darkgreen"); - edgetextmap[active_edge]->raise_to_top(); - - //updating its properties -// mapwin.updateEdge(active_edge); - propertyUpdate(active_edge); - } - else - { - target_node=INVALID; - std::cerr << "Loop edge is not yet implemented!" << std::endl; - } - } - //clicked item was not a node. it could be an e.g. edge. we do not - //deal with it furthermore. - else - { - target_item=NULL; - } - } - } - break; - case GDK_BUTTON_RELEASE: - isbutton=0; - //we clear settings in two cases - //1: the edge is ready (target_item has valid value) - //2: the edge creation is cancelled with right button - if((target_item)||(e->button.button==3)) - { - if(active_item) - { - *active_item << Gnome::Canvas::Properties::fill_color("blue"); - active_item=NULL; - } - if(target_item) - { - *target_item << Gnome::Canvas::Properties::fill_color("blue"); - target_item=NULL; - } - active_node=INVALID; - active_edge=INVALID; - } - break; - default: - break; - } - return false; -} - -bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e) -{ - switch(e->type) - { - case GDK_BUTTON_PRESS: - //finding the clicked items - window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); - active_item=(get_item_at(clicked_x, clicked_y)); - active_node=INVALID; - active_edge=INVALID; - //was it a node? - for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - if(nodesmap[i]==active_item) - { - active_node=i; - } - } - //or was it an edge? - if(active_node==INVALID) - { - for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - if(edgesmap[i]==active_item) - { - active_edge=i; - } - } - } - - // return if the clicked object is neither an edge nor a node - if (active_edge == INVALID) return false; - - //recolor activated item - if(active_item) - { - *active_item << Gnome::Canvas::Properties::fill_color("red"); - } - break; - - case GDK_BUTTON_RELEASE: - window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); - if(active_item) - { - //the cursor was not moved since pressing it - if( active_item == ( get_item_at (clicked_x, clicked_y) ) ) - { - //a node was found - if(active_node!=INVALID) - { - (mytab.mapstorage).modified = true; - - std::set edges_to_delete; - - for(OutEdgeIt e((mytab.mapstorage).graph,active_node);e!=INVALID;++e) - { - edges_to_delete.insert(e); - } - - for(InEdgeIt e((mytab.mapstorage).graph,active_node);e!=INVALID;++e) - { - edges_to_delete.insert(e); - } - - //deleting collected edges - for(std::set::iterator - edge_set_it=edges_to_delete.begin(); - edge_set_it!=edges_to_delete.end(); - ++edge_set_it) - { - deleteItem(*edge_set_it); - } - deleteItem(active_node); - } - //a simple edge was chosen - else if (active_edge != INVALID) - { - deleteItem(active_edge); - } - } - //pointer was moved, deletion is cancelled - else - { - if(active_node!=INVALID) - { - *active_item << Gnome::Canvas::Properties::fill_color("blue"); - } - else if (active_edge != INVALID) - { - *active_item << Gnome::Canvas::Properties::fill_color("green"); - } - } - } - //reseting datas - active_item=NULL; - active_edge=INVALID; - active_node=INVALID; - break; - - case GDK_MOTION_NOTIFY: - break; - - default: - break; - } - return false; -} - -bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e) -{ - if(actual_tool==EDGE_MAP_EDIT) - { - switch(e->type) - { - case GDK_BUTTON_PRESS: - { - //for determine, whether it was an edge - Edge clicked_edge=INVALID; - - window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); - active_item=(get_item_at(clicked_x, clicked_y)); - - //find the activated item between texts - for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - //at the same time only one can be active - if(edgetextmap[i]==active_item) - { - clicked_edge=i; - } - } - - //if it was not between texts, search for it between edges - if(clicked_edge==INVALID) - { - for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - //at the same time only one can be active - if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item)) - { - clicked_edge=i; - } - } - } - - //if it was really an edge... - if(clicked_edge!=INVALID) - { - // the id map is not editable - if (edgemap_to_edit == "label") return 0; - - //and there is activated map - if(edgetextmap[clicked_edge]->property_text().get_value()!="") - { - //activate the general variable for it - active_edge=clicked_edge; - - //create a dialog - Gtk::Dialog dialog("Edit value", true); - dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); - Gtk::VBox* vbox = dialog.get_vbox(); - Gtk::SpinButton spin(0.0, 4); - spin.set_increments(1.0, 10.0); - spin.set_range(-1000000.0, 1000000.0); - spin.set_numeric(true); - vbox->add(spin); - spin.show(); - switch (dialog.run()) - { - case Gtk::RESPONSE_NONE: - case Gtk::RESPONSE_CANCEL: - break; - case Gtk::RESPONSE_ACCEPT: - double new_value = spin.get_value(); - (*(mytab.mapstorage).edgemap_storage[edgemap_to_edit])[active_edge] = - new_value; - std::ostringstream ostr; - ostr << new_value; - edgetextmap[active_edge]->property_text().set_value( - ostr.str()); - //mapwin.updateEdge(active_edge); -// mapwin.updateEdge(Edge(INVALID)); - propertyUpdate(Edge(INVALID)); - } - } - } - break; - } - default: - break; - } - } - return false; -} - -bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e) -{ - if(actual_tool==NODE_MAP_EDIT) - { - switch(e->type) - { - case GDK_BUTTON_PRESS: - { - //for determine, whether it was a node - Node clicked_node=INVALID; - - window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); - active_item=(get_item_at(clicked_x, clicked_y)); - - //find the activated item between texts - for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - //at the same time only one can be active - if(nodetextmap[i]==active_item) - { - clicked_node=i; - } - } - - //if there was not, search for it between nodes - if(clicked_node==INVALID) - { - for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - //at the same time only one can be active - if(nodesmap[i]==active_item) - { - clicked_node=i; - } - } - } - - //if it was really a node... - if(clicked_node!=INVALID) - { - // the id map is not editable - if (nodemap_to_edit == "label") return 0; - - //and there is activated map - if(nodetextmap[clicked_node]->property_text().get_value()!="") - { - //activate the general variable for it - active_node=clicked_node; - - //create a dialog - Gtk::Dialog dialog("Edit value", true); - dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); - Gtk::VBox* vbox = dialog.get_vbox(); - Gtk::SpinButton spin(0.0, 4); - spin.set_increments(1.0, 10.0); - spin.set_range(-1000000.0, 1000000.0); - spin.set_numeric(true); - vbox->add(spin); - spin.show(); - switch (dialog.run()) - { - case Gtk::RESPONSE_NONE: - case Gtk::RESPONSE_CANCEL: - break; - case Gtk::RESPONSE_ACCEPT: - double new_value = spin.get_value(); - (*(mytab.mapstorage).nodemap_storage[nodemap_to_edit])[active_node] = - new_value; - std::ostringstream ostr; - ostr << new_value; - nodetextmap[active_node]->property_text().set_value( - ostr.str()); - //mapwin.updateNode(active_node); -// mapwin.updateNode(Node(INVALID)); - propertyUpdate(Node(INVALID)); - } - } - } - break; - } - default: - break; - } - } - return false; -} - -void GraphDisplayerCanvas::deleteItem(Node node_to_delete) -{ - delete(nodetextmap[node_to_delete]); - delete(nodesmap[node_to_delete]); - (mytab.mapstorage).graph.erase(node_to_delete); -} - -void GraphDisplayerCanvas::deleteItem(Edge edge_to_delete) -{ - delete(edgetextmap[edge_to_delete]); - delete(edgesmap[edge_to_delete]); - (mytab.mapstorage).graph.erase(edge_to_delete); -} - -void GraphDisplayerCanvas::textReposition(xy new_place) -{ - new_place+=(xy(10,10)); - edgetextmap[forming_edge]->property_x().set_value(new_place.x); - edgetextmap[forming_edge]->property_y().set_value(new_place.y); -} - -void GraphDisplayerCanvas::toggleEdgeActivity(BrokenEdge* active_bre, bool on) -{ - if(on) - { - if(forming_edge!=INVALID) - { - std::cerr << "ERROR!!!! Valid edge found!" << std::endl; - } - else - { - for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - if(edgesmap[i]==active_bre) - { - forming_edge=i; - } - } - } - } - else - { - if(forming_edge!=INVALID) - { - forming_edge=INVALID; - } - else - { - std::cerr << "ERROR!!!! Invalid edge found!" << std::endl; - } - } -} diff -r a979fcdda073 -r 8e27998e9b1d gui/graph_displayer_canvas-node.cc --- a/gui/graph_displayer_canvas-node.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,286 +0,0 @@ -#include "graph_displayer_canvas.h" -#include - - -int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node) -{ - Graph::NodeMap * actual_map; - double min, max; - min=(mytab.mapstorage).minOfNodeMap(mapname); - max=(mytab.mapstorage).maxOfNodeMap(mapname); - actual_map=((mytab.mapstorage).nodemap_storage)[mapname]; - - if(node==INVALID) - { - for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - double v=fabs((*actual_map)[i]); - int w; - if(min==max) - { - w=(int)(node_property_defaults[N_RADIUS]); - } - else - { - w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS)); - } - if(w>=0) - { - double x1, y1, x2, y2; - x1=nodesmap[i]->property_x1().get_value(); - x2=nodesmap[i]->property_x2().get_value(); - y1=nodesmap[i]->property_y1().get_value(); - y2=nodesmap[i]->property_y2().get_value(); - nodesmap[i]->property_x1().set_value((x1+x2)/2-w); - nodesmap[i]->property_x2().set_value((x1+x2)/2+w); - nodesmap[i]->property_y1().set_value((y1+y2)/2-w); - nodesmap[i]->property_y2().set_value((y1+y2)/2+w); - } - } - } - else - { - //I think only new nodes use this case -// int w=(int)(*actual_map)[node]; - int w=(int)(node_property_defaults[N_RADIUS]); - if(w>=0) - { - double x1, y1, x2, y2; - x1=nodesmap[node]->property_x1().get_value(); - x2=nodesmap[node]->property_x2().get_value(); - y1=nodesmap[node]->property_y1().get_value(); - y2=nodesmap[node]->property_y2().get_value(); - nodesmap[node]->property_x1().set_value((x1+x2)/2-w); - nodesmap[node]->property_x2().set_value((x1+x2)/2+w); - nodesmap[node]->property_y1().set_value((y1+y2)/2-w); - nodesmap[node]->property_y2().set_value((y1+y2)/2+w); - } - } - return 0; -}; - -int GraphDisplayerCanvas::resetNodeRadius (Node node) -{ - double min, max; - min=node_property_defaults[N_RADIUS]; - max=node_property_defaults[N_RADIUS]; - Graph::NodeMap actual_map((mytab.mapstorage).graph,node_property_defaults[N_RADIUS]); - - if(node==INVALID) - { - for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - double v=fabs(actual_map[i]); - int w; - if(min==max) - { - w=(int)(node_property_defaults[N_RADIUS]); - } - else - { - w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS)); - } - if(w>=0) - { - double x1, y1, x2, y2; - x1=nodesmap[i]->property_x1().get_value(); - x2=nodesmap[i]->property_x2().get_value(); - y1=nodesmap[i]->property_y1().get_value(); - y2=nodesmap[i]->property_y2().get_value(); - nodesmap[i]->property_x1().set_value((x1+x2)/2-w); - nodesmap[i]->property_x2().set_value((x1+x2)/2+w); - nodesmap[i]->property_y1().set_value((y1+y2)/2-w); - nodesmap[i]->property_y2().set_value((y1+y2)/2+w); - } - } - } - else - { - //I think only new nodes use this case -// int w=(int)actual_map[node]; - int w=(int)(node_property_defaults[N_RADIUS]); - if(w>=0) - { - double x1, y1, x2, y2; - x1=nodesmap[node]->property_x1().get_value(); - x2=nodesmap[node]->property_x2().get_value(); - y1=nodesmap[node]->property_y1().get_value(); - y2=nodesmap[node]->property_y2().get_value(); - nodesmap[node]->property_x1().set_value((x1+x2)/2-w); - nodesmap[node]->property_x2().set_value((x1+x2)/2+w); - nodesmap[node]->property_y1().set_value((y1+y2)/2-w); - nodesmap[node]->property_y2().set_value((y1+y2)/2+w); - } - } - return 0; -}; - -int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node) -{ - - //function maps the range of the maximum and - //the minimum of the nodemap to the range of - //green in RGB - - Graph::NodeMap * actual_map; - actual_map=((mytab.mapstorage).nodemap_storage)[mapname]; - - double max, min; - - max=(mytab.mapstorage).maxOfNodeMap(mapname); - min=(mytab.mapstorage).minOfNodeMap(mapname); - - if(node==INVALID) - { - - for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - Gdk::Color color; - - double w=(*actual_map)[i]; - - if(max!=min) - { - color.set_rgb_p (0, 0, 100*(w-min)/(max-min)); - } - else - { - color.set_rgb_p (0, 0, 100); - } - - nodesmap[i]->property_fill_color_gdk().set_value(color); - } - } - else - { - Gdk::Color color; - - double w=(*actual_map)[node]; - - if(max!=min) - { - color.set_rgb_p (0, 0, 100*(w-min)/(max-min)); - } - else - { - color.set_rgb_p (0, 0, 100); - } - - nodesmap[node]->property_fill_color_gdk().set_value(color); - } - return 0; -}; - -int GraphDisplayerCanvas::resetNodeColor (Node node) -{ - - //function maps the range of the maximum and - //the minimum of the nodemap to the range of - //green in RGB - - Graph::NodeMap actual_map((mytab.mapstorage).graph,node_property_defaults[N_COLOR]); - - double max, min; - - max=node_property_defaults[N_COLOR]; - min=node_property_defaults[N_COLOR]; - - if(node==INVALID) - { - - for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - Gdk::Color color; - - double w=actual_map[i]; - - if(max!=min) - { - color.set_rgb_p (0, 0, 100*(w-min)/(max-min)); - } - else - { - color.set_rgb_p (0, 0, 100); - } - - nodesmap[i]->property_fill_color_gdk().set_value(color); - } - } - else - { - Gdk::Color color; - - double w=actual_map[node]; - - if(max!=min) - { - color.set_rgb_p (0, 0, 100*(w-min)/(max-min)); - } - else - { - color.set_rgb_p (0, 0, 100); - } - - nodesmap[node]->property_fill_color_gdk().set_value(color); - } - return 0; -}; - -int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node) -{ - - //the number in the map will be written on the node - //EXCEPT when the name of the map is Text, because - //in that case empty string will be written, because - //that is the deleter map - - Graph::NodeMap * actual_map=NULL; - actual_map=((mytab.mapstorage).nodemap_storage)[mapname]; - - if(node==INVALID) - { - for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - nodemap_to_edit=mapname; - double number=(*actual_map)[i]; - - std::ostringstream ostr; - ostr << number; - - nodetextmap[i]->property_text().set_value(ostr.str()); - } - } - else - { - double number=(*actual_map)[node]; - - std::ostringstream ostr; - ostr << number; - - nodetextmap[node]->property_text().set_value(ostr.str()); - } - return 0; -}; - -int GraphDisplayerCanvas::resetNodeText (Node node) -{ - - //the number in the map will be written on the node - //EXCEPT when the name of the map is Text, because - //in that case empty string will be written, because - //that is the deleter map - - if(node==INVALID) - { - for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - nodemap_to_edit=""; - nodetextmap[i]->property_text().set_value(""); - } - } - else - { - nodetextmap[node]->property_text().set_value(""); - } - return 0; -}; diff -r a979fcdda073 -r 8e27998e9b1d gui/graph_displayer_canvas-zoom.cc --- a/gui/graph_displayer_canvas-zoom.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -#include "graph_displayer_canvas.h" -#include - -void GraphDisplayerCanvas::zoomIn() -{ - set_pixels_per_unit( - (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit()); -} - -void GraphDisplayerCanvas::zoomOut() -{ - set_pixels_per_unit( - (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit()); -} - -void GraphDisplayerCanvas::zoomFit() -{ - updateScrollRegion(); - - // get the height and width of the canvas - Gtk::Allocation a = get_allocation(); - int aw = a.get_width(); - int ah = a.get_height(); - - // get the bounding box of the graph - update_now(); - double x1, y1, x2, y2; - root()->get_bounds(x1, y1, x2, y2); - - // fit the graph to the window - double ppu1 = (double) aw / fabs(x2 - x1); - double ppu2 = (double) ah / fabs(y2 - y1); - set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2); -} - -void GraphDisplayerCanvas::zoom100() -{ - updateScrollRegion(); - set_pixels_per_unit(1.0); -} - -void GraphDisplayerCanvas::updateScrollRegion() -{ - // get_bounds() yields something sane only when no updates are pending - // and it returns a sufficient, not an exact bounding box - update_now(); - double x1, y1, x2, y2; - root()->get_bounds(x1, y1, x2, y2); - set_scroll_region(x1, y1, x2, y2); -} diff -r a979fcdda073 -r 8e27998e9b1d gui/graph_displayer_canvas.cc --- a/gui/graph_displayer_canvas.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,236 +0,0 @@ -#include "graph_displayer_canvas.h" -#include - -GraphDisplayerCanvas::GraphDisplayerCanvas(NoteBookTab & mainw) : - nodesmap(mainw.mapstorage.graph), edgesmap(mainw.mapstorage.graph), edgetextmap(mainw.mapstorage.graph), - nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0), - isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""), - edgemap_to_edit(""), mytab(mainw) -{ - //base event handler is move tool - actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); - actual_tool=MOVE; - - active_node=INVALID; - active_edge=INVALID; - forming_edge=INVALID; -} - -GraphDisplayerCanvas::~GraphDisplayerCanvas() -{ - for (NodeIt n((mytab.mapstorage).graph); n != INVALID; ++n) - { - delete nodesmap[n]; - delete nodetextmap[n]; - } - - for (EdgeIt e((mytab.mapstorage).graph); e != INVALID; ++e) - { - delete edgesmap[e]; - delete edgetextmap[e]; - } -} - -void GraphDisplayerCanvas::propertyChange(bool itisedge, int prop) -{ - if(itisedge) - { - propertyUpdate(Edge(INVALID), prop); - } - else - { - propertyUpdate(Node(INVALID), prop); - } -} - -void GraphDisplayerCanvas::propertyUpdate(Edge edge) -{ - for(int i=0;iproperty_width_units().set_value(10); - edgesmap[i]->lower_to_bottom(); - - //initializing edge-text as well, to empty string - - XY text_pos=mytab.mapstorage.arrow_pos[i]; - text_pos+=(XY(10,10)); - - edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, ""); - edgetextmap[i]->property_fill_color().set_value("darkgreen"); - edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false); - edgetextmap[i]->raise_to_top(); - } - - //afterwards nodes come to be drawn - - for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) - { - //drawing bule nodes, with black line around them - - nodesmap[i]=new Gnome::Canvas::Ellipse( - displayed_graph, - (mytab.mapstorage).coords[i].x-20, - (mytab.mapstorage).coords[i].y-20, - (mytab.mapstorage).coords[i].x+20, - (mytab.mapstorage).coords[i].y+20); - *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue"); - *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black"); - nodesmap[i]->raise_to_top(); - - //initializing edge-text as well, to empty string - - xy text_pos( - ((mytab.mapstorage).coords[i].x+node_property_defaults[N_RADIUS]+5), - ((mytab.mapstorage).coords[i].y+node_property_defaults[N_RADIUS]+5)); - - nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, - text_pos.x, text_pos.y, ""); - nodetextmap[i]->property_fill_color().set_value("darkblue"); - nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false); - nodetextmap[i]->raise_to_top(); - } - - updateScrollRegion(); -} - -void GraphDisplayerCanvas::clear() -{ - active_node=INVALID; - active_edge=INVALID; - forming_edge=INVALID; - - for (NodeIt n((mytab.mapstorage).graph); n != INVALID; ++n) - { - delete nodesmap[n]; - delete nodetextmap[n]; - } - - for (EdgeIt e((mytab.mapstorage).graph); e != INVALID; ++e) - { - delete edgesmap[e]; - delete edgetextmap[e]; - } -} diff -r a979fcdda073 -r 8e27998e9b1d gui/graph_displayer_canvas.h --- a/gui/graph_displayer_canvas.h Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,357 +0,0 @@ -// -*- C++ -*- // - -#ifndef GRAPH_DISPLAYER_CANVAS_H -#define GRAPH_DISPLAYER_CANVAS_H - -class GraphDisplayerCanvas; - -#include "all_include.h" -#include "nbtab.h" -#include -#include -#include - -///This class is the canvas, on which the graph can be drawn. -class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA -{ - friend class BrokenEdge; - - ///Edge displayer class - - ///This class is responsible for displaying edges in graph. - ///The displayed edge is broken in the middle. The - ///aim of this is to be able to indicate direction of edges - ///and to be able to display more then one edges between the - ///same source and target - class BrokenEdge : public Gnome::Canvas::Line - { - ///The edge that the class displays. - - ///It is needed, because some datas needed from - ///graph can be accessed by this or should be sent - ///as parameter, but it would be complicated - Edge edge; - - ///Reference to the canvas, on which the graph is drawn. - - ///It is needed, because some datas needed from - ///graph can be accessed by this or should be sent - ///as parameter, but it would be complicated - GraphDisplayerCanvas & gdc; - - ///An arrow that indicates the direction of the edges - - ///in case of directional graph direction can be indicated - ///by this polygon. The polygon formulates a red arrow. - Gnome::Canvas::Polygon * arrow; - - ///Indicates whether the button of mouse is pressed or not at the moment. - bool isbutton; - - ///At this location was the mousebutton pressed. Horizontal component. - - ///It helps to calculate the - ///distance of dragging. - double clicked_x; - - ///At this location was the mousebutton pressed. Vertical component. - - ///It helps to calculate the - ///distance of dragging. - double clicked_y; - - ///event handler for forming broken edges - - ///\param event the - ///event to handle - bool edgeFormerEventHandler(GdkEvent* event); - public: - - ///Constructor of broken edge class. - - ///\param g the group to which the edge belongs - ///\param _edge the represented edge - ///\param gc the canvas - BrokenEdge(Gnome::Canvas::Group & g, Edge _edge, GraphDisplayerCanvas & gc); - - ///Destructor of broken edge class - - ///Frees up - ///reserved memory - ~BrokenEdge(); - - ///The function that draws the edge based on collected data - void draw(); - }; - - ///Type of canvas, on which the graph is drawn - typedef Gnome::Canvas::CanvasAA Parent; - -public: - ///Constructor - - ///\param nbt the tab of the window, in which the graph is displayed - GraphDisplayerCanvas(NoteBookTab & nbt); - - ///destructor of the class - virtual ~GraphDisplayerCanvas(); - - ///Changes the width of edge(s) according to the given map. - - ///\param mapname is the name of the map which contains the values to be set - ///\param edge if it is given, only the width of the given edge will be set, instead of all of them. - int changeEdgeWidth (std::string mapname, Edge edge=INVALID); - - ///Resets width of edge(s) to the default value - - ///\param edge if it is given, only the width of the - ///given edge will be reset, instead of all of them. - int resetEdgeWidth (Edge edge=INVALID); - - ///Changes the color of edge(s) according to the given map. - - ///\param mapname is the name of the map which contains the new values - ///\param edge if it is given, only the color of the given edge will be set, instead of all of them. - int changeEdgeColor (std::string mapname, Edge edge=INVALID); - - ///Resets color of edge(s) to the default value - - ///\param edge if it is given, only the color of the - ///given edge will be reset, instead of all of them. - int resetEdgeColor (Edge edge=INVALID); - - ///Changes the label of edge(s) according to the given map. - - ///\param mapname is the name of the map which contains the new values - ///\param edge if it is given, only the label of the given edge will be set, instead of all of them. - int changeEdgeText (std::string mapname, Edge edge=INVALID); - - ///Resets label of edge(s) to the default value - - ///\param edge if it is given, only the color of the - ///given edge will be reset, instead of all of them. - int resetEdgeText (Edge edge=INVALID); - - ///Changes the radius of node(s) according to the given map. - - ///\param mapname is the name of the map which contains the new values - ///\param node if it is given, only the radius of the given node will be set, instead of all of them. - int changeNodeRadius (std::string mapname, Node node=INVALID); - - ///Resets radius of node(s) to the default value - - ///\param node if it is given, only the radius of the - ///given node will be reset, instead of all of them. - int resetNodeRadius (Node node=INVALID); - - ///Changes the color of node(s) according to the given map. - - ///\param mapname is the name of the map which contains the new values - ///\param node if it is given, only the color of the given node will be set, instead of all of them. - int changeNodeColor (std::string mapname, Node node=INVALID); - - ///Resets color of node(s) to the default value - - ///\param node if it is given, only the color of the - ///given node will be reset, instead of all of them. - int resetNodeColor (Node node=INVALID); - - ///Changes the label of node(s) according to the given map. - - ///\param mapname is the name of the map which contains the new values - ///\param node if it is given, only the label of the given node will be set, instead of all of them. - int changeNodeText (std::string mapname, Node node=INVALID); - - ///Resets label of node(s) to the default value - - ///\param node if it is given, only the label of the - ///given node will be reset, instead of all of them. - int resetNodeText (Node node=INVALID); - - ///This function is called, when any of the displayed attributes have to be updated, or changed - - ///\param itisedge if true, edge property has to be changed, else node property - ///\param prop the id of property that has to changed or updated - void propertyChange(bool itisedge, int prop); - - ///updates the given property - - ///\param edge if it is not INVALID, only the property of the given edge will be updated, instead of all of them - ///\param prop the property to update - void propertyUpdate(Edge edge, int prop); - - ///updates the given property - - ///\param node if it is not INVALID, only the property of the given node will be updated, instead of all of them - ///\param prop the property to update - void propertyUpdate(Node node, int prop); - - ///updates all the property for the given edge - void propertyUpdate(Edge); - - ///updates all the property for the given node - void propertyUpdate(Node); - - ///Callback for 'ViewZoomIn' action. - virtual void zoomIn(); - ///Callback for 'ViewZoomOut' action. - virtual void zoomOut(); - ///Callback for 'ViewZoomFit' action. - virtual void zoomFit(); - ///Callback for 'ViewZoom100' action. - virtual void zoom100(); - ///Sets the scroll region of the convas to the bounding box of the graph. - void updateScrollRegion(); - - ///This function changes the tool in the graph-editor's hand - void changeEditorialTool(int); - -protected: - - //maximizing, minimizing, restoring window, etc. - virtual bool on_expose_event(GdkEventExpose *); - -private: - - ///This function is responsible for the correct - ///reaction of any action happened in the territory - ///of the canvas - ///DEPRECATED!!!! - bool eventHandler(GdkEvent* e, Node n); - - ///actual event handler - /// - ///Actual event handler should be stored, to be able to disconnect it and later reconnect it. - sigc::connection actual_handler; - - ///event handler for the case when move-tool is active - bool moveEventHandler(GdkEvent*); - ///event handler for the case when create_node-tool is active - bool createNodeEventHandler(GdkEvent*); - ///event handler for the case when create_edge-tool is active - bool createEdgeEventHandler(GdkEvent*); - ///event handler for the case when eraser-tool is active - bool eraserEventHandler(GdkEvent*); - ///event handler for the case when edge map editor tool is active - bool edgeMapEditEventHandler(GdkEvent*); - ///event handler for the case when node map editor tool is active - bool nodeMapEditEventHandler(GdkEvent*); - -public: - ///Moves the text to new place - void textReposition(xy); - - ///Activates an edge belonging to a BrokenEdge - - ///After we have activated an edge this way, - ///the GDC object will know, which edge is under forming - ///therefore it can redraw the necessary elements on the canvas, - ///for example the text belonging to the \ref BrokenEdge can be - ///redrawn (\ref textReposition). - void toggleEdgeActivity(BrokenEdge*, bool); - -public: - - ///Returns the actual tool in hand - int getActualTool(); - - ///draws the graph - - ///Called when opening a file. - void drawGraph(); - - ///Clears the canvas - - ///It achieves this by deleting all data - ///structure used to help handle the displayed graph. - void clear(); - - ///creates a new Nodemap - - ///\param init initial value of the map - ///\param mapname name of new map - int addNewNodeMap(double init,std::string mapname); - ///creates a new Edgemap - - ///\param init initial value of the map - ///\param mapname name of new map - int addNewEdgeMap(double init,std::string mapname); - -private: - ///Deletes the given element. - void deleteItem(Node); - ///Deletes the given element. - void deleteItem(Edge); - -private: - - ///Map of nodes of graph - Graph::NodeMap nodesmap; - - ///Map of edges of graph - Graph::EdgeMap edgesmap; - - ///Map of texts to write on edges - Graph::EdgeMap edgetextmap; - - ///Map of texts to write on nodes - Graph::NodeMap nodetextmap; - - ///Group of graphical elements of displayed_graph - Gnome::Canvas::Group displayed_graph; - -private: - ///Indicates whether the button of mouse is pressed or not - int isbutton; - - ///Stores the actual tool in hand - int actual_tool; - - ///At this location was the mousebutton pressed. - ///It helps to calculate the distance of dragging. - double clicked_x, clicked_y; - - ///Remembers which Gnome::Canvas::Item was pressed. - - ///this variable is needed, to work on it after selection - Gnome::Canvas::Item * active_item; - - ///Remembers which Gnome::Canvas::Item was pressed. - - ///this variable is used at edge creation, it will - ///be the secondly selected node. No local variable - ///can be used for this purpose inside the function, - ///because the node selected by button press, and - ///the edge is created by button release. Both of - ///them is different function call. - Gnome::Canvas::Item * target_item; - - ///selected node (for any editing) - Node active_node; - - ///selected edge (for any editing) - Edge active_edge; - - ///the edge that is selected by clicking on the red arrow in the middle of it - - ///This edge is stored only for the purpose of reshape it. - ///That is why it is selected in a different manner. - Edge forming_edge; - - ///Map displayed by label can be edited. - std::string nodemap_to_edit; - - ///Map displayed by label can be edited. - std::string edgemap_to_edit; - - static const int zoom_step = 5; - -private: - - ///reference to the container, in which the canvas is - NoteBookTab & mytab; - - XY calcArrowPos(XY, XY, XY, XY, bool); -}; - -#endif //GRAPH_DISPLAYER_CANVAS_H diff -r a979fcdda073 -r 8e27998e9b1d gui/graphocska.lgf --- a/gui/graphocska.lgf Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -@nodeset -label coordinates_x coordinates_y data -1 230 -80 1.123 -2 230 100 3.234 -3 120 -80 5.345 -4 120 100 7.456 -5 20 100 9.567 -6 20 -80 11.678 -7 -40 10 13.789 -8 -100 100 15.890 -9 -100 10 17.901 -10 -100 -80 19.012 -11 -200 -80 21.000 -12 -200 10 23.001 -13 -200 100 25.003 -14 -300 100 27.004 -15 -300 -80 29.9999 - -@edgeset - cap map1 map2 map3 map4 -15 14 1 21 111 231 3 -14 13 2 22 112 232 6 -13 12 3 23 113 233 9 -13 8 4 24 114 234 12 -12 11 5 25 115 235 15 -12 9 6 26 116 236 18 -11 10 7 27 117 237 21 -10 9 8 28 118 238 24 -10 7 9 29 119 239 27 -9 8 10 30 120 230 30 -7 6 11 31 121 241 33 -6 5 12 32 122 242 36 -6 3 13 33 123 243 39 -5 4 14 34 124 244 42 -4 3 15 35 125 245 45 -3 2 16 36 126 246 48 -2 1 17 37 127 247 51 - -@end \ No newline at end of file diff -r a979fcdda073 -r 8e27998e9b1d gui/gui_reader.cc --- a/gui/gui_reader.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -#include "gui_reader.h" -#include "xml.h" -#include "mapstorage.h" -#include -#include - -bool GuiReader::header(const std::string& line) -{ - std::istringstream ls(line); - std::string head; - ls >> head; - return head == "@gui"; -} - -void GuiReader::read(std::istream& is) -{ - XmlIo x(is); - std::map > m; - x("arrow_pos", m); - - if ((int)m.size() != countEdges(mapstorage->graph)) return; - - for (EdgeIt e(mapstorage->graph); e != INVALID; ++e) - { - int edgeid = (int)(*mapstorage->edgemap_storage["label"])[e]; - mapstorage->arrow_pos.set(e, m[edgeid]); - } - mapstorage->ArrowPosReadOK(); -} - -GuiReader::GuiReader(LemonReader& reader, MapStorage* ms) : Parent(reader), mapstorage(ms) -{ -} diff -r a979fcdda073 -r 8e27998e9b1d gui/gui_reader.h --- a/gui/gui_reader.h Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -#ifndef GUI_READER_H -#define GUI_READER_H - -#include "mapstorage.h" -#include - -using lemon::LemonReader; - -class GuiReader : public LemonReader::SectionReader -{ - private: - MapStorage* mapstorage; - protected: - virtual bool header(const std::string&); - virtual void read(std::istream&); - public: - typedef LemonReader::SectionReader Parent; - GuiReader(LemonReader&, MapStorage*); -}; - -#endif diff -r a979fcdda073 -r 8e27998e9b1d gui/gui_writer.cc --- a/gui/gui_writer.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -#include "gui_writer.h" -#include "xml.h" -#include "mapstorage.h" -#include -#include - -std::string GuiWriter::header() -{ - return "@gui"; -} - -void GuiWriter::write(std::ostream& os) -{ - XmlIo x(os); - std::map > m; - for (EdgeIt e(mapstorage->graph); e != INVALID; ++e) - { - int edgeid = (int)(*(mapstorage->edgemap_storage["label"]))[e]; - m[edgeid] = mapstorage->arrow_pos[e]; - } - x("arrow_pos", m); -} - -GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) : Parent(writer), mapstorage(ms) -{ -} diff -r a979fcdda073 -r 8e27998e9b1d gui/gui_writer.h --- a/gui/gui_writer.h Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -#ifndef GUI_WRITER_H -#define GUI_WRITER_H - -#include "mapstorage.h" -#include - -using lemon::LemonWriter; - -class GuiWriter : public LemonWriter::SectionWriter -{ - private: - MapStorage* mapstorage; - protected: - virtual std::string header(); - virtual void write(std::ostream&); - public: - typedef LemonWriter::SectionWriter Parent; - GuiWriter(LemonWriter&, MapStorage*); -}; - -#endif diff -r a979fcdda073 -r 8e27998e9b1d gui/i18n.h --- a/gui/i18n.h Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -#ifndef I18N_H -#define I18N_H - -#include "gettext.h" -#define _(string) gettext (string) - -#endif diff -r a979fcdda073 -r 8e27998e9b1d gui/icons/addlink.png Binary file gui/icons/addlink.png has changed diff -r a979fcdda073 -r 8e27998e9b1d gui/icons/addnode.png Binary file gui/icons/addnode.png has changed diff -r a979fcdda073 -r 8e27998e9b1d gui/icons/delete.png Binary file gui/icons/delete.png has changed diff -r a979fcdda073 -r 8e27998e9b1d gui/icons/editlink.png Binary file gui/icons/editlink.png has changed diff -r a979fcdda073 -r 8e27998e9b1d gui/icons/editnode.png Binary file gui/icons/editnode.png has changed diff -r a979fcdda073 -r 8e27998e9b1d gui/icons/move.png Binary file gui/icons/move.png has changed diff -r a979fcdda073 -r 8e27998e9b1d gui/icons/newmap.png Binary file gui/icons/newmap.png has changed diff -r a979fcdda073 -r 8e27998e9b1d gui/kruskalbox.cc --- a/gui/kruskalbox.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -#include - -enum {INPUT, OUTPUT, MAP_NUM}; - -KruskalBox::KruskalBox(std::vector t):AlgoBox() -{ - init(t); -} - -void KruskalBox::run() -{ - if( - tabcbt.get_active_text()!="" && - (edgemapcbts[INPUT])->get_active_text()!="" && - (edgemapcbts[OUTPUT])->get_active_text()!="" - ) - { - - Graph g=mapstorage->graph; - Graph::EdgeMap * inputmap= - ((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]); - Graph::EdgeMap outputmap(g); - double res=kruskal(g, *inputmap, outputmap); - - for (EdgeIt i(g); i!=INVALID; ++i) - { - if(outputmap[i]) - { - (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])-> - get_active_text()]))[i]=1; - } - else - { - (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])-> - get_active_text()]))[i]=0; - } - } - - std::ostringstream o; - o << "Result: " << res; - resultlabel.set_text(o.str()); - - mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text()); - // mapstorage->changeActiveMap(true, E_COLOR, - // (edgemapcbts[OUTPUT])->get_active_text()); - // mapstorage->changeActiveMap(true, E_TEXT, - // (edgemapcbts[INPUT])->get_active_text()); - - } -} - -void KruskalBox::build_box() -{ - std::vector empty_vector; - - addMapSelector("Edgecosts: ", true); - addMapSelector("Edges of tree here: ", true); - - resultlabel.set_text("Result: algorithm is not run yet."); - pack_start(resultlabel); -} diff -r a979fcdda073 -r 8e27998e9b1d gui/kruskalbox.h --- a/gui/kruskalbox.h Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -// -*- C++ -*- // - -#ifndef KRUSKALBOX_H -#define KRUSKALBOX_H - -class KruskalBox; - -#include -#include -#include -#include -#include - -///Graphical interface to run Kruskal algorithm. - -///Child of \ref AlgoBox, -///therefore the only task to do at implementation was to -/// -///-call init function with correct parameters from correctly parametrized constructor -/// -///-implement \ref build_box function -/// -///-implement \ref run function -class KruskalBox : public AlgoBox -{ - ///Shows result of Kruskal algorithm - Gtk::Label resultlabel; - -public: - ///Calls \ref AlgoBox::init function to initialize class properly, automatically. - KruskalBox(std::vector t); - - ///Prepare, run and postprocess Kruskal algorithm. - - ///\ref glemon works only with maps filled with double values - ///at the moment. While Kruskal nedds a bool map as output. - ///As postprocess this bool map should be transformed to - ///double map. - void run(); - - ///Builds the graphical design of the interface. - void build_box(); -}; -#endif //KRUSKALBOX_H diff -r a979fcdda073 -r 8e27998e9b1d gui/main_win.cc --- a/gui/main_win.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,489 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "main_win.h" -#include "guipixbufs.h" - -#include "i18n.h" - -MainWin::MainWin() -{ - set_title ("no file"); - set_default_size(WIN_WIDTH,WIN_HEIGHT); - add(vbox); - - // custom icons for the toolbar - Glib::RefPtr p_icon_factory = Gtk::IconFactory::create(); - - Glib::RefPtr p_move_pixbuf = Gdk::Pixbuf::create_from_inline( - 2328, gui_icons_move); - Glib::RefPtr p_addnode_pixbuf = Gdk::Pixbuf::create_from_inline( - 2328, gui_icons_addnode); - Glib::RefPtr p_addlink_pixbuf = Gdk::Pixbuf::create_from_inline( - 2328, gui_icons_addlink); - Glib::RefPtr p_delete_pixbuf = Gdk::Pixbuf::create_from_inline( - 2328, gui_icons_delete); - Glib::RefPtr p_editlink_pixbuf = Gdk::Pixbuf::create_from_inline( - 2328, gui_icons_editlink); - Glib::RefPtr p_editnode_pixbuf = Gdk::Pixbuf::create_from_inline( - 2328, gui_icons_editnode); - Glib::RefPtr p_newmap_pixbuf = Gdk::Pixbuf::create_from_inline( - 2328, gui_icons_newmap); - - Gtk::IconSource move_icon_source; - move_icon_source.set_pixbuf(p_move_pixbuf); - Gtk::IconSet move_icon_set; - move_icon_set.add_source(move_icon_source); - p_icon_factory->add(Gtk::StockID("gd-move"), move_icon_set); - - Gtk::IconSource addnode_icon_source; - addnode_icon_source.set_pixbuf(p_addnode_pixbuf); - Gtk::IconSet addnode_icon_set; - addnode_icon_set.add_source(addnode_icon_source); - p_icon_factory->add(Gtk::StockID("gd-addnode"), addnode_icon_set); - - Gtk::IconSource addlink_icon_source; - addlink_icon_source.set_pixbuf(p_addlink_pixbuf); - Gtk::IconSet addlink_icon_set; - addlink_icon_set.add_source(addlink_icon_source); - p_icon_factory->add(Gtk::StockID("gd-addlink"), addlink_icon_set); - - Gtk::IconSource delete_icon_source; - delete_icon_source.set_pixbuf(p_delete_pixbuf); - Gtk::IconSet delete_icon_set; - delete_icon_set.add_source(delete_icon_source); - p_icon_factory->add(Gtk::StockID("gd-delete"), delete_icon_set); - - Gtk::IconSource editlink_icon_source; - editlink_icon_source.set_pixbuf(p_editlink_pixbuf); - Gtk::IconSet editlink_icon_set; - editlink_icon_set.add_source(editlink_icon_source); - p_icon_factory->add(Gtk::StockID("gd-editlink"), editlink_icon_set); - - Gtk::IconSource editnode_icon_source; - editnode_icon_source.set_pixbuf(p_editnode_pixbuf); - Gtk::IconSet editnode_icon_set; - editnode_icon_set.add_source(editnode_icon_source); - p_icon_factory->add(Gtk::StockID("gd-editnode"), editnode_icon_set); - - Gtk::IconSource newmap_icon_source; - newmap_icon_source.set_pixbuf(p_newmap_pixbuf); - Gtk::IconSet newmap_icon_set; - newmap_icon_set.add_source(newmap_icon_source); - p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set); - - p_icon_factory->add_default(); - - ag=Gtk::ActionGroup::create(); - - ag->add( Gtk::Action::create("FileMenu", _("_File")) ); - ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW), - sigc::mem_fun(*this, &MainWin::newTab)); - ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN), - sigc::mem_fun(*this, &MainWin::openFile)); - ag->add( Gtk::Action::create("FileClearTab", _("Clear Tab")), - sigc::mem_fun(*this, &MainWin::newFile)); - ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE), - sigc::mem_fun(*this, &MainWin::saveFile)); - ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS), - sigc::mem_fun(*this, &MainWin::saveFileAs)); - ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE), - sigc::mem_fun(*this, &MainWin::closeTab)); - ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT), - sigc::mem_fun(*this, &MainWin::hide)); - - ag->add( Gtk::Action::create("ViewMenu", _("_View")) ); - ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN), - sigc::mem_fun(*this, &MainWin::zoomIn)); - ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT), - sigc::mem_fun(*this, &MainWin::zoomOut)); - ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT), - 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("ShowMenu", _("_Show")) ); - ag->add( Gtk::Action::create("ShowMaps", _("_Maps")), - sigc::mem_fun(*this, &MainWin::createMapWin)); - - ag->add( Gtk::Action::create("AlgoMenu", _("_Algorithms")) ); - ag->add( Gtk::Action::create("AlgoGeneral", _("_General")), - sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 0) ); - ag->add( Gtk::Action::create("AlgoKruskal", _("_Kruskal")), - sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 1) ); - - Gtk::RadioAction::Group tool_group; - ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), _("Move")), - sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) ); - ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), _("Create node")), - sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) ); - ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), _("Create edge")), - sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) ); - ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), _("Delete")), - sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) ); - - ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), _("Edit edge map")), - sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) ); - ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), _("Edit node map")), - sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 5) ); - - ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")), - sigc::mem_fun ( *this , &MainWin::createNewMapWin ) ); - - uim=Gtk::UIManager::create(); - uim->insert_action_group(ag); - add_accel_group(uim->get_accel_group()); - - try - { - - Glib::ustring ui_info = - "" - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - ""; - - uim->add_ui_from_string(ui_info); - - } - catch(const Glib::Error& ex) - { - std::cerr << "building menus failed: " << ex.what(); - } - - Gtk::Widget* menubar = uim->get_widget("/MenuBar"); - if (menubar){ - vbox.pack_start(*menubar, Gtk::PACK_SHRINK); - } - - Gtk::Widget* toolbar = uim->get_widget("/ToolBar"); - if (toolbar) - { - static_cast(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS); - vbox.pack_start(*toolbar, Gtk::PACK_SHRINK); - } - - tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node"); - tooltips.enable(); - - active_tab=-1; - notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab)); - - active_tool = MOVE; - - vbox.pack_start(notebook); - - show_all_children(); -} - -void MainWin::set_tabtitle(std::string name) -{ - if(strinst.find(name)==strinst.end()) - { - tabnames[active_tab]=name; - strinst[name]=1; - } - else - { - strinst[name]++; - std::ostringstream o; - o << strinst[name]; - tabnames[active_tab]=name+" - "+o.str(); - } - set_title(tabnames[active_tab] + " - " + prog_name); - notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]); - updateAlgoWinTabs(); -} - -void MainWin::readFile(const std::string & filename) -{ - newTab(); - tabs[active_tab]->readFile(filename); -} - -void MainWin::newTab() -{ - int size=tabs.size(); - tabs.resize(size+1); - tabnames.resize(size+1); - active_tab=size; - tabs[active_tab]=new NoteBookTab(); - tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle)); - tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal)); - tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool); - notebook.append_page((Gtk::Widget&)(*(tabs[active_tab]))); - notebook.set_current_page(size); - set_tabtitle(_("unsaved file")); - updateAlgoWinTabs(); -} - -void MainWin::closeTab() -{ - if(active_tab!=-1) - { - if (tabs[active_tab]->mapstorage.modified) - { - Gtk::MessageDialog mdialog(_("Save changes before closing?"), true, - Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); - mdialog.add_button(_("Close file _without Saving"), Gtk::RESPONSE_REJECT); - mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); - switch (mdialog.run()) - { - case Gtk::RESPONSE_CANCEL: - return; - case Gtk::RESPONSE_REJECT: - break; - case Gtk::RESPONSE_ACCEPT: - tabs[active_tab]->saveFile(); - break; - } - } - //tabs vector will be decreased with the deleted value - int size=tabs.size(); - if(size>1) - { - for(int i=active_tab+1;igd_canvas->changeEditorialTool(active_tool); - set_title(tabnames[active_tab]); -} - -void MainWin::newFile() -{ - if(active_tab!=-1) - { - tabs[active_tab]->newFile(); - } -} - -void MainWin::openFile() -{ - if(active_tab!=-1) - { - tabs[active_tab]->openFile(); - } -} - -void MainWin::saveFile() -{ - if(active_tab!=-1) - { - tabs[active_tab]->saveFile(); - } -} - -void MainWin::saveFileAs() -{ - if(active_tab!=-1) - { - tabs[active_tab]->saveFileAs(); - } -} - -void MainWin::close() -{ - if(active_tab!=-1) - { - tabs[active_tab]->close(); - } -} - -void MainWin::zoomIn() -{ - if(active_tab!=-1) - { - tabs[active_tab]->gd_canvas->zoomIn(); - } -} - -void MainWin::zoomOut() -{ - if(active_tab!=-1) - { - tabs[active_tab]->gd_canvas->zoomOut(); - } -} - -void MainWin::zoomFit() -{ - if(active_tab!=-1) - { - tabs[active_tab]->gd_canvas->zoomFit(); - } -} - -void MainWin::zoom100() -{ - if(active_tab!=-1) - { - tabs[active_tab]->gd_canvas->zoom100(); - } -} - -void MainWin::createMapWin() -{ - if(active_tab!=-1) - { - tabs[active_tab]->createMapWin(tabnames[active_tab]); - } -} - -void MainWin::createAlgoWin(int algoid) -{ - AlgoWin * aw=new AlgoWin(algoid, tabnames); - aw->signal_closing().connect(sigc::mem_fun(*this, &MainWin::deRegisterAlgoWin)); - aw->signal_maplist_needed().connect(sigc::mem_fun(*this, &MainWin::updateAlgoWinMaps)); - aw->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinTabString)); - aws.insert(aw); - aw->show(); -} - -void MainWin::updateAlgoWinTabs() -{ - std::set< AlgoWin* >::iterator awsi=aws.begin(); - for(;awsi!=aws.end();awsi++) - { - (*awsi)->update_tablist(tabnames); - } -} - -void MainWin::updateAlgoWinMaps(AlgoWin * awp, std::string tabname) -{ - int i=0; - for(;(i<(int)tabnames.size())&&(tabnames[i]!=tabname);i++) - { - } - awp->update_maplist(&(tabs[i]->mapstorage)); -} - -void MainWin::deRegisterAlgoWin(AlgoWin * awp) -{ - aws.erase(awp); -} - -void MainWin::changeEditorialTool(int tool) -{ - active_tool=tool; - if(active_tab!=-1) - { - tabs[active_tab]->gd_canvas->changeEditorialTool(tool); - } -} - -void MainWin::createNewMapWin() -{ - if(active_tab!=-1) - { - NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[active_tab], *(tabs[active_tab])); - nmw->show(); - } -} - -void MainWin::createNewMapWinTabString(std::string tabname, bool itisedge) -{ - int i=0; - for(;((i<(int)tabnames.size())&&(tabnames[i]!=tabname));i++) - { - } - createNewMapWinAfterSignal(tabs[i], itisedge); -} - -void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge) -{ - std::vector::iterator nbti=tabs.begin(); - int i=0; - for(;nbti!=tabs.end();nbti++) - { - if(*nbti!=nbt) - { - i++; - } - else - { - continue; - } - } - NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[i], *nbt, itisedge, false); - nmw->run(); -} diff -r a979fcdda073 -r 8e27998e9b1d gui/main_win.h --- a/gui/main_win.h Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,226 +0,0 @@ -// -*- C++ -*- // - -#ifndef MAIN_WIN_H -#define MAIN_WIN_H - -#include "all_include.h" -#include "algowin.h" -#include "map_win.h" -#include "new_map_win.h" -#include "nbtab.h" -#include -#include - - -///This class is the main window of GUI. - -///It has menus, and a notebook. Notebook has different pages, -///the so called tabs (\ref NoteBookTab). Each \ref NoteBookTab contains a canvas on which graphs can be drawn. -///To manage creation and close of tabs and tabswitching is the task of MainWin. -class MainWin : public Gtk::Window -{ - ///Container in which the menus and the notebook is. - Gtk::VBox vbox; - - ///The notebook that has tabs (\ref NoteBookTab) with different graphs. - Gtk::Notebook notebook; - - ///The tool selected to manipulate graph. - - ///It has to be stored, because in case of tabswitching - ///the correct tool has to be set for the actual graph. - int active_tool; - - ///The number of active tab in the notebook. - int active_tab; - - ///Vector of existing tabs in the notebook. - std::vector tabs; - - ///Vector of the name of tabs. - - ///All \ref NoteBookTab has a name that is stored here. The index of the name - ///is the same as the index of the \ref NoteBookTab in \ref tabs. - std::vector tabnames; - - ///Counter of occurence of the same file names. - - ///If a file is opened more than once we have to score - ///the occurences to let the titles on tabs different. - ///If more than one occurence is present, from the second - ///one near the filename the number of the occurence appear. - std::map strinst; - - ///Set of opened \ref AlgoWin s. - - ///More than one \refAlgoWin can be opened. We have to - ///communicate with them in case of new \ref NoteBookTab creation, - ///\ref NoteBookTab close, or map change. Therefore we have to score - ///their occurences. - std::set< AlgoWin* > aws; - -public: - - ///Constructor of the \ref MainWin. - - ///It creates the menus, the toolbar and the notebook in which - ///\ref NoteBookTab s take place. \ref NoteBookTab s are the - ///holder of the canvases on which the graphs are drawn. - MainWin(); - - ///Sets title of tabs. - - ///It alse registrates it in \ref tabnames. If more than one - ///occurence is in the notebook of the same file it has to - ///extend tabname with the number of occurence. - void set_tabtitle(std::string); - - ///ActionGroup for menu - Glib::RefPtr ag; - - ///UIManager for menu - Glib::RefPtr uim; - - ///Creates a new \ref NoteBookTab and opens the given file. - - ///It is called only with command line parameters at stratup. - void readFile(const std::string &); - - ///Tooltips - Gtk::Tooltips tooltips; - - //Call-backs of buttons - - ///Callback for 'FileNew' action. - virtual void newFile(); - ///Callback for 'FileOpen' action. - virtual void openFile(); - ///Callback for 'FileSave' action. - virtual void saveFile(); - ///Callback for 'FileSaveAs' action. - virtual void saveFileAs(); - ///Callback for 'Close' action. - virtual void close(); - - //Toolbar - - ///Callback for 'zoomIn' action. - - ///It calls the appropriate function in - ///\ref GraphDisplayerCanvas - virtual void zoomIn(); - ///Callback for 'zoomOut' action. - - ///It calls the appropriate function in - ///\ref GraphDisplayerCanvas - virtual void zoomOut(); - ///Callback for 'zoomFit' action. - - ///It calls the appropriate function in - ///\ref GraphDisplayerCanvas - virtual void zoomFit(); - ///Callback for 'zoom100' action. - - ///It calls the appropriate function in - ///\ref GraphDisplayerCanvas - virtual void zoom100(); - - ///Callback for Show Maps menupoint. - - ///It calls the appropriate function in - ///\ref NoteBookTab - virtual void createMapWin(); - - ///Pops up an Algorithm window. - - ///It not only creates but registrates the newly created \ref AlgoWin. - ///It is necessary, because in case of changement between tabs or maps - ///we have to communicate with it. Signals are also have to be connected - ///to it, because \ref AlgoWin emits signals if it needs anything (maplist, deregistration). - ///\param algo type of the algorithm to run. - virtual void createAlgoWin(int algo); - - ///Deregisters AlgoWin - - ///This is the function connected to the closing signal of \ref AlgoWin. - ///It only deletes the sender \ref AlgoWin from \ref aws. This function - ///is called only by the closing \ref AlgoWin itself. - ///\param aw the \ref AlgoWin to delete. - virtual void deRegisterAlgoWin(AlgoWin * aw); - - ///Updates list of tabs in all of the \ref AlgoWin - - ///When \ref NoteBookTab inserted somewhere or closed one tablist in all \ref AlgoWin - ///have to be updated. That is why we score all the opened \ref AlgoWin. - ///During update \ref tabnames will be passed to each \ref AlgoWin. - virtual void updateAlgoWinTabs(); - - ///Refresh list of maps in the AlgoWin that requested it. - - ///In an \ref AlgoWin there is a ComboBoxText, in which - ///a \ref NoteBookTab can be chosen that contains the graph and the maps, - ///on which we would like to run algorithms. If we change the - ///tab the available maps also have to be updated, because - ///in the different tabs different maps are available. Therefore - ///on tab change the \ref AlgoWin emits a signal that contains itself - ///so that the appropriate maps can be sent to it. For the sake of simplicity - ///the program answers this call with the mapstorage of the newly selected tab. - ///\param aw the caller \ref AlgoWin - ///\param tabname the newly selected tab in the \ref AlgoWin - virtual void updateAlgoWinMaps(AlgoWin * aw, std::string tabname); - - ///Registrates the new graph-editor tool in hand. - - ///The editor-tool in hand is global, it is the same for all tab - ///at the same time. Therefore the active tool has to be scored here (\ref active_tool). - ///This function is the callback function of the editor-tool buttons. It sets \ref active_tool - ///to the correct value. - ///\param tool the newly selected graph-editor tool (See all_include.h) - virtual void changeEditorialTool(int tool); - - ///Pops up a \ref NewMapWin dialog after requested by a \ref MapWin - - ///Each tab can pop-up a \ref MapWin. In \ref MapWin new tab can be created. - ///In this case \ref NoteBookTab emits a signal. This function is connected to that signal. - ///It sends the caller \ref NoteBookTab and whether an edgemap or a nodemap should be created. - ///Caller \ref NoteBookTab is necessary for the window to be able to place the new map in its - ///correct place. - ///\param nbt the caller tab - ///\param itisedge true if edgemap has to be created, false if nodemap - virtual void createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge); - - ///Pops up a \ref NewMapWin dialog after requested by an \ref AlgoWin - - ///\ref AlgoWin can also can request a \ref NewMapWin to pop-up. - ///It emits a signal in this case. This function is bound to that signal. - ///The signal contains the name of \ref NoteBookTab in which the new map has to be - ///placed and whether the new map is an edgemap or a nodemap. - ///\ref tabname the tab in which the new map has to be placed - ///\ref itisedge true if the new map will be edge map, false if it will be nodemap - virtual void createNewMapWinTabString(std::string tabname, bool itisedge); - - ///Pops up a \ref NewMapWin dialog if button on \ref MainWin has been pressed. - - ///In this case a general \ref NewMapWin will be popped up. This means that - ///both edge and nodemap can be created by it. The new map will be placed in - ///\MapStorage of the actual selected \ref NoteBookTab. - virtual void createNewMapWin(); - - //Notebook handlers - ///Callback for 'FileNewTab' action. - virtual void newTab(); - - ///Callback for 'FileCloseTab' action. - - ///It closes the actual \ref NoteBookTab and registrates this event: - ///data is shifted to the correct places in vectors. - virtual void closeTab(); - - ///Tabswitching handler - - ///Sets the variables that have to store the actual state, and it - ///updates the title of window to the actually selected \ref NoteBookTab. - virtual void onChangeTab(GtkNotebookPage*, guint); -}; - -#endif //MAIN_WIN_H diff -r a979fcdda073 -r 8e27998e9b1d gui/map_win.cc --- a/gui/map_win.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -#include "map_win.h" -#include - -bool MapWin::closeIfEscapeIsPressed(GdkEventKey* e) -{ - if(e->keyval==GDK_Escape) - { - mytab.closeMapWin(); - // hide(); - } - return true; -} - -MapWin::MapWin(const std::string& title, std::vector eml, std::vector nml, NoteBookTab & mw):mytab(mw) -{ - set_title(title); - set_default_size(200, 50); - - signal_key_press_event().connect(sigc::mem_fun(*this, &MapWin::closeIfEscapeIsPressed)); - - e_combo_array=new MapSelector * [EDGE_PROPERTY_NUM]; - - table=new Gtk::Table(EDGE_PROPERTY_NUM, 1, false); - - for(int i=0;isignal_cbt_ch().connect(sigc::bind(sigc::mem_fun(*this, &MapWin::edgeMapChanged), i)); - e_combo_array[i]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MapWin::newMapWinNeeded)); - } - - vbox.pack_start(*(new Gtk::Label("Edge properties"))); - - vbox.pack_start(*table); - - vbox.pack_start(*(new Gtk::HSeparator)); - - n_combo_array=new MapSelector * [NODE_PROPERTY_NUM]; - - table=new Gtk::Table(NODE_PROPERTY_NUM, 1, false); - - for(int i=0;isignal_cbt_ch().connect(sigc::bind(sigc::mem_fun(*this, &MapWin::nodeMapChanged), i)); - n_combo_array[i]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MapWin::newMapWinNeeded)); - } - - add(vbox); - - vbox.pack_start(*(new Gtk::Label("Node properties"))); - - vbox.pack_start(*table); - - show_all_children(); - -} - -void MapWin::nodeMapChanged(std::string mapname, int prop) -{ - mytab.propertyChange(false, prop, mapname); -} - -void MapWin::edgeMapChanged(std::string mapname, int prop) -{ - mytab.propertyChange(true, prop, mapname); -} - -void MapWin::newMapWinNeeded(bool itisedge) -{ - mytab.popupNewMapWin(itisedge); -} - -void MapWin::update(std::vector eml, std::vector nml) -{ - for(int i=0;iupdate_list(eml); - } - - for(int i=0;iupdate_list(nml); - } -} - -void MapWin::registerNewEdgeMap(std::string newmapname) -{ - for(int i=0;iappend_text((Glib::ustring)newmapname); - } -} - -void MapWin::registerNewNodeMap(std::string newmapname) -{ - for(int i=0;iappend_text((Glib::ustring)newmapname); - } -} - -bool MapWin::on_delete_event(GdkEventAny * event) -{ - event=event; - mytab.closeMapWin(); - return true; -} diff -r a979fcdda073 -r 8e27998e9b1d gui/map_win.h --- a/gui/map_win.h Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -// -*- C++ -*- // - -#ifndef MAP_WIN_H -#define MAP_WIN_H - -class MapWin; - -#include -#include -#include -#include -#include - -///Graph visualization setup window. - -///This class is responsible for creating a window, -///on which the visualization attributes can be -///assigned to maps. -class MapWin : public Gtk::Window -{ -protected: - ///\ref NoteBookTab to that the \ref MapWin belongs to. - NoteBookTab & mytab; - - ///Designing element - Gtk::Table * table; - - ///\ref MapSelectors for each property - - ///Each property has an own \ref MapSelector through which - ///the map to visualize by the property van be set. - MapSelector ** e_combo_array; - - ///\ref MapSelectors for each property - - ///Each property has an own \ref MapSelector through which - ///the map to visualize by the property van be set. - MapSelector ** n_combo_array; - - ///Information holder - Gtk::Label * label; - - ///Container in which elements are organized. - Gtk::VBox vbox; - -public: - ///Constructor - - ///It creates the widgets shown in \ref MapWin and - ///binds the needed signal to the correct place. - ///\param title title of window - ///\param eml edgemap list - ///\param nml nodemap list - ///\param mw the owner \ref NoteBookTab (\ref mytab) - MapWin(const std::string& title, std::vector eml, std::vector nml, NoteBookTab & mw); - - ///Deregistrates \ref MapWin in its \ref NoteBookTab (\ref mytab) - virtual bool on_delete_event(GdkEventAny *); - - ///Handles changement in nodemap selection - - ///If \ref MapSelector emits a signal that indicates - ///changement in nodemap selection this function will - ///be called. It calls the appropriate handler function, - ///\ref NoteBookTab::propertyChange with parameters describing the changement. - ///\param mapname the recently selected map - ///\param prop the changed property - void nodeMapChanged(std::string mapname, int prop); - - ///Handles changement in edgemap selection - - ///If \ref MapSelector emits a signal that indicates - ///changement in edgemap selection this function will - ///be called. It calls the appropriate handler function, - ///\ref NoteBookTab::propertyChange with parameters describing the changement. - ///\param mapname the recently selected map - ///\param prop the changed property - void edgeMapChanged(std::string mapname, int prop); - - ///Indicates to the owner \ref NoteBookTab that a \ref NewMapWin should be opened. - - ///This function is bound to the - ///signal emitted by the \ref MapSelector in case of - ///the user wants to create a new map. It only pass the - ///information further to the tab owning this \ref MapWin that is needed to open the - ///\ref NewMapWin. (\ref NoteBookTab::popupNewMapWin) - ///\param itisedge should the new map will be an edgemap? (or nodemap) - void newMapWinNeeded(bool itisedge); - - ///This function inserts name of the new edgemap in the name list in \ref MapSelector s - - ///\param new_name - ///name of new map - void registerNewEdgeMap(std::string new_name); - - ///This function inserts name of the new nodemap in the name list in \ref MapSelector s - - ///\param new_name - ///name of new map - void registerNewNodeMap(std::string new_name); - - ///Close window if Esc key pressed. - virtual bool closeIfEscapeIsPressed(GdkEventKey*); - - ///Updates list of maps in all \ref MapSelector - - ///This function is called by \ref NoteBookTab, when the file - ///showed in it has changed, therefore the contained maps - ///have changed as well. \ref NoteBookTab knows, whether it - ///has to call this function or not from the \ref NoteBookTab::mapwinexists - ///variable. - ///\param eml edge map list - ///\param nml node map list - void update(std::vector eml, std::vector nml); -}; - -#endif //MAP_WIN_H diff -r a979fcdda073 -r 8e27998e9b1d gui/mapselector.cc --- a/gui/mapselector.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +0,0 @@ -#include "mapselector.h" - -MapSelector::MapSelector(std::vector ml, std::string act, std::string labeltext, bool edge, bool d):def(d),itisedge(edge),set_new_map(false) -{ - update_list(ml); - - if(act=="") - { - cbt.set_active(0); - default_state=true; - } - else - { - cbt.set_active_text((Glib::ustring)act); - default_state=false; - } - - //binding signal to the actual entry - cbt.signal_changed().connect - ( - sigc::mem_fun((*this), &MapSelector::comboChanged), - false - ); - - label=new Gtk::Label(labeltext); - - label->set_width_chars(longest_property_string_length); - - defbut=NULL; - if(def) - { - defbut=new Gtk::Button(); - defbut->set_label("Reset"); - - defbut->signal_pressed().connect - ( - sigc::mem_fun(*this, &MapSelector::reset) - ); - } - - newbut=new Gtk::Button(Gtk::Stock::NEW); - - newbut->signal_pressed().connect - ( - sigc::mem_fun(*this, &MapSelector::new_but_pressed) - ); - - add(*label); - - add(cbt); - - if(def) - { - add(*defbut); - } - - add(*newbut); -} - -void MapSelector::new_but_pressed() -{ - set_new_map=true; - signal_newmapwin.emit(itisedge); -} - -void MapSelector::update_list( std::vector< std::string > ml ) -{ - int prev_act=cbt.get_active_row_number(); - cbt.clear(); - std::vector< std::string >::iterator emsi=ml.begin(); - for(;emsi!=ml.end();emsi++) - { - cbt.append_text(*emsi); - } - if(def) - { - cbt.prepend_text("Default values"); - } - if(prev_act!=-1) - { - cbt.set_active(prev_act); - } -} - -void MapSelector::comboChanged() -{ - if(cbt.get_active_row_number()!=0 || !def) - { - default_state=false; - Glib::ustring mapname = cbt.get_active_text(); - if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty. - { - signal_cbt.emit(mapname); - } - } - else if((!default_state)&&(cbt.get_active_row_number()==0)) - { - reset(); - } -} - -void MapSelector::reset() -{ - default_state=true; - - cbt.set_active(0); - - signal_cbt.emit(""); -} - - -Glib::ustring MapSelector::get_active_text() -{ - return cbt.get_active_text(); -} - -void MapSelector::set_active_text(Glib::ustring text) -{ - cbt.set_active_text(text); -} - -void MapSelector::append_text(Glib::ustring text) -{ - cbt.append_text(text); - if(set_new_map) - { - set_active_text(text); - set_new_map=false; - } -} - -sigc::signal MapSelector::signal_cbt_ch() -{ - return signal_cbt; -} - -sigc::signal MapSelector::signal_newmapwin_needed() -{ - return signal_newmapwin; -} diff -r a979fcdda073 -r 8e27998e9b1d gui/mapselector.h --- a/gui/mapselector.h Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,158 +0,0 @@ -// -*- C++ -*- // - -#ifndef MAPSELECTOR_H -#define MAPSELECTOR_H - -class MapSelector; - -#include -#include -#include -#include - -///A widget by which node and edgemaps can be selected, deselected and created. - -///During the usage of \ref glemon we have to select -///maps several times. We also need some aid-function -///like new map creation and deselecting previously -///selected map. Instead of writing a the mapselection -///at all occurences we can use this widget by connecting -///its signals to the correct place. -class MapSelector : public Gtk::HBox -{ - protected: - ///This signal indicates that the selection has been changed by user. - sigc::signal signal_cbt; - - ///Signal that indicates that user wants to create a new map. - sigc::signal signal_newmapwin; - - ///If this is true, beyond the mapnames a 'Default' selection is available as well. - - ///For example \ref MapWin needs 'Default' option as well. In this case no map - ///will be visualized by the appropriate property. - ///But \ref AlgoWin do not need 'Default' option, because if no map is selected, - ///no algorithm can be run. - ///Its value is got and set in contructor. - bool def; - - ///Are the names of edgemaps or nodemaps stored here. - bool itisedge; - - ///Shows whether 'Default' option is selected or not. - bool default_state; - - ///It is true when the new button had been pressed but the new map has not been registrated yet. - - ///Before signal of \ref NewMapWin request is emitted by the \ref MapSelector - ///this variable is set to true. When the new map - ///is done, it will be registrated in all existing \ref MapSelector - ///by \ref append_text function. That function checks - ///whether this variable is true. If it is true that means - ///that this \ref MapSelector has requested \ref NewMapWin. - ///Therefore it set itself to the recently created map. - ///After that \ref set_new_map is set again false, not to - ///set maps active if \ref MapSelector piece is not the requester. - bool set_new_map; - - ///The widget that holds the names of maps. - - ///It can be rolled down - ///Names in it are selectable. - Gtk::ComboBoxText cbt; - - ///New button. - - ///By pressing it - ///\ref NewMapWin wilol pop-up - Gtk::Button * newbut; - - ///Reset button. - - ///If pressed \ref cbt will - ///set to 'Default' option. - /// - ///It is visible only if \ref def is true. - Gtk::Button * defbut; - - ///Container in which GUI elements are packed. - Gtk::HBox hbox; - - ///Shows purpose of \ref MapSelector piece. - Gtk::Label * label; - - public: - - ///Constructor of \ref MapSelector - - ///Creates the layout and binds signal to the correct place. - ///\param optionlist list of names to place in \ref cbt - ///\param act preselected option - ///\param purpose text of label indicating purpose of \ref MapStorage - ///\param itisedge do \ref MapSelector contains edgemap names or nodemapnames. - ///\param def do we need 'Default' option. See \ref def. - MapSelector(std::vector optionlist, std::string act, std::string purpose, bool itisedge, bool def=true); - - ///Returns signal emitted if the user has changed the selection. (\ref signal_cbt) - sigc::signal signal_cbt_ch(); - - ///Returns signal emitted if the user has pressed New button (\ref newbut) (\ref signal_newmapwin) - sigc::signal signal_newmapwin_needed(); - - ///Maintain \ref cbt. - - ///Fills in \ref cbt with names, taking - ///into account that the previously selected option - ///has to be set back after the operation. - void update_list( std::vector ); - - ///Handles changement in \ref cbt. - - ///In default case it emits a signal with the selected option. - ///But if 'Default' option is selected, it resets the \ref MapSelector - virtual void comboChanged(); - - ///Requests a \ref NewMapWin - - ///See \ref set_new_map. - ///First it sets \ref set_new_map true to be identified - ///at registration of new map that - ///it has sent the \ref signal_newmapwin, therefore it - ///has to set \ref cbt to that option. - virtual void new_but_pressed(); - - ///If called, 'Default' option is selected, that means unselection of any maps. - - ///Practically this means that if this is called, - ///properties of graph will set to default state. - ///The function achieves this by emitting appropriately - ///parametrized signal_cbt. - virtual void reset(); - - ///Returns the currently selected option. - Glib::ustring get_active_text(); - - ///Sets the parameter active in \ref cbt. - - ///\param new_value the - ///new value to be set in \ref cbt. - void set_active_text(Glib::ustring new_value); - - ///Sets the parameter active in \ref cbt. - ///\param index the - ///index of row to be set in \ref cbt. - void set_active(int index){cbt.set_active(index);}; - - ///Clear all options from \ref cbt. - void clear(){cbt.clear();}; - - ///Appends a new option to the existing ones in \ref cbt. - - ///If \ref set_new_map is true, the - ///\ref MapSelector has requested the opened \ref NewMapWin, - ///from that the option to append is coming. In this case - ///this function will set \ref cbt to the new option. - ///\param new_option new option to append - void append_text(Glib::ustring new_option); -}; -#endif //MAPSELECTOR_H diff -r a979fcdda073 -r 8e27998e9b1d gui/mapstorage.cc --- a/gui/mapstorage.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,479 +0,0 @@ -#include "mapstorage.h" -#include "gui_writer.h" -#include "gui_reader.h" -#include -#include -#include - -MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false) -{ - nodemap_storage["coordinates_x"] = new Graph::NodeMap(graph); - coords.setXMap(*nodemap_storage["coordinates_x"]); - nodemap_storage["coordinates_y"] = new Graph::NodeMap(graph); - coords.setYMap(*nodemap_storage["coordinates_y"]); - - edgemap_storage["arrow_pos_x"] = new Graph::EdgeMap(graph); - arrow_pos.setXMap(*edgemap_storage["arrow_pos_x"]); - edgemap_storage["arrow_pos_y"] = new Graph::EdgeMap(graph); - arrow_pos.setYMap(*edgemap_storage["arrow_pos_y"]); - - nodemap_storage["label"] = new Graph::NodeMap(graph); - edgemap_storage["label"] = new Graph::EdgeMap(graph); - - nodemap_default["label"] = 1.0; - edgemap_default["label"] = 1.0; - - active_nodemaps.resize(NODE_PROPERTY_NUM); - for(int i=0;i*>::const_iterator it = - nodemap_storage.begin(); it != nodemap_storage.end(); ++it) - { - delete it->second; - } - for (std::map*>::const_iterator it = - edgemap_storage.begin(); it != edgemap_storage.end(); ++it) - { - delete it->second; - } -} - -int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap *nodemap, double default_value) -{ - std::cout << default_value << std::endl; - if( nodemap_storage.find(name) == nodemap_storage.end() ) - { - nodemap_storage[name]=nodemap; - // set the maps default value - nodemap_default[name] = default_value; - - //announce changement in maps - signal_node_map.emit(name); - return 0; - } - return 1; -} - -void MapStorage::changeActiveMap(bool itisedge, int prop, std::string mapname) -{ - if(itisedge) - { - active_edgemaps[prop]=mapname; - } - else - { - active_nodemaps[prop]=mapname; - } - signal_prop.emit(itisedge, prop); -} - -std::string MapStorage::getActiveEdgeMap(int prop) -{ - return active_edgemaps[prop]; -} - -std::string MapStorage::getActiveNodeMap(int prop) -{ - return active_nodemaps[prop]; -} - -std::vector MapStorage::getEdgeMapList() -{ - std::vector eml; - eml.resize(edgemap_storage.size()); - int i=0; - std::map< std::string,Graph::EdgeMap * >::iterator emsi=beginOfEdgeMaps(); - for(;emsi!=endOfEdgeMaps();emsi++) - { - eml[i]=(emsi->first); - i++; - } - return eml; -} - -std::vector MapStorage::getNodeMapList() -{ - std::vector nml; - nml.resize(nodemap_storage.size()); - int i=0; - std::map< std::string,Graph::NodeMap * >::iterator nmsi=beginOfNodeMaps(); - for(;nmsi!=endOfNodeMaps();nmsi++) - { - nml[i]=(nmsi->first); - i++; - } - return nml; -} - -MapStorage::Signal_Prop MapStorage::signal_prop_ch() -{ - return signal_prop; -} - -int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap *edgemap, double default_value) -{ - if( edgemap_storage.find(name) == edgemap_storage.end() ) - { - edgemap_storage[name]=edgemap; - // set the maps default value - edgemap_default[name] = default_value; - - //announce changement in maps - signal_edge_map.emit(name); - return 0; - } - return 1; -} - -double MapStorage::maxOfNodeMap(const std::string & name) -{ - double max=0; - for (NodeIt j(graph); j!=INVALID; ++j) - { - if( (*nodemap_storage[name])[j]>max ) - { - max=(*nodemap_storage[name])[j]; - } - } - return max; -} - -double MapStorage::maxOfEdgeMap(const std::string & name) -{ - double max=0; - for (EdgeIt j(graph); j!=INVALID; ++j) - { - if( (*edgemap_storage[name])[j]>max ) - { - max=(*edgemap_storage[name])[j]; - } - } - return max; -} - -double MapStorage::minOfNodeMap(const std::string & name) -{ - NodeIt j(graph); - double min; - if(j!=INVALID) - { - min=(*nodemap_storage[name])[j]; - } - else - { - min=0; - } - for (; j!=INVALID; ++j) - { - if( (*nodemap_storage[name])[j]& nodeMapNames = content.nodeSetMaps(0); - const std::vector& edgeMapNames = content.edgeSetMaps(0); - - GraphReader greader(filename, graph); - for (std::vector::const_iterator it = nodeMapNames.begin(); - it != nodeMapNames.end(); ++it) - { - if (*it == "coordinates_x") - { - read_x = true; - //std::cout << "read X nodemap" << std::endl; - } - else if (*it == "coordinates_y") - { - read_y = true; - //std::cout << "read Y nodemap" << std::endl; - } - else if (*it == "label") - { - //std::cout << "read id nodemap" << std::endl; - } - else - { - nodemap_storage[*it] = new Graph::NodeMap(graph); - //std::cout << "read " << *it << " nodemap" << std::endl; - } - greader.readNodeMap(*it, *nodemap_storage[*it]); - } - for (std::vector::const_iterator it = edgeMapNames.begin(); - it != edgeMapNames.end(); ++it) - { - if (*it == "label") - { - //std::cout << "read id edgemap" << std::endl; - read_edge_id = true; - } - else - { - edgemap_storage[*it] = new Graph::EdgeMap(graph); - //std::cout << "read " << *it << " edgemap" << std::endl; - } - greader.readEdgeMap(*it, *edgemap_storage[*it]); - } - GuiReader gui_reader(greader, this); - greader.run(); - } catch (Exception& error) { - Gtk::MessageDialog mdialog(error.what()); - mdialog.run(); - clear(); - return 1; - } - - if (!read_edge_id) - { - edgemap_storage["label"] = new Graph::EdgeMap(graph); - int i = 1; - for (EdgeIt e(graph); e != INVALID; ++e) - { - (*edgemap_storage["label"])[e] = i++; - } - } - - if (!read_x || !read_y) - { - int node_num = 0; - for (NodeIt n(graph); n != INVALID; ++n) - { - node_num++; - } - const double pi = 3.142; - double step = 2 * pi / (double) node_num; - int i = 0; - for (NodeIt n(graph); n != INVALID; ++n) - { - nodemap_storage["coordinates_x"]->set(n, 250.0 * std::cos(i * step)); - nodemap_storage["coordinates_y"]->set(n, 250.0 * std::sin(i * step)); - i++; - } - } - - if (!arrow_pos_read_ok) - { - arrow_pos_read_ok = false; - for (EdgeIt e(graph); e != INVALID; ++e) - { - arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0); - } - } - - // fill in the default values for the maps - for (std::map*>::const_iterator it = - nodemap_storage.begin(); it != nodemap_storage.end(); ++it) - { - if ((it->first != "label") && - (it->first != "coordiantes_x") && - (it->first != "coordinates_y")) - { - nodemap_default[it->first] = 0.0; - } - else if (it->first == "label") - { - NodeIt n(graph); - double max = (*nodemap_storage["label"])[n]; - for (; n != INVALID; ++n) - { - if ((*nodemap_storage["label"])[n] > max) - max = (*nodemap_storage["label"])[n]; - } - nodemap_default["label"] = max + 1.0; - } - } - for (std::map*>::const_iterator it = - edgemap_storage.begin(); it != edgemap_storage.end(); ++it) - { - if (it->first != "label") - { - edgemap_default[it->first] = 0.0; - } - else - { - double max = std::numeric_limits::min(); - for (EdgeIt e(graph); e != INVALID; ++e) - { - if ((*edgemap_storage["label"])[e] > max) - max = (*edgemap_storage["label"])[e]; - } - if (max > std::numeric_limits::min()) - edgemap_default["label"] = max + 1.0; - else - edgemap_default["label"] = 1.0; - } - } - - // filter loop edges - for (EdgeIt e(graph); e != INVALID; ++e) - { - if (graph.source(e) == graph.target(e)) - { - std::cerr << "Removed loop edge " << (*edgemap_storage["label"])[e] - << " (from " << (*nodemap_storage["label"])[graph.source(e)] - << ", to " << (*nodemap_storage["label"])[graph.target(e)] << ")." - << std::endl; - - graph.erase(e); - } - } - - return 0; -} - -void MapStorage::writeToFile(const std::string &filename) -{ - GraphWriter gwriter(filename, graph); - - for (std::map*>::const_iterator it = - nodemap_storage.begin(); it != nodemap_storage.end(); ++it) - { - gwriter.writeNodeMap(it->first, *(it->second)); - } - for (std::map*>::const_iterator it = - edgemap_storage.begin(); it != edgemap_storage.end(); ++it) - { - if ((it->first != "arrow_pos_x") && - (it->first != "arrow_pos_y")) - { - gwriter.writeEdgeMap(it->first, *(it->second)); - } - } - - GuiWriter gui_writer(gwriter, this); - - gwriter.run(); -} - -void MapStorage::clear() -{ - for (std::map*>::iterator it = - nodemap_storage.begin(); it != nodemap_storage.end(); ++it) - { - if ((it->first != "coordinates_x") && - (it->first != "coordinates_y") && - (it->first != "label")) - { - delete it->second; - nodemap_storage.erase(it); - } - } - for (std::map*>::iterator it = - edgemap_storage.begin(); it != edgemap_storage.end(); ++it) - { - if ((it->first != "label") && - (it->first != "arrow_pos_x") && - (it->first != "arrow_pos_y")) - { - delete it->second; - edgemap_storage.erase(it); - } - } - for (std::map::iterator it = - nodemap_default.begin(); it != nodemap_default.end(); ++it) - { - if (it->first != "label") - nodemap_default.erase(it); - } - for (std::map::iterator it = - edgemap_default.begin(); it != edgemap_default.end(); ++it) - { - if (it->first != "label") - edgemap_default.erase(it); - } - graph.clear(); - file_name = ""; - modified = false; -} - -void MapStorage::ArrowPosReadOK() -{ - arrow_pos_read_ok = true; -} - -void MapStorage::mapChanged(bool itisedge, std::string mapname) -{ - if(itisedge) - { - for(int i=0;i - -///class MapStorage handles NodeMaps and EdgeMaps. - -///Class MapStorage is responsible for storing -///NodeMaps and EdgeMaps that can be shown later -///on GUI. Therefore maps can be added to it, -///and datas over the added maps can be queried. -///The maps will be stored in an std::map, -///referenced with their names. Unfortunately at -///the moment it works only with double type maps -/// -///\todo too many things are public!! -class MapStorage -{ -public: - - ///The graph for which the datas are stored. - Graph graph; - /// the coordinates of the nodes - XYMap > coords; - /// the coordinates of the arrows on the edges - XYMap > arrow_pos; - - ///The content of the object has changed, update is needed. - bool modified; - - ///Name of file loaded in object. - std::string file_name; - - ///Stores double type NodeMaps - std::map< std::string,Graph::NodeMap * > nodemap_storage; - - ///Stores double type EdgeMaps - std::map< std::string,Graph::EdgeMap * > edgemap_storage; - - ///Stores the default values for the different visualization node attributes - std::vector > default_nodemaps; - - ///Stores the default values for the different visualization edge attributes - std::vector > default_edgemaps; - - ///Stores the active maps for the different visualization node attributes - std::vector< std::string > active_nodemaps; - - /// Stores the active maps for the different visualization edge attributes - std::vector< std::string > active_edgemaps; - - /// Default values for the maps - std::map< std::string, double > nodemap_default; - - /// Default values for the maps - std::map< std::string, double > edgemap_default; - - bool arrow_pos_read_ok; - -protected: - /// type of the signal emitted if the visualization of the maps might have to be updated. - - /// bool shows us whether the changed map is edge or nodemap. - /// int tells us the refreshed property - typedef sigc::signal Signal_Prop; - - /// Signal emitted on any change made on map values - Signal_Prop signal_prop; - - /// Signal emitted in the case of nodemap addition - - /// std::string is the - ///name of the new map - sigc::signal signal_node_map; - - /// Signal emitted in the case of edgemap addition - - /// std::string is the - ///name of the new map - sigc::signal signal_edge_map; - -public: - ///Constructor of MapStorage. - - ///Its all activity is initializing default values - ///for different visualization attributes. - MapStorage(); - - ///Destructor of MapStorage - - ///Maps stored here are created with new. Destructor - ///deletes them to free up the reserved memory. - ~MapStorage(); - - /// Registrates if the shown map by any attribute has changed to another. - - ///It handles the \ref active_edgemaps and - ///\ref active_nodemaps vectors. It also emits \ref signal_prop signal to let - ///know the interested objects that the visible map of a certain - ///attribute has changed. - ///\param itisedge edgemap or nodemap has changed - ///\param prop the property of which the map is changed - ///\param mapname the visible map - void changeActiveMap(bool itisedge , int prop , std::string mapname); - - /// Returns the active edgemap shown by a visualization property. - - /// \param prop is the property - ///that shows the requested map. - std::string getActiveEdgeMap(int prop); - - /// Returns the active nodemap shown by a visualization property. - - /// \param prop is the property - ///that shows the requested map. - std::string getActiveNodeMap(int prop); - - /// Returns the names of the edgemaps stored here. - std::vector getEdgeMapList(); - - /// Returns the names of the nodemaps stored here. - std::vector getNodeMapList(); - - ///returns \ref signal_prop to be able to connect functions to it - Signal_Prop signal_prop_ch(); - - ///returns \ref signal_node_map to be able to connect functions to it - sigc::signal signal_node_map_ch(){return signal_node_map;}; - - ///returns \ref signal_edge_map to be able to connect functions to it - sigc::signal signal_edge_map_ch(){return signal_edge_map;}; - - ///Adds given map to storage. - - ///A name and the map itself has to be provided. - ///\param mapname is the name of map - ///\param nodemap is the pointer of the given nodemap - ///\param def the default value of the map. If not given, it will be 0. - ///If new edge is added to graph the value of it in the map will be this. - ///\todo map should be given by reference! - ///\todo why is default value stored? - int addNodeMap(const std::string & mapname,Graph::NodeMap * nodemap, double def=0.0); - - ///Adds given map to storage. A name and the map itself has to be provided. - - ///A name and the map itself has to be provided. - ///\param mapname is the name of map - ///\param edgemap is the pointer of the given edgemap - ///\param def the default value of the map. If not given, it will be 0. - ///If new edge is added to graph the value of it in the map will be this. - ///\todo map should be given by reference! - int addEdgeMap(const std::string & mapname,Graph::EdgeMap * edgemap, double def=0.0); - - ///Returns how much nodemaps is stored in \ref MapStorage - int numOfNodeMaps() {return nodemap_storage.size();}; - - ///Returns how much edgemaps is stored in \ref MapStorage - int numOfEdgeMaps() {return edgemap_storage.size();}; - - ///Returns the maximum value of the given NodeMap. - - ///NodeMap has to be given by its name. - ///\param name the name of map of which maximum is searched - double maxOfNodeMap(const std::string & name); - - ///Returns the maximum value of the given EdgeMap. - - ///EdgeMap has to be given by its name. - ///\param name the name of map of which maximum is searched - double maxOfEdgeMap(const std::string & name); - - ///Returns the minimum value of the given NodeMap. - - ///NodeMap has to be given by its name. - ///\param name the name of map of which minimum is searched - double minOfNodeMap(const std::string & name); - - ///Returns the minimum value of the given EdgeMap. - - ///EdgeMap has to be given by its name. - ///\param name the name of map of which minimum is searched - double minOfEdgeMap(const std::string & name); - - ///Returns iterator pointing to the first NodeMap in storage. - - ///To be able to iterate through each maps this function - ///returns an iterator pointing to the first nodemap in - ///the storage. - std::map< std::string,Graph::NodeMap * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();}; - - ///Returns iterator pointing to the first EdgeMap in storage. - - ///To be able to iterate through each maps this function - ///returns an iterator pointing to the first edgemap in - ///the storage. - std::map< std::string,Graph::EdgeMap * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();}; - - ///Returns iterator pointing after the last NodeMap in storage. - - ///To be able to iterate through each maps this function - ///returns an iterator pointing to the last nodemap in the storage. - std::map< std::string,Graph::NodeMap * >::iterator endOfNodeMaps(){return nodemap_storage.end();}; - - ///Returns iterator pointing after the last EdgeMap in storage. - - ///To be able to iterate through each maps this function - ///returns an iterator pointing to the last edgemap in the storage. - std::map< std::string,Graph::EdgeMap * >::iterator endOfEdgeMaps(){return edgemap_storage.end();}; - - ///Emits \ref signal_prop if mapvalues have changed, and MapStorage gets to know it. - - ///If values in a map have changed, this function checks, whether it is displayed. - ///This check means searching the given mapname between active maps - ///(\ref active_nodemaps, \ref active_edgemaps). If it is there at a certain property, - ///it emits a signal with the property, where the gotten mapname was found. One signal - ///is emitted for each property displaying the given map. - ///\param itisedge whether the map an edgemap or nodemap - ///\param mapname name of map to visualize - void mapChanged(bool itisedge, std::string mapname); - - ///Read datas from the given filename. - int readFromFile(const std::string &); - - ///Save datas to the given filename. - void writeToFile(const std::string &); - - ///Deletes all datastructures stored here. - void clear(); - - void ArrowPosReadOK(); -}; - -#endif //MAPSTORAGE_H diff -r a979fcdda073 -r 8e27998e9b1d gui/nbtab.cc --- a/gui/nbtab.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,220 +0,0 @@ -#include - -NoteBookTab::NoteBookTab():mapwinexists(false) -{ - Gtk::ScrolledWindow *pScrolledWindow = manage(new Gtk::ScrolledWindow); - gd_canvas=new GraphDisplayerCanvas(*this); - pScrolledWindow->add(*gd_canvas); - add(*pScrolledWindow); - - //connecting signals - controller character - mapstorage.signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::propertyChange)); - mapstorage.signal_node_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewNodeMap)); - mapstorage.signal_edge_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewEdgeMap)); - show_all_children(); - show(); -} - -void NoteBookTab::readFile(const std::string &file) -{ - mapstorage.readFromFile(file); - mapstorage.file_name = file; - mapstorage.modified = false; - gd_canvas->drawGraph(); - if(mapwinexists) - { - mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList()); - } - signal_title.emit(Glib::filename_display_basename(file)); -} - -void NoteBookTab::newFile() -{ - if (mapstorage.modified) - { - Gtk::MessageDialog mdialog("Save changes before closing?", true, - Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); - mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT); - mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); - switch (mdialog.run()) - { - case Gtk::RESPONSE_CANCEL: - return; - case Gtk::RESPONSE_REJECT: - break; - case Gtk::RESPONSE_ACCEPT: - saveFile(); - break; - } - } - gd_canvas->clear(); - mapstorage.clear(); - if(mapwinexists) - { - mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList()); - } - signal_title.emit("unsaved file"); -} - -void NoteBookTab::openFile() -{ - if (mapstorage.modified) - { - Gtk::MessageDialog mdialog("Save changes before closing?", true, - Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); - mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT); - mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); - switch (mdialog.run()) - { - case Gtk::RESPONSE_CANCEL: - return; - case Gtk::RESPONSE_REJECT: - break; - case Gtk::RESPONSE_ACCEPT: - saveFile(); - break; - } - } - Gtk::FileChooserDialog fcdialog("Open File"); - fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT); - if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) - { - gd_canvas->clear(); - mapstorage.clear(); - Glib::ustring filename = fcdialog.get_filename(); - if (!mapstorage.readFromFile(filename)) - { - mapstorage.file_name = filename; - mapstorage.modified = false; - gd_canvas->drawGraph(); - if(mapwinexists) - { - mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList()); - } - signal_title.emit(Glib::filename_display_basename(filename)); - } - } -} - -void NoteBookTab::saveFile() -{ - if (mapstorage.file_name == "") { - saveFileAs(); - } - else - { - mapstorage.writeToFile(mapstorage.file_name); - mapstorage.modified = false; - signal_title.emit(Glib::filename_display_basename(mapstorage.file_name)); - } -} - -void NoteBookTab::saveFileAs() -{ - Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE); - fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); - if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) - { - Glib::ustring filename = fcdialog.get_filename(); - mapstorage.file_name = filename; - mapstorage.writeToFile(filename); - mapstorage.modified = false; - signal_title.emit(Glib::filename_display_basename(filename)); - } -} - -void NoteBookTab::close() -{ - if (mapstorage.modified) - { - Gtk::MessageDialog mdialog("Save changes before closing?", true, - Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); - mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); - mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); - switch (mdialog.run()) - { - case Gtk::RESPONSE_CANCEL: - return; - case Gtk::RESPONSE_REJECT: - break; - case Gtk::RESPONSE_ACCEPT: - saveFile(); - break; - } - } - gd_canvas->clear(); - mapstorage.clear(); - if(mapwinexists) - { - mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList()); - } - signal_title.emit("unsaved file"); -} - -void NoteBookTab::propertyChange(bool itisedge, int prop, std::string mapname) -{ - mapstorage.changeActiveMap(itisedge, prop, mapname); -} - -sigc::signal NoteBookTab::signal_newmap_needed() -{ - return signal_newmap; -} - -void NoteBookTab::popupNewMapWin(bool itisedge) -{ - signal_newmap.emit(this, itisedge); -} - -std::string NoteBookTab::getActiveEdgeMap(int prop) -{ - return mapstorage.getActiveEdgeMap(prop); -} - -std::string NoteBookTab::getActiveNodeMap(int prop) -{ - return mapstorage.getActiveNodeMap(prop); -} - -void NoteBookTab::registerNewEdgeMap(std::string mapname) -{ - if(mapwinexists) - { - mapwin->registerNewEdgeMap(mapname); - } -} - -void NoteBookTab::registerNewNodeMap(std::string mapname) -{ - if(mapwinexists) - { - mapwin->registerNewNodeMap(mapname); - } -} - -void NoteBookTab::createMapWin(std::string name) -{ - if(!mapwinexists) - { - mapwin=new MapWin("Map Setup - "+name, mapstorage.getEdgeMapList(), mapstorage.getNodeMapList(), *this); - mapwin->show(); - mapwinexists=true; - } -} - -void NoteBookTab::closeMapWin() -{ - mapwinexists=false; - delete mapwin; -} - -sigc::signal NoteBookTab::signal_title_ch() -{ - return signal_title; -} - diff -r a979fcdda073 -r 8e27998e9b1d gui/nbtab.h --- a/gui/nbtab.h Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,161 +0,0 @@ -// -*- C++ -*- // - -#ifndef NBTAB_H -#define NBTAB_H - -class NoteBookTab; - -#include "mapstorage.h" -#include "map_win.h" -#include "graph_displayer_canvas.h" -#include -#include - -///One tab in the Notebook that is placed in the main window (\ref MainWin). - -///One graph and all of its accessories like maps are assigned to one tab in the notebook. -///\ref NoteBookTab is responsible for the user defined display of the graph: view can be -///set by visualized maps, therefore \ref NoteBookTab must provide an interface to set the -///view of graph. This is \ref Mapwin window. -/// -///\ref NoteBookTab is also -///responsible for modify the graph if it is -///requested. Therefore it is responsible for translating user events to modifications to -///do on graph, like node/edge addition/deletion, map modification, addition and so on. -/// -///To be able to solve these tasks the help of \ref MainWin is also needed, for example to -///know which editor-tool is active at the moment. Therefore \ref MainWin knows \ref NoteBookTab. -/// -///Some information in the other direction is needed as well: for example when new map creation is requested for this tab -///\ref NoteBookTab must ask \ref MainWin to pop-up a \ref NewMapWin. Communication in this direction is realized by signals -///therefore \ref NoteBookTab does not know \ref MainWin at all, but in this way it is not necessary. -class NoteBookTab : public Gtk::VBox -{ -public: - - ///Constructor of \ref NoteBookTab - - ///It initiates the \re GraphDisplayerCanvas, on which the graph will be drawn - ///Signals of \ref MapStorage will be bound to the appropriate callback functions here. - NoteBookTab(); - - ///Maps assigned to the graph displayed in this \ref NoteBookTab of notebook. - MapStorage mapstorage; - - ///Title changement indicator. - - ///If graph is loaded from disk or saved to disk or changed its name somehow - ///this signal will be emit to let - ///\ref MainWin know that it has to modify the title of the main window. - ///It contains the new title. - sigc::signal signal_title; - - ///Returns \ref signal_title to be the caller able to connect it to a callback function. - sigc::signal signal_title_ch(); - - ///Indicates that new map window should be popped up. - - ///\ref NoteBookTab can ask \ref MainWin to pop up a \ref NweMapWin ny emitting this signal. - ///The signal contains whether an edgemap or a nodemap should be popped up. \ref NewMapWin - ///is not popped up by \ref NoteBookTab, because not only \ref NoteBookTab needs \ref NewMapWin, - ///but for example \ref MainWin and \ref AlgoWin s as well. - sigc::signal signal_newmap; - - ///Returns \ref signal_newmap to be the caller able to connect it to a callback function. - sigc::signal signal_newmap_needed(); - - ///Loads the given file. - - ///The given file will be load in the \ref MapStorage and afeter that - ///\ref GraphDisplayerCanvas will be requested to display the graph. - ///\ref GraphDisplayer will get datas from the recently set \ref MapStorage. - void readFile(const std::string &); - - ///The graph will be drawn on this \ref GraphDisplayerCanvas - GraphDisplayerCanvas * gd_canvas; - - ///Indicates whether the \ref MapWin is opened or not. See \ref mapwin. - bool mapwinexists; - - ///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), - ///because there is no need for more, one per tab is enough. - ///There won1t be benefit of more than one, but it would be - ///more complicated to synchronize them. - MapWin * mapwin; - -public: - ///Callback for 'FileNew' action. - virtual void newFile(); - ///Callback for 'FileOpen' action. - virtual void openFile(); - ///Callback for 'FileSave' action. - virtual void saveFile(); - ///Callback for 'FileSaveAs' action. - virtual void saveFileAs(); - ///Callback for 'Close' action. - virtual void close(); - - ///Handles changement of view of graph. - - ///If the user changes the map to show by a property to a nother in \ref MapWin, - ///\ref MapWin will call this function. This function will registrate in \ref MapStorage - ///the new map to display by the changed property. After that \ref MapStorage will - ///emits a signal that will be forwarded to \ref GraphDisplayerCanvas to update the - ///appropriate parts of graph. - ///\param itiesedge whether the changed property is edge property or node property - ///\param prop id of property, see all_include.h - ///\param mapname name of the recently selected map - void propertyChange(bool itisedge, int prop, std::string mapname); - - ///Emits a signal that request \ref MainWin to pop up \ref NewMapWin - - ///This function is called by \ref MapWin. - ///\param itisedge whether the new map should be an edgemap or a nodemap. - void popupNewMapWin(bool itisedge); - - ///Returns the actually selected edgemap to visualize by the given property. - - ///\ref MapWin calls this function, beacuse it does not know \ref MapStorage. - ///\param prop property to inquire. - std::string getActiveEdgeMap(int prop); - - ///Returns the actually selected nodemap to visualize by the given property. - - ///\ref MapWin calls this function, beacuse it does not know \ref MapStorage. - ///\param prop property to inquire. - std::string getActiveNodeMap(int prop); - - ///Registers recently created edgemap in \ref MapWin. - - ///After creation of new map \ref MapStorage emits a signal. - ///This signal is bound to this callback function, that will call - ///a function with the same name and same parameterin \ref MapWin. - ///This call-forwarder function is needed, because \ref Mapstorage does not know \ref MapWin - ///\param mapname name of new map - void registerNewEdgeMap(std::string mapname); - - ///Registers recently created nodemap in \ref MapWin. - - ///After creation of new map \ref MapStorage emits a signal. - ///This signal is bound to this callback function, that will call - ///a function with the same name and same parameter in \ref MapWin. - ///This call-forwarder function is needed, because \ref Mapstorage does not know \ref MapWin - ///\param mapname name of new map - void registerNewNodeMap(std::string mapname); - - ///Pops up and registrates the \ref MapWin of \ref NoteBookTab. - - ///See also - ///\ref mapwin. - void createMapWin(std::string); - - ///Closes and deregistrates the \ref MapWin of \ref NoteBookTab. - - ///See also - ///\ref mapwin. - void closeMapWin(); -}; - -#endif //NBTAB_H diff -r a979fcdda073 -r 8e27998e9b1d gui/new_map_win.cc --- a/gui/new_map_win.cc Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,499 +0,0 @@ -#include - -bool NewMapWin::closeIfEscapeIsPressed(GdkEventKey* e) -{ - if(e->keyval==GDK_Escape) - { - hide(); - } - return true; -} - -NewMapWin::NewMapWin(const std::string& title, NoteBookTab & mw, bool itisedge, bool edgenode):Gtk::Dialog(title, true, true),mytab(mw),node("Create NodeMap"),edge("Create EdgeMap") -{ - set_default_size(200, 50); - - signal_key_press_event().connect(sigc::mem_fun(*this, &NewMapWin::closeIfEscapeIsPressed)); - - Gtk::VBox * vbox=get_vbox(); - - //entries - table=new Gtk::Table(3, 2, false); - - label=new Gtk::Label; - label->set_text("Name of new map:"); - name.set_text(""); - - (*table).attach(*label,0,1,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3); - (*table).attach(name,1,2,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3); - - label=new Gtk::Label; - label->set_text("Default value in the map:"); - default_value.set_text("0"); - - (*table).attach(*label,0,1,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3); - (*table).attach(default_value,1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3); - - //node vs. edge map selector - Gtk::RadioButton::Group group = node.get_group(); - edge.set_group(group); - - if(edgenode) - { - (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3); - (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3); - } - else - { - if(itisedge) - { - edge.set_active(); - } - else - { - node.set_active(); - } - } - - vbox->pack_start(*table); - - //OK button - add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); - - show_all_children(); - -} - -void NewMapWin::on_response(int response_id) -{ - if(response_id==Gtk::RESPONSE_OK) - { - double def_val=0; - - //get and formulate text - std::string def_val_str=default_value.get_text(); - - bool only_nums=true; - for(int i=0;i<(int)def_val_str.size() && only_nums;i++) - { - if( def_val_str[i]<'0' || def_val_str[i]>'9' ) - { - only_nums=false; - } - } - std::string polishform; - - if(only_nums) - { - def_val=atof(def_val_str.c_str()); - } - else - { - polishform=string2Polishform(def_val_str,edge.get_active()); - } - - //get name of text - std::string mapname=name.get_text(); - - if(!mapname.empty()&&(!polishform.empty()||only_nums)) - { - int abortion=0; - if(edge.get_active()) - { - //create the new map - Graph::EdgeMap * emptr=new Graph::EdgeMap (mytab.mapstorage.graph, def_val); - - if(!only_nums) - { - std::stack polishstack; - - for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k) - { - for(int i=0;i<(int)polishform.size();i++) - { - double op1=0, op2=0; - bool operation=true; - switch(polishform[i]) - { - case '+': - case '-': - case '/': - case '*': - op1=polishstack.top(); - polishstack.pop(); - op2=polishstack.top(); - polishstack.pop(); - break; - default: - //substitute variable - std::map< std::string,Graph::EdgeMap * > ems=mytab.mapstorage.edgemap_storage; - bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end()); - if(itisvar) - { - polishstack.push( (*(mytab.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]); - } - else - { - polishstack.push(atof(ch2var[ polishform[i] ].c_str())); - } - operation=false; - break; - } - if(operation) - { - double res; - switch(polishform[i]) - { - case '+': - res=op1+op2; - break; - case '-': - res=op2-op1; - break; - case '/': - res=op2/op1; - break; - case '*': - res=op1*op2; - break; - default: - std::cout << "How could we get here?" << std::endl; - break; - } - polishstack.push(res); - } - }//foreach letter in polishform - (*emptr)[k]=polishstack.top(); - }//foreach edge - }//!only_nums - - //if addition was not successful addEdgeMap returns one. - //cause can be that there is already a map named like the new one - if(mytab.mapstorage.addEdgeMap(mapname, emptr, def_val)) - { - abortion=1; - } - - //add it to the list of the displayable maps - //furthermore it is done by signals - //mytab.registerNewEdgeMap(mapname); - - //display it - //gdc.changeEdgeText(mapname); - } - else //!edge.get_active() - { - //create the new map - Graph::NodeMap * emptr=new Graph::NodeMap (mytab.mapstorage.graph, def_val); - - if(!only_nums) - { - std::stack polishstack; - - for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k) - { - for(int i=0;i<(int)polishform.size();i++) - { - double op1=0, op2=0; - bool operation=true; - switch(polishform[i]) - { - case '+': - case '-': - case '/': - case '*': - op1=polishstack.top(); - polishstack.pop(); - op2=polishstack.top(); - polishstack.pop(); - break; - default: - std::map< std::string,Graph::NodeMap * > nms=mytab.mapstorage.nodemap_storage; - bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end()); - if(itisvar) - { - polishstack.push( (*(mytab.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]); - } - else - { - polishstack.push(atof(ch2var[ polishform[i] ].c_str())); - } - operation=false; - break; - } - if(operation) - { - double res; - switch(polishform[i]) - { - case '+': - res=op1+op2; - break; - case '-': - res=op2-op1; - break; - case '/': - res=op2/op1; - break; - case '*': - res=op1*op2; - break; - default: - std::cout << "How could we get here?" << std::endl; - break; - } - polishstack.push(res); - } - } - (*emptr)[k]=polishstack.top(); - } - } - //if addition was not successful addNodeMap returns one. - //cause can be that there is already a map named like the new one - if(mytab.mapstorage.addNodeMap(mapname,emptr, def_val)) - { - abortion=1; - } - - //add it to the list of the displayable maps - //furthermore it is done by signals - //mytab.registerNewNodeMap(mapname); - - //display it - //gdc.changeNodeText(mapname); - } - if(!abortion) - { - name.set_text(""); - default_value.set_text("0"); - edge.show(); - node.show(); - hide(); - } - } - } -} - - -std::string NewMapWin::string2Polishform(std::string rawcommand, bool itisedge) -{ - bool valid_entry=true; - - std::map str2i; - - std::string command; - - std::string variable; - - char index='a'; - - for(int i=0;(valid_entry&&(i<(int)rawcommand.size()));i++) - { - switch(rawcommand[i]) - { - case '+': - case '-': - case '*': - case '/': - case ')': - case '(': - if(!variable.empty()) - { - valid_entry=validVariable(variable, itisedge); - ch2var[index]=variable; - command+=index; - index++; - variable.erase(0,variable.size()); - } - command+=rawcommand[i]; - break; - default: - variable+=rawcommand[i]; - break; - } - } - - if(!variable.empty()&&valid_entry) - { - valid_entry=validVariable(variable, itisedge); - ch2var[index]=variable; - command+=index; - index++; - variable.erase(0,variable.size()); - } - - if(valid_entry) - { - unsigned int pr=10000; - bool prevmult=false; - unsigned int prev_change=pr; - unsigned int prev_br=pr; - int counter=0; - std::string comm_nobr=""; - std::vector p; - p.resize(counter+1); - - //limits - //6 brackets embedded - //100 operation in a row from the same priority - - for(int i=0;i<(int)command.size();i++) - { - bool put_in_string=true; - switch(command[i]) - { - case '(': - pr=prev_br+10000; - prev_br=pr; - prevmult=false; - put_in_string=false; - break; - case ')': - pr=prev_br-10000; - prev_br=pr; - prevmult=false; - put_in_string=false; - break; - case '+': - case '-': - if(prevmult) - { - pr=prev_change; - } - p[counter]=pr; - pr-=100; - - prevmult=false; - break; - case '/': - case '*': - if(!prevmult) - { - prev_change=pr; - pr+=200; - pr-=1; - } - p[counter]=pr; - pr-=1; - prevmult=true; - break; - default: - p[counter]=65000; - break; - } - if(put_in_string) - { - counter++; - p.resize(counter+1); - comm_nobr=comm_nobr+command[i]; - } - } - - tree_node * root=weightedString2Tree(comm_nobr, p, 0); - - std::string polishform=postOrder(root); - - deleteTree(root); - - return polishform; - } - return ""; -} - -void NewMapWin::deleteTree(NewMapWin::tree_node * node) -{ - if(node->left_child!=NULL) - { - deleteTree(node->left_child); - } - if(node->right_child!=NULL) - { - deleteTree(node->right_child); - } - delete node; -} - -NewMapWin::tree_node * NewMapWin::weightedString2Tree(std::string to_tree, std::vector & p, int offset) -{ - unsigned int min=p[offset]; - int minplace=0; - for(int i=0;i<(int)to_tree.size();i++) - { - if(min>p[offset+i]) - { - min=p[offset+i]; - minplace=i; - } - } - tree_node * act_node=new tree_node; - act_node->ch=to_tree[minplace]; - if(to_tree.size()>=3) - { - act_node->left_child=weightedString2Tree(to_tree.substr(0,minplace), p, offset); - act_node->right_child=weightedString2Tree(to_tree.substr(minplace+1,to_tree.size()-minplace-1), p, offset+minplace+1); - } - else - { - act_node->left_child=NULL; - act_node->right_child=NULL; - } - return act_node; -} - -std::string NewMapWin::postOrder(tree_node * subtree) -{ - std::string subtree_to_string; - if(subtree->left_child) - { - subtree_to_string=postOrder(subtree->left_child); - } - if(subtree->right_child) - { - subtree_to_string=subtree_to_string+postOrder(subtree->right_child); - } - subtree_to_string=subtree_to_string+subtree->ch; - return subtree_to_string; -} - -bool NewMapWin::validVariable(std::string variable, bool itisedge) -{ - bool cancel; - //is it mapname? - if(itisedge) - { - cancel=(mytab.mapstorage.edgemap_storage.find(variable)==mytab.mapstorage.edgemap_storage.end()); - } - else - { - cancel=(mytab.mapstorage.nodemap_storage.find(variable)==mytab.mapstorage.nodemap_storage.end()); - } - //maybe it is number - int point_num=0; - if(cancel) - { - cancel=false; - for(int j=0;(!cancel)&&(j<(int)variable.size());j++) - { - if(((variable[j]<'0')||(variable[j]>'9'))&&(variable[j]!='.')) - { - cancel=true; - } - else - { - if(variable[j]=='.') - { - point_num++; - if(point_num>1) - { - cancel=true; - } - } - } - } - } - if(cancel) - { - return false; - } - return true; -} diff -r a979fcdda073 -r 8e27998e9b1d gui/new_map_win.h --- a/gui/new_map_win.h Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,136 +0,0 @@ -// -*- C++ -*- // - -#ifndef NEWMAPWIN_H -#define NEWMAPWIN_H - -class NewMapWin; - -#include -#include -#include -#include -#include - -///Graphical interface for node/edge map creation. - -///This class is responsible for creating a window, -///on which the parameters of a new map can be set. -class NewMapWin : public Gtk::Dialog -{ - ///The \ref NoteBookTab in which the new map has to be placed. - NoteBookTab & mytab; - -public: - - ///Struct to be able to evaluate expressions. - - ///Initial values of map elements can be given - ///by numbers or by expressions. From expressions - ///we build first a tree according to the priorities - ///of operations in the expression. This is the data - ///structure - ///that can store one tree element. - struct tree_node - { - ///Character stored in this tree element - char ch; - ///Left child of tree element. - tree_node * left_child; - ///Right child of tree element. - tree_node * right_child; - }; - - ///Constructor of NewMapWin. - - ///It creates the widgets shown in - ///NewMapWin. - NewMapWin(const std::string& title, NoteBookTab &, bool itisedge=true, bool edgenode=true); - - ///Callback function for OK button. It creates the map. - - ///This function determines whether the input is correct: - ///the name of new map must not be already used, the expression - ///that gives tha initial values of map elements has to be valid. - ///If input is correct it creates and registrates the new map - ///to the correct place. (\ref mytab) - virtual void on_response(int response_id); - - ///Close window if Esc key pressed. - virtual bool closeIfEscapeIsPressed(GdkEventKey*); - - ///Function that creates a tree from an appropriately manipulated string. - - ///Tree is builded according to priorities of operations in expression given by string. - ///Priorities are indicated in a vector that contains weights for each operation. - ///\param to_tree string to build tree from - ///\param weights weights (priorities) - ///\param offset this function call is recursive. This parameter tells us, - ///with which part of the string do we have to deal with. - tree_node * weightedString2Tree(std::string to_tree, std::vector & weights, int offset); - - ///Function that creates a string from a tree by postorder reading. - - ///This is the last step of creating polishform - ///from a given expression string. - ///\param root the root of the tree to read through - std::string postOrder(tree_node * root); - - ///From the given expression it creates expression given in polish form. - - ///First it substitutes variables and numbers in the given expression. - ///The substitutions will be one character long local variables. - ///The substituted-substitution pair is registrated in \ref ch2var. - ///After that it gives weights fo each character in substituted expression. - ///Weights are calculated according to the priority of operations in expression. - ///Then it creates tree (\ref tree_node) from the weighted string. (\ref weightedString2Tree) - ///\param to_polish the string to turn into polish_form - ///\param itisedge do we have to create an edgemap or a nodemap. - ///It is important, because variables are maps and if expression - ///citates a map that does not exists the expression is not valid. - ///But to determine, whether the map exists we have to know where - ///to search for it. And of course for a new edgemap only edgemaps can be serve with values. - std::string string2Polishform(std::string to_polish, bool itisedge); - - ///Returns whether a string can be used as value in an expression. - - ///The given string has to be either a mapname or a number. If it is a mapname - ///we have to know whether it is an edgemap or a nodemap. - ///\param variable the string about the function has to determine whether it is usable in expressions - ///\param itisedge should the mapname be between edgemaps, or nodemaps - bool validVariable(std::string variable, bool itisedge); - - ///Deletes the whole tree created for translating string to polishform. - - ///\param root - ///root of the tree - void deleteTree(tree_node * root); - - ///Dictionary of substitutions in expression. - - ///Variables and numbers are substituted with one character long variables in expressions. - ///This is the dictionary. - std::map ch2var; - - ///Entry which gives us the name of new map. - Gtk::Entry name; - - ///Entry which gives us the initial values of elements of new map. - - ///Initial value can be a number or an expression after that the - ///initial value for each map element can be calculated. - Gtk::Entry default_value; - - ///GTK Designing object. - Gtk::Table * table; - - ///Information holder in window. - Gtk::Label * label; - - ///If selected, nodemap will be created. - Gtk::RadioButton node; - - ///If selected, edgemap will be created. - Gtk::RadioButton edge; -}; - -#endif //NEWMAPWIN_H diff -r a979fcdda073 -r 8e27998e9b1d gui/xml.h --- a/gui/xml.h Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,442 +0,0 @@ -/* -*- C++ -*- - * gui/xml.h - Part of LEMON, a generic C++ optimization library - * - * Copyright (C) 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 -#include -#include -#include -#include -#include -#include - -namespace lemon { - - class XmlIo - { - bool _writeMode; - public: - ///Check if XmlIo is in write mode. - bool write() { return _writeMode;} - ///Check if XmlIo is in read mode. - bool read() { return !_writeMode;} - - std::ostream& os; - int level; - - protected: - void indent(int level) { - os << std::endl; - for(int i=0;i'; - } - void etag(const std::string &_tag) { - os << "'; - } - void itag(const std::string &_tag) { indent();tag(_tag); } - void ietag(const std::string &_tag) { indent();etag(_tag); } - - void beginTag(const std::string &_tag) { - itag(_tag); - level++; - } - void endTag(const std::string &_tag) { - level--; - ietag(_tag); - } - - public: - ///Indent the line according to its level. - - ///\warning It can only be used in write mode. - /// - void indent() - { - if(write()) - if(level>=0) indent(level); - else level=0; - else throw LogicError(); - } - - ///Read/write a tag - - ///Read/write a tag. - ///In write mode it does not start a new line. - class ContTag - { - XmlIo &ix; - const std::string _tag; - public: - ///\e - - ///\e - /// - ContTag(XmlIo &_ix,const std::string &_t) : - ix(_ix), _tag(_t) - { - if(ix.write()) ix.tag(_tag); - else ix.useTag(_tag); - } - ~ContTag() { - if(ix.write()) ix.etag(_tag); - else if(!std::uncaught_exception()) ix.useTag('/'+_tag); - } - }; - - ///Read/write a tag - - ///Read/write a tag. - ///The whole \ ... \ will be placed in a single line. - class LineTag - { - XmlIo &ix; - const std::string _tag; - public: - ///\e - - ///\e - /// - LineTag(XmlIo &_ix,const std::string &_t) : - ix(_ix), _tag(_t) - { - if(ix.write()) ix.itag(_tag); - else ix.useTag(_tag); - } - ~LineTag() { - if(ix.write()) ix.etag(_tag); - else if(!std::uncaught_exception()) ix.useTag('/'+_tag); - } - }; - - ///Read/write a tag - - ///Read/write a tag. - /// - class Tag - { - XmlIo &ix; - const std::string _tag; - public: - ///\e - - ///\e - /// - Tag(XmlIo &_ix,const std::string &_t) : - ix(_ix), _tag(_t) - { - if(ix.write()) ix.beginTag(_tag); - else ix.useTag(_tag); - } - ~Tag() { - if(ix.write()) ix.endTag(_tag); - else if(!std::uncaught_exception()) ix.useTag('/'+_tag); - } - }; - - private: - std::istream& is; - std::string next_tag; - int line_number; - - void skipWhiteSpaces() - { - if(write()) throw LogicError(); - { - char c; - while (is.get(c) && std::isspace(c,is.getloc())) - if(c=='\n') line_number++; - is.unget(); - } - } - protected: - /// Use the next tag. - - ///\e - /// - void useTag() {next_tag.clear();} - - ///Use the next tag and check if it is equal with \c _tag - - ///\e - /// - void useTag(const std::string &_tag) { - if(nextTag()==_tag) useTag(); - else throw DataFormatError("",line_number,"Unexpected token name"); - } - public: - ///Return the next tag (if a tag follows on the stream). - - ///\warning It can only be used in read mode. - /// - const std::string &nextTag() - { - if(write()) throw LogicError(); - else if(next_tag.empty()) { - char c; - skipWhiteSpaces(); - if(!is.get(c) || c!='<') - throw DataFormatError("",line_number,"Bad format"); - next_tag.clear(); - while (is.get(c) && c!='>') next_tag.push_back(c); - if(c!='>') - throw DataFormatError("",line_number,"Bad format"); - } - return next_tag; - } - - /**********************************************************************/ - - - ///\e - - ///\e - /// - XmlIo(std::ostream& _os) : _writeMode(true), os(_os), - level(-1), - is(std::cin) {} - ///\e - /// - XmlIo(std::istream& _is) : _writeMode(false), - os(std::cout), is(_is), - line_number(1) {} - - ~XmlIo() { if(write()) os<< std::endl; } - - - - XmlIo &operator()(const int &v) - { - if(write()) os << v; - else { - skipWhiteSpaces(); - if(!(is >> const_cast(v))) - throw DataFormatError("",line_number,"Not an 'int'"); - } - return *this; - } - XmlIo &operator()(const double &v) - { - if(write()) os << v; - else { - skipWhiteSpaces(); - if(!(is >> const_cast(v))) - throw DataFormatError("",line_number,"Not an 'double'"); - } - return *this; - } - XmlIo &operator()(const std::string &v) - { - if(write()) - for(std::string::const_iterator i=v.begin();i!=v.end();++i) - switch(*i) { - case '\\': - os << "\\\\"; - break; - case '<': - os << "\\<"; - break; - case '&': - os << "\\&"; - break; - case '\n': - os << "\\n"; - break; - default: - os<<*i; - break; - } - else { - std::string &w = const_cast(v); - w.clear(); - char c; - while (is.get(c) && c!='<') - if(c=='\\') - if(!is.get(c)) - throw DataFormatError("",line_number,"Bad string"); - else switch(c) { - case 'n': - w.push_back('\n'); - break; - default: - w.push_back(c); - break; - } - else { - if(c=='\n') line_number++; - w.push_back(c); - } - if(c!='<') - throw DataFormatError("",line_number,"Unexpected eof"); - is.unget(); - } - return *this; - } - - - XmlIo &operator()(const std::string &_tag,const int &v) - { - LineTag t(*this,_tag); - (*this)(v); - return *this; - } - XmlIo &operator()(const std::string &_tag,const double &v) - { - LineTag t(*this,_tag); - (*this)(v); - return *this; - } - XmlIo &operator()(const std::string &_tag,const std::string &v) - { - LineTag t(*this,_tag); - (*this)(v); - return *this; - } - ///\e - - ///\e - /// - template - XmlIo &operator()(const std::string &_tag,const V &v) - { - Tag t(*this,_tag); - xml(*this,const_cast(v)); - return *this; - } - ///\e - - ///\e - /// - template - XmlIo &operator()(const V &v) - { - xml(*this,const_cast(v)); - return *this; - } - }; - - ////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////// - - ///\e - - ///\relates XmlIo - /// - template - void xml(XmlIo &x,std::auto_ptr &v) - { - if(x.write()) v=new A; - x(*v); - } - - ///\e - - ///\relates XmlIo - /// - template - void xml(XmlIo &x,std::pair &v) - { - x("first",v.first); - x("second",v.second); - } - - ///\e - - ///\relates XmlIo - /// - template - void xml(XmlIo &x,std::list &v) - { - if(x.write()) - for(typename std::list::const_iterator it=v.begin(); - it!=v.end();++it) x("item",*it); - else while(x.nextTag()=="item") - { - v.push_back(T()); - x("item",v.back()); - } - } - ///\e - - ///\relates XmlIo - /// - template - void xml(XmlIo &x,std::vector &v) - { - if(x.write()) - for(typename std::vector::const_iterator it=v.begin(); - it!=v.end();++it) x("item",*it); - else while(x.nextTag()=="item") - { - v.push_back(T()); - x("item",v.back()); - } - } - - ///\e - - ///\relates XmlIo - /// - template - void xml(XmlIo &x,std::map &v) - { - if(x.write()) - for(typename std::map::const_iterator it=v.begin(); - it!=v.end();++it) x("item",*it); - else while(x.nextTag()=="item") - { - typename std::map::value_type it; - x("item",it); - v.insert(it); - } - } - - ///\e - - ///\relates XmlIo - /// - template - void xml(XmlIo &x,lemon::xy &v) - { - { XmlIo::LineTag t(x,"x"); x(v.x); } - { XmlIo::ContTag t(x,"y"); x(v.y); } - } - - ///\e - - ///\relates XmlIo - /// - template - void xml(XmlIo &x,lemon::BoundingBox &v) - { - if(x.write()) { - if(!v.empty()) { - x("point",v.bottomLeft()); - if(v.bottomLeft()!=v.topRight()) x("point",v.topRight()); - } - } - else { - v.clear(); - while(x.nextTag()=="point") { - lemon::xy co; - x("point",co); - v.add(co); - } - } - } - -} - diff -r a979fcdda073 -r 8e27998e9b1d gui/xymap.h --- a/gui/xymap.h Wed Jun 21 08:35:23 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -#ifndef XYMAP_H -#define XYMAP_H - -#include -#include - -template -class XYMap -{ - private: - M *xmap, *ymap; - - public: - typedef typename M::Key Key; - typedef lemon::xy Value; - XYMap() {} - XYMap(M &_xmap, M &_ymap) : xmap(&_xmap), ymap(&_ymap) {} - void setXMap(M &_xmap) { xmap = &_xmap; } - void setYMap(M &_ymap) { ymap = &_ymap; } - Value operator[](Key k) const - { - Value v(xmap->operator[](k), ymap->operator[](k)); - return v; - } - void set(Key k, Value v) - { - xmap->set(k, v.x); - ymap->set(k, v.y); - } -}; - -#endif