25 #include "ElementiGrafici.h" 27 #include <Q3PaintDeviceMetrics> 29 void ElementiGrafici::GrMessage(
const char * s, ...){
33 fprintf(stderr,
"%d) ",
NDis);
34 vfprintf(stderr, s, args);
35 fprintf(stderr,
"\n");
41 void ElementiGrafici::paintEvent(QPaintEvent *e){
42 GrMessage(
"Visualizza.paintEvent(begin)");
48 Immagine.load(
"Logo.png");
49 p.drawPixmap(200,300,QPixmap(Immagine),0,0,-1,-1);
51 GrMessage(
"Visualizza.paintEvent(end)");
53 void ElementiGrafici::DisegnaPunti(QPainter *p){
57 if(NVisMin < 0 || NVisMax > PuntiMax || NVisMin > NVisMax){
58 sprintf(stringa,
"Non `e corretto l'ordine 0<=%d<%d<=%d",NVisMin,NVisMax,PuntiMax);
59 printf(
"Non `e corretto l'ordine 0<=%d<%d<=%d\n",NVisMin,NVisMax,PuntiMax);
60 ErrPrima->message(stringa);
63 if( IfRiscala != 0 ) GrRiscala();
67 if( DIS_IF_TYPE(IfDisegna,DIS_TUTTI) ){
68 for(
int s=0,sColor=0;s<NVar;s++){
71 p->setBrush( GrLinee[sColor] );
72 p->setPen( QPen( GrLinee[sColor],2 ) );
73 Quadrati = DIS_IF_TYPE(LineaCome[sColor],LINEA_PUNTO);
74 Linee = DIS_IF_TYPE(LineaCome[sColor],LINEA_TRATTO);
79 if( DIS_IF_TYPE(IfDisegna,DIS_SEGNALE) ){
80 p->setBrush( GrLinee[CoordY] );
81 p->setPen( QPen( GrLinee[CoordY],2 ) );
84 if( DIS_IF_TYPE(IfDisegna,DIS_MOMENTI) )
86 if( DIS_IF_TYPE(IfDisegna,DIS_PUNTI) ){
87 p->setBrush( GrLinee[CoordY] );
88 p->setPen( QPen( GrLinee[CoordY],2 ) );
91 if( DIS_IF_TYPE(IfDisegna,DIS_BLU) ) GrBlu(p);
92 if( Griglia ) GrGriglia(p);
93 if(!IfStampa) GrBarre(p);
95 GrMessage(
"Disegna %d = Tutti %d Set %d Momenti %d Punti %d Blu %d Riscala %d = RisUno %d RisTutti %d",IfDisegna,
96 DIS_IF_TYPE(IfDisegna,DIS_TUTTI),
97 DIS_IF_TYPE(IfDisegna,DIS_SEGNALE),
98 DIS_IF_TYPE(IfDisegna,DIS_MOMENTI),
99 DIS_IF_TYPE(IfDisegna,DIS_PUNTI),
100 DIS_IF_TYPE(IfDisegna,DIS_BLU),
102 DIS_IF_TYPE(IfRiscala,RIS_UNO),
103 DIS_IF_TYPE(IfRiscala,RIS_TUTTI));
106 void ElementiGrafici::GrSet(QPainter *p,
int s){
107 GrMessage(
"Visualizza.Dis.GrSet");
111 for(
int i=MIN(NVisMin,
v1->
pNRow(s));i<MIN(NVisMax,
v1->
pNRow(s));i++){
113 if(!DIS_IF_TYPE(LogLog,DIS_LOGX))
114 Tempx = (
int) ( (double)((
v1->
Abscissa(s,i)-xMin)*RisX)/(double)(xMax-xMin) );
117 Tempx = (int) ( (log10(
v1->
Abscissa(s,i))-xMin)/(xMax-xMin)*RisX);
119 if(!DIS_IF_TYPE(LogLog,DIS_LOGY))
120 Tempy = RisY-(
int)( (
v1->
Val(s,i)-yMin)*RisY/ (yMax-yMin) );
122 if(
v1->
Val(s,i) <= 0.)
continue;
123 Tempy = RisY-(int)( (log10(
v1->
Val(s,i))-yMin)*RisY/ (yMax-yMin) );
130 if(Tempx > RisX){Tempx = RisX;}
131 if(Tempy > RisY){Tempy = RisY;}
132 if(Tempx < 0 ){Tempx = 0;}
133 if(Tempy < 0 ){Tempy = 0;}
134 Punto = QPoint(Tempx, Tempy);
137 Punto2 = QPoint(Punto.x()-PointSize,Punto.y()-PointSize);
138 Punto3 = QPoint(Punto.x()+PointSize,Punto.y()+PointSize);
139 p->drawLine(Punto2,Punto3);
140 Punto2 = QPoint(Punto.x()+PointSize,Punto.y()-PointSize);
141 Punto3 = QPoint(Punto.x()-PointSize,Punto.y()+PointSize);
142 p->drawLine(Punto2,Punto3);
158 if(Linee && IfDrawLine) p->drawLine(Punto,Punto1);
163 void ElementiGrafici::GrPunti(QPainter *p){
164 GrMessage(
"Visualizza.Dis.GrPunti");
165 for(
int i=NVisMin;i<NVisMax*NMobile;i+=NMobile){
167 if(xMax < v1->Abscissa(CoordY,i)) xMax =
v1->
Abscissa(CoordY,i);
169 ScalaTopoX = xMax-xMin;
171 for(
int i=NVisMin;i<NVisMax;i++){
173 if(!DIS_IF_TYPE(LogLog,DIS_LOGX))
174 Tempx = (int) ( (
double)((
v1->
Abscissa(CoordY,i*NMobile)-xMin)*RisX)/(double)(xMax-xMin) );
177 Tempx = (int) ( (log10(
v1->
Abscissa(CoordY,i))-xMin)/(xMax-xMin)*RisX);
179 if(!DIS_IF_TYPE(LogLog,DIS_LOGY))
180 Tempy = RisY-(
int)( (
v1->
pPunti(i)-yMin)*RisY/ (yMax-yMin) );
183 Tempy = RisY-(int)( (log10(
v1->
pPunti(i))-yMin)*RisY/ (yMax-yMin) );
186 if(Tempx > RisX) Tempx=RisX;
187 if(Tempy > RisY) Tempy=RisY;
188 if(Tempx < 0 ) Tempx=0;
189 if(Tempy < 0 ) Tempy=0;
190 Punto = QPoint(Tempx, Tempy);
191 if(Quadrati) p->drawRect( PuntiRett(Punto) );
192 if( Linee && i > NVisMin) p->drawLine(Punto,Punto1);
194 int ErrY = (int)( .5*(
v1->
pPuntiErr(i))*RisY/ (yMax-yMin) );
195 QPoint PuntoErr1(Tempx,Tempy+ErrY);
196 QPoint PuntoErr2(Tempx,Tempy-ErrY);
199 p->drawLine(PuntoErr1,PuntoErr2);
203 void ElementiGrafici::GrMomenti(QPainter *p){
204 GrMessage(
"Visualizza.Dis.GrMomenti");
205 p->setBrush( Qt::red );
206 p->setPen( Qt::red );
207 for(
int i=NVisMin;i<NVisMax;i++){
208 Tempx = (int) ( (
double)((i-NVisMin)*RisX)/(double)(NVisMax-NVisMin) );
209 int Tempx2 = (int) ( (
double)((i+1-NVisMin)*RisX)/(double)(NVisMax-NVisMin) );
210 Tempy = RisY-(int)( (
v1->
pInter(i)-yMin)*RisY/ (yMax-yMin) );
211 Punto = QPoint(Tempx,Tempy);
212 QPoint Punto2 = QPoint(Tempx2,Tempy);
213 if( Quadrati ) p->drawRect( PuntiRett(Punto) );
214 if( Linee && i>NVisMin){
215 p->drawLine(Punto2,Punto);
216 p->drawLine(Punto,Punto1);
220 GrMessage(
"Visualizza.Dis.GrMomenti.Blue");
221 p->setBrush( Qt::blue );
222 p->setPen( Qt::blue );
225 for(
int i=NVisMin;i<NVisMax;i++){
226 Tempx = (int) ( (
double)((i-NVisMin)*RisX)/(double)(NVisMax-NVisMin) );
227 Tempy = RisY-(int)( (
v1->
pInter1(i)-yMin)*RisY/ (yMax-yMin) );
228 Punto = QPoint(Tempx,Tempy);
229 if( Quadrati ) p->drawRect( PuntiRett(Punto) );
230 if( Linee && i>NVisMin) p->drawLine(Punto,Punto1);
234 if( yBluMax < v1->pInter1(i) )
237 GrMessage(
"Visualizza.Dis.GrMomenti.String");
238 sprintf(stringa,
"%.2g",yBluMax);
239 p->drawText(RisX-70,15,QString(stringa));
240 sprintf(stringa,
"%.2g",yBluMax/2.);
241 p->drawText(RisX-70,(
int)RisY/2,QString(stringa));
242 sprintf(stringa,
"%.2g",yBluMin);
243 p->drawText(RisX-70,RisY-15,QString(stringa));
244 int PosMomX=(int)(PosInterp[0]*RisX);
245 int PosMomY=(int)((1.-PosInterp[1])*RisY);
246 sprintf(stringa,
"m %.4g s %g N %d",m1.
Uno,m1.
Due,m1.
Num);
247 p->drawText(PosMomX,PosMomY,QString(stringa));
249 sprintf(stringa,
"t %g Chi %.2g",m1.
Tre,m1.
Chi);
250 p->drawText(RisX/2-70,RisY/2+120,QString(stringa));
253 void ElementiGrafici::GrBlu(QPainter *p){
254 GrMessage(
"Visualizza.Dis.GrBlu");
256 p->setBrush( Qt::blue );
257 p->setPen( Qt::blue );
259 p->setPen(QPen(Qt::blue,1,Qt::DashLine,Qt::RoundCap,Qt::RoundJoin));
261 p->setPen(QPen(Qt::blue,3,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
262 for(
int i=NElMin;i<NElMax;i++){
263 if(!DIS_IF_TYPE(LogLog,DIS_LOGX))
264 Tempx = (int) ( (
double)((
v1->
Abscissa(CoordY,i)-xMin)*RisX)/(double)(xMax-xMin) ) ;
267 Tempx = (int) ( (log10(
v1->
Abscissa(CoordY,i))-xMin)/(xMax-xMin)*RisX );
268 if( DIS_IF_TYPE(IfDisegna,DIS_RETTA) ){
269 if(!DIS_IF_TYPE(LogLog,DIS_LOGY)){
270 Tempy = RisY-(int)( (
v1->
Abscissa(CoordY,i)*r1.
m+r1.
q-yMin)*RisY/ (yMax-yMin) );
274 Tempy = RisY-(int)( (log10(
v1->
Abscissa(CoordY,i))*r1.
m+r1.
q-yMin)*RisY/(yMax-yMin) );
276 else if( DIS_IF_TYPE(IfDisegna,DIS_PARABOLA) ){
277 if(!DIS_IF_TYPE(LogLog,DIS_LOGY)){
283 Tempy = RisY-(int)((y*y*p1.
a2+y*p1.
a1+p1.
a0-yMin)*RisY/(yMax-yMin));
286 else if( DIS_IF_TYPE(IfDisegna,DIS_EXP) ){
287 if(!DIS_IF_TYPE(LogLog,DIS_LOGY)){
288 Tempy = RisY-(int)((exp(r1.
q+r1.
m*
v1->
Abscissa(CoordY,i))-yMin)*RisY/(yMax-yMin));
291 Tempy = RisY-(int)((exp(r1.
q+r1.
m*log10(
v1->
Abscissa(CoordY,i)))-yMin)*RisY/(yMax-yMin));
293 else if( DIS_IF_TYPE(IfDisegna,DIS_GAUSS) ){
297 Tempy = RisY-(int)( (
v1->
pInter1(i)-yMin)*RisY/ (yMax-yMin) );
299 Punto = QPoint(Tempx,Tempy);
300 if(Tempx > RisX){IfDrawLine=0;
continue;}
301 if(Tempy > RisY){IfDrawLine=0;
continue;}
302 if(Tempx < 0 ){IfDrawLine=0;
continue;}
303 if(Tempy < 0 ){IfDrawLine=0;
continue;}
305 if( IfDrawLine) p->drawLine(Punto,Punto1);
310 int PosLegX=(int)(PosInterp[0]*RisX);
311 int PosLegY=(int)((1.-PosInterp[1])*RisY);
312 if( DIS_IF_TYPE(IfDisegna,DIS_RETTA) ){
315 sprintf(stringa,
"m %.3g+-%.3g q %.3g+-%.3g",r1.
m,r1.
ErrM,r1.
q,r1.
ErrQ);
316 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY,QString(stringa));
317 sprintf(stringa,
"r %.5g Corr %.3g",r1.
Corr,r1.
Cov);
318 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY+15,QString(stringa));
321 sprintf(stringa,
"y=%.3f x + %.3f",r1.
m,r1.
ErrM,r1.
q,r1.
ErrQ);
322 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY,QString(stringa));
327 else if( DIS_IF_TYPE(IfDisegna,DIS_PARABOLA) ){
328 int RefY = (int)(.1*RisY);
330 sprintf(stringa,
"%.2g + %.2g x + %.2g x^2",p1.
a0,p1.
a1,p1.
a2);
331 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY,QString(stringa));
332 sprintf(stringa,
"Minimum (%.3g %.3g) ",p1.
Minimo,p1.
MinimoY);
333 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY+25,QString(stringa));
336 p->setFont(QFont(
"Palatino",FontSize-6));
337 sprintf(stringa,
"%.2g + %.2g x + %.2g x^2",p1.
a0,p1.
a1,p1.
a2);
338 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY,QString(stringa));
339 sprintf(stringa,
"min %.2g ",p1.
Minimo);
340 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY+25,QString(stringa));
341 p->setFont(QFont(
"Palatino",FontSize));
344 else if( DIS_IF_TYPE(IfDisegna,DIS_GAUSS) ){
345 int RefY = (int)(.1*RisY);
346 sprintf(stringa,
"x_0 = %.3g s = %.3g ",m1.
Uno,m1.
Due);
347 p->drawText(PosLegX,PosLegY,QString(stringa));
349 else if( DIS_IF_TYPE(IfDisegna,DIS_EXP) ){
352 sprintf(stringa,
"y=(%.3g+-%.3g)exp(x/(%.3g+-%.3g))",log10(r1.
q),log10(r1.
ErrQ),1./r1.
m,r1.
ErrM/SQR(r1.
m));
353 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY,QString(stringa));
356 sprintf(stringa,
"y=%.3g exp(%.3g x)",log10(r1.
q),r1.
m);
357 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY,QString(stringa));
369 void ElementiGrafici::GrBarre(QPainter *p){
370 GrMessage(
"Visualizza.Dis.GrBarre");
371 p->setBrush( Qt::black );
372 p->setPen( QPen(Qt::black,1) );
374 GrMessage(
"Visualizza.Dis.GrBarre.Ascissa");
375 if(DIS_IF_TYPE(LogLog,DIS_LOGX)){
377 Tempx = (
int)( (log10(
v1->
Abscissa(CoordY,NElMin))-xMin)/(xMax-xMin)*RisX);
380 Tempx = (int) ( (
double)((
v1->
Abscissa(CoordY,NElMin)-xMin)*RisX)/(double)(xMax-xMin) );
381 p->drawLine( QPoint(Tempx ,0), QPoint(Tempx ,RisY));
382 if(DIS_IF_TYPE(LogLog,DIS_LOGY)){
384 Tempx = (
int)( (log10(
v1->
Abscissa(CoordY,NElMax))-xMin)/(xMax-xMin)*RisX);
387 Tempx = (int) ( (
double)((
v1->
Abscissa(CoordY,NElMax)-xMin)*RisX)/(double)(xMax-xMin) );
388 p->drawLine( QPoint(Tempx ,0), QPoint(Tempx ,RisY));
389 p->drawLine( QPoint(0,NElMinY), QPoint(RisX,NElMinY));
390 p->drawLine( QPoint(0 ,NElMaxY), QPoint(RisX,NElMaxY));
393 void ElementiGrafici::GrStampante(QPainter *p){
394 GrMessage(
"Visualizza.Dis.GrStampante");
395 Font.setFamily(
"Helvetica");
399 QRect view(0,0,width(),height());
400 p->setViewport(view);
405 Font.setPointSize(12);
407 p->setFont(QFont(
"Palatino",12 ));
408 int PosLabel = (int)(RisX/2. - 2.*
nomeEtX.length());
411 p->translate(PosLabel,height()-40);
413 doc.setDefaultFont(QFont(
"Palatino",18 ));
418 PosLabel = RisY - (int)(RisY/2. - 2.*
nomeEtY.length());
419 p->translate(width()-40,PosLabel);
426 Q3PaintDeviceMetrics metrics( p->device() );
427 int dpiy = metrics.logicalDpiY();
428 int margin = (int) ((2/2.54)*dpiy);
430 QRect window(0.,0.,RatioWidthHeight*metrics.height(),metrics.height());
431 p->setWindow(window);
432 QRect view(3*margin,margin,metrics.height() - 2*margin,metrics.height() - 2*margin );
433 p->setViewport(view);
434 Font.setPointSize(32);
436 p->setFont(QFont(
"Helvetica",FontSize));
438 RisX = (int)(.9*metrics.width());
439 RisY = (int)(.9*metrics.height());
442 NElMinY = (int) (NElMinY*metrics.height()/(double)RisY);
443 NElMaxY = (int) (NElMaxY*metrics.height()/(double)RisY);
445 int PosLabel = (int)(RisX/2. - 2.*
nomeEtX.length());
450 p->translate(PosLabel,metrics.height()-10);
452 doc.setDefaultFont(QFont(
"Helvetica",FontSize));
457 PosLabel = RisY - (int)(RisY/2. - 2.*
nomeEtY.length());
458 p->translate(-(
int)(3.5*margin),PosLabel);
467 void ElementiGrafici::GrGriglia(QPainter *p){
468 GrMessage(
"Visualizza.Dis.GrGriglia");
469 QString NumLabel = QString();
471 p->setPen(QPen(Qt::black,1,Qt::DashLine,Qt::RoundCap,Qt::RoundJoin));
473 p->setPen(QPen(Qt::black,3,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
477 p->drawLine(QPoint(0,RisY),QPoint(RisX,RisY) );
478 p->drawLine(QPoint(RisX,0),QPoint(RisX,RisY) );
479 p->drawLine(QPoint(0,0),QPoint(RisX,0) );
480 p->drawLine(QPoint(0,0),QPoint(0,RisY) );
481 if(!DIS_IF_TYPE(LogLog,DIS_LOGY)){
483 for(
int i=0;i<=GrigliaY;i++){
484 Tempy = (int) (RisY/(
double)GrigliaY*i);
486 p->drawLine(QPoint(0,Tempy),QPoint(RisX,Tempy) );
488 p->drawLine(QPoint(0,Tempy),QPoint(10,Tempy) );
489 p->drawLine(QPoint(RisX,Tempy),QPoint(RisX-10,Tempy) );
491 int RiTempY = Tempy+(int)(.5*RisY/(
double)GrigliaY);
492 p->drawLine(QPoint(0,RiTempY),QPoint(5,RiTempY) );
493 p->drawLine(QPoint(RisX,RiTempY),QPoint(RisX-5,RiTempY) );
496 NumLabel.setNum((
double)(yMax-yMin)/(
double)GrigliaY*i+yMin,FormatPrecY,DigPrecY);
497 if(i==GrigliaY && !IfStampa) Tempy -= 10;
498 if(i==0 && !IfStampa) Tempy += 10;
499 if(IfStampa) Tempy += 10;
500 if(!IfStampa) p->drawText(StampaY,RisY-Tempy,NumLabel);
501 else p->drawText(StampaY,RisY-Tempy-15,50,20,Qt::AlignRight|Qt::TextDontClip,NumLabel);
504 if(!DIS_IF_TYPE(LogLog,DIS_LOGX)){
506 for(
int i = 0;i<=GrigliaX;i++){
507 Tempx = (int) (RisX/(
double)GrigliaX*i);
509 p->drawLine(QPoint(Tempx,0),QPoint(Tempx,RisY) );
511 p->drawLine(QPoint(Tempx,RisY-10),QPoint(Tempx,RisY) );
512 p->drawLine(QPoint(Tempx,0),QPoint(Tempx,10) );
514 int RiTempX = Tempx+(int)(.5*RisX/(
double)GrigliaX);
515 p->drawLine(QPoint(RiTempX,RisY-5),QPoint(RiTempX,RisY) );
516 p->drawLine(QPoint(RiTempX,0),QPoint(RiTempX,5) );
519 NumLabel.setNum((
double)(xMax-xMin)/(
double)GrigliaX*i+xMin,FormatPrecX,DigPrecX);
521 if(IfStampa) Tempx -= (
int)(9.*NumLabel.length());
522 p->drawText(Tempx,RisY+StampaX,NumLabel);
526 sprintf(stringa,
"%% %.4g",(
double)(yMax-yMin)/(
double)((yMax+yMin)*.5)*100.);
527 p->drawText(RisX/2,10,QString(stringa));
530 if(DIS_IF_TYPE(LogLog,DIS_LOGY)){
536 for(
int i=NyMin;i<0;i++){
541 for(
int i=0;i<NyMin;i++){
546 for(
int i = NyMin;i<=NyMax;i++){
547 Tempy = (int)( (
double)(i-yMin)/((yMax-yMin))*RisY);
548 if(Tempy < 0 || Tempy >= RisY)
continue;
549 sprintf(stringa,
"%.2g",Delta);
550 if(!IfStampa) p->drawText(StampaY,RisY-Tempy,stringa);
551 else p->drawText(StampaY,RisY-Tempy+5,50,20,Qt::AlignRight|Qt::TextDontClip,stringa);
555 p->drawLine( QPoint(0,Tempy),QPoint(RisX,Tempy));
557 p->drawLine(QPoint(0,Tempy),QPoint(15,Tempy) );
558 p->drawLine(QPoint(RisX,Tempy),QPoint(RisX-15,Tempy) );
560 Tempy = (int)( (
double)(i-(yMin)+.30)/((yMax-yMin))*RisY);
561 if(Tempy < 0 || Tempy >= RisY)
continue;
562 p->drawLine(QPoint(0,Tempy),QPoint(10,Tempy) );
563 p->drawLine(QPoint(RisX,Tempy),QPoint(RisX-10,Tempy) );
564 Tempy = (int)( (
double)(i-(yMin)+.60)/((yMax-yMin))*RisY);
565 if(Tempy < 0 || Tempy >= RisY)
continue;
566 p->drawLine(QPoint(0,Tempy),QPoint(10,Tempy) );
567 p->drawLine(QPoint(RisX,Tempy),QPoint(RisX-10,Tempy) );
568 Tempy = (int)( (
double)(i-(yMin)+.77)/((yMax-yMin))*RisY);
569 if(Tempy < 0 || Tempy >= RisY)
continue;
570 p->drawLine(QPoint(0,Tempy),QPoint(10,Tempy) );
571 p->drawLine(QPoint(RisX,Tempy),QPoint(RisX-10,Tempy) );
572 Tempy = (int)( (
double)(i-(yMin)+.90)/((yMax-yMin))*RisY);
573 if(Tempy < 0 || Tempy >= RisY)
continue;
574 p->drawLine(QPoint(0,Tempy),QPoint(10,Tempy) );
575 p->drawLine(QPoint(RisX,Tempy),QPoint(RisX-10,Tempy) );
580 Tempy = (int)(RisY/2.);
581 p->drawLine(QPoint(0,RisY-Tempy),QPoint(RisX,RisY-Tempy));
582 sprintf(stringa,
"%.2g",yMin/2.);
583 p->drawText(0,RisY- Tempy -7,QString(stringa));
586 if(DIS_IF_TYPE(LogLog,DIS_LOGX)){
592 for(
int i=NxMin;i<0;i++){
597 for(
int i=0;i<NxMin;i++){
601 double Ratio = RisX /(xMax-xMin);
602 for(
int i = NxMin;i<=NxMax;i++){
603 sprintf(stringa,
"%.2g",Delta);
604 double x = log10(Delta);
605 Tempx = (int)( (x - xMin)*Ratio);
606 if(Tempx < 0 || Tempx >= RisX)
continue;
607 if(IfStampa) p->drawText(Tempx-strlen(stringa)*9., RisY+35,QString(stringa));
608 else p->drawText( Tempx, RisY ,QString(stringa));
610 p->drawLine( QPoint(Tempx,RisY),QPoint(Tempx,0));
612 p->drawLine(QPoint(Tempx,RisY-15),QPoint(Tempx,RisY) );
613 p->drawLine(QPoint(Tempx,0),QPoint(Tempx,15) );
615 Tempx = (int)( (
double)(x+.30-xMin)*Ratio);
616 if(Tempx < 0 || Tempx >= RisX)
continue;
617 p->drawLine(QPoint(Tempx,RisY-10),QPoint(Tempx,RisY) );
618 p->drawLine(QPoint(Tempx,0),QPoint(Tempx,10) );
619 Tempx = (int)( (
double)(x+.60-xMin)*Ratio);
620 if(Tempx < 0 || Tempx >= RisX)
continue;
621 p->drawLine(QPoint(Tempx,RisY-10),QPoint(Tempx,RisY) );
622 p->drawLine(QPoint(Tempx,0),QPoint(Tempx,10) );
623 Tempx = (int)( (
double)(x+.77-xMin)*Ratio);
624 if(Tempx < 0 || Tempx >= RisX)
continue;
625 p->drawLine(QPoint(Tempx,RisY-10),QPoint(Tempx,RisY) );
626 p->drawLine(QPoint(Tempx,0),QPoint(Tempx,10) );
627 Tempx = (int)( (
double)(x+.90-xMin)*Ratio);
628 if(Tempx < 0 || Tempx >= RisX)
continue;
629 p->drawLine(QPoint(Tempx,RisY-10),QPoint(Tempx,RisY) );
630 p->drawLine(QPoint(Tempx,0),QPoint(Tempx,10) );
635 void ElementiGrafici::GrRiscala(){
636 GrMessage(
"Visualizza.Dis.GrRiscala.x");
637 if(DIS_IF_TYPE(IfRiscala,RIS_UNO) ){
639 xMin =
v1->
pMin(CoordX,NVisMin,NVisMax);
640 xMax =
v1->
pMax(CoordX,NVisMin,NVisMax);
646 GrMessage(
"Visualizza.Dis.GrRiscala.y");
647 yMin =
v1->
pMin(CoordY,NVisMin,NVisMax);
648 yMax =
v1->
pMax(CoordY,NVisMin,NVisMax);
650 else if(DIS_IF_TYPE(IfRiscala,RIS_TUTTI) ){
651 GrMessage(
"Visualizza.Dis.GrRiscala.Tutto %d",NVar);
659 if( DIS_IF_TYPE(IfDisegna,DIS_PUNTI) ){
660 GrMessage(
"Visualizza.Dis.GrRiscala.Punti");
664 if( DIS_IF_TYPE(IfDisegna,DIS_MOMENTI) ){
665 GrMessage(
"Visualizza.Dis.GrRiscala.Momenti");
671 if(DIS_IF_TYPE(LogLog,DIS_LOGX)){
672 GrMessage(
"Visualizza.Dis.GrRiscala.Logx");
674 xMin =
v1->
pMinLog(CoordX,NVisMin,NVisMax);
675 xMax =
v1->
pMaxLog(CoordX,NVisMin,NVisMax);
678 xMin = log10(NVisMin);
679 xMax = log10(NVisMax);
682 if(DIS_IF_TYPE(LogLog,DIS_LOGY)){
683 GrMessage(
"Visualizza.Dis.GrRiscala.Logy");
684 if( DIS_IF_TYPE(IfRiscala,RIS_UNO) ){
685 yMin =
v1->
pMinLog(CoordY,NVisMin,NVisMax);
686 yMax =
v1->
pMaxLog(CoordY,NVisMin,NVisMax);
688 else if( DIS_IF_TYPE(IfRiscala,RIS_TUTTI) ){
701 GrMessage(
"xBound %lf-%lf yBound %lf-%lf\n",xMin,xMax,yMin,yMax);
702 ScalaTopoX = xMax-xMin;
703 ScalaTopoY = yMax-yMin;
708 yMax += (yMax-yMin)*ViewportY;
709 yMin -= (yMax-yMin)*ViewportY;
710 xMax += (xMax-xMin)*ViewportX;
711 xMin -= (xMax-xMin)*ViewportX;
713 void ElementiGrafici::GrLegenda(QPainter *p){
714 GrMessage(
"Visualizza.Dis.GrLegenda");
722 int PosLegX=(int)(PosLegenda[0]*RisX);
723 int PosLegY=(int)((1.-PosLegenda[1])*RisY);
724 int PosFinL=PosLegX, PosFinY=PosLegY;
726 if(IfStampa) IncrY = 30;
727 for(
int s=0;s<NVar;s++){
729 if(LineaCome[s]==0)
continue;
730 p->setBrush( GrLinee[s] );
731 p->setPen( QPen( GrLinee[s],2 ) );
732 Quadrati = DIS_IF_TYPE(LineaCome[s],LINEA_PUNTO);
733 Linee = DIS_IF_TYPE(LineaCome[s],LINEA_TRATTO);
734 Punto = QPoint(PosLegX,PosFinY-5);
735 Punto1 = QPoint(PosLegX+15,PosFinY-5);
736 p->drawLine(Punto,Punto1);
737 p->drawText(PosLegX+25,PosFinY,GrLabel[s]);
741 void ElementiGrafici::GrScript(
char *File2Read,QPainter *p){
742 GrMessage(
"Visualizza.Dis.GrScript");
744 if( (File2Open = fopen(File2Read,
"r"))==0){
753 for(
int k=0;!(fgets(cLine,256,File2Open)==NULL);k++){
754 if(strncmp(cLine,
"PutStr",6)==0){
755 fgets(cLine,256,File2Open);
756 sscanf(cLine,
"%lf %lf %lf %lf\n",Color,Color+1,Color+2,Color+3);
757 fgets(cLine,256,File2Open);
758 sscanf(cLine,
"%lf %lf %lf %lf\n",Pos,Pos+1,Pos+2,Pos+3);
760 fgets(cLine,256,File2Open);
762 sprintf(String,
"%s",cLine);
763 QColor ColorLabel = QColor((
int)(255.*Color[0]),(
int)(255.*Color[1]),(
int)(255.*Color[2]),(
int)(255.*Color[3]));
764 if(IfStampa) Pos[3] *= 2.;
765 p->setFont(QFont(
"Palatino",Pos[3]));
766 p->setBrush(ColorLabel);
769 p->drawText(Pos[0]*RisX,(1.-Pos[1])*RisY,QString(String));
772 p->setFont(QFont(
"Palatino",FontSize));
774 p->setFont(QFont(
"Palatino",12));
776 else if(strncmp(cLine,
"PutLine",7)==0){
778 fgets(cLine,256,File2Open);
779 p->setPen(QPen(Qt::blue,3,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
780 sscanf(cLine,
"%lf %lf %lf %lf\n",Color,Color+1,Color+2,Color+3);
781 QColor ColorLabel = QColor((
int)(255.*Color[0]),(
int)(255.*Color[1]),(
int)(255.*Color[2]),(
int)(255.*Color[3]));
782 p->setBrush(ColorLabel);
784 fgets(cLine,256,File2Open);
785 sscanf(cLine,
"%lf %lf %lf %lf\n",Pos,Pos+1,Pos+2,Pos+3);
786 int Fromx = (int)(RisX*Pos[0]);
787 int Fromy = (int)(RisY*(1.-Pos[1]));
788 int Tox = (int)(RisX*Pos[2]);
789 int Toy = (int)(RisY*(1.-Pos[3]));
790 Punto = QPoint(Fromx,Fromy);
791 Punto1 = QPoint(Tox,Toy);
792 p->drawLine(Punto,Punto1);
794 else if(strncmp(cLine,
"Text",4)==0){
796 fgets(cLine,256,File2Open);
797 sscanf(cLine,
"%lf %lf %lf %lf\n",Hue,Hue+1,Hue+2,Hue+3);
798 for(
int i=0;i<4;i++) iHue[i] = (
int)(255.*Hue[i]);
799 p->setBrush( QColor(iHue[0],iHue[1],iHue[2],iHue[3]) );
801 fgets(cLine,256,File2Open);
802 sscanf(cLine,
"%lf %lf\n",Pos,Pos+1);
803 int Fromx = (int)(width()*Pos[0]);
804 int Fromy = (int)(height()*(1.-Pos[1]));
806 fgets(cLine,256,File2Open);
807 QChar ChType = QChar::NoCategory;
814 for(
int i=0,j=0;i<strlen(cLine);i++){
815 if(cLine[i] ==
'\\'){
819 else if(cLine[i] ==
'^'){
823 else if(cLine[i] ==
'_'){
827 else if(cLine[i] ==
'%'){
833 String.insert(j,QChar((uint)(cLine[i]+IfSymbol)));
836 p->drawText(Fromx,Fromy,String,-1,Qt::AlignTop);
838 else if(strncmp(cLine,
"Picture",4)==0){
839 fgets(cLine,256,File2Open);
840 sscanf(cLine,
"%lf %lf %lf %lf\n",Pos,Pos+1,Pos+2,Pos+3);
841 int Fromx = (int)(width()*Pos[0]);
842 int Fromy = (int)(height()*(1.-Pos[1]));
843 int Tox = (int)(width()*Pos[2]);
844 int Toy = (int)(height()*(1.-Pos[3]));
846 fgets(cLine,512,File2Open);
847 for(
int c=0;c<strlen(cLine)-1;c++) String[c] = cLine[c];
848 p->drawImage(QRect(Fromx,Fromy,Tox,Toy),QImage(QString(String),0));
850 else if(strncmp(cLine,
"Background",10)==0){
855 void ElementiGrafici::GrConf(
char *File2Read){
856 GrMessage(
"Visualizza.Dis.GrConf");
858 if( (File2Open = fopen(File2Read,
"r"))==0){
863 for(
int k=0;!(fgets(cLine,256,File2Open)==NULL);k++){
866 if(strncmp(cLine,
"NGrid",5)==0){
867 fgets(cLine,256,File2Open);
868 sscanf(cLine,
"%d %d\n",&GrigliaX,&GrigliaY);
870 else if(strncmp(cLine,
"XFormula",8)==0){
871 fgets(cLine,256,File2Open);
872 sscanf(cLine,
"%s\n",XFormula);
875 else if(strncmp(cLine,
"YFormula",8)==0){
876 fgets(cLine,256,File2Open);
877 sscanf(cLine,
"%s\n",YFormula);
880 else if(strncmp(cLine,
"XBound",6)==0){
881 fgets(cLine,256,File2Open);
882 if( DIS_IF_TYPE(IfRiscala,RIS_TUTTI) )
883 sscanf(cLine,
"%lf %lf\n",&xMin,&xMax);
884 if(DIS_IF_TYPE(LogLog,DIS_LOGX)){
885 if(xMin < 0 ) printf(
"xMin can't be negative in log log\n");
886 else xMin = log10(xMin);
887 if(xMax < 0 ) printf(
"xMax can't be negative in log log\n");
888 else xMax = log10(xMax);
891 else if(strncmp(cLine,
"YBound",6)==0){
892 fgets(cLine,256,File2Open);
893 if( DIS_IF_TYPE(IfRiscala,RIS_TUTTI) )
894 sscanf(cLine,
"%lf %lf\n",&yMin,&yMax);
895 if(DIS_IF_TYPE(LogLog,DIS_LOGY)){
896 if(yMin < 0 ) printf(
"yMin can't be negative in log log\n");
897 else yMin = log10(yMin);
898 if(yMax < 0 ) printf(
"yMax can't be negative in log log\n");
899 else yMax = log10(yMax);
902 else if(strncmp(cLine,
"PosLegend",6)==0){
903 fgets(cLine,256,File2Open);
904 sscanf(cLine,
"%lf %lf %lf %lf\n",(PosLegenda+0),(PosLegenda+1),(PosLegenda+2),(PosLegenda+3));
906 else if(strncmp(cLine,
"PosInterp",6)==0){
907 fgets(cLine,256,File2Open);
908 sscanf(cLine,
"%lf %lf\n",(PosInterp+0),(PosInterp+1));
910 else if(strncmp(cLine,
"DigPrecX",8)==0){
911 fgets(cLine,256,File2Open);
912 sscanf(cLine,
"%d %c\n",&DigPrecX,&FormatPrecX);
914 else if(strncmp(cLine,
"DigPrecY",8)==0){
915 fgets(cLine,256,File2Open);
916 sscanf(cLine,
"%d %c\n",&DigPrecY,&FormatPrecY);
918 else if(strncmp(cLine,
"ViewportX",9)==0){
919 fgets(cLine,256,File2Open);
920 sscanf(cLine,
"%lf\n",&ViewportX);
922 else if(strncmp(cLine,
"ViewportY",9)==0){
923 fgets(cLine,256,File2Open);
924 sscanf(cLine,
"%lf\n",&ViewportY);
926 else if(strncmp(cLine,
"FontSize",8)==0){
927 fgets(cLine,256,File2Open);
928 sscanf(cLine,
"%d\n",&FontSize);
930 else if(strncmp(cLine,
"RatioWidthHeight",16)==0){
931 fgets(cLine,256,File2Open);
932 sscanf(cLine,
"%lf\n",&RatioWidthHeight);
934 else if(strncmp(cLine,
"LabelX",6)==0){
935 char *String = (
char *)calloc(265,
sizeof(
char));
936 fgets(cLine,256,File2Open);
937 for(
int c=0;c<strlen(cLine);c++) String[c] = cLine[c];
939 StringToUnicode(String,&
nomeEtX);
942 else if(strncmp(cLine,
"LabelY",6)==0){
943 char *String = (
char *)calloc(265,
sizeof(
char));
944 fgets(cLine,256,File2Open);
945 for(
int c=0;c<strlen(cLine);c++) String[c] = cLine[c];
947 StringToUnicode(String,&
nomeEtY);
950 else if(strncmp(cLine,
"Title",5)==0){
951 char *String = (
char *)calloc(265,
sizeof(
char));
952 fgets(cLine,256,File2Open);
953 for(
int c=0;c<strlen(cLine);c++) String[c] = cLine[c];
955 StringToUnicode(String,&
nomeTit);
958 else if(strncmp(cLine,
"Line",4)==0){
962 fgets(cLine,256,File2Open);
963 sscanf(cLine,
"%d\n",&NLine);
969 fgets(cLine,256,File2Open);
970 sscanf(cLine,
"%lf %lf %lf %lf\n",Color,Color+1,Color+2,Color+3);
971 fgets(cLine,256,File2Open);
972 sscanf(cLine,
"%d\n",&Type);
974 QColor ColorSet = QColor((
int)(255.*Color[0]),(
int)(255.*Color[1]),(
int)(255.*Color[2]),(
int)(255.*Color[3]));
975 GrLinee[NLine] = ColorSet;
976 LineaCome[NLine] = Type;
977 fgets(cLine,256,File2Open);
978 GrLabel[NLine].clear();
979 StringToUnicode(cLine,GrLabel + NLine);
980 GrMessage(
"Line n: %d type: %d name: %s color: %lf %lf %lf\n",NLine,Type,cLine,Color[0],Color[1],Color[2]);
983 GrMessage(
"NGrid %d %d XBond %lf %lf YBound %lf %lf\n",GrigliaX,GrigliaY,xMin,xMax,yMin,yMax);
986 void ElementiGrafici::StringToUnicode(
char *cLine,QString *Label){
987 QChar ChType = QChar::NoCategory;
990 for(
int i=0,j=0;i<strlen(cLine);i++){
992 if(cLine[i] ==
'\\' && i < strlen(cLine)-1){
993 if(cLine[i+1] ==
's'){
998 else if(cLine[i+1] ==
'l')
999 ChType = QChar::Letter_Lowercase;
1000 else if(cLine[i+1] ==
'u')
1001 ChType = QChar::Letter_Uppercase;
1002 else if(cLine[i+1] ==
'n'){
1005 ChType = QChar::NoCategory;
1011 ChType = QChar::NoCategory;
1013 QChar Char1 = QChar(Char+CharOffset);
1016 Label->insert(j,QChar(Char1.cell(),UnicodeRow));
double pPunti(int n)
Value of the elaborated array at position.
double a1
a0 + a1 x + a2 x^2
int pNRow(int CoordY)
Print the maximum number of data for the column.
double pMinLog(int CoordY, int NVisMin, int NVisMax)
Print the minimum of the column.
char * nomeConf
Name of the config file.
double pInter1(int n)
Print the postion.
double pMinGlobLog(int NVisMin, int NVisMax)
Print the minimum of all sets.
double pPuntiErr(int n)
Value of the error array at postion.
double a2
a0 + a1 x + a2 x^2
double MinimoY
Minimum of the parabola.
double yMin
Minimum of the ordinate.
QString nomeTit
Title name.
double PuntiMax()
Print the maximum of.
double ErrQ
Error on the intercept.
double pMax(int CoordY, int NVisMin, int NVisMax)
Print the maximum of the column.
QString nomeEtY
Y axis label.
double yMax
Maximum of the ordinate.
double PuntiMin()
Print the minimum of.
void pGlobBorder(double *xMin, double *xMax, double *yMin, double *yMax)
Print global borders.
int NDis
Current number of visualisation (debugging)
QString nomeEtX
X axis label.
double pMaxLog(int CoordY, int NVisMin, int NVisMax)
Print the maximum of the column.
double ErrM
Error on the slope.
double pMaxGlobLog(int NVisMin, int NVisMax)
Print the maximum of all sets.
void setXFormula(char *str)
Set the value of XFormula.
double pInter(int n)
Print the postion.
double a0
a0 + a1 x + a2 x^2
double Val(int CoordY, int n)
Value at the position.
int IsAbscissa(int Col)
If the column is an ascissa.
double Gauss(double Media, double Scarto, double x)
Gaussian.
double Minimo
Minimum of the parabola.
void setYFormula(char *str)
Set the value of YFormula.
int Num
Number of points considered.
void pMinMaxGlob(int NVisMin, int NVisMax)
Find the borders globally.
double Abscissa(int CoordY, int n)
Value of the Abscissa at position.
double pMin(int CoordY, int NVisMin, int NVisMax)
Print the minimum of the column.
VarDatFile * v1
Class for the file handle.