COIN-OR::LEMON - Graph Library

source: glemon-0.x/new_map_win.h @ 120:9166130d8d56

gui
Last change on this file since 120:9166130d8d56 was 120:9166130d8d56, checked in by Hegyi Péter, 18 years ago

Documentation of NewMapWin?.

File size: 4.8 KB
Line 
1// -*- C++ -*- //
2
3#ifndef NEWMAPWIN_H
4#define NEWMAPWIN_H
5
6class NewMapWin;
7
8#include <all_include.h>
9#include <nbtab.h>
10#include <libgnomecanvasmm.h>
11#include <libgnomecanvasmm/polygon.h>
12#include <stack>
13
14///Graphical interface for node/edge map creation.
15
16///This class is responsible for creating a window,
17///on which the parameters of a new map can be set.
18class NewMapWin : public Gtk::Dialog
19{
20  ///The \ref NoteBookTab in which the new map has to be placed.
21  NoteBookTab & mytab;
22
23public:
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.
31  struct tree_node
32  {
33    ///Character stored in this tree element
34    char ch;
35    ///Left child of tree element.
36    tree_node * left_child;
37    ///Right child of tree element.
38    tree_node * right_child;
39  };
40 
41  ///Constructor of NewMapWin.
42
43  ///It creates the widgets shown in
44  ///NewMapWin.
45  NewMapWin(const std::string& title, NoteBookTab &, bool itisedge=true, bool edgenode=true);
46
47  ///Callback function for OK button. It creates the map.
48 
49  ///This function determines whether the input is correct:
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)
54  virtual void on_response(int response_id);
55
56  ///Close window if Esc key pressed.
57  virtual bool closeIfEscapeIsPressed(GdkEventKey*);
58
59  ///Function that creates a tree from an appropriately manipulated string.
60
61  ///Tree is builded according to priorities of operations in expression given by string.
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);
68
69  ///Function that creates a string from a tree by postorder reading.
70
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);
75
76  ///From the given expression it creates expression given in polish form.
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.
110  std::map<char, std::string> ch2var;
111
112  ///Entry which gives us the name of new map.
113  Gtk::Entry name;
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.
122  Gtk::Table * table;
123
124  ///Information holder in window.
125  Gtk::Label * label;
126
127  ///If selected, nodemap will be created.
128  Gtk::RadioButton node;
129
130  ///If selected, edgemap will be created.
131  Gtk::RadioButton edge;
132};
133
134#endif //NEWMAPWIN_H
Note: See TracBrowser for help on using the repository browser.