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