PlotterBase.cxx
Go to the documentation of this file.
1 
12 // for truncation warning in debug mode
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #include "PlotterBase.h"
18 #include "PlotterException.h"
19 
20 #include "axes/AxisTick.h"
21 #include "datareps/DataRep.h"
23 #include "pattern/string_convert.h"
24 
25 using namespace hippodraw;
26 
27 using std::string;
28 using std::vector;
29 
31 
34  : m_aspect_ratio ( 0.0 ),
35  m_name ( "" ),
36  m_title( "%t" ),
37  m_crossX ( 0 ),
38  m_crossY ( 0 ),
39  m_parent_plotter( 0 ),
40  m_parent_datarep_index( -1 )
41 
42 {
43  current_range_saved = false;
44  setPlotterId();
45 }
46 
48 PlotterBase ( const std::string & name )
49  : m_aspect_ratio ( 0.0 ),
50  m_name ( name ),
51  m_title( "%t" ),
52  m_crossX ( 0 ),
53  m_crossY ( 0 ),
54  m_parent_plotter( 0 ),
55  m_parent_datarep_index( -1 )
56 
57 {
58  current_range_saved = false;
59  setPlotterId();
60 }
61 
63  : Observer (),
64  Observable (),
65  m_aspect_ratio ( plotter.m_aspect_ratio ),
66  m_name ( plotter.m_name ),
67  m_title( plotter.m_title ),
68  m_parent_plotter( plotter.m_parent_plotter ),
69  m_parent_datarep_index( plotter.m_parent_datarep_index ),
70  m_views( plotter.m_views ),
71  m_currentView( plotter.m_currentView )
72 
73 {
74  current_range_saved = false;
75  setPlotterId();
76 }
77 
79 {
81 }
82 
83 const string & PlotterBase::name () const
84 {
85  return m_name;
86 }
87 
88 /* virtual */
90 {
91  notifyObservers ();
92 }
93 
94 void
97 {
98  // does nothing
99 }
100 
101 bool
104 {
105  return false;
106 }
107 
108 bool
110 hasZoomY ( ) const
111 {
112  return true;
113 }
114 
115 
119 {
120  return 0;
121 }
122 
124 {
125 }
126 
128 {
129  return 0;
130 }
131 
133 {
134  return false;
135 }
136 
138 {
139  return 0;
140 }
141 
144 getProjector ( int ) const
145 {
146  return 0;
147 }
148 
150 {
151  return 0;
152 }
153 
154 DataRep *
156 getDataRep ( int ) const
157 {
158  return 0;
159 }
160 
162 {
163  return 0;
164 }
165 
166 void
169 {
170 }
171 
172 void
174 setActivePlot ( int, bool )
175 {
176  // Only CompositePlotter responds to this.
177 }
178 
180 {
181  return 0;
182 }
183 
185 {
186  // Only the composite plotters respond.
187 }
188 
189 const BinToColor *
191 getValueRep () const
192 {
193  return 0;
194 }
195 
196 void
199 {
200  // do nothing
201 }
202 
203 void
205 setAutoRanging ( const std::string & axis, bool flag )
206 {
207  Axes::Type at = Axes::convert ( axis );
208  setAutoRanging ( at, flag );
209 
210  autoScale ();
211 }
212 
213 /* @bug @@@ When the histogram weight is set using the Inspector, this
214  assert fails and the program crashes.
215 
216  @request @@@ Could we change all asserts of this to type (I count
217  about 80 of them throughout the code) to tests which throw a
218  run-time error exception instead?
219 */
220 void
223 {
224 }
225 
226 /* virtual dummy holder for non-composite displays */
227 void
230 {
231 }
232 
233 bool
236 {
237  return false;
238 }
239 
240 void
242 setReverse ( bool )
243 {
244 }
245 
246 bool
248 isReverse ( ) const
249 {
250  return false;
251 }
252 
253 void PlotterBase::setTitle( const std::string & title )
254 {
255  if ( title != "%t" ) {
256  m_title = title;
257  } else {
258  int index = activePlotIndex ();
259  if ( index > -1 ) {
260  if ( index == -1 ) index = 0;
261  DataRep * rep = getDataRep ( index );
262  // could be zero during initialization from document file
263  if ( rep != 0 ) rep -> setTitle ( title );
264  }
265  }
266 
267  notifyObservers ();
268 }
269 
270 const string & PlotterBase::getTitle() const
271 {
272  if ( m_title != "%t" ) {
273  return m_title;
274  }
275  int index = activePlotIndex ();
276  if ( index < 0 ) index = 0;
277  const DataRep * rep = getDataRep ( index );
278 
279  return rep -> getTitle ();
280 }
281 
282 void PlotterBase::setLabel ( const std::string & axis,
283  const std::string & label )
284 {
285  Axes::Type type = Axes::convert ( axis );
286  setLabel ( type, label );
287 
288  notifyObservers ();
289 }
290 
291 void
293 setLabel ( hippodraw::Axes::Type, const std::string & )
294 {
295 }
296 
297 const string &
300 {
301  static string s;
302 
303  return s;
304 }
305 
306 const string &
309 {
310  return m_title;
311 }
312 
313 const string &
316 {
317  static string s;
318 
319  return s;
320 }
321 
323 {
324 // do nothing
325 }
326 
327 void
329 setRange ( const std::string & axis, double low, double high )
330 {
331  Axes::Type type = Axes::convert ( axis );
332  const Range range ( low, high );
333 
334  setRange ( type, range, true, true );
335 }
336 
337 void
340  bool, bool )
341 {
342 }
343 
345  int, bool )
346 {
347 
348 }
349 
351  int, bool )
352 {
353 }
354 
357 const Range &
360 {
361  static Range range;
362 
363  return range;
364 }
365 
366 void
369 {
370  // does nothing
371 }
372 
373 void
376 {
377  // does nothing
378 }
379 
380 void
382 setBinWidth ( Axes::Type axis, int parm, bool dragging )
383 {
384  int index = activePlotIndex ();
385  index = std::max ( 0, index );
386 
387  ProjectorBase * projector = getProjector ( index );
388  const Range & range = projector -> setBinWidth ( axis, parm, dragging );
389 
390  setRange ( axis, range, false );
391 }
392 
393 void
396 {
397  // does nothing
398 }
399 
400 void
402 setBinWidth ( const std::string & axis, double width )
403 {
404  Axes::Type at = Axes::convert ( axis );
405  setBinWidth ( at, width );
406 }
407 
408 void
410 setOffset ( const std::string & axis, double offset )
411 {
412  Axes::Type at = Axes::convert ( axis );
413  setOffset ( at, offset );
414 }
415 
416 void
418 setNumberOfBins ( const std::string & axis, unsigned int number )
419 {
420  Axes::Type at = Axes::convert ( axis );
421  setNumberOfBins ( at, number );
422 }
423 
424 void
426 reset ( )
427 {
428  // does nothing
429 }
430 
431 const Rect &
433 getUserRect() const
434 {
435  return m_user_rect;
436 }
437 
438 const Rect &
440 getRawRect() const
441 {
442  return m_raw_rect;
443 }
444 
445 void
448 {
449 }
450 
451 void
454 {
455 }
456 
457 double
459 getBinWidth ( const std::string & axis ) const
460 {
461  Axes::Type type = Axes::convert ( axis );
462 
463  return getBinWidth ( type );
464 }
465 
466 double
469 {
470  return 1.0;
471 }
472 
473 double
476 {
477  return 1.0;
478 }
479 
480 double
482 getOffset ( const std::string & axis ) const
483 {
484  Axes::Type type = Axes::convert ( axis );
485 
486  return getOffset ( type );
487 }
488 
489 int
492 {
493  return 0;
494 }
495 
496 int
499 {
500  return getNumberOfEntries ();
501 }
502 
504 {
505 // do nothing
506 }
507 
508 double
511 {
512  return DBL_EPSILON;
513 }
514 
515 double PlotterBase::getZValue ( double , double , bool ) const
516 {
517  return 0.0;
518 }
519 
520 void PlotterBase::setCrossX ( double val )
521 {
522  m_crossX = val;
523 }
524 
525 void PlotterBase::setCrossY ( double val )
526 {
527  m_crossY = val;
528 }
529 
530 void
533 {
534  // does nothing
535 }
536 
537 void
539 addValues ( const std::vector < double > & )
540 {
541  // do nothing
542 }
543 
544 double
547 {
548  return m_aspect_ratio;
549 }
550 
551 void
553 setAspectRatio ( double ratio )
554 {
555  m_aspect_ratio = ratio;
556  notifyObservers ();
557 }
558 
559 bool
561 wantsPixmap ( ) const
562 {
563  return false;
564 }
565 
566 NTuple *
569 {
570  return 0;
571 }
572 
573 void
575 fillPickedPointFrom ( double, double,
576  std::vector < double > & ) const
577 {
578 }
579 
580 void PlotterBase::setOffsets( double xoffset, double yoffset )
581 {
582  setOffset ( Axes::X, xoffset );
583  setOffset ( Axes::Y, yoffset );
584 }
585 
587 {
588  return m_parent_datarep_index;
589 }
590 
592 {
593  m_parent_datarep_index = index;
594 }
595 
597 {
598  return m_parent_plotter;
599 }
600 
602 {
603  m_parent_plotter = plotter;
604 }
605 
606 void
608 setEnableZ ( bool )
609 {
610  // do nothing
611 }
612 
613 void
616 {
617  // do nothing
618 }
619 
620 void
622 setTicks ( hippodraw::Axes::Type, const std::vector < AxisTick > & )
623 {
624 }
625 
626 void
628 setAutoTicksOnX ( bool yes )
629 {
630  setAutoTicks ( Axes::X, yes );
631 }
632 
633 void
635 setAutoTicks ( const std::string & axis, bool yes )
636 {
637  Axes::Type type = Axes::convert ( axis );
638  setAutoTicks ( type, yes );
639 }
640 
641 void
643 setTicksOnX ( const std::vector < double > & values,
644  const std::vector < std::string > & labels )
645 {
646  unsigned int size = values.size ();
647  vector < AxisTick > ticks ( size );
648 
649  for ( unsigned int i = 0; i < size; i++ ) {
650  ticks[i].setValue ( values[i] );
651  ticks[i].setContent ( labels[i] );
652  }
653 
654  setTicks ( Axes::X, ticks );
655 }
656 
657 void
659 setTicks ( const std::string & axis,
660  const std::vector < double > & values,
661  const std::vector < std::string > & labels )
662 {
663  unsigned int size = values.size ();
664  vector < AxisTick > ticks ( size );
665 
666  for ( unsigned int i = 0; i < size; i++ ) {
667  ticks[i].setValue ( values[i] );
668  ticks[i].setContent ( labels[i] );
669  }
670  Axes::Type type = Axes::convert ( axis );
671 
672  setTicks ( type, ticks );
673 }
674 
675 double
678 {
679  const Range & range = getRange ( Axes::X, true ); // scaled range
680 
681  return range.low ();
682 }
683 
684 double
687 {
688  const Range & range = getRange ( Axes::X, true ); // scaled range
689 
690  return range.high ();
691 }
692 
693 void
696 {
697  // do nothing
698 }
699 
700 bool
702 isTargetable () const
703 {
704  return false;
705 }
706 
707 DataRep *
709 getTarget () const
710 {
711  return 0;
712 }
713 
714 int
716 indexOf ( const DataRep * ) const
717 {
718  return -1;
719 }
720 
721 void
724 {
725  int to_select = 0;
726  int number = getNumDataReps ();
727 
728  if ( number > 1 ) {
729  to_select = activePlotIndex ();
730  to_select++;
731 
732  if ( to_select == number ) {
733  to_select = -1;
734  }
735  setActivePlot ( to_select, true );
736  }
737 }
738 
739 void
742 {
744  s_plotters++;
745 }
746 
747 int
749 plotterId () const
750 {
751  return m_plotterId;
752 }
753 
754 int
756 saveView ( const std::vector<double> & range_values )
757 {
758  if (range_values.size() != 4) {
759  throw PlotterException("PlotterBase::saveView: "
760  "Invalid number of range values.");
761  }
762  m_views.push_back(range_values);
763 
764  m_currentView = static_cast<int>(m_views.size() - 1);
765 
766  return m_currentView;
767 }
768 
769 int
771 saveViewAtIndex ( const std::vector<double> & range_values , unsigned int i )
772 {
773  if ( i > m_views.size() ) {
774  i = 0;
775  }
776 
777  if (range_values.size() != 4) {
778  throw PlotterException("PlotterBase::saveView: "
779  "Invalid number of range values.");
780  }
781  vector < vector < double > > :: iterator iter = m_views.begin ();
782  advance ( iter, i );
783  m_views.insert( iter , range_values);
784 
785  for ( unsigned int k = m_views.size() - 1 ; k>i; k--) {
786  m_views.pop_back();
787  }
788  m_currentView = static_cast<int>( i );
789 
790  return m_currentView;
791 }
792 
793 
794 int
796 nextView ( bool stepForward )
797 {
798  if (m_views.size() == 0) {
799  return -1;
800  }
801  if (stepForward) {
802  m_currentView += 1;
803  if (m_currentView >= static_cast<int>(m_views.size())) {
804  m_currentView = 0;
805  }
806  } else {
807  m_currentView -= 1;
808  if (m_currentView <= -1) {
809  m_currentView = m_views.size() - 1;
810  }
811  }
813  return m_currentView;
814 }
815 
816 
817 
818 void
820 setView ( int index )
821 {
822  if ( m_views.size() == 0 || index < 0 ||
823  index >= static_cast<int>(m_views.size()) ) {
824  string what ( "PlotterBase::setView: Invalid plot view index " );
825  what += String::convert ( index );
826  what += ".";
827  throw PlotterException ( what );
828  }
829  setRange("x", m_views[index][0], m_views[index][1]);
830  setRange("y", m_views[index][2], m_views[index][3]);
831  m_currentView = index;
832 }
833 
834 int
836 numViews () const
837 {
838  return static_cast<int>(m_views.size());
839 }
840 
841 void
843 deleteView ( int index )
844 {
845  std::vector< std::vector<double> > views;
846  for (unsigned int i = 0; i < m_views.size(); i++) {
847  if (static_cast<int>(i) != index) {
848  views.push_back(m_views[i]);
849  }
850  }
851  m_views = views;
852  index--;
853  if (index > 0 && m_views.size() > 0) {
854  setView(index);
855  }
856 }
857 
858 int
860 currentView () const
861 {
862  return m_currentView;
863 }
864 
865 void
867 fillCutList ( std::vector < const TupleCut * > & ) const
868 {
869  // do nothing.
870 }
871 
872 void
874 setCutRangeAt ( const Range &, unsigned int )
875 {
876  // do nothing
877 }
878 
879 void
882 {
883  current_range_saved = flag;
884 }
885 
886 bool
889 {
890  return current_range_saved ;
891 }
892 
893 Range
896 {
897  ProjectorBase * proj = activeProjector ();
898  Range r = proj -> dataRangeOn ( axis );
899  return r;
900 }
901 
902 const std::vector <double> &
905 {
906  ProjectorBase * proj = activeProjector ();
907  return ( proj -> getZValues () );
908 }
909 
910 const std::vector <unsigned int> &
913 {
914  ProjectorBase * proj = activeProjector();
915  return ( proj -> getShape() );
916 }
917 
918 void
920 setShowGrid( bool flag )
921 {
922 
923 }
924 
925 void
927 setBoxEdge( bool flag )
928 {
929 }
930 
931 bool
934 {
935  return false;
936 }
937 
938 bool
941 {
942  return false;
943 }
944 
945 void
947 setFitsTransform ( const std::string & transform )
948 {
949 }
950 
954 {
955  return 0;
956 }
957 
958 void
960 setMinEntries(int entries)
961 {
962 }
963 
964 int
967 {
968  return -1;
969 }
970 
971 const FontBase *
973 titleFont( ) const
974 {
975  return NULL;
976 }
977 
978 FontBase*
981 {
982  return NULL;
983 }
984 
985 bool
988 {
989  return false;
990 }
991 
992 bool
995 {
996  return false;
997 }
998 
999 
1000 double
1003 {
1004  return 0.0;
1005 }
1006 
1007 double
1010 {
1011  return 0.0;
1012 }
1013 
1014 double
1017 {
1018  return 0.0;
1019 }
1020 
1021 double
1024 {
1025  return 0.0;
1026 }
1027 
1028 void
1030 setTopMargin( double top )
1031 {
1032  // Do nothing
1033 }
1034 
1035 void
1037 setZMargin( double z )
1038 {
1039  // Do nothing
1040 }
1041 
1042 void
1044 setBottomMargin( double bottom )
1045 {
1046  // Do nothing
1047 }
1048 
1049 void
1051 setLeftMargin( double left )
1052 {
1053  // Do nothing
1054 }
1055 
1056 void
1058 setNeedUpdate(bool isChanged)
1059 {
1060  // Do nothing
1061 }
1062 
1063 double
1066 {
1067  return 1.0;
1068 }
1069 
1070 bool
1073 {
1074  return false;
1075 }

Generated for HippoDraw Class Library by doxygen