#ifndef CHARTGRAPHICSITEM_H
#define CHARTGRAPHICSITEM_H

#include <QGraphicsItem>
#include <QPainter>
#include <QPoint>
#include "gimbaldata.h"

#define CHART_maxPoints IMU_BUF_COUNT

enum {
	CHART_GENERIC,
	CHART_BODE_TOP,
	CHART_BODE_BOT
};
enum{
	CHART_generic,
	CHART_bodeGain,
	CHART_filtGain,
	CHART_openGain,
	CHART_shakeGain,
	CHART_fftAmp,

	CHART_bodePhase,
	CHART_filtPhase,
	CHART_openPhase,
	CHART_shakeJitter,
	CHART_stepVel,
	CHART_fftRaw,
	CHART_numTypes
};
enum{
	CHART_activeVersion,
	CHART_refVersion,
	CHART_numVersions
};

//	-----------------------------------------------------------
//	Colors
//	-----------------------------------------------------------

	#define COLOR_BODE		0x00,0x00,0x00
	#define COLOR_OPEN		0xc0,0x00,0xc0
	#define COLOR_FILTER	0x00,0x00,0xff
	#define COLOR_SHAKE		0x00,0xa0,0x80
	#define COLOR_STEP		0xff,0x8c,0x00
	#define COLOR_FFT		0xff,0x00,0x00
	#define COLOR_CURSOR	0x60,0x60,0x60

class chartGraphicsItem : public QGraphicsItem
{
public:
	chartGraphicsItem();
	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
	QRectF boundingRect() const;

private:
	void gridLogX(QPainter *painter);
	void gridLinX(QPainter *painter);
	void drawChart(QPainter *painter);
	void drawBodeTop(QPainter *painter);
	void drawBodeBot(QPainter *painter);
	void scalings(float x, float y, float xrange=0, float yrange=0);
	int scaleY(float y);
	int scaleX(float x);
	int gScaleY(float gain);
	int gScaleX(float freq);
	void setBodeAmp(float *xvalues, float *yvalues, int count, int version, int type);
	void setBodePhase(float *xvalues, float *yvalues, int count, int version, int type);
public:
	void setPoints(float *values,int count, int reset=0);
	void setPoints(float *xvalues, float *yvalues, int count);
	void addPoint(int axis, float xvalue, float yvalue, int reset=0);
	void fftPoints(float *values, int count, int reset=0);
	void newTuneState(int axis,tuneState *g,tuneState *r);

public:
	QPoint points[CHART_numVersions][CHART_numTypes][CHART_maxPoints];
	int npoints[CHART_numVersions][CHART_numTypes];
	float xpoints[CHART_maxPoints];
	float ypoints[CHART_maxPoints];

	float xscale;
	float yscale;
	float xofs;
	float yofs;
	float minx;
	float maxx;
	float miny;
	float maxy;
	int yT;
	int yB;
	int xL;
	int xR;
	int yM;
	int hT;

	int ipoint;
	float minFreq;
	float maxFreq;
	int npixx;			// display X size [pixels]
	int npixy;			// display Y size [pixels]
	QRectF rect;		// display bounds [pixels]
	int logscaleX;
	int chartType;
	int symmY;

};

#endif // CHARTGRAPHICSITEM_H
