[Lemon-commits] [lemon_svn] ladanyi: r2159 - hugo/trunk/gui
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:50:36 CET 2006
Author: ladanyi
Date: Tue Aug 23 17:57:12 2005
New Revision: 2159
Modified:
hugo/trunk/gui/graph_displayer_canvas-event.cc
hugo/trunk/gui/mapstorage.cc
Log:
- handle the case when there is no id map in the edgeset section
- do not use ListGraph.id() to determine the id of a new node/edge
Modified: hugo/trunk/gui/graph_displayer_canvas-event.cc
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas-event.cc (original)
+++ hugo/trunk/gui/graph_displayer_canvas-event.cc Tue Aug 23 17:57:12 2005
@@ -240,23 +240,20 @@
// update coordinates
mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
- // update id map
- (*mapstorage.nodemap_storage["id"])[active_node] =
- mapstorage.graph.id(active_node);
-
// update all other maps
for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
mapstorage.nodemap_storage.begin(); it !=
mapstorage.nodemap_storage.end(); ++it)
{
- if ((it->first != "id") &&
- (it->first != "coordinates_x") &&
- (it->first != "coordiantes_y"))
+ if ((it->first != "coordinates_x") &&
+ (it->first != "coordinates_y"))
{
(*(it->second))[active_node] =
mapstorage.nodemap_default[it->first];
}
}
+ // increment the id map's default value
+ mapstorage.nodemap_default["id"] += 1.0;
nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
@@ -356,22 +353,17 @@
active_edge=mapstorage.graph.addEdge(active_node,
target_node);
- // update id map
- (*mapstorage.edgemap_storage["id"])[active_edge] =
- mapstorage.graph.id(active_edge);
-
- // update all other maps
+ // update maps
for (std::map<std::string,
Graph::EdgeMap<double>*>::const_iterator it =
mapstorage.edgemap_storage.begin(); it !=
mapstorage.edgemap_storage.end(); ++it)
{
- if (it->first != "id")
- {
- (*(it->second))[active_edge] =
- mapstorage.edgemap_default[it->first];
- }
+ (*(it->second))[active_edge] =
+ mapstorage.edgemap_default[it->first];
}
+ // increment the id map's default value
+ mapstorage.edgemap_default["id"] += 1.0;
//calculating coordinates of new edge
Gnome::Canvas::Points coos;
Modified: hugo/trunk/gui/mapstorage.cc
==============================================================================
--- hugo/trunk/gui/mapstorage.cc (original)
+++ hugo/trunk/gui/mapstorage.cc Tue Aug 23 17:57:12 2005
@@ -11,6 +11,9 @@
nodemap_storage["id"] = new Graph::NodeMap<double>(graph);
edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
+
+ nodemap_default["id"] = 1.0;
+ edgemap_default["id"] = 1.0;
}
MapStorage::~MapStorage()
@@ -125,6 +128,7 @@
{
bool read_x = false;
bool read_y = false;
+ bool read_edge_id = false;
try {
LemonReader lreader(filename);
@@ -182,6 +186,16 @@
return 1;
}
+ if (!read_edge_id)
+ {
+ edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
+ int i = 1;
+ for (EdgeIt e(graph); e != INVALID; ++e)
+ {
+ (*edgemap_storage["id"])[e] = i++;
+ }
+ }
+
if (!read_x || !read_y)
{
int node_num = 0;
@@ -210,6 +224,17 @@
{
nodemap_default[it->first] = 0.0;
}
+ else if (it->first == "id")
+ {
+ NodeIt n(graph);
+ double max = (*nodemap_storage["id"])[n];
+ for (; n != INVALID; ++n)
+ {
+ if ((*nodemap_storage["id"])[n] > max)
+ max = (*nodemap_storage["id"])[n];
+ }
+ nodemap_default["id"] = max + 1.0;
+ }
}
for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
@@ -218,6 +243,17 @@
{
edgemap_default[it->first] = 0.0;
}
+ else
+ {
+ EdgeIt e(graph);
+ double max = (*edgemap_storage["id"])[e];
+ for (; e != INVALID; ++e)
+ {
+ if ((*edgemap_storage["id"])[e] > max)
+ max = (*edgemap_storage["id"])[e];
+ }
+ edgemap_default["id"] = max + 1.0;
+ }
}
return 0;
@@ -267,12 +303,14 @@
for (std::map<std::string, double>::iterator it =
nodemap_default.begin(); it != nodemap_default.end(); ++it)
{
- nodemap_default.erase(it);
+ if (it->first != "id")
+ nodemap_default.erase(it);
}
for (std::map<std::string, double>::iterator it =
edgemap_default.begin(); it != edgemap_default.end(); ++it)
{
- edgemap_default.erase(it);
+ if (it->first != "id")
+ edgemap_default.erase(it);
}
graph.clear();
file_name = "";
More information about the Lemon-commits
mailing list