COIN-OR::LEMON - Graph Library

source: glemon-0.x/map_win.cc @ 48:b8ec84524fa2

gui
Last change on this file since 48:b8ec84524fa2 was 48:b8ec84524fa2, checked in by Hegyi Péter, 19 years ago

cout->cerr, node radius and edge width is now scaled, maps are editable by clicking on texts.

File size: 6.4 KB
RevLine 
[6]1#include <map_win.h>
2#include <set>
3
[30]4bool MapWin::closeIfEscapeIsPressed(GdkEventKey* e)
[6]5{
[8]6  if(e->keyval==GDK_Escape)
7  {
8    hide();
9  }
10  return true;
11}
[6]12
[28]13MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst)
[8]14{
15  set_title(title);
16  set_default_size(200, 50);
[6]17
[30]18  signal_key_press_event().connect(sigc::mem_fun(*this, &MapWin::closeIfEscapeIsPressed));
[6]19
[28]20  e_combo_array=new Gtk::Combo [EDGE_PROPERTY_NUM];
[8]21
[28]22  table=new Gtk::Table(EDGE_PROPERTY_NUM, 2, false);
23
24  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
[6]25  {
[8]26    //filling in combo box with choices
27    std::list<Glib::ustring> listStrings;
28
29    listStrings.push_back("Default");
[6]30
[31]31    std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
32    for(;emsi!=ms.endOfEdgeMaps();emsi++)
[6]33    {
[8]34        listStrings.push_back(emsi->first);
[6]35    }
[8]36
[28]37    e_combo_array[i].set_popdown_strings(listStrings);
[8]38
39    //Restrict it to these choices only:
[28]40    e_combo_array[i].set_value_in_list();
[8]41
[28]42    //binding signal to the actual entry
43    e_combo_array[i].get_entry()->signal_changed().connect
[8]44    (
45     sigc::bind
46     (
[30]47      sigc::mem_fun(*this, &MapWin::eComboChanged),
[8]48      i
49     )
50    );
51
52    //placing actual entry in the right place
53
54    label=new Gtk::Label;
[28]55    label->set_text(edge_property_strings[i]);
56       
57    (*table).attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
58    (*table).attach(e_combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
[8]59
60
[6]61  }
62
[28]63  vbox.pack_start(*(new Gtk::Label("Edge properties")));
[8]64
[28]65  vbox.pack_start(*table);
66
67  vbox.pack_start(*(new Gtk::HSeparator));
68
69  n_combo_array=new Gtk::Combo [NODE_PROPERTY_NUM];
70
71  table=new Gtk::Table(NODE_PROPERTY_NUM, 2, false);
72
73  for(int i=0;i<NODE_PROPERTY_NUM;i++)
74  {
75    //filling in combo box with choices
76    std::list<Glib::ustring> listStrings;
77
78    listStrings.push_back("Default");
79
[31]80    std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps();
[28]81
[31]82    for(;emsi!=ms.endOfNodeMaps();emsi++)
[28]83    {
[31]84      listStrings.push_back(emsi->first);
[28]85    }
86
87    n_combo_array[i].set_popdown_strings(listStrings);
88
89    //Restrict it to these choices only:
90    n_combo_array[i].set_value_in_list();
91
92    //binding signal to thew actual entry
93    n_combo_array[i].get_entry()->signal_changed().connect
94    (
95     sigc::bind
96     (
[30]97      sigc::mem_fun(*this, &MapWin::nComboChanged),
[28]98      i
99     )
100    );
101
102    //placing actual entry in the right place
103
104    label=new Gtk::Label;
105    label->set_text(node_property_strings[i]);
106       
107    (*table).attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
108    (*table).attach(n_combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
109
110
111  }
112
113  add(vbox);
114
115  vbox.pack_start(*(new Gtk::Label("Node properties")));
116
117  vbox.pack_start(*table);
[6]118
119  show_all_children();
120
121}
122
[30]123void MapWin::eComboChanged(int prop)
[6]124{
[40]125
[28]126  Gtk::Entry* entry = e_combo_array[prop].get_entry();
[6]127
[8]128  if(entry)
[6]129  {
[8]130    Glib::ustring mapname = entry->get_text();
131    if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
132    {
[31]133      if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) || (mapname=="Default") )
[8]134      {
135        switch(prop)
136        {
[28]137          case E_WIDTH:
138            gdc.changeEdgeWidth(mapname);
[8]139            break;
[28]140          case E_COLOR:
141            gdc.changeEdgeColor(mapname);
[8]142            break;
[28]143          case E_TEXT:
144            gdc.changeEdgeText(mapname);
[8]145            break;
146          default:
[48]147            std::cerr<<"Error\n";
[8]148        }
149      }
[6]150    }
151  }
152};
[28]153
[30]154void MapWin::nComboChanged(int prop)
[28]155{
156
157  Gtk::Entry* entry = n_combo_array[prop].get_entry();
158
159  if(entry)
160  {
161    Glib::ustring mapname = entry->get_text();
162    if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
163    {
[31]164      if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) || (mapname=="Default") )
[28]165      {
166        switch(prop)
167        {
168          case N_RADIUS:
169            gdc.changeNodeRadius(mapname);
170            break;
171          case N_COLOR:
172            gdc.changeNodeColor(mapname);
173            break;
174          case N_TEXT:
175            gdc.changeNodeText(mapname);
176            break;
177          default:
[48]178            std::cerr<<"Error\n";
[28]179        }
180      }
181    }
182  }
183};
184
[30]185void MapWin::updateNode(Graph::Node node)
[28]186{
187  for(int i=0;i<NODE_PROPERTY_NUM;i++)
188    {
189      Gtk::Entry* entry = n_combo_array[i].get_entry();
190
191      if(entry)
192        {
193          Glib::ustring mapname = entry->get_text();
194          if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
195            {
[31]196              if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) || (mapname=="Default") )
[28]197                {
198                  switch(i)
199                    {
200                    case N_RADIUS:
[31]201                      gdc.changeNodeRadius(mapname, node);
[28]202                      break;
203                    case N_COLOR:
204                      gdc.changeNodeColor(mapname, node);
205                      break;
206                    case N_TEXT:
207                      gdc.changeNodeText(mapname, node);
208                      break;
209                    default:
[48]210                      std::cerr<<"Error\n";
[28]211                    }
212                }
213            }
214        }
215    }
216}
217
[30]218void MapWin::updateEdge(Graph::Edge edge)
[28]219{
220  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
221    {
222
223      Gtk::Entry* entry = e_combo_array[i].get_entry();
224
225      if(entry)
226        {
227          Glib::ustring mapname = entry->get_text();
228          if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
229            {
230
[31]231              if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) || (mapname=="Default") )
[28]232                {
233                  switch(i)
234                    {
235                    case E_WIDTH:
[31]236                      gdc.changeEdgeWidth(mapname, edge);
[28]237                      break;
238                    case E_COLOR:
239                      gdc.changeEdgeColor(mapname, edge);
240                      break;
241                    case E_TEXT:
242                      gdc.changeEdgeText(mapname, edge);
243                      break;
244                    default:
[48]245                      std::cerr<<"Error\n";
[28]246                    }
247                }
248            }
249        }
250    }
251}
[38]252
[40]253void MapWin::registerNewEdgeMap(std::string newmapname)
[38]254{
[40]255  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
256  {
257    //filling in combo box with choices
258    std::list<Glib::ustring> listStrings=e_combo_array[i].get_popdown_strings();
259    listStrings.push_back(newmapname);
260    e_combo_array[i].set_popdown_strings(listStrings);
261  }
[43]262  //setting text property for the new map
[40]263  Gtk::Entry* entry = e_combo_array[E_TEXT].get_entry();
264  entry->set_text((Glib::ustring)newmapname);
[38]265}
266
[40]267void MapWin::registerNewNodeMap(std::string newmapname)
[38]268{
[41]269  for(int i=0;i<NODE_PROPERTY_NUM;i++)
[40]270  {
271    //filling in combo box with choices
272    std::list<Glib::ustring> listStrings=n_combo_array[i].get_popdown_strings();
273    listStrings.push_back(newmapname);
274    n_combo_array[i].set_popdown_strings(listStrings);
275  }
[43]276  //setting text property for the new map
[41]277  Gtk::Entry* entry = n_combo_array[N_TEXT].get_entry();
278  entry->set_text((Glib::ustring)newmapname);
[38]279}
Note: See TracBrowser for help on using the repository browser.