gui/map_win.cc
author klao
Mon, 27 Jun 2005 19:47:09 +0000
changeset 1519 17e367a93cbb
parent 1446 320f73c5cfc1
child 1524 587a823bcdd0
permissions -rw-r--r--
getstart improvements
ladanyi@1442
     1
#include <map_win.h>
ladanyi@1442
     2
#include <set>
ladanyi@1442
     3
hegyi@1446
     4
bool MapWin::close_if_escape_is_pressed(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@1446
    18
  signal_key_press_event().connect(sigc::mem_fun(*this, &MapWin::close_if_escape_is_pressed));
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
  {
ladanyi@1442
    26
ladanyi@1442
    27
    std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
ladanyi@1442
    28
    std::set<int> props;
ladanyi@1442
    29
ladanyi@1442
    30
    int actprop;
hegyi@1446
    31
hegyi@1446
    32
    //here we find out, which map is the default in MapStorage for this property, which are not
ladanyi@1442
    33
    for(int j=0;j<ms.numOfEdgeMaps();j++)
ladanyi@1442
    34
    {
hegyi@1446
    35
      //this is the default value for this property
ladanyi@1442
    36
      if(emsi->second==&(ms.default_edgemaps[i]))
ladanyi@1442
    37
      {
ladanyi@1442
    38
	actprop=j;
ladanyi@1442
    39
      }
hegyi@1512
    40
      //these are the maps NOT to show for this property
hegyi@1512
    41
      for(int k=0;k<EDGE_PROPERTY_NUM;k++)
ladanyi@1442
    42
      {
ladanyi@1442
    43
	if(emsi->second==&(ms.default_edgemaps[k]))
ladanyi@1442
    44
	{
ladanyi@1442
    45
	  props.insert(j);
ladanyi@1442
    46
	}
ladanyi@1442
    47
      }
ladanyi@1442
    48
      emsi++;
ladanyi@1442
    49
    }
ladanyi@1442
    50
hegyi@1446
    51
    //filling in combo box with choices
hegyi@1446
    52
    std::list<Glib::ustring> listStrings;
hegyi@1446
    53
hegyi@1446
    54
    listStrings.push_back("Default");
ladanyi@1442
    55
ladanyi@1442
    56
    emsi=ms.beginOfEdgeMaps();
hegyi@1446
    57
ladanyi@1442
    58
    for(int j=0;j<ms.numOfEdgeMaps();j++)
ladanyi@1442
    59
    {
ladanyi@1442
    60
      if( ( props.find(j) )==( props.end() ) )
ladanyi@1442
    61
      {
hegyi@1446
    62
	listStrings.push_back(emsi->first);
ladanyi@1442
    63
      }
ladanyi@1442
    64
      emsi++;
ladanyi@1442
    65
    }
hegyi@1446
    66
hegyi@1512
    67
    e_combo_array[i].set_popdown_strings(listStrings);
hegyi@1446
    68
hegyi@1446
    69
    //Restrict it to these choices only:
hegyi@1512
    70
    e_combo_array[i].set_value_in_list();
hegyi@1446
    71
hegyi@1512
    72
    //binding signal to the actual entry
hegyi@1512
    73
    e_combo_array[i].get_entry()->signal_changed().connect
hegyi@1446
    74
    (
hegyi@1446
    75
     sigc::bind
hegyi@1446
    76
     (
hegyi@1512
    77
      sigc::mem_fun(*this, &MapWin::e_combo_changed),
hegyi@1446
    78
      i
hegyi@1446
    79
     )
hegyi@1446
    80
    );
hegyi@1446
    81
hegyi@1446
    82
    //placing actual entry in the right place
hegyi@1446
    83
hegyi@1446
    84
    label=new Gtk::Label;
hegyi@1512
    85
    label->set_text(edge_property_strings[i]);
hegyi@1512
    86
        
hegyi@1512
    87
    (*table).attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@1512
    88
    (*table).attach(e_combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@1446
    89
hegyi@1446
    90
ladanyi@1442
    91
  }
ladanyi@1442
    92
hegyi@1512
    93
  vbox.pack_start(*(new Gtk::Label("Edge properties")));
hegyi@1446
    94
hegyi@1512
    95
  vbox.pack_start(*table);
hegyi@1512
    96
hegyi@1512
    97
  vbox.pack_start(*(new Gtk::HSeparator));
hegyi@1512
    98
hegyi@1512
    99
  n_combo_array=new Gtk::Combo [NODE_PROPERTY_NUM];
hegyi@1512
   100
hegyi@1512
   101
  table=new Gtk::Table(NODE_PROPERTY_NUM, 2, false);
hegyi@1512
   102
hegyi@1512
   103
  for(int i=0;i<NODE_PROPERTY_NUM;i++)
hegyi@1512
   104
  {
hegyi@1512
   105
hegyi@1512
   106
    std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps();
hegyi@1512
   107
    std::set<int> props;
hegyi@1512
   108
hegyi@1512
   109
    int actprop;
hegyi@1512
   110
hegyi@1512
   111
    //here we find out, which map is the default in MapStorage for this property, which are not
hegyi@1512
   112
    for(int j=0;j<ms.numOfNodeMaps();j++)
hegyi@1512
   113
    {
hegyi@1512
   114
      //these are the maps NOT to show for this property
hegyi@1512
   115
      if(emsi->second==&(ms.default_nodemaps[i]))
hegyi@1512
   116
      {
hegyi@1512
   117
	actprop=j;
hegyi@1512
   118
      }
hegyi@1512
   119
      //this is the other maps to show for this property
hegyi@1512
   120
      for(int k=0;k<NODE_PROPERTY_NUM;k++)
hegyi@1512
   121
      {
hegyi@1512
   122
	if(emsi->second==&(ms.default_nodemaps[k]))
hegyi@1512
   123
	{
hegyi@1512
   124
	  props.insert(j);
hegyi@1512
   125
	}
hegyi@1512
   126
      }
hegyi@1512
   127
      emsi++;
hegyi@1512
   128
    }
hegyi@1512
   129
hegyi@1512
   130
    //filling in combo box with choices
hegyi@1512
   131
    std::list<Glib::ustring> listStrings;
hegyi@1512
   132
hegyi@1512
   133
    listStrings.push_back("Default");
hegyi@1512
   134
hegyi@1512
   135
    emsi=ms.beginOfNodeMaps();
hegyi@1512
   136
hegyi@1512
   137
    for(int j=0;j<ms.numOfNodeMaps();j++)
hegyi@1512
   138
    {
hegyi@1512
   139
      if( ( props.find(j) )==( props.end() ) )
hegyi@1512
   140
      {
hegyi@1512
   141
	listStrings.push_back(emsi->first);
hegyi@1512
   142
      }
hegyi@1512
   143
      emsi++;
hegyi@1512
   144
    }
hegyi@1512
   145
hegyi@1512
   146
    n_combo_array[i].set_popdown_strings(listStrings);
hegyi@1512
   147
hegyi@1512
   148
    //Restrict it to these choices only:
hegyi@1512
   149
    n_combo_array[i].set_value_in_list();
hegyi@1512
   150
hegyi@1512
   151
    //binding signal to thew actual entry
hegyi@1512
   152
    n_combo_array[i].get_entry()->signal_changed().connect
hegyi@1512
   153
    (
hegyi@1512
   154
     sigc::bind
hegyi@1512
   155
     (
hegyi@1512
   156
      sigc::mem_fun(*this, &MapWin::n_combo_changed),
hegyi@1512
   157
      i
hegyi@1512
   158
     )
hegyi@1512
   159
    );
hegyi@1512
   160
hegyi@1512
   161
    //placing actual entry in the right place
hegyi@1512
   162
hegyi@1512
   163
    label=new Gtk::Label;
hegyi@1512
   164
    label->set_text(node_property_strings[i]);
hegyi@1512
   165
        
hegyi@1512
   166
    (*table).attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@1512
   167
    (*table).attach(n_combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@1512
   168
hegyi@1512
   169
hegyi@1512
   170
  }
hegyi@1512
   171
hegyi@1512
   172
  add(vbox);
hegyi@1512
   173
hegyi@1512
   174
  vbox.pack_start(*(new Gtk::Label("Node properties")));
hegyi@1512
   175
hegyi@1512
   176
  vbox.pack_start(*table);
ladanyi@1442
   177
ladanyi@1442
   178
  show_all_children();
ladanyi@1442
   179
ladanyi@1442
   180
}
ladanyi@1442
   181
hegyi@1512
   182
void MapWin::e_combo_changed(int prop)
ladanyi@1442
   183
{
hegyi@1512
   184
  Gtk::Entry* entry = e_combo_array[prop].get_entry();
ladanyi@1442
   185
hegyi@1446
   186
  if(entry)
ladanyi@1442
   187
  {
hegyi@1446
   188
    Glib::ustring mapname = entry->get_text();
hegyi@1446
   189
    if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@1446
   190
    {
hegyi@1446
   191
      if(mapname=="Default")
hegyi@1446
   192
      {
hegyi@1512
   193
	mapname=edge_property_strings[prop];
hegyi@1446
   194
      }
ladanyi@1442
   195
hegyi@1446
   196
      if( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() )
hegyi@1446
   197
      {
hegyi@1446
   198
	switch(prop)
hegyi@1446
   199
	{
hegyi@1512
   200
          case E_WIDTH:
hegyi@1512
   201
	    gdc.changeEdgeWidth(mapname);
hegyi@1446
   202
	    break;
hegyi@1512
   203
          case E_COLOR:
hegyi@1512
   204
	    gdc.changeEdgeColor(mapname);
hegyi@1446
   205
	    break;
hegyi@1512
   206
          case E_TEXT:
hegyi@1512
   207
	    gdc.changeEdgeText(mapname);
hegyi@1446
   208
	    break;
hegyi@1446
   209
          default:
hegyi@1446
   210
	    std::cout<<"Error\n";
hegyi@1446
   211
	}
hegyi@1446
   212
      }
ladanyi@1442
   213
    }
ladanyi@1442
   214
  }
ladanyi@1442
   215
};
hegyi@1512
   216
hegyi@1512
   217
void MapWin::n_combo_changed(int prop)
hegyi@1512
   218
{
hegyi@1512
   219
hegyi@1512
   220
  Gtk::Entry* entry = n_combo_array[prop].get_entry();
hegyi@1512
   221
hegyi@1512
   222
  if(entry)
hegyi@1512
   223
  {
hegyi@1512
   224
    Glib::ustring mapname = entry->get_text();
hegyi@1512
   225
    if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@1512
   226
    {
hegyi@1512
   227
      if(mapname=="Default")
hegyi@1512
   228
      {
hegyi@1512
   229
	mapname=node_property_strings[prop];
hegyi@1512
   230
      }
hegyi@1512
   231
hegyi@1512
   232
      if( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() )
hegyi@1512
   233
      {
hegyi@1512
   234
	switch(prop)
hegyi@1512
   235
	{
hegyi@1512
   236
          case N_RADIUS:
hegyi@1512
   237
	    gdc.changeNodeRadius(mapname);
hegyi@1512
   238
	    break;
hegyi@1512
   239
          case N_COLOR:
hegyi@1512
   240
	    gdc.changeNodeColor(mapname);
hegyi@1512
   241
	    break;
hegyi@1512
   242
          case N_TEXT:
hegyi@1512
   243
	    gdc.changeNodeText(mapname);
hegyi@1512
   244
	    break;
hegyi@1512
   245
          default:
hegyi@1512
   246
	    std::cout<<"Error\n";
hegyi@1512
   247
	}
hegyi@1512
   248
      }
hegyi@1512
   249
    }
hegyi@1512
   250
  }
hegyi@1512
   251
};
hegyi@1512
   252
hegyi@1512
   253
void MapWin::update_node(Graph::Node node)
hegyi@1512
   254
{
hegyi@1512
   255
  for(int i=0;i<NODE_PROPERTY_NUM;i++)
hegyi@1512
   256
    {
hegyi@1512
   257
      Gtk::Entry* entry = n_combo_array[i].get_entry();
hegyi@1512
   258
hegyi@1512
   259
      if(entry)
hegyi@1512
   260
	{
hegyi@1512
   261
	  Glib::ustring mapname = entry->get_text();
hegyi@1512
   262
	  if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@1512
   263
	    {
hegyi@1512
   264
	      if(mapname=="Default")
hegyi@1512
   265
		{
hegyi@1512
   266
		  mapname=node_property_strings[i];
hegyi@1512
   267
		}
hegyi@1512
   268
hegyi@1512
   269
	      if( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() )
hegyi@1512
   270
		{
hegyi@1512
   271
		  switch(i)
hegyi@1512
   272
		    {
hegyi@1512
   273
		    case N_RADIUS:
hegyi@1512
   274
		      //gdc.changeNodeRadius(mapname, node);
hegyi@1512
   275
		      std::cout << "If default map-value problem is solved, uncomment line in MapWin::node_update!" << std::endl;
hegyi@1512
   276
		      break;
hegyi@1512
   277
		    case N_COLOR:
hegyi@1512
   278
		      gdc.changeNodeColor(mapname, node);
hegyi@1512
   279
		      break;
hegyi@1512
   280
		    case N_TEXT:
hegyi@1512
   281
		      gdc.changeNodeText(mapname, node);
hegyi@1512
   282
		      break;
hegyi@1512
   283
		    default:
hegyi@1512
   284
		      std::cout<<"Error\n";
hegyi@1512
   285
		    }
hegyi@1512
   286
		}
hegyi@1512
   287
	    }
hegyi@1512
   288
	}
hegyi@1512
   289
    }
hegyi@1512
   290
}
hegyi@1512
   291
hegyi@1512
   292
void MapWin::update_edge(Graph::Edge edge)
hegyi@1512
   293
{
hegyi@1512
   294
  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
hegyi@1512
   295
    {
hegyi@1512
   296
hegyi@1512
   297
      Gtk::Entry* entry = e_combo_array[i].get_entry();
hegyi@1512
   298
hegyi@1512
   299
      if(entry)
hegyi@1512
   300
	{
hegyi@1512
   301
	  Glib::ustring mapname = entry->get_text();
hegyi@1512
   302
	  if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@1512
   303
	    {
hegyi@1512
   304
	      if(mapname=="Default")
hegyi@1512
   305
		{
hegyi@1512
   306
		  mapname=edge_property_strings[i];
hegyi@1512
   307
		}
hegyi@1512
   308
hegyi@1512
   309
	      if( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() )
hegyi@1512
   310
		{
hegyi@1512
   311
		  switch(i)
hegyi@1512
   312
		    {
hegyi@1512
   313
		    case E_WIDTH:
hegyi@1512
   314
		      //gdc.changeEdgeWidth(mapname, edge);
hegyi@1512
   315
		      std::cout << "If default map-value problem is solved, uncomment line in MapWin::edge_update!" << std::endl;
hegyi@1512
   316
		      break;
hegyi@1512
   317
		    case E_COLOR:
hegyi@1512
   318
		      gdc.changeEdgeColor(mapname, edge);
hegyi@1512
   319
		      break;
hegyi@1512
   320
		    case E_TEXT:
hegyi@1512
   321
		      gdc.changeEdgeText(mapname, edge);
hegyi@1512
   322
		      break;
hegyi@1512
   323
		    default:
hegyi@1512
   324
		      std::cout<<"Error\n";
hegyi@1512
   325
		    }
hegyi@1512
   326
		}
hegyi@1512
   327
	    }
hegyi@1512
   328
	}
hegyi@1512
   329
    }
hegyi@1512
   330
}