Documentation was added to GUI.
authorhegyi
Wed, 27 Jul 2005 10:47:38 +0000
changeset 15940bd9e53c8b28
parent 1593 a8a007f1c01c
child 1595 3bde58e2d5ca
Documentation was added to GUI.
gui/graph_displayer_canvas-event.cc
gui/map_win.cc
     1.1 --- a/gui/graph_displayer_canvas-event.cc	Tue Jul 26 21:20:01 2005 +0000
     1.2 +++ b/gui/graph_displayer_canvas-event.cc	Wed Jul 27 10:47:38 2005 +0000
     1.3 @@ -424,10 +424,13 @@
     1.4    switch(e->type)
     1.5      {
     1.6      case GDK_BUTTON_PRESS:
     1.7 +      //finding the clicked items
     1.8        window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
     1.9        active_item=(get_item_at(clicked_x, clicked_y));
    1.10        active_node=INVALID;
    1.11        active_edge=INVALID;
    1.12 +
    1.13 +      //was it a node?
    1.14        for (NodeIt i(g); i!=INVALID; ++i)
    1.15  	{
    1.16  	  if(nodesmap[i]==active_item)
    1.17 @@ -435,6 +438,7 @@
    1.18  	      active_node=i;
    1.19  	    }
    1.20  	}
    1.21 +      //or was it an edge?
    1.22        if(active_node==INVALID)
    1.23  	{
    1.24  	  for (EdgeIt i(g); i!=INVALID; ++i)
    1.25 @@ -445,6 +449,8 @@
    1.26  		}
    1.27  	    }
    1.28  	}
    1.29 +
    1.30 +      //recolor activated item
    1.31        if(active_item)
    1.32  	{
    1.33  	  *active_item << Gnome::Canvas::Properties::fill_color("red");
    1.34 @@ -455,8 +461,10 @@
    1.35        window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    1.36        if(active_item)
    1.37  	{
    1.38 +	  //the cursor was not moved since pressing it
    1.39  	  if( active_item == ( get_item_at (clicked_x, clicked_y) ) )
    1.40  	    {
    1.41 +	      //a node was found
    1.42  	      if(active_node!=INVALID)
    1.43  		{
    1.44  
    1.45 @@ -522,14 +530,19 @@
    1.46    switch(e->type)
    1.47      {
    1.48      case GDK_KEY_PRESS:
    1.49 +      //for Escape or Enter hide the displayed widget
    1.50        {
    1.51  	nodeMapEditEventHandler(e);
    1.52  	break;
    1.53        }
    1.54      case GDK_BUTTON_PRESS:
    1.55 +      //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
    1.56        {
    1.57 +	//find the activated item
    1.58  	window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    1.59  	active_item=(get_item_at(clicked_x, clicked_y));
    1.60 +
    1.61 +	//determine, whether it was an edge
    1.62  	Graph::EdgeIt clicked_edge=INVALID;
    1.63  	for (EdgeIt i(g); i!=INVALID; ++i)
    1.64  	  {
    1.65 @@ -538,29 +551,55 @@
    1.66  		clicked_edge=i;
    1.67  	      }
    1.68  	  }
    1.69 +	//if it was really an edge...
    1.70  	if(clicked_edge!=INVALID)
    1.71  	  {
    1.72 -	    if(edgetextmap[clicked_edge]->property_text().get_value()!="")
    1.73 +	    //If there is already edited edge, it has to be saved first
    1.74 +	    if(entrywidget.is_visible())
    1.75  	      {
    1.76 -		active_edge=clicked_edge;
    1.77 -		if(canvasentrywidget)
    1.78 +		GdkEvent * generated=new GdkEvent();
    1.79 +		generated->type=GDK_KEY_PRESS;
    1.80 +		((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
    1.81 +		entryWidgetChangeHandler(generated);
    1.82 +	      }
    1.83 +	    //If the previous value could be saved, we can go further, otherwise not
    1.84 +	    if(!entrywidget.is_visible())
    1.85 +	      {
    1.86 +		//and there is activated map
    1.87 +		if(edgetextmap[clicked_edge]->property_text().get_value()!="")
    1.88  		  {
    1.89 -		    delete(canvasentrywidget);
    1.90 +		    //activate the general variable for it
    1.91 +		    active_edge=clicked_edge;
    1.92 +		    //delete visible widget if there is
    1.93 +		    if(canvasentrywidget)
    1.94 +		      {
    1.95 +			delete(canvasentrywidget);
    1.96 +		      }
    1.97 +
    1.98 +		    //initialize the entry
    1.99 +		    entrywidget.show();
   1.100 +
   1.101 +		    //fill in the correct value
   1.102 +		    entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
   1.103 +
   1.104 +		    //replace and resize the entry to the activated edge and put it in a Canvas::Widget to be able to display it on gdc
   1.105 +		    xy<double> entry_coos;
   1.106 +		    entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
   1.107 +		    entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
   1.108 +		    entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
   1.109 +		    entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
   1.110 +		    canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
   1.111 +		    canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*1.5);
   1.112 +		    canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
   1.113  		  }
   1.114 -		entrywidget.show();
   1.115 -		entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
   1.116 -		xy<double> entry_coos;
   1.117 -		entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
   1.118 -		entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
   1.119 -		entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
   1.120 -		entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
   1.121 -		canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
   1.122 -		canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*1.5);
   1.123 -		canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
   1.124  	      }
   1.125  	  }
   1.126 +	//if it was not an edge...
   1.127  	else
   1.128  	  {
   1.129 +	    //In this case the click did not happen on an edge
   1.130 +	    //if there is visible entry we save the value in it
   1.131 +	    //we pretend like an Enter was presse din the Entry widget
   1.132  	    GdkEvent * generated=new GdkEvent();
   1.133  	    generated->type=GDK_KEY_PRESS;
   1.134  	    ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
   1.135 @@ -579,6 +618,7 @@
   1.136    switch(e->type)
   1.137      {
   1.138      case GDK_KEY_PRESS:
   1.139 +      //for Escape or Enter hide the displayed widget
   1.140        {
   1.141  	switch(((GdkEventKey*)e)->keyval)
   1.142  	  {
   1.143 @@ -596,9 +636,13 @@
   1.144  	break;
   1.145        }
   1.146      case GDK_BUTTON_PRESS:
   1.147 +      //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
   1.148        {
   1.149 +	//find the activated item
   1.150  	window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
   1.151  	active_item=(get_item_at(clicked_x, clicked_y));
   1.152 +
   1.153 +	//determine, whether it was a node
   1.154  	Graph::NodeIt clicked_node=INVALID;
   1.155  	for (NodeIt i(g); i!=INVALID; ++i)
   1.156  	  {
   1.157 @@ -607,6 +651,8 @@
   1.158  		clicked_node=i;
   1.159  	      }
   1.160  	  }
   1.161 +
   1.162 +	//if it was really an edge...
   1.163  	if(clicked_node!=INVALID)
   1.164  	  {
   1.165  	    //If there is already edited edge, it has to be saved first
   1.166 @@ -620,16 +666,24 @@
   1.167  	    //If the previous value could be saved, we can go further, otherwise not
   1.168  	    if(!entrywidget.is_visible())
   1.169  	      {
   1.170 -
   1.171 +		//and there is activated map
   1.172  		if(nodetextmap[clicked_node]->property_text().get_value()!="")
   1.173  		  {
   1.174 +		    //activate the general variable for it
   1.175  		    active_node=clicked_node;
   1.176 +		    //delete visible widget if there is
   1.177  		    if(canvasentrywidget)
   1.178  		      {
   1.179  			delete(canvasentrywidget);
   1.180  		      }
   1.181 +
   1.182 +		    //initialize the entry
   1.183  		    entrywidget.show();
   1.184 +
   1.185 +		    //fill in the correct value
   1.186  		    entrywidget.set_text(nodetextmap[active_node]->property_text().get_value());
   1.187 +
   1.188 +		    //replace and resize the entry to the activated node and put it in a Canvas::Widget to be able to display it on gdc
   1.189  		    xy<double> entry_coos;
   1.190  		    entry_coos.x=(nodetextmap[active_node])->property_x().get_value();
   1.191  		    entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2;
   1.192 @@ -641,8 +695,12 @@
   1.193  		  }
   1.194  	      }
   1.195  	  }
   1.196 +	//if it was not an edge...
   1.197  	else
   1.198  	  {
   1.199 +	    //In this case the click did not happen on an edge
   1.200 +	    //if there is visible entry we save the value in it
   1.201 +	    //we pretend like an Enter was presse din the Entry widget
   1.202  	    GdkEvent * generated=new GdkEvent();
   1.203  	    generated->type=GDK_KEY_PRESS;
   1.204  	    ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
   1.205 @@ -670,8 +728,11 @@
   1.206  	    case GDK_KP_Enter:
   1.207  	    case GDK_Return:
   1.208  	      {
   1.209 +		//these variables check whether the text in the entry is valid
   1.210  		bool valid_double=true;
   1.211  		int point_num=0;
   1.212 +
   1.213 +		//getting the value from the entry and converting it to double
   1.214  		Glib::ustring mapvalue_str = entrywidget.get_text();
   1.215  
   1.216  		char * mapvalue_ch=new char [mapvalue_str.length()];
   1.217 @@ -693,46 +754,10 @@
   1.218    
   1.219  		double mapvalue_d=atof(mapvalue_ch);
   1.220  
   1.221 -// 		double double_map_fract_value=0;
   1.222 -// 		double double_map_value=0;
   1.223 -// 		int offset=0;
   1.224 -// 		int found_letter=0;
   1.225 -		//converting text to double
   1.226 -// 		for(int i=0;i<(int)(mapvalue.length());i++)
   1.227 -// 		  {
   1.228 -// 		    if(((mapvalue[i]<='9')&&(mapvalue[i]>='0'))||(mapvalue[i]=='.'))
   1.229 -// 		      {
   1.230 -// 			if(mapvalue[i]=='.')
   1.231 -// 			  {
   1.232 -// 			    //for calculating non-integer part of double we step backward from the end
   1.233 -// 			    //after each step the number will be divided by ten, and the new value will be added
   1.234 -// 			    //to step backward from the end until the point the actual character of the string is the following:
   1.235 -// 			    // mapvalue.length()-(i-position_of_point)
   1.236 -// 			    //if i was the number of the first character after the decimal point the selected character will be the last
   1.237 -// 			    //if i was the number of the last character, the selected character will be the first after the decimal point
   1.238 -// 			    offset=mapvalue.length()+i;
   1.239 -// 			  }
   1.240 -// 			else
   1.241 -// 			  {
   1.242 -// 			    if(!offset)
   1.243 -// 			      {
   1.244 -// 				double_map_value=10*double_map_value+mapvalue[i]-'0';
   1.245 -// 			      }
   1.246 -// 			    else
   1.247 -// 			      {
   1.248 -// 				double_map_fract_value=double_map_fract_value/10+(double)(mapvalue[offset-i]-'0')/10;
   1.249 -// 			      }
   1.250 -// 			  }
   1.251 -// 		      }
   1.252 -// 		    else
   1.253 -// 		      {
   1.254 -// 			found_letter++;
   1.255 -// 			continue;
   1.256 -// 		      }
   1.257 -// 		  }
   1.258 -
   1.259 +		//if the text in the entry was correct
   1.260  		if((point_num<=1)&&(valid_double))
   1.261  		  {
   1.262 +		    //save the value to the correct place
   1.263  		    switch(actual_tool)
   1.264  		      {
   1.265  		      case EDGE_MAP_EDIT:
   1.266 @@ -748,6 +773,7 @@
   1.267  		      }
   1.268  		    entrywidget.hide();
   1.269  		  }
   1.270 +		//the text in the entry was not correct for a double
   1.271  		else
   1.272  		  {
   1.273  		    std::cout << "ERROR: only handling of double values is implemented yet!" << std::endl;
   1.274 @@ -826,17 +852,27 @@
   1.275  
   1.276  void GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname)
   1.277  {
   1.278 +  //create the new map
   1.279    Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (g,default_value);
   1.280    mapstorage.addEdgeMap(mapname,emptr);
   1.281 +
   1.282 +  //add it to the list of the displayable maps
   1.283    mapwin->registerNewEdgeMap(mapname);
   1.284 +
   1.285 +  //display it
   1.286    changeEdgeText(mapname);
   1.287  }
   1.288  
   1.289  void GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname)
   1.290  {
   1.291 +  //create the new map
   1.292    Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (g,default_value);
   1.293    mapstorage.addNodeMap(mapname,emptr);
   1.294 +
   1.295 +  //add it to the list of the displayable maps
   1.296    mapwin->registerNewNodeMap(mapname);
   1.297 +
   1.298 +  //display it
   1.299    changeNodeText(mapname);
   1.300  }
   1.301  
     2.1 --- a/gui/map_win.cc	Tue Jul 26 21:20:01 2005 +0000
     2.2 +++ b/gui/map_win.cc	Wed Jul 27 10:47:38 2005 +0000
     2.3 @@ -259,6 +259,7 @@
     2.4      listStrings.push_back(newmapname);
     2.5      e_combo_array[i].set_popdown_strings(listStrings);
     2.6    }
     2.7 +  //setting text property for the new map
     2.8    Gtk::Entry* entry = e_combo_array[E_TEXT].get_entry();
     2.9    entry->set_text((Glib::ustring)newmapname);
    2.10  }
    2.11 @@ -272,6 +273,7 @@
    2.12      listStrings.push_back(newmapname);
    2.13      n_combo_array[i].set_popdown_strings(listStrings);
    2.14    }
    2.15 +  //setting text property for the new map
    2.16    Gtk::Entry* entry = n_combo_array[N_TEXT].get_entry();
    2.17    entry->set_text((Glib::ustring)newmapname);
    2.18  }