# HG changeset patch # User ladanyi # Date 1122638497 0 # Node ID dc4ea2010dee198167422b9c8461ec6773066d25 # Parent 4fa618f7aa69cbbc38b59b32ee33777db72d2c9e added support for saving files diff -r 4fa618f7aa69 -r dc4ea2010dee gui/Makefile.am --- a/gui/Makefile.am Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/Makefile.am Fri Jul 29 12:01:37 2005 +0000 @@ -25,7 +25,8 @@ broken_edge.cc \ broken_edge.h \ new_map_win.cc \ - new_map_win.h + new_map_win.h \ + xymap.h gd_CXXFLAGS = $(GTK_CFLAGS) gd_LDFLAGS = $(GTK_LIBS) diff -r 4fa618f7aa69 -r dc4ea2010dee gui/broken_edge.cc --- a/gui/broken_edge.cc Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/broken_edge.cc Fri Jul 29 12:01:37 2005 +0000 @@ -1,4 +1,4 @@ -#include +#include "broken_edge.h" #include BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Gnome::Canvas::Points p, GraphDisplayerCanvas & gc) : Line(g), gdc(gc), isbutton(false) diff -r 4fa618f7aa69 -r dc4ea2010dee gui/broken_edge.h --- a/gui/broken_edge.h Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/broken_edge.h Fri Jul 29 12:01:37 2005 +0000 @@ -5,10 +5,10 @@ class BrokenEdge; -#include +#include "all_include.h" #include #include -#include +#include "graph_displayer_canvas.h" #include class BrokenEdge : public Gnome::Canvas::Line diff -r 4fa618f7aa69 -r dc4ea2010dee gui/graph-displayer.cc --- a/gui/graph-displayer.cc Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/graph-displayer.cc Fri Jul 29 12:01:37 2005 +0000 @@ -1,6 +1,6 @@ -#include -#include -#include +#include "all_include.h" +#include "mapstorage.h" +#include "main_win.h" #include #include @@ -37,56 +37,12 @@ node_property_defaults[N_COLOR]=100; node_property_defaults[N_TEXT]=0; - if(argc<2) - { - std::cerr << "USAGE: gd " << std::endl; - return 0; - } - - Coordinates coosvector; - - Graph g; - - CoordinatesMap cm(g); - Graph::EdgeMap cap(g), map1(g), map2(g), map3(g), map4(g); - Graph::NodeMap nodedata (g); - - //we create one object to read x coordinates - //and one to read y coordinate of nodes and write them to cm NodeMap. - XMap xreader (cm); - YMap yreader (cm); - - //reading in graph and its maps - - std::ifstream is(argv[1]); - - GraphReader reader(is, g); - reader.readNodeMap("coordinates_x", xreader); - reader.readNodeMap("coordinates_y", yreader); - reader.readNodeMap("data", nodedata); - reader.readEdgeMap("cap", cap); - reader.readEdgeMap("map1", map1); - reader.readEdgeMap("map2", map2); - reader.readEdgeMap("map3", map3); - reader.readEdgeMap("map4", map4); - reader.run(); - - //initializing MapStorage with the read data - - MapStorage ms(g); - ms.addNodeMap("data",&nodedata); - ms.addEdgeMap("cap",&cap); - ms.addEdgeMap("map1",&map1); - ms.addEdgeMap("map2",&map2); - ms.addEdgeMap("map3",&map3); - ms.addEdgeMap("map4",&map4); - //initializing GUI Gnome::Canvas::init(); Gtk::Main app(argc, argv); - MainWin mainwin("Displayed Graph", g, cm, ms); + MainWin mainwin("Displayed Graph"); app.run(mainwin); return 0; diff -r 4fa618f7aa69 -r dc4ea2010dee gui/graph_displayer_canvas-edge.cc --- a/gui/graph_displayer_canvas-edge.cc Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/graph_displayer_canvas-edge.cc Fri Jul 29 12:01:37 2005 +0000 @@ -1,5 +1,5 @@ -#include -#include +#include "graph_displayer_canvas.h" +#include "broken_edge.h" #include @@ -12,7 +12,7 @@ { min=edge_property_defaults[E_WIDTH]; max=edge_property_defaults[E_WIDTH]; - actual_map=new Graph::EdgeMap(g,edge_property_defaults[E_WIDTH]); + actual_map=new Graph::EdgeMap(mapstorage.graph,edge_property_defaults[E_WIDTH]); } else { @@ -23,7 +23,7 @@ if(edge==INVALID) { - for (EdgeIt i(g); i!=INVALID; ++i) + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) { double v=abs((*actual_map)[i]); int w; @@ -58,7 +58,7 @@ Graph::EdgeMap * actual_map; if(mapname=="Default") { - actual_map=new Graph::EdgeMap(g,edge_property_defaults[E_COLOR]); + actual_map=new Graph::EdgeMap(mapstorage.graph,edge_property_defaults[E_COLOR]); } else { @@ -80,7 +80,7 @@ if(edge==INVALID) { - for (EdgeIt i(g); i!=INVALID; ++i) + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) { double w=(*actual_map)[i]; @@ -125,7 +125,7 @@ if(edge==INVALID) { - for (EdgeIt i(g); i!=INVALID; ++i) + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) { if(mapname!="Default") { diff -r 4fa618f7aa69 -r dc4ea2010dee gui/graph_displayer_canvas-event.cc --- a/gui/graph_displayer_canvas-event.cc Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/graph_displayer_canvas-event.cc Fri Jul 29 12:01:37 2005 +0000 @@ -1,5 +1,5 @@ -#include -#include +#include "graph_displayer_canvas.h" +#include "broken_edge.h" #include @@ -99,7 +99,7 @@ active_item=(get_item_at(clicked_x, clicked_y)); active_node=INVALID; - for (NodeIt i(g); i!=INVALID; ++i) + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) { if(nodesmap[i]==active_item) { @@ -125,6 +125,8 @@ //we only have to do sg. if the mouse button is pressed AND the click was on a node that was found in the set of nodes if(active_node!=INVALID) { + mapstorage.modified = true; + mapstorage.coords.set(active_node, xy(clicked_x, clicked_y)); //new coordinates will be the old values, //because the item will be moved to the //new coordinate therefore the new movement @@ -147,17 +149,17 @@ //all the edges connected to the moved point has to be redrawn EdgeIt ei; - g.firstOut(ei,active_node); + mapstorage.graph.firstOut(ei,active_node); - for(;ei!=INVALID;g.nextOut(ei)) + for(;ei!=INVALID;mapstorage.graph.nextOut(ei)) { Gnome::Canvas::Points coos; double x1, x2, y1, y2; - nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2); + nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2); coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); - nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2); + nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2); coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); if(isbutton==3) @@ -176,16 +178,16 @@ edgetextmap[ei]->property_y().set_value(text_pos.y); } - g.firstIn(ei,active_node); - for(;ei!=INVALID;g.nextIn(ei)) + mapstorage.graph.firstIn(ei,active_node); + for(;ei!=INVALID;mapstorage.graph.nextIn(ei)) { Gnome::Canvas::Points coos; double x1, x2, y1, y2; - nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2); + nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2); coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); - nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2); + nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2); coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); if(isbutton==3) @@ -219,24 +221,33 @@ //std::cout << "double click" << std::endl; break; case GDK_BUTTON_PRESS: + mapstorage.modified = true; + isbutton=1; - active_node=NodeIt(g,g.addNode()); + active_node=NodeIt(mapstorage.graph,mapstorage.graph.addNode()); //initiating values corresponding to new node in maps 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); + mapstorage.coords.set(active_node, xy(clicked_x, clicked_y)); + (*mapstorage.nodemap_storage["id"])[active_node] = + mapstorage.graph.id(active_node); + + 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(); - nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph, clicked_x+node_property_defaults[N_RADIUS]+5, clicked_y+node_property_defaults[N_RADIUS]+5, ""); + nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph, + clicked_x+node_property_defaults[N_RADIUS]+5, + clicked_y+node_property_defaults[N_RADIUS]+5, ""); nodetextmap[active_node]->property_fill_color().set_value("darkblue"); - mapwin->updateNode(active_node); + mapwin.updateNode(active_node); break; @@ -300,7 +311,7 @@ active_item=(get_item_at(clicked_x, clicked_y)); active_node=INVALID; - for (NodeIt i(g); i!=INVALID; ++i) + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) { if(nodesmap[i]==active_item) { @@ -329,7 +340,7 @@ window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); target_item=(get_item_at(clicked_x, clicked_y)); Graph::NodeIt target_node=INVALID; - for (NodeIt i(g); i!=INVALID; ++i) + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) { if(nodesmap[i]==target_item) { @@ -341,13 +352,16 @@ { if(target_node!=active_node) { + mapstorage.modified = true; + *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red"); //creating new edge - active_edge=EdgeIt(g,g.addEdge(active_node, target_node)); + active_edge=EdgeIt(mapstorage.graph,mapstorage.graph.addEdge(active_node, target_node)); //initiating values corresponding to new edge in maps mapstorage.initMapsForEdge(active_edge); + (*mapstorage.edgemap_storage["id"])[active_edge] = mapstorage.graph.id(active_edge); //calculating coordinates of new edge Gnome::Canvas::Points coos; @@ -376,7 +390,7 @@ edgetextmap[active_edge]->property_fill_color().set_value("darkgreen"); //updating its properties - mapwin->updateEdge(active_edge); + mapwin.updateEdge(active_edge); } else { @@ -429,9 +443,8 @@ active_item=(get_item_at(clicked_x, clicked_y)); active_node=INVALID; active_edge=INVALID; - //was it a node? - for (NodeIt i(g); i!=INVALID; ++i) + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) { if(nodesmap[i]==active_item) { @@ -441,7 +454,7 @@ //or was it an edge? if(active_node==INVALID) { - for (EdgeIt i(g); i!=INVALID; ++i) + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) { if(edgesmap[i]==active_item) { @@ -467,19 +480,20 @@ //a node was found if(active_node!=INVALID) { + mapstorage.modified = true; //collecting edges to delete EdgeIt e; std::set edges_to_delete; - g.firstOut(e,active_node); - for(;e!=INVALID;g.nextOut(e)) + mapstorage.graph.firstOut(e,active_node); + for(;e!=INVALID;mapstorage.graph.nextOut(e)) { edges_to_delete.insert(e); } - g.firstIn(e,active_node); - for(;e!=INVALID;g.nextIn(e)) + mapstorage.graph.firstIn(e,active_node); + for(;e!=INVALID;mapstorage.graph.nextIn(e)) { edges_to_delete.insert(e); } @@ -545,7 +559,7 @@ //find the activated item between texts active_item=(get_item_at(e->button.x, e->button.y)); - for (EdgeIt i(g); i!=INVALID; ++i) + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) { if(edgetextmap[i]==active_item) { @@ -559,7 +573,7 @@ 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(g); i!=INVALID; ++i) + 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)) @@ -663,7 +677,7 @@ //find the activated item between texts active_item=(get_item_at(e->button.x, e->button.y)); - for (NodeIt i(g); i!=INVALID; ++i) + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) { //at the same time only one can be active if(nodetextmap[i]==active_item) @@ -678,7 +692,7 @@ window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); active_item=(get_item_at(clicked_x, clicked_y)); - for (NodeIt i(g); i!=INVALID; ++i) + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) { //at the same time only one can be active if(nodesmap[i]==active_item) @@ -803,12 +817,12 @@ 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); + 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); + mapwin.updateNode(active_node); break; default: break; @@ -835,21 +849,21 @@ { delete(nodetextmap[node_to_delete]); delete(nodesmap[node_to_delete]); - g.erase(node_to_delete); + mapstorage.graph.erase(node_to_delete); } void GraphDisplayerCanvas::deleteItem(EdgeIt edge_to_delete) { delete(edgetextmap[edge_to_delete]); delete(edgesmap[edge_to_delete]); - g.erase(edge_to_delete); + mapstorage.graph.erase(edge_to_delete); } void GraphDisplayerCanvas::deleteItem(Graph::Edge edge_to_delete) { delete(edgetextmap[edge_to_delete]); delete(edgesmap[edge_to_delete]); - g.erase(edge_to_delete); + mapstorage.graph.erase(edge_to_delete); } void GraphDisplayerCanvas::textReposition(xy new_place) @@ -869,7 +883,7 @@ } else { - for (EdgeIt i(g); i!=INVALID; ++i) + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) { if(edgesmap[i]==active_bre) { @@ -895,7 +909,7 @@ int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname) { //create the new map - Graph::EdgeMap * emptr=new Graph::EdgeMap (g,default_value); + Graph::EdgeMap * emptr=new Graph::EdgeMap (mapstorage.graph, default_value); //if addition was not successful addEdgeMap returns one. //cause can be that there is already a map named like the new one @@ -906,7 +920,7 @@ //add it to the list of the displayable maps - mapwin->registerNewEdgeMap(mapname); + mapwin.registerNewEdgeMap(mapname); //display it changeEdgeText(mapname); @@ -917,7 +931,7 @@ int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname) { //create the new map - Graph::NodeMap * emptr=new Graph::NodeMap (g,default_value); + Graph::NodeMap * emptr=new Graph::NodeMap (mapstorage.graph,default_value); //if addition was not successful addNodeMap returns one. //cause can be that there is already a map named like the new one @@ -927,7 +941,7 @@ } //add it to the list of the displayable maps - mapwin->registerNewNodeMap(mapname); + mapwin.registerNewNodeMap(mapname); //display it changeNodeText(mapname); diff -r 4fa618f7aa69 -r dc4ea2010dee gui/graph_displayer_canvas-node.cc --- a/gui/graph_displayer_canvas-node.cc Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/graph_displayer_canvas-node.cc Fri Jul 29 12:01:37 2005 +0000 @@ -1,5 +1,5 @@ -#include -#include +#include "graph_displayer_canvas.h" +#include "broken_edge.h" #include @@ -11,7 +11,7 @@ { min=node_property_defaults[N_RADIUS]; max=node_property_defaults[N_RADIUS]; - actual_map=new Graph::NodeMap(g,node_property_defaults[N_RADIUS]); + actual_map=new Graph::NodeMap(mapstorage.graph,node_property_defaults[N_RADIUS]); } else { @@ -22,7 +22,7 @@ if(node==INVALID) { - for (NodeIt i(g); i!=INVALID; ++i) + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) { double v=abs((*actual_map)[i]); int w; @@ -79,7 +79,7 @@ Graph::NodeMap * actual_map; if(mapname=="Default") { - actual_map=new Graph::NodeMap(g,node_property_defaults[N_COLOR]); + actual_map=new Graph::NodeMap(mapstorage.graph,node_property_defaults[N_COLOR]); } else { @@ -103,7 +103,7 @@ if(node==INVALID) { - for (NodeIt i(g); i!=INVALID; ++i) + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) { Gdk::Color color; @@ -157,7 +157,7 @@ if(node==INVALID) { - for (NodeIt i(g); i!=INVALID; ++i) + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) { if(mapname!="Default") { diff -r 4fa618f7aa69 -r dc4ea2010dee gui/graph_displayer_canvas-zoom.cc --- a/gui/graph_displayer_canvas-zoom.cc Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/graph_displayer_canvas-zoom.cc Fri Jul 29 12:01:37 2005 +0000 @@ -1,5 +1,5 @@ -#include -#include +#include "graph_displayer_canvas.h" +#include "broken_edge.h" #include void GraphDisplayerCanvas::zoomIn() diff -r 4fa618f7aa69 -r dc4ea2010dee gui/graph_displayer_canvas.cc --- a/gui/graph_displayer_canvas.cc Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/graph_displayer_canvas.cc Fri Jul 29 12:01:37 2005 +0000 @@ -1,34 +1,61 @@ -#include -#include +#include "graph_displayer_canvas.h" +#include "broken_edge.h" #include -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),nodemap_to_edit(""),edgemap_to_edit(""),mapwin(mw) +GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw) : + 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) { - - //Initializing values. - active_node=INVALID; - active_edge=INVALID; - forming_edge=INVALID; + //base event handler is move tool + 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); - //base event handler is move tool - actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); - actual_tool=MOVE; + active_node=INVALID; + active_edge=INVALID; + forming_edge=INVALID; +} - //set_center_scroll_region(true); +GraphDisplayerCanvas::~GraphDisplayerCanvas() +{ + for (NodeIt n(mapstorage.graph); n != INVALID; ++n) + { + delete nodesmap[n]; + delete nodetextmap[n]; + } + for (EdgeIt e(mapstorage.graph); e != INVALID; ++e) + { + delete edgesmap[e]; + delete edgetextmap[e]; + } + + if(canvasentrywidget) + { + delete(canvasentrywidget); + } +} + +void GraphDisplayerCanvas::drawGraph() +{ //first edges are drawn, to hide joining with nodes later - for (EdgeIt i(g); i!=INVALID; ++i) + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) { - //drawing green lines, coordinates are from cm + //drawing green lines, coordinates are from mapstorage.coords Gnome::Canvas::Points coos; - coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y)); - coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y)); + coos.push_back(Gnome::Art::Point( + mapstorage.coords[mapstorage.graph.source(i)].x, + mapstorage.coords[mapstorage.graph.source(i)].y)); + coos.push_back(Gnome::Art::Point( + mapstorage.coords[mapstorage.graph.target(i)].x, + mapstorage.coords[mapstorage.graph.target(i)].y)); edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this); *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green"); @@ -46,29 +73,27 @@ //afterwards nodes come to be drawn - NodeIt i(g); - int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y; - - for (; i!=INVALID; ++i) + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) { - //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen) - - if(cm[i].x>maxx)maxx=(int)cm[i].x; - if(cm[i].y>maxy)maxy=(int)cm[i].y; - if(cm[i].x text_pos((cm[i].x+node_property_defaults[N_RADIUS]+5),(cm[i].y+node_property_defaults[N_RADIUS]+5)); + xy text_pos( + (mapstorage.coords[i].x+node_property_defaults[N_RADIUS]+5), + (mapstorage.coords[i].y+node_property_defaults[N_RADIUS]+5)); - nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, ""); + nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, + text_pos.x, text_pos.y, ""); nodetextmap[i]->property_fill_color().set_value("darkblue"); nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false); } @@ -76,36 +101,21 @@ updateScrollRegion(); } -GraphDisplayerCanvas::~GraphDisplayerCanvas() +void GraphDisplayerCanvas::clear() { - if(canvasentrywidget) - { - delete(canvasentrywidget); - } + active_node=INVALID; + active_edge=INVALID; + forming_edge=INVALID; - //writing out the end state of the graph - //\todo all the maps has to be write out! - - Graph::NodeMap id(g); - Graph::NodeMap xc(g); - Graph::NodeMap yc(g); - - int j=1; - - for (NodeIt i(g); i!=INVALID; ++i) + for (NodeIt n(mapstorage.graph); n != INVALID; ++n) { - double x1,y1,x2,y2; - nodesmap[i]->get_bounds(x1, y1, x2, y2); - - id[i]=j++; - xc[i]=(x1+x2)/2; - yc[i]=(y1+y2)/2; + delete nodesmap[n]; + delete nodetextmap[n]; } - GraphWriter writer(std::cout,g); - - writer.writeNodeMap("id", id); - writer.writeNodeMap("coordinates_x", xc); - writer.writeNodeMap("coordinates_y", yc); - writer.run(); + for (EdgeIt e(mapstorage.graph); e != INVALID; ++e) + { + delete edgesmap[e]; + delete edgetextmap[e]; + } } diff -r 4fa618f7aa69 -r dc4ea2010dee gui/graph_displayer_canvas.h --- a/gui/graph_displayer_canvas.h Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/graph_displayer_canvas.h Fri Jul 29 12:01:37 2005 +0000 @@ -5,10 +5,10 @@ class GraphDisplayerCanvas; -#include -#include -#include -#include +#include "all_include.h" +#include "mapstorage.h" +#include "broken_edge.h" +#include "map_win.h" #include #include @@ -18,7 +18,7 @@ typedef Gnome::Canvas::CanvasAA Parent; public: - GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &, MapWin *); + GraphDisplayerCanvas(MapStorage &, MapWin &); virtual ~GraphDisplayerCanvas(); ///Changes the linewidth attribute according to the given map. @@ -109,6 +109,9 @@ ///\return the actual tool in hand int getActualTool(); + void drawGraph(); + void clear(); + ///creates a new Nodemap int addNewNodeMap(double,std::string); ///creates a new Edgemap @@ -124,9 +127,6 @@ private: - ///The graph, on which we work - Graph & g; - ///Map of nodes of graph Graph::NodeMap nodesmap; @@ -175,7 +175,7 @@ static const int zoom_step = 5; ///We need to store mapwin, to be able to ask the appropriate values for properties of new items. - MapWin * mapwin; + MapWin & mapwin; }; diff -r 4fa618f7aa69 -r dc4ea2010dee gui/main_win.cc --- a/gui/main_win.cc Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/main_win.cc Fri Jul 29 12:01:37 2005 +0000 @@ -1,7 +1,8 @@ -#include +#include "main_win.h" -MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm, - MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),newmapwin("Creating new map",gd_canvas),gd_canvas(graph, cm, ms, &mapwin) +MainWin::MainWin(const std::string& title) : + mapwin("Map Setup", mapstorage, gd_canvas), + newmapwin("Creating new map", gd_canvas), gd_canvas(mapstorage, mapwin) { set_title (title); @@ -19,7 +20,9 @@ sigc::mem_fun(*this, &MainWin::saveFile)); ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS), sigc::mem_fun(*this, &MainWin::saveFileAs)); - ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), + ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE), + sigc::mem_fun(*this, &MainWin::close)); + ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT), sigc::mem_fun(*this, &MainWin::hide)); ag->add( Gtk::Action::create("ViewMenu", "_View") ); @@ -36,14 +39,15 @@ ag->add( Gtk::Action::create("ShowMaps", "_Maps"), sigc::mem_fun(this->mapwin, &MapWin::show)); - ag->add( Gtk::Action::create("CreateNode", Gtk::Stock::NO), + Gtk::RadioAction::Group tool_group; + ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::Stock::CONVERT, "Move"), + sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) ); + ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::Stock::NO, "Create node"), sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) ); - ag->add( Gtk::Action::create("CreateEdge", Gtk::Stock::REMOVE), + ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::Stock::REMOVE, "Create edge"), sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) ); - ag->add( Gtk::Action::create("EraseItem", Gtk::Stock::DELETE), + ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::Stock::DELETE, "Delete"), sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) ); - ag->add( Gtk::Action::create("MoveItem", Gtk::Stock::CONVERT), - sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) ); ag->add( Gtk::Action::create("EditEdgeMap", Gtk::Stock::PROPERTIES), sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 4) ); ag->add( Gtk::Action::create("EditNodeMap", Gtk::Stock::PREFERENCES), @@ -66,7 +70,8 @@ " " " " " " - " " + " " + " " " " " " " " @@ -82,16 +87,17 @@ " " " " " " + " " " " " " " " " " " " " " + " " " " " " " " - " " " " " " " " @@ -130,20 +136,115 @@ void MainWin::newFile() { - std::cerr << "MainWin::newFile(): not yet implemented" << std::endl; + if (mapstorage.modified) + { + Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING, + Gtk::BUTTONS_NONE); + mdialog.set_message("Save changes before closing?", true); + mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); + mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); + switch (mdialog.run()) + { + case Gtk::RESPONSE_CANCEL: + return; + case Gtk::RESPONSE_REJECT: + break; + case Gtk::RESPONSE_ACCEPT: + saveFile(); + break; + } + } + gd_canvas.clear(); + mapstorage.clear(); + mapwin.update(); } void MainWin::openFile() { - std::cerr << "MainWin::openFile(): not yet implemented" << std::endl; + if (mapstorage.modified) + { + Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING, + Gtk::BUTTONS_NONE); + mdialog.set_message("Save changes before closing?", true); + mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); + mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); + switch (mdialog.run()) + { + case Gtk::RESPONSE_CANCEL: + return; + case Gtk::RESPONSE_REJECT: + break; + case Gtk::RESPONSE_ACCEPT: + saveFile(); + break; + } + } + gd_canvas.clear(); + mapstorage.clear(); + Gtk::FileChooserDialog fcdialog("Open File"); + fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT); + if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) + { + Glib::ustring filename = fcdialog.get_filename(); + mapstorage.readFromFile(filename); + mapstorage.file_name = filename; + mapstorage.modified = false; + gd_canvas.drawGraph(); + mapwin.update(); + } } void MainWin::saveFile() { - std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl; + if (mapstorage.file_name == "") { + saveFileAs(); + } + else + { + mapstorage.writeToFile(mapstorage.file_name); + mapstorage.modified = false; + } } void MainWin::saveFileAs() { - std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl; + Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE); + fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); + if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) + { + Glib::ustring filename = fcdialog.get_filename(); + mapstorage.file_name = filename; + mapstorage.writeToFile(filename); + mapstorage.modified = false; + } } + +void MainWin::close() +{ + if (mapstorage.modified) + { + Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING, + Gtk::BUTTONS_NONE); + mdialog.set_message("Save changes before closing?", true); + mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); + mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); + switch (mdialog.run()) + { + case Gtk::RESPONSE_CANCEL: + return; + case Gtk::RESPONSE_REJECT: + break; + case Gtk::RESPONSE_ACCEPT: + saveFile(); + break; + } + } + gd_canvas.clear(); + mapstorage.clear(); + mapwin.update(); +} diff -r 4fa618f7aa69 -r dc4ea2010dee gui/main_win.h --- a/gui/main_win.h Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/main_win.h Fri Jul 29 12:01:37 2005 +0000 @@ -3,10 +3,12 @@ #ifndef MAIN_WIN_H #define MAIN_WIN_H -#include -#include -#include -#include +#include "all_include.h" +#include "mapstorage.h" +#include "map_win.h" +#include "new_map_win.h" +#include "edit_win.h" +#include "graph_displayer_canvas.h" #include #include @@ -17,10 +19,9 @@ public: ///Constructor of the \ref MainWin. It creates the menu and the \ref GraphDisplayerCanvas on which the graph will be drawn. ///\param title is the title of the window - ///\param graph is the graph that will be drawn here. It will be given further to the \ref GraphDisplayerCanvas - ///\param cm stores the coordinates of the nodes of the graph - ///\param ms is the \ref MapStorage in which the different visualizable maps are stored - MainWin(const std::string& title, Graph &, CoordinatesMap &, MapStorage &); + MainWin(const std::string& title); + + MapStorage mapstorage; protected: ///Window of map-showing setup. Its type is \ref MapWin @@ -52,6 +53,8 @@ virtual void saveFile(); ///Callback for 'FileSaveAs' action. virtual void saveFileAs(); + ///Callback for 'Close' action. + virtual void close(); }; #endif //MAIN_WIN_H diff -r 4fa618f7aa69 -r dc4ea2010dee gui/map_win.cc --- a/gui/map_win.cc Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/map_win.cc Fri Jul 29 12:01:37 2005 +0000 @@ -1,4 +1,4 @@ -#include +#include "map_win.h" #include bool MapWin::closeIfEscapeIsPressed(GdkEventKey* e) @@ -120,6 +120,41 @@ } +void MapWin::update() +{ + for(int i=0;i listStrings; + + listStrings.push_back("Default"); + + std::map< std::string,Graph::EdgeMap * >::iterator emsi=ms.beginOfEdgeMaps(); + for(;emsi!=ms.endOfEdgeMaps();emsi++) + { + listStrings.push_back(emsi->first); + } + + e_combo_array[i].set_popdown_strings(listStrings); + } + for(int i=0;i listStrings; + + listStrings.push_back("Default"); + + std::map< std::string,Graph::NodeMap * >::iterator emsi=ms.beginOfNodeMaps(); + + for(;emsi!=ms.endOfNodeMaps();emsi++) + { + listStrings.push_back(emsi->first); + } + + n_combo_array[i].set_popdown_strings(listStrings); + } +} + void MapWin::eComboChanged(int prop) { diff -r 4fa618f7aa69 -r dc4ea2010dee gui/map_win.h --- a/gui/map_win.h Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/map_win.h Fri Jul 29 12:01:37 2005 +0000 @@ -5,9 +5,9 @@ class MapWin; -#include -#include -#include +#include "all_include.h" +#include "graph_displayer_canvas.h" +#include "mapstorage.h" #include #include @@ -63,6 +63,7 @@ virtual bool closeIfEscapeIsPressed(GdkEventKey*); + void update(); }; #endif //MAP_WIN_H diff -r 4fa618f7aa69 -r dc4ea2010dee gui/mapstorage.cc --- a/gui/mapstorage.cc Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/mapstorage.cc Fri Jul 29 12:01:37 2005 +0000 @@ -1,8 +1,29 @@ -#include +#include "mapstorage.h" -MapStorage::MapStorage(Graph & graph):g(graph) +MapStorage::MapStorage() : modified(false), file_name("") { -}; + nodemap_storage["coordinates_x"] = new Graph::NodeMap(graph); + coords.setXMap(*nodemap_storage["coordinates_x"]); + nodemap_storage["coordinates_y"] = new Graph::NodeMap(graph); + coords.setYMap(*nodemap_storage["coordinates_y"]); + + nodemap_storage["id"] = new Graph::NodeMap(graph); + edgemap_storage["id"] = new Graph::EdgeMap(graph); +} + +MapStorage::~MapStorage() +{ + for (std::map*>::const_iterator it = + nodemap_storage.begin(); it != nodemap_storage.end(); ++it) + { + delete it->second; + } + for (std::map*>::const_iterator it = + edgemap_storage.begin(); it != edgemap_storage.end(); ++it) + { + delete it->second; + } +} int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap *nodemap) { @@ -27,7 +48,7 @@ double MapStorage::maxOfNodeMap(const std::string & name) { double max=0; - for (NodeIt j(g); j!=INVALID; ++j) + for (NodeIt j(graph); j!=INVALID; ++j) { if( (*nodemap_storage[name])[j]>max ) { @@ -40,7 +61,7 @@ double MapStorage::maxOfEdgeMap(const std::string & name) { double max=0; - for (EdgeIt j(g); j!=INVALID; ++j) + for (EdgeIt j(graph); j!=INVALID; ++j) { if( (*edgemap_storage[name])[j]>max ) { @@ -52,7 +73,7 @@ double MapStorage::minOfNodeMap(const std::string & name) { - NodeIt j(g); + NodeIt j(graph); double min=(*nodemap_storage[name])[j]; for (; j!=INVALID; ++j) { @@ -66,9 +87,9 @@ double MapStorage::minOfEdgeMap(const std::string & name) { - EdgeIt j(g); + EdgeIt j(graph); double min=(*edgemap_storage[name])[j]; - for (EdgeIt j(g); j!=INVALID; ++j) + for (EdgeIt j(graph); j!=INVALID; ++j) { if( (*edgemap_storage[name])[j]& nodeMapNames = content.nodeSetMaps(0); + const std::vector& edgeMapNames = content.edgeSetMaps(0); + + GraphReader greader(filename, graph); + for (std::vector::const_iterator it = nodeMapNames.begin(); + it != nodeMapNames.end(); ++it) + { + if (*it == "coordinates_x") + { + read_x = true; + //std::cout << "read X nodemap" << std::endl; + } + else if (*it == "coordinates_y") + { + read_y = true; + //std::cout << "read Y nodemap" << std::endl; + } + else if (*it == "id") + { + //std::cout << "read id nodemap" << std::endl; + } + else + { + nodemap_storage[*it] = new Graph::NodeMap(graph); + //std::cout << "read " << *it << " nodemap" << std::endl; + } + greader.readNodeMap(*it, *nodemap_storage[*it]); + } + for (std::vector::const_iterator it = edgeMapNames.begin(); + it != edgeMapNames.end(); ++it) + { + if (*it == "id") + { + //std::cout << "read id edgemap" << std::endl; + } + else + { + edgemap_storage[*it] = new Graph::EdgeMap(graph); + //std::cout << "read " << *it << " edgemap" << std::endl; + } + greader.readEdgeMap(*it, *edgemap_storage[*it]); + } + greader.run(); + } catch (DataFormatError& error) { + /* + Gtk::MessageDialog mdialog("Read Error"); + mdialog.set_message(error.what()); + mdialog.run(); + */ + // reset graph and mapstorage ? + return; + } + + if (!read_x || !read_y) + { + int node_num = 0; + for (NodeIt n(graph); n != INVALID; ++n) + { + node_num++; + } + const double pi = 3.142; + double step = 2 * pi / (double) node_num; + int i = 0; + for (NodeIt n(graph); n != INVALID; ++n) + { + nodemap_storage["coordinates_x"]->set(n, 250.0 * cos(i * step)); + nodemap_storage["coordinates_y"]->set(n, 250.0 * sin(i * step)); + i++; + } + } +} + +void MapStorage::writeToFile(const std::string &filename) +{ + GraphWriter gwriter(filename, graph); + + for (std::map*>::const_iterator it = + nodemap_storage.begin(); it != nodemap_storage.end(); ++it) + { + gwriter.writeNodeMap(it->first, *(it->second)); + //std::cout << "wrote " << it->first << " nodemap" << std::endl; + } + for (std::map*>::const_iterator it = + edgemap_storage.begin(); it != edgemap_storage.end(); ++it) + { + gwriter.writeEdgeMap(it->first, *(it->second)); + //std::cout << "wrote " << it->first << " edgemap" << std::endl; + } + gwriter.run(); +} + +void MapStorage::clear() +{ + for (std::map*>::iterator it = + nodemap_storage.begin(); it != nodemap_storage.end(); ++it) + { + if ((it->first != "coordinates_x") && + (it->first != "coordinates_y") && + (it->first != "id")) + { + delete it->second; + nodemap_storage.erase(it); + } + } + for (std::map*>::iterator it = + edgemap_storage.begin(); it != edgemap_storage.end(); ++it) + { + if (it->first != "id") + { + delete it->second; + edgemap_storage.erase(it); + } + } + graph.clear(); + file_name = ""; + modified = false; +} diff -r 4fa618f7aa69 -r dc4ea2010dee gui/mapstorage.h --- a/gui/mapstorage.h Thu Jul 28 19:09:39 2005 +0000 +++ b/gui/mapstorage.h Fri Jul 29 12:01:37 2005 +0000 @@ -3,7 +3,8 @@ #ifndef MAPSTORAGE_H #define MAPSTORAGE_H -#include +#include "all_include.h" +#include "xymap.h" ///Class MapStorage is responsible for storing ///NodeMaps and EdgeMaps that can be shown later @@ -18,7 +19,11 @@ { public: - Graph &g; + Graph graph; + XYMap > coords; + + bool modified; + std::string file_name; ///Stores double type NodeMaps std::map< std::string,Graph::NodeMap * > nodemap_storage; @@ -39,7 +44,9 @@ ///for different visualization attributes /// ///\param graph is the graph for which the maps are stored in this object. - MapStorage(Graph &); + MapStorage(); + + ~MapStorage(); ///Adds given map to storage. A name and the map itself has to be provided. ///\param name is the name of map @@ -92,6 +99,11 @@ ///This function sets a default base value for the newly created node void initMapsForEdge(Graph::Edge); + + void readFromFile(const std::string &); + void writeToFile(const std::string &); + + void clear(); }; #endif //MAPSTORAGE_H diff -r 4fa618f7aa69 -r dc4ea2010dee gui/xymap.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gui/xymap.h Fri Jul 29 12:01:37 2005 +0000 @@ -0,0 +1,35 @@ +#ifndef XYMAP_H +#define XYMAP_H + +#include +#include + +using lemon::ListGraph; +using lemon::xy; + +template +class XYMap +{ + private: + M *xmap, *ymap; + + public: + typedef typename M::Key Key; + typedef xy Value; + XYMap() {} + XYMap(M &_xmap, M &_ymap) : xmap(&_xmap), ymap(&_ymap) {} + void setXMap(M &_xmap) { xmap = &_xmap; } + void setYMap(M &_ymap) { ymap = &_ymap; } + Value operator[](Key k) const + { + Value v(xmap->operator[](k), ymap->operator[](k)); + return v; + } + void set(Key k, Value v) + { + xmap->set(k, v.x); + ymap->set(k, v.y); + } +}; + +#endif