Skip to content
Snippets Groups Projects
Commit f124fa3e authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

Almost all PS formatting moved to static fcts in anonymous namespace.

parent b5a1bac7
Branches
Tags
No related merge requests found
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "../plot/dualplot.hpp" #include "../plot/dualplot.hpp"
#include "../trivia/vector_ops.hpp" #include "../trivia/vector_ops.hpp"
#include "config.hpp"
#include "curve.hpp" #include "curve.hpp"
#include "fsel.hpp" #include "fsel.hpp"
#include "jsel.hpp" #include "jsel.hpp"
...@@ -437,8 +438,7 @@ void NPlot::plot(class CPlot* plot, bool add, const string& mode) ...@@ -437,8 +438,7 @@ void NPlot::plot(class CPlot* plot, bool add, const string& mode)
CCoord yCo = SFSel::instance()->sel_first()->yco; CCoord yCo = SFSel::instance()->sel_first()->yco;
// draw new frame: // draw new frame:
plot->clear_frame(); plot->start_frame("Frida version " VERSION, xCo.str_ps(), yCo.str_ps());
plot->plot_frame(xCo.str_ps(), yCo.str_ps());
} }
// plot: // plot:
......
...@@ -35,15 +35,6 @@ CPlot::CPlot(int _iPlot, bool _logx, bool _logy) ...@@ -35,15 +35,6 @@ CPlot::CPlot(int _iPlot, bool _logx, bool _logy)
{} {}
//! Clear plot frame and buffer.
void CPlot::clear_frame()
{
gnuPlotter->clear();
ps_Plotter->clear();
}
//! Change one setup parameter per command. //! Change one setup parameter per command.
void CPlot::set_aux(const string& cmd) void CPlot::set_aux(const string& cmd)
...@@ -89,10 +80,10 @@ void CPlot::set_aux(const string& cmd) ...@@ -89,10 +80,10 @@ void CPlot::set_aux(const string& cmd)
//! Plot coordinate frame (axes, ticks, labels). //! Plot coordinate frame (axes, ticks, labels).
void CPlot::plot_frame(const string& xlabel, const string& ylabel) void CPlot::start_frame(const string& caller, const string& xlabel, const string& ylabel)
{ {
gnuPlotter->plot_frame(X, Y); gnuPlotter->start_frame(X, Y);
ps_Plotter->plot_frame(X, Y, xlabel, ylabel); ps_Plotter->start_frame(caller, X, Y, xlabel, ylabel);
} }
......
...@@ -31,8 +31,8 @@ public: ...@@ -31,8 +31,8 @@ public:
void gp_write(const std::string& in); void gp_write(const std::string& in);
void clear_frame(); void start_frame(const std::string& caller,
void plot_frame(const std::string& xlabel, const std::string& ylabel); const std::string& xlabel, const std::string& ylabel);
void add_spec( void add_spec(
bool as_line, bool new_slice, int style_no, const std::vector<double>& xp, bool as_line, bool new_slice, int style_no, const std::vector<double>& xp,
const std::vector<double>& yp, const std::vector<double>& dyp, const std::vector<double>& yp, const std::vector<double>& dyp,
......
...@@ -55,12 +55,6 @@ CGnuPlotter::CGnuPlotter(int _iPlot) ...@@ -55,12 +55,6 @@ CGnuPlotter::CGnuPlotter(int _iPlot)
write("set terminal x11"); write("set terminal x11");
} }
void CGnuPlotter::clear()
{
gp_fno = 0;
gp_fnames = "";
}
//! Send one line to gnuplot fifo. //! Send one line to gnuplot fifo.
void CGnuPlotter::write(const string& in) void CGnuPlotter::write(const string& in)
...@@ -70,10 +64,12 @@ void CGnuPlotter::write(const string& in) ...@@ -70,10 +64,12 @@ void CGnuPlotter::write(const string& in)
throw S("could not write to gp_fifo"); throw S("could not write to gp_fifo");
} }
void CGnuPlotter::plot_frame(const CAxis& _X, const CAxis& _Y) void CGnuPlotter::start_frame(const CAxis& _X, const CAxis& _Y)
{ {
X = &_X; X = &_X;
Y = &_Y; Y = &_Y;
gp_fno = 0;
gp_fnames = "";
write("set nologscale"); write("set nologscale");
string whichlog = ""; string whichlog = "";
if (X->logflag) if (X->logflag)
......
...@@ -17,9 +17,8 @@ public: ...@@ -17,9 +17,8 @@ public:
CGnuPlotter(int _iPlot); CGnuPlotter(int _iPlot);
CGnuPlotter(CGnuPlotter const&) = delete; CGnuPlotter(CGnuPlotter const&) = delete;
CGnuPlotter& operator=(CGnuPlotter const&) = delete; CGnuPlotter& operator=(CGnuPlotter const&) = delete;
void clear();
void write(const std::string& in); void write(const std::string& in);
void plot_frame(const CAxis& _X, const CAxis& _Y); void start_frame(const CAxis& _X, const CAxis& _Y);
void add_spec( void add_spec(
bool as_line, bool new_slice, bool plot_errorbars, int style_no, bool as_line, bool new_slice, bool plot_errorbars, int style_no,
const std::vector<double>& xp, const std::vector<double>& yp, const std::vector<double>& xp, const std::vector<double>& yp,
......
...@@ -21,18 +21,30 @@ using std::string; ...@@ -21,18 +21,30 @@ using std::string;
using std::vector; using std::vector;
using boost::format; using boost::format;
void CPS_Plotter::clear() namespace {
{ string ps_ticktack(
ps_accu = "\n%% output created by frida2\n\n"; const vector<double>& Tacks, const int ntpt, const double* ticklim, const CAxis* A);
ps_snum = 0; string ps_frame(
ps_Doc = ""; const CAxis* X, const CAxis* Y, const string& xlabel, const string& ylabel);
string ps_slice_header(
bool as_line, int slice_no, int style_no, const vector<string>& zentries,
const string& xco, const string& yco);
string ps_data_block(
const CAxis* X, const CAxis* Y,
const vector<double>& xp, const vector<double>& yp, const vector<double>& dyp);
string ps_footer(
const string& fname, const string& doc_lines);
} }
void CPS_Plotter::plot_frame( void CPS_Plotter::start_frame(
const CAxis& _X, const CAxis& _Y, const string& xlabel, const string& ylabel) const string& caller, const CAxis& _X, const CAxis& _Y,
const string& xlabel, const string& ylabel)
{ {
X = &_X; X = &_X;
Y = &_Y; Y = &_Y;
ps_snum = 0;
ps_Doc = "";
ps_accu = "\n%% output created by " + caller + "\n\n";
ps_accu += ps_frame(X, Y, xlabel, ylabel); ps_accu += ps_frame(X, Y, xlabel, ylabel);
} }
...@@ -44,28 +56,12 @@ void CPS_Plotter::add_spec( ...@@ -44,28 +56,12 @@ void CPS_Plotter::add_spec(
{ {
// Postscript copy: // Postscript copy:
if (new_slice) { if (new_slice)
ps_accu += str(format("\n%3u [") % ++ps_snum); ps_accu += ps_slice_header(as_line, ++ps_snum, style_no, zentries, xco, yco);
for (string zentry: zentries) else
ps_accu += " " + zentry;
ps_accu += " ] zValues\n";
ps_accu += str(format("%2i %cstyle %% (%s -> %s)\n")
% style_no
% (as_line ? 'c' : 'p')
% xco
% yco);
} else {
ps_accu += "\n"; ps_accu += "\n";
}
int np = xp.size(); ps_accu += ps_data_block(X, Y, xp, yp, dyp);
for (int i = 0; i < np; i++)
ps_accu += str(format("%8.5f %8.5f %8.5f t%c %% %13.7g wx %13.7g wy\n")
% X->pc(xp[i])
% Y->pc(yp[i])
% (dyp.size() ? Y->pcerr(yp[i], dyp[i]) : 0)
% (i == 0 ? 'i' : i == np - 1 ? 'f' : ' ')
% xp[i]
% yp[i]);
} }
void CPS_Plotter::doc_line(const string& line) void CPS_Plotter::doc_line(const string& line)
...@@ -100,11 +96,7 @@ void CPS_Plotter::write_postscript( ...@@ -100,11 +96,7 @@ void CPS_Plotter::write_postscript(
throw "BUG: after copying headers, graphic output file " + fname + " still doesn't exist"; throw "BUG: after copying headers, graphic output file " + fname + " still doesn't exist";
std::fstream fs(fname, std::fstream::out | std::fstream::app); std::fstream fs(fname, std::fstream::out | std::fstream::app);
fs << ps_accu; fs << ps_accu;
fs << "\n{ black 0 -4 13 1.65 NewList\n"; fs << ps_footer(fname, ps_Doc);
fs << ps_Doc;
fs << "} oooinfo 1 eq { exec } { pop } ifelse\n";
fs << "\n{(" << fname << ")} /filename exch def 10 -2.8 18 showfilename\n\n";
fs << " EndFrame\n",
fs.close(); fs.close();
} }
...@@ -112,9 +104,10 @@ void CPS_Plotter::write_postscript( ...@@ -112,9 +104,10 @@ void CPS_Plotter::write_postscript(
// static functions // static functions
//************************************************************************************************** //**************************************************************************************************
//! Format ticks and tacks for postscript file. namespace {
string CPS_Plotter::ps_ticktack( //! Format ticks and tacks for postscript file.
string ps_ticktack(
const vector<double>& Tacks, const int ntpt, const double* ticklim, const CAxis* A) const vector<double>& Tacks, const int ntpt, const double* ticklim, const CAxis* A)
{ {
string ret; string ret;
...@@ -144,7 +137,7 @@ string CPS_Plotter::ps_ticktack( ...@@ -144,7 +137,7 @@ string CPS_Plotter::ps_ticktack(
return ret; return ret;
} }
string CPS_Plotter::ps_frame( string ps_frame(
const CAxis* X, const CAxis* Y, const string& xlabel, const string& ylabel) const CAxis* X, const CAxis* Y, const string& xlabel, const string& ylabel)
{ {
string ret; string ret;
...@@ -181,3 +174,48 @@ string CPS_Plotter::ps_frame( ...@@ -181,3 +174,48 @@ string CPS_Plotter::ps_frame(
"plotbefore\n\n"; "plotbefore\n\n";
return ret; return ret;
} }
string ps_slice_header(
bool as_line, int slice_no, int style_no, const vector<string>& zentries,
const string& xco, const string& yco)
{
string ret;
ret += str(format("\n%3u [") % slice_no);
for (string zentry: zentries)
ret += " " + zentry;
ret += " ] zValues\n";
ret += str(format("%2i %cstyle %% (%s -> %s)\n")
% style_no
% (as_line ? 'c' : 'p')
% xco
% yco);
return ret;
}
string ps_data_block(
const CAxis* X, const CAxis* Y,
const vector<double>& xp, const vector<double>& yp, const vector<double>& dyp)
{
string ret;
int np = xp.size();
for (int i = 0; i < np; i++)
ret += str(format("%8.5f %8.5f %8.5f t%c %% %13.7g wx %13.7g wy\n")
% X->pc(xp[i])
% Y->pc(yp[i])
% (dyp.size() ? Y->pcerr(yp[i], dyp[i]) : 0)
% (i == 0 ? 'i' : i == np - 1 ? 'f' : ' ')
% xp[i]
% yp[i]);
return ret;
}
string ps_footer(const string& fname, const string& doc_lines)
{
return "\n{ black 0 -4 13 1.65 NewList\n"
+ doc_lines
+ "} oooinfo 1 eq { exec } { pop } ifelse\n"
+ "\n{(" + fname + ")} /filename exch def 10 -2.8 18 showfilename\n\n"
+ " EndFrame\n";
}
} // anonymous namespace
...@@ -17,8 +17,7 @@ public: ...@@ -17,8 +17,7 @@ public:
CPS_Plotter() {} CPS_Plotter() {}
CPS_Plotter(CPS_Plotter const&) = delete; CPS_Plotter(CPS_Plotter const&) = delete;
CPS_Plotter& operator=(CPS_Plotter const&) = delete; CPS_Plotter& operator=(CPS_Plotter const&) = delete;
void clear(); void start_frame(const std::string& caller, const CAxis& _X, const CAxis& _Y,
void plot_frame(const CAxis& _X, const CAxis& _Y,
const std::string& xlabel, const std::string& ylabel); const std::string& xlabel, const std::string& ylabel);
void add_spec( void add_spec(
bool as_line, bool new_slice, int style_no, bool as_line, bool new_slice, int style_no,
...@@ -33,10 +32,6 @@ private: ...@@ -33,10 +32,6 @@ private:
const CAxis* X; const CAxis* X;
const CAxis* Y; const CAxis* Y;
int ps_snum; //!< Slice number in Postscript file. int ps_snum; //!< Slice number in Postscript file.
static std::string ps_ticktack(
const std::vector<double>& Tacks, const int ntpt, const double* ticklim, const CAxis* A);
static std::string ps_frame(
const CAxis* X, const CAxis* Y, const std::string& xlabel, const std::string& ylabel);
std::string ps_accu; //!< Main Postscript cache. std::string ps_accu; //!< Main Postscript cache.
std::string ps_Doc; //!< Special Postscript cache for doc lines ?. std::string ps_Doc; //!< Special Postscript cache for doc lines ?.
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment