#include "simulation_graphic.h"


SimulationGraphicCurve::SimulationGraphicCurve()
{
	_pen = QPen(Qt::gray);
	_pen.setStyle(Qt::SolidLine);
	_pen.setWidth(1);
}

void SimulationGraphicCurve::addPoint(double x, double y)
{
	_points.push_back(QPointF(x, y));
}

bool SimulationGraphicCurve::removePoint(double x, double y)
{
	bool ret = false;
	for(PointList::iterator it = _points.begin(); it != _points.end(); it++) {
		if(it->x() == x && it->y() == y) {
			_points.erase(it);
			ret = true;
		}
	}
	return ret;
}

void SimulationGraphicCurve::setColor(int r, int g, int b, int a)
{
	QColor c(r, g, b, a);
	if(c.isValid())
		_pen.setColor(c);
}

void SimulationGraphicCurve::setWidth(int w)
{
	_pen.setWidth(w);
}

void SimulationGraphicCurve::setStyle(LineStyle style)
{
	_pen.setStyle((Qt::PenStyle) style);
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////
SimulationGraphic::SimulationGraphic()
{
	_maxYSet = _maxXSet = _minYSet = _minXSet = false;
}

SimulationGraphic::~SimulationGraphic()
{
	for(SimulationGraphicCurveList::iterator it = _curves.begin(); it != _curves.end(); it++) {
		delete (*it);
	}
	_curves.clear();
}

void SimulationGraphic::setTitle(const char *title)
{
	_title = title;
}

const char *SimulationGraphic::title() const
{
	return _title.data();
}

SimulationGraphicCurve *SimulationGraphic::createCurve()
{
	SimulationGraphicCurve *newLine = new SimulationGraphicCurve;
	_curves.push_back(newLine);
	return newLine;
}

int SimulationGraphic::curveCount() const
{
	return _curves.count();
}

SimulationGraphicCurve *SimulationGraphic::curve(int index)
{
	SimulationGraphicCurve *ret = NULL;

	if(index < _curves.count()) {
		ret = _curves[index];
	}
	return ret;
}
