COIN-OR::LEMON - Graph Library

source: lemon-0.x/gui/map_win.cc @ 1587:8f1c317ebeb4

Last change on this file since 1587:8f1c317ebeb4 was 1586:1a8630f2e944, checked in by Hegyi Péter, 19 years ago

Continuing adding new maps.

File size: 5.8 KB
RevLine 
[1442]1#include <map_win.h>
2#include <set>
3
[1524]4bool MapWin::closeIfEscapeIsPressed(GdkEventKey* e)
[1442]5{
[1446]6  if(e->keyval==GDK_Escape)
7  {
8    hide();
9  }
10  return true;
11}
[1442]12
[1512]13MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst)
[1446]14{
15  set_title(title);
16  set_default_size(200, 50);
[1442]17
[1524]18  signal_key_press_event().connect(sigc::mem_fun(*this, &MapWin::closeIfEscapeIsPressed));
[1442]19
[1512]20  e_combo_array=new Gtk::Combo [EDGE_PROPERTY_NUM];
[1446]21
[1512]22  table=new Gtk::Table(EDGE_PROPERTY_NUM, 2, false);
23
24  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
[1442]25  {
[1446]26    //filling in combo box with choices
27    std::list<Glib::ustring> listStrings;
28
29    listStrings.push_back("Default");
[1442]30
[1525]31    std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
32    for(;emsi!=ms.endOfEdgeMaps();emsi++)
[1442]33    {
[1446]34        listStrings.push_back(emsi->first);
[1442]35    }
[1446]36
[1512]37    e_combo_array[i].set_popdown_strings(listStrings);
[1446]38
39    //Restrict it to these choices only:
[1512]40    e_combo_array[i].set_value_in_list();
[1446]41
[1512]42    //binding signal to the actual entry
43    e_combo_array[i].get_entry()->signal_changed().connect
[1446]44    (
45     sigc::bind
46     (
[1524]47      sigc::mem_fun(*this, &MapWin::eComboChanged),
[1446]48      i
49     )
50    );
51
52    //placing actual entry in the right place
53
54    label=new Gtk::Label;
[1512]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);
[1446]59
60
[1442]61  }
62
[1512]63  vbox.pack_start(*(new Gtk::Label("Edge properties")));
[1446]64
[1512]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
[1525]80    std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps();
[1512]81
[1525]82    for(;emsi!=ms.endOfNodeMaps();emsi++)
[1512]83    {
[1525]84      listStrings.push_back(emsi->first);
[1512]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     (
[1524]97      sigc::mem_fun(*this, &MapWin::nComboChanged),
[1512]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);
[1442]118
119  show_all_children();
120
121}
122
[1524]123void MapWin::eComboChanged(int prop)
[1442]124{
[1512]125  Gtk::Entry* entry = e_combo_array[prop].get_entry();
[1442]126
[1446]127  if(entry)
[1442]128  {
[1446]129    Glib::ustring mapname = entry->get_text();
130    if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
131    {
[1525]132      if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) || (mapname=="Default") )
[1446]133      {
134        switch(prop)
135        {
[1512]136          case E_WIDTH:
137            gdc.changeEdgeWidth(mapname);
[1446]138            break;
[1512]139          case E_COLOR:
140            gdc.changeEdgeColor(mapname);
[1446]141            break;
[1512]142          case E_TEXT:
143            gdc.changeEdgeText(mapname);
[1446]144            break;
145          default:
146            std::cout<<"Error\n";
147        }
148      }
[1442]149    }
150  }
151};
[1512]152
[1524]153void MapWin::nComboChanged(int prop)
[1512]154{
155
156  Gtk::Entry* entry = n_combo_array[prop].get_entry();
157
158  if(entry)
159  {
160    Glib::ustring mapname = entry->get_text();
161    if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
162    {
[1525]163      if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) || (mapname=="Default") )
[1512]164      {
165        switch(prop)
166        {
167          case N_RADIUS:
168            gdc.changeNodeRadius(mapname);
169            break;
170          case N_COLOR:
171            gdc.changeNodeColor(mapname);
172            break;
173          case N_TEXT:
174            gdc.changeNodeText(mapname);
175            break;
176          default:
177            std::cout<<"Error\n";
178        }
179      }
180    }
181  }
182};
183
[1524]184void MapWin::updateNode(Graph::Node node)
[1512]185{
186  for(int i=0;i<NODE_PROPERTY_NUM;i++)
187    {
188      Gtk::Entry* entry = n_combo_array[i].get_entry();
189
190      if(entry)
191        {
192          Glib::ustring mapname = entry->get_text();
193          if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
194            {
[1525]195              if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) || (mapname=="Default") )
[1512]196                {
197                  switch(i)
198                    {
199                    case N_RADIUS:
[1525]200                      gdc.changeNodeRadius(mapname, node);
[1512]201                      break;
202                    case N_COLOR:
203                      gdc.changeNodeColor(mapname, node);
204                      break;
205                    case N_TEXT:
206                      gdc.changeNodeText(mapname, node);
207                      break;
208                    default:
209                      std::cout<<"Error\n";
210                    }
211                }
212            }
213        }
214    }
215}
216
[1524]217void MapWin::updateEdge(Graph::Edge edge)
[1512]218{
219  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
220    {
221
222      Gtk::Entry* entry = e_combo_array[i].get_entry();
223
224      if(entry)
225        {
226          Glib::ustring mapname = entry->get_text();
227          if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
228            {
229
[1525]230              if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) || (mapname=="Default") )
[1512]231                {
232                  switch(i)
233                    {
234                    case E_WIDTH:
[1525]235                      gdc.changeEdgeWidth(mapname, edge);
[1512]236                      break;
237                    case E_COLOR:
238                      gdc.changeEdgeColor(mapname, edge);
239                      break;
240                    case E_TEXT:
241                      gdc.changeEdgeText(mapname, edge);
242                      break;
243                    default:
244                      std::cout<<"Error\n";
245                    }
246                }
247            }
248        }
249    }
250}
[1586]251
252void MapWin::registerNewEdgeMap(std::string)
253{
254  std::cout << "void MapWin::registerNewEdgeMap(std::string) is not yet implemented" << std::endl;
255}
256
257void MapWin::registerNewNodeMap(std::string)
258{
259  std::cout << "void MapWin::registerNewNodeMap(std::string) is not yet implemented" << std::endl;
260}
Note: See TracBrowser for help on using the repository browser.