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