[Lemon-commits] [lemon_svn] ladanyi: r2161 - hugo/trunk/gui
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:50:37 CET 2006
Author: ladanyi
Date: Fri Aug 26 09:35:23 2005
New Revision: 2161
Modified:
hugo/trunk/gui/graph_displayer_canvas-event.cc
hugo/trunk/gui/graph_displayer_canvas.cc
hugo/trunk/gui/graph_displayer_canvas.h
hugo/trunk/gui/map_win.cc
Log:
- use Gtk::Dialog to set the new values of edge and node maps
- update all edges/nodes when editing a map so that edge widths and node
sizes change properly
- coordinate maps are no longer selectable in the maps window
Modified: hugo/trunk/gui/graph_displayer_canvas-event.cc
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas-event.cc (original)
+++ hugo/trunk/gui/graph_displayer_canvas-event.cc Fri Aug 26 09:35:23 2005
@@ -32,11 +32,6 @@
//has to do the same thing as in the case of NODE_MAP_EDIT
case NODE_MAP_EDIT:
{
- GdkEvent * generated=new GdkEvent();
- generated->type=GDK_KEY_PRESS;
- ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
- entryWidgetChangeHandler(generated);
- entrywidget.hide();
break;
}
default:
@@ -548,314 +543,187 @@
bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e)
{
if(actual_tool==EDGE_MAP_EDIT)
+ {
+ switch(e->type)
{
- switch(e->type)
- {
- case GDK_KEY_PRESS:
- //for Escape or Enter hide the displayed widget
- {
- nodeMapEditEventHandler(e);
- break;
- }
- case GDK_BUTTON_PRESS:
- //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
- {
- //for determine, whether it was an edge
- Edge clicked_edge=INVALID;
+ case GDK_BUTTON_PRESS:
+ {
+ //for determine, whether it was an edge
+ Edge clicked_edge=INVALID;
- //find the activated item between texts
- window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
- active_item=(get_item_at(clicked_x, clicked_y));
- for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
- {
- if(edgetextmap[i]==active_item)
- {
- clicked_edge=i;
- }
- }
+ window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
+ active_item=(get_item_at(clicked_x, clicked_y));
- //if it was not between texts, search for it between edges
- if(clicked_edge==INVALID)
- {
- for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
- {
- //at the same time only one can be active
- if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item))
- {
- clicked_edge=i;
- }
- }
- }
- //if it was really an edge...
- if(clicked_edge!=INVALID)
- {
- // the id map is not editable
- if (edgemap_to_edit == "id") return 0;
+ //find the activated item between texts
+ for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
+ {
+ //at the same time only one can be active
+ if(edgetextmap[i]==active_item)
+ {
+ clicked_edge=i;
+ }
+ }
- //If there is already edited edge, it has to be saved first
- if(entrywidget.is_visible())
- {
- GdkEvent * generated=new GdkEvent();
- generated->type=GDK_KEY_PRESS;
- ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
- entryWidgetChangeHandler(generated);
- }
- //If the previous value could be saved, we can go further, otherwise not
- if(!entrywidget.is_visible())
- {
- //and there is activated map
- if(edgetextmap[clicked_edge]->property_text().get_value()!="")
- {
- //activate the general variable for it
- active_edge=clicked_edge;
- //delete visible widget if there is
- if(canvasentrywidget)
- {
- delete(canvasentrywidget);
- }
-
- //initialize the entry
- entrywidget.show();
-
- //fill in the correct value
- entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
-
- //replace and resize the entry to the activated edge and put it in a Canvas::Widget to be able to display it on gdc
- xy<double> entry_coos;
- entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
- entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
- entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
- entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
- canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
- canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*4);
- canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
-
- //setting the focus to newly created widget
- parentwin->set_focus(entrywidget);
- parentwin->activate_focus();
- }
- }
- }
- //if it was not an edge...
- else
- {
- //In this case the click did not happen on an edge
- //if there is visible entry we save the value in it
- //we pretend like an Enter was presse din the Entry widget
- GdkEvent * generated=new GdkEvent();
- generated->type=GDK_KEY_PRESS;
- ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
- entryWidgetChangeHandler(generated);
- }
- break;
- }
- default:
- break;
- }
+ //if it was not between texts, search for it between edges
+ if(clicked_edge==INVALID)
+ {
+ for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
+ {
+ //at the same time only one can be active
+ if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item))
+ {
+ clicked_edge=i;
+ }
+ }
+ }
+
+ //if it was really an edge...
+ if(clicked_edge!=INVALID)
+ {
+ // the id map is not editable
+ if (edgemap_to_edit == "id") return 0;
+
+ //and there is activated map
+ if(edgetextmap[clicked_edge]->property_text().get_value()!="")
+ {
+ //activate the general variable for it
+ active_edge=clicked_edge;
+
+ //create a dialog
+ Gtk::Dialog dialog("Edit value", *parentwin, true);
+ dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
+ Gtk::VBox* vbox = dialog.get_vbox();
+ Gtk::Adjustment adj(
+ (*mapstorage.edgemap_storage[edgemap_to_edit])[active_edge],
+ -1000000.0,
+ 1000000.0,
+ 1.0, 5.0, 0.0);
+ //TODO: find out why doesn't it work with
+ //numeric_limits<double>::min/max
+ Gtk::SpinButton spin(adj);
+ spin.set_numeric(true);
+ spin.set_digits(4);
+ vbox->add(spin);
+ spin.show();
+ switch (dialog.run())
+ {
+ case Gtk::RESPONSE_NONE:
+ case Gtk::RESPONSE_CANCEL:
+ break;
+ case Gtk::RESPONSE_ACCEPT:
+ double new_value = spin.get_value();
+ (*mapstorage.edgemap_storage[edgemap_to_edit])[active_edge] =
+ new_value;
+ std::ostringstream ostr;
+ ostr << new_value;
+ edgetextmap[active_edge]->property_text().set_value(
+ ostr.str());
+ //mapwin.updateEdge(active_edge);
+ mapwin.updateEdge(Edge(INVALID));
+ }
+ }
+ }
+ break;
+ }
+ default:
+ break;
}
+ }
return false;
}
bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e)
{
if(actual_tool==NODE_MAP_EDIT)
+ {
+ switch(e->type)
{
- switch(e->type)
- {
- case GDK_KEY_PRESS:
- //for Escape or Enter hide the displayed widget
- {
- switch(((GdkEventKey*)e)->keyval)
- {
- case GDK_Escape:
- entrywidget.hide();
- break;
- case GDK_Return:
- case GDK_KP_Enter:
- entrywidget.hide();
- break;
- default:
- break;
- }
-
- break;
- }
- case GDK_BUTTON_PRESS:
- //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
- {
- //for determine, whether it was a node
- Node clicked_node=INVALID;
+ case GDK_BUTTON_PRESS:
+ {
+ //for determine, whether it was a node
+ Node clicked_node=INVALID;
- //find the activated item between texts
- active_item=(get_item_at(e->button.x, e->button.y));
- for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
- {
- //at the same time only one can be active
- if(nodetextmap[i]==active_item)
- {
- clicked_node=i;
- }
- }
+ window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
+ active_item=(get_item_at(clicked_x, clicked_y));
- //if there was not, search for it between nodes
- if(clicked_node==INVALID)
- {
- window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
- active_item=(get_item_at(clicked_x, clicked_y));
+ //find the activated item between texts
+ for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
+ {
+ //at the same time only one can be active
+ if(nodetextmap[i]==active_item)
+ {
+ clicked_node=i;
+ }
+ }
- for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
- {
- //at the same time only one can be active
- if(nodesmap[i]==active_item)
- {
- clicked_node=i;
- }
- }
- }
- //if it was really an edge...
- if(clicked_node!=INVALID)
- {
- // the id map is not editable
- if (nodemap_to_edit == "id") return 0;
- //If there is already edited edge, it has to be saved first
- if(entrywidget.is_visible())
- {
- GdkEvent * generated=new GdkEvent();
- generated->type=GDK_KEY_PRESS;
- ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
- entryWidgetChangeHandler(generated);
- }
- //If the previous value could be saved, we can go further, otherwise not
- if(!entrywidget.is_visible())
- {
- //and there is activated map
- if(nodetextmap[clicked_node]->property_text().get_value()!="")
- {
- //activate the general variable for it
- active_node=clicked_node;
- //delete visible widget if there is
- if(canvasentrywidget)
- {
- delete(canvasentrywidget);
- }
-
- //initialize the entry
- entrywidget.show();
-
- //fill in the correct value
- entrywidget.set_text(nodetextmap[active_node]->property_text().get_value());
-
- //replace and resize the entry to the activated node and put it in a Canvas::Widget to be able to display it on gdc
- xy<double> entry_coos;
- entry_coos.x=(nodetextmap[active_node])->property_x().get_value();
- entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2;
- entry_coos.y=(nodetextmap[active_node])->property_y().get_value();
- entry_coos.y-=nodetextmap[active_node]->property_text_height().get_value()*1.5/2;
- canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
- canvasentrywidget->property_width().set_value(nodetextmap[active_node]->property_text_width().get_value()*4);
- canvasentrywidget->property_height().set_value(nodetextmap[active_node]->property_text_height().get_value()*1.5);
- }
- }
- }
- //if it was not an edge...
- else
- {
- //In this case the click did not happen on an edge
- //if there is visible entry we save the value in it
- //we pretend like an Enter was presse din the Entry widget
- GdkEvent * generated=new GdkEvent();
- generated->type=GDK_KEY_PRESS;
- ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
- entryWidgetChangeHandler(generated);
- }
- break;
- }
- default:
- break;
- }
- }
- return false;
-}
+ //if there was not, search for it between nodes
+ if(clicked_node==INVALID)
+ {
+ for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
+ {
+ //at the same time only one can be active
+ if(nodesmap[i]==active_item)
+ {
+ clicked_node=i;
+ }
+ }
+ }
-bool GraphDisplayerCanvas::entryWidgetChangeHandler(GdkEvent* e)
-{
- if(entrywidget.is_visible())
- {
- if(e->type==GDK_KEY_PRESS)
- {
- switch(((GdkEventKey*)e)->keyval)
- {
- case GDK_Escape:
- entrywidget.hide();
- break;
- case GDK_KP_Enter:
- case GDK_Return:
- {
- //these variables check whether the text in the entry is valid
- bool valid_double=true;
- int point_num=0;
-
- //getting the value from the entry and converting it to double
- Glib::ustring mapvalue_str = entrywidget.get_text();
-
- char * mapvalue_ch=new char [mapvalue_str.length()];
- for(int i=0;i<(int)(mapvalue_str.length());i++)
- {
- if(((mapvalue_str[i]<'0')||(mapvalue_str[i]>'9'))&&(mapvalue_str[i]!='.'))
- {
- valid_double=false;
- }
- else
- {
- if(mapvalue_str[i]=='.')
- {
- point_num++;
- }
- }
- mapvalue_ch[i]=mapvalue_str[i];
- }
-
- //if the text in the entry was correct
- if((point_num<=1)&&(valid_double))
- {
- double mapvalue_d=atof(mapvalue_ch);
-
- //reconvert the double to string for the correct format
- std::ostringstream ostr;
- ostr << mapvalue_d;
-
- //save the value to the correct place
- switch(actual_tool)
- {
- case EDGE_MAP_EDIT:
- edgetextmap[active_edge]->property_text().set_value(ostr.str());
- (*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d;
- mapwin.updateEdge(active_edge);
- break;
- case NODE_MAP_EDIT:
- nodetextmap[active_node]->property_text().set_value(ostr.str());
- (*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=mapvalue_d;
- mapwin.updateNode(active_node);
- break;
- default:
- break;
- }
- entrywidget.hide();
- }
- //the text in the entry was not correct for a double
- else
- {
- std::cerr << "ERROR: only handling of double values is implemented yet!" << std::endl;
- }
+ //if it was really a node...
+ if(clicked_node!=INVALID)
+ {
+ // the id map is not editable
+ if (nodemap_to_edit == "id") return 0;
- break;
- }
- default:
- break;
- }
- }
+ //and there is activated map
+ if(nodetextmap[clicked_node]->property_text().get_value()!="")
+ {
+ //activate the general variable for it
+ active_node=clicked_node;
+
+ //create a dialog
+ Gtk::Dialog dialog("Edit value", *parentwin, true);
+ dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
+ Gtk::VBox* vbox = dialog.get_vbox();
+ Gtk::Adjustment adj(
+ (*mapstorage.nodemap_storage[nodemap_to_edit])[active_node],
+ -1000000.0,
+ 1000000.0,
+ 1.0, 5.0, 0.0);
+ //TODO: find out why doesn't it work with
+ //numeric_limits<double>::min/max
+ Gtk::SpinButton spin(adj);
+ spin.set_numeric(true);
+ spin.set_digits(4);
+ vbox->add(spin);
+ spin.show();
+ switch (dialog.run())
+ {
+ case Gtk::RESPONSE_NONE:
+ case Gtk::RESPONSE_CANCEL:
+ break;
+ case Gtk::RESPONSE_ACCEPT:
+ double new_value = spin.get_value();
+ (*mapstorage.nodemap_storage[nodemap_to_edit])[active_node] =
+ new_value;
+ std::ostringstream ostr;
+ ostr << new_value;
+ nodetextmap[active_node]->property_text().set_value(
+ ostr.str());
+ //mapwin.updateNode(active_node);
+ mapwin.updateNode(Node(INVALID));
+ }
+ }
+ }
+ break;
+ }
+ default:
+ break;
}
- return false;
+ }
+ return false;
}
void GraphDisplayerCanvas::deleteItem(Node node_to_delete)
Modified: hugo/trunk/gui/graph_displayer_canvas.cc
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.cc (original)
+++ hugo/trunk/gui/graph_displayer_canvas.cc Fri Aug 26 09:35:23 2005
@@ -4,9 +4,9 @@
GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw, Gtk::Window * mainwin) :
nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph),
- nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0),
- canvasentrywidget(NULL), mapstorage(ms), isbutton(0), active_item(NULL),
- target_item(NULL), nodemap_to_edit(""), edgemap_to_edit(""), mapwin(mw)
+ nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0), mapstorage(ms),
+ isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
+ edgemap_to_edit(""), mapwin(mw)
{
parentwin=mainwin;
@@ -14,9 +14,6 @@
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
actual_tool=MOVE;
- //setting event handler for the editor widget
- entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false);
-
active_node=INVALID;
active_edge=INVALID;
forming_edge=INVALID;
@@ -35,11 +32,6 @@
delete edgesmap[e];
delete edgetextmap[e];
}
-
- if(canvasentrywidget)
- {
- delete(canvasentrywidget);
- }
}
void GraphDisplayerCanvas::drawGraph()
Modified: hugo/trunk/gui/graph_displayer_canvas.h
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.h (original)
+++ hugo/trunk/gui/graph_displayer_canvas.h Fri Aug 26 09:35:23 2005
@@ -90,9 +90,6 @@
///event handler for the case when node map editor tool is active
bool nodeMapEditEventHandler(GdkEvent*);
- ///event handler for the case when the entry widget is changed
- bool entryWidgetChangeHandler(GdkEvent*);
-
public:
///Moves the text to new place
void textReposition(xy<double>);
@@ -140,12 +137,6 @@
///Group of graphical elements of displayed_graph
Gnome::Canvas::Group displayed_graph;
- ///Map editor entry
- Gtk::Entry entrywidget;
-
- ///GnomeCanvas holder for entry
- Gnome::Canvas::Widget * canvasentrywidget;
-
///Here we store the maps that can be displayed through properties.
MapStorage & mapstorage;
@@ -175,8 +166,7 @@
///We need to store mapwin, to be able to ask the appropriate values for properties of new items.
MapWin & mapwin;
- ///We need to store the parent window to be able to set the focus on a given widget
- ///We will use this variable to activate the set focus on entry widget in the case of editing map values.
+ ///pointer to the parent window
Gtk::Window * parentwin;
};
Modified: hugo/trunk/gui/map_win.cc
==============================================================================
--- hugo/trunk/gui/map_win.cc (original)
+++ hugo/trunk/gui/map_win.cc Fri Aug 26 09:35:23 2005
@@ -81,7 +81,10 @@
for(;emsi!=ms.endOfNodeMaps();emsi++)
{
- listStrings.push_back(emsi->first);
+ if ((emsi->first != "coordinates_x") && (emsi->first != "coordinates_y"))
+ {
+ listStrings.push_back(emsi->first);
+ }
}
n_combo_array[i].set_popdown_strings(listStrings);
@@ -148,7 +151,10 @@
for(;emsi!=ms.endOfNodeMaps();emsi++)
{
- listStrings.push_back(emsi->first);
+ if ((emsi->first != "coordinates_x") && (emsi->first != "coordinates_y"))
+ {
+ listStrings.push_back(emsi->first);
+ }
}
n_combo_array[i].set_popdown_strings(listStrings);
More information about the Lemon-commits
mailing list