[Lemon-commits] ladanyi: r3113 - glemon/branches/akos
Lemon SVN
svn at lemon.cs.elte.hu
Fri Dec 15 18:45:49 CET 2006
Author: ladanyi
Date: Fri Dec 15 18:45:48 2006
New Revision: 3113
Modified:
glemon/branches/akos/dijkstrabox.cc
glemon/branches/akos/graph_displayer_canvas-event.cc
glemon/branches/akos/graph_displayer_canvas-node.cc
glemon/branches/akos/gui_reader.cc
glemon/branches/akos/gui_writer.cc
glemon/branches/akos/kruskalbox.cc
glemon/branches/akos/main_win.cc
glemon/branches/akos/mapstorage.cc
glemon/branches/akos/mapstorage.h
glemon/branches/akos/nbtab.cc
glemon/branches/akos/new_map_win.cc
Log:
The Mapstorage interface changes broke some things. Now it compiles again.
Modified: glemon/branches/akos/dijkstrabox.cc
==============================================================================
--- glemon/branches/akos/dijkstrabox.cc (original)
+++ glemon/branches/akos/dijkstrabox.cc Fri Dec 15 18:45:48 2006
@@ -27,151 +27,147 @@
{
init(t);
}
-
+
SuurballeBox::SuurballeBox(std::vector<std::string> t):DijkstraBox(t)
{
Gtk::Adjustment * adjustment=new Gtk::Adjustment(2, 1, 20, 1, 5);
num_set = new Gtk::SpinButton(*adjustment, 5,0);
Gtk::Label * label=new Gtk::Label("No. of paths to find: ");
-// hbox.pack_start(*label);
-// hbox.pack_start(*num_set);
-// hbox.show_all_children();
+ // hbox.pack_start(*label);
+ // hbox.pack_start(*num_set);
+ // hbox.show_all_children();
table.attach(*label, 0,1,2,3);
table.attach(*num_set, 1,2,2,3);
-// pack_start(hbox);
+ // pack_start(hbox);
}
-
+
void DijkstraBox::run()
{
if(
- tabcbt.get_active_text()!="" &&
- (edgemapcbts[INPUT])->get_active_text()!="" &&
- (edgemapcbts[OUTPUT])->get_active_text()!="" &&
- source.get_active_text()!="" &&
- target.get_active_text()!=""
- )
- {
- const Graph &g=mapstorage->graph;
- Node from, to;
+ tabcbt.get_active_text()!="" &&
+ (edgemapcbts[INPUT])->get_active_text()!="" &&
+ (edgemapcbts[OUTPUT])->get_active_text()!="" &&
+ source.get_active_text()!="" &&
+ target.get_active_text()!=""
+ )
+ {
+ const Graph &g=mapstorage->graph;
+ Node from, to;
- get_from_to(from, to, (Graph&)g);
+ get_from_to(from, to, (Graph&)g);
- std::ostringstream o;
+ std::ostringstream o;
- if(!(from==to))
- {
- Graph::EdgeMap<double> * inputmap=
- (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()];
- Graph::EdgeMap<double> * outputmap=
- (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()];
-
- //zero out output map
- for (EdgeIt i(g); i!=INVALID; ++i)
- {
- (*outputmap)[i]=0;
- }
-
- Dijkstra<Graph, Graph::EdgeMap<double> > dijkstra(g, *inputmap);
- dijkstra.run(from, to);
-
- if(dijkstra.reached(to))
- {
- Node n=to;
- int length=0;
- while (n!=INVALID && n!=from)
- {
- Edge e=dijkstra.predEdge(n);
- (*outputmap)[e]=1;
- n=dijkstra.predNode(n);
- length++;
- }
- o << "Result: " << length << " long path, with cost " << dijkstra.dist(to);
- }
- else
- {
- o << "Result: failed to find shortest path between ";
- o << source.get_active_text() << " and " << target.get_active_text();
- }
- resultlabel.set_text(o.str());
-
- mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
- // mapstorage->changeActiveMap(true, E_COLOR,
- // (edgemapcbts[OUTPUT])->get_active_text());
- // mapstorage->changeActiveMap(true, E_TEXT,
- // (edgemapcbts[INPUT])->get_active_text());
- }
+ if(!(from==to))
+ {
+ Graph::EdgeMap<double>& inputmap = mapstorage->getEdgeMap(edgemapcbts[INPUT]->get_active_text());
+ Graph::EdgeMap<double>& outputmap = mapstorage->getEdgeMap(edgemapcbts[OUTPUT]->get_active_text());
+
+ //zero out output map
+ for (EdgeIt i(g); i!=INVALID; ++i)
+ {
+ outputmap[i]=0;
+ }
+
+ Dijkstra<Graph, Graph::EdgeMap<double> > dijkstra(g, inputmap);
+ dijkstra.run(from, to);
+
+ if(dijkstra.reached(to))
+ {
+ Node n=to;
+ int length=0;
+ while (n!=INVALID && n!=from)
+ {
+ Edge e=dijkstra.predEdge(n);
+ outputmap[e]=1;
+ n=dijkstra.predNode(n);
+ length++;
+ }
+ o << "Result: " << length << " long path, with cost " << dijkstra.dist(to);
+ }
+ else
+ {
+ o << "Result: failed to find shortest path between ";
+ o << source.get_active_text() << " and " << target.get_active_text();
+ }
+ resultlabel.set_text(o.str());
+
+ mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
+ // mapstorage->changeActiveMap(true, E_COLOR,
+ // (edgemapcbts[OUTPUT])->get_active_text());
+ // mapstorage->changeActiveMap(true, E_TEXT,
+ // (edgemapcbts[INPUT])->get_active_text());
}
+ }
}
void SuurballeBox::run()
{
if(
- tabcbt.get_active_text()!="" &&
- (edgemapcbts[INPUT])->get_active_text()!="" &&
- (edgemapcbts[OUTPUT])->get_active_text()!="" &&
- source.get_active_text()!="" &&
- target.get_active_text()!=""
- )
- {
- const Graph &g=mapstorage->graph;
- Node from, to;
+ tabcbt.get_active_text()!="" &&
+ (edgemapcbts[INPUT])->get_active_text()!="" &&
+ (edgemapcbts[OUTPUT])->get_active_text()!="" &&
+ source.get_active_text()!="" &&
+ target.get_active_text()!=""
+ )
+ {
+ const Graph &g=mapstorage->graph;
+ Node from, to;
- get_from_to(from, to, (Graph&)g);
+ get_from_to(from, to, (Graph&)g);
- std::ostringstream o;
+ std::ostringstream o;
- if(!(from==to))
- {
- Graph::EdgeMap<double> * inputmap=
- (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()];
- Graph::EdgeMap<double> * outputmap=
- (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()];
-
- //zero out output map
- for (EdgeIt i(g); i!=INVALID; ++i)
- {
- (*outputmap)[i]=0;
- }
-
- Suurballe<Graph, Graph::EdgeMap<double> > sb((Graph&)g, *inputmap, from, to);
-
- int found=sb.run(num_set->get_value_as_int());
- if(found)
- {
- for(int j=0;j<found;j++)
- {
- Path<Graph> path(g);
- sb.getPath(path, j);
- for(int k=0;k<path.length();k++)
- {
- Path<Graph>::EdgeIt ei;
- ei=path.nthEdge(k);
- (*outputmap)[ei]=j+1;
- }
- }
- o << "Result: found " << found << " paths between ";
- o << source.get_active_text() << " and " << target.get_active_text();
- }
- else
- {
- o << "Result: failed to find shortest path between ";
- o << source.get_active_text() << " and " << target.get_active_text();
- }
- resultlabel.set_text(o.str());
-
- mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
- // mapstorage->changeActiveMap(true, E_COLOR,
- // (edgemapcbts[OUTPUT])->get_active_text());
- // mapstorage->changeActiveMap(true, E_TEXT,
- // (edgemapcbts[INPUT])->get_active_text());
- }
+ if(!(from==to))
+ {
+ Graph::EdgeMap<double>& inputmap = mapstorage->getEdgeMap(edgemapcbts[INPUT]->get_active_text());
+ Graph::EdgeMap<double>& outputmap = mapstorage->getEdgeMap(edgemapcbts[OUTPUT]->get_active_text());
+
+ //zero out output map
+ for (EdgeIt i(g); i!=INVALID; ++i)
+ {
+ outputmap[i]=0;
+ }
+
+ Suurballe<Graph, Graph::EdgeMap<double> > sb((Graph&)g, inputmap, from, to);
+
+ int found=sb.run(num_set->get_value_as_int());
+ if(found)
+ {
+ for(int j=0;j<found;j++)
+ {
+ Path<Graph> path(g);
+ sb.getPath(path, j);
+ for(int k=0;k<path.length();k++)
+ {
+ Path<Graph>::EdgeIt ei;
+ ei=path.nthEdge(k);
+ outputmap[ei]=j+1;
+ }
+ }
+ o << "Result: found " << found << " paths between ";
+ o << source.get_active_text() << " and " << target.get_active_text();
+ }
+ else
+ {
+ o << "Result: failed to find shortest path between ";
+ o << source.get_active_text() << " and " << target.get_active_text();
+ }
+ resultlabel.set_text(o.str());
+
+ mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
+ // mapstorage->changeActiveMap(true, E_COLOR,
+ // (edgemapcbts[OUTPUT])->get_active_text());
+ // mapstorage->changeActiveMap(true, E_TEXT,
+ // (edgemapcbts[INPUT])->get_active_text());
}
+ }
}
-
+
void DijkstraBox::build_box()
{
//if active tab is changed, labels of graph nodes had to be loaded into comboboxes
@@ -203,36 +199,36 @@
void DijkstraBox::maplists_updated()
{
if(tabcbt.get_active_text()!="")
+ {
+ source.clear();
+ target.clear();
+ const Graph &g=mapstorage->graph;
+ for (NodeIt i(g); i!=INVALID; ++i)
{
- source.clear();
- target.clear();
- const Graph &g=mapstorage->graph;
- for (NodeIt i(g); i!=INVALID; ++i)
- {
- std::ostringstream text;
- text << (*((mapstorage->nodemap_storage)["label"]))[i];
- source.prepend_text(text.str());
- target.prepend_text(text.str());
- }
+ std::ostringstream text;
+ text << mapstorage->getLabel(i);
+ source.prepend_text(text.str());
+ target.prepend_text(text.str());
}
+ }
}
void DijkstraBox::get_from_to(Node & from, Node & to, Graph & g)
{
int assigned=0;
for (NodeIt i(g); (i!=INVALID) && (assigned<2); ++i)
+ {
+ std::ostringstream text;
+ text << mapstorage->getLabel(i);
+ if(!(text.str().compare(source.get_active_text())))
{
- std::ostringstream text;
- text << (*((mapstorage->nodemap_storage)["label"]))[i];
- if(!(text.str().compare(source.get_active_text())))
- {
- from=i;
- assigned++;
- }
- if(!(text.str().compare(target.get_active_text())))
- {
- to=i;
- assigned++;
- }
+ from=i;
+ assigned++;
+ }
+ if(!(text.str().compare(target.get_active_text())))
+ {
+ to=i;
+ assigned++;
}
+ }
}
Modified: glemon/branches/akos/graph_displayer_canvas-event.cc
==============================================================================
--- glemon/branches/akos/graph_displayer_canvas-event.cc (original)
+++ glemon/branches/akos/graph_displayer_canvas-event.cc Fri Dec 15 18:45:48 2006
@@ -266,29 +266,9 @@
isbutton=1;
- active_node=(mytab.mapstorage).graph.addNode();
-
- //initiating values corresponding to new node in maps
-
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
- // update coordinates
- mytab.mapstorage.setNodeCoords(active_node, XY(clicked_x, clicked_y));
-
- // update all other maps
- for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
- (mytab.mapstorage).nodemap_storage.begin(); it !=
- (mytab.mapstorage).nodemap_storage.end(); ++it)
- {
- if ((it->first != "coordinates_x") &&
- (it->first != "coordinates_y"))
- {
- (*(it->second))[active_node] =
- (mytab.mapstorage).nodemap_default[it->first];
- }
- }
- // increment the id map's default value
- (mytab.mapstorage).nodemap_default["label"] += 1.0;
+ active_node = mytab.mapstorage.addNode(XY(clicked_x, clicked_y));
nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
@@ -382,49 +362,19 @@
*(nodesmap[target_node]) <<
Gnome::Canvas::Properties::fill_color("red");
- //creating new edge
- active_edge=(mytab.mapstorage).graph.addEdge(active_node,
- target_node);
-
- // update maps
- for (std::map<std::string,
- Graph::EdgeMap<double>*>::const_iterator it =
- (mytab.mapstorage).edgemap_storage.begin(); it !=
- (mytab.mapstorage).edgemap_storage.end(); ++it)
- {
- (*(it->second))[active_edge] =
- (mytab.mapstorage).edgemap_default[it->first];
- }
- // increment the id map's default value
- (mytab.mapstorage).edgemap_default["label"] += 1.0;
+ active_edge = mytab.mapstorage.addEdge(active_node, target_node);
if(target_node!=active_node)
{
- // set the coordinates of the arrow on the new edge
- MapStorage& ms = mytab.mapstorage;
- ms.arrow_pos.set(active_edge,
- (ms.getNodeCoords(ms.graph.source(active_edge)) +
- ms.getNodeCoords(ms.graph.target(active_edge)))/ 2.0);
-
- //drawing new edge
- edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge,
- *this);
+ edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge, *this);
}
else
{
- // set the coordinates of the arrow on the new edge
- MapStorage& ms = mytab.mapstorage;
- ms.arrow_pos.set(active_edge,
- (ms.getNodeCoords(ms.graph.source(active_edge)) +
- XY(0.0, 80.0)));
-
- //drawing new edge
- edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge,
- *this);
+ edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge, *this);
}
//initializing edge-text as well, to empty string
- XY text_pos=mytab.mapstorage.arrow_pos[active_edge];
+ XY text_pos=mytab.mapstorage.getArrowCoords(active_edge);
text_pos+=(XY(10,10));
edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,
@@ -675,8 +625,7 @@
break;
case Gtk::RESPONSE_ACCEPT:
double new_value = spin.get_value();
- (*(mytab.mapstorage).nodemap_storage[nodemap_to_edit])[active_node] =
- new_value;
+ mytab.mapstorage.set(nodemap_to_edit, active_node, new_value);
std::ostringstream ostr;
ostr << new_value;
nodetextmap[active_node]->property_text().set_value(ostr.str());
@@ -718,8 +667,7 @@
break;
case Gtk::RESPONSE_ACCEPT:
double new_value = spin.get_value();
- (*(mytab.mapstorage).edgemap_storage[edgemap_to_edit])[active_edge] =
- new_value;
+ mytab.mapstorage.set(edgemap_to_edit, active_edge, new_value);
std::ostringstream ostr;
ostr << new_value;
edgetextmap[active_edge]->property_text().set_value(
@@ -825,7 +773,7 @@
if (mytab.mapstorage.graph.source(ei) == mytab.mapstorage.graph.target(ei))
{
- arrow_pos = mytab.mapstorage.arrow_pos[ei] + XY(dx, dy);
+ arrow_pos = mytab.mapstorage.getArrowCoords(ei) + XY(dx, dy);
}
else
{
@@ -833,16 +781,16 @@
XY moved_node_2(coord_x, coord_y);
Node target = mytab.mapstorage.graph.target(ei);
XY fix_node = mytab.mapstorage.getNodeCoords(target);
- XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
+ XY old_arrow_pos(mytab.mapstorage.getArrowCoords(ei));
arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
}
- mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
+ mytab.mapstorage.setArrowCoords(ei, arrow_pos);
edgesmap[ei]->draw();
//reposition of edgetext
- XY text_pos=mytab.mapstorage.arrow_pos[ei];
+ XY text_pos=mytab.mapstorage.getArrowCoords(ei);
text_pos+=(XY(10,10));
edgetextmap[ei]->property_x().set_value(text_pos.x);
edgetextmap[ei]->property_y().set_value(text_pos.y);
@@ -856,16 +804,16 @@
XY moved_node_2(coord_x, coord_y);
Node source = mytab.mapstorage.graph.source(ei);
XY fix_node = mytab.mapstorage.getNodeCoords(source);
- XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
+ XY old_arrow_pos(mytab.mapstorage.getArrowCoords(ei));
XY arrow_pos;
arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
- mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
+ mytab.mapstorage.setArrowCoords(ei, arrow_pos);
edgesmap[ei]->draw();
//reposition of edgetext
- XY text_pos=mytab.mapstorage.arrow_pos[ei];
+ XY text_pos=mytab.mapstorage.getArrowCoords(ei);
text_pos+=(XY(10,10));
edgetextmap[ei]->property_x().set_value(text_pos.x);
edgetextmap[ei]->property_y().set_value(text_pos.y);
Modified: glemon/branches/akos/graph_displayer_canvas-node.cc
==============================================================================
--- glemon/branches/akos/graph_displayer_canvas-node.cc (original)
+++ glemon/branches/akos/graph_displayer_canvas-node.cc Fri Dec 15 18:45:48 2006
@@ -23,17 +23,15 @@
int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
{
- Graph::NodeMap<double> * actual_map;
double min, max;
min=(mytab.mapstorage).minOfNodeMap(mapname);
max=(mytab.mapstorage).maxOfNodeMap(mapname);
- actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
if(node==INVALID)
{
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
{
- double v=fabs((*actual_map)[i]);
+ double v=fabs(mytab.mapstorage.get(mapname,i));
int w;
if(autoscale)
{
@@ -166,9 +164,6 @@
//the minimum of the nodemap to the range of
//green in RGB
- Graph::NodeMap<double> * actual_map;
- actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
-
double max, min;
max=(mytab.mapstorage).maxOfNodeMap(mapname);
@@ -181,7 +176,7 @@
{
Gdk::Color color;
- double w=(*actual_map)[i];
+ double w=mytab.mapstorage.get(mapname, i);
if(max!=min)
{
@@ -199,7 +194,7 @@
{
Gdk::Color color;
- double w=(*actual_map)[node];
+ double w=mytab.mapstorage.get(mapname, node);
if(max!=min)
{
@@ -278,15 +273,12 @@
//in that case empty string will be written, because
//that is the deleter map
- Graph::NodeMap<double> * actual_map=NULL;
- actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
-
if(node==INVALID)
{
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
{
nodemap_to_edit=mapname;
- double number=(*actual_map)[i];
+ double number=mytab.mapstorage.get(mapname, i);
std::ostringstream ostr;
ostr << number;
@@ -296,7 +288,7 @@
}
else
{
- double number=(*actual_map)[node];
+ double number=mytab.mapstorage.get(mapname, node);
std::ostringstream ostr;
ostr << number;
Modified: glemon/branches/akos/gui_reader.cc
==============================================================================
--- glemon/branches/akos/gui_reader.cc (original)
+++ glemon/branches/akos/gui_reader.cc Fri Dec 15 18:45:48 2006
@@ -37,29 +37,29 @@
x("arrow_pos", m);
if ((int)m.size() == countEdges(mapstorage->graph))
+ {
+ for (EdgeIt e(mapstorage->graph); e != INVALID; ++e)
{
- for (EdgeIt e(mapstorage->graph); e != INVALID; ++e)
- {
- int edgeid = (int)(*mapstorage->edgemap_storage["label"])[e];
- mapstorage->arrow_pos.set(e, m[edgeid]);
- }
- mapstorage->ArrowPosReadOK();
+ int edgeid = (int) mapstorage->getLabel(e);
+ mapstorage->setArrowCoords(e, m[edgeid]);
}
-
+ mapstorage->ArrowPosReadOK();
+ }
+
std::map<int, std::string> nm;
x("active_nodemaps", nm);
for(int i=0;i<NODE_PROPERTY_NUM;i++)
- {
- mapstorage->changeActiveMap(false, i, nm[i]);
- }
+ {
+ mapstorage->changeActiveMap(false, i, nm[i]);
+ }
std::map<int, std::string> em;
x("active_edgemaps", em);
for(int i=0;i<EDGE_PROPERTY_NUM;i++)
- {
- mapstorage->changeActiveMap(true, i, em[i]);
- }
+ {
+ mapstorage->changeActiveMap(true, i, em[i]);
+ }
double attraction;
double propulsation;
Modified: glemon/branches/akos/gui_writer.cc
==============================================================================
--- glemon/branches/akos/gui_writer.cc (original)
+++ glemon/branches/akos/gui_writer.cc Fri Dec 15 18:45:48 2006
@@ -33,8 +33,8 @@
std::map<int, XY > m;
for (EdgeIt e(mapstorage->graph); e != INVALID; ++e)
{
- int edgeid = (int)(*(mapstorage->edgemap_storage["label"]))[e];
- m[edgeid] = mapstorage->arrow_pos[e];
+ int edgeid = (int) mapstorage->getLabel(e);
+ m[edgeid] = mapstorage->getArrowCoords(e);
}
x("arrow_pos", m);
Modified: glemon/branches/akos/kruskalbox.cc
==============================================================================
--- glemon/branches/akos/kruskalbox.cc (original)
+++ glemon/branches/akos/kruskalbox.cc Fri Dec 15 18:45:48 2006
@@ -28,43 +28,41 @@
void KruskalBox::run()
{
if(
- tabcbt.get_active_text()!="" &&
- (edgemapcbts[INPUT])->get_active_text()!="" &&
- (edgemapcbts[OUTPUT])->get_active_text()!=""
- )
- {
+ tabcbt.get_active_text()!="" &&
+ (edgemapcbts[INPUT])->get_active_text()!="" &&
+ (edgemapcbts[OUTPUT])->get_active_text()!=""
+ )
+ {
+
+ const Graph &g=mapstorage->graph;
+ const Graph::EdgeMap<double>& inputmap=
+ mapstorage->getEdgeMap(edgemapcbts[INPUT]->get_active_text());
+ Graph::EdgeMap<bool> outputmap(g);
+ double res=kruskal(g, inputmap, outputmap);
- const Graph &g=mapstorage->graph;
- Graph::EdgeMap<double> * inputmap=
- ((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]);
- Graph::EdgeMap<bool> outputmap(g);
- double res=kruskal(g, *inputmap, outputmap);
-
- for (EdgeIt i(g); i!=INVALID; ++i)
- {
- if(outputmap[i])
- {
- (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
- get_active_text()]))[i]=1;
- }
- else
- {
- (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
- get_active_text()]))[i]=0;
- }
- }
-
- std::ostringstream o;
- o << "Result: " << res;
- resultlabel.set_text(o.str());
-
- mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
- // mapstorage->changeActiveMap(true, E_COLOR,
- // (edgemapcbts[OUTPUT])->get_active_text());
- // mapstorage->changeActiveMap(true, E_TEXT,
- // (edgemapcbts[INPUT])->get_active_text());
-
+ for (EdgeIt i(g); i!=INVALID; ++i)
+ {
+ if(outputmap[i])
+ {
+ mapstorage->set(edgemapcbts[OUTPUT]->get_active_text(), i, 1);
+ }
+ else
+ {
+ mapstorage->set(edgemapcbts[OUTPUT]->get_active_text(), i, 0);
+ }
}
+
+ std::ostringstream o;
+ o << "Result: " << res;
+ resultlabel.set_text(o.str());
+
+ mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
+ // mapstorage->changeActiveMap(true, E_COLOR,
+ // (edgemapcbts[OUTPUT])->get_active_text());
+ // mapstorage->changeActiveMap(true, E_TEXT,
+ // (edgemapcbts[INPUT])->get_active_text());
+
+ }
}
void KruskalBox::build_box()
Modified: glemon/branches/akos/main_win.cc
==============================================================================
--- glemon/branches/akos/main_win.cc (original)
+++ glemon/branches/akos/main_win.cc Fri Dec 15 18:45:48 2006
@@ -326,7 +326,7 @@
{
if(active_tab!=-1)
{
- if (tabs[active_tab]->mapstorage.modified)
+ if (tabs[active_tab]->mapstorage.getModified())
{
Gtk::MessageDialog mdialog(_("<b>Save changes before closing?</b>"), true,
Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
Modified: glemon/branches/akos/mapstorage.cc
==============================================================================
--- glemon/branches/akos/mapstorage.cc (original)
+++ glemon/branches/akos/mapstorage.cc Fri Dec 15 18:45:48 2006
@@ -31,17 +31,29 @@
const double a_d=0.05;
const double p_d=40000;
-MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false), iterations(i_d), attraction(a_d), propulsation(p_d)
-{
- nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
- coords.setXMap(*nodemap_storage["coordinates_x"]);
- nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
- coords.setYMap(*nodemap_storage["coordinates_y"]);
-
- edgemap_storage["arrow_pos_x"] = new Graph::EdgeMap<double>(graph);
- arrow_pos.setXMap(*edgemap_storage["arrow_pos_x"]);
- edgemap_storage["arrow_pos_y"] = new Graph::EdgeMap<double>(graph);
- arrow_pos.setYMap(*edgemap_storage["arrow_pos_y"]);
+MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false), iterations(i_d), attraction(a_d), propulsation(p_d),
+ node_x_coord(graph),
+ node_y_coord(graph),
+ arrow_x_coord(graph),
+ arrow_y_coord(graph),
+ node_label(graph),
+ edge_label(graph)
+{
+ //nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
+ //coords.setXMap(*nodemap_storage["coordinates_x"]);
+ //nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
+ //coords.setYMap(*nodemap_storage["coordinates_y"]);
+ /*
+ coords.setXMap(node_x_coord);
+ coords.setYMap(node_y_coord);
+ */
+
+ //edgemap_storage["arrow_pos_x"] = new Graph::EdgeMap<double>(graph);
+ //arrow_pos.setXMap(*edgemap_storage["arrow_pos_x"]);
+ //edgemap_storage["arrow_pos_y"] = new Graph::EdgeMap<double>(graph);
+ //arrow_pos.setYMap(*edgemap_storage["arrow_pos_y"]);
+ arrow_pos.setXMap(arrow_x_coord);
+ arrow_pos.setYMap(arrow_y_coord);
nodemap_storage["label"] = new Graph::NodeMap<double>(graph);
edgemap_storage["label"] = new Graph::EdgeMap<double>(graph);
@@ -117,7 +129,6 @@
}
}
-
std::string MapStorage::getActiveEdgeMap(int prop)
{
return active_edgemaps[prop];
@@ -337,23 +348,26 @@
if (*it == "coordinates_x")
{
read_x = true;
+ greader.readNodeMap(*it, node_x_coord);
//std::cout << "read X nodemap" << std::endl;
}
else if (*it == "coordinates_y")
{
read_y = true;
+ greader.readNodeMap(*it, node_y_coord);
//std::cout << "read Y nodemap" << std::endl;
}
else if (*it == "label")
{
+ greader.readNodeMap(*it, node_label);
//std::cout << "read id nodemap" << std::endl;
}
else
{
nodemap_storage[*it] = new Graph::NodeMap<double>(graph);
+ greader.readNodeMap(*it, *nodemap_storage[*it]);
//std::cout << "read " << *it << " nodemap" << std::endl;
}
- greader.readNodeMap(*it, *nodemap_storage[*it]);
}
for (std::vector<std::string>::const_iterator it = edgeMapNames.begin();
it != edgeMapNames.end(); ++it)
@@ -362,13 +376,14 @@
{
//std::cout << "read id edgemap" << std::endl;
read_edge_id = true;
+ greader.readEdgeMap(*it, edge_label);
}
else
{
edgemap_storage[*it] = new Graph::EdgeMap<double>(graph);
//std::cout << "read " << *it << " edgemap" << std::endl;
+ greader.readEdgeMap(*it, *edgemap_storage[*it]);
}
- greader.readEdgeMap(*it, *edgemap_storage[*it]);
}
GuiReader gui_reader(greader, this);
greader.run();
@@ -381,11 +396,10 @@
if (!read_edge_id)
{
- edgemap_storage["label"] = new Graph::EdgeMap<double>(graph);
int i = 1;
for (EdgeIt e(graph); e != INVALID; ++e)
{
- (*edgemap_storage["label"])[e] = i++;
+ edge_label[e] = i++;
}
}
@@ -401,8 +415,7 @@
int i = 0;
for (NodeIt n(graph); n != INVALID; ++n)
{
- nodemap_storage["coordinates_x"]->set(n, 250.0 * std::cos(i * step));
- nodemap_storage["coordinates_y"]->set(n, 250.0 * std::sin(i * step));
+ setNodeCoords(n, XY(250.0 * std::cos(i * step), 250.0 * std::sin(i * step)));
i++;
}
}
@@ -414,11 +427,13 @@
{
if (graph.source(e) == graph.target(e))
{
- arrow_pos.set(e, coords[graph.source(e)] + XY(0.0, 80.0));
+ setArrowCoords(e, getNodeCoords(graph.source(e)) + XY(0.0, 80.0));
}
else
{
- arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0);
+ setArrowCoords(e,
+ (getNodeCoords(graph.source(e)) +
+ getNodeCoords(graph.target(e))) / 2.0);
}
}
}
@@ -563,25 +578,25 @@
void MapStorage::mapChanged(bool itisedge, std::string mapname)
{
if(itisedge)
+ {
+ for(int i=0;i<EDGE_PROPERTY_NUM;i++)
{
- for(int i=0;i<EDGE_PROPERTY_NUM;i++)
- {
- if(active_edgemaps[i]==mapname)
- {
- signal_prop.emit(itisedge, i);
- }
- }
+ if(active_edgemaps[i]==mapname)
+ {
+ signal_prop.emit(itisedge, i);
+ }
}
+ }
else
+ {
+ for(int i=0;i<NODE_PROPERTY_NUM;i++)
{
- for(int i=0;i<NODE_PROPERTY_NUM;i++)
- {
- if(active_nodemaps[i]==mapname)
- {
- signal_prop.emit(itisedge, i);
- }
- }
+ if(active_nodemaps[i]==mapname)
+ {
+ signal_prop.emit(itisedge, i);
+ }
}
+ }
}
void MapStorage::get_design_data(double & attraction_p, double & propulsation_p, int & iterations_p)
@@ -670,3 +685,69 @@
{
modified = m;
}
+
+Node MapStorage::addNode(XY coords)
+{
+ Node node = graph.addNode();
+
+ setNodeCoords(node, coords);
+
+ max_node_label++;
+
+ node_label[node] = max_node_label;
+
+ std::vector<std::string> node_maps = getNodeMapList();
+ for (std::vector<std::string>::const_iterator it = node_maps.begin();
+ it != node_maps.end(); ++it)
+ {
+ set(*it, node, nodemap_default[*it]);
+ }
+
+ return node;
+}
+
+Edge MapStorage::addEdge(Node from, Node to)
+{
+ Edge edge = graph.addEdge(from, to);
+
+ if (from == to)
+ {
+ setArrowCoords(edge, getNodeCoords(from) + XY(0.0, 80.0));
+ }
+ else
+ {
+ setArrowCoords(edge, (getNodeCoords(from) + getNodeCoords(to)) / 2.0);
+ }
+
+ max_edge_label++;
+
+ edge_label[edge] = max_edge_label;
+
+ std::vector<std::string> edge_maps = getEdgeMapList();
+ for (std::vector<std::string>::const_iterator it = edge_maps.begin();
+ it != edge_maps.end(); ++it)
+ {
+ set(*it, edge, edgemap_default[*it]);
+ }
+ return edge;
+}
+
+Graph::NodeMap<double>& MapStorage::getNodeMap(const std::string& name)
+{
+ return *nodemap_storage[name];
+}
+
+Graph::EdgeMap<double>& MapStorage::getEdgeMap(const std::string& name)
+{
+ return *edgemap_storage[name];
+}
+
+double MapStorage::getLabel(Node n) const
+{
+ return node_label[n];
+}
+
+double MapStorage::getLabel(Edge e) const
+{
+ return edge_label[e];
+}
Modified: glemon/branches/akos/mapstorage.h
==============================================================================
--- glemon/branches/akos/mapstorage.h (original)
+++ glemon/branches/akos/mapstorage.h Fri Dec 15 18:45:48 2006
@@ -45,6 +45,16 @@
/// the coordinates of the arrows on the edges
XYMap<Graph::EdgeMap<double> > arrow_pos;
+ Graph::NodeMap<double> node_x_coord;
+ Graph::NodeMap<double> node_y_coord;
+
+ Graph::EdgeMap<double> arrow_x_coord;
+ Graph::EdgeMap<double> arrow_y_coord;
+
+ Graph::NodeMap<double> node_label;
+
+ Graph::EdgeMap<double> edge_label;
+
///Stores double type EdgeMaps
std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage;
@@ -57,10 +67,11 @@
///Name of file loaded in object.
std::string file_name;
+ // the largest node label
+ double max_node_label;
+ // the largest edge label
+ double max_edge_label;
public:
- enum value {DOUBLE, STRING};
- enum type {NORMAL, GUI};
-
///The graph for which the datas are stored.
Graph graph;
@@ -301,6 +312,15 @@
bool getModified() const;
void setModified(bool m = true);
+
+ Node addNode(XY);
+ Edge addEdge(Node, Node);
+
+ Graph::NodeMap<double>& getNodeMap(const std::string&);
+ Graph::EdgeMap<double>& getEdgeMap(const std::string&);
+
+ double getLabel(Node) const;
+ double getLabel(Edge) const;
};
#endif //MAPSTORAGE_H
Modified: glemon/branches/akos/nbtab.cc
==============================================================================
--- glemon/branches/akos/nbtab.cc (original)
+++ glemon/branches/akos/nbtab.cc Fri Dec 15 18:45:48 2006
@@ -37,8 +37,8 @@
void NoteBookTab::readFile(const std::string &file)
{
mapstorage.readFromFile(file);
- mapstorage.file_name = file;
- mapstorage.modified = false;
+ mapstorage.setFileName(file);
+ mapstorage.setModified(false);
gd_canvas->drawGraph();
if(mapwinexists)
{
@@ -49,7 +49,7 @@
void NoteBookTab::newFile()
{
- if (mapstorage.modified)
+ if (mapstorage.getModified())
{
Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
@@ -78,7 +78,7 @@
void NoteBookTab::openFile()
{
- if (mapstorage.modified)
+ if (mapstorage.getModified())
{
Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
@@ -106,8 +106,8 @@
Glib::ustring filename = fcdialog.get_filename();
if (!mapstorage.readFromFile(filename))
{
- mapstorage.file_name = filename;
- mapstorage.modified = false;
+ mapstorage.setFileName(filename);
+ mapstorage.setModified(false);
gd_canvas->drawGraph();
if(mapwinexists)
{
@@ -120,14 +120,14 @@
void NoteBookTab::saveFile()
{
- if (mapstorage.file_name == "") {
+ if (mapstorage.getFileName() == "") {
saveFileAs();
}
else
{
- mapstorage.writeToFile(mapstorage.file_name);
- mapstorage.modified = false;
- signal_title.emit(Glib::filename_display_basename(mapstorage.file_name));
+ mapstorage.writeToFile(mapstorage.getFileName());
+ mapstorage.setModified(false);
+ signal_title.emit(Glib::filename_display_basename(mapstorage.getFileName()));
}
}
@@ -141,16 +141,16 @@
if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
{
Glib::ustring filename = fcdialog.get_filename();
- mapstorage.file_name = filename;
+ mapstorage.setFileName(filename);
mapstorage.writeToFile(filename);
- mapstorage.modified = false;
+ mapstorage.setModified(false);
signal_title.emit(Glib::filename_display_basename(filename));
}
}
void NoteBookTab::close()
{
- if (mapstorage.modified)
+ if (mapstorage.getModified())
{
Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
Modified: glemon/branches/akos/new_map_win.cc
==============================================================================
--- glemon/branches/akos/new_map_win.cc (original)
+++ glemon/branches/akos/new_map_win.cc Fri Dec 15 18:45:48 2006
@@ -55,23 +55,23 @@
//node vs. edge map selector
Gtk::RadioButton::Group group = node.get_group();
edge.set_group(group);
-
+
if(edgenode)
+ {
+ (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
+ (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
+ }
+ else
+ {
+ if(itisedge)
{
- (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
- (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
+ edge.set_active();
}
- else
+ else
{
- if(itisedge)
- {
- edge.set_active();
- }
- else
- {
- node.set_active();
- }
+ node.set_active();
}
+ }
vbox->pack_start(*table);
@@ -85,211 +85,211 @@
void NewMapWin::on_response(int response_id)
{
if(response_id==Gtk::RESPONSE_OK)
- {
- double def_val=0;
+ {
+ double def_val=0;
- //get and formulate text
- std::string def_val_str=default_value.get_text();
+ //get and formulate text
+ std::string def_val_str=default_value.get_text();
- bool only_nums=true;
- for(int i=0;i<(int)def_val_str.size() && only_nums;i++)
- {
- if( def_val_str[i]<'0' || def_val_str[i]>'9' )
- {
- only_nums=false;
- }
- }
- std::string polishform;
-
- if(only_nums)
- {
- def_val=atof(def_val_str.c_str());
- }
- else
- {
- polishform=string2Polishform(def_val_str,edge.get_active());
- }
-
- //get name of text
- std::string mapname=name.get_text();
-
- if(!mapname.empty()&&(!polishform.empty()||only_nums))
- {
- int abortion=0;
- if(edge.get_active())
- {
- //create the new map
- Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mytab.mapstorage.graph, def_val);
-
- if(!only_nums)
- {
- std::stack<double> polishstack;
-
- for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
- {
- for(int i=0;i<(int)polishform.size();i++)
- {
- double op1=0, op2=0;
- bool operation=true;
- switch(polishform[i])
- {
- case '+':
- case '-':
- case '/':
- case '*':
- op1=polishstack.top();
- polishstack.pop();
- op2=polishstack.top();
- polishstack.pop();
- break;
- default:
- //substitute variable
- std::map< std::string,Graph::EdgeMap<double> * > ems=mytab.mapstorage.edgemap_storage;
- bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
- if(itisvar)
- {
- polishstack.push( (*(mytab.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
- }
- else
- {
- polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
- }
- operation=false;
- break;
- }
- if(operation)
- {
- double res;
- switch(polishform[i])
- {
- case '+':
- res=op1+op2;
- break;
- case '-':
- res=op2-op1;
- break;
- case '/':
- res=op2/op1;
- break;
- case '*':
- res=op1*op2;
- break;
- default:
- std::cout << "How could we get here?" << std::endl;
- break;
- }
- polishstack.push(res);
- }
- }//foreach letter in polishform
- (*emptr)[k]=polishstack.top();
- }//foreach edge
- }//!only_nums
-
- //if addition was not successful addEdgeMap returns one.
- //cause can be that there is already a map named like the new one
- if(mytab.mapstorage.addEdgeMap(mapname, emptr, def_val))
- {
- abortion=1;
- }
-
- //add it to the list of the displayable maps
- //furthermore it is done by signals
- //mytab.registerNewEdgeMap(mapname);
-
- //display it
- //gdc.changeEdgeText(mapname);
- }
- else //!edge.get_active()
- {
- //create the new map
- Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mytab.mapstorage.graph, def_val);
-
- if(!only_nums)
- {
- std::stack<double> polishstack;
-
- for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
- {
- for(int i=0;i<(int)polishform.size();i++)
- {
- double op1=0, op2=0;
- bool operation=true;
- switch(polishform[i])
- {
- case '+':
- case '-':
- case '/':
- case '*':
- op1=polishstack.top();
- polishstack.pop();
- op2=polishstack.top();
- polishstack.pop();
- break;
- default:
- std::map< std::string,Graph::NodeMap<double> * > nms=mytab.mapstorage.nodemap_storage;
- bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
- if(itisvar)
- {
- polishstack.push( (*(mytab.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
- }
- else
- {
- polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
- }
- operation=false;
- break;
- }
- if(operation)
- {
- double res;
- switch(polishform[i])
- {
- case '+':
- res=op1+op2;
- break;
- case '-':
- res=op2-op1;
- break;
- case '/':
- res=op2/op1;
- break;
- case '*':
- res=op1*op2;
- break;
- default:
- std::cout << "How could we get here?" << std::endl;
- break;
- }
- polishstack.push(res);
- }
- }
- (*emptr)[k]=polishstack.top();
- }
- }
- //if addition was not successful addNodeMap returns one.
- //cause can be that there is already a map named like the new one
- if(mytab.mapstorage.addNodeMap(mapname,emptr, def_val))
- {
- abortion=1;
- }
-
- //add it to the list of the displayable maps
- //furthermore it is done by signals
- //mytab.registerNewNodeMap(mapname);
-
- //display it
- //gdc.changeNodeText(mapname);
- }
- if(!abortion)
- {
- name.set_text("");
- default_value.set_text("0");
- edge.show();
- node.show();
- hide();
- }
- }
+ bool only_nums=true;
+ for(int i=0;i<(int)def_val_str.size() && only_nums;i++)
+ {
+ if( def_val_str[i]<'0' || def_val_str[i]>'9' )
+ {
+ only_nums=false;
+ }
+ }
+ std::string polishform;
+
+ if(only_nums)
+ {
+ def_val=atof(def_val_str.c_str());
+ }
+ else
+ {
+ polishform=string2Polishform(def_val_str,edge.get_active());
+ }
+
+ //get name of text
+ std::string mapname=name.get_text();
+
+ if(!mapname.empty()&&(!polishform.empty()||only_nums))
+ {
+ int abortion=0;
+ if(edge.get_active())
+ {
+ //create the new map
+ Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mytab.mapstorage.graph, def_val);
+
+ if(!only_nums)
+ {
+ std::stack<double> polishstack;
+
+ for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
+ {
+ for(int i=0;i<(int)polishform.size();i++)
+ {
+ double op1=0, op2=0;
+ bool operation=true;
+ switch(polishform[i])
+ {
+ case '+':
+ case '-':
+ case '/':
+ case '*':
+ op1=polishstack.top();
+ polishstack.pop();
+ op2=polishstack.top();
+ polishstack.pop();
+ break;
+ default:
+ //substitute variable
+ std::vector<std::string> ems = mytab.mapstorage.getEdgeMapList();
+ bool itisvar=(std::find(ems.begin(), ems.end(), ch2var[ polishform[i] ]) != ems.end());
+ if(itisvar)
+ {
+ polishstack.push(mytab.mapstorage.get(ch2var[ polishform[i] ], k));
+ }
+ else
+ {
+ polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
+ }
+ operation=false;
+ break;
+ }
+ if(operation)
+ {
+ double res;
+ switch(polishform[i])
+ {
+ case '+':
+ res=op1+op2;
+ break;
+ case '-':
+ res=op2-op1;
+ break;
+ case '/':
+ res=op2/op1;
+ break;
+ case '*':
+ res=op1*op2;
+ break;
+ default:
+ std::cout << "How could we get here?" << std::endl;
+ break;
+ }
+ polishstack.push(res);
+ }
+ }//foreach letter in polishform
+ (*emptr)[k]=polishstack.top();
+ }//foreach edge
+ }//!only_nums
+
+ //if addition was not successful addEdgeMap returns one.
+ //cause can be that there is already a map named like the new one
+ if(mytab.mapstorage.addEdgeMap(mapname, emptr, def_val))
+ {
+ abortion=1;
+ }
+
+ //add it to the list of the displayable maps
+ //furthermore it is done by signals
+ //mytab.registerNewEdgeMap(mapname);
+
+ //display it
+ //gdc.changeEdgeText(mapname);
+ }
+ else //!edge.get_active()
+ {
+ //create the new map
+ Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mytab.mapstorage.graph, def_val);
+
+ if(!only_nums)
+ {
+ std::stack<double> polishstack;
+
+ for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
+ {
+ for(int i=0;i<(int)polishform.size();i++)
+ {
+ double op1=0, op2=0;
+ bool operation=true;
+ switch(polishform[i])
+ {
+ case '+':
+ case '-':
+ case '/':
+ case '*':
+ op1=polishstack.top();
+ polishstack.pop();
+ op2=polishstack.top();
+ polishstack.pop();
+ break;
+ default:
+ std::vector<std::string> nms = mytab.mapstorage.getNodeMapList();
+ bool itisvar=(std::find(nms.begin(), nms.end(), ch2var[ polishform[i] ])!=nms.end());
+ if(itisvar)
+ {
+ polishstack.push( mytab.mapstorage.get(ch2var[ polishform[i] ],k));
+ }
+ else
+ {
+ polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
+ }
+ operation=false;
+ break;
+ }
+ if(operation)
+ {
+ double res;
+ switch(polishform[i])
+ {
+ case '+':
+ res=op1+op2;
+ break;
+ case '-':
+ res=op2-op1;
+ break;
+ case '/':
+ res=op2/op1;
+ break;
+ case '*':
+ res=op1*op2;
+ break;
+ default:
+ std::cout << "How could we get here?" << std::endl;
+ break;
+ }
+ polishstack.push(res);
+ }
+ }
+ (*emptr)[k]=polishstack.top();
+ }
+ }
+ //if addition was not successful addNodeMap returns one.
+ //cause can be that there is already a map named like the new one
+ if(mytab.mapstorage.addNodeMap(mapname,emptr, def_val))
+ {
+ abortion=1;
+ }
+
+ //add it to the list of the displayable maps
+ //furthermore it is done by signals
+ //mytab.registerNewNodeMap(mapname);
+
+ //display it
+ //gdc.changeNodeText(mapname);
+ }
+ if(!abortion)
+ {
+ name.set_text("");
+ default_value.set_text("0");
+ edge.show();
+ node.show();
+ hide();
+ }
}
+ }
}
@@ -306,128 +306,128 @@
char index='a';
for(int i=0;(valid_entry&&(i<(int)rawcommand.size()));i++)
+ {
+ switch(rawcommand[i])
{
- switch(rawcommand[i])
- {
- case '+':
- case '-':
- case '*':
- case '/':
- case ')':
- case '(':
- if(!variable.empty())
- {
- valid_entry=validVariable(variable, itisedge);
- ch2var[index]=variable;
- command+=index;
- index++;
- variable.erase(0,variable.size());
- }
- command+=rawcommand[i];
- break;
- default:
- variable+=rawcommand[i];
- break;
- }
+ case '+':
+ case '-':
+ case '*':
+ case '/':
+ case ')':
+ case '(':
+ if(!variable.empty())
+ {
+ valid_entry=validVariable(variable, itisedge);
+ ch2var[index]=variable;
+ command+=index;
+ index++;
+ variable.erase(0,variable.size());
+ }
+ command+=rawcommand[i];
+ break;
+ default:
+ variable+=rawcommand[i];
+ break;
}
+ }
if(!variable.empty()&&valid_entry)
- {
- valid_entry=validVariable(variable, itisedge);
- ch2var[index]=variable;
- command+=index;
- index++;
- variable.erase(0,variable.size());
- }
+ {
+ valid_entry=validVariable(variable, itisedge);
+ ch2var[index]=variable;
+ command+=index;
+ index++;
+ variable.erase(0,variable.size());
+ }
if(valid_entry)
- {
- unsigned int pr=10000;
- bool prevmult=false;
- unsigned int prev_change=pr;
- unsigned int prev_br=pr;
- int counter=0;
- std::string comm_nobr="";
- std::vector<unsigned int> p;
- p.resize(counter+1);
-
- //limits
- //6 brackets embedded
- //100 operation in a row from the same priority
-
- for(int i=0;i<(int)command.size();i++)
- {
- bool put_in_string=true;
- switch(command[i])
- {
- case '(':
- pr=prev_br+10000;
- prev_br=pr;
- prevmult=false;
- put_in_string=false;
- break;
- case ')':
- pr=prev_br-10000;
- prev_br=pr;
- prevmult=false;
- put_in_string=false;
- break;
- case '+':
- case '-':
- if(prevmult)
- {
- pr=prev_change;
- }
- p[counter]=pr;
- pr-=100;
-
- prevmult=false;
- break;
- case '/':
- case '*':
- if(!prevmult)
- {
- prev_change=pr;
- pr+=200;
- pr-=1;
- }
- p[counter]=pr;
- pr-=1;
- prevmult=true;
- break;
- default:
- p[counter]=65000;
- break;
- }
- if(put_in_string)
- {
- counter++;
- p.resize(counter+1);
- comm_nobr=comm_nobr+command[i];
- }
- }
+ {
+ unsigned int pr=10000;
+ bool prevmult=false;
+ unsigned int prev_change=pr;
+ unsigned int prev_br=pr;
+ int counter=0;
+ std::string comm_nobr="";
+ std::vector<unsigned int> p;
+ p.resize(counter+1);
+
+ //limits
+ //6 brackets embedded
+ //100 operation in a row from the same priority
+
+ for(int i=0;i<(int)command.size();i++)
+ {
+ bool put_in_string=true;
+ switch(command[i])
+ {
+ case '(':
+ pr=prev_br+10000;
+ prev_br=pr;
+ prevmult=false;
+ put_in_string=false;
+ break;
+ case ')':
+ pr=prev_br-10000;
+ prev_br=pr;
+ prevmult=false;
+ put_in_string=false;
+ break;
+ case '+':
+ case '-':
+ if(prevmult)
+ {
+ pr=prev_change;
+ }
+ p[counter]=pr;
+ pr-=100;
+
+ prevmult=false;
+ break;
+ case '/':
+ case '*':
+ if(!prevmult)
+ {
+ prev_change=pr;
+ pr+=200;
+ pr-=1;
+ }
+ p[counter]=pr;
+ pr-=1;
+ prevmult=true;
+ break;
+ default:
+ p[counter]=65000;
+ break;
+ }
+ if(put_in_string)
+ {
+ counter++;
+ p.resize(counter+1);
+ comm_nobr=comm_nobr+command[i];
+ }
+ }
- tree_node * root=weightedString2Tree(comm_nobr, p, 0);
+ tree_node * root=weightedString2Tree(comm_nobr, p, 0);
- std::string polishform=postOrder(root);
+ std::string polishform=postOrder(root);
- deleteTree(root);
+ deleteTree(root);
- return polishform;
- }
+ return polishform;
+ }
return "";
}
void NewMapWin::deleteTree(NewMapWin::tree_node * node)
{
if(node->left_child!=NULL)
- {
- deleteTree(node->left_child);
- }
+ {
+ deleteTree(node->left_child);
+ }
if(node->right_child!=NULL)
- {
- deleteTree(node->right_child);
- }
+ {
+ deleteTree(node->right_child);
+ }
delete node;
}
@@ -436,25 +436,25 @@
unsigned int min=p[offset];
int minplace=0;
for(int i=0;i<(int)to_tree.size();i++)
+ {
+ if(min>p[offset+i])
{
- if(min>p[offset+i])
- {
- min=p[offset+i];
- minplace=i;
- }
+ min=p[offset+i];
+ minplace=i;
}
+ }
tree_node * act_node=new tree_node;
act_node->ch=to_tree[minplace];
if(to_tree.size()>=3)
- {
- act_node->left_child=weightedString2Tree(to_tree.substr(0,minplace), p, offset);
- act_node->right_child=weightedString2Tree(to_tree.substr(minplace+1,to_tree.size()-minplace-1), p, offset+minplace+1);
- }
+ {
+ act_node->left_child=weightedString2Tree(to_tree.substr(0,minplace), p, offset);
+ act_node->right_child=weightedString2Tree(to_tree.substr(minplace+1,to_tree.size()-minplace-1), p, offset+minplace+1);
+ }
else
- {
- act_node->left_child=NULL;
- act_node->right_child=NULL;
- }
+ {
+ act_node->left_child=NULL;
+ act_node->right_child=NULL;
+ }
return act_node;
}
@@ -462,13 +462,13 @@
{
std::string subtree_to_string;
if(subtree->left_child)
- {
- subtree_to_string=postOrder(subtree->left_child);
- }
+ {
+ subtree_to_string=postOrder(subtree->left_child);
+ }
if(subtree->right_child)
- {
- subtree_to_string=subtree_to_string+postOrder(subtree->right_child);
- }
+ {
+ subtree_to_string=subtree_to_string+postOrder(subtree->right_child);
+ }
subtree_to_string=subtree_to_string+subtree->ch;
return subtree_to_string;
}
@@ -478,40 +478,42 @@
bool cancel;
//is it mapname?
if(itisedge)
- {
- cancel=(mytab.mapstorage.edgemap_storage.find(variable)==mytab.mapstorage.edgemap_storage.end());
- }
+ {
+ std::vector<std::string> edge_maps = mytab.mapstorage.getEdgeMapList();
+ cancel=(std::find(edge_maps.begin(), edge_maps.end(), variable)==edge_maps.end());
+ }
else
- {
- cancel=(mytab.mapstorage.nodemap_storage.find(variable)==mytab.mapstorage.nodemap_storage.end());
- }
+ {
+ std::vector<std::string> node_maps = mytab.mapstorage.getNodeMapList();
+ cancel=(std::find(node_maps.begin(), node_maps.end(), variable)==node_maps.end());
+ }
//maybe it is number
int point_num=0;
if(cancel)
- {
- cancel=false;
- for(int j=0;(!cancel)&&(j<(int)variable.size());j++)
- {
- if(((variable[j]<'0')||(variable[j]>'9'))&&(variable[j]!='.'))
- {
- cancel=true;
- }
- else
- {
- if(variable[j]=='.')
- {
- point_num++;
- if(point_num>1)
- {
- cancel=true;
- }
- }
- }
- }
+ {
+ cancel=false;
+ for(int j=0;(!cancel)&&(j<(int)variable.size());j++)
+ {
+ if(((variable[j]<'0')||(variable[j]>'9'))&&(variable[j]!='.'))
+ {
+ cancel=true;
+ }
+ else
+ {
+ if(variable[j]=='.')
+ {
+ point_num++;
+ if(point_num>1)
+ {
+ cancel=true;
+ }
+ }
+ }
}
+ }
if(cancel)
- {
- return false;
- }
+ {
+ return false;
+ }
return true;
}
More information about the Lemon-commits
mailing list