Changeset 53:e73d7540bd24 in glemon-0.x
- Timestamp:
- 07/29/05 14:01:37 (19 years ago)
- Branch:
- gui
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk/gui@2111
- Files:
-
- 1 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile.am
r52 r53 26 26 broken_edge.h \ 27 27 new_map_win.cc \ 28 new_map_win.h 28 new_map_win.h \ 29 xymap.h 29 30 30 31 gd_CXXFLAGS = $(GTK_CFLAGS) -
broken_edge.cc
r51 r53 1 #include <broken_edge.h>1 #include "broken_edge.h" 2 2 #include <math.h> 3 3 -
broken_edge.h
r30 r53 6 6 class BrokenEdge; 7 7 8 #include <all_include.h>8 #include "all_include.h" 9 9 #include <libgnomecanvasmm.h> 10 10 #include <libgnomecanvasmm/polygon.h> 11 #include <graph_displayer_canvas.h>11 #include "graph_displayer_canvas.h" 12 12 #include <lemon/xy.h> 13 13 -
graph-displayer.cc
r28 r53 1 #include <all_include.h>2 #include <mapstorage.h>3 #include <main_win.h>1 #include "all_include.h" 2 #include "mapstorage.h" 3 #include "main_win.h" 4 4 #include <libgnomecanvasmm.h> 5 5 #include <libgnomecanvasmm/polygon.h> … … 38 38 node_property_defaults[N_TEXT]=0; 39 39 40 if(argc<2)41 {42 std::cerr << "USAGE: gd <input filename.lgf>" << std::endl;43 return 0;44 }45 46 Coordinates coosvector;47 48 Graph g;49 50 CoordinatesMap cm(g);51 Graph::EdgeMap<double> cap(g), map1(g), map2(g), map3(g), map4(g);52 Graph::NodeMap<double> nodedata (g);53 54 //we create one object to read x coordinates55 //and one to read y coordinate of nodes and write them to cm NodeMap.56 XMap <CoordinatesMap> xreader (cm);57 YMap <CoordinatesMap> yreader (cm);58 59 //reading in graph and its maps60 61 std::ifstream is(argv[1]);62 63 GraphReader<Graph> reader(is, g);64 reader.readNodeMap("coordinates_x", xreader);65 reader.readNodeMap("coordinates_y", yreader);66 reader.readNodeMap("data", nodedata);67 reader.readEdgeMap("cap", cap);68 reader.readEdgeMap("map1", map1);69 reader.readEdgeMap("map2", map2);70 reader.readEdgeMap("map3", map3);71 reader.readEdgeMap("map4", map4);72 reader.run();73 74 //initializing MapStorage with the read data75 76 MapStorage ms(g);77 ms.addNodeMap("data",&nodedata);78 ms.addEdgeMap("cap",&cap);79 ms.addEdgeMap("map1",&map1);80 ms.addEdgeMap("map2",&map2);81 ms.addEdgeMap("map3",&map3);82 ms.addEdgeMap("map4",&map4);83 84 40 //initializing GUI 85 41 … … 87 43 Gtk::Main app(argc, argv); 88 44 89 MainWin mainwin("Displayed Graph" , g, cm, ms);45 MainWin mainwin("Displayed Graph"); 90 46 app.run(mainwin); 91 47 -
graph_displayer_canvas-edge.cc
r48 r53 1 #include <graph_displayer_canvas.h>2 #include <broken_edge.h>1 #include "graph_displayer_canvas.h" 2 #include "broken_edge.h" 3 3 #include <math.h> 4 4 … … 13 13 min=edge_property_defaults[E_WIDTH]; 14 14 max=edge_property_defaults[E_WIDTH]; 15 actual_map=new Graph::EdgeMap<double>( g,edge_property_defaults[E_WIDTH]);15 actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_WIDTH]); 16 16 } 17 17 else … … 24 24 if(edge==INVALID) 25 25 { 26 for (EdgeIt i( g); i!=INVALID; ++i)26 for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) 27 27 { 28 28 double v=abs((*actual_map)[i]); … … 59 59 if(mapname=="Default") 60 60 { 61 actual_map=new Graph::EdgeMap<double>( g,edge_property_defaults[E_COLOR]);61 actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_COLOR]); 62 62 } 63 63 else … … 81 81 if(edge==INVALID) 82 82 { 83 for (EdgeIt i( g); i!=INVALID; ++i)83 for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) 84 84 { 85 85 double w=(*actual_map)[i]; … … 126 126 if(edge==INVALID) 127 127 { 128 for (EdgeIt i( g); i!=INVALID; ++i)128 for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) 129 129 { 130 130 if(mapname!="Default") -
graph_displayer_canvas-event.cc
r48 r53 1 #include <graph_displayer_canvas.h>2 #include <broken_edge.h>1 #include "graph_displayer_canvas.h" 2 #include "broken_edge.h" 3 3 #include <math.h> 4 4 … … 100 100 active_item=(get_item_at(clicked_x, clicked_y)); 101 101 active_node=INVALID; 102 for (NodeIt i( g); i!=INVALID; ++i)102 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 103 103 { 104 104 if(nodesmap[i]==active_item) … … 126 126 if(active_node!=INVALID) 127 127 { 128 mapstorage.modified = true; 129 mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y)); 128 130 //new coordinates will be the old values, 129 131 //because the item will be moved to the … … 148 150 EdgeIt ei; 149 151 150 g.firstOut(ei,active_node);151 152 for(;ei!=INVALID; g.nextOut(ei))152 mapstorage.graph.firstOut(ei,active_node); 153 154 for(;ei!=INVALID;mapstorage.graph.nextOut(ei)) 153 155 { 154 156 Gnome::Canvas::Points coos; 155 157 double x1, x2, y1, y2; 156 158 157 nodesmap[ g.source(ei)]->get_bounds(x1, y1, x2, y2);159 nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2); 158 160 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 159 161 160 nodesmap[ g.target(ei)]->get_bounds(x1, y1, x2, y2);162 nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2); 161 163 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 162 164 … … 177 179 } 178 180 179 g.firstIn(ei,active_node);180 for(;ei!=INVALID; g.nextIn(ei))181 mapstorage.graph.firstIn(ei,active_node); 182 for(;ei!=INVALID;mapstorage.graph.nextIn(ei)) 181 183 { 182 184 Gnome::Canvas::Points coos; 183 185 double x1, x2, y1, y2; 184 186 185 nodesmap[ g.source(ei)]->get_bounds(x1, y1, x2, y2);187 nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2); 186 188 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 187 189 188 nodesmap[ g.target(ei)]->get_bounds(x1, y1, x2, y2);190 nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2); 189 191 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 190 192 … … 220 222 break; 221 223 case GDK_BUTTON_PRESS: 224 mapstorage.modified = true; 225 222 226 isbutton=1; 223 227 224 active_node=NodeIt( g,g.addNode());228 active_node=NodeIt(mapstorage.graph,mapstorage.graph.addNode()); 225 229 226 230 //initiating values corresponding to new node in maps … … 228 232 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 229 233 230 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); 234 mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y)); 235 (*mapstorage.nodemap_storage["id"])[active_node] = 236 mapstorage.graph.id(active_node); 237 238 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, 239 clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); 231 240 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); 232 241 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); … … 234 243 (nodesmap[active_node])->show(); 235 244 236 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, ""); 245 nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph, 246 clicked_x+node_property_defaults[N_RADIUS]+5, 247 clicked_y+node_property_defaults[N_RADIUS]+5, ""); 237 248 nodetextmap[active_node]->property_fill_color().set_value("darkblue"); 238 249 239 mapwin ->updateNode(active_node);250 mapwin.updateNode(active_node); 240 251 241 252 break; … … 301 312 active_item=(get_item_at(clicked_x, clicked_y)); 302 313 active_node=INVALID; 303 for (NodeIt i( g); i!=INVALID; ++i)314 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 304 315 { 305 316 if(nodesmap[i]==active_item) … … 330 341 target_item=(get_item_at(clicked_x, clicked_y)); 331 342 Graph::NodeIt target_node=INVALID; 332 for (NodeIt i( g); i!=INVALID; ++i)343 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 333 344 { 334 345 if(nodesmap[i]==target_item) … … 342 353 if(target_node!=active_node) 343 354 { 355 mapstorage.modified = true; 356 344 357 *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red"); 345 358 346 359 //creating new edge 347 active_edge=EdgeIt( g,g.addEdge(active_node, target_node));360 active_edge=EdgeIt(mapstorage.graph,mapstorage.graph.addEdge(active_node, target_node)); 348 361 349 362 //initiating values corresponding to new edge in maps 350 363 mapstorage.initMapsForEdge(active_edge); 364 (*mapstorage.edgemap_storage["id"])[active_edge] = mapstorage.graph.id(active_edge); 351 365 352 366 //calculating coordinates of new edge … … 377 391 378 392 //updating its properties 379 mapwin ->updateEdge(active_edge);393 mapwin.updateEdge(active_edge); 380 394 } 381 395 else … … 430 444 active_node=INVALID; 431 445 active_edge=INVALID; 432 433 446 //was it a node? 434 for (NodeIt i( g); i!=INVALID; ++i)447 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 435 448 { 436 449 if(nodesmap[i]==active_item) … … 442 455 if(active_node==INVALID) 443 456 { 444 for (EdgeIt i( g); i!=INVALID; ++i)457 for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) 445 458 { 446 459 if(edgesmap[i]==active_item) … … 468 481 if(active_node!=INVALID) 469 482 { 483 mapstorage.modified = true; 470 484 471 485 //collecting edges to delete … … 473 487 std::set<Graph::Edge> edges_to_delete; 474 488 475 g.firstOut(e,active_node);476 for(;e!=INVALID; g.nextOut(e))489 mapstorage.graph.firstOut(e,active_node); 490 for(;e!=INVALID;mapstorage.graph.nextOut(e)) 477 491 { 478 492 edges_to_delete.insert(e); 479 493 } 480 494 481 g.firstIn(e,active_node);482 for(;e!=INVALID; g.nextIn(e))495 mapstorage.graph.firstIn(e,active_node); 496 for(;e!=INVALID;mapstorage.graph.nextIn(e)) 483 497 { 484 498 edges_to_delete.insert(e); … … 546 560 //find the activated item between texts 547 561 active_item=(get_item_at(e->button.x, e->button.y)); 548 for (EdgeIt i( g); i!=INVALID; ++i)562 for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) 549 563 { 550 564 if(edgetextmap[i]==active_item) … … 560 574 active_item=(get_item_at(clicked_x, clicked_y)); 561 575 562 for (EdgeIt i( g); i!=INVALID; ++i)576 for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) 563 577 { 564 578 //at the same time only one can be active … … 664 678 //find the activated item between texts 665 679 active_item=(get_item_at(e->button.x, e->button.y)); 666 for (NodeIt i( g); i!=INVALID; ++i)680 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 667 681 { 668 682 //at the same time only one can be active … … 679 693 active_item=(get_item_at(clicked_x, clicked_y)); 680 694 681 for (NodeIt i( g); i!=INVALID; ++i)695 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 682 696 { 683 697 //at the same time only one can be active … … 804 818 edgetextmap[active_edge]->property_text().set_value(ostr.str()); 805 819 (*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d; 806 mapwin ->updateEdge(active_edge);820 mapwin.updateEdge(active_edge); 807 821 break; 808 822 case NODE_MAP_EDIT: 809 823 nodetextmap[active_node]->property_text().set_value(ostr.str()); 810 824 (*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=mapvalue_d; 811 mapwin ->updateNode(active_node);825 mapwin.updateNode(active_node); 812 826 break; 813 827 default: … … 836 850 delete(nodetextmap[node_to_delete]); 837 851 delete(nodesmap[node_to_delete]); 838 g.erase(node_to_delete);852 mapstorage.graph.erase(node_to_delete); 839 853 } 840 854 … … 843 857 delete(edgetextmap[edge_to_delete]); 844 858 delete(edgesmap[edge_to_delete]); 845 g.erase(edge_to_delete);859 mapstorage.graph.erase(edge_to_delete); 846 860 } 847 861 … … 850 864 delete(edgetextmap[edge_to_delete]); 851 865 delete(edgesmap[edge_to_delete]); 852 g.erase(edge_to_delete);866 mapstorage.graph.erase(edge_to_delete); 853 867 } 854 868 … … 870 884 else 871 885 { 872 for (EdgeIt i( g); i!=INVALID; ++i)886 for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) 873 887 { 874 888 if(edgesmap[i]==active_bre) … … 896 910 { 897 911 //create the new map 898 Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> ( g,default_value);912 Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mapstorage.graph, default_value); 899 913 900 914 //if addition was not successful addEdgeMap returns one. … … 907 921 908 922 //add it to the list of the displayable maps 909 mapwin ->registerNewEdgeMap(mapname);923 mapwin.registerNewEdgeMap(mapname); 910 924 911 925 //display it … … 918 932 { 919 933 //create the new map 920 Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> ( g,default_value);934 Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mapstorage.graph,default_value); 921 935 922 936 //if addition was not successful addNodeMap returns one. … … 928 942 929 943 //add it to the list of the displayable maps 930 mapwin ->registerNewNodeMap(mapname);944 mapwin.registerNewNodeMap(mapname); 931 945 932 946 //display it -
graph_displayer_canvas-node.cc
r48 r53 1 #include <graph_displayer_canvas.h>2 #include <broken_edge.h>1 #include "graph_displayer_canvas.h" 2 #include "broken_edge.h" 3 3 #include <math.h> 4 4 … … 12 12 min=node_property_defaults[N_RADIUS]; 13 13 max=node_property_defaults[N_RADIUS]; 14 actual_map=new Graph::NodeMap<double>( g,node_property_defaults[N_RADIUS]);14 actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_RADIUS]); 15 15 } 16 16 else … … 23 23 if(node==INVALID) 24 24 { 25 for (NodeIt i( g); i!=INVALID; ++i)25 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 26 26 { 27 27 double v=abs((*actual_map)[i]); … … 80 80 if(mapname=="Default") 81 81 { 82 actual_map=new Graph::NodeMap<double>( g,node_property_defaults[N_COLOR]);82 actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_COLOR]); 83 83 } 84 84 else … … 104 104 { 105 105 106 for (NodeIt i( g); i!=INVALID; ++i)106 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 107 107 { 108 108 Gdk::Color color; … … 158 158 if(node==INVALID) 159 159 { 160 for (NodeIt i( g); i!=INVALID; ++i)160 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 161 161 { 162 162 if(mapname!="Default") -
graph_displayer_canvas-zoom.cc
r27 r53 1 #include <graph_displayer_canvas.h>2 #include <broken_edge.h>1 #include "graph_displayer_canvas.h" 2 #include "broken_edge.h" 3 3 #include <math.h> 4 4 -
graph_displayer_canvas.cc
r48 r53 1 #include <graph_displayer_canvas.h>2 #include <broken_edge.h>1 #include "graph_displayer_canvas.h" 2 #include "broken_edge.h" 3 3 #include <math.h> 4 4 5 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) 5 GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw) : 6 nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph), 7 nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0), 8 canvasentrywidget(NULL), mapstorage(ms), isbutton(0), active_item(NULL), 9 target_item(NULL), nodemap_to_edit(""), edgemap_to_edit(""), mapwin(mw) 6 10 { 7 8 //Initializing values. 9 active_node=INVALID; 10 active_edge=INVALID; 11 forming_edge=INVALID; 11 //base event handler is move tool 12 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); 13 actual_tool=MOVE; 12 14 13 15 //setting event handler for the editor widget 14 16 entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false); 15 17 16 //base event handler is move tool 17 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); 18 actual_tool=MOVE; 18 active_node=INVALID; 19 active_edge=INVALID; 20 forming_edge=INVALID; 21 } 19 22 20 //set_center_scroll_region(true); 23 GraphDisplayerCanvas::~GraphDisplayerCanvas() 24 { 25 for (NodeIt n(mapstorage.graph); n != INVALID; ++n) 26 { 27 delete nodesmap[n]; 28 delete nodetextmap[n]; 29 } 21 30 31 for (EdgeIt e(mapstorage.graph); e != INVALID; ++e) 32 { 33 delete edgesmap[e]; 34 delete edgetextmap[e]; 35 } 36 37 if(canvasentrywidget) 38 { 39 delete(canvasentrywidget); 40 } 41 } 42 43 void GraphDisplayerCanvas::drawGraph() 44 { 22 45 //first edges are drawn, to hide joining with nodes later 23 46 24 for (EdgeIt i( g); i!=INVALID; ++i)47 for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) 25 48 { 26 49 27 //drawing green lines, coordinates are from cm50 //drawing green lines, coordinates are from mapstorage.coords 28 51 29 52 Gnome::Canvas::Points coos; 30 coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y)); 31 coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y)); 53 coos.push_back(Gnome::Art::Point( 54 mapstorage.coords[mapstorage.graph.source(i)].x, 55 mapstorage.coords[mapstorage.graph.source(i)].y)); 56 coos.push_back(Gnome::Art::Point( 57 mapstorage.coords[mapstorage.graph.target(i)].x, 58 mapstorage.coords[mapstorage.graph.target(i)].y)); 32 59 33 60 edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this); … … 47 74 //afterwards nodes come to be drawn 48 75 49 NodeIt i(g); 50 int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y; 51 52 for (; i!=INVALID; ++i) 76 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 53 77 { 54 //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)55 56 if(cm[i].x>maxx)maxx=(int)cm[i].x;57 if(cm[i].y>maxy)maxy=(int)cm[i].y;58 if(cm[i].x<minx)minx=(int)cm[i].x;59 if(cm[i].y<miny)miny=(int)cm[i].y;60 61 78 //drawing bule nodes, with black line around them 62 79 63 nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20); 80 nodesmap[i]=new Gnome::Canvas::Ellipse( 81 displayed_graph, 82 mapstorage.coords[i].x-20, 83 mapstorage.coords[i].y-20, 84 mapstorage.coords[i].x+20, 85 mapstorage.coords[i].y+20); 64 86 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue"); 65 87 *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black"); … … 67 89 //initializing edge-text as well, to empty string 68 90 69 xy<double> text_pos((cm[i].x+node_property_defaults[N_RADIUS]+5),(cm[i].y+node_property_defaults[N_RADIUS]+5)); 91 xy<double> text_pos( 92 (mapstorage.coords[i].x+node_property_defaults[N_RADIUS]+5), 93 (mapstorage.coords[i].y+node_property_defaults[N_RADIUS]+5)); 70 94 71 nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, ""); 95 nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, 96 text_pos.x, text_pos.y, ""); 72 97 nodetextmap[i]->property_fill_color().set_value("darkblue"); 73 98 nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false); … … 77 102 } 78 103 79 GraphDisplayerCanvas::~GraphDisplayerCanvas()104 void GraphDisplayerCanvas::clear() 80 105 { 81 if(canvasentrywidget) 82 { 83 delete(canvasentrywidget); 84 } 106 active_node=INVALID; 107 active_edge=INVALID; 108 forming_edge=INVALID; 85 109 86 //writing out the end state of the graph 87 //\todo all the maps has to be write out! 88 89 Graph::NodeMap <int> id(g); 90 Graph::NodeMap <double> xc(g); 91 Graph::NodeMap <double> yc(g); 92 93 int j=1; 94 95 for (NodeIt i(g); i!=INVALID; ++i) 110 for (NodeIt n(mapstorage.graph); n != INVALID; ++n) 96 111 { 97 double x1,y1,x2,y2; 98 nodesmap[i]->get_bounds(x1, y1, x2, y2); 99 100 id[i]=j++; 101 xc[i]=(x1+x2)/2; 102 yc[i]=(y1+y2)/2; 112 delete nodesmap[n]; 113 delete nodetextmap[n]; 103 114 } 104 115 105 GraphWriter<Graph> writer(std::cout,g); 106 107 writer.writeNodeMap("id", id); 108 writer.writeNodeMap("coordinates_x", xc); 109 writer.writeNodeMap("coordinates_y", yc); 110 writer.run(); 116 for (EdgeIt e(mapstorage.graph); e != INVALID; ++e) 117 { 118 delete edgesmap[e]; 119 delete edgetextmap[e]; 120 } 111 121 } -
graph_displayer_canvas.h
r46 r53 6 6 class GraphDisplayerCanvas; 7 7 8 #include <all_include.h>9 #include <map_win.h>10 #include <mapstorage.h>11 #include <broken_edge.h>8 #include "all_include.h" 9 #include "mapstorage.h" 10 #include "broken_edge.h" 11 #include "map_win.h" 12 12 #include <libgnomecanvasmm.h> 13 13 #include <libgnomecanvasmm/polygon.h> … … 19 19 20 20 public: 21 GraphDisplayerCanvas( Graph &, CoordinatesMap &, MapStorage &, MapWin *);21 GraphDisplayerCanvas(MapStorage &, MapWin &); 22 22 virtual ~GraphDisplayerCanvas(); 23 23 … … 110 110 int getActualTool(); 111 111 112 void drawGraph(); 113 void clear(); 114 112 115 ///creates a new Nodemap 113 116 int addNewNodeMap(double,std::string); … … 124 127 125 128 private: 126 127 ///The graph, on which we work128 Graph & g;129 129 130 130 ///Map of nodes of graph … … 176 176 177 177 ///We need to store mapwin, to be able to ask the appropriate values for properties of new items. 178 MapWin *mapwin;178 MapWin & mapwin; 179 179 180 180 }; -
main_win.cc
r50 r53 1 #include <main_win.h> 2 3 MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm, 4 MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),newmapwin("Creating new map",gd_canvas),gd_canvas(graph, cm, ms, &mapwin) 1 #include "main_win.h" 2 3 MainWin::MainWin(const std::string& title) : 4 mapwin("Map Setup", mapstorage, gd_canvas), 5 newmapwin("Creating new map", gd_canvas), gd_canvas(mapstorage, mapwin) 5 6 { 6 7 … … 20 21 ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS), 21 22 sigc::mem_fun(*this, &MainWin::saveFileAs)); 22 ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), 23 ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE), 24 sigc::mem_fun(*this, &MainWin::close)); 25 ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT), 23 26 sigc::mem_fun(*this, &MainWin::hide)); 24 27 … … 37 40 sigc::mem_fun(this->mapwin, &MapWin::show)); 38 41 39 ag->add( Gtk::Action::create("CreateNode", Gtk::Stock::NO), 42 Gtk::RadioAction::Group tool_group; 43 ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::Stock::CONVERT, "Move"), 44 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) ); 45 ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::Stock::NO, "Create node"), 40 46 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) ); 41 ag->add( Gtk:: Action::create("CreateEdge", Gtk::Stock::REMOVE),47 ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::Stock::REMOVE, "Create edge"), 42 48 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) ); 43 ag->add( Gtk:: Action::create("EraseItem", Gtk::Stock::DELETE),49 ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::Stock::DELETE, "Delete"), 44 50 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) ); 45 ag->add( Gtk::Action::create("MoveItem", Gtk::Stock::CONVERT),46 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) );47 51 ag->add( Gtk::Action::create("EditEdgeMap", Gtk::Stock::PROPERTIES), 48 52 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 4) ); … … 67 71 " <menuitem action='FileSave'/>" 68 72 " <menuitem action='FileSaveAs'/>" 69 " <menuitem action='FileQuit'/>" 73 " <menuitem action='Close'/>" 74 " <menuitem action='Quit'/>" 70 75 " </menu>" 71 76 " <menu action='ViewMenu'>" … … 83 88 " <toolitem action='FileOpen' />" 84 89 " <toolitem action='FileSave' />" 90 " <toolitem action='Close' />" 85 91 " <separator />" 86 92 " <toolitem action='ViewZoomIn' />" … … 89 95 " <toolitem action='ViewZoom100' />" 90 96 " <separator />" 97 " <toolitem action='MoveItem' />" 91 98 " <toolitem action='CreateNode' />" 92 99 " <toolitem action='CreateEdge' />" 93 100 " <toolitem action='EraseItem' />" 94 " <toolitem action='MoveItem' />"95 101 " <toolitem action='EditEdgeMap' />" 96 102 " <toolitem action='EditNodeMap' />" … … 131 137 void MainWin::newFile() 132 138 { 133 std::cerr << "MainWin::newFile(): not yet implemented" << std::endl; 139 if (mapstorage.modified) 140 { 141 Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING, 142 Gtk::BUTTONS_NONE); 143 mdialog.set_message("<b>Save changes before closing?</b>", true); 144 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); 145 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 146 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); 147 switch (mdialog.run()) 148 { 149 case Gtk::RESPONSE_CANCEL: 150 return; 151 case Gtk::RESPONSE_REJECT: 152 break; 153 case Gtk::RESPONSE_ACCEPT: 154 saveFile(); 155 break; 156 } 157 } 158 gd_canvas.clear(); 159 mapstorage.clear(); 160 mapwin.update(); 134 161 } 135 162 136 163 void MainWin::openFile() 137 164 { 138 std::cerr << "MainWin::openFile(): not yet implemented" << std::endl; 165 if (mapstorage.modified) 166 { 167 Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING, 168 Gtk::BUTTONS_NONE); 169 mdialog.set_message("<b>Save changes before closing?</b>", true); 170 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); 171 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 172 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); 173 switch (mdialog.run()) 174 { 175 case Gtk::RESPONSE_CANCEL: 176 return; 177 case Gtk::RESPONSE_REJECT: 178 break; 179 case Gtk::RESPONSE_ACCEPT: 180 saveFile(); 181 break; 182 } 183 } 184 gd_canvas.clear(); 185 mapstorage.clear(); 186 Gtk::FileChooserDialog fcdialog("Open File"); 187 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 188 fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT); 189 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) 190 { 191 Glib::ustring filename = fcdialog.get_filename(); 192 mapstorage.readFromFile(filename); 193 mapstorage.file_name = filename; 194 mapstorage.modified = false; 195 gd_canvas.drawGraph(); 196 mapwin.update(); 197 } 139 198 } 140 199 141 200 void MainWin::saveFile() 142 201 { 143 std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl; 202 if (mapstorage.file_name == "") { 203 saveFileAs(); 204 } 205 else 206 { 207 mapstorage.writeToFile(mapstorage.file_name); 208 mapstorage.modified = false; 209 } 144 210 } 145 211 146 212 void MainWin::saveFileAs() 147 213 { 148 std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl; 149 } 214 Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE); 215 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 216 fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); 217 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) 218 { 219 Glib::ustring filename = fcdialog.get_filename(); 220 mapstorage.file_name = filename; 221 mapstorage.writeToFile(filename); 222 mapstorage.modified = false; 223 } 224 } 225 226 void MainWin::close() 227 { 228 if (mapstorage.modified) 229 { 230 Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING, 231 Gtk::BUTTONS_NONE); 232 mdialog.set_message("<b>Save changes before closing?</b>", true); 233 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); 234 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 235 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); 236 switch (mdialog.run()) 237 { 238 case Gtk::RESPONSE_CANCEL: 239 return; 240 case Gtk::RESPONSE_REJECT: 241 break; 242 case Gtk::RESPONSE_ACCEPT: 243 saveFile(); 244 break; 245 } 246 } 247 gd_canvas.clear(); 248 mapstorage.clear(); 249 mapwin.update(); 250 } -
main_win.h
r50 r53 4 4 #define MAIN_WIN_H 5 5 6 #include <all_include.h> 7 #include <mapstorage.h> 8 #include <map_win.h> 9 #include <new_map_win.h> 6 #include "all_include.h" 7 #include "mapstorage.h" 8 #include "map_win.h" 9 #include "new_map_win.h" 10 #include "edit_win.h" 11 #include "graph_displayer_canvas.h" 10 12 #include <libgnomecanvasmm.h> 11 13 #include <libgnomecanvasmm/polygon.h> … … 18 20 ///Constructor of the \ref MainWin. It creates the menu and the \ref GraphDisplayerCanvas on which the graph will be drawn. 19 21 ///\param title is the title of the window 20 ///\param graph is the graph that will be drawn here. It will be given further to the \ref GraphDisplayerCanvas 21 ///\param cm stores the coordinates of the nodes of the graph 22 ///\param ms is the \ref MapStorage in which the different visualizable maps are stored 23 MainWin(const std::string& title, Graph &, CoordinatesMap &, MapStorage &); 22 MainWin(const std::string& title); 23 24 MapStorage mapstorage; 24 25 25 26 protected: … … 53 54 ///Callback for 'FileSaveAs' action. 54 55 virtual void saveFileAs(); 56 ///Callback for 'Close' action. 57 virtual void close(); 55 58 }; 56 59 -
map_win.cc
r48 r53 1 #include <map_win.h>1 #include "map_win.h" 2 2 #include <set> 3 3 … … 119 119 show_all_children(); 120 120 121 } 122 123 void MapWin::update() 124 { 125 for(int i=0;i<EDGE_PROPERTY_NUM;i++) 126 { 127 //filling in combo box with choices 128 std::list<Glib::ustring> listStrings; 129 130 listStrings.push_back("Default"); 131 132 std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps(); 133 for(;emsi!=ms.endOfEdgeMaps();emsi++) 134 { 135 listStrings.push_back(emsi->first); 136 } 137 138 e_combo_array[i].set_popdown_strings(listStrings); 139 } 140 for(int i=0;i<NODE_PROPERTY_NUM;i++) 141 { 142 //filling in combo box with choices 143 std::list<Glib::ustring> listStrings; 144 145 listStrings.push_back("Default"); 146 147 std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps(); 148 149 for(;emsi!=ms.endOfNodeMaps();emsi++) 150 { 151 listStrings.push_back(emsi->first); 152 } 153 154 n_combo_array[i].set_popdown_strings(listStrings); 155 } 121 156 } 122 157 -
map_win.h
r38 r53 6 6 class MapWin; 7 7 8 #include <all_include.h>9 #include <mapstorage.h>10 #include <graph_displayer_canvas.h>8 #include "all_include.h" 9 #include "graph_displayer_canvas.h" 10 #include "mapstorage.h" 11 11 #include <libgnomecanvasmm.h> 12 12 #include <libgnomecanvasmm/polygon.h> … … 64 64 virtual bool closeIfEscapeIsPressed(GdkEventKey*); 65 65 66 void update(); 66 67 }; 67 68 -
mapstorage.cc
r46 r53 1 #include <mapstorage.h> 2 3 MapStorage::MapStorage(Graph & graph):g(graph) 4 { 5 }; 1 #include "mapstorage.h" 2 3 MapStorage::MapStorage() : modified(false), file_name("") 4 { 5 nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph); 6 coords.setXMap(*nodemap_storage["coordinates_x"]); 7 nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph); 8 coords.setYMap(*nodemap_storage["coordinates_y"]); 9 10 nodemap_storage["id"] = new Graph::NodeMap<double>(graph); 11 edgemap_storage["id"] = new Graph::EdgeMap<double>(graph); 12 } 13 14 MapStorage::~MapStorage() 15 { 16 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = 17 nodemap_storage.begin(); it != nodemap_storage.end(); ++it) 18 { 19 delete it->second; 20 } 21 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it = 22 edgemap_storage.begin(); it != edgemap_storage.end(); ++it) 23 { 24 delete it->second; 25 } 26 } 6 27 7 28 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap) … … 28 49 { 29 50 double max=0; 30 for (NodeIt j(g ); j!=INVALID; ++j)51 for (NodeIt j(graph); j!=INVALID; ++j) 31 52 { 32 53 if( (*nodemap_storage[name])[j]>max ) … … 41 62 { 42 63 double max=0; 43 for (EdgeIt j(g ); j!=INVALID; ++j)64 for (EdgeIt j(graph); j!=INVALID; ++j) 44 65 { 45 66 if( (*edgemap_storage[name])[j]>max ) … … 53 74 double MapStorage::minOfNodeMap(const std::string & name) 54 75 { 55 NodeIt j(g );76 NodeIt j(graph); 56 77 double min=(*nodemap_storage[name])[j]; 57 78 for (; j!=INVALID; ++j) … … 67 88 double MapStorage::minOfEdgeMap(const std::string & name) 68 89 { 69 EdgeIt j(g );90 EdgeIt j(graph); 70 91 double min=(*edgemap_storage[name])[j]; 71 for (EdgeIt j(g ); j!=INVALID; ++j)92 for (EdgeIt j(graph); j!=INVALID; ++j) 72 93 { 73 94 if( (*edgemap_storage[name])[j]<min ) … … 87 108 } 88 109 } 110 111 void MapStorage::readFromFile(const std::string &filename) 112 { 113 bool read_x = false; 114 bool read_y = false; 115 116 try { 117 LemonReader lreader(filename); 118 ContentReader content(lreader); 119 lreader.run(); 120 121 const std::vector<std::string>& nodeMapNames = content.nodeSetMaps(0); 122 const std::vector<std::string>& edgeMapNames = content.edgeSetMaps(0); 123 124 GraphReader<Graph> greader(filename, graph); 125 for (std::vector<std::string>::const_iterator it = nodeMapNames.begin(); 126 it != nodeMapNames.end(); ++it) 127 { 128 if (*it == "coordinates_x") 129 { 130 read_x = true; 131 //std::cout << "read X nodemap" << std::endl; 132 } 133 else if (*it == "coordinates_y") 134 { 135 read_y = true; 136 //std::cout << "read Y nodemap" << std::endl; 137 } 138 else if (*it == "id") 139 { 140 //std::cout << "read id nodemap" << std::endl; 141 } 142 else 143 { 144 nodemap_storage[*it] = new Graph::NodeMap<double>(graph); 145 //std::cout << "read " << *it << " nodemap" << std::endl; 146 } 147 greader.readNodeMap(*it, *nodemap_storage[*it]); 148 } 149 for (std::vector<std::string>::const_iterator it = edgeMapNames.begin(); 150 it != edgeMapNames.end(); ++it) 151 { 152 if (*it == "id") 153 { 154 //std::cout << "read id edgemap" << std::endl; 155 } 156 else 157 { 158 edgemap_storage[*it] = new Graph::EdgeMap<double>(graph); 159 //std::cout << "read " << *it << " edgemap" << std::endl; 160 } 161 greader.readEdgeMap(*it, *edgemap_storage[*it]); 162 } 163 greader.run(); 164 } catch (DataFormatError& error) { 165 /* 166 Gtk::MessageDialog mdialog("Read Error"); 167 mdialog.set_message(error.what()); 168 mdialog.run(); 169 */ 170 // reset graph and mapstorage ? 171 return; 172 } 173 174 if (!read_x || !read_y) 175 { 176 int node_num = 0; 177 for (NodeIt n(graph); n != INVALID; ++n) 178 { 179 node_num++; 180 } 181 const double pi = 3.142; 182 double step = 2 * pi / (double) node_num; 183 int i = 0; 184 for (NodeIt n(graph); n != INVALID; ++n) 185 { 186 nodemap_storage["coordinates_x"]->set(n, 250.0 * cos(i * step)); 187 nodemap_storage["coordinates_y"]->set(n, 250.0 * sin(i * step)); 188 i++; 189 } 190 } 191 } 192 193 void MapStorage::writeToFile(const std::string &filename) 194 { 195 GraphWriter<Graph> gwriter(filename, graph); 196 197 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = 198 nodemap_storage.begin(); it != nodemap_storage.end(); ++it) 199 { 200 gwriter.writeNodeMap(it->first, *(it->second)); 201 //std::cout << "wrote " << it->first << " nodemap" << std::endl; 202 } 203 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it = 204 edgemap_storage.begin(); it != edgemap_storage.end(); ++it) 205 { 206 gwriter.writeEdgeMap(it->first, *(it->second)); 207 //std::cout << "wrote " << it->first << " edgemap" << std::endl; 208 } 209 gwriter.run(); 210 } 211 212 void MapStorage::clear() 213 { 214 for (std::map<std::string, Graph::NodeMap<double>*>::iterator it = 215 nodemap_storage.begin(); it != nodemap_storage.end(); ++it) 216 { 217 if ((it->first != "coordinates_x") && 218 (it->first != "coordinates_y") && 219 (it->first != "id")) 220 { 221 delete it->second; 222 nodemap_storage.erase(it); 223 } 224 } 225 for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it = 226 edgemap_storage.begin(); it != edgemap_storage.end(); ++it) 227 { 228 if (it->first != "id") 229 { 230 delete it->second; 231 edgemap_storage.erase(it); 232 } 233 } 234 graph.clear(); 235 file_name = ""; 236 modified = false; 237 } -
mapstorage.h
r31 r53 4 4 #define MAPSTORAGE_H 5 5 6 #include <all_include.h> 6 #include "all_include.h" 7 #include "xymap.h" 7 8 8 9 ///Class MapStorage is responsible for storing … … 19 20 public: 20 21 21 Graph &g; 22 Graph graph; 23 XYMap<Graph::NodeMap<double> > coords; 24 25 bool modified; 26 std::string file_name; 22 27 23 28 ///Stores double type NodeMaps … … 40 45 /// 41 46 ///\param graph is the graph for which the maps are stored in this object. 42 MapStorage(Graph &); 47 MapStorage(); 48 49 ~MapStorage(); 43 50 44 51 ///Adds given map to storage. A name and the map itself has to be provided. … … 93 100 ///This function sets a default base value for the newly created node 94 101 void initMapsForEdge(Graph::Edge); 102 103 void readFromFile(const std::string &); 104 void writeToFile(const std::string &); 105 106 void clear(); 95 107 }; 96 108
Note: See TracChangeset
for help on using the changeset viewer.