gui/graph_displayer_canvas.cc
changeset 1849 a4d1362397fe
parent 1837 8dd6160ff699
child 1860 27a9a75b957b
equal deleted inserted replaced
34:57211cc072cc 35:582c0a680fa5
     1 #include "graph_displayer_canvas.h"
     1 #include "graph_displayer_canvas.h"
     2 #include <cmath>
     2 #include <cmath>
     3 
     3 
     4 GraphDisplayerCanvas::GraphDisplayerCanvas(MainWin & mainw) :
     4 GraphDisplayerCanvas::GraphDisplayerCanvas(NoteBookTab & mainw) :
     5   nodesmap(mainw.mapstorage.graph), edgesmap(mainw.mapstorage.graph), edgetextmap(mainw.mapstorage.graph),
     5   nodesmap(mainw.mapstorage.graph), edgesmap(mainw.mapstorage.graph), edgetextmap(mainw.mapstorage.graph),
     6   nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0),
     6   nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0),
     7   isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
     7   isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
     8   edgemap_to_edit(""), mainwin(mainw)
     8   edgemap_to_edit(""), mytab(mainw)
     9 {
     9 {
    10   //base event handler is move tool
    10   //base event handler is move tool
    11   actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
    11   actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
    12   actual_tool=MOVE;
    12   actual_tool=MOVE;
    13 
    13 
    16   forming_edge=INVALID;
    16   forming_edge=INVALID;
    17 }
    17 }
    18 
    18 
    19 GraphDisplayerCanvas::~GraphDisplayerCanvas()
    19 GraphDisplayerCanvas::~GraphDisplayerCanvas()
    20 {
    20 {
    21   for (NodeIt n((mainwin.mapstorage).graph); n != INVALID; ++n)
    21   for (NodeIt n((mytab.mapstorage).graph); n != INVALID; ++n)
    22     {
    22     {
    23       delete nodesmap[n];
    23       delete nodesmap[n];
    24       delete nodetextmap[n];
    24       delete nodetextmap[n];
    25     }
    25     }
    26   
    26   
    27   for (EdgeIt e((mainwin.mapstorage).graph); e != INVALID; ++e)
    27   for (EdgeIt e((mytab.mapstorage).graph); e != INVALID; ++e)
    28     {
    28     {
    29       delete edgesmap[e];
    29       delete edgesmap[e];
    30       delete edgetextmap[e];
    30       delete edgetextmap[e];
    31     }
    31     }
    32 }
    32 }
    61 
    61 
    62 void GraphDisplayerCanvas::propertyUpdate(Node node, int prop, int dummy)
    62 void GraphDisplayerCanvas::propertyUpdate(Node node, int prop, int dummy)
    63 {
    63 {
    64   dummy=dummy;
    64   dummy=dummy;
    65 
    65 
    66   std::string mapname=mainwin.getActiveNodeMap(prop);
    66   std::string mapname=mytab.getActiveNodeMap(prop);
    67 
    67 
    68   if(mapname!="")
    68   if(mapname!="")
    69     {
    69     {
    70       if( ( ((mainwin.mapstorage).nodemap_storage).find(mapname) != ((mainwin.mapstorage).nodemap_storage).end() ) )
    70       if( ( ((mytab.mapstorage).nodemap_storage).find(mapname) != ((mytab.mapstorage).nodemap_storage).end() ) )
    71 	{
    71 	{
    72 	  switch(prop)
    72 	  switch(prop)
    73 	    {
    73 	    {
    74 	    case N_RADIUS:
    74 	    case N_RADIUS:
    75 	      changeNodeRadius(mapname, node);
    75 	      changeNodeRadius(mapname, node);
   108 
   108 
   109 void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop, int dummy)
   109 void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop, int dummy)
   110 {
   110 {
   111   dummy=dummy;
   111   dummy=dummy;
   112 
   112 
   113   std::string mapname=mainwin.getActiveEdgeMap(prop);
   113   std::string mapname=mytab.getActiveEdgeMap(prop);
   114 
   114 
   115   if(mapname!="")
   115   if(mapname!="")
   116     {
   116     {
   117       if( ( ((mainwin.mapstorage).edgemap_storage).find(mapname) != ((mainwin.mapstorage).edgemap_storage).end() ) )
   117       if( ( ((mytab.mapstorage).edgemap_storage).find(mapname) != ((mytab.mapstorage).edgemap_storage).end() ) )
   118 	{
   118 	{
   119 	  switch(prop)
   119 	  switch(prop)
   120 	    {
   120 	    {
   121 	    case E_WIDTH:
   121 	    case E_WIDTH:
   122 	      changeEdgeWidth(mapname, edge);
   122 	      changeEdgeWidth(mapname, edge);
   153 
   153 
   154 void GraphDisplayerCanvas::drawGraph()
   154 void GraphDisplayerCanvas::drawGraph()
   155 {
   155 {
   156   //first edges are drawn, to hide joining with nodes later
   156   //first edges are drawn, to hide joining with nodes later
   157 
   157 
   158   for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
   158   for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   159   {
   159   {
   160 
   160 
   161     //drawing green lines, coordinates are from mapstorage.coords
   161     //drawing green lines, coordinates are from mapstorage.coords
   162 
   162 
   163     Gnome::Canvas::Points coos;
   163     Gnome::Canvas::Points coos;
   164     coos.push_back(Gnome::Art::Point(
   164     coos.push_back(Gnome::Art::Point(
   165           (mainwin.mapstorage).coords[(mainwin.mapstorage).graph.source(i)].x,
   165           (mytab.mapstorage).coords[(mytab.mapstorage).graph.source(i)].x,
   166           (mainwin.mapstorage).coords[(mainwin.mapstorage).graph.source(i)].y));
   166           (mytab.mapstorage).coords[(mytab.mapstorage).graph.source(i)].y));
   167     coos.push_back(Gnome::Art::Point(
   167     coos.push_back(Gnome::Art::Point(
   168           (mainwin.mapstorage).coords[(mainwin.mapstorage).graph.target(i)].x,
   168           (mytab.mapstorage).coords[(mytab.mapstorage).graph.target(i)].x,
   169           (mainwin.mapstorage).coords[(mainwin.mapstorage).graph.target(i)].y));
   169           (mytab.mapstorage).coords[(mytab.mapstorage).graph.target(i)].y));
   170     
   170     
   171     edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
   171     edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
   172     *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
   172     *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
   173     edgesmap[i]->property_width_units().set_value(10);    
   173     edgesmap[i]->property_width_units().set_value(10);    
   174     edgesmap[i]->lower_to_bottom();
   174     edgesmap[i]->lower_to_bottom();
   184     edgetextmap[i]->raise_to_top();
   184     edgetextmap[i]->raise_to_top();
   185   }
   185   }
   186 
   186 
   187   //afterwards nodes come to be drawn
   187   //afterwards nodes come to be drawn
   188 
   188 
   189   for (NodeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
   189   for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   190   {
   190   {
   191     //drawing bule nodes, with black line around them
   191     //drawing bule nodes, with black line around them
   192 
   192 
   193     nodesmap[i]=new Gnome::Canvas::Ellipse(
   193     nodesmap[i]=new Gnome::Canvas::Ellipse(
   194         displayed_graph,
   194         displayed_graph,
   195         (mainwin.mapstorage).coords[i].x-20,
   195         (mytab.mapstorage).coords[i].x-20,
   196         (mainwin.mapstorage).coords[i].y-20,
   196         (mytab.mapstorage).coords[i].y-20,
   197         (mainwin.mapstorage).coords[i].x+20,
   197         (mytab.mapstorage).coords[i].x+20,
   198         (mainwin.mapstorage).coords[i].y+20);
   198         (mytab.mapstorage).coords[i].y+20);
   199     *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
   199     *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
   200     *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
   200     *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
   201     nodesmap[i]->raise_to_top();
   201     nodesmap[i]->raise_to_top();
   202 
   202 
   203     //initializing edge-text as well, to empty string
   203     //initializing edge-text as well, to empty string
   204 
   204 
   205     xy<double> text_pos(
   205     xy<double> text_pos(
   206         ((mainwin.mapstorage).coords[i].x+node_property_defaults[N_RADIUS]+5),
   206         ((mytab.mapstorage).coords[i].x+node_property_defaults[N_RADIUS]+5),
   207         ((mainwin.mapstorage).coords[i].y+node_property_defaults[N_RADIUS]+5));
   207         ((mytab.mapstorage).coords[i].y+node_property_defaults[N_RADIUS]+5));
   208 
   208 
   209     nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
   209     nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
   210         text_pos.x, text_pos.y, "");
   210         text_pos.x, text_pos.y, "");
   211     nodetextmap[i]->property_fill_color().set_value("darkblue");
   211     nodetextmap[i]->property_fill_color().set_value("darkblue");
   212     nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
   212     nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
   220 {
   220 {
   221   active_node=INVALID;
   221   active_node=INVALID;
   222   active_edge=INVALID;
   222   active_edge=INVALID;
   223   forming_edge=INVALID;
   223   forming_edge=INVALID;
   224 
   224 
   225   for (NodeIt n((mainwin.mapstorage).graph); n != INVALID; ++n)
   225   for (NodeIt n((mytab.mapstorage).graph); n != INVALID; ++n)
   226   {
   226   {
   227     delete nodesmap[n];
   227     delete nodesmap[n];
   228     delete nodetextmap[n];
   228     delete nodetextmap[n];
   229   }
   229   }
   230 
   230 
   231   for (EdgeIt e((mainwin.mapstorage).graph); e != INVALID; ++e)
   231   for (EdgeIt e((mytab.mapstorage).graph); e != INVALID; ++e)
   232   {
   232   {
   233     delete edgesmap[e];
   233     delete edgesmap[e];
   234     delete edgetextmap[e];
   234     delete edgetextmap[e];
   235   }
   235   }
   236 }
   236 }