hegyi@1: /* -*- C++ -*- hegyi@1: * hegyi@1: * This file is a part of LEMON, a generic C++ optimization library hegyi@1: * hegyi@1: * Copyright (C) 2003-2006 hegyi@1: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport hegyi@1: * (Egervary Research Group on Combinatorial Optimization, EGRES). hegyi@1: * hegyi@1: * Permission to use, modify and distribute this software is granted hegyi@1: * provided that this copyright notice appears in all copies. For hegyi@1: * precise terms see the accompanying LICENSE file. hegyi@1: * hegyi@1: * This software is provided "AS IS" with no warranty of any kind, hegyi@1: * express or implied, and with no claim as to its suitability for any hegyi@1: * purpose. hegyi@1: * hegyi@1: */ hegyi@1: hegyi@1: #ifndef MAPSTORAGE_H hegyi@1: #define MAPSTORAGE_H hegyi@1: hegyi@1: class Mapstorage; hegyi@1: hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: #include "all_include.h" hegyi@1: #include "xymap.h" hegyi@1: #include hegyi@1: #include "map_value.h" hegyi@1: #include "map_value_map.h" hegyi@1: hegyi@1: ///class MapStorage handles NodeMaps and ArcMaps. hegyi@1: hegyi@1: ///Class MapStorage is responsible for storing hegyi@1: ///NodeMaps and ArcMaps that can be shown later hegyi@1: ///on GUI. Therefore maps can be added to it, hegyi@1: ///and datas over the added maps can be queried. hegyi@1: ///The maps will be stored in an std::map, hegyi@1: ///referenced with their names. Unfortunately at hegyi@1: ///the moment it works only with double type maps hegyi@1: /// hegyi@1: ///\todo too many things are public!! hegyi@1: class MapStorage hegyi@1: { hegyi@1: private: hegyi@1: std::string background_file_name; hegyi@1: bool background_set; hegyi@1: double background_scaling; hegyi@1: public: hegyi@1: class Error : public std::exception hegyi@1: { hegyi@1: private: hegyi@1: std::string message; hegyi@1: public: hegyi@1: Error(const std::string& msg) : message(msg) {} hegyi@1: virtual const char* what() const throw() hegyi@1: { hegyi@1: return message.c_str(); hegyi@1: } hegyi@1: ~Error() throw() {} hegyi@1: }; hegyi@1: hegyi@1: void setBackground(const std::string& file_name); hegyi@1: const std::string& getBackgroundFilename(); hegyi@1: bool isBackgroundSet(); hegyi@1: double getBackgroundScaling(); hegyi@1: void setBackgroundScaling(double scaling); hegyi@1: hegyi@1: enum MapSaveDest { GUI_SECT, NESET_SECT, DONT_SAVE }; hegyi@1: enum GuiSectSaveDest { LGF_FILE, CONF_FILE }; hegyi@1: struct SpecMapSaveOpts hegyi@1: { hegyi@1: enum Dest { GUI_SECT, NESET_SECT }; hegyi@1: enum MapNum { ONE_MAP, TWO_MAPS }; hegyi@1: }; hegyi@1: hegyi@1: typedef Digraph::NodeMap NumericNodeMap; hegyi@1: typedef Digraph::NodeMap StringNodeMap; hegyi@1: typedef Digraph::ArcMap NumericArcMap; hegyi@1: typedef Digraph::ArcMap StringArcMap; hegyi@1: typedef Digraph::NodeMap NodeLabelMap; hegyi@1: typedef Digraph::ArcMap ArcLabelMap; hegyi@1: typedef XYMap > NodeCoordMap; hegyi@1: typedef XYMap > ArrowCoordMap; hegyi@1: hegyi@1: struct ArcMapData hegyi@1: { hegyi@1: /// where to save the map hegyi@1: MapSaveDest save_dest; hegyi@1: /// read-only or read-write hegyi@1: bool writeable; hegyi@1: /// default value hegyi@1: MapValue default_value; hegyi@1: virtual MapValue::Type type() = 0; hegyi@1: virtual MapValue get(Arc e) = 0; hegyi@1: virtual void set(Arc e, MapValue v) = 0; hegyi@1: ArcMapData(MapValue def_val) : hegyi@1: save_dest(GUI_SECT), hegyi@1: writeable(true), hegyi@1: default_value(def_val) hegyi@1: {} hegyi@1: }; hegyi@1: hegyi@1: struct NumericArcMapData : public ArcMapData hegyi@1: { hegyi@1: NumericArcMap map; hegyi@1: MapValue::Type type() { return MapValue::NUMERIC; } hegyi@1: MapValue get(Arc e) { return MapValue(map[e]); } hegyi@1: void set(Arc e, MapValue v) { map.set(e, static_cast(v)); } hegyi@1: NumericArcMapData(Digraph& g, double def_val) : hegyi@1: ArcMapData(MapValue(def_val)), hegyi@1: map(g, def_val) hegyi@1: {} hegyi@1: }; hegyi@1: hegyi@1: struct StringArcMapData : public ArcMapData hegyi@1: { hegyi@1: StringArcMap map; hegyi@1: MapValue::Type type() { return MapValue::STRING; } hegyi@1: MapValue get(Arc e) { return MapValue(map[e]); } hegyi@1: void set(Arc e, MapValue v) { map.set(e, static_cast(v)); } hegyi@1: StringArcMapData(Digraph& g, std::string def_val) : hegyi@1: ArcMapData(MapValue(def_val)), hegyi@1: map(g, def_val) hegyi@1: {} hegyi@1: }; hegyi@1: hegyi@1: struct NodeMapData hegyi@1: { hegyi@1: /// where to save the map hegyi@1: MapSaveDest save_dest; hegyi@1: /// read-only or read-write hegyi@1: bool writeable; hegyi@1: /// default value hegyi@1: MapValue default_value; hegyi@1: virtual MapValue::Type type() = 0; hegyi@1: virtual MapValue get(Node e) = 0; hegyi@1: virtual void set(Node e, MapValue v) = 0; hegyi@1: NodeMapData(MapValue def_val) : hegyi@1: save_dest(GUI_SECT), hegyi@1: writeable(true), hegyi@1: default_value(def_val) hegyi@1: {} hegyi@1: }; hegyi@1: hegyi@1: struct NumericNodeMapData : public NodeMapData hegyi@1: { hegyi@1: NumericNodeMap map; hegyi@1: MapValue::Type type() { return MapValue::NUMERIC; } hegyi@1: MapValue get(Node e) { return MapValue(map[e]); } hegyi@1: void set(Node e, MapValue v) { map.set(e, static_cast(v)); } hegyi@1: NumericNodeMapData(Digraph& g, double def_val) : hegyi@1: NodeMapData(MapValue(def_val)), hegyi@1: map(g, def_val) hegyi@1: {} hegyi@1: }; hegyi@1: hegyi@1: struct StringNodeMapData : public NodeMapData hegyi@1: { hegyi@1: StringNodeMap map; hegyi@1: MapValue::Type type() { return MapValue::STRING; } hegyi@1: MapValue get(Node e) { return MapValue(map[e]); } hegyi@1: void set(Node e, MapValue v) { map.set(e, static_cast(v)); } hegyi@1: StringNodeMapData(Digraph& g, std::string def_val) : hegyi@1: NodeMapData(MapValue(def_val)), hegyi@1: map(g, def_val) hegyi@1: {} hegyi@1: }; hegyi@1: hegyi@1: typedef std::map NodeMapStore; hegyi@1: typedef std::map ArcMapStore; hegyi@1: hegyi@1: struct GUISectData hegyi@1: { hegyi@1: std::vector main_node_map_names; hegyi@1: std::vector main_arc_map_names; hegyi@1: hegyi@1: std::vector gui_node_map_names; hegyi@1: std::vector gui_arc_map_names; hegyi@1: hegyi@1: std::map node_map_types; hegyi@1: std::map arc_map_types; hegyi@1: hegyi@1: std::map* > numeric_node_maps; hegyi@1: std::map* > string_node_maps; hegyi@1: hegyi@1: std::map* > numeric_arc_maps; hegyi@1: std::map* > string_arc_maps; hegyi@1: hegyi@1: std::map node_coord_map; hegyi@1: std::map arrow_coord_map; hegyi@1: hegyi@1: SpecMapSaveOpts::Dest node_coords_save_dest; hegyi@1: SpecMapSaveOpts::MapNum node_coords_save_map_num; hegyi@1: std::string node_coords_one_map_name; hegyi@1: std::string node_coords_two_maps_1_name; hegyi@1: std::string node_coords_two_maps_2_name; hegyi@1: hegyi@1: SpecMapSaveOpts::Dest arrow_coords_save_dest; hegyi@1: SpecMapSaveOpts::MapNum arrow_coords_save_map_num; hegyi@1: std::string arrow_coords_one_map_name; hegyi@1: std::string arrow_coords_two_maps_1_name; hegyi@1: std::string arrow_coords_two_maps_2_name; hegyi@1: hegyi@1: ~GUISectData() hegyi@1: { hegyi@1: using std::map; hegyi@1: using std::vector; hegyi@1: using std::pair; hegyi@1: using std::string; hegyi@1: hegyi@1: for (map* >::iterator it = hegyi@1: numeric_node_maps.begin(); it != numeric_node_maps.end(); ++it) hegyi@1: { hegyi@1: delete it->second; hegyi@1: } hegyi@1: for (map* >::iterator it = hegyi@1: string_node_maps.begin(); it != string_node_maps.end(); ++it) hegyi@1: { hegyi@1: delete it->second; hegyi@1: } hegyi@1: for (map* >::iterator it = hegyi@1: numeric_arc_maps.begin(); it != numeric_arc_maps.end(); ++it) hegyi@1: { hegyi@1: delete it->second; hegyi@1: } hegyi@1: for (map* >::iterator it = hegyi@1: string_arc_maps.begin(); it != string_arc_maps.end(); ++it) hegyi@1: { hegyi@1: delete it->second; hegyi@1: } hegyi@1: } hegyi@1: }; hegyi@1: public: hegyi@1: ///The digraph for which the datas are stored. hegyi@1: Digraph digraph; hegyi@1: const Digraph& getDigraph(); hegyi@1: hegyi@1: private: hegyi@1: GuiSectSaveDest gui_sect_save_dest; hegyi@1: hegyi@1: SpecMapSaveOpts::Dest node_coords_save_dest; hegyi@1: SpecMapSaveOpts::MapNum node_coords_save_map_num; hegyi@1: SpecMapSaveOpts::Dest arrow_coords_save_dest; hegyi@1: SpecMapSaveOpts::MapNum arrow_coords_save_map_num; hegyi@1: hegyi@1: NodeMapStore nodemaps; hegyi@1: ArcMapStore arcmaps; hegyi@1: hegyi@1: NodeLabelMap node_label; hegyi@1: ArcLabelMap arc_label; hegyi@1: hegyi@1: /// the coordinates of the nodes hegyi@1: NodeCoordMap node_coords; hegyi@1: Digraph::NodeMap node_coords_x; hegyi@1: Digraph::NodeMap node_coords_y; hegyi@1: hegyi@1: /// the coordinates of the arrows on the arcs hegyi@1: ArrowCoordMap arrow_coords; hegyi@1: Digraph::ArcMap arrow_coords_x; hegyi@1: Digraph::ArcMap arrow_coords_y; hegyi@1: hegyi@1: ///The content of the object has changed, update is needed. hegyi@1: bool modified; hegyi@1: hegyi@1: ///Name of file loaded in object. hegyi@1: std::string file_name; hegyi@1: hegyi@1: // the largest node label hegyi@1: int max_node_label; hegyi@1: hegyi@1: // the largest arc label hegyi@1: int max_arc_label; hegyi@1: hegyi@1: std::string node_coords_one_map_name; hegyi@1: std::string node_coords_two_maps_1_name; hegyi@1: std::string node_coords_two_maps_2_name; hegyi@1: hegyi@1: std::string arrow_coords_one_map_name; hegyi@1: std::string arrow_coords_two_maps_1_name; hegyi@1: std::string arrow_coords_two_maps_2_name; hegyi@1: hegyi@1: public: hegyi@1: ///Stores the default values for the different visualization node attributes hegyi@1: std::vector > default_nodemaps; hegyi@1: hegyi@1: ///Stores the default values for the different visualization arc attributes hegyi@1: std::vector > default_arcmaps; hegyi@1: hegyi@1: ///Stores the active maps for the different visualization node attributes hegyi@1: std::vector< std::string > active_nodemaps; hegyi@1: hegyi@1: /// Stores the active maps for the different visualization arc attributes hegyi@1: std::vector< std::string > active_arcmaps; hegyi@1: hegyi@1: protected: hegyi@1: hegyi@1: /// Signal emitted on any change made on map values hegyi@1: hegyi@1: /// Signal emitted if the visualization of the maps might have to be updated. hegyi@1: /// bool shows us whether the changed map is arc or nodemap. hegyi@1: /// int tells us the refreshed property hegyi@1: sigc::signal signal_prop; hegyi@1: hegyi@1: /// Signal emitted in the case of nodemap addition hegyi@1: hegyi@1: /// std::string is the hegyi@1: ///name of the new map hegyi@1: sigc::signal signal_node_map; hegyi@1: hegyi@1: /// Signal emitted in the case of arcmap addition hegyi@1: hegyi@1: /// std::string is the hegyi@1: ///name of the new map hegyi@1: sigc::signal signal_arc_map; hegyi@1: hegyi@1: /// Signal emitted, when entry in \ref MapWin should be changed. hegyi@1: sigc::signal signal_map_win; hegyi@1: hegyi@1: /// Signal emitted, when entry in \ref DesignWin should be changed. hegyi@1: sigc::signal signal_design_win; hegyi@1: hegyi@1: ///Signal emitted when background should be set by \ref NoteBookTab hegyi@1: sigc::signal signal_background; hegyi@1: hegyi@1: ///Iteration number during digraph design hegyi@1: int iterations; hegyi@1: hegyi@1: ///Attraction factor during digraph design hegyi@1: double attraction; hegyi@1: hegyi@1: ///Propulsation factor during digraph design hegyi@1: double propulsation; hegyi@1: hegyi@1: public: hegyi@1: ///Constructor of MapStorage. hegyi@1: hegyi@1: ///Its all activity is initializing default values hegyi@1: ///for different visualization attributes. hegyi@1: MapStorage(); hegyi@1: hegyi@1: ///Destructor of MapStorage hegyi@1: hegyi@1: ///Maps stored here are created with new. Destructor hegyi@1: ///deletes them to free up the reserved memory. hegyi@1: ~MapStorage(); hegyi@1: hegyi@1: /// Registrates if the shown map by any attribute has changed to another. hegyi@1: hegyi@1: ///It handles the \ref active_arcmaps and hegyi@1: ///\ref active_nodemaps vectors. It also emits \ref signal_prop signal to let hegyi@1: ///know the interested objects that the visible map of a certain hegyi@1: ///attribute has changed. hegyi@1: ///\param itisarc arcmap or nodemap has changed hegyi@1: ///\param prop the property of which the map is changed hegyi@1: ///\param mapname the visible map hegyi@1: void changeActiveMap(bool itisarc , int prop , std::string mapname); hegyi@1: hegyi@1: ///Emits signals that let change the active maps in \ref MapWin. hegyi@1: void broadcastActiveMaps(); hegyi@1: hegyi@1: /// Returns the active arcmap shown by a visualization property. hegyi@1: hegyi@1: /// \param prop is the property hegyi@1: ///that shows the requested map. hegyi@1: std::string getActiveArcMap(int prop); hegyi@1: hegyi@1: /// Returns the active nodemap shown by a visualization property. hegyi@1: hegyi@1: /// \param prop is the property hegyi@1: ///that shows the requested map. hegyi@1: std::string getActiveNodeMap(int prop); hegyi@1: hegyi@1: /// Returns the names of the arcmaps stored here. hegyi@1: std::vector getArcMapList(MapType type = ALL); hegyi@1: hegyi@1: /// Returns the names of the nodemaps stored here. hegyi@1: std::vector getNodeMapList(MapType type = ALL); hegyi@1: hegyi@1: ///returns \ref signal_prop to be able to connect functions to it hegyi@1: sigc::signal signal_prop_ch(); hegyi@1: hegyi@1: ///returns \ref signal_node_map to be able to connect functions to it hegyi@1: sigc::signal signal_node_map_ch(){return signal_node_map;}; hegyi@1: hegyi@1: ///returns \ref signal_arc_map to be able to connect functions to it hegyi@1: sigc::signal signal_arc_map_ch(){return signal_arc_map;}; hegyi@1: hegyi@1: ///returns \ref signal_map_win to be able to connect functions to it hegyi@1: sigc::signal signal_map_win_ch(){return signal_map_win;}; hegyi@1: hegyi@1: ///returns \ref signal_design_win to be able to connect functions to it hegyi@1: sigc::signal signal_design_win_ch(){return signal_design_win;}; hegyi@1: hegyi@1: void createNodeMap(const std::string& name, MapValue::Type type, hegyi@1: MapValue def_val); hegyi@1: void createArcMap(const std::string& name, MapValue::Type type, hegyi@1: MapValue def_val); hegyi@1: hegyi@1: ///returns \ref signal_background to be able to connect functions to it hegyi@1: sigc::signal signal_background_ch(){return signal_background;}; hegyi@1: hegyi@1: hegyi@1: ///Adds given map to storage. hegyi@1: hegyi@1: ///Emits \ref signal_prop if mapvalues have changed, and MapStorage gets to know it. hegyi@1: hegyi@1: ///If values in a map have changed, this function checks, whether it is displayed. hegyi@1: ///This check means searching the given mapname between active maps hegyi@1: ///(\ref active_nodemaps, \ref active_arcmaps). If it is there at a certain property, hegyi@1: ///it emits a signal with the property, where the gotten mapname was found. One signal hegyi@1: ///is emitted for each property displaying the given map. hegyi@1: ///\param itisarc whether the map an arcmap or nodemap hegyi@1: ///\param mapname name of map to visualize hegyi@1: void mapChanged(bool itisarc, std::string mapname); hegyi@1: hegyi@1: ///Read datas from the given filename. hegyi@1: int readFromFile(const std::string &); hegyi@1: hegyi@1: ///Save datas to the given filename. hegyi@1: void writeToFile(const std::string &); hegyi@1: hegyi@1: ///Deletes all datastructures stored here. hegyi@1: void clear(); hegyi@1: hegyi@1: void get_design_data(double &, double &, int &); hegyi@1: void set_attraction(double); hegyi@1: void set_propulsation(double); hegyi@1: void set_iteration(int); hegyi@1: hegyi@1: void redesign_data_changed(); hegyi@1: hegyi@1: XY getNodeCoords(Node n) const; hegyi@1: void setNodeCoords(Node n, XY c); hegyi@1: XY getArrowCoords(Arc e) const; hegyi@1: void setArrowCoords(Arc e, XY c); hegyi@1: hegyi@1: MapValue get(const std::string& name, Node node) const; hegyi@1: void set(const std::string& name, Node node, MapValue val); hegyi@1: MapValue get(const std::string& name, Arc arc) const; hegyi@1: void set(const std::string& name, Arc arc, MapValue val); hegyi@1: hegyi@1: const std::string& getFileName() const; hegyi@1: void setFileName(const std::string& fn); hegyi@1: hegyi@1: bool getModified() const; hegyi@1: void setModified(bool m = true); hegyi@1: hegyi@1: Node addNode(XY); hegyi@1: Arc addArc(Node, Node); hegyi@1: hegyi@1: NumericNodeMap& getNumericNodeMap(const std::string& name); hegyi@1: StringNodeMap& getStringNodeMap(const std::string& name); hegyi@1: NumericArcMap& getNumericArcMap(const std::string& name); hegyi@1: StringArcMap& getStringArcMap(const std::string& name); hegyi@1: hegyi@1: MapValueArcMap getArcMap(const std::string& name); hegyi@1: MapValueNodeMap getNodeMap(const std::string& name); hegyi@1: hegyi@1: int getLabel(Node) const; hegyi@1: int getLabel(Arc) const; hegyi@1: hegyi@1: GuiSectSaveDest getGUIDataSaveLocation(); hegyi@1: void setGUIDataSaveLocation(GuiSectSaveDest dest); hegyi@1: hegyi@1: MapSaveDest getNodeMapSaveDest(std::string name) const; hegyi@1: MapSaveDest getArcMapSaveDest(std::string name) const; hegyi@1: void setNodeMapSaveDest(std::string name, MapSaveDest dest); hegyi@1: void setArcMapSaveDest(std::string name, MapSaveDest dest); hegyi@1: hegyi@1: SpecMapSaveOpts::Dest getNodeCoordsSaveDest(); hegyi@1: SpecMapSaveOpts::Dest getArrowCoordsSaveDest(); hegyi@1: void setNodeCoordsSaveDest(SpecMapSaveOpts::Dest dest); hegyi@1: void setArrowCoordsSaveDest(SpecMapSaveOpts::Dest dest); hegyi@1: hegyi@1: SpecMapSaveOpts::MapNum getNodeCoordsSaveMapNum(); hegyi@1: SpecMapSaveOpts::MapNum getArrowCoordsSaveMapNum(); hegyi@1: void setNodeCoordsSaveMapNum(SpecMapSaveOpts::MapNum num); hegyi@1: void setArrowCoordsSaveMapNum(SpecMapSaveOpts::MapNum num); hegyi@1: hegyi@1: MapValue::Type getNodeMapElementType(std::string name) const; hegyi@1: MapValue::Type getArcMapElementType(std::string name) const; hegyi@1: hegyi@1: const NodeLabelMap& getNodeLabelMap(); hegyi@1: const ArcLabelMap& getArcLabelMap(); hegyi@1: hegyi@1: bool nodeMapExists(std::string name); hegyi@1: bool arcMapExists(std::string name); hegyi@1: hegyi@1: std::vector getArcMaps(MapType type = ALL); hegyi@1: std::vector getNodeMaps(MapType type = ALL); hegyi@1: hegyi@1: NodeCoordMap& getNodeCoordMap(); hegyi@1: ArrowCoordMap& getArrowCoordMap(); hegyi@1: hegyi@1: const std::string& getNodeCoordsOneMapName(); hegyi@1: const std::string& getNodeCoordsTwoMaps1Name(); hegyi@1: const std::string& getNodeCoordsTwoMaps2Name(); hegyi@1: void setNodeCoordsOneMapName(const std::string& name); hegyi@1: void setNodeCoordsTwoMaps1Name(const std::string& name); hegyi@1: void setNodeCoordsTwoMaps2Name(const std::string& name); hegyi@1: hegyi@1: const std::string& getArrowCoordsOneMapName(); hegyi@1: const std::string& getArrowCoordsTwoMaps1Name(); hegyi@1: const std::string& getArrowCoordsTwoMaps2Name(); hegyi@1: void setArrowCoordsOneMapName(const std::string& name); hegyi@1: void setArrowCoordsTwoMaps1Name(const std::string& name); hegyi@1: void setArrowCoordsTwoMaps2Name(const std::string& name); hegyi@1: hegyi@1: private: hegyi@1: ArcMapData* getArcMapData(std::string name) const; hegyi@1: NodeMapData* getNodeMapData(std::string name) const; hegyi@1: void readLGF( hegyi@1: const std::string& filename, hegyi@1: bool read_arc_label, hegyi@1: const std::vector& node_map_names, hegyi@1: const std::vector& arc_map_names, hegyi@1: const std::map& node_map_types, hegyi@1: const std::map& arc_map_types, hegyi@1: const std::string& node_coord_xmap_name, hegyi@1: const std::string& node_coord_ymap_name, hegyi@1: const std::string& arrow_coord_xmap_name, hegyi@1: const std::string& arrow_coord_ymap_name); hegyi@1: hegyi@1: public: hegyi@1: void exportDigraphToEPS(std::vector, std::string, std::string); hegyi@1: }; hegyi@1: hegyi@1: #endif //MAPSTORAGE_H