diff -r c7ae8642a8d8 -r 879e47e5b731 gui_writer.cc --- a/gui_writer.cc Wed May 02 20:33:58 2007 +0000 +++ b/gui_writer.cc Wed Jan 02 21:03:09 2008 +0000 @@ -16,7 +16,10 @@ * */ -#include +#include "gui_writer.h" +#include "io_helper.h" +#include "mapstorage.h" +#include "xml.h" #include #include @@ -30,28 +33,232 @@ void GuiWriter::write(std::ostream& os) { + using std::vector; + using std::string; + using std::map; + using std::string; + XmlIo x(os); - std::map m; - for (EdgeIt e(mapstorage->graph); e != INVALID; ++e) + + vector all_node_map_names = mapstorage->getNodeMapList(); + // name of the maps saved to the nodeset section + vector main_node_map_names; + // name of the maps saved to the gui section + vector gui_node_map_names; + + for (vector::const_iterator it = all_node_map_names.begin(); + it != all_node_map_names.end(); ++it) { - int edgeid = (int)(*(mapstorage->edgemap_storage["label"]))[e]; - m[edgeid] = mapstorage->arrow_pos[e]; + if (mapstorage->getNodeMapSaveDest(*it) == MapStorage::NESET_SECT) + main_node_map_names.push_back(*it); + else if (mapstorage->getNodeMapSaveDest(*it) == MapStorage::GUI_SECT) + gui_node_map_names.push_back(*it); } - x("arrow_pos", m); + + { x("main_node_map_names", main_node_map_names); } + { x("gui_node_map_names", gui_node_map_names); } + + map node_map_types; + for (vector::const_iterator it = main_node_map_names.begin(); + it != main_node_map_names.end(); ++it) + { + node_map_types[*it] = mapstorage->getNodeMapElementType(*it); + } + for (vector::const_iterator it = gui_node_map_names.begin(); + it != gui_node_map_names.end(); ++it) + { + node_map_types[*it] = mapstorage->getNodeMapElementType(*it); + } + + { x("node_map_types", node_map_types); } + + + vector all_edge_map_names = mapstorage->getEdgeMapList(); + // name of the maps saved to the edgeset section + vector main_edge_map_names; + // name of the maps saved to the gui section + vector gui_edge_map_names; + + for (vector::const_iterator it = all_edge_map_names.begin(); + it != all_edge_map_names.end(); ++it) + { + if (mapstorage->getEdgeMapSaveDest(*it) == MapStorage::NESET_SECT) + main_edge_map_names.push_back(*it); + if (mapstorage->getEdgeMapSaveDest(*it) == MapStorage::GUI_SECT) + gui_edge_map_names.push_back(*it); + } + + { x("main_edge_map_names", main_edge_map_names); } + { x("gui_edge_map_names", gui_edge_map_names); } + + map edge_map_types; + for (vector::const_iterator it = main_edge_map_names.begin(); + it != main_edge_map_names.end(); ++it) + { + edge_map_types[*it] = mapstorage->getEdgeMapElementType(*it); + } + for (vector::const_iterator it = gui_edge_map_names.begin(); + it != gui_edge_map_names.end(); ++it) + { + edge_map_types[*it] = mapstorage->getEdgeMapElementType(*it); + } + + { x("edge_map_types", edge_map_types); } + + // write the gui node maps + for (vector::const_iterator it = gui_node_map_names.begin(); + it != gui_node_map_names.end(); ++it) + { + MapValue::Type type = mapstorage->getNodeMapElementType(*it); + const MapStorage::NodeLabelMap& labels = mapstorage->getNodeLabelMap(); + switch (type) + { + case MapValue::NUMERIC: + { + std::map map_data; + MapStorage::NumericNodeMap& map = + mapstorage->getNumericNodeMap(*it); + for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n) + { + map_data[labels[n]] = map[n]; + } + { x(*it, map_data); } + } + break; + case MapValue::STRING: + { + std::map map_data; + MapStorage::StringNodeMap& map = + mapstorage->getStringNodeMap(*it); + for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n) + { + map_data[labels[n]] = map[n]; + } + { x(*it, map_data); } + } + break; + } + } + + // write the gui edge maps + for (vector::const_iterator it = gui_edge_map_names.begin(); + it != gui_edge_map_names.end(); ++it) + { + MapValue::Type type = mapstorage->getEdgeMapElementType(*it); + const MapStorage::EdgeLabelMap& labels = mapstorage->getEdgeLabelMap(); + switch (type) + { + case MapValue::NUMERIC: + { + std::map map_data; + MapStorage::NumericEdgeMap& map = + mapstorage->getNumericEdgeMap(*it); + for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e) + { + map_data[labels[e]] = map[e]; + } + { x(*it, map_data); } + } + break; + case MapValue::STRING: + { + std::map map_data; + MapStorage::StringEdgeMap& map = + mapstorage->getStringEdgeMap(*it); + for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e) + { + map_data[labels[e]] = map[e]; + } + { x(*it, map_data); } + } + break; + } + } + + { + switch (mapstorage->getNodeCoordsSaveDest()) + { + case MapStorage::SpecMapSaveOpts::GUI_SECT: + { x("node_coords_save_dest", string("gui_sect")); } + // write the node coorinates + { + const MapStorage::NodeLabelMap& labels = + mapstorage->getNodeLabelMap(); + std::map node_coord_map; + MapStorage::NodeCoordMap& map = mapstorage->getNodeCoordMap(); + for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n) + { + node_coord_map[labels[n]] = map[n]; + } + { x("node_coord_map", node_coord_map); } + } + break; + case MapStorage::SpecMapSaveOpts::NESET_SECT: + switch (mapstorage->getNodeCoordsSaveMapNum()) + { + case MapStorage::SpecMapSaveOpts::ONE_MAP: + { x("node_coords_save_dest", string("nodeset_sect_1_map")); } + { x("map_name", mapstorage->getNodeCoordsOneMapName()); } + break; + case MapStorage::SpecMapSaveOpts::TWO_MAPS: + { x("node_coords_save_dest", string("nodeset_sect_2_maps")); } + { x("map1_name", mapstorage->getNodeCoordsTwoMaps1Name()); } + { x("map2_name", mapstorage->getNodeCoordsTwoMaps2Name()); } + break; + } + break; + } + } + + { + switch (mapstorage->getArrowCoordsSaveDest()) + { + case MapStorage::SpecMapSaveOpts::GUI_SECT: + { x("arrow_coords_save_dest", string("gui_sect")); } + // write the arrow coorinates + { + const MapStorage::EdgeLabelMap& labels = + mapstorage->getEdgeLabelMap(); + std::map arrow_coord_map; + MapStorage::ArrowCoordMap& map = mapstorage->getArrowCoordMap(); + for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e) + { + arrow_coord_map[labels[e]] = map[e]; + } + { x("arrow_coord_map", arrow_coord_map); } + } + break; + case MapStorage::SpecMapSaveOpts::NESET_SECT: + switch (mapstorage->getArrowCoordsSaveMapNum()) + { + case MapStorage::SpecMapSaveOpts::ONE_MAP: + { x("arrow_coords_save_dest", string("edgeset_sect_1_map")); } + { x("map_name", mapstorage->getArrowCoordsOneMapName()); } + break; + case MapStorage::SpecMapSaveOpts::TWO_MAPS: + { x("arrow_coords_save_dest", string("edgeset_sect_2_maps")); } + { x("map1_name", mapstorage->getArrowCoordsTwoMaps1Name()); } + { x("map2_name", mapstorage->getArrowCoordsTwoMaps2Name()); } + break; + } + break; + } + } + std::map nm; for(int i=0;iactive_nodemaps[i]; } - x("active_nodemaps", nm); + { x("active_nodemaps", nm); } std::map em; for(int i=0;iactive_edgemaps[i]; } - x("active_edgemaps", em); + { x("active_edgemaps", em); } double attraction; double propulsation; @@ -59,11 +266,13 @@ mapstorage->get_design_data(attraction, propulsation, iteration); - x("redesign-attraction", attraction); - x("redesign-propulsation", propulsation); - x("redesign-iteration", iteration); + { x("redesign-attraction", attraction); } + { x("redesign-propulsation", propulsation); } + { x("redesign-iteration", iteration); } } -GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) : Parent(writer), mapstorage(ms) +GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) : + Parent(writer), + mapstorage(ms) { }