[Lemon-commits] [lemon_svn] hegyi: r1948 - hugo/trunk/gui
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:49:00 CET 2006
Author: hegyi
Date: Fri Jun 10 13:58:03 2005
New Revision: 1948
Modified:
hugo/trunk/gui/Makefile.am
hugo/trunk/gui/all_include.h
hugo/trunk/gui/graph_displayer_canvas.cc
hugo/trunk/gui/graph_displayer_canvas.h
hugo/trunk/gui/main_win.cc
hugo/trunk/gui/main_win.h
Log:
Hopefully, node creation works well, after a small structural consideration.
Modified: hugo/trunk/gui/Makefile.am
==============================================================================
--- hugo/trunk/gui/Makefile.am (original)
+++ hugo/trunk/gui/Makefile.am Fri Jun 10 13:58:03 2005
@@ -13,7 +13,9 @@
mapstorage.cc \
mapstorage.h \
map_win.cc \
- map_win.h
+ map_win.h \
+ edit_win.cc \
+ edit_win.h
gd_CXXFLAGS = $(GTK_CFLAGS)
gd_LDFLAGS = $(GTK_LIBS)
Modified: hugo/trunk/gui/all_include.h
==============================================================================
--- hugo/trunk/gui/all_include.h (original)
+++ hugo/trunk/gui/all_include.h Fri Jun 10 13:58:03 2005
@@ -16,7 +16,8 @@
#include <lemon/error.h>
#include <lemon/xy.h>
-enum {WIDTH, COLOR, TEXT, PROPERTY_NUM};// properties;
+enum {WIDTH, COLOR, TEXT, PROPERTY_NUM}; // edge properties;
+enum {MOVE, CREATE_NODE, CREATE_EDGE, TOOL_NUM}; // tools;
#define RANGE 3
#define WIN_WIDTH 900
#define WIN_HEIGHT 600
Modified: hugo/trunk/gui/graph_displayer_canvas.cc
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.cc (original)
+++ hugo/trunk/gui/graph_displayer_canvas.cc Fri Jun 10 13:58:03 2005
@@ -3,6 +3,12 @@
GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(false),active_item(NULL)
{
+ Gnome::Canvas::Ellipse * origo=new Gnome::Canvas::Ellipse(displayed_graph, 0-20, 0-20, 0+20, 0+20);
+ *origo << Gnome::Canvas::Properties::fill_color("black");
+ *origo << Gnome::Canvas::Properties::outline_color("black");
+
+ actual_handler=/*displayed_graph.*/signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
+
//set_center_scroll_region(true);
//first edges are drawn, to hide joining with nodes later
@@ -48,20 +54,9 @@
nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
*(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
*(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
- (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
+ //!!!!!!! (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
}
-/*
- //setting zoom to be able to see the whole graph on the canvas
-
- double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
- double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
-
- set_pixels_per_unit((biggest_x>biggest_y)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
- std::cout<<abs(maxx)<<" "<<abs(minx)<<" big x "<<biggest_x<<" "<<abs(maxy)<<" "<<abs(miny)<<" big y "<<biggest_y<<std::endl;
- std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl;
- std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl;
-*/
updateScrollRegion();
}
@@ -308,3 +303,162 @@
pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
set_scroll_region(wx1, wy1, wx2, wy2);
}
+
+void GraphDisplayerCanvas::changeEditorialTool(int newtool)
+{
+ actual_handler.disconnect();
+
+ switch(newtool)
+ {
+ case MOVE:
+ actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::move_event_handler), false);
+ break;
+ case CREATE_NODE:
+ actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
+ break;
+ case CREATE_EDGE:
+ actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false);
+ break;
+ default:
+ break;
+ }
+}
+
+bool GraphDisplayerCanvas::move_event_handler(GdkEvent* e)
+{
+ switch(e->type)
+ {
+ case GDK_BUTTON_PRESS:
+ //we mark the location of the event to be able to calculate parameters of dragging
+ clicked_x=e->button.x;
+ clicked_y=e->button.y;
+ active_item=(get_item_at(e->button.x, e->button.y));
+ active_node=INVALID;
+ for (NodeIt i(g); i!=INVALID; ++i)
+ {
+ if(nodesmap[i]==active_item)
+ {
+ active_node=i;
+ }
+ }
+ isbutton=true;
+ break;
+ case GDK_BUTTON_RELEASE:
+ isbutton=false;
+ active_item=NULL;
+ updateScrollRegion();
+ break;
+ case GDK_MOTION_NOTIFY:
+ //we only have to do sg. if the mouse button is pressed
+ if(isbutton)
+ {
+ //new coordinates will be the old values,
+ //because the item will be moved to the
+ //new coordinate therefore the new movement
+ //has to be calculated from here
+
+ double dx=e->motion.x-clicked_x;
+ double dy=e->motion.y-clicked_y;
+
+ active_item->move(dx, dy);
+
+ clicked_x=e->motion.x;
+ clicked_y=e->motion.y;
+
+ //all the edges connected to the moved point has to be redrawn
+
+ EdgeIt e;
+
+ g.firstOut(e,active_node);
+
+ for(;e!=INVALID;g.nextOut(e))
+ {
+ Gnome::Canvas::Points coos;
+ double x1, x2, y1, y2;
+
+ nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
+ coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
+
+ nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
+ coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
+
+ edgesmap[e]->property_points().set_value(coos);
+
+ edgesmap[e]->get_bounds(x1, y1, x2, y2);
+
+ edgetextmap[e]->property_x().set_value((x1+x2)/2);
+ edgetextmap[e]->property_y().set_value((y1+y2)/2);
+ }
+
+ g.firstIn(e,active_node);
+ for(;e!=INVALID;g.nextIn(e))
+ {
+ Gnome::Canvas::Points coos;
+ double x1, x2, y1, y2;
+
+ nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
+ coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
+
+ nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
+ coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
+
+ edgesmap[e]->property_points().set_value(coos);
+
+ edgesmap[e]->get_bounds(x1, y1, x2, y2);
+
+ edgetextmap[e]->property_x().set_value((x1+x2)/2);
+ edgetextmap[e]->property_y().set_value((y1+y2)/2);
+ }
+ }
+ default: break;
+ }
+
+ return true;
+}
+
+bool GraphDisplayerCanvas::create_node_event_handler(GdkEvent* e)
+{
+ switch(e->type)
+ {
+ case GDK_BUTTON_PRESS:
+ isbutton=true;
+
+ active_node=NodeIt(g,g.addNode());
+
+ window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
+
+ nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
+ active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
+ *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
+ *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
+ (nodesmap[active_node])->show();
+ break;
+ case GDK_MOTION_NOTIFY:
+ {
+ double world_motion_x, world_motion_y;
+ GdkEvent * generated=new GdkEvent();
+ window_to_world (e->motion.x, e->motion.y, world_motion_x, world_motion_y);
+ generated->motion.x=world_motion_x;
+ generated->motion.y=world_motion_y;
+ generated->type=GDK_MOTION_NOTIFY;
+ move_event_handler(generated);
+ break;
+ }
+ case GDK_BUTTON_RELEASE:
+ isbutton=false;
+ *active_item << Gnome::Canvas::Properties::fill_color("blue");
+ active_item=NULL;
+ updateScrollRegion();
+ break;
+ default:
+ break;
+ }
+ return false;
+}
+
+bool GraphDisplayerCanvas::create_edge_event_handler(GdkEvent* e)
+{
+ e=e;
+ return false;
+}
+
Modified: hugo/trunk/gui/graph_displayer_canvas.h
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.h (original)
+++ hugo/trunk/gui/graph_displayer_canvas.h Fri Jun 10 13:58:03 2005
@@ -40,6 +40,9 @@
///Sets the scroll region of the convas to the bounding box of the graph.
void updateScrollRegion();
+ ///This function changes the tool in the graph-editor's hand
+ void changeEditorialTool(int);
+
protected:
//maximizing, minimizing, restoring window, etc.
@@ -52,6 +55,18 @@
///of the canvas
bool event_handler(GdkEvent* e, Node n);
+ ///actual event handler
+ ///
+ ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
+ sigc::connection actual_handler;
+
+ ///event handler for the case when move-tool is active
+ bool move_event_handler(GdkEvent*);
+ ///event handler for the case when create_node-tool is active
+ bool create_node_event_handler(GdkEvent*);
+ ///event handler for the case when create_edge-tool is active
+ bool create_edge_event_handler(GdkEvent*);
+
///The graph, on which we work
Graph g;
@@ -82,6 +97,7 @@
///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
Gnome::Canvas::Item * active_item;
+ Graph::NodeIt active_node;
static const int zoom_step = 5;
};
Modified: hugo/trunk/gui/main_win.cc
==============================================================================
--- hugo/trunk/gui/main_win.cc (original)
+++ hugo/trunk/gui/main_win.cc Fri Jun 10 13:58:03 2005
@@ -1,7 +1,7 @@
#include <main_win.h>
MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
- MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms)
+ MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),editwin("Editorial Window", gd_canvas),gd_canvas(graph, cm, ms)
{
set_title (title);
set_default_size(WIN_WIDTH,WIN_HEIGHT);
@@ -34,6 +34,8 @@
ag->add( Gtk::Action::create("ShowMenu", "_Show") );
ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
sigc::mem_fun(*this, &MainWin::showMaps));
+ ag->add( Gtk::Action::create("ShowEditorials", "_Editorials"),
+ sigc::mem_fun(*this, &MainWin::showEditorials));
uim=Gtk::UIManager::create();
uim->insert_action_group(ag);
@@ -60,6 +62,7 @@
" </menu>"
" <menu action='ShowMenu'>"
" <menuitem action='ShowMaps'/>"
+ " <menuitem action='ShowEditorials'/>"
" </menu>"
" </menubar>"
" <toolbar name='ToolBar'>"
@@ -107,6 +110,11 @@
mapwin.show();
}
+void MainWin::showEditorials()
+{
+ editwin.show();
+}
+
void MainWin::quit()
{
hide();
Modified: hugo/trunk/gui/main_win.h
==============================================================================
--- hugo/trunk/gui/main_win.h (original)
+++ hugo/trunk/gui/main_win.h Fri Jun 10 13:58:03 2005
@@ -6,6 +6,7 @@
#include <all_include.h>
#include <mapstorage.h>
#include <map_win.h>
+#include <edit_win.h>
#include <libgnomecanvasmm.h>
#include <libgnomecanvasmm/polygon.h>
@@ -25,6 +26,9 @@
///Window of map-showing setup. Its type is \ref MapWin
MapWin mapwin;
+ ///Window of editorial tools. Its type is \ref EditWin
+ EditWin editwin;
+
///The graph will be drawn on this \ref GraphDisplayerCanvas
GraphDisplayerCanvas gd_canvas;
@@ -39,6 +43,8 @@
///This function makes map-setup window popped up.
virtual void showMaps();
+ ///This function makes editorial window popped up.
+ virtual void showEditorials();
///Callback for 'FileNew' action.
virtual void newFile();
///Callback for 'FileOpen' action.
More information about the Lemon-commits
mailing list