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