new_map_win.h
changeset 1 67188bd752db
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/new_map_win.h	Mon Jul 07 08:10:39 2008 -0500
     1.3 @@ -0,0 +1,160 @@
     1.4 +/* -*- C++ -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library
     1.7 + *
     1.8 + * Copyright (C) 2003-2006
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +#ifndef NEWMAPWIN_H
    1.23 +#define NEWMAPWIN_H
    1.24 +
    1.25 +#include <all_include.h>
    1.26 +#include <libgnomecanvasmm.h>
    1.27 +#include <libgnomecanvasmm/polygon.h>
    1.28 +#include <stack>
    1.29 +
    1.30 +class NoteBookTab;
    1.31 +
    1.32 +///Digraphical interface for node/arc map creation.
    1.33 +
    1.34 +///This class is responsible for creating a window,
    1.35 +///on which the parameters of a new map can be set.
    1.36 +class NewMapWin : public Gtk::Dialog
    1.37 +{
    1.38 +  ///The \ref NoteBookTab in which the new map has to be placed.
    1.39 +  NoteBookTab & mytab;
    1.40 +
    1.41 +  MapType map_type;
    1.42 +  Gtk::Label lblType;
    1.43 +  Gtk::ComboBoxText cbType;
    1.44 +
    1.45 +  Gtk::Label lblErrorMsg;
    1.46 +  void setErrorMsg(const Glib::ustring& msg);
    1.47 +
    1.48 +  std::vector<double>* evaluate_expr(const std::string polishform, bool itisarc);
    1.49 +
    1.50 +public:
    1.51 +
    1.52 +  ///Struct to be able to evaluate expressions.
    1.53 +
    1.54 +  ///Initial values of map elements can be given
    1.55 +  ///by numbers or by expressions. From expressions
    1.56 +  ///we build first a tree according to the priorities
    1.57 +  ///of operations in the expression. This is the data
    1.58 +  ///structure
    1.59 +  ///that can store one tree element.
    1.60 +  struct tree_node
    1.61 +  {
    1.62 +    ///Character stored in this tree element
    1.63 +    char ch;
    1.64 +    ///Left child of tree element.
    1.65 +    tree_node * left_child;
    1.66 +    ///Right child of tree element.
    1.67 +    tree_node * right_child;
    1.68 +  };
    1.69 +  
    1.70 +  ///Constructor of NewMapWin.
    1.71 +
    1.72 +  ///It creates the widgets shown in
    1.73 +  ///NewMapWin.
    1.74 +  NewMapWin(const std::string& title, NoteBookTab &, bool itisarc=true, bool arcnode=true, MapType type = ALL);
    1.75 +
    1.76 +  ///Callback function for OK button. It creates the map.
    1.77 +  
    1.78 +  ///This function determines whether the input is correct:
    1.79 +  ///the name of new map must not be already used, the expression
    1.80 +  ///that gives tha initial values of map elements has to be valid.
    1.81 +  ///If input is correct it creates and registrates the new map
    1.82 +  ///to the correct place. (\ref mytab)
    1.83 +  virtual void on_response(int response_id);
    1.84 +
    1.85 +  ///Close window if Esc key pressed.
    1.86 +  virtual bool closeIfEscapeIsPressed(GdkEventKey*);
    1.87 +
    1.88 +  ///Function that creates a tree from an appropriately manipulated string.
    1.89 +
    1.90 +  ///Tree is builded according to priorities of operations in expression given by string.
    1.91 +  ///Priorities are indicated in a vector that contains weights for each operation.
    1.92 +  ///\param to_tree string to build tree from
    1.93 +  ///\param weights weights (priorities)
    1.94 +  ///\param offset this function call is recursive. This parameter tells us,
    1.95 +  ///with which part of the string do we have to deal with.
    1.96 +  tree_node * weightedString2Tree(std::string to_tree, std::vector<unsigned int> & weights, int offset);
    1.97 +
    1.98 +  ///Function that creates a string from a tree by postorder reading.
    1.99 +
   1.100 +  ///This is the last step of creating polishform
   1.101 +  ///from a given expression string.
   1.102 +  ///\param root the root of the tree to read through
   1.103 +  std::string postOrder(tree_node * root);
   1.104 +
   1.105 +  ///From the given expression it creates expression given in polish form.
   1.106 +
   1.107 +  ///First it substitutes variables and numbers in the given expression.
   1.108 +  ///The substitutions will be one character long local variables.
   1.109 +  ///The substituted-substitution pair is registrated in \ref ch2var.
   1.110 +  ///After that it gives weights fo each character in substituted expression.
   1.111 +  ///Weights are calculated according to the priority of operations in expression.
   1.112 +  ///Then it creates tree (\ref tree_node) from the weighted string. (\ref weightedString2Tree)
   1.113 +  ///\param to_polish the string to turn into polish_form
   1.114 +  ///\param itisarc do we have to create an arcmap or a nodemap.
   1.115 +  ///It is important, because variables are maps and if expression
   1.116 +  ///citates a map that does not exists the expression is not valid.
   1.117 +  ///But to determine, whether the map exists we have to know where
   1.118 +  ///to search for it. And of course for a new arcmap only arcmaps can be serve with values. 
   1.119 +  std::string string2Polishform(std::string to_polish, bool itisarc);
   1.120 +
   1.121 +  ///Returns whether a string can be used as value in an expression.
   1.122 +
   1.123 +  ///The given string has to be either a mapname or a number. If it is a mapname
   1.124 +  ///we have to know whether it is an arcmap or a nodemap.
   1.125 +  ///\param variable the string about the function has to determine whether it is usable in expressions
   1.126 +  ///\param itisarc should the mapname be between arcmaps, or nodemaps
   1.127 +  bool validVariable(std::string variable, bool itisarc);
   1.128 +
   1.129 +  ///Deletes the whole tree created for translating string to polishform.
   1.130 + 
   1.131 +  ///\param root
   1.132 +  ///root of the tree
   1.133 +  void deleteTree(tree_node * root);
   1.134 +
   1.135 +  ///Dictionary of substitutions in expression.
   1.136 +
   1.137 +  ///Variables and numbers are substituted with one character long variables in expressions.
   1.138 +  ///This is the dictionary.
   1.139 +  std::map<char, std::string> ch2var;
   1.140 +
   1.141 +  ///Entry which gives us the name of new map.
   1.142 +  Gtk::Entry name;
   1.143 +
   1.144 +  ///Entry which gives us the initial values of elements of new map.
   1.145 +
   1.146 +  ///Initial value can be a number or an expression after that the
   1.147 +  ///initial value for each map element can be calculated.
   1.148 +  Gtk::Entry default_value;
   1.149 +
   1.150 +  ///GTK Designing object.
   1.151 +  Gtk::Table * table;
   1.152 +
   1.153 +  ///Information holder in window.
   1.154 +  Gtk::Label * label;
   1.155 +
   1.156 +  ///If selected, nodemap will be created.
   1.157 +  Gtk::RadioButton node;
   1.158 +
   1.159 +  ///If selected, arcmap will be created.
   1.160 +  Gtk::RadioButton arc;
   1.161 +};
   1.162 +
   1.163 +#endif //NEWMAPWIN_H