Newer
Older
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#include <Plot.h>
#include <console.h>
#include <command>
Plot :: Plot(Profile profile_) :
profile(&profile_)
{
for (int i = 0; i < profile->nProjs(); i++)
{
projection.push_back(new Projection(i, profile->argvComp(i)));
for (int j = 0; j < profile->nComps(); j++)
{
projection[i]->addComp(profile->component(j));
}
projection[i]->geometry(profile->argvType(i));
projection[i]->extractArgv();
if ( profile->argvType(i) == TRIANGLE )
{
projection[i]->addCmd(new TriangCommand(projection[i]));
}
}
}
void Plot :: eventloop()
{
if ( profile->verbose() )
{
int i;
cout << endl << "Available projections:" << endl;
for (i=0; i < projection.size(); i++)
{
cout << " Proj[" << i << "]: " << projection[i]->argvComp() << endl;
projection[i]->showComps();
}
cout << endl;
}
console::consolecolor(console::BLUE);
optionMenu();
console::consolecolor();
bool plotting = false;
bool replot = true;
bool cont = true;
int index = 0;
int ch;
int step = 1;
int i, j;
execute(new RangeCommand);
execute(new SetDecorCommand);
execute(new SetLinesCommand);
changemode(1);
while ( cont )
{
while ( !kbhit() )
{
if (replot)
{
if (plotting)
index = index + step;
else
replot = false;
if (index >= profile->nSteps()-1)
{
index = profile->nSteps()-1;
step = 1;
plotting = false;
}
if (index <= 0)
{
index = 0;
step = 1;
plotting = false;
}
profile->index(index);
if ( profile->decoration() )
execute(new TitleCommand);
execute(new PlotCommand);
system ("sleep 0.05");
}
}
ch = getchar();
if ( ch == '\033' ) // Is key is a arrow skip extra characters
{
ch = getchar();
ch = getchar();
}
switch (ch)
{
case 65: // arrow up
plotting = true;
replot = true;
break;
case 66: // arrow down
if (plotting) plotting = false; else index = 0;
step = 1;
replot = true;
break;
case 67: // arrow right
index = index + step;
if (plotting)
{
step++;
if (step == 0) step++;
}
replot = true;
break;
case 68: // arrow left
if (plotting)
{
step--;
if (step == 0) step--;
}
else
index--;
replot = true;
break;
case 77: // 'M' - print eps image
execute(new MakeMovieCommand);
optionMenu();
break;
case 98: // 'b' - border percentage
float border;
console::eraser();
cout << "Entre border percentage: ";
changemode(0);
cin >> border;
changemode(1);
if ( cin )
{
profile->border(border/100);
execute(new RangeCommand);
}
replot = true;
break;
case 100: // 'd' - toggle decoration
if ( profile->decoration() )
execute(new UnsetDecorCommand);
else
execute(new SetDecorCommand);
replot = true;
break;
case 103: // 'g' - toggle grid
if ( profile->grid() )
execute(new UnsetGridCommand);
else
execute(new SetGridCommand);
replot = true;
break;
case 108: // 'l' - change legend position
execute(new LegendPosCommand);
replot = true;
break;
case 113: // 'q' - quit
cont = false;
replot = false;
break;
case 114: // 'r' - set range
int proj;
changemode(0);
console::eraser();
cout << "Enter projection number: ";
cin >> proj;
if ( proj >= projection.size() || proj < 0)
{
cout << "There's no projection " << proj << "!!" << endl;
changemode(1);
break;
}
if ( projection[proj]->sRange() )
{
projection[proj]->resetSrange();
execute(new RangeCommand);
}
else
{
float xmin, xmax, ymin, ymax;
console::eraser();
cout << "Entre range [xmin, xmax, ymin, ymax]: ";
cin >> xmin >> xmax >> ymin >> ymax;;
if ( cin )
{
projection[proj]->setSrange(xmin, xmax, ymin, ymax);
execute(new RangeCommand);
}
}
replot = true;
changemode(1);
break;
case 115: // 's' - print eps image
execute(new PrintEpsCommand);
break;
/*
case 116: // 't' - draw triangle
int in;
cout << "Enter projection number: ";
changemode(0);
cin >> in;
changemode(1);
execute(new TriangCommand(projection[in]));
break;
case 117: // 'u' - print gnuplot command for debug
// DEBUG routine
break;
*/
case 119: // 'w' - line width
float linew;
changemode(0);
console::eraser();
cout << "Entre line width (" << profile->lineWidth() << "): ";
cin >> linew;
changemode(1);
if ( cin )
{
profile->lineWidth(linew);
execute(new SetLinesCommand);
}
replot = true;
break;
}
}
changemode(0);
}
void Plot :: execute(Command * cmd)
{
string command;
for (int i=0; i<projection.size(); i++)
{
command = cmd->execute(projection[i], profile);
projection[i]->projection()->cmd(command);
command = "";
}
}
void Plot :: optionMenu()
{
cout << "\n" ;
cout << "\n" ;
cout << "==============================================================\n" ;
cout << " NPLOT (v2.0): " << profile->fileName() << endl;
cout << "==============================================================\n" ;
cout << " Keyboard commands:\n" ;
cout << " Arroy up -> start animation\n" ;
cout << " Arroy down -> stop animation or reset to step 0\n" ;
cout << " Arroy right -> one step forward or speed up animation\n" ;
cout << " Arroy left -> one step backward or slow down animation\n" ;
cout << " b -> change border percentage\n" ;
cout << " d -> toggle decoration\n" ;
cout << " g -> toggle grid\n" ;
cout << " l -> change legend position\n" ;
cout << " r -> set or reset range (zoom)\n" ;
cout << " w -> set line width\n" ;
cout << " s -> save image (eps format)\n" ;
cout << " M -> make a movie (avi format)\n" ;
cout << " q -> quit\n" ;
cout << "==============================================================\n" ;
cout << "\n" ;
cout << "\n" ;
}
#include <termios.h>
#include <unistd.h>
void Plot :: changemode(int dir)
{
static struct termios oldt, newt;
if ( dir == 1 )
{
tcgetattr( STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt);
}
else
tcsetattr( STDIN_FILENO, TCSANOW, &oldt);
}
int Plot :: kbhit (void)
{
struct timeval tv;
fd_set rdfs;
tv.tv_sec = 0;
tv.tv_usec = 0;
FD_ZERO(&rdfs);
FD_SET (STDIN_FILENO, &rdfs);
select(STDIN_FILENO+1, &rdfs, NULL, NULL, &tv);
return FD_ISSET(STDIN_FILENO, &rdfs);
}