Edge and nodemap edition is done.
1.1 --- a/gui/graph_displayer_canvas-edge.cc Wed Jul 20 22:36:37 2005 +0000
1.2 +++ b/gui/graph_displayer_canvas-edge.cc Thu Jul 21 19:28:29 2005 +0000
1.3 @@ -118,6 +118,7 @@
1.4 {
1.5 if(mapname!="Default")
1.6 {
1.7 + edgemap_to_edit=mapname;
1.8 double number=(*(mapstorage.edgemap_storage)[mapname])[i];
1.9 int length=1;
1.10 //if number is smaller than one, length would be negative, or invalid
1.11 @@ -146,6 +147,7 @@
1.12 }
1.13 else
1.14 {
1.15 + edgemap_to_edit="";
1.16 edgetextmap[i]->property_text().set_value("");
1.17 }
1.18 }
2.1 --- a/gui/graph_displayer_canvas-event.cc Wed Jul 20 22:36:37 2005 +0000
2.2 +++ b/gui/graph_displayer_canvas-event.cc Thu Jul 21 19:28:29 2005 +0000
2.3 @@ -29,7 +29,16 @@
2.4 break;
2.5 }
2.6 case EDGE_MAP_EDIT:
2.7 - break;
2.8 + //has to do the same thing as in the case of NODE_MAP_EDIT
2.9 + case NODE_MAP_EDIT:
2.10 + {
2.11 + GdkEvent * generated=new GdkEvent();
2.12 + generated->type=GDK_KEY_PRESS;
2.13 + ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
2.14 + entryWidgetChangeHandler(generated);
2.15 + entrywidget.hide();
2.16 + break;
2.17 + }
2.18 default:
2.19 break;
2.20 }
2.21 @@ -218,9 +227,6 @@
2.22
2.23 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
2.24
2.25 - target_item=NULL;
2.26 - target_item=get_item_at(clicked_x, clicked_y);
2.27 -
2.28 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
2.29 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
2.30 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
2.31 @@ -247,11 +253,20 @@
2.32
2.33 //finalize the new node
2.34 case GDK_BUTTON_RELEASE:
2.35 + window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
2.36 +
2.37 + active_item->lower_to_bottom();
2.38 +
2.39 + target_item=NULL;
2.40 + target_item=get_item_at(clicked_x, clicked_y);
2.41 +
2.42 + active_item->raise_to_top();
2.43 +
2.44 isbutton=0;
2.45 - if(!target_item)
2.46 + if(target_item==active_item)
2.47 {
2.48 //Its appropriate color is given by update.
2.49 - //*active_item << Gnome::Canvas::Properties::fill_color("blue");
2.50 + *active_item << Gnome::Canvas::Properties::fill_color("blue");
2.51 }
2.52 else
2.53 {
2.54 @@ -508,16 +523,7 @@
2.55 {
2.56 case GDK_KEY_PRESS:
2.57 {
2.58 - std::cout << "Any button was pressed" << std::endl;
2.59 - switch(((GdkEventKey*)e)->keyval)
2.60 - {
2.61 - case GDK_A:
2.62 - std::cout << "A button was pressed" << std::endl;
2.63 - break;
2.64 - default:
2.65 - break;
2.66 - }
2.67 -
2.68 + nodeMapEditEventHandler(e);
2.69 break;
2.70 }
2.71 case GDK_BUTTON_PRESS:
2.72 @@ -555,8 +561,10 @@
2.73 }
2.74 else
2.75 {
2.76 - //mentse el -> problema, hogy nem tudja melyik map-be
2.77 - entrywidget.hide();
2.78 + GdkEvent * generated=new GdkEvent();
2.79 + generated->type=GDK_KEY_PRESS;
2.80 + ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
2.81 + entryWidgetChangeHandler(generated);
2.82 }
2.83 break;
2.84 }
2.85 @@ -568,15 +576,169 @@
2.86
2.87 bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e)
2.88 {
2.89 - e=e;
2.90 - return false;
2.91 + switch(e->type)
2.92 + {
2.93 + case GDK_KEY_PRESS:
2.94 + {
2.95 + switch(((GdkEventKey*)e)->keyval)
2.96 + {
2.97 + case GDK_Escape:
2.98 + entrywidget.hide();
2.99 + break;
2.100 + case GDK_Return:
2.101 + case GDK_KP_Enter:
2.102 + entrywidget.hide();
2.103 + break;
2.104 + default:
2.105 + break;
2.106 + }
2.107 +
2.108 + break;
2.109 + }
2.110 + case GDK_BUTTON_PRESS:
2.111 + {
2.112 + window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
2.113 + active_item=(get_item_at(clicked_x, clicked_y));
2.114 + Graph::NodeIt clicked_node=INVALID;
2.115 + for (NodeIt i(g); i!=INVALID; ++i)
2.116 + {
2.117 + if(nodesmap[i]==active_item)
2.118 + {
2.119 + clicked_node=i;
2.120 + }
2.121 + }
2.122 + if(clicked_node!=INVALID)
2.123 + {
2.124 + //If there is already edited edge, it has to be saved first
2.125 + if(entrywidget.is_visible())
2.126 + {
2.127 + GdkEvent * generated=new GdkEvent();
2.128 + generated->type=GDK_KEY_PRESS;
2.129 + ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
2.130 + entryWidgetChangeHandler(generated);
2.131 + }
2.132 + //If the previous value could be saved, we can go further, otherwise not
2.133 + if(!entrywidget.is_visible())
2.134 + {
2.135 +
2.136 + if(nodetextmap[clicked_node]->property_text().get_value()!="")
2.137 + {
2.138 + active_node=clicked_node;
2.139 + if(canvasentrywidget)
2.140 + {
2.141 + delete(canvasentrywidget);
2.142 + }
2.143 + entrywidget.show();
2.144 + entrywidget.set_text(nodetextmap[active_node]->property_text().get_value());
2.145 + xy<double> entry_coos;
2.146 + entry_coos.x=(nodetextmap[active_node])->property_x().get_value();
2.147 + entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2;
2.148 + entry_coos.y=(nodetextmap[active_node])->property_y().get_value();
2.149 + entry_coos.y-=nodetextmap[active_node]->property_text_height().get_value()*1.5/2;
2.150 + canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
2.151 + canvasentrywidget->property_width().set_value(nodetextmap[active_node]->property_text_width().get_value()*1.5);
2.152 + canvasentrywidget->property_height().set_value(nodetextmap[active_node]->property_text_height().get_value()*1.5);
2.153 + }
2.154 + }
2.155 + }
2.156 + else
2.157 + {
2.158 + GdkEvent * generated=new GdkEvent();
2.159 + generated->type=GDK_KEY_PRESS;
2.160 + ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
2.161 + entryWidgetChangeHandler(generated);
2.162 + }
2.163 + break;
2.164 + }
2.165 + default:
2.166 + break;
2.167 + }
2.168 + return false;
2.169 }
2.170
2.171 bool GraphDisplayerCanvas::entryWidgetChangeHandler(GdkEvent* e)
2.172 {
2.173 - Glib::ustring mapvalue = entrywidget.get_text();
2.174 - std::cout << mapvalue << std::endl;
2.175 - e=e;
2.176 + if(entrywidget.is_visible())
2.177 + {
2.178 + if(e->type==GDK_KEY_PRESS)
2.179 + {
2.180 + switch(((GdkEventKey*)e)->keyval)
2.181 + {
2.182 + case GDK_Escape:
2.183 + entrywidget.hide();
2.184 + break;
2.185 + case GDK_KP_Enter:
2.186 + case GDK_Return:
2.187 + {
2.188 + Glib::ustring mapvalue = entrywidget.get_text();
2.189 +
2.190 + double double_map_fract_value=0;
2.191 + double double_map_value=0;
2.192 + int offset=0;
2.193 + int found_letter=0;
2.194 + //converting text to double
2.195 + for(int i=0;i<(int)(mapvalue.length());i++)
2.196 + {
2.197 + if(((mapvalue[i]<='9')&&(mapvalue[i]>='0'))||(mapvalue[i]=='.'))
2.198 + {
2.199 + if(mapvalue[i]=='.')
2.200 + {
2.201 + //for calculating non-integer part of double we step backward from the end
2.202 + //after each step the number will be divided by ten, and the new value will be added
2.203 + //to step backward from the end until the point the actual character of the string is the following:
2.204 + // mapvalue.length()-(i-position_of_point)
2.205 + //if i was the number of the first character after the decimal point the selected character will be the last
2.206 + //if i was the number of the last character, the selected character will be the first after the decimal point
2.207 + offset=mapvalue.length()+i;
2.208 + }
2.209 + else
2.210 + {
2.211 + if(!offset)
2.212 + {
2.213 + double_map_value=10*double_map_value+mapvalue[i]-'0';
2.214 + }
2.215 + else
2.216 + {
2.217 + double_map_fract_value=double_map_fract_value/10+(double)(mapvalue[offset-i]-'0')/10;
2.218 + }
2.219 + }
2.220 + }
2.221 + else
2.222 + {
2.223 + found_letter++;
2.224 + continue;
2.225 + }
2.226 + }
2.227 +
2.228 + if(!found_letter)
2.229 + {
2.230 + switch(actual_tool)
2.231 + {
2.232 + case EDGE_MAP_EDIT:
2.233 + edgetextmap[active_edge]->property_text().set_value(mapvalue);
2.234 + (*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=double_map_value+double_map_fract_value;
2.235 + break;
2.236 + case NODE_MAP_EDIT:
2.237 + nodetextmap[active_node]->property_text().set_value(mapvalue);
2.238 + (*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=double_map_value+double_map_fract_value;
2.239 + break;
2.240 + default:
2.241 + break;
2.242 + }
2.243 + entrywidget.hide();
2.244 + }
2.245 + else
2.246 + {
2.247 + std::cout << "ERROR: only handling of double values is implemented yet!" << std::endl;
2.248 + }
2.249 +
2.250 + break;
2.251 + }
2.252 + default:
2.253 + break;
2.254 + }
2.255 + }
2.256 + }
2.257 return false;
2.258 }
2.259
2.260 @@ -604,15 +766,15 @@
2.261 void GraphDisplayerCanvas::textReposition(xy<double> new_place)
2.262 {
2.263 new_place+=(xy<double>(10,10));
2.264 - edgetextmap[active_edge]->property_x().set_value(new_place.x);
2.265 - edgetextmap[active_edge]->property_y().set_value(new_place.y);
2.266 + edgetextmap[forming_edge]->property_x().set_value(new_place.x);
2.267 + edgetextmap[forming_edge]->property_y().set_value(new_place.y);
2.268 }
2.269
2.270 void GraphDisplayerCanvas::toggleEdgeActivity(BrokenEdge* active_bre, bool on)
2.271 {
2.272 if(on)
2.273 {
2.274 - if(active_edge!=INVALID)
2.275 + if(forming_edge!=INVALID)
2.276 {
2.277 std::cout << "ERROR!!!! Valid edge found!" << std::endl;
2.278 }
2.279 @@ -622,16 +784,16 @@
2.280 {
2.281 if(edgesmap[i]==active_bre)
2.282 {
2.283 - active_edge=i;
2.284 + forming_edge=i;
2.285 }
2.286 }
2.287 }
2.288 }
2.289 else
2.290 {
2.291 - if(active_edge!=INVALID)
2.292 + if(forming_edge!=INVALID)
2.293 {
2.294 - active_edge=INVALID;
2.295 + forming_edge=INVALID;
2.296 }
2.297 else
2.298 {
3.1 --- a/gui/graph_displayer_canvas-node.cc Wed Jul 20 22:36:37 2005 +0000
3.2 +++ b/gui/graph_displayer_canvas-node.cc Thu Jul 21 19:28:29 2005 +0000
3.3 @@ -136,11 +136,7 @@
3.4 //that is the deleter map
3.5
3.6 Graph::NodeMap<double> * actual_map;
3.7 - if(mapname=="Default")
3.8 - {
3.9 - actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_COLOR]);
3.10 - }
3.11 - else
3.12 + if(mapname!="Default")
3.13 {
3.14 actual_map=(mapstorage.nodemap_storage)[mapname];
3.15 }
3.16 @@ -151,6 +147,7 @@
3.17 {
3.18 if(mapname!="Default")
3.19 {
3.20 + nodemap_to_edit=mapname;
3.21 double number=(*actual_map)[i];
3.22 int length=1;
3.23 //if number is smaller than one, length would be negative, or invalid
3.24 @@ -168,7 +165,7 @@
3.25 {
3.26 if(j!=length)
3.27 {
3.28 - int digit=(int)(number/maxpos);
3.29 + int digit=(int)round(number/maxpos);
3.30 str[j]=(digit+'0');
3.31 number-=digit*maxpos;
3.32 number*=10;
3.33 @@ -179,6 +176,7 @@
3.34 }
3.35 else
3.36 {
3.37 + nodemap_to_edit="";
3.38 nodetextmap[i]->property_text().set_value("");
3.39 }
3.40 }
4.1 --- a/gui/graph_displayer_canvas.cc Wed Jul 20 22:36:37 2005 +0000
4.2 +++ b/gui/graph_displayer_canvas.cc Thu Jul 21 19:28:29 2005 +0000
4.3 @@ -2,18 +2,20 @@
4.4 #include <broken_edge.h>
4.5 #include <math.h>
4.6
4.7 -GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms, MapWin * mw):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),nodetextmap(g),displayed_graph(*(root()), 0, 0),canvasentrywidget(NULL),mapstorage(ms),isbutton(0),active_item(NULL),target_item(NULL),mapwin(mw)
4.8 +GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms, MapWin * mw):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),nodetextmap(g),displayed_graph(*(root()), 0, 0),canvasentrywidget(NULL),mapstorage(ms),isbutton(0),active_item(NULL),target_item(NULL),edgemap_to_edit(""),nodemap_to_edit(""),mapwin(mw)
4.9 {
4.10
4.11 +
4.12 active_node=INVALID;
4.13 active_edge=INVALID;
4.14 + forming_edge=INVALID;
4.15
4.16 //setting event handler for the editor widget
4.17 entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false);
4.18
4.19 //base event handler is move tool
4.20 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
4.21 - actual_tool=CREATE_NODE;
4.22 + actual_tool=MOVE;
4.23
4.24 //set_center_scroll_region(true);
4.25
5.1 --- a/gui/graph_displayer_canvas.h Wed Jul 20 22:36:37 2005 +0000
5.2 +++ b/gui/graph_displayer_canvas.h Thu Jul 21 19:28:29 2005 +0000
5.3 @@ -97,6 +97,12 @@
5.4 ///Moves the text to new place
5.5 void textReposition(xy<double>);
5.6 ///Activates an edge belonging to a BrokenEdge
5.7 + ///
5.8 + ///After we have activated an edge this way,
5.9 + ///the GDC object will know, which edge is under forming
5.10 + ///therefore it can redraw the necessarz elementy on the canvas,
5.11 + ///for example the text belonging to the \ref BrokenEdge can be
5.12 + ///redrawn (\ref textReposition).
5.13 void toggleEdgeActivity(BrokenEdge*, bool);
5.14
5.15 public:
5.16 @@ -157,6 +163,9 @@
5.17 Gnome::Canvas::Item * active_item, * target_item;
5.18 Graph::NodeIt active_node;
5.19 Graph::EdgeIt active_edge;
5.20 + Graph::EdgeIt forming_edge;
5.21 +
5.22 + std::string nodemap_to_edit, edgemap_to_edit;
5.23
5.24 static const int zoom_step = 5;
5.25
6.1 --- a/gui/graphocska.lgf Wed Jul 20 22:36:37 2005 +0000
6.2 +++ b/gui/graphocska.lgf Thu Jul 21 19:28:29 2005 +0000
6.3 @@ -1,6 +1,6 @@
6.4 @nodeset
6.5 id coordinates_x coordinates_y data
6.6 -1 230 -80 1
6.7 +1 230 -80 1.123
6.8 2 230 100 3
6.9 3 120 -80 5
6.10 4 120 100 7