]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blob - src/gen_for_gnuplot.cc
Change generate plot for parking slot
[hubacji1/bcar.git] / src / gen_for_gnuplot.cc
1 /*
2  * SPDX-FileCopyrightText: 2021 Jiri Vlasak <jiri.vlasak.2@cvut.cz>
3  *
4  * SPDX-License-Identifier: GPL-3.0-only
5  */
6
7 #include <fstream>
8 #include <iostream>
9 #include <vector>
10 #include "pslot.hh"
11
12 #define SP 0.5
13 #define STEPS 60
14
15 #define V v
16 #define INIT_V vector<M> V;
17 #define P(W) V.push_back(M(#W)); V.back().o.W = true;
18
19 class M {
20 public:
21         std::string fn;
22         std::ofstream f;
23         bcar::BicycleCar c;
24         bcar::BicycleCar::GenPlotOpts o;
25
26         void gpl()
27         {
28                 this->c.gen_gnuplot_to(this->f, this->o);
29                 this->c.next();
30         }
31
32         ~M()
33         {
34                 this->f.close();
35         }
36         M(std::string fn) : fn(fn)
37         {
38                 this->f.open(this->fn);
39                 this->o.ALL = false;
40         }
41         M(M const& m) : fn(m.fn), c(m.c), o(m.o)
42         {
43                 this->f.open(this->fn);
44         }
45         M& operator=(M m)
46         {
47                 swap(*this, m);
48                 return *this;
49         }
50         friend void swap(M& f, M& t)
51         {
52                 using std::swap;
53                 f.f.close();
54                 t.f.close();
55                 swap(f.fn, t.fn);
56                 swap(f.c, t.c);
57                 swap(f.o, t.o);
58                 f.f.open(f.fn);
59                 t.f.open(t.fn);
60         }
61         M(M&& m) noexcept
62         {
63                 swap(*this, m);
64         }
65 };
66
67 void
68 gpl_slot(bcar::ParkingSlot& s, std::string fn)
69 {
70         if (fn.compare("") == 0) {
71                 return;
72         }
73         using namespace std;
74         ofstream f;
75         f.open(fn);
76         s.gen_gnuplot_to(f);
77         f.close();
78 }
79
80 void
81 gen_pl_script(std::vector<M>& ms, std::string with_slot)
82 {
83         using namespace std;
84         ofstream f;
85         f.open("plot.pl");
86         f << "#!/usr/bin/gnuplot" << endl;
87         f << "set size ratio -1" << endl;
88         f << "plot";
89         for (auto& m: ms) {
90                 f << " '" << m.fn << "'" << " w l,";
91         }
92         if (with_slot.compare("") != 0) {
93                 f << " '" << with_slot << "' w l";
94         }
95         f << endl;
96         f << "pause -1" << endl;
97         f.close();
98 }
99
100 int
101 main()
102 {
103         using namespace std;
104         cout << fixed;
105         cerr << fixed;
106
107         bcar::ParkingSlot s(bcar::Point(0, 0), 0, 2.5, 6);
108         string sn("slot");
109         gpl_slot(s, sn);
110
111         s.fe(bcar::BicycleCar());
112
113         INIT_V
114         P(RF_POINT)
115         P(RFM_POINT)
116         P(RRA_POINT)
117         P(RR_POINT)
118
119         for (auto& m: V) {
120                 m.c = s._entries.front().front();
121                 m.c.sp(m.c.sp() * -1.0);
122                 m.c.st(m.c.st() * -1.0);
123         }
124         for (unsigned int i = 0; i < STEPS; i++) {
125                 for (auto& m: V) {
126                         m.gpl();
127                 }
128         }
129         gen_pl_script(V, sn);
130         return 0;
131 }