gui/map_win.cc
author alpar
Thu, 18 Aug 2005 12:22:44 +0000
changeset 1642 a2dda876316f
parent 1599 c2f95eac652b
child 1643 9285f3777553
permissions -rw-r--r--
icc need this...
... and she's right.
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
    {
hegyi@1525
    84
      listStrings.push_back(emsi->first);
hegyi@1512
    85
    }
hegyi@1512
    86
hegyi@1512
    87
    n_combo_array[i].set_popdown_strings(listStrings);
hegyi@1512
    88
hegyi@1512
    89
    //Restrict it to these choices only:
hegyi@1512
    90
    n_combo_array[i].set_value_in_list();
hegyi@1512
    91
hegyi@1512
    92
    //binding signal to thew actual entry
hegyi@1512
    93
    n_combo_array[i].get_entry()->signal_changed().connect
hegyi@1512
    94
    (
hegyi@1512
    95
     sigc::bind
hegyi@1512
    96
     (
hegyi@1524
    97
      sigc::mem_fun(*this, &MapWin::nComboChanged),
hegyi@1512
    98
      i
hegyi@1512
    99
     )
hegyi@1512
   100
    );
hegyi@1512
   101
hegyi@1512
   102
    //placing actual entry in the right place
hegyi@1512
   103
hegyi@1512
   104
    label=new Gtk::Label;
hegyi@1512
   105
    label->set_text(node_property_strings[i]);
hegyi@1512
   106
        
hegyi@1512
   107
    (*table).attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@1512
   108
    (*table).attach(n_combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@1512
   109
hegyi@1512
   110
hegyi@1512
   111
  }
hegyi@1512
   112
hegyi@1512
   113
  add(vbox);
hegyi@1512
   114
hegyi@1512
   115
  vbox.pack_start(*(new Gtk::Label("Node properties")));
hegyi@1512
   116
hegyi@1512
   117
  vbox.pack_start(*table);
ladanyi@1442
   118
ladanyi@1442
   119
  show_all_children();
ladanyi@1442
   120
ladanyi@1442
   121
}
ladanyi@1442
   122
ladanyi@1606
   123
void MapWin::update()
ladanyi@1606
   124
{
ladanyi@1606
   125
  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
ladanyi@1606
   126
  {
ladanyi@1606
   127
    //filling in combo box with choices
ladanyi@1606
   128
    std::list<Glib::ustring> listStrings;
ladanyi@1606
   129
ladanyi@1606
   130
    listStrings.push_back("Default");
ladanyi@1606
   131
ladanyi@1606
   132
    std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
ladanyi@1606
   133
    for(;emsi!=ms.endOfEdgeMaps();emsi++)
ladanyi@1606
   134
    {
ladanyi@1606
   135
      listStrings.push_back(emsi->first);
ladanyi@1606
   136
    }
ladanyi@1606
   137
ladanyi@1606
   138
    e_combo_array[i].set_popdown_strings(listStrings);
ladanyi@1606
   139
  }
ladanyi@1606
   140
  for(int i=0;i<NODE_PROPERTY_NUM;i++)
ladanyi@1606
   141
  {
ladanyi@1606
   142
    //filling in combo box with choices
ladanyi@1606
   143
    std::list<Glib::ustring> listStrings;
ladanyi@1606
   144
ladanyi@1606
   145
    listStrings.push_back("Default");
ladanyi@1606
   146
ladanyi@1606
   147
    std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps();
ladanyi@1606
   148
ladanyi@1606
   149
    for(;emsi!=ms.endOfNodeMaps();emsi++)
ladanyi@1606
   150
    {
ladanyi@1606
   151
      listStrings.push_back(emsi->first);
ladanyi@1606
   152
    }
ladanyi@1606
   153
ladanyi@1606
   154
    n_combo_array[i].set_popdown_strings(listStrings);
ladanyi@1606
   155
  }
ladanyi@1606
   156
}
ladanyi@1606
   157
hegyi@1524
   158
void MapWin::eComboChanged(int prop)
ladanyi@1442
   159
{
hegyi@1589
   160
hegyi@1512
   161
  Gtk::Entry* entry = e_combo_array[prop].get_entry();
ladanyi@1442
   162
hegyi@1446
   163
  if(entry)
ladanyi@1442
   164
  {
hegyi@1446
   165
    Glib::ustring mapname = entry->get_text();
hegyi@1446
   166
    if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@1446
   167
    {
hegyi@1525
   168
      if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) || (mapname=="Default") )
hegyi@1446
   169
      {
hegyi@1446
   170
	switch(prop)
hegyi@1446
   171
	{
hegyi@1512
   172
          case E_WIDTH:
hegyi@1512
   173
	    gdc.changeEdgeWidth(mapname);
hegyi@1446
   174
	    break;
hegyi@1512
   175
          case E_COLOR:
hegyi@1512
   176
	    gdc.changeEdgeColor(mapname);
hegyi@1446
   177
	    break;
hegyi@1512
   178
          case E_TEXT:
hegyi@1512
   179
	    gdc.changeEdgeText(mapname);
hegyi@1446
   180
	    break;
hegyi@1446
   181
          default:
hegyi@1599
   182
	    std::cerr<<"Error\n";
hegyi@1446
   183
	}
hegyi@1446
   184
      }
ladanyi@1442
   185
    }
ladanyi@1442
   186
  }
ladanyi@1442
   187
};
hegyi@1512
   188
hegyi@1524
   189
void MapWin::nComboChanged(int prop)
hegyi@1512
   190
{
hegyi@1512
   191
hegyi@1512
   192
  Gtk::Entry* entry = n_combo_array[prop].get_entry();
hegyi@1512
   193
hegyi@1512
   194
  if(entry)
hegyi@1512
   195
  {
hegyi@1512
   196
    Glib::ustring mapname = entry->get_text();
hegyi@1512
   197
    if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@1512
   198
    {
hegyi@1525
   199
      if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) || (mapname=="Default") )
hegyi@1512
   200
      {
hegyi@1512
   201
	switch(prop)
hegyi@1512
   202
	{
hegyi@1512
   203
          case N_RADIUS:
hegyi@1512
   204
	    gdc.changeNodeRadius(mapname);
hegyi@1512
   205
	    break;
hegyi@1512
   206
          case N_COLOR:
hegyi@1512
   207
	    gdc.changeNodeColor(mapname);
hegyi@1512
   208
	    break;
hegyi@1512
   209
          case N_TEXT:
hegyi@1512
   210
	    gdc.changeNodeText(mapname);
hegyi@1512
   211
	    break;
hegyi@1512
   212
          default:
hegyi@1599
   213
	    std::cerr<<"Error\n";
hegyi@1512
   214
	}
hegyi@1512
   215
      }
hegyi@1512
   216
    }
hegyi@1512
   217
  }
hegyi@1512
   218
};
hegyi@1512
   219
hegyi@1524
   220
void MapWin::updateNode(Graph::Node node)
hegyi@1512
   221
{
hegyi@1512
   222
  for(int i=0;i<NODE_PROPERTY_NUM;i++)
hegyi@1512
   223
    {
hegyi@1512
   224
      Gtk::Entry* entry = n_combo_array[i].get_entry();
hegyi@1512
   225
hegyi@1512
   226
      if(entry)
hegyi@1512
   227
	{
hegyi@1512
   228
	  Glib::ustring mapname = entry->get_text();
hegyi@1512
   229
	  if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@1512
   230
	    {
hegyi@1525
   231
	      if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) || (mapname=="Default") )
hegyi@1512
   232
		{
hegyi@1512
   233
		  switch(i)
hegyi@1512
   234
		    {
hegyi@1512
   235
		    case N_RADIUS:
hegyi@1525
   236
		      gdc.changeNodeRadius(mapname, node);
hegyi@1512
   237
		      break;
hegyi@1512
   238
		    case N_COLOR:
hegyi@1512
   239
		      gdc.changeNodeColor(mapname, node);
hegyi@1512
   240
		      break;
hegyi@1512
   241
		    case N_TEXT:
hegyi@1512
   242
		      gdc.changeNodeText(mapname, node);
hegyi@1512
   243
		      break;
hegyi@1512
   244
		    default:
hegyi@1599
   245
		      std::cerr<<"Error\n";
hegyi@1512
   246
		    }
hegyi@1512
   247
		}
hegyi@1512
   248
	    }
hegyi@1512
   249
	}
hegyi@1512
   250
    }
hegyi@1512
   251
}
hegyi@1512
   252
hegyi@1524
   253
void MapWin::updateEdge(Graph::Edge edge)
hegyi@1512
   254
{
hegyi@1512
   255
  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
hegyi@1512
   256
    {
hegyi@1512
   257
hegyi@1512
   258
      Gtk::Entry* entry = e_combo_array[i].get_entry();
hegyi@1512
   259
hegyi@1512
   260
      if(entry)
hegyi@1512
   261
	{
hegyi@1512
   262
	  Glib::ustring mapname = entry->get_text();
hegyi@1512
   263
	  if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@1512
   264
	    {
hegyi@1512
   265
hegyi@1525
   266
	      if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) || (mapname=="Default") )
hegyi@1512
   267
		{
hegyi@1512
   268
		  switch(i)
hegyi@1512
   269
		    {
hegyi@1512
   270
		    case E_WIDTH:
hegyi@1525
   271
		      gdc.changeEdgeWidth(mapname, edge);
hegyi@1512
   272
		      break;
hegyi@1512
   273
		    case E_COLOR:
hegyi@1512
   274
		      gdc.changeEdgeColor(mapname, edge);
hegyi@1512
   275
		      break;
hegyi@1512
   276
		    case E_TEXT:
hegyi@1512
   277
		      gdc.changeEdgeText(mapname, edge);
hegyi@1512
   278
		      break;
hegyi@1512
   279
		    default:
hegyi@1599
   280
		      std::cerr<<"Error\n";
hegyi@1512
   281
		    }
hegyi@1512
   282
		}
hegyi@1512
   283
	    }
hegyi@1512
   284
	}
hegyi@1512
   285
    }
hegyi@1512
   286
}
hegyi@1586
   287
hegyi@1589
   288
void MapWin::registerNewEdgeMap(std::string newmapname)
hegyi@1586
   289
{
hegyi@1589
   290
  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
hegyi@1589
   291
  {
hegyi@1589
   292
    //filling in combo box with choices
hegyi@1589
   293
    std::list<Glib::ustring> listStrings=e_combo_array[i].get_popdown_strings();
hegyi@1589
   294
    listStrings.push_back(newmapname);
hegyi@1589
   295
    e_combo_array[i].set_popdown_strings(listStrings);
hegyi@1589
   296
  }
hegyi@1594
   297
  //setting text property for the new map
hegyi@1589
   298
  Gtk::Entry* entry = e_combo_array[E_TEXT].get_entry();
hegyi@1589
   299
  entry->set_text((Glib::ustring)newmapname);
hegyi@1586
   300
}
hegyi@1586
   301
hegyi@1589
   302
void MapWin::registerNewNodeMap(std::string newmapname)
hegyi@1586
   303
{
hegyi@1592
   304
  for(int i=0;i<NODE_PROPERTY_NUM;i++)
hegyi@1589
   305
  {
hegyi@1589
   306
    //filling in combo box with choices
hegyi@1589
   307
    std::list<Glib::ustring> listStrings=n_combo_array[i].get_popdown_strings();
hegyi@1589
   308
    listStrings.push_back(newmapname);
hegyi@1589
   309
    n_combo_array[i].set_popdown_strings(listStrings);
hegyi@1589
   310
  }
hegyi@1594
   311
  //setting text property for the new map
hegyi@1592
   312
  Gtk::Entry* entry = n_combo_array[N_TEXT].get_entry();
hegyi@1592
   313
  entry->set_text((Glib::ustring)newmapname);
hegyi@1586
   314
}