Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

PlotterBase.cxx

Go to the documentation of this file.
00001 
00012 // for truncation warning in debug mode
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016 
00017 #include "PlotterBase.h"
00018 #include "PlotterException.h"
00019 
00020 #include "axes/AxisTick.h"
00021 #include "axes/Range.h"
00022 #include "datareps/DataRep.h"
00023 #include "projectors/ProjectorBase.h"
00024 
00025 #include <sstream>
00026 
00027 using namespace hippodraw;
00028 
00029 using std::string;
00030 using std::vector;
00031 
00032 int PlotterBase::s_plotters(0);
00033 
00034 PlotterBase::
00035 PlotterBase ( ) 
00036    : m_aspect_ratio ( 0.0 ),
00037      m_name ( "" ),
00038      m_title( "%t" ),
00039      m_crossX ( 0 ),
00040      m_crossY ( 0 ),
00041      m_parent_plotter( 0 ),
00042      m_parent_datarep_index( -1 )
00043 
00044 {
00045   current_range_saved = false;
00046    setPlotterId();
00047 }
00048 
00049 PlotterBase::
00050 PlotterBase ( const std::string & name )
00051   : m_aspect_ratio ( 0.0 ),
00052     m_name ( name ),
00053     m_title( "%t" ),
00054     m_crossX ( 0 ),
00055     m_crossY ( 0 ),
00056     m_parent_plotter( 0 ),
00057     m_parent_datarep_index( -1 )
00058     
00059 {
00060   current_range_saved = false;
00061    setPlotterId();
00062 }
00063 
00064 PlotterBase::PlotterBase ( const PlotterBase & plotter )
00065   : m_aspect_ratio ( plotter.m_aspect_ratio ),
00066     m_name ( plotter.m_name ),
00067     m_title( plotter.m_title ),
00068     m_parent_plotter( plotter.m_parent_plotter ),
00069     m_parent_datarep_index( plotter.m_parent_datarep_index ),
00070     m_views( plotter.m_views ),
00071     m_currentView( plotter.m_currentView )
00072 
00073 {
00074   current_range_saved = false;
00075    setPlotterId();
00076 }
00077 
00078 PlotterBase::~PlotterBase()
00079 {
00080 }
00081 
00082 const string & PlotterBase::name () const
00083 {
00084   return m_name;
00085 }
00086 
00087 /* virtual */
00088 void PlotterBase::update ( const Observable * )
00089 {
00090   notifyObservers ();
00091 }
00092 
00093 bool
00094 PlotterBase::
00095 hasAxis ( hippodraw::Axes::Type axis ) const
00096 {
00097   return false;
00098 }
00099 
00100 bool
00101 PlotterBase::
00102 hasZoomY ( ) const
00103 {
00104   return true;
00105 }
00106 
00107 
00108 AxisModelBase *
00109 PlotterBase::
00110 getAxisModel ( hippodraw::Axes::Type axis ) const
00111 {
00112   return 0;
00113 }
00114 
00115 void PlotterBase:: setTransform ( TransformBase * transform )
00116 {
00117 }
00118 
00119 TransformBase * PlotterBase:: getTransform () const
00120 {
00121   return 0;
00122 }
00123 
00124 bool PlotterBase::hasAutoScaled () const
00125 {
00126   return false;
00127 }
00128 
00129 ProjectorBase * PlotterBase::activeProjector () const
00130 {
00131   return 0;
00132 }
00133 
00134 ProjectorBase * PlotterBase::getProjector (int ind) const
00135 {
00136   return 0;
00137 }
00138 
00139 int PlotterBase::getNumDataReps () const
00140 {
00141   return 0;
00142 }
00143 
00144 DataRep * PlotterBase::getDataRep ( int index ) const
00145 {
00146   return 0;
00147 }
00148 
00149 DataRep * PlotterBase::selectedDataRep ( ) const
00150 {
00151   return 0;
00152 }
00153 
00164 void PlotterBase::addDataRep ( DataRep * rep )
00165 {
00166 }
00167 
00168 void
00169 PlotterBase::
00170 setActivePlot ( int, bool )
00171 {
00172   // Only CompositePlotter responds to this.
00173 }
00174 
00175 int PlotterBase::activePlotIndex ( ) const
00176 {
00177   return 0;
00178 }
00179 
00180 void PlotterBase::removeDataRep ( DataRep * )
00181 {
00182   // Only the composite plotters respond.
00183 }
00184 
00185 const BinToColor *
00186 PlotterBase::
00187 getValueRep () const
00188 {
00189   return 0;
00190 }
00191 
00192 void
00193 PlotterBase::
00194 setValueRep ( BinToColor * )
00195 {
00196   // do nothing
00197 }
00198 
00199 void
00200 PlotterBase::
00201 setAutoRanging ( const std::string & axis, bool flag )
00202 {
00203   Axes::Type at = Axes::convert ( axis );
00204   setAutoRanging ( at, flag );
00205 
00206   autoScale ();
00207 }
00208 
00209 /* @bug @@@ When the histogram weight is set using the Inspector, this
00210    assert fails and the program crashes.  
00211    
00212    @request @@@ Could we change all asserts of this to type (I count
00213    about 80 of them throughout the code) to tests which throw a
00214    runtime error exception instead?
00215 */
00216 void
00217 PlotterBase::
00218 setAutoRanging ( hippodraw::Axes::Type axis, bool flag )
00219 {
00220 }
00221 
00222 /* virtual dummy holder for non-composite displays */
00223 void PlotterBase::setAutoRanging ( bool flag )
00224 {
00225 }
00226 
00227 bool
00228 PlotterBase::
00229 isAutoRanging ( hippodraw::Axes::Type axis ) const
00230 {
00231   return false;
00232 }
00233 
00234 void PlotterBase::setTitle( const std::string & title )
00235 {
00236   if ( title != "%t" ) {
00237     m_title = title;
00238   } else {
00239     int index = activePlotIndex ();
00240     if ( index > -1 ) {
00241       if ( index == -1 ) index = 0;
00242       DataRep * rep = getDataRep ( index );
00243       // could be zero during initialization from document file
00244       if ( rep != 0 ) rep -> setTitle ( title );
00245     }
00246   }
00247 
00248   notifyObservers ();
00249 }
00250 
00251 const string & PlotterBase::getTitle() const
00252 {
00253   if ( m_title != "%t" ) {
00254     return m_title;
00255   }
00256   int index = activePlotIndex ();
00257   if ( index  < 0 ) index = 0;
00258   const DataRep * rep = getDataRep ( index );
00259 
00260   return rep -> getTitle ();
00261 }
00262 
00263 void PlotterBase::setLabel ( const std::string & axis, 
00264                              const std::string & label )
00265 {
00266   Axes::Type type = Axes::convert ( axis );
00267   setLabel ( type, label );
00268 
00269   notifyObservers ();
00270 }
00271 
00272 void
00273 PlotterBase::
00274 setLabel ( hippodraw::Axes::Type axis, const std::string & value )
00275 {
00276 }
00277 
00278 const string &
00279 PlotterBase::
00280 getLabel ( hippodraw::Axes::Type axis ) const
00281 {
00282   static string s;
00283 
00284   return s;
00285 }
00286 
00287 const string &
00288 PlotterBase::
00289 getInternalTitle ( ) const
00290 {
00291   return m_title;
00292 }
00293 
00294 const string &
00295 PlotterBase::
00296 getInternalLabel ( hippodraw::Axes::Type axis ) const
00297 {
00298   static string s;
00299 
00300   return s;
00301 }
00302 
00303 void PlotterBase::autoScale ( )
00304 {
00305 // do nothing
00306 }
00307 
00308 void 
00309 PlotterBase::
00310 setRange ( const std::string & axis, double low, double high )
00311 {
00312   Axes::Type type = Axes::convert ( axis );
00313   const Range range ( low, high );
00314 
00315   setRange ( type, range, true, false );
00316 }
00317 
00318 void
00319 PlotterBase::
00320 setRange ( hippodraw::Axes::Type axis, const Range & range, 
00321            bool scaled, bool adjust_width )
00322 {
00323 }
00324 
00325 void PlotterBase::setLowRange ( hippodraw::Axes::Type  type,
00326                                 int parm, bool dragging )
00327 {
00328 
00329 }
00330 
00331 void PlotterBase::setHighRange ( hippodraw::Axes::Type type,
00332                                  int parm, bool dragging )
00333 {
00334 }
00335 
00338 const Range & 
00339 PlotterBase::
00340 getRange ( hippodraw::Axes::Type axis, bool scaled ) const
00341 {
00342   static Range range;
00343 
00344   return range;
00345 }
00346 
00347 void
00348 PlotterBase::
00349 setNumberOfBins ( hippodraw::Axes::Type axes, unsigned int number )
00350 {
00351   // does nothing
00352 }
00353 
00354 void 
00355 PlotterBase::
00356 setBinWidth ( hippodraw::Axes::Type, double )
00357 {
00358   // does nothing
00359 }
00360 void
00361 PlotterBase::
00362 setOffset ( hippodraw::Axes::Type, double offset )
00363 {
00364   // does nothing
00365 }
00366 
00367 void 
00368 PlotterBase::
00369 setBinWidth ( const std::string & axis, double width )
00370 {
00371   Axes::Type at = Axes::convert ( axis );
00372   setBinWidth ( at, width );
00373 }
00374 
00375 void 
00376 PlotterBase::
00377 setOffset ( const std::string & axis, double offset )
00378 {
00379   Axes::Type at = Axes::convert ( axis );
00380   setOffset ( at, offset );
00381 }
00382 
00383 void 
00384 PlotterBase::
00385 setNumberOfBins ( const std::string & axis, unsigned int number )
00386 {
00387   Axes::Type at = Axes::convert ( axis );
00388   setNumberOfBins ( at, number );
00389 }
00390 
00391 void 
00392 PlotterBase::
00393 reset ( )
00394 {
00395   // does nothing
00396 }
00397 
00398 const HippoRectangle &
00399 PlotterBase::
00400 getUserRect() const
00401 {
00402   return m_user_rect;
00403 }
00404 
00405 HippoRectangle PlotterBase::getMarginRect () const
00406 {
00407   return m_margin_rect;
00408 }
00409 
00410 float PlotterBase::userToMarginColor ( double c ) const
00411 {
00412   // The default is to do nothing.
00413   return 0.0;
00414 }
00415 
00416 void
00417 PlotterBase::
00418 setScaleFactor ( hippodraw::Axes::Type axis, double factor )
00419 {
00420 }
00421 
00422 void PlotterBase:: setScaling ( hippodraw::Axes::Type axis, bool on )
00423 {
00424 }
00425 
00426 double
00427 PlotterBase::
00428 getBinWidth ( const std::string & axis ) const
00429 {
00430   Axes::Type type = Axes::convert ( axis );
00431 
00432   return getBinWidth ( type );
00433 }
00434 
00435 double
00436 PlotterBase::
00437 getBinWidth ( hippodraw::Axes::Type ) const
00438 {
00439   return 1.0;
00440 }
00441 
00442 double
00443 PlotterBase::
00444 getOffset ( hippodraw::Axes::Type ) const
00445 {
00446   return 1.0;
00447 }
00448 
00449 double
00450 PlotterBase::
00451 getOffset ( const std::string & axis ) const
00452 {
00453   Axes::Type type = Axes::convert ( axis );
00454 
00455   return getOffset ( type );
00456 }
00457 
00458 int
00459 PlotterBase::
00460 getNumberOfEntries () const
00461 {
00462   return 0;
00463 }
00464 
00465 int
00466 PlotterBase::
00467 getNumOfEntries () const
00468 {
00469   return getNumberOfEntries ();
00470 }
00471 
00472 void PlotterBase::checkAxisScaling ( )
00473 {
00474 // do nothing
00475 }
00476 
00477 double
00478 PlotterBase::
00479 getPosRange ( hippodraw::Axes::Type ) const
00480 {
00481   return DBL_EPSILON;
00482 }
00483 
00484 double PlotterBase::getZValue ( double , double , bool ) const
00485 {
00486   return 0.0;
00487 }
00488 
00489 void PlotterBase::setCrossX ( double val )
00490 {
00491   m_crossX = val;
00492 }
00493 
00494 void PlotterBase::setCrossY ( double val )
00495 {
00496   m_crossY = val;
00497 }
00498 
00499 void
00500 PlotterBase::
00501 drawCrossHairs ( ViewBase * view )
00502 {
00503   // does nothing
00504 }
00505 
00506 void
00507 PlotterBase::
00508 addValues ( const std::vector < double > & v )
00509 {
00510   // do nothing
00511 }
00512 
00513 double
00514 PlotterBase::
00515 getAspectRatio () const
00516 {
00517   return 0;
00518 }
00519 
00520 void
00521 PlotterBase::
00522 setAspectRatio ( double ratio )
00523 {
00524   m_aspect_ratio = ratio;
00525 }
00526 
00527 bool
00528 PlotterBase::
00529 wantsPixmap ( ) const
00530 {
00531   return false;
00532 }
00533 
00534 NTuple *
00535 PlotterBase::
00536 createPickTuple ()
00537 {
00538   return 0;
00539 }
00540 
00541 void
00542 PlotterBase::
00543 fillPickedPoint ( double mx, double my, 
00544                   std::vector < double > & picked ) const
00545 {
00546 }
00547 
00548 void PlotterBase::setOffsets( double xoffset, double yoffset )
00549 {
00550   setOffset ( Axes::X, xoffset );
00551   setOffset ( Axes::Y, yoffset );
00552 }
00553 
00554 int PlotterBase::getParentDataRepIndex ( ) const
00555 {
00556   return m_parent_datarep_index;
00557 }
00558   
00559 void PlotterBase::setParentDataRepIndex ( int index ) 
00560 {
00561   m_parent_datarep_index = index;
00562 }
00563 
00564 PlotterBase* PlotterBase::getParentPlotter ( ) const
00565 {
00566   return m_parent_plotter;
00567 }
00568   
00569 void PlotterBase::setParentPlotter( PlotterBase* plotter ) 
00570 {
00571   m_parent_plotter = plotter;
00572 }
00573 
00574 void
00575 PlotterBase::
00576 setEnableZ ( bool )
00577 {
00578   // do nothing
00579 }
00580 
00581 void
00582 PlotterBase::
00583 setAutoTicks ( hippodraw::Axes::Type axis, bool yes )
00584 {
00585   // do nothing
00586 }
00587 
00588 void
00589 PlotterBase::
00590 setTicks ( hippodraw::Axes::Type axis, const std::vector < AxisTick > & ticks )
00591 {
00592 }
00593 
00594 void
00595 PlotterBase::
00596 setAutoTicksOnX ( bool yes )
00597 {
00598   setAutoTicks ( Axes::X, yes );
00599 }
00600 
00601 void
00602 PlotterBase::
00603 setAutoTicks ( const std::string & axis, bool yes )
00604 {
00605   Axes::Type type = Axes::convert ( axis );
00606   setAutoTicks ( type, yes );
00607 }
00608 
00609 void
00610 PlotterBase::
00611 setTicksOnX ( const std::vector < double > & values,
00612               const std::vector < std::string > & labels )
00613 {
00614   unsigned int size = values.size ();
00615   vector < AxisTick > ticks ( size );
00616 
00617   for ( unsigned int i = 0; i < size; i++ ) {
00618     ticks[i].setValue ( values[i] );
00619     ticks[i].setContent ( labels[i] );
00620   }
00621 
00622   setTicks ( Axes::X, ticks );
00623 }
00624 
00625 void
00626 PlotterBase::
00627 setTicks ( const std::string & axis, 
00628            const std::vector < double > & values,
00629            const std::vector < std::string > & labels )
00630 {
00631   unsigned int size = values.size ();
00632   vector < AxisTick > ticks ( size );
00633 
00634   for ( unsigned int i = 0; i < size; i++ ) {
00635     ticks[i].setValue ( values[i] );
00636     ticks[i].setContent ( labels[i] );
00637   }
00638   Axes::Type type = Axes::convert ( axis );
00639 
00640   setTicks ( type, ticks );
00641 }
00642 
00643 double
00644 PlotterBase::
00645 getLowRangeOnX () const
00646 {
00647   const Range & range = getRange ( Axes::X, true ); // scaled range
00648 
00649   return range.low ();
00650 }
00651 
00652 double
00653 PlotterBase::
00654 getHighRangeOnX () const
00655 {
00656   const Range & range = getRange ( Axes::X, true ); // scaled range
00657 
00658   return range.high ();
00659 }
00660 
00661 void
00662 PlotterBase::
00663 matrixTranspose ( bool )
00664 {
00665   // do nothing
00666 }
00667 
00668 bool
00669 PlotterBase::
00670 isTargetable () const
00671 {
00672   return false;
00673 }
00674 
00675 DataRep *
00676 PlotterBase::
00677 getTarget () const
00678 {
00679   return 0;
00680 }
00681 
00682 int
00683 PlotterBase::
00684 indexOf ( const DataRep * ) const
00685 {
00686   return -1;
00687 }
00688 
00689 void
00690 PlotterBase::
00691 toggleActivePlot ()
00692 {
00693   int to_select = 0;
00694   int number = getNumDataReps ();
00695 
00696   if ( number > 1 ) {
00697     to_select = activePlotIndex ();
00698     to_select++;
00699 
00700     if ( to_select == number ) {
00701       to_select = -1;
00702     }
00703     setActivePlot ( to_select, true );
00704     checkAxisScaling ();
00705   }
00706 }
00707 
00708 void 
00709 PlotterBase::
00710 setPlotterId ()
00711 {
00712    m_plotterId = s_plotters;
00713    s_plotters++;
00714 }
00715 
00716 int
00717 PlotterBase::
00718 plotterId () const 
00719 {
00720    return m_plotterId;
00721 }
00722 
00723 int 
00724 PlotterBase::
00725 saveView ( const std::vector<double> & range_values ) 
00726 {
00727    if (range_values.size() != 4) {
00728       throw PlotterException("PlotterBase::saveView: "
00729                              "Invalid number of range values.");
00730    }
00731    m_views.push_back(range_values);
00732    
00733    m_currentView = static_cast<int>(m_views.size() - 1);
00734 
00735    return m_currentView;
00736 }
00737 
00738 int 
00739 PlotterBase::
00740 saveViewAtIndex ( const std::vector<double> & range_values , unsigned int i ) 
00741 {
00742   if ( (i < 0) || ( i > m_views.size() ) ) {
00743     i = 0;
00744   }
00745  
00746    if (range_values.size() != 4) {
00747       throw PlotterException("PlotterBase::saveView: "
00748                              "Invalid number of range values.");
00749    }
00750    vector < vector < double > > :: iterator iter = m_views.begin ();
00751    advance ( iter, i );
00752    m_views.insert( iter , range_values);
00753 
00754    for ( unsigned int k = m_views.size() - 1 ; k>i; k--) {
00755      m_views.pop_back();
00756    }
00757    m_currentView = static_cast<int>( i );
00758 
00759    return m_currentView;
00760 }
00761 
00762 
00763 int 
00764 PlotterBase::
00765 nextView ( bool stepForward )
00766 {
00767    if (m_views.size() == 0) {
00768       return -1;
00769    }
00770    if (stepForward) {
00771       m_currentView += 1;
00772       if (m_currentView >= static_cast<int>(m_views.size())) {
00773          m_currentView = 0;
00774       }
00775    } else {
00776       m_currentView -= 1;
00777       if (m_currentView <= -1) {
00778          m_currentView = m_views.size() - 1;
00779       }
00780    }
00781    setView(m_currentView);
00782    return m_currentView;
00783 }
00784 
00785 
00786 
00787 void
00788 PlotterBase::
00789 setView ( int index )
00790 {
00791    if ( m_views.size() == 0 || index < 0 || 
00792         index >= static_cast<int>(m_views.size()) ) {
00793       std::ostringstream what;
00794       what << "PlotterBase::setView: Invalid plot view index "
00795            << index << ".";
00796       throw PlotterException(what.str());
00797    }
00798    setRange("x", m_views[index][0], m_views[index][1]);
00799    setRange("y", m_views[index][2], m_views[index][3]);
00800    m_currentView = index;
00801 }
00802 
00803 int
00804 PlotterBase::
00805 numViews () const
00806 {
00807    return static_cast<int>(m_views.size());
00808 }
00809 
00810 void
00811 PlotterBase::
00812 deleteView ( int index )
00813 {
00814    std::vector< std::vector<double> > views;
00815    for (unsigned int i = 0; i < m_views.size(); i++) {
00816       if (static_cast<int>(i) != index) {
00817          views.push_back(m_views[i]);
00818       }
00819    }
00820    m_views = views;
00821    index--;
00822    if (index > 0 && m_views.size() > 0) {
00823       setView(index);
00824    }
00825 }
00826 
00827 int 
00828 PlotterBase::
00829 currentView () const
00830 {
00831    return m_currentView;
00832 }
00833 
00834 void
00835 PlotterBase::
00836 fillCutList ( std::vector < const TupleCut * > & cuts ) const
00837 {
00838   // do nothing.
00839 }
00840 
00841 void
00842 PlotterBase::
00843 setCutRangeAt ( const Range & range, unsigned int i )
00844 {
00845   // do nothing
00846 }
00847 
00848 void
00849 PlotterBase::
00850 setCurrentRangeSaved( bool flag )
00851 {
00852   current_range_saved = flag;
00853 }
00854 
00855 bool
00856 PlotterBase::
00857 getCurrentRangeSaved( )
00858 {
00859   return current_range_saved ;
00860 }
00861 

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3