Working tooltips are added. No segmentation fault is occured if empty graphs are redesigned.
authorhegyi
Tue, 20 Feb 2007 17:45:44 +0000
changeset 1902cac5b936a2b
parent 189 8b69c54d5bf0
child 191 af2ed974ab68
Working tooltips are added. No segmentation fault is occured if empty graphs are redesigned.
graph_displayer_canvas.cc
main_win.cc
main_win.h
     1.1 --- a/graph_displayer_canvas.cc	Tue Feb 20 15:46:19 2007 +0000
     1.2 +++ b/graph_displayer_canvas.cc	Tue Feb 20 17:45:44 2007 +0000
     1.3 @@ -323,110 +323,115 @@
     1.4  
     1.5  void GraphDisplayerCanvas::reDesignGraph()
     1.6  {
     1.7 -  double max_coord=50000;
     1.8 -  double min_dist=20;
     1.9 -  double init_vector_length=25;
    1.10 +  NodeIt firstnode((mytab.mapstorage).graph);
    1.11 +  //is it not an empty graph?
    1.12 +  if(firstnode!=INVALID)
    1.13 +    {
    1.14 +      double max_coord=50000;
    1.15 +      double min_dist=20;
    1.16 +      double init_vector_length=25;
    1.17  
    1.18 -  if(!was_redesigned)
    1.19 -    {
    1.20 -      NodeIt i((mytab.mapstorage).graph);
    1.21 +      if(!was_redesigned)
    1.22 +	{
    1.23 +	  NodeIt i((mytab.mapstorage).graph);
    1.24  
    1.25 -      dim2::Point<double> init(init_vector_length*rnd(),
    1.26 -			       init_vector_length*rnd());
    1.27 -      moveNode(init.x, init.y, nodesmap[i], i);
    1.28 -      was_redesigned=true;
    1.29 -    }
    1.30 +	  dim2::Point<double> init(init_vector_length*rnd(),
    1.31 +				   init_vector_length*rnd());
    1.32 +	  moveNode(init.x, init.y, nodesmap[i], i);
    1.33 +	  was_redesigned=true;
    1.34 +	}
    1.35  
    1.36 -  double attraction;
    1.37 -  double propulsation;
    1.38 -  int iterations;
    1.39 +      double attraction;
    1.40 +      double propulsation;
    1.41 +      int iterations;
    1.42  
    1.43 -  (mytab.mapstorage).get_design_data(attraction, propulsation, iterations);
    1.44 +      (mytab.mapstorage).get_design_data(attraction, propulsation, iterations);
    1.45  
    1.46 -  //iteration counter
    1.47 -  for(int l=0;l<iterations;l++)
    1.48 -    {
    1.49 -      Graph::NodeMap<double> x(mytab.mapstorage.graph);
    1.50 -      Graph::NodeMap<double> y(mytab.mapstorage.graph);
    1.51 -      XYMap<Graph::NodeMap<double> > actual_forces;
    1.52 -      actual_forces.setXMap(x);
    1.53 -      actual_forces.setYMap(y);
    1.54 +      //iteration counter
    1.55 +      for(int l=0;l<iterations;l++)
    1.56 +	{
    1.57 +	  Graph::NodeMap<double> x(mytab.mapstorage.graph);
    1.58 +	  Graph::NodeMap<double> y(mytab.mapstorage.graph);
    1.59 +	  XYMap<Graph::NodeMap<double> > actual_forces;
    1.60 +	  actual_forces.setXMap(x);
    1.61 +	  actual_forces.setYMap(y);
    1.62  
    1.63 -      //count actual force for each nodes
    1.64 -      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
    1.65 -	{
    1.66 -	  //propulsation of nodes
    1.67 -	  for (NodeIt j((mytab.mapstorage).graph); j!=INVALID; ++j)
    1.68 +	  //count actual force for each nodes
    1.69 +	  for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
    1.70  	    {
    1.71 -	      if(i!=j)
    1.72 +	      //propulsation of nodes
    1.73 +	      for (NodeIt j((mytab.mapstorage).graph); j!=INVALID; ++j)
    1.74 +		{
    1.75 +		  if(i!=j)
    1.76 +		    {
    1.77 +		      lemon::dim2::Point<double> delta =
    1.78 +			((mytab.mapstorage).coords[i]-
    1.79 +			 (mytab.mapstorage).coords[j]);
    1.80 +
    1.81 +		      const double length_sqr=std::max(delta.normSquare(),min_dist);
    1.82 +
    1.83 +		      //normalize vector
    1.84 +		      delta/=sqrt(length_sqr);
    1.85 +
    1.86 +		      //calculating propulsation strength
    1.87 +		      //greater distance menas smaller propulsation strength
    1.88 +		      delta*=propulsation/length_sqr;
    1.89 +		    
    1.90 +		      actual_forces.set(i,(actual_forces[i]+delta));
    1.91 +		    }
    1.92 +		}
    1.93 +	      //attraction of nodes, to which actual node is bound
    1.94 +	      for(OutEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei)
    1.95  		{
    1.96  		  lemon::dim2::Point<double> delta =
    1.97  		    ((mytab.mapstorage).coords[i]-
    1.98 -		     (mytab.mapstorage).coords[j]);
    1.99 -
   1.100 -		  const double length_sqr=std::max(delta.normSquare(),min_dist);
   1.101 -
   1.102 -		  //normalize vector
   1.103 -		  delta/=sqrt(length_sqr);
   1.104 -
   1.105 -		  //calculating propulsation strength
   1.106 -		  //greater distance menas smaller propulsation strength
   1.107 -		  delta*=propulsation/length_sqr;
   1.108 -		    
   1.109 -		  actual_forces.set(i,(actual_forces[i]+delta));
   1.110 +		     (mytab.mapstorage).coords[mytab.mapstorage.
   1.111 +					       graph.target(ei)]);
   1.112 +		
   1.113 +		  //calculating attraction strength
   1.114 +		  //greater distance means greater strength
   1.115 +		  delta*=attraction;
   1.116 +		
   1.117 +		  actual_forces.set(i,actual_forces[i]-delta);
   1.118 +		}
   1.119 +	      for(InEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei)
   1.120 +		{
   1.121 +		  lemon::dim2::Point<double> delta =
   1.122 +		    ((mytab.mapstorage).coords[i]-
   1.123 +		     (mytab.mapstorage).coords[mytab.mapstorage.
   1.124 +					       graph.source(ei)]);
   1.125 +		
   1.126 +		  //calculating attraction strength
   1.127 +		  //greater distance means greater strength
   1.128 +		  delta*=attraction;
   1.129 +		
   1.130 +		  actual_forces.set(i,actual_forces[i]-delta);
   1.131  		}
   1.132  	    }
   1.133 -	  //attraction of nodes, to which actual node is bound
   1.134 -	  for(OutEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei)
   1.135 +	  for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   1.136  	    {
   1.137 -	      lemon::dim2::Point<double> delta =
   1.138 -		((mytab.mapstorage).coords[i]-
   1.139 -		 (mytab.mapstorage).coords[mytab.mapstorage.
   1.140 -					   graph.target(ei)]);
   1.141 -		
   1.142 -		//calculating attraction strength
   1.143 -		//greater distance means greater strength
   1.144 -		delta*=attraction;
   1.145 -		
   1.146 -		actual_forces.set(i,actual_forces[i]-delta);
   1.147 +	      if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x>max_coord)
   1.148 +		{
   1.149 +		  actual_forces[i].x=max_coord-((mytab.mapstorage).coords[i].x);
   1.150 +		  std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl;
   1.151 +		}
   1.152 +	      else if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x<(0-max_coord))
   1.153 +		{
   1.154 +		  actual_forces[i].x=0-max_coord-((mytab.mapstorage).coords[i].x);
   1.155 +		  std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl;
   1.156 +		}
   1.157 +	      if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y>max_coord)
   1.158 +		{
   1.159 +		  actual_forces[i].y=max_coord-((mytab.mapstorage).coords[i].y);
   1.160 +		  std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl;
   1.161 +		}
   1.162 +	      else if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y<(0-max_coord))
   1.163 +		{
   1.164 +		  actual_forces[i].y=0-max_coord-((mytab.mapstorage).coords[i].y);
   1.165 +		  std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl;
   1.166 +		}
   1.167 +	      moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i);
   1.168  	    }
   1.169 -	  for(InEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei)
   1.170 -	    {
   1.171 -	      lemon::dim2::Point<double> delta =
   1.172 -		((mytab.mapstorage).coords[i]-
   1.173 -		 (mytab.mapstorage).coords[mytab.mapstorage.
   1.174 -					   graph.source(ei)]);
   1.175 -		
   1.176 -		//calculating attraction strength
   1.177 -		//greater distance means greater strength
   1.178 -		delta*=attraction;
   1.179 -		
   1.180 -		actual_forces.set(i,actual_forces[i]-delta);
   1.181 -	    }
   1.182 -	}
   1.183 -      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   1.184 -	{
   1.185 -	  if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x>max_coord)
   1.186 -	    {
   1.187 -	      actual_forces[i].x=max_coord-((mytab.mapstorage).coords[i].x);
   1.188 -	      std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl;
   1.189 -	    }
   1.190 -	  else if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x<(0-max_coord))
   1.191 -	    {
   1.192 -	      actual_forces[i].x=0-max_coord-((mytab.mapstorage).coords[i].x);
   1.193 -	      std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl;
   1.194 -	    }
   1.195 -	  if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y>max_coord)
   1.196 -	    {
   1.197 -	      actual_forces[i].y=max_coord-((mytab.mapstorage).coords[i].y);
   1.198 -	      std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl;
   1.199 -	    }
   1.200 -	  else if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y<(0-max_coord))
   1.201 -	    {
   1.202 -	      actual_forces[i].y=0-max_coord-((mytab.mapstorage).coords[i].y);
   1.203 -	      std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl;
   1.204 -	    }
   1.205 -	  moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i);
   1.206  	}
   1.207      }
   1.208  }
     2.1 --- a/main_win.cc	Tue Feb 20 15:46:19 2007 +0000
     2.2 +++ b/main_win.cc	Tue Feb 20 17:45:44 2007 +0000
     2.3 @@ -229,6 +229,7 @@
     2.4    if (toolbar)
     2.5    {
     2.6      static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
     2.7 +    static_cast<Gtk::Toolbar*>(toolbar)->set_tooltips(true);
     2.8      //hbox.pack_start(*toolbar, Gtk::PACK_EXPAND_WIDGET);
     2.9  
    2.10      table.attach(*toolbar, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
    2.11 @@ -269,8 +270,32 @@
    2.12  
    2.13    table.attach(table2, 1, 2, 0, 2, Gtk::SHRINK, Gtk::SHRINK);
    2.14  
    2.15 -  tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
    2.16 -  tooltips.enable();
    2.17 +  tooltips=Gtk::manage(new Gtk::Tooltips());
    2.18 +  if(tooltips)
    2.19 +    {
    2.20 +      tooltips->set_tip(*zoom_track, "If on, edge widths and node radiuses are constant, independent from zooming");
    2.21 +      tooltips->set_tip(*auto_scale, "If on, glemon automatically determines the size of edges and nodes");
    2.22 +      tooltips->set_tip(*radius_size, "Sets maximum node radius, if auto-scale is off");
    2.23 +      tooltips->set_tip(*edge_width, "Sets maximum edge width, if auto-scale is off");
    2.24 +
    2.25 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/FileNew"))->set_tooltip(*tooltips, "Inserts new tab");
    2.26 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/FileOpen"))->set_tooltip(*tooltips, "Lets you open a file");
    2.27 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/FileSave"))->set_tooltip(*tooltips, "Saves the graph on the active tab");
    2.28 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/Close"))->set_tooltip(*tooltips, "Closes the active tab");
    2.29 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/ViewZoomIn"))->set_tooltip(*tooltips, "Zoom in the graph");
    2.30 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/ViewZoomOut"))->set_tooltip(*tooltips, "Zoom out the graph");
    2.31 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/ViewZoom100"))->set_tooltip(*tooltips, "Shows actual size of graph");
    2.32 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/ViewZoomFit"))->set_tooltip(*tooltips, "Fits graph into window");
    2.33 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/MoveItem"))->set_tooltip(*tooltips, "Moves the clicked item (edge/node)");
    2.34 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/CreateNode"))->set_tooltip(*tooltips, "Adds new node");
    2.35 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/CreateEdge"))->set_tooltip(*tooltips, "Lets you create new edge");
    2.36 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/EraseItem"))->set_tooltip(*tooltips, "Erases the clicked item (edge/node)");
    2.37 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/EditEdgeMap"))->set_tooltip(*tooltips, "Lets you edit the values written on the items");
    2.38 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/AddMap"))->set_tooltip(*tooltips, "Adds edge/nodemap");
    2.39 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/DesignGraph"))->set_tooltip(*tooltips, "Redesigns your graph, supposing elastic edges and propulsation of nodes.");
    2.40 +
    2.41 +      tooltips->enable();
    2.42 +    }
    2.43  
    2.44    active_tab=-1;
    2.45    notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab));
     3.1 --- a/main_win.h	Tue Feb 20 15:46:19 2007 +0000
     3.2 +++ b/main_win.h	Tue Feb 20 17:45:44 2007 +0000
     3.3 @@ -117,7 +117,7 @@
     3.4    void readFile(const std::string &);
     3.5  
     3.6    ///Tooltips
     3.7 -  Gtk::Tooltips tooltips;
     3.8 +  Gtk::Tooltips * tooltips;
     3.9  
    3.10    //Call-backs of buttons
    3.11