Draw2D
Dr2D_gnuplot_api.hh
1 /*
2 Copyright 2021 Arkadiusz Mielczarek
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 
6 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 
8 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 */
10 
11 #ifndef DR2D_GPLT_API_HH
12 #define DR2D_GPLT_API_HH
13 
14 #include "Draw2D_api_interface.hh"
15 #include <list>
16 #include <map>
17 #include <utility>
18 #include <memory>
19 #include <mutex>
20 #include <thread>
21 
22 using shape_and_color = std::pair<std::list<std::list<drawNS::Point2D> >,std::string>;
23 
24 namespace drawNS {
25 
40  int pipe_fd[2];
44  std::unique_ptr<std::thread> refresh_thread_ptr;
48  std::mutex gnuplot_pipe_mutex;
52  int gnuplot_pid;
56  std::string intro;
61  std::string command;
65  uint last_shape;
69  std::map<uint,shape_and_color> shapes;
70  void send2gnuplot(const std::string & command_arg);
71  void replot_loop();
72  uint add2shape_list(const std::list<std::list<Point2D> > & _list, const std::string & color);
73  void draw_all_shapes();
74  std::string translate_color(const std::string & color) const;
75  void stop_drawing_proces();
76 public:
80  APIGnuPlot2D() = delete;
91  APIGnuPlot2D(double minX, double maxX, double minY, double maxY, int ref_time_ms = 0);
95  ~APIGnuPlot2D() {stop_drawing_proces();}
96  uint draw_line(const Point2D & point1, const Point2D & point2, const std::string & color = "black") override;
97  uint draw_polygonal_chain(const std::vector<Point2D> & points, const std::string & color = "black") override;
98  void erase_shape(uint id) override;
99  void change_shape_color(uint id, const std::string & color) override;
100  void change_ref_time_ms(int ref_time_ms) override;
101  void redraw() override;
102 };
103 
104 }
105 
106 #endif
APIGnuPlot2D()=delete
deleted non-parametric constructor to force using parametric.
uint draw_line(const Point2D &point1, const Point2D &point2, const std::string &color="black") override
draws line between 2 points
Definition: Dr2D_gnuplot_api.cpp:138
Implementation drawing 2D class using gnuplot Class implements proxy between gnuplot and C++ code...
Definition: Dr2D_gnuplot_api.hh:36
void erase_shape(uint id) override
draws polyhedron described by its apexs
Definition: Dr2D_gnuplot_api.cpp:154
Abstract interface for drawing class Abstract class used as interface for 2D drawing class implementa...
Definition: Draw2D_api_interface.hh:86
uint draw_polygonal_chain(const std::vector< Point2D > &points, const std::string &color="black") override
draws polygonal_chain between n points
Definition: Dr2D_gnuplot_api.cpp:146
void change_ref_time_ms(int ref_time_ms) override
change mode for ploting and/or time between auto-replots
Definition: Dr2D_gnuplot_api.cpp:177
void redraw() override
replot all shapes Replots all shapes, works only in negative refresh_rate_ms value mode...
Definition: Dr2D_gnuplot_api.cpp:187
~APIGnuPlot2D()
destructor, also stops gnuplot proces.
Definition: Dr2D_gnuplot_api.hh:95
Point in 2D Class represents point in 2D.
Definition: Draw2D_api_interface.hh:35
void change_shape_color(uint id, const std::string &color) override
change color of shape
Definition: Dr2D_gnuplot_api.cpp:161
Namespace for drawing tools - abstract interface and 2D point Namespace for drawing tools - abstract ...
Definition: Dr2D_gnuplot_api.hh:24