//**************************************************************************************************
//*  FRIDA: fast reliable interactive data analysis                        
//*  (C) Joachim Wuttke 1990-, v2(C++) 2001-                                
//*  http://apps.jcns.fz-juelich.de/frida                                   
//**************************************************************************************************

//! \file  dualplot.hpp
//! \brief Collection NPlot of plot frames CPlot.

#include "axis.hpp"


//! One plot frame.

class CPlot {
 public:
    int iPlot;             //!< The index of this frame in NPloWin::Plots.
    CAxis X;               //!< Limits, log flag &c for x axis.
    CAxis Y;               //!< Limits, log flag &c for y axis.
    // For data plotting:
    int maxpoints;         //!< Maximum # points to be plotted without reduction.
    bool with_errors;      //!< Plot error bars?
    // For curve plotting:
    int equipoints;        //!< Start curve plot with this # grid points.
    bool refine;           //!< Refine curve plot when appropriate?

    CPlot( int _iPlot, bool _logx, bool _logy );

    void gp_write( const string& in );
    void clearFrame();
    void plotFrame( const string& xlabel, const string& ylabel );
    void addSpec( bool as_line, bool new_style, int style_no,
                  const vector<double>& xp,
                  const vector<double>& yp,
                  const vector<double>& dyp,
                  const vector<string>& z,
                  const string& xco,
                  const string& yco,
                  const string& info );
    void showSpecs();
    void docTxLine( const string& line );
    void docPtTxLine( const string& line, int num );
    void docCvTxLine( const string& line, int num );
    void writePostscript( const string& ps_outdir,
                          const string& ps_head,
                          const string& ps_dict );
    void setAux( const string& cmd );
    string info() const;

private:
    // TODO: some of this could be made local static, if class instances
    // are created anew instead of calling clearFrame().
    int gp_fifo;      //!< Pipe to Gnuplot.
    int gp_fno;       //!< Number of Gnuplot input file.
    string gp_fnames; //!< List of currently plotted Gnuplot input file names.

    int ps_fnum;      //!< Postscript output file number.
    int ps_snum;      //!< Slice number in Postscript file.
    int ps_pnum;      //!< Spectrum number, for setting pstyle.
    int ps_cnum;      //!< Curve number, for setting cstyle.
    void ps_ticktack( const vector<double>& Tacks, int ntpt,
                      const double *ticklim, const CAxis *A );
    vector<string> ps_accu; //!< Main Postscript cache.
    vector<string> ps_Doc;  //!< Special Postscript cache for doc lines ?.
};


//! Direct access to plot windows collection.

namespace NPloWin {
    extern vector<CPlot*> Plots; //!< This vector holds all plot windows.
    extern int nPlot;            //!< Must be kept equal to Plots.size().
    extern int iPlot;            //!< Index of currently active plot window.

    void initialize();
}