OSCAR-code/Graphs/gpiechart.cpp

90 lines
2.4 KiB
C++
Raw Normal View History

2011-06-28 15:25:20 +00:00
#include <math.h>
#include "gpiechart.h"
2011-07-27 09:21:53 +00:00
gPieChart::gPieChart(MachineCode code,QColor col)
:gLayer(code)
2011-06-28 15:25:20 +00:00
{
color.clear();
color.push_back(col);
}
gPieChart::~gPieChart()
{
}
void gPieChart::Plot(gGraphWindow & w,float scrx,float scry)
{
if (!m_visible) return;
2011-07-27 09:21:53 +00:00
/*if (!data) return;
2011-06-28 15:25:20 +00:00
if (!data->IsReady()) return;
int start_px=w.GetLeftMargin();
int start_py=w.GetBottomMargin();
int width=scrx-(w.GetLeftMargin()+w.GetRightMargin());
int height=scry-(w.GetTopMargin()+w.GetBottomMargin());
float diameter=MIN(width,height);
2011-06-28 15:30:43 +00:00
diameter-=8;
2011-06-28 15:25:20 +00:00
float radius=diameter/2.0;
double total=0;
for (int i=0;i<data->np[0];i++)
total+=data->point[0][i].y();
double j=0.0;
double sum=0.0;
2011-06-28 15:44:44 +00:00
double step=1.0/45.0;
2011-06-28 15:25:20 +00:00
float px,py;
//glEnable(GL_TEXTURE_2D);
//glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
2011-06-28 15:30:43 +00:00
//glEnable(GL_POLYGON_SMOOTH);
2011-06-28 15:25:20 +00:00
glEnable(GL_LINE_SMOOTH);
2011-06-28 15:44:44 +00:00
glLineWidth(1.5);
2011-06-28 15:25:20 +00:00
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc( GL_SRC_ALPHA_SATURATE, GL_ONE );
2011-06-28 15:30:43 +00:00
//glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
2011-06-28 15:25:20 +00:00
for (int i=0;i<data->np[0];i++) {
j=(data->point[0][i].y()/total); // ratio of this pie slice
QColor col1=color[i % color.size()];
w.qglColor(col1);
2011-06-28 15:44:44 +00:00
glPolygonMode(GL_BACK,GL_FILL);
2011-06-28 15:25:20 +00:00
glBegin(GL_POLYGON);
2011-06-28 15:30:43 +00:00
glVertex2f(start_px+radius+4, start_py+radius+4);
2011-06-28 15:44:44 +00:00
double q;
for (q=sum;q<sum+j;q+=step) {
2011-06-28 15:30:43 +00:00
px=start_px+radius+4+sin(q*2*M_PI)*radius;
py=start_py+radius+4+cos(q*2*M_PI)*radius;
2011-06-28 15:25:20 +00:00
glVertex2f(px,py);
}
2011-06-28 15:44:44 +00:00
q=sum+j;
px=start_px+radius+4+sin(q*2*M_PI)*radius;
py=start_py+radius+4+cos(q*2*M_PI)*radius;
glVertex2f(px,py);
2011-06-28 15:25:20 +00:00
glEnd();
glPolygonMode(GL_BACK,GL_LINE);
w.qglColor(Qt::black);
glBegin(GL_POLYGON);
2011-06-28 15:30:43 +00:00
glVertex2f(start_px+radius+4, start_py+radius+4);
2011-06-28 15:44:44 +00:00
for (q=sum;q<sum+j;q+=step) {
2011-06-28 15:30:43 +00:00
px=start_px+radius+4+sin(q*2*M_PI)*radius;
py=start_py+radius+4+cos(q*2*M_PI)*radius;
2011-06-28 15:25:20 +00:00
glVertex2f(px,py);
}
2011-06-28 15:44:44 +00:00
q=sum+j;
px=start_px+radius+4+sin(q*2*M_PI)*radius;
py=start_py+radius+4+cos(q*2*M_PI)*radius;
glVertex2f(px,py);
2011-06-28 15:25:20 +00:00
glEnd();
2011-06-28 15:44:44 +00:00
sum=q;
2011-06-28 15:25:20 +00:00
}
glDisable(GL_POLYGON_SMOOTH);
2011-07-27 09:21:53 +00:00
glDisable(GL_BLEND); */
2011-06-28 15:25:20 +00:00
//glDisable(GL_DEPTH_TEST);
//glDisable(GL_TEXTURE_2D);
}