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