gui/graph_displayer_canvas.cc
changeset 1837 8dd6160ff699
parent 1819 fd82adfbe905
child 1849 a4d1362397fe
equal deleted inserted replaced
33:2ff39da36fa3 34:57211cc072cc
     1 #include "graph_displayer_canvas.h"
     1 #include "graph_displayer_canvas.h"
     2 #include <cmath>
     2 #include <cmath>
     3 
     3 
     4 GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw, Gtk::Window * mainwin) :
     4 GraphDisplayerCanvas::GraphDisplayerCanvas(MainWin & mainw) :
     5   nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph),
     5   nodesmap(mainw.mapstorage.graph), edgesmap(mainw.mapstorage.graph), edgetextmap(mainw.mapstorage.graph),
     6   nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0), mapstorage(ms),
     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(""), mapwin(mw)
     8   edgemap_to_edit(""), mainwin(mainw)
     9 {
     9 {
    10   parentwin=mainwin;
       
    11 
       
    12   //base event handler is move tool
    10   //base event handler is move tool
    13   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);
    14   actual_tool=MOVE;
    12   actual_tool=MOVE;
    15 
    13 
    16   active_node=INVALID;
    14   active_node=INVALID;
    18   forming_edge=INVALID;
    16   forming_edge=INVALID;
    19 }
    17 }
    20 
    18 
    21 GraphDisplayerCanvas::~GraphDisplayerCanvas()
    19 GraphDisplayerCanvas::~GraphDisplayerCanvas()
    22 {
    20 {
    23   for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
    21   for (NodeIt n((mainwin.mapstorage).graph); n != INVALID; ++n)
    24   {
    22     {
    25     delete nodesmap[n];
    23       delete nodesmap[n];
    26     delete nodetextmap[n];
    24       delete nodetextmap[n];
    27   }
    25     }
    28 
    26   
    29   for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
    27   for (EdgeIt e((mainwin.mapstorage).graph); e != INVALID; ++e)
    30   {
    28     {
    31     delete edgesmap[e];
    29       delete edgesmap[e];
    32     delete edgetextmap[e];
    30       delete edgetextmap[e];
    33   }
    31     }
       
    32 }
       
    33 
       
    34 void GraphDisplayerCanvas::propertyChange(bool itisedge, int prop)
       
    35 {
       
    36   if(itisedge)
       
    37     {
       
    38       propertyUpdate(Edge(INVALID), prop);
       
    39     }
       
    40   else
       
    41     {
       
    42       propertyUpdate(Node(INVALID), prop);
       
    43     }
       
    44 }
       
    45 
       
    46 void GraphDisplayerCanvas::propertyUpdate(Edge edge)
       
    47 {
       
    48   for(int i=0;i<EDGE_PROPERTY_NUM;i++)
       
    49     {
       
    50       propertyUpdate(edge, i);
       
    51     }
       
    52 }
       
    53 
       
    54 void GraphDisplayerCanvas::propertyUpdate(Node node)
       
    55 {
       
    56   for(int i=0;i<NODE_PROPERTY_NUM;i++)
       
    57     {
       
    58       propertyUpdate(node, i);
       
    59     }
       
    60 }
       
    61 
       
    62 void GraphDisplayerCanvas::propertyUpdate(Node node, int prop, int dummy)
       
    63 {
       
    64   dummy=dummy;
       
    65 
       
    66   std::string mapname=mainwin.getActiveNodeMap(prop);
       
    67 
       
    68   if(mapname!="")
       
    69     {
       
    70       if( ( ((mainwin.mapstorage).nodemap_storage).find(mapname) != ((mainwin.mapstorage).nodemap_storage).end() ) )
       
    71 	{
       
    72 	  switch(prop)
       
    73 	    {
       
    74 	    case N_RADIUS:
       
    75 	      changeNodeRadius(mapname, node);
       
    76 	      break;
       
    77 	    case N_COLOR:
       
    78 	      changeNodeColor(mapname, node);
       
    79 	      break;
       
    80 	    case N_TEXT:
       
    81 	      changeNodeText(mapname, node);
       
    82 	      break;
       
    83 	    default:
       
    84 	      std::cerr<<"Error\n";
       
    85 	    }
       
    86 	}
       
    87     }
       
    88   else //mapname==""
       
    89     {
       
    90       Node node=INVALID;	
       
    91       switch(prop)
       
    92 	{
       
    93 	case N_RADIUS:
       
    94 	  resetNodeRadius(node);
       
    95 	  break;
       
    96 	case N_COLOR:
       
    97 	  resetNodeColor(node);
       
    98 	  break;
       
    99 	case N_TEXT:
       
   100 	  resetNodeText(node);
       
   101 	  break;
       
   102 	default:
       
   103 	  std::cerr<<"Error\n";
       
   104 	}
       
   105     }
       
   106 
       
   107 }
       
   108 
       
   109 void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop, int dummy)
       
   110 {
       
   111   dummy=dummy;
       
   112 
       
   113   std::string mapname=mainwin.getActiveEdgeMap(prop);
       
   114 
       
   115   if(mapname!="")
       
   116     {
       
   117       if( ( ((mainwin.mapstorage).edgemap_storage).find(mapname) != ((mainwin.mapstorage).edgemap_storage).end() ) )
       
   118 	{
       
   119 	  switch(prop)
       
   120 	    {
       
   121 	    case E_WIDTH:
       
   122 	      changeEdgeWidth(mapname, edge);
       
   123 	      break;
       
   124 	    case E_COLOR:
       
   125 	      changeEdgeColor(mapname, edge);
       
   126 	      break;
       
   127 	    case E_TEXT:
       
   128 	      changeEdgeText(mapname, edge);
       
   129 	      break;
       
   130 	    default:
       
   131 	      std::cerr<<"Error\n";
       
   132 	    }
       
   133 	}
       
   134     }
       
   135   else //mapname==""
       
   136     {
       
   137       switch(prop)
       
   138 	{
       
   139 	case E_WIDTH:
       
   140 	  resetEdgeWidth(edge);
       
   141 	  break;
       
   142 	case E_COLOR:
       
   143 	  resetEdgeColor(edge);
       
   144 	  break;
       
   145 	case E_TEXT:
       
   146 	  resetEdgeText(edge);
       
   147 	  break;
       
   148 	default:
       
   149 	  std::cerr<<"Error\n";
       
   150 	}
       
   151     }
    34 }
   152 }
    35 
   153 
    36 void GraphDisplayerCanvas::drawGraph()
   154 void GraphDisplayerCanvas::drawGraph()
    37 {
   155 {
    38   //first edges are drawn, to hide joining with nodes later
   156   //first edges are drawn, to hide joining with nodes later
    39 
   157 
    40   for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
   158   for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
    41   {
   159   {
    42 
   160 
    43     //drawing green lines, coordinates are from mapstorage.coords
   161     //drawing green lines, coordinates are from mapstorage.coords
    44 
   162 
    45     Gnome::Canvas::Points coos;
   163     Gnome::Canvas::Points coos;
    46     coos.push_back(Gnome::Art::Point(
   164     coos.push_back(Gnome::Art::Point(
    47           mapstorage.coords[mapstorage.graph.source(i)].x,
   165           (mainwin.mapstorage).coords[(mainwin.mapstorage).graph.source(i)].x,
    48           mapstorage.coords[mapstorage.graph.source(i)].y));
   166           (mainwin.mapstorage).coords[(mainwin.mapstorage).graph.source(i)].y));
    49     coos.push_back(Gnome::Art::Point(
   167     coos.push_back(Gnome::Art::Point(
    50           mapstorage.coords[mapstorage.graph.target(i)].x,
   168           (mainwin.mapstorage).coords[(mainwin.mapstorage).graph.target(i)].x,
    51           mapstorage.coords[mapstorage.graph.target(i)].y));
   169           (mainwin.mapstorage).coords[(mainwin.mapstorage).graph.target(i)].y));
    52     
   170     
    53     edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
   171     edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
    54     *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
   172     *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
    55     edgesmap[i]->property_width_units().set_value(10);    
   173     edgesmap[i]->property_width_units().set_value(10);    
    56     edgesmap[i]->lower_to_bottom();
   174     edgesmap[i]->lower_to_bottom();
    66     edgetextmap[i]->raise_to_top();
   184     edgetextmap[i]->raise_to_top();
    67   }
   185   }
    68 
   186 
    69   //afterwards nodes come to be drawn
   187   //afterwards nodes come to be drawn
    70 
   188 
    71   for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   189   for (NodeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
    72   {
   190   {
    73     //drawing bule nodes, with black line around them
   191     //drawing bule nodes, with black line around them
    74 
   192 
    75     nodesmap[i]=new Gnome::Canvas::Ellipse(
   193     nodesmap[i]=new Gnome::Canvas::Ellipse(
    76         displayed_graph,
   194         displayed_graph,
    77         mapstorage.coords[i].x-20,
   195         (mainwin.mapstorage).coords[i].x-20,
    78         mapstorage.coords[i].y-20,
   196         (mainwin.mapstorage).coords[i].y-20,
    79         mapstorage.coords[i].x+20,
   197         (mainwin.mapstorage).coords[i].x+20,
    80         mapstorage.coords[i].y+20);
   198         (mainwin.mapstorage).coords[i].y+20);
    81     *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
   199     *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
    82     *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
   200     *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
    83     nodesmap[i]->raise_to_top();
   201     nodesmap[i]->raise_to_top();
    84 
   202 
    85     //initializing edge-text as well, to empty string
   203     //initializing edge-text as well, to empty string
    86 
   204 
    87     xy<double> text_pos(
   205     xy<double> text_pos(
    88         (mapstorage.coords[i].x+node_property_defaults[N_RADIUS]+5),
   206         ((mainwin.mapstorage).coords[i].x+node_property_defaults[N_RADIUS]+5),
    89         (mapstorage.coords[i].y+node_property_defaults[N_RADIUS]+5));
   207         ((mainwin.mapstorage).coords[i].y+node_property_defaults[N_RADIUS]+5));
    90 
   208 
    91     nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
   209     nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
    92         text_pos.x, text_pos.y, "");
   210         text_pos.x, text_pos.y, "");
    93     nodetextmap[i]->property_fill_color().set_value("darkblue");
   211     nodetextmap[i]->property_fill_color().set_value("darkblue");
    94     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);
   102 {
   220 {
   103   active_node=INVALID;
   221   active_node=INVALID;
   104   active_edge=INVALID;
   222   active_edge=INVALID;
   105   forming_edge=INVALID;
   223   forming_edge=INVALID;
   106 
   224 
   107   for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
   225   for (NodeIt n((mainwin.mapstorage).graph); n != INVALID; ++n)
   108   {
   226   {
   109     delete nodesmap[n];
   227     delete nodesmap[n];
   110     delete nodetextmap[n];
   228     delete nodetextmap[n];
   111   }
   229   }
   112 
   230 
   113   for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
   231   for (EdgeIt e((mainwin.mapstorage).graph); e != INVALID; ++e)
   114   {
   232   {
   115     delete edgesmap[e];
   233     delete edgesmap[e];
   116     delete edgetextmap[e];
   234     delete edgetextmap[e];
   117   }
   235   }
   118 }
   236 }