EdgeMap and NodeMap creation is done, at last. Bach 4ever.
authorhegyi
Tue, 26 Jul 2005 21:20:01 +0000
changeset 1593a8a007f1c01c
parent 1592 4708b716d2f4
child 1594 0bd9e53c8b28
EdgeMap and NodeMap creation is done, at last. Bach 4ever.
gui/new_map_win.cc
gui/new_map_win.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gui/new_map_win.cc	Tue Jul 26 21:20:01 2005 +0000
     1.3 @@ -0,0 +1,105 @@
     1.4 +#include <new_map_win.h>
     1.5 +
     1.6 +bool NewMapWin::closeIfEscapeIsPressed(GdkEventKey* e)
     1.7 +{
     1.8 +  if(e->keyval==GDK_Escape)
     1.9 +  {
    1.10 +    hide();
    1.11 +  }
    1.12 +  return true;
    1.13 +}
    1.14 +
    1.15 +NewMapWin::NewMapWin(const std::string& title, GraphDisplayerCanvas & grdispc):gdc(grdispc),node("Create NodeMap"),edge("Create EdgeMap")
    1.16 +{
    1.17 +  set_title(title);
    1.18 +  set_default_size(200, 50);
    1.19 +
    1.20 +  signal_key_press_event().connect(sigc::mem_fun(*this, &NewMapWin::closeIfEscapeIsPressed));
    1.21 +
    1.22 +
    1.23 +  //entries
    1.24 +  table=new Gtk::Table(3, 2, false);
    1.25 +
    1.26 +  label=new Gtk::Label;
    1.27 +  label->set_text("Name of new map:");
    1.28 +  name.set_text("");
    1.29 +
    1.30 +  (*table).attach(*label,0,1,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.31 +  (*table).attach(name,1,2,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.32 +
    1.33 +  label=new Gtk::Label;
    1.34 +  label->set_text("Default value in the map:");
    1.35 +  default_value.set_text("0");
    1.36 +
    1.37 +  (*table).attach(*label,0,1,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.38 +  (*table).attach(default_value,1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.39 +
    1.40 +  //node vs. edge map selector
    1.41 +  Gtk::RadioButton::Group group = node.get_group();
    1.42 +  edge.set_group(group);
    1.43 +
    1.44 +  (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.45 +  (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.46 +
    1.47 +  vbox.pack_start(*table);
    1.48 +
    1.49 +  //OK button
    1.50 +  button=new Gtk::Button("OK");
    1.51 +
    1.52 +  button->signal_clicked().connect
    1.53 +    (
    1.54 +     sigc::mem_fun(*this, &NewMapWin::buttonPressed)
    1.55 +    );
    1.56 +
    1.57 +
    1.58 +  vbox.pack_start(*button);
    1.59 +
    1.60 +  add(vbox);
    1.61 +
    1.62 +  show_all_children();
    1.63 +
    1.64 +}
    1.65 +
    1.66 +void NewMapWin::buttonPressed()
    1.67 +{
    1.68 +  bool valid_double=true;
    1.69 +  int point_num=0;
    1.70 +
    1.71 +  std::string def_val_str=default_value.get_text();
    1.72 +  char * def_val_ch=new char [def_val_str.length()];
    1.73 +  for(int i=0;i<(int)(def_val_str.length());i++)
    1.74 +    {
    1.75 +      if(((def_val_str[i]<'0')||(def_val_str[i]>'9'))&&(def_val_str[i]!='.'))
    1.76 +	{
    1.77 +	  valid_double=false;
    1.78 +	}
    1.79 +      else
    1.80 +	{
    1.81 +	  if(def_val_str[i]=='.')
    1.82 +	    {
    1.83 +	      point_num++;
    1.84 +	    }
    1.85 +	}
    1.86 +      def_val_ch[i]=def_val_str[i];
    1.87 +    }
    1.88 +  
    1.89 +  double def_val=atof(def_val_ch);
    1.90 +
    1.91 +  std::string mapname=name.get_text();
    1.92 +
    1.93 +  if((point_num<=1)&&(valid_double)&&(!mapname.empty()))
    1.94 +    {
    1.95 +      if(edge.get_active())
    1.96 +	{
    1.97 +	  gdc.addNewEdgeMap(def_val,mapname);
    1.98 +	}
    1.99 +      else
   1.100 +	{
   1.101 +	  gdc.addNewNodeMap(def_val,mapname);
   1.102 +	}
   1.103 +      name.set_text("");
   1.104 +      default_value.set_text("0");
   1.105 +      hide();
   1.106 +    }
   1.107 +}
   1.108 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/gui/new_map_win.h	Tue Jul 26 21:20:01 2005 +0000
     2.3 @@ -0,0 +1,49 @@
     2.4 +// -*- C++ -*- //
     2.5 +
     2.6 +#ifndef NEWMAPWIN_H
     2.7 +#define NEWMAPWIN_H
     2.8 +
     2.9 +class NewMapWin;
    2.10 +
    2.11 +#include <all_include.h>
    2.12 +#include <graph_displayer_canvas.h>
    2.13 +#include <libgnomecanvasmm.h>
    2.14 +#include <libgnomecanvasmm/polygon.h>
    2.15 +
    2.16 +///This class is responsible for creating a window,
    2.17 +///on which the parameters of a new map can be set.
    2.18 +
    2.19 +class NewMapWin : public Gtk::Window
    2.20 +{
    2.21 +  ///The \ref GraphDisplayerCanvas on which the graph will be drawn.
    2.22 +  ///It has to be known for this class, because
    2.23 +  ///when a map is created
    2.24 +  ///a function of the \ref GraphDisplayerCanvas will be called.
    2.25 +  GraphDisplayerCanvas & gdc;
    2.26 +
    2.27 + public:
    2.28 +  ///Constructor of NewMapWin creates the widgets shown in NewMapWin.
    2.29 +  NewMapWin(const std::string& title, GraphDisplayerCanvas &);
    2.30 +
    2.31 +
    2.32 +  ///Signal on button is connected to this function,
    2.33 +  ///Therefore this function determines whether to
    2.34 +  ///call the map/creatort function, and if yes, it
    2.35 +  //tells it the attributes.(name, default value)
    2.36 +  virtual void buttonPressed();
    2.37 +
    2.38 +  virtual bool closeIfEscapeIsPressed(GdkEventKey*);
    2.39 +
    2.40 +  Gtk::Entry name, default_value;
    2.41 +
    2.42 +  Gtk::VBox vbox;
    2.43 +
    2.44 +  Gtk::Button * button;
    2.45 +
    2.46 +  Gtk::Table * table;
    2.47 +  Gtk::Label * label;
    2.48 +
    2.49 +  Gtk::RadioButton node, edge;
    2.50 +};
    2.51 +
    2.52 +#endif //NEWMAPWIN_H