map_win.cc
author hegyi
Tue, 26 Jul 2005 18:14:23 +0000
branchgui
changeset 40 cebacea4f965
parent 38 9cab23d9b124
child 41 06f1f9a8d51f
permissions -rw-r--r--
creates one new edgemap
ladanyi@6
     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
    {
hegyi@31
    84
      listStrings.push_back(emsi->first);
hegyi@28
    85
    }
hegyi@28
    86
hegyi@28
    87
    n_combo_array[i].set_popdown_strings(listStrings);
hegyi@28
    88
hegyi@28
    89
    //Restrict it to these choices only:
hegyi@28
    90
    n_combo_array[i].set_value_in_list();
hegyi@28
    91
hegyi@28
    92
    //binding signal to thew actual entry
hegyi@28
    93
    n_combo_array[i].get_entry()->signal_changed().connect
hegyi@28
    94
    (
hegyi@28
    95
     sigc::bind
hegyi@28
    96
     (
hegyi@30
    97
      sigc::mem_fun(*this, &MapWin::nComboChanged),
hegyi@28
    98
      i
hegyi@28
    99
     )
hegyi@28
   100
    );
hegyi@28
   101
hegyi@28
   102
    //placing actual entry in the right place
hegyi@28
   103
hegyi@28
   104
    label=new Gtk::Label;
hegyi@28
   105
    label->set_text(node_property_strings[i]);
hegyi@28
   106
        
hegyi@28
   107
    (*table).attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@28
   108
    (*table).attach(n_combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@28
   109
hegyi@28
   110
hegyi@28
   111
  }
hegyi@28
   112
hegyi@28
   113
  add(vbox);
hegyi@28
   114
hegyi@28
   115
  vbox.pack_start(*(new Gtk::Label("Node properties")));
hegyi@28
   116
hegyi@28
   117
  vbox.pack_start(*table);
ladanyi@6
   118
ladanyi@6
   119
  show_all_children();
ladanyi@6
   120
ladanyi@6
   121
}
ladanyi@6
   122
hegyi@30
   123
void MapWin::eComboChanged(int prop)
ladanyi@6
   124
{
hegyi@40
   125
hegyi@28
   126
  Gtk::Entry* entry = e_combo_array[prop].get_entry();
ladanyi@6
   127
hegyi@8
   128
  if(entry)
ladanyi@6
   129
  {
hegyi@8
   130
    Glib::ustring mapname = entry->get_text();
hegyi@8
   131
    if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@8
   132
    {
hegyi@31
   133
      if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) || (mapname=="Default") )
hegyi@8
   134
      {
hegyi@8
   135
	switch(prop)
hegyi@8
   136
	{
hegyi@28
   137
          case E_WIDTH:
hegyi@28
   138
	    gdc.changeEdgeWidth(mapname);
hegyi@8
   139
	    break;
hegyi@28
   140
          case E_COLOR:
hegyi@28
   141
	    gdc.changeEdgeColor(mapname);
hegyi@8
   142
	    break;
hegyi@28
   143
          case E_TEXT:
hegyi@28
   144
	    gdc.changeEdgeText(mapname);
hegyi@8
   145
	    break;
hegyi@8
   146
          default:
hegyi@8
   147
	    std::cout<<"Error\n";
hegyi@8
   148
	}
hegyi@8
   149
      }
ladanyi@6
   150
    }
ladanyi@6
   151
  }
ladanyi@6
   152
};
hegyi@28
   153
hegyi@30
   154
void MapWin::nComboChanged(int prop)
hegyi@28
   155
{
hegyi@28
   156
hegyi@28
   157
  Gtk::Entry* entry = n_combo_array[prop].get_entry();
hegyi@28
   158
hegyi@28
   159
  if(entry)
hegyi@28
   160
  {
hegyi@28
   161
    Glib::ustring mapname = entry->get_text();
hegyi@28
   162
    if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@28
   163
    {
hegyi@31
   164
      if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) || (mapname=="Default") )
hegyi@28
   165
      {
hegyi@28
   166
	switch(prop)
hegyi@28
   167
	{
hegyi@28
   168
          case N_RADIUS:
hegyi@28
   169
	    gdc.changeNodeRadius(mapname);
hegyi@28
   170
	    break;
hegyi@28
   171
          case N_COLOR:
hegyi@28
   172
	    gdc.changeNodeColor(mapname);
hegyi@28
   173
	    break;
hegyi@28
   174
          case N_TEXT:
hegyi@28
   175
	    gdc.changeNodeText(mapname);
hegyi@28
   176
	    break;
hegyi@28
   177
          default:
hegyi@28
   178
	    std::cout<<"Error\n";
hegyi@28
   179
	}
hegyi@28
   180
      }
hegyi@28
   181
    }
hegyi@28
   182
  }
hegyi@28
   183
};
hegyi@28
   184
hegyi@30
   185
void MapWin::updateNode(Graph::Node node)
hegyi@28
   186
{
hegyi@28
   187
  for(int i=0;i<NODE_PROPERTY_NUM;i++)
hegyi@28
   188
    {
hegyi@28
   189
      Gtk::Entry* entry = n_combo_array[i].get_entry();
hegyi@28
   190
hegyi@28
   191
      if(entry)
hegyi@28
   192
	{
hegyi@28
   193
	  Glib::ustring mapname = entry->get_text();
hegyi@28
   194
	  if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@28
   195
	    {
hegyi@31
   196
	      if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) || (mapname=="Default") )
hegyi@28
   197
		{
hegyi@28
   198
		  switch(i)
hegyi@28
   199
		    {
hegyi@28
   200
		    case N_RADIUS:
hegyi@31
   201
		      gdc.changeNodeRadius(mapname, node);
hegyi@28
   202
		      break;
hegyi@28
   203
		    case N_COLOR:
hegyi@28
   204
		      gdc.changeNodeColor(mapname, node);
hegyi@28
   205
		      break;
hegyi@28
   206
		    case N_TEXT:
hegyi@28
   207
		      gdc.changeNodeText(mapname, node);
hegyi@28
   208
		      break;
hegyi@28
   209
		    default:
hegyi@28
   210
		      std::cout<<"Error\n";
hegyi@28
   211
		    }
hegyi@28
   212
		}
hegyi@28
   213
	    }
hegyi@28
   214
	}
hegyi@28
   215
    }
hegyi@28
   216
}
hegyi@28
   217
hegyi@30
   218
void MapWin::updateEdge(Graph::Edge edge)
hegyi@28
   219
{
hegyi@28
   220
  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
hegyi@28
   221
    {
hegyi@28
   222
hegyi@28
   223
      Gtk::Entry* entry = e_combo_array[i].get_entry();
hegyi@28
   224
hegyi@28
   225
      if(entry)
hegyi@28
   226
	{
hegyi@28
   227
	  Glib::ustring mapname = entry->get_text();
hegyi@28
   228
	  if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@28
   229
	    {
hegyi@28
   230
hegyi@31
   231
	      if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) || (mapname=="Default") )
hegyi@28
   232
		{
hegyi@28
   233
		  switch(i)
hegyi@28
   234
		    {
hegyi@28
   235
		    case E_WIDTH:
hegyi@31
   236
		      gdc.changeEdgeWidth(mapname, edge);
hegyi@28
   237
		      break;
hegyi@28
   238
		    case E_COLOR:
hegyi@28
   239
		      gdc.changeEdgeColor(mapname, edge);
hegyi@28
   240
		      break;
hegyi@28
   241
		    case E_TEXT:
hegyi@28
   242
		      gdc.changeEdgeText(mapname, edge);
hegyi@28
   243
		      break;
hegyi@28
   244
		    default:
hegyi@28
   245
		      std::cout<<"Error\n";
hegyi@28
   246
		    }
hegyi@28
   247
		}
hegyi@28
   248
	    }
hegyi@28
   249
	}
hegyi@28
   250
    }
hegyi@28
   251
}
hegyi@38
   252
hegyi@40
   253
void MapWin::registerNewEdgeMap(std::string newmapname)
hegyi@38
   254
{
hegyi@40
   255
  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
hegyi@40
   256
  {
hegyi@40
   257
    //filling in combo box with choices
hegyi@40
   258
    std::list<Glib::ustring> listStrings=e_combo_array[i].get_popdown_strings();
hegyi@40
   259
    listStrings.push_back(newmapname);
hegyi@40
   260
    e_combo_array[i].set_popdown_strings(listStrings);
hegyi@40
   261
  }
hegyi@40
   262
  Gtk::Entry* entry = e_combo_array[E_TEXT].get_entry();
hegyi@40
   263
  entry->set_text((Glib::ustring)newmapname);
hegyi@38
   264
}
hegyi@38
   265
hegyi@40
   266
void MapWin::registerNewNodeMap(std::string newmapname)
hegyi@38
   267
{
hegyi@40
   268
  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
hegyi@40
   269
  {
hegyi@40
   270
    //filling in combo box with choices
hegyi@40
   271
    std::list<Glib::ustring> listStrings=n_combo_array[i].get_popdown_strings();
hegyi@40
   272
    listStrings.push_back(newmapname);
hegyi@40
   273
    n_combo_array[i].set_popdown_strings(listStrings);
hegyi@40
   274
  }
hegyi@38
   275
}