1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
| #include "graphique.h"
#include "donnecharger.h"
#include <math.h>
#include <iostream.h>
#include <QPaintEvent>
#include <QPainter>
Graph::Graph( QWidget *parent) : QWidget(parent)
{
heur1=1;
heur2=1;
moi1=1;
moi2=1;
pixelsWide=1 ;
pixelsHigh=1 ;
maxvalpsyf=1;
setBackgroundRole(QPalette::Base);
setAutoFillBackground(true);
}
QSize Graph::minimumSizeHint() const
{
return QSize(100, 100);
}
QSize Graph::sizeHint() const
{
return QSize(400, 800);
}
void Graph::setPen(const QPen &pen)
{
this->pen = pen;
update();
}
void Graph::setBrush(const QBrush &brush)
{
this->brush = brush;
update();
}
void Graph::paintEvent(QPaintEvent * /* event */)
{
QFont font("times", 10);
QFontMetrics fm(font);
pixelsWide = fm.width("10000");
pixelsHigh = fm.height();
QRect rect(10, 10, width()-25-pixelsWide, height()-20-pixelsHigh);
QPainter painter(this);
painter.drawRect(rect);
tracereper(painter);
tracecourbe(painter);
tracepoints(painter);
painter.setPen(palette().dark().color());
painter.setBrush(Qt::NoBrush);
}
void Graph::tracereper(QPainter &painter)
{
QFont font("times", 10);
QFontMetrics fm(font);
double maxvalpsyf =psyfunc(60.0,40.0,pression(),0);
int transDoubleInt=(int)(maxvalpsyf*1000.0);
double xmin=10.0;
double xmax=40.0;
double ymin=0.0;
double ymax=transDoubleInt/1000.0;
painter.setFont(font);
for(double i=0;i<=100;i+=(100/5)) {
int scalecoef=(int) ((height()-20-pixelsHigh)*i/100+10);
painter.drawText ( QRectF ( QPointF ( width()-pixelsWide-10,scalecoef-pixelsHigh/2 ),QSizeF (pixelsWide,pixelsHigh) ) ,
Qt::AlignLeft , QString("%1").arg((100.0-i)/100.0*(ymax-ymin)+ymin) );
painter.drawLine ( width()-pixelsWide-15,scalecoef,width()-pixelsWide-15 +5,scalecoef );
}
for(int i=0;i<=100;i+=(100/5)) {
int scalecoef=(int) ((width()-25-pixelsWide)*i/100+10);
painter.drawText ( QRectF ( QPointF ( 5+ scalecoef-pixelsWide/2, height()-pixelsHigh-10+5+5 ),
QSizeF (pixelsWide,pixelsHigh) ) ,
Qt::AlignLeft , QString("%1").arg((i)/100.0*(xmax-xmin)+xmin) );
painter.drawLine ( scalecoef, height()-pixelsHigh-10,scalecoef, height()-pixelsHigh-10 +5 );
}
}
void Graph::tracecourbe(QPainter &painter)
{
double maxvalpsyf =psyfunc(60.0,40.0,pression(),0);
for(double l=0;l<=100;l+=(100/10)){
for (int i=0;i<=(width()-25-pixelsWide);i++){
double j=i*30.0/(width()-25-pixelsWide);
double ratiohauteur=(height()-30-pixelsHigh)/maxvalpsyf;
double w=ratiohauteur*psyfunc(l,j+10,pression(),0);
///double rs=(p-w)*2.0*(height()-10-pixelsHigh)/height();///translation vertical
double px1=i+10.0;
///double py1=rs;
double py2=(height()-10-pixelsHigh)-w;
if(py2>10){
painter.drawPoint((int)px1,(int)py2);
///
}
}
}
}
void Graph::tracepoints(QPainter &painter)
{
double maxvalpsyf =psyfunc(60.0,40.0,pression(),0);
double **Tabl;
int *tablco;
char filename[50];
double li,col;
Donne p1;
strcpy(filename,"C:\\Users\\jean-charles\\Desktop\\sortie_e+2.csv");
Tabl = p1.Tableaulecture(filename);
tablco= p1.dim_def(filename);
for(int i=0;i<=tablco[1];i++){
if ((moi1<=Tabl[i][0])&&(Tabl[i][0]<=moi2)){
if ((heur1<=Tabl[i][1])&&(Tabl[i][1]<=heur2)){
li=(Tabl[i][4]-10.0)*(width()-25-pixelsWide)/30+10;
col=(height()-10-pixelsHigh)-psyfunc(Tabl[i][5],Tabl[i][4],pression(),0.0)*(height()-30-pixelsHigh)/maxvalpsyf;
painter.drawPoint((int)li,(int)col);
}}
}
}
void Graph::resizeEvent(QResizeEvent *event)
{
wgheight=height();
wgwidth =width();
QWidget::resizeEvent(event);
}
double Graph::psyfunc(double HR,double DBT, double P,double K)
{
double pws=1.40974109*pow(10,10)*exp(-3928.5/(DBT+231.667));
////double pws=exp(C8/(273.15+DBT)+C9+C10*pow(273.15+DBT,1.0)+C11*pow(273.15+DBT,2.0)+C12*pow(273.15+DBT,3.0)+C13*log(DBT+273.15));
double pw=pws*HR/100.0;
double W=0.62198*pw/(P-pw);
/////double Wsortie=(K-W)*2;
return(W);
/////return(Wsortie);
}
double Graph::pression(double altitude)
{
///double P=101.325*pow(1-2.25577E-5*altitude,5.2559);
double P1=101300*exp(-altitude/8000);
return(P1);
}
//////////////////////////////////////////////////////tous les update sont desous////////////
void Graph:: recupvalheur1(int val){
heur1=val;
update();
}
void Graph:: recupvalheur2(int val){
heur2=val;
update();
repaint();
}
void Graph:: recupvalmoi2(int val){
int t;
moi2=val;
update();
repaint();
t=heur1;
t=heur2;
t=moi1;
t=moi2;
}
void Graph:: recupvalmoi1(int val){
moi1=val;
update();
repaint();
} |
Partager