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