forked from alandefreitas/matplotplusplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend_interface.cpp
205 lines (173 loc) · 7.44 KB
/
backend_interface.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//
// Created by Alan Freitas on 26/08/20.
//
#include "backend_interface.h"
#include <matplot/core/figure_type.h>
#include <matplot/util/common.h>
namespace matplot::backend {
bool backend_interface::consumes_gnuplot_commands() { return false; }
bool backend_interface::is_interactive() { return true; }
const std::string &backend_interface::output() {
const static std::string r{};
return r;
}
const std::string &backend_interface::output_format() {
const static std::string r{};
return r;
}
bool
backend_interface::output([[maybe_unused]] const std::string &filename) {
throw std::logic_error(
"There is no function to set the output in this backend yet. Maybe "
"this backend does not support non-interactive mode.");
}
bool
backend_interface::output([[maybe_unused]] const std::string &filename,
[[maybe_unused]] const std::string &file_format) {
throw std::logic_error(
"There is no function to set the output in this backend yet. Maybe "
"this backend does not support non-interactive mode.");
}
unsigned int backend_interface::width() { return 560; }
unsigned int backend_interface::height() { return 420; }
void backend_interface::width([[maybe_unused]] unsigned int new_width) {
throw std::logic_error(
"There is no function to set the width in this backend yet");
}
void backend_interface::height([[maybe_unused]] unsigned int new_height) {
throw std::logic_error(
"There is no function to set the height in this backend yet");
}
bool backend_interface::new_frame() {
return true;
}
bool backend_interface::render_data() {
if (!consumes_gnuplot_commands()) {
throw std::logic_error(
"There is no function to render_data in this backend yet");
} else {
throw std::logic_error(
"This backend has no function to flush commands yet");
}
}
void backend_interface::draw_path(
[[maybe_unused]] const std::vector<double> &x,
[[maybe_unused]] const std::vector<double> &y,
[[maybe_unused]] const std::array<float, 4> &color) {
if (!consumes_gnuplot_commands()) {
throw std::logic_error(
"There is no function to draw_path in this backend yet");
} else {
throw std::logic_error("This backend has no function draw_path "
"because it is based on gnuplot commands");
}
}
void backend_interface::draw_markers(
[[maybe_unused]] const std::vector<double> &x,
[[maybe_unused]] const std::vector<double> &y,
[[maybe_unused]] const std::vector<double> &z) {
if (!consumes_gnuplot_commands()) {
throw std::logic_error(
"There is no function to draw_markers in this backend yet");
} else {
throw std::logic_error("This backend has no function draw_markers "
"because it is based on gnuplot commands");
}
}
void backend_interface::draw_text(
[[maybe_unused]] const std::vector<double> &x,
[[maybe_unused]] const std::vector<double> &y,
[[maybe_unused]] const std::vector<double> &z) {
if (!consumes_gnuplot_commands()) {
throw std::logic_error(
"There is no function to draw_text in this backend yet");
} else {
throw std::logic_error("This backend has no function draw_text "
"because it is based on gnuplot commands");
}
}
void backend_interface::draw_image(
[[maybe_unused]] const std::vector<std::vector<double>> &x,
[[maybe_unused]] const std::vector<std::vector<double>> &y,
[[maybe_unused]] const std::vector<std::vector<double>> &z) {
if (!consumes_gnuplot_commands()) {
throw std::logic_error(
"There is no function to draw_image in this backend yet");
} else {
throw std::logic_error("This backend has no function draw_image "
"because it is based on gnuplot commands");
}
}
void backend_interface::draw_triangle(
[[maybe_unused]] const std::vector<double> &x,
[[maybe_unused]] const std::vector<double> &y,
[[maybe_unused]] const std::vector<double> &z) {
if (!consumes_gnuplot_commands()) {
throw std::logic_error(
"There is no function to draw_triangle in this backend yet");
} else {
throw std::logic_error("This backend has no function draw_triangle "
"because it is based on gnuplot commands");
}
}
void
backend_interface::run_command([[maybe_unused]] const std::string &text) {
if (consumes_gnuplot_commands()) {
throw std::logic_error(
"There is no function to run_command in this backend yet");
} else {
throw std::logic_error(
"This backend has no function to run_command because it is not "
"based on gnuplot commands");
}
}
void backend_interface::include_comment(
[[maybe_unused]] const std::string &text) {
if (consumes_gnuplot_commands()) {
throw std::logic_error(
"There is no function to include_comment in this backend yet");
} else {
throw std::logic_error(
"This backend has no function to include_comment because it is "
"not based on gnuplot commands");
}
}
void backend_interface::show(class matplot::figure_type *f) {
// The default implementation waits for the user to interact with the
// console. In interactive backends we expect this to start a render
// loop that will stop only when the user closes the window.
f->draw();
matplot::wait();
}
bool backend_interface::supports_fonts() { return false; }
unsigned int backend_interface::position_x() { return 680; }
unsigned int backend_interface::position_y() { return 558; }
void backend_interface::position_x(
[[maybe_unused]] unsigned int new_position_x) {}
void backend_interface::position_y(
[[maybe_unused]] unsigned int new_position_y) {}
void backend_interface::draw_background(
[[maybe_unused]] const std::array<float, 4> &color) {}
void backend_interface::draw_rectangle(
[[maybe_unused]] const double x1, [[maybe_unused]] const double x2,
[[maybe_unused]] const double y1, [[maybe_unused]] const double y2,
[[maybe_unused]] const std::array<float, 4> &color) {
if (!consumes_gnuplot_commands()) {
throw std::logic_error(
"There is no function to draw_rectangle in this backend yet");
} else {
throw std::logic_error("This backend has no function draw_triangle "
"because it is based on gnuplot commands");
}
}
bool backend_interface::should_close() {
// by default, we assume backends simply don't have this feature
return false;
}
void
backend_interface::window_title([[maybe_unused]] const std::string &title) {
}
std::string backend_interface::window_title() {
return "";
}
} // namespace matplot::backend