COIN-OR::LEMON - Graph Library

Changeset 172:fc1e478697d3 in glemon-0.x


Ignore:
Timestamp:
10/25/06 15:21:24 (17 years ago)
Author:
Hegyi Péter
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@3017
Message:

Currently visualized map can be saved and loaded from file.

Files:
14 edited

Legend:

Unmodified
Added
Removed
  • design_win.cc

    r161 r172  
    1010}
    1111
    12 DesignWin::DesignWin(const std::string& title, double attraction_v, double propulsation_v, int iterations_v)
     12DesignWin::DesignWin(const std::string& title, double attraction_v, double propulsation_v, int iterations_v, NoteBookTab & mw):mytab(mw)
    1313{
    1414  set_title(title);
     15
     16  mytab.signal_title_ch().connect(sigc::mem_fun(*this, &DesignWin::set_title));
    1517
    1618  signal_key_press_event().connect(sigc::mem_fun(*this, &DesignWin::closeIfEscapeIsPressed));
     
    6567  signal_iteration_ch.emit((int)iteration->get_value());
    6668}
     69
     70void DesignWin::set_title(std::string tabname)
     71{
     72  Gtk::Window::set_title("Design Setup - "+tabname);
     73}
  • design_win.h

    r161 r172  
    44#define DESWIN_H
    55
     6class DesignWin;
     7
    68#include <all_include.h>
     9#include <nbtab.h>
    710#include <libgnomecanvasmm.h>
    811#include <libgnomecanvasmm/polygon.h>
     
    1114{
    1215private:
     16  ///\ref NoteBookTab to that the \ref MapWin belongs to.
     17  NoteBookTab & mytab;
     18
    1319  Gtk::SpinButton * attraction;
    1420  Gtk::SpinButton * propulsation;
     
    3440
    3541  ///It builds the window.
    36   DesignWin(const std::string&, double, double, int);
     42  DesignWin(const std::string&, double, double, int, NoteBookTab & mw);
    3743
    3844  sigc::signal<void, double> signal_attraction(){return signal_attraction_ch;};
     
    4046  sigc::signal<void, int> signal_iteration(){return signal_iteration_ch;};
    4147  sigc::signal<void> close_run(){return close_run_pr;};
     48
     49  void set_title(std::string);
    4250};
    4351#endif //DESWIN_H
  • graph_displayer_canvas.cc

    r168 r172  
    88  isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
    99  edgemap_to_edit(""), autoscale(true), zoomtrack(false), radius_size(20), edge_width(10),
    10   iterations(20), attraction(0.05), propulsation(40000), was_redesigned(false), mytab(mainw)
     10  iterations(20), attraction(0.05), propulsation(40000), was_redesigned(false), is_drawn(false), mytab(mainw)
    1111{
    1212  //base event handler is move tool
     
    6464void GraphDisplayerCanvas::propertyUpdate(Node node, int prop)
    6565{
    66   //dummy=dummy;
    67 
    6866  std::string mapname=mytab.getActiveNodeMap(prop);
    6967
    70   if(mapname!="")
    71     {
    72       if( ( ((mytab.mapstorage).nodemap_storage).find(mapname) != ((mytab.mapstorage).nodemap_storage).end() ) )
    73         {
     68  if(is_drawn)
     69    {
     70      if(mapname!="")
     71        {
     72          if( ( ((mytab.mapstorage).nodemap_storage).find(mapname) != ((mytab.mapstorage).nodemap_storage).end() ) )
     73            {
     74              switch(prop)
     75                {
     76                case N_RADIUS:
     77                  changeNodeRadius(mapname, node);
     78                  break;
     79                case N_COLOR:
     80                  changeNodeColor(mapname, node);
     81                  break;
     82                case N_TEXT:
     83                  changeNodeText(mapname, node);
     84                  break;
     85                default:
     86                  std::cerr<<"Error\n";
     87                }
     88            }
     89        }
     90      else //mapname==""
     91        {
     92          Node node=INVALID;   
    7493          switch(prop)
    7594            {
    7695            case N_RADIUS:
    77               changeNodeRadius(mapname, node);
     96              resetNodeRadius(node);
    7897              break;
    7998            case N_COLOR:
    80               changeNodeColor(mapname, node);
     99              resetNodeColor(node);
    81100              break;
    82101            case N_TEXT:
    83               changeNodeText(mapname, node);
     102              resetNodeText(node);
    84103              break;
    85104            default:
     
    88107        }
    89108    }
    90   else //mapname==""
    91     {
    92       Node node=INVALID;       
    93       switch(prop)
    94         {
    95         case N_RADIUS:
    96           resetNodeRadius(node);
    97           break;
    98         case N_COLOR:
    99           resetNodeColor(node);
    100           break;
    101         case N_TEXT:
    102           resetNodeText(node);
    103           break;
    104         default:
    105           std::cerr<<"Error\n";
    106         }
    107     }
    108 
    109109}
    110110
    111111void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop)
    112112{
    113   //dummy=dummy;
    114 
    115113  std::string mapname=mytab.getActiveEdgeMap(prop);
    116114
    117   if(mapname!="")
    118     {
    119       if( ( ((mytab.mapstorage).edgemap_storage).find(mapname) != ((mytab.mapstorage).edgemap_storage).end() ) )
     115  if(is_drawn)
     116    {
     117      if(mapname!="")
     118        {
     119          if( ( ((mytab.mapstorage).edgemap_storage).find(mapname) != ((mytab.mapstorage).edgemap_storage).end() ) )
     120            {
     121              switch(prop)
     122                {
     123                case E_WIDTH:
     124                  changeEdgeWidth(mapname, edge);
     125                  break;
     126                case E_COLOR:
     127                  changeEdgeColor(mapname, edge);
     128                  break;
     129                case E_TEXT:
     130                  changeEdgeText(mapname, edge);
     131                  break;
     132                default:
     133                  std::cerr<<"Error\n";
     134                }
     135            }
     136        }
     137      else //mapname==""
    120138        {
    121139          switch(prop)
    122140            {
    123141            case E_WIDTH:
    124               changeEdgeWidth(mapname, edge);
     142              resetEdgeWidth(edge);
    125143              break;
    126144            case E_COLOR:
    127               changeEdgeColor(mapname, edge);
     145              resetEdgeColor(edge);
    128146              break;
    129147            case E_TEXT:
    130               changeEdgeText(mapname, edge);
     148              resetEdgeText(edge);
    131149              break;
    132150            default:
    133151              std::cerr<<"Error\n";
    134152            }
    135         }
    136     }
    137   else //mapname==""
    138     {
    139       switch(prop)
    140         {
    141         case E_WIDTH:
    142           resetEdgeWidth(edge);
    143           break;
    144         case E_COLOR:
    145           resetEdgeColor(edge);
    146           break;
    147         case E_TEXT:
    148           resetEdgeText(edge);
    149           break;
    150         default:
    151           std::cerr<<"Error\n";
    152153        }
    153154    }
     
    208209  }
    209210
     211  is_drawn=true;
     212
     213  //upon drawing graph
     214  //properties have to
     215  //be set in as well
     216  for(int i=0;i<NODE_PROPERTY_NUM;i++)
     217    {
     218      propertyUpdate(Node(INVALID), i);
     219    }
     220
     221  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
     222    {
     223      propertyUpdate(Edge(INVALID), i);
     224    }
     225
    210226  updateScrollRegion();
    211227}
     
    228244    delete edgetextmap[e];
    229245  }
     246
     247  is_drawn=false;
    230248}
    231249
  • graph_displayer_canvas.h

    r166 r172  
    326326  void set_iteration(int);
    327327
     328  ///Show whether the graph is already drawn.
     329  bool is_drawn;
     330
    328331private:
    329332  ///Deletes the given element.
  • gui_reader.cc

    r150 r172  
    2727  }
    2828  mapstorage->ArrowPosReadOK();
     29
     30  std::map<int, std::string> nm;
     31  x("active_nodemaps", nm);
     32
     33  for(int i=0;i<NODE_PROPERTY_NUM;i++)
     34    {
     35      mapstorage->changeActiveMap(false, i, nm[i]);
     36    }
     37
     38  std::map<int, std::string> em;
     39  x("active_edgemaps", em);
     40  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
     41    {
     42      mapstorage->changeActiveMap(true, i, em[i]);
     43    }
    2944}
    3045
  • gui_writer.cc

    r150 r172  
    2020  }
    2121  x("arrow_pos", m);
     22
     23  std::map<int, std::string> nm;
     24  for(int i=0;i<NODE_PROPERTY_NUM;i++)
     25    {
     26      nm[i]=mapstorage->active_nodemaps[i];
     27    }
     28  x("active_nodemaps", nm);
     29
     30  std::map<int, std::string> em;
     31  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
     32    {
     33      em[i]=mapstorage->active_edgemaps[i];
     34    }
     35  x("active_edgemaps", em);
    2236}
    2337
  • map_win.cc

    r146 r172  
    2020
    2121  signal_key_press_event().connect(sigc::mem_fun(*this, &MapWin::closeIfEscapeIsPressed));
     22
     23  mytab.signal_title_ch().connect(sigc::mem_fun(*this, &MapWin::set_title));
    2224
    2325  e_combo_array=new MapSelector * [EDGE_PROPERTY_NUM];
     
    9193    n_combo_array[i]->update_list(nml);
    9294  }
     95
     96  mytab.active_maps_needed();
    9397}
    9498
     
    117121  return true;
    118122}
     123
     124void MapWin::changeEntry(bool isitedge, int prop, std::string mapname)
     125{
     126  if(isitedge)
     127    {
     128      e_combo_array[prop]->set_active_text(mapname);
     129    }
     130  else
     131    {
     132      n_combo_array[prop]->set_active_text(mapname);
     133    }
     134}
     135
     136void MapWin::set_title(std::string tabname)
     137{
     138  Gtk::Window::set_title("Map Setup - "+tabname);
     139}
  • map_win.h

    r123 r172  
    113113  ///\param nml node map list
    114114  void update(std::vector<std::string> eml, std::vector<std::string> nml);
     115
     116  void changeEntry(bool, int, std::string);
     117
     118  void set_title(std::string);
    115119};
    116120
  • mapselector.cc

    r122 r172  
    6868  int prev_act=cbt.get_active_row_number();
    6969  cbt.clear();
     70  cbt_content.clear();
    7071  std::vector< std::string >::iterator emsi=ml.begin();
    7172  for(;emsi!=ml.end();emsi++)
    7273    {
    7374      cbt.append_text(*emsi);
     75      cbt_content.push_back(*emsi);
    7476    }
    7577  if(def)
    7678    {
    7779      cbt.prepend_text("Default values");
     80      cbt_content.push_back("Default values");
    7881    }
    7982  if(prev_act!=-1)
     
    117120void MapSelector::set_active_text(Glib::ustring text)
    118121{
    119   cbt.set_active_text(text);
     122  if(text.compare(""))
     123    {
     124      cbt.set_active_text(text);
     125    }
     126  else
     127    {
     128      cbt.set_active_text("Default values");
     129    }
    120130}
    121131
     
    123133{
    124134  cbt.append_text(text);
     135  cbt_content.push_back(text);
     136
    125137  if(set_new_map)
    126138    {
  • mapselector.h

    r123 r172  
    6161  ///Names in it are selectable.
    6262  Gtk::ComboBoxText cbt;
     63
     64  std::vector<std::string> cbt_content;
    6365
    6466  ///New button.
  • mapstorage.cc

    r151 r172  
    5353int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value)
    5454{
    55   std::cout << default_value << std::endl;
    5655  if( nodemap_storage.find(name) == nodemap_storage.end() )
    5756    {
     
    7978  signal_prop.emit(itisedge, prop);
    8079}
     80
     81void MapStorage::broadcastActiveMaps()
     82{
     83  for(int i=0;i<NODE_PROPERTY_NUM;i++)
     84    {
     85      signal_map_win.emit(false, i, active_nodemaps[i]);
     86    }
     87 
     88  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
     89    {
     90      signal_map_win.emit(true, i, active_edgemaps[i]);
     91    }
     92}
     93
    8194
    8295std::string MapStorage::getActiveEdgeMap(int prop)
     
    441454  file_name = "";
    442455  modified = false;
     456
     457  arrow_pos_read_ok = false;
     458 
     459  for(int i=0;i<NODE_PROPERTY_NUM;i++)
     460    {
     461      changeActiveMap(false, i, "");
     462      signal_map_win.emit(false, i, "");
     463    }
     464 
     465  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
     466    {
     467      changeActiveMap(true, i, "");
     468      signal_map_win.emit(true, i, "");
     469    }
    443470}
    444471
  • mapstorage.h

    r118 r172  
    8686  sigc::signal<void, std::string> signal_edge_map;
    8787
     88  /// Signal emitted, when entry in \ref MapWin should be changed.
     89  sigc::signal<void, bool, int, std::string> signal_map_win;
     90
    8891public:
    8992  ///Constructor of MapStorage.
     
    110113  void changeActiveMap(bool itisedge , int prop , std::string mapname);
    111114
     115  ///Emits signals that let change the active maps in \ref MapWin.
     116  void broadcastActiveMaps();
     117
    112118  /// Returns the active edgemap shown by a visualization property.
    113119
     
    136142  ///returns \ref signal_edge_map to be able to connect functions to it
    137143  sigc::signal<void, std::string> signal_edge_map_ch(){return signal_edge_map;};
     144
     145  ///returns \ref signal_map_win to be able to connect functions to it
     146  sigc::signal<void, bool, int, std::string> signal_map_win_ch(){return signal_map_win;};
    138147
    139148  ///Adds given map to storage.
  • nbtab.cc

    r160 r172  
    203203    {
    204204      mapwin=new MapWin("Map Setup - "+name, mapstorage.getEdgeMapList(), mapstorage.getNodeMapList(), *this);
     205      mapst2mapwin=mapstorage.signal_map_win_ch().connect(sigc::mem_fun(*mapwin, &MapWin::changeEntry));
    205206      mapwin->show();
    206207      mapwinexists=true;
     
    215216      int iterations;
    216217      gd_canvas->get_design_data(attraction, propulsation, iterations);
    217       designwin=new DesignWin("Design Setup - "+name, attraction, propulsation, iterations);
     218      designwin=new DesignWin("Design Setup - "+name, attraction, propulsation, iterations, *this);
    218219
    219220      designwin->signal_attraction().connect(sigc::mem_fun(*this, &NoteBookTab::attraction_ch));
     
    231232void NoteBookTab::closeMapWin()
    232233{
     234  mapst2mapwin.disconnect();
    233235  mapwinexists=false;
    234236  delete mapwin;
     
    279281}
    280282
     283void NoteBookTab::active_maps_needed()
     284{
     285  mapstorage.broadcastActiveMaps();
     286}
  • nbtab.h

    r160 r172  
    184184  void getView(bool &, bool &, double&, double&);
    185185
     186  ///Let the graph redesign, based on gravity and edge elasticity.
    186187  void reDesignGraph();
    187188
     189  ///Indicates that attraction factor is changed
    188190  void attraction_ch(double);
    189191
     192  ///Indicates that propulsation factor is changed
    190193  void propulsation_ch(double);
    191194
     195  ///Indicates that iteration number of redesign is changed
    192196  void iteration_ch(int);
     197
     198  ///\ref MapWin calls this function when it updates the maplist in comboboxes.
     199  void active_maps_needed();
     200
     201private:
     202  ///Signal connection from \ref MapStorage to \ref MapWin
     203
     204  ///If \ref MapWin is closed this connection has to be disconnected,
     205  ///therefore we have to store it.
     206  sigc::connection mapst2mapwin;
    193207};
    194208
Note: See TracChangeset for help on using the changeset viewer.