diff --git a/Plot.cc b/Plot.cc index e89c180b5d7d0c849ee773bb56f1278998265fed..e01796252c7444dd7ee6669865821a4cf15980f4 100644 --- a/Plot.cc +++ b/Plot.cc @@ -133,7 +133,18 @@ void Plot :: eventloop() break; case 77: // 'M' - print eps image execute(new MakeMovieCommand); + console::consolecolor(console::BLUE); optionMenu(); + console::consolecolor(); + break; + case 82: // 'R' - reset range + int p2; + if ( projection[p2]->sRange() ) + { + projection[p2]->resetSrange(); + execute(new RangeCommand); + } + replot = true; break; case 98: // 'b' - border percentage float border; @@ -149,6 +160,11 @@ void Plot :: eventloop() } replot = true; break; + case 99: // 'c' - toggle ticmarks + profile->toggleTicMarks(); + execute(new TicsCommand); + replot = true; + break; case 100: // 'd' - toggle decoration if ( profile->decoration() ) execute(new UnsetDecorCommand); @@ -172,23 +188,18 @@ void Plot :: eventloop() cont = false; replot = false; break; - case 114: // 'r' - set range - int proj; + case 114: // 'r' - change range + int p1; changemode(0); console::eraser(); cout << "Enter projection number: "; - cin >> proj; - if ( proj >= projection.size() || proj < 0) + cin >> p1; + if ( p1 >= projection.size() || p1 < 0) { - cout << "There's no projection " << proj << "!!" << endl; + cout << "There's no projection " << p1 << "!!" << endl; changemode(1); break; } - if ( projection[proj]->sRange() ) - { - projection[proj]->resetSrange(); - execute(new RangeCommand); - } else { float xmin, xmax, ymin, ymax; @@ -197,7 +208,8 @@ void Plot :: eventloop() cin >> xmin >> xmax >> ymin >> ymax;; if ( cin ) { - projection[proj]->setSrange(xmin, xmax, ymin, ymax); + projection[p1]->setSrange(xmin, xmax, ymin, ymax); + execute(new TicsCommand); execute(new RangeCommand); } } @@ -258,22 +270,27 @@ void Plot :: optionMenu() cout << "\n" ; cout << "\n" ; cout << "==============================================================\n" ; - cout << " NPLOT (v2.0): " << profile->fileName() << endl; + cout << " NPLOT : " << 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 << " arrow up - start animation\n" ; + cout << " arrow down - stop animation or reset to step 0\n" ; + cout << " arrow right - one step forward or speed up animation\n" ; + cout << " arrow left - one step backward or slow down animation\n" ; + cout << "---------------------------------------------------------------\n" ; + cout << " b - change border percentage\n" ; + cout << " c - toggle tic marks\n" ; + cout << " d - toggle decoration\n" ; + cout << " g - toggle grid\n" ; + cout << " i - set step number\n" ; + cout << " l - change legend position\n" ; + cout << " M - make a movie (avi format)\n" ; + cout << " r - change range (zoom)\n" ; + cout << " R - reset range\n" ; + cout << " s - save image (eps format)\n" ; + cout << " w - set line width\n" ; + cout << " q - quit\n" ; cout << "==============================================================\n" ; cout << "\n" ; cout << "\n" ; diff --git a/Profile.cc b/Profile.cc index ead1b102d7f46e14b19c914c44825b5e335b9eb1..0fb625654c93e1370e613e8d489c5996946840a7 100644 --- a/Profile.cc +++ b/Profile.cc @@ -20,6 +20,7 @@ Profile :: Profile(int argc, char **argv) gridSize_ = 0; index_ = 0; + ticMarks_ = 0; legendPos_ = 0; decoration_ = true; grid_ = false; @@ -311,6 +312,12 @@ int Profile :: index() } +int Profile :: ticMarks() +{ + return ticMarks_; +} + + int Profile :: legendPos() { return legendPos_; @@ -399,6 +406,14 @@ void Profile :: lineWidth(float b_) } +void Profile :: toggleTicMarks() +{ + ticMarks_ += 1; + if ( ticMarks_ > 2 ) + ticMarks_ = 0; +} + + void Profile :: toggleLegend() { legendPos_ += 1; diff --git a/Profile.h b/Profile.h index 81aa204aa0d93ae73e4430b72f2cbfe331c3541b..656d0d0ae6fa63faf5da3f1cb89d2b3a12dca97a 100644 --- a/Profile.h +++ b/Profile.h @@ -25,6 +25,7 @@ private: int gridSize_; // grid size read from input file int index_; + int ticMarks_; int legendPos_; bool decoration_; bool grid_; @@ -57,6 +58,7 @@ public: int gridSize(void); int index(void); + int ticMarks(void); int legendPos(void); string legend(void); bool decoration(void); @@ -72,6 +74,7 @@ public: void grid(bool); void border(float); void lineWidth(float); + void toggleTicMarks(void); void toggleLegend(void); void toggleDecoration(void); void toggleGrid(void); diff --git a/command/MakeMovieCommand.cc b/command/MakeMovieCommand.cc index 884c53c2461858e9f5d4e53b8bd386ba4e12cb36..a4fe0965e8f8bd9dbeb5625eeba5284663703e1c 100644 --- a/command/MakeMovieCommand.cc +++ b/command/MakeMovieCommand.cc @@ -23,7 +23,7 @@ string MakeMovieCommand :: execute(Projection *projection, Profile *profile) plotCmd->execute(projection, profile, j); } - gplt->cmd ("CMD = 'mencoder mf://mov/proj%d_*.png -mf fps=25:type=png -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o mov/proj%d.avi'; system(CMD);", projection->ID(), projection->ID()); + gplt->cmd ("CMD = 'mencoder mf://mov/proj%d_*.png -mf fps=25:type=png -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o mov/proj%d.avi > /tmp/nplot_movie.log 2>&1'; system(CMD);", projection->ID(), projection->ID()); gplt->cmd ("system ('rm -f mov/*.png')"); gplt->cmd ("set term %s noraise title 'Projection %d'", projection->terminal().c_str(), projection->ID()); diff --git a/command/PrintEpsCommand.cc b/command/PrintEpsCommand.cc index 540d48c82202f3edc5c2f879537311bac438248c..263c40c68eb79995cf4b6487e75966a532404314 100644 --- a/command/PrintEpsCommand.cc +++ b/command/PrintEpsCommand.cc @@ -24,6 +24,7 @@ string PrintEpsCommand :: execute(Projection *projection, Profile *profile) // terminal epslatex produces a .tex file !! //gplt->cmd ("set terminal epslatex size 7.0,5.24 color colortext 10"); + //gplt->cmd ("set terminal postscript eps size 7.0,5.24 solid enhanced color font 'Helvetica,15'"); gplt->cmd ("set terminal postscript eps size 3.5,2.62 solid enhanced color font 'Helvetica,15' linewidth %f",\ profile->lineWidth() ); gplt->cmd ("set output 'img/proj%d_step%d%s.eps'", projection->ID(), profile->index(), decor.c_str()); diff --git a/command/TicsCommand.cc b/command/TicsCommand.cc new file mode 100644 index 0000000000000000000000000000000000000000..91efcbcd7a9e433552a951934e12f13f04232fdc --- /dev/null +++ b/command/TicsCommand.cc @@ -0,0 +1,35 @@ +#include + + +TicsCommand :: TicsCommand() : + name("Tics") +{ +} + + +string TicsCommand :: execute(Projection *projection, Profile *profile) +{ + Gnuplot * gplt = projection->projection(); + + switch ( profile->ticMarks() ) + { + case 0: + gplt->cmd ("set xtics autofreq"); + gplt->cmd ("set ytics autofreq"); + break; + + case 1: + gplt->cmd ("set xtics (%f, %f)", projection->xmin(), projection->xmax()); + gplt->cmd ("set ytics (%f, %f)", projection->ymin(), projection->ymax()); + break; + + case 2: + gplt->cmd ("unset xtics"); + gplt->cmd ("unset ytics"); + break; + } + + return ""; +} + + diff --git a/command/TicsCommand.h b/command/TicsCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..cc1736ca9d5e87597546ee72827f0c70824098d7 --- /dev/null +++ b/command/TicsCommand.h @@ -0,0 +1,18 @@ +#include + +#ifndef _TicsCommand +#define _TicsCommand + + +class TicsCommand : public Command +{ +private: + string name; + +public: + TicsCommand(); + string execute(Projection *, Profile *); + +}; + +#endif diff --git a/command/command b/command/command index 9ebff456e8f0e92d06a07743cb3246bb455fe033..9ca8a5b09d17d89ab8b362b187801c97cf26d4e7 100644 --- a/command/command +++ b/command/command @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/gnuplot/mouse.c b/gnuplot/mouse.c new file mode 100644 index 0000000000000000000000000000000000000000..23181cb4043a44410915085a386d3e125e5a570d --- /dev/null +++ b/gnuplot/mouse.c @@ -0,0 +1,107 @@ +/* + +gpReadMouseTest.c + +Test piped communication and mouse readback with gnuplot. +This code is published under the GNU Public License. + +This example demonstrates how to wait for a mouse press and get the +mouse button number and mouse position, from a graph in gnuplot. + + +Is this still true? Maybe no more necessary: +The weird thing is that the FIFO apparently wants to receive an +initial linefeed from gnuplot before it works. If you uncomment the +one line designated below, it still _may_ work (with emphasis on +"may"). Any ideas why? + +*/ + +#include +#include +#include +#include +#include +#include + +#define wait (printf("Press the 'any' key\n"), fgets(buf, 10, stdin)); +#define GPFIFO "./gpio" /* any unique name */ + +int +main(int argc, char *argv[]) +{ +FILE *gp, *gpin; +float mx = 0.0, my = 0.0; +int mb = 0; +int n; +char buf[80]; + +/* Create a FIFO we later use for communication gnuplot => our program. */ +if (mkfifo(GPFIFO, 0600)) { + if (errno != EEXIST) { + perror(GPFIFO); + unlink(GPFIFO); + return 1; + } +} + +if (NULL == (gp = popen("gnuplot","w"))) { + perror("gnuplot"); + pclose(gp); + return 1; +} +puts("Connected to gnuplot.\n"); + +/* Init mouse and redirect all gnuplot printings to our FIFO */ +fprintf(gp, "set mouse; set print \"%s\"\n", GPFIFO); +fflush(gp); + +/* Sometimes it was necessary to print \n from gnuplot to avoid a block. + Probably it is no more necessary. +*/ +#if 0 +fprintf(gp, "print \"\\n\"\n"); +fflush(gp); +#endif + +/* Open the FIFO (where gnuplot is writing to) for reading. */ +if (NULL == (gpin = fopen(GPFIFO,"r"))) { + perror(GPFIFO); + pclose(gp); + return 1; +} + +puts("FIFO open for reading.\n"); + + +/* Now do the work. */ +fprintf(gp, "plot sin(x)\n"); +fflush(gp); + +/* Do it 5 times. */ +for (n=0; n<5; n++) { + printf("\n%i/5. -- Click anywhere in the graph by mouse button 1.\n", n+1); + fprintf(gp, "pause mouse 'Click mouse!'\n"); + fflush(gp); + + fprintf(stdout,"I'M HERE: %i\n", __LINE__); + /* Let gnuplot write to coordinates values (to the FIFO). */ + fprintf(gp, "print MOUSE_X, MOUSE_Y, MOUSE_BUTTON\n"); + fflush(gp); + + fprintf(stdout,"I'M HERE: %i - %s\n", __LINE__, __FILE__); + /* Read from the FIFO. */ + fscanf(gpin, "%f %f %d", &mx, &my, &mb); + fprintf(stdout,"I'M HERE: %i\n", __LINE__); + printf("You pressed mouse button %d at x=%f y=%f\n", mb, mx, my); +/* wait; */ +} + +fclose(gpin); +pclose(gp); +unlink (GPFIFO); +return 0; +} + +/* eof gpReadMouseTest.c */ + diff --git a/makefile b/makefile index 7feb825d51139fbab247b0f6ac5e5fa1e5b0c99b..73e506c50d789cbac22e390ff7b65f8e587ea71c 100644 --- a/makefile +++ b/makefile @@ -16,6 +16,7 @@ CPROGSRC += \ UnsetDecorCommand.cc \ SetGridCommand.cc \ UnsetGridCommand.cc \ + TicsCommand.cc \ TitleCommand.cc \ PrintEpsCommand.cc \ PlotCommand.cc \