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