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