- id maps are not editable
authorladanyi
Tue, 23 Aug 2005 07:36:09 +0000
changeset 16454a04bb856ac7
parent 1644 62548b317e65
child 1646 2dd083dded66
- id maps are not editable
- handle exceptions thrown by the file reader
- texts are always above the edges
- store a default value for all maps, so that edges and nodes created after
adding a new map receive the default value too
- create node on button release, not on click (fixes a few oddities)
gui/broken_edge.cc
gui/graph_displayer_canvas-edge.cc
gui/graph_displayer_canvas-event.cc
gui/graph_displayer_canvas.cc
gui/main_win.cc
gui/mapstorage.cc
gui/mapstorage.h
     1.1 --- a/gui/broken_edge.cc	Fri Aug 19 12:09:21 2005 +0000
     1.2 +++ b/gui/broken_edge.cc	Tue Aug 23 07:36:09 2005 +0000
     1.3 @@ -8,6 +8,7 @@
     1.4    arrow=new Gnome::Canvas::Polygon(g);
     1.5    *arrow << Gnome::Canvas::Properties::fill_color("red");
     1.6    arrow->signal_event().connect(sigc::mem_fun(*this, &BrokenEdge::edgeFormerEventHandler));
     1.7 +  arrow->lower_to_bottom();
     1.8    setPoints(p);
     1.9  }
    1.10  
     2.1 --- a/gui/graph_displayer_canvas-edge.cc	Fri Aug 19 12:09:21 2005 +0000
     2.2 +++ b/gui/graph_displayer_canvas-edge.cc	Tue Aug 23 07:36:09 2005 +0000
     2.3 @@ -122,7 +122,7 @@
     2.4    //EXCEPT when the name of the map is Default, because
     2.5    //in that case empty string will be written, because
     2.6    //that is the deleter map
     2.7 -
     2.8 +  
     2.9    if(edge==INVALID)
    2.10      {
    2.11        for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
     3.1 --- a/gui/graph_displayer_canvas-event.cc	Fri Aug 19 12:09:21 2005 +0000
     3.2 +++ b/gui/graph_displayer_canvas-event.cc	Tue Aug 23 07:36:09 2005 +0000
     3.3 @@ -214,13 +214,19 @@
     3.4  bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
     3.5  {
     3.6    switch(e->type)
     3.7 -    {
     3.8 +  {
     3.9 +    //move the new node
    3.10 +    case GDK_MOTION_NOTIFY:
    3.11 +      {
    3.12 +        GdkEvent * generated=new GdkEvent();
    3.13 +        generated->motion.x=e->motion.x;
    3.14 +        generated->motion.y=e->motion.y;
    3.15 +        generated->type=GDK_MOTION_NOTIFY;
    3.16 +        moveEventHandler(generated);      
    3.17 +        break;
    3.18 +      }
    3.19  
    3.20 -      //draw the new node in red at the clicked place
    3.21 -    case GDK_2BUTTON_PRESS:
    3.22 -      //std::cout << "double click" << std::endl;
    3.23 -      break;
    3.24 -    case GDK_BUTTON_PRESS:
    3.25 +    case GDK_BUTTON_RELEASE:
    3.26        mapstorage.modified = true;
    3.27  
    3.28        isbutton=1;
    3.29 @@ -231,183 +237,188 @@
    3.30  
    3.31        window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    3.32  
    3.33 +      // update coordinates
    3.34        mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
    3.35 +
    3.36 +      // update id map
    3.37        (*mapstorage.nodemap_storage["id"])[active_node] =
    3.38          mapstorage.graph.id(active_node);
    3.39  
    3.40 +      // update all other maps
    3.41 +      for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
    3.42 +          mapstorage.nodemap_storage.begin(); it !=
    3.43 +          mapstorage.nodemap_storage.end(); ++it)
    3.44 +      {
    3.45 +        if ((it->first != "id") &&
    3.46 +            (it->first != "coordinates_x") &&
    3.47 +            (it->first != "coordiantes_y"))
    3.48 +        {
    3.49 +          (*(it->second))[active_node] =
    3.50 +            mapstorage.nodemap_default[it->first];
    3.51 +        }
    3.52 +      }
    3.53 +
    3.54        nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
    3.55 -        clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
    3.56 +          clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
    3.57        active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
    3.58 -      *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
    3.59 -      *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
    3.60 +      *(nodesmap[active_node]) <<
    3.61 +        Gnome::Canvas::Properties::fill_color("blue");
    3.62 +      *(nodesmap[active_node]) <<
    3.63 +        Gnome::Canvas::Properties::outline_color("black");
    3.64 +      active_item->raise_to_top();
    3.65 +
    3.66        (nodesmap[active_node])->show();
    3.67  
    3.68        nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph,
    3.69 -        clicked_x+node_property_defaults[N_RADIUS]+5,
    3.70 -        clicked_y+node_property_defaults[N_RADIUS]+5, "");
    3.71 +          clicked_x+node_property_defaults[N_RADIUS]+5,
    3.72 +          clicked_y+node_property_defaults[N_RADIUS]+5, "");
    3.73        nodetextmap[active_node]->property_fill_color().set_value("darkblue");
    3.74 +      nodetextmap[active_node]->raise_to_top();
    3.75  
    3.76        mapwin.updateNode(active_node);
    3.77  
    3.78 -      break;
    3.79 -
    3.80 -      //move the new node
    3.81 -    case GDK_MOTION_NOTIFY:
    3.82 -      {
    3.83 -	GdkEvent * generated=new GdkEvent();
    3.84 -	generated->motion.x=e->motion.x;
    3.85 -	generated->motion.y=e->motion.y;
    3.86 -	generated->type=GDK_MOTION_NOTIFY;
    3.87 -	moveEventHandler(generated);      
    3.88 -	break;
    3.89 -      }
    3.90 -
    3.91 -      //finalize the new node
    3.92 -    case GDK_BUTTON_RELEASE:
    3.93 -      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    3.94 -
    3.95 -      active_item->lower_to_bottom();
    3.96 -
    3.97 -      target_item=NULL;
    3.98 -      target_item=get_item_at(clicked_x, clicked_y);
    3.99 -
   3.100 -      active_item->raise_to_top();
   3.101 -
   3.102        isbutton=0;
   3.103 -      if(target_item==active_item)
   3.104 -	{
   3.105 -	  //Its appropriate color is given by update.
   3.106 -	  *active_item << Gnome::Canvas::Properties::fill_color("blue");
   3.107 -	}
   3.108 -      else
   3.109 -	{
   3.110 -	  //In this case the given color has to be overwritten, because the noe covers an other item.
   3.111 -	  *active_item << Gnome::Canvas::Properties::fill_color("lightblue");
   3.112 -	}
   3.113        target_item=NULL;
   3.114        active_item=NULL;
   3.115        active_node=INVALID;
   3.116 +
   3.117        break;
   3.118      default:
   3.119        break;
   3.120 -    }
   3.121 +  }
   3.122    return false;
   3.123  }
   3.124  
   3.125  bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e)
   3.126  {
   3.127    switch(e->type)
   3.128 -    {
   3.129 +  {
   3.130      case GDK_BUTTON_PRESS:
   3.131        //in edge creation right button has special meaning
   3.132        if(e->button.button!=3)
   3.133 -	{
   3.134 -	  //there is not yet selected node
   3.135 -	  if(active_node==INVALID)
   3.136 -	    {
   3.137 -	      //we mark the location of the event to be able to calculate parameters of dragging
   3.138 +      {
   3.139 +        //there is not yet selected node
   3.140 +        if(active_node==INVALID)
   3.141 +        {
   3.142 +          //we mark the location of the event to be able to calculate parameters of dragging
   3.143  
   3.144 -	      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
   3.145 +          window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
   3.146  
   3.147 -	      active_item=(get_item_at(clicked_x, clicked_y));
   3.148 -	      active_node=INVALID;
   3.149 -	      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   3.150 -		{
   3.151 -		  if(nodesmap[i]==active_item)
   3.152 -		    {
   3.153 -		      active_node=i;
   3.154 -		    }
   3.155 -		}
   3.156 -	      //the clicked item is really a node
   3.157 -	      if(active_node!=INVALID)
   3.158 -		{
   3.159 -		  *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
   3.160 -		  isbutton=1;
   3.161 -		}
   3.162 -	      //clicked item was not a node. It could be e.g. edge.
   3.163 -	      else
   3.164 -		{
   3.165 -		  active_item=NULL;
   3.166 -		}
   3.167 -	    }
   3.168 -	  //we only have to do sg. if the mouse button
   3.169 -	  // is pressed already once AND the click was
   3.170 -	  // on a node that was found in the set of 
   3.171 -	  //nodes, and now we only search for the second 
   3.172 -	  //node
   3.173 -	  else
   3.174 -	    {
   3.175 -	      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
   3.176 -	      target_item=(get_item_at(clicked_x, clicked_y));
   3.177 -	      Node target_node=INVALID;
   3.178 -	      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   3.179 -		{
   3.180 -		  if(nodesmap[i]==target_item)
   3.181 -		    {
   3.182 -		      target_node=i;
   3.183 -		    }
   3.184 -		}
   3.185 -	      //the clicked item is a node, the edge can be drawn
   3.186 -	      if(target_node!=INVALID)
   3.187 -		{
   3.188 -		  if(target_node!=active_node)		
   3.189 -		    {
   3.190 -          mapstorage.modified = true;
   3.191 +          active_item=(get_item_at(clicked_x, clicked_y));
   3.192 +          active_node=INVALID;
   3.193 +          for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   3.194 +          {
   3.195 +            if(nodesmap[i]==active_item)
   3.196 +            {
   3.197 +              active_node=i;
   3.198 +            }
   3.199 +          }
   3.200 +          //the clicked item is really a node
   3.201 +          if(active_node!=INVALID)
   3.202 +          {
   3.203 +            *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
   3.204 +            isbutton=1;
   3.205 +          }
   3.206 +          //clicked item was not a node. It could be e.g. edge.
   3.207 +          else
   3.208 +          {
   3.209 +            active_item=NULL;
   3.210 +          }
   3.211 +        }
   3.212 +        //we only have to do sg. if the mouse button
   3.213 +        // is pressed already once AND the click was
   3.214 +        // on a node that was found in the set of 
   3.215 +        //nodes, and now we only search for the second 
   3.216 +        //node
   3.217 +        else
   3.218 +        {
   3.219 +          window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
   3.220 +          target_item=(get_item_at(clicked_x, clicked_y));
   3.221 +          Node target_node=INVALID;
   3.222 +          for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   3.223 +          {
   3.224 +            if(nodesmap[i]==target_item)
   3.225 +            {
   3.226 +              target_node=i;
   3.227 +            }
   3.228 +          }
   3.229 +          //the clicked item is a node, the edge can be drawn
   3.230 +          if(target_node!=INVALID)
   3.231 +          {
   3.232 +            if(target_node!=active_node)		
   3.233 +            {
   3.234 +              mapstorage.modified = true;
   3.235  
   3.236 -		      *(nodesmap[target_node]) <<
   3.237 -			Gnome::Canvas::Properties::fill_color("red");
   3.238 +              *(nodesmap[target_node]) <<
   3.239 +                Gnome::Canvas::Properties::fill_color("red");
   3.240  
   3.241 -		      //creating new edge
   3.242 -		      active_edge=mapstorage.graph.addEdge(active_node,
   3.243 -							   target_node);
   3.244 +              //creating new edge
   3.245 +              active_edge=mapstorage.graph.addEdge(active_node,
   3.246 +                  target_node);
   3.247  
   3.248 -		      //initiating values corresponding to new edge in maps
   3.249 -		      mapstorage.initMapsForEdge(active_edge);
   3.250 -                      (*mapstorage.edgemap_storage["id"])[active_edge] = 
   3.251 -			mapstorage.graph.id(active_edge);
   3.252 -	  
   3.253 -		      //calculating coordinates of new edge
   3.254 -		      Gnome::Canvas::Points coos;
   3.255 -		      double x1, x2, y1, y2;
   3.256 -	  
   3.257 -		      active_item->get_bounds(x1, y1, x2, y2);
   3.258 -		      coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   3.259 +              // update id map
   3.260 +              (*mapstorage.edgemap_storage["id"])[active_edge] = 
   3.261 +                mapstorage.graph.id(active_edge);
   3.262 + 
   3.263 +              // update all other maps
   3.264 +              for (std::map<std::string,
   3.265 +                  Graph::EdgeMap<double>*>::const_iterator it =
   3.266 +                  mapstorage.edgemap_storage.begin(); it !=
   3.267 +                  mapstorage.edgemap_storage.end(); ++it)
   3.268 +              {
   3.269 +                if (it->first != "id")
   3.270 +                {
   3.271 +                  (*(it->second))[active_edge] =
   3.272 +                    mapstorage.edgemap_default[it->first];
   3.273 +                }
   3.274 +              }
   3.275  
   3.276 -		      target_item->get_bounds(x1, y1, x2, y2);
   3.277 -		      coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   3.278 +              //calculating coordinates of new edge
   3.279 +              Gnome::Canvas::Points coos;
   3.280 +              double x1, x2, y1, y2;
   3.281  
   3.282 -		      //drawing new edge
   3.283 -		      edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this);
   3.284 -		      *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
   3.285 -		      edgesmap[active_edge]->property_width_pixels().set_value(10);
   3.286 +              active_item->get_bounds(x1, y1, x2, y2);
   3.287 +              coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   3.288  
   3.289 -		      //redraw nodes to blank terminations of the new edge
   3.290 -		      target_item->raise_to_top();
   3.291 -		      active_item->raise_to_top();
   3.292 +              target_item->get_bounds(x1, y1, x2, y2);
   3.293 +              coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   3.294  
   3.295 -		      //initializing edge-text as well, to empty string
   3.296 -		      xy<double> text_pos=edgesmap[active_edge]->getArrowPos();
   3.297 -		      text_pos+=(xy<double>(10,10));
   3.298 +              //drawing new edge
   3.299 +              edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos,
   3.300 +                  *this);
   3.301 +              *(edgesmap[active_edge]) <<
   3.302 +                Gnome::Canvas::Properties::fill_color("green");
   3.303 +              edgesmap[active_edge]->property_width_pixels().set_value(10);
   3.304  
   3.305 -		      edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
   3.306 -		      edgetextmap[active_edge]->property_fill_color().set_value("darkgreen");
   3.307 +              edgesmap[active_edge]->lower_to_bottom();
   3.308  
   3.309 -		      //updating its properties
   3.310 -		      mapwin.updateEdge(active_edge);
   3.311 -		    }
   3.312 -		  else
   3.313 -		    {
   3.314 -		      target_node=INVALID;
   3.315 -		      std::cerr << "Loop edge is not yet implemented!" << std::endl;
   3.316 -		    }
   3.317 -		}
   3.318 -	      //clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore.
   3.319 -	      else
   3.320 -		{
   3.321 -		  target_item=NULL;
   3.322 -		}
   3.323 -	    }
   3.324 -	}
   3.325 +              //initializing edge-text as well, to empty string
   3.326 +              xy<double> text_pos=edgesmap[active_edge]->getArrowPos();
   3.327 +              text_pos+=(xy<double>(10,10));
   3.328 +
   3.329 +              edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,
   3.330 +                  text_pos.x, text_pos.y, "");
   3.331 +              edgetextmap[active_edge]->property_fill_color().set_value(
   3.332 +                  "darkgreen");
   3.333 +              edgetextmap[active_edge]->raise_to_top();
   3.334 +
   3.335 +              //updating its properties
   3.336 +              mapwin.updateEdge(active_edge);
   3.337 +            }
   3.338 +            else
   3.339 +            {
   3.340 +              target_node=INVALID;
   3.341 +              std::cerr << "Loop edge is not yet implemented!" << std::endl;
   3.342 +            }
   3.343 +          }
   3.344 +          //clicked item was not a node. it could be an e.g. edge. we do not
   3.345 +          //deal with it furthermore.
   3.346 +          else
   3.347 +          {
   3.348 +            target_item=NULL;
   3.349 +          }
   3.350 +        }
   3.351 +      }
   3.352        break;
   3.353      case GDK_BUTTON_RELEASE:
   3.354        isbutton=0;
   3.355 @@ -415,24 +426,24 @@
   3.356        //1: the edge is ready (target_item has valid value)
   3.357        //2: the edge creation is cancelled with right button
   3.358        if((target_item)||(e->button.button==3))
   3.359 -	{
   3.360 -	  if(active_item)
   3.361 -	    {
   3.362 -	      *active_item << Gnome::Canvas::Properties::fill_color("blue");
   3.363 -	      active_item=NULL;
   3.364 -	    }
   3.365 -	  if(target_item)
   3.366 -	    {
   3.367 -	      *target_item << Gnome::Canvas::Properties::fill_color("blue");
   3.368 -	      target_item=NULL;
   3.369 -	    }
   3.370 -	  active_node=INVALID;
   3.371 -	  active_edge=INVALID;
   3.372 -	}
   3.373 +      {
   3.374 +        if(active_item)
   3.375 +        {
   3.376 +          *active_item << Gnome::Canvas::Properties::fill_color("blue");
   3.377 +          active_item=NULL;
   3.378 +        }
   3.379 +        if(target_item)
   3.380 +        {
   3.381 +          *target_item << Gnome::Canvas::Properties::fill_color("blue");
   3.382 +          target_item=NULL;
   3.383 +        }
   3.384 +        active_node=INVALID;
   3.385 +        active_edge=INVALID;
   3.386 +      }
   3.387        break;
   3.388      default:
   3.389        break;
   3.390 -    }
   3.391 +  }
   3.392    return false;
   3.393  }
   3.394  
   3.395 @@ -588,6 +599,8 @@
   3.396  	    //if it was really an edge...
   3.397  	    if(clicked_edge!=INVALID)
   3.398  	      {
   3.399 +                // the id map is not editable
   3.400 +                if (nodemap_to_edit == "id") return 0;
   3.401  		//If there is already edited edge, it has to be saved first
   3.402  		if(entrywidget.is_visible())
   3.403  		  {
   3.404 @@ -711,6 +724,8 @@
   3.405  	    //if it was really an edge...
   3.406  	    if(clicked_node!=INVALID)
   3.407  	      {
   3.408 +                // the id map is not editable
   3.409 +                if (nodemap_to_edit == "id") return 0;
   3.410  		//If there is already edited edge, it has to be saved first
   3.411  		if(entrywidget.is_visible())
   3.412  		  {
   3.413 @@ -913,7 +928,7 @@
   3.414  
   3.415    //if addition was not successful addEdgeMap returns one.
   3.416    //cause can be that there is already a map named like the new one
   3.417 -  if(mapstorage.addEdgeMap(mapname,emptr))
   3.418 +  if(mapstorage.addEdgeMap(mapname,emptr, default_value))
   3.419      {
   3.420        return 1;
   3.421      }
   3.422 @@ -935,7 +950,7 @@
   3.423  
   3.424    //if addition was not successful addNodeMap returns one.
   3.425    //cause can be that there is already a map named like the new one
   3.426 -  if(mapstorage.addNodeMap(mapname,emptr))
   3.427 +  if(mapstorage.addNodeMap(mapname,emptr, default_value))
   3.428      {
   3.429        return 1;
   3.430      }
     4.1 --- a/gui/graph_displayer_canvas.cc	Fri Aug 19 12:09:21 2005 +0000
     4.2 +++ b/gui/graph_displayer_canvas.cc	Tue Aug 23 07:36:09 2005 +0000
     4.3 @@ -62,6 +62,7 @@
     4.4      edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
     4.5      *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
     4.6      edgesmap[i]->property_width_units().set_value(10);    
     4.7 +    edgesmap[i]->lower_to_bottom();
     4.8      
     4.9      //initializing edge-text as well, to empty string
    4.10  
    4.11 @@ -71,6 +72,7 @@
    4.12      edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
    4.13      edgetextmap[i]->property_fill_color().set_value("darkgreen");
    4.14      edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
    4.15 +    edgetextmap[i]->raise_to_top();
    4.16    }
    4.17  
    4.18    //afterwards nodes come to be drawn
    4.19 @@ -87,6 +89,7 @@
    4.20          mapstorage.coords[i].y+20);
    4.21      *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
    4.22      *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
    4.23 +    nodesmap[i]->raise_to_top();
    4.24  
    4.25      //initializing edge-text as well, to empty string
    4.26  
    4.27 @@ -98,6 +101,7 @@
    4.28          text_pos.x, text_pos.y, "");
    4.29      nodetextmap[i]->property_fill_color().set_value("darkblue");
    4.30      nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
    4.31 +    nodetextmap[i]->raise_to_top();
    4.32    }
    4.33  
    4.34    updateScrollRegion();
     5.1 --- a/gui/main_win.cc	Fri Aug 19 12:09:21 2005 +0000
     5.2 +++ b/gui/main_win.cc	Tue Aug 23 07:36:09 2005 +0000
     5.3 @@ -264,11 +264,13 @@
     5.4    if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
     5.5    {
     5.6      Glib::ustring filename = fcdialog.get_filename();
     5.7 -    mapstorage.readFromFile(filename);
     5.8 -    mapstorage.file_name = filename;
     5.9 -    mapstorage.modified = false;
    5.10 -    gd_canvas.drawGraph();
    5.11 -    mapwin.update();
    5.12 +    if (!mapstorage.readFromFile(filename))
    5.13 +    {
    5.14 +      mapstorage.file_name = filename;
    5.15 +      mapstorage.modified = false;
    5.16 +      gd_canvas.drawGraph();
    5.17 +      mapwin.update();
    5.18 +    }
    5.19    }
    5.20  }
    5.21  
     6.1 --- a/gui/mapstorage.cc	Fri Aug 19 12:09:21 2005 +0000
     6.2 +++ b/gui/mapstorage.cc	Tue Aug 23 07:36:09 2005 +0000
     6.3 @@ -1,4 +1,5 @@
     6.4  #include "mapstorage.h"
     6.5 +#include <gtkmm.h>
     6.6  #include <cmath>
     6.7  
     6.8  MapStorage::MapStorage() : modified(false), file_name("")
     6.9 @@ -26,21 +27,25 @@
    6.10    }
    6.11  }
    6.12  
    6.13 -int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap)
    6.14 +int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value = 0.0)
    6.15  {
    6.16    if( nodemap_storage.find(name) == nodemap_storage.end() )
    6.17      {
    6.18        nodemap_storage[name]=nodemap;
    6.19 +      // set the maps default value
    6.20 +      nodemap_default[name] = default_value;
    6.21        return 0;
    6.22      }
    6.23    return 1;
    6.24  }
    6.25  
    6.26 -int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap)
    6.27 +int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value = 0.0)
    6.28  {
    6.29    if( edgemap_storage.find(name) == edgemap_storage.end() )
    6.30      {
    6.31        edgemap_storage[name]=edgemap;
    6.32 +      // set the maps default value
    6.33 +      edgemap_default[name] = default_value;
    6.34        return 0;
    6.35      }
    6.36    return 1;
    6.37 @@ -116,16 +121,7 @@
    6.38    return min;
    6.39  }
    6.40  
    6.41 -void MapStorage::initMapsForEdge(Edge e)
    6.42 -{
    6.43 -  std::map< std::string,Graph::EdgeMap<double> * >::iterator ems_it;
    6.44 -  for(ems_it=edgemap_storage.begin();ems_it!=edgemap_storage.end();ems_it++)
    6.45 -    {
    6.46 -      (*((*ems_it).second))[e]=5;
    6.47 -    }
    6.48 -}
    6.49 -
    6.50 -void MapStorage::readFromFile(const std::string &filename)
    6.51 +int MapStorage::readFromFile(const std::string &filename)
    6.52  {
    6.53    bool read_x = false;
    6.54    bool read_y = false;
    6.55 @@ -179,13 +175,11 @@
    6.56      }
    6.57      greader.run();
    6.58    } catch (DataFormatError& error) {
    6.59 -    /*
    6.60      Gtk::MessageDialog mdialog("Read Error");
    6.61      mdialog.set_message(error.what());
    6.62      mdialog.run();
    6.63 -    */
    6.64 -    // reset graph and mapstorage ?
    6.65 -    return;
    6.66 +    clear();
    6.67 +    return 1;
    6.68    }
    6.69  
    6.70    if (!read_x || !read_y)
    6.71 @@ -205,6 +199,28 @@
    6.72        i++;
    6.73      }
    6.74    }
    6.75 +
    6.76 +  // fill in the default values for the maps
    6.77 +  for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
    6.78 +      nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
    6.79 +  {
    6.80 +    if ((it->first != "id") &&
    6.81 +        (it->first != "coordiantes_x") &&
    6.82 +        (it->first != "coordinates_y"))
    6.83 +    {
    6.84 +      nodemap_default[it->first] = 0.0;
    6.85 +    }
    6.86 +  }
    6.87 +  for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
    6.88 +      edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
    6.89 +  {
    6.90 +    if (it->first != "id")
    6.91 +    {
    6.92 +      edgemap_default[it->first] = 0.0;
    6.93 +    }
    6.94 +  }
    6.95 +
    6.96 +  return 0;
    6.97  }
    6.98  
    6.99  void MapStorage::writeToFile(const std::string &filename)
   6.100 @@ -248,6 +264,16 @@
   6.101        edgemap_storage.erase(it);
   6.102      }
   6.103    }
   6.104 +  for (std::map<std::string, double>::iterator it =
   6.105 +      nodemap_default.begin(); it != nodemap_default.end(); ++it)
   6.106 +  {
   6.107 +    nodemap_default.erase(it);
   6.108 +  }
   6.109 +  for (std::map<std::string, double>::iterator it =
   6.110 +      edgemap_default.begin(); it != edgemap_default.end(); ++it)
   6.111 +  {
   6.112 +    edgemap_default.erase(it);
   6.113 +  }
   6.114    graph.clear();
   6.115    file_name = "";
   6.116    modified = false;
     7.1 --- a/gui/mapstorage.h	Fri Aug 19 12:09:21 2005 +0000
     7.2 +++ b/gui/mapstorage.h	Tue Aug 23 07:36:09 2005 +0000
     7.3 @@ -37,6 +37,12 @@
     7.4    //Stores the default values for the different visualization edge attributes
     7.5    std::vector<Graph::EdgeMap<double> > default_edgemaps;
     7.6  
     7.7 +  // Default values for the maps
     7.8 +  std::map< std::string, double > nodemap_default;
     7.9 +
    7.10 +  // Default values for the maps
    7.11 +  std::map< std::string, double > edgemap_default;
    7.12 +
    7.13  public:
    7.14    ///Constructor of MapStorage. Expects the Graph of
    7.15    ///which maps will be stored in it.
    7.16 @@ -52,13 +58,13 @@
    7.17    ///\param name is the name of map
    7.18    ///\nodemap is the pointer of the given nodemap
    7.19    ///\todo map should be given by reference!
    7.20 -  int addNodeMap(const std::string &,Graph::NodeMap<double> *);
    7.21 +  int addNodeMap(const std::string &,Graph::NodeMap<double> *, double);
    7.22  
    7.23    ///Adds given map to storage. A name and the map itself has to be provided.
    7.24    ///\param name is the name of map
    7.25    ///\edgemap is the pointer of the given edgemap
    7.26    ///\todo map should be given by reference!
    7.27 -  int addEdgeMap(const std::string &,Graph::EdgeMap<double> *);
    7.28 +  int addEdgeMap(const std::string &,Graph::EdgeMap<double> *, double);
    7.29  
    7.30    ///Returns how much nodemaps is stored in \ref MapStorage
    7.31    int numOfNodeMaps() {return nodemap_storage.size();};
    7.32 @@ -94,13 +100,7 @@
    7.33    ///To be able to iterate through each maps this function returns an iterator pointing to the last edgemap in the storage.
    7.34    std::map< std::string,Graph::EdgeMap<double> * >::iterator endOfEdgeMaps(){return edgemap_storage.end();};
    7.35  
    7.36 -  ///This function sets a default base value for the newly created node
    7.37 -  void initMapsForNode(NodeIt);
    7.38 -
    7.39 -  ///This function sets a default base value for the newly created node
    7.40 -  void initMapsForEdge(Graph::Edge);
    7.41 -
    7.42 -  void readFromFile(const std::string &);
    7.43 +  int readFromFile(const std::string &);
    7.44    void writeToFile(const std::string &);
    7.45  
    7.46    void clear();