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 NEWMAPWIN_H hegyi@1: #define NEWMAPWIN_H hegyi@1: hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: hegyi@1: class NoteBookTab; hegyi@1: hegyi@1: ///Digraphical interface for node/arc map creation. hegyi@1: hegyi@1: ///This class is responsible for creating a window, hegyi@1: ///on which the parameters of a new map can be set. hegyi@1: class NewMapWin : public Gtk::Dialog hegyi@1: { hegyi@1: ///The \ref NoteBookTab in which the new map has to be placed. hegyi@1: NoteBookTab & mytab; hegyi@1: hegyi@1: MapType map_type; hegyi@1: Gtk::Label lblType; hegyi@1: Gtk::ComboBoxText cbType; hegyi@1: hegyi@1: Gtk::Label lblErrorMsg; hegyi@1: void setErrorMsg(const Glib::ustring& msg); hegyi@1: hegyi@1: std::vector* evaluate_expr(const std::string polishform, bool itisarc); hegyi@1: hegyi@1: public: hegyi@1: hegyi@1: ///Struct to be able to evaluate expressions. hegyi@1: hegyi@1: ///Initial values of map elements can be given hegyi@1: ///by numbers or by expressions. From expressions hegyi@1: ///we build first a tree according to the priorities hegyi@1: ///of operations in the expression. This is the data hegyi@1: ///structure hegyi@1: ///that can store one tree element. hegyi@1: struct tree_node hegyi@1: { hegyi@1: ///Character stored in this tree element hegyi@1: char ch; hegyi@1: ///Left child of tree element. hegyi@1: tree_node * left_child; hegyi@1: ///Right child of tree element. hegyi@1: tree_node * right_child; hegyi@1: }; hegyi@1: hegyi@1: ///Constructor of NewMapWin. hegyi@1: hegyi@1: ///It creates the widgets shown in hegyi@1: ///NewMapWin. hegyi@1: NewMapWin(const std::string& title, NoteBookTab &, bool itisarc=true, bool arcnode=true, MapType type = ALL); hegyi@1: hegyi@1: ///Callback function for OK button. It creates the map. hegyi@1: hegyi@1: ///This function determines whether the input is correct: hegyi@1: ///the name of new map must not be already used, the expression hegyi@1: ///that gives tha initial values of map elements has to be valid. hegyi@1: ///If input is correct it creates and registrates the new map hegyi@1: ///to the correct place. (\ref mytab) hegyi@1: virtual void on_response(int response_id); hegyi@1: hegyi@1: ///Close window if Esc key pressed. hegyi@1: virtual bool closeIfEscapeIsPressed(GdkEventKey*); hegyi@1: hegyi@1: ///Function that creates a tree from an appropriately manipulated string. hegyi@1: hegyi@1: ///Tree is builded according to priorities of operations in expression given by string. hegyi@1: ///Priorities are indicated in a vector that contains weights for each operation. hegyi@1: ///\param to_tree string to build tree from hegyi@1: ///\param weights weights (priorities) hegyi@1: ///\param offset this function call is recursive. This parameter tells us, hegyi@1: ///with which part of the string do we have to deal with. hegyi@1: tree_node * weightedString2Tree(std::string to_tree, std::vector & weights, int offset); hegyi@1: hegyi@1: ///Function that creates a string from a tree by postorder reading. hegyi@1: hegyi@1: ///This is the last step of creating polishform hegyi@1: ///from a given expression string. hegyi@1: ///\param root the root of the tree to read through hegyi@1: std::string postOrder(tree_node * root); hegyi@1: hegyi@1: ///From the given expression it creates expression given in polish form. hegyi@1: hegyi@1: ///First it substitutes variables and numbers in the given expression. hegyi@1: ///The substitutions will be one character long local variables. hegyi@1: ///The substituted-substitution pair is registrated in \ref ch2var. hegyi@1: ///After that it gives weights fo each character in substituted expression. hegyi@1: ///Weights are calculated according to the priority of operations in expression. hegyi@1: ///Then it creates tree (\ref tree_node) from the weighted string. (\ref weightedString2Tree) hegyi@1: ///\param to_polish the string to turn into polish_form hegyi@1: ///\param itisarc do we have to create an arcmap or a nodemap. hegyi@1: ///It is important, because variables are maps and if expression hegyi@1: ///citates a map that does not exists the expression is not valid. hegyi@1: ///But to determine, whether the map exists we have to know where hegyi@1: ///to search for it. And of course for a new arcmap only arcmaps can be serve with values. hegyi@1: std::string string2Polishform(std::string to_polish, bool itisarc); hegyi@1: hegyi@1: ///Returns whether a string can be used as value in an expression. hegyi@1: hegyi@1: ///The given string has to be either a mapname or a number. If it is a mapname hegyi@1: ///we have to know whether it is an arcmap or a nodemap. hegyi@1: ///\param variable the string about the function has to determine whether it is usable in expressions hegyi@1: ///\param itisarc should the mapname be between arcmaps, or nodemaps hegyi@1: bool validVariable(std::string variable, bool itisarc); hegyi@1: hegyi@1: ///Deletes the whole tree created for translating string to polishform. hegyi@1: hegyi@1: ///\param root hegyi@1: ///root of the tree hegyi@1: void deleteTree(tree_node * root); hegyi@1: hegyi@1: ///Dictionary of substitutions in expression. hegyi@1: hegyi@1: ///Variables and numbers are substituted with one character long variables in expressions. hegyi@1: ///This is the dictionary. hegyi@1: std::map ch2var; hegyi@1: hegyi@1: ///Entry which gives us the name of new map. hegyi@1: Gtk::Entry name; hegyi@1: hegyi@1: ///Entry which gives us the initial values of elements of new map. hegyi@1: hegyi@1: ///Initial value can be a number or an expression after that the hegyi@1: ///initial value for each map element can be calculated. hegyi@1: Gtk::Entry default_value; hegyi@1: hegyi@1: ///GTK Designing object. hegyi@1: Gtk::Table * table; hegyi@1: hegyi@1: ///Information holder in window. hegyi@1: Gtk::Label * label; hegyi@1: hegyi@1: ///If selected, nodemap will be created. hegyi@1: Gtk::RadioButton node; hegyi@1: hegyi@1: ///If selected, arcmap will be created. hegyi@1: Gtk::RadioButton arc; hegyi@1: }; hegyi@1: hegyi@1: #endif //NEWMAPWIN_H