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