Changeset 201:879e47e5b731 in glemon-0.x
- Timestamp:
- 01/02/08 22:03:09 (17 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@3431
- Files:
-
- 12 added
- 31 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile.am
r193 r201 48 48 dijkstrabox.h \ 49 49 dijkstrabox.cc \ 50 file_import_dialog.h \ 51 file_import_dialog.cc \ 52 map_value.h \ 53 map_value.cc \ 54 map_value_map.h \ 55 map_value_map.cc \ 56 save_details_widget.h \ 57 save_details_widget.cc \ 58 save_details_dialog.h \ 59 save_details_dialog.cc \ 60 io_helper.h \ 61 io_helper.cc \ 50 62 background_chooser_dialog.h \ 51 63 background_chooser_dialog.cc \ -
algobox.cc
r194 r201 83 83 { 84 84 mapstorage=ms; 85 std::vector<std::string> nml; 86 std::vector<std::string> eml; 85 std::vector<std::string> n_nml; 86 std::vector<std::string> s_nml; 87 std::vector<std::string> n_eml; 88 std::vector<std::string> s_eml; 87 89 if(mapstorage!=NULL) 88 90 { 89 91 mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed)); 90 92 mapstorage->signal_edge_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::edgemaplist_changed)); 91 nml=mapstorage->getNodeMapList(); 92 eml=mapstorage->getEdgeMapList(); 93 n_nml=mapstorage->getNodeMapList(NUM); 94 s_nml=mapstorage->getNodeMapList(STR); 95 n_eml=mapstorage->getEdgeMapList(NUM); 96 s_eml=mapstorage->getEdgeMapList(STR); 93 97 } 94 98 for(int i=0;i<(int)nodemapcbts.size();i++) 95 99 { 96 (nodemapcbts[i])->update_list(n ml);100 (nodemapcbts[i])->update_list(n_nml, s_nml); 97 101 //update_cbt(nml, *(nodemapcbts[i])); 98 102 } 99 103 for(int i=0;i<(int)edgemapcbts.size();i++) 100 104 { 101 (edgemapcbts[i])->update_list( eml);105 (edgemapcbts[i])->update_list(n_eml, s_eml); 102 106 //update_cbt(eml, *(edgemapcbts[i])); 103 107 } … … 105 109 } 106 110 107 void AlgoBox::nodemaplist_changed(std::string newmap )111 void AlgoBox::nodemaplist_changed(std::string newmap, MapValue::Type type) 108 112 { 109 113 for(int i=0;i<(int)nodemapcbts.size();i++) 110 114 { 111 (nodemapcbts[i])->append_text(newmap );112 } 113 } 114 115 void AlgoBox::edgemaplist_changed(std::string newmap )115 (nodemapcbts[i])->append_text(newmap, type); 116 } 117 } 118 119 void AlgoBox::edgemaplist_changed(std::string newmap, MapValue::Type type) 116 120 { 117 121 for(int i=0;i<(int)edgemapcbts.size();i++) 118 122 { 119 (edgemapcbts[i])->append_text(newmap );123 (edgemapcbts[i])->append_text(newmap, type); 120 124 } 121 125 } … … 161 165 } 162 166 163 void AlgoBox::addMapSelector(std::string inputname, bool itisedge )167 void AlgoBox::addMapSelector(std::string inputname, bool itisedge, MapType type) 164 168 { 165 169 std::vector<std::string> empty_vector; 166 170 167 MapSelector * msp=new MapSelector(empty_vector, "",inputname,itisedge, false);171 MapSelector * msp=new MapSelector(empty_vector,empty_vector,"",inputname,itisedge, false, type); 168 172 169 173 if(itisedge) -
algobox.h
r194 r201 26 26 #include <libgnomecanvasmm.h> 27 27 #include <libgnomecanvasmm/polygon.h> 28 #include "map_value.h" 28 29 29 30 ///Ancestor class of algorithm graphical interface classes. … … 139 140 ///a signal is emitted by it. This signal is connected to this function, so \ref MapSelector s 140 141 ///in \ref nodemapcbts can be notified, and those can registrate the new map. (\ref MapSelector::append_text) 141 void nodemaplist_changed(std::string );142 void nodemaplist_changed(std::string, MapValue::Type); 142 143 143 144 ///Interface, through which \ref AlgoBox can be notified about edgemap addition. … … 146 147 ///a signal is emitted by it. This signal is connected to this function, so \ref MapSelector s 147 148 ///in \ref edgemapcbts can be notified, and those can registrate the new map. (\ref MapSelector::append_text) 148 void edgemaplist_changed(std::string );149 void edgemaplist_changed(std::string, MapValue::Type); 149 150 150 151 ///Aid function to provide data for a given entry. … … 184 185 ///\param label label to show in \ref MapSelector 185 186 ///\param itisedge whether edge or nodemaps stored in \ref MapSelector 186 void addMapSelector(std::string label, bool itisedge );187 void addMapSelector(std::string label, bool itisedge, MapType type = ALL); 187 188 }; 188 189 #endif //ALGOBOX_H -
all_include.h
r191 r201 66 66 const std::string prog_name = "LEMON Graph Editor"; 67 67 68 enum MapType 69 { 70 NUM = 1 << 0, 71 STR = 1 << 1, 72 ALL = (1 << 0) | (1 << 1) 73 }; 74 68 75 #endif // ALL_INCLUDE_H -
configure.ac
r183 r201 27 27 PKG_CHECK_MODULES([GTK], [libgnomecanvasmm-2.6 >= 2.6.0 gtkmm-2.4 >= 2.6]) 28 28 29 AC_ARG_WITH([lemon -prefix],30 AS_HELP_STRING([--with-lemon -prefix@<:@=PREFIX@:>@], [search for LEMON under PREFIX]), [], [with_lemon_prefix=no])31 if test x"$with_lemon _prefix" != x"no"; then32 export PKG_CONFIG_PATH="$with_lemon _prefix/lib/pkgconfig/:$PKG_CONFIG_PATH"29 AC_ARG_WITH([lemon], 30 AS_HELP_STRING([--with-lemon@<:@=PREFIX@:>@], [search for LEMON under PREFIX]), [], [with_lemon=no]) 31 if test x"$with_lemon" != x"no"; then 32 export PKG_CONFIG_PATH="$with_lemon/lib/pkgconfig/:$PKG_CONFIG_PATH" 33 33 fi 34 34 35 PKG_CHECK_MODULES([LEMON_0_5], [lemon >= 0.5], 36 [lemon_0_5_found=yes], [ 37 AC_MSG_RESULT([no]) 38 lemon_0_5_found=no]) 39 PKG_CHECK_MODULES([LEMON_SVNHEAD], [lemon = svnhead], 40 [lemon_svn_head_found=yes], [ 41 AC_MSG_RESULT([no]) 42 lemon_svn_head_found=no]) 43 if test x"$lemon_0_5_found" = x"no" -a x"$lemon_svn_head_found" = x"no"; then 44 AC_MSG_ERROR([LEMON not found.]) 45 else 46 if test x"$lemon_svn_head_found" = x"yes"; then 47 LEMON_CFLAGS="$LEMON_SVNHEAD_CFLAGS" 48 LEMON_LIBS="$LEMON_SVNHEAD_LIBS" 49 else 50 LEMON_CFLAGS="$LEMON_0_5_CFLAGS" 51 LEMON_LIBS="$LEMON_0_5_LIBS" 52 fi 53 AC_SUBST(LEMON_CFLAGS) 54 AC_SUBST(LEMON_LIBS) 55 fi 35 PKG_CHECK_MODULES([LEMON], [lemon >= 0.6.90]) 56 36 57 37 dnl Checks for header files. -
dijkstrabox.cc
r194 r201 51 51 52 52 void DijkstraBox::run() 53 { 54 if( 55 tabcbt.get_active_text()!="" && 56 (edgemapcbts[INPUT])->get_active_text()!="" && 57 (edgemapcbts[OUTPUT])->get_active_text()!="" && 58 source.get_active_text()!="" && 59 target.get_active_text()!="" 60 ) 61 { 62 const Graph &g=mapstorage->graph; 63 Node from, to; 64 65 get_from_to(from, to, (Graph&)g); 66 67 std::ostringstream o; 68 69 if(!(from==to)) 70 { 71 std::string inputmapName = edgemapcbts[INPUT]->get_active_text(); 72 std::string outputmapName = edgemapcbts[OUTPUT]->get_active_text(); 73 74 MapStorage::NumericEdgeMap& inputmap = mapstorage->getNumericEdgeMap(inputmapName); 75 MapStorage::NumericEdgeMap& outputmap = mapstorage->getNumericEdgeMap(outputmapName); 76 77 //zero out output map 78 for (EdgeIt i(g); i!=INVALID; ++i) 79 { 80 outputmap[i]=0; 81 } 82 83 Dijkstra<Graph, MapStorage::NumericEdgeMap > dijkstra(g, inputmap); 84 dijkstra.run(from, to); 85 86 if(dijkstra.reached(to)) 87 { 88 Node n=to; 89 int length=0; 90 while (n!=INVALID && n!=from) 91 { 92 Edge e=dijkstra.predEdge(n); 93 outputmap[e]=1; 94 n=dijkstra.predNode(n); 95 length++; 96 } 97 o << "Result: " << length << " long path, with cost " << dijkstra.dist(to); 98 } 99 else 100 { 101 o << "Result: failed to find shortest path between "; 102 o << source.get_active_text() << " and " << target.get_active_text(); 103 } 104 resultlabel.set_text(o.str()); 105 106 mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text()); 107 // mapstorage->changeActiveMap(true, E_COLOR, 108 // (edgemapcbts[OUTPUT])->get_active_text()); 109 // mapstorage->changeActiveMap(true, E_TEXT, 110 // (edgemapcbts[INPUT])->get_active_text()); 111 } 112 } 113 } 114 115 void SuurballeBox::run() 53 116 { 54 117 if( … … 69 132 if(!(from==to)) 70 133 { 71 Graph::EdgeMap<double> *inputmap=72 (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()];73 Graph::EdgeMap<double> *outputmap=74 (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()];134 MapStorage::NumericEdgeMap& inputmap= 135 mapstorage->getNumericEdgeMap(edgemapcbts[INPUT]->get_active_text()); 136 MapStorage::NumericEdgeMap& outputmap= 137 mapstorage->getNumericEdgeMap(edgemapcbts[OUTPUT]->get_active_text()); 75 138 76 139 //zero out output map 77 140 for (EdgeIt i(g); i!=INVALID; ++i) 78 141 { 79 (*outputmap)[i]=0;142 outputmap[i]=0; 80 143 } 81 144 82 Dijkstra<Graph, Graph::EdgeMap<double> > dijkstra(g, *inputmap); 83 dijkstra.run(from, to); 84 85 if(dijkstra.reached(to)) 86 { 87 Node n=to; 88 int length=0; 89 while (n!=INVALID && n!=from) 90 { 91 Edge e=dijkstra.predEdge(n); 92 (*outputmap)[e]=1; 93 n=dijkstra.predNode(n); 94 length++; 95 } 96 o << "Result: " << length << " long path, with cost " << dijkstra.dist(to); 97 } 98 else 99 { 100 o << "Result: failed to find shortest path between "; 101 o << source.get_active_text() << " and " << target.get_active_text(); 102 } 103 resultlabel.set_text(o.str()); 104 105 mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text()); 106 // mapstorage->changeActiveMap(true, E_COLOR, 107 // (edgemapcbts[OUTPUT])->get_active_text()); 108 // mapstorage->changeActiveMap(true, E_TEXT, 109 // (edgemapcbts[INPUT])->get_active_text()); 110 } 111 } 112 } 113 114 void SuurballeBox::run() 115 { 116 if( 117 tabcbt.get_active_text()!="" && 118 (edgemapcbts[INPUT])->get_active_text()!="" && 119 (edgemapcbts[OUTPUT])->get_active_text()!="" && 120 source.get_active_text()!="" && 121 target.get_active_text()!="" 122 ) 123 { 124 const Graph &g=mapstorage->graph; 125 Node from, to; 126 127 get_from_to(from, to, (Graph&)g); 128 129 std::ostringstream o; 130 131 if(!(from==to)) 132 { 133 Graph::EdgeMap<double> * inputmap= 134 (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]; 135 Graph::EdgeMap<double> * outputmap= 136 (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]; 137 138 //zero out output map 139 for (EdgeIt i(g); i!=INVALID; ++i) 140 { 141 (*outputmap)[i]=0; 142 } 143 144 Suurballe<Graph, Graph::EdgeMap<double> > sb((Graph&)g, *inputmap, from, to); 145 Suurballe<Graph, MapStorage::NumericEdgeMap > sb((Graph&)g, inputmap, from, to); 145 146 146 147 int found=sb.run(num_set->get_value_as_int()); … … 153 154 for(int k=0;k<path.length();k++) 154 155 { 155 (*outputmap)[path.nth(k)]=j+1;156 outputmap[path.nth(k)]=j+1; 156 157 } 157 158 } … … 181 182 signal_upon_maplist_updated().connect(sigc::mem_fun(*this, &DijkstraBox::maplists_updated)); 182 183 183 addMapSelector("Cost map: ", true );184 addMapSelector("Edges of path here: ", true );184 addMapSelector("Cost map: ", true, NUM); 185 addMapSelector("Edges of path here: ", true, NUM); 185 186 186 187 Gtk::Label * source_label=new Gtk::Label("Source: "); … … 213 214 { 214 215 std::ostringstream text; 215 text << (*((mapstorage->nodemap_storage)["label"]))[i];216 text << mapstorage->getLabel(i); 216 217 source.prepend_text(text.str()); 217 218 target.prepend_text(text.str()); … … 226 227 { 227 228 std::ostringstream text; 228 text << (*((mapstorage->nodemap_storage)["label"]))[i];229 text << mapstorage->getLabel(i); 229 230 if(!(text.str().compare(source.get_active_text()))) 230 231 { -
eps_win.cc
r198 r201 32 32 } 33 33 34 EpsWin::EpsWin(const std::string& title, std::vector<std::string> n ml):Gtk::Dialog(title, true, true)34 EpsWin::EpsWin(const std::string& title, std::vector<std::string> n_nml, std::vector<std::string> s_nml):Gtk::Dialog(title, true, true) 35 35 { 36 36 set_default_size(200, 50); … … 58 58 } 59 59 60 mapselector=new MapSelector(n ml, "", "Nodeshapes", false);60 mapselector=new MapSelector(n_nml, s_nml, "", "Nodeshapes", false, true, NUM); 61 61 mapselector->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &EpsWin::newMapWinNeeded)); 62 62 … … 105 105 } 106 106 107 void EpsWin::registerNewNodeMap(std::string newmapname )107 void EpsWin::registerNewNodeMap(std::string newmapname, MapValue::Type type) 108 108 { 109 mapselector->append_text((Glib::ustring)newmapname );109 mapselector->append_text((Glib::ustring)newmapname, type); 110 110 } -
eps_win.h
r198 r201 25 25 #include <libgnomecanvasmm.h> 26 26 #include <libgnomecanvasmm/polygon.h> 27 #include "map_value.h" 27 28 28 29 ///Graph visualization setup window. … … 62 63 ///\param nml nodemap list 63 64 ///\param mw the owner \ref NoteBookTab (\ref mytab) 64 EpsWin(const std::string& title, std::vector<std::string> );65 EpsWin(const std::string& title, std::vector<std::string>, std::vector<std::string>); 65 66 66 67 ///Deregistrates \ref EpsWin in its \ref NoteBookTab (\ref mytab) … … 103 104 ///\param new_name 104 105 ///name of new map 105 void registerNewNodeMap(std::string new_name );106 void registerNewNodeMap(std::string new_name, MapValue::Type type); 106 107 }; 107 108 -
gdc-broken_edge.cc
r194 r201 37 37 { 38 38 MapStorage& ms = *canvas.mytab.mapstorage; 39 XY center(ms. arrow_pos[edge]);39 XY center(ms.getArrowCoords(edge)); 40 40 XY unit_norm_vector(0-unit_vector_in_dir.y, unit_vector_in_dir.x); 41 41 … … 90 90 91 91 //calculating coordinates of the direction indicator arrow 92 XY head(ms. coords[ms.graph.target(edge)]);93 XY center(ms. arrow_pos[edge]);92 XY head(ms.getNodeCoords(ms.graph.target(edge))); 93 XY center(ms.getArrowCoords(edge)); 94 94 95 95 XY unit_vector_in_dir(head-center); … … 108 108 Node source = ms.graph.source(edge); 109 109 Node target = ms.graph.target(edge); 110 points.push_back(Gnome::Art::Point(ms. coords[source].x,111 ms. coords[source].y));112 points.push_back(Gnome::Art::Point(ms. arrow_pos[edge].x,113 ms. arrow_pos[edge].y));114 points.push_back(Gnome::Art::Point(ms. coords[target].x,115 ms. coords[target].y));110 points.push_back(Gnome::Art::Point(ms.getNodeCoords(source).x, 111 ms.getNodeCoords(source).y)); 112 points.push_back(Gnome::Art::Point(ms.getArrowCoords(edge).x, 113 ms.getArrowCoords(edge).y)); 114 points.push_back(Gnome::Art::Point(ms.getNodeCoords(target).x, 115 ms.getNodeCoords(target).y)); 116 116 line.property_points().set_value(points); 117 117 } … … 153 153 Gnome::Canvas::Points points_new; 154 154 155 canvas.mytab.mapstorage-> arrow_pos.set(edge, canvas.mytab.mapstorage->arrow_pos[edge]+ XY(dx, dy));155 canvas.mytab.mapstorage->setArrowCoords(edge, canvas.mytab.mapstorage->getArrowCoords(edge) + XY(dx, dy)); 156 156 157 157 draw(); 158 canvas.textReposition(canvas.mytab.mapstorage-> arrow_pos[edge]);158 canvas.textReposition(canvas.mytab.mapstorage->getArrowCoords(edge)); 159 159 160 160 clicked_x=e->motion.x; … … 200 200 201 201 Node node = ms.graph.source(edge); 202 XY center = (ms. coords[node] + ms.arrow_pos[edge]) / 2.0;203 204 XY unit_vector_in_dir(rot90(center - ms. arrow_pos[edge]));202 XY center = (ms.getNodeCoords(node) + ms.getArrowCoords(edge)) / 2.0; 203 204 XY unit_vector_in_dir(rot90(center - ms.getArrowCoords(edge))); 205 205 double length = sqrt(unit_vector_in_dir.normSquare()); 206 206 unit_vector_in_dir /= length; … … 209 209 210 210 double radius = 211 sqrt((ms. arrow_pos[edge] - ms.coords[node]).normSquare()) / 2.0;211 sqrt((ms.getArrowCoords(edge) - ms.getNodeCoords(node)).normSquare()) / 2.0; 212 212 213 213 XY p1 = center + XY(-radius, radius); … … 250 250 if(isbutton) 251 251 { 252 canvas.mytab.mapstorage-> arrow_pos.set(edge, XY(e->motion.x, e->motion.y));252 canvas.mytab.mapstorage->setArrowCoords(edge, XY(e->motion.x, e->motion.y)); 253 253 254 254 draw(); 255 canvas.textReposition(canvas.mytab.mapstorage-> arrow_pos[edge]);255 canvas.textReposition(canvas.mytab.mapstorage->getArrowCoords(edge)); 256 256 } 257 257 default: break; -
graph-displayer.cc
r194 r201 96 96 // } 97 97 if(argc>=2) 98 { 99 for(int i=1;i<argc;i++) 98 100 { 99 for(int i=1;i<argc;i++) 100 { 101 if(Glib::file_test(argv[i], Glib::FILE_TEST_IS_REGULAR)) 102 { 103 mytab.readFile(argv[i]); 104 } 105 } 101 if(Glib::file_test(argv[i], Glib::FILE_TEST_IS_REGULAR)) 102 { 103 mytab.readFile(argv[i]); 104 } 106 105 } 106 } 107 107 else 108 108 { -
graph_displayer_canvas-edge.cc
r194 r201 26 26 int GraphDisplayerCanvas::resetEdgeWidth (Edge edge) 27 27 { 28 MapStorage& ms = *mytab.mapstorage; 28 29 double min, max; 29 30 30 31 min=edge_property_defaults[E_WIDTH]; 31 32 max=edge_property_defaults[E_WIDTH]; 32 Graph::EdgeMap<double> actual_map( (mytab.mapstorage)->graph,edge_property_defaults[E_WIDTH]);33 34 if(edge==INVALID) 35 36 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 else 57 58 59 60 61 62 63 33 Graph::EdgeMap<double> actual_map(ms.graph,edge_property_defaults[E_WIDTH]); 34 35 if(edge==INVALID) 36 { 37 for (EdgeIt i(ms.graph); i!=INVALID; ++i) 38 { 39 double v=fabs(actual_map[i]); 40 int w; 41 if(min==max) 42 { 43 w=(int)(edge_property_defaults[E_WIDTH]); 44 } 45 else 46 { 47 w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH)); 48 } 49 if(zoomtrack) 50 { 51 double actual_ppu=get_pixels_per_unit(); 52 w=(int)(w/actual_ppu*fixed_zoom_factor); 53 } 54 edgesmap[i]->setLineWidth(w); 55 } 56 } 57 else 58 { 59 int w=(int)actual_map[edge]; 60 if(w>=0) 61 { 62 edgesmap[edge]->setLineWidth(w); 63 } 64 } 64 65 return 0; 65 66 } … … 68 69 int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge) 69 70 { 70 Graph::EdgeMap<double> * actual_map;71 MapStorage& ms = *mytab.mapstorage; 71 72 double min, max; 72 73 73 min=(mytab.mapstorage)->minOfEdgeMap(mapname); 74 max=(mytab.mapstorage)->maxOfEdgeMap(mapname); 75 actual_map=((mytab.mapstorage)->edgemap_storage)[mapname]; 76 77 if(edge==INVALID) 78 { 79 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 80 { 81 double v=(*actual_map)[i]; 82 int w; 83 if(autoscale) 84 { 85 if(min==max) 86 { 87 w=(int)(edge_property_defaults[E_WIDTH]); 88 } 89 else 90 { 91 w=(int)(minimum_edge_width+(v-min)/(max-min)*(edge_width-minimum_edge_width)); 92 } 93 } 94 else 95 { 96 w=(int)(v*edge_width); 97 } 98 if(w<0) 99 { 100 edgesmap[i]->hide(); 101 } 102 else 103 { 104 edgesmap[i]->show(); 105 if(w<minimum_edge_width) 106 { 107 w=minimum_edge_width; 108 } 109 if(zoomtrack) 110 { 111 double actual_ppu=get_pixels_per_unit(); 112 w=(int)(w/actual_ppu*fixed_zoom_factor); 113 } 114 edgesmap[i]->setLineWidth(w); 115 } 116 } 117 } 118 else 119 { 120 int w=(int)(*actual_map)[edge]; 121 if(w>=0) 122 { 123 edgesmap[edge]->setLineWidth(w); 124 } 125 } 74 { 75 EdgeIt e(ms.graph); 76 min = max = ms.get(mapname, e); 77 for (; e != INVALID; ++e) 78 { 79 if (static_cast<double>(ms.get(mapname, e)) > max) 80 max = ms.get(mapname, e); 81 if (static_cast<double>(ms.get(mapname, e)) < min) 82 min = ms.get(mapname, e); 83 } 84 } 85 86 if(edge==INVALID) 87 { 88 for (EdgeIt i(ms.graph); i!=INVALID; ++i) 89 { 90 double v=ms.get(mapname, i); 91 int w; 92 if(autoscale) 93 { 94 if(min==max) 95 { 96 w=(int)(edge_property_defaults[E_WIDTH]); 97 } 98 else 99 { 100 w=(int)(minimum_edge_width+(v-min)/(max-min)*(edge_width-minimum_edge_width)); 101 } 102 } 103 else 104 { 105 w=(int)(v*edge_width); 106 } 107 if(w<0) 108 { 109 edgesmap[i]->hide(); 110 } 111 else 112 { 113 edgesmap[i]->show(); 114 if(w<minimum_edge_width) 115 { 116 w=minimum_edge_width; 117 } 118 if(zoomtrack) 119 { 120 double actual_ppu=get_pixels_per_unit(); 121 w=(int)(w/actual_ppu*fixed_zoom_factor); 122 } 123 edgesmap[i]->setLineWidth(w); 124 } 125 } 126 } 127 else 128 { 129 int w=(int)ms.get(mapname, edge); 130 if(w>=0) 131 { 132 edgesmap[edge]->setLineWidth(w); 133 } 134 } 126 135 return 0; 127 136 }; … … 129 138 int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge) 130 139 { 140 MapStorage& ms = *mytab.mapstorage; 131 141 132 142 //function maps the range of the maximum and 133 143 //the minimum of the nodemap to the range of 134 144 //green in RGB 135 Graph::EdgeMap<double> * actual_map;136 actual_map=((mytab.mapstorage)->edgemap_storage)[mapname];137 145 138 146 double max, min; 139 147 140 max=(mytab.mapstorage)->maxOfEdgeMap(mapname); 141 min=(mytab.mapstorage)->minOfEdgeMap(mapname); 142 143 if(edge==INVALID) 144 { 145 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 148 { 149 EdgeIt e(ms.graph); 150 min = max = ms.get(mapname, e); 151 for (; e != INVALID; ++e) 152 { 153 if (static_cast<double>(ms.get(mapname, e)) > max) 154 max = ms.get(mapname, e); 155 if (static_cast<double>(ms.get(mapname, e)) < min) 156 min = ms.get(mapname, e); 157 } 158 } 159 160 if(edge==INVALID) 161 { 162 for (EdgeIt i(ms.graph); i!=INVALID; ++i) 146 163 { 147 double w= (*actual_map)[i];164 double w=ms.get(mapname, i); 148 165 149 166 Gdk::Color color; … … 163 180 Gdk::Color color; 164 181 165 double w= (*actual_map)[edge];182 double w=ms.get(mapname, edge); 166 183 167 184 if(max!=min) … … 181 198 int GraphDisplayerCanvas::resetEdgeColor (Edge edge) 182 199 { 200 MapStorage& ms = *mytab.mapstorage; 183 201 184 202 //function maps the range of the maximum and 185 203 //the minimum of the nodemap to the range of 186 204 //green in RGB 187 Graph::EdgeMap<double> actual_map( (mytab.mapstorage)->graph,edge_property_defaults[E_COLOR]);205 Graph::EdgeMap<double> actual_map(ms.graph,edge_property_defaults[E_COLOR]); 188 206 189 207 double max, min; … … 193 211 194 212 if(edge==INVALID) 195 { 196 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 197 { 198 double w=actual_map[i]; 199 200 Gdk::Color color; 201 if(max!=min) 202 { 203 color.set_rgb_p (0, 100*(w-min)/(max-min), 0); 204 } 205 else 206 { 207 color.set_rgb_p (0, 100, 0); 208 } 209 edgesmap[i]->setFillColor(color); 210 } 211 } 212 else 213 { 213 { 214 for (EdgeIt i(ms.graph); i!=INVALID; ++i) 215 { 216 double w=actual_map[i]; 217 214 218 Gdk::Color color; 215 216 double w=actual_map[edge];217 218 219 if(max!=min) 219 { 220 color.set_rgb_p (0, 100*(w-min)/(max-min), 0); 221 } 222 else 223 { 224 color.set_rgb_p (0, 100, 0); 225 } 226 227 edgesmap[edge]->setFillColor(color); 228 } 220 { 221 color.set_rgb_p (0, 100*(w-min)/(max-min), 0); 222 } 223 else 224 { 225 color.set_rgb_p (0, 100, 0); 226 } 227 edgesmap[i]->setFillColor(color); 228 } 229 } 230 else 231 { 232 Gdk::Color color; 233 234 double w=actual_map[edge]; 235 236 if(max!=min) 237 { 238 color.set_rgb_p (0, 100*(w-min)/(max-min), 0); 239 } 240 else 241 { 242 color.set_rgb_p (0, 100, 0); 243 } 244 245 edgesmap[edge]->setFillColor(color); 246 } 229 247 return 0; 230 248 }; … … 232 250 int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge) 233 251 { 252 MapStorage& ms = *mytab.mapstorage; 253 234 254 //the number in the map will be written on the edge 235 255 //EXCEPT when the name of the map is Default, because 236 256 //in that case empty string will be written, because 237 257 //that is the deleter map 238 239 if(edge==INVALID) 240 { 241 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 242 { 243 edgemap_to_edit=mapname; 244 double number=(*((mytab.mapstorage)->edgemap_storage)[mapname])[i]; 245 246 std::ostringstream ostr; 247 ostr << number; 248 249 edgetextmap[i]->property_text().set_value(ostr.str()); 250 } 251 252 } 253 else 254 { 255 double number=(*((mytab.mapstorage)->edgemap_storage)[mapname])[edge]; 256 257 std::ostringstream ostr; 258 ostr << number; 259 260 edgetextmap[edge]->property_text().set_value(ostr.str()); 261 } 262 263 return 0; 264 258 259 if(edge==INVALID) 260 { 261 for (EdgeIt i(ms.graph); i!=INVALID; ++i) 262 { 263 edgemap_to_edit=mapname; 264 265 edgetextmap[i]->property_text().set_value( 266 static_cast<std::string>(ms.get(mapname, i))); 267 } 268 269 } 270 else 271 { 272 edgetextmap[edge]->property_text().set_value( 273 static_cast<std::string>(ms.get(mapname, edge))); 274 } 275 276 return 0; 265 277 }; 266 278 267 279 int GraphDisplayerCanvas::resetEdgeText (Edge edge) 268 280 { 281 MapStorage& ms = *mytab.mapstorage; 282 269 283 //the number in the map will be written on the edge 270 284 //EXCEPT when the name of the map is Default, because 271 285 //in that case empty string will be written, because 272 286 //that is the deleter map 273 274 if(edge==INVALID) 275 { 276 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 277 { 278 edgemap_to_edit=""; 279 edgetextmap[i]->property_text().set_value(""); 280 } 281 282 } 283 else 284 { 285 edgetextmap[edge]->property_text().set_value(""); 286 } 287 288 return 0; 289 290 }; 287 288 if(edge==INVALID) 289 { 290 for (EdgeIt i(ms.graph); i!=INVALID; ++i) 291 { 292 edgemap_to_edit=""; 293 edgetextmap[i]->property_text().set_value(""); 294 } 295 } 296 else 297 { 298 edgetextmap[edge]->property_text().set_value(""); 299 } 300 301 return 0; 302 }; -
graph_displayer_canvas-event.cc
r200 r201 34 34 { 35 35 if(actual_tool!=newtool) 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 36 { 37 38 actual_handler.disconnect(); 39 40 switch(actual_tool) 41 { 42 case CREATE_EDGE: 43 { 44 GdkEvent * generated=new GdkEvent(); 45 generated->type=GDK_BUTTON_RELEASE; 46 generated->button.button=3; 47 createEdgeEventHandler(generated); 48 break; 49 } 50 case MAP_EDIT: 51 { 52 break; 53 } 54 default: 55 break; 56 } 57 58 active_item=NULL; 59 target_item=NULL; 60 active_edge=INVALID; 61 active_node=INVALID; 62 63 64 actual_tool=newtool; 65 66 switch(newtool) 67 { 68 case MOVE: 69 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); 70 break; 71 72 case CREATE_NODE: 73 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false); 74 break; 75 76 case CREATE_EDGE: 77 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false); 78 break; 79 80 case ERASER: 81 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false); 82 break; 83 84 case MAP_EDIT: 85 grab_focus(); 86 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::mapEditEventHandler), false); 87 break; 88 89 default: 90 break; 91 } 92 } 93 93 } 94 94 … … 139 139 bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e) 140 140 { 141 MapStorage& ms = *mytab.mapstorage; 142 141 143 static Gnome::Canvas::Text *coord_text = 0; 142 144 switch(e->type) 143 145 { 144 146 case GDK_BUTTON_PRESS: 145 147 //we mark the location of the event to be able to calculate parameters of dragging 146 148 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 147 149 148 150 active_item=(get_item_at(clicked_x, clicked_y)); 149 151 active_node=INVALID; 150 for (NodeIt i( (mytab.mapstorage)->graph); i!=INVALID; ++i)151 152 153 154 155 156 152 for (NodeIt i(ms.graph); i!=INVALID; ++i) 153 { 154 if(nodesmap[i]==active_item) 155 { 156 active_node=i; 157 } 158 } 157 159 isbutton=e->button.button; 158 160 break; 159 161 case GDK_BUTTON_RELEASE: 160 162 if (coord_text) 161 162 163 164 163 { 164 delete coord_text; 165 coord_text = 0; 166 } 165 167 isbutton=0; 166 168 active_item=NULL; … … 170 172 //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 171 173 if(active_node!=INVALID) 172 173 (mytab.mapstorage)->modified = true;174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 (mytab.mapstorage)->coords[active_node].x << ", " <<196 (mytab.mapstorage)->coords[active_node].y << ")";197 198 199 200 201 202 203 coord_text->property_x().set_value((mytab.mapstorage)->coords[active_node].x + 204 205 coord_text->property_y().set_value((mytab.mapstorage)->coords[active_node].y - 206 207 208 209 210 211 212 (mytab.mapstorage)->coords[active_node].x + radius,213 (mytab.mapstorage)->coords[active_node].y - radius,214 215 216 217 218 219 220 174 { 175 ms.setModified(); 176 177 //new coordinates will be the old values, 178 //because the item will be moved to the 179 //new coordinate therefore the new movement 180 //has to be calculated from here 181 182 double new_x, new_y; 183 184 window_to_world (e->motion.x, e->motion.y, new_x, new_y); 185 186 double dx=new_x-clicked_x; 187 double dy=new_y-clicked_y; 188 189 moveNode(dx, dy); 190 191 clicked_x=new_x; 192 clicked_y=new_y; 193 194 // reposition the coordinates text 195 std::ostringstream ostr; 196 ostr << "(" << 197 ms.getNodeCoords(active_node).x << ", " << 198 ms.getNodeCoords(active_node).y << ")"; 199 double radius = 200 (nodesmap[active_node]->property_x2().get_value() - 201 nodesmap[active_node]->property_x1().get_value()) / 2.0; 202 if (coord_text) 203 { 204 coord_text->property_text().set_value(ostr.str()); 205 coord_text->property_x().set_value( 206 ms.getNodeCoords(active_node).x + radius); 207 coord_text->property_y().set_value( 208 ms.getNodeCoords(active_node).y - radius); 209 } 210 else 211 { 212 coord_text = new Gnome::Canvas::Text( 213 displayed_graph, 214 ms.getNodeCoords(active_node).x + radius, 215 ms.getNodeCoords(active_node).y - radius, 216 ostr.str()); 217 coord_text->property_fill_color().set_value("black"); 218 coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST); 219 } 220 221 222 } 221 223 default: break; 222 223 224 return false;224 } 225 226 return false; 225 227 } 226 228 … … 228 230 { 229 231 switch(move_code) 230 232 { 231 233 case 1: 232 234 return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0); … … 237 239 case 3: 238 240 { 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 241 ////////////////////////////////////////////////////////////////////////////////////////////////////// 242 /////////// keeps shape-with scalar multiplication - version 2. 243 ////////////////////////////////////////////////////////////////////////////////////////////////////// 244 245 //old vector from one to the other node - a 246 XY a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y); 247 //new vector from one to the other node - b 248 XY b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y); 249 250 double absa=sqrt(a_v.normSquare()); 251 double absb=sqrt(b_v.normSquare()); 252 253 if ((absa == 0.0) || (absb == 0.0)) 254 { 255 return old_arrow_pos; 256 } 257 else 258 { 259 //old vector from one node to the breakpoint - c 260 XY c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y); 261 262 //unit vector with the same direction to a_v 263 XY a_v_u(a_v.x/absa,a_v.y/absa); 264 265 //normal vector of unit vector with the same direction to a_v 266 XY a_v_u_n(((-1)*a_v_u.y),a_v_u.x); 267 268 //unit vector with the same direction to b_v 269 XY b_v_u(b_v.x/absb,b_v.y/absb); 270 271 //normal vector of unit vector with the same direction to b_v 272 XY b_v_u_n(((-1)*b_v_u.y),b_v_u.x); 273 274 //vector c in a_v_u and a_v_u_n co-ordinate system 275 XY c_a(c_v*a_v_u,c_v*a_v_u_n); 276 277 //new vector from one node to the breakpoint - d - we have to calculate this one 278 XY d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n); 279 280 return XY(d_v.x+fix_node.x,d_v.y+fix_node.y); 281 } 282 break; 281 283 } 282 284 default: 283 285 break; 284 286 } 285 287 } 286 288 … … 288 290 bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e) 289 291 { 292 MapStorage& ms = *mytab.mapstorage; 293 290 294 switch(e->type) 291 295 { … … 302 306 303 307 case GDK_BUTTON_RELEASE: 304 (mytab.mapstorage)->modified = true;308 ms.setModified(); 305 309 306 310 is_drawn=true; … … 308 312 isbutton=1; 309 313 310 active_node=(mytab.mapstorage)->graph.addNode();311 312 //initiating values corresponding to new node in maps313 314 314 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 315 315 316 // update coordinates 317 (mytab.mapstorage)->coords.set(active_node, XY(clicked_x, clicked_y)); 318 319 // update all other maps 320 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = 321 (mytab.mapstorage)->nodemap_storage.begin(); it != 322 (mytab.mapstorage)->nodemap_storage.end(); ++it) 323 { 324 if ((it->first != "coordinates_x") && 325 (it->first != "coordinates_y")) 326 { 327 (*(it->second))[active_node] = 328 (mytab.mapstorage)->nodemap_default[it->first]; 329 } 330 } 331 // increment the id map's default value 332 (mytab.mapstorage)->nodemap_default["label"] += 1.0; 316 active_node = ms.addNode(XY(clicked_x, clicked_y)); 333 317 334 318 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, … … 349 333 nodetextmap[active_node]->raise_to_top(); 350 334 351 // mapwin.updateNode(active_node);335 // mapwin.updateNode(active_node); 352 336 propertyUpdate(active_node); 353 337 … … 365 349 bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e) 366 350 { 351 MapStorage& ms = *mytab.mapstorage; 352 367 353 switch(e->type) 368 354 { … … 380 366 active_item=(get_item_at(clicked_x, clicked_y)); 381 367 active_node=INVALID; 382 for (NodeIt i( (mytab.mapstorage)->graph); i!=INVALID; ++i)368 for (NodeIt i(ms.graph); i!=INVALID; ++i) 383 369 { 384 370 if(nodesmap[i]==active_item) … … 409 395 target_item=(get_item_at(clicked_x, clicked_y)); 410 396 Node target_node=INVALID; 411 for (NodeIt i( (mytab.mapstorage)->graph); i!=INVALID; ++i)397 for (NodeIt i(ms.graph); i!=INVALID; ++i) 412 398 { 413 399 if(nodesmap[i]==target_item) … … 419 405 if(target_node!=INVALID) 420 406 { 421 (mytab.mapstorage)->modified = true;407 ms.setModified(); 422 408 423 409 *(nodesmap[target_node]) << 424 410 Gnome::Canvas::Properties::fill_color("red"); 425 411 426 //creating new edge 427 active_edge=(mytab.mapstorage)->graph.addEdge(active_node, 428 target_node); 429 430 // update maps 431 for (std::map<std::string, 432 Graph::EdgeMap<double>*>::const_iterator it = 433 (mytab.mapstorage)->edgemap_storage.begin(); it != 434 (mytab.mapstorage)->edgemap_storage.end(); ++it) 435 { 436 (*(it->second))[active_edge] = 437 (mytab.mapstorage)->edgemap_default[it->first]; 438 } 439 // increment the id map's default value 440 (mytab.mapstorage)->edgemap_default["label"] += 1.0; 412 active_edge = ms.addEdge(active_node, target_node); 441 413 442 414 if(target_node!=active_node) 443 415 { 444 // set the coordinates of the arrow on the new edge 445 MapStorage& ms = *mytab.mapstorage; 446 ms.arrow_pos.set(active_edge, 447 (ms.coords[ms.graph.source(active_edge)] + 448 ms.coords[ms.graph.target(active_edge)])/ 2.0); 449 450 //drawing new edge 451 edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge, 452 *this); 416 edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge, *this); 453 417 } 454 418 else 455 419 { 456 // set the coordinates of the arrow on the new edge 457 MapStorage& ms = *mytab.mapstorage; 458 ms.arrow_pos.set(active_edge, 459 (ms.coords[ms.graph.source(active_edge)] + 460 XY(0.0, 80.0))); 461 462 //drawing new edge 463 edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge, 464 *this); 420 edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge, *this); 465 421 } 466 422 467 423 //initializing edge-text as well, to empty string 468 XY text_pos=m ytab.mapstorage->arrow_pos[active_edge];424 XY text_pos=ms.getArrowCoords(active_edge); 469 425 text_pos+=(XY(10,10)); 470 426 … … 495 451 if(active_item) 496 452 { 497 453 propertyUpdate(active_node,N_COLOR); 498 454 active_item=NULL; 499 455 } 500 456 if(target_item) 501 457 { 502 propertyUpdate((mytab.mapstorage)->graph.target(active_edge),N_COLOR);458 propertyUpdate(ms.graph.target(active_edge),N_COLOR); 503 459 target_item=NULL; 504 460 } … … 515 471 bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e) 516 472 { 473 MapStorage& ms = *mytab.mapstorage; 474 517 475 switch(e->type) 518 476 { 519 477 case GDK_BUTTON_PRESS: 520 478 //finding the clicked items … … 524 482 active_edge=INVALID; 525 483 //was it a node? 526 for (NodeIt i( (mytab.mapstorage)->graph); i!=INVALID; ++i)527 528 529 530 531 532 484 for (NodeIt i(ms.graph); i!=INVALID; ++i) 485 { 486 if(nodesmap[i]==active_item) 487 { 488 active_node=i; 489 } 490 } 533 491 //or was it an edge? 534 492 if(active_node==INVALID) 535 536 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)537 538 539 540 541 542 543 493 { 494 for (EdgeIt i(ms.graph); i!=INVALID; ++i) 495 { 496 if(edgesmap[i]->getLine()==active_item) 497 { 498 active_edge=i; 499 } 500 } 501 } 544 502 545 503 // return if the clicked object is neither an edge nor a node 546 504 if (active_edge == INVALID) return false; 547 505 548 506 //recolor activated item 549 507 if(active_item) 550 551 552 508 { 509 *active_item << Gnome::Canvas::Properties::fill_color("red"); 510 } 553 511 break; 554 512 … … 556 514 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 557 515 if(active_item) 558 559 560 561 562 563 564 565 (mytab.mapstorage)->modified = true;566 567 568 569 for(OutEdgeIt e((mytab.mapstorage)->graph,active_node);e!=INVALID;++e)570 571 572 573 574 for(InEdgeIt e((mytab.mapstorage)->graph,active_node);e!=INVALID;++e)575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 516 { 517 //the cursor was not moved since pressing it 518 if( active_item == ( get_item_at (clicked_x, clicked_y) ) ) 519 { 520 //a node was found 521 if(active_node!=INVALID) 522 { 523 ms.setModified(); 524 525 std::set<Graph::Edge> edges_to_delete; 526 527 for(OutEdgeIt e(ms.graph,active_node);e!=INVALID;++e) 528 { 529 edges_to_delete.insert(e); 530 } 531 532 for(InEdgeIt e(ms.graph,active_node);e!=INVALID;++e) 533 { 534 edges_to_delete.insert(e); 535 } 536 537 //deleting collected edges 538 for(std::set<Graph::Edge>::iterator 539 edge_set_it=edges_to_delete.begin(); 540 edge_set_it!=edges_to_delete.end(); 541 ++edge_set_it) 542 { 543 deleteItem(*edge_set_it); 544 } 545 deleteItem(active_node); 546 } 547 //a simple edge was chosen 548 else if (active_edge != INVALID) 549 { 550 deleteItem(active_edge); 551 } 552 } 553 //pointer was moved, deletion is cancelled 554 else 555 { 556 if(active_node!=INVALID) 557 { 558 *active_item << Gnome::Canvas::Properties::fill_color("blue"); 559 } 560 else if (active_edge != INVALID) 561 { 562 *active_item << Gnome::Canvas::Properties::fill_color("green"); 563 } 564 } 565 } 608 566 //reseting datas 609 567 active_item=NULL; … … 617 575 default: 618 576 break; 619 577 } 620 578 return false; 621 579 } … … 623 581 bool GraphDisplayerCanvas::mapEditEventHandler(GdkEvent* e) 624 582 { 583 MapStorage& ms = *mytab.mapstorage; 584 625 585 if(actual_tool==MAP_EDIT) 626 { 627 switch(e->type) 628 { 629 case GDK_BUTTON_PRESS: 630 { 631 //for determine, whether it was an edge 632 Edge clicked_edge=INVALID; 633 //for determine, whether it was a node 634 Node clicked_node=INVALID; 635 636 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 637 active_item=(get_item_at(clicked_x, clicked_y)); 638 639 //find the activated item between text of nodes 640 for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 641 { 642 //at the same time only one can be active 643 if(nodetextmap[i]==active_item) 644 { 645 clicked_node=i; 646 } 647 } 648 649 //if there was not, search for it between nodes 650 if(clicked_node==INVALID) 651 { 652 for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 653 { 654 //at the same time only one can be active 655 if(nodesmap[i]==active_item) 656 { 657 clicked_node=i; 658 } 659 } 660 } 661 662 if(clicked_node==INVALID) 663 { 664 //find the activated item between texts 665 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 666 { 667 //at the same time only one can be active 668 if(edgetextmap[i]==active_item) 669 { 670 clicked_edge=i; 671 } 672 } 673 674 //if it was not between texts, search for it between edges 675 if(clicked_edge==INVALID) 676 { 677 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 678 { 679 //at the same time only one can be active 680 if((edgesmap[i]->getLine())==active_item) 681 { 682 clicked_edge=i; 683 } 684 } 685 } 686 } 687 688 //if it was really a node... 689 if(clicked_node!=INVALID) 690 { 691 // the id map is not editable 692 if (nodemap_to_edit == "label") return 0; 693 694 //and there is activated map 695 if(nodetextmap[clicked_node]->property_text().get_value()!="") 696 { 697 //activate the general variable for it 698 active_node=clicked_node; 699 700 //create a dialog 701 Gtk::Dialog dialog("Edit value", true); 702 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 703 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); 704 Gtk::VBox* vbox = dialog.get_vbox(); 705 Gtk::SpinButton spin(0.0, 4); 706 spin.set_increments(1.0, 10.0); 707 spin.set_range(-1000000.0, 1000000.0); 708 spin.set_numeric(true); 709 spin.set_value(atof(nodetextmap[active_node]->property_text().get_value().c_str())); 710 vbox->add(spin); 711 spin.show(); 712 switch (dialog.run()) 713 { 714 case Gtk::RESPONSE_NONE: 715 case Gtk::RESPONSE_CANCEL: 716 break; 717 case Gtk::RESPONSE_ACCEPT: 718 double new_value = spin.get_value(); 719 (*(mytab.mapstorage)->nodemap_storage[nodemap_to_edit])[active_node] = 720 new_value; 721 std::ostringstream ostr; 722 ostr << new_value; 723 nodetextmap[active_node]->property_text().set_value(ostr.str()); 724 //mapwin.updateNode(active_node); 725 //mapwin.updateNode(Node(INVALID)); 726 propertyUpdate(Node(INVALID)); 727 } 728 } 729 } 730 else 731 //if it was really an edge... 732 if(clicked_edge!=INVALID) 733 { 734 // the id map is not editable 735 if (edgemap_to_edit == "label") return 0; 736 737 //and there is activated map 738 if(edgetextmap[clicked_edge]->property_text().get_value()!="") 739 { 740 //activate the general variable for it 741 active_edge=clicked_edge; 742 743 //create a dialog 744 Gtk::Dialog dialog("Edit value", true); 745 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 746 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); 747 Gtk::VBox* vbox = dialog.get_vbox(); 748 Gtk::SpinButton spin(0.0, 4); 749 spin.set_increments(1.0, 10.0); 750 spin.set_range(-1000000.0, 1000000.0); 751 spin.set_numeric(true); 752 spin.set_value(atof(edgetextmap[active_edge]->property_text().get_value().c_str())); 753 vbox->add(spin); 754 spin.show(); 755 switch (dialog.run()) 756 { 757 case Gtk::RESPONSE_NONE: 758 case Gtk::RESPONSE_CANCEL: 759 break; 760 case Gtk::RESPONSE_ACCEPT: 761 double new_value = spin.get_value(); 762 (*(mytab.mapstorage)->edgemap_storage[edgemap_to_edit])[active_edge] = 763 new_value; 764 std::ostringstream ostr; 765 ostr << new_value; 766 edgetextmap[active_edge]->property_text().set_value( 767 ostr.str()); 768 //mapwin.updateEdge(active_edge); 769 // mapwin.updateEdge(Edge(INVALID)); 770 propertyUpdate(Edge(INVALID)); 771 } 772 } 773 } 774 break; 775 } 776 default: 777 break; 778 } 779 } 586 { 587 switch(e->type) 588 { 589 case GDK_BUTTON_PRESS: 590 { 591 //for determine, whether it was an edge 592 Edge clicked_edge=INVALID; 593 //for determine, whether it was a node 594 Node clicked_node=INVALID; 595 596 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 597 active_item=(get_item_at(clicked_x, clicked_y)); 598 599 //find the activated item between text of nodes 600 for (NodeIt i(ms.graph); i!=INVALID; ++i) 601 { 602 //at the same time only one can be active 603 if(nodetextmap[i]==active_item) 604 { 605 clicked_node=i; 606 } 607 } 608 609 //if there was not, search for it between nodes 610 if(clicked_node==INVALID) 611 { 612 for (NodeIt i(ms.graph); i!=INVALID; ++i) 613 { 614 //at the same time only one can be active 615 if(nodesmap[i]==active_item) 616 { 617 clicked_node=i; 618 } 619 } 620 } 621 622 if(clicked_node==INVALID) 623 { 624 //find the activated item between texts 625 for (EdgeIt i(ms.graph); i!=INVALID; ++i) 626 { 627 //at the same time only one can be active 628 if(edgetextmap[i]==active_item) 629 { 630 clicked_edge=i; 631 } 632 } 633 634 //if it was not between texts, search for it between edges 635 if(clicked_edge==INVALID) 636 { 637 for (EdgeIt i(ms.graph); i!=INVALID; ++i) 638 { 639 //at the same time only one can be active 640 if((edgesmap[i]->getLine())==active_item) 641 { 642 clicked_edge=i; 643 } 644 } 645 } 646 } 647 648 //if it was really a node... 649 if(clicked_node!=INVALID) 650 { 651 // the id map is not editable 652 if (nodemap_to_edit == "label") return 0; 653 654 //and there is activated map 655 if(nodetextmap[clicked_node]->property_text().get_value()!="") 656 { 657 //activate the general variable for it 658 active_node=clicked_node; 659 660 //create a dialog 661 Gtk::Dialog dialog("Edit value", true); 662 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 663 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); 664 Gtk::VBox* vbox = dialog.get_vbox(); 665 666 /* 667 Gtk::SpinButton spin(0.0, 4); 668 spin.set_increments(1.0, 10.0); 669 spin.set_range(-1000000.0, 1000000.0); 670 spin.set_numeric(true); 671 spin.set_value(atof(nodetextmap[active_node]->property_text().get_value().c_str())); 672 vbox->add(spin); 673 spin.show(); 674 */ 675 Gtk::Entry entry; 676 entry.set_text(nodetextmap[active_node]->property_text().get_value()); 677 vbox->add(entry); 678 entry.show(); 679 680 switch (dialog.run()) 681 { 682 case Gtk::RESPONSE_NONE: 683 case Gtk::RESPONSE_CANCEL: 684 break; 685 case Gtk::RESPONSE_ACCEPT: 686 switch (ms.getNodeMapElementType(nodemap_to_edit)) 687 { 688 case MapValue::NUMERIC: 689 ms.set(nodemap_to_edit, active_node, 690 atof(entry.get_text().c_str())); 691 break; 692 case MapValue::STRING: 693 ms.set(nodemap_to_edit, active_node, 694 static_cast<std::string>(entry.get_text())); 695 break; 696 } 697 nodetextmap[active_node]->property_text().set_value( 698 static_cast<std::string>(ms.get(nodemap_to_edit, active_node))); 699 700 //mapwin.updateNode(active_node); 701 //mapwin.updateNode(Node(INVALID)); 702 propertyUpdate(Node(INVALID)); 703 } 704 } 705 } 706 else 707 //if it was really an edge... 708 if(clicked_edge!=INVALID) 709 { 710 // the id map is not editable 711 if (edgemap_to_edit == "label") return 0; 712 713 //and there is activated map 714 if(edgetextmap[clicked_edge]->property_text().get_value()!="") 715 { 716 //activate the general variable for it 717 active_edge=clicked_edge; 718 719 //create a dialog 720 Gtk::Dialog dialog("Edit value", true); 721 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 722 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); 723 Gtk::VBox* vbox = dialog.get_vbox(); 724 725 /* 726 Gtk::SpinButton spin(0.0, 4); 727 spin.set_increments(1.0, 10.0); 728 spin.set_range(-1000000.0, 1000000.0); 729 spin.set_numeric(true); 730 spin.set_value(atof(edgetextmap[active_edge]->property_text().get_value().c_str())); 731 vbox->add(spin); 732 spin.show(); 733 */ 734 Gtk::Entry entry; 735 entry.set_text(edgetextmap[active_edge]->property_text().get_value()); 736 vbox->add(entry); 737 entry.show(); 738 739 std::cout << edgemap_to_edit << std::endl; 740 switch (dialog.run()) 741 { 742 case Gtk::RESPONSE_NONE: 743 case Gtk::RESPONSE_CANCEL: 744 break; 745 case Gtk::RESPONSE_ACCEPT: 746 switch (ms.getEdgeMapElementType(edgemap_to_edit)) 747 { 748 case MapValue::NUMERIC: 749 ms.set(edgemap_to_edit, active_edge, 750 atof(entry.get_text().c_str())); 751 break; 752 case MapValue::STRING: 753 ms.set(edgemap_to_edit, active_edge, 754 static_cast<std::string>(entry.get_text())); 755 break; 756 } 757 edgetextmap[active_edge]->property_text().set_value( 758 static_cast<std::string>(ms.get(edgemap_to_edit, active_edge))); 759 760 //mapwin.updateEdge(active_edge); 761 // mapwin.updateEdge(Edge(INVALID)); 762 propertyUpdate(Edge(INVALID)); 763 } 764 } 765 } 766 break; 767 } 768 default: 769 break; 770 } 771 } 780 772 return false; 781 773 } … … 785 777 delete(nodetextmap[node_to_delete]); 786 778 delete(nodesmap[node_to_delete]); 787 (mytab.mapstorage)->graph.erase(node_to_delete);779 mytab.mapstorage->graph.erase(node_to_delete); 788 780 } 789 781 … … 792 784 delete(edgetextmap[edge_to_delete]); 793 785 delete(edgesmap[edge_to_delete]); 794 (mytab.mapstorage)->graph.erase(edge_to_delete);786 mytab.mapstorage->graph.erase(edge_to_delete); 795 787 } 796 788 … … 812 804 else 813 805 { 814 for (EdgeIt i( (mytab.mapstorage)->graph); i!=INVALID; ++i)806 for (EdgeIt i(mytab.mapstorage->graph); i!=INVALID; ++i) 815 807 { 816 808 if(edgesmap[i]==active_bre) … … 822 814 } 823 815 else 824 825 826 827 828 829 830 831 832 833 816 { 817 if(forming_edge!=INVALID) 818 { 819 forming_edge=INVALID; 820 } 821 else 822 { 823 std::cerr << "ERROR!!!! Invalid edge found!" << std::endl; 824 } 825 } 834 826 } 835 827 836 828 void GraphDisplayerCanvas::moveNode(double dx, double dy, Gnome::Canvas::Item * item, Node node) 837 829 { 830 MapStorage& ms = *mytab.mapstorage; 831 838 832 Gnome::Canvas::Item * moved_item=item; 839 833 Node moved_node=node; 840 834 841 835 if(item==NULL && node==INVALID) 842 843 844 845 836 { 837 moved_item=active_item; 838 moved_node=active_node; 839 } 846 840 else 847 848 849 841 { 842 isbutton=1; 843 } 850 844 851 845 //repositioning node and its text … … 854 848 855 849 // the new coordinates of the centre of the node 856 double coord_x = dx + (mytab.mapstorage)->coords[moved_node].x;857 double coord_y = dy + (mytab.mapstorage)->coords[moved_node].y;850 double coord_x = dx + ms.getNodeCoords(moved_node).x; 851 double coord_y = dy + ms.getNodeCoords(moved_node).y; 858 852 859 853 // write back the new coordinates to the coords map 860 (mytab.mapstorage)->coords.set(moved_node, XY(coord_x, coord_y));854 ms.setNodeCoords(moved_node, XY(coord_x, coord_y)); 861 855 862 856 //all the edges connected to the moved point has to be redrawn 863 for(OutEdgeIt ei((mytab.mapstorage)->graph,moved_node);ei!=INVALID;++ei) 864 { 857 for(OutEdgeIt ei(ms.graph,moved_node);ei!=INVALID;++ei) 858 { 859 XY arrow_pos; 860 861 if (ms.graph.source(ei) == ms.graph.target(ei)) 862 { 863 arrow_pos = ms.getArrowCoords(ei) + XY(dx, dy); 864 } 865 else 866 { 867 XY moved_node_1(coord_x - dx, coord_y - dy); 868 XY moved_node_2(coord_x, coord_y); 869 Node target = ms.graph.target(ei); 870 XY fix_node = ms.getNodeCoords(target); 871 XY old_arrow_pos(ms.getArrowCoords(ei)); 872 873 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); 874 } 875 876 ms.setArrowCoords(ei, arrow_pos); 877 edgesmap[ei]->draw(); 878 879 //reposition of edgetext 880 XY text_pos=ms.getArrowCoords(ei); 881 text_pos+=(XY(10,10)); 882 edgetextmap[ei]->property_x().set_value(text_pos.x); 883 edgetextmap[ei]->property_y().set_value(text_pos.y); 884 } 885 886 for(InEdgeIt ei(ms.graph,moved_node);ei!=INVALID;++ei) 887 { 888 if (ms.graph.source(ei) != ms.graph.target(ei)) 889 { 890 XY moved_node_1(coord_x - dx, coord_y - dy); 891 XY moved_node_2(coord_x, coord_y); 892 Node source = ms.graph.source(ei); 893 XY fix_node = ms.getNodeCoords(source); 894 XY old_arrow_pos(ms.getArrowCoords(ei)); 895 865 896 XY arrow_pos; 866 867 if (mytab.mapstorage->graph.source(ei) == mytab.mapstorage->graph.target(ei)) 868 { 869 arrow_pos = mytab.mapstorage->arrow_pos[ei] + XY(dx, dy); 870 } 871 else 872 { 873 XY moved_node_1(coord_x - dx, coord_y - dy); 874 XY moved_node_2(coord_x, coord_y); 875 Node target = mytab.mapstorage->graph.target(ei); 876 XY fix_node(mytab.mapstorage->coords[target].x, 877 mytab.mapstorage->coords[target].y); 878 XY old_arrow_pos(mytab.mapstorage->arrow_pos[ei]); 879 880 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); 881 } 882 883 mytab.mapstorage->arrow_pos.set(ei, arrow_pos); 897 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); 898 899 ms.setArrowCoords(ei, arrow_pos); 884 900 edgesmap[ei]->draw(); 885 901 886 902 //reposition of edgetext 887 XY text_pos=m ytab.mapstorage->arrow_pos[ei];903 XY text_pos=ms.getArrowCoords(ei); 888 904 text_pos+=(XY(10,10)); 889 905 edgetextmap[ei]->property_x().set_value(text_pos.x); 890 906 edgetextmap[ei]->property_y().set_value(text_pos.y); 891 907 } 892 893 for(InEdgeIt ei((mytab.mapstorage)->graph,moved_node);ei!=INVALID;++ei) 894 { 895 if (mytab.mapstorage->graph.source(ei) != mytab.mapstorage->graph.target(ei)) 896 { 897 XY moved_node_1(coord_x - dx, coord_y - dy); 898 XY moved_node_2(coord_x, coord_y); 899 Node source = mytab.mapstorage->graph.source(ei); 900 XY fix_node(mytab.mapstorage->coords[source].x, 901 mytab.mapstorage->coords[source].y); 902 XY old_arrow_pos(mytab.mapstorage->arrow_pos[ei]); 903 904 XY arrow_pos; 905 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); 906 907 mytab.mapstorage->arrow_pos.set(ei, arrow_pos); 908 edgesmap[ei]->draw(); 909 910 //reposition of edgetext 911 XY text_pos=mytab.mapstorage->arrow_pos[ei]; 912 text_pos+=(XY(10,10)); 913 edgetextmap[ei]->property_x().set_value(text_pos.x); 914 edgetextmap[ei]->property_y().set_value(text_pos.y); 915 } 916 } 908 } 917 909 } 918 910 … … 929 921 //the actual value belongs to 930 922 for (int i=0;i<=5;i++) 931 932 933 934 935 936 923 { 924 if(((double)i/6<pos)&&(pos<=(double(i+1)/6))) 925 { 926 phase=i; 927 } 928 } 937 929 if(phase<6) 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 930 { 931 //within its 1/6 long phase the relativ position 932 //determines the power of the color changed in 933 //that phase 934 //we normalize that to one, to be able to give percentage 935 //value for the function 936 double rel_pos=(pos-(phase/6.0))*6.0; 937 938 switch(phase) 939 { 940 case 0: 941 color.set_rgb_p (1, 0, 1-rel_pos); 942 break; 943 case 1: 944 color.set_rgb_p (1, rel_pos, 0); 945 break; 946 case 2: 947 color.set_rgb_p (1-rel_pos, 1, 0); 948 break; 949 case 3: 950 color.set_rgb_p (0, 1, rel_pos); 951 break; 952 case 4: 953 color.set_rgb_p (0, 1-rel_pos, 1); 954 break; 955 case 5: 956 color.set_rgb_p ((rel_pos/3.0), 0, 1); 957 break; 958 default: 959 std::cout << "Wrong phase: " << phase << " " << pos << std::endl; 960 } 961 } 970 962 else 971 972 973 963 { 964 std::cout << "Wrong phase: " << phase << " " << pos << std::endl; 965 } 974 966 return color; 975 967 } -
graph_displayer_canvas-node.cc
r194 r201 26 26 int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node) 27 27 { 28 Graph::NodeMap<double> * actual_map; 28 MapStorage& ms = *mytab.mapstorage; 29 29 30 double min, max; 30 min=(mytab.mapstorage)->minOfNodeMap(mapname); 31 max=(mytab.mapstorage)->maxOfNodeMap(mapname); 32 actual_map=((mytab.mapstorage)->nodemap_storage)[mapname]; 33 34 if(node==INVALID) 35 { 36 for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 37 { 38 double v=fabs((*actual_map)[i]); 31 32 { 33 NodeIt n(ms.graph); 34 min = max = ms.get(mapname, n); 35 for (; n != INVALID; ++n) 36 { 37 if (static_cast<double>(ms.get(mapname, n)) > max) 38 max = ms.get(mapname, n); 39 if (static_cast<double>(ms.get(mapname, n)) < min) 40 min = ms.get(mapname, n); 41 } 42 } 43 44 if(node==INVALID) 45 { 46 for (NodeIt i(ms.graph); i!=INVALID; ++i) 47 { 48 double v=fabs(ms.get(mapname,i)); 39 49 int w; 40 50 if(autoscale) … … 103 113 int GraphDisplayerCanvas::resetNodeRadius (Node node) 104 114 { 115 MapStorage& ms = *mytab.mapstorage; 116 105 117 double min, max; 106 118 min=node_property_defaults[N_RADIUS]; 107 119 max=node_property_defaults[N_RADIUS]; 108 Graph::NodeMap<double> actual_map( (mytab.mapstorage)->graph,node_property_defaults[N_RADIUS]);120 Graph::NodeMap<double> actual_map(ms.graph,node_property_defaults[N_RADIUS]); 109 121 110 122 if(node==INVALID) 111 123 { 112 for (NodeIt i( (mytab.mapstorage)->graph); i!=INVALID; ++i)124 for (NodeIt i(ms.graph); i!=INVALID; ++i) 113 125 { 114 126 double v=fabs(actual_map[i]); … … 164 176 int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node) 165 177 { 178 MapStorage& ms = *mytab.mapstorage; 166 179 167 180 //function maps the range of the maximum and … … 169 182 //green in RGB 170 183 171 Graph::NodeMap<double> * actual_map;172 actual_map=((mytab.mapstorage)->nodemap_storage)[mapname];173 174 184 double max, min; 175 185 176 max=(mytab.mapstorage)->maxOfNodeMap(mapname); 177 min=(mytab.mapstorage)->minOfNodeMap(mapname); 178 179 if(node==INVALID) 180 { 181 182 for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 186 { 187 NodeIt n(ms.graph); 188 min = max = ms.get(mapname, n); 189 for (; n != INVALID; ++n) 190 { 191 if (static_cast<double>(ms.get(mapname, n)) > max) 192 max = ms.get(mapname, n); 193 if (static_cast<double>(ms.get(mapname, n)) < min) 194 min = ms.get(mapname, n); 195 } 196 } 197 198 if(node==INVALID) 199 { 200 201 for (NodeIt i(ms.graph); i!=INVALID; ++i) 183 202 { 184 203 Gdk::Color color; 185 204 186 double w= (*actual_map)[i];205 double w=ms.get(mapname, i); 187 206 188 207 if(max!=min) … … 202 221 Gdk::Color color; 203 222 204 double w= (*actual_map)[node];223 double w=ms.get(mapname, node); 205 224 206 225 if(max!=min) … … 220 239 int GraphDisplayerCanvas::resetNodeColor (Node node) 221 240 { 241 MapStorage& ms = *mytab.mapstorage; 222 242 223 243 //function maps the range of the maximum and … … 225 245 //green in RGB 226 246 227 Graph::NodeMap<double> actual_map( (mytab.mapstorage)->graph,node_property_defaults[N_COLOR]);247 Graph::NodeMap<double> actual_map(ms.graph,node_property_defaults[N_COLOR]); 228 248 229 249 double max, min; … … 235 255 { 236 256 237 for (NodeIt i( (mytab.mapstorage)->graph); i!=INVALID; ++i)257 for (NodeIt i(ms.graph); i!=INVALID; ++i) 238 258 { 239 259 Gdk::Color color; … … 275 295 int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node) 276 296 { 297 MapStorage& ms = *mytab.mapstorage; 277 298 278 299 //the number in the map will be written on the node … … 281 302 //that is the deleter map 282 303 283 Graph::NodeMap<double> * actual_map=NULL; 284 actual_map=((mytab.mapstorage)->nodemap_storage)[mapname]; 285 286 if(node==INVALID) 287 { 288 for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 304 if(node==INVALID) 305 { 306 for (NodeIt i(ms.graph); i!=INVALID; ++i) 289 307 { 290 308 nodemap_to_edit=mapname; 291 double number=(*actual_map)[i]; 292 293 std::ostringstream ostr; 294 ostr << number; 295 296 nodetextmap[i]->property_text().set_value(ostr.str()); 297 } 298 } 299 else 300 { 301 double number=(*actual_map)[node]; 302 303 std::ostringstream ostr; 304 ostr << number; 305 306 nodetextmap[node]->property_text().set_value(ostr.str()); 309 310 nodetextmap[i]->property_text().set_value( 311 static_cast<std::string>(ms.get(mapname, i))); 312 } 313 } 314 else 315 { 316 nodetextmap[node]->property_text().set_value( 317 static_cast<std::string>(ms.get(mapname, node))); 307 318 } 308 319 return 0; … … 311 322 int GraphDisplayerCanvas::resetNodeText (Node node) 312 323 { 324 MapStorage& ms = *mytab.mapstorage; 313 325 314 326 //the number in the map will be written on the node … … 319 331 if(node==INVALID) 320 332 { 321 for (NodeIt i( (mytab.mapstorage)->graph); i!=INVALID; ++i)333 for (NodeIt i(ms.graph); i!=INVALID; ++i) 322 334 { 323 335 nodemap_to_edit=""; -
graph_displayer_canvas.cc
r194 r201 118 118 119 119 if(is_drawn) 120 { 121 if(mapname!="") 122 { 123 if( ( ((mytab.mapstorage)->nodemap_storage).find(mapname) != ((mytab.mapstorage)->nodemap_storage).end() ) ) 124 { 125 switch(prop) 126 { 127 case N_RADIUS: 128 changeNodeRadius(mapname, node); 129 break; 130 case N_COLOR: 131 changeNodeColor(mapname, node); 132 break; 133 case N_TEXT: 134 changeNodeText(mapname, node); 135 break; 136 default: 137 std::cerr<<"Error\n"; 138 } 139 } 140 } 141 else //mapname=="" 142 { 143 Node node=INVALID; 144 switch(prop) 145 { 146 case N_RADIUS: 147 resetNodeRadius(node); 148 break; 149 case N_COLOR: 150 resetNodeColor(node); 151 break; 152 case N_TEXT: 153 resetNodeText(node); 154 break; 155 default: 156 std::cerr<<"Error\n"; 157 } 158 } 159 } 120 { 121 if(mapname!="") 122 { 123 std::vector<std::string> nodemaps = mytab.mapstorage->getNodeMapList(); 124 bool found = false; 125 for (std::vector<std::string>::const_iterator it = nodemaps.begin(); 126 it != nodemaps.end(); ++it) 127 { 128 if (*it == mapname) 129 { 130 found = true; 131 break; 132 } 133 } 134 if (found) 135 { 136 switch(prop) 137 { 138 case N_RADIUS: 139 changeNodeRadius(mapname, node); 140 break; 141 case N_COLOR: 142 changeNodeColor(mapname, node); 143 break; 144 case N_TEXT: 145 changeNodeText(mapname, node); 146 break; 147 default: 148 std::cerr<<"Error\n"; 149 } 150 } 151 } 152 else //mapname=="" 153 { 154 Node node=INVALID; 155 switch(prop) 156 { 157 case N_RADIUS: 158 resetNodeRadius(node); 159 break; 160 case N_COLOR: 161 resetNodeColor(node); 162 break; 163 case N_TEXT: 164 resetNodeText(node); 165 break; 166 default: 167 std::cerr<<"Error\n"; 168 } 169 } 170 } 160 171 } 161 172 … … 165 176 166 177 if(is_drawn) 167 { 168 if(mapname!="") 169 { 170 if( ( ((mytab.mapstorage)->edgemap_storage).find(mapname) != ((mytab.mapstorage)->edgemap_storage).end() ) ) 171 { 172 switch(prop) 173 { 174 case E_WIDTH: 175 changeEdgeWidth(mapname, edge); 176 break; 177 case E_COLOR: 178 changeEdgeColor(mapname, edge); 179 break; 180 case E_TEXT: 181 changeEdgeText(mapname, edge); 182 break; 183 default: 184 std::cerr<<"Error\n"; 185 } 186 } 187 } 188 else //mapname=="" 189 { 190 switch(prop) 191 { 192 case E_WIDTH: 193 resetEdgeWidth(edge); 194 break; 195 case E_COLOR: 196 resetEdgeColor(edge); 197 break; 198 case E_TEXT: 199 resetEdgeText(edge); 200 break; 201 default: 202 std::cerr<<"Error\n"; 203 } 204 } 205 } 178 { 179 if(mapname!="") 180 { 181 std::vector<std::string> edgemaps = mytab.mapstorage->getEdgeMapList(); 182 bool found = false; 183 for (std::vector<std::string>::const_iterator it = edgemaps.begin(); 184 it != edgemaps.end(); ++it) 185 { 186 if (*it == mapname) 187 { 188 found = true; 189 break; 190 } 191 } 192 if (found) 193 { 194 switch(prop) 195 { 196 case E_WIDTH: 197 changeEdgeWidth(mapname, edge); 198 break; 199 case E_COLOR: 200 changeEdgeColor(mapname, edge); 201 break; 202 case E_TEXT: 203 changeEdgeText(mapname, edge); 204 break; 205 default: 206 std::cerr<<"Error\n"; 207 } 208 } 209 } 210 else //mapname=="" 211 { 212 switch(prop) 213 { 214 case E_WIDTH: 215 resetEdgeWidth(edge); 216 break; 217 case E_COLOR: 218 resetEdgeColor(edge); 219 break; 220 case E_TEXT: 221 resetEdgeText(edge); 222 break; 223 default: 224 std::cerr<<"Error\n"; 225 } 226 } 227 } 206 228 } 207 229 … … 222 244 //initializing edge-text as well, to empty string 223 245 224 XY text_pos=mytab.mapstorage-> arrow_pos[i];246 XY text_pos=mytab.mapstorage->getArrowCoords(i); 225 247 text_pos+=(XY(10,10)); 226 248 … … 239 261 nodesmap[i]=new Gnome::Canvas::Ellipse( 240 262 displayed_graph, 241 (mytab.mapstorage)->coords[i].x-20,242 (mytab.mapstorage)->coords[i].y-20,243 (mytab.mapstorage)->coords[i].x+20,244 (mytab.mapstorage)->coords[i].y+20);263 mytab.mapstorage->getNodeCoords(i).x-20, 264 mytab.mapstorage->getNodeCoords(i).y-20, 265 mytab.mapstorage->getNodeCoords(i).x+20, 266 mytab.mapstorage->getNodeCoords(i).y+20); 245 267 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue"); 246 268 *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black"); … … 250 272 251 273 XY text_pos( 252 ( (mytab.mapstorage)->coords[i].x+node_property_defaults[N_RADIUS]+5),253 ( (mytab.mapstorage)->coords[i].y+node_property_defaults[N_RADIUS]+5));274 (mytab.mapstorage->getNodeCoords(i).x+node_property_defaults[N_RADIUS]+5), 275 (mytab.mapstorage->getNodeCoords(i).y+node_property_defaults[N_RADIUS]+5)); 254 276 255 277 nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, … … 326 348 void GraphDisplayerCanvas::reDesignGraph() 327 349 { 328 NodeIt firstnode((mytab.mapstorage)->graph); 350 MapStorage& ms = *mytab.mapstorage; 351 NodeIt firstnode(ms.graph); 329 352 //is it not an empty graph? 330 353 if(firstnode!=INVALID) … … 336 359 if(!was_redesigned) 337 360 { 338 NodeIt i( (mytab.mapstorage)->graph);361 NodeIt i(ms.graph); 339 362 340 363 dim2::Point<double> init(init_vector_length*rnd(), … … 348 371 int iterations; 349 372 350 (mytab.mapstorage)->get_design_data(attraction, propulsation, iterations);373 ms.get_design_data(attraction, propulsation, iterations); 351 374 352 375 //iteration counter 353 376 for(int l=0;l<iterations;l++) 354 377 { 355 Graph::NodeMap<double> x(m ytab.mapstorage->graph);356 Graph::NodeMap<double> y(m ytab.mapstorage->graph);378 Graph::NodeMap<double> x(ms.graph); 379 Graph::NodeMap<double> y(ms.graph); 357 380 XYMap<Graph::NodeMap<double> > actual_forces; 358 381 actual_forces.setXMap(x); … … 360 383 361 384 //count actual force for each nodes 362 for (NodeIt i( (mytab.mapstorage)->graph); i!=INVALID; ++i)385 for (NodeIt i(ms.graph); i!=INVALID; ++i) 363 386 { 364 387 //propulsation of nodes 365 for (NodeIt j( (mytab.mapstorage)->graph); j!=INVALID; ++j)388 for (NodeIt j(ms.graph); j!=INVALID; ++j) 366 389 { 367 390 if(i!=j) 368 391 { 369 392 lemon::dim2::Point<double> delta = 370 ( (mytab.mapstorage)->coords[i]-371 (mytab.mapstorage)->coords[j]);393 (ms.getNodeCoords(i)- 394 ms.getNodeCoords(j)); 372 395 373 396 const double length_sqr=std::max(delta.normSquare(),min_dist); … … 383 406 } 384 407 } 385 //attraction of nodes, to which actual node is bound 386 for(OutEdgeIt ei((mytab.mapstorage)->graph,i);ei!=INVALID;++ei) 408 //attraction of nodes, to which actual node is bound 409 for(OutEdgeIt ei(ms.graph,i);ei!=INVALID;++ei) 410 { 411 lemon::dim2::Point<double> delta = 412 (ms.getNodeCoords(i)- 413 ms.getNodeCoords(ms.graph.target(ei))); 414 415 //calculating attraction strength 416 //greater distance means greater strength 417 delta*=attraction; 418 419 actual_forces.set(i,actual_forces[i]-delta); 420 } 421 for(InEdgeIt ei(ms.graph,i);ei!=INVALID;++ei) 422 { 423 lemon::dim2::Point<double> delta = 424 (ms.getNodeCoords(i)- 425 ms.getNodeCoords(ms.graph.source(ei))); 426 427 //calculating attraction strength 428 //greater distance means greater strength 429 delta*=attraction; 430 431 actual_forces.set(i,actual_forces[i]-delta); 432 } 433 } 434 for (NodeIt i(ms.graph); i!=INVALID; ++i) 435 { 436 if((ms.getNodeCoords(i).x)+actual_forces[i].x>max_coord) 387 437 { 388 lemon::dim2::Point<double> delta = 389 ((mytab.mapstorage)->coords[i]- 390 (mytab.mapstorage)->coords[mytab.mapstorage-> 391 graph.target(ei)]); 392 393 //calculating attraction strength 394 //greater distance means greater strength 395 delta*=attraction; 396 397 actual_forces.set(i,actual_forces[i]-delta); 438 actual_forces[i].x=max_coord-(ms.getNodeCoords(i).x); 439 std::cout << "Correction! " << ((ms.getNodeCoords(i).x)+actual_forces[i].x) << std::endl; 398 440 } 399 for(InEdgeIt ei((mytab.mapstorage)->graph,i);ei!=INVALID;++ei)441 else if((ms.getNodeCoords(i).x)+actual_forces[i].x<(0-max_coord)) 400 442 { 401 lemon::dim2::Point<double> delta = 402 ((mytab.mapstorage)->coords[i]- 403 (mytab.mapstorage)->coords[mytab.mapstorage-> 404 graph.source(ei)]); 405 406 //calculating attraction strength 407 //greater distance means greater strength 408 delta*=attraction; 409 410 actual_forces.set(i,actual_forces[i]-delta); 443 actual_forces[i].x=0-max_coord-(ms.getNodeCoords(i).x); 444 std::cout << "Correction! " << ((ms.getNodeCoords(i).x)+actual_forces[i].x) << std::endl; 411 445 } 412 } 413 for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 414 { 415 if(((mytab.mapstorage)->coords[i].x)+actual_forces[i].x>max_coord) 446 if((ms.getNodeCoords(i).y)+actual_forces[i].y>max_coord) 416 447 { 417 actual_forces[i]. x=max_coord-((mytab.mapstorage)->coords[i].x);418 std::cout << "Correction! " << (( (mytab.mapstorage)->coords[i].x)+actual_forces[i].x) << std::endl;448 actual_forces[i].y=max_coord-(ms.getNodeCoords(i).y); 449 std::cout << "Correction! " << ((ms.getNodeCoords(i).y)+actual_forces[i].y) << std::endl; 419 450 } 420 else if(( (mytab.mapstorage)->coords[i].x)+actual_forces[i].x<(0-max_coord))451 else if((ms.getNodeCoords(i).y)+actual_forces[i].y<(0-max_coord)) 421 452 { 422 actual_forces[i].x=0-max_coord-((mytab.mapstorage)->coords[i].x); 423 std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].x)+actual_forces[i].x) << std::endl; 424 } 425 if(((mytab.mapstorage)->coords[i].y)+actual_forces[i].y>max_coord) 426 { 427 actual_forces[i].y=max_coord-((mytab.mapstorage)->coords[i].y); 428 std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].y)+actual_forces[i].y) << std::endl; 429 } 430 else if(((mytab.mapstorage)->coords[i].y)+actual_forces[i].y<(0-max_coord)) 431 { 432 actual_forces[i].y=0-max_coord-((mytab.mapstorage)->coords[i].y); 433 std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].y)+actual_forces[i].y) << std::endl; 453 actual_forces[i].y=0-max_coord-(ms.getNodeCoords(i).y); 454 std::cout << "Correction! " << ((ms.getNodeCoords(i).y)+actual_forces[i].y) << std::endl; 434 455 } 435 456 moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i); -
gui_reader.cc
r194 r201 21 21 22 22 #include <xml.h> 23 #include "io_helper.h" 23 24 #include <lemon/dim2.h> 24 25 #include <vector> … … 34 35 void GuiReader::read(std::istream& is) 35 36 { 37 using std::vector; 38 using std::string; 39 using std::pair; 40 using std::make_pair; 41 using std::string; 42 using std::map; 43 36 44 XmlIo x(is); 37 std::map<int, XY > m;38 x("arrow_pos", m);39 45 40 if ((int)m.size() == countEdges(mapstorage->graph)) 46 { x("main_node_map_names", gui_data.main_node_map_names); } 47 { x("gui_node_map_names", gui_data.gui_node_map_names); } 48 49 { x("node_map_types", gui_data.node_map_types); } 50 51 { x("main_edge_map_names", gui_data.main_edge_map_names); } 52 { x("gui_edge_map_names", gui_data.gui_edge_map_names); } 53 54 { x("edge_map_types", gui_data.edge_map_types); } 55 56 for (vector<string>::const_iterator it = gui_data.gui_node_map_names.begin(); 57 it != gui_data.gui_node_map_names.end(); ++it) 58 { 59 MapValue::Type type = gui_data.node_map_types[*it]; 60 switch (type) 41 61 { 42 for (EdgeIt e(mapstorage->graph); e != INVALID; ++e) 43 { 44 int edgeid = (int)(*mapstorage->edgemap_storage["label"])[e]; 45 mapstorage->arrow_pos.set(e, m[edgeid]); 46 } 47 mapstorage->ArrowPosReadOK(); 62 case MapValue::NUMERIC: 63 { 64 map<int, double>* p_map_data = 65 new map<int, double>; 66 gui_data.numeric_node_maps[*it] = p_map_data; 67 { x(*it, *p_map_data); } 68 } 69 break; 70 case MapValue::STRING: 71 { 72 map<int, string>* p_map_data = 73 new map<int, string>; 74 gui_data.string_node_maps[*it] = p_map_data; 75 { x(*it, *p_map_data); } 76 } 77 break; 48 78 } 49 79 } 80 81 for (vector<string>::const_iterator it = gui_data.gui_edge_map_names.begin(); 82 it != gui_data.gui_edge_map_names.end(); ++it) 83 { 84 MapValue::Type type = gui_data.edge_map_types[*it]; 85 switch (type) 86 { 87 case MapValue::NUMERIC: 88 { 89 map<int, double>* p_map_data = 90 new map<int, double>; 91 gui_data.numeric_edge_maps[*it] = p_map_data; 92 { x(*it, *p_map_data); } 93 } 94 break; 95 case MapValue::STRING: 96 { 97 map<int, string>* p_map_data = 98 new map<int, string>; 99 gui_data.string_edge_maps[*it] = p_map_data; 100 { x(*it, *p_map_data); } 101 } 102 break; 103 } 104 } 105 106 { 107 std::string node_coords_save_dest; 108 { x("node_coords_save_dest", node_coords_save_dest); } 109 if (node_coords_save_dest == "gui_sect") 110 { 111 // read the node coorinates 112 gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::GUI_SECT; 113 { x("node_coord_map", gui_data.node_coord_map); } 114 } 115 else if (node_coords_save_dest == "nodeset_sect_1_map") 116 { 117 gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT; 118 gui_data.node_coords_save_map_num = MapStorage::SpecMapSaveOpts::ONE_MAP; 119 { x("map_name", gui_data.node_coords_one_map_name); } 120 } 121 else if (node_coords_save_dest == "nodeset_sect_2_maps") 122 { 123 gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT; 124 gui_data.node_coords_save_map_num = MapStorage::SpecMapSaveOpts::TWO_MAPS; 125 { x("map1_name", gui_data.node_coords_two_maps_1_name); } 126 { x("map2_name", gui_data.node_coords_two_maps_2_name); } 127 } 128 } 129 130 { 131 std::string arrow_coords_save_dest; 132 { x("arrow_coords_save_dest", arrow_coords_save_dest); } 133 if (arrow_coords_save_dest == "gui_sect") 134 { 135 // read the arrow coorinates 136 gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::GUI_SECT; 137 { x("arrow_coord_map", gui_data.arrow_coord_map); } 138 } 139 else if (arrow_coords_save_dest == "edgeset_sect_1_map") 140 { 141 gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT; 142 gui_data.arrow_coords_save_map_num = MapStorage::SpecMapSaveOpts::ONE_MAP; 143 { x("map_name", gui_data.arrow_coords_one_map_name); } 144 } 145 else if (arrow_coords_save_dest == "edgeset_sect_2_maps") 146 { 147 gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT; 148 gui_data.arrow_coords_save_map_num = MapStorage::SpecMapSaveOpts::TWO_MAPS; 149 { x("map1_name", gui_data.arrow_coords_two_maps_1_name); } 150 { x("map2_name", gui_data.arrow_coords_two_maps_2_name); } 151 } 152 } 153 154 155 50 156 std::map<int, std::string> nm; 51 157 x("active_nodemaps", nm); 52 158 53 159 for(int i=0;i<NODE_PROPERTY_NUM;i++) 54 55 56 160 { 161 mapstorage->changeActiveMap(false, i, nm[i]); 162 } 57 163 58 164 std::map<int, std::string> em; 59 165 x("active_edgemaps", em); 60 166 for(int i=0;i<EDGE_PROPERTY_NUM;i++) 61 62 63 167 { 168 mapstorage->changeActiveMap(true, i, em[i]); 169 } 64 170 65 171 double attraction; … … 78 184 } 79 185 80 GuiReader::GuiReader(LemonReader& reader, MapStorage* ms) : Parent(reader), mapstorage(ms) 186 GuiReader::GuiReader(LemonReader& reader, MapStorage* _mapstorage, 187 MapStorage::GUISectData& _gui_data) : 188 Parent(reader), 189 mapstorage(_mapstorage), 190 gui_data(_gui_data) 81 191 { 82 192 } -
gui_reader.h
r194 r201 21 21 #include <lemon/lemon_reader.h> 22 22 23 class MapStorage; 23 #include "mapstorage.h" 24 24 25 25 using lemon::LemonReader; … … 29 29 private: 30 30 MapStorage* mapstorage; 31 MapStorage::GUISectData& gui_data; 31 32 protected: 32 33 virtual bool header(const std::string&); … … 34 35 public: 35 36 typedef LemonReader::SectionReader Parent; 36 GuiReader(LemonReader&, MapStorage* );37 GuiReader(LemonReader&, MapStorage*, MapStorage::GUISectData&); 37 38 }; 38 39 -
gui_writer.cc
r194 r201 17 17 */ 18 18 19 #include <xml.h> 19 #include "gui_writer.h" 20 #include "io_helper.h" 21 #include "mapstorage.h" 22 #include "xml.h" 20 23 #include <lemon/dim2.h> 21 24 #include <vector> … … 31 34 void GuiWriter::write(std::ostream& os) 32 35 { 36 using std::vector; 37 using std::string; 38 using std::map; 39 using std::string; 40 33 41 XmlIo x(os); 34 std::map<int, XY > m; 35 for (EdgeIt e(mapstorage->graph); e != INVALID; ++e) 36 { 37 int edgeid = (int)(*(mapstorage->edgemap_storage["label"]))[e]; 38 m[edgeid] = mapstorage->arrow_pos[e]; 39 } 40 x("arrow_pos", m); 42 43 vector<string> all_node_map_names = mapstorage->getNodeMapList(); 44 // name of the maps saved to the nodeset section 45 vector<string> main_node_map_names; 46 // name of the maps saved to the gui section 47 vector<string> gui_node_map_names; 48 49 for (vector<string>::const_iterator it = all_node_map_names.begin(); 50 it != all_node_map_names.end(); ++it) 51 { 52 if (mapstorage->getNodeMapSaveDest(*it) == MapStorage::NESET_SECT) 53 main_node_map_names.push_back(*it); 54 else if (mapstorage->getNodeMapSaveDest(*it) == MapStorage::GUI_SECT) 55 gui_node_map_names.push_back(*it); 56 } 57 58 { x("main_node_map_names", main_node_map_names); } 59 { x("gui_node_map_names", gui_node_map_names); } 60 61 map<string, MapValue::Type> node_map_types; 62 for (vector<string>::const_iterator it = main_node_map_names.begin(); 63 it != main_node_map_names.end(); ++it) 64 { 65 node_map_types[*it] = mapstorage->getNodeMapElementType(*it); 66 } 67 for (vector<string>::const_iterator it = gui_node_map_names.begin(); 68 it != gui_node_map_names.end(); ++it) 69 { 70 node_map_types[*it] = mapstorage->getNodeMapElementType(*it); 71 } 72 73 { x("node_map_types", node_map_types); } 74 75 76 vector<string> all_edge_map_names = mapstorage->getEdgeMapList(); 77 // name of the maps saved to the edgeset section 78 vector<string> main_edge_map_names; 79 // name of the maps saved to the gui section 80 vector<string> gui_edge_map_names; 81 82 for (vector<string>::const_iterator it = all_edge_map_names.begin(); 83 it != all_edge_map_names.end(); ++it) 84 { 85 if (mapstorage->getEdgeMapSaveDest(*it) == MapStorage::NESET_SECT) 86 main_edge_map_names.push_back(*it); 87 if (mapstorage->getEdgeMapSaveDest(*it) == MapStorage::GUI_SECT) 88 gui_edge_map_names.push_back(*it); 89 } 90 91 { x("main_edge_map_names", main_edge_map_names); } 92 { x("gui_edge_map_names", gui_edge_map_names); } 93 94 map<string, MapValue::Type> edge_map_types; 95 for (vector<string>::const_iterator it = main_edge_map_names.begin(); 96 it != main_edge_map_names.end(); ++it) 97 { 98 edge_map_types[*it] = mapstorage->getEdgeMapElementType(*it); 99 } 100 for (vector<string>::const_iterator it = gui_edge_map_names.begin(); 101 it != gui_edge_map_names.end(); ++it) 102 { 103 edge_map_types[*it] = mapstorage->getEdgeMapElementType(*it); 104 } 105 106 { x("edge_map_types", edge_map_types); } 107 108 // write the gui node maps 109 for (vector<string>::const_iterator it = gui_node_map_names.begin(); 110 it != gui_node_map_names.end(); ++it) 111 { 112 MapValue::Type type = mapstorage->getNodeMapElementType(*it); 113 const MapStorage::NodeLabelMap& labels = mapstorage->getNodeLabelMap(); 114 switch (type) 115 { 116 case MapValue::NUMERIC: 117 { 118 std::map<int, double> map_data; 119 MapStorage::NumericNodeMap& map = 120 mapstorage->getNumericNodeMap(*it); 121 for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n) 122 { 123 map_data[labels[n]] = map[n]; 124 } 125 { x(*it, map_data); } 126 } 127 break; 128 case MapValue::STRING: 129 { 130 std::map<int, std::string> map_data; 131 MapStorage::StringNodeMap& map = 132 mapstorage->getStringNodeMap(*it); 133 for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n) 134 { 135 map_data[labels[n]] = map[n]; 136 } 137 { x(*it, map_data); } 138 } 139 break; 140 } 141 } 142 143 // write the gui edge maps 144 for (vector<string>::const_iterator it = gui_edge_map_names.begin(); 145 it != gui_edge_map_names.end(); ++it) 146 { 147 MapValue::Type type = mapstorage->getEdgeMapElementType(*it); 148 const MapStorage::EdgeLabelMap& labels = mapstorage->getEdgeLabelMap(); 149 switch (type) 150 { 151 case MapValue::NUMERIC: 152 { 153 std::map<int, double> map_data; 154 MapStorage::NumericEdgeMap& map = 155 mapstorage->getNumericEdgeMap(*it); 156 for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e) 157 { 158 map_data[labels[e]] = map[e]; 159 } 160 { x(*it, map_data); } 161 } 162 break; 163 case MapValue::STRING: 164 { 165 std::map<int, std::string> map_data; 166 MapStorage::StringEdgeMap& map = 167 mapstorage->getStringEdgeMap(*it); 168 for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e) 169 { 170 map_data[labels[e]] = map[e]; 171 } 172 { x(*it, map_data); } 173 } 174 break; 175 } 176 } 177 178 { 179 switch (mapstorage->getNodeCoordsSaveDest()) 180 { 181 case MapStorage::SpecMapSaveOpts::GUI_SECT: 182 { x("node_coords_save_dest", string("gui_sect")); } 183 // write the node coorinates 184 { 185 const MapStorage::NodeLabelMap& labels = 186 mapstorage->getNodeLabelMap(); 187 std::map<int, XY> node_coord_map; 188 MapStorage::NodeCoordMap& map = mapstorage->getNodeCoordMap(); 189 for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n) 190 { 191 node_coord_map[labels[n]] = map[n]; 192 } 193 { x("node_coord_map", node_coord_map); } 194 } 195 break; 196 case MapStorage::SpecMapSaveOpts::NESET_SECT: 197 switch (mapstorage->getNodeCoordsSaveMapNum()) 198 { 199 case MapStorage::SpecMapSaveOpts::ONE_MAP: 200 { x("node_coords_save_dest", string("nodeset_sect_1_map")); } 201 { x("map_name", mapstorage->getNodeCoordsOneMapName()); } 202 break; 203 case MapStorage::SpecMapSaveOpts::TWO_MAPS: 204 { x("node_coords_save_dest", string("nodeset_sect_2_maps")); } 205 { x("map1_name", mapstorage->getNodeCoordsTwoMaps1Name()); } 206 { x("map2_name", mapstorage->getNodeCoordsTwoMaps2Name()); } 207 break; 208 } 209 break; 210 } 211 } 212 213 { 214 switch (mapstorage->getArrowCoordsSaveDest()) 215 { 216 case MapStorage::SpecMapSaveOpts::GUI_SECT: 217 { x("arrow_coords_save_dest", string("gui_sect")); } 218 // write the arrow coorinates 219 { 220 const MapStorage::EdgeLabelMap& labels = 221 mapstorage->getEdgeLabelMap(); 222 std::map<int, XY> arrow_coord_map; 223 MapStorage::ArrowCoordMap& map = mapstorage->getArrowCoordMap(); 224 for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e) 225 { 226 arrow_coord_map[labels[e]] = map[e]; 227 } 228 { x("arrow_coord_map", arrow_coord_map); } 229 } 230 break; 231 case MapStorage::SpecMapSaveOpts::NESET_SECT: 232 switch (mapstorage->getArrowCoordsSaveMapNum()) 233 { 234 case MapStorage::SpecMapSaveOpts::ONE_MAP: 235 { x("arrow_coords_save_dest", string("edgeset_sect_1_map")); } 236 { x("map_name", mapstorage->getArrowCoordsOneMapName()); } 237 break; 238 case MapStorage::SpecMapSaveOpts::TWO_MAPS: 239 { x("arrow_coords_save_dest", string("edgeset_sect_2_maps")); } 240 { x("map1_name", mapstorage->getArrowCoordsTwoMaps1Name()); } 241 { x("map2_name", mapstorage->getArrowCoordsTwoMaps2Name()); } 242 break; 243 } 244 break; 245 } 246 } 247 41 248 42 249 std::map<int, std::string> nm; … … 45 252 nm[i]=mapstorage->active_nodemaps[i]; 46 253 } 47 x("active_nodemaps", nm);254 { x("active_nodemaps", nm); } 48 255 49 256 std::map<int, std::string> em; … … 52 259 em[i]=mapstorage->active_edgemaps[i]; 53 260 } 54 x("active_edgemaps", em);261 { x("active_edgemaps", em); } 55 262 56 263 double attraction; … … 60 267 mapstorage->get_design_data(attraction, propulsation, iteration); 61 268 62 x("redesign-attraction", attraction);63 x("redesign-propulsation", propulsation);64 x("redesign-iteration", iteration);269 { x("redesign-attraction", attraction); } 270 { x("redesign-propulsation", propulsation); } 271 { x("redesign-iteration", iteration); } 65 272 } 66 273 67 GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) : Parent(writer), mapstorage(ms) 274 GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) : 275 Parent(writer), 276 mapstorage(ms) 68 277 { 69 278 } -
kruskalbox.cc
r194 r201 34 34 { 35 35 if( 36 tabcbt.get_active_text()!="" && 37 (edgemapcbts[INPUT])->get_active_text()!="" && 38 (edgemapcbts[OUTPUT])->get_active_text()!="" 39 ) 36 tabcbt.get_active_text()!="" && 37 (edgemapcbts[INPUT])->get_active_text()!="" && 38 (edgemapcbts[OUTPUT])->get_active_text()!="" 39 ) 40 { 41 42 const Graph &g=mapstorage->getGraph(); 43 std::string input_map_name = edgemapcbts[INPUT]->get_active_text(); 44 Graph::EdgeMap<bool> outputmap(g); 45 const MapStorage::NumericEdgeMap& inputmap= 46 mapstorage->getNumericEdgeMap(input_map_name); 47 double res=kruskal(g, inputmap, outputmap); 48 49 for (EdgeIt i(g); i!=INVALID; ++i) 40 50 { 51 if(outputmap[i]) 52 { 53 mapstorage->set(edgemapcbts[OUTPUT]->get_active_text(), i, 1.0); 54 } 55 else 56 { 57 mapstorage->set(edgemapcbts[OUTPUT]->get_active_text(), i, 0.0); 58 } 59 } 41 60 42 const Graph &g=mapstorage->graph; 43 Graph::EdgeMap<double> * inputmap= 44 ((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]); 45 Graph::EdgeMap<bool> outputmap(g); 46 double res=kruskal(g, *inputmap, outputmap); 61 std::ostringstream o; 62 o << "Result: " << res; 63 resultlabel.set_text(o.str()); 47 64 48 for (EdgeIt i(g); i!=INVALID; ++i) 49 { 50 if(outputmap[i]) 51 { 52 (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])-> 53 get_active_text()]))[i]=1; 54 } 55 else 56 { 57 (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])-> 58 get_active_text()]))[i]=0; 59 } 60 } 65 mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text()); 66 // mapstorage->changeActiveMap(true, E_COLOR, 67 // (edgemapcbts[OUTPUT])->get_active_text()); 68 // mapstorage->changeActiveMap(true, E_TEXT, 69 // (edgemapcbts[INPUT])->get_active_text()); 61 70 62 std::ostringstream o; 63 o << "Result: " << res; 64 resultlabel.set_text(o.str()); 65 66 mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text()); 67 // mapstorage->changeActiveMap(true, E_COLOR, 68 // (edgemapcbts[OUTPUT])->get_active_text()); 69 // mapstorage->changeActiveMap(true, E_TEXT, 70 // (edgemapcbts[INPUT])->get_active_text()); 71 72 } 71 } 73 72 } 74 73 … … 77 76 std::vector<std::string> empty_vector; 78 77 79 addMapSelector("Edgecosts: ", true );80 addMapSelector("Edges of tree here: ", true );78 addMapSelector("Edgecosts: ", true, NUM); 79 addMapSelector("Edges of tree here: ", true, NUM); 81 80 82 81 resultlabel.set_text("Result: algorithm is not run yet."); -
main_win.cc
r194 r201 21 21 #endif 22 22 23 #include <main_win.h> 24 #include <guipixbufs.h> 25 #include <background_chooser_dialog.h> 23 #include "main_win.h" 24 #include "guipixbufs.h" 25 #include "save_details_dialog.h" 26 #include "background_chooser_dialog.h" 26 27 27 28 #include <mapstorage.h> … … 115 116 ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS), 116 117 sigc::mem_fun(*this, &MainWin::saveFileAs)); 118 ag->add( Gtk::Action::create("SaveDetails", _("Save _Details...")), 119 sigc::mem_fun(*this, &MainWin::createSaveDetailsDialog)); 117 120 ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE), 118 121 sigc::mem_fun(*this, &MainWin::closeTab)); … … 161 164 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) ); 162 165 163 ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap") ),166 ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap"), "New map"), 164 167 sigc::mem_fun ( *this , &MainWin::createNewMapWin ) ); 165 168 … … 167 170 sigc::mem_fun ( *this , &MainWin::reDesignGraph ) ); 168 171 169 ag->add( Gtk::Action::create("Eps", Gtk::StockID("gd-eps") ),172 ag->add( Gtk::Action::create("Eps", Gtk::StockID("gd-eps"), "Export to EPS"), 170 173 sigc::mem_fun ( *this , &MainWin::exportToEPS ) ); 171 174 … … 186 189 " <menuitem action='FileSave'/>" 187 190 " <menuitem action='FileSaveAs'/>" 191 " <menuitem action='SaveDetails'/>" 188 192 " <menuitem action='Close'/>" 189 193 " <menuitem action='Quit'/>" … … 371 375 if(active_tab!=-1) 372 376 { 373 if (tabs[active_tab]->mapstorage-> modified)377 if (tabs[active_tab]->mapstorage->getModified()) 374 378 { 375 379 Gtk::MessageDialog mdialog(_("<b>Save changes before closing?</b>"), true, … … 629 633 } 630 634 635 void MainWin::createSaveDetailsDialog() 636 { 637 SaveDetailsDialog dialog(tabs[active_tab]->mapstorage); 638 dialog.run(); 639 } 640 631 641 void MainWin::exportToEPS() 632 642 { -
main_win.h
r194 r201 261 261 virtual void reDesignGraph(); 262 262 263 /// Pops up a SaveDetailsDialog. 264 void createSaveDetailsDialog(); 265 263 266 virtual void exportToEPS(); 264 267 -
map_win.cc
r194 r201 32 32 } 33 33 34 MapWin::MapWin(const std::string& title, std::vector<std::string> eml, std::vector<std::string> nml, NoteBookTab & mw):mytab(mw) 34 MapWin::MapWin(const std::string& title, 35 std::vector<std::string> n_eml, 36 std::vector<std::string> s_eml, 37 std::vector<std::string> n_nml, 38 std::vector<std::string> s_nml, 39 NoteBookTab & mw):mytab(mw) 35 40 { 36 41 set_title(title); … … 49 54 for(int i=0;i<EDGE_PROPERTY_NUM;i++) 50 55 { 51 e_combo_array[i]=new MapSelector(eml, mytab.getActiveEdgeMap(i), edge_property_strings[i], true); 56 switch (i) 57 { 58 case E_WIDTH: 59 e_combo_array[i]=new MapSelector(n_eml, s_eml, 60 mytab.getActiveEdgeMap(i), edge_property_strings[i], 61 true, true, NUM); 62 break; 63 case E_COLOR: 64 e_combo_array[i]=new MapSelector(n_eml, s_eml, 65 mytab.getActiveEdgeMap(i), edge_property_strings[i], 66 true, true, NUM); 67 break; 68 case E_TEXT: 69 e_combo_array[i]=new MapSelector(n_eml, s_eml, 70 mytab.getActiveEdgeMap(i), edge_property_strings[i], 71 true, true, ALL); 72 break; 73 } 52 74 53 75 (*table).attach((*(e_combo_array[i])),0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3); … … 69 91 for(int i=0;i<NODE_PROPERTY_NUM;i++) 70 92 { 71 n_combo_array[i]=new MapSelector(nml, mytab.getActiveNodeMap(i), node_property_strings[i], false); 93 switch (i) 94 { 95 case N_RADIUS: 96 n_combo_array[i]=new MapSelector(n_nml, s_nml, 97 mytab.getActiveNodeMap(i), node_property_strings[i], 98 false, true, NUM); 99 break; 100 case N_COLOR: 101 n_combo_array[i]=new MapSelector(n_nml, s_nml, 102 mytab.getActiveNodeMap(i), node_property_strings[i], 103 false, true, NUM); 104 break; 105 case N_TEXT: 106 n_combo_array[i]=new MapSelector(n_nml, s_nml, 107 mytab.getActiveNodeMap(i), node_property_strings[i], 108 false, true, ALL); 109 break; 110 } 72 111 73 112 (*table).attach((*(n_combo_array[i])),0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3); … … 83 122 vbox.pack_start(*table); 84 123 124 update(n_eml, s_eml, n_nml, s_nml); 125 85 126 show_all_children(); 86 127 … … 102 143 } 103 144 104 void MapWin::update(std::vector<std::string> eml, std::vector<std::string> nml) 145 void MapWin::update( 146 std::vector<std::string> n_eml, 147 std::vector<std::string> s_eml, 148 std::vector<std::string> n_nml, 149 std::vector<std::string> s_nml) 105 150 { 106 151 for(int i=0;i<EDGE_PROPERTY_NUM;i++) 107 152 { 108 e_combo_array[i]->update_list( eml);153 e_combo_array[i]->update_list(n_eml, s_eml); 109 154 } 110 155 111 156 for(int i=0;i<NODE_PROPERTY_NUM;i++) 112 157 { 113 n_combo_array[i]->update_list(n ml);158 n_combo_array[i]->update_list(n_nml, s_nml); 114 159 } 115 160 … … 117 162 } 118 163 119 void MapWin::registerNewEdgeMap(std::string newmapname )164 void MapWin::registerNewEdgeMap(std::string newmapname, MapValue::Type type) 120 165 { 121 166 for(int i=0;i<EDGE_PROPERTY_NUM;i++) 122 167 { 123 168 //filling in combo box with choices 124 e_combo_array[i]->append_text((Glib::ustring)newmapname );125 } 126 } 127 128 void MapWin::registerNewNodeMap(std::string newmapname )169 e_combo_array[i]->append_text((Glib::ustring)newmapname, type); 170 } 171 } 172 173 void MapWin::registerNewNodeMap(std::string newmapname, MapValue::Type type) 129 174 { 130 175 for(int i=0;i<NODE_PROPERTY_NUM;i++) 131 176 { 132 177 //filling in combo box with choices 133 n_combo_array[i]->append_text((Glib::ustring)newmapname );178 n_combo_array[i]->append_text((Glib::ustring)newmapname, type); 134 179 } 135 180 } -
map_win.h
r194 r201 26 26 #include <libgnomecanvasmm.h> 27 27 #include <libgnomecanvasmm/polygon.h> 28 #include "map_value.h" 28 29 29 30 ///Graph visualization setup window. … … 65 66 ///binds the needed signal to the correct place. 66 67 ///\param title title of window 67 ///\param eml edgemap list68 ///\param nml nodemap list69 68 ///\param mw the owner \ref NoteBookTab (\ref mytab) 70 MapWin(const std::string& title, std::vector<std::string> eml, std::vector<std::string> nml, NoteBookTab & mw); 69 MapWin(const std::string& title, 70 std::vector<std::string> n_eml, 71 std::vector<std::string> s_eml, 72 std::vector<std::string> n_nml, 73 std::vector<std::string> s_nml, 74 NoteBookTab & mw); 71 75 72 76 ///Deregistrates \ref MapWin in its \ref NoteBookTab (\ref mytab) … … 107 111 ///\param new_name 108 112 ///name of new map 109 void registerNewEdgeMap(std::string new_name );113 void registerNewEdgeMap(std::string new_name, MapValue::Type type); 110 114 111 115 ///This function inserts name of the new nodemap in the name list in \ref MapSelector s … … 113 117 ///\param new_name 114 118 ///name of new map 115 void registerNewNodeMap(std::string new_name );119 void registerNewNodeMap(std::string new_name, MapValue::Type type); 116 120 117 121 ///Close window if Esc key pressed. … … 125 129 ///has to call this function or not from the \ref NoteBookTab::mapwinexists 126 130 ///variable. 127 ///\param eml edge map list 128 ///\param nml node map list 129 void update(std::vector<std::string> eml, std::vector<std::string> nml); 131 void update( 132 std::vector<std::string> n_eml, 133 std::vector<std::string> s_eml, 134 std::vector<std::string> n_nml, 135 std::vector<std::string> s_nml); 130 136 131 137 void changeEntry(bool, int, std::string); -
mapselector.cc
r194 r201 19 19 #include <mapselector.h> 20 20 21 MapSelector::MapSelector(std::vector<std::string> ml, std::string act, std::string labeltext, bool edge, bool d):def(d),itisedge(edge),set_new_map(false) 21 MapSelector::MapSelector(std::vector<std::string> n_ml, 22 std::vector<std::string> s_ml, std::string act, 23 std::string labeltext, bool edge, bool d, MapType type) : 24 def(d), 25 itisedge(edge), 26 set_new_map(false), 27 label(labeltext), 28 map_type(type), 29 newbut(Gtk::Stock::NEW) 22 30 { 23 update_list( ml);31 update_list(n_ml, s_ml); 24 32 25 33 if(act=="") 26 27 28 29 34 { 35 cbt.set_active(0); 36 default_state=true; 37 } 30 38 else 31 32 33 34 39 { 40 cbt.set_active_text((Glib::ustring)act); 41 default_state=false; 42 } 35 43 36 44 //binding signal to the actual entry … … 39 47 sigc::mem_fun((*this), &MapSelector::comboChanged), 40 48 false 41 ); 42 43 label=new Gtk::Label(labeltext); 49 ); 44 50 45 label ->set_width_chars(longest_property_string_length);51 label.set_width_chars(longest_property_string_length); 46 52 47 defbut=NULL;48 53 if(def) 49 { 50 defbut=new Gtk::Button(); 51 defbut->set_label("Reset"); 52 53 defbut->signal_pressed().connect 54 ( 55 sigc::mem_fun(*this, &MapSelector::reset) 56 ); 57 } 54 { 55 defbut.set_label("Reset"); 56 defbut.signal_pressed().connect 57 ( 58 sigc::mem_fun(*this, &MapSelector::reset) 59 ); 60 } 58 61 59 newbut=new Gtk::Button(Gtk::Stock::NEW);60 62 61 newbut ->signal_pressed().connect63 newbut.signal_pressed().connect 62 64 ( 63 65 sigc::mem_fun(*this, &MapSelector::new_but_pressed) 64 66 ); 65 67 66 add( *label);68 add(label); 67 69 68 70 add(cbt); 69 71 70 72 if(def) 71 72 add(*defbut);73 73 { 74 add(defbut); 75 } 74 76 75 add( *newbut);77 add(newbut); 76 78 } 77 79 … … 82 84 } 83 85 84 void MapSelector::update_list( std::vector< std::string > ml ) 86 void MapSelector::update_list(std::vector<std::string> n_ml, 87 std::vector<std::string> s_ml) 85 88 { 86 89 int prev_act=cbt.get_active_row_number(); 87 90 cbt.clear(); 88 91 cbt_content.clear(); 89 std::vector< std::string >::iterator emsi=ml.begin(); 90 for(;emsi!=ml.end();emsi++) 92 93 if (map_type & NUM) 94 { 95 std::vector< std::string >::iterator emsi=n_ml.begin(); 96 for(;emsi!=n_ml.end();emsi++) 91 97 { 92 98 cbt.append_text(*emsi); 93 99 cbt_content.push_back(*emsi); 94 100 } 101 } 102 if (map_type & STR) 103 { 104 std::vector< std::string >::iterator emsi=s_ml.begin(); 105 for(;emsi!=s_ml.end();emsi++) 106 { 107 cbt.append_text(*emsi); 108 cbt_content.push_back(*emsi); 109 } 110 } 95 111 if(def) 96 112 { … … 148 164 } 149 165 150 void MapSelector::append_text(Glib::ustring text )166 void MapSelector::append_text(Glib::ustring text, MapValue::Type type) 151 167 { 152 cbt.append_text(text); 153 cbt_content.push_back(text); 168 if (type & map_type) 169 { 170 cbt.append_text(text); 171 cbt_content.push_back(text); 154 172 155 if(set_new_map)173 if(set_new_map) 156 174 { 157 175 set_active_text(text); 158 176 set_new_map=false; 159 177 } 178 } 160 179 } 161 180 -
mapselector.h
r194 r201 23 23 #include <libgnomecanvasmm.h> 24 24 #include <libgnomecanvasmm/polygon.h> 25 #include "map_value.h" 25 26 26 27 ///A widget by which node and edgemaps can be selected, deselected and created. … … 81 82 ///By pressing it 82 83 ///\ref NewMapWin wilol pop-up 83 Gtk::Button *newbut;84 Gtk::Button newbut; 84 85 85 86 ///Reset button. … … 89 90 /// 90 91 ///It is visible only if \ref def is true. 91 Gtk::Button * defbut; 92 93 ///Container in which GUI elements are packed. 94 Gtk::HBox hbox; 92 Gtk::Button defbut; 95 93 96 94 ///Shows purpose of \ref MapSelector piece. 97 Gtk::Label * label; 95 Gtk::Label label; 96 97 /// Which types of maps (integer, string, ...) to display. 98 MapType map_type; 98 99 99 100 public: … … 102 103 103 104 ///Creates the layout and binds signal to the correct place. 104 ///\param optionlist list of names to place in \ref cbt105 ///\param mapstorage Pointer to the \ref MapStorage to get the map list from. 105 106 ///\param act preselected option 106 107 ///\param purpose text of label indicating purpose of \ref MapStorage 107 108 ///\param itisedge do \ref MapSelector contains edgemap names or nodemapnames. 108 109 ///\param def do we need 'Default' option. See \ref def. 109 MapSelector(std::vector<std::string> optionlist, std::string act, std::string purpose, bool itisedge, bool def=true); 110 ///\param type Specifies which types of maps to display. 111 MapSelector(std::vector<std::string> n_ml, 112 std::vector<std::string> s_ml, std::string act, std::string labeltext, 113 bool edge, bool d = true, MapType type = ALL); 110 114 111 115 ///Returns signal emitted if the user has changed the selection. (\ref signal_cbt) … … 120 124 ///into account that the previously selected option 121 125 ///has to be set back after the operation. 122 void update_list( std::vector<std::string> ); 126 void update_list(std::vector<std::string> n_ml, 127 std::vector<std::string> s_ml); 123 128 124 129 ///Handles changement in \ref cbt. … … 169 174 ///this function will set \ref cbt to the new option. 170 175 ///\param new_option new option to append 171 void append_text(Glib::ustring new_option );176 void append_text(Glib::ustring new_option, MapValue::Type); 172 177 }; 173 178 #endif //MAPSELECTOR_H -
mapstorage.cc
r199 r201 8 8 * 9 9 * Permission to use, modify and distribute this software is granted 10 * provided that this copyright notice appears in all cop ies. For10 * provided that this copyright notice appears in all cop ies. For 11 11 * precise terms see the accompanying LICENSE file. 12 12 * … … 17 17 */ 18 18 19 #include "i18n.h" 19 20 #include <limits> 20 21 #include <cmath> 22 #include <iostream> 23 #include <fstream> 24 #include <string> 25 #include <algorithm> 21 26 #include <gtkmm.h> 22 27 #include "file_import_dialog.h" 23 28 #include <mapstorage.h> 24 29 #include <gui_writer.h> … … 30 35 const double p_d=40000; 31 36 32 MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false), iterations(i_d), attraction(a_d), propulsation(p_d), background_set(false) 33 { 34 nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph); 35 coords.setXMap(*nodemap_storage["coordinates_x"]); 36 nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph); 37 coords.setYMap(*nodemap_storage["coordinates_y"]); 38 39 edgemap_storage["arrow_pos_x"] = new Graph::EdgeMap<double>(graph); 40 arrow_pos.setXMap(*edgemap_storage["arrow_pos_x"]); 41 edgemap_storage["arrow_pos_y"] = new Graph::EdgeMap<double>(graph); 42 arrow_pos.setYMap(*edgemap_storage["arrow_pos_y"]); 43 44 nodemap_storage["label"] = new Graph::NodeMap<double>(graph); 45 edgemap_storage["label"] = new Graph::EdgeMap<double>(graph); 46 47 nodemap_default["label"] = 1.0; 48 edgemap_default["label"] = 1.0; 37 MapStorage::MapStorage() : 38 gui_sect_save_dest(LGF_FILE), 39 node_coords_save_dest(SpecMapSaveOpts::GUI_SECT), 40 arrow_coords_save_dest(SpecMapSaveOpts::GUI_SECT), 41 modified(false), 42 file_name(""), 43 max_node_label(0), 44 max_edge_label(0), 45 node_coords_one_map_name("coord"), 46 node_coords_two_maps_1_name("coord_x"), 47 node_coords_two_maps_2_name("coord_y"), 48 arrow_coords_one_map_name("arrow"), 49 arrow_coords_two_maps_1_name("arrow_x"), 50 arrow_coords_two_maps_2_name("arrow_y"), 51 iterations(i_d), 52 attraction(a_d), 53 propulsation(p_d), 54 node_coords_x(graph), 55 node_coords_y(graph), 56 arrow_coords_x(graph), 57 arrow_coords_y(graph), 58 node_label(graph), 59 edge_label(graph), 60 background_set(false) 61 { 62 node_coords.setXMap(node_coords_x); 63 node_coords.setYMap(node_coords_y); 64 arrow_coords.setXMap(arrow_coords_x); 65 arrow_coords.setYMap(arrow_coords_y); 49 66 50 67 active_nodemaps.resize(NODE_PROPERTY_NUM); … … 63 80 MapStorage::~MapStorage() 64 81 { 65 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = 66 nodemap_storage.begin(); it != nodemap_storage.end(); ++it) 67 { 68 delete it->second; 69 } 70 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it = 71 edgemap_storage.begin(); it != edgemap_storage.end(); ++it) 72 { 73 delete it->second; 74 } 75 } 76 77 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value) 78 { 79 if( nodemap_storage.find(name) == nodemap_storage.end() ) 80 { 81 nodemap_storage[name]=nodemap; 82 // set the maps default value 83 nodemap_default[name] = default_value; 84 85 //announce changement in maps 86 signal_node_map.emit(name); 87 return 0; 88 } 89 return 1; 82 clear(); 83 } 84 85 void MapStorage::createNodeMap(const std::string& name, MapValue::Type type, 86 MapValue def_val) 87 { 88 NodeMapStore::const_iterator it = nodemaps.find(name); 89 if (it != nodemaps.end()) 90 throw Error("Node map " + name + " already exists."); 91 92 switch (type) 93 { 94 case MapValue::NUMERIC: 95 nodemaps[name] = new NumericNodeMapData(graph, def_val); 96 break; 97 case MapValue::STRING: 98 nodemaps[name] = new StringNodeMapData(graph, def_val); 99 break; 100 } 101 102 nodemaps[name]->default_value = def_val; 103 104 signal_node_map.emit(name, type); 105 } 106 107 void MapStorage::createEdgeMap(const std::string& name, MapValue::Type type, 108 MapValue def_val) 109 { 110 EdgeMapStore::const_iterator it = edgemaps.find(name); 111 if (it != edgemaps.end()) 112 throw Error("Edge map " + name + " already exists."); 113 114 switch (type) 115 { 116 case MapValue::NUMERIC: 117 edgemaps[name] = new NumericEdgeMapData(graph, def_val); 118 break; 119 case MapValue::STRING: 120 edgemaps[name] = new StringEdgeMapData(graph, def_val); 121 break; 122 } 123 124 edgemaps[name]->default_value = def_val; 125 126 signal_edge_map.emit(name, type); 90 127 } 91 128 … … 116 153 } 117 154 118 119 155 std::string MapStorage::getActiveEdgeMap(int prop) 120 156 { … … 127 163 } 128 164 129 std::vector<std::string> MapStorage::getEdgeMapList() 130 { 131 std::vector<std::string> eml; 132 eml.resize(edgemap_storage.size()); 133 int i=0; 134 std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=beginOfEdgeMaps(); 135 for(;emsi!=endOfEdgeMaps();emsi++) 136 { 137 eml[i]=(emsi->first); 138 i++; 139 } 140 return eml; 141 } 142 143 std::vector<std::string> MapStorage::getNodeMapList() 144 { 145 std::vector<std::string> nml; 146 nml.resize(nodemap_storage.size()); 147 int i=0; 148 std::map< std::string,Graph::NodeMap<double> * >::iterator nmsi=beginOfNodeMaps(); 149 for(;nmsi!=endOfNodeMaps();nmsi++) 150 { 151 nml[i]=(nmsi->first); 152 i++; 153 } 154 return nml; 165 std::vector<std::string> MapStorage::getEdgeMapList(MapType type) 166 { 167 if (type == ALL) 168 { 169 std::vector<std::string> ret; 170 for (EdgeMapStore::const_iterator it = edgemaps.begin(); 171 it != edgemaps.end(); ++it) 172 { 173 ret.push_back(it->first); 174 } 175 return ret; 176 } 177 else 178 { 179 std::vector<std::string> ret; 180 for (EdgeMapStore::const_iterator it = edgemaps.begin(); 181 it != edgemaps.end(); ++it) 182 { 183 EdgeMapData* data = getEdgeMapData(it->first); 184 MapValue::Type t = data->type(); 185 if ((t == MapValue::NUMERIC && (type & NUM)) || 186 (t == MapValue::STRING && (type & STR))) 187 { 188 ret.push_back(it->first); 189 } 190 } 191 return ret; 192 } 193 } 194 195 std::vector<std::string> MapStorage::getNodeMapList(MapType type) 196 { 197 if (type == ALL) 198 { 199 std::vector<std::string> ret; 200 for (NodeMapStore::const_iterator it = nodemaps.begin(); 201 it != nodemaps.end(); ++it) 202 { 203 ret.push_back(it->first); 204 } 205 return ret; 206 } 207 else 208 { 209 std::vector<std::string> ret; 210 for (NodeMapStore::const_iterator it = nodemaps.begin(); 211 it != nodemaps.end(); ++it) 212 { 213 NodeMapData* data = getNodeMapData(it->first); 214 MapValue::Type t = data->type(); 215 if ((t == MapValue::NUMERIC && (type & NUM)) || 216 (t == MapValue::STRING && (type & STR))) 217 { 218 ret.push_back(it->first); 219 } 220 } 221 return ret; 222 } 155 223 } 156 224 … … 160 228 } 161 229 162 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value) 163 { 164 if( edgemap_storage.find(name) == edgemap_storage.end() ) 165 { 166 edgemap_storage[name]=edgemap; 167 // set the maps default value 168 edgemap_default[name] = default_value; 169 170 //announce changement in maps 171 signal_edge_map.emit(name); 172 return 0; 173 } 174 return 1; 175 } 176 177 double MapStorage::maxOfNodeMap(const std::string & name) 178 { 179 double max=0; 180 for (NodeIt j(graph); j!=INVALID; ++j) 181 { 182 if( (*nodemap_storage[name])[j]>max ) 183 { 184 max=(*nodemap_storage[name])[j]; 185 } 186 } 187 return max; 188 } 189 190 double MapStorage::maxOfEdgeMap(const std::string & name) 191 { 192 double max=0; 193 for (EdgeIt j(graph); j!=INVALID; ++j) 194 { 195 if( (*edgemap_storage[name])[j]>max ) 196 { 197 max=(*edgemap_storage[name])[j]; 198 } 199 } 200 return max; 201 } 202 203 double MapStorage::minOfNodeMap(const std::string & name) 204 { 205 NodeIt j(graph); 206 double min; 207 if(j!=INVALID) 208 { 209 min=(*nodemap_storage[name])[j]; 210 } 230 int MapStorage::readFromFile(const std::string &filename) 231 { 232 using std::vector; 233 using std::map; 234 using std::string; 235 236 // check whether the .conf file exists 237 bool gui_data_in_conf = g_file_test((filename + ".conf").c_str(), 238 (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)); 239 240 // check whether the .lgf file contains a gui section 241 bool gui_data_in_lgf = false; 242 { 243 std::ifstream ifs(filename.c_str()); 244 std::string line; 245 while (getline(ifs, line)) 246 { 247 int pos = line.find("@gui"); 248 if (pos != std::string::npos) 249 { 250 bool only_whitespace_before = true; 251 for (int i = 0; i < pos; ++i) 252 { 253 if (!std::isspace(line[i])) 254 { 255 only_whitespace_before = false; 256 break; 257 } 258 } 259 if (only_whitespace_before) gui_data_in_lgf = true; 260 } 261 } 262 } 263 264 bool gui_data_found = gui_data_in_lgf || gui_data_in_conf; 265 266 // ask for user input if both exist 267 bool use_gui_data_in_lgf = false; 268 if (gui_data_in_conf && gui_data_in_lgf) 269 { 270 Gtk::MessageDialog mdialog(_("<b>Found both ") + filename + 271 _(".conf and a gui section in ") + filename + _(".</b>"), true, 272 Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE); 273 mdialog.add_button(_("Use the ._conf file"), 1); 274 mdialog.add_button(_("Use the _gui section"), 2); 275 switch (mdialog.run()) 276 { 277 case 1: 278 use_gui_data_in_lgf = false; 279 break; 280 case 2: 281 use_gui_data_in_lgf = true; 282 break; 283 case Gtk::RESPONSE_NONE: 284 return 1; 285 } 286 } 211 287 else 212 { 213 min=0; 214 } 215 for (; j!=INVALID; ++j) 216 { 217 if( (*nodemap_storage[name])[j]<min ) 218 { 219 min=(*nodemap_storage[name])[j]; 220 } 221 } 222 return min; 223 } 224 225 double MapStorage::minOfEdgeMap(const std::string & name) 226 { 227 EdgeIt j(graph); 228 double min; 229 if(j!=INVALID) 230 { 231 min=(*edgemap_storage[name])[j]; 232 } 233 else 234 { 235 min=0; 236 } 237 for (EdgeIt j(graph); j!=INVALID; ++j) 238 { 239 if( (*edgemap_storage[name])[j]<min ) 240 { 241 min=(*edgemap_storage[name])[j]; 242 } 243 } 244 return min; 245 } 246 247 int MapStorage::readFromFile(const std::string &filename) 248 { 249 bool read_x = false; 250 bool read_y = false; 251 bool read_edge_id = false; 252 253 try { 254 LemonReader lreader(filename); 255 ContentReader content(lreader); 256 lreader.run(); 257 258 if (content.nodeSetNum() < 1) 259 { 260 Gtk::MessageDialog mdialog("No nodeset found in file."); 261 mdialog.run(); 288 { 289 use_gui_data_in_lgf = gui_data_in_lgf; 290 } 291 292 if (gui_data_found) 293 { 294 GUISectData gui_data; 295 if (use_gui_data_in_lgf) 296 { 297 // read the gui section from the .lgf file 298 try 299 { 300 LemonReader lreader(filename); 301 GuiReader gui_reader(lreader, this, gui_data); 302 lreader.run(); 303 gui_sect_save_dest = LGF_FILE; 304 } 305 catch (Exception& error) 306 { 307 clear(); 308 return 1; 309 } 310 } 311 else 312 { 313 // read the gui section from the .conf file 314 try 315 { 316 LemonReader lreader(filename + ".conf"); 317 GuiReader gui_reader(lreader, this, gui_data); 318 lreader.run(); 319 gui_sect_save_dest = CONF_FILE; 320 } 321 catch (Exception& error) 322 { 323 clear(); 324 return 1; 325 } 326 } 327 328 // read the graph and maps form the .lgf file 329 try 330 { 331 std::string node_coord_xmap_name, node_coord_ymap_name; 332 std::string arrow_coord_xmap_name, arrow_coord_ymap_name; 333 334 if (gui_data.node_coords_save_dest == 335 MapStorage::SpecMapSaveOpts::NESET_SECT) 336 { 337 switch (gui_data.node_coords_save_map_num) 338 { 339 case SpecMapSaveOpts::ONE_MAP: 340 node_coord_xmap_name = gui_data.node_coords_one_map_name + ":x"; 341 node_coord_ymap_name = gui_data.node_coords_one_map_name + ":y"; 342 node_coords_one_map_name = gui_data.node_coords_one_map_name; 343 break; 344 case SpecMapSaveOpts::TWO_MAPS: 345 node_coord_xmap_name = gui_data.node_coords_two_maps_1_name; 346 node_coord_ymap_name = gui_data.node_coords_two_maps_2_name; 347 node_coords_two_maps_1_name = gui_data.node_coords_two_maps_1_name; 348 node_coords_two_maps_2_name = gui_data.node_coords_two_maps_2_name; 349 break; 350 } 351 node_coords_save_dest = gui_data.node_coords_save_dest; 352 node_coords_save_map_num = gui_data.node_coords_save_map_num; 353 } 354 355 if (gui_data.arrow_coords_save_dest == 356 MapStorage::SpecMapSaveOpts::NESET_SECT) 357 { 358 switch (gui_data.arrow_coords_save_map_num) 359 { 360 case SpecMapSaveOpts::ONE_MAP: 361 arrow_coord_xmap_name = gui_data.arrow_coords_one_map_name + ":x"; 362 arrow_coord_ymap_name = gui_data.arrow_coords_one_map_name + ":y"; 363 arrow_coords_one_map_name = gui_data.arrow_coords_one_map_name; 364 break; 365 case SpecMapSaveOpts::TWO_MAPS: 366 arrow_coord_xmap_name = gui_data.arrow_coords_two_maps_1_name; 367 arrow_coord_ymap_name = gui_data.arrow_coords_two_maps_2_name; 368 arrow_coords_two_maps_1_name = 369 gui_data.arrow_coords_two_maps_1_name; 370 arrow_coords_two_maps_2_name = 371 gui_data.arrow_coords_two_maps_2_name; 372 break; 373 } 374 arrow_coords_save_dest = gui_data.arrow_coords_save_dest; 375 arrow_coords_save_map_num = gui_data.arrow_coords_save_map_num; 376 } 377 readLGF(filename, true, 378 gui_data.main_node_map_names, gui_data.main_edge_map_names, 379 gui_data.node_map_types, gui_data.edge_map_types, 380 node_coord_xmap_name, node_coord_ymap_name, 381 arrow_coord_xmap_name, arrow_coord_ymap_name); 382 } 383 catch (Exception& error) 384 { 262 385 clear(); 263 386 return 1; 264 387 } 265 388 266 if (content.edgeSetNum() < 1) 267 { 268 Gtk::MessageDialog mdialog("No edgeset found in file."); 269 mdialog.run(); 270 clear(); 271 return 1; 272 } 273 274 const std::vector<std::string>& nodeMapNames = content.nodeSetMaps(0); 275 const std::vector<std::string>& edgeMapNames = content.edgeSetMaps(0); 276 277 GraphReader<Graph> greader(filename, graph); 278 for (std::vector<std::string>::const_iterator it = nodeMapNames.begin(); 279 it != nodeMapNames.end(); ++it) 280 { 281 if (*it == "coordinates_x") 282 { 283 read_x = true; 284 //std::cout << "read X nodemap" << std::endl; 285 } 286 else if (*it == "coordinates_y") 287 { 288 read_y = true; 289 //std::cout << "read Y nodemap" << std::endl; 290 } 291 else if (*it == "label") 292 { 293 //std::cout << "read id nodemap" << std::endl; 389 // add the maps from the gui section 390 for (vector<string>::const_iterator 391 it = gui_data.gui_node_map_names.begin(); 392 it != gui_data.gui_node_map_names.end(); ++it) 393 { 394 string map_name = *it; 395 switch (gui_data.node_map_types[map_name]) 396 { 397 case MapValue::NUMERIC: 398 { 399 createNodeMap(map_name, MapValue::NUMERIC, double()); 400 NumericNodeMap& dmap = getNumericNodeMap(map_name); 401 map<int, double>& smap = *gui_data.numeric_node_maps[map_name]; 402 for (NodeIt n(graph); n != INVALID; ++n) 403 { 404 dmap[n] = smap[node_label[n]]; 405 } 406 break; 407 } 408 case MapValue::STRING: 409 { 410 createNodeMap(map_name, MapValue::STRING, string()); 411 StringNodeMap& dmap = getStringNodeMap(map_name); 412 map<int, string>& smap = *gui_data.string_node_maps[map_name]; 413 for (NodeIt n(graph); n != INVALID; ++n) 414 { 415 dmap[n] = smap[node_label[n]]; 416 } 417 break; 418 } 419 } 420 getNodeMapData(map_name)->save_dest = GUI_SECT; 421 } 422 for (vector<string>::const_iterator 423 it = gui_data.gui_edge_map_names.begin(); 424 it != gui_data.gui_edge_map_names.end(); ++it) 425 { 426 string map_name = *it; 427 switch (gui_data.edge_map_types[map_name]) 428 { 429 case MapValue::NUMERIC: 430 { 431 createEdgeMap(map_name, MapValue::NUMERIC, double()); 432 NumericEdgeMap& dmap = getNumericEdgeMap(map_name); 433 map<int, double>& smap = *gui_data.numeric_edge_maps[map_name]; 434 for (EdgeIt e(graph); e != INVALID; ++e) 435 { 436 dmap[e] = smap[edge_label[e]]; 437 } 438 break; 439 } 440 case MapValue::STRING: 441 { 442 createEdgeMap(map_name, MapValue::STRING, string()); 443 StringEdgeMap& dmap = getStringEdgeMap(map_name); 444 map<int, string>& smap = *gui_data.string_edge_maps[map_name]; 445 for (EdgeIt e(graph); e != INVALID; ++e) 446 { 447 dmap[e] = smap[edge_label[e]]; 448 } 449 break; 450 } 451 } 452 getEdgeMapData(map_name)->save_dest = GUI_SECT; 453 } 454 455 // restore the node coordinate maps 456 if (gui_data.node_coords_save_dest == 457 MapStorage::SpecMapSaveOpts::GUI_SECT) 458 { 459 for (NodeIt n(graph); n != INVALID; ++n) 460 { 461 node_coords.set(n, gui_data.node_coord_map[node_label[n]]); 462 } 463 node_coords_save_dest = gui_data.node_coords_save_dest; 464 } 465 // restore the arrow coordinate maps 466 if (gui_data.arrow_coords_save_dest == 467 MapStorage::SpecMapSaveOpts::GUI_SECT) 468 { 469 for (EdgeIt e(graph); e != INVALID; ++e) 470 { 471 arrow_coords.set(e, gui_data.arrow_coord_map[edge_label[e]]); 472 } 473 arrow_coords_save_dest = gui_data.arrow_coords_save_dest; 474 } 475 } 476 else 477 { 478 // there is no gui section neither in the .lgf file nor in the .conf file 479 { 480 LemonReader lreader(filename); 481 ContentReader content(lreader); 482 try 483 { 484 lreader.run(); 485 } 486 catch (Exception& error) 487 { 488 Gtk::MessageDialog mdialog(error.what()); 489 mdialog.run(); 490 clear(); 491 return 1; 492 } 493 494 if (content.nodeSetNum() < 1) 495 { 496 Gtk::MessageDialog mdialog("No nodeset found in file."); 497 mdialog.run(); 498 clear(); 499 return 1; 500 } 501 502 if (content.edgeSetNum() < 1) 503 { 504 Gtk::MessageDialog mdialog("No edgeset found in file."); 505 mdialog.run(); 506 clear(); 507 return 1; 508 } 509 510 std::vector<std::string> nodeMapNames = content.nodeSetMaps(0); 511 std::vector<std::string> edgeMapNames = content.edgeSetMaps(0); 512 513 bool read_edge_label = true; 514 if (std::find(edgeMapNames.begin(), edgeMapNames.end(), "label") == 515 edgeMapNames.end()) 516 { 517 read_edge_label = false; 518 } 519 520 nodeMapNames.erase( 521 std::remove(nodeMapNames.begin(), nodeMapNames.end(), "label"), 522 nodeMapNames.end()); 523 524 edgeMapNames.erase( 525 std::remove(edgeMapNames.begin(), edgeMapNames.end(), "label"), 526 edgeMapNames.end()); 527 528 FileImportDialog::ImportData data(nodeMapNames, edgeMapNames); 529 FileImportDialog fidialog(&data); 530 int response = fidialog.run(); 531 if (response == Gtk::RESPONSE_OK) 532 { 533 try 534 { 535 std::string node_coord_xmap_name, node_coord_ymap_name; 536 std::string arrow_coord_xmap_name, arrow_coord_ymap_name; 537 bool gen_node_coords = false; 538 bool gen_arrow_coords = false; 539 540 switch (data.node_coord_load_from) 541 { 542 case FileImportDialog::ImportData::ONE_MAP: 543 node_coord_xmap_name = data.node_coord_one_map_name + ":x"; 544 node_coord_ymap_name = data.node_coord_one_map_name + ":y"; 545 node_coords_one_map_name = data.node_coord_one_map_name; 546 547 node_coords_save_dest = SpecMapSaveOpts::NESET_SECT; 548 node_coords_save_map_num = SpecMapSaveOpts::ONE_MAP; 549 break; 550 case FileImportDialog::ImportData::TWO_MAPS: 551 node_coord_xmap_name = data.node_coord_two_maps_1_name; 552 node_coord_ymap_name = data.node_coord_two_maps_2_name; 553 node_coords_two_maps_1_name = data.node_coord_two_maps_1_name; 554 node_coords_two_maps_2_name = data.node_coord_two_maps_2_name; 555 556 node_coords_save_dest = SpecMapSaveOpts::NESET_SECT; 557 node_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS; 558 break; 559 case FileImportDialog::ImportData::DONT_READ: 560 node_coord_xmap_name = ""; 561 node_coord_ymap_name = ""; 562 563 node_coords_save_dest = SpecMapSaveOpts::GUI_SECT; 564 gen_node_coords = true; 565 break; 566 } 567 568 switch (data.arrow_coord_load_from) 569 { 570 case FileImportDialog::ImportData::ONE_MAP: 571 arrow_coord_xmap_name = data.arrow_coord_one_map_name + ":x"; 572 arrow_coord_ymap_name = data.arrow_coord_one_map_name + ":y"; 573 arrow_coords_one_map_name = data.arrow_coord_one_map_name; 574 575 arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT; 576 arrow_coords_save_map_num = SpecMapSaveOpts::ONE_MAP; 577 break; 578 case FileImportDialog::ImportData::TWO_MAPS: 579 arrow_coord_xmap_name = data.arrow_coord_two_maps_1_name; 580 arrow_coord_ymap_name = data.arrow_coord_two_maps_2_name; 581 arrow_coords_two_maps_1_name = data.arrow_coord_two_maps_1_name; 582 arrow_coords_two_maps_2_name = data.arrow_coord_two_maps_2_name; 583 584 arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT; 585 arrow_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS; 586 break; 587 case FileImportDialog::ImportData::DONT_READ: 588 arrow_coord_xmap_name = ""; 589 arrow_coord_ymap_name = ""; 590 591 arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT; 592 gen_arrow_coords = true; 593 break; 594 } 595 596 // read edge and node maps 597 std::vector<std::string> node_map_names; 598 std::vector<std::string> edge_map_names; 599 std::map<std::string, MapValue::Type> node_map_types; 600 std::map<std::string, MapValue::Type> edge_map_types; 601 for (std::vector<std::string>::const_iterator it = 602 data.numeric_node_map_names.begin(); 603 it != data.numeric_node_map_names.end(); ++it) 604 { 605 node_map_names.push_back(*it); 606 node_map_types[*it] = MapValue::NUMERIC; 607 } 608 for (std::vector<std::string>::const_iterator it = 609 data.string_node_map_names.begin(); 610 it != data.string_node_map_names.end(); ++it) 611 { 612 node_map_names.push_back(*it); 613 node_map_types[*it] = MapValue::STRING; 614 } 615 for (std::vector<std::string>::const_iterator it = 616 data.numeric_edge_map_names.begin(); 617 it != data.numeric_edge_map_names.end(); ++it) 618 { 619 edge_map_names.push_back(*it); 620 edge_map_types[*it] = MapValue::NUMERIC; 621 } 622 for (std::vector<std::string>::const_iterator it = 623 data.string_edge_map_names.begin(); 624 it != data.string_edge_map_names.end(); ++it) 625 { 626 edge_map_names.push_back(*it); 627 edge_map_types[*it] = MapValue::STRING; 628 } 629 630 readLGF(filename, read_edge_label, 631 node_map_names, edge_map_names, 632 node_map_types, edge_map_types, 633 node_coord_xmap_name, node_coord_ymap_name, 634 arrow_coord_xmap_name, arrow_coord_ymap_name); 635 636 // generate edge labels 637 if (!read_edge_label) 638 { 639 int l = 0; 640 for (EdgeIt e(graph); e != INVALID; ++e) 641 { 642 edge_label[e] = l++; 643 } 644 } 645 646 if (gen_node_coords) 647 { 648 // generate node coordinates 649 int node_num = 0; 650 for (NodeIt n(graph); n != INVALID; ++n) { node_num++; } 651 const double pi = 3.142; 652 double step = 2 * pi / (double) node_num; 653 int i = 0; 654 for (NodeIt n(graph); n != INVALID; ++n) 655 { 656 setNodeCoords(n, 657 XY(250.0 * std::cos(i * step), 658 250.0 * std::sin(i * step))); 659 i++; 660 } 661 } 662 if (gen_arrow_coords) 663 { 664 // generate arrow coordinates 665 for (EdgeIt e(graph); e != INVALID; ++e) 666 { 667 if (graph.source(e) == graph.target(e)) 668 { 669 setArrowCoords(e, 670 getNodeCoords(graph.source(e)) + XY(0.0, 80.0)); 671 } 672 else 673 { 674 setArrowCoords(e, 675 (getNodeCoords(graph.source(e)) + 676 getNodeCoords(graph.target(e))) / 2.0); 677 } 678 } 679 } 680 } 681 catch (Exception& error) 682 { 683 clear(); 684 return 1; 685 } 294 686 } 295 687 else 296 688 { 297 nodemap_storage[*it] = new Graph::NodeMap<double>(graph); 298 //std::cout << "read " << *it << " nodemap" << std::endl; 299 } 300 greader.readNodeMap(*it, *nodemap_storage[*it]); 301 } 302 for (std::vector<std::string>::const_iterator it = edgeMapNames.begin(); 303 it != edgeMapNames.end(); ++it) 304 { 305 if (*it == "label") 306 { 307 //std::cout << "read id edgemap" << std::endl; 308 read_edge_id = true; 309 } 310 else 311 { 312 edgemap_storage[*it] = new Graph::EdgeMap<double>(graph); 313 //std::cout << "read " << *it << " edgemap" << std::endl; 314 } 315 greader.readEdgeMap(*it, *edgemap_storage[*it]); 316 } 317 GuiReader gui_reader(greader, this); 318 greader.run(); 319 } catch (Exception& error) { 320 Gtk::MessageDialog mdialog(error.what()); 321 mdialog.run(); 322 clear(); 323 return 1; 324 } 325 326 if (!read_edge_id) 327 { 328 edgemap_storage["label"] = new Graph::EdgeMap<double>(graph); 329 int i = 1; 689 clear(); 690 return 1; 691 } 692 } 693 } 694 695 // set max_node_label 696 { 697 max_node_label = std::numeric_limits<int>::min(); 698 for (NodeIt n(graph); n != INVALID; ++n) 699 { 700 if (node_label[n] > max_node_label) 701 { 702 max_node_label = node_label[n]; 703 } 704 } 705 } 706 // set max_edge_label 707 { 708 max_edge_label = std::numeric_limits<int>::min(); 330 709 for (EdgeIt e(graph); e != INVALID; ++e) 331 710 { 332 (*edgemap_storage["label"])[e] = i++; 333 } 334 } 335 336 if (!read_x || !read_y) 337 { 338 int node_num = 0; 339 for (NodeIt n(graph); n != INVALID; ++n) 340 { 341 node_num++; 342 } 343 const double pi = 3.142; 344 double step = 2 * pi / (double) node_num; 345 int i = 0; 346 for (NodeIt n(graph); n != INVALID; ++n) 347 { 348 nodemap_storage["coordinates_x"]->set(n, 250.0 * std::cos(i * step)); 349 nodemap_storage["coordinates_y"]->set(n, 250.0 * std::sin(i * step)); 350 i++; 351 } 352 } 353 354 if (!arrow_pos_read_ok) 355 { 356 arrow_pos_read_ok = false; 357 for (EdgeIt e(graph); e != INVALID; ++e) 358 { 359 if (graph.source(e) == graph.target(e)) 360 { 361 arrow_pos.set(e, coords[graph.source(e)] + XY(0.0, 80.0)); 362 } 363 else 364 { 365 arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0); 366 } 367 } 368 } 369 370 // fill in the default values for the maps 371 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = 372 nodemap_storage.begin(); it != nodemap_storage.end(); ++it) 373 { 374 if ((it->first != "label") && 375 (it->first != "coordiantes_x") && 376 (it->first != "coordinates_y")) 377 { 378 nodemap_default[it->first] = 0.0; 379 } 380 else if (it->first == "label") 381 { 382 NodeIt n(graph); 383 double max = (*nodemap_storage["label"])[n]; 384 for (; n != INVALID; ++n) 385 { 386 if ((*nodemap_storage["label"])[n] > max) 387 max = (*nodemap_storage["label"])[n]; 388 } 389 nodemap_default["label"] = max + 1.0; 390 } 391 } 392 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it = 393 edgemap_storage.begin(); it != edgemap_storage.end(); ++it) 394 { 395 if (it->first != "label") 396 { 397 edgemap_default[it->first] = 0.0; 711 if (edge_label[e] > max_edge_label) 712 { 713 max_edge_label = edge_label[e]; 714 } 715 } 716 } 717 718 return 0; 719 } 720 721 void MapStorage::writeToFile(const std::string &filename) 722 { 723 // relabel nodes and edges 724 int i = 0; 725 for (NodeIt n(graph); n != INVALID; ++n) 726 { 727 node_label[n] = i++; 728 } 729 max_node_label = i-1; 730 i = 0; 731 for (EdgeIt e(graph); e != INVALID; ++e) 732 { 733 edge_label[e] = i++; 734 } 735 max_edge_label = i-1; 736 737 // write .lgf file 738 { 739 GraphWriter<Graph> gwriter(filename, graph); 740 741 gwriter.writeNodeMap("label", node_label); 742 gwriter.writeEdgeMap("label", edge_label); 743 744 // write node maps 745 for (NodeMapStore::const_iterator it = nodemaps.begin(); 746 it != nodemaps.end(); ++it) 747 { 748 if (it->second->save_dest == NESET_SECT) 749 { 750 switch (it->second->type()) 751 { 752 case MapValue::NUMERIC: 753 gwriter.writeNodeMap(it->first, getNumericNodeMap(it->first)); 754 break; 755 case MapValue::STRING: 756 gwriter.writeNodeMap(it->first, getStringNodeMap(it->first)); 757 break; 758 } 759 } 760 } 761 762 // write edge maps 763 for (EdgeMapStore::const_iterator it = edgemaps.begin(); 764 it != edgemaps.end(); ++it) 765 { 766 if (it->second->save_dest == NESET_SECT) 767 { 768 switch (it->second->type()) 769 { 770 case MapValue::NUMERIC: 771 gwriter.writeEdgeMap(it->first, getNumericEdgeMap(it->first)); 772 break; 773 case MapValue::STRING: 774 gwriter.writeEdgeMap(it->first, getStringEdgeMap(it->first)); 775 break; 776 } 777 } 778 } 779 780 // write node coordinates 781 switch (getNodeCoordsSaveDest()) 782 { 783 case MapStorage::SpecMapSaveOpts::GUI_SECT: 784 break; 785 case MapStorage::SpecMapSaveOpts::NESET_SECT: 786 switch (getNodeCoordsSaveMapNum()) 787 { 788 case MapStorage::SpecMapSaveOpts::ONE_MAP: 789 gwriter.writeNodeMap(node_coords_one_map_name + ":x", 790 node_coords_x); 791 gwriter.writeNodeMap(node_coords_one_map_name + ":y", 792 node_coords_y); 793 break; 794 case MapStorage::SpecMapSaveOpts::TWO_MAPS: 795 gwriter.writeNodeMap(node_coords_two_maps_1_name, 796 node_coords_x); 797 gwriter.writeNodeMap(node_coords_two_maps_2_name, 798 node_coords_y); 799 break; 800 } 801 break; 802 } 803 804 // write arrow coordinates 805 switch (getArrowCoordsSaveDest()) 806 { 807 case MapStorage::SpecMapSaveOpts::GUI_SECT: 808 break; 809 case MapStorage::SpecMapSaveOpts::NESET_SECT: 810 switch (getArrowCoordsSaveMapNum()) 811 { 812 case MapStorage::SpecMapSaveOpts::ONE_MAP: 813 gwriter.writeEdgeMap(arrow_coords_one_map_name + ":x", 814 arrow_coords_x); 815 gwriter.writeEdgeMap(arrow_coords_one_map_name + ":y", 816 arrow_coords_y); 817 break; 818 case MapStorage::SpecMapSaveOpts::TWO_MAPS: 819 gwriter.writeEdgeMap(arrow_coords_two_maps_1_name, 820 arrow_coords_x); 821 gwriter.writeEdgeMap(arrow_coords_two_maps_2_name, 822 arrow_coords_y); 823 break; 824 } 825 break; 826 } 827 828 if (gui_sect_save_dest == LGF_FILE) 829 { 830 GuiWriter gui_writer(gwriter, this); 831 gwriter.run(); 398 832 } 399 833 else 400 834 { 401 double max = std::numeric_limits<double>::min(); 402 for (EdgeIt e(graph); e != INVALID; ++e) 403 { 404 if ((*edgemap_storage["label"])[e] > max) 405 max = (*edgemap_storage["label"])[e]; 406 } 407 if (max > std::numeric_limits<double>::min()) 408 edgemap_default["label"] = max + 1.0; 409 else 410 edgemap_default["label"] = 1.0; 411 } 412 } 413 414 return 0; 415 } 416 417 void MapStorage::writeToFile(const std::string &filename) 418 { 419 GraphWriter<Graph> gwriter(filename, graph); 420 421 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = 422 nodemap_storage.begin(); it != nodemap_storage.end(); ++it) 423 { 424 gwriter.writeNodeMap(it->first, *(it->second)); 425 } 426 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it = 427 edgemap_storage.begin(); it != edgemap_storage.end(); ++it) 428 { 429 if ((it->first != "arrow_pos_x") && 430 (it->first != "arrow_pos_y")) 431 { 432 gwriter.writeEdgeMap(it->first, *(it->second)); 433 } 434 } 435 436 GuiWriter gui_writer(gwriter, this); 437 438 gwriter.run(); 835 gwriter.run(); 836 } 837 } 838 839 // write .conf file 840 if (gui_sect_save_dest == CONF_FILE) 841 { 842 LemonWriter lwriter(filename + ".conf"); 843 GuiWriter gui_writer(lwriter, this); 844 lwriter.run(); 845 } 439 846 } 440 847 441 848 void MapStorage::clear() 442 849 { 443 for (std::map<std::string, Graph::NodeMap<double>*>::iterator it = 444 nodemap_storage.begin(); it != nodemap_storage.end(); ++it) 445 { 446 if ((it->first != "coordinates_x") && 447 (it->first != "coordinates_y") && 448 (it->first != "label")) 449 { 450 delete it->second; 451 nodemap_storage.erase(it); 452 } 453 } 454 for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it = 455 edgemap_storage.begin(); it != edgemap_storage.end(); ++it) 456 { 457 if ((it->first != "label") && 458 (it->first != "arrow_pos_x") && 459 (it->first != "arrow_pos_y")) 460 { 461 delete it->second; 462 edgemap_storage.erase(it); 463 } 464 } 465 for (std::map<std::string, double>::iterator it = 466 nodemap_default.begin(); it != nodemap_default.end(); ++it) 467 { 468 if (it->first != "label") 469 nodemap_default.erase(it); 470 } 471 for (std::map<std::string, double>::iterator it = 472 edgemap_default.begin(); it != edgemap_default.end(); ++it) 473 { 474 if (it->first != "label") 475 edgemap_default.erase(it); 850 for (NodeMapStore::iterator it = nodemaps.begin(); it != nodemaps.end(); ++it) 851 { 852 delete it->second; 853 nodemaps.erase(it); 854 } 855 for (EdgeMapStore::iterator it = edgemaps.begin(); it != edgemaps.end(); ++it) 856 { 857 delete it->second; 858 edgemaps.erase(it); 476 859 } 477 860 graph.clear(); 478 861 file_name = ""; 479 862 modified = false; 480 481 arrow_pos_read_ok = false; 482 863 max_node_label = 0; 864 max_edge_label = 0; 865 background_set = false; 866 867 gui_sect_save_dest = LGF_FILE; 868 node_coords_save_dest = SpecMapSaveOpts::GUI_SECT; 869 arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT; 870 node_coords_one_map_name = "coord"; 871 node_coords_two_maps_1_name = "coord_x"; 872 node_coords_two_maps_2_name = "coord_y"; 873 arrow_coords_one_map_name = "arrow"; 874 arrow_coords_two_maps_1_name = "arrow_x"; 875 arrow_coords_two_maps_2_name = "arrow_y"; 876 483 877 for(int i=0;i<NODE_PROPERTY_NUM;i++) 484 878 { … … 500 894 } 501 895 502 void MapStorage::ArrowPosReadOK()503 {504 arrow_pos_read_ok = true;505 }506 507 896 void MapStorage::mapChanged(bool itisedge, std::string mapname) 508 897 { 509 898 if(itisedge) 510 511 512 513 514 515 516 517 518 899 { 900 for(int i=0;i<EDGE_PROPERTY_NUM;i++) 901 { 902 if(active_edgemaps[i]==mapname) 903 { 904 signal_prop.emit(itisedge, i); 905 } 906 } 907 } 519 908 else 520 521 522 523 524 525 526 527 528 909 { 910 for(int i=0;i<NODE_PROPERTY_NUM;i++) 911 { 912 if(active_nodemaps[i]==mapname) 913 { 914 signal_prop.emit(itisedge, i); 915 } 916 } 917 } 529 918 } 530 919 … … 554 943 { 555 944 signal_design_win.emit(attraction, propulsation, iterations); 945 } 946 947 XY MapStorage::getNodeCoords(Node n) const 948 { 949 return node_coords[n]; 950 } 951 952 void MapStorage::setNodeCoords(Node n, XY c) 953 { 954 node_coords.set(n, c); 955 } 956 957 XY MapStorage::getArrowCoords(Edge e) const 958 { 959 return arrow_coords[e]; 960 } 961 962 void MapStorage::setArrowCoords(Edge e, XY c) 963 { 964 arrow_coords.set(e, c); 965 } 966 967 MapValue MapStorage::get(const std::string& name, Node node) const 968 { 969 NodeMapData* data = getNodeMapData(name); 970 return data->get(node); 971 } 972 973 void MapStorage::set(const std::string& name, Node node, MapValue val) 974 { 975 NodeMapData* data = getNodeMapData(name); 976 data->set(node, val); 977 } 978 979 MapValue MapStorage::get(const std::string& name, Edge edge) const 980 { 981 EdgeMapData* data = getEdgeMapData(name); 982 return data->get(edge); 983 } 984 985 void MapStorage::set(const std::string& name, Edge edge, MapValue val) 986 { 987 EdgeMapData* data = getEdgeMapData(name); 988 data->set(edge, val); 989 } 990 991 const std::string& MapStorage::getFileName() const 992 { 993 return file_name; 994 } 995 996 void MapStorage::setFileName(const std::string& fn) 997 { 998 file_name = fn; 999 } 1000 1001 bool MapStorage::getModified() const 1002 { 1003 return modified; 1004 } 1005 1006 void MapStorage::setModified(bool m) 1007 { 1008 modified = m; 1009 } 1010 1011 Node MapStorage::addNode(XY coords) 1012 { 1013 Node node = graph.addNode(); 1014 1015 setNodeCoords(node, coords); 1016 1017 max_node_label++; 1018 1019 node_label[node] = max_node_label; 1020 1021 std::vector<std::string> node_maps = getNodeMapList(); 1022 for (std::vector<std::string>::const_iterator it = node_maps.begin(); 1023 it != node_maps.end(); ++it) 1024 { 1025 NodeMapData* data = getNodeMapData(*it); 1026 set(*it, node, data->default_value); 1027 } 1028 1029 return node; 1030 } 1031 1032 Edge MapStorage::addEdge(Node from, Node to) 1033 { 1034 Edge edge = graph.addEdge(from, to); 1035 1036 if (from == to) 1037 { 1038 setArrowCoords(edge, getNodeCoords(from) + XY(0.0, 80.0)); 1039 } 1040 else 1041 { 1042 setArrowCoords(edge, (getNodeCoords(from) + getNodeCoords(to)) / 2.0); 1043 } 1044 1045 max_edge_label++; 1046 1047 edge_label[edge] = max_edge_label; 1048 1049 std::vector<std::string> edge_maps = getEdgeMapList(); 1050 for (std::vector<std::string>::const_iterator it = edge_maps.begin(); 1051 it != edge_maps.end(); ++it) 1052 { 1053 EdgeMapData* data = getEdgeMapData(*it); 1054 set(*it, edge, data->default_value); 1055 } 1056 return edge; 1057 } 1058 1059 MapStorage::NumericNodeMap& MapStorage::getNumericNodeMap(const std::string& name) 1060 { 1061 NodeMapData* data = getNodeMapData(name); 1062 if (data->type() != MapValue::NUMERIC) 1063 throw Error("Numeric node map " + name + " does not exists."); 1064 return static_cast<NumericNodeMapData*>(data)->map; 1065 } 1066 1067 MapStorage::StringNodeMap& MapStorage::getStringNodeMap(const std::string& name) 1068 { 1069 NodeMapData* data = getNodeMapData(name); 1070 if (data->type() != MapValue::STRING) 1071 throw Error("String node map " + name + " does not exists."); 1072 return static_cast<StringNodeMapData*>(data)->map; 1073 } 1074 1075 MapStorage::NumericEdgeMap& MapStorage::getNumericEdgeMap(const std::string& name) 1076 { 1077 EdgeMapData* data = getEdgeMapData(name); 1078 if (data->type() != MapValue::NUMERIC) 1079 throw Error("Numeric edge map " + name + " does not exists."); 1080 return static_cast<NumericEdgeMapData*>(data)->map; 1081 } 1082 1083 MapStorage::StringEdgeMap& MapStorage::getStringEdgeMap(const std::string& name) 1084 { 1085 EdgeMapData* data = getEdgeMapData(name); 1086 if (data->type() != MapValue::STRING) 1087 throw Error("String edge map " + name + " does not exists."); 1088 return static_cast<StringEdgeMapData*>(data)->map; 1089 } 1090 1091 MapValueEdgeMap MapStorage::getEdgeMap(const std::string& name) 1092 { 1093 return MapValueEdgeMap(name, this); 1094 } 1095 1096 MapValueNodeMap MapStorage::getNodeMap(const std::string& name) 1097 { 1098 return MapValueNodeMap(name, this); 1099 } 1100 1101 int MapStorage::getLabel(Node n) const 1102 { 1103 return node_label[n]; 1104 } 1105 1106 int MapStorage::getLabel(Edge e) const 1107 { 1108 return edge_label[e]; 1109 } 1110 1111 MapStorage::GuiSectSaveDest MapStorage::getGUIDataSaveLocation() 1112 { 1113 return gui_sect_save_dest; 1114 } 1115 1116 void MapStorage::setGUIDataSaveLocation(MapStorage::GuiSectSaveDest dest) 1117 { 1118 gui_sect_save_dest = dest; 1119 } 1120 1121 MapStorage::MapSaveDest MapStorage::getNodeMapSaveDest(std::string name) const 1122 { 1123 NodeMapData *data = getNodeMapData(name); 1124 return data->save_dest; 1125 } 1126 1127 MapStorage::MapSaveDest MapStorage::getEdgeMapSaveDest(std::string name) const 1128 { 1129 EdgeMapData *data = getEdgeMapData(name); 1130 return data->save_dest; 1131 } 1132 1133 void MapStorage::setNodeMapSaveDest(std::string name, MapStorage::MapSaveDest dest) 1134 { 1135 NodeMapData *data = getNodeMapData(name); 1136 data->save_dest = dest; 1137 } 1138 1139 void MapStorage::setEdgeMapSaveDest(std::string name, MapStorage::MapSaveDest dest) 1140 { 1141 EdgeMapData *data = getEdgeMapData(name); 1142 data->save_dest = dest; 1143 } 1144 1145 MapStorage::EdgeMapData* MapStorage::getEdgeMapData(std::string name) const 1146 { 1147 EdgeMapStore::const_iterator it = edgemaps.find(name); 1148 if (it != edgemaps.end()) 1149 return it->second; 1150 else 1151 throw Error("Edge map " + name + " does not exists."); 1152 } 1153 1154 MapStorage::NodeMapData* MapStorage::getNodeMapData(std::string name) const 1155 { 1156 NodeMapStore::const_iterator it = nodemaps.find(name); 1157 if (it != nodemaps.end()) 1158 return it->second; 1159 else 1160 throw Error("Node map " + name + " does not exists."); 1161 } 1162 1163 MapValue::Type MapStorage::getNodeMapElementType(std::string name) const 1164 { 1165 NodeMapData *data = getNodeMapData(name); 1166 return data->type(); 1167 } 1168 1169 MapValue::Type MapStorage::getEdgeMapElementType(std::string name) const 1170 { 1171 EdgeMapData *data = getEdgeMapData(name); 1172 return data->type(); 1173 } 1174 1175 const MapStorage::NodeLabelMap& MapStorage::getNodeLabelMap() 1176 { 1177 return node_label; 1178 } 1179 1180 const MapStorage::EdgeLabelMap& MapStorage::getEdgeLabelMap() 1181 { 1182 return edge_label; 1183 } 1184 1185 const Graph& MapStorage::getGraph() 1186 { 1187 return graph; 1188 } 1189 1190 bool MapStorage::nodeMapExists(std::string name) 1191 { 1192 NodeMapStore::const_iterator it = nodemaps.find(name); 1193 if (it == nodemaps.end()) 1194 return false; 1195 else 1196 return true; 1197 } 1198 1199 bool MapStorage::edgeMapExists(std::string name) 1200 { 1201 EdgeMapStore::const_iterator it = edgemaps.find(name); 1202 if (it == edgemaps.end()) 1203 return false; 1204 else 1205 return true; 1206 } 1207 1208 std::vector<std::string> MapStorage::getEdgeMaps(MapType type) 1209 { 1210 std::vector<std::string> maps; 1211 for (EdgeMapStore::const_iterator it = edgemaps.begin(); it != edgemaps.end(); ++it) 1212 { 1213 if (it->second->type() & type) 1214 { 1215 maps.push_back(it->first); 1216 } 1217 } 1218 return maps; 1219 } 1220 1221 std::vector<std::string> MapStorage::getNodeMaps(MapType type) 1222 { 1223 std::vector<std::string> maps; 1224 for (NodeMapStore::const_iterator it = nodemaps.begin(); it != nodemaps.end(); ++it) 1225 { 1226 if (it->second->type() & type) 1227 { 1228 maps.push_back(it->first); 1229 } 1230 } 1231 return maps; 1232 } 1233 1234 MapStorage::NodeCoordMap& MapStorage::getNodeCoordMap() 1235 { 1236 return node_coords; 1237 } 1238 1239 MapStorage::ArrowCoordMap& MapStorage::getArrowCoordMap() 1240 { 1241 return arrow_coords; 1242 } 1243 1244 MapStorage::SpecMapSaveOpts::Dest MapStorage::getNodeCoordsSaveDest() 1245 { 1246 return node_coords_save_dest; 1247 } 1248 1249 MapStorage::SpecMapSaveOpts::Dest MapStorage::getArrowCoordsSaveDest() 1250 { 1251 return arrow_coords_save_dest; 1252 } 1253 1254 void MapStorage::setNodeCoordsSaveDest(MapStorage::SpecMapSaveOpts::Dest dest) 1255 { 1256 node_coords_save_dest = dest; 1257 } 1258 1259 void MapStorage::setArrowCoordsSaveDest(MapStorage::SpecMapSaveOpts::Dest dest) 1260 { 1261 arrow_coords_save_dest = dest; 1262 } 1263 1264 MapStorage::SpecMapSaveOpts::MapNum MapStorage::getNodeCoordsSaveMapNum() 1265 { 1266 return node_coords_save_map_num; 1267 } 1268 1269 MapStorage::SpecMapSaveOpts::MapNum MapStorage::getArrowCoordsSaveMapNum() 1270 { 1271 return arrow_coords_save_map_num; 1272 } 1273 1274 void MapStorage::setNodeCoordsSaveMapNum(MapStorage::SpecMapSaveOpts::MapNum num) 1275 { 1276 node_coords_save_map_num = num; 1277 } 1278 1279 void MapStorage::setArrowCoordsSaveMapNum(MapStorage::SpecMapSaveOpts::MapNum num) 1280 { 1281 arrow_coords_save_map_num = num; 1282 } 1283 1284 const std::string& MapStorage::getNodeCoordsOneMapName() 1285 { 1286 return node_coords_one_map_name; 1287 } 1288 const std::string& MapStorage::getNodeCoordsTwoMaps1Name() 1289 { 1290 return node_coords_two_maps_1_name; 1291 } 1292 const std::string& MapStorage::getNodeCoordsTwoMaps2Name() 1293 { 1294 return node_coords_two_maps_2_name; 1295 } 1296 1297 void MapStorage::setNodeCoordsOneMapName(const std::string& name) 1298 { 1299 node_coords_one_map_name = name; 1300 } 1301 void MapStorage::setNodeCoordsTwoMaps1Name(const std::string& name) 1302 { 1303 node_coords_two_maps_1_name = name; 1304 } 1305 void MapStorage::setNodeCoordsTwoMaps2Name(const std::string& name) 1306 { 1307 node_coords_two_maps_2_name = name; 1308 } 1309 1310 const std::string& MapStorage::getArrowCoordsOneMapName() 1311 { 1312 return arrow_coords_one_map_name; 1313 } 1314 const std::string& MapStorage::getArrowCoordsTwoMaps1Name() 1315 { 1316 return arrow_coords_two_maps_1_name; 1317 } 1318 const std::string& MapStorage::getArrowCoordsTwoMaps2Name() 1319 { 1320 return arrow_coords_two_maps_2_name; 1321 } 1322 1323 void MapStorage::setArrowCoordsOneMapName(const std::string& name) 1324 { 1325 arrow_coords_one_map_name = name; 1326 } 1327 void MapStorage::setArrowCoordsTwoMaps1Name(const std::string& name) 1328 { 1329 arrow_coords_two_maps_1_name = name; 1330 } 1331 void MapStorage::setArrowCoordsTwoMaps2Name(const std::string& name) 1332 { 1333 arrow_coords_two_maps_2_name = name; 1334 } 1335 1336 void MapStorage::readLGF( 1337 const std::string& filename, 1338 bool read_edge_label, 1339 const std::vector<std::string>& node_map_names, 1340 const std::vector<std::string>& edge_map_names, 1341 const std::map<std::string, MapValue::Type>& node_map_types, 1342 const std::map<std::string, MapValue::Type>& edge_map_types, 1343 const std::string& node_coord_xmap_name, 1344 const std::string& node_coord_ymap_name, 1345 const std::string& arrow_coord_xmap_name, 1346 const std::string& arrow_coord_ymap_name) 1347 { 1348 using std::vector; 1349 using std::map; 1350 using std::string; 1351 1352 GraphReader<Graph> greader(filename, graph); 1353 1354 // read the label maps 1355 greader.readNodeMap("label", node_label); 1356 if (read_edge_label) 1357 greader.readEdgeMap("label", edge_label); 1358 1359 // read the node maps 1360 for (vector<string>::const_iterator 1361 it = node_map_names.begin(); 1362 it != node_map_names.end(); ++it) 1363 { 1364 switch (node_map_types.find(*it)->second) 1365 { 1366 case MapValue::NUMERIC: 1367 { 1368 createNodeMap(*it, MapValue::NUMERIC, double()); 1369 greader.readNodeMap(*it, getNumericNodeMap(*it)); 1370 break; 1371 } 1372 case MapValue::STRING: 1373 { 1374 createNodeMap(*it, MapValue::STRING, string()); 1375 greader.readNodeMap(*it, getStringNodeMap(*it)); 1376 break; 1377 } 1378 } 1379 getNodeMapData(*it)->save_dest = NESET_SECT; 1380 } 1381 1382 // read the edge maps 1383 for (vector<string>::const_iterator 1384 it = edge_map_names.begin(); 1385 it != edge_map_names.end(); ++it) 1386 { 1387 switch (edge_map_types.find(*it)->second) 1388 { 1389 case MapValue::NUMERIC: 1390 { 1391 createEdgeMap(*it, MapValue::NUMERIC, double()); 1392 greader.readEdgeMap(*it, getNumericEdgeMap(*it)); 1393 break; 1394 } 1395 case MapValue::STRING: 1396 { 1397 createEdgeMap(*it, MapValue::STRING, string()); 1398 greader.readEdgeMap(*it, getStringEdgeMap(*it)); 1399 break; 1400 } 1401 } 1402 getEdgeMapData(*it)->save_dest = NESET_SECT; 1403 } 1404 1405 // read the node coordinate maps 1406 if (node_coord_xmap_name != "") 1407 greader.readNodeMap(node_coord_xmap_name, node_coords_x); 1408 if (node_coord_ymap_name != "") 1409 greader.readNodeMap(node_coord_ymap_name, node_coords_y); 1410 1411 // read the arrow coordinate maps 1412 if (arrow_coord_xmap_name != "") 1413 greader.readEdgeMap(arrow_coord_xmap_name, arrow_coords_x); 1414 if (arrow_coord_ymap_name != "") 1415 greader.readEdgeMap(arrow_coord_ymap_name, arrow_coords_y); 1416 1417 greader.run(); 556 1418 } 557 1419 … … 611 1473 if(active_nodemaps[N_RADIUS]!="") 612 1474 { 613 _nodeSizes= *(nodemap_storage[active_nodemaps[N_RADIUS]]);1475 _nodeSizes=getNumericNodeMap(active_nodemaps[N_RADIUS]); 614 1476 } 615 1477 if(active_nodemaps[N_COLOR]!="") … … 617 1479 for(NodeIt ni(graph);ni!=INVALID;++ni) 618 1480 { 619 _nodeColors[ni]=(int) ((*(nodemap_storage[active_nodemaps[N_COLOR]]))[ni]);1481 _nodeColors[ni]=(int)get(active_nodemaps[N_COLOR], ni); 620 1482 } 621 1483 } … … 625 1487 { 626 1488 std::ostringstream o; 627 o << ((*(nodemap_storage[active_nodemaps[N_TEXT]]))[ni]);1489 o << get(active_nodemaps[N_TEXT], ni); 628 1490 _nodeTextMap[ni]=o.str(); 629 1491 } … … 634 1496 if(active_edgemaps[E_WIDTH]!="") 635 1497 { 636 _edgeWidths= *(edgemap_storage[active_edgemaps[E_WIDTH]]);1498 _edgeWidths=getNumericEdgeMap(active_edgemaps[E_WIDTH]); 637 1499 } 638 1500 if(active_edgemaps[E_COLOR]!="") … … 640 1502 for(EdgeIt ei(graph);ei!=INVALID;++ei) 641 1503 { 642 _edgeColors[ei]=(int) ((*(edgemap_storage[active_edgemaps[E_COLOR]]))[ei]);1504 _edgeColors[ei]=(int)get(active_edgemaps[E_COLOR], ei); 643 1505 } 644 1506 } … … 646 1508 if(shapemap!="Default values") 647 1509 { 648 if((minOfNodeMap(shapemap)>=0)&&(maxOfNodeMap(shapemap)<=4)) 1510 double min = std::numeric_limits<double>::max(); 1511 double max = std::numeric_limits<double>::min(); 1512 for (NodeIt n(graph); n != INVALID; ++n) 1513 { 1514 double v = static_cast<double>(get(shapemap, n)); 1515 if (v < min) min = v; 1516 if (v > max) max = v; 1517 } 1518 if((min>=0)&&(max<=4)) 649 1519 { 650 _shapes=*(nodemap_storage[shapemap]); 1520 NumericNodeMap& map = static_cast<NumericNodeMapData*>(getNodeMapData(shapemap))->map; 1521 for (NodeIt n(graph); n != INVALID; ++n) 1522 { 1523 _shapes[n] = static_cast<int>(map[n]); 1524 } 651 1525 } 652 1526 } … … 660 1534 absoluteNodeSizes().absoluteEdgeWidths(). 661 1535 nodeScale(2).nodeSizes(_nodeSizes). 662 coords( coords).1536 coords(node_coords). 663 1537 nodeShapes(_shapes). 664 1538 nodeColors(composeMap(paletteW,_nodeColors)). -
mapstorage.h
r198 r201 20 20 #define MAPSTORAGE_H 21 21 22 #include <all_include.h> 23 #include <xymap.h> 22 class Mapstorage; 23 24 #include <vector> 25 #include <map> 26 #include <string> 27 #include "all_include.h" 28 #include "xymap.h" 24 29 #include <libgnomecanvasmm.h> 30 #include "map_value.h" 31 #include "map_value_map.h" 25 32 26 33 ///class MapStorage handles NodeMaps and EdgeMaps. … … 42 49 double background_scaling; 43 50 public: 51 class Error : public std::exception 52 { 53 private: 54 std::string message; 55 public: 56 Error(const std::string& msg) : message(msg) {} 57 virtual const char* what() const throw() 58 { 59 return message.c_str(); 60 } 61 ~Error() throw() {} 62 }; 63 44 64 void setBackground(const std::string& file_name); 45 65 const std::string& getBackgroundFilename(); … … 47 67 double getBackgroundScaling(); 48 68 void setBackgroundScaling(double scaling); 69 70 enum MapSaveDest { GUI_SECT, NESET_SECT, DONT_SAVE }; 71 enum GuiSectSaveDest { LGF_FILE, CONF_FILE }; 72 struct SpecMapSaveOpts 73 { 74 enum Dest { GUI_SECT, NESET_SECT }; 75 enum MapNum { ONE_MAP, TWO_MAPS }; 76 }; 77 78 typedef Graph::NodeMap<double> NumericNodeMap; 79 typedef Graph::NodeMap<std::string> StringNodeMap; 80 typedef Graph::EdgeMap<double> NumericEdgeMap; 81 typedef Graph::EdgeMap<std::string> StringEdgeMap; 82 typedef Graph::NodeMap<int> NodeLabelMap; 83 typedef Graph::EdgeMap<int> EdgeLabelMap; 84 typedef XYMap<Graph::NodeMap<double> > NodeCoordMap; 85 typedef XYMap<Graph::EdgeMap<double> > ArrowCoordMap; 86 87 struct EdgeMapData 88 { 89 /// where to save the map 90 MapSaveDest save_dest; 91 /// read-only or read-write 92 bool writeable; 93 /// default value 94 MapValue default_value; 95 virtual MapValue::Type type() = 0; 96 virtual MapValue get(Edge e) = 0; 97 virtual void set(Edge e, MapValue v) = 0; 98 EdgeMapData(MapValue def_val) : 99 save_dest(GUI_SECT), 100 writeable(true), 101 default_value(def_val) 102 {} 103 }; 104 105 struct NumericEdgeMapData : public EdgeMapData 106 { 107 NumericEdgeMap map; 108 MapValue::Type type() { return MapValue::NUMERIC; } 109 MapValue get(Edge e) { return MapValue(map[e]); } 110 void set(Edge e, MapValue v) { map.set(e, static_cast<double>(v)); } 111 NumericEdgeMapData(Graph& g, double def_val) : 112 EdgeMapData(MapValue(def_val)), 113 map(g, def_val) 114 {} 115 }; 116 117 struct StringEdgeMapData : public EdgeMapData 118 { 119 StringEdgeMap map; 120 MapValue::Type type() { return MapValue::STRING; } 121 MapValue get(Edge e) { return MapValue(map[e]); } 122 void set(Edge e, MapValue v) { map.set(e, static_cast<std::string>(v)); } 123 StringEdgeMapData(Graph& g, std::string def_val) : 124 EdgeMapData(MapValue(def_val)), 125 map(g, def_val) 126 {} 127 }; 128 129 struct NodeMapData 130 { 131 /// where to save the map 132 MapSaveDest save_dest; 133 /// read-only or read-write 134 bool writeable; 135 /// default value 136 MapValue default_value; 137 virtual MapValue::Type type() = 0; 138 virtual MapValue get(Node e) = 0; 139 virtual void set(Node e, MapValue v) = 0; 140 NodeMapData(MapValue def_val) : 141 save_dest(GUI_SECT), 142 writeable(true), 143 default_value(def_val) 144 {} 145 }; 146 147 struct NumericNodeMapData : public NodeMapData 148 { 149 NumericNodeMap map; 150 MapValue::Type type() { return MapValue::NUMERIC; } 151 MapValue get(Node e) { return MapValue(map[e]); } 152 void set(Node e, MapValue v) { map.set(e, static_cast<double>(v)); } 153 NumericNodeMapData(Graph& g, double def_val) : 154 NodeMapData(MapValue(def_val)), 155 map(g, def_val) 156 {} 157 }; 158 159 struct StringNodeMapData : public NodeMapData 160 { 161 StringNodeMap map; 162 MapValue::Type type() { return MapValue::STRING; } 163 MapValue get(Node e) { return MapValue(map[e]); } 164 void set(Node e, MapValue v) { map.set(e, static_cast<std::string>(v)); } 165 StringNodeMapData(Graph& g, std::string def_val) : 166 NodeMapData(MapValue(def_val)), 167 map(g, def_val) 168 {} 169 }; 170 171 typedef std::map<std::string, NodeMapData*> NodeMapStore; 172 typedef std::map<std::string, EdgeMapData*> EdgeMapStore; 173 174 struct GUISectData 175 { 176 std::vector<std::string> main_node_map_names; 177 std::vector<std::string> main_edge_map_names; 178 179 std::vector<std::string> gui_node_map_names; 180 std::vector<std::string> gui_edge_map_names; 181 182 std::map<std::string, MapValue::Type> node_map_types; 183 std::map<std::string, MapValue::Type> edge_map_types; 184 185 std::map<std::string, std::map<int, double>* > numeric_node_maps; 186 std::map<std::string, std::map<int, std::string>* > string_node_maps; 187 188 std::map<std::string, std::map<int, double>* > numeric_edge_maps; 189 std::map<std::string, std::map<int, std::string>* > string_edge_maps; 190 191 std::map<int, XY> node_coord_map; 192 std::map<int, XY> arrow_coord_map; 193 194 SpecMapSaveOpts::Dest node_coords_save_dest; 195 SpecMapSaveOpts::MapNum node_coords_save_map_num; 196 std::string node_coords_one_map_name; 197 std::string node_coords_two_maps_1_name; 198 std::string node_coords_two_maps_2_name; 199 200 SpecMapSaveOpts::Dest arrow_coords_save_dest; 201 SpecMapSaveOpts::MapNum arrow_coords_save_map_num; 202 std::string arrow_coords_one_map_name; 203 std::string arrow_coords_two_maps_1_name; 204 std::string arrow_coords_two_maps_2_name; 205 206 ~GUISectData() 207 { 208 using std::map; 209 using std::vector; 210 using std::pair; 211 using std::string; 212 213 for (map<string, map<int, double>* >::iterator it = 214 numeric_node_maps.begin(); it != numeric_node_maps.end(); ++it) 215 { 216 delete it->second; 217 } 218 for (map<string, map<int, string>* >::iterator it = 219 string_node_maps.begin(); it != string_node_maps.end(); ++it) 220 { 221 delete it->second; 222 } 223 for (map<string, map<int, double>* >::iterator it = 224 numeric_edge_maps.begin(); it != numeric_edge_maps.end(); ++it) 225 { 226 delete it->second; 227 } 228 for (map<string, map<int, string>* >::iterator it = 229 string_edge_maps.begin(); it != string_edge_maps.end(); ++it) 230 { 231 delete it->second; 232 } 233 } 234 }; 235 public: 49 236 ///The graph for which the datas are stored. 50 237 Graph graph; 238 const Graph& getGraph(); 239 240 private: 241 GuiSectSaveDest gui_sect_save_dest; 242 243 SpecMapSaveOpts::Dest node_coords_save_dest; 244 SpecMapSaveOpts::MapNum node_coords_save_map_num; 245 SpecMapSaveOpts::Dest arrow_coords_save_dest; 246 SpecMapSaveOpts::MapNum arrow_coords_save_map_num; 247 248 NodeMapStore nodemaps; 249 EdgeMapStore edgemaps; 250 251 NodeLabelMap node_label; 252 EdgeLabelMap edge_label; 253 51 254 /// the coordinates of the nodes 52 XYMap<Graph::NodeMap<double> > coords; 255 NodeCoordMap node_coords; 256 Graph::NodeMap<double> node_coords_x; 257 Graph::NodeMap<double> node_coords_y; 258 53 259 /// the coordinates of the arrows on the edges 54 XYMap<Graph::EdgeMap<double> > arrow_pos; 260 ArrowCoordMap arrow_coords; 261 Graph::EdgeMap<double> arrow_coords_x; 262 Graph::EdgeMap<double> arrow_coords_y; 55 263 56 264 ///The content of the object has changed, update is needed. … … 60 268 std::string file_name; 61 269 62 ///Stores double type NodeMaps 63 std::map< std::string,Graph::NodeMap<double> * > nodemap_storage; 64 65 ///Stores double type EdgeMaps 66 std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage; 67 270 // the largest node label 271 int max_node_label; 272 273 // the largest edge label 274 int max_edge_label; 275 276 std::string node_coords_one_map_name; 277 std::string node_coords_two_maps_1_name; 278 std::string node_coords_two_maps_2_name; 279 280 std::string arrow_coords_one_map_name; 281 std::string arrow_coords_two_maps_1_name; 282 std::string arrow_coords_two_maps_2_name; 283 284 public: 68 285 ///Stores the default values for the different visualization node attributes 69 286 std::vector<Graph::NodeMap<double> > default_nodemaps; … … 77 294 /// Stores the active maps for the different visualization edge attributes 78 295 std::vector< std::string > active_edgemaps; 79 80 /// Default values for the maps81 std::map< std::string, double > nodemap_default;82 83 /// Default values for the maps84 std::map< std::string, double > edgemap_default;85 86 bool arrow_pos_read_ok;87 296 88 297 protected: … … 99 308 /// std::string is the 100 309 ///name of the new map 101 sigc::signal<void, std::string > signal_node_map;310 sigc::signal<void, std::string, MapValue::Type> signal_node_map; 102 311 103 312 /// Signal emitted in the case of edgemap addition … … 105 314 /// std::string is the 106 315 ///name of the new map 107 sigc::signal<void, std::string > signal_edge_map;316 sigc::signal<void, std::string, MapValue::Type> signal_edge_map; 108 317 109 318 /// Signal emitted, when entry in \ref MapWin should be changed. … … 165 374 166 375 /// Returns the names of the edgemaps stored here. 167 std::vector<std::string> getEdgeMapList( );376 std::vector<std::string> getEdgeMapList(MapType type = ALL); 168 377 169 378 /// Returns the names of the nodemaps stored here. 170 std::vector<std::string> getNodeMapList( );379 std::vector<std::string> getNodeMapList(MapType type = ALL); 171 380 172 381 ///returns \ref signal_prop to be able to connect functions to it … … 174 383 175 384 &nb