frame.hpp

Go to the documentation of this file.
00001 
00005 /* Copyright (c) 2005-2010 Taneli Kalvas. All rights reserved.
00006  *
00007  * You can redistribute this software and/or modify it under the terms
00008  * of the GNU General Public License as published by the Free Software
00009  * Foundation; either version 2 of the License, or (at your option)
00010  * any later version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00015  * General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this library (file "COPYING" included in the package);
00019  * if not, write to the Free Software Foundation, Inc., 51 Franklin
00020  * Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  * 
00022  * If you have questions about your rights to use or distribute this
00023  * software, please contact Berkeley Lab's Technology Transfer
00024  * Department at TTD@lbl.gov. Other questions, comments and bug
00025  * reports should be sent directly to the author via email at
00026  * taneli.kalvas@jyu.fi.
00027  * 
00028  * NOTICE. This software was developed under partial funding from the
00029  * U.S.  Department of Energy.  As such, the U.S. Government has been
00030  * granted for itself and others acting on its behalf a paid-up,
00031  * nonexclusive, irrevocable, worldwide license in the Software to
00032  * reproduce, prepare derivative works, and perform publicly and
00033  * display publicly.  Beginning five (5) years after the date
00034  * permission to assert copyright is obtained from the U.S. Department
00035  * of Energy, and subject to any subsequent five (5) year renewals,
00036  * the U.S. Government is granted for itself and others acting on its
00037  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
00038  * the Software to reproduce, prepare derivative works, distribute
00039  * copies to the public, perform publicly and display publicly, and to
00040  * permit others to do so.
00041  */
00042 
00043 #ifndef FRAME_HPP
00044 #define FRAME_HPP 1
00045 
00046 
00047 #include <string>
00048 #include <vector>
00049 #include <cairo.h>
00050 #include "color.hpp"
00051 #include "ruler.hpp"
00052 #include "coordmapper.hpp"
00053 #include "graph.hpp"
00054 
00055 
00056 
00057 enum PlotFixedMode {
00058     PLOT_FIXED_ASPECT_DISABLED = 0,
00059     PLOT_FIXED_ASPECT_EXTEND_RANGE,
00060     PLOT_FIXED_ASPECT_INCREASE_MARGIN
00061 };
00062 
00063 
00064 enum PlotAxis {
00065     PLOT_AXIS_X1 = 0,
00066     PLOT_AXIS_Y1,
00067     PLOT_AXIS_X2,
00068     PLOT_AXIS_Y2,
00069     PLOT_AXIS_Z
00070 };
00071 
00072 
00073 
00090 class Frame {
00091 
00092     struct DObj {
00093         PlotAxis        _xaxis;         
00094         PlotAxis        _yaxis;         
00095         Graph          *_graph;         
00097         DObj( PlotAxis xaxis, PlotAxis yaxis, Graph *graph )
00098             : _xaxis(xaxis), _yaxis(yaxis), _graph(graph) {}
00099     };
00100 
00101     Ruler               _ruler[4];      
00102     Coordmapper1D       _cm[4];         
00103     bool                _enable[4];     
00104     bool                _fenable[4];    
00105     bool                _autorange[8];  
00107     int                 _offx;          
00108     int                 _offy;          
00110     int                 _width;         
00111     int                 _height;        
00113     double              _fontsize;      
00114     double              _titlespace;    
00115     Color               _bg;            
00116     Color               _fg;            
00118     std::vector<DObj>   _dobj;          
00120     Label               _title;         
00122     PlotFixedMode       _fixedaspect;   
00124     bool                _automargin;    
00125     double              _tmargin[4];    
00133     void calculate_autoranging( void );
00134     void calculate_ruler_autoenable( void );
00135     void calculate_rulers( cairo_t *cairo, bool ruler_tic_bbox_test );
00136     void calculate_frame( cairo_t *cairo );
00137     void draw_frame( cairo_t *cairo );
00138     void mirror_rulers( void );
00139     void set_frame_clipping( cairo_t *cairo );
00140     void unset_frame_clipping( cairo_t *cairo );
00141 
00142 public:
00143 
00146     Frame();
00147 
00150     ~Frame() {}
00151 
00159     void set_geometry( int width, int height, int offx, int offy ) {
00160         _width = width;
00161         _height = height;
00162         _offx = offx;
00163         _offy = offy;
00164     }
00165 
00168     void set_font_size( double size );
00169 
00172     double get_font_size( void ) {
00173         return( _fontsize );
00174     }
00175 
00178     void set_background( Color &bg ) {
00179         _bg = bg;
00180     }    
00181 
00184     void set_foreground( Color &fg ) {
00185         _fg = fg;
00186     }
00187 
00193     Coordmapper get_coordmapper( PlotAxis xaxis, PlotAxis yaxis ) const;
00194 
00197     void get_margins( double margin[4] ) const;
00198 
00204     void get_frame_edges( double edge[4] ) const;
00205 
00208     void set_title( const std::string &title );
00209 
00212     void set_axis_label( PlotAxis axis, const std::string &label );
00213 
00220     void force_enable_ruler( PlotAxis axis, bool force );
00221 
00228     void ruler_autorange_enable( PlotAxis axis, bool min, bool max );
00229 
00236     void set_ranges( PlotAxis axis, double min, double max );
00237 
00243     void get_ranges( PlotAxis axis, double &min, double &max ) const;
00244         
00256     void set_fixed_aspect( PlotFixedMode mode );
00257 
00270     void set_automargin( bool enable );
00271 
00277     void add_graph( PlotAxis xaxis, PlotAxis yaxis, Graph *drawable );
00278 
00284     void clear_graphs( void );
00285 
00296     void draw( cairo_t *cairo );
00297 };
00298 
00299 
00300 #endif
00301 
00302 
00303 
00304 
00305 
00306 
00307 
00308 
00309 
00310 
00311 
00312 
00313 
00314 
00315 
00316 
00317 
00318 

Generated on 18 Apr 2011 for IBSimu by  doxygen 1.6.1