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