alpar@174: /* -*- C++ -*- alpar@174: * alpar@174: * This file is a part of LEMON, a generic C++ optimization library alpar@174: * alpar@174: * Copyright (C) 2003-2006 alpar@174: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@174: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@174: * alpar@174: * Permission to use, modify and distribute this software is granted alpar@174: * provided that this copyright notice appears in all copies. For alpar@174: * precise terms see the accompanying LICENSE file. alpar@174: * alpar@174: * This software is provided "AS IS" with no warranty of any kind, alpar@174: * express or implied, and with no claim as to its suitability for any alpar@174: * purpose. alpar@174: * alpar@174: */ hegyi@42: hegyi@42: #ifndef NEWMAPWIN_H hegyi@42: #define NEWMAPWIN_H hegyi@42: hegyi@42: #include hegyi@42: #include hegyi@42: #include hegyi@88: #include hegyi@42: hegyi@194: class NoteBookTab; hegyi@194: hegyi@120: ///Graphical interface for node/edge map creation. hegyi@120: hegyi@42: ///This class is responsible for creating a window, hegyi@42: ///on which the parameters of a new map can be set. hegyi@90: class NewMapWin : public Gtk::Dialog hegyi@42: { hegyi@120: ///The \ref NoteBookTab in which the new map has to be placed. hegyi@96: NoteBookTab & mytab; hegyi@42: hegyi@88: public: hegyi@120: hegyi@120: ///Struct to be able to evaluate expressions. hegyi@120: hegyi@120: ///Initial values of map elements can be given hegyi@120: ///by numbers or by expressions. From expressions hegyi@121: ///we build first a tree according to the priorities hegyi@121: ///of operations in the expression. This is the data hegyi@121: ///structure hegyi@120: ///that can store one tree element. hegyi@88: struct tree_node hegyi@88: { hegyi@120: ///Character stored in this tree element hegyi@88: char ch; hegyi@120: ///Left child of tree element. hegyi@88: tree_node * left_child; hegyi@120: ///Right child of tree element. hegyi@88: tree_node * right_child; hegyi@88: }; hegyi@88: hegyi@120: ///Constructor of NewMapWin. hegyi@120: hegyi@120: ///It creates the widgets shown in hegyi@120: ///NewMapWin. hegyi@96: NewMapWin(const std::string& title, NoteBookTab &, bool itisedge=true, bool edgenode=true); hegyi@117: hegyi@120: ///Callback function for OK button. It creates the map. hegyi@120: hegyi@120: ///This function determines whether the input is correct: hegyi@120: ///the name of new map must not be already used, the expression hegyi@120: ///that gives tha initial values of map elements has to be valid. hegyi@120: ///If input is correct it creates and registrates the new map hegyi@120: ///to the correct place. (\ref mytab) hegyi@90: virtual void on_response(int response_id); hegyi@85: hegyi@120: ///Close window if Esc key pressed. hegyi@42: virtual bool closeIfEscapeIsPressed(GdkEventKey*); hegyi@42: hegyi@120: ///Function that creates a tree from an appropriately manipulated string. hegyi@88: hegyi@120: ///Tree is builded according to priorities of operations in expression given by string. hegyi@120: ///Priorities are indicated in a vector that contains weights for each operation. hegyi@120: ///\param to_tree string to build tree from hegyi@120: ///\param weights weights (priorities) hegyi@120: ///\param offset this function call is recursive. This parameter tells us, hegyi@120: ///with which part of the string do we have to deal with. hegyi@120: tree_node * weightedString2Tree(std::string to_tree, std::vector & weights, int offset); hegyi@88: hegyi@120: ///Function that creates a string from a tree by postorder reading. hegyi@88: hegyi@120: ///This is the last step of creating polishform hegyi@120: ///from a given expression string. hegyi@120: ///\param root the root of the tree to read through hegyi@120: std::string postOrder(tree_node * root); hegyi@88: hegyi@120: ///From the given expression it creates expression given in polish form. hegyi@117: hegyi@120: ///First it substitutes variables and numbers in the given expression. hegyi@120: ///The substitutions will be one character long local variables. hegyi@120: ///The substituted-substitution pair is registrated in \ref ch2var. hegyi@120: ///After that it gives weights fo each character in substituted expression. hegyi@120: ///Weights are calculated according to the priority of operations in expression. hegyi@120: ///Then it creates tree (\ref tree_node) from the weighted string. (\ref weightedString2Tree) hegyi@120: ///\param to_polish the string to turn into polish_form hegyi@120: ///\param itisedge do we have to create an edgemap or a nodemap. hegyi@120: ///It is important, because variables are maps and if expression hegyi@120: ///citates a map that does not exists the expression is not valid. hegyi@120: ///But to determine, whether the map exists we have to know where hegyi@120: ///to search for it. And of course for a new edgemap only edgemaps can be serve with values. hegyi@120: std::string string2Polishform(std::string to_polish, bool itisedge); hegyi@120: hegyi@120: ///Returns whether a string can be used as value in an expression. hegyi@120: hegyi@120: ///The given string has to be either a mapname or a number. If it is a mapname hegyi@120: ///we have to know whether it is an edgemap or a nodemap. hegyi@120: ///\param variable the string about the function has to determine whether it is usable in expressions hegyi@120: ///\param itisedge should the mapname be between edgemaps, or nodemaps hegyi@120: bool validVariable(std::string variable, bool itisedge); hegyi@120: hegyi@120: ///Deletes the whole tree created for translating string to polishform. hegyi@120: hegyi@120: ///\param root hegyi@120: ///root of the tree hegyi@120: void deleteTree(tree_node * root); hegyi@120: hegyi@120: ///Dictionary of substitutions in expression. hegyi@120: hegyi@120: ///Variables and numbers are substituted with one character long variables in expressions. hegyi@120: ///This is the dictionary. hegyi@88: std::map ch2var; hegyi@88: hegyi@120: ///Entry which gives us the name of new map. hegyi@120: Gtk::Entry name; hegyi@42: hegyi@120: ///Entry which gives us the initial values of elements of new map. hegyi@120: hegyi@120: ///Initial value can be a number or an expression after that the hegyi@120: ///initial value for each map element can be calculated. hegyi@120: Gtk::Entry default_value; hegyi@120: hegyi@120: ///GTK Designing object. hegyi@42: Gtk::Table * table; hegyi@120: hegyi@120: ///Information holder in window. hegyi@42: Gtk::Label * label; hegyi@42: hegyi@120: ///If selected, nodemap will be created. hegyi@120: Gtk::RadioButton node; hegyi@120: hegyi@120: ///If selected, edgemap will be created. hegyi@120: Gtk::RadioButton edge; hegyi@42: }; hegyi@42: hegyi@42: #endif //NEWMAPWIN_H