1.1 --- a/new_map_win.h Wed Jan 11 15:06:17 2006 +0000
1.2 +++ b/new_map_win.h Wed Jan 11 15:49:06 2006 +0000
1.3 @@ -11,52 +11,124 @@
1.4 #include <libgnomecanvasmm/polygon.h>
1.5 #include <stack>
1.6
1.7 +///Graphical interface for node/edge map creation.
1.8 +
1.9 ///This class is responsible for creating a window,
1.10 ///on which the parameters of a new map can be set.
1.11 -
1.12 class NewMapWin : public Gtk::Dialog
1.13 {
1.14 + ///The \ref NoteBookTab in which the new map has to be placed.
1.15 NoteBookTab & mytab;
1.16
1.17 public:
1.18 +
1.19 + ///Struct to be able to evaluate expressions.
1.20 +
1.21 + ///Initial values of map elements can be given
1.22 + ///by numbers or by expressions. From expressions
1.23 + ///we build first a tree. This is the data structure
1.24 + ///that can store one tree element.
1.25 struct tree_node
1.26 {
1.27 + ///Character stored in this tree element
1.28 char ch;
1.29 + ///Left child of tree element.
1.30 tree_node * left_child;
1.31 + ///Right child of tree element.
1.32 tree_node * right_child;
1.33 };
1.34
1.35 - ///Constructor of NewMapWin creates the widgets shown in NewMapWin.
1.36 + ///Constructor of NewMapWin.
1.37 +
1.38 + ///It creates the widgets shown in
1.39 + ///NewMapWin.
1.40 NewMapWin(const std::string& title, NoteBookTab &, bool itisedge=true, bool edgenode=true);
1.41
1.42 - ///Signal on button is connected to this function,
1.43 - ///Therefore this function determines whether to
1.44 - ///call the map/creatort function, and if yes, it
1.45 - //tells it the attributes.(name, default value)
1.46 + ///Callback function for OK button. It creates the map.
1.47 +
1.48 + ///This function determines whether the input is correct:
1.49 + ///the name of new map must not be already used, the expression
1.50 + ///that gives tha initial values of map elements has to be valid.
1.51 + ///If input is correct it creates and registrates the new map
1.52 + ///to the correct place. (\ref mytab)
1.53 virtual void on_response(int response_id);
1.54
1.55 + ///Close window if Esc key pressed.
1.56 virtual bool closeIfEscapeIsPressed(GdkEventKey*);
1.57
1.58 - ///Function that creates a tree from an appropriately manipulated string
1.59 - tree_node * weightedString2Tree(std::string, std::vector<unsigned int> &, int);
1.60 + ///Function that creates a tree from an appropriately manipulated string.
1.61
1.62 - ///Function that creates a string from a tree by postorder reading.
1.63 - std::string postOrder(tree_node *);
1.64 + ///Tree is builded according to priorities of operations in expression given by string.
1.65 + ///Priorities are indicated in a vector that contains weights for each operation.
1.66 + ///\param to_tree string to build tree from
1.67 + ///\param weights weights (priorities)
1.68 + ///\param offset this function call is recursive. This parameter tells us,
1.69 + ///with which part of the string do we have to deal with.
1.70 + tree_node * weightedString2Tree(std::string to_tree, std::vector<unsigned int> & weights, int offset);
1.71
1.72 - std::string string2Polishform(std::string, bool);
1.73 + ///Function that creates a string from a tree by postorder reading.
1.74
1.75 - bool validVariable(std::string, bool);
1.76 + ///This is the last step of creating polishform
1.77 + ///from a given expression string.
1.78 + ///\param root the root of the tree to read through
1.79 + std::string postOrder(tree_node * root);
1.80
1.81 - void deleteTree(tree_node *);
1.82 + ///From the given expression it creates expression given in polish form.
1.83
1.84 + ///First it substitutes variables and numbers in the given expression.
1.85 + ///The substitutions will be one character long local variables.
1.86 + ///The substituted-substitution pair is registrated in \ref ch2var.
1.87 + ///After that it gives weights fo each character in substituted expression.
1.88 + ///Weights are calculated according to the priority of operations in expression.
1.89 + ///Then it creates tree (\ref tree_node) from the weighted string. (\ref weightedString2Tree)
1.90 + ///\param to_polish the string to turn into polish_form
1.91 + ///\param itisedge do we have to create an edgemap or a nodemap.
1.92 + ///It is important, because variables are maps and if expression
1.93 + ///citates a map that does not exists the expression is not valid.
1.94 + ///But to determine, whether the map exists we have to know where
1.95 + ///to search for it. And of course for a new edgemap only edgemaps can be serve with values.
1.96 + std::string string2Polishform(std::string to_polish, bool itisedge);
1.97 +
1.98 + ///Returns whether a string can be used as value in an expression.
1.99 +
1.100 + ///The given string has to be either a mapname or a number. If it is a mapname
1.101 + ///we have to know whether it is an edgemap or a nodemap.
1.102 + ///\param variable the string about the function has to determine whether it is usable in expressions
1.103 + ///\param itisedge should the mapname be between edgemaps, or nodemaps
1.104 + bool validVariable(std::string variable, bool itisedge);
1.105 +
1.106 + ///Deletes the whole tree created for translating string to polishform.
1.107 +
1.108 + ///\param root
1.109 + ///root of the tree
1.110 + void deleteTree(tree_node * root);
1.111 +
1.112 + ///Dictionary of substitutions in expression.
1.113 +
1.114 + ///Variables and numbers are substituted with one character long variables in expressions.
1.115 + ///This is the dictionary.
1.116 std::map<char, std::string> ch2var;
1.117
1.118 - Gtk::Entry name, default_value;
1.119 + ///Entry which gives us the name of new map.
1.120 + Gtk::Entry name;
1.121
1.122 + ///Entry which gives us the initial values of elements of new map.
1.123 +
1.124 + ///Initial value can be a number or an expression after that the
1.125 + ///initial value for each map element can be calculated.
1.126 + Gtk::Entry default_value;
1.127 +
1.128 + ///GTK Designing object.
1.129 Gtk::Table * table;
1.130 +
1.131 + ///Information holder in window.
1.132 Gtk::Label * label;
1.133
1.134 - Gtk::RadioButton node, edge;
1.135 + ///If selected, nodemap will be created.
1.136 + Gtk::RadioButton node;
1.137 +
1.138 + ///If selected, edgemap will be created.
1.139 + Gtk::RadioButton edge;
1.140 };
1.141
1.142 #endif //NEWMAPWIN_H