map_win.cc
author hegyi
Mon, 25 Jul 2005 11:17:23 +0000
branchgui
changeset 38 9cab23d9b124
parent 31 66e85f44a66f
child 40 cebacea4f965
permissions -rw-r--r--
Continuing adding new maps.
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@28
   125
  Gtk::Entry* entry = e_combo_array[prop].get_entry();
ladanyi@6
   126
hegyi@8
   127
  if(entry)
ladanyi@6
   128
  {
hegyi@8
   129
    Glib::ustring mapname = entry->get_text();
hegyi@8
   130
    if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@8
   131
    {
hegyi@31
   132
      if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) || (mapname=="Default") )
hegyi@8
   133
      {
hegyi@8
   134
	switch(prop)
hegyi@8
   135
	{
hegyi@28
   136
          case E_WIDTH:
hegyi@28
   137
	    gdc.changeEdgeWidth(mapname);
hegyi@8
   138
	    break;
hegyi@28
   139
          case E_COLOR:
hegyi@28
   140
	    gdc.changeEdgeColor(mapname);
hegyi@8
   141
	    break;
hegyi@28
   142
          case E_TEXT:
hegyi@28
   143
	    gdc.changeEdgeText(mapname);
hegyi@8
   144
	    break;
hegyi@8
   145
          default:
hegyi@8
   146
	    std::cout<<"Error\n";
hegyi@8
   147
	}
hegyi@8
   148
      }
ladanyi@6
   149
    }
ladanyi@6
   150
  }
ladanyi@6
   151
};
hegyi@28
   152
hegyi@30
   153
void MapWin::nComboChanged(int prop)
hegyi@28
   154
{
hegyi@28
   155
hegyi@28
   156
  Gtk::Entry* entry = n_combo_array[prop].get_entry();
hegyi@28
   157
hegyi@28
   158
  if(entry)
hegyi@28
   159
  {
hegyi@28
   160
    Glib::ustring mapname = entry->get_text();
hegyi@28
   161
    if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@28
   162
    {
hegyi@31
   163
      if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) || (mapname=="Default") )
hegyi@28
   164
      {
hegyi@28
   165
	switch(prop)
hegyi@28
   166
	{
hegyi@28
   167
          case N_RADIUS:
hegyi@28
   168
	    gdc.changeNodeRadius(mapname);
hegyi@28
   169
	    break;
hegyi@28
   170
          case N_COLOR:
hegyi@28
   171
	    gdc.changeNodeColor(mapname);
hegyi@28
   172
	    break;
hegyi@28
   173
          case N_TEXT:
hegyi@28
   174
	    gdc.changeNodeText(mapname);
hegyi@28
   175
	    break;
hegyi@28
   176
          default:
hegyi@28
   177
	    std::cout<<"Error\n";
hegyi@28
   178
	}
hegyi@28
   179
      }
hegyi@28
   180
    }
hegyi@28
   181
  }
hegyi@28
   182
};
hegyi@28
   183
hegyi@30
   184
void MapWin::updateNode(Graph::Node node)
hegyi@28
   185
{
hegyi@28
   186
  for(int i=0;i<NODE_PROPERTY_NUM;i++)
hegyi@28
   187
    {
hegyi@28
   188
      Gtk::Entry* entry = n_combo_array[i].get_entry();
hegyi@28
   189
hegyi@28
   190
      if(entry)
hegyi@28
   191
	{
hegyi@28
   192
	  Glib::ustring mapname = entry->get_text();
hegyi@28
   193
	  if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@28
   194
	    {
hegyi@31
   195
	      if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) || (mapname=="Default") )
hegyi@28
   196
		{
hegyi@28
   197
		  switch(i)
hegyi@28
   198
		    {
hegyi@28
   199
		    case N_RADIUS:
hegyi@31
   200
		      gdc.changeNodeRadius(mapname, node);
hegyi@28
   201
		      break;
hegyi@28
   202
		    case N_COLOR:
hegyi@28
   203
		      gdc.changeNodeColor(mapname, node);
hegyi@28
   204
		      break;
hegyi@28
   205
		    case N_TEXT:
hegyi@28
   206
		      gdc.changeNodeText(mapname, node);
hegyi@28
   207
		      break;
hegyi@28
   208
		    default:
hegyi@28
   209
		      std::cout<<"Error\n";
hegyi@28
   210
		    }
hegyi@28
   211
		}
hegyi@28
   212
	    }
hegyi@28
   213
	}
hegyi@28
   214
    }
hegyi@28
   215
}
hegyi@28
   216
hegyi@30
   217
void MapWin::updateEdge(Graph::Edge edge)
hegyi@28
   218
{
hegyi@28
   219
  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
hegyi@28
   220
    {
hegyi@28
   221
hegyi@28
   222
      Gtk::Entry* entry = e_combo_array[i].get_entry();
hegyi@28
   223
hegyi@28
   224
      if(entry)
hegyi@28
   225
	{
hegyi@28
   226
	  Glib::ustring mapname = entry->get_text();
hegyi@28
   227
	  if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@28
   228
	    {
hegyi@28
   229
hegyi@31
   230
	      if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) || (mapname=="Default") )
hegyi@28
   231
		{
hegyi@28
   232
		  switch(i)
hegyi@28
   233
		    {
hegyi@28
   234
		    case E_WIDTH:
hegyi@31
   235
		      gdc.changeEdgeWidth(mapname, edge);
hegyi@28
   236
		      break;
hegyi@28
   237
		    case E_COLOR:
hegyi@28
   238
		      gdc.changeEdgeColor(mapname, edge);
hegyi@28
   239
		      break;
hegyi@28
   240
		    case E_TEXT:
hegyi@28
   241
		      gdc.changeEdgeText(mapname, edge);
hegyi@28
   242
		      break;
hegyi@28
   243
		    default:
hegyi@28
   244
		      std::cout<<"Error\n";
hegyi@28
   245
		    }
hegyi@28
   246
		}
hegyi@28
   247
	    }
hegyi@28
   248
	}
hegyi@28
   249
    }
hegyi@28
   250
}
hegyi@38
   251
hegyi@38
   252
void MapWin::registerNewEdgeMap(std::string)
hegyi@38
   253
{
hegyi@38
   254
  std::cout << "void MapWin::registerNewEdgeMap(std::string) is not yet implemented" << std::endl;
hegyi@38
   255
}
hegyi@38
   256
hegyi@38
   257
void MapWin::registerNewNodeMap(std::string)
hegyi@38
   258
{
hegyi@38
   259
  std::cout << "void MapWin::registerNewNodeMap(std::string) is not yet implemented" << std::endl;
hegyi@38
   260
}