Panda3D
gtkStatsMonitor.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 gtkStatsMonitor.h
10  * @author drose
11  * @date 2006-01-16
12  */
13 
14 #ifndef GTKSTATSMONITOR_H
15 #define GTKSTATSMONITOR_H
16 
17 #include "pandatoolbase.h"
18 
19 #include "gtkStatsGraph.h"
20 #include "pStatMonitor.h"
21 #include "pointerTo.h"
22 #include "pset.h"
23 #include "pvector.h"
24 #include "pmap.h"
25 
26 #include <gtk/gtk.h>
27 
28 class GtkStatsServer;
29 class GtkStatsChartMenu;
30 
31 /**
32  * This class represents a connection to a PStatsClient and manages the data
33  * exchange with the client.
34  */
35 class GtkStatsMonitor : public PStatMonitor {
36 public:
37  class MenuDef {
38  public:
39  INLINE MenuDef(int thread_index, int collector_index, bool show_level);
40  INLINE bool operator < (const MenuDef &other) const;
41 
42  int _thread_index;
43  int _collector_index;
44  bool _show_level;
45  GtkStatsMonitor *_monitor;
46  };
47 
49  virtual ~GtkStatsMonitor();
50 
51  virtual std::string get_monitor_name();
52 
53  virtual void initialized();
54  virtual void got_hello();
55  virtual void got_bad_version(int client_major, int client_minor,
56  int server_major, int server_minor);
57  virtual void new_collector(int collector_index);
58  virtual void new_thread(int thread_index);
59  virtual void new_data(int thread_index, int frame_number);
60  virtual void lost_connection();
61  virtual void idle();
62  virtual bool has_idle();
63 
64  virtual void user_guide_bars_changed();
65 
66  GtkWidget *get_window() const;
67  void open_strip_chart(int thread_index, int collector_index, bool show_level);
68  void open_piano_roll(int thread_index);
69 
70  const MenuDef *add_menu(const MenuDef &menu_def);
71 
72  void set_time_units(int unit_mask);
73  void set_scroll_speed(double scroll_speed);
74  void set_pause(bool pause);
75 
76 private:
77  void add_graph(GtkStatsGraph *graph);
78  void remove_graph(GtkStatsGraph *graph);
79 
80  void create_window();
81  void shutdown();
82  static gboolean window_delete_event(GtkWidget *widget, GdkEvent *event,
83  gpointer data);
84  static void window_destroy(GtkWidget *widget, gpointer data);
85  void setup_frame_rate_label();
86 
87  static void handle_menu_command(gpointer callback_data, guint menu_id, GtkWidget *widget);
88 
90  Graphs _graphs;
91 
93  ChartMenus _chart_menus;
94 
95  typedef pset<MenuDef> Menus;
96  Menus _menus;
97 
98  GtkWidget *_window;
99  GtkItemFactory *_item_factory;
100  int _next_chart_index;
101  GtkWidget *_frame_rate_menu_item;
102  GtkWidget *_frame_rate_label;
103  std::string _window_title;
104  int _time_units;
105  double _scroll_speed;
106  bool _pause;
107 
108  static GtkItemFactoryEntry menu_entries[];
109  static int num_menu_entries;
110 
111  friend class GtkStatsGraph;
112 };
113 
114 #include "gtkStatsMonitor.I"
115 
116 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void new_thread(int thread_index)
Called whenever a new Thread definition is received from the client.
virtual void got_hello()
Called when the "hello" message has been received from the client.
void open_piano_roll(int thread_index)
Opens a new piano roll showing the indicated data.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The class that owns the main loop, waiting for client connections.
virtual void got_bad_version(int client_major, int client_minor, int server_major, int server_minor)
Like got_hello(), this is called when the "hello" message has been received from the client.
virtual void user_guide_bars_changed()
Called when the user guide bars have been changed.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
virtual std::string get_monitor_name()
Should be redefined to return a descriptive name for the type of PStatsMonitor this is.
A pulldown menu of charts available for a particular thread.
This is just an abstract base class to provide a common pointer type for the various kinds of graphs ...
Definition: gtkStatsGraph.h:29
const MenuDef * add_menu(const MenuDef &menu_def)
Adds a new MenuDef to the monitor, or returns an existing one if there is already one just like it.
This class represents a connection to a PStatsClient and manages the data exchange with the client.
void open_strip_chart(int thread_index, int collector_index, bool show_level)
Opens a new strip chart showing the indicated data.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_time_units(int unit_mask)
Called when the user selects a new time units from the monitor pulldown menu, this should adjust the ...
virtual void initialized()
Called after the monitor has been fully set up.
virtual void new_data(int thread_index, int frame_number)
Called as each frame's data is made available.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
GtkWidget * get_window() const
Returns the window handle to the monitor's window.
virtual void lost_connection()
Called whenever the connection to the client has been lost.
virtual bool has_idle()
Should be redefined to return true if you want to redefine idle() and expect it to be called.
virtual void idle()
If has_idle() returns true, this will be called periodically to allow the monitor to update its displ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_scroll_speed(double scroll_speed)
Called when the user selects a new scroll speed from the monitor pulldown menu, this should adjust th...
virtual void new_collector(int collector_index)
Called whenever a new Collector definition is received from the client.
void set_pause(bool pause)
Called when the user selects a pause on or pause off option from the menu.