moved the gui
authorladanyi
Wed, 11 May 2005 16:55:18 +0000
changeset 1412c7fab5a1174a
parent 1411 5d161e08bda8
child 1413 3f45d58969d4
moved the gui
configure.ac
src/gui/Makefile.am
src/gui/all_include.h
src/gui/graph-displayer.cc
src/gui/graph_displayer_canvas.cc
src/gui/graph_displayer_canvas.h
src/gui/graphocska.lgf
src/gui/main_win.cc
src/gui/main_win.h
src/gui/map_win.cc
src/gui/map_win.h
src/gui/mapstorage.cc
src/gui/mapstorage.h
src/gui/src/Makefile.am
src/gui/src/main.cc
     1.1 --- a/configure.ac	Wed May 11 13:49:17 2005 +0000
     1.2 +++ b/configure.ac	Wed May 11 16:55:18 2005 +0000
     1.3 @@ -58,7 +58,6 @@
     1.4  src/demo/Makefile
     1.5  src/test/Makefile
     1.6  src/gui/Makefile
     1.7 -src/gui/src/Makefile
     1.8  ])
     1.9  
    1.10  AC_OUTPUT
     2.1 --- a/src/gui/Makefile.am	Wed May 11 13:49:17 2005 +0000
     2.2 +++ b/src/gui/Makefile.am	Wed May 11 16:55:18 2005 +0000
     2.3 @@ -1,1 +1,19 @@
     2.4 -SUBDIRS = src
     2.5 +AM_CPPFLAGS = -I$(top_srcdir)/src
     2.6 +LDADD = $(top_builddir)/src/lemon/libemon.la
     2.7 +
     2.8 +bin_PROGRAMS = gd
     2.9 +
    2.10 +gd_SOURCES = \
    2.11 +	all_include.h \
    2.12 +	graph_displayer_canvas.cc \
    2.13 +	graph_displayer_canvas.h \
    2.14 +	graph-displayer.cc \
    2.15 +	main_win.cc \
    2.16 +	main_win.h \
    2.17 +	mapstorage.cc \
    2.18 +	mapstorage.h \
    2.19 +	map_win.cc \
    2.20 +	map_win.h
    2.21 +
    2.22 +gd_CXXFLAGS = $(GTK_CFLAGS)
    2.23 +gd_LDFLAGS = $(GTK_LIBS)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/gui/all_include.h	Wed May 11 16:55:18 2005 +0000
     3.3 @@ -0,0 +1,39 @@
     3.4 +// -*- C++ -*- //
     3.5 +
     3.6 +#ifndef ALL_INCLUDE_H
     3.7 +#define ALL_INCLUDE_H
     3.8 +
     3.9 +#include <fstream>
    3.10 +#include <iostream>
    3.11 +
    3.12 +#include <vector>
    3.13 +
    3.14 +#include <lemon/list_graph.h>
    3.15 +#include <lemon/graph_reader.h>
    3.16 +#include <lemon/graph_writer.h>
    3.17 +#include <lemon/graph_utils.h>
    3.18 +#include <lemon/maps.h>
    3.19 +#include <lemon/error.h>
    3.20 +#include <lemon/xy.h>
    3.21 +
    3.22 +enum {WIDTH, COLOR, TEXT, PROPERTY_NUM};// properties;
    3.23 +#define RANGE 3
    3.24 +#define WIN_WIDTH 900
    3.25 +#define WIN_HEIGHT 600
    3.26 +
    3.27 +
    3.28 +#ifndef MAIN_PART
    3.29 +extern std::string * property_strings;
    3.30 +extern double * property_defaults;
    3.31 +#endif //MAIN_PART
    3.32 +
    3.33 +using namespace lemon;
    3.34 +
    3.35 +typedef xy<double> Coordinates;
    3.36 +typedef ListGraph Graph;
    3.37 +typedef Graph::NodeMap<Coordinates> CoordinatesMap;
    3.38 +typedef Graph::Node Node;
    3.39 +typedef Graph::EdgeIt EdgeIt;
    3.40 +typedef Graph::NodeIt NodeIt;
    3.41 +
    3.42 +#endif // ALL_INCLUDE_H
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/gui/graph-displayer.cc	Wed May 11 16:55:18 2005 +0000
     4.3 @@ -0,0 +1,73 @@
     4.4 +#include <all_include.h>
     4.5 +#include <mapstorage.h>
     4.6 +#include <main_win.h>
     4.7 +#include <libgnomecanvasmm.h>
     4.8 +#include <libgnomecanvasmm/polygon.h>
     4.9 +
    4.10 +#define MAIN_PART
    4.11 +
    4.12 +std::string * property_strings;
    4.13 +double * property_defaults;
    4.14 +
    4.15 +
    4.16 +int main(int argc, char *argv[])
    4.17 +{
    4.18 +  property_strings=new std::string[PROPERTY_NUM];
    4.19 +  property_strings[WIDTH]="Width";
    4.20 +  property_strings[COLOR]="Color";
    4.21 +  property_strings[TEXT]="Text";
    4.22 +
    4.23 +  property_defaults=new double[PROPERTY_NUM];
    4.24 +  property_defaults[WIDTH]=10.0;
    4.25 +  property_defaults[COLOR]=100;
    4.26 +  property_defaults[TEXT]=0;
    4.27 +
    4.28 +  if(argc<2)
    4.29 +  {
    4.30 +      std::cerr << "USAGE: gd <input filename.lgf>" << std::endl;
    4.31 +      return 0;
    4.32 +  }
    4.33 +
    4.34 +  Coordinates coosvector;
    4.35 +
    4.36 +  Graph g;
    4.37 +
    4.38 +  CoordinatesMap cm(g);
    4.39 +  Graph::EdgeMap<double> cap(g), map1(g), map2(g), map3(g), map4(g);
    4.40 +
    4.41 +  //we create one object to read x coordinates
    4.42 +  //and one to read y coordinate of nodes and write them to cm NodeMap.
    4.43 +
    4.44 +  XMap <CoordinatesMap> xreader (cm);
    4.45 +  YMap <CoordinatesMap> yreader (cm);
    4.46 +  Graph::NodeMap<double> nodedata (g);
    4.47 +
    4.48 +  std::ifstream is(argv[1]);
    4.49 +
    4.50 +  GraphReader<Graph> reader(is, g);
    4.51 +  reader.readNodeMap("coordinates_x", xreader);
    4.52 +  reader.readNodeMap("coordinates_y", yreader);
    4.53 +  reader.readNodeMap("data", nodedata);
    4.54 +  reader.readEdgeMap("cap", cap);
    4.55 +  reader.readEdgeMap("map1", map1);
    4.56 +  reader.readEdgeMap("map2", map2);
    4.57 +  reader.readEdgeMap("map3", map3);
    4.58 +  reader.readEdgeMap("map4", map4);
    4.59 +  reader.run();
    4.60 +
    4.61 +  MapStorage ms(g);
    4.62 +  ms.addNodeMap("data",&nodedata);
    4.63 +  ms.addEdgeMap("cap",&cap);
    4.64 +  ms.addEdgeMap("map1",&map1);
    4.65 +  ms.addEdgeMap("map2",&map2);
    4.66 +  ms.addEdgeMap("map3",&map3);
    4.67 +  ms.addEdgeMap("map4",&map4);
    4.68 +
    4.69 +  Gnome::Canvas::init();
    4.70 +  Gtk::Main app(argc, argv);
    4.71 +
    4.72 +  MainWin mainwin("Displayed Graph", g, cm, ms);
    4.73 +  app.run(mainwin);
    4.74 +
    4.75 +  return 0;
    4.76 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/gui/graph_displayer_canvas.cc	Wed May 11 16:55:18 2005 +0000
     5.3 @@ -0,0 +1,259 @@
     5.4 +#include <graph_displayer_canvas.h>
     5.5 +
     5.6 +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)
     5.7 +{
     5.8 +
     5.9 +  for (EdgeIt i(g); i!=INVALID; ++i)
    5.10 +  {
    5.11 +    Gnome::Canvas::Points coos;
    5.12 +    coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
    5.13 +    coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
    5.14 +    
    5.15 +    edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);
    5.16 +    *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
    5.17 +    edgesmap[i]->property_width_pixels().set_value(10);
    5.18 +    
    5.19 +    
    5.20 +    double x1, x2, y1, y2;
    5.21 +    edgesmap[i]->get_bounds(x1, y1, x2, y2);
    5.22 +    
    5.23 +    edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, "");
    5.24 +    edgetextmap[i]->property_fill_color().set_value("black");
    5.25 +  }
    5.26 +
    5.27 +  NodeIt i(g);
    5.28 +  int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
    5.29 +
    5.30 +  for (; i!=INVALID; ++i)
    5.31 +  {
    5.32 +    if(cm[i].x>maxx)maxx=(int)cm[i].x;
    5.33 +    if(cm[i].y>maxy)maxy=(int)cm[i].y;
    5.34 +    if(cm[i].x<minx)minx=(int)cm[i].x;
    5.35 +    if(cm[i].y<miny)miny=(int)cm[i].y;
    5.36 +
    5.37 +    nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
    5.38 +    *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
    5.39 +    *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
    5.40 +    (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
    5.41 +  }
    5.42 +
    5.43 +  double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
    5.44 +  double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
    5.45 +
    5.46 +  set_pixels_per_unit((biggest_x>biggest_y)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
    5.47 +  std::cout<<abs(maxx)<<" "<<abs(minx)<<" big x "<<biggest_x<<" "<<abs(maxy)<<" "<<abs(miny)<<" big y "<<biggest_y<<std::endl;
    5.48 +  std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl;
    5.49 +  std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl;
    5.50 +
    5.51 +}
    5.52 +
    5.53 +GraphDisplayerCanvas::~GraphDisplayerCanvas()
    5.54 +{
    5.55 +    Graph::NodeMap <int> id(g);
    5.56 +    Graph::NodeMap <double> xc(g);
    5.57 +    Graph::NodeMap <double> yc(g);
    5.58 +
    5.59 +    int j=1;
    5.60 +
    5.61 +    for (NodeIt i(g); i!=INVALID; ++i)
    5.62 +    {
    5.63 +        double x1,y1,x2,y2;
    5.64 +        nodesmap[i]->get_bounds(x1, y1, x2, y2);
    5.65 +
    5.66 +        id[i]=j++;
    5.67 +        xc[i]=(x1+x2)/2;
    5.68 +        yc[i]=(y1+y2)/2;
    5.69 +    }
    5.70 +
    5.71 +    GraphWriter<Graph> writer(std::cout,g);
    5.72 +
    5.73 +    writer.writeNodeMap("id", id);
    5.74 +    writer.writeNodeMap("coordinates_x", xc);
    5.75 +    writer.writeNodeMap("coordinates_y", yc);
    5.76 +    writer.run();
    5.77 +}
    5.78 +
    5.79 +int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
    5.80 +{
    5.81 +  for (EdgeIt i(g); i!=INVALID; ++i)
    5.82 +  {
    5.83 +    int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
    5.84 +    edgesmap[i]->property_width_pixels().set_value(w);
    5.85 +  }
    5.86 +  return 0;
    5.87 +};
    5.88 +
    5.89 +int GraphDisplayerCanvas::changeColor (std::string mapname)
    5.90 +{  
    5.91 +  for (EdgeIt i(g); i!=INVALID; ++i)
    5.92 +  {
    5.93 +    double w=(*(mapstorage.edgemap_storage)[mapname])[i];
    5.94 +    double max=mapstorage.maxOfEdgeMap(mapname);
    5.95 +    double min=mapstorage.minOfEdgeMap(mapname);
    5.96 +      
    5.97 +    //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
    5.98 +    Gdk::Color color;
    5.99 +    if(max!=min)
   5.100 +    {
   5.101 +      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
   5.102 +    }
   5.103 +    else
   5.104 +    {
   5.105 +      color.set_rgb_p (0, 100, 0);
   5.106 +    }
   5.107 +
   5.108 +    edgesmap[i]->property_fill_color_gdk().set_value(color);
   5.109 +  }
   5.110 +  return 0;
   5.111 +};
   5.112 +
   5.113 +int GraphDisplayerCanvas::changeText (std::string mapname)
   5.114 +{
   5.115 +  for (EdgeIt i(g); i!=INVALID; ++i)
   5.116 +  {
   5.117 +    if(mapname!="Text")
   5.118 +    {
   5.119 +      double number=(*(mapstorage.edgemap_storage)[mapname])[i];
   5.120 +      int length=(int)(floor(log(number)/log(10)))+1;
   5.121 +      int maxpos=(int)(pow(10,length-1));
   5.122 +      int strl=length+1+RANGE;
   5.123 +      char * str=new char[strl];
   5.124 +      str[length]='.';
   5.125 +      str[strl]='\0';
   5.126 +      
   5.127 +      for(int j=0;j<strl;j++)
   5.128 +      {
   5.129 +	if(j!=length)
   5.130 +        {
   5.131 +	  int digit=(int)(number/maxpos);
   5.132 +	  str[j]=(digit+'0');
   5.133 +	  number-=digit*maxpos;
   5.134 +	  number*=10;
   5.135 +        }
   5.136 +      }
   5.137 +      
   5.138 +      edgetextmap[i]->property_text().set_value(str);
   5.139 +    }
   5.140 +    else
   5.141 +    {
   5.142 +      edgetextmap[i]->property_text().set_value("");
   5.143 +    }
   5.144 +  }
   5.145 +  return 0;
   5.146 +};
   5.147 +
   5.148 +
   5.149 +int GraphDisplayerCanvas::rezoom ()
   5.150 +{
   5.151 +  double x1, x2, y1, y2;
   5.152 +  int x,y;
   5.153 +
   5.154 +  NodeIt i(g);
   5.155 +  nodesmap[i]->get_bounds(x1, y1, x2, y2);
   5.156 +
   5.157 +  x=(int)((x1+x2)/2);
   5.158 +  y=(int)((y1+y2)/2);
   5.159 +  
   5.160 +  int maxx=0, maxy=0, minx=(int)x, miny=(int)y;
   5.161 +
   5.162 +  for (; i!=INVALID; ++i)
   5.163 +  {
   5.164 +    nodesmap[i]->get_bounds(x1, y1, x2, y2);
   5.165 +
   5.166 +    x=(int)((x1+x2)/2);
   5.167 +    y=(int)((y1+y2)/2);
   5.168 +
   5.169 +    if(x>maxx)maxx=x;
   5.170 +    if(y>maxy)maxy=y;
   5.171 +    if(x<minx)minx=x;
   5.172 +    if(y<miny)miny=y;
   5.173 +  }
   5.174 +
   5.175 +  double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
   5.176 +  double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
   5.177 +
   5.178 +  set_pixels_per_unit((biggest_x-WIN_WIDTH>biggest_y-WIN_HEIGHT)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
   5.179 +  return 0;
   5.180 +};
   5.181 +
   5.182 +
   5.183 +///This function moves only one node of displayed_graph,
   5.184 +///but recalculate the location of weight point,
   5.185 +///and also redraw the sides of the planefigure.
   5.186 +bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
   5.187 +{
   5.188 +  switch(e->type)
   5.189 +  {
   5.190 +    case GDK_BUTTON_PRESS:
   5.191 +      clicked_x=e->button.x;
   5.192 +      clicked_y=e->button.y;
   5.193 +      active_item=(get_item_at(e->button.x, e->button.y));
   5.194 +      isbutton=true;
   5.195 +      break;
   5.196 +    case GDK_BUTTON_RELEASE:
   5.197 +      isbutton=false;
   5.198 +      active_item=NULL;
   5.199 +      break;
   5.200 +    case GDK_MOTION_NOTIFY:
   5.201 +      if(isbutton)
   5.202 +      {
   5.203 +        double dx=e->motion.x-clicked_x;
   5.204 +        double dy=e->motion.y-clicked_y;
   5.205 +        active_item->move(dx, dy);
   5.206 +        clicked_x=e->motion.x;
   5.207 +        clicked_y=e->motion.y;
   5.208 +
   5.209 +        EdgeIt e;
   5.210 +
   5.211 +        g.firstOut(e,n);
   5.212 +        for(;e!=INVALID;g.nextOut(e))
   5.213 +        {
   5.214 +            Gnome::Canvas::Points coos;
   5.215 +            double x1, x2, y1, y2;
   5.216 +
   5.217 +            nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
   5.218 +            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   5.219 +
   5.220 +            nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
   5.221 +            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   5.222 +
   5.223 +            edgesmap[e]->property_points().set_value(coos);
   5.224 +
   5.225 +	    edgesmap[e]->get_bounds(x1, y1, x2, y2);
   5.226 +
   5.227 +	    edgetextmap[e]->property_x().set_value((x1+x2)/2);
   5.228 +	    edgetextmap[e]->property_y().set_value((y1+y2)/2);
   5.229 +        }
   5.230 +
   5.231 +        g.firstIn(e,n);
   5.232 +        for(;e!=INVALID;g.nextIn(e))
   5.233 +        {
   5.234 +            Gnome::Canvas::Points coos;
   5.235 +            double x1, x2, y1, y2;
   5.236 +
   5.237 +            nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
   5.238 +            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   5.239 +
   5.240 +            nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
   5.241 +            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   5.242 +
   5.243 +            edgesmap[e]->property_points().set_value(coos);
   5.244 +
   5.245 +	    edgesmap[e]->get_bounds(x1, y1, x2, y2);
   5.246 +
   5.247 +	    edgetextmap[e]->property_x().set_value((x1+x2)/2);
   5.248 +	    edgetextmap[e]->property_y().set_value((y1+y2)/2);
   5.249 +        }
   5.250 +      }
   5.251 +    default: break;
   5.252 +  }
   5.253 +  return true;
   5.254 +}
   5.255 +
   5.256 +bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
   5.257 +{
   5.258 +  Gnome::Canvas::CanvasAA::on_expose_event(event);
   5.259 +  //usleep(10000);
   5.260 +  //rezoom();
   5.261 +  return true;
   5.262 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/gui/graph_displayer_canvas.h	Wed May 11 16:55:18 2005 +0000
     6.3 @@ -0,0 +1,65 @@
     6.4 +// -*- C++ -*- //
     6.5 +
     6.6 +#ifndef GRAPH_DISPLAYER_CANVAS_H
     6.7 +#define GRAPH_DISPLAYER_CANVAS_H
     6.8 +
     6.9 +#include <all_include.h>
    6.10 +#include <mapstorage.h>
    6.11 +#include <libgnomecanvasmm.h>
    6.12 +#include <libgnomecanvasmm/polygon.h>
    6.13 +
    6.14 +class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
    6.15 +{
    6.16 +  typedef Gnome::Canvas::CanvasAA Parent;
    6.17 +
    6.18 +public:
    6.19 +  GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &);
    6.20 +  virtual ~GraphDisplayerCanvas();
    6.21 +
    6.22 +  int changeLineWidth (std::string mapname);
    6.23 +  int changeColor (std::string mapname);
    6.24 +  int changeText (std::string mapname);
    6.25 +  int rezoom();
    6.26 +
    6.27 +protected:
    6.28 +
    6.29 +  virtual bool on_expose_event(GdkEventExpose *);
    6.30 +
    6.31 +private:
    6.32 +
    6.33 +  ///Event handler function that handles dragging nodes of displayed_graph
    6.34 +  bool event_handler(GdkEvent* e, Node n);
    6.35 +
    6.36 +  ///The graph, on which we work
    6.37 +  Graph g;
    6.38 +  ///Map of nodes of planefigure
    6.39 +  Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
    6.40 +  ///Map of edges of planefigure
    6.41 +  Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap;
    6.42 +
    6.43 +  ///Map of texts to write on edges
    6.44 +  Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
    6.45 +
    6.46 +  ///Group of graphical elements of displayed_graph
    6.47 +  Gnome::Canvas::Group displayed_graph;
    6.48 +
    6.49 +  ///Here we store the maps that can be displayed through properties.
    6.50 +  MapStorage mapstorage;
    6.51 +
    6.52 +  ///Indicates whether the button of mouse is pressed or not
    6.53 +  bool isbutton;
    6.54 +
    6.55 +  ///At this location was the mousebutton pressed.
    6.56 +  ///It helps to calculate the distance of dragging.
    6.57 +  double clicked_x, clicked_y;
    6.58 +
    6.59 +  ///Remembers which Gnome::Canvas::Item was pressed.
    6.60 +  ///this variable is needed, because
    6.61 +  ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
    6.62 +  ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
    6.63 +  Gnome::Canvas::Item * active_item;
    6.64 +
    6.65 +
    6.66 +};
    6.67 +
    6.68 +#endif //GRAPH_DISPLAYER_CANVAS_H
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/gui/graphocska.lgf	Wed May 11 16:55:18 2005 +0000
     7.3 @@ -0,0 +1,39 @@
     7.4 +@nodeset
     7.5 +id	coordinates_x	coordinates_y data
     7.6 +1	230	-80	1
     7.7 +2	230	100	3
     7.8 +3	120	-80	5
     7.9 +4	120	100	7
    7.10 +5	20	100	9
    7.11 +6	20	-80	11
    7.12 +7	-40	10	13
    7.13 +8	-100	100	15
    7.14 +9	-100	10	17
    7.15 +10	-100	-80	19
    7.16 +11	-200	-80	21
    7.17 +12	-200	10	23
    7.18 +13	-200	100	25
    7.19 +14	-300	100	27
    7.20 +15	-300	-80	29
    7.21 +
    7.22 +@edgeset
    7.23 +	        cap	map1	map2	map3	map4
    7.24 +15	14	1	21	111	231	3
    7.25 +14	13	2	22	112	232	6
    7.26 +13	12	3	23	113	233	9
    7.27 +13	8	4	24	114	234	12
    7.28 +12	11	5	25	115	235	15
    7.29 +12	9	6	26	116	236	18
    7.30 +11	10	7	27	117	237	21
    7.31 +10	9	8	28	118	238	24
    7.32 +10	7	9	29	119	239	27
    7.33 +9	8	10	30	120	230	30
    7.34 +7	6	11	31	121	241	33
    7.35 +6	5	12	32	122	242	36
    7.36 +6	3	13	33	123	243	39
    7.37 +5	4	14	34	124	244	42
    7.38 +4	3	15	35	125	245	45
    7.39 +3	2	16	36	126	246	48
    7.40 +2	1	17	37	127	247	51
    7.41 +
    7.42 +@end
    7.43 \ No newline at end of file
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/gui/main_win.cc	Wed May 11 16:55:18 2005 +0000
     8.3 @@ -0,0 +1,69 @@
     8.4 +#include <main_win.h>
     8.5 +
     8.6 +MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm, MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms)
     8.7 +{
     8.8 +  set_title (title);
     8.9 +  set_default_size(WIN_WIDTH,WIN_HEIGHT);
    8.10 +  add(vbox);
    8.11 +
    8.12 +  ag=Gtk::ActionGroup::create();
    8.13 +  ag->add( Gtk::Action::create("ShowMenu", "_Show") );
    8.14 +  ag->add( Gtk::Action::create("ShowMaps", "_Maps"), sigc::mem_fun(*this, &MainWin::showMaps));
    8.15 +  ag->add( Gtk::Action::create("FileMenu", "_File") );
    8.16 +  ag->add( Gtk::Action::create("FileQuit", "_Quit"), sigc::mem_fun(*this, &MainWin::quit));
    8.17 +  ag->add( Gtk::Action::create("ZoomMenu", "_Zoom") );
    8.18 +  ag->add( Gtk::Action::create("ZoomRezoom", "_Rezoom"), sigc::mem_fun(*this, &MainWin::rezoom)); //!!!!!!
    8.19 +
    8.20 +  uim=Gtk::UIManager::create();
    8.21 +  uim->insert_action_group(ag);
    8.22 +  add_accel_group(uim->get_accel_group());
    8.23 +
    8.24 +  try
    8.25 +  {
    8.26 +
    8.27 +    Glib::ustring ui_info =
    8.28 +      "<ui>"
    8.29 +      "  <menubar name='MenuBar'>"
    8.30 +      "    <menu action='FileMenu'>"
    8.31 +      "      <menuitem action='FileQuit'/>"
    8.32 +      "    </menu>"
    8.33 +      "    <menu action='ShowMenu'>"
    8.34 +      "      <menuitem action='ShowMaps'/>"
    8.35 +      "    </menu>"
    8.36 +      "    <menu action='ZoomMenu'>"
    8.37 +      "      <menuitem action='ZoomRezoom'/>"
    8.38 +      "    </menu>"
    8.39 +      "  </menubar>"
    8.40 +      "</ui>";
    8.41 +
    8.42 +    uim->add_ui_from_string(ui_info);
    8.43 +
    8.44 +  }
    8.45 +  catch(const Glib::Error& ex)
    8.46 +  {
    8.47 +    std::cerr << "building menus failed: " <<  ex.what();
    8.48 +  }
    8.49 +
    8.50 +  Gtk::Widget* menubar = uim->get_widget("/MenuBar");
    8.51 +  if(menubar)vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
    8.52 +
    8.53 +  vbox.pack_start(gd_canvas);
    8.54 +
    8.55 +  show_all_children();
    8.56 +}
    8.57 +
    8.58 +void MainWin::showMaps()
    8.59 +{
    8.60 +  mapwin.show();
    8.61 +}
    8.62 +
    8.63 +void MainWin::quit()
    8.64 +{
    8.65 +  hide();
    8.66 +}
    8.67 +
    8.68 +void MainWin::rezoom()
    8.69 +{
    8.70 +  gd_canvas.rezoom();
    8.71 +}
    8.72 +
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/gui/main_win.h	Wed May 11 16:55:18 2005 +0000
     9.3 @@ -0,0 +1,44 @@
     9.4 +// -*- C++ -*- //
     9.5 +
     9.6 +#ifndef MAIN_WIN_H
     9.7 +#define MAIN_WIN_H
     9.8 +
     9.9 +#include <all_include.h>
    9.10 +#include <mapstorage.h>
    9.11 +#include <map_win.h>
    9.12 +#include <libgnomecanvasmm.h>
    9.13 +#include <libgnomecanvasmm/polygon.h>
    9.14 +
    9.15 +class MainWin : public Gtk::Window
    9.16 +{
    9.17 +public:
    9.18 +  MainWin(const std::string& title, Graph &, CoordinatesMap &, MapStorage &);
    9.19 +
    9.20 +protected:
    9.21 +  //Window of map-showing setup
    9.22 +  MapWin mapwin;
    9.23 +
    9.24 +  //Member widgets:
    9.25 +  GraphDisplayerCanvas gd_canvas;
    9.26 +
    9.27 +  //ActionGroup for menu
    9.28 +  Glib::RefPtr<Gtk::ActionGroup> ag;
    9.29 +
    9.30 +  //UIManager for menu
    9.31 +  Glib::RefPtr<Gtk::UIManager> uim;
    9.32 +
    9.33 +  //Container
    9.34 +  Gtk::VBox vbox;
    9.35 +
    9.36 +  //Pops up map-setup window
    9.37 +  virtual void showMaps();
    9.38 +
    9.39 +  //Exit
    9.40 +  virtual void quit();
    9.41 +
    9.42 +  //Refit screen
    9.43 +  virtual void rezoom();
    9.44 +
    9.45 +};
    9.46 +
    9.47 +#endif //MAIN_WIN_H
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/gui/map_win.cc	Wed May 11 16:55:18 2005 +0000
    10.3 @@ -0,0 +1,116 @@
    10.4 +#include <map_win.h>
    10.5 +#include <set>
    10.6 +
    10.7 +MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst)
    10.8 +{
    10.9 +  set_title(title);
   10.10 +  set_default_size(400, 200);
   10.11 +
   10.12 +  rb_array=new Gtk::RadioButton * [PROPERTY_NUM];
   10.13 +  vbox_r1=new Gtk::VBox[PROPERTY_NUM];
   10.14 +  vbox_r2=new Gtk::VBox[PROPERTY_NUM];
   10.15 +  radios=new Gtk::HBox[PROPERTY_NUM];
   10.16 +  for(int i=0;i<PROPERTY_NUM;i++)
   10.17 +  {
   10.18 +    rb_array[i]=new Gtk::RadioButton[ms.numOfEdgeMaps()+1];
   10.19 +
   10.20 +    Gtk::RadioButton::Group group;
   10.21 +
   10.22 +    std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
   10.23 +    std::set<int> props;
   10.24 +
   10.25 +    int actprop;
   10.26 +    for(int j=0;j<ms.numOfEdgeMaps();j++)
   10.27 +    {
   10.28 +
   10.29 +      if(emsi->second==&(ms.default_edgemaps[i]))
   10.30 +      {
   10.31 +	actprop=j;
   10.32 +      }
   10.33 +      for(int k=0;k<PROPERTY_NUM;k++)
   10.34 +      {
   10.35 +	if(emsi->second==&(ms.default_edgemaps[k]))
   10.36 +	{
   10.37 +	  props.insert(j);
   10.38 +	}
   10.39 +      }
   10.40 +      emsi++;
   10.41 +    }
   10.42 +
   10.43 +    rb_array[i][0].set_group(group);
   10.44 +    rb_array[i][0].set_label("Default");
   10.45 +    rb_array[i][0].signal_clicked().connect( sigc::bind( sigc::bind( sigc::mem_fun(*this, &MapWin::radio_click), 0), i) );
   10.46 +    vbox_r1[i].pack_start(rb_array[i][0]);
   10.47 +
   10.48 +
   10.49 +    emsi=ms.beginOfEdgeMaps();
   10.50 +    int actpos=1;
   10.51 +    for(int j=0;j<ms.numOfEdgeMaps();j++)
   10.52 +    {
   10.53 +      if( ( props.find(j) )==( props.end() ) )
   10.54 +      {
   10.55 +	rb_array[i][actpos].set_group(group);
   10.56 +	rb_array[i][actpos].set_label(emsi->first);
   10.57 +	rb_array[i][actpos].signal_clicked().connect
   10.58 +	  (
   10.59 +	   sigc::bind( 
   10.60 +	    sigc::bind(
   10.61 +	     sigc::mem_fun(*this, &MapWin::radio_click),
   10.62 +	     actpos
   10.63 +	    ),
   10.64 +	    i
   10.65 +	   ) 
   10.66 +	  );
   10.67 +
   10.68 +    	if(actpos<(ms.numOfEdgeMaps()-PROPERTY_NUM+1)/2)
   10.69 +        {
   10.70 +          vbox_r1[i].pack_start(rb_array[i][actpos]);
   10.71 +	}
   10.72 +	else
   10.73 +        {
   10.74 +	  vbox_r2[i].pack_start(rb_array[i][actpos]);
   10.75 +	}
   10.76 +	actpos++;
   10.77 +      }
   10.78 +      emsi++;
   10.79 +    }
   10.80 +    radios[i].pack_start(vbox_r1[i]);
   10.81 +    radios[i].pack_start(vbox_r2[i]);
   10.82 +    notebook.append_page(radios[i], property_strings[i]);
   10.83 +  }
   10.84 +
   10.85 +  add(vbox_b);
   10.86 +  vbox_b.pack_start(notebook);
   10.87 +
   10.88 +  show_all_children();
   10.89 +
   10.90 +}
   10.91 +
   10.92 +void MapWin::radio_click(int prop, int actpos)
   10.93 +{
   10.94 +  if(rb_array[prop][actpos].get_active())
   10.95 +  {
   10.96 +
   10.97 +    std::string mapname=rb_array[prop][actpos].get_label();
   10.98 +
   10.99 +    if(mapname=="Default")
  10.100 +    {
  10.101 +      mapname=property_strings[prop];
  10.102 +    }
  10.103 +
  10.104 +    switch(prop)
  10.105 +    {
  10.106 +      case WIDTH:
  10.107 +        gdc.changeLineWidth(mapname);
  10.108 +        break;
  10.109 +      case COLOR:
  10.110 +        gdc.changeColor(mapname);
  10.111 +        break;
  10.112 +      case TEXT:
  10.113 +        gdc.changeText(mapname);
  10.114 +        break;
  10.115 +      default:
  10.116 +        std::cout<<"Error\n";
  10.117 +    }
  10.118 +  }
  10.119 +};
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/gui/map_win.h	Wed May 11 16:55:18 2005 +0000
    11.3 @@ -0,0 +1,30 @@
    11.4 +// -*- C++ -*- //
    11.5 +
    11.6 +#ifndef MAP_WIN_H
    11.7 +#define MAP_WIN_H
    11.8 +
    11.9 +#include <all_include.h>
   11.10 +#include <mapstorage.h>
   11.11 +#include <graph_displayer_canvas.h>
   11.12 +#include <libgnomecanvasmm.h>
   11.13 +#include <libgnomecanvasmm/polygon.h>
   11.14 +
   11.15 +class MapWin : public Gtk::Window
   11.16 +{
   11.17 +protected:
   11.18 +  GraphDisplayerCanvas & gdc;
   11.19 +  MapStorage & ms;
   11.20 +
   11.21 +  Gtk::HBox * radios;
   11.22 +  Gtk::RadioButton ** rb_array;
   11.23 +
   11.24 +  Gtk::VBox vbox_b, * vbox_r1, * vbox_r2;
   11.25 +  Gtk::Notebook notebook;
   11.26 +  Gtk::Label * labels;
   11.27 +
   11.28 +public:
   11.29 +  MapWin(const std::string& title, MapStorage &, GraphDisplayerCanvas &);
   11.30 +  virtual void radio_click(int, int);
   11.31 +};
   11.32 +
   11.33 +#endif //MAP_WIN_H
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/gui/mapstorage.cc	Wed May 11 16:55:18 2005 +0000
    12.3 @@ -0,0 +1,89 @@
    12.4 +#include <mapstorage.h>
    12.5 +
    12.6 +MapStorage::MapStorage(Graph & graph):g(graph)
    12.7 +{
    12.8 +  for(int i=0;i<PROPERTY_NUM;i++)
    12.9 +  {
   12.10 +    Graph::EdgeMap<double> emd(g);
   12.11 +    default_edgemaps.push_back(emd);
   12.12 +    Graph::NodeMap<double> nmd(g);
   12.13 +    default_nodemaps.push_back(nmd);
   12.14 +  }
   12.15 +
   12.16 +  //std::string defaultstr="Default ";
   12.17 +  for(int i=0;i<PROPERTY_NUM;i++)
   12.18 +  {
   12.19 +      for (EdgeIt j(g); j!=INVALID; ++j)
   12.20 +      {
   12.21 +	(default_edgemaps[i])[j]=property_defaults[i];
   12.22 +      }
   12.23 +      addEdgeMap(property_strings[i],&(default_edgemaps[i]));
   12.24 +  }
   12.25 +
   12.26 +};
   12.27 +
   12.28 +int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap)
   12.29 +{
   12.30 +  nodemap_storage[name]=nodemap;
   12.31 +  return 0;
   12.32 +}
   12.33 +int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap)
   12.34 +{
   12.35 +  edgemap_storage[name]=edgemap;
   12.36 +  return 0;
   12.37 +}
   12.38 +
   12.39 +double MapStorage::maxOfNodeMap(const std::string & name)
   12.40 +{
   12.41 +  double max=0;
   12.42 +  for (NodeIt j(g); j!=INVALID; ++j)
   12.43 +  {
   12.44 +    if( (*nodemap_storage[name])[j]>max )
   12.45 +    {
   12.46 +      max=(*nodemap_storage[name])[j];
   12.47 +    }
   12.48 +  }
   12.49 +  return max;
   12.50 +}
   12.51 +
   12.52 +double MapStorage::maxOfEdgeMap(const std::string & name)
   12.53 +{
   12.54 +  double max=0;
   12.55 +  for (EdgeIt j(g); j!=INVALID; ++j)
   12.56 +  {
   12.57 +    if( (*edgemap_storage[name])[j]>max )
   12.58 +    {
   12.59 +      max=(*edgemap_storage[name])[j];
   12.60 +    }
   12.61 +  }
   12.62 +  return max;
   12.63 +}
   12.64 +
   12.65 +double MapStorage::minOfNodeMap(const std::string & name)
   12.66 +{
   12.67 +  NodeIt j(g);
   12.68 +  double min=(*nodemap_storage[name])[j];
   12.69 +  for (; j!=INVALID; ++j)
   12.70 +  {
   12.71 +    if( (*nodemap_storage[name])[j]<min )
   12.72 +    {
   12.73 +      min=(*nodemap_storage[name])[j];
   12.74 +    }
   12.75 +  }
   12.76 +  return min;
   12.77 +}
   12.78 +
   12.79 +double MapStorage::minOfEdgeMap(const std::string & name)
   12.80 +{
   12.81 +  EdgeIt j(g);
   12.82 +  double min=(*edgemap_storage[name])[j];
   12.83 +  for (EdgeIt j(g); j!=INVALID; ++j)
   12.84 +  {
   12.85 +    if( (*edgemap_storage[name])[j]<min )
   12.86 +    {
   12.87 +      min=(*edgemap_storage[name])[j];
   12.88 +    }
   12.89 +  }
   12.90 +  return min;
   12.91 +}
   12.92 +
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/gui/mapstorage.h	Wed May 11 16:55:18 2005 +0000
    13.3 @@ -0,0 +1,37 @@
    13.4 +// -*- C++ -*- //
    13.5 +
    13.6 +#ifndef MAPSTORAGE_H
    13.7 +#define MAPSTORAGE_H
    13.8 +
    13.9 +#include <all_include.h>
   13.10 +
   13.11 +class MapStorage
   13.12 +{
   13.13 +
   13.14 +public: ///!!!!!!!!
   13.15 +  Graph g;
   13.16 +  std::map< std::string,Graph::NodeMap<double> * > nodemap_storage;
   13.17 +  std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage;
   13.18 +
   13.19 +  std::vector<Graph::NodeMap<double> > default_nodemaps;
   13.20 +  std::vector<Graph::EdgeMap<double> > default_edgemaps;
   13.21 +
   13.22 +public:
   13.23 +  MapStorage(Graph &);
   13.24 +  int addNodeMap(const std::string &,Graph::NodeMap<double> *);
   13.25 +  int addEdgeMap(const std::string &,Graph::EdgeMap<double> *);
   13.26 +
   13.27 +  int numOfNodeMaps() {return nodemap_storage.size();};
   13.28 +  int numOfEdgeMaps() {return edgemap_storage.size();};
   13.29 +
   13.30 +  double maxOfNodeMap(const std::string &);
   13.31 +  double maxOfEdgeMap(const std::string &);
   13.32 +
   13.33 +  double minOfNodeMap(const std::string &);
   13.34 +  double minOfEdgeMap(const std::string &);
   13.35 +
   13.36 +  std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};
   13.37 +  std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};
   13.38 +};
   13.39 +
   13.40 +#endif //MAPSTORAGE_H
    14.1 --- a/src/gui/src/Makefile.am	Wed May 11 13:49:17 2005 +0000
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,6 +0,0 @@
    14.4 -AM_CPPFLAGS = -I$(top_srcdir)/src
    14.5 -LDADD = $(top_builddir)/src/lemon/libemon.la
    14.6 -
    14.7 -bin_PROGRAMS = gui
    14.8 -
    14.9 -gui_SOURCES = main.cc
    15.1 --- a/src/gui/src/main.cc	Wed May 11 13:49:17 2005 +0000
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,10 +0,0 @@
    15.4 -#ifdef HAVE_CONFIG_H
    15.5 -#include <config.h>
    15.6 -#endif
    15.7 -
    15.8 -#include <iostream>
    15.9 -
   15.10 -int main()
   15.11 -{
   15.12 -  std::cout << "Hello World!" << std::endl;
   15.13 -}