Allink  v0.1
ElementiGraficiDis.cpp
1 /***********************************************************************
2 ElementiGrafici: Class that interface the VarData, VarElementiGrafici
3 and Matematica classes function for comunicating with main window of
4 Visualizza. The main function is the plotting function DisegnaPunti()
5 that provides the visualisation of two set of data. The bars at the
6 bottom permits to change the visualisation and the limit for the analisys
7  Copyright (C) 2008 by Giovanni Marelli <sabeiro@virgilio.it>
8 
9 
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 ***********************************************************************/
24 ;// α-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
25 #include "ElementiGrafici.h"
26 #include <qpainter.h>
27 #include <Q3PaintDeviceMetrics>
28 
29 void ElementiGrafici::GrMessage(const char * s, ...){
30 #ifdef DEBUG
31  va_list args;
32  va_start(args, s);
33  fprintf(stderr,"%d) ",NDis);
34  vfprintf(stderr, s, args);
35  fprintf(stderr, "\n");
36  va_end(args);
37 #else
38  return;
39 #endif
40 }
41 void ElementiGrafici::paintEvent(QPaintEvent *e){
42  GrMessage("Visualizza.paintEvent(begin)");
43  //QRect DaNuovo = e->rect();
44  // if(DaNuovo.intersects( PuntiRett(0)) )
45  QPainter p(this);
46  DisegnaPunti(&p);
47  if(PrimaVolta){
48  Immagine.load("Logo.png");
49  p.drawPixmap(200,300,QPixmap(Immagine),0,0,-1,-1);
50  }
51  GrMessage("Visualizza.paintEvent(end)");
52 }
53 void ElementiGrafici::DisegnaPunti(QPainter *p){
54  if(PrimaVolta){
55  return;
56  }
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);
61  return;
62  }
63  if( IfRiscala != 0 ) GrRiscala();
64  GrStampante(p);
65  GrConf(nomeConf);
66  GrScript(nomeConf,p);
67  if( DIS_IF_TYPE(IfDisegna,DIS_TUTTI) ){
68  for(int s=0,sColor=0;s<NVar;s++){
69  if(v1->IsAbscissa(s)) continue;
70  sColor = 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);
75  GrSet(p,s);
76  sColor++;
77  }
78  }
79  if( DIS_IF_TYPE(IfDisegna,DIS_SEGNALE) ){
80  p->setBrush( GrLinee[CoordY] );
81  p->setPen( QPen( GrLinee[CoordY],2 ) );
82  GrSet(p,CoordY);
83  }
84  if( DIS_IF_TYPE(IfDisegna,DIS_MOMENTI) )
85  GrMomenti(p);
86  if( DIS_IF_TYPE(IfDisegna,DIS_PUNTI) ){
87  p->setBrush( GrLinee[CoordY] );
88  p->setPen( QPen( GrLinee[CoordY],2 ) );
89  GrPunti(p);
90  }
91  if( DIS_IF_TYPE(IfDisegna,DIS_BLU) ) GrBlu(p);
92  if( Griglia ) GrGriglia(p);
93  if(!IfStampa) GrBarre(p);
94  GrLegenda(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),
101  IfRiscala,
102  DIS_IF_TYPE(IfRiscala,RIS_UNO),
103  DIS_IF_TYPE(IfRiscala,RIS_TUTTI));
104  NDis++;
105 }
106 void ElementiGrafici::GrSet(QPainter *p,int s){
107  GrMessage("Visualizza.Dis.GrSet");
108  if(v1->IsAbscissa(s)) return;
109  //printf("%d %d\n",s,v1->pRefAbsc(s));
110  int IfDrawLine = 0;
111  for(int i=MIN(NVisMin,v1->pNRow(s));i<MIN(NVisMax,v1->pNRow(s));i++){
112  //printf("%lf %lf\n",v1->Ascissa(i),v1->Val(i));
113  if(!DIS_IF_TYPE(LogLog,DIS_LOGX))
114  Tempx = (int) ( (double)((v1->Abscissa(s,i)-xMin)*RisX)/(double)(xMax-xMin) );
115  else {
116  if(v1->Abscissa(s,i)<=0.) continue;
117  Tempx = (int) ( (log10(v1->Abscissa(s,i))-xMin)/(xMax-xMin)*RisX);
118  }
119  if(!DIS_IF_TYPE(LogLog,DIS_LOGY))
120  Tempy = RisY-(int)( (v1->Val(s,i)-yMin)*RisY/ (yMax-yMin) );
121  else {
122  if(v1->Val(s,i) <= 0.) continue;
123  Tempy = RisY-(int)( (log10(v1->Val(s,i))-yMin)*RisY/ (yMax-yMin) );
124  //printf("%d %d %lf\n",Tempy,RisY,log10(v1->Val(s,i)));
125  }
126  // if(Tempx > RisX){IfDrawLine=0;continue;}
127  // if(Tempy > RisY){IfDrawLine=0;continue;}
128  // if(Tempx < 0 ){IfDrawLine=0;continue;}
129  // if(Tempy < 0 ){IfDrawLine=0;continue;}
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);
135  //if(Quadrati) p->drawRect( PuntiRett(Punto) );
136  if(Quadrati){
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);
143  }
144  // if(Quadrati){
145  // Punto2 = QPoint(Punto.x()+PointSize,Punto.y()+PointSize);
146  // Punto3 = QPoint(Punto.x()+PointSize,Punto.y()-PointSize);
147  // p->drawLine(Punto2,Punto3);
148  // Punto2 = QPoint(Punto.x()+PointSize,Punto.y()-PointSize);
149  // Punto3 = QPoint(Punto.x()-PointSize,Punto.y()-PointSize);
150  // p->drawLine(Punto2,Punto3);
151  // Punto2 = QPoint(Punto.x()-PointSize,Punto.y()-PointSize);
152  // Punto3 = QPoint(Punto.x()-PointSize,Punto.y()+PointSize);
153  // p->drawLine(Punto2,Punto3);
154  // Punto2 = QPoint(Punto.x()-PointSize,Punto.y()+PointSize);
155  // Punto3 = QPoint(Punto.x()+PointSize,Punto.y()+PointSize);
156  // p->drawLine(Punto2,Punto3);
157  // }
158  if(Linee && IfDrawLine) p->drawLine(Punto,Punto1);
159  IfDrawLine = 1;
160  Punto1 = Punto;
161  }
162 }
163 void ElementiGrafici::GrPunti(QPainter *p){
164  GrMessage("Visualizza.Dis.GrPunti");
165  for(int i=NVisMin;i<NVisMax*NMobile;i+=NMobile){// FIXME
166  if(xMin > v1->Abscissa(CoordY,i)) xMin = v1->Abscissa(CoordY,i);
167  if(xMax < v1->Abscissa(CoordY,i)) xMax = v1->Abscissa(CoordY,i);
168  }
169  ScalaTopoX = xMax-xMin;
170  //FILE *Apri = fopen("Scritto.dat","w");
171  for(int i=NVisMin;i<NVisMax;i++){
172  //printf("%lf %lf\n",v1->Ascissa(i*NMobile),v1->pPunti(i));
173  if(!DIS_IF_TYPE(LogLog,DIS_LOGX))
174  Tempx = (int) ( (double)((v1->Abscissa(CoordY,i*NMobile)-xMin)*RisX)/(double)(xMax-xMin) );
175  else{
176  if(v1->Abscissa(CoordY,i)<=0.) continue;
177  Tempx = (int) ( (log10(v1->Abscissa(CoordY,i))-xMin)/(xMax-xMin)*RisX);
178  }
179  if(!DIS_IF_TYPE(LogLog,DIS_LOGY))
180  Tempy = RisY-(int)( (v1->pPunti(i)-yMin)*RisY/ (yMax-yMin) );
181  else {
182  if(v1->pPunti(i) <= 0.) continue;
183  Tempy = RisY-(int)( (log10(v1->pPunti(i))-yMin)*RisY/ (yMax-yMin) );
184  //printf("%d %d %lf\n",Tempy,RisY,log10(v1->Val(s,i)));
185  }
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);
193  Punto1 = Punto;
194  int ErrY = (int)( .5*(v1->pPuntiErr(i))*RisY/ (yMax-yMin) );
195  QPoint PuntoErr1(Tempx,Tempy+ErrY);
196  QPoint PuntoErr2(Tempx,Tempy-ErrY);
197  //p->setPen( QPen(Qt::SolidPattern,1,Qt::SolidLine,Qt::SquareCap,Qt::BevelJoin) );
198  //fprintf(Apri,"%lf %lf %lf\n",v1->Ascissa(i*NMobile)*.2,v1->pPunti(i),v1->pPuntiErr(i));
199  p->drawLine(PuntoErr1,PuntoErr2);
200  }
201  //fclose(Apri);
202 }
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);
217  }
218  Punto1 = Punto2;
219  }
220  GrMessage("Visualizza.Dis.GrMomenti.Blue");
221  p->setBrush( Qt::blue );
222  p->setPen( Qt::blue );
223  yBluMin = v1->pInter1(NVisMin);
224  yBluMax = v1->pInter1(NVisMin);
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);
231  Punto1 = Punto;
232  if( yBluMin > v1->pInter1(i) )
233  yBluMin = v1->pInter1(i);
234  if( yBluMax < v1->pInter1(i) )
235  yBluMax = v1->pInter1(i);
236  }
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));
248  if(!IfStampa){
249  sprintf(stringa,"t %g Chi %.2g",m1.Tre,m1.Chi);
250  p->drawText(RisX/2-70,RisY/2+120,QString(stringa));
251  }
252 }
253 void ElementiGrafici::GrBlu(QPainter *p){
254  GrMessage("Visualizza.Dis.GrBlu");
255  int IfDrawLine = 0;
256  p->setBrush( Qt::blue );
257  p->setPen( Qt::blue );
258  if(!IfStampa)
259  p->setPen(QPen(Qt::blue,1,Qt::DashLine,Qt::RoundCap,Qt::RoundJoin));
260  else
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) ) ;
265  else
266  //Tempx = (int) ( log10((v1->Abscissa(CoordY,i))/(xMin))/log10((xMax)/(xMin))*RisX );
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) );
271  }
272  else
273  //Tempy = RisY-(int)( (log10(v1->Abscissa(CoordY,i))*r1.m+r1.q-log10(yMin))*RisY/ (log10(yMax/yMin)) );
274  Tempy = RisY-(int)( (log10(v1->Abscissa(CoordY,i))*r1.m+r1.q-yMin)*RisY/(yMax-yMin) );
275  }
276  else if( DIS_IF_TYPE(IfDisegna,DIS_PARABOLA) ){
277  if(!DIS_IF_TYPE(LogLog,DIS_LOGY)){
278  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) );
279  }
280  else{
281  double y = log10(v1->Abscissa(CoordY,i));
282  // 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)) );
283  Tempy = RisY-(int)((y*y*p1.a2+y*p1.a1+p1.a0-yMin)*RisY/(yMax-yMin));
284  }
285  }
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));
289  }
290  else
291  Tempy = RisY-(int)((exp(r1.q+r1.m*log10(v1->Abscissa(CoordY,i)))-yMin)*RisY/(yMax-yMin));
292  }
293  else if( DIS_IF_TYPE(IfDisegna,DIS_GAUSS) ){
294  Tempy = RisY-(int)( (v1->Gauss(m1.Uno,m1.Due,v1->Abscissa(CoordY,i))-yMin)*RisY/(yMax-yMin));
295  }
296  else
297  Tempy = RisY-(int)( (v1->pInter1(i)-yMin)*RisY/ (yMax-yMin) );
298  //printf("%d %d %d %d %lf %lf %lf %lf\n",Tempx,Tempy,RisX,RisY,yMin,yMax,v1->Abscissa(CoordY,i),v1->Val(CoordY,i));
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;}
304  //if( Quadrati ) p->drawRect( PuntiRett(Punto) );
305  if( /*Linee && */ IfDrawLine) p->drawLine(Punto,Punto1);
306  Punto1 = Punto;
307  IfDrawLine = 1;
308  }
309  //----------------------LABEL-------------------------
310  int PosLegX=(int)(PosInterp[0]*RisX);
311  int PosLegY=(int)((1.-PosInterp[1])*RisY);
312  if( DIS_IF_TYPE(IfDisegna,DIS_RETTA) ){
313  // NumLabel.setNum(r1.m,'g',DigPrec);
314  if(!IfStampa){
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));
319  }
320  else {
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));
323  //sprintf(stringa,"r %.5e Corr %.3e",r1.Corr,r1.Cov);
324  //p->drawText(RisX/2-RisX/8,RisY-15,QString(stringa));
325  }
326  }
327  else if( DIS_IF_TYPE(IfDisegna,DIS_PARABOLA) ){
328  int RefY = (int)(.1*RisY);
329  if(!IfStampa){
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));
334  }
335  else {
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));
342  }
343  }
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));
348  }
349  else if( DIS_IF_TYPE(IfDisegna,DIS_EXP) ){
350  // NumLabel.setNum(r1.m,'g',DigPrec);
351  if(!IfStampa){
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));
354  }
355  else {
356  sprintf(stringa,"y=%.3g exp(%.3g x)",log10(r1.q),r1.m);
357  p->drawText(PosLegX-strlen(stringa)*3.4,PosLegY,QString(stringa));
358  //sprintf(stringa,"r %.5e Corr %.3e",r1.Corr,r1.Cov);
359  //p->drawText(RisX/2-RisX/8,RisY-15,QString(stringa));
360  }
361  }
362  //printf("%d %d %d %d\n",NElMin,NElMax,NxMin,NxMax);
363 }
364 // if( (i%3)==0 ){
365 // for(int j=0;j<3;j++){
366 // PuntiLinea[j].setPoint(j,Mas(i,(int) ( i*RisX/(double)(NVisMax-NVisMin)) ),RisY-(int)( (double) Punti[i]*(double)(RisY)/yMax ) + (int) ( RisY/yMin) );
367 // }
368 // }
369 void ElementiGrafici::GrBarre(QPainter *p){
370  GrMessage("Visualizza.Dis.GrBarre");
371  p->setBrush( Qt::black );// Barre
372  p->setPen( QPen(Qt::black,1) );
373  Tempx = 0;
374  GrMessage("Visualizza.Dis.GrBarre.Ascissa");
375  if(DIS_IF_TYPE(LogLog,DIS_LOGX)){
376  if(v1->Abscissa(CoordY,NElMin) > 0. )
377  Tempx = (int)( (log10(v1->Abscissa(CoordY,NElMin))-xMin)/(xMax-xMin)*RisX);
378  }
379  else
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)){
383  if(v1->Abscissa(CoordY,NElMax) > 0. )
384  Tempx = (int)( (log10(v1->Abscissa(CoordY,NElMax))-xMin)/(xMax-xMin)*RisX);
385  }
386  else
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));
391  //emit SegnaleGrafico(1);
392 }
393 void ElementiGrafici::GrStampante(QPainter *p){
394  GrMessage("Visualizza.Dis.GrStampante");
395  Font.setFamily("Helvetica");
396  if(!IfStampa){
397  RisX = width();
398  RisY = height();
399  QRect view(0,0,width(),height());
400  p->setViewport(view);
401  ImpInterY(0,RisY);
402  StampaX = 0;
403  StampaY = 0;
404  PointSize = 2;
405  Font.setPointSize(12);
406  p->setFont(Font);
407  p->setFont(QFont("Palatino",12 ));
408  int PosLabel = (int)(RisX/2. - 2.*nomeEtX.length());
409  //int PosLabel = 0;
410  p->save();
411  p->translate(PosLabel,height()-40);
412  QTextDocument doc;
413  doc.setDefaultFont(QFont("Palatino",18 ));
414  doc.setHtml(nomeEtX); // or populate using QTextCursor
415  doc.drawContents(p);
416  p->restore();
417  p->save();
418  PosLabel = RisY - (int)(RisY/2. - 2.*nomeEtY.length());
419  p->translate(width()-40,PosLabel);
420  p->rotate(270);
421  doc.setHtml(nomeEtY); // or populate using QTextCursor
422  doc.drawContents(p);
423  p->restore();
424  }
425  else{
426  Q3PaintDeviceMetrics metrics( p->device() );
427  int dpiy = metrics.logicalDpiY();
428  int margin = (int) ((2/2.54)*dpiy);
429  //QRect view(3*margin,margin,metrics.width() - 3*margin, metrics.height() - 2*margin );
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);
435  p->setFont(Font);
436  p->setFont(QFont("Helvetica",FontSize));
437  PointSize = 5;
438  RisX = (int)(.9*metrics.width());
439  RisY = (int)(.9*metrics.height());
440  StampaX = 43;
441  StampaY = -60;
442  NElMinY = (int) (NElMinY*metrics.height()/(double)RisY);
443  NElMaxY = (int) (NElMaxY*metrics.height()/(double)RisY);
444  p->drawText(RisX/2-nomeTit.length(),-15,nomeTit);
445  int PosLabel = (int)(RisX/2. - 2.*nomeEtX.length());
446  //int PosLabel = 0;
447  QString Label1(nomeTit);
448  // p->drawText((int)(RisX/2. - nomeEtX.length()*7.),metrics.height()+40,nomeEtX,-1,Qt::AlignTop);
449  p->save();
450  p->translate(PosLabel,metrics.height()-10);
451  QTextDocument doc;
452  doc.setDefaultFont(QFont("Helvetica",FontSize));
453  doc.setHtml(nomeEtX); // or populate using QTextCursor
454  doc.drawContents(p);
455  p->restore();
456  p->save();
457  PosLabel = RisY - (int)(RisY/2. - 2.*nomeEtY.length());
458  p->translate(-(int)(3.5*margin),PosLabel);
459  p->rotate(270);
460  doc.setHtml(nomeEtY); // or populate using QTextCursor
461  doc.drawContents(p);
462  // PosLabel = RisY - (int)(RisY/2. - nomeEtY.length()*7.);
463  //p->drawText(0,0,nomeEtY);//,-1,Qt::AlignRight);
464  p->restore();
465  }
466 }
467 void ElementiGrafici::GrGriglia(QPainter *p){
468  GrMessage("Visualizza.Dis.GrGriglia");
469  QString NumLabel = QString();
470  if(!IfStampa)
471  p->setPen(QPen(Qt::black,1,Qt::DashLine,Qt::RoundCap,Qt::RoundJoin));
472  else
473  p->setPen(QPen(Qt::black,3,Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin));
474  //p->setPen( QPen(Qt::black,1) );
475  //p->setBrush( Qt::black );
476  //p->setPen( Qt::DashLine );
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)){
482  //---------------------Griglia-y---------------------
483  for(int i=0;i<=GrigliaY;i++){
484  Tempy = (int) (RisY/(double)GrigliaY*i);
485  if(!IfStampa)
486  p->drawLine(QPoint(0,Tempy),QPoint(RisX,Tempy) );
487  else{
488  p->drawLine(QPoint(0,Tempy),QPoint(10,Tempy) );
489  p->drawLine(QPoint(RisX,Tempy),QPoint(RisX-10,Tempy) );
490  if(i<GrigliaY-1) {
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) );
494  }
495  }
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);
502  }
503  }
504  if(!DIS_IF_TYPE(LogLog,DIS_LOGX)){
505  //---------------------Griglia-x---------------------
506  for(int i = 0;i<=GrigliaX;i++){
507  Tempx = (int) (RisX/(double)GrigliaX*i);
508  if(!IfStampa)
509  p->drawLine(QPoint(Tempx,0),QPoint(Tempx,RisY) );
510  else{
511  p->drawLine(QPoint(Tempx,RisY-10),QPoint(Tempx,RisY) );
512  p->drawLine(QPoint(Tempx,0),QPoint(Tempx,10) );
513  if(i<GrigliaX-1) {
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) );
517  }
518  }
519  NumLabel.setNum((double)(xMax-xMin)/(double)GrigliaX*i+xMin,FormatPrecX,DigPrecX);
520  //p->drawText(Tempx,RisY+StampaX,QString(stringa));
521  if(IfStampa) Tempx -= (int)(9.*NumLabel.length());
522  p->drawText(Tempx,RisY+StampaX,NumLabel);
523  // p->drawText(Tempx-(int)(.5*RisX/(double)GrigliaX),RisY+StampaX,NumLabel);
524  }
525  if(!IfStampa){
526  sprintf(stringa,"%% %.4g",(double)(yMax-yMin)/(double)((yMax+yMin)*.5)*100.);
527  p->drawText(RisX/2,10,QString(stringa));
528  }
529  }
530  if(DIS_IF_TYPE(LogLog,DIS_LOGY)){
531  //--------LogLog-y-----------------------
532  NyMin = (int)yMin;
533  NyMax = (int)yMax;
534  Delta = 1;
535  if(NyMin < 0){
536  for(int i=NyMin;i<0;i++){
537  Delta /= 10;
538  }
539  }
540  else if(NyMin > 0){
541  for(int i=0;i<NyMin;i++){
542  Delta *= 10;
543  }
544  }
545  if( NyMin < NyMax){
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);
552  //if(i==NyMax) Tempy -= 10;
553  //if(i==NyMin) Tempy += 10;
554  if(!IfStampa)
555  p->drawLine( QPoint(0,Tempy),QPoint(RisX,Tempy));
556  else{
557  p->drawLine(QPoint(0,Tempy),QPoint(15,Tempy) );
558  p->drawLine(QPoint(RisX,Tempy),QPoint(RisX-15,Tempy) );
559  }
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) );
576  Delta *= 10;
577  }
578  }
579  if(NyMin == NyMax){
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));
584  }
585  }
586  if(DIS_IF_TYPE(LogLog,DIS_LOGX)){
587  //--------------LogLog-x--------------------------
588  NxMin = (int)xMin;
589  NxMax = (int)xMax;
590  Delta = 1;
591  if(NxMin < 0){
592  for(int i=NxMin;i<0;i++){
593  Delta /= 10;
594  }
595  }
596  else if(NxMin > 0){
597  for(int i=0;i<NxMin;i++){
598  Delta *= 10;
599  }
600  }
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));
609  if(!IfStampa)
610  p->drawLine( QPoint(Tempx,RisY),QPoint(Tempx,0));
611  else{
612  p->drawLine(QPoint(Tempx,RisY-15),QPoint(Tempx,RisY) );
613  p->drawLine(QPoint(Tempx,0),QPoint(Tempx,15) );
614  }
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) );
631  Delta *= 10;
632  }
633  }
634 }
635 void ElementiGrafici::GrRiscala(){
636  GrMessage("Visualizza.Dis.GrRiscala.x");
637  if(DIS_IF_TYPE(IfRiscala,RIS_UNO) ){
638  if(v1->IsAbscissa(CoordX)){
639  xMin = v1->pMin(CoordX,NVisMin,NVisMax);
640  xMax = v1->pMax(CoordX,NVisMin,NVisMax);
641  }
642  else{
643  xMin = NVisMin;
644  xMax = NVisMax;
645  }
646  GrMessage("Visualizza.Dis.GrRiscala.y");
647  yMin = v1->pMin(CoordY,NVisMin,NVisMax);
648  yMax = v1->pMax(CoordY,NVisMin,NVisMax);
649  }
650  else if(DIS_IF_TYPE(IfRiscala,RIS_TUTTI) ){
651  GrMessage("Visualizza.Dis.GrRiscala.Tutto %d",NVar);
652  v1->pMinMaxGlob(NVisMin,NVisMax);
653  v1->pGlobBorder(&xMin,&xMax,&yMin,&yMax);
654  if(!v1->IsAbscissa(CoordX)){
655  xMin = NVisMin;
656  xMax = NVisMax;
657  }
658  }
659  if( DIS_IF_TYPE(IfDisegna,DIS_PUNTI) ){
660  GrMessage("Visualizza.Dis.GrRiscala.Punti");
661  yMin = v1->PuntiMin();
662  yMax = v1->PuntiMax();
663  }
664  if( DIS_IF_TYPE(IfDisegna,DIS_MOMENTI) ){
665  GrMessage("Visualizza.Dis.GrRiscala.Momenti");
666  yMin = m1.yMin;
667  yMax = m1.yMax;
668  xMin = m1.Min;
669  xMax = m1.Max;
670  }
671  if(DIS_IF_TYPE(LogLog,DIS_LOGX)){// LogLog
672  GrMessage("Visualizza.Dis.GrRiscala.Logx");
673  if(v1->IsAbscissa(CoordX)){
674  xMin = v1->pMinLog(CoordX,NVisMin,NVisMax);
675  xMax = v1->pMaxLog(CoordX,NVisMin,NVisMax);
676  }
677  else{
678  xMin = log10(NVisMin);
679  xMax = log10(NVisMax);
680  }
681  }
682  if(DIS_IF_TYPE(LogLog,DIS_LOGY)){// LogLog
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);
687  }
688  else if( DIS_IF_TYPE(IfRiscala,RIS_TUTTI) ){
689  yMin = v1->pMinGlobLog(NVisMin,NVisMax);
690  yMax = v1->pMaxGlobLog(NVisMin,NVisMax);
691  }
692  // if(yMin <= 0.){
693  // char SErr[120];
694  // sprintf(SErr,"Ordinates negative or null %f, no log log possible",yMin);
695  // ErrPrima->message(QString(SErr));
696  // //QMessageBox::information(this,"Visualizza","Numeri negativi o nulli\n Non posso visualizzare LogLog","Va Be!");
697  // DIS_REM_TYPE(LogLog,DIS_LOGY);
698  // emit LogyCambiato(LogLog);
699  // }
700  }
701  GrMessage("xBound %lf-%lf yBound %lf-%lf\n",xMin,xMax,yMin,yMax);
702  ScalaTopoX = xMax-xMin;
703  ScalaTopoY = yMax-yMin;
704  // yMax = (yMax*1.1);
705  // yMin = (yMin*0.9);
706  // xMax = (xMax*1.1);
707  // xMin = (xMin*0.9);
708  yMax += (yMax-yMin)*ViewportY;
709  yMin -= (yMax-yMin)*ViewportY;
710  xMax += (xMax-xMin)*ViewportX;
711  xMin -= (xMax-xMin)*ViewportX;
712 }
713 void ElementiGrafici::GrLegenda(QPainter *p){
714  GrMessage("Visualizza.Dis.GrLegenda");
715  //QRect Leg((int)(PosLegenda[0]*width()),(int)((1.-PosLegenda[1])*height()),
716  // (int)(PosLegenda[2]*width()),(int)((1.-PosLegenda[3])*height()));
717  // QRect Leg((int)(.8*width()),(int)((1.-.8)*height()),
718  // (int)(.9*width()),(int)((1.-.9)*height()));
719  //p->drawText(Leg,Qt::AlignCenter,tr("Ciccia"));
720  //p->drawText((int)(PosLegenda[0]*width()),(int)((1.-PosLegenda[1])*height()),tr("Chem Pot"));
721  //p->drawText((int)(.8*width()),(int)((1.-.8)*height()),tr("Chem Pot"));
722  int PosLegX=(int)(PosLegenda[0]*RisX);
723  int PosLegY=(int)((1.-PosLegenda[1])*RisY);
724  int PosFinL=PosLegX, PosFinY=PosLegY;
725  int IncrY = 15;
726  if(IfStampa) IncrY = 30;
727  for(int s=0;s<NVar;s++){
728  if(v1->IsAbscissa(s)) continue;
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]);
738  PosFinY += IncrY;
739  }
740 }
741 void ElementiGrafici::GrScript(char *File2Read,QPainter *p){
742  GrMessage("Visualizza.Dis.GrScript");
743  FILE *File2Open;
744  if( (File2Open = fopen(File2Read,"r"))==0){
745  // printf("The file %s does not exist\n");
746  return ;
747  }
748  char cLine[256];
749  double Color[4];
750  double Pos[4];
751  double Hue[4];
752  int iHue[4];
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);
759  char String[256];
760  fgets(cLine,256,File2Open);
761  //for(int c=0;c<strlen(cLine);c++) String[c] = cLine[c];
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);
767  p->save();
768  p->rotate(Pos[2]);
769  p->drawText(Pos[0]*RisX,(1.-Pos[1])*RisY,QString(String));
770  p->restore();
771  if(IfStampa)
772  p->setFont(QFont("Palatino",FontSize));
773  else
774  p->setFont(QFont("Palatino",12));
775  }
776  else if(strncmp(cLine,"PutLine",7)==0){
777  //Colore
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);
783  //Posizione
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);
793  }
794  else if(strncmp(cLine,"Text",4)==0){
795  //Colore
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]) );
800  //Posizione
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]));
805  //Testo
806  fgets(cLine,256,File2Open);
807  QChar ChType = QChar::NoCategory;
808  QString String;
809  int Posx = Fromx;
810  int Posy = Fromy;
811  int FontSize = 12;
812  int IfSymbol = 0;
813  int IfUpper = 0;
814  for(int i=0,j=0;i<strlen(cLine);i++){
815  if(cLine[i] == '\\'){
816  IfSymbol = 0x0350;
817  continue;
818  }
819  else if(cLine[i] == '^'){
820  IfUpper = 1;
821  continue;
822  }
823  else if(cLine[i] == '_'){
824  IfUpper = -1;
825  continue;
826  }
827  else if(cLine[i] == '%'){
828  IfSymbol = 0;
829  IfUpper = 1;
830  continue;
831  }
832  //String.insert(i,QChar(sTable(cLine+j)));
833  String.insert(j,QChar((uint)(cLine[i]+IfSymbol)));
834  j++;
835  }
836  p->drawText(Fromx,Fromy,String,-1,Qt::AlignTop);
837  }
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]));
845  char String[512];
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));
849  }
850  else if(strncmp(cLine,"Background",10)==0){
851  }
852  }
853  fclose(File2Open);
854 }
855 void ElementiGrafici::GrConf(char *File2Read){
856  GrMessage("Visualizza.Dis.GrConf");
857  FILE *File2Open;
858  if( (File2Open = fopen(File2Read,"r"))==0){
859  // printf("The file %s does not exist\n");
860  return ;
861  }
862  char cLine[256];
863  for(int k=0;!(fgets(cLine,256,File2Open)==NULL);k++){
864  //printf("%s",cLine);
865  //if(cLine[0] == '#') continue;
866  if(strncmp(cLine,"NGrid",5)==0){
867  fgets(cLine,256,File2Open);
868  sscanf(cLine,"%d %d\n",&GrigliaX,&GrigliaY);
869  }
870  else if(strncmp(cLine,"XFormula",8)==0){
871  fgets(cLine,256,File2Open);
872  sscanf(cLine,"%s\n",XFormula);
873  v1->setXFormula(XFormula);
874  }
875  else if(strncmp(cLine,"YFormula",8)==0){
876  fgets(cLine,256,File2Open);
877  sscanf(cLine,"%s\n",YFormula);
878  v1->setYFormula(YFormula);
879  }
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);
889  }
890  }
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);
900  }
901  }
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));
905  }
906  else if(strncmp(cLine,"PosInterp",6)==0){
907  fgets(cLine,256,File2Open);
908  sscanf(cLine,"%lf %lf\n",(PosInterp+0),(PosInterp+1));
909  }
910  else if(strncmp(cLine,"DigPrecX",8)==0){
911  fgets(cLine,256,File2Open);
912  sscanf(cLine,"%d %c\n",&DigPrecX,&FormatPrecX);
913  }
914  else if(strncmp(cLine,"DigPrecY",8)==0){
915  fgets(cLine,256,File2Open);
916  sscanf(cLine,"%d %c\n",&DigPrecY,&FormatPrecY);
917  }
918  else if(strncmp(cLine,"ViewportX",9)==0){
919  fgets(cLine,256,File2Open);
920  sscanf(cLine,"%lf\n",&ViewportX);
921  }
922  else if(strncmp(cLine,"ViewportY",9)==0){
923  fgets(cLine,256,File2Open);
924  sscanf(cLine,"%lf\n",&ViewportY);
925  }
926  else if(strncmp(cLine,"FontSize",8)==0){
927  fgets(cLine,256,File2Open);
928  sscanf(cLine,"%d\n",&FontSize);
929  }
930  else if(strncmp(cLine,"RatioWidthHeight",16)==0){
931  fgets(cLine,256,File2Open);
932  sscanf(cLine,"%lf\n",&RatioWidthHeight);
933  }
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];
938  nomeEtX.clear();
939  StringToUnicode(String,&nomeEtX);
940  free(String);
941  }
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];
946  nomeEtY.clear();
947  StringToUnicode(String,&nomeEtY);
948  free(String);
949  }
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];
954  nomeTit.clear();
955  StringToUnicode(String,&nomeTit);
956  free(String);
957  }
958  else if(strncmp(cLine,"Line",4)==0){
959  int NLine;
960  int Type;
961  double Color[4];
962  fgets(cLine,256,File2Open);
963  sscanf(cLine,"%d\n",&NLine);
964  if(NLine >= NVar) {
965  //printf("The %d th column is not present\n",NLine);
966  NLine = 0;
967  continue;
968  }
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);
973  //printf("%d %d %lf %lf %lf\n",NLine,Type,Color[0],Color[1],Color[2],Color[3]);
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]);
981  }
982  }
983  GrMessage("NGrid %d %d XBond %lf %lf YBound %lf %lf\n",GrigliaX,GrigliaY,xMin,xMax,yMin,yMax);
984  fclose(File2Open);
985 }
986 void ElementiGrafici::StringToUnicode(char *cLine,QString *Label){
987  QChar ChType = QChar::NoCategory;
988  int UnicodeRow = 0;
989  int CharOffset = 0;
990  for(int i=0,j=0;i<strlen(cLine);i++){
991  int Char = cLine[i];
992  if(cLine[i] == '\\' && i < strlen(cLine)-1){
993  if(cLine[i+1] == 's'){
994  //ChType = QChar::Symbol_Math;
995  CharOffset = 0x0350;
996  UnicodeRow = 3;
997  }
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'){
1003  UnicodeRow = 0;
1004  CharOffset = 0;
1005  ChType = QChar::NoCategory;
1006  }
1007  i+=1;
1008  continue;
1009  }
1010  else
1011  ChType = QChar::NoCategory;
1012  //QChar Character = QChar(QChar(Char).cell(),QChar(QChar::Symbol_Math).row());
1013  QChar Char1 = QChar(Char+CharOffset);
1014  //printf("%c %d %d %x\n",Char1.toAscii(),Char1.cell(),Char1.row(),Char1.unicode());
1015  //GrLabel[NLine].insert(i,Char1);
1016  Label->insert(j,QChar(Char1.cell(),UnicodeRow));//QChar(Char));
1017  j++;
1018  }
1019  //GrLabel[NLine].append(cLine);
1020  //sprintf(LineaQuale[NLine],"%s",cLine);
1021 }
double pPunti(int n)
Value of the elaborated array at position.
Definition: VarDatFile.cpp:673
double a1
a0 + a1 x + a2 x^2
int pNRow(int CoordY)
Print the maximum number of data for the column.
Definition: VarDatFile.cpp:664
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.
Definition: VarDatFile.h:250
double pMinGlobLog(int NVisMin, int NVisMax)
Print the minimum of all sets.
double Min
Minimum value.
double Due
Second moment.
double pPuntiErr(int n)
Value of the error array at postion.
Definition: VarDatFile.cpp:680
double Tre
Third moment.
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.
Definition: VarDatFile.cpp:700
double m
y = m*x + q
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 Cov
Covariance.
double PuntiMin()
Print the minimum of.
Definition: VarDatFile.cpp:690
void pGlobBorder(double *xMin, double *xMax, double *yMin, double *yMax)
Print global borders.
Definition: VarDatFile.h:209
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.
Definition: VarDatFile.h:246
double a0
a0 + a1 x + a2 x^2
double Val(int CoordY, int n)
Value at the position.
Definition: VarDatFile.cpp:657
int IsAbscissa(int Col)
If the column is an ascissa.
Definition: VarDatFile.h:256
double Gauss(double Media, double Scarto, double x)
Gaussian.
double Minimo
Minimum of the parabola.
double Max
Maximum value.
double Uno
First moment.
void setYFormula(char *str)
Set the value of YFormula.
double Chi
Chi square.
int Num
Number of points considered.
void pMinMaxGlob(int NVisMin, int NVisMax)
Find the borders globally.
Definition: VarDatFile.cpp:986
double Abscissa(int CoordY, int n)
Value of the Abscissa at position.
Definition: VarDatFile.cpp:667
double q
y = m*x + q
double pMin(int CoordY, int NVisMin, int NVisMax)
Print the minimum of the column.
VarDatFile * v1
Class for the file handle.
double Corr
Correlation.