graph_displayer_canvas-event.cc
branchgui
changeset 96 e664d8aa3f72
parent 94 adfdc2f70548
child 98 f60f89147531
     1.1 --- a/graph_displayer_canvas-event.cc	Wed Nov 30 13:24:23 2005 +0000
     1.2 +++ b/graph_displayer_canvas-event.cc	Tue Dec 06 10:53:38 2005 +0000
     1.3 @@ -94,7 +94,7 @@
     1.4  
     1.5        active_item=(get_item_at(clicked_x, clicked_y));
     1.6        active_node=INVALID;
     1.7 -      for (NodeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
     1.8 +      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
     1.9  	{
    1.10  	  if(nodesmap[i]==active_item)
    1.11  	    {
    1.12 @@ -125,7 +125,7 @@
    1.13        //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
    1.14        if(active_node!=INVALID)
    1.15        {
    1.16 -        (mainwin.mapstorage).modified = true;
    1.17 +        (mytab.mapstorage).modified = true;
    1.18  
    1.19  	//new coordinates will be the old values,
    1.20  	//because the item will be moved to the
    1.21 @@ -144,52 +144,52 @@
    1.22  	nodetextmap[active_node]->move(dx, dy);
    1.23  
    1.24          // the new coordinates of the centre of the node 
    1.25 -        double coord_x = new_x - (clicked_x - (mainwin.mapstorage).coords[active_node].x);
    1.26 -        double coord_y = new_y - (clicked_y - (mainwin.mapstorage).coords[active_node].y);
    1.27 +        double coord_x = new_x - (clicked_x - (mytab.mapstorage).coords[active_node].x);
    1.28 +        double coord_y = new_y - (clicked_y - (mytab.mapstorage).coords[active_node].y);
    1.29  
    1.30          clicked_x=new_x;
    1.31          clicked_y=new_y;
    1.32  
    1.33          // write back the new coordinates to the coords map
    1.34 -        (mainwin.mapstorage).coords.set(active_node, xy<double>(coord_x, coord_y));
    1.35 +        (mytab.mapstorage).coords.set(active_node, xy<double>(coord_x, coord_y));
    1.36  
    1.37          // reposition the coordinates text
    1.38          std::ostringstream ostr;
    1.39          ostr << "(" <<
    1.40 -          (mainwin.mapstorage).coords[active_node].x << ", " <<
    1.41 -          (mainwin.mapstorage).coords[active_node].y << ")";
    1.42 +          (mytab.mapstorage).coords[active_node].x << ", " <<
    1.43 +          (mytab.mapstorage).coords[active_node].y << ")";
    1.44          double radius =
    1.45            (nodesmap[active_node]->property_x2().get_value() -
    1.46            nodesmap[active_node]->property_x1().get_value()) / 2.0;
    1.47          if (coord_text)
    1.48          {
    1.49            coord_text->property_text().set_value(ostr.str());
    1.50 -          coord_text->property_x().set_value((mainwin.mapstorage).coords[active_node].x +
    1.51 +          coord_text->property_x().set_value((mytab.mapstorage).coords[active_node].x +
    1.52                radius);
    1.53 -          coord_text->property_y().set_value((mainwin.mapstorage).coords[active_node].y -
    1.54 +          coord_text->property_y().set_value((mytab.mapstorage).coords[active_node].y -
    1.55                radius);
    1.56          }
    1.57          else
    1.58          {
    1.59            coord_text = new Gnome::Canvas::Text(
    1.60                displayed_graph,
    1.61 -              (mainwin.mapstorage).coords[active_node].x + radius,
    1.62 -              (mainwin.mapstorage).coords[active_node].y - radius,
    1.63 +              (mytab.mapstorage).coords[active_node].x + radius,
    1.64 +              (mytab.mapstorage).coords[active_node].y - radius,
    1.65                ostr.str());
    1.66            coord_text->property_fill_color().set_value("black");
    1.67            coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST);
    1.68          }
    1.69  
    1.70  	//all the edges connected to the moved point has to be redrawn
    1.71 -        for(OutEdgeIt ei((mainwin.mapstorage).graph,active_node);ei!=INVALID;++ei)
    1.72 +        for(OutEdgeIt ei((mytab.mapstorage).graph,active_node);ei!=INVALID;++ei)
    1.73          {
    1.74              Gnome::Canvas::Points coos;
    1.75              double x1, x2, y1, y2;
    1.76  
    1.77 -            nodesmap[(mainwin.mapstorage).graph.source(ei)]->get_bounds(x1, y1, x2, y2);
    1.78 +            nodesmap[(mytab.mapstorage).graph.source(ei)]->get_bounds(x1, y1, x2, y2);
    1.79              coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    1.80  
    1.81 -            nodesmap[(mainwin.mapstorage).graph.target(ei)]->get_bounds(x1, y1, x2, y2);
    1.82 +            nodesmap[(mytab.mapstorage).graph.target(ei)]->get_bounds(x1, y1, x2, y2);
    1.83              coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    1.84  
    1.85  	    if(isbutton==3)
    1.86 @@ -208,15 +208,15 @@
    1.87  	    edgetextmap[ei]->property_y().set_value(text_pos.y);
    1.88          }
    1.89  
    1.90 -        for(InEdgeIt ei((mainwin.mapstorage).graph,active_node);ei!=INVALID;++ei)
    1.91 +        for(InEdgeIt ei((mytab.mapstorage).graph,active_node);ei!=INVALID;++ei)
    1.92          {
    1.93              Gnome::Canvas::Points coos;
    1.94              double x1, x2, y1, y2;
    1.95  
    1.96 -            nodesmap[(mainwin.mapstorage).graph.source(ei)]->get_bounds(x1, y1, x2, y2);
    1.97 +            nodesmap[(mytab.mapstorage).graph.source(ei)]->get_bounds(x1, y1, x2, y2);
    1.98              coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    1.99  
   1.100 -            nodesmap[(mainwin.mapstorage).graph.target(ei)]->get_bounds(x1, y1, x2, y2);
   1.101 +            nodesmap[(mytab.mapstorage).graph.target(ei)]->get_bounds(x1, y1, x2, y2);
   1.102              coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   1.103  
   1.104  	    if(isbutton==3)
   1.105 @@ -256,33 +256,33 @@
   1.106        }
   1.107  
   1.108      case GDK_BUTTON_RELEASE:
   1.109 -      (mainwin.mapstorage).modified = true;
   1.110 +      (mytab.mapstorage).modified = true;
   1.111  
   1.112        isbutton=1;
   1.113  
   1.114 -      active_node=(mainwin.mapstorage).graph.addNode();
   1.115 +      active_node=(mytab.mapstorage).graph.addNode();
   1.116  
   1.117        //initiating values corresponding to new node in maps
   1.118  
   1.119        window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
   1.120  
   1.121        // update coordinates
   1.122 -      (mainwin.mapstorage).coords.set(active_node, xy<double>(clicked_x, clicked_y));
   1.123 +      (mytab.mapstorage).coords.set(active_node, xy<double>(clicked_x, clicked_y));
   1.124  
   1.125        // update all other maps
   1.126        for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
   1.127 -          (mainwin.mapstorage).nodemap_storage.begin(); it !=
   1.128 -          (mainwin.mapstorage).nodemap_storage.end(); ++it)
   1.129 +          (mytab.mapstorage).nodemap_storage.begin(); it !=
   1.130 +          (mytab.mapstorage).nodemap_storage.end(); ++it)
   1.131        {
   1.132          if ((it->first != "coordinates_x") &&
   1.133              (it->first != "coordinates_y"))
   1.134          {
   1.135            (*(it->second))[active_node] =
   1.136 -            (mainwin.mapstorage).nodemap_default[it->first];
   1.137 +            (mytab.mapstorage).nodemap_default[it->first];
   1.138          }
   1.139        }
   1.140        // increment the id map's default value
   1.141 -      (mainwin.mapstorage).nodemap_default["id"] += 1.0;
   1.142 +      (mytab.mapstorage).nodemap_default["id"] += 1.0;
   1.143  
   1.144        nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
   1.145            clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
   1.146 @@ -332,7 +332,7 @@
   1.147  
   1.148            active_item=(get_item_at(clicked_x, clicked_y));
   1.149            active_node=INVALID;
   1.150 -          for (NodeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
   1.151 +          for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   1.152            {
   1.153              if(nodesmap[i]==active_item)
   1.154              {
   1.155 @@ -361,7 +361,7 @@
   1.156            window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
   1.157            target_item=(get_item_at(clicked_x, clicked_y));
   1.158            Node target_node=INVALID;
   1.159 -          for (NodeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
   1.160 +          for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   1.161            {
   1.162              if(nodesmap[i]==target_item)
   1.163              {
   1.164 @@ -373,26 +373,26 @@
   1.165            {
   1.166              if(target_node!=active_node)		
   1.167              {
   1.168 -              (mainwin.mapstorage).modified = true;
   1.169 +              (mytab.mapstorage).modified = true;
   1.170  
   1.171                *(nodesmap[target_node]) <<
   1.172                  Gnome::Canvas::Properties::fill_color("red");
   1.173  
   1.174                //creating new edge
   1.175 -              active_edge=(mainwin.mapstorage).graph.addEdge(active_node,
   1.176 +              active_edge=(mytab.mapstorage).graph.addEdge(active_node,
   1.177                    target_node);
   1.178  
   1.179                // update maps
   1.180                for (std::map<std::string,
   1.181                    Graph::EdgeMap<double>*>::const_iterator it =
   1.182 -                  (mainwin.mapstorage).edgemap_storage.begin(); it !=
   1.183 -                  (mainwin.mapstorage).edgemap_storage.end(); ++it)
   1.184 +                  (mytab.mapstorage).edgemap_storage.begin(); it !=
   1.185 +                  (mytab.mapstorage).edgemap_storage.end(); ++it)
   1.186                {
   1.187                  (*(it->second))[active_edge] =
   1.188 -                  (mainwin.mapstorage).edgemap_default[it->first];
   1.189 +                  (mytab.mapstorage).edgemap_default[it->first];
   1.190                }
   1.191                // increment the id map's default value
   1.192 -              (mainwin.mapstorage).edgemap_default["id"] += 1.0;
   1.193 +              (mytab.mapstorage).edgemap_default["id"] += 1.0;
   1.194  
   1.195                //calculating coordinates of new edge
   1.196                Gnome::Canvas::Points coos;
   1.197 @@ -480,7 +480,7 @@
   1.198        active_node=INVALID;
   1.199        active_edge=INVALID;
   1.200        //was it a node?
   1.201 -      for (NodeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
   1.202 +      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   1.203  	{
   1.204  	  if(nodesmap[i]==active_item)
   1.205  	    {
   1.206 @@ -490,7 +490,7 @@
   1.207        //or was it an edge?
   1.208        if(active_node==INVALID)
   1.209  	{
   1.210 -	  for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
   1.211 +	  for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   1.212  	    {
   1.213  	      if(edgesmap[i]==active_item)
   1.214  		{
   1.215 @@ -516,16 +516,16 @@
   1.216  	      //a node was found
   1.217  	      if(active_node!=INVALID)
   1.218  		{
   1.219 -                  (mainwin.mapstorage).modified = true;
   1.220 +                  (mytab.mapstorage).modified = true;
   1.221  
   1.222  		  std::set<Graph::Edge> edges_to_delete;
   1.223  
   1.224 -		  for(OutEdgeIt e((mainwin.mapstorage).graph,active_node);e!=INVALID;++e)
   1.225 +		  for(OutEdgeIt e((mytab.mapstorage).graph,active_node);e!=INVALID;++e)
   1.226  		    {
   1.227  		      edges_to_delete.insert(e);
   1.228  		    }
   1.229  		  
   1.230 -		  for(InEdgeIt e((mainwin.mapstorage).graph,active_node);e!=INVALID;++e)
   1.231 +		  for(InEdgeIt e((mytab.mapstorage).graph,active_node);e!=INVALID;++e)
   1.232  		    {
   1.233  		      edges_to_delete.insert(e);
   1.234  		    }
   1.235 @@ -589,7 +589,7 @@
   1.236            active_item=(get_item_at(clicked_x, clicked_y));
   1.237  
   1.238            //find the activated item between texts
   1.239 -          for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
   1.240 +          for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   1.241            {
   1.242              //at the same time only one can be active
   1.243              if(edgetextmap[i]==active_item)
   1.244 @@ -601,7 +601,7 @@
   1.245            //if it was not between texts, search for it between edges
   1.246            if(clicked_edge==INVALID)
   1.247            {
   1.248 -            for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
   1.249 +            for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   1.250              {
   1.251                //at the same time only one can be active
   1.252                if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item))
   1.253 @@ -624,7 +624,7 @@
   1.254                active_edge=clicked_edge;
   1.255  
   1.256                //create a dialog
   1.257 -              Gtk::Dialog dialog("Edit value", mainwin, true);
   1.258 +              Gtk::Dialog dialog("Edit value", true);
   1.259                dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   1.260                dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
   1.261                Gtk::VBox* vbox = dialog.get_vbox();
   1.262 @@ -641,7 +641,7 @@
   1.263                    break;
   1.264                  case Gtk::RESPONSE_ACCEPT:
   1.265                    double new_value = spin.get_value();
   1.266 -                  (*(mainwin.mapstorage).edgemap_storage[edgemap_to_edit])[active_edge] =
   1.267 +                  (*(mytab.mapstorage).edgemap_storage[edgemap_to_edit])[active_edge] =
   1.268                      new_value;
   1.269                    std::ostringstream ostr;
   1.270                    ostr << new_value;
   1.271 @@ -677,7 +677,7 @@
   1.272            active_item=(get_item_at(clicked_x, clicked_y));
   1.273  
   1.274            //find the activated item between texts
   1.275 -          for (NodeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
   1.276 +          for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   1.277            {
   1.278              //at the same time only one can be active
   1.279              if(nodetextmap[i]==active_item)
   1.280 @@ -689,7 +689,7 @@
   1.281            //if there was not, search for it between nodes
   1.282            if(clicked_node==INVALID)
   1.283            {
   1.284 -            for (NodeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
   1.285 +            for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   1.286              {
   1.287                //at the same time only one can be active
   1.288                if(nodesmap[i]==active_item)
   1.289 @@ -712,7 +712,7 @@
   1.290                active_node=clicked_node;
   1.291  
   1.292                //create a dialog
   1.293 -              Gtk::Dialog dialog("Edit value", mainwin, true);
   1.294 +              Gtk::Dialog dialog("Edit value", true);
   1.295                dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   1.296                dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
   1.297                Gtk::VBox* vbox = dialog.get_vbox();
   1.298 @@ -729,7 +729,7 @@
   1.299                    break;
   1.300                  case Gtk::RESPONSE_ACCEPT:
   1.301                    double new_value = spin.get_value();
   1.302 -                  (*(mainwin.mapstorage).nodemap_storage[nodemap_to_edit])[active_node] =
   1.303 +                  (*(mytab.mapstorage).nodemap_storage[nodemap_to_edit])[active_node] =
   1.304                      new_value;
   1.305                    std::ostringstream ostr;
   1.306                    ostr << new_value;
   1.307 @@ -754,14 +754,14 @@
   1.308  {
   1.309    delete(nodetextmap[node_to_delete]);
   1.310    delete(nodesmap[node_to_delete]);
   1.311 -  (mainwin.mapstorage).graph.erase(node_to_delete);
   1.312 +  (mytab.mapstorage).graph.erase(node_to_delete);
   1.313  }
   1.314  
   1.315  void GraphDisplayerCanvas::deleteItem(Edge edge_to_delete)
   1.316  {
   1.317    delete(edgetextmap[edge_to_delete]);
   1.318    delete(edgesmap[edge_to_delete]);
   1.319 -  (mainwin.mapstorage).graph.erase(edge_to_delete);
   1.320 +  (mytab.mapstorage).graph.erase(edge_to_delete);
   1.321  }
   1.322  
   1.323  void GraphDisplayerCanvas::textReposition(xy<double> new_place)
   1.324 @@ -781,7 +781,7 @@
   1.325  	}
   1.326        else
   1.327  	{
   1.328 -	  for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
   1.329 +	  for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   1.330  	    {
   1.331  	      if(edgesmap[i]==active_bre)
   1.332  		{
   1.333 @@ -807,18 +807,18 @@
   1.334  int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname)
   1.335  {
   1.336    //create the new map
   1.337 -  Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> ((mainwin.mapstorage).graph, default_value);
   1.338 +  Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> ((mytab.mapstorage).graph, default_value);
   1.339  
   1.340    //if addition was not successful addEdgeMap returns one.
   1.341    //cause can be that there is already a map named like the new one
   1.342 -  if((mainwin.mapstorage).addEdgeMap(mapname,emptr, default_value))
   1.343 +  if((mytab.mapstorage).addEdgeMap(mapname,emptr, default_value))
   1.344      {
   1.345        return 1;
   1.346      }
   1.347  
   1.348  
   1.349    //add it to the list of the displayable maps
   1.350 -  mainwin.registerNewEdgeMap(mapname);
   1.351 +  mytab.registerNewEdgeMap(mapname);
   1.352  
   1.353    //display it
   1.354    changeEdgeText(mapname);
   1.355 @@ -829,17 +829,17 @@
   1.356  int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname)
   1.357  {
   1.358    //create the new map
   1.359 -  Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> ((mainwin.mapstorage).graph,default_value);
   1.360 +  Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> ((mytab.mapstorage).graph,default_value);
   1.361  
   1.362    //if addition was not successful addNodeMap returns one.
   1.363    //cause can be that there is already a map named like the new one
   1.364 -  if((mainwin.mapstorage).addNodeMap(mapname,emptr, default_value))
   1.365 +  if((mytab.mapstorage).addNodeMap(mapname,emptr, default_value))
   1.366      {
   1.367        return 1;
   1.368      }
   1.369  
   1.370    //add it to the list of the displayable maps
   1.371 -  mainwin.registerNewNodeMap(mapname);
   1.372 +  mytab.registerNewNodeMap(mapname);
   1.373  
   1.374    //display it
   1.375    changeNodeText(mapname);