gui/map_win.cc
author alpar
Thu, 09 Jun 2005 09:49:56 +0000
changeset 1459 2ee881cf30a8
parent 1442 1e3c69aa035b
child 1512 e54392395480
permissions -rw-r--r--
- InDegMap fixed
- OutDegMap added
- test cases added for them both
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@1446
    13
MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst),table(PROPERTY_NUM, 2, false)
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@1446
    20
  combo_array=new Gtk::Combo [PROPERTY_NUM];
hegyi@1446
    21
ladanyi@1442
    22
  for(int i=0;i<PROPERTY_NUM;i++)
ladanyi@1442
    23
  {
ladanyi@1442
    24
ladanyi@1442
    25
    std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
ladanyi@1442
    26
    std::set<int> props;
ladanyi@1442
    27
ladanyi@1442
    28
    int actprop;
hegyi@1446
    29
hegyi@1446
    30
    //here we find out, which map is the default in MapStorage for this property, which are not
ladanyi@1442
    31
    for(int j=0;j<ms.numOfEdgeMaps();j++)
ladanyi@1442
    32
    {
hegyi@1446
    33
      //this is the default value for this property
ladanyi@1442
    34
      if(emsi->second==&(ms.default_edgemaps[i]))
ladanyi@1442
    35
      {
ladanyi@1442
    36
	actprop=j;
ladanyi@1442
    37
      }
hegyi@1446
    38
      //this is the other maps to show for this property
ladanyi@1442
    39
      for(int k=0;k<PROPERTY_NUM;k++)
ladanyi@1442
    40
      {
ladanyi@1442
    41
	if(emsi->second==&(ms.default_edgemaps[k]))
ladanyi@1442
    42
	{
ladanyi@1442
    43
	  props.insert(j);
ladanyi@1442
    44
	}
ladanyi@1442
    45
      }
ladanyi@1442
    46
      emsi++;
ladanyi@1442
    47
    }
ladanyi@1442
    48
hegyi@1446
    49
    //combo_array[i].set_group(group);
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@1446
    67
    combo_array[i].set_popdown_strings(listStrings);
hegyi@1446
    68
hegyi@1446
    69
    //Restrict it to these choices only:
hegyi@1446
    70
    combo_array[i].set_value_in_list();
hegyi@1446
    71
hegyi@1446
    72
    //binding signal to thew actual entry
hegyi@1446
    73
    combo_array[i].get_entry()->signal_changed().connect
hegyi@1446
    74
    (
hegyi@1446
    75
     sigc::bind
hegyi@1446
    76
     (
hegyi@1446
    77
      sigc::mem_fun(*this, &MapWin::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@1446
    85
    label->set_text(property_strings[i]);
hegyi@1446
    86
hegyi@1446
    87
    //    labelpluscombo=new Gtk::HBox;
hegyi@1446
    88
    //    labelpluscombo->pack_start(*label);
hegyi@1446
    89
    //    labelpluscombo->pack_start(combo_array[i]);
hegyi@1446
    90
        
hegyi@1446
    91
    table.attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@1446
    92
    table.attach(combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@1446
    93
hegyi@1446
    94
    /*
hegyi@1446
    95
    if(actpos<(ms.numOfEdgeMaps()-PROPERTY_NUM+1)/2)
hegyi@1446
    96
    {
hegyi@1446
    97
      vbox_r1.pack_start(*labelpluscombo);
hegyi@1446
    98
    }
hegyi@1446
    99
    else
hegyi@1446
   100
    {
hegyi@1446
   101
      vbox_r2.pack_start(*labelpluscombo);
hegyi@1446
   102
    }
hegyi@1446
   103
    actpos++;
hegyi@1446
   104
    //*/
hegyi@1446
   105
ladanyi@1442
   106
  }
ladanyi@1442
   107
hegyi@1446
   108
  combos.pack_start(vbox_r1);
hegyi@1446
   109
  combos.pack_start(vbox_r2);
hegyi@1446
   110
hegyi@1446
   111
  //add(combos);
hegyi@1446
   112
  add(table);
ladanyi@1442
   113
ladanyi@1442
   114
  show_all_children();
ladanyi@1442
   115
ladanyi@1442
   116
}
ladanyi@1442
   117
hegyi@1446
   118
void MapWin::combo_changed(int prop)
ladanyi@1442
   119
{
ladanyi@1442
   120
ladanyi@1442
   121
  //most nem kommentezem fel, mert ugyis valtozik
hegyi@1446
   122
  Gtk::Entry* entry = combo_array[prop].get_entry();
ladanyi@1442
   123
hegyi@1446
   124
  if(entry)
ladanyi@1442
   125
  {
hegyi@1446
   126
    Glib::ustring mapname = entry->get_text();
hegyi@1446
   127
    if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@1446
   128
    {
hegyi@1446
   129
      if(mapname=="Default")
hegyi@1446
   130
      {
hegyi@1446
   131
	mapname=property_strings[prop];
hegyi@1446
   132
      }
ladanyi@1442
   133
hegyi@1446
   134
      if( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() )
hegyi@1446
   135
      {
hegyi@1446
   136
	switch(prop)
hegyi@1446
   137
	{
hegyi@1446
   138
          case WIDTH:
hegyi@1446
   139
	    gdc.changeLineWidth(mapname);
hegyi@1446
   140
	    break;
hegyi@1446
   141
          case COLOR:
hegyi@1446
   142
	    gdc.changeColor(mapname);
hegyi@1446
   143
	    break;
hegyi@1446
   144
          case TEXT:
hegyi@1446
   145
	    gdc.changeText(mapname);
hegyi@1446
   146
	    break;
hegyi@1446
   147
          default:
hegyi@1446
   148
	    std::cout<<"Error\n";
hegyi@1446
   149
	}
hegyi@1446
   150
      }
ladanyi@1442
   151
    }
ladanyi@1442
   152
  }
ladanyi@1442
   153
};