Allink
v0.1
|
00001 /*********************************************************************** 00002 ElementiGrafici: Class that interface the VarData, VarElementiGrafici 00003 and Matematica classes function for comunicating with main window of 00004 Visualizza. The main function is the plotting function DisegnaPunti() 00005 that provides the visualisation of two set of data. The bars at the 00006 bottom permits to change the visualisation and the limit for the analisys 00007 Copyright (C) 2008 by Giovanni Marelli <sabeiro@virgilio.it> 00008 00009 00010 This program is free software; you can redistribute it and/or modify 00011 it under the terms of the GNU General Public License as published by 00012 the Free Software Foundation; either version 2 of the License, or 00013 (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 ***********************************************************************/ 00024 ;// α-a β-b γ-c δ-d ε-e ζ-f η-g θ-h ι-i κ-l λ-k μ-l ν-m ξ-n ο-o π-p ρ-q σ-r ς-r τ-s υ-t φ-u ψ-v ω-x χ-y 00025 #include "ElementiGrafici.h" 00026 #include <qpainter.h> 00027 #include <Q3PaintDeviceMetrics> 00028 00029 void ElementiGrafici::GrMessage(const char * s, ...){ 00030 #ifdef DEBUG 00031 va_list args; 00032 va_start(args, s); 00033 fprintf(stderr,"%d) ",NDis); 00034 vfprintf(stderr, s, args); 00035 fprintf(stderr, "\n"); 00036 va_end(args); 00037 #else 00038 return; 00039 #endif 00040 } 00041 void ElementiGrafici::paintEvent(QPaintEvent *e){ 00042 GrMessage("Visualizza.paintEvent(begin)"); 00043 //QRect DaNuovo = e->rect(); 00044 // if(DaNuovo.intersects( PuntiRett(0)) ) 00045 QPainter p(this); 00046 DisegnaPunti(&p); 00047 if(PrimaVolta){ 00048 Immagine.load("Logo.png"); 00049 p.drawPixmap(200,300,QPixmap(Immagine),0,0,-1,-1); 00050 } 00051 GrMessage("Visualizza.paintEvent(end)"); 00052 } 00053 void ElementiGrafici::DisegnaPunti(QPainter *p){ 00054 if(PrimaVolta){ 00055 return; 00056 } 00057 if(NVisMin < 0 || NVisMax > PuntiMax || NVisMin > NVisMax){ 00058 sprintf(stringa,"Non `e corretto l'ordine 0<=%d<%d<=%d",NVisMin,NVisMax,PuntiMax); 00059 printf("Non `e corretto l'ordine 0<=%d<%d<=%d\n",NVisMin,NVisMax,PuntiMax); 00060 ErrPrima->message(stringa); 00061 return; 00062 } 00063 if( IfRiscala != 0 ) GrRiscala(); 00064 GrStampante(p); 00065 GrConf(nomeConf); 00066 GrScript(nomeConf,p); 00067 if( DIS_IF_TYPE(IfDisegna,DIS_TUTTI) ){ 00068 for(int s=0,sColor=0;s<NVar;s++){ 00069 if(v1->IsAbscissa(s)) continue; 00070 sColor = s; 00071 p->setBrush( GrLinee[sColor] ); 00072 p->setPen( QPen( GrLinee[sColor],2 ) ); 00073 Quadrati = DIS_IF_TYPE(LineaCome[sColor],LINEA_PUNTO); 00074 Linee = DIS_IF_TYPE(LineaCome[sColor],LINEA_TRATTO); 00075 GrSet(p,s); 00076 sColor++; 00077 } 00078 } 00079 if( DIS_IF_TYPE(IfDisegna,DIS_SEGNALE) ){ 00080 p->setBrush( GrLinee[CoordY] ); 00081 p->setPen( QPen( GrLinee[CoordY],2 ) ); 00082 GrSet(p,CoordY); 00083 } 00084 if( DIS_IF_TYPE(IfDisegna,DIS_MOMENTI) ) 00085 GrMomenti(p); 00086 if( DIS_IF_TYPE(IfDisegna,DIS_PUNTI) ){ 00087 p->setBrush( GrLinee[CoordY] ); 00088 p->setPen( QPen( GrLinee[CoordY],2 ) ); 00089 GrPunti(p); 00090 } 00091 if( DIS_IF_TYPE(IfDisegna,DIS_BLU) ) GrBlu(p); 00092 if( Griglia ) GrGriglia(p); 00093 if(!IfStampa) GrBarre(p); 00094 GrLegenda(p); 00095 GrMessage("Disegna %d = Tutti %d Set %d Momenti %d Punti %d Blu %d Riscala %d = RisUno %d RisTutti %d",IfDisegna, 00096 DIS_IF_TYPE(IfDisegna,DIS_TUTTI), 00097 DIS_IF_TYPE(IfDisegna,DIS_SEGNALE), 00098 DIS_IF_TYPE(IfDisegna,DIS_MOMENTI), 00099 DIS_IF_TYPE(IfDisegna,DIS_PUNTI), 00100 DIS_IF_TYPE(IfDisegna,DIS_BLU), 00101 IfRiscala, 00102 DIS_IF_TYPE(IfRiscala,RIS_UNO), 00103 DIS_IF_TYPE(IfRiscala,RIS_TUTTI)); 00104 NDis++; 00105 } 00106 void ElementiGrafici::GrSet(QPainter *p,int s){ 00107 GrMessage("Visualizza.Dis.GrSet"); 00108 if(v1->IsAbscissa(s)) return; 00109 //printf("%d %d\n",s,v1->pRefAbsc(s)); 00110 int IfDrawLine = 0; 00111 for(int i=MIN(NVisMin,v1->pNRow(s));i<MIN(NVisMax,v1->pNRow(s));i++){ 00112 //printf("%lf %lf\n",v1->Ascissa(i),v1->Val(i)); 00113 if(!DIS_IF_TYPE(LogLog,DIS_LOGX)) 00114 Tempx = (int) ( (double)((v1->Abscissa(s,i)-xMin)*RisX)/(double)(xMax-xMin) ); 00115 else { 00116 if(v1->Abscissa(s,i)<=0.) continue; 00117 Tempx = (int) ( (log10(v1->Abscissa(s,i))-xMin)/(xMax-xMin)*RisX); 00118 } 00119 if(!DIS_IF_TYPE(LogLog,DIS_LOGY)) 00120 Tempy = RisY-(int)( (v1->Val(s,i)-yMin)*RisY/ (yMax-yMin) ); 00121 else { 00122 if(v1->Val(s,i) <= 0.) continue; 00123 Tempy = RisY-(int)( (log10(v1->Val(s,i))-yMin)*RisY/ (yMax-yMin) ); 00124 //printf("%d %d %lf\n",Tempy,RisY,log10(v1->Val(s,i))); 00125 } 00126 // if(Tempx > RisX){IfDrawLine=0;continue;} 00127 // if(Tempy > RisY){IfDrawLine=0;continue;} 00128 // if(Tempx < 0 ){IfDrawLine=0;continue;} 00129 // if(Tempy < 0 ){IfDrawLine=0;continue;} 00130 if(Tempx > RisX){Tempx = RisX;} 00131 if(Tempy > RisY){Tempy = RisY;} 00132 if(Tempx < 0 ){Tempx = 0;} 00133 if(Tempy < 0 ){Tempy = 0;} 00134 Punto = QPoint(Tempx, Tempy); 00135 //if(Quadrati) p->drawRect( PuntiRett(Punto) ); 00136 if(Quadrati){ 00137 Punto2 = QPoint(Punto.x()-PointSize,Punto.y()-PointSize); 00138 Punto3 = QPoint(Punto.x()+PointSize,Punto.y()+PointSize); 00139 p->drawLine(Punto2,Punto3); 00140 Punto2 = QPoint(Punto.x()+PointSize,Punto.y()-PointSize); 00141 Punto3 = QPoint(Punto.x()-PointSize,Punto.y()+PointSize); 00142 p->drawLine(Punto2,Punto3); 00143 } 00144 // if(Quadrati){ 00145 // Punto2 = QPoint(Punto.x()+PointSize,Punto.y()+PointSize); 00146 // Punto3 = QPoint(Punto.x()+PointSize,Punto.y()-PointSize); 00147 // p->drawLine(Punto2,Punto3); 00148 // Punto2 = QPoint(Punto.x()+PointSize,Punto.y()-PointSize); 00149 // Punto3 = QPoint(Punto.x()-PointSize,Punto.y()-PointSize); 00150 // p->drawLine(Punto2,Punto3); 00151 // Punto2 = QPoint(Punto.x()-PointSize,Punto.y()-PointSize); 00152 // Punto3 = QPoint(Punto.x()-PointSize,Punto.y()+PointSize); 00153 // p->drawLine(Punto2,Punto3); 00154 // Punto2 = QPoint(Punto.x()-PointSize,Punto.y()+PointSize); 00155 // Punto3 = QPoint(Punto.x()+PointSize,Punto.y()+PointSize); 00156 // p->drawLine(Punto2,Punto3); 00157 // } 00158 if(Linee && IfDrawLine) p->drawLine(Punto,Punto1); 00159 IfDrawLine = 1; 00160 Punto1 = Punto; 00161 } 00162 } 00163 void ElementiGrafici::GrPunti(QPainter *p){ 00164 GrMessage("Visualizza.Dis.GrPunti"); 00165 for(int i=NVisMin;i<NVisMax*NMobile;i+=NMobile){// FIXME 00166 if(xMin > v1->Abscissa(CoordY,i)) xMin = v1->Abscissa(CoordY,i); 00167 if(xMax < v1->Abscissa(CoordY,i)) xMax = v1->Abscissa(CoordY,i); 00168 } 00169 ScalaTopoX = xMax-xMin; 00170 //FILE *Apri = fopen("Scritto.dat","w"); 00171 for(int i=NVisMin;i<NVisMax;i++){ 00172 //printf("%lf %lf\n",v1->Ascissa(i*NMobile),v1->pPunti(i)); 00173 if(!DIS_IF_TYPE(LogLog,DIS_LOGX)) 00174 Tempx = (int) ( (double)((v1->Abscissa(CoordY,i*NMobile)-xMin)*RisX)/(double)(xMax-xMin) ); 00175 else{ 00176 if(v1->Abscissa(CoordY,i)<=0.) continue; 00177 Tempx = (int) ( (log10(v1->Abscissa(CoordY,i))-xMin)/(xMax-xMin)*RisX); 00178 } 00179 if(!DIS_IF_TYPE(LogLog,DIS_LOGY)) 00180 Tempy = RisY-(int)( (v1->pPunti(i)-yMin)*RisY/ (yMax-yMin) ); 00181 else { 00182 if(v1->pPunti(i) <= 0.) continue; 00183 Tempy = RisY-(int)( (log10(v1->pPunti(i))-yMin)*RisY/ (yMax-yMin) ); 00184 //printf("%d %d %lf\n",Tempy,RisY,log10(v1->Val(s,i))); 00185 } 00186 if(Tempx > RisX) Tempx=RisX; 00187 if(Tempy > RisY) Tempy=RisY; 00188 if(Tempx < 0 ) Tempx=0; 00189 if(Tempy < 0 ) Tempy=0; 00190 Punto = QPoint(Tempx, Tempy); 00191 if(Quadrati) p->drawRect( PuntiRett(Punto) ); 00192 if( Linee && i > NVisMin) p->drawLine(Punto,Punto1); 00193 Punto1 = Punto; 00194 int ErrY = (int)( .5*(v1->pPuntiErr(i))*RisY/ (yMax-yMin) ); 00195 QPoint PuntoErr1(Tempx,Tempy+ErrY); 00196 QPoint PuntoErr2(Tempx,Tempy-ErrY); 00197 //p->setPen( QPen(Qt::SolidPattern,1,Qt::SolidLine,Qt::SquareCap,Qt::BevelJoin) ); 00198 //fprintf(Apri,"%lf %lf %lf\n",v1->Ascissa(i*NMobile)*.2,v1->pPunti(i),v1->pPuntiErr(i)); 00199 p->drawLine(PuntoErr1,PuntoErr2); 00200 } 00201 //fclose(Apri); 00202 } 00203 void ElementiGrafici::GrMomenti(QPainter *p){ 00204 GrMessage("Visualizza.Dis.GrMomenti"); 00205 p->setBrush( Qt::red ); 00206 p->setPen( Qt::red ); 00207 for(int i=NVisMin;i<NVisMax;i++){ 00208 Tempx = (int) ( (double)((i-NVisMin)*RisX)/(double)(NVisMax-NVisMin) ); 00209 int Tempx2 = (int) ( (double)((i+1-NVisMin)*RisX)/(double)(NVisMax-NVisMin) ); 00210 Tempy = RisY-(int)( (v1->pInter(i)-yMin)*RisY/ (yMax-yMin) ); 00211 Punto = QPoint(Tempx,Tempy); 00212 QPoint Punto2 = QPoint(Tempx2,Tempy); 00213 if( Quadrati ) p->drawRect( PuntiRett(Punto) ); 00214 if( Linee && i>NVisMin){ 00215 p->drawLine(Punto2,Punto); 00216 p->drawLine(Punto,Punto1); 00217 } 00218 Punto1 = Punto2; 00219 } 00220 GrMessage("Visualizza.Dis.GrMomenti.Blue"); 00221 p->setBrush( Qt::blue ); 00222 p->setPen( Qt::blue ); 00223 yBluMin = v1->pInter1(NVisMin); 00224 yBluMax = v1->pInter1(NVisMin); 00225 for(int i=NVisMin;i<NVisMax;i++){ 00226 Tempx = (int) ( (double)((i-NVisMin)*RisX)/(double)(NVisMax-NVisMin) ); 00227 Tempy = RisY-(int)( (v1->pInter1(i)-yMin)*RisY/ (yMax-yMin) ); 00228 Punto = QPoint(Tempx,Tempy); 00229 if( Quadrati ) p->drawRect( PuntiRett(Punto) ); 00230 if( Linee && i>NVisMin) p->drawLine(Punto,Punto1); 00231 Punto1 = Punto; 00232 if( yBluMin > v1->pInter1(i) ) 00233 yBluMin = v1->pInter1(i); 00234 if( yBluMax < v1->pInter1(i) ) 00235 yBluMax = v1->pInter1(i); 00236 } 00237 GrMessage("Visualizza.Dis.GrMomenti.String"); 00238 sprintf(stringa,"%.2g",yBluMax); 00239 p->drawText(RisX-70,15,QString(stringa)); 00240 sprintf(stringa,"%.2g",yBluMax/2.); 00241 p->drawText(RisX-70,(int)RisY/2,QString(stringa)); 00242 sprintf(stringa,"%.2g",yBluMin); 00243 p->drawText(RisX-70,RisY-15,QString(stringa)); 00244 int PosMomX=(int)(PosInterp[0]*RisX); 00245 int PosMomY=(int)((1.-PosInterp[1])*RisY); 00246 sprintf(stringa,"m %.4g s %g N %d",m1.Uno,m1.Due,m1.Num); 00247 p->drawText(PosMomX,PosMomY,QString(stringa)); 00248 if(!IfStampa){ 00249 sprintf(stringa,"t %g Chi %.2g",m1.Tre,m1.Chi); 00250 p->drawText(RisX/2-70,RisY/2+120,QString(stringa)); 00251 } 00252 } 00253 void ElementiGrafici::GrBlu(QPainter *p){ 00254 GrMessage("Visualizza.Dis.GrBlu"); 00255 int IfDrawLine = 0; 00256 p->setBrush( Qt::blue ); 00257 p->setPen( Qt::blue ); 00258 if(!IfStampa) 00259 p->setPen(QPen(Qt::blue,1,Qt::DashLine,Qt::RoundCap,Qt::RoundJoin)); 00260 else 00261 p->setPen(QPen(Qt::blue,3,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin)); 00262 for(int i=NElMin;i<NElMax;i++){ 00263 if(!DIS_IF_TYPE(LogLog,DIS_LOGX)) 00264 Tempx = (int) ( (double)((v1->Abscissa(CoordY,i)-xMin)*RisX)/(double)(xMax-xMin) ) ; 00265 else 00266 //Tempx = (int) ( log10((v1->Abscissa(CoordY,i))/(xMin))/log10((xMax)/(xMin))*RisX ); 00267 Tempx = (int) ( (log10(v1->Abscissa(CoordY,i))-xMin)/(xMax-xMin)*RisX ); 00268 if( DIS_IF_TYPE(IfDisegna,DIS_RETTA) ){ 00269 if(!DIS_IF_TYPE(LogLog,DIS_LOGY)){ 00270 Tempy = RisY-(int)( (v1->Abscissa(CoordY,i)*r1.m+r1.q-yMin)*RisY/ (yMax-yMin) ); 00271 } 00272 else 00273 //Tempy = RisY-(int)( (log10(v1->Abscissa(CoordY,i))*r1.m+r1.q-log10(yMin))*RisY/ (log10(yMax/yMin)) ); 00274 Tempy = RisY-(int)( (log10(v1->Abscissa(CoordY,i))*r1.m+r1.q-yMin)*RisY/(yMax-yMin) ); 00275 } 00276 else if( DIS_IF_TYPE(IfDisegna,DIS_PARABOLA) ){ 00277 if(!DIS_IF_TYPE(LogLog,DIS_LOGY)){ 00278 Tempy = RisY-(int)( (v1->Abscissa(CoordY,i)*p1.a1+v1->Abscissa(CoordY,i)*v1->Abscissa(CoordY,i)*p1.a2+p1.a0-yMin)*RisY/ (yMax-yMin) ); 00279 } 00280 else{ 00281 double y = log10(v1->Abscissa(CoordY,i)); 00282 // Tempy = RisY-(int)( (log10(v1->Abscissa(CoordY,i))*log10(v1->Abscissa(CoordY,i))*p1.a2+log10(v1->Abscissa(CoordY,i))*p1.a1+p1.a0-log10(yMin))*RisY/ (log10(yMax/yMin)) ); 00283 Tempy = RisY-(int)((y*y*p1.a2+y*p1.a1+p1.a0-yMin)*RisY/(yMax-yMin)); 00284 } 00285 } 00286 else if( DIS_IF_TYPE(IfDisegna,DIS_EXP) ){ 00287 if(!DIS_IF_TYPE(LogLog,DIS_LOGY)){ 00288 Tempy = RisY-(int)((exp(r1.q+r1.m*v1->Abscissa(CoordY,i))-yMin)*RisY/(yMax-yMin)); 00289 } 00290 else 00291 Tempy = RisY-(int)((exp(r1.q+r1.m*log10(v1->Abscissa(CoordY,i)))-yMin)*RisY/(yMax-yMin)); 00292 } 00293 else if( DIS_IF_TYPE(IfDisegna,DIS_GAUSS) ){ 00294 Tempy = RisY-(int)( (v1->Gauss(m1.Uno,m1.Due,v1->Abscissa(CoordY,i))-yMin)*RisY/(yMax-yMin)); 00295 } 00296 else 00297 Tempy = RisY-(int)( (v1->pInter1(i)-yMin)*RisY/ (yMax-yMin) ); 00298 //printf("%d %d %d %d %lf %lf %lf %lf\n",Tempx,Tempy,RisX,RisY,yMin,yMax,v1->Abscissa(CoordY,i),v1->Val(CoordY,i)); 00299 Punto = QPoint(Tempx,Tempy); 00300 if(Tempx > RisX){IfDrawLine=0;continue;} 00301 if(Tempy > RisY){IfDrawLine=0;continue;} 00302 if(Tempx < 0 ){IfDrawLine=0;continue;} 00303 if(Tempy < 0 ){IfDrawLine=0;continue;} 00304 //if( Quadrati ) p->drawRect( PuntiRett(Punto) ); 00305 if( /*Linee && */ IfDrawLine) p->drawLine(Punto,Punto1); 00306 Punto1 = Punto; 00307 IfDrawLine = 1; 00308 } 00309 //----------------------LABEL------------------------- 00310 int PosLegX=(int)(PosInterp[0]*RisX); 00311 int PosLegY=(int)((1.-PosInterp[1])*RisY); 00312 if( DIS_IF_TYPE(IfDisegna,DIS_RETTA) ){ 00313 // NumLabel.setNum(r1.m,'g',DigPrec); 00314 if(!IfStampa){ 00315 sprintf(stringa,"m %.3g+-%.3g q %.3g+-%.3g",r1.m,r1.ErrM,r1.q,r1.ErrQ); 00316 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY,QString(stringa)); 00317 sprintf(stringa,"r %.5g Corr %.3g",r1.Corr,r1.Cov); 00318 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY+15,QString(stringa)); 00319 } 00320 else { 00321 sprintf(stringa,"y=%.3f x + %.3f",r1.m,r1.ErrM,r1.q,r1.ErrQ); 00322 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY,QString(stringa)); 00323 //sprintf(stringa,"r %.5e Corr %.3e",r1.Corr,r1.Cov); 00324 //p->drawText(RisX/2-RisX/8,RisY-15,QString(stringa)); 00325 } 00326 } 00327 else if( DIS_IF_TYPE(IfDisegna,DIS_PARABOLA) ){ 00328 int RefY = (int)(.1*RisY); 00329 if(!IfStampa){ 00330 sprintf(stringa,"%.2g + %.2g x + %.2g x^2",p1.a0,p1.a1,p1.a2); 00331 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY,QString(stringa)); 00332 sprintf(stringa,"Minimum (%.3g %.3g) ",p1.Minimo,p1.MinimoY); 00333 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY+25,QString(stringa)); 00334 } 00335 else { 00336 p->setFont(QFont("Palatino",FontSize-6)); 00337 sprintf(stringa,"%.2g + %.2g x + %.2g x^2",p1.a0,p1.a1,p1.a2); 00338 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY,QString(stringa)); 00339 sprintf(stringa,"min %.2g ",p1.Minimo); 00340 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY+25,QString(stringa)); 00341 p->setFont(QFont("Palatino",FontSize)); 00342 } 00343 } 00344 else if( DIS_IF_TYPE(IfDisegna,DIS_GAUSS) ){ 00345 int RefY = (int)(.1*RisY); 00346 sprintf(stringa,"x_0 = %.3g s = %.3g ",m1.Uno,m1.Due); 00347 p->drawText(PosLegX,PosLegY,QString(stringa)); 00348 } 00349 else if( DIS_IF_TYPE(IfDisegna,DIS_EXP) ){ 00350 // NumLabel.setNum(r1.m,'g',DigPrec); 00351 if(!IfStampa){ 00352 sprintf(stringa,"y=(%.3g+-%.3g)exp(x/(%.3g+-%.3g))",log10(r1.q),log10(r1.ErrQ),1./r1.m,r1.ErrM/SQR(r1.m)); 00353 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY,QString(stringa)); 00354 } 00355 else { 00356 sprintf(stringa,"y=%.3g exp(%.3g x)",log10(r1.q),r1.m); 00357 p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY,QString(stringa)); 00358 //sprintf(stringa,"r %.5e Corr %.3e",r1.Corr,r1.Cov); 00359 //p->drawText(RisX/2-RisX/8,RisY-15,QString(stringa)); 00360 } 00361 } 00362 //printf("%d %d %d %d\n",NElMin,NElMax,NxMin,NxMax); 00363 } 00364 // if( (i%3)==0 ){ 00365 // for(int j=0;j<3;j++){ 00366 // PuntiLinea[j].setPoint(j,Mas(i,(int) ( i*RisX/(double)(NVisMax-NVisMin)) ),RisY-(int)( (double) Punti[i]*(double)(RisY)/yMax ) + (int) ( RisY/yMin) ); 00367 // } 00368 // } 00369 void ElementiGrafici::GrBarre(QPainter *p){ 00370 GrMessage("Visualizza.Dis.GrBarre"); 00371 p->setBrush( Qt::black );// Barre 00372 p->setPen( QPen(Qt::black,1) ); 00373 Tempx = 0; 00374 GrMessage("Visualizza.Dis.GrBarre.Ascissa"); 00375 if(DIS_IF_TYPE(LogLog,DIS_LOGX)){ 00376 if(v1->Abscissa(CoordY,NElMin) > 0. ) 00377 Tempx = (int)( (log10(v1->Abscissa(CoordY,NElMin))-xMin)/(xMax-xMin)*RisX); 00378 } 00379 else 00380 Tempx = (int) ( (double)((v1->Abscissa(CoordY,NElMin)-xMin)*RisX)/(double)(xMax-xMin) ); 00381 p->drawLine( QPoint(Tempx ,0), QPoint(Tempx ,RisY)); 00382 if(DIS_IF_TYPE(LogLog,DIS_LOGY)){ 00383 if(v1->Abscissa(CoordY,NElMax) > 0. ) 00384 Tempx = (int)( (log10(v1->Abscissa(CoordY,NElMax))-xMin)/(xMax-xMin)*RisX); 00385 } 00386 else 00387 Tempx = (int) ( (double)((v1->Abscissa(CoordY,NElMax)-xMin)*RisX)/(double)(xMax-xMin) ); 00388 p->drawLine( QPoint(Tempx ,0), QPoint(Tempx ,RisY)); 00389 p->drawLine( QPoint(0,NElMinY), QPoint(RisX,NElMinY)); 00390 p->drawLine( QPoint(0 ,NElMaxY), QPoint(RisX,NElMaxY)); 00391 //emit SegnaleGrafico(1); 00392 } 00393 void ElementiGrafici::GrStampante(QPainter *p){ 00394 GrMessage("Visualizza.Dis.GrStampante"); 00395 Font.setFamily("Helvetica"); 00396 if(!IfStampa){ 00397 RisX = width(); 00398 RisY = height(); 00399 QRect view(0,0,width(),height()); 00400 p->setViewport(view); 00401 ImpInterY(0,RisY); 00402 StampaX = 0; 00403 StampaY = 0; 00404 PointSize = 2; 00405 Font.setPointSize(12); 00406 p->setFont(Font); 00407 p->setFont(QFont("Palatino",12 )); 00408 int PosLabel = (int)(RisX/2. - 2.*nomeEtX.length()); 00409 //int PosLabel = 0; 00410 p->save(); 00411 p->translate(PosLabel,height()-40); 00412 QTextDocument doc; 00413 doc.setDefaultFont(QFont("Palatino",18 )); 00414 doc.setHtml(nomeEtX); // or populate using QTextCursor 00415 doc.drawContents(p); 00416 p->restore(); 00417 p->save(); 00418 PosLabel = RisY - (int)(RisY/2. - 2.*nomeEtY.length()); 00419 p->translate(width()-40,PosLabel); 00420 p->rotate(270); 00421 doc.setHtml(nomeEtY); // or populate using QTextCursor 00422 doc.drawContents(p); 00423 p->restore(); 00424 } 00425 else{ 00426 Q3PaintDeviceMetrics metrics( p->device() ); 00427 int dpiy = metrics.logicalDpiY(); 00428 int margin = (int) ((2/2.54)*dpiy); 00429 //QRect view(3*margin,margin,metrics.width() - 3*margin, metrics.height() - 2*margin ); 00430 QRect window(0.,0.,RatioWidthHeight*metrics.height(),metrics.height()); 00431 p->setWindow(window); 00432 QRect view(3*margin,margin,metrics.height() - 2*margin,metrics.height() - 2*margin ); 00433 p->setViewport(view); 00434 Font.setPointSize(32); 00435 p->setFont(Font); 00436 p->setFont(QFont("Helvetica",FontSize)); 00437 PointSize = 5; 00438 RisX = (int)(.9*metrics.width()); 00439 RisY = (int)(.9*metrics.height()); 00440 StampaX = 43; 00441 StampaY = -60; 00442 NElMinY = (int) (NElMinY*metrics.height()/(double)RisY); 00443 NElMaxY = (int) (NElMaxY*metrics.height()/(double)RisY); 00444 p->drawText(RisX/2-nomeTit.length(),-15,nomeTit); 00445 int PosLabel = (int)(RisX/2. - 2.*nomeEtX.length()); 00446 //int PosLabel = 0; 00447 QString Label1(nomeTit); 00448 // p->drawText((int)(RisX/2. - nomeEtX.length()*7.),metrics.height()+40,nomeEtX,-1,Qt::AlignTop); 00449 p->save(); 00450 p->translate(PosLabel,metrics.height()-10); 00451 QTextDocument doc; 00452 doc.setDefaultFont(QFont("Helvetica",FontSize)); 00453 doc.setHtml(nomeEtX); // or populate using QTextCursor 00454 doc.drawContents(p); 00455 p->restore(); 00456 p->save(); 00457 PosLabel = RisY - (int)(RisY/2. - 2.*nomeEtY.length()); 00458 p->translate(-(int)(3.5*margin),PosLabel); 00459 p->rotate(270); 00460 doc.setHtml(nomeEtY); // or populate using QTextCursor 00461 doc.drawContents(p); 00462 // PosLabel = RisY - (int)(RisY/2. - nomeEtY.length()*7.); 00463 //p->drawText(0,0,nomeEtY);//,-1,Qt::AlignRight); 00464 p->restore(); 00465 } 00466 } 00467 void ElementiGrafici::GrGriglia(QPainter *p){ 00468 GrMessage("Visualizza.Dis.GrGriglia"); 00469 QString NumLabel = QString(); 00470 if(!IfStampa) 00471 p->setPen(QPen(Qt::black,1,Qt::DashLine,Qt::RoundCap,Qt::RoundJoin)); 00472 else 00473 p->setPen(QPen(Qt::black,3,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin)); 00474 //p->setPen( QPen(Qt::black,1) ); 00475 //p->setBrush( Qt::black ); 00476 //p->setPen( Qt::DashLine ); 00477 p->drawLine(QPoint(0,RisY),QPoint(RisX,RisY) ); 00478 p->drawLine(QPoint(RisX,0),QPoint(RisX,RisY) ); 00479 p->drawLine(QPoint(0,0),QPoint(RisX,0) ); 00480 p->drawLine(QPoint(0,0),QPoint(0,RisY) ); 00481 if(!DIS_IF_TYPE(LogLog,DIS_LOGY)){ 00482 //---------------------Griglia-y--------------------- 00483 for(int i=0;i<=GrigliaY;i++){ 00484 Tempy = (int) (RisY/(double)GrigliaY*i); 00485 if(!IfStampa) 00486 p->drawLine(QPoint(0,Tempy),QPoint(RisX,Tempy) ); 00487 else{ 00488 p->drawLine(QPoint(0,Tempy),QPoint(10,Tempy) ); 00489 p->drawLine(QPoint(RisX,Tempy),QPoint(RisX-10,Tempy) ); 00490 if(i<GrigliaY-1) { 00491 int RiTempY = Tempy+(int)(.5*RisY/(double)GrigliaY); 00492 p->drawLine(QPoint(0,RiTempY),QPoint(5,RiTempY) ); 00493 p->drawLine(QPoint(RisX,RiTempY),QPoint(RisX-5,RiTempY) ); 00494 } 00495 } 00496 NumLabel.setNum((double)(yMax-yMin)/(double)GrigliaY*i+yMin,FormatPrecY,DigPrecY); 00497 if(i==GrigliaY && !IfStampa) Tempy -= 10; 00498 if(i==0 && !IfStampa) Tempy += 10; 00499 if(IfStampa) Tempy += 10; 00500 if(!IfStampa) p->drawText(StampaY,RisY-Tempy,NumLabel); 00501 else p->drawText(StampaY,RisY-Tempy-15,50,20,Qt::AlignRight|Qt::TextDontClip,NumLabel); 00502 } 00503 } 00504 if(!DIS_IF_TYPE(LogLog,DIS_LOGX)){ 00505 //---------------------Griglia-x--------------------- 00506 for(int i = 0;i<=GrigliaX;i++){ 00507 Tempx = (int) (RisX/(double)GrigliaX*i); 00508 if(!IfStampa) 00509 p->drawLine(QPoint(Tempx,0),QPoint(Tempx,RisY) ); 00510 else{ 00511 p->drawLine(QPoint(Tempx,RisY-10),QPoint(Tempx,RisY) ); 00512 p->drawLine(QPoint(Tempx,0),QPoint(Tempx,10) ); 00513 if(i<GrigliaX-1) { 00514 int RiTempX = Tempx+(int)(.5*RisX/(double)GrigliaX); 00515 p->drawLine(QPoint(RiTempX,RisY-5),QPoint(RiTempX,RisY) ); 00516 p->drawLine(QPoint(RiTempX,0),QPoint(RiTempX,5) ); 00517 } 00518 } 00519 NumLabel.setNum((double)(xMax-xMin)/(double)GrigliaX*i+xMin,FormatPrecX,DigPrecX); 00520 //p->drawText(Tempx,RisY+StampaX,QString(stringa)); 00521 if(IfStampa) Tempx -= (int)(9.*NumLabel.length()); 00522 p->drawText(Tempx,RisY+StampaX,NumLabel); 00523 // p->drawText(Tempx-(int)(.5*RisX/(double)GrigliaX),RisY+StampaX,NumLabel); 00524 } 00525 if(!IfStampa){ 00526 sprintf(stringa,"%% %.4g",(double)(yMax-yMin)/(double)((yMax+yMin)*.5)*100.); 00527 p->drawText(RisX/2,10,QString(stringa)); 00528 } 00529 } 00530 if(DIS_IF_TYPE(LogLog,DIS_LOGY)){ 00531 //--------LogLog-y----------------------- 00532 NyMin = (int)yMin; 00533 NyMax = (int)yMax; 00534 Delta = 1; 00535 if(NyMin < 0){ 00536 for(int i=NyMin;i<0;i++){ 00537 Delta /= 10; 00538 } 00539 } 00540 else if(NyMin > 0){ 00541 for(int i=0;i<NyMin;i++){ 00542 Delta *= 10; 00543 } 00544 } 00545 if( NyMin < NyMax){ 00546 for(int i = NyMin;i<=NyMax;i++){ 00547 Tempy = (int)( (double)(i-yMin)/((yMax-yMin))*RisY); 00548 if(Tempy < 0 || Tempy >= RisY) continue; 00549 sprintf(stringa,"%.2g",Delta); 00550 if(!IfStampa) p->drawText(StampaY,RisY-Tempy,stringa); 00551 else p->drawText(StampaY,RisY-Tempy+5,50,20,Qt::AlignRight|Qt::TextDontClip,stringa); 00552 //if(i==NyMax) Tempy -= 10; 00553 //if(i==NyMin) Tempy += 10; 00554 if(!IfStampa) 00555 p->drawLine( QPoint(0,Tempy),QPoint(RisX,Tempy)); 00556 else{ 00557 p->drawLine(QPoint(0,Tempy),QPoint(15,Tempy) ); 00558 p->drawLine(QPoint(RisX,Tempy),QPoint(RisX-15,Tempy) ); 00559 } 00560 Tempy = (int)( (double)(i-(yMin)+.30)/((yMax-yMin))*RisY); 00561 if(Tempy < 0 || Tempy >= RisY) continue; 00562 p->drawLine(QPoint(0,Tempy),QPoint(10,Tempy) ); 00563 p->drawLine(QPoint(RisX,Tempy),QPoint(RisX-10,Tempy) ); 00564 Tempy = (int)( (double)(i-(yMin)+.60)/((yMax-yMin))*RisY); 00565 if(Tempy < 0 || Tempy >= RisY) continue; 00566 p->drawLine(QPoint(0,Tempy),QPoint(10,Tempy) ); 00567 p->drawLine(QPoint(RisX,Tempy),QPoint(RisX-10,Tempy) ); 00568 Tempy = (int)( (double)(i-(yMin)+.77)/((yMax-yMin))*RisY); 00569 if(Tempy < 0 || Tempy >= RisY) continue; 00570 p->drawLine(QPoint(0,Tempy),QPoint(10,Tempy) ); 00571 p->drawLine(QPoint(RisX,Tempy),QPoint(RisX-10,Tempy) ); 00572 Tempy = (int)( (double)(i-(yMin)+.90)/((yMax-yMin))*RisY); 00573 if(Tempy < 0 || Tempy >= RisY) continue; 00574 p->drawLine(QPoint(0,Tempy),QPoint(10,Tempy) ); 00575 p->drawLine(QPoint(RisX,Tempy),QPoint(RisX-10,Tempy) ); 00576 Delta *= 10; 00577 } 00578 } 00579 if(NyMin == NyMax){ 00580 Tempy = (int)(RisY/2.); 00581 p->drawLine(QPoint(0,RisY-Tempy),QPoint(RisX,RisY-Tempy)); 00582 sprintf(stringa,"%.2g",yMin/2.); 00583 p->drawText(0,RisY- Tempy -7,QString(stringa)); 00584 } 00585 } 00586 if(DIS_IF_TYPE(LogLog,DIS_LOGX)){ 00587 //--------------LogLog-x-------------------------- 00588 NxMin = (int)xMin; 00589 NxMax = (int)xMax; 00590 Delta = 1; 00591 if(NxMin < 0){ 00592 for(int i=NxMin;i<0;i++){ 00593 Delta /= 10; 00594 } 00595 } 00596 else if(NxMin > 0){ 00597 for(int i=0;i<NxMin;i++){ 00598 Delta *= 10; 00599 } 00600 } 00601 double Ratio = RisX /(xMax-xMin); 00602 for(int i = NxMin;i<=NxMax;i++){ 00603 sprintf(stringa,"%.2g",Delta); 00604 double x = log10(Delta); 00605 Tempx = (int)( (x - xMin)*Ratio); 00606 if(Tempx < 0 || Tempx >= RisX) continue; 00607 if(IfStampa) p->drawText(Tempx-strlen(stringa)*9., RisY+35,QString(stringa)); 00608 else p->drawText( Tempx, RisY ,QString(stringa)); 00609 if(!IfStampa) 00610 p->drawLine( QPoint(Tempx,RisY),QPoint(Tempx,0)); 00611 else{ 00612 p->drawLine(QPoint(Tempx,RisY-15),QPoint(Tempx,RisY) ); 00613 p->drawLine(QPoint(Tempx,0),QPoint(Tempx,15) ); 00614 } 00615 Tempx = (int)( (double)(x+.30-xMin)*Ratio); 00616 if(Tempx < 0 || Tempx >= RisX) continue; 00617 p->drawLine(QPoint(Tempx,RisY-10),QPoint(Tempx,RisY) ); 00618 p->drawLine(QPoint(Tempx,0),QPoint(Tempx,10) ); 00619 Tempx = (int)( (double)(x+.60-xMin)*Ratio); 00620 if(Tempx < 0 || Tempx >= RisX) continue; 00621 p->drawLine(QPoint(Tempx,RisY-10),QPoint(Tempx,RisY) ); 00622 p->drawLine(QPoint(Tempx,0),QPoint(Tempx,10) ); 00623 Tempx = (int)( (double)(x+.77-xMin)*Ratio); 00624 if(Tempx < 0 || Tempx >= RisX) continue; 00625 p->drawLine(QPoint(Tempx,RisY-10),QPoint(Tempx,RisY) ); 00626 p->drawLine(QPoint(Tempx,0),QPoint(Tempx,10) ); 00627 Tempx = (int)( (double)(x+.90-xMin)*Ratio); 00628 if(Tempx < 0 || Tempx >= RisX) continue; 00629 p->drawLine(QPoint(Tempx,RisY-10),QPoint(Tempx,RisY) ); 00630 p->drawLine(QPoint(Tempx,0),QPoint(Tempx,10) ); 00631 Delta *= 10; 00632 } 00633 } 00634 } 00635 void ElementiGrafici::GrRiscala(){ 00636 GrMessage("Visualizza.Dis.GrRiscala.x"); 00637 if(DIS_IF_TYPE(IfRiscala,RIS_UNO) ){ 00638 if(v1->IsAbscissa(CoordX)){ 00639 xMin = v1->pMin(CoordX,NVisMin,NVisMax); 00640 xMax = v1->pMax(CoordX,NVisMin,NVisMax); 00641 } 00642 else{ 00643 xMin = NVisMin; 00644 xMax = NVisMax; 00645 } 00646 GrMessage("Visualizza.Dis.GrRiscala.y"); 00647 yMin = v1->pMin(CoordY,NVisMin,NVisMax); 00648 yMax = v1->pMax(CoordY,NVisMin,NVisMax); 00649 } 00650 else if(DIS_IF_TYPE(IfRiscala,RIS_TUTTI) ){ 00651 GrMessage("Visualizza.Dis.GrRiscala.Tutto %d",NVar); 00652 v1->pMinMaxGlob(NVisMin,NVisMax); 00653 v1->pGlobBorder(&xMin,&xMax,&yMin,&yMax); 00654 if(!v1->IsAbscissa(CoordX)){ 00655 xMin = NVisMin; 00656 xMax = NVisMax; 00657 } 00658 } 00659 if( DIS_IF_TYPE(IfDisegna,DIS_PUNTI) ){ 00660 GrMessage("Visualizza.Dis.GrRiscala.Punti"); 00661 yMin = v1->PuntiMin(); 00662 yMax = v1->PuntiMax(); 00663 } 00664 if( DIS_IF_TYPE(IfDisegna,DIS_MOMENTI) ){ 00665 GrMessage("Visualizza.Dis.GrRiscala.Momenti"); 00666 yMin = m1.yMin; 00667 yMax = m1.yMax; 00668 xMin = m1.Min; 00669 xMax = m1.Max; 00670 } 00671 if(DIS_IF_TYPE(LogLog,DIS_LOGX)){// LogLog 00672 GrMessage("Visualizza.Dis.GrRiscala.Logx"); 00673 if(v1->IsAbscissa(CoordX)){ 00674 xMin = v1->pMinLog(CoordX,NVisMin,NVisMax); 00675 xMax = v1->pMaxLog(CoordX,NVisMin,NVisMax); 00676 } 00677 else{ 00678 xMin = log10(NVisMin); 00679 xMax = log10(NVisMax); 00680 } 00681 } 00682 if(DIS_IF_TYPE(LogLog,DIS_LOGY)){// LogLog 00683 GrMessage("Visualizza.Dis.GrRiscala.Logy"); 00684 if( DIS_IF_TYPE(IfRiscala,RIS_UNO) ){ 00685 yMin = v1->pMinLog(CoordY,NVisMin,NVisMax); 00686 yMax = v1->pMaxLog(CoordY,NVisMin,NVisMax); 00687 } 00688 else if( DIS_IF_TYPE(IfRiscala,RIS_TUTTI) ){ 00689 yMin = v1->pMinGlobLog(NVisMin,NVisMax); 00690 yMax = v1->pMaxGlobLog(NVisMin,NVisMax); 00691 } 00692 // if(yMin <= 0.){ 00693 // char SErr[120]; 00694 // sprintf(SErr,"Ordinates negative or null %f, no log log possible",yMin); 00695 // ErrPrima->message(QString(SErr)); 00696 // //QMessageBox::information(this,"Visualizza","Numeri negativi o nulli\n Non posso visualizzare LogLog","Va Be!"); 00697 // DIS_REM_TYPE(LogLog,DIS_LOGY); 00698 // emit LogyCambiato(LogLog); 00699 // } 00700 } 00701 GrMessage("xBound %lf-%lf yBound %lf-%lf\n",xMin,xMax,yMin,yMax); 00702 ScalaTopoX = xMax-xMin; 00703 ScalaTopoY = yMax-yMin; 00704 // yMax = (yMax*1.1); 00705 // yMin = (yMin*0.9); 00706 // xMax = (xMax*1.1); 00707 // xMin = (xMin*0.9); 00708 yMax += (yMax-yMin)*ViewportY; 00709 yMin -= (yMax-yMin)*ViewportY; 00710 xMax += (xMax-xMin)*ViewportX; 00711 xMin -= (xMax-xMin)*ViewportX; 00712 } 00713 void ElementiGrafici::GrLegenda(QPainter *p){ 00714 GrMessage("Visualizza.Dis.GrLegenda"); 00715 //QRect Leg((int)(PosLegenda[0]*width()),(int)((1.-PosLegenda[1])*height()), 00716 // (int)(PosLegenda[2]*width()),(int)((1.-PosLegenda[3])*height())); 00717 // QRect Leg((int)(.8*width()),(int)((1.-.8)*height()), 00718 // (int)(.9*width()),(int)((1.-.9)*height())); 00719 //p->drawText(Leg,Qt::AlignCenter,tr("Ciccia")); 00720 //p->drawText((int)(PosLegenda[0]*width()),(int)((1.-PosLegenda[1])*height()),tr("Chem Pot")); 00721 //p->drawText((int)(.8*width()),(int)((1.-.8)*height()),tr("Chem Pot")); 00722 int PosLegX=(int)(PosLegenda[0]*RisX); 00723 int PosLegY=(int)((1.-PosLegenda[1])*RisY); 00724 int PosFinL=PosLegX, PosFinY=PosLegY; 00725 int IncrY = 15; 00726 if(IfStampa) IncrY = 30; 00727 for(int s=0;s<NVar;s++){ 00728 if(v1->IsAbscissa(s)) continue; 00729 if(LineaCome[s]==0) continue; 00730 p->setBrush( GrLinee[s] ); 00731 p->setPen( QPen( GrLinee[s],2 ) ); 00732 Quadrati = DIS_IF_TYPE(LineaCome[s],LINEA_PUNTO); 00733 Linee = DIS_IF_TYPE(LineaCome[s],LINEA_TRATTO); 00734 Punto = QPoint(PosLegX,PosFinY-5); 00735 Punto1 = QPoint(PosLegX+15,PosFinY-5); 00736 p->drawLine(Punto,Punto1); 00737 p->drawText(PosLegX+25,PosFinY,GrLabel[s]); 00738 PosFinY += IncrY; 00739 } 00740 } 00741 void ElementiGrafici::GrScript(char *File2Read,QPainter *p){ 00742 GrMessage("Visualizza.Dis.GrScript"); 00743 FILE *File2Open; 00744 if( (File2Open = fopen(File2Read,"r"))==0){ 00745 // printf("The file %s does not exist\n"); 00746 return ; 00747 } 00748 char cLine[256]; 00749 double Color[4]; 00750 double Pos[4]; 00751 double Hue[4]; 00752 int iHue[4]; 00753 for(int k=0;!(fgets(cLine,256,File2Open)==NULL);k++){ 00754 if(strncmp(cLine,"PutStr",6)==0){ 00755 fgets(cLine,256,File2Open); 00756 sscanf(cLine,"%lf %lf %lf %lf\n",Color,Color+1,Color+2,Color+3); 00757 fgets(cLine,256,File2Open); 00758 sscanf(cLine,"%lf %lf %lf %lf\n",Pos,Pos+1,Pos+2,Pos+3); 00759 char String[256]; 00760 fgets(cLine,256,File2Open); 00761 //for(int c=0;c<strlen(cLine);c++) String[c] = cLine[c]; 00762 sprintf(String,"%s",cLine); 00763 QColor ColorLabel = QColor((int)(255.*Color[0]),(int)(255.*Color[1]),(int)(255.*Color[2]),(int)(255.*Color[3])); 00764 if(IfStampa) Pos[3] *= 2.; 00765 p->setFont(QFont("Palatino",Pos[3])); 00766 p->setBrush(ColorLabel); 00767 p->save(); 00768 p->rotate(Pos[2]); 00769 p->drawText(Pos[0]*RisX,(1.-Pos[1])*RisY,QString(String)); 00770 p->restore(); 00771 if(IfStampa) 00772 p->setFont(QFont("Palatino",FontSize)); 00773 else 00774 p->setFont(QFont("Palatino",12)); 00775 } 00776 else if(strncmp(cLine,"PutLine",7)==0){ 00777 //Colore 00778 fgets(cLine,256,File2Open); 00779 p->setPen(QPen(Qt::blue,3,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin)); 00780 sscanf(cLine,"%lf %lf %lf %lf\n",Color,Color+1,Color+2,Color+3); 00781 QColor ColorLabel = QColor((int)(255.*Color[0]),(int)(255.*Color[1]),(int)(255.*Color[2]),(int)(255.*Color[3])); 00782 p->setBrush(ColorLabel); 00783 //Posizione 00784 fgets(cLine,256,File2Open); 00785 sscanf(cLine,"%lf %lf %lf %lf\n",Pos,Pos+1,Pos+2,Pos+3); 00786 int Fromx = (int)(RisX*Pos[0]); 00787 int Fromy = (int)(RisY*(1.-Pos[1])); 00788 int Tox = (int)(RisX*Pos[2]); 00789 int Toy = (int)(RisY*(1.-Pos[3])); 00790 Punto = QPoint(Fromx,Fromy); 00791 Punto1 = QPoint(Tox,Toy); 00792 p->drawLine(Punto,Punto1); 00793 } 00794 else if(strncmp(cLine,"Text",4)==0){ 00795 //Colore 00796 fgets(cLine,256,File2Open); 00797 sscanf(cLine,"%lf %lf %lf %lf\n",Hue,Hue+1,Hue+2,Hue+3); 00798 for(int i=0;i<4;i++) iHue[i] = (int)(255.*Hue[i]); 00799 p->setBrush( QColor(iHue[0],iHue[1],iHue[2],iHue[3]) ); 00800 //Posizione 00801 fgets(cLine,256,File2Open); 00802 sscanf(cLine,"%lf %lf\n",Pos,Pos+1); 00803 int Fromx = (int)(width()*Pos[0]); 00804 int Fromy = (int)(height()*(1.-Pos[1])); 00805 //Testo 00806 fgets(cLine,256,File2Open); 00807 QChar ChType = QChar::NoCategory; 00808 QString String; 00809 int Posx = Fromx; 00810 int Posy = Fromy; 00811 int FontSize = 12; 00812 int IfSymbol = 0; 00813 int IfUpper = 0; 00814 for(int i=0,j=0;i<strlen(cLine);i++){ 00815 if(cLine[i] == '\\'){ 00816 IfSymbol = 0x0350; 00817 continue; 00818 } 00819 else if(cLine[i] == '^'){ 00820 IfUpper = 1; 00821 continue; 00822 } 00823 else if(cLine[i] == '_'){ 00824 IfUpper = -1; 00825 continue; 00826 } 00827 else if(cLine[i] == '%'){ 00828 IfSymbol = 0; 00829 IfUpper = 1; 00830 continue; 00831 } 00832 //String.insert(i,QChar(sTable(cLine+j))); 00833 String.insert(j,QChar((uint)(cLine[i]+IfSymbol))); 00834 j++; 00835 } 00836 p->drawText(Fromx,Fromy,String,-1,Qt::AlignTop); 00837 } 00838 else if(strncmp(cLine,"Picture",4)==0){ 00839 fgets(cLine,256,File2Open); 00840 sscanf(cLine,"%lf %lf %lf %lf\n",Pos,Pos+1,Pos+2,Pos+3); 00841 int Fromx = (int)(width()*Pos[0]); 00842 int Fromy = (int)(height()*(1.-Pos[1])); 00843 int Tox = (int)(width()*Pos[2]); 00844 int Toy = (int)(height()*(1.-Pos[3])); 00845 char String[512]; 00846 fgets(cLine,512,File2Open); 00847 for(int c=0;c<strlen(cLine)-1;c++) String[c] = cLine[c]; 00848 p->drawImage(QRect(Fromx,Fromy,Tox,Toy),QImage(QString(String),0)); 00849 } 00850 else if(strncmp(cLine,"Background",10)==0){ 00851 } 00852 } 00853 fclose(File2Open); 00854 } 00855 void ElementiGrafici::GrConf(char *File2Read){ 00856 GrMessage("Visualizza.Dis.GrConf"); 00857 FILE *File2Open; 00858 if( (File2Open = fopen(File2Read,"r"))==0){ 00859 // printf("The file %s does not exist\n"); 00860 return ; 00861 } 00862 char cLine[256]; 00863 for(int k=0;!(fgets(cLine,256,File2Open)==NULL);k++){ 00864 //printf("%s",cLine); 00865 //if(cLine[0] == '#') continue; 00866 if(strncmp(cLine,"NGrid",5)==0){ 00867 fgets(cLine,256,File2Open); 00868 sscanf(cLine,"%d %d\n",&GrigliaX,&GrigliaY); 00869 } 00870 else if(strncmp(cLine,"XFormula",8)==0){ 00871 fgets(cLine,256,File2Open); 00872 sscanf(cLine,"%s\n",XFormula); 00873 v1->setXFormula(XFormula); 00874 } 00875 else if(strncmp(cLine,"YFormula",8)==0){ 00876 fgets(cLine,256,File2Open); 00877 sscanf(cLine,"%s\n",YFormula); 00878 v1->setYFormula(YFormula); 00879 } 00880 else if(strncmp(cLine,"XBound",6)==0){ 00881 fgets(cLine,256,File2Open); 00882 if( DIS_IF_TYPE(IfRiscala,RIS_TUTTI) ) 00883 sscanf(cLine,"%lf %lf\n",&xMin,&xMax); 00884 if(DIS_IF_TYPE(LogLog,DIS_LOGX)){ 00885 if(xMin < 0 ) printf("xMin can't be negative in log log\n"); 00886 else xMin = log10(xMin); 00887 if(xMax < 0 ) printf("xMax can't be negative in log log\n"); 00888 else xMax = log10(xMax); 00889 } 00890 } 00891 else if(strncmp(cLine,"YBound",6)==0){ 00892 fgets(cLine,256,File2Open); 00893 if( DIS_IF_TYPE(IfRiscala,RIS_TUTTI) ) 00894 sscanf(cLine,"%lf %lf\n",&yMin,&yMax); 00895 if(DIS_IF_TYPE(LogLog,DIS_LOGY)){ 00896 if(yMin < 0 ) printf("yMin can't be negative in log log\n"); 00897 else yMin = log10(yMin); 00898 if(yMax < 0 ) printf("yMax can't be negative in log log\n"); 00899 else yMax = log10(yMax); 00900 } 00901 } 00902 else if(strncmp(cLine,"PosLegend",6)==0){ 00903 fgets(cLine,256,File2Open); 00904 sscanf(cLine,"%lf %lf %lf %lf\n",(PosLegenda+0),(PosLegenda+1),(PosLegenda+2),(PosLegenda+3)); 00905 } 00906 else if(strncmp(cLine,"PosInterp",6)==0){ 00907 fgets(cLine,256,File2Open); 00908 sscanf(cLine,"%lf %lf\n",(PosInterp+0),(PosInterp+1)); 00909 } 00910 else if(strncmp(cLine,"DigPrecX",8)==0){ 00911 fgets(cLine,256,File2Open); 00912 sscanf(cLine,"%d %c\n",&DigPrecX,&FormatPrecX); 00913 } 00914 else if(strncmp(cLine,"DigPrecY",8)==0){ 00915 fgets(cLine,256,File2Open); 00916 sscanf(cLine,"%d %c\n",&DigPrecY,&FormatPrecY); 00917 } 00918 else if(strncmp(cLine,"ViewportX",9)==0){ 00919 fgets(cLine,256,File2Open); 00920 sscanf(cLine,"%lf\n",&ViewportX); 00921 } 00922 else if(strncmp(cLine,"ViewportY",9)==0){ 00923 fgets(cLine,256,File2Open); 00924 sscanf(cLine,"%lf\n",&ViewportY); 00925 } 00926 else if(strncmp(cLine,"FontSize",8)==0){ 00927 fgets(cLine,256,File2Open); 00928 sscanf(cLine,"%d\n",&FontSize); 00929 } 00930 else if(strncmp(cLine,"RatioWidthHeight",16)==0){ 00931 fgets(cLine,256,File2Open); 00932 sscanf(cLine,"%lf\n",&RatioWidthHeight); 00933 } 00934 else if(strncmp(cLine,"LabelX",6)==0){ 00935 char *String = (char *)calloc(265,sizeof(char)); 00936 fgets(cLine,256,File2Open); 00937 for(int c=0;c<strlen(cLine);c++) String[c] = cLine[c]; 00938 nomeEtX.clear(); 00939 StringToUnicode(String,&nomeEtX); 00940 free(String); 00941 } 00942 else if(strncmp(cLine,"LabelY",6)==0){ 00943 char *String = (char *)calloc(265,sizeof(char)); 00944 fgets(cLine,256,File2Open); 00945 for(int c=0;c<strlen(cLine);c++) String[c] = cLine[c]; 00946 nomeEtY.clear(); 00947 StringToUnicode(String,&nomeEtY); 00948 free(String); 00949 } 00950 else if(strncmp(cLine,"Title",5)==0){ 00951 char *String = (char *)calloc(265,sizeof(char)); 00952 fgets(cLine,256,File2Open); 00953 for(int c=0;c<strlen(cLine);c++) String[c] = cLine[c]; 00954 nomeTit.clear(); 00955 StringToUnicode(String,&nomeTit); 00956 free(String); 00957 } 00958 else if(strncmp(cLine,"Line",4)==0){ 00959 int NLine; 00960 int Type; 00961 double Color[4]; 00962 fgets(cLine,256,File2Open); 00963 sscanf(cLine,"%d\n",&NLine); 00964 if(NLine >= NVar) { 00965 //printf("The %d th column is not present\n",NLine); 00966 NLine = 0; 00967 continue; 00968 } 00969 fgets(cLine,256,File2Open); 00970 sscanf(cLine,"%lf %lf %lf %lf\n",Color,Color+1,Color+2,Color+3); 00971 fgets(cLine,256,File2Open); 00972 sscanf(cLine,"%d\n",&Type); 00973 //printf("%d %d %lf %lf %lf\n",NLine,Type,Color[0],Color[1],Color[2],Color[3]); 00974 QColor ColorSet = QColor((int)(255.*Color[0]),(int)(255.*Color[1]),(int)(255.*Color[2]),(int)(255.*Color[3])); 00975 GrLinee[NLine] = ColorSet; 00976 LineaCome[NLine] = Type; 00977 fgets(cLine,256,File2Open); 00978 GrLabel[NLine].clear(); 00979 StringToUnicode(cLine,GrLabel + NLine); 00980 GrMessage("Line n: %d type: %d name: %s color: %lf %lf %lf\n",NLine,Type,cLine,Color[0],Color[1],Color[2]); 00981 } 00982 } 00983 GrMessage("NGrid %d %d XBond %lf %lf YBound %lf %lf\n",GrigliaX,GrigliaY,xMin,xMax,yMin,yMax); 00984 fclose(File2Open); 00985 } 00986 void ElementiGrafici::StringToUnicode(char *cLine,QString *Label){ 00987 QChar ChType = QChar::NoCategory; 00988 int UnicodeRow = 0; 00989 int CharOffset = 0; 00990 for(int i=0,j=0;i<strlen(cLine);i++){ 00991 int Char = cLine[i]; 00992 if(cLine[i] == '\\' && i < strlen(cLine)-1){ 00993 if(cLine[i+1] == 's'){ 00994 //ChType = QChar::Symbol_Math; 00995 CharOffset = 0x0350; 00996 UnicodeRow = 3; 00997 } 00998 else if(cLine[i+1] == 'l') 00999 ChType = QChar::Letter_Lowercase; 01000 else if(cLine[i+1] == 'u') 01001 ChType = QChar::Letter_Uppercase; 01002 else if(cLine[i+1] == 'n'){ 01003 UnicodeRow = 0; 01004 CharOffset = 0; 01005 ChType = QChar::NoCategory; 01006 } 01007 i+=1; 01008 continue; 01009 } 01010 else 01011 ChType = QChar::NoCategory; 01012 //QChar Character = QChar(QChar(Char).cell(),QChar(QChar::Symbol_Math).row()); 01013 QChar Char1 = QChar(Char+CharOffset); 01014 //printf("%c %d %d %x\n",Char1.toAscii(),Char1.cell(),Char1.row(),Char1.unicode()); 01015 //GrLabel[NLine].insert(i,Char1); 01016 Label->insert(j,QChar(Char1.cell(),UnicodeRow));//QChar(Char)); 01017 j++; 01018 } 01019 //GrLabel[NLine].append(cLine); 01020 //sprintf(LineaQuale[NLine],"%s",cLine); 01021 }