Choreonoid  1.8
GraphWidget.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_BASE_GRAPH_WIDGET_H
6 #define CNOID_BASE_GRAPH_WIDGET_H
7 
8 #include <cnoid/Archive>
9 #include <QWidget>
10 #include <QLabel>
11 #include <memory>
12 #include <string>
13 #include <vector>
14 #include "exportdecl.h"
15 
16 namespace cnoid {
17 
18 class View;
19 class ToolBar;
20 class Archive;
21 class GraphDataHandler;
22 class GraphDataHandlerImpl;
23 class GraphWidgetImpl;
24 
25 typedef std::shared_ptr<GraphDataHandler> GraphDataHandlerPtr;
26 
27 class CNOID_EXPORT GraphDataHandler
28 {
29 public:
32 
33  void setID(int id) { this->id = id; }
34  int getID() const { return id; }
35 
36  void setColor(float r, float g, float b);
37  void setLabel(const std::string& label);
38 
39  void setFrameProperties(int numFrames, double frameRate, double offset = 0.0);
40 
41  void setValueLimits(double lower, double upper);
42  void setVelocityLimits(double lower, double upper);
43 
44  void addVerticalLine(double x, const std::string& label);
45  void addHorizontalLine(double y, const std::string& label);
46  void clearLines();
47 
48  void update();
49 
50  typedef std::function<void(int frame, int size, double* out_values)> DataRequestCallback;
51  void setDataRequestCallback(DataRequestCallback callback);
52 
53  typedef std::function<void(int frame, int size, double* values)> DataModifiedCallback;
54  void setDataModifiedCallback(DataModifiedCallback callback);
55 
56 private:
57 
58  int id;
59 
60  friend class GraphWidgetImpl;
61 
62  GraphDataHandlerImpl* impl;
63 };
64 
65 
66 class CNOID_EXPORT GraphWidget : public QWidget
67 {
68 public:
69 
70  GraphWidget(View* parentView);
71  ~GraphWidget();
72 
73  void addDataHandler(GraphDataHandlerPtr handler);
74  void clearDataHandlers();
75 
76  void setRenderingTypes(bool showOriginalValues, bool showVelocities, bool showAccelerations);
77  void getRenderingTypes(bool& showOriginalValues, bool& showVelocities, bool& showAccelerations);
78 
79  bool setCursorPosition(double pos);
80 
81  void setTimeBarSyncMode(bool on);
82  bool isTimeBarSyncMode();
83 
84  enum ScrollMode { OFF, CONTINUOUS, PAGE };
85  void setAutoScrollMode(ScrollMode on);
86  ScrollMode autoScrollMode();
87 
88  void setVerticalValueRange(double lower, double upper);
89  void getVerticalValueRange(double& lower, double& upper);
90 
91  void setLineWidth(double width);
92  double getLineWidth();
93 
94  void showRulers(bool show);
95  bool showsRulers();
96 
97  void showLimits(bool show);
98  bool showsLimits();
99 
100  void showGrid(bool show);
101  bool showsGrid();
102 
103  void setGridSize(double width, double height);
104  void getGridSize(double& width, double& height);
105 
106  void setControlPointStep(int step, int offset = 0);
107  void getControlPointStep(int& step, int& offset);
108 
109  void highlightControlPoints(bool on);
110  bool highlightsControlPoints();
111 
112  enum Mode { VIEW_MODE, EDIT_MODE };
113  void changeMode(Mode mode);
114  Mode mode();
115 
116  enum EditMode { FREE_LINE_MODE, LINE_MODE };
117  void changeEditMode(EditMode mode);
118  EditMode editMode();
119 
120  QLabel& statusLabel();
121 
122  bool saveImage(const std::string& filename);
123 
124  virtual bool storeState(Archive& archive);
125  virtual bool restoreState(const Archive& archive);
126 
127 protected:
128  virtual bool eventFilter(QObject* obj, QEvent* event);
129 
130 private:
131 
132  friend class GraphDataHandler;
133 
134  GraphWidgetImpl* impl;
135 };
136 
137 }
138 
139 #endif
cnoid::GraphWidget::Mode
Mode
Definition: GraphWidget.h:112
cnoid::GraphWidget::EditMode
EditMode
Definition: GraphWidget.h:116
cnoid::GraphDataHandler::getID
int getID() const
Definition: GraphWidget.h:34
cnoid::View
Definition: View.h:27
cnoid::Archive
Definition: Archive.h:22
cnoid::GraphWidget
Definition: GraphWidget.h:66
cnoid::GraphDataHandler::DataRequestCallback
std::function< void(int frame, int size, double *out_values)> DataRequestCallback
Definition: GraphWidget.h:50
cnoid::GraphDataHandler::setID
void setID(int id)
Definition: GraphWidget.h:33
cnoid::GraphWidget::ScrollMode
ScrollMode
Definition: GraphWidget.h:84
cnoid::GraphDataHandlerPtr
std::shared_ptr< GraphDataHandler > GraphDataHandlerPtr
Definition: GraphWidget.h:23
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::GraphDataHandler
Definition: GraphWidget.h:27
cnoid::GraphWidget::VIEW_MODE
@ VIEW_MODE
Definition: GraphWidget.h:112
cnoid::GraphDataHandler::DataModifiedCallback
std::function< void(int frame, int size, double *values)> DataModifiedCallback
Definition: GraphWidget.h:53