COIN-OR::LEMON - Graph Library

Changeset 1823:cb082cdf3667 in lemon-0.x


Ignore:
Timestamp:
11/21/05 19:03:20 (18 years ago)
Author:
Hegyi Péter
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2373
Message:

NewMapWin? has become Dialog instead of Window. Therefore it is created dynamically, when there is need for it, instead of keeping one instance in memory. This solution is slower, but more correct than before.

Location:
gui
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • gui/Doxyfile

    r1736 r1823  
    2626INLINE_INHERITED_MEMB  = NO
    2727FULL_PATH_NAMES        = YES
    28 STRIP_FROM_PATH        = /home/alpar/projects/ETIK/hugo/gui/
     28STRIP_FROM_PATH        = .
    2929STRIP_FROM_INC_PATH    =
    3030SHORT_NAMES            = NO
     
    8383# configuration options related to the input files
    8484#---------------------------------------------------------------------------
    85 INPUT                  = /home/alpar/projects/ETIK/hugo/gui
     85INPUT                  = .
    8686FILE_PATTERNS          = *.c \
    8787                         *.cc \
  • gui/main_win.cc

    r1777 r1823  
    33
    44MainWin::MainWin() :
    5   newmapwin("Creating new map", gd_canvas),
    6   mapwin("Map Setup", mapstorage, gd_canvas, newmapwin),
     5  mapwin("Map Setup", mapstorage, gd_canvas),
    76  gd_canvas(mapstorage, mapwin, (Gtk::Window *)this)
    87{
     
    122121
    123122  ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
    124       sigc::mem_fun ( this->newmapwin, &NewMapWin::show ) );
     123      sigc::mem_fun (new NewMapWin("NewMapWin", gd_canvas), &NewMapWin::show ) );
    125124
    126125  uim=Gtk::UIManager::create();
  • gui/main_win.h

    r1733 r1823  
    2626
    2727protected:
    28   ///We need to store newmapwin, to be able to set the appropriate values for properties of new map.
    29   NewMapWin newmapwin;
    30 
    3128  ///Window of map-showing setup. Its type is \ref MapWin
    3229  MapWin mapwin;
  • gui/map_win.cc

    r1737 r1823  
    1111}
    1212
    13 MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc, NewMapWin & newmapwin):gdc(grdispc),ms(mapst), nmw(newmapwin)
     13MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst)
    1414{
    1515  set_title(title);
     
    2424  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
    2525  {
    26     e_combo_array[i]=new MapSelector(gdc, ms, nmw, i, true);
     26    e_combo_array[i]=new MapSelector(gdc, ms, i, true);
    2727
    2828    (*table).attach((*(e_combo_array[i])),0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
     
    4141  for(int i=0;i<NODE_PROPERTY_NUM;i++)
    4242  {
    43     n_combo_array[i]=new MapSelector(gdc, ms, nmw, i, false);
     43    n_combo_array[i]=new MapSelector(gdc, ms, i, false);
    4444
    4545    (*table).attach((*(n_combo_array[i])),0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
  • gui/map_win.h

    r1819 r1823  
    2525    ///The \ref MapStorage in which the visualizable maps are stored
    2626    MapStorage & ms;
    27     NewMapWin & nmw;
    2827
    2928    int id;
     
    4948  public:
    5049
    51     MapSelector(GraphDisplayerCanvas &, MapStorage &, NewMapWin &, int, bool);
     50    MapSelector(GraphDisplayerCanvas &, MapStorage &, int, bool);
    5251
    5352    void update_list();
     
    8382  MapStorage & ms;
    8483
    85   NewMapWin & nmw;
    86 
    8784  Gtk::Table * table;
    8885 
     
    9592public:
    9693  ///Constructor of MapWin creates the widgets shown in MapWin.
    97   MapWin(const std::string& title, MapStorage &, GraphDisplayerCanvas &, NewMapWin &);
     94  MapWin(const std::string& title, MapStorage &, GraphDisplayerCanvas &);
    9895
    9996  ///This function is created to set the appropriate maps on the newly created node
  • gui/mw-mapselector.cc

    r1819 r1823  
    11#include "map_win.h"
    22
    3 MapWin::MapSelector::MapSelector(GraphDisplayerCanvas & grdispc, MapStorage & mapst, NewMapWin & newmapw, int identifier, bool edge):gdc(grdispc),ms(mapst),nmw(newmapw),id(identifier),itisedge(edge),default_state(true),set_new_map(false),node_to_update(INVALID),edge_to_update(INVALID)
     3MapWin::MapSelector::MapSelector(GraphDisplayerCanvas & grdispc, MapStorage & mapst, int identifier, bool edge):gdc(grdispc),ms(mapst),id(identifier),itisedge(edge),default_state(true),set_new_map(false),node_to_update(INVALID),edge_to_update(INVALID)
    44{
    55  update_list();
     
    5151{
    5252  set_new_map=true;
    53   nmw.showByPreChoose(itisedge);
     53  (new NewMapWin("NewMapWin", gdc, itisedge, false))->run();
    5454}
    5555
  • gui/new_map_win.cc

    r1819 r1823  
    1010}
    1111
    12 NewMapWin::NewMapWin(const std::string& title, GraphDisplayerCanvas & grdispc):gdc(grdispc),node("Create NodeMap"),edge("Create EdgeMap")
    13 {
    14   set_title(title);
     12NewMapWin::NewMapWin(const std::string& title, GraphDisplayerCanvas & grdispc, bool itisedge, bool edgenode):Gtk::Dialog(title, true, true),gdc(grdispc),node("Create NodeMap"),edge("Create EdgeMap")
     13{
    1514  set_default_size(200, 50);
    1615
    1716  signal_key_press_event().connect(sigc::mem_fun(*this, &NewMapWin::closeIfEscapeIsPressed));
    1817
     18  Gtk::VBox * vbox=get_vbox();
    1919
    2020  //entries
     
    3838  Gtk::RadioButton::Group group = node.get_group();
    3939  edge.set_group(group);
    40 
    41   (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    42   (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    43 
    44   vbox.pack_start(*table);
     40 
     41  if(edgenode)
     42    {
     43      (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
     44      (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
     45    }
     46  else
     47    {
     48      if(itisedge)
     49        {
     50          edge.set_active();
     51        }
     52      else
     53        {
     54          node.set_active();
     55        }
     56    }
     57
     58  vbox->pack_start(*table);
    4559
    4660  //OK button
    47   button=new Gtk::Button("OK");
    48 
    49   button->signal_clicked().connect
    50     (
    51      sigc::mem_fun(*this, &NewMapWin::buttonPressed)
    52     );
    53 
    54 
    55   vbox.pack_start(*button);
    56 
    57   add(vbox);
     61  add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
    5862
    5963  show_all_children();
     
    6165}
    6266
    63 void NewMapWin::showByPreChoose(bool itisedge)
    64 {
    65   if(itisedge)
    66     {
    67       edge.set_active();
    68     }
    69   else
    70     {
    71       node.set_active();
    72     }
    73   node.hide();
    74   edge.hide();
    75   show();
    76 }
    77 
    78 void NewMapWin::buttonPressed()
    79 {
    80   double def_val=0;
    81 
    82   //get and formulate text
    83   std::string def_val_str=default_value.get_text();
    84   std::string polishform=string2Polishform(def_val_str,edge.get_active());
    85 
    86   //get name of text
    87   std::string mapname=name.get_text();
    88 
    89   if(!mapname.empty()&&!polishform.empty())
    90     {
    91       int abortion=0;
    92       if(edge.get_active())
    93         {
    94           //create the new map
    95           Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (gdc.mapstorage.graph);
    96 
    97           std::stack<double> polishstack;
     67void NewMapWin::on_response(int response_id)
     68{
     69  if(response_id==Gtk::RESPONSE_OK)
     70    {
     71      double def_val=0;
     72
     73      //get and formulate text
     74      std::string def_val_str=default_value.get_text();
     75      std::string polishform=string2Polishform(def_val_str,edge.get_active());
     76
     77      //get name of text
     78      std::string mapname=name.get_text();
     79
     80      if(!mapname.empty()&&!polishform.empty())
     81        {
     82          int abortion=0;
     83          if(edge.get_active())
     84            {
     85              //create the new map
     86              Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (gdc.mapstorage.graph);
     87
     88              std::stack<double> polishstack;
    9889 
    99           for(EdgeIt k(gdc.mapstorage.graph); k!=INVALID; ++k)
    100             {
    101               for(int i=0;i<(int)polishform.size();i++)
    102                 {
    103                   double op1, op2;
    104                   bool operation=true;
    105                   switch(polishform[i])
     90              for(EdgeIt k(gdc.mapstorage.graph); k!=INVALID; ++k)
     91                {
     92                  for(int i=0;i<(int)polishform.size();i++)
    10693                    {
    107                     case '+':
    108                     case '-':
    109                     case '/':
    110                     case '*':
    111                       op1=polishstack.top();
    112                       polishstack.pop();
    113                       op2=polishstack.top();
    114                       polishstack.pop();
    115                       break;
    116                     default:
    117                       //substitute variable
    118                       std::map< std::string,Graph::EdgeMap<double> * > ems=gdc.mapstorage.edgemap_storage;
    119                       bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
    120                       if(itisvar)
    121                         {
    122                           polishstack.push( (*(gdc.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
    123                         }
    124                       else
    125                         {
    126                           char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())];
    127                           for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++)
    128                             {
    129                               def_val_ch[j]=ch2var[ polishform[i] ][j];
    130                             }
    131                           polishstack.push(atof(def_val_ch));
    132                         }
    133                       operation=false;
    134                       break;
    135                     }
    136                   if(operation)
    137                     {
    138                       double res;
     94                      double op1, op2;
     95                      bool operation=true;
    13996                      switch(polishform[i])
    14097                        {
    14198                        case '+':
    142                           res=op1+op2;
    143                           break;
    14499                        case '-':
    145                           res=op2-op1;
    146                           break;
    147100                        case '/':
    148                           res=op2/op1;
    149                           break;
    150101                        case '*':
    151                           res=op1*op2;
     102                          op1=polishstack.top();
     103                          polishstack.pop();
     104                          op2=polishstack.top();
     105                          polishstack.pop();
    152106                          break;
    153107                        default:
    154                           std::cout << "How could we get here?" << std::endl;
     108                          //substitute variable
     109                          std::map< std::string,Graph::EdgeMap<double> * > ems=gdc.mapstorage.edgemap_storage;
     110                          bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
     111                          if(itisvar)
     112                            {
     113                              polishstack.push( (*(gdc.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
     114                            }
     115                          else
     116                            {
     117                              char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())];
     118                              for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++)
     119                                {
     120                                  def_val_ch[j]=ch2var[ polishform[i] ][j];
     121                                }
     122                              polishstack.push(atof(def_val_ch));
     123                            }
     124                          operation=false;
    155125                          break;
    156126                        }
    157                       polishstack.push(res);
     127                      if(operation)
     128                        {
     129                          double res;
     130                          switch(polishform[i])
     131                            {
     132                            case '+':
     133                              res=op1+op2;
     134                              break;
     135                            case '-':
     136                              res=op2-op1;
     137                              break;
     138                            case '/':
     139                              res=op2/op1;
     140                              break;
     141                            case '*':
     142                              res=op1*op2;
     143                              break;
     144                            default:
     145                              std::cout << "How could we get here?" << std::endl;
     146                              break;
     147                            }
     148                          polishstack.push(res);
     149                        }
    158150                    }
    159                 }
    160               (*emptr)[k]=polishstack.top();
    161             }
    162 
    163           //if addition was not successful addEdgeMap returns one.
    164           //cause can be that there is already a map named like the new one
    165           if(gdc.mapstorage.addEdgeMap(mapname, emptr, def_val))
    166             {
    167               abortion=1;
    168             }
    169 
    170           //add it to the list of the displayable maps
    171           gdc.mapwin.registerNewEdgeMap(mapname);
    172 
    173           //display it
    174           gdc.changeEdgeText(mapname);
    175         }
    176       else //!edge.get_active()
    177         {
    178           //create the new map
    179           Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (gdc.mapstorage.graph);
    180 
    181           std::stack<double> polishstack;
     151                  (*emptr)[k]=polishstack.top();
     152                }
     153
     154              //if addition was not successful addEdgeMap returns one.
     155              //cause can be that there is already a map named like the new one
     156              if(gdc.mapstorage.addEdgeMap(mapname, emptr, def_val))
     157                {
     158                  abortion=1;
     159                }
     160
     161              //add it to the list of the displayable maps
     162              gdc.mapwin.registerNewEdgeMap(mapname);
     163
     164              //display it
     165              gdc.changeEdgeText(mapname);
     166            }
     167          else //!edge.get_active()
     168            {
     169              //create the new map
     170              Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (gdc.mapstorage.graph);
     171
     172              std::stack<double> polishstack;
    182173 
    183           for(NodeIt k(gdc.mapstorage.graph); k!=INVALID; ++k)
    184             {
    185               for(int i=0;i<(int)polishform.size();i++)
    186                 {
    187                   double op1, op2;
    188                   bool operation=true;
    189                   switch(polishform[i])
     174              for(NodeIt k(gdc.mapstorage.graph); k!=INVALID; ++k)
     175                {
     176                  for(int i=0;i<(int)polishform.size();i++)
    190177                    {
    191                     case '+':
    192                     case '-':
    193                     case '/':
    194                     case '*':
    195                       op1=polishstack.top();
    196                       polishstack.pop();
    197                       op2=polishstack.top();
    198                       polishstack.pop();
    199                       break;
    200                     default:
    201                       std::map< std::string,Graph::NodeMap<double> * > nms=gdc.mapstorage.nodemap_storage;
    202                       bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
    203                       if(itisvar)
    204                         {
    205                           polishstack.push( (*(gdc.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
    206                         }
    207                       else
    208                         {
    209                           char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())];
    210                           for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++)
    211                             {
    212                               def_val_ch[j]=ch2var[ polishform[i] ][j];
    213                             }
    214                           polishstack.push(atof(def_val_ch));
    215                         }
    216                       operation=false;
    217                       break;
    218                     }
    219                   if(operation)
    220                     {
    221                       double res;
     178                      double op1, op2;
     179                      bool operation=true;
    222180                      switch(polishform[i])
    223181                        {
    224182                        case '+':
    225                           res=op1+op2;
    226                           break;
    227183                        case '-':
    228                           res=op2-op1;
    229                           break;
    230184                        case '/':
    231                           res=op2/op1;
    232                           break;
    233185                        case '*':
    234                           res=op1*op2;
     186                          op1=polishstack.top();
     187                          polishstack.pop();
     188                          op2=polishstack.top();
     189                          polishstack.pop();
    235190                          break;
    236191                        default:
    237                           std::cout << "How could we get here?" << std::endl;
     192                          std::map< std::string,Graph::NodeMap<double> * > nms=gdc.mapstorage.nodemap_storage;
     193                          bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
     194                          if(itisvar)
     195                            {
     196                              polishstack.push( (*(gdc.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
     197                            }
     198                          else
     199                            {
     200                              char * def_val_ch=new char [(int)(ch2var[ polishform[i] ].length())];
     201                              for(int j=0;j<(int)(ch2var[ polishform[i] ].length());j++)
     202                                {
     203                                  def_val_ch[j]=ch2var[ polishform[i] ][j];
     204                                }
     205                              polishstack.push(atof(def_val_ch));
     206                            }
     207                          operation=false;
    238208                          break;
    239209                        }
    240                       polishstack.push(res);
     210                      if(operation)
     211                        {
     212                          double res;
     213                          switch(polishform[i])
     214                            {
     215                            case '+':
     216                              res=op1+op2;
     217                              break;
     218                            case '-':
     219                              res=op2-op1;
     220                              break;
     221                            case '/':
     222                              res=op2/op1;
     223                              break;
     224                            case '*':
     225                              res=op1*op2;
     226                              break;
     227                            default:
     228                              std::cout << "How could we get here?" << std::endl;
     229                              break;
     230                            }
     231                          polishstack.push(res);
     232                        }
    241233                    }
    242                 }
    243               (*emptr)[k]=polishstack.top();
    244             }
    245 
    246           //if addition was not successful addNodeMap returns one.
    247           //cause can be that there is already a map named like the new one
    248           if(gdc.mapstorage.addNodeMap(mapname,emptr, def_val))
    249             {
    250               abortion=1;
    251             }
    252 
    253           //add it to the list of the displayable maps
    254           gdc.mapwin.registerNewNodeMap(mapname);
    255 
    256           //display it
    257           gdc.changeNodeText(mapname);
    258         }
    259       if(!abortion)
    260         {
    261           name.set_text("");
    262           default_value.set_text("0");
    263           edge.show();
    264           node.show();
    265           hide();
    266         }
    267     }
    268 }
     234                  (*emptr)[k]=polishstack.top();
     235                }
     236
     237              //if addition was not successful addNodeMap returns one.
     238              //cause can be that there is already a map named like the new one
     239              if(gdc.mapstorage.addNodeMap(mapname,emptr, def_val))
     240                {
     241                  abortion=1;
     242                }
     243
     244              //add it to the list of the displayable maps
     245              gdc.mapwin.registerNewNodeMap(mapname);
     246
     247              //display it
     248              //gdc.changeNodeText(mapname);
     249            }
     250          if(!abortion)
     251            {
     252              name.set_text("");
     253              default_value.set_text("0");
     254              edge.show();
     255              node.show();
     256              hide();
     257            }
     258        }
     259    }
     260}
     261
    269262
    270263std::string NewMapWin::string2Polishform(std::string rawcommand, bool itisedge)
  • gui/new_map_win.h

    r1814 r1823  
    1515///on which the parameters of a new map can be set.
    1616
    17 class NewMapWin : public Gtk::Window
     17class NewMapWin : public Gtk::Dialog
    1818{
    1919  ///The \ref GraphDisplayerCanvas on which the graph will be drawn.
     
    3232 
    3333  ///Constructor of NewMapWin creates the widgets shown in NewMapWin.
    34   NewMapWin(const std::string& title, GraphDisplayerCanvas &);
    35 
     34  NewMapWin(const std::string& title, GraphDisplayerCanvas &, bool itisedge=true, bool edgenode=true);
    3635 
    3736  ///Signal on button is connected to this function,
     
    3938  ///call the map/creatort function, and if yes, it
    4039  //tells it the attributes.(name, default value)
    41   virtual void buttonPressed();
    42  
    43   virtual void showByPreChoose(bool);
     40  virtual void on_response(int response_id);
    4441
    4542  virtual bool closeIfEscapeIsPressed(GdkEventKey*);
     
    5956  Gtk::Entry name, default_value;
    6057
    61   Gtk::VBox vbox;
    62 
    63   Gtk::Button * button;
    64 
    6558  Gtk::Table * table;
    6659  Gtk::Label * label;
Note: See TracChangeset for help on using the changeset viewer.