Panda3D
pStatGraph.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file pStatGraph.h
10  * @author drose
11  * @date 2000-07-19
12  */
13 
14 #ifndef PSTATGRAPH_H
15 #define PSTATGRAPH_H
16 
17 #include "pandatoolbase.h"
18 
19 #include "pStatMonitor.h"
20 #include "pStatClientData.h"
21 
22 #include "luse.h"
23 #include "vector_int.h"
24 
25 #include "pmap.h"
26 
27 class PStatView;
28 
29 /**
30  * This is an abstract base class for several different kinds of graphs that
31  * have a few things in common, like labels and guide bars.
32  */
33 class PStatGraph {
34 public:
35  PStatGraph(PStatMonitor *monitor, int xsize, int ysize);
36  virtual ~PStatGraph();
37 
38  INLINE PStatMonitor *get_monitor() const;
39 
40  INLINE int get_num_labels() const;
41  INLINE int get_label_collector(int n) const;
42  INLINE std::string get_label_name(int n) const;
43  INLINE LRGBColor get_label_color(int n) const;
44 
45  INLINE void set_target_frame_rate(double frame_rate);
46  INLINE double get_target_frame_rate() const;
47 
48  INLINE int get_xsize() const;
49  INLINE int get_ysize() const;
50 
51  enum GuideBarStyle {
52  GBS_normal,
53  GBS_target,
54  GBS_user,
55  };
56 
57  class GuideBar {
58  public:
59  GuideBar(double height, const std::string &label, GuideBarStyle style);
60  GuideBar(const GuideBar &copy);
61 
62  double _height;
63  std::string _label;
64  GuideBarStyle _style;
65  };
66 
67  enum GuideBarUnits {
68  GBU_hz = 0x0001,
69  GBU_ms = 0x0002,
70  GBU_named = 0x0004,
71  GBU_show_units = 0x0008,
72  };
73 
74  int get_num_guide_bars() const;
75  const GuideBar &get_guide_bar(int n) const;
76 
77  int get_num_user_guide_bars() const;
78  GuideBar get_user_guide_bar(int n) const;
79  void move_user_guide_bar(int n, double height);
80  int add_user_guide_bar(double height);
81  void remove_user_guide_bar(int n);
82  int find_user_guide_bar(double from_height, double to_height) const;
83 
84  INLINE void set_guide_bar_units(int unit_mask);
85  INLINE int get_guide_bar_units() const;
86  INLINE void set_guide_bar_unit_name(const std::string &unit_name);
87  INLINE const std::string &get_guide_bar_unit_name() const;
88 
89  static std::string format_number(double value);
90  static std::string format_number(double value, int guide_bar_units,
91  const std::string &unit_name = std::string());
92 
93 protected:
94  virtual void normal_guide_bars()=0;
95  void update_guide_bars(int num_bars, double scale);
96  GuideBar make_guide_bar(double value, GuideBarStyle style = GBS_normal) const;
97 
98  bool _labels_changed;
99  bool _guide_bars_changed;
100 
101  PT(PStatMonitor) _monitor;
102 
103  double _target_frame_rate;
104 
105  int _xsize;
106  int _ysize;
107 
108  // Table of the collectors that should be drawn as labels, in order from
109  // bottom to top.
110  typedef vector_int Labels;
111  Labels _labels;
112 
113  typedef pvector<GuideBar> GuideBars;
114  GuideBars _guide_bars;
115  int _guide_bar_units;
116  std::string _unit_name;
117 };
118 
119 #include "pStatGraph.I"
120 
121 #endif
int get_xsize() const
Returns the width of the chart in pixels.
Definition: pStatGraph.I:82
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_guide_bar_units() const
Returns the units that are displayed for the guide bar labels.
Definition: pStatGraph.I:111
void set_guide_bar_units(int unit_mask)
Sets the units that are displayed for the guide bar labels.
Definition: pStatGraph.I:99
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_ysize() const
Returns the height of the chart in pixels.
Definition: pStatGraph.I:90
int get_num_labels() const
Returns the number of labels to be drawn for this chart.
Definition: pStatGraph.I:26
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::string get_label_name(int n) const
Returns the text associated with the nth label.
Definition: pStatGraph.I:43
void move_user_guide_bar(int n, double height)
Adjusts the height of the nth user-defined guide bar.
Definition: pStatGraph.cxx:117
This is an abstract base class for several different kinds of graphs that have a few things in common...
Definition: pStatGraph.h:33
int find_user_guide_bar(double from_height, double to_height) const
Returns the index number of the first user guide bar found whose height is within the indicated range...
Definition: pStatGraph.cxx:144
double get_target_frame_rate() const
Returns the indicated target frame rate in Hz.
Definition: pStatGraph.I:74
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatMonitor * get_monitor() const
Returns the monitor associated with this chart.
Definition: pStatGraph.I:18
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is an abstract class that presents the interface to any number of different front-ends for the s...
Definition: pStatMonitor.h:39
const GuideBar & get_guide_bar(int n) const
Returns the nth horizontal guide bar.
Definition: pStatGraph.cxx:87
A View boils down the frame data to a linear list of times spent in a number of different Collectors,...
Definition: pStatView.h:31
int get_label_collector(int n) const
Returns the collector index associated with the nth label.
Definition: pStatGraph.I:34
int get_num_guide_bars() const
Returns the number of horizontal guide bars that should be drawn, based on the indicated target frame...
Definition: pStatGraph.cxx:75
const std::string & get_guide_bar_unit_name() const
Returns the name of the units to be used for the guide bars if the units type is set to GBU_named | G...
Definition: pStatGraph.I:129
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_guide_bar_unit_name(const std::string &unit_name)
Sets the name of the units to be used for the guide bars if the units type is set to GBU_named | GBU_...
Definition: pStatGraph.I:120
void set_target_frame_rate(double frame_rate)
Sets the target frame rate of the application in Hz.
Definition: pStatGraph.I:62
int add_user_guide_bar(double height)
Creates a new user guide bar and returns its index number.
Definition: pStatGraph.cxx:125
static std::string format_number(double value)
Returns a string representing the value nicely formatted for its range.
Definition: pStatGraph.cxx:153
GuideBar get_user_guide_bar(int n) const
Returns the nth user-defined guide bar.
Definition: pStatGraph.cxx:108
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LRGBColor get_label_color(int n) const
Returns the color associated with the nth label.
Definition: pStatGraph.I:52
int get_num_user_guide_bars() const
Returns the current number of user-defined guide bars.
Definition: pStatGraph.cxx:100
void remove_user_guide_bar(int n)
Removes the user guide bar with the indicated index number.
Definition: pStatGraph.cxx:134