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