9 #include <nbtab.h> |
9 #include <nbtab.h> |
10 #include <libgnomecanvasmm.h> |
10 #include <libgnomecanvasmm.h> |
11 #include <libgnomecanvasmm/polygon.h> |
11 #include <libgnomecanvasmm/polygon.h> |
12 #include <stack> |
12 #include <stack> |
13 |
13 |
|
14 ///Graphical interface for node/edge map creation. |
|
15 |
14 ///This class is responsible for creating a window, |
16 ///This class is responsible for creating a window, |
15 ///on which the parameters of a new map can be set. |
17 ///on which the parameters of a new map can be set. |
16 |
|
17 class NewMapWin : public Gtk::Dialog |
18 class NewMapWin : public Gtk::Dialog |
18 { |
19 { |
|
20 ///The \ref NoteBookTab in which the new map has to be placed. |
19 NoteBookTab & mytab; |
21 NoteBookTab & mytab; |
20 |
22 |
21 public: |
23 public: |
|
24 |
|
25 ///Struct to be able to evaluate expressions. |
|
26 |
|
27 ///Initial values of map elements can be given |
|
28 ///by numbers or by expressions. From expressions |
|
29 ///we build first a tree. This is the data structure |
|
30 ///that can store one tree element. |
22 struct tree_node |
31 struct tree_node |
23 { |
32 { |
|
33 ///Character stored in this tree element |
24 char ch; |
34 char ch; |
|
35 ///Left child of tree element. |
25 tree_node * left_child; |
36 tree_node * left_child; |
|
37 ///Right child of tree element. |
26 tree_node * right_child; |
38 tree_node * right_child; |
27 }; |
39 }; |
28 |
40 |
29 ///Constructor of NewMapWin creates the widgets shown in NewMapWin. |
41 ///Constructor of NewMapWin. |
|
42 |
|
43 ///It creates the widgets shown in |
|
44 ///NewMapWin. |
30 NewMapWin(const std::string& title, NoteBookTab &, bool itisedge=true, bool edgenode=true); |
45 NewMapWin(const std::string& title, NoteBookTab &, bool itisedge=true, bool edgenode=true); |
31 |
46 |
32 ///Signal on button is connected to this function, |
47 ///Callback function for OK button. It creates the map. |
33 ///Therefore this function determines whether to |
48 |
34 ///call the map/creatort function, and if yes, it |
49 ///This function determines whether the input is correct: |
35 //tells it the attributes.(name, default value) |
50 ///the name of new map must not be already used, the expression |
|
51 ///that gives tha initial values of map elements has to be valid. |
|
52 ///If input is correct it creates and registrates the new map |
|
53 ///to the correct place. (\ref mytab) |
36 virtual void on_response(int response_id); |
54 virtual void on_response(int response_id); |
37 |
55 |
|
56 ///Close window if Esc key pressed. |
38 virtual bool closeIfEscapeIsPressed(GdkEventKey*); |
57 virtual bool closeIfEscapeIsPressed(GdkEventKey*); |
39 |
58 |
40 ///Function that creates a tree from an appropriately manipulated string |
59 ///Function that creates a tree from an appropriately manipulated string. |
41 tree_node * weightedString2Tree(std::string, std::vector<unsigned int> &, int); |
|
42 |
60 |
43 ///Function that creates a string from a tree by postorder reading. |
61 ///Tree is builded according to priorities of operations in expression given by string. |
44 std::string postOrder(tree_node *); |
62 ///Priorities are indicated in a vector that contains weights for each operation. |
|
63 ///\param to_tree string to build tree from |
|
64 ///\param weights weights (priorities) |
|
65 ///\param offset this function call is recursive. This parameter tells us, |
|
66 ///with which part of the string do we have to deal with. |
|
67 tree_node * weightedString2Tree(std::string to_tree, std::vector<unsigned int> & weights, int offset); |
45 |
68 |
46 std::string string2Polishform(std::string, bool); |
69 ///Function that creates a string from a tree by postorder reading. |
47 |
70 |
48 bool validVariable(std::string, bool); |
71 ///This is the last step of creating polishform |
|
72 ///from a given expression string. |
|
73 ///\param root the root of the tree to read through |
|
74 std::string postOrder(tree_node * root); |
49 |
75 |
50 void deleteTree(tree_node *); |
76 ///From the given expression it creates expression given in polish form. |
51 |
77 |
|
78 ///First it substitutes variables and numbers in the given expression. |
|
79 ///The substitutions will be one character long local variables. |
|
80 ///The substituted-substitution pair is registrated in \ref ch2var. |
|
81 ///After that it gives weights fo each character in substituted expression. |
|
82 ///Weights are calculated according to the priority of operations in expression. |
|
83 ///Then it creates tree (\ref tree_node) from the weighted string. (\ref weightedString2Tree) |
|
84 ///\param to_polish the string to turn into polish_form |
|
85 ///\param itisedge do we have to create an edgemap or a nodemap. |
|
86 ///It is important, because variables are maps and if expression |
|
87 ///citates a map that does not exists the expression is not valid. |
|
88 ///But to determine, whether the map exists we have to know where |
|
89 ///to search for it. And of course for a new edgemap only edgemaps can be serve with values. |
|
90 std::string string2Polishform(std::string to_polish, bool itisedge); |
|
91 |
|
92 ///Returns whether a string can be used as value in an expression. |
|
93 |
|
94 ///The given string has to be either a mapname or a number. If it is a mapname |
|
95 ///we have to know whether it is an edgemap or a nodemap. |
|
96 ///\param variable the string about the function has to determine whether it is usable in expressions |
|
97 ///\param itisedge should the mapname be between edgemaps, or nodemaps |
|
98 bool validVariable(std::string variable, bool itisedge); |
|
99 |
|
100 ///Deletes the whole tree created for translating string to polishform. |
|
101 |
|
102 ///\param root |
|
103 ///root of the tree |
|
104 void deleteTree(tree_node * root); |
|
105 |
|
106 ///Dictionary of substitutions in expression. |
|
107 |
|
108 ///Variables and numbers are substituted with one character long variables in expressions. |
|
109 ///This is the dictionary. |
52 std::map<char, std::string> ch2var; |
110 std::map<char, std::string> ch2var; |
53 |
111 |
54 Gtk::Entry name, default_value; |
112 ///Entry which gives us the name of new map. |
|
113 Gtk::Entry name; |
55 |
114 |
|
115 ///Entry which gives us the initial values of elements of new map. |
|
116 |
|
117 ///Initial value can be a number or an expression after that the |
|
118 ///initial value for each map element can be calculated. |
|
119 Gtk::Entry default_value; |
|
120 |
|
121 ///GTK Designing object. |
56 Gtk::Table * table; |
122 Gtk::Table * table; |
|
123 |
|
124 ///Information holder in window. |
57 Gtk::Label * label; |
125 Gtk::Label * label; |
58 |
126 |
59 Gtk::RadioButton node, edge; |
127 ///If selected, nodemap will be created. |
|
128 Gtk::RadioButton node; |
|
129 |
|
130 ///If selected, edgemap will be created. |
|
131 Gtk::RadioButton edge; |
60 }; |
132 }; |
61 |
133 |
62 #endif //NEWMAPWIN_H |
134 #endif //NEWMAPWIN_H |