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