#ifndef __SIMULATION_GRAPHIC_H
#define __SIMULATION_GRAPHIC_H

#include <QList>
#include <QPointF>
#include <QColor>
#include <QPen>

typedef QList<QPointF> PointList;

/**
This class represents a curve in a SimulationGraphic 
*/
class SimulationGraphicCurve
{
	friend class SimulationGraphic;
	friend class SimulationResults;
	friend class SimulationGraphicView;
public:

	typedef enum {
		_solid_line = 1,
		_dash_line = 2,
		_dot_line = 3,
		_dash_dot_line = 4,
		_dash_dot_dot_line =5
	} LineStyle;

	/**
	Add point to the line
	*/
	virtual void addPoint(double x, double y);

	/**
	Remove point from line.<br>
	Return: true if the point was found and removed.
	*/
	virtual bool removePoint(double x, double y);

	/**
	Set color with the RGB value r, g, b, and the alpha-channel (transparency) value of a.<br>
	The color is not changed if any of the arguments are invalid.
	*/
	virtual void setColor(int r, int g, int b, int a = 255 );

	virtual void setStyle(LineStyle style);
	virtual void setWidth(int w);

	virtual void setText(const char *text) { _text = text; }
	virtual const char *text() { return _text.data(); }

protected:
	SimulationGraphicCurve();

	PointList points() { return _points; }
	QPen pen() { return _pen; }

private:
	PointList _points;
	QPen _pen;
	QByteArray _text;
};

typedef QList<SimulationGraphicCurve*> SimulationGraphicCurveList;

class SimulationGraphic
{
	friend class GridDesigner;
	friend class SimulationResults;
	friend class SimulationGraphicView;
public:
	/**
	Set graphic title.
	*/
	virtual void setTitle(const char *title);

	/**
	Get graphic title.
	*/
	virtual const char *title() const;

	/**
	Create a new line for this graphic.
	*/
	virtual SimulationGraphicCurve *createCurve();

	/**
	Get line count.
	*/
	virtual int curveCount() const;
	
	/**
	Get line by index.
	*/
	virtual SimulationGraphicCurve *curve(int index);

	/**
	Set the text of the x-axis.
	*/
	virtual void setXText(const char *xText) { _xText = xText; }

	/**
	Get the text of the x-axis.
	*/
	virtual const char *xText() const { return _xText.data(); }
	
	/**
	Set the text of the y-axis.
	*/
	virtual void setYText(const char *xText) { _yText = xText; }

	/**
	Get the text of the y-axis.
	*/
	virtual const char *yText() const { return _yText.data(); }

	/**
	Set the maximum value for x. If not specified all the points are tested and the maximum is the higher value.
	*/
	virtual void setMaxX(double maxX) { _maxX = maxX; _maxXSet = true; }

	/**
	Get the maximum value for x. Only valid if set using SetMaxX.
	*/
	virtual double maxX() { return _maxX; }

	/**
	Return: true if SetMaxX was called.
	*/
	virtual bool maxXSet() { return _maxXSet; }

	/**
	Set the maximum value for y. If not specified all the points are tested and the maximum is the higher value.
	*/
	virtual void setMaxY(double maxY) { _maxY = maxY; _maxYSet = true; }

	/**
	Get the maximum value for y. Only valid if set using SetMaxY.
	*/
	virtual double maxY() { return _maxY; }

	/**
	Return: true if SetMaxY was called.
	*/
	virtual bool maxYSet() { return _maxYSet; }

	virtual void setMinX(double minX) { _minX = minX; _minXSet = true; }
	virtual double minX() { return _minX; }
	virtual bool minXSet() { return _minXSet; }

	virtual void setMinY(double minY) { _minY = minY; _minYSet = true; }
	virtual double minY() { return _minY; }
	virtual bool minYSet() { return _minYSet; }

protected:
	SimulationGraphic();
	~SimulationGraphic();

	SimulationGraphicCurveList curves() { return _curves; }

private:
	SimulationGraphicCurveList _curves;
	QByteArray _title, _xText, _yText;
	double _maxX, _maxY, _minX, _minY;
	bool _maxXSet, _maxYSet, _minXSet, _minYSet;
};

typedef QList<SimulationGraphic*> SimulationGraphicList;


#endif // __SIMULATION_GRAPHIC_H