]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blob - src/gen_for_gnuplot.cc
29731adae96dbdefe58db3df19a05795de426ffc
[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         if (with_slot.compare("") != 0) {
89                 f << "plot '" << with_slot << "' w l,";
90         } else {
91                 f << "plot";
92         }
93         for (auto& m: ms) {
94                 f << " '" << m.fn << "'" << " w l,";
95         }
96         f << endl;
97         f << "pause -1" << endl;
98         f.close();
99 }
100
101 int
102 main()
103 {
104         using namespace std;
105         cout << fixed;
106         cerr << fixed;
107
108         bcar::ParkingSlot s(bcar::Point(0, 0), 0, 2.5, 6);
109         string sn("slot");
110         gpl_slot(s, sn);
111
112         s.fe(bcar::BicycleCar());
113         s.compute_entries();
114
115         INIT_V
116         P(RF_POINT)
117         P(RFM_POINT)
118         P(RRA_POINT)
119         P(RR_POINT)
120
121         for (auto& m: V) {
122                 m.c = s._entries.front();
123                 m.c.st(m.c.st() * -1.0);
124         }
125         for (unsigned int i = 0; i < STEPS; i++) {
126                 for (auto& m: V) {
127                         m.gpl();
128                 }
129         }
130         gen_pl_script(V, sn);
131         return 0;
132 }