00001
00012
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 "datareps/DataRep.h"
00022 #include "projectors/ProjectorBase.h"
00023 #include "pattern/string_convert.h"
00024
00025 using namespace hippodraw;
00026
00027 using std::string;
00028 using std::vector;
00029
00030 int PlotterBase::s_plotters(0);
00031
00032 PlotterBase::
00033 PlotterBase ( )
00034 : m_aspect_ratio ( 0.0 ),
00035 m_name ( "" ),
00036 m_title( "%t" ),
00037 m_crossX ( 0 ),
00038 m_crossY ( 0 ),
00039 m_parent_plotter( 0 ),
00040 m_parent_datarep_index( -1 )
00041
00042 {
00043 current_range_saved = false;
00044 setPlotterId();
00045 }
00046
00047 PlotterBase::
00048 PlotterBase ( const std::string & name )
00049 : m_aspect_ratio ( 0.0 ),
00050 m_name ( name ),
00051 m_title( "%t" ),
00052 m_crossX ( 0 ),
00053 m_crossY ( 0 ),
00054 m_parent_plotter( 0 ),
00055 m_parent_datarep_index( -1 )
00056
00057 {
00058 current_range_saved = false;
00059 setPlotterId();
00060 }
00061
00062 PlotterBase::PlotterBase ( const PlotterBase & plotter )
00063 : Observer (),
00064 Observable (),
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 Observable::notifyObservers ( &hippodraw::Observer::willDelete );
00081 }
00082
00083 const string & PlotterBase::name () const
00084 {
00085 return m_name;
00086 }
00087
00088
00089 void PlotterBase::update ( const Observable * )
00090 {
00091 notifyObservers ();
00092 }
00093
00094 void
00095 PlotterBase::
00096 prepareToDraw ()
00097 {
00098
00099 }
00100
00101 bool
00102 PlotterBase::
00103 hasAxis ( hippodraw::Axes::Type ) const
00104 {
00105 return false;
00106 }
00107
00108 bool
00109 PlotterBase::
00110 hasZoomY ( ) const
00111 {
00112 return true;
00113 }
00114
00115
00116 AxisModelBase *
00117 PlotterBase::
00118 getAxisModel ( hippodraw::Axes::Type ) const
00119 {
00120 return 0;
00121 }
00122
00123 void PlotterBase:: setTransform ( TransformBase * )
00124 {
00125 }
00126
00127 TransformBase * PlotterBase:: getTransform () const
00128 {
00129 return 0;
00130 }
00131
00132 bool PlotterBase::hasAutoScaled () const
00133 {
00134 return false;
00135 }
00136
00137 ProjectorBase * PlotterBase::activeProjector () const
00138 {
00139 return 0;
00140 }
00141
00142 ProjectorBase *
00143 PlotterBase::
00144 getProjector ( int ) const
00145 {
00146 return 0;
00147 }
00148
00149 int PlotterBase::getNumDataReps () const
00150 {
00151 return 0;
00152 }
00153
00154 DataRep *
00155 PlotterBase::
00156 getDataRep ( int ) const
00157 {
00158 return 0;
00159 }
00160
00161 DataRep * PlotterBase::selectedDataRep ( ) const
00162 {
00163 return 0;
00164 }
00165
00166 void
00167 PlotterBase::
00168 addDataRep ( DataRep * )
00169 {
00170 }
00171
00172 void
00173 PlotterBase::
00174 setActivePlot ( int, bool )
00175 {
00176
00177 }
00178
00179 int PlotterBase::activePlotIndex ( ) const
00180 {
00181 return 0;
00182 }
00183
00184 void PlotterBase::removeDataRep ( DataRep * )
00185 {
00186
00187 }
00188
00189 const BinToColor *
00190 PlotterBase::
00191 getValueRep () const
00192 {
00193 return 0;
00194 }
00195
00196 void
00197 PlotterBase::
00198 setValueRep ( BinToColor * )
00199 {
00200
00201 }
00202
00203 void
00204 PlotterBase::
00205 setAutoRanging ( const std::string & axis, bool flag )
00206 {
00207 Axes::Type at = Axes::convert ( axis );
00208 setAutoRanging ( at, flag );
00209
00210 autoScale ();
00211 }
00212
00213
00214
00215
00216
00217
00218
00219
00220 void
00221 PlotterBase::
00222 setAutoRanging ( hippodraw::Axes::Type, bool )
00223 {
00224 }
00225
00226
00227 void
00228 PlotterBase::
00229 setAutoRanging ( bool )
00230 {
00231 }
00232
00233 bool
00234 PlotterBase::
00235 isAutoRanging ( hippodraw::Axes::Type ) const
00236 {
00237 return false;
00238 }
00239
00240 void
00241 PlotterBase::
00242 setReverse ( bool )
00243 {
00244 }
00245
00246 bool
00247 PlotterBase::
00248 isReverse ( ) const
00249 {
00250 return false;
00251 }
00252
00253 void PlotterBase::setTitle( const std::string & title )
00254 {
00255 if ( title != "%t" ) {
00256 m_title = title;
00257 } else {
00258 int index = activePlotIndex ();
00259 if ( index > -1 ) {
00260 if ( index == -1 ) index = 0;
00261 DataRep * rep = getDataRep ( index );
00262
00263 if ( rep != 0 ) rep -> setTitle ( title );
00264 }
00265 }
00266
00267 notifyObservers ();
00268 }
00269
00270 const string & PlotterBase::getTitle() const
00271 {
00272 if ( m_title != "%t" ) {
00273 return m_title;
00274 }
00275 int index = activePlotIndex ();
00276 if ( index < 0 ) index = 0;
00277 const DataRep * rep = getDataRep ( index );
00278
00279 return rep -> getTitle ();
00280 }
00281
00282 void PlotterBase::setLabel ( const std::string & axis,
00283 const std::string & label )
00284 {
00285 Axes::Type type = Axes::convert ( axis );
00286 setLabel ( type, label );
00287
00288 notifyObservers ();
00289 }
00290
00291 void
00292 PlotterBase::
00293 setLabel ( hippodraw::Axes::Type, const std::string & )
00294 {
00295 }
00296
00297 const string &
00298 PlotterBase::
00299 getLabel ( hippodraw::Axes::Type ) const
00300 {
00301 static string s;
00302
00303 return s;
00304 }
00305
00306 const string &
00307 PlotterBase::
00308 getInternalTitle ( ) const
00309 {
00310 return m_title;
00311 }
00312
00313 const string &
00314 PlotterBase::
00315 getInternalLabel ( hippodraw::Axes::Type ) const
00316 {
00317 static string s;
00318
00319 return s;
00320 }
00321
00322 void PlotterBase::autoScale ( )
00323 {
00324
00325 }
00326
00327 void
00328 PlotterBase::
00329 setRange ( const std::string & axis, double low, double high )
00330 {
00331 Axes::Type type = Axes::convert ( axis );
00332 const Range range ( low, high );
00333
00334 setRange ( type, range, true, true );
00335 }
00336
00337 void
00338 PlotterBase::
00339 setRange ( hippodraw::Axes::Type, const Range &,
00340 bool, bool )
00341 {
00342 }
00343
00344 void PlotterBase::setLowRange ( hippodraw::Axes::Type,
00345 int, bool )
00346 {
00347
00348 }
00349
00350 void PlotterBase::setHighRange ( hippodraw::Axes::Type,
00351 int, bool )
00352 {
00353 }
00354
00357 const Range &
00358 PlotterBase::
00359 getRange ( hippodraw::Axes::Type, bool ) const
00360 {
00361 static Range range;
00362
00363 return range;
00364 }
00365
00366 void
00367 PlotterBase::
00368 setNumberOfBins ( hippodraw::Axes::Type, unsigned int )
00369 {
00370
00371 }
00372
00373 void
00374 PlotterBase::
00375 setBinWidth ( hippodraw::Axes::Type, double )
00376 {
00377
00378 }
00379
00380 void
00381 PlotterBase::
00382 setBinWidth ( Axes::Type axis, int parm, bool dragging )
00383 {
00384 int index = activePlotIndex ();
00385 index = std::max ( 0, index );
00386
00387 ProjectorBase * projector = getProjector ( index );
00388 const Range & range = projector -> setBinWidth ( axis, parm, dragging );
00389
00390 setRange ( axis, range, false );
00391 }
00392
00393 void
00394 PlotterBase::
00395 setOffset ( hippodraw::Axes::Type, double )
00396 {
00397
00398 }
00399
00400 void
00401 PlotterBase::
00402 setBinWidth ( const std::string & axis, double width )
00403 {
00404 Axes::Type at = Axes::convert ( axis );
00405 setBinWidth ( at, width );
00406 }
00407
00408 void
00409 PlotterBase::
00410 setOffset ( const std::string & axis, double offset )
00411 {
00412 Axes::Type at = Axes::convert ( axis );
00413 setOffset ( at, offset );
00414 }
00415
00416 void
00417 PlotterBase::
00418 setNumberOfBins ( const std::string & axis, unsigned int number )
00419 {
00420 Axes::Type at = Axes::convert ( axis );
00421 setNumberOfBins ( at, number );
00422 }
00423
00424 void
00425 PlotterBase::
00426 reset ( )
00427 {
00428
00429 }
00430
00431 const Rect &
00432 PlotterBase::
00433 getUserRect() const
00434 {
00435 return m_user_rect;
00436 }
00437
00438 const Rect &
00439 PlotterBase::
00440 getRawRect() const
00441 {
00442 return m_raw_rect;
00443 }
00444
00445 void
00446 PlotterBase::
00447 setScaleFactor ( hippodraw::Axes::Type, double )
00448 {
00449 }
00450
00451 void
00452 PlotterBase::
00453 setScaling ( hippodraw::Axes::Type, bool )
00454 {
00455 }
00456
00457 double
00458 PlotterBase::
00459 getBinWidth ( const std::string & axis ) const
00460 {
00461 Axes::Type type = Axes::convert ( axis );
00462
00463 return getBinWidth ( type );
00464 }
00465
00466 double
00467 PlotterBase::
00468 getBinWidth ( hippodraw::Axes::Type ) const
00469 {
00470 return 1.0;
00471 }
00472
00473 double
00474 PlotterBase::
00475 getOffset ( hippodraw::Axes::Type ) const
00476 {
00477 return 1.0;
00478 }
00479
00480 double
00481 PlotterBase::
00482 getOffset ( const std::string & axis ) const
00483 {
00484 Axes::Type type = Axes::convert ( axis );
00485
00486 return getOffset ( type );
00487 }
00488
00489 int
00490 PlotterBase::
00491 getNumberOfEntries () const
00492 {
00493 return 0;
00494 }
00495
00496 int
00497 PlotterBase::
00498 getNumOfEntries () const
00499 {
00500 return getNumberOfEntries ();
00501 }
00502
00503 void PlotterBase::checkAxisScaling ( )
00504 {
00505
00506 }
00507
00508 double
00509 PlotterBase::
00510 getPosRange ( hippodraw::Axes::Type ) const
00511 {
00512 return DBL_EPSILON;
00513 }
00514
00515 double PlotterBase::getZValue ( double , double , bool ) const
00516 {
00517 return 0.0;
00518 }
00519
00520 void PlotterBase::setCrossX ( double val )
00521 {
00522 m_crossX = val;
00523 }
00524
00525 void PlotterBase::setCrossY ( double val )
00526 {
00527 m_crossY = val;
00528 }
00529
00530 void
00531 PlotterBase::
00532 drawCrossHairs ( ViewBase * )
00533 {
00534
00535 }
00536
00537 void
00538 PlotterBase::
00539 addValues ( const std::vector < double > & )
00540 {
00541
00542 }
00543
00544 double
00545 PlotterBase::
00546 getAspectRatio () const
00547 {
00548 return m_aspect_ratio;
00549 }
00550
00551 void
00552 PlotterBase::
00553 setAspectRatio ( double ratio )
00554 {
00555 m_aspect_ratio = ratio;
00556 notifyObservers ();
00557 }
00558
00559 bool
00560 PlotterBase::
00561 wantsPixmap ( ) const
00562 {
00563 return false;
00564 }
00565
00566 NTuple *
00567 PlotterBase::
00568 createPickTuple ()
00569 {
00570 return 0;
00571 }
00572
00573 void
00574 PlotterBase::
00575 fillPickedPointFrom ( double, double,
00576 std::vector < double > & ) const
00577 {
00578 }
00579
00580 void PlotterBase::setOffsets( double xoffset, double yoffset )
00581 {
00582 setOffset ( Axes::X, xoffset );
00583 setOffset ( Axes::Y, yoffset );
00584 }
00585
00586 int PlotterBase::getParentDataRepIndex ( ) const
00587 {
00588 return m_parent_datarep_index;
00589 }
00590
00591 void PlotterBase::setParentDataRepIndex ( int index )
00592 {
00593 m_parent_datarep_index = index;
00594 }
00595
00596 PlotterBase* PlotterBase::getParentPlotter ( ) const
00597 {
00598 return m_parent_plotter;
00599 }
00600
00601 void PlotterBase::setParentPlotter( PlotterBase* plotter )
00602 {
00603 m_parent_plotter = plotter;
00604 }
00605
00606 void
00607 PlotterBase::
00608 setEnableZ ( bool )
00609 {
00610
00611 }
00612
00613 void
00614 PlotterBase::
00615 setAutoTicks ( hippodraw::Axes::Type, bool )
00616 {
00617
00618 }
00619
00620 void
00621 PlotterBase::
00622 setTicks ( hippodraw::Axes::Type, const std::vector < AxisTick > & )
00623 {
00624 }
00625
00626 void
00627 PlotterBase::
00628 setAutoTicksOnX ( bool yes )
00629 {
00630 setAutoTicks ( Axes::X, yes );
00631 }
00632
00633 void
00634 PlotterBase::
00635 setAutoTicks ( const std::string & axis, bool yes )
00636 {
00637 Axes::Type type = Axes::convert ( axis );
00638 setAutoTicks ( type, yes );
00639 }
00640
00641 void
00642 PlotterBase::
00643 setTicksOnX ( const std::vector < double > & values,
00644 const std::vector < std::string > & labels )
00645 {
00646 unsigned int size = values.size ();
00647 vector < AxisTick > ticks ( size );
00648
00649 for ( unsigned int i = 0; i < size; i++ ) {
00650 ticks[i].setValue ( values[i] );
00651 ticks[i].setContent ( labels[i] );
00652 }
00653
00654 setTicks ( Axes::X, ticks );
00655 }
00656
00657 void
00658 PlotterBase::
00659 setTicks ( const std::string & axis,
00660 const std::vector < double > & values,
00661 const std::vector < std::string > & labels )
00662 {
00663 unsigned int size = values.size ();
00664 vector < AxisTick > ticks ( size );
00665
00666 for ( unsigned int i = 0; i < size; i++ ) {
00667 ticks[i].setValue ( values[i] );
00668 ticks[i].setContent ( labels[i] );
00669 }
00670 Axes::Type type = Axes::convert ( axis );
00671
00672 setTicks ( type, ticks );
00673 }
00674
00675 double
00676 PlotterBase::
00677 getLowRangeOnX () const
00678 {
00679 const Range & range = getRange ( Axes::X, true );
00680
00681 return range.low ();
00682 }
00683
00684 double
00685 PlotterBase::
00686 getHighRangeOnX () const
00687 {
00688 const Range & range = getRange ( Axes::X, true );
00689
00690 return range.high ();
00691 }
00692
00693 void
00694 PlotterBase::
00695 matrixTranspose ( bool )
00696 {
00697
00698 }
00699
00700 bool
00701 PlotterBase::
00702 isTargetable () const
00703 {
00704 return false;
00705 }
00706
00707 DataRep *
00708 PlotterBase::
00709 getTarget () const
00710 {
00711 return 0;
00712 }
00713
00714 int
00715 PlotterBase::
00716 indexOf ( const DataRep * ) const
00717 {
00718 return -1;
00719 }
00720
00721 void
00722 PlotterBase::
00723 toggleActivePlot ()
00724 {
00725 int to_select = 0;
00726 int number = getNumDataReps ();
00727
00728 if ( number > 1 ) {
00729 to_select = activePlotIndex ();
00730 to_select++;
00731
00732 if ( to_select == number ) {
00733 to_select = -1;
00734 }
00735 setActivePlot ( to_select, true );
00736 }
00737 }
00738
00739 void
00740 PlotterBase::
00741 setPlotterId ()
00742 {
00743 m_plotterId = s_plotters;
00744 s_plotters++;
00745 }
00746
00747 int
00748 PlotterBase::
00749 plotterId () const
00750 {
00751 return m_plotterId;
00752 }
00753
00754 int
00755 PlotterBase::
00756 saveView ( const std::vector<double> & range_values )
00757 {
00758 if (range_values.size() != 4) {
00759 throw PlotterException("PlotterBase::saveView: "
00760 "Invalid number of range values.");
00761 }
00762 m_views.push_back(range_values);
00763
00764 m_currentView = static_cast<int>(m_views.size() - 1);
00765
00766 return m_currentView;
00767 }
00768
00769 int
00770 PlotterBase::
00771 saveViewAtIndex ( const std::vector<double> & range_values , unsigned int i )
00772 {
00773 if ( i > m_views.size() ) {
00774 i = 0;
00775 }
00776
00777 if (range_values.size() != 4) {
00778 throw PlotterException("PlotterBase::saveView: "
00779 "Invalid number of range values.");
00780 }
00781 vector < vector < double > > :: iterator iter = m_views.begin ();
00782 advance ( iter, i );
00783 m_views.insert( iter , range_values);
00784
00785 for ( unsigned int k = m_views.size() - 1 ; k>i; k--) {
00786 m_views.pop_back();
00787 }
00788 m_currentView = static_cast<int>( i );
00789
00790 return m_currentView;
00791 }
00792
00793
00794 int
00795 PlotterBase::
00796 nextView ( bool stepForward )
00797 {
00798 if (m_views.size() == 0) {
00799 return -1;
00800 }
00801 if (stepForward) {
00802 m_currentView += 1;
00803 if (m_currentView >= static_cast<int>(m_views.size())) {
00804 m_currentView = 0;
00805 }
00806 } else {
00807 m_currentView -= 1;
00808 if (m_currentView <= -1) {
00809 m_currentView = m_views.size() - 1;
00810 }
00811 }
00812 setView(m_currentView);
00813 return m_currentView;
00814 }
00815
00816
00817
00818 void
00819 PlotterBase::
00820 setView ( int index )
00821 {
00822 if ( m_views.size() == 0 || index < 0 ||
00823 index >= static_cast<int>(m_views.size()) ) {
00824 string what ( "PlotterBase::setView: Invalid plot view index " );
00825 what += String::convert ( index );
00826 what += ".";
00827 throw PlotterException ( what );
00828 }
00829 setRange("x", m_views[index][0], m_views[index][1]);
00830 setRange("y", m_views[index][2], m_views[index][3]);
00831 m_currentView = index;
00832 }
00833
00834 int
00835 PlotterBase::
00836 numViews () const
00837 {
00838 return static_cast<int>(m_views.size());
00839 }
00840
00841 void
00842 PlotterBase::
00843 deleteView ( int index )
00844 {
00845 std::vector< std::vector<double> > views;
00846 for (unsigned int i = 0; i < m_views.size(); i++) {
00847 if (static_cast<int>(i) != index) {
00848 views.push_back(m_views[i]);
00849 }
00850 }
00851 m_views = views;
00852 index--;
00853 if (index > 0 && m_views.size() > 0) {
00854 setView(index);
00855 }
00856 }
00857
00858 int
00859 PlotterBase::
00860 currentView () const
00861 {
00862 return m_currentView;
00863 }
00864
00865 void
00866 PlotterBase::
00867 fillCutList ( std::vector < const TupleCut * > & ) const
00868 {
00869
00870 }
00871
00872 void
00873 PlotterBase::
00874 setCutRangeAt ( const Range &, unsigned int )
00875 {
00876
00877 }
00878
00879 void
00880 PlotterBase::
00881 setCurrentRangeSaved( bool flag )
00882 {
00883 current_range_saved = flag;
00884 }
00885
00886 bool
00887 PlotterBase::
00888 getCurrentRangeSaved( )
00889 {
00890 return current_range_saved ;
00891 }
00892
00893 Range
00894 PlotterBase::
00895 getDataRange( hippodraw::Axes::Type axis )
00896 {
00897 ProjectorBase * proj = activeProjector ();
00898 Range r = proj -> dataRangeOn ( axis );
00899 return r;
00900 }
00901
00902 const std::vector <double> &
00903 PlotterBase::
00904 getZValues()
00905 {
00906 ProjectorBase * proj = activeProjector ();
00907 return ( proj -> getZValues () );
00908 }
00909
00910 const std::vector <unsigned int> &
00911 PlotterBase::
00912 getShape()
00913 {
00914 ProjectorBase * proj = activeProjector();
00915 return ( proj -> getShape() );
00916 }
00917
00918 void
00919 PlotterBase::
00920 setShowGrid( bool flag )
00921 {
00922
00923 }
00924
00925 void
00926 PlotterBase::
00927 setBoxEdge( bool flag )
00928 {
00929 }
00930
00931 bool
00932 PlotterBase::
00933 getBoxEdge()
00934 {
00935 return false;
00936 }
00937
00938 bool
00939 PlotterBase::
00940 getShowGrid ()
00941 {
00942 return false;
00943 }
00944
00945 void
00946 PlotterBase::
00947 setFitsTransform ( const std::string & transform )
00948 {
00949 }
00950
00951 TransformBase *
00952 PlotterBase::
00953 getFitsTransform () const
00954 {
00955 return 0;
00956 }
00957
00958 void
00959 PlotterBase::
00960 setMinEntries(int entries)
00961 {
00962 }
00963
00964 int
00965 PlotterBase::
00966 getMinEntries ()
00967 {
00968 return -1;
00969 }
00970
00971 const FontBase *
00972 PlotterBase::
00973 titleFont( ) const
00974 {
00975 return NULL;
00976 }
00977
00978 FontBase*
00979 PlotterBase::
00980 labelFont ( hippodraw::Axes::Type axes ) const
00981 {
00982 return NULL;
00983 }
00984
00985 bool
00986 PlotterBase::
00987 isImageConvertable () const
00988 {
00989 return false;
00990 }
00991
00992 bool
00993 PlotterBase::
00994 isTextPlotter() const
00995 {
00996 return false;
00997 }
00998
00999
01000 double
01001 PlotterBase::
01002 getTopMargin()
01003 {
01004 return 0.0;
01005 }
01006
01007 double
01008 PlotterBase::
01009 getZMargin()
01010 {
01011 return 0.0;
01012 }
01013
01014 double
01015 PlotterBase::
01016 getBottomMargin()
01017 {
01018 return 0.0;
01019 }
01020
01021 double
01022 PlotterBase::
01023 getLeftMargin()
01024 {
01025 return 0.0;
01026 }
01027
01028 void
01029 PlotterBase::
01030 setTopMargin( double top )
01031 {
01032
01033 }
01034
01035 void
01036 PlotterBase::
01037 setZMargin( double z )
01038 {
01039
01040 }
01041
01042 void
01043 PlotterBase::
01044 setBottomMargin( double bottom )
01045 {
01046
01047 }
01048
01049 void
01050 PlotterBase::
01051 setLeftMargin( double left )
01052 {
01053
01054 }
01055
01056 void
01057 PlotterBase::
01058 setNeedUpdate(bool isChanged)
01059 {
01060
01061 }
01062
01063 double
01064 PlotterBase::
01065 getScaleFactor ( hippodraw::Axes::Type axis ) const
01066 {
01067 return 1.0;
01068 }
01069
01070 bool
01071 PlotterBase::
01072 isAxisScaled ( hippodraw::Axes::Type axis ) const
01073 {
01074 return false;
01075 }