COIN-OR::LEMON - Graph Library

source: glemon/new_map_win.h

tip
Last change on this file was 1:67188bd752db, checked in by Peter Hegyi <hegyi@…>, 10 years ago

SVN revision 3500 made compilable with Lemon 1.0.

File size: 5.6 KB
Line 
1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 *
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
12 *
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
15 * purpose.
16 *
17 */
18
19#ifndef NEWMAPWIN_H
20#define NEWMAPWIN_H
21
22#include <all_include.h>
23#include <libgnomecanvasmm.h>
24#include <libgnomecanvasmm/polygon.h>
25#include <stack>
26
27class NoteBookTab;
28
29///Digraphical interface for node/arc map creation.
30
31///This class is responsible for creating a window,
32///on which the parameters of a new map can be set.
33class NewMapWin : public Gtk::Dialog
34{
35  ///The \ref NoteBookTab in which the new map has to be placed.
36  NoteBookTab & mytab;
37
38  MapType map_type;
39  Gtk::Label lblType;
40  Gtk::ComboBoxText cbType;
41
42  Gtk::Label lblErrorMsg;
43  void setErrorMsg(const Glib::ustring& msg);
44
45  std::vector<double>* evaluate_expr(const std::string polishform, bool itisarc);
46
47public:
48
49  ///Struct to be able to evaluate expressions.
50
51  ///Initial values of map elements can be given
52  ///by numbers or by expressions. From expressions
53  ///we build first a tree according to the priorities
54  ///of operations in the expression. This is the data
55  ///structure
56  ///that can store one tree element.
57  struct tree_node
58  {
59    ///Character stored in this tree element
60    char ch;
61    ///Left child of tree element.
62    tree_node * left_child;
63    ///Right child of tree element.
64    tree_node * right_child;
65  };
66 
67  ///Constructor of NewMapWin.
68
69  ///It creates the widgets shown in
70  ///NewMapWin.
71  NewMapWin(const std::string& title, NoteBookTab &, bool itisarc=true, bool arcnode=true, MapType type = ALL);
72
73  ///Callback function for OK button. It creates the map.
74 
75  ///This function determines whether the input is correct:
76  ///the name of new map must not be already used, the expression
77  ///that gives tha initial values of map elements has to be valid.
78  ///If input is correct it creates and registrates the new map
79  ///to the correct place. (\ref mytab)
80  virtual void on_response(int response_id);
81
82  ///Close window if Esc key pressed.
83  virtual bool closeIfEscapeIsPressed(GdkEventKey*);
84
85  ///Function that creates a tree from an appropriately manipulated string.
86
87  ///Tree is builded according to priorities of operations in expression given by string.
88  ///Priorities are indicated in a vector that contains weights for each operation.
89  ///\param to_tree string to build tree from
90  ///\param weights weights (priorities)
91  ///\param offset this function call is recursive. This parameter tells us,
92  ///with which part of the string do we have to deal with.
93  tree_node * weightedString2Tree(std::string to_tree, std::vector<unsigned int> & weights, int offset);
94
95  ///Function that creates a string from a tree by postorder reading.
96
97  ///This is the last step of creating polishform
98  ///from a given expression string.
99  ///\param root the root of the tree to read through
100  std::string postOrder(tree_node * root);
101
102  ///From the given expression it creates expression given in polish form.
103
104  ///First it substitutes variables and numbers in the given expression.
105  ///The substitutions will be one character long local variables.
106  ///The substituted-substitution pair is registrated in \ref ch2var.
107  ///After that it gives weights fo each character in substituted expression.
108  ///Weights are calculated according to the priority of operations in expression.
109  ///Then it creates tree (\ref tree_node) from the weighted string. (\ref weightedString2Tree)
110  ///\param to_polish the string to turn into polish_form
111  ///\param itisarc do we have to create an arcmap or a nodemap.
112  ///It is important, because variables are maps and if expression
113  ///citates a map that does not exists the expression is not valid.
114  ///But to determine, whether the map exists we have to know where
115  ///to search for it. And of course for a new arcmap only arcmaps can be serve with values.
116  std::string string2Polishform(std::string to_polish, bool itisarc);
117
118  ///Returns whether a string can be used as value in an expression.
119
120  ///The given string has to be either a mapname or a number. If it is a mapname
121  ///we have to know whether it is an arcmap or a nodemap.
122  ///\param variable the string about the function has to determine whether it is usable in expressions
123  ///\param itisarc should the mapname be between arcmaps, or nodemaps
124  bool validVariable(std::string variable, bool itisarc);
125
126  ///Deletes the whole tree created for translating string to polishform.
127 
128  ///\param root
129  ///root of the tree
130  void deleteTree(tree_node * root);
131
132  ///Dictionary of substitutions in expression.
133
134  ///Variables and numbers are substituted with one character long variables in expressions.
135  ///This is the dictionary.
136  std::map<char, std::string> ch2var;
137
138  ///Entry which gives us the name of new map.
139  Gtk::Entry name;
140
141  ///Entry which gives us the initial values of elements of new map.
142
143  ///Initial value can be a number or an expression after that the
144  ///initial value for each map element can be calculated.
145  Gtk::Entry default_value;
146
147  ///GTK Designing object.
148  Gtk::Table * table;
149
150  ///Information holder in window.
151  Gtk::Label * label;
152
153  ///If selected, nodemap will be created.
154  Gtk::RadioButton node;
155
156  ///If selected, arcmap will be created.
157  Gtk::RadioButton arc;
158};
159
160#endif //NEWMAPWIN_H
Note: See TracBrowser for help on using the repository browser.