ColumnPointRep.cxx

Go to the documentation of this file.
00001 
00012 // For truncation warning
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016 
00017 #include "ColumnPointRep.h"
00018 #include "ErrorBarRep.h"
00019 
00020 #include "datasrcs/DataPointTuple.h"
00021 #include "datasrcs/DataSource.h"
00022 #include "graphics/ViewBase.h"
00023 #include "transforms/BinaryTransform.h"
00024 
00025 #include <cmath>
00026 
00027 #include <cassert>
00028 
00029 using std::abs;
00030 using std::string;
00031 using std::vector;
00032 
00033 using namespace hippodraw;
00034 
00039 ColumnPointRep::ColumnPointRep ()
00040   : PointRepBase ( "Column", 1.0 ),
00041     m_line_style( Line::Solid ),
00042     m_y_flag ( false )
00043 {
00044   m_error_rep = new ErrorBarRep();
00045 }
00046 
00047 ColumnPointRep::ColumnPointRep ( const ColumnPointRep & point_rep )
00048   : PointRepBase ( point_rep ), 
00049     m_line_style ( point_rep.m_line_style ),
00050     m_y_flag ( point_rep.m_y_flag )
00051 {
00052   RepBase * clone = point_rep.m_error_rep->clone ();
00053   m_error_rep = dynamic_cast< ErrorBarRep  *> ( clone );
00054 }
00055 
00056 ColumnPointRep::~ColumnPointRep ()
00057 {
00058   delete m_error_rep;
00059 }
00060 
00061 RepBase * ColumnPointRep::clone ()
00062 {
00063   return new ColumnPointRep ( *this );
00064 }
00065 
00066 void ColumnPointRep::setColor ( const Color & color )
00067 {
00068   RepBase::setColor ( color );
00069 
00070   if ( m_error_rep ) {
00071     m_error_rep->setColor ( color );
00072   }
00073 }
00074 
00075 void
00076 ColumnPointRep::
00077 setStyle ( unsigned int style )
00078 {
00079   m_line_style = Line::convert ( style );
00080 }
00081 
00082 unsigned int
00083 ColumnPointRep::
00084 getStyle ( ) const
00085 {
00086   return m_line_style;
00087 }
00088 
00089 void
00090 ColumnPointRep::
00091 setErrorOn ( Axes::Type axis, bool flag )
00092 {
00093   if ( axis == Axes::Y ) {
00094     m_error_rep->setYError ( flag );
00095     m_y_flag = flag;
00096   }
00097 }
00098 
00099 bool ColumnPointRep::yError () const
00100 {
00101   return m_y_flag;
00102 }
00103 
00104 void
00105 ColumnPointRep::
00106 drawValues ( ViewBase * view ) const
00107 {
00108   const Color & cur_color = color();
00109   view -> drawPolyLine ( m_x, m_y, m_line_style, cur_color, m_size );
00110 }
00111 
00112 namespace dp = hippodraw::DataPoint2DTuple;
00113 
00116 void
00117 ColumnPointRep::
00118 drawProjectedValues ( const DataSource * ntuple,
00119                       TransformBase * transform,
00120                       ViewBase * view )
00121 {
00122   m_x.clear();
00123   m_y.clear();
00124 
00125   unsigned int size = ntuple -> rows ();
00126   unsigned int reserve = 2 * ( size + 1 );
00127 
00128   m_x.reserve ( reserve );
00129   m_y.reserve ( reserve );
00130 
00131   double last_x = 0.0;
00132 
00133   const Rect & user_rect = view -> getUserRect ();
00134 
00135   for ( unsigned int i = 0; i < size; i ++ ) {
00136     const vector < double > & row = ntuple -> getRow ( i );
00137     double x = row [ dp::X ];
00138     double hw = row [ dp::XERR ];
00139     if ( i == 0 ) {
00140       m_x.push_back ( x - hw );
00141       m_y.push_back ( 0.0 ); // The first y is always zero.
00142 
00143       m_x.push_back ( x -hw );
00144     }
00145     else {
00146       m_x.push_back ( last_x );
00147     }
00148     double y = row [ dp::Y ];
00149     m_y.push_back ( y ); // X was already set.
00150     x += hw;
00151     m_x.push_back ( x );
00152     m_y.push_back ( y );
00153 
00154     last_x = x;
00155   }
00156   m_x.push_back ( last_x );
00157 
00158   const BinaryTransform * t 
00159     = dynamic_cast < const BinaryTransform * > ( transform );
00160   assert ( t != 0 );
00161 
00162   m_y.push_back ( 0.0 ); // The last y is always zero.
00163   assert ( m_x.size() == m_y.size() );
00164 
00165   t -> transform ( m_x, m_y );
00166 
00167   user_rect.makeInBounds ( m_x, m_y );
00168 
00169   drawValues ( view );
00170 
00171   if ( m_y_flag ) {
00172     m_error_rep -> drawProjectedValues ( ntuple, transform, view );
00173   }
00174 }
00175 
00176 bool
00177 ColumnPointRep::
00178 uses ( Line::Style ) const
00179 {
00180   return true;
00181 }
00182 
00183 void
00184 ColumnPointRep::
00185 setSize ( float value )
00186 {
00187   RepBase::setSize ( value );
00188 
00189   m_error_rep -> setSize ( value );
00190 }    

Generated for HippoDraw Class Library by doxygen