Page.hh 4.86 KB
/*
 * Page.hh
 *
 *  Created on: 28 oct. 2013
 *      Author: CS
 */

#ifndef PAGE_HH_
#define PAGE_HH_

#include "Panel.hh"
#include "Font.hh"
#include "PlotCommon.hh"
#include "LayoutProperties.hh"

#include <boost/shared_ptr.hpp>
#include <vector>
#include <tuple>
#include <memory>

#include "plplot/plstream.h"

namespace plot {

class Page {
public:

	static const PLINT A4_X_LENGTH_IN_MM;
	static const PLINT A4_Y_LENGTH_IN_MM;
	static const PLINT LETTER_X_LENGTH_IN_MM;
	static const PLINT LETTER_Y_LENGTH_IN_MM;

	static const PLFLT A4_X_LENGTH_IN_INCHES;
	static const PLFLT A4_Y_LENGTH_IN_INCHES;
	static const PLFLT LETTER_X_LENGTH_IN_INCHES;
	static const PLFLT LETTER_Y_LENGTH_IN_INCHES;

	static const PLINT A4_X_LENGTH_IN_PT;
	static const PLINT A4_Y_LENGTH_IN_PT;
	static const PLINT LETTER_X_LENGTH_IN_PT;
	static const PLINT LETTER_Y_LENGTH_IN_PT;

	/* externalized
	static const PLINT A4_X_LENGTH_IN_PX;
	static const PLINT A4_Y_LENGTH_IN_PX;
	static const PLINT LETTER_X_LENGTH_IN_PX;
	static const PLINT LETTER_Y_LENGTH_IN_PX;

	static const PLINT DPI;*/

	Page();
	Page(DefaultPlotConfiguration& defaults);
	Page(const Page& page);
	virtual ~Page();

	/**
	 * @brief Get page size in millimeter.
	 * @return Return a tuple which contain page size in x coordinate and then page size in y coordinate.
	 */
	std::tuple<float, float> getSizeInMm();

	/**
	 * @brief Get page size in current coordinate (point or pixel) according to device.
	 * @return Return a tuple which contain page size in x coordinate and then page size in y coordinate.
	 */
	std::tuple<float, float> getSize();

	void setFont(std::string pname, int psize) {
		_font = Font(pname, psize);
	}

	void setDimension(const std::string& pdimension);

	void setOrientation(const std::string& porientation);

	void setMode(const std::string& pmode);

	void draw(std::shared_ptr<plstream>& pls, bool newFile, const char *plotFilePrefix);

	/*void addPanel(boost::shared_ptr<Panel> panel){
	 _panels.push_back(panel);
	 }*/
public:

	//std::vector<boost::shared_ptr<Panel>> _panels;

	/**
	 * Page format : png, ps etc.
	 */
	std::string _format;

	/**
	 * Page horizontal margin
	 */
	float _xMargin;

	/**
	 * Page vertical margin
	 */
	float _yMargin;

	/**
	 * Page orientation : landscape, portrait
	 */
	PlotCommon::Orientation _orientation;

	/**
	 * Page mode : color, greyscale
	 */
	PlotCommon::Mode _mode;

	/**
	 * Page dimension : a4, letter
	 */
	PlotCommon::Dimension _dimension;

	/**
	 * Page, panel etc. default font
	 */
	Font _font;

	/**
	 * Page title
	 */
	Label _title;

	/**
	 * Page align : left, center, right
	 */
	PlotCommon::Align _titleAlign;

	/**
	 * Page position : top, bottom
	 */
	PlotCommon::Position _titlePosition;
	
	int _dpi;

	LayoutProperties _layoutProperties;

	/**
	 * Page file name
	 */
	std::string _fileName;

	/**
	 * Default TimePlot and XYPLot width and height (used by vertical layout)
	 * Default TimePlot and XYPlot margins (used to fix plot area size)
	 */
	double _defaultTimePlotWidth;
	double _defaultTimePlotHeight;
	double _defaultTimePlotLeftMargin;
	double _defaultTimePlotRightMargin;
	double _defaultTimePlotTopMargin;
	double _defaultTimePlotBottomMargin;

	double _defaultXYPlotWidth;
	double _defaultXYPlotHeight;
	double _defaultXYPlotLeftMargin;
	double _defaultXYPlotRightMargin;
	double _defaultXYPlotTopMargin;
	double _defaultXYPlotBottomMargin;

	/**
	 * Superpose draw of all intervals in the same page
	 */
	bool _superposeMode;

private:

	void initPageParameters(std::shared_ptr<plstream>& pls);

	void writeCopywrite(std::shared_ptr<plstream>& pls);

	void calculateXMargin(PlotCommon::Orientation& orientation,
			PlotCommon::Dimension& dimension);
	void calculateYMargin(PlotCommon::Orientation& orientation,
			PlotCommon::Dimension& dimension);

};

std::ostream& operator <<(std::ostream& out, Page& page);
std::ostream& operator <<(std::ostream& out, PlotCommon::Dimension& dimension);
std::ostream& operator <<(std::ostream& out,
		PlotCommon::Orientation& orientation);
std::ostream& operator <<(std::ostream& out, PlotCommon::Mode& mode);

const std::string getPlSide(PlotCommon::Position& position);
PLFLT getPlPos(PlotCommon::Align& align);
PLFLT getPlJust(PlotCommon::Align& align);
PLFLT getPlColor(PlotCommon::Mode& mode);
const std::string getPlDev(const std::string& format);
PLFLT getPlVportYmin(PlotCommon::Position& position);
PLFLT getPlVportYmax(PlotCommon::Position& position);
PLINT getPlDevXLength(const std::string& format,
		PlotCommon::Dimension& dimension, int dpi);
PLINT getPlDevYLength(const std::string& format,
		PlotCommon::Dimension& dimension, int dpi);

Color changeColor(std::shared_ptr<plstream>& pls, Color& color, PlotCommon::Mode mode, int cmap = 0);
void restoreColor(std::shared_ptr<plstream>& pls, Color& color, PlotCommon::Mode mode, int cmap = 0);

void getDefaultColor(PlotCommon::Mode mode, int& cursor, Color& color);

} /* namespace plot */
#endif /* PAGE_HH_ */