algobox.h
author Akos Ladanyi <ladanyi@tmit.bme.hu>
Mon, 07 Jul 2008 15:20:43 +0100
changeset 3 2cc5ed6e6255
permissions -rw-r--r--
Use hg changeset hash instead of svn revision.
hegyi@1
     1
/* -*- C++ -*-
hegyi@1
     2
 *
hegyi@1
     3
 * This file is a part of LEMON, a generic C++ optimization library
hegyi@1
     4
 *
hegyi@1
     5
 * Copyright (C) 2003-2006
hegyi@1
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
hegyi@1
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
hegyi@1
     8
 *
hegyi@1
     9
 * Permission to use, modify and distribute this software is granted
hegyi@1
    10
 * provided that this copyright notice appears in all copies. For
hegyi@1
    11
 * precise terms see the accompanying LICENSE file.
hegyi@1
    12
 *
hegyi@1
    13
 * This software is provided "AS IS" with no warranty of any kind,
hegyi@1
    14
 * express or implied, and with no claim as to its suitability for any
hegyi@1
    15
 * purpose.
hegyi@1
    16
 *
hegyi@1
    17
 */
hegyi@1
    18
hegyi@1
    19
#ifndef ALGOBOX_H
hegyi@1
    20
#define ALGOBOX_H
hegyi@1
    21
hegyi@1
    22
class MapStorage;
hegyi@1
    23
class MapSelector;
hegyi@1
    24
hegyi@1
    25
#include <all_include.h>
hegyi@1
    26
#include <libgnomecanvasmm.h>
hegyi@1
    27
#include <libgnomecanvasmm/polygon.h>
hegyi@1
    28
#include "map_value.h"
hegyi@1
    29
hegyi@1
    30
///Ancestor class of algorithm digraphical interface classes.
hegyi@1
    31
hegyi@1
    32
///It also demonstrates, how should an algorithm digraphical interface
hegyi@1
    33
///work. Children of this class have the same functions and attributes,
hegyi@1
    34
///therefore with all of them can the holder \ref AlgoWin communicate
hegyi@1
    35
///in the same way.
hegyi@1
    36
///
hegyi@1
    37
///IMPORTANT! In a child class only the following tasks are to do:
hegyi@1
    38
///
hegyi@1
    39
///-call \ref init function with correct parameters from correctly parametrized constructor
hegyi@1
    40
///
hegyi@1
    41
///-implement \ref build_box function
hegyi@1
    42
///
hegyi@1
    43
///-implement \ref run function
hegyi@1
    44
///
hegyi@1
    45
///because all other thing is automatically done in \ref init function!
hegyi@1
    46
hegyi@1
    47
class AlgoBox : public Gtk::VBox
hegyi@1
    48
{
hegyi@1
    49
  ///Signal emitted in case of need for list of maps.
hegyi@1
    50
hegyi@1
    51
  ///If the user has selected different tab to work on
hegyi@1
    52
  ///new maps are selected as well. These new maps should be
hegyi@1
    53
  ///provided for \ref AlgoBox. To get these maps, \ref AlgoBox
hegyi@1
    54
  ///emits this signal.
hegyi@1
    55
  sigc::signal<void, std::string> signal_maplist_need;
hegyi@1
    56
hegyi@1
    57
  ///Signal emitted in case of need for \ref NewMapWin.
hegyi@1
    58
hegyi@1
    59
  ///If user wants to create a new for an input, or output
hegyi@1
    60
  ///it can let \ref NewMapWin popped up from here as well.
hegyi@1
    61
  ///In that case will be this signal emitted.
hegyi@1
    62
  sigc::signal<void, std::string, bool> signal_newmapwin_need;
hegyi@1
    63
hegyi@1
    64
  ///Signal emitted when maplists are updated after tab change
hegyi@1
    65
  sigc::signal<void> signal_maplist_updated;
hegyi@1
    66
hegyi@1
    67
hegyi@1
    68
protected:
hegyi@1
    69
  ///Holder of tabnames.
hegyi@1
    70
  Gtk::ComboBoxText tabcbt;
hegyi@1
    71
hegyi@1
    72
  ///Holder of widgets, in which nodemaps can be selected to work on.
hegyi@1
    73
  std::vector<MapSelector *> nodemapcbts;
hegyi@1
    74
hegyi@1
    75
  ///Holder of widgets, in which arcmaps can be selected to work on.
hegyi@1
    76
  std::vector<MapSelector *> arcmapcbts;
hegyi@1
    77
hegyi@1
    78
  ///Maps of selected tabs.
hegyi@1
    79
  MapStorage * mapstorage;
hegyi@1
    80
hegyi@1
    81
public:
hegyi@1
    82
  ///Empty constructor called by children.
hegyi@1
    83
  AlgoBox(){};
hegyi@1
    84
hegyi@1
    85
  ///Constructor
hegyi@1
    86
hegyi@1
    87
  ///Calls \ref init function
hegyi@1
    88
  ///with the provided parameters. \ref init function
hegyi@1
    89
  ///is needed, because it is virtual, therefore the
hegyi@1
    90
  ///functions of the proper class will be called when
hegyi@1
    91
  ///running.
hegyi@1
    92
  ///\param tablist list of tabs in \ref MainWin
hegyi@1
    93
  AlgoBox(std::vector<std::string> tablist);
hegyi@1
    94
hegyi@1
    95
  ///Initiates \ref AlgoBox.
hegyi@1
    96
hegyi@1
    97
  ///Creates the digraphical interface for the realized algorithm, initiates variables, connects signals.
hegyi@1
    98
  ///
hegyi@1
    99
  ///List of tabs in \ref MainWin is required, but no one
hegyi@1
   100
  ///will be selected automatically. Every other
hegyi@1
   101
  ///entry field remains empty (unselected), until a \ref NoteBookTab
hegyi@1
   102
  ///is selected.
hegyi@1
   103
  ///
hegyi@1
   104
  ///It also have to bind all the signals to the correct place.
hegyi@1
   105
  ///This function is virtual, in all type of children of
hegyi@1
   106
  ///\ref AlgoBox the correct function willbe called.
hegyi@1
   107
  ///
hegyi@1
   108
  ///Therefore it is IMPORTANT that only \ref run and \ref build_box
hegyi@1
   109
  ///has to be implemented in children of \ref AlgoBox, every other
hegyi@1
   110
  ///thing will automatically work properly by the help of this
hegyi@1
   111
  ///function that must be called in constructor of child!!!
hegyi@1
   112
  virtual void init(std::vector<std::string>);
hegyi@1
   113
hegyi@1
   114
  ///Signal emitted, when selected tab changes, and new list of maps required.
hegyi@1
   115
  sigc::signal<void, std::string> signal_maplist_needed();
hegyi@1
   116
hegyi@1
   117
  ///Emitted if user wants to create a new map for inpuit or output.
hegyi@1
   118
  sigc::signal<void, std::string, bool> signal_newmapwin_needed(){return signal_newmapwin_need;};
hegyi@1
   119
hegyi@1
   120
  sigc::signal<void> signal_upon_maplist_updated(){return signal_maplist_updated;};
hegyi@1
   121
hegyi@1
   122
  ///Emits signal that requires list of maps for the recently selected \ref NoteBookTab.
hegyi@1
   123
  void emit_tab_change();
hegyi@1
   124
hegyi@1
   125
  ///Interface, through which \ref AlgoBox can be notified about tab addition, deletion in \ref MainWin
hegyi@1
   126
hegyi@1
   127
  ///\param tl list
hegyi@1
   128
  ///of new tab state.
hegyi@1
   129
  void update_tablist( std::vector< std::string > tl );
hegyi@1
   130
hegyi@1
   131
  ///Interface, through which \ref AlgoBox can get the maps of the recently selected \ref NoteBookTab
hegyi@1
   132
hegyi@1
   133
  ///\param ms the maps
hegyi@1
   134
  ///of the recently selected \ref NoteBookTab
hegyi@1
   135
  void update_maplist( MapStorage * ms);
hegyi@1
   136
hegyi@1
   137
  ///Interface, through which \ref AlgoBox can be notified about nodemap addition.
hegyi@1
   138
hegyi@1
   139
  ///If new map was added to \ref MapStorage of currently selected \ref NoteBookTab
hegyi@1
   140
  ///a signal is emitted by it. This signal is connected to this function, so \ref MapSelector s
hegyi@1
   141
  ///in \ref nodemapcbts can be notified, and those can registrate the new map. (\ref MapSelector::append_text)
hegyi@1
   142
  void nodemaplist_changed(std::string, MapValue::Type);
hegyi@1
   143
hegyi@1
   144
  ///Interface, through which \ref AlgoBox can be notified about arcmap addition.
hegyi@1
   145
hegyi@1
   146
  ///If new map was added to \ref MapStorage of currently selected \ref NoteBookTab
hegyi@1
   147
  ///a signal is emitted by it. This signal is connected to this function, so \ref MapSelector s
hegyi@1
   148
  ///in \ref arcmapcbts can be notified, and those can registrate the new map. (\ref MapSelector::append_text)
hegyi@1
   149
  void arcmaplist_changed(std::string, MapValue::Type);
hegyi@1
   150
hegyi@1
   151
  ///Aid function to provide data for a given entry.
hegyi@1
   152
hegyi@1
   153
  ///At the moment it is only used for updating info
hegyi@1
   154
  ///in \ref tabcbt. It clears it first, after that
hegyi@1
   155
  ///inserts the data got from caller, and if there
hegyi@1
   156
  ///was previously selected item it switches entry
hegyi@1
   157
  ///to that.
hegyi@1
   158
  ///\param tl list of entries (at the moment tabs in \ref MainWin)
hegyi@1
   159
  ///\param cbt the entry to update (at the moment only \ref tabcbt)
hegyi@1
   160
  void update_cbt( std::vector< std::string > tl, Gtk::ComboBoxText & cbt);
hegyi@1
   161
hegyi@1
   162
  ///Runs the ralized algorithm.
hegyi@1
   163
hegyi@1
   164
  ///Prepare the data for it
hegyi@1
   165
  ///and after that postprocess it if necessary.
hegyi@1
   166
  ///This is only a demo here, but in children it
hegyi@1
   167
  ///runs the algorithm really.
hegyi@1
   168
  virtual void run();
hegyi@1
   169
hegyi@1
   170
  ///Creates the layout of the \ref AlgoBox
hegyi@1
   171
hegyi@1
   172
  ///Place all the entries
hegyi@1
   173
  ///required. Run and close button is not
hegyi@1
   174
  ///its responsibility!
hegyi@1
   175
  virtual void build_box();
hegyi@1
   176
hegyi@1
   177
  ///Emits \ref signal_newmapwin_need if user wants to create new input or output map.
hegyi@1
   178
hegyi@1
   179
  ///Called in case of pressing \ref MapSelector::newbut.
hegyi@1
   180
  ///\param itisarc arc or nodemap is required.
hegyi@1
   181
  virtual void emit_new_map_signal(bool itisarc);
hegyi@1
   182
hegyi@1
   183
  ///Aid function to make addition of \ref MapSelector easy in \ref build_box.
hegyi@1
   184
hegyi@1
   185
  ///\param label label to show in \ref MapSelector
hegyi@1
   186
  ///\param itisarc whether arc or nodemaps stored in \ref MapSelector
hegyi@1
   187
  void addMapSelector(std::string label, bool itisarc, MapType type = ALL);
hegyi@1
   188
};
hegyi@1
   189
#endif //ALGOBOX_H