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